ResourceDimensions { public static ResourceDimension alignUp(ResourceDimension source, ResourceDimension reference) { double cpuRatio = source.getCpu() / reference.getCpu(); double memoryRatio = source.getMemoryMB() / reference.getMemoryMB(); if (cpuRatio == memoryRatio) { return source; } if (cpuRatio > memoryRatio) { return ResourceDimension.newBuilder() .withCpus(source.getCpu()) .withMemoryMB((long) (reference.getMemoryMB() * cpuRatio)) .withDiskMB((long) (reference.getDiskMB() * cpuRatio)) .withNetworkMbs((long) (reference.getNetworkMbs() * cpuRatio)) .withGpu((long) (reference.getGpu() * cpuRatio)) .withOpportunisticCpus((long) (reference.getOpportunisticCpu() * cpuRatio)) .build(); } return ResourceDimension.newBuilder() .withCpus(reference.getCpu() * memoryRatio) .withMemoryMB(source.getMemoryMB()) .withDiskMB((long) (reference.getDiskMB() * memoryRatio)) .withNetworkMbs((long) (reference.getNetworkMbs() * memoryRatio)) .withGpu((long) (reference.getGpu() * memoryRatio)) .withOpportunisticCpus((long) (reference.getOpportunisticCpu() * memoryRatio)) .build(); }  static ResourceDimension add(ResourceDimension... parts); static ResourceDimension add(Collection<ResourceDimension> parts); static ResourceDimension subtractPositive(ResourceDimension left, ResourceDimension right); static ResourceDimension multiply(ResourceDimension base, double multiplier); static Pair<Long, ResourceDimension> divide(ResourceDimension left, ResourceDimension right); static long divideAndRoundUp(ResourceDimension left, ResourceDimension right); static ResourceDimension alignUp(ResourceDimension source, ResourceDimension reference); static boolean isBigger(ResourceDimension dimension, ResourceDimension subDimension); static StringBuilder format(ResourceDimension input, StringBuilder output); static String format(ResourceDimension input); static ResourceDimension fromServerInfo(ServerInfo serverInfo); static ResourceDimension fromAwsInstanceType(AwsInstanceType instanceType); static ResAllocs toResAllocs(String name, ResourceDimension resourceDimension); static ResourceDimension fromResAllocs(ResAllocs resAllocs);  }
@Test public void testAligningUpToHigherCPU() throws Exception { ResourceDimension small2X = ResourceDimensionSample.SmallWithGpuAndOpportunisticX2.build(); ResourceDimension original = ResourceDimensionSample.SmallWithGpuAndOpportunistic.builder().withCpus(small2X.getCpu()).build(); assertThat(ResourceDimensions.alignUp(original, small2X)).isEqualTo(small2X); }
@Test public void testAligningUpToHigherMemory() throws Exception { ResourceDimension small2X = ResourceDimensionSample.SmallWithGpuAndOpportunisticX2.build(); ResourceDimension original = ResourceDimensionSample.SmallWithGpuAndOpportunistic.builder().withMemoryMB(small2X.getMemoryMB()).build(); assertThat(ResourceDimensions.alignUp(original, small2X)).isEqualTo(small2X); }