Search in sources :

Example 26 with InstanceId

use of com.twitter.heron.spi.packing.InstanceId in project incubator-heron by apache.

the class PackingPlanBuilderTest method testGetContainers.

/**
 * Tests the getContainers method.
 */
@Test
public void testGetContainers() throws ResourceExceededException {
    int paddingPercentage = 10;
    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, paddingPercentage, new HashMap<String, TreeSet<Integer>>(), new TreeSet<Integer>());
    assertEquals(packing.size(), containers.size());
    for (Integer containerId : packing.keySet()) {
        Container foundContainer = containers.get(containerId);
        assertEquals(paddingPercentage, foundContainer.getPaddingPercentage());
        assertEquals(packingPlan.getMaxContainerResources(), foundContainer.getCapacity());
        assertEquals(2, foundContainer.getInstances().size());
    }
}
Also used : HashMap(java.util.HashMap) InstanceId(com.twitter.heron.spi.packing.InstanceId) PackingPlan(com.twitter.heron.spi.packing.PackingPlan) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Example 27 with InstanceId

use of com.twitter.heron.spi.packing.InstanceId in project incubator-heron by apache.

the class PackingPlanBuilderTest method testRemoveFromPackingPlan.

@Test
public void testRemoveFromPackingPlan() throws ResourceExceededException {
    PackingPlan plan = doCreatePackingPlanTest(testContainerInstances);
    @SuppressWarnings({ "unchecked", "rawtypes" }) Pair<Integer, String>[] removed = new Pair[] { new Pair<>(1, "componentA"), new Pair<>(3, "componentA") };
    PackingPlan updatedPlan = PackingTestHelper.removeFromTestPackingPlan(TOPOLOGY_ID, plan, removed, 0);
    @SuppressWarnings({ "unchecked", "rawtypes" }) Pair<Integer, InstanceId>[] expected = new Pair[] { new Pair<>(3, new InstanceId("componentB", 3, 0)) };
    AssertPacking.assertPackingPlan(TOPOLOGY_ID, expected, updatedPlan);
}
Also used : InstanceId(com.twitter.heron.spi.packing.InstanceId) PackingPlan(com.twitter.heron.spi.packing.PackingPlan) Pair(com.twitter.heron.common.basics.Pair) Test(org.junit.Test)

Example 28 with InstanceId

use of com.twitter.heron.spi.packing.InstanceId in project incubator-heron by apache.

the class PackingPlanBuilder method buildContainerPlans.

/**
 * Estimate the per instance and topology resources for the packing plan based on the ramMap,
 * instance defaults and paddingPercentage.
 *
 * @return container plans
 */
private static Set<PackingPlan.ContainerPlan> buildContainerPlans(Map<Integer, Container> containerInstances, Map<String, ByteAmount> ramMap, Resource instanceDefaults, int paddingPercentage) {
    Set<PackingPlan.ContainerPlan> containerPlans = new LinkedHashSet<>();
    for (Integer containerId : containerInstances.keySet()) {
        Container container = containerInstances.get(containerId);
        if (container.getInstances().size() == 0) {
            continue;
        }
        ByteAmount containerRam = ByteAmount.ZERO;
        ByteAmount containerDiskInBytes = ByteAmount.ZERO;
        double containerCpu = 0;
        // Calculate the resource required for single instance
        Set<PackingPlan.InstancePlan> instancePlans = new HashSet<>();
        for (PackingPlan.InstancePlan instancePlan : container.getInstances()) {
            InstanceId instanceId = new InstanceId(instancePlan.getComponentName(), instancePlan.getTaskId(), instancePlan.getComponentIndex());
            ByteAmount instanceRam;
            if (ramMap.containsKey(instanceId.getComponentName())) {
                instanceRam = ramMap.get(instanceId.getComponentName());
            } else {
                instanceRam = instanceDefaults.getRam();
            }
            containerRam = containerRam.plus(instanceRam);
            // Currently not yet support disk or cpu config for different components,
            // so just use the default value.
            ByteAmount instanceDisk = instanceDefaults.getDisk();
            containerDiskInBytes = containerDiskInBytes.plus(instanceDisk);
            double instanceCpu = instanceDefaults.getCpu();
            containerCpu += instanceCpu;
            // Insert it into the map
            instancePlans.add(new PackingPlan.InstancePlan(instanceId, new Resource(instanceCpu, instanceRam, instanceDisk)));
        }
        containerCpu += (paddingPercentage * containerCpu) / 100;
        containerRam = containerRam.increaseBy(paddingPercentage);
        containerDiskInBytes = containerDiskInBytes.increaseBy(paddingPercentage);
        Resource resource = new Resource(Math.round(containerCpu), containerRam, containerDiskInBytes);
        PackingPlan.ContainerPlan containerPlan = new PackingPlan.ContainerPlan(containerId, instancePlans, resource);
        containerPlans.add(containerPlan);
    }
    return containerPlans;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ByteAmount(com.twitter.heron.common.basics.ByteAmount) InstanceId(com.twitter.heron.spi.packing.InstanceId) PackingPlan(com.twitter.heron.spi.packing.PackingPlan) Resource(com.twitter.heron.spi.packing.Resource) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Aggregations

InstanceId (com.twitter.heron.spi.packing.InstanceId)28 PackingPlan (com.twitter.heron.spi.packing.PackingPlan)18 HashMap (java.util.HashMap)16 Test (org.junit.Test)14 Pair (com.twitter.heron.common.basics.Pair)12 Resource (com.twitter.heron.spi.packing.Resource)8 ArrayList (java.util.ArrayList)8 HashSet (java.util.HashSet)8 ByteAmount (com.twitter.heron.common.basics.ByteAmount)6 List (java.util.List)6 Map (java.util.Map)4 ResourceExceededException (com.twitter.heron.packing.ResourceExceededException)2 LinkedHashSet (java.util.LinkedHashSet)2 Set (java.util.Set)2 TreeSet (java.util.TreeSet)2