Search in sources :

Example 31 with Resource

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

the class PackingUtilsTest method testResourceScaleDown.

@Test
public void testResourceScaleDown() {
    int noSpouts = 6;
    int noBolts = 3;
    int boltScalingDown = 2;
    org.apache.heron.api.Config topologyConfig = new org.apache.heron.api.Config();
    TopologyAPI.Topology topology = getTopology(noSpouts, noBolts, topologyConfig);
    Config config = PackingTestUtils.newTestConfig(topology);
    Resource defaultInstanceResources = new Resource(Context.instanceCpu(config), Context.instanceRam(config), Context.instanceDisk(config));
    Map<String, Integer> componentChanges = new HashMap<>();
    // 1 bolt
    componentChanges.put("bolt", -boltScalingDown);
    Resource scaledownResource = PackingUtils.computeTotalResourceChange(topology, componentChanges, defaultInstanceResources, PackingUtils.ScalingDirection.DOWN);
    Assert.assertEquals((long) (boltScalingDown * defaultInstanceResources.getCpu()), (long) scaledownResource.getCpu());
    Assert.assertEquals(defaultInstanceResources.getRam().multiply(boltScalingDown), scaledownResource.getRam());
    Assert.assertEquals(defaultInstanceResources.getDisk().multiply(boltScalingDown), scaledownResource.getDisk());
}
Also used : HashMap(java.util.HashMap) Config(org.apache.heron.spi.common.Config) Resource(org.apache.heron.spi.packing.Resource) TopologyAPI(org.apache.heron.api.generated.TopologyAPI) Test(org.junit.Test)

Example 32 with Resource

use of org.apache.heron.spi.packing.Resource 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 33 with Resource

use of org.apache.heron.spi.packing.Resource 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 34 with Resource

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

the class ResourceCompliantRRPackingTest method testContainerRequestedResourcesSingleContainer.

/**
 * Test the scenario where container level resource config are set
 */
@Test
public void testContainerRequestedResourcesSingleContainer() throws Exception {
    int numContainers = 1;
    // Set up the topology and its config
    topologyConfig.setNumStmgrs(numContainers);
    // Explicit set resources for container
    ByteAmount containerRam = ByteAmount.fromGigabytes(10);
    ByteAmount containerDisk = ByteAmount.fromGigabytes(20);
    double containerCpu = 30;
    Resource containerResource = new Resource(containerCpu, containerRam, containerDisk);
    Resource padding = PackingUtils.finalizePadding(new Resource(containerCpu, containerRam, containerDisk), new Resource(PackingUtils.DEFAULT_CONTAINER_CPU_PADDING, PackingUtils.DEFAULT_CONTAINER_RAM_PADDING, PackingUtils.DEFAULT_CONTAINER_RAM_PADDING), PackingUtils.DEFAULT_CONTAINER_PADDING_PERCENTAGE);
    topologyConfig.setContainerRamRequested(containerRam);
    topologyConfig.setContainerDiskRequested(containerDisk);
    topologyConfig.setContainerCpuRequested(containerCpu);
    topology = getTopology(spoutParallelism, boltParallelism, topologyConfig);
    PackingPlan packingPlan = doPackingTest(topology, instanceDefaultResources, boltParallelism, instanceDefaultResources, spoutParallelism, numContainers, containerResource);
    for (PackingPlan.ContainerPlan containerPlan : packingPlan.getContainers()) {
        Assert.assertEquals(Math.round(totalInstances * instanceDefaultResources.getCpu() + padding.getCpu()), (long) containerPlan.getRequiredResource().getCpu());
        Assert.assertEquals(instanceDefaultResources.getRam().multiply(totalInstances).plus(padding.getRam()), containerPlan.getRequiredResource().getRam());
        Assert.assertEquals(instanceDefaultResources.getDisk().multiply(totalInstances).plus(padding.getDisk()), containerPlan.getRequiredResource().getDisk());
        // All instances' resource requirement should be equal
        // So the size of set should be 1
        Set<Resource> resources = new HashSet<>();
        for (PackingPlan.InstancePlan instancePlan : containerPlan.getInstances()) {
            resources.add(instancePlan.getResource());
        }
        Assert.assertEquals(1, resources.size());
        Assert.assertEquals(instanceDefaultResources.getRam(), resources.iterator().next().getRam());
    }
}
Also used : ByteAmount(org.apache.heron.common.basics.ByteAmount) PackingPlan(org.apache.heron.spi.packing.PackingPlan) Resource(org.apache.heron.spi.packing.Resource) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 35 with Resource

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

the class ResourceCompliantRRPacking method computeNumAdditionalContainers.

/**
 * Computes the additional number of containers needed to accommodate a scale up/down operation
 *
 * @param componentChanges parallelism changes for scale up/down
 * @param packingPlan existing packing plan
 * @return additional number of containers needed
 */
private int computeNumAdditionalContainers(Map<String, Integer> componentChanges, PackingPlan packingPlan) {
    Resource scaleDownResource = PackingUtils.computeTotalResourceChange(topology, componentChanges, defaultInstanceResources, PackingUtils.ScalingDirection.DOWN);
    Resource scaleUpResource = PackingUtils.computeTotalResourceChange(topology, componentChanges, defaultInstanceResources, PackingUtils.ScalingDirection.UP);
    Resource additionalResource = scaleUpResource.subtractAbsolute(scaleDownResource);
    return (int) additionalResource.divideBy(packingPlan.getMaxContainerResources());
}
Also used : Resource(org.apache.heron.spi.packing.Resource)

Aggregations

Resource (org.apache.heron.spi.packing.Resource)47 PackingPlan (org.apache.heron.spi.packing.PackingPlan)25 Test (org.junit.Test)22 HashSet (java.util.HashSet)18 ByteAmount (org.apache.heron.common.basics.ByteAmount)17 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)7 HashMap (java.util.HashMap)6 Config (org.apache.heron.spi.common.Config)6 Task (com.hashicorp.nomad.apimodel.Task)4 ArrayList (java.util.ArrayList)4 TopologyAPI (org.apache.heron.api.generated.TopologyAPI)4 InstanceId (org.apache.heron.spi.packing.InstanceId)4 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)3 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)2 Job (com.hashicorp.nomad.apimodel.Job)2 TaskGroup (com.hashicorp.nomad.apimodel.TaskGroup)2 Quantity (io.kubernetes.client.custom.Quantity)2 V1Container (io.kubernetes.client.openapi.models.V1Container)2 V1ContainerBuilder (io.kubernetes.client.openapi.models.V1ContainerBuilder)2 List (java.util.List)2