xiaoyao1991 commented on a change in pull request #3187: Consolidate Packing
URL: https://github.com/apache/incubator-heron/pull/3187#discussion_r254104849
##########
File path:
heron/packing/src/java/org/apache/heron/packing/builder/Container.java
##########
@@ -150,51 +146,17 @@ public String toString() {
return Optional.absent();
}
- /**
- * Check whether the container can accommodate a new instance with specific
resource requirements
- */
- private void assertHasSpace(Resource resource) throws
ResourceExceededException {
- Resource usedResources = this.getTotalUsedResources();
- ByteAmount newRam =
-
usedResources.getRam().plus(resource.getRam()).increaseBy(paddingPercentage);
- double newCpu = Math.round(
- PackingUtils.increaseBy(usedResources.getCpu() + resource.getCpu(),
paddingPercentage));
- ByteAmount newDisk =
-
usedResources.getDisk().plus(resource.getDisk()).increaseBy(paddingPercentage);
-
- if (newRam.greaterThan(this.capacity.getRam())) {
- throw new ResourceExceededException(String.format("Adding %s bytes of
RAM to existing %s "
- + "bytes with %d percent padding would exceed capacity %s",
- resource.getRam(), usedResources.getRam(), paddingPercentage,
this.capacity.getRam()));
- }
- if (newCpu > this.capacity.getCpu()) {
- throw new ResourceExceededException(String.format("Adding %s cores to
existing %s "
- + "cores with %d percent padding would exceed capacity %s",
- resource.getCpu(), usedResources.getCpu(), paddingPercentage,
this.capacity.getCpu()));
- }
- if (newDisk.greaterThan(this.capacity.getDisk())) {
- throw new ResourceExceededException(String.format("Adding %s bytes of
disk to existing %s "
- + "bytes with %s percent padding would exceed capacity %s",
- resource.getDisk(), usedResources.getDisk(), paddingPercentage,
this.capacity.getDisk()));
- }
- }
-
/**
* Computes the used resources of the container by taking into account the
resources
* allocated for each instance.
*
* @return a Resource object that describes the used CPU, RAM and disk in
the container.
*/
public Resource getTotalUsedResources() {
- ByteAmount usedRam = ByteAmount.ZERO;
- double usedCpuCores = 0;
- ByteAmount usedDisk = ByteAmount.ZERO;
- for (PackingPlan.InstancePlan instancePlan : this.instances) {
- Resource resource = instancePlan.getResource();
- usedRam = usedRam.plus(resource.getRam());
- usedCpuCores += resource.getCpu();
- usedDisk = usedDisk.plus(resource.getDisk());
- }
- return new Resource(usedCpuCores, usedRam, usedDisk);
+ return getInstances().stream()
+ .map(PackingPlan.InstancePlan::getResource)
+ .reduce(Resource::plus)
Review comment:
nice catch
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services