Search in sources :

Example 56 with PackingPlan

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);
    }
}
Also used : ByteAmount(org.apache.heron.common.basics.ByteAmount) PackingPlan(org.apache.heron.spi.packing.PackingPlan) Resource(org.apache.heron.spi.packing.Resource) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 57 with PackingPlan

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()));
}
Also used : HashMap(java.util.HashMap) PackingPlan(org.apache.heron.spi.packing.PackingPlan) Test(org.junit.Test)

Example 58 with PackingPlan

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());
    }
}
Also used : LauncherException(org.apache.heron.spi.scheduler.LauncherException) ExecutionEnvironment(org.apache.heron.proto.system.ExecutionEnvironment) PackingPlan(org.apache.heron.spi.packing.PackingPlan) SchedulerClientFactory(org.apache.heron.scheduler.client.SchedulerClientFactory) PackingException(org.apache.heron.spi.packing.PackingException) LauncherException(org.apache.heron.spi.scheduler.LauncherException) SchedulerStateManagerAdaptor(org.apache.heron.spi.statemgr.SchedulerStateManagerAdaptor) TopologyAPI(org.apache.heron.api.generated.TopologyAPI) SubmitDryRunResponse(org.apache.heron.scheduler.dryrun.SubmitDryRunResponse) ISchedulerClient(org.apache.heron.scheduler.client.ISchedulerClient)

Example 59 with PackingPlan

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;
}
Also used : PackingPlan(org.apache.heron.spi.packing.PackingPlan)

Example 60 with PackingPlan

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);
}
Also used : InstanceId(org.apache.heron.spi.packing.InstanceId) PackingPlan(org.apache.heron.spi.packing.PackingPlan) Resource(org.apache.heron.spi.packing.Resource) HashSet(java.util.HashSet)

Aggregations

PackingPlan (org.apache.heron.spi.packing.PackingPlan)83 Test (org.junit.Test)43 HashSet (java.util.HashSet)32 Resource (org.apache.heron.spi.packing.Resource)18 Config (org.apache.heron.spi.common.Config)15 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)14 ByteAmount (org.apache.heron.common.basics.ByteAmount)13 HashMap (java.util.HashMap)10 SchedulerStateManagerAdaptor (org.apache.heron.spi.statemgr.SchedulerStateManagerAdaptor)9 TopologyAPI (org.apache.heron.api.generated.TopologyAPI)8 RoundRobinPacking (org.apache.heron.packing.roundrobin.RoundRobinPacking)7 InstanceId (org.apache.heron.spi.packing.InstanceId)7 Pair (org.apache.heron.common.basics.Pair)6 PackingPlans (org.apache.heron.proto.system.PackingPlans)6 PackingPlanProtoDeserializer (org.apache.heron.spi.packing.PackingPlanProtoDeserializer)6 ContainerPlan (org.apache.heron.spi.packing.PackingPlan.ContainerPlan)5 ArrayList (java.util.ArrayList)4 PackingPlanProtoSerializer (org.apache.heron.spi.packing.PackingPlanProtoSerializer)4 EvaluatorRequest (org.apache.reef.driver.evaluator.EvaluatorRequest)4 Before (org.junit.Before)3