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);
}
}
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);
}
}
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);
}
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);
}
}
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);
}
Aggregations