Search in sources :

Example 1 with IPacking

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

the class LauncherUtils method createPackingPlan.

/**
   * Returns a packing plan generated by configured packing class
   */
public PackingPlan createPackingPlan(final Config config, final Config runtime) throws PackingException {
    // Create an instance of the packing class
    String packingClass = Context.packingClass(config);
    IPacking packing;
    try {
        // create an instance of the packing class
        packing = ReflectionUtils.newInstance(packingClass);
    } catch (IllegalAccessException | InstantiationException | ClassNotFoundException e) {
        throw new PackingException(String.format("Failed to instantiate packing instance using packing class %s", packingClass), e);
    }
    try {
        TopologyAPI.Topology topology = Runtime.topology(runtime);
        packing.initialize(config, topology);
        return packing.pack();
    } finally {
        SysUtils.closeIgnoringExceptions(packing);
    }
}
Also used : IPacking(com.twitter.heron.spi.packing.IPacking) PackingException(com.twitter.heron.spi.packing.PackingException) TopologyAPI(com.twitter.heron.api.generated.TopologyAPI)

Example 2 with IPacking

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

the class LaunchRunnerTest method createRunnerRuntime.

private static Config createRunnerRuntime(com.twitter.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(com.twitter.heron.spi.packing.PackingPlan.ContainerPlan) IPacking(com.twitter.heron.spi.packing.IPacking) ILauncher(com.twitter.heron.spi.scheduler.ILauncher) Config(com.twitter.heron.spi.common.Config) PackingPlan(com.twitter.heron.spi.packing.PackingPlan) LauncherUtils(com.twitter.heron.scheduler.utils.LauncherUtils) SchedulerStateManagerAdaptor(com.twitter.heron.spi.statemgr.SchedulerStateManagerAdaptor) TopologyAPI(com.twitter.heron.api.generated.TopologyAPI) HashSet(java.util.HashSet)

Example 3 with IPacking

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

the class LauncherUtilsTest method generatesPackingPlan.

@Test
public void generatesPackingPlan() throws Exception {
    final String PACKING_CLASS = "nonExistingTestPackingClass";
    final PackingPlan mockPackingPlan = Mockito.mock(PackingPlan.class);
    IPacking mockPacking = Mockito.mock(IPacking.class);
    Mockito.when(mockPacking.pack()).thenReturn(mockPackingPlan);
    PowerMockito.spy(ReflectionUtils.class);
    PowerMockito.doReturn(mockPacking).when(ReflectionUtils.class, "newInstance", PACKING_CLASS);
    TopologyAPI.Topology mockTopology = PowerMockito.mock(TopologyAPI.Topology.class);
    Config mockConfig = Mockito.mock(Config.class);
    Mockito.when(mockConfig.getStringValue(Key.PACKING_CLASS)).thenReturn(PACKING_CLASS);
    Mockito.when(mockConfig.get(Key.TOPOLOGY_DEFINITION)).thenReturn(mockTopology);
    PackingPlan resultPacking = LauncherUtils.getInstance().createPackingPlan(mockConfig, mockConfig);
    Assert.assertEquals(mockPackingPlan, resultPacking);
    Mockito.verify(mockPacking).initialize(Mockito.any(Config.class), Mockito.eq(mockTopology));
    Mockito.verify(mockPacking).pack();
    Mockito.verify(mockPacking).close();
}
Also used : IPacking(com.twitter.heron.spi.packing.IPacking) Config(com.twitter.heron.spi.common.Config) PackingPlan(com.twitter.heron.spi.packing.PackingPlan) TopologyAPI(com.twitter.heron.api.generated.TopologyAPI) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 4 with IPacking

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

the class SubmitterMainTest method setUp.

@Before
public void setUp() throws Exception {
    // Mock objects to be verified
    IPacking packing = mock(IPacking.class);
    statemgr = mock(IStateManager.class);
    launcher = mock(ILauncher.class);
    uploader = mock(IUploader.class);
    // Mock ReflectionUtils stuff
    PowerMockito.spy(ReflectionUtils.class);
    PowerMockito.doReturn(statemgr).when(ReflectionUtils.class, "newInstance", STATE_MANAGER_CLASS);
    PowerMockito.doReturn(launcher).when(ReflectionUtils.class, "newInstance", LAUNCHER_CLASS);
    PowerMockito.doReturn(packing).when(ReflectionUtils.class, "newInstance", PACKING_CLASS);
    PowerMockito.doReturn(uploader).when(ReflectionUtils.class, "newInstance", UPLOADER_CLASS);
    config = mock(Config.class);
    when(config.getStringValue(Key.STATE_MANAGER_CLASS)).thenReturn(STATE_MANAGER_CLASS);
    when(config.getStringValue(Key.LAUNCHER_CLASS)).thenReturn(LAUNCHER_CLASS);
    when(config.getStringValue(Key.PACKING_CLASS)).thenReturn(PACKING_CLASS);
    when(config.getStringValue(Key.UPLOADER_CLASS)).thenReturn(UPLOADER_CLASS);
    when(packing.pack()).thenReturn(PackingTestUtils.testPackingPlan(TOPOLOGY_NAME, new RoundRobinPacking()));
    topology = TopologyAPI.Topology.getDefaultInstance();
}
Also used : IStateManager(com.twitter.heron.spi.statemgr.IStateManager) IUploader(com.twitter.heron.spi.uploader.IUploader) IPacking(com.twitter.heron.spi.packing.IPacking) ILauncher(com.twitter.heron.spi.scheduler.ILauncher) RoundRobinPacking(com.twitter.heron.packing.roundrobin.RoundRobinPacking) Config(com.twitter.heron.spi.common.Config) Before(org.junit.Before)

Example 5 with IPacking

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

the class CommonPackingTests method pack.

protected PackingPlan pack(TopologyAPI.Topology testTopology) {
    IPacking packing = getPackingImpl();
    packing.initialize(PackingTestUtils.newTestConfig(testTopology), testTopology);
    return packing.pack();
}
Also used : IPacking(com.twitter.heron.spi.packing.IPacking)

Aggregations

IPacking (com.twitter.heron.spi.packing.IPacking)5 TopologyAPI (com.twitter.heron.api.generated.TopologyAPI)3 Config (com.twitter.heron.spi.common.Config)3 PackingPlan (com.twitter.heron.spi.packing.PackingPlan)2 ILauncher (com.twitter.heron.spi.scheduler.ILauncher)2 RoundRobinPacking (com.twitter.heron.packing.roundrobin.RoundRobinPacking)1 LauncherUtils (com.twitter.heron.scheduler.utils.LauncherUtils)1 PackingException (com.twitter.heron.spi.packing.PackingException)1 ContainerPlan (com.twitter.heron.spi.packing.PackingPlan.ContainerPlan)1 IStateManager (com.twitter.heron.spi.statemgr.IStateManager)1 SchedulerStateManagerAdaptor (com.twitter.heron.spi.statemgr.SchedulerStateManagerAdaptor)1 IUploader (com.twitter.heron.spi.uploader.IUploader)1 HashSet (java.util.HashSet)1 Before (org.junit.Before)1 Test (org.junit.Test)1 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)1