• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java Value类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: sufficientValue

import org.apache.mesos.Protos.Value; //导入依赖的package包/类
private static boolean sufficientValue(Value desired, Value available) {
    if (desired == null) {
        return true;
    } else if (available == null) {
        return false;
    }

    Value difference = ValueUtils.subtract(desired, available);
    return ValueUtils.compare(difference, ValueUtils.getZero(desired.getType())) <= 0;
}
 
开发者ID:mesosphere,项目名称:dcos-commons,代码行数:11,代码来源:MesosResourcePool.java


示例17: getResourcePool

import org.apache.mesos.Protos.Value; //导入依赖的package包/类
private static Map<String, Value> getResourcePool(Collection<MesosResource> mesosResources) {
    Map<String, Value> pool = new HashMap<>();
    for (MesosResource mesosResource : mesosResources) {
        String name = mesosResource.getName();
        Value currValue = pool.get(name);

        if (currValue == null) {
            currValue = ValueUtils.getZero(mesosResource.getType());
        }

        pool.put(name, ValueUtils.add(currValue, mesosResource.getValue()));
    }

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


示例18: getZero

import org.apache.mesos.Protos.Value; //导入依赖的package包/类
public static Value getZero(Value.Type type) {
    switch (type) {
        case SCALAR:
            Value.Scalar scalar = Value.Scalar.newBuilder().setValue(0).build();
            return Value.newBuilder().setType(type).setScalar(scalar).build();
        case RANGES:
            Value.Ranges ranges = Value.Ranges.newBuilder().addAllRange(Collections.emptyList()).build();
            return Value.newBuilder().setType(type).setRanges(ranges).build();
        default:
            return null;
    }
}
 
开发者ID:mesosphere,项目名称:dcos-commons,代码行数:13,代码来源:ValueUtils.java


示例19: addResource

import org.apache.mesos.Protos.Value; //导入依赖的package包/类
/**
 * Minimum to keep required field errors away.
 */
public static void addResource(Offer.Builder o, String name, String role) {
    Resource.Builder b = o.addResourcesBuilder().setType(Value.Type.RANGES).setName(name);
    if (role != null) {
        b.setRole(role);
    }
}
 
开发者ID:mesosphere,项目名称:dcos-commons,代码行数:10,代码来源:OfferTestUtils.java


示例20: offerWithAttribute

import org.apache.mesos.Protos.Value; //导入依赖的package包/类
private static Offer offerWithAttribute(String name, String value) {
    Protos.Resource resource = ResourceBuilder.fromUnreservedValue(
            "cpus",
            Protos.Value.newBuilder()
                    .setType(Protos.Value.Type.SCALAR)
                    .setScalar(Protos.Value.Scalar.newBuilder().setValue(1.0))
                    .build())
            .build();
    Offer.Builder offerBuilder = OfferTestUtils.getCompleteOffer(resource).toBuilder();
    offerBuilder.addAttributesBuilder()
            .setName(name)
            .setType(Value.Type.TEXT)
            .getTextBuilder().setValue(value);
    return offerBuilder.build();
}
 
开发者ID:mesosphere,项目名称:dcos-commons,代码行数:16,代码来源:RoundRobinByAttributeRuleTest.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java DomNodeList类代码示例发布时间:2022-05-22
下一篇:
Java StandalonePluginWorkspace类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap