use of com.twitter.heron.packing.ResourceExceededException in project heron by twitter.
the class Container method assertHasSpace.
/**
* 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()));
}
}
use of com.twitter.heron.packing.ResourceExceededException in project heron by twitter.
the class PackingPlanBuilder method getContainers.
/**
* Generates the containers that correspond to the current packing plan
* along with their associated instances.
*
* @return Map of containers for the current packing plan, keyed by containerId
*/
@VisibleForTesting
static Map<Integer, Container> getContainers(PackingPlan currentPackingPlan, int paddingPercentage, Map<String, TreeSet<Integer>> componentIndexes, TreeSet<Integer> taskIds) throws ResourceExceededException {
Map<Integer, Container> containers = new HashMap<>();
Resource capacity = currentPackingPlan.getMaxContainerResources();
for (PackingPlan.ContainerPlan currentContainerPlan : currentPackingPlan.getContainers()) {
Container container = new Container(currentContainerPlan.getId(), capacity, paddingPercentage);
for (PackingPlan.InstancePlan instancePlan : currentContainerPlan.getInstances()) {
try {
addToContainer(container, instancePlan, componentIndexes, taskIds);
} catch (ResourceExceededException e) {
throw new ResourceExceededException(String.format("Insufficient container resources to add instancePlan %s to container %s", instancePlan, container), e);
}
}
containers.put(currentContainerPlan.getId(), container);
}
return containers;
}
use of com.twitter.heron.packing.ResourceExceededException in project heron by twitter.
the class ResourceCompliantRRPacking method pack.
@Override
public PackingPlan pack() {
while (true) {
try {
PackingPlanBuilder planBuilder = newPackingPlanBuilder(null);
planBuilder.updateNumContainers(numContainers);
planBuilder = getResourceCompliantRRAllocation(planBuilder);
return planBuilder.build();
} catch (ResourceExceededException e) {
//Not enough containers. Adjust the number of containers.
LOG.finest(String.format("%s Increasing the number of containers to %s and attempting to place again.", e.getMessage(), this.numContainers + 1));
increaseNumContainers(1);
resetToFirstContainer();
}
}
}
use of com.twitter.heron.packing.ResourceExceededException in project heron by twitter.
the class ResourceCompliantRRPacking method repack.
/**
* Get a new packing plan given an existing packing plan and component-level changes.
*
* @return new packing plan
*/
@Override
public PackingPlan repack(PackingPlan currentPackingPlan, Map<String, Integer> componentChanges) {
this.numContainers = currentPackingPlan.getContainers().size();
resetToFirstContainer();
int additionalContainers = computeNumAdditionalContainers(componentChanges, currentPackingPlan);
if (additionalContainers > 0) {
increaseNumContainers(additionalContainers);
LOG.info(String.format("Allocated %s additional containers for repack bring the number of containers to %s.", additionalContainers, this.numContainers));
}
while (true) {
try {
PackingPlanBuilder planBuilder = newPackingPlanBuilder(currentPackingPlan);
planBuilder.updateNumContainers(numContainers);
planBuilder = getResourceCompliantRRAllocation(planBuilder, componentChanges);
return planBuilder.build();
} catch (ResourceExceededException e) {
//Not enough containers. Adjust the number of containers.
increaseNumContainers(1);
resetToFirstContainer();
LOG.info(String.format("%s Increasing the number of containers to %s and attempting packing again.", e.getMessage(), this.numContainers));
}
}
}
use of com.twitter.heron.packing.ResourceExceededException in project incubator-heron by apache.
the class ResourceCompliantRRPacking method repack.
/**
* Get a new packing plan given an existing packing plan and component-level changes.
*
* @return new packing plan
*/
@Override
public PackingPlan repack(PackingPlan currentPackingPlan, Map<String, Integer> componentChanges) {
this.numContainers = currentPackingPlan.getContainers().size();
resetToFirstContainer();
int additionalContainers = computeNumAdditionalContainers(componentChanges, currentPackingPlan);
if (additionalContainers > 0) {
increaseNumContainers(additionalContainers);
LOG.info(String.format("Allocated %s additional containers for repack bring the number of containers to %s.", additionalContainers, this.numContainers));
}
while (true) {
try {
PackingPlanBuilder planBuilder = newPackingPlanBuilder(currentPackingPlan);
planBuilder.updateNumContainers(numContainers);
planBuilder = getResourceCompliantRRAllocation(planBuilder, componentChanges);
return planBuilder.build();
} catch (ResourceExceededException e) {
// Not enough containers. Adjust the number of containers.
increaseNumContainers(1);
resetToFirstContainer();
LOG.info(String.format("%s Increasing the number of containers to %s and attempting packing again.", e.getMessage(), this.numContainers));
}
}
}
Aggregations