Search in sources :

Example 11 with ResourceExceededException

use of com.twitter.heron.packing.ResourceExceededException in project heron by twitter.

the class PackingPlanBuilder method initContainers.

private void initContainers() {
    assertResourceSettings();
    Map<Integer, Container> newContainerMap = this.containers;
    HashMap<String, TreeSet<Integer>> newComponentIndexes = this.componentIndexes;
    TreeSet<Integer> newTaskIds = this.taskIds;
    if (newComponentIndexes == null) {
        newComponentIndexes = new HashMap<>();
    }
    if (newTaskIds == null) {
        newTaskIds = new TreeSet<>();
    }
    // if this is the first time called, initialize container map with empty or existing containers
    if (newContainerMap == null) {
        if (this.existingPacking == null) {
            newContainerMap = new HashMap<>();
            for (int containerId = 1; containerId <= numContainers; containerId++) {
                newContainerMap.put(containerId, new Container(containerId, this.maxContainerResource, this.requestedContainerPadding));
            }
        } else {
            try {
                newContainerMap = getContainers(this.existingPacking, this.requestedContainerPadding, newComponentIndexes, newTaskIds);
            } catch (ResourceExceededException e) {
                throw new PackingException("Could not initialize containers using existing packing plan", e);
            }
        }
    }
    if (this.numContainers > newContainerMap.size()) {
        List<Scorer<Container>> scorers = new ArrayList<>();
        scorers.add(new ContainerIdScorer());
        List<Container> sortedContainers = sortContainers(scorers, newContainerMap.values());
        int nextContainerId = sortedContainers.get(sortedContainers.size() - 1).getContainerId() + 1;
        Resource capacity = newContainerMap.get(sortedContainers.get(0).getContainerId()).getCapacity();
        for (int i = 0; i < numContainers - newContainerMap.size(); i++) {
            newContainerMap.put(nextContainerId, new Container(nextContainerId, capacity, this.requestedContainerPadding));
            nextContainerId++;
        }
    }
    this.containers = newContainerMap;
    this.componentIndexes = newComponentIndexes;
    this.taskIds = newTaskIds;
}
Also used : ResourceExceededException(com.twitter.heron.packing.ResourceExceededException) ArrayList(java.util.ArrayList) Resource(com.twitter.heron.spi.packing.Resource) TreeSet(java.util.TreeSet) PackingException(com.twitter.heron.spi.packing.PackingException)

Example 12 with ResourceExceededException

use of com.twitter.heron.packing.ResourceExceededException in project incubator-heron by apache.

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)

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