当前位置: 首页>>代码示例>>Java>>正文


Java Value类代码示例

本文整理汇总了Java中org.apache.mesos.Protos.Value的典型用法代码示例。如果您正苦于以下问题:Java Value类的具体用法?Java Value怎么用?Java Value使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Value类属于org.apache.mesos.Protos包,在下文中一共展示了Value类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: setValue

import org.apache.mesos.Protos.Value; //导入依赖的package包/类
private static Resource.Builder setValue(Resource.Builder builder, Value value) {
    builder.setType(value.getType());
    switch (value.getType()) {
    case SCALAR:
        builder.setScalar(value.getScalar());
        return builder;
    case RANGES:
        builder.setRanges(value.getRanges());
        return builder;
    case SET:
        builder.setSet(value.getSet());
        return builder;
    default:
        throw new IllegalArgumentException(String.format("Unsupported spec value type: %s", value.getType()));
    }
}
 
开发者ID:mesosphere,项目名称:dcos-commons,代码行数:17,代码来源:ResourceBuilder.java

示例2: freeMergedResource

import org.apache.mesos.Protos.Value; //导入依赖的package包/类
private void freeMergedResource(MesosResource mesosResource) {
    if (mesosResource.getResourceId().isPresent()) {
        dynamicallyReservedPoolByResourceId.remove(mesosResource.getResourceId().get());
        logger.info("Freed resource: {}", !dynamicallyReservedPoolByResourceId
                .containsKey(mesosResource.getResourceId().get()));
    }

    String previousRole = mesosResource.getPreviousRole();
    Map<String, Value> pool = reservableMergedPoolByRole.get(previousRole);
    if (pool == null) {
        pool = new HashMap<>();
    }

    Value currValue = pool.get(mesosResource.getName());
    if (currValue == null) {
        currValue = ValueUtils.getZero(mesosResource.getType());
    }

    Value updatedValue = ValueUtils.add(currValue, mesosResource.getValue());
    pool.put(mesosResource.getName(), updatedValue);
    reservableMergedPoolByRole.put(previousRole, pool);
}
 
开发者ID:mesosphere,项目名称:dcos-commons,代码行数:23,代码来源:MesosResourcePool.java

示例3: getReservableMergedPool

import org.apache.mesos.Protos.Value; //导入依赖的package包/类
private Map<String, Map<String, Value>> getReservableMergedPool(Collection<MesosResource> mesosResources) {
    Map<String, List<MesosResource>> rolePool = new HashMap<>();
    for (MesosResource mesosResource : getMergedResources(mesosResources)) {
        if (!mesosResource.hasResourceId()) {
            String role = mesosResource.getRole();
            List<MesosResource> resources = rolePool.get(role);
            if (resources == null) {
                resources = new ArrayList<>();
            }

            resources.add(mesosResource);
            rolePool.put(role, resources);
        }
    }

    Map<String, Map<String, Value>> roleResourcePool = new HashMap<>();
    for (Map.Entry<String, List<MesosResource>> entry : rolePool.entrySet()) {
        roleResourcePool.put(entry.getKey(), getResourcePool(entry.getValue()));
    }

    return roleResourcePool;
}
 
开发者ID:mesosphere,项目名称:dcos-commons,代码行数:23,代码来源:MesosResourcePool.java

示例4: getValue

import org.apache.mesos.Protos.Value; //导入依赖的package包/类
public static Value getValue(Resource resource) {
    Type type = resource.getType();
    Value.Builder builder = Value.newBuilder();
    builder.setType(type);

    switch (type) {
        case SCALAR:
            return builder.setScalar(resource.getScalar()).build();
        case RANGES:
            return builder.setRanges(resource.getRanges()).build();
        case SET:
            return builder.setSet(resource.getSet()).build();
        default:
            return null;
    }
}
 
开发者ID:mesosphere,项目名称:dcos-commons,代码行数:17,代码来源:ValueUtils.java

示例5: add

import org.apache.mesos.Protos.Value; //导入依赖的package包/类
public static Value add(Value val1, Value val2) {
    Type type1 = val1.getType();
    Type type2 = val2.getType();

    if (type1 != type2) {
        return null;
    }

    switch (type1) {
        case SCALAR:
            Value.Scalar scalar = add(val1.getScalar(), val2.getScalar());
            return Value.newBuilder().setType(type1).setScalar(scalar).build();
        case RANGES:
            Value.Ranges ranges = add(val1.getRanges(), val2.getRanges());
            return Value.newBuilder().setType(type1).setRanges(ranges).build();
        default:
            return null;
    }
}
 
开发者ID:mesosphere,项目名称:dcos-commons,代码行数:20,代码来源:ValueUtils.java

示例6: subtract

import org.apache.mesos.Protos.Value; //导入依赖的package包/类
public static Value subtract(Value val1, Value val2) {
    Type type1 = val1.getType();
    Type type2 = val2.getType();

    if (type1 != type2) {
        return null;
    }

    switch (type1) {
        case SCALAR:
            Value.Scalar scalar = subtract(val1.getScalar(), val2.getScalar());
            return Value.newBuilder().setType(type1).setScalar(scalar).build();
        case RANGES:
            Value.Ranges ranges = subtract(val1.getRanges(), val2.getRanges());
            return Value.newBuilder().setType(type1).setRanges(ranges).build();
        default:
            return null;
    }
}
 
开发者ID:mesosphere,项目名称:dcos-commons,代码行数:20,代码来源:ValueUtils.java

示例7: compare

import org.apache.mesos.Protos.Value; //导入依赖的package包/类
public static Integer compare(Value val1, Value val2) {
    Type type1 = val1.getType();
    Type type2 = val2.getType();

    if (type1 != type2) {
        return null;
    }

    switch (type1) {
        case SCALAR:
            return compare(val1.getScalar(), val2.getScalar());
        case RANGES:
            return compare(val1.getRanges(), val2.getRanges());
        default:
            return null;
    }
}
 
开发者ID:mesosphere,项目名称:dcos-commons,代码行数:18,代码来源:ValueUtils.java

示例8: pickAndRegisterPortNumber

import org.apache.mesos.Protos.Value; //导入依赖的package包/类
/**
 * Picks a port number from the given offer's port resources
 *
 * @param taskId the TaskID to register the picked ports with
 * @param offer  the offer from which's resources to pick a port
 * @return a port number
 */
public long pickAndRegisterPortNumber(TaskID taskId, Offer offer) {
    for (Resource resource : offer.getResourcesList()) {
        if (!resource.getName().equals("ports")) continue;

        List<Value.Range> offeredRanges = resource.getRanges().getRangeList();
        for (Value.Range portRange : offeredRanges) {
            long begin = portRange.getBegin();
            long end = portRange.getEnd();
            for (long port = begin; port < end; port++) {
                if (!usedPortNumbers.values().contains(port)) {
                    usedPortNumbers.put(taskId, port);
                    LOGGER.info("Task {} received port {}.", taskId, port);
                    return port;
                }
            }
        }
    }
    LOGGER.warn("Offer {} had no unused port to offer! Task {} received no port!", offer.getId().getValue(), taskId.getValue());
    return -1;
}
 
开发者ID:Praqma,项目名称:mesos-kibana,代码行数:28,代码来源:SchedulerConfiguration.java

示例9: getExecutorResources

import org.apache.mesos.Protos.Value; //导入依赖的package包/类
private List<Resource> getExecutorResources() {
  return Arrays.asList(Resource.newBuilder()
      .setName("cpus")
      .setType(Value.Type.SCALAR)
      .setScalar(Value.Scalar.newBuilder()
          .setValue(hbaseFrameworkConfig.getExecutorCpus()).build())
      .setRole(hbaseFrameworkConfig.getHbaseRole())
      .build(),
      Resource
          .newBuilder()
          .setName("mem")
          .setType(Value.Type.SCALAR)
          .setScalar(Value.Scalar
              .newBuilder()
              .setValue(hbaseFrameworkConfig.getExecutorHeap()
                  * hbaseFrameworkConfig.getJvmOverhead()).build())
          .setRole(hbaseFrameworkConfig.getHbaseRole())
          .build());
}
 
开发者ID:jan-zajic,项目名称:mesos-hbase,代码行数:20,代码来源:HBaseScheduler.java

示例10: getTaskResources

import org.apache.mesos.Protos.Value; //导入依赖的package包/类
private List<Resource> getTaskResources(String taskName) {
  return Arrays.asList(Resource.newBuilder()
      .setName("cpus")
      .setType(Value.Type.SCALAR)
      .setScalar(Value.Scalar.newBuilder()
          .setValue(hbaseFrameworkConfig.getTaskCpus(taskName)).build())
      .setRole(hbaseFrameworkConfig.getHbaseRole())
      .build(),
      Resource.newBuilder()
          .setName("mem")
          .setType(Value.Type.SCALAR)
          .setScalar(Value.Scalar.newBuilder()
              .setValue(hbaseFrameworkConfig.getTaskHeapSize(taskName) *
                  hbaseFrameworkConfig.getJvmOverhead()).build())
          .setRole(hbaseFrameworkConfig.getHbaseRole())
          .build());
}
 
开发者ID:jan-zajic,项目名称:mesos-hbase,代码行数:18,代码来源:HBaseScheduler.java

示例11: getTaskInfo

import org.apache.mesos.Protos.Value; //导入依赖的package包/类
/**
 * Builds a TaskInfo from the given jobspec
 * @param job - JobSpec to TaskInfo-ify
 * @param offer - offer add extra data (SlaveId)
 * @return TaskInfo fully formed
 */
private TaskInfo getTaskInfo(JobSpec job,Offer offer) {
    TaskID taskId = TaskID.newBuilder().setValue(job.getJob().getId()).build();
    TaskInfo info = TaskInfo.newBuilder().setName("task " + taskId.getValue())
             .setTaskId(taskId)
             .setSlaveId(offer.getSlaveId())
             .addResources(Resource.newBuilder()
                           .setName("cpus")
                           .setType(Value.Type.SCALAR)
                           .setScalar(Value.Scalar.newBuilder().setValue(job.getJob().getLoadValue()*1.0)))
             .addResources(Resource.newBuilder()
                           .setName("mem")
                           .setType(Value.Type.SCALAR)
                           .setScalar(Value.Scalar.newBuilder().setValue(job.getJob().getLoadValue()*1024.0)))
             .setExecutor(ExecutorInfo.newBuilder(executor)).setData(MesosUtilities.jobSpecToByteString(job)).build();
    return info;
}
 
开发者ID:apache,项目名称:oodt,代码行数:23,代码来源:ResourceMesosScheduler.java

示例12: ResourceBuilder

import org.apache.mesos.Protos.Value; //导入依赖的package包/类
private ResourceBuilder(String resourceName, Value value, String preReservedRole) {
    this.resourceName = resourceName;
    this.value = value;
    this.preReservedRole = preReservedRole;
    this.role = Optional.empty();
    this.principal = Optional.empty();
    this.resourceId = Optional.empty();
    this.diskContainerPath = Optional.empty();
    this.diskPersistenceId = Optional.empty();
    this.diskMountInfo = Optional.empty();
}
 
开发者ID:mesosphere,项目名称:dcos-commons,代码行数:12,代码来源:ResourceBuilder.java

示例13: consumeReserved

import org.apache.mesos.Protos.Value; //导入依赖的package包/类
public Optional<MesosResource> consumeReserved(String name, Value value, String resourceId) {
    MesosResource mesosResource = dynamicallyReservedPoolByResourceId.get(resourceId);

    if (mesosResource != null) {
        if (mesosResource.isAtomic()) {
            if (sufficientValue(value, mesosResource.getValue())) {
                dynamicallyReservedPoolByResourceId.remove(resourceId);
            } else {
                logger.warn("Reserved atomic quantity of {} is insufficient: desired {}, reserved {}",
                        name,
                        TextFormat.shortDebugString(value),
                        TextFormat.shortDebugString(mesosResource.getValue()));
                return Optional.empty();
            }
        } else {
            Value availableValue = mesosResource.getValue();
            if (ValueUtils.compare(availableValue, value) > 0) {
                // Update the value in pool with the remaining unclaimed resource amount
                Resource remaining = ResourceBuilder.fromExistingResource(mesosResource.getResource())
                        .setValue(ValueUtils.subtract(availableValue, value))
                        .build();
                dynamicallyReservedPoolByResourceId.put(resourceId, new MesosResource(remaining));
                // Return only the claimed resource amount from this reservation
            } else {
                dynamicallyReservedPoolByResourceId.remove(resourceId);
            }
        }
    } else {
        logger.warn("Failed to find reserved {} resource with ID: {}. Reserved resource IDs are: {}",
                name,
                resourceId,
                dynamicallyReservedPoolByResourceId.keySet());
    }

    return Optional.ofNullable(mesosResource);
}
 
开发者ID:mesosphere,项目名称:dcos-commons,代码行数:37,代码来源:MesosResourcePool.java

示例14: consumeAtomic

import org.apache.mesos.Protos.Value; //导入依赖的package包/类
public Optional<MesosResource> consumeAtomic(String resourceName, Value value) {
    List<MesosResource> atomicResources = unreservedAtomicPool.get(resourceName);
    List<MesosResource> filteredResources = new ArrayList<>();
    Optional<MesosResource> sufficientResource = Optional.empty();

    if (atomicResources != null) {
        for (MesosResource atomicResource : atomicResources) {
            if (!sufficientResource.isPresent() && sufficientValue(value, atomicResource.getValue())) {
                sufficientResource = Optional.of(atomicResource);
                // do NOT break: ensure filteredResources is fully populated
            } else {
                filteredResources.add(atomicResource);
            }
        }
    }

    if (filteredResources.isEmpty()) {
        unreservedAtomicPool.remove(resourceName);
    } else {
        unreservedAtomicPool.put(resourceName, filteredResources);
    }

    if (!sufficientResource.isPresent()) {
        if (atomicResources == null) {
            logger.info("Offer lacks any atomic resources named {}", resourceName);
        } else {
            logger.info("Offered quantity in all {} instances of {} is insufficient: desired {}",
                    atomicResources.size(),
                    resourceName,
                    value);
        }
    }

    return sufficientResource;
}
 
开发者ID:mesosphere,项目名称:dcos-commons,代码行数:36,代码来源:MesosResourcePool.java

示例15: consumeReservableMerged

import org.apache.mesos.Protos.Value; //导入依赖的package包/类
public Optional<MesosResource> consumeReservableMerged(String name, Value desiredValue, String preReservedRole) {
    Map<String, Value> pool = reservableMergedPoolByRole.get(preReservedRole);
    if (pool == null) {
        logger.info("No unreserved resources available for role '{}'. Reservable roles are: {}",
                preReservedRole, reservableMergedPoolByRole.keySet());
        return Optional.empty();
    }

    Value availableValue = pool.get(name);

    if (sufficientValue(desiredValue, availableValue)) {
        pool.put(name, ValueUtils.subtract(availableValue, desiredValue));
        reservableMergedPoolByRole.put(preReservedRole, pool);

        Resource.Builder builder = ResourceBuilder.fromUnreservedValue(name, desiredValue).build().toBuilder();
        if (Capabilities.getInstance().supportsPreReservedResources() &&
                !preReservedRole.equals(Constants.ANY_ROLE)) {
            builder.addReservations(
                    Resource.ReservationInfo.newBuilder()
                            .setRole(preReservedRole)
                            .setType(Resource.ReservationInfo.Type.STATIC));
        }

        return Optional.of(new MesosResource(builder.build()));
    } else {
        if (availableValue == null) {
            logger.info("Offer lacks any unreserved {} resources for role {}", name, preReservedRole);
        } else {
            logger.info("Offered quantity of {} for role {} is insufficient: desired {}, offered {}",
                    name,
                    preReservedRole,
                    TextFormat.shortDebugString(desiredValue),
                    TextFormat.shortDebugString(availableValue));
        }
        return Optional.empty();
    }
}
 
开发者ID:mesosphere,项目名称:dcos-commons,代码行数:38,代码来源:MesosResourcePool.java


注:本文中的org.apache.mesos.Protos.Value类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。