/** * Add the resources in other to this. * * @param other the other Request to add to this. */ public void add(NormalizedResourceRequest other) { this.normalizedResources.add(other.normalizedResources); onHeap += other.onHeap; offHeap += other.offHeap; }
public void add(NormalizedResources other) { this.cpu += other.cpu; add(other.otherResources); }
/** * Add the resources from a worker to those in this. * @param value the resources on the worker. */ public void add(WorkerResources value) { this.normalizedResources.add(value); //The resources are already normalized Map<String, Double> resources = value.get_resources(); onHeap += resources.getOrDefault(Constants.COMMON_ONHEAP_MEMORY_RESOURCE_NAME, 0.0); offHeap += resources.getOrDefault(Constants.COMMON_OFFHEAP_MEMORY_RESOURCE_NAME, 0.0); }
/** * Add the resources from a worker to this. * * @param value the worker resources that should be added to this. */ public void add(WorkerResources value) { Map<String, Double> workerNormalizedResources = value.get_resources(); cpu += workerNormalizedResources.getOrDefault(Constants.COMMON_CPU_RESOURCE_NAME, 0.0); add(RESOURCE_MAP_ARRAY_BRIDGE.translateToResourceArray(workerNormalizedResources)); }
public void add(NormalizedResourcesWithMemory other) { normalizedResources.add(other.getNormalizedResources()); totalMemoryMb += other.getTotalMemoryMb(); }
@Test public void testAddWhenOtherHasDifferentResourceThanThis() { String disks = "disks"; NormalizedResources resources = new NormalizedResources(normalize(Collections.singletonMap(disks, 23))); NormalizedResources addedResources = new NormalizedResources(normalize(Collections.singletonMap(gpuResourceName, 1))); resources.add(addedResources); Map<String, Double> normalizedMap = resources.toNormalizedMap(); assertThat(normalizedMap.get(disks), is(23.0)); assertThat(normalizedMap.get(gpuResourceName), is(1.0)); }
@Test public void testAddToExistingResource() { NormalizedResources resources = new NormalizedResources(normalize(Collections.singletonMap(gpuResourceName, 1))); NormalizedResources addedResources = new NormalizedResources(normalize(Collections.singletonMap(gpuResourceName, 1))); resources.add(addedResources); Map<String, Double> normalizedMap = resources.toNormalizedMap(); assertThat(normalizedMap.get(gpuResourceName), is(2.0)); }
@Test public void testAddWhenOtherHasMoreResourcesThanThis() { NormalizedResources resources = new NormalizedResources(normalize(Collections.emptyMap())); NormalizedResources addedResources = new NormalizedResources(normalize(Collections.singletonMap(gpuResourceName, 1))); resources.add(addedResources); Map<String, Double> normalizedMap = resources.toNormalizedMap(); assertThat(normalizedMap.get(gpuResourceName), is(1.0)); }
@Test public void testAddCpu() { NormalizedResources resources = new NormalizedResources(normalize(Collections.singletonMap(Constants.COMMON_CPU_RESOURCE_NAME, 1))); NormalizedResources addedResources = new NormalizedResources(normalize(Collections.singletonMap(Constants.COMMON_CPU_RESOURCE_NAME, 1))); resources.add(addedResources); Map<String, Double> normalizedMap = resources.toNormalizedMap(); assertThat(normalizedMap.get(Constants.COMMON_CPU_RESOURCE_NAME), is(2.0)); assertThat(resources.getTotalCpu(), is(2.0)); }