use of org.apache.heron.packing.constraints.InstanceConstraint in project heron by twitter.
the class PackingPlanBuilder method addInstance.
// adds an instance to a container with id containerId. If that container does not exist, it will
// be lazily initialized, which could result in more containers than those requested using the
// updateNumContainers method
public PackingPlanBuilder addInstance(Integer containerId, String componentName) throws ConstraintViolationException {
// create container if not existed
initContainer(containerId);
Integer taskId = taskIds.isEmpty() ? 1 : taskIds.last() + 1;
Integer componentIndex = componentIndexes.containsKey(componentName) ? componentIndexes.get(componentName).last() + 1 : 0;
InstanceId instanceId = new InstanceId(componentName, taskId, componentIndex);
Resource instanceResource = componentResourceMap.getOrDefault(componentName, defaultInstanceResource);
Container container = containers.get(containerId);
PackingPlan.InstancePlan instancePlan = new PackingPlan.InstancePlan(instanceId, instanceResource);
// Check constraints
for (InstanceConstraint constraint : instanceConstraints) {
constraint.validate(instancePlan);
}
for (PackingConstraint constraint : packingConstraints) {
constraint.validate(container, instancePlan);
}
addToContainer(container, instancePlan, this.componentIndexes, this.taskIds);
LOG.finest(String.format("Added to container %d instance %s", containerId, instanceId));
return this;
}
Aggregations