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

(cherry picked from commit 82621e38a0)
This commit is contained in:
Arun Suresh 2016-04-01 14:57:06 -07:00
parent 719c131c4d
commit 9def4d4d39
1 changed files with 22 additions and 0 deletions

View File

@ -44,6 +44,14 @@ public abstract class ResourceUtilization implements
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 abstract class ResourceUtilization implements
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);
}
}