Search in sources :

Example 1 with IRepacking

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

the class CommonPackingTests method repack.

private PackingPlan repack(TopologyAPI.Topology testTopology, PackingPlan initialPackingPlan, Map<String, Integer> componentChanges) {
    IRepacking repacking = getRepackingImpl();
    repacking.initialize(PackingTestUtils.newTestConfig(testTopology), testTopology);
    return repacking.repack(initialPackingPlan, componentChanges);
}
Also used : IRepacking(org.apache.heron.spi.packing.IRepacking)

Example 2 with IRepacking

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

the class ScaleUpResolver method buildNewPackingPlan.

@VisibleForTesting
PackingPlan buildNewPackingPlan(Map<String, Integer> changeRequests, PackingPlan currentPackingPlan) {
    Map<String, Integer> componentDeltas = new HashMap<>();
    Map<String, Integer> componentCounts = currentPackingPlan.getComponentCounts();
    for (String compName : changeRequests.keySet()) {
        if (!componentCounts.containsKey(compName)) {
            throw new IllegalArgumentException(String.format("Invalid component name in scale up diagnosis: %s. Valid components include: %s", compName, Arrays.toString(componentCounts.keySet().toArray(new String[componentCounts.keySet().size()]))));
        }
        Integer newValue = changeRequests.get(compName);
        int delta = newValue - componentCounts.get(compName);
        if (delta == 0) {
            LOG.info(String.format("New parallelism for %s is unchanged: %d", compName, newValue));
            continue;
        }
        componentDeltas.put(compName, delta);
    }
    // Create an instance of the packing class
    IRepacking packing = getRepackingClass(Context.repackingClass(config));
    Topology topology = physicalPlanProvider.get().getTopology();
    try {
        packing.initialize(config, topology);
        return packing.repack(currentPackingPlan, componentDeltas);
    } finally {
        SysUtils.closeIgnoringExceptions(packing);
    }
}
Also used : HashMap(java.util.HashMap) IRepacking(org.apache.heron.spi.packing.IRepacking) Topology(org.apache.heron.api.generated.TopologyAPI.Topology) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 3 with IRepacking

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

the class ScaleUpResolverTest method testBuildPackingPlan.

@Test
public void testBuildPackingPlan() {
    TopologyAPI.Topology topology = createTestTopology();
    PhysicalPlanProvider topologyProvider = createPhysicalPlanProvider(topology);
    Config config = createConfig(topology);
    PackingPlan currentPlan = createPacking(topology, config);
    Map<String, Integer> changeRequest = new HashMap<>();
    changeRequest.put("bolt-2", 4);
    Map<String, Integer> deltaChange = new HashMap<>();
    deltaChange.put("bolt-2", 3);
    IRepacking repacking = mock(IRepacking.class);
    when(repacking.repack(currentPlan, deltaChange)).thenReturn(currentPlan);
    ScaleUpResolver resolver = new ScaleUpResolver(topologyProvider, null, null, eventManager, config);
    ScaleUpResolver spyResolver = spy(resolver);
    doReturn(repacking).when(spyResolver).getRepackingClass("Repacking");
    PackingPlan newPlan = spyResolver.buildNewPackingPlan(changeRequest, currentPlan);
    assertEquals(currentPlan, newPlan);
}
Also used : PhysicalPlanProvider(org.apache.heron.healthmgr.common.PhysicalPlanProvider) HashMap(java.util.HashMap) IRepacking(org.apache.heron.spi.packing.IRepacking) Config(org.apache.heron.spi.common.Config) PackingPlan(org.apache.heron.spi.packing.PackingPlan) TopologyAPI(org.apache.heron.api.generated.TopologyAPI) Test(org.junit.Test)

Example 4 with IRepacking

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

the class RuntimeManagerRunner method buildNewPackingPlan.

@VisibleForTesting
PackingPlans.PackingPlan buildNewPackingPlan(PackingPlans.PackingPlan currentProtoPlan, Map<String, Integer> changeRequests, Integer containerNum, TopologyAPI.Topology topology) throws PackingException {
    PackingPlanProtoDeserializer deserializer = new PackingPlanProtoDeserializer();
    PackingPlanProtoSerializer serializer = new PackingPlanProtoSerializer();
    PackingPlan currentPackingPlan = deserializer.fromProto(currentProtoPlan);
    Map<String, Integer> componentCounts = currentPackingPlan.getComponentCounts();
    Map<String, Integer> componentChanges = parallelismDelta(componentCounts, changeRequests);
    // Create an instance of the packing class
    String repackingClass = Context.repackingClass(config);
    IRepacking packing;
    try {
        // create an instance of the packing class
        packing = ReflectionUtils.newInstance(repackingClass);
    } catch (IllegalAccessException | InstantiationException | ClassNotFoundException e) {
        throw new IllegalArgumentException("Failed to instantiate packing instance: " + repackingClass, e);
    }
    LOG.info("Updating packing plan using " + repackingClass);
    try {
        packing.initialize(config, topology);
        PackingPlan packedPlan = null;
        if (containerNum == null) {
            packedPlan = packing.repack(currentPackingPlan, componentChanges);
        } else {
            packedPlan = packing.repack(currentPackingPlan, containerNum, componentChanges);
        }
        return serializer.toProto(packedPlan);
    } finally {
        SysUtils.closeIgnoringExceptions(packing);
    }
}
Also used : PackingPlanProtoDeserializer(org.apache.heron.spi.packing.PackingPlanProtoDeserializer) PackingPlanProtoSerializer(org.apache.heron.spi.packing.PackingPlanProtoSerializer) IRepacking(org.apache.heron.spi.packing.IRepacking) PackingPlan(org.apache.heron.spi.packing.PackingPlan) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

IRepacking (org.apache.heron.spi.packing.IRepacking)4 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 HashMap (java.util.HashMap)2 PackingPlan (org.apache.heron.spi.packing.PackingPlan)2 TopologyAPI (org.apache.heron.api.generated.TopologyAPI)1 Topology (org.apache.heron.api.generated.TopologyAPI.Topology)1 PhysicalPlanProvider (org.apache.heron.healthmgr.common.PhysicalPlanProvider)1 Config (org.apache.heron.spi.common.Config)1 PackingPlanProtoDeserializer (org.apache.heron.spi.packing.PackingPlanProtoDeserializer)1 PackingPlanProtoSerializer (org.apache.heron.spi.packing.PackingPlanProtoSerializer)1 Test (org.junit.Test)1