Search in sources :

Example 6 with Config

use of com.twitter.heron.spi.common.Config in project heron by twitter.

the class RuntimeManagerMainTest method testManageTopologyFailGetSchdulerClient.

@PrepareForTest(ReflectionUtils.class)
@Test(expected = SchedulerException.class)
public void testManageTopologyFailGetSchdulerClient() throws Exception {
    config = mock(Config.class);
    when(config.getStringValue(Key.TOPOLOGY_NAME)).thenReturn(TOPOLOGY_NAME);
    RuntimeManagerMain runtimeManagerMain = spy(new RuntimeManagerMain(config, MOCK_COMMAND));
    // Valid state manager class
    Mockito.when(config.getStringValue(Key.STATE_MANAGER_CLASS)).thenReturn(IStateManager.class.getName());
    PowerMockito.mockStatic(ReflectionUtils.class);
    PowerMockito.doReturn(Mockito.mock(IStateManager.class)).when(ReflectionUtils.class, "newInstance", Mockito.eq(IStateManager.class.getName()));
    // Legal request
    doNothing().when(runtimeManagerMain).validateRuntimeManage(any(SchedulerStateManagerAdaptor.class), eq(TOPOLOGY_NAME));
    // Failed to get ISchedulerClient
    doThrow(new SchedulerException("")).when(runtimeManagerMain).getSchedulerClient(any(Config.class));
    runtimeManagerMain.manageTopology();
}
Also used : IStateManager(com.twitter.heron.spi.statemgr.IStateManager) SchedulerException(com.twitter.heron.spi.scheduler.SchedulerException) Config(com.twitter.heron.spi.common.Config) SchedulerStateManagerAdaptor(com.twitter.heron.spi.statemgr.SchedulerStateManagerAdaptor) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 7 with Config

use of com.twitter.heron.spi.common.Config in project heron by twitter.

the class SchedulerMainTest method setUp.

/**
   * Basic setup before executing a test case
   */
@Before
public void setUp() throws Exception {
    Config config = mock(Config.class);
    when(config.getStringValue(Key.STATE_MANAGER_CLASS)).thenReturn(STATE_MANAGER_CLASS);
    when(config.getStringValue(Key.SCHEDULER_CLASS)).thenReturn(SCHEDULER_CLASS);
    int iSchedulerServerPort = 0;
    TopologyAPI.Topology topology = TopologyTests.createTopology(iTopologyName, new com.twitter.heron.api.Config(), new HashMap<String, Integer>(), new HashMap<String, Integer>());
    // Mock objects to be verified
    stateManager = mock(IStateManager.class);
    scheduler = mock(IScheduler.class);
    final SettableFuture<PackingPlans.PackingPlan> future = getTestPacking();
    when(stateManager.getPackingPlan(null, iTopologyName)).thenReturn(future);
    // Mock ReflectionUtils stuff
    PowerMockito.spy(ReflectionUtils.class);
    PowerMockito.doReturn(stateManager).when(ReflectionUtils.class, "newInstance", STATE_MANAGER_CLASS);
    PowerMockito.doReturn(scheduler).when(ReflectionUtils.class, "newInstance", SCHEDULER_CLASS);
    // Mock objects to be verified
    schedulerMain = spy(new SchedulerMain(config, topology, iSchedulerServerPort, mock(Properties.class)));
    schedulerServer = mock(SchedulerServer.class);
    doReturn(schedulerServer).when(schedulerMain).getServer(any(Config.class), eq(scheduler), eq(iSchedulerServerPort));
    doReturn(true).when(scheduler).onSchedule(any(PackingPlan.class));
    // Mock SchedulerUtils stuff
    PowerMockito.spy(SchedulerUtils.class);
    PowerMockito.doReturn(true).when(SchedulerUtils.class, "setSchedulerLocation", any(Config.class), anyString(), eq(scheduler));
    // Avoid infinite waiting
    Shutdown shutdown = mock(Shutdown.class);
    doReturn(shutdown).when(schedulerMain).getShutdown();
}
Also used : IStateManager(com.twitter.heron.spi.statemgr.IStateManager) Config(com.twitter.heron.spi.common.Config) PackingPlan(com.twitter.heron.spi.packing.PackingPlan) Mockito.anyString(org.mockito.Mockito.anyString) Properties(java.util.Properties) TopologyAPI(com.twitter.heron.api.generated.TopologyAPI) Shutdown(com.twitter.heron.scheduler.utils.Shutdown) SchedulerServer(com.twitter.heron.scheduler.server.SchedulerServer) IScheduler(com.twitter.heron.spi.scheduler.IScheduler) Before(org.junit.Before)

Example 8 with Config

use of com.twitter.heron.spi.common.Config in project heron by twitter.

the class SlurmLauncher method launch.

@Override
public boolean launch(PackingPlan packing) {
    LOG.log(Level.FINE, "Launching topology for local cluster {0}", SlurmContext.cluster(config));
    // this working directory is a shared directory among the nodes
    if (!setupWorkingDirectory()) {
        LOG.log(Level.SEVERE, "Failed to download the core and topology packages");
        return false;
    }
    LauncherUtils launcherUtils = LauncherUtils.getInstance();
    Config ytruntime = launcherUtils.createConfigWithPackingDetails(runtime, packing);
    return launcherUtils.onScheduleAsLibrary(config, ytruntime, new SlurmScheduler(topologyWorkingDirectory), packing);
}
Also used : Config(com.twitter.heron.spi.common.Config) LauncherUtils(com.twitter.heron.scheduler.utils.LauncherUtils)

Example 9 with Config

use of com.twitter.heron.spi.common.Config in project heron by twitter.

the class HeronExecutorTask method getExecutorCommand.

String[] getExecutorCommand() {
    String topologyDefFile = getTopologyDefnFile();
    Topology topology = getTopology(topologyDefFile);
    Config config = SchedulerConfigUtils.loadConfig(cluster, role, env, topologyJar, topologyDefFile, verboseMode, topology);
    List<Integer> freePorts = new ArrayList<>(SchedulerUtils.PORTS_REQUIRED_FOR_EXECUTOR);
    for (int i = 0; i < SchedulerUtils.PORTS_REQUIRED_FOR_EXECUTOR; i++) {
        freePorts.add(SysUtils.getFreePort());
    }
    Config runtime = Config.newBuilder().put(Key.COMPONENT_RAMMAP, componentRamMap).put(Key.TOPOLOGY_DEFINITION, topology).build();
    String[] executorCmd = SchedulerUtils.executorCommand(config, runtime, heronExecutorId, freePorts);
    LOG.info("Executor command line: " + Arrays.toString(executorCmd));
    return executorCmd;
}
Also used : Config(com.twitter.heron.spi.common.Config) ArrayList(java.util.ArrayList) Topology(com.twitter.heron.api.generated.TopologyAPI.Topology)

Example 10 with Config

use of com.twitter.heron.spi.common.Config in project heron by twitter.

the class AuroraContextTest method testUsesConfigString.

@Test
public void testUsesConfigString() {
    final String auroraTemplate = "/dir/test.aurora";
    Config config = Config.newBuilder().put(AuroraContext.JOB_TEMPLATE, auroraTemplate).put(Key.HERON_CONF, "/test").build();
    Assert.assertEquals("Expected to use value from JOB_TEMPLATE config", auroraTemplate, AuroraContext.getHeronAuroraPath(config));
}
Also used : Config(com.twitter.heron.spi.common.Config) Test(org.junit.Test)

Aggregations

Config (com.twitter.heron.spi.common.Config)87 Test (org.junit.Test)55 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)31 PackingPlan (com.twitter.heron.spi.packing.PackingPlan)23 TopologyAPI (com.twitter.heron.api.generated.TopologyAPI)20 SchedulerStateManagerAdaptor (com.twitter.heron.spi.statemgr.SchedulerStateManagerAdaptor)17 IStateManager (com.twitter.heron.spi.statemgr.IStateManager)9 LauncherUtils (com.twitter.heron.scheduler.utils.LauncherUtils)8 IScheduler (com.twitter.heron.spi.scheduler.IScheduler)8 ILauncher (com.twitter.heron.spi.scheduler.ILauncher)7 Before (org.junit.Before)7 HashSet (java.util.HashSet)5 ByteAmount (com.twitter.heron.common.basics.ByteAmount)4 ISchedulerClient (com.twitter.heron.scheduler.client.ISchedulerClient)4 PackingException (com.twitter.heron.spi.packing.PackingException)4 Resource (com.twitter.heron.spi.packing.Resource)4 URI (java.net.URI)4 Properties (java.util.Properties)4 CommandLine (org.apache.commons.cli.CommandLine)4 HeronTopology (com.twitter.heron.api.HeronTopology)3