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;
}
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();
}
}
}
Aggregations