Search in sources :

Example 66 with PackingPlan

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

the class ResourceCompliantRRPackingTest method removeFirstContainer.

/**
   * Test the scenario where the scaling down is requested and the first container is removed
   */
@Test
public void removeFirstContainer() throws Exception {
    int spoutScalingDown = -3;
    int boltScalingDown = -3;
    /* The packing plan consists of two containers. The first one contains 2 spouts and 2 bolts
       the second one contains 2 spouts and 1 bolt. During scaling we remove 3 spouts and 3 bolts
       and thus the first container is removed.
     */
    Map<String, Integer> componentChanges = new HashMap<>();
    //leave 1 spout
    componentChanges.put(SPOUT_NAME, spoutScalingDown);
    //leave 1 bolt
    componentChanges.put(BOLT_NAME, boltScalingDown);
    int numContainersBeforeRepack = 2;
    PackingPlan newPackingPlan = doDefaultScalingTest(componentChanges, numContainersBeforeRepack);
    Assert.assertEquals(1, newPackingPlan.getContainers().size());
    Assert.assertEquals((Integer) (totalInstances + spoutScalingDown + boltScalingDown), newPackingPlan.getInstanceCount());
    AssertPacking.assertNumInstances(newPackingPlan.getContainers(), BOLT_NAME, 0);
    AssertPacking.assertNumInstances(newPackingPlan.getContainers(), SPOUT_NAME, 1);
}
Also used : HashMap(java.util.HashMap) PackingPlan(com.twitter.heron.spi.packing.PackingPlan) Test(org.junit.Test)

Example 67 with PackingPlan

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

the class PackingTestUtils method testProtoPackingPlan.

public static PackingPlans.PackingPlan testProtoPackingPlan(String topologyName, IPacking packing) {
    PackingPlan plan = testPackingPlan(topologyName, packing);
    PackingPlanProtoSerializer serializer = new PackingPlanProtoSerializer();
    return serializer.toProto(plan);
}
Also used : PackingPlanProtoSerializer(com.twitter.heron.spi.packing.PackingPlanProtoSerializer) PackingPlan(com.twitter.heron.spi.packing.PackingPlan)

Example 68 with PackingPlan

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

the class SlurmSchedulerTest method testOnSchedule.

/**
   * Test the schedule method
   * @throws Exception
   */
@Test
public void testOnSchedule() throws Exception {
    SlurmController controller = Mockito.mock(SlurmController.class);
    Mockito.doReturn(controller).when(scheduler).getController();
    Config config = createRunnerConfig();
    Config runtime = Mockito.mock(Config.class);
    PowerMockito.spy(SlurmContext.class);
    PowerMockito.doReturn(WORKING_DIRECTORY).when(SlurmContext.class, "workingDirectory", config);
    scheduler.initialize(config, runtime);
    // Fail to schedule due to null PackingPlan
    Assert.assertFalse(scheduler.onSchedule(null));
    PackingPlan plan = new PackingPlan(PACKING_PLAN_ID, new HashSet<PackingPlan.ContainerPlan>());
    Assert.assertTrue(plan.getContainers().isEmpty());
    // Fail to schedule due to PackingPlan is empty
    Assert.assertFalse(scheduler.onSchedule(plan));
    // Construct valid PackingPlan
    Set<PackingPlan.ContainerPlan> containers = new HashSet<>();
    containers.add(Mockito.mock(PackingPlan.ContainerPlan.class));
    PackingPlan validPlan = new PackingPlan(PACKING_PLAN_ID, containers);
    // Failed to create job via controller
    Mockito.doReturn(false).when(controller).createJob(Mockito.anyString(), Mockito.anyString(), Matchers.any(String[].class), Mockito.anyString(), Mockito.anyInt());
    Assert.assertFalse(scheduler.onSchedule(validPlan));
    Mockito.verify(controller).createJob(Mockito.eq(SLURM_PATH), Mockito.anyString(), Matchers.any(String[].class), Mockito.anyString(), Mockito.anyInt());
    // Happy path
    Mockito.doReturn(true).when(controller).createJob(Mockito.anyString(), Mockito.anyString(), Matchers.any(String[].class), Mockito.anyString(), Mockito.anyInt());
    Assert.assertTrue(scheduler.onSchedule(validPlan));
    Mockito.verify(controller, Mockito.times(2)).createJob(Mockito.anyString(), Mockito.anyString(), Matchers.any(String[].class), Mockito.anyString(), Mockito.anyInt());
}
Also used : Config(com.twitter.heron.spi.common.Config) PackingPlan(com.twitter.heron.spi.packing.PackingPlan) HashSet(java.util.HashSet) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 69 with PackingPlan

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

the class HeronMasterDriverTest method killWorkersTerminatesSpecificContainers.

@Test
public void killWorkersTerminatesSpecificContainers() throws Exception {
    int numContainers = 5;
    Set<PackingPlan.ContainerPlan> containers = new HashSet<>();
    for (int id = 0; id < numContainers; id++) {
        containers.add(PackingTestUtils.testContainerPlan(id));
    }
    PackingPlan packingPlan = new PackingPlan("packing", containers);
    spyDriver.scheduleHeronWorkers(packingPlan);
    for (int id = 0; id < numContainers; id++) {
        verify(spyDriver, times(1)).requestContainerForWorker(eq(id), anyHeronWorker());
        assertTrue(spyDriver.lookupByContainerPlan(id).isPresent());
    }
    verify(mockRequestor, times(numContainers)).submit(any(EvaluatorRequest.class));
    AllocatedEvaluator[] mockEvaluators = createApplicationWithContainers(numContainers);
    Set<PackingPlan.ContainerPlan> containersTobeDeleted = new HashSet<>();
    containersTobeDeleted.add(PackingTestUtils.testContainerPlan(2));
    containersTobeDeleted.add(PackingTestUtils.testContainerPlan(3));
    spyDriver.killWorkers(containersTobeDeleted);
    for (int id = 0; id < numContainers; id++) {
        if (id == 2 || id == 3) {
            verify(mockEvaluators[id], times(1)).close();
            assertFalse(spyDriver.lookupByContainerPlan(id).isPresent());
            assertFalse(spyDriver.lookupByEvaluatorId("e" + id).isPresent());
            continue;
        }
        verify(mockEvaluators[id], never()).close();
        assertTrue(spyDriver.lookupByContainerPlan(id).isPresent());
        assertTrue(spyDriver.lookupByEvaluatorId("e" + id).isPresent());
    }
}
Also used : PackingPlan(com.twitter.heron.spi.packing.PackingPlan) EvaluatorRequest(org.apache.reef.driver.evaluator.EvaluatorRequest) HashSet(java.util.HashSet) AllocatedEvaluator(org.apache.reef.driver.evaluator.AllocatedEvaluator) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 70 with PackingPlan

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

the class HeronMasterDriverTest method scheduleHeronWorkersAddsContainers.

@Test
public void scheduleHeronWorkersAddsContainers() throws Exception {
    PackingPlan packingPlan = PackingTestUtils.testPackingPlan("test", new RoundRobinPacking());
    spyDriver.scheduleHeronWorkers(packingPlan);
    verify(spyDriver, times(1)).requestContainerForWorker(eq(1), anyHeronWorker());
    verify(mockRequestor, times(1)).submit(any(EvaluatorRequest.class));
    Set<PackingPlan.ContainerPlan> toBeAddedContainerPlans = new HashSet<>();
    toBeAddedContainerPlans.add(PackingTestUtils.testContainerPlan(2));
    toBeAddedContainerPlans.add(PackingTestUtils.testContainerPlan(3));
    spyDriver.scheduleHeronWorkers(toBeAddedContainerPlans);
    verify(spyDriver, times(1)).requestContainerForWorker(eq(2), anyHeronWorker());
    verify(spyDriver, times(1)).requestContainerForWorker(eq(3), anyHeronWorker());
    verify(mockRequestor, times(3)).submit(any(EvaluatorRequest.class));
}
Also used : RoundRobinPacking(com.twitter.heron.packing.roundrobin.RoundRobinPacking) PackingPlan(com.twitter.heron.spi.packing.PackingPlan) EvaluatorRequest(org.apache.reef.driver.evaluator.EvaluatorRequest) HashSet(java.util.HashSet) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

PackingPlan (com.twitter.heron.spi.packing.PackingPlan)87 Test (org.junit.Test)63 TopologyAPI (com.twitter.heron.api.generated.TopologyAPI)34 ByteAmount (com.twitter.heron.common.basics.ByteAmount)27 HashSet (java.util.HashSet)22 HashMap (java.util.HashMap)20 Config (com.twitter.heron.spi.common.Config)18 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)13 Resource (com.twitter.heron.spi.packing.Resource)10 InstanceId (com.twitter.heron.spi.packing.InstanceId)7 SchedulerStateManagerAdaptor (com.twitter.heron.spi.statemgr.SchedulerStateManagerAdaptor)7 Pair (com.twitter.heron.common.basics.Pair)6 RoundRobinPacking (com.twitter.heron.packing.roundrobin.RoundRobinPacking)5 PackingPlanProtoDeserializer (com.twitter.heron.spi.packing.PackingPlanProtoDeserializer)4 EvaluatorRequest (org.apache.reef.driver.evaluator.EvaluatorRequest)4 VisibleForTesting (com.google.common.annotations.VisibleForTesting)3 PackingPlans (com.twitter.heron.proto.system.PackingPlans)3 LauncherUtils (com.twitter.heron.scheduler.utils.LauncherUtils)3 ContainerPlan (com.twitter.heron.spi.packing.PackingPlan.ContainerPlan)3 PackingPlanProtoSerializer (com.twitter.heron.spi.packing.PackingPlanProtoSerializer)3