Search in sources :

Example 16 with PackingPlan

use of org.apache.heron.spi.packing.PackingPlan in project heron by twitter.

the class LocalSchedulerTest method testRemoveContainer.

/**
 * Verify containers can be removed by Local Scheduler
 */
@Test
public void testRemoveContainer() throws Exception {
    final int LOCAL_NUM_CONTAINER = 6;
    // verify plan is deployed and containers are created
    Mockito.doNothing().when(scheduler).startExecutorMonitor(Mockito.anyInt(), Mockito.any(Process.class), Mockito.anySet());
    Process[] processes = new Process[LOCAL_NUM_CONTAINER];
    Set<PackingPlan.ContainerPlan> existingContainers = new HashSet<>();
    for (int i = 0; i < LOCAL_NUM_CONTAINER; i++) {
        processes[i] = Mockito.mock(Process.class);
        Set<PackingPlan.InstancePlan> instances = (i == 0) ? null : PackingTestUtils.testContainerPlan(i).getInstances();
        Mockito.doReturn(processes[i]).when(scheduler).startExecutorProcess(i, instances);
        if (i > 0) {
            // ignore the container for TManager. existing containers simulate the containers created
            // by packing plan
            existingContainers.add(PackingTestUtils.testContainerPlan(i));
        }
    }
    PackingPlan packingPlan = Mockito.mock(PackingPlan.class);
    Mockito.when(packingPlan.getContainers()).thenReturn(existingContainers);
    Assert.assertTrue(scheduler.onSchedule(packingPlan));
    verifyIdsOfLaunchedContainers(0, 1, 2, 3, 4, 5);
    Mockito.verify(scheduler, Mockito.times(LOCAL_NUM_CONTAINER)).startExecutor(Mockito.anyInt(), Mockito.anySet());
    Set<PackingPlan.ContainerPlan> containersToRemove = new HashSet<>();
    PackingPlan.ContainerPlan containerToRemove = PackingTestUtils.testContainerPlan(LOCAL_NUM_CONTAINER - 1);
    containersToRemove.add(containerToRemove);
    scheduler.removeContainers(containersToRemove);
    verifyIdsOfLaunchedContainers(0, 1, 2, 3, 4);
    Mockito.verify(processes[LOCAL_NUM_CONTAINER - 1]).destroy();
    // verify no new process restarts
    Mockito.verify(scheduler, Mockito.times(LOCAL_NUM_CONTAINER)).startExecutor(Mockito.anyInt(), Mockito.anySet());
    containersToRemove.clear();
    containersToRemove.add(PackingTestUtils.testContainerPlan(1));
    containersToRemove.add(PackingTestUtils.testContainerPlan(2));
    scheduler.removeContainers(containersToRemove);
    verifyIdsOfLaunchedContainers(0, 3, 4);
    Mockito.verify(processes[1]).destroy();
    Mockito.verify(processes[2]).destroy();
    // verify no new process restarts
    Mockito.verify(scheduler, Mockito.times(LOCAL_NUM_CONTAINER)).startExecutor(Mockito.anyInt(), Mockito.anySet());
}
Also used : PackingPlan(org.apache.heron.spi.packing.PackingPlan) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 17 with PackingPlan

use of org.apache.heron.spi.packing.PackingPlan in project heron by twitter.

the class KubernetesController method getContainerResource.

Resource getContainerResource(PackingPlan packingPlan) {
    // Align resources to maximal requested resource
    PackingPlan updatedPackingPlan = packingPlan.cloneWithHomogeneousScheduledResource();
    SchedulerUtils.persistUpdatedPackingPlan(Runtime.topologyName(runtimeConfiguration), updatedPackingPlan, Runtime.schedulerStateManagerAdaptor(runtimeConfiguration));
    return updatedPackingPlan.getContainers().iterator().next().getScheduledResource().get();
}
Also used : PackingPlan(org.apache.heron.spi.packing.PackingPlan)

Example 18 with PackingPlan

use of org.apache.heron.spi.packing.PackingPlan in project heron by twitter.

the class MarathonScheduler method getTopologyConf.

protected String getTopologyConf(PackingPlan packing) {
    config = Config.newBuilder().putAll(config).put(Key.TOPOLOGY_BINARY_FILE, Context.topologyBinaryFile(config)).build();
    ObjectMapper mapper = new ObjectMapper();
    // TODO (nlu): use heterogeneous resources
    // Align resources to maximal requested resource
    PackingPlan updatedPackingPlan = packing.cloneWithHomogeneousScheduledResource();
    SchedulerUtils.persistUpdatedPackingPlan(Runtime.topologyName(runtime), updatedPackingPlan, Runtime.schedulerStateManagerAdaptor(runtime));
    Resource containerResource = updatedPackingPlan.getContainers().iterator().next().getRequiredResource();
    // Create app conf list for each container
    ArrayNode instances = mapper.createArrayNode();
    for (int i = 0; i < Runtime.numContainers(runtime); i++) {
        ObjectNode instance = mapper.createObjectNode();
        instance.put(MarathonConstants.ID, marathonGroupId + "/" + Integer.toString(i));
        instance.put(MarathonConstants.COMMAND, getExecutorCommand(i));
        instance.put(MarathonConstants.CPU, containerResource.getCpu());
        instance.set(MarathonConstants.CONTAINER, getContainer(mapper));
        instance.put(MarathonConstants.MEMORY, containerResource.getRam().asMegabytes());
        instance.put(MarathonConstants.DISK, containerResource.getDisk().asMegabytes());
        instance.put(MarathonConstants.INSTANCES, 1);
        instance.set(MarathonConstants.LABELS, getLabels(mapper));
        instance.set(MarathonConstants.FETCH, getFetchList(mapper));
        instances.add(instance);
    }
    // Create marathon group for a topology
    ObjectNode appConf = mapper.createObjectNode();
    appConf.put(MarathonConstants.ID, marathonGroupId);
    appConf.set(MarathonConstants.APPS, instances);
    return appConf.toString();
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) PackingPlan(org.apache.heron.spi.packing.PackingPlan) Resource(org.apache.heron.spi.packing.Resource) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 19 with PackingPlan

use of org.apache.heron.spi.packing.PackingPlan in project heron by twitter.

the class SchedulerMainTest method updateNumContainersIfNeeded.

@Test
public void updateNumContainersIfNeeded() {
    int configuredNumContainers = 4;
    int configuredNumStreamManagers = configuredNumContainers - 1;
    int packingPlanSize = 1;
    SubmitterMain submitterMain = new SubmitterMain(Config.newBuilder().put(Key.PACKING_CLASS, "org.apache.heron.packing.roundrobin.ResourceCompliantRRPacking").build(), null);
    PackingPlan packingPlan = PackingTestUtils.testPackingPlan(TOPOLOGY_NAME, new RoundRobinPacking());
    assertEquals(packingPlanSize, packingPlan.getContainers().size());
    org.apache.heron.api.Config apiConfig = new org.apache.heron.api.Config();
    apiConfig.setNumStmgrs(configuredNumStreamManagers);
    TopologyAPI.Topology initialTopology = TopologyTests.createTopology(TOPOLOGY_NAME, apiConfig, new HashMap<String, Integer>(), new HashMap<String, Integer>());
    Config initialConfig = Config.newBuilder().put(Key.NUM_CONTAINERS, configuredNumContainers).put(Key.PACKING_CLASS, RoundRobinPacking.class.getName()).put(Key.TOPOLOGY_DEFINITION, initialTopology).build();
    // assert preconditions
    assertEquals(Integer.toString(configuredNumStreamManagers), apiConfig.get(org.apache.heron.api.Config.TOPOLOGY_STMGRS));
    assertEquals(configuredNumStreamManagers, TopologyUtils.getNumContainers(initialTopology));
    assertContainerCount(configuredNumStreamManagers, initialConfig);
    Config newConfig = submitterMain.updateNumContainersIfNeeded(initialConfig, initialTopology, packingPlan);
    assertContainerCount(packingPlanSize, newConfig);
}
Also used : RoundRobinPacking(org.apache.heron.packing.roundrobin.RoundRobinPacking) Config(org.apache.heron.spi.common.Config) PackingPlan(org.apache.heron.spi.packing.PackingPlan) Mockito.anyString(org.mockito.Mockito.anyString) TopologyAPI(org.apache.heron.api.generated.TopologyAPI) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 20 with PackingPlan

use of org.apache.heron.spi.packing.PackingPlan in project heron by twitter.

the class LaunchRunnerTest method createRunnerRuntime.

private static Config createRunnerRuntime(org.apache.heron.api.Config topologyConfig) throws Exception {
    Config runtime = spy(Config.newBuilder().build());
    ILauncher launcher = mock(ILauncher.class);
    IPacking packing = mock(IPacking.class);
    SchedulerStateManagerAdaptor adaptor = mock(SchedulerStateManagerAdaptor.class);
    TopologyAPI.Topology topology = createTopology(topologyConfig);
    doReturn(launcher).when(runtime).get(Key.LAUNCHER_CLASS_INSTANCE);
    doReturn(adaptor).when(runtime).get(Key.SCHEDULER_STATE_MANAGER_ADAPTOR);
    doReturn(topology).when(runtime).get(Key.TOPOLOGY_DEFINITION);
    PackingPlan packingPlan = mock(PackingPlan.class);
    when(packingPlan.getContainers()).thenReturn(new HashSet<ContainerPlan>());
    when(packingPlan.getComponentRamDistribution()).thenReturn("ramdist");
    when(packingPlan.getId()).thenReturn("packing_plan_id");
    Set<ContainerPlan> containerPlans = new HashSet<>();
    // just need it to be of size 1
    containerPlans.add(PackingTestUtils.testContainerPlan(1));
    when(packingPlan.getContainers()).thenReturn(containerPlans);
    when(packing.pack()).thenReturn(packingPlan);
    LauncherUtils mockLauncherUtils = mock(LauncherUtils.class);
    when(mockLauncherUtils.createPackingPlan(any(Config.class), any(Config.class))).thenReturn(packingPlan);
    PowerMockito.spy(LauncherUtils.class);
    PowerMockito.doReturn(mockLauncherUtils).when(LauncherUtils.class, "getInstance");
    return runtime;
}
Also used : ContainerPlan(org.apache.heron.spi.packing.PackingPlan.ContainerPlan) IPacking(org.apache.heron.spi.packing.IPacking) ILauncher(org.apache.heron.spi.scheduler.ILauncher) Config(org.apache.heron.spi.common.Config) PackingPlan(org.apache.heron.spi.packing.PackingPlan) LauncherUtils(org.apache.heron.scheduler.utils.LauncherUtils) SchedulerStateManagerAdaptor(org.apache.heron.spi.statemgr.SchedulerStateManagerAdaptor) TopologyAPI(org.apache.heron.api.generated.TopologyAPI) 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