YARN-4895. Add subtractFrom method to ResourceUtilization class. Contributed by Konstantinos Karanasos.

This commit is contained in:
Arun Suresh 2016-04-01 14:57:06 -07:00
parent 256c82fe29
commit 82621e38a0

View File

@ -44,6 +44,14 @@ public static ResourceUtilization newInstance(int pmem, int vmem, float cpu) {
return utilization;
}
@Public
@Unstable
public static ResourceUtilization newInstance(
ResourceUtilization resourceUtil) {
return newInstance(resourceUtil.getPhysicalMemory(),
resourceUtil.getVirtualMemory(), resourceUtil.getCPU());
}
/**
* Get used <em>virtual memory</em>.
*
@ -147,4 +155,18 @@ public void addTo(int pmem, int vmem, float cpu) {
this.setVirtualMemory(this.getVirtualMemory() + vmem);
this.setCPU(this.getCPU() + cpu);
}
/**
* Subtract utilization from the current one.
* @param pmem Physical memory to be subtracted.
* @param vmem Virtual memory to be subtracted.
* @param cpu CPU utilization to be subtracted.
*/
@Public
@Unstable
public void subtractFrom(int pmem, int vmem, float cpu) {
this.setPhysicalMemory(this.getPhysicalMemory() - pmem);
this.setVirtualMemory(this.getVirtualMemory() - vmem);
this.setCPU(this.getCPU() - cpu);
}
}