public double getTotalCpu() { return this.normalizedResources.getTotalCpu(); }
public double getTotalCpu() { return normalizedResources.getTotalCpu(); }
skippedResourceTypes++; double totalCpu = getTotalCpu(); if (used.getTotalCpu() > getTotalCpu()) { throwBecauseUsedIsNotSubsetOfTotal(used, totalMemoryMb, usedMemoryMb); total += used.getTotalCpu() / getTotalCpu(); } else { skippedResourceTypes++;
/** * A simple sanity check to see if all of the resources in this would be large enough to hold the resources in other ignoring memory. It * does not check memory because with shared memory it is beyond the scope of this. * * @param other the resources that we want to check if they would fit in this. * @param thisTotalMemoryMb The total memory in MB of this * @param otherTotalMemoryMb The total memory in MB of other * @return true if it might fit, else false if it could not possibly fit. */ public boolean couldHoldIgnoringSharedMemory(NormalizedResources other, double thisTotalMemoryMb, double otherTotalMemoryMb) { if (this.cpu < other.getTotalCpu()) { return false; } int length = Math.max(this.otherResources.length, other.otherResources.length); for (int i = 0; i < length; i++) { if (getResourceAt(i) < other.getResourceAt(i)) { return false; } } return thisTotalMemoryMb >= otherTotalMemoryMb; }
min = Math.min(min, usedMemoryMb / totalMemoryMb); double totalCpu = getTotalCpu(); if (used.getTotalCpu() > totalCpu) { throwBecauseUsedIsNotSubsetOfTotal(used, totalMemoryMb, usedMemoryMb); min = Math.min(min, used.getTotalCpu() / totalCpu);
@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)); }
@Test public void testRemoveFromCpu() { NormalizedResources resources = new NormalizedResources(normalize(Collections.singletonMap(Constants.COMMON_CPU_RESOURCE_NAME, 2))); NormalizedResources removedResources = new NormalizedResources(normalize(Collections.singletonMap(Constants.COMMON_CPU_RESOURCE_NAME, 1))); resources.remove(removedResources, new ResourceMetrics(new StormMetricsRegistry())); Map<String, Double> normalizedMap = resources.toNormalizedMap(); assertThat(normalizedMap.get(Constants.COMMON_CPU_RESOURCE_NAME), is(1.0)); assertThat(resources.getTotalCpu(), is(1.0)); }
@Test public void testRemoveZeroesWhenCpuBecomesNegative() { NormalizedResources resources = new NormalizedResources(normalize(Collections.singletonMap(Constants.COMMON_CPU_RESOURCE_NAME, 1))); NormalizedResources removedResources = new NormalizedResources(normalize(Collections.singletonMap(Constants.COMMON_CPU_RESOURCE_NAME, 2))); resources.remove(removedResources, new ResourceMetrics(new StormMetricsRegistry())); assertThat(resources.getTotalCpu(), is(0.0)); }