Search in sources :

Example 1 with IRepacking

use of com.twitter.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, 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 = packing.repack(currentPackingPlan, componentChanges);
        return serializer.toProto(packedPlan);
    } finally {
        SysUtils.closeIgnoringExceptions(packing);
    }
}
Also used : PackingPlanProtoDeserializer(com.twitter.heron.spi.packing.PackingPlanProtoDeserializer) PackingPlanProtoSerializer(com.twitter.heron.spi.packing.PackingPlanProtoSerializer) IRepacking(com.twitter.heron.spi.packing.IRepacking) PackingPlan(com.twitter.heron.spi.packing.PackingPlan) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 2 with IRepacking

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

the class RuntimeManagerRunner method buildNewPackingPlan.

@VisibleForTesting
PackingPlans.PackingPlan buildNewPackingPlan(PackingPlans.PackingPlan currentProtoPlan, Map<String, Integer> changeRequests, 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 = packing.repack(currentPackingPlan, componentChanges);
        return serializer.toProto(packedPlan);
    } finally {
        SysUtils.closeIgnoringExceptions(packing);
    }
}
Also used : PackingPlanProtoDeserializer(com.twitter.heron.spi.packing.PackingPlanProtoDeserializer) PackingPlanProtoSerializer(com.twitter.heron.spi.packing.PackingPlanProtoSerializer) IRepacking(com.twitter.heron.spi.packing.IRepacking) PackingPlan(com.twitter.heron.spi.packing.PackingPlan) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 3 with IRepacking

use of com.twitter.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(com.twitter.heron.spi.packing.IRepacking)

Example 4 with IRepacking

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

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 = topologyProvider.get();
    try {
        packing.initialize(config, topology);
        return packing.repack(currentPackingPlan, componentDeltas);
    } finally {
        SysUtils.closeIgnoringExceptions(packing);
    }
}
Also used : HashMap(java.util.HashMap) IRepacking(com.twitter.heron.spi.packing.IRepacking) Topology(com.twitter.heron.api.generated.TopologyAPI.Topology) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 5 with IRepacking

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

the class ScaleUpResolverTest method testBuildPackingPlan.

@Test
public void testBuildPackingPlan() {
    TopologyAPI.Topology topology = createTestTopology();
    TopologyProvider topologyProvider = createTopologyProvider(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 : HashMap(java.util.HashMap) IRepacking(com.twitter.heron.spi.packing.IRepacking) TopologyProvider(com.twitter.heron.healthmgr.common.TopologyProvider) Config(com.twitter.heron.spi.common.Config) PackingPlan(com.twitter.heron.spi.packing.PackingPlan) TopologyAPI(com.twitter.heron.api.generated.TopologyAPI) Test(org.junit.Test)

Aggregations

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