ResourceSlot { @VisibleForTesting static ResourceSlot maxElements(ResourceSlot a, ResourceSlot b) { double maxCPU = Math.max(a.getNumCpus(), b.getNumCpus()); Amount<Long, Data> maxRAM = Amount.of( Math.max(a.getRam().as(Data.MB), b.getRam().as(Data.MB)), Data.MB); Amount<Long, Data> maxDisk = Amount.of( Math.max(a.getDisk().as(Data.MB), b.getDisk().as(Data.MB)), Data.MB); int maxPorts = Math.max(a.getNumPorts(), b.getNumPorts()); return new ResourceSlot(maxCPU, maxRAM, maxDisk, maxPorts); } ResourceSlot(
      double numCpus,
      Amount<Long, Data> ram,
      Amount<Long, Data> disk,
      int numPorts); static ResourceSlot from(ITaskConfig task); static TaskInfo matchResourceTypes(TaskInfo task); List<Protos.Resource> toResourceList(TierInfo tierInfo); @VisibleForTesting static Protos.Resource makeMesosRangeResource(
      ResourceType resourceType,
      Set<Integer> values); double getNumCpus(); Amount<Long, Data> getDisk(); Amount<Long, Data> getRam(); int getNumPorts(); @Override boolean equals(Object o); @Override int hashCode(); static ResourceSlot sum(Iterable<ResourceSlot> slots); ResourceSlot add(ResourceSlot other); ResourceSlot subtract(ResourceSlot other); static final ResourceSlot NONE; static final Function<Range<Integer>, Protos.Value.Range> RANGE_TRANSFORM; static final Ordering<ResourceSlot> ORDER; }
@Test public void testMaxElements() { ResourceSlot highRAM = new ResourceSlot(1, Amount.of(8L, Data.GB), Amount.of(10L, Data.MB), 0); ResourceSlot rest = new ResourceSlot(10, Amount.of(1L, Data.MB), Amount.of(10L, Data.GB), 1); ResourceSlot result = ResourceSlot.maxElements(highRAM, rest); assertEquals(result.getNumCpus(), 10, 0.001); assertEquals(result.getRam(), Amount.of(8L, Data.GB)); assertEquals(result.getDisk(), Amount.of(10L, Data.GB)); assertEquals(result.getNumPorts(), 1); }