@Test public void testMerge() throws Exception { ResourceProfile rp1 = new ResourceProfile(1.0, 100, 100, 100, 100, 100, Collections.emptyMap()); ResourceProfile rp2 = new ResourceProfile(2.0, 200, 200, 200, 200, 200, Collections.singletonMap("gpu", new GPUResource(2.0))); ResourceProfile rp1MergeRp1 = new ResourceProfile(2.0, 200, 200, 200, 200, 200, Collections.emptyMap()); ResourceProfile rp1MergeRp2 = new ResourceProfile(3.0, 300, 300, 300, 300, 300, Collections.singletonMap("gpu", new GPUResource(2.0))); ResourceProfile rp2MergeRp2 = new ResourceProfile(4.0, 400, 400, 400, 400, 400, Collections.singletonMap("gpu", new GPUResource(4.0))); assertEquals(rp1MergeRp1, rp1.merge(rp1)); assertEquals(rp1MergeRp2, rp1.merge(rp2)); assertEquals(rp1MergeRp2, rp2.merge(rp1)); assertEquals(rp2MergeRp2, rp2.merge(rp2)); assertEquals(ResourceProfile.UNKNOWN, rp1.merge(ResourceProfile.UNKNOWN)); assertEquals(ResourceProfile.UNKNOWN, ResourceProfile.UNKNOWN.merge(rp1)); assertEquals(ResourceProfile.UNKNOWN, ResourceProfile.UNKNOWN.merge(ResourceProfile.UNKNOWN)); assertEquals(ResourceProfile.ANY, rp1.merge(ResourceProfile.ANY)); assertEquals(ResourceProfile.ANY, ResourceProfile.ANY.merge(rp1)); assertEquals(ResourceProfile.ANY, ResourceProfile.ANY.merge(ResourceProfile.ANY)); }
@Nonnull public ResourceProfile merge(@Nonnull ResourceProfile other) { if (equals(ANY) || other.equals(ANY)) { return ANY; } if (this.equals(UNKNOWN) || other.equals(UNKNOWN)) { return UNKNOWN; } Map<String, Resource> resultExtendedResource = new HashMap<>(extendedResources); other.extendedResources.forEach((String name, Resource resource) -> { resultExtendedResource.compute(name, (ignored, oldResource) -> oldResource == null ? resource : oldResource.merge(resource)); }); return new ResourceProfile( addNonNegativeDoublesConsideringOverflow(cpuCores, other.cpuCores), addNonNegativeIntegersConsideringOverflow(heapMemoryInMB, other.heapMemoryInMB), addNonNegativeIntegersConsideringOverflow(directMemoryInMB, other.directMemoryInMB), addNonNegativeIntegersConsideringOverflow(nativeMemoryInMB, other.nativeMemoryInMB), addNonNegativeIntegersConsideringOverflow(networkMemoryInMB, other.networkMemoryInMB), addNonNegativeIntegersConsideringOverflow(managedMemoryInMB, other.managedMemoryInMB), resultExtendedResource); }
ResourceProfile implements Serializable, Comparable<ResourceProfile> { @Nonnull public ResourceProfile merge(@Nonnull ResourceProfile other) { if (equals(ANY) || other.equals(ANY)) { return ANY; } if (this.equals(UNKNOWN) || other.equals(UNKNOWN)) { return UNKNOWN; } Map<String, Resource> resultExtendedResource = new HashMap<>(extendedResources); other.extendedResources.forEach((String name, Resource resource) -> { resultExtendedResource.compute(name, (ignored, oldResource) -> oldResource == null ? resource : oldResource.merge(resource)); }); return new ResourceProfile( addNonNegativeDoublesConsideringOverflow(cpuCores, other.cpuCores), addNonNegativeIntegersConsideringOverflow(heapMemoryInMB, other.heapMemoryInMB), addNonNegativeIntegersConsideringOverflow(directMemoryInMB, other.directMemoryInMB), addNonNegativeIntegersConsideringOverflow(nativeMemoryInMB, other.nativeMemoryInMB), addNonNegativeIntegersConsideringOverflow(networkMemoryInMB, other.networkMemoryInMB), addNonNegativeIntegersConsideringOverflow(managedMemoryInMB, other.managedMemoryInMB), resultExtendedResource); } }
ResourceProfile implements Serializable, Comparable<ResourceProfile> { @Nonnull public ResourceProfile merge(@Nonnull ResourceProfile other) { if (equals(ANY) || other.equals(ANY)) { return ANY; } if (this.equals(UNKNOWN) || other.equals(UNKNOWN)) { return UNKNOWN; } Map<String, Resource> resultExtendedResource = new HashMap<>(extendedResources); other.extendedResources.forEach((String name, Resource resource) -> { resultExtendedResource.compute(name, (ignored, oldResource) -> oldResource == null ? resource : oldResource.merge(resource)); }); return new ResourceProfile( addNonNegativeDoublesConsideringOverflow(cpuCores, other.cpuCores), addNonNegativeIntegersConsideringOverflow(heapMemoryInMB, other.heapMemoryInMB), addNonNegativeIntegersConsideringOverflow(directMemoryInMB, other.directMemoryInMB), addNonNegativeIntegersConsideringOverflow(nativeMemoryInMB, other.nativeMemoryInMB), addNonNegativeIntegersConsideringOverflow(networkMemoryInMB, other.networkMemoryInMB), addNonNegativeIntegersConsideringOverflow(managedMemoryInMB, other.managedMemoryInMB), resultExtendedResource); } ResourceProfile(
			double cpuCores,
			int heapMemoryInMB,
			int directMemoryInMB,
			int nativeMemoryInMB,
			int networkMemoryInMB,
			int managedMemoryInMB,
			Map<String, Resource> extendedResources);  ResourceProfile(double cpuCores, int heapMemoryInMB); private  ResourceProfile();  ResourceProfile(ResourceProfile other); }
ResourceProfile implements Serializable, Comparable<ResourceProfile> { @Nonnull public ResourceProfile merge(@Nonnull ResourceProfile other) { if (equals(ANY) || other.equals(ANY)) { return ANY; } if (this.equals(UNKNOWN) || other.equals(UNKNOWN)) { return UNKNOWN; } Map<String, Resource> resultExtendedResource = new HashMap<>(extendedResources); other.extendedResources.forEach((String name, Resource resource) -> { resultExtendedResource.compute(name, (ignored, oldResource) -> oldResource == null ? resource : oldResource.merge(resource)); }); return new ResourceProfile( addNonNegativeDoublesConsideringOverflow(cpuCores, other.cpuCores), addNonNegativeIntegersConsideringOverflow(heapMemoryInMB, other.heapMemoryInMB), addNonNegativeIntegersConsideringOverflow(directMemoryInMB, other.directMemoryInMB), addNonNegativeIntegersConsideringOverflow(nativeMemoryInMB, other.nativeMemoryInMB), addNonNegativeIntegersConsideringOverflow(networkMemoryInMB, other.networkMemoryInMB), addNonNegativeIntegersConsideringOverflow(managedMemoryInMB, other.managedMemoryInMB), resultExtendedResource); } ResourceProfile(
			double cpuCores,
			int heapMemoryInMB,
			int directMemoryInMB,
			int nativeMemoryInMB,
			int networkMemoryInMB,
			int managedMemoryInMB,
			Map<String, Resource> extendedResources);  ResourceProfile(double cpuCores, int heapMemoryInMB); private  ResourceProfile();  ResourceProfile(ResourceProfile other); double getCpuCores(); int getHeapMemoryInMB(); int getDirectMemoryInMB(); int getNativeMemoryInMB(); int getNetworkMemoryInMB(); int getManagedMemoryInMB(); int getMemoryInMB(); int getOperatorsMemoryInMB(); Map<String, Resource> getExtendedResources(); boolean isMatching(ResourceProfile required); @Override int compareTo(@Nonnull ResourceProfile other); @Override int hashCode(); @Override boolean equals(Object obj); @Nonnull ResourceProfile merge(@Nonnull ResourceProfile other); ResourceProfile subtract(ResourceProfile other); @Override String toString(); static ResourceProfile fromResourceSpec(ResourceSpec resourceSpec, int networkMemory); }
ResourceProfile implements Serializable, Comparable<ResourceProfile> { @Nonnull public ResourceProfile merge(@Nonnull ResourceProfile other) { if (equals(ANY) || other.equals(ANY)) { return ANY; } if (this.equals(UNKNOWN) || other.equals(UNKNOWN)) { return UNKNOWN; } Map<String, Resource> resultExtendedResource = new HashMap<>(extendedResources); other.extendedResources.forEach((String name, Resource resource) -> { resultExtendedResource.compute(name, (ignored, oldResource) -> oldResource == null ? resource : oldResource.merge(resource)); }); return new ResourceProfile( addNonNegativeDoublesConsideringOverflow(cpuCores, other.cpuCores), addNonNegativeIntegersConsideringOverflow(heapMemoryInMB, other.heapMemoryInMB), addNonNegativeIntegersConsideringOverflow(directMemoryInMB, other.directMemoryInMB), addNonNegativeIntegersConsideringOverflow(nativeMemoryInMB, other.nativeMemoryInMB), addNonNegativeIntegersConsideringOverflow(networkMemoryInMB, other.networkMemoryInMB), addNonNegativeIntegersConsideringOverflow(managedMemoryInMB, other.managedMemoryInMB), resultExtendedResource); } ResourceProfile(
			double cpuCores,
			int heapMemoryInMB,
			int directMemoryInMB,
			int nativeMemoryInMB,
			int networkMemoryInMB,
			int managedMemoryInMB,
			Map<String, Resource> extendedResources);  ResourceProfile(double cpuCores, int heapMemoryInMB); private  ResourceProfile();  ResourceProfile(ResourceProfile other); double getCpuCores(); int getHeapMemoryInMB(); int getDirectMemoryInMB(); int getNativeMemoryInMB(); int getNetworkMemoryInMB(); int getManagedMemoryInMB(); int getMemoryInMB(); int getOperatorsMemoryInMB(); Map<String, Resource> getExtendedResources(); boolean isMatching(ResourceProfile required); @Override int compareTo(@Nonnull ResourceProfile other); @Override int hashCode(); @Override boolean equals(Object obj); @Nonnull ResourceProfile merge(@Nonnull ResourceProfile other); ResourceProfile subtract(ResourceProfile other); @Override String toString(); static ResourceProfile fromResourceSpec(ResourceSpec resourceSpec, int networkMemory); static final ResourceProfile UNKNOWN; static final ResourceProfile ANY; static final ResourceProfile ZERO; }