use of org.apache.heron.spi.packing.PackingPlan in project heron by twitter.
the class RoundRobinPackingTest method testNoRamMapWithoutContainerRequestedResources.
@Test
public void testNoRamMapWithoutContainerRequestedResources() throws Exception {
// Explicit set resources for container
// max container resource is 6G
ByteAmount containerRam = ByteAmount.fromGigabytes(6);
ByteAmount containerDisk = ByteAmount.fromGigabytes(20);
double containerCpu = 30;
Resource containerResource = new Resource(containerCpu, containerRam, containerDisk);
// Container RAM is not set in config
topologyConfig.setContainerDiskRequested(containerDisk);
topologyConfig.setContainerCpuRequested(containerCpu);
topology = getTopology(spoutParallelism, boltParallelism, topologyConfig);
PackingPlan packingPlan = doPackingTestWithPartialResource(topology, Optional.empty(), Optional.empty(), boltParallelism, Optional.empty(), Optional.empty(), spoutParallelism, numContainers, getDefaultPadding(), containerResource);
for (PackingPlan.ContainerPlan containerPlan : packingPlan.getContainers()) {
// All instances' resource requirement should be equal
// So the size of set should be 1
Set<Resource> differentResources = new HashSet<>();
for (PackingPlan.InstancePlan instancePlan : containerPlan.getInstances()) {
differentResources.add(instancePlan.getResource());
}
Assert.assertEquals(1, differentResources.size());
int instancesCount = containerPlan.getInstances().size();
Assert.assertEquals(containerRam.minus(RoundRobinPacking.DEFAULT_RAM_PADDING_PER_CONTAINER).divide(instancesCount), differentResources.iterator().next().getRam());
Assert.assertEquals((containerCpu - RoundRobinPacking.DEFAULT_CPU_PADDING_PER_CONTAINER) / instancesCount, differentResources.iterator().next().getCpu(), DELTA);
}
}
use of org.apache.heron.spi.packing.PackingPlan in project heron by twitter.
the class RoundRobinPackingTest method testRepackingWithSameTotalInstances.
/**
* test re-packing with same total instances
*/
@Test
public void testRepackingWithSameTotalInstances() throws Exception {
int componentParallelism = 4;
boltParallelism = componentParallelism;
spoutParallelism = componentParallelism;
topology = getTopology(spoutParallelism, boltParallelism, topologyConfig);
PackingPlan packingPlan = doPackingTestWithPartialResource(topology, Optional.empty(), Optional.empty(), boltParallelism, Optional.empty(), Optional.empty(), spoutParallelism, numContainers, getDefaultPadding(), getDefaultUnspecifiedContainerResource(boltParallelism + spoutParallelism, numContainers, getDefaultPadding()));
Map<String, Integer> componentChanges = new HashMap<>();
componentChanges.put(SPOUT_NAME, -1);
componentChanges.put(BOLT_NAME, +1);
doScalingTestWithPartialResource(topology, packingPlan, componentChanges, Optional.empty(), Optional.empty(), boltParallelism, Optional.empty(), Optional.empty(), spoutParallelism, numContainers, getDefaultPadding(), getDefaultUnspecifiedContainerResource(boltParallelism + spoutParallelism, numContainers, getDefaultPadding()));
}
use of org.apache.heron.spi.packing.PackingPlan in project heron by twitter.
the class LaunchRunner method call.
/**
* Call launcher to launch topology
*
* @throws LauncherException
* @throws PackingException
* @throws SubmitDryRunResponse
*/
public void call() throws LauncherException, PackingException, SubmitDryRunResponse {
SchedulerStateManagerAdaptor statemgr = Runtime.schedulerStateManagerAdaptor(runtime);
TopologyAPI.Topology topology = Runtime.topology(runtime);
String topologyName = Context.topologyName(config);
PackingPlan packedPlan = LauncherUtils.getInstance().createPackingPlan(config, runtime);
if (Context.dryRun(config)) {
throw new SubmitDryRunResponse(topology, config, packedPlan);
}
// initialize the launcher
launcher.initialize(config, runtime);
// Set topology def first since we determine whether a topology is running
// by checking the existence of topology def
// store the trimmed topology definition into the state manager
// TODO(rli): log-and-false anti-pattern is too nested on this path. will not refactor
Boolean result = statemgr.setTopology(trimTopology(topology), topologyName);
if (result == null || !result) {
throw new LauncherException(String.format("Failed to set topology definition for topology '%s'", topologyName));
}
result = statemgr.setPackingPlan(createPackingPlan(packedPlan), topologyName);
if (result == null || !result) {
statemgr.deleteTopology(topologyName);
throw new LauncherException(String.format("Failed to set packing plan for topology '%s'", topologyName));
}
// store the execution state into the state manager
ExecutionEnvironment.ExecutionState executionState = createExecutionState();
result = statemgr.setExecutionState(executionState, topologyName);
if (result == null || !result) {
statemgr.deletePackingPlan(topologyName);
statemgr.deleteTopology(topologyName);
throw new LauncherException(String.format("Failed to set execution state for topology '%s'", topologyName));
}
// returning false. In some cases the scheduler needs to have the topology deleted.
try {
if (!launcher.launch(packedPlan)) {
throw new TopologySubmissionException(null);
}
} catch (TopologySubmissionException e) {
// Compile error message to throw.
final StringBuilder errorMessage = new StringBuilder(String.format("Failed to launch topology '%s'", topologyName));
if (e.getMessage() != null) {
errorMessage.append("\n").append(e.getMessage());
}
try {
// Clear state from the Scheduler via RPC.
Scheduler.KillTopologyRequest killTopologyRequest = Scheduler.KillTopologyRequest.newBuilder().setTopologyName(topologyName).build();
ISchedulerClient schedulerClient = new SchedulerClientFactory(config, runtime).getSchedulerClient();
if (!schedulerClient.killTopology(killTopologyRequest)) {
final String logMessage = String.format("Failed to remove topology '%s' from scheduler after failed submit. " + "Please re-try the kill command.", topologyName);
errorMessage.append("\n").append(logMessage);
LOG.log(Level.SEVERE, logMessage);
}
// SUPPRESS CHECKSTYLE IllegalCatch
} catch (Exception ignored) {
// The above call to clear the Scheduler may fail. This situation can be ignored.
LOG.log(Level.FINE, String.format("Failure clearing failed topology `%s` from Scheduler during `submit`", topologyName));
}
// Clear state from the State Manager.
statemgr.deleteExecutionState(topologyName);
statemgr.deletePackingPlan(topologyName);
statemgr.deleteTopology(topologyName);
throw new LauncherException(errorMessage.toString());
}
}
use of org.apache.heron.spi.packing.PackingPlan in project heron by twitter.
the class PackingPlanBuilderTest method doCreatePackingPlanTest.
private static PackingPlan doCreatePackingPlanTest(Pair<Integer, InstanceId>[] instances) throws ConstraintViolationException {
PackingPlan plan = PackingTestHelper.createTestPackingPlan(TOPOLOGY_ID, PackingTestHelper.toContainerIdComponentNames(instances), 0);
AssertPacking.assertPackingPlan(TOPOLOGY_ID, instances, plan);
return plan;
}
use of org.apache.heron.spi.packing.PackingPlan 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);
}
Aggregations