AcceptedOffer { public static AcceptedOffer create( Offer offer, ResourceSlot taskSlot, ResourceSlot executorSlot, Set<Integer> selectedPorts, TierInfo tierInfo) throws Resources.InsufficientResourcesException { List<Resource> reservedFirst = ImmutableList.<Resource>builder() .addAll(Iterables.filter(offer.getResourcesList(), RESERVED)) .addAll(Iterables.filter(offer.getResourcesList(), NOT_RESERVED)) .build(); boolean revocable = tierInfo.isRevocable(); List<Resource.Builder> cpuResources = filterToBuilders( reservedFirst, ResourceType.CPUS.getMesosName(), revocable ? Resources.REVOCABLE : Resources.NON_REVOCABLE); List<Resource.Builder> memResources = filterToBuilderNonRevocable( reservedFirst, ResourceType.RAM_MB.getMesosName()); List<Resource.Builder> diskResources = filterToBuilderNonRevocable( reservedFirst, ResourceType.DISK_MB.getMesosName()); List<Resource.Builder> portsResources = filterToBuilderNonRevocable( reservedFirst, ResourceType.PORTS.getMesosName()); List<Resource> taskResources = ImmutableList.<Resource>builder() .addAll(allocateScalarType(cpuResources, taskSlot.getNumCpus(), revocable)) .addAll(allocateScalarType(memResources, taskSlot.getRam().as(Data.MB), false)) .addAll(allocateScalarType(diskResources, taskSlot.getDisk().as(Data.MB), false)) .addAll(allocateRangeType(portsResources, selectedPorts)) .build(); List<Resource> executorResources = ImmutableList.<Resource>builder() .addAll(allocateScalarType(cpuResources, executorSlot.getNumCpus(), revocable)) .addAll(allocateScalarType(memResources, executorSlot.getRam().as(Data.MB), false)) .addAll(allocateScalarType(diskResources, executorSlot.getDisk().as(Data.MB), false)) .build(); return new AcceptedOffer(taskResources, executorResources); } private  AcceptedOffer(
      List<Resource> taskResources,
      List<Resource> executorResources); static boolean nearZero(double value); List<Resource> getTaskResources(); List<Resource> getExecutorResources(); static AcceptedOffer create(
      Offer offer,
      ResourceSlot taskSlot,
      ResourceSlot executorSlot,
      Set<Integer> selectedPorts,
      TierInfo tierInfo); static final String DEFAULT_ROLE_NAME; static final Predicate<Resource> RESERVED; static final Predicate<Resource> NOT_RESERVED; }
@Test(expected = Resources.InsufficientResourcesException.class) public void testAllocateRangeInsufficent() { List<Resource> resources = ImmutableList.of( makePortResource(ABSENT_ROLE, 80), makePortResource(ABSENT_ROLE, 100, 101)); AcceptedOffer.create( fakeOffer(resources), ResourceSlot.NONE, ResourceSlot.NONE, ImmutableSet.of(80, 90, 100), TaskTestUtil.DEV_TIER); }
@Test(expected = Resources.InsufficientResourcesException.class) public void testAllocateSingleRoleInsufficient() { List<Resource> resources = ImmutableList.<Resource>builder() .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)); }
@Test(expected = Resources.InsufficientResourcesException.class) public void testMultipleRolesInsufficient() { List<Resource> resources = ImmutableList.<Resource>builder() .add(makeScalar( CPUS.getMesosName(), TEST_ROLE, true, EXECUTOR_SLOT.getNumCpus())) .add(makeScalar( CPUS.getMesosName(), ABSENT_ROLE, false, TASK_SLOT.getNumCpus())) .add(makeScalar( RAM_MB.getMesosName(), ABSENT_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, 80)) .add(makePortResource(ABSENT_ROLE, 90)) .build(); Protos.Offer offer = fakeOffer(resources); AcceptedOffer.create( offer, TASK_SLOT, EXECUTOR_SLOT, TASK_PORTS_SET, new TierInfo(false, false)); }