use of org.apache.heron.packing.exceptions.ResourceExceededException in project heron by twitter.
the class ResourceConstraint method validate.
@Override
public void validate(Container container, PackingPlan.InstancePlan instancePlan) throws ResourceExceededException {
Resource usedResource = container.getTotalUsedResources();
Resource newUsedResource = usedResource.plus(instancePlan.getResource());
Resource capacity = container.getCapacity();
if (capacity.getCpu() < newUsedResource.getCpu()) {
throw new ResourceExceededException(String.format("Adding instance %s with %.3f cores " + "to container %d with existing %.3f cores " + "would exceed its capacity of %.3f cores", instancePlan.getComponentName(), instancePlan.getResource().getCpu(), container.getContainerId(), usedResource.getCpu(), capacity.getCpu()));
}
if (capacity.getRam().lessThan(newUsedResource.getRam())) {
throw new ResourceExceededException(String.format("Adding instance %s with %s RAM " + "to container %d with existing %s RAM " + "would exceed its capacity of %s RAM", instancePlan.getComponentName(), instancePlan.getResource().getRam().toString(), container.getContainerId(), usedResource.getRam().toString(), capacity.getRam().toString()));
}
if (capacity.getDisk().lessThan(newUsedResource.getDisk())) {
throw new ResourceExceededException(String.format("Adding instance %s with %s disk " + "to container %d with existing %s disk " + "would exceed its capacity of %s disk", instancePlan.getComponentName(), instancePlan.getResource().getDisk().toString(), container.getContainerId(), usedResource.getDisk().toString(), capacity.getDisk().toString()));
}
}
Aggregations