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


Java Resource类代码示例

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


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

示例1: createResources

import org.apache.mesos.Protos.Resource; //导入依赖的package包/类
private List<Resource> createResources(int cpus, int memory, String... ranges) {
  List<Resource> resources = Lists.newArrayList();

  if (cpus > 0) {
    resources.add(Resource.newBuilder().setType(Type.SCALAR).setName(MesosUtils.CPUS).setScalar(Scalar.newBuilder().setValue(cpus).build()).build());
  }

  if (memory > 0) {
    resources.add(Resource.newBuilder().setType(Type.SCALAR).setName(MesosUtils.MEMORY).setScalar(Scalar.newBuilder().setValue(memory).build()).build());
  }

  if (ranges.length > 0) {
    resources.add(buildPortRanges(ranges));
  }

  return resources;
}
 
开发者ID:PacktPublishing,项目名称:Mastering-Mesos,代码行数:18,代码来源:MesosUtilsTest.java

示例2: testLiteralHostPortSelection

import org.apache.mesos.Protos.Resource; //导入依赖的package包/类
@Test
public void testLiteralHostPortSelection() {
  String[] rangesNotOverlappingRequestedPorts = {"23:24", "25:25", "31:32", "50:51"};
  int numPorts = 1;
  List<Long> requestedPorts = Arrays.asList(50L, 51L);
  Resource resource = MesosUtils.getPortsResource(numPorts, buildOffer(rangesNotOverlappingRequestedPorts).getResourcesList(), requestedPorts);
  Assert.assertTrue(MesosUtils.getAllPorts(Collections.singletonList(resource)).containsAll(requestedPorts));
  Assert.assertEquals(numPorts + requestedPorts.size(), MesosUtils.getNumPorts(Collections.singletonList(resource)));

  String[] rangesOverlappingRequestPorts = {"23:28"};
  numPorts = 4;
  requestedPorts = Arrays.asList(25L, 27L);
  resource = MesosUtils.getPortsResource(numPorts, buildOffer(rangesOverlappingRequestPorts).getResourcesList(), requestedPorts);
  Assert.assertTrue(MesosUtils.getAllPorts(Collections.singletonList(resource)).containsAll(requestedPorts));
  Assert.assertEquals(numPorts + requestedPorts.size(), MesosUtils.getNumPorts(Collections.singletonList(resource)));
}
 
开发者ID:PacktPublishing,项目名称:Mastering-Mesos,代码行数:17,代码来源:MesosUtilsTest.java

示例3: buildPortRanges

import org.apache.mesos.Protos.Resource; //导入依赖的package包/类
public static Resource buildPortRanges(String... ranges) {
  Resource.Builder resources = Resource.newBuilder()
      .setType(Type.RANGES)
      .setName(MesosUtils.PORTS);

  Ranges.Builder rangesBuilder = Ranges.newBuilder();

  for (String range : ranges) {
    String[] split = range.split("\\:");

    rangesBuilder.addRange(
        Range.newBuilder()
        .setBegin(Long.parseLong(split[0]))
        .setEnd(Long.parseLong(split[1])));
  }

  resources.setRanges(rangesBuilder);

  return resources.build();
}
 
开发者ID:PacktPublishing,项目名称:Mastering-Mesos,代码行数:21,代码来源:MesosUtilsTest.java

示例4: doesOfferMatchResources

import org.apache.mesos.Protos.Resource; //导入依赖的package包/类
public static boolean doesOfferMatchResources(Resources resources, List<Resource> offerResources, List<Long> otherRequestedPorts) {
  double numCpus = getNumCpus(offerResources);

  if (numCpus < resources.getCpus()) {
    return false;
  }

  double memory = getMemory(offerResources);

  if (memory < resources.getMemoryMb()) {
    return false;
  }

  int numPorts = getNumPorts(offerResources);

  if (numPorts < resources.getNumPorts()) {
    return false;
  }

  if (!getAllPorts(offerResources).containsAll(otherRequestedPorts)) {
    return false;
  }

  return true;
}
 
开发者ID:PacktPublishing,项目名称:Mastering-Mesos,代码行数:26,代码来源:MesosUtils.java

示例5: getReservedResource

import org.apache.mesos.Protos.Resource; //导入依赖的package包/类
/**
 * The resource passed in is the fully completed Resource which will be launched.  This may include volume/disk
 * information which is not appropriate for the RESERVE operation.  It is filtered out here.
 */
private static Resource getReservedResource(Resource resource) {
    // The resource passed in is the fully completed Resource which will be launched.  This may include volume/disk
    // information which is not appropriate for the RESERVE operation.  It is filtered out here.
    Resource.Builder resBuilder = Resource.newBuilder(resource);
    if (resBuilder.hasDisk() && resBuilder.getDisk().hasSource()) {
        // Mount volume: Copy disk, but without 'persistence' nor 'volume' fields
        resBuilder.setDisk(DiskInfo.newBuilder(resBuilder.getDisk())
                .clearPersistence()
                .clearVolume());
    } else {
        // Root volume: Clear the disk.
        resBuilder.clearDisk();
    }
    resBuilder.clearRevocable();
    return resBuilder.build();
}
 
开发者ID:mesosphere,项目名称:dcos-commons,代码行数:21,代码来源:ReserveOfferRecommendation.java

示例6: UnreserveOfferRecommendation

import org.apache.mesos.Protos.Resource; //导入依赖的package包/类
public UnreserveOfferRecommendation(Offer offer, Resource resource) {
    this.offer = offer;
    Resource.Builder resourceBuilder = resource.toBuilder();

    // If non-root disk resource, we want to clear ALL fields except for the field indicating the disk source.
    if (resource.hasDisk() && resource.getDisk().hasSource()) {
        resource = resourceBuilder.setDisk(
                Resource.DiskInfo.newBuilder()
                        .setSource(resource.getDisk().getSource()))
                .build();
    } else {
        resource = resourceBuilder.clearDisk().clearRevocable().build();
    }

    this.operation = Operation.newBuilder()
            .setType(Operation.Type.UNRESERVE)
            .setUnreserve(Operation.Unreserve.newBuilder()
                    .addAllResources(Arrays.asList(resource)))
            .build();
    this.resource = resource;
}
 
开发者ID:mesosphere,项目名称:dcos-commons,代码行数:22,代码来源:UnreserveOfferRecommendation.java

示例7: getUnreservedResource

import org.apache.mesos.Protos.Resource; //导入依赖的package包/类
@SuppressWarnings("deprecation") // for Resource.setRole()
private static Protos.Resource getUnreservedResource(String name, Protos.Value value, String role) {
    Protos.Resource.Builder resBuilder = Protos.Resource.newBuilder()
            .setName(name)
            .setType(value.getType())
            .setRole(role);
    if (!role.equals(Constants.ANY_ROLE)) {
        // Fill in the prereserved role info:
        resBuilder.addReservationsBuilder()
                .setRole(role)
                .setPrincipal(TestConstants.PRINCIPAL);
    }
    switch (value.getType()) {
        case SCALAR:
            return resBuilder.setScalar(value.getScalar()).build();
        case RANGES:
            return resBuilder.setRanges(value.getRanges()).build();
        case SET:
            return resBuilder.setSet(value.getSet()).build();
        default:
            return null;
    }
}
 
开发者ID:mesosphere,项目名称:dcos-commons,代码行数:24,代码来源:ResourceTestUtils.java

示例8: testConsumeMultipleMountVolumesFailure

import org.apache.mesos.Protos.Resource; //导入依赖的package包/类
@Test
public void testConsumeMultipleMountVolumesFailure() throws Exception {
    Resource offeredResource = ResourceTestUtils.getUnreservedMountVolume(2000);
    ResourceSet volumeResourceSet = DefaultResourceSet.newBuilder(TestConstants.ROLE, Constants.ANY_ROLE, TestConstants.PRINCIPAL)
            .id(TestConstants.RESOURCE_SET_ID)
            .cpus(1.0)
            .addVolume(VolumeSpec.Type.MOUNT.name(), 1000.0, TestConstants.CONTAINER_PATH + "-A")
            .addVolume(VolumeSpec.Type.MOUNT.name(), 1000.0, TestConstants.CONTAINER_PATH + "-B")
            .build();
    PodInstanceRequirement podInstanceRequirement =
            PodInstanceRequirementTestUtils.getRequirement(volumeResourceSet, 0);
    Protos.Offer offer = OfferTestUtils.getCompleteOffer(Arrays.asList(offeredResource));

    List<OfferRecommendation> recommendations = evaluator.evaluate(podInstanceRequirement, Arrays.asList(offer));
    Assert.assertEquals(0, recommendations.size());
}
 
开发者ID:mesosphere,项目名称:dcos-commons,代码行数:17,代码来源:OfferEvaluatorVolumesTest.java

示例9: testAllocateRange

import org.apache.mesos.Protos.Resource; //导入依赖的package包/类
@Test
public void testAllocateRange() {
  List<Resource> resources = ImmutableList.<Resource>builder()
      .add(makePortResource(Optional.absent(), 80, 81, 90, 91, 92, 93))
      .add(makePortResource(TEST_ROLE, 100, 101))
      .build();
  AcceptedOffer acceptedOffer = AcceptedOffer.create(
      fakeOffer(resources),
      ResourceSlot.NONE,
      ResourceSlot.NONE,
      ImmutableSet.of(80, 90, 100),
      TaskTestUtil.DEV_TIER);

  List<Resource> expected = ImmutableList.<Resource>builder()
      // Because we prefer reserved resources and handle them before non-reserved resources,
      // result should have ports for the reserved resources first.
      .add(makePortResource(TEST_ROLE, 100))
      .add(makePortResource(Optional.absent(), 80, 90))
      .build();
  assertEquals(expected, acceptedOffer.getTaskResources());
  assertEquals(Collections.emptyList(), acceptedOffer.getExecutorResources());
}
 
开发者ID:PacktPublishing,项目名称:Mastering-Mesos,代码行数:23,代码来源:AcceptedOfferTest.java

示例10: testAllocateSingleRoleInsufficient

import org.apache.mesos.Protos.Resource; //导入依赖的package包/类
@Test(expected = Resources.InsufficientResourcesException.class)
public void testAllocateSingleRoleInsufficient() {
  List<Resource> resources = ImmutableList.<Resource>builder()
      // EXECUTOR_SLOT's CPU is not included here.
      .add(makeScalar(CPUS.getMesosName(), TEST_ROLE, false, TASK_SLOT.getNumCpus()))
      .add(makeScalar(
          RAM_MB.getMesosName(), TEST_ROLE, false, TOTAL_SLOT.getRam().as(Data.MB)))
      .add(makeScalar(
          DISK_MB.getMesosName(), TEST_ROLE, false, TOTAL_SLOT.getDisk().as(Data.MB)))
      .add(makePortResource(TEST_ROLE, TASK_PORTS))
      .build();
  Protos.Offer offer = fakeOffer(resources);

  AcceptedOffer.create(
      offer, TASK_SLOT, EXECUTOR_SLOT, TASK_PORTS_SET, new TierInfo(false, false));
}
 
开发者ID:PacktPublishing,项目名称:Mastering-Mesos,代码行数:17,代码来源:AcceptedOfferTest.java

示例11: recordLaunchWithOfferedResources

import org.apache.mesos.Protos.Resource; //导入依赖的package包/类
private List<Resource> recordLaunchWithOfferedResources(
        Protos.Offer offer, PodInstanceRequirement podInstanceRequirement, Resource... offeredResources)
        throws InvalidRequirementException, IOException {
    List<OfferRecommendation> recommendations = evaluator.evaluate(
            podInstanceRequirement, Arrays.asList(offer));

    List<Resource> reservedResources = new ArrayList<>();
    for (OfferRecommendation recommendation : recommendations) {
        if (recommendation instanceof ReserveOfferRecommendation) {
            reservedResources.addAll(recommendation.getOperation().getReserve().getResourcesList());
        } else if (recommendation instanceof LaunchOfferRecommendation) {
            // DO NOT extract the TaskInfo from the Launch Operation. That version has a packed CommandInfo.
            stateStore.storeTasks(Arrays.asList(
                    ((LaunchOfferRecommendation) recommendation).getStoreableTaskInfo()));
        }
    }

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

示例12: testReserveTaskDynamicPort

import org.apache.mesos.Protos.Resource; //导入依赖的package包/类
@Test
public void testReserveTaskDynamicPort() throws Exception {
    Protos.Resource offeredPorts = ResourceTestUtils.getUnreservedPorts(10000, 10000);
    PodInstanceRequirement podInstanceRequirement = PodInstanceRequirementTestUtils.getPortRequirement(0);

    List<OfferRecommendation> recommendations =
            evaluator.evaluate(podInstanceRequirement, OfferTestUtils.getCompleteOffers(offeredPorts));

    Assert.assertEquals(5, recommendations.size());

    Protos.Offer.Operation launchOperation = recommendations.get(4).getOperation();
    Protos.TaskInfo taskInfo = launchOperation.getLaunchGroup().getTaskGroup().getTasks(0);
    Protos.Resource fulfilledPortResource = taskInfo.getResources(0);
    Assert.assertFalse(getResourceId(fulfilledPortResource).isEmpty());

    Map<String, String> envvars = EnvUtils.toMap(
            TaskPackingUtils.unpack(taskInfo).getCommand().getEnvironment());
    Assert.assertEquals(envvars.toString(),
            String.valueOf(10000), envvars.get(TestConstants.PORT_ENV_NAME + "_0"));
}
 
开发者ID:mesosphere,项目名称:dcos-commons,代码行数:21,代码来源:OfferEvaluatorPortsTest.java

示例13: testLaunchTransient

import org.apache.mesos.Protos.Resource; //导入依赖的package包/类
@Test
public void testLaunchTransient() {
    Resource resource = ResourceTestUtils.getUnreservedCpus(1.0);
    Offer offer = OfferTestUtils.getCompleteOffer(resource);
    TaskInfo.Builder taskInfoBuilder = TaskTestUtils.getTaskInfo(resource).toBuilder();
    taskInfoBuilder.setLabels(new TaskLabelWriter(taskInfoBuilder).setTransient().toProto());

    TestOperationRecorder recorder = new TestOperationRecorder();
    OfferAccepter accepter = new OfferAccepter(Arrays.asList(recorder));
    accepter.accept(
            driver,
            Arrays.asList(new LaunchOfferRecommendation(
                    offer,
                    taskInfoBuilder.build(),
                    Protos.ExecutorInfo.newBuilder().setExecutorId(TestConstants.EXECUTOR_ID).build(),
                    false,
                    true)));
    Assert.assertEquals(1, recorder.getLaunches().size());
    verify(driver, times(0)).acceptOffers(
            anyCollectionOf(OfferID.class),
            anyCollectionOf(Operation.class),
            anyObject());
}
 
开发者ID:mesosphere,项目名称:dcos-commons,代码行数:24,代码来源:OfferAccepterTest.java

示例14: setValue

import org.apache.mesos.Protos.Resource; //导入依赖的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

示例15: consumeReservableMerged

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