Search in sources :

Example 11 with InstanceId

use of org.apache.heron.spi.packing.InstanceId in project heron by twitter.

the class PackingTestHelper method toContainerIdComponentNames.

public static Pair<Integer, String>[] toContainerIdComponentNames(Pair<Integer, InstanceId>[] containerIdInstanceIds) {
    @SuppressWarnings({ "unchecked", "rawtypes" }) Pair<Integer, String>[] containerIdComponentNames = new Pair[containerIdInstanceIds.length];
    int i = 0;
    for (Pair<Integer, InstanceId> containerIdInstanceId : containerIdInstanceIds) {
        containerIdComponentNames[i++] = new Pair<>(containerIdInstanceId.first, containerIdInstanceId.second.getComponentName());
    }
    return containerIdComponentNames;
}
Also used : InstanceId(org.apache.heron.spi.packing.InstanceId) MinRamConstraint(org.apache.heron.packing.constraints.MinRamConstraint) ResourceConstraint(org.apache.heron.packing.constraints.ResourceConstraint) Pair(org.apache.heron.common.basics.Pair)

Example 12 with InstanceId

use of org.apache.heron.spi.packing.InstanceId in project heron by twitter.

the class PackingPlanBuilderTest method generatePacking.

private static PackingPlan generatePacking(Map<Integer, List<InstanceId>> basePacking) throws RuntimeException {
    Resource resource = new Resource(2.0, ByteAmount.fromGigabytes(6), ByteAmount.fromGigabytes(25));
    Set<PackingPlan.ContainerPlan> containerPlans = new HashSet<>();
    for (int containerId : basePacking.keySet()) {
        List<InstanceId> instanceList = basePacking.get(containerId);
        Set<PackingPlan.InstancePlan> instancePlans = new HashSet<>();
        for (InstanceId instanceId : instanceList) {
            String componentName = instanceId.getComponentName();
            Resource instanceResource;
            switch(componentName) {
                case "bolt":
                    instanceResource = new Resource(1.0, ByteAmount.fromGigabytes(2), ByteAmount.fromGigabytes(10));
                    break;
                case "spout":
                    instanceResource = new Resource(1.0, ByteAmount.fromGigabytes(3), ByteAmount.fromGigabytes(10));
                    break;
                default:
                    throw new RuntimeException(String.format("%s is not a valid component name", componentName));
            }
            instancePlans.add(new PackingPlan.InstancePlan(instanceId, instanceResource));
        }
        PackingPlan.ContainerPlan containerPlan = new PackingPlan.ContainerPlan(containerId, instancePlans, resource);
        containerPlans.add(containerPlan);
    }
    return new PackingPlan("", containerPlans);
}
Also used : InstanceId(org.apache.heron.spi.packing.InstanceId) PackingPlan(org.apache.heron.spi.packing.PackingPlan) Resource(org.apache.heron.spi.packing.Resource) HashSet(java.util.HashSet)

Example 13 with InstanceId

use of org.apache.heron.spi.packing.InstanceId in project heron by twitter.

the class PackingPlanBuilderTest method testGetContainers.

/**
 * Tests the getContainers method.
 */
@Test
public void testGetContainers() {
    Resource padding = new Resource(1.0, ByteAmount.fromGigabytes(1), ByteAmount.fromGigabytes(1));
    Map<Integer, List<InstanceId>> packing = new HashMap<>();
    packing.put(7, Arrays.asList(new InstanceId("spout", 1, 0), new InstanceId("bolt", 2, 0)));
    packing.put(3, Arrays.asList(new InstanceId("spout", 3, 0), new InstanceId("bolt", 4, 0)));
    PackingPlan packingPlan = generatePacking(packing);
    Map<Integer, Container> containers = PackingPlanBuilder.getContainers(packingPlan, packingPlan.getMaxContainerResources(), padding, new HashMap<String, TreeSet<Integer>>(), new TreeSet<Integer>());
    assertEquals(packing.size(), containers.size());
    for (Integer containerId : packing.keySet()) {
        Container foundContainer = containers.get(containerId);
        assertEquals(padding, foundContainer.getPadding());
        assertEquals(packingPlan.getMaxContainerResources(), foundContainer.getCapacity());
        assertEquals(2, foundContainer.getInstances().size());
    }
}
Also used : HashMap(java.util.HashMap) InstanceId(org.apache.heron.spi.packing.InstanceId) PackingPlan(org.apache.heron.spi.packing.PackingPlan) Resource(org.apache.heron.spi.packing.Resource) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Example 14 with InstanceId

use of org.apache.heron.spi.packing.InstanceId in project heron by twitter.

the class PackingPlanBuilderTest method testExceededCapacityAddingToPackingPlan.

@Test(expected = ResourceExceededException.class)
public void testExceededCapacityAddingToPackingPlan() throws ConstraintViolationException {
    PackingPlan plan = doCreatePackingPlanTest(testContainerInstances);
    @SuppressWarnings({ "unchecked", "rawtypes" }) Pair<Integer, InstanceId>[] added = new Pair[] { new Pair<>(3, new InstanceId("componentB", 4, 1)), new Pair<>(3, new InstanceId("componentB", 5, 2)) };
    PackingTestHelper.addToTestPackingPlan(TOPOLOGY_ID, plan, PackingTestHelper.toContainerIdComponentNames(added), 0);
}
Also used : InstanceId(org.apache.heron.spi.packing.InstanceId) PackingPlan(org.apache.heron.spi.packing.PackingPlan) Pair(org.apache.heron.common.basics.Pair) Test(org.junit.Test)

Example 15 with InstanceId

use of org.apache.heron.spi.packing.InstanceId in project heron by twitter.

the class ResourceCompliantRRPackingTest method testScaleDownHomogenousFirst.

@Test
public void testScaleDownHomogenousFirst() throws Exception {
    @SuppressWarnings({ "unchecked", "rawtypes" }) Pair<Integer, InstanceId>[] initialComponentInstances = new Pair[] { new Pair<>(1, new InstanceId(SPOUT_NAME, 1, 0)), new Pair<>(1, new InstanceId(SPOUT_NAME, 2, 1)), new Pair<>(1, new InstanceId(BOLT_NAME, 3, 0)), new Pair<>(3, new InstanceId(BOLT_NAME, 4, 1)), new Pair<>(3, new InstanceId(BOLT_NAME, 5, 2)), new Pair<>(3, new InstanceId(BOLT_NAME, 6, 3)), new Pair<>(3, new InstanceId(BOLT_NAME, 7, 4)) };
    Map<String, Integer> componentChanges = new HashMap<>();
    componentChanges.put(BOLT_NAME, -4);
    @SuppressWarnings({ "unchecked", "rawtypes" }) Pair<Integer, InstanceId>[] expectedComponentInstances = new Pair[] { new Pair<>(1, new InstanceId(SPOUT_NAME, 1, 0)), new Pair<>(1, new InstanceId(SPOUT_NAME, 2, 1)), new Pair<>(1, new InstanceId(BOLT_NAME, 3, 0)) };
    doScaleDownTest(initialComponentInstances, componentChanges, expectedComponentInstances);
}
Also used : InstanceId(org.apache.heron.spi.packing.InstanceId) HashMap(java.util.HashMap) Pair(org.apache.heron.common.basics.Pair) Test(org.junit.Test)

Aggregations

InstanceId (org.apache.heron.spi.packing.InstanceId)17 HashMap (java.util.HashMap)11 Pair (org.apache.heron.common.basics.Pair)10 Test (org.junit.Test)10 PackingPlan (org.apache.heron.spi.packing.PackingPlan)8 ArrayList (java.util.ArrayList)4 Resource (org.apache.heron.spi.packing.Resource)4 HashSet (java.util.HashSet)3 List (java.util.List)3 Map (java.util.Map)2 Set (java.util.Set)1 TreeSet (java.util.TreeSet)1 ByteAmount (org.apache.heron.common.basics.ByteAmount)1 InstanceConstraint (org.apache.heron.packing.constraints.InstanceConstraint)1 MinRamConstraint (org.apache.heron.packing.constraints.MinRamConstraint)1 PackingConstraint (org.apache.heron.packing.constraints.PackingConstraint)1 ResourceConstraint (org.apache.heron.packing.constraints.ResourceConstraint)1 PackingException (org.apache.heron.spi.packing.PackingException)1