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);
}
}
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;
}
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();
}
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();
}
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();
}
Aggregations