Search in sources :

Example 1 with MinRamConstraint

use of org.apache.heron.packing.constraints.MinRamConstraint in project heron by twitter.

the class PackingTestHelper method generateTestPackingPlan.

/**
 * Returns a PackingPlan to use for testing scale up/down that has instances of specific
 * components on specific containers.
 */
private static PackingPlan generateTestPackingPlan(String topologyName, PackingPlan previousPackingPlan, Pair<Integer, String>[] addInstances, Pair<Integer, String>[] removeInstances, int containerPadding) throws ConstraintViolationException {
    PackingPlanBuilder builder = new PackingPlanBuilder(topologyName, previousPackingPlan);
    int instanceCount = 0;
    if (previousPackingPlan != null) {
        instanceCount = previousPackingPlan.getInstanceCount();
    } else if (addInstances != null) {
        instanceCount = addInstances.length;
    }
    // use basic default resource to allow all instances to fit on a single container, if that's
    // what the tester desired. We can extend this to permit passing custom resource requirements
    // as needed.
    Resource defaultInstanceResource = new Resource(1, ByteAmount.fromMegabytes(192), ByteAmount.fromMegabytes(1));
    Map<String, Resource> componentResourceMap = PackingUtils.getComponentResourceMap(toParallelismMap(previousPackingPlan, addInstances, removeInstances).keySet(), new HashMap<>(), new HashMap<>(), new HashMap<>(), defaultInstanceResource);
    builder.setDefaultInstanceResource(defaultInstanceResource);
    builder.setRequestedComponentResource(componentResourceMap);
    builder.setMaxContainerResource(new Resource(instanceCount, ByteAmount.fromMegabytes(192).multiply(instanceCount), ByteAmount.fromMegabytes(instanceCount)));
    builder.setInstanceConstraints(Collections.singletonList(new MinRamConstraint()));
    builder.setPackingConstraints(Collections.singletonList(new ResourceConstraint()));
    if (addInstances != null) {
        for (Pair<Integer, String> componentInstance : addInstances) {
            builder.addInstance(componentInstance.first, componentInstance.second);
        }
    }
    if (removeInstances != null) {
        for (Pair<Integer, String> componentInstance : removeInstances) {
            builder.removeInstance(componentInstance.first, componentInstance.second);
        }
    }
    return builder.build();
}
Also used : MinRamConstraint(org.apache.heron.packing.constraints.MinRamConstraint) PackingPlanBuilder(org.apache.heron.packing.builder.PackingPlanBuilder) Resource(org.apache.heron.spi.packing.Resource) MinRamConstraint(org.apache.heron.packing.constraints.MinRamConstraint) ResourceConstraint(org.apache.heron.packing.constraints.ResourceConstraint) ResourceConstraint(org.apache.heron.packing.constraints.ResourceConstraint)

Aggregations

PackingPlanBuilder (org.apache.heron.packing.builder.PackingPlanBuilder)1 MinRamConstraint (org.apache.heron.packing.constraints.MinRamConstraint)1 ResourceConstraint (org.apache.heron.packing.constraints.ResourceConstraint)1 Resource (org.apache.heron.spi.packing.Resource)1