Search in sources :

Example 1 with ResourceExceededException

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()));
    }
}
Also used : ByteAmount(com.twitter.heron.common.basics.ByteAmount) ResourceExceededException(com.twitter.heron.packing.ResourceExceededException) Resource(com.twitter.heron.spi.packing.Resource)

Example 2 with ResourceExceededException

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;
}
Also used : HashMap(java.util.HashMap) ResourceExceededException(com.twitter.heron.packing.ResourceExceededException) PackingPlan(com.twitter.heron.spi.packing.PackingPlan) Resource(com.twitter.heron.spi.packing.Resource) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 3 with ResourceExceededException

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();
        }
    }
}
Also used : ResourceExceededException(com.twitter.heron.packing.ResourceExceededException) PackingPlanBuilder(com.twitter.heron.packing.builder.PackingPlanBuilder)

Example 4 with ResourceExceededException

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));
        }
    }
}
Also used : ResourceExceededException(com.twitter.heron.packing.ResourceExceededException) PackingPlanBuilder(com.twitter.heron.packing.builder.PackingPlanBuilder)

Example 5 with ResourceExceededException

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));
        }
    }
}
Also used : ResourceExceededException(com.twitter.heron.packing.ResourceExceededException) PackingPlanBuilder(com.twitter.heron.packing.builder.PackingPlanBuilder)

Aggregations

ResourceExceededException (com.twitter.heron.packing.ResourceExceededException)12 Resource (com.twitter.heron.spi.packing.Resource)8 PackingPlanBuilder (com.twitter.heron.packing.builder.PackingPlanBuilder)4 PackingPlan (com.twitter.heron.spi.packing.PackingPlan)4 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 ByteAmount (com.twitter.heron.common.basics.ByteAmount)2 InstanceId (com.twitter.heron.spi.packing.InstanceId)2 PackingException (com.twitter.heron.spi.packing.PackingException)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 TreeSet (java.util.TreeSet)2