Search in sources :

Example 1 with InstanceConstraint

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;
}
Also used : PackingConstraint(org.apache.heron.packing.constraints.PackingConstraint) InstanceConstraint(org.apache.heron.packing.constraints.InstanceConstraint) InstanceId(org.apache.heron.spi.packing.InstanceId) PackingPlan(org.apache.heron.spi.packing.PackingPlan) Resource(org.apache.heron.spi.packing.Resource)

Aggregations

InstanceConstraint (org.apache.heron.packing.constraints.InstanceConstraint)1 PackingConstraint (org.apache.heron.packing.constraints.PackingConstraint)1 InstanceId (org.apache.heron.spi.packing.InstanceId)1 PackingPlan (org.apache.heron.spi.packing.PackingPlan)1 Resource (org.apache.heron.spi.packing.Resource)1