Search in sources :

Example 1 with PackingPlanProtoSerializer

use of com.twitter.heron.spi.packing.PackingPlanProtoSerializer in project heron by twitter.

the class SchedulerUtils method persistUpdatedPackingPlan.

/**
   * Replaces persisted packing plan in state manager.
   */
public static void persistUpdatedPackingPlan(String topologyName, PackingPlan updatedPackingPlan, SchedulerStateManagerAdaptor stateManager) {
    LOG.log(Level.INFO, "Updating scheduled-resource in packing plan: {0}", topologyName);
    PackingPlanProtoSerializer serializer = new PackingPlanProtoSerializer();
    if (!stateManager.updatePackingPlan(serializer.toProto(updatedPackingPlan), topologyName)) {
        throw new RuntimeException(String.format("Failed to update packing plan for topology %s", topologyName));
    }
}
Also used : PackingPlanProtoSerializer(com.twitter.heron.spi.packing.PackingPlanProtoSerializer)

Example 2 with PackingPlanProtoSerializer

use of com.twitter.heron.spi.packing.PackingPlanProtoSerializer in project heron by twitter.

the class UpdateTopologyManagerTest method init.

@Before
public void init() {
    Integer[] instanceIndexA = new Integer[] { 37, 48, 59 };
    Integer[] instanceIndexB = new Integer[] { 17, 22 };
    currentContainerPlan = buildContainerSet(new Integer[] { 1, 2, 3, 4 }, instanceIndexA);
    proposedContainerPlan = buildContainerSet(new Integer[] { 1, 3, 5, 6 }, instanceIndexB);
    expectedContainersToAdd = buildContainerSet(new Integer[] { 5, 6 }, instanceIndexB);
    expectedContainersToRemove = buildContainerSet(new Integer[] { 2, 4 }, instanceIndexA);
    PackingPlanProtoSerializer serializer = new PackingPlanProtoSerializer();
    PackingPlan currentPacking = new PackingPlan("current", currentContainerPlan);
    proposedPacking = new PackingPlan("proposed", proposedContainerPlan);
    currentProtoPlan = serializer.toProto(currentPacking);
    proposedProtoPlan = serializer.toProto(proposedPacking);
    testTopology = TopologyTests.createTopology(TOPOLOGY_NAME, new com.twitter.heron.api.Config(), "spoutname", "boltname", 1, 1);
    assertEquals(TopologyAPI.TopologyState.RUNNING, testTopology.getState());
}
Also used : PackingPlanProtoSerializer(com.twitter.heron.spi.packing.PackingPlanProtoSerializer) Config(com.twitter.heron.spi.common.Config) PackingPlan(com.twitter.heron.spi.packing.PackingPlan) Before(org.junit.Before)

Example 3 with PackingPlanProtoSerializer

use of com.twitter.heron.spi.packing.PackingPlanProtoSerializer 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 4 with PackingPlanProtoSerializer

use of com.twitter.heron.spi.packing.PackingPlanProtoSerializer 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 5 with PackingPlanProtoSerializer

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

the class UpdateTopologyManagerTest method init.

@Before
public void init() {
    Integer[] instanceIndexA = new Integer[] { 37, 48, 59 };
    Integer[] instanceIndexB = new Integer[] { 17, 22 };
    currentContainerPlan = buildContainerSet(new Integer[] { 1, 2, 3, 4 }, instanceIndexA);
    proposedContainerPlan = buildContainerSet(new Integer[] { 1, 3, 5, 6 }, instanceIndexB);
    expectedContainersToAdd = buildContainerSet(new Integer[] { 5, 6 }, instanceIndexB);
    expectedContainersToRemove = buildContainerSet(new Integer[] { 2, 4 }, instanceIndexA);
    PackingPlanProtoSerializer serializer = new PackingPlanProtoSerializer();
    PackingPlan currentPacking = new PackingPlan("current", currentContainerPlan);
    proposedPacking = new PackingPlan("proposed", proposedContainerPlan);
    currentProtoPlan = serializer.toProto(currentPacking);
    proposedProtoPlan = serializer.toProto(proposedPacking);
    testTopology = TopologyTests.createTopology(TOPOLOGY_NAME, new com.twitter.heron.api.Config(), "spoutname", "boltname", 1, 1);
    assertEquals(TopologyAPI.TopologyState.RUNNING, testTopology.getState());
}
Also used : PackingPlanProtoSerializer(com.twitter.heron.spi.packing.PackingPlanProtoSerializer) Config(com.twitter.heron.spi.common.Config) PackingPlan(com.twitter.heron.spi.packing.PackingPlan) Before(org.junit.Before)

Aggregations

PackingPlanProtoSerializer (com.twitter.heron.spi.packing.PackingPlanProtoSerializer)9 PackingPlan (com.twitter.heron.spi.packing.PackingPlan)7 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 Config (com.twitter.heron.spi.common.Config)2 IRepacking (com.twitter.heron.spi.packing.IRepacking)2 PackingPlanProtoDeserializer (com.twitter.heron.spi.packing.PackingPlanProtoDeserializer)2 Before (org.junit.Before)2 TopologyAPI (com.twitter.heron.api.generated.TopologyAPI)1 PackingPlans (com.twitter.heron.proto.system.PackingPlans)1 HashSet (java.util.HashSet)1