Search in sources :

Example 11 with LauncherUtils

use of com.twitter.heron.scheduler.utils.LauncherUtils in project heron by twitter.

the class SlurmLauncherTest method testLaunch.

/**
   * Test slurm scheduler launcher
   */
@Test
public void testLaunch() throws Exception {
    Config config = createRunnerConfig();
    Config runtime = Mockito.mock(Config.class);
    PackingPlan packingPlan = Mockito.mock(PackingPlan.class);
    PackingPlan plan = new PackingPlan("plan.id", new HashSet<PackingPlan.ContainerPlan>());
    PowerMockito.spy(SlurmContext.class);
    PowerMockito.doReturn(WORKING_DIRECTORY).when(SlurmContext.class, "workingDirectory", config);
    LauncherUtils mockLauncherUtils = Mockito.mock(LauncherUtils.class);
    PowerMockito.spy(LauncherUtils.class);
    PowerMockito.doReturn(mockLauncherUtils).when(LauncherUtils.class, "getInstance");
    SlurmLauncher slurmLauncher = Mockito.spy(new SlurmLauncher());
    slurmLauncher.initialize(config, runtime);
    SlurmScheduler slurmScheduler = Mockito.spy(new SlurmScheduler());
    PowerMockito.doReturn(true).when(slurmScheduler).onSchedule(plan);
    // Failed to download
    Mockito.doReturn(false).when(slurmLauncher).setupWorkingDirectory();
    Assert.assertFalse(slurmLauncher.launch(packingPlan));
    Mockito.verify(slurmLauncher).setupWorkingDirectory();
    // Failed to schedule
    Mockito.when(mockLauncherUtils.onScheduleAsLibrary(Mockito.any(Config.class), Mockito.any(Config.class), Mockito.any(IScheduler.class), Mockito.any(PackingPlan.class))).thenReturn(false);
    PowerMockito.doReturn(true).when(slurmLauncher).setupWorkingDirectory();
    Assert.assertFalse(slurmLauncher.launch(Mockito.mock(PackingPlan.class)));
    Mockito.verify(mockLauncherUtils).onScheduleAsLibrary(Mockito.any(Config.class), Mockito.any(Config.class), Mockito.any(IScheduler.class), Mockito.any(PackingPlan.class));
    // happy path
    Mockito.when(mockLauncherUtils.onScheduleAsLibrary(Mockito.any(Config.class), Mockito.any(Config.class), Mockito.any(IScheduler.class), Mockito.any(PackingPlan.class))).thenReturn(true);
    Assert.assertTrue(slurmLauncher.launch(Mockito.mock(PackingPlan.class)));
    Mockito.verify(slurmLauncher, Mockito.times(3)).launch(Mockito.any(PackingPlan.class));
    Mockito.verify(mockLauncherUtils, Mockito.times(2)).onScheduleAsLibrary(Mockito.any(Config.class), Mockito.any(Config.class), Mockito.any(IScheduler.class), Mockito.any(PackingPlan.class));
    slurmLauncher.close();
}
Also used : Config(com.twitter.heron.spi.common.Config) PackingPlan(com.twitter.heron.spi.packing.PackingPlan) LauncherUtils(com.twitter.heron.scheduler.utils.LauncherUtils) IScheduler(com.twitter.heron.spi.scheduler.IScheduler) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 12 with LauncherUtils

use of com.twitter.heron.scheduler.utils.LauncherUtils in project heron by twitter.

the class SchedulerMain method runScheduler.

/**
   * Run the scheduler.
   * It is a blocking call, and it will return in 2 cases:
   * 1. The topology is requested to kill
   * 2. Unexpected exceptions happen
   *
   * @return true if scheduled successfully
   */
public boolean runScheduler() {
    IScheduler scheduler = null;
    String statemgrClass = Context.stateManagerClass(config);
    IStateManager statemgr;
    try {
        // create an instance of state manager
        statemgr = ReflectionUtils.newInstance(statemgrClass);
    } catch (IllegalAccessException | InstantiationException | ClassNotFoundException e) {
        LOG.log(Level.SEVERE, "Failed to instantiate instances using config: " + config, e);
        return false;
    }
    SchedulerServer server = null;
    boolean isSuccessful = false;
    // Put it in a try block so that we can always clean resources
    try {
        // initialize the state manager
        statemgr.initialize(config);
        // TODO(mfu): timeout should read from config
        SchedulerStateManagerAdaptor adaptor = new SchedulerStateManagerAdaptor(statemgr, 5000);
        // get a packed plan and schedule it
        PackingPlans.PackingPlan serializedPackingPlan = adaptor.getPackingPlan(topology.getName());
        if (serializedPackingPlan == null) {
            LOG.log(Level.SEVERE, "Failed to fetch PackingPlan for topology:{0} from the state manager", topology.getName());
            return false;
        }
        LOG.log(Level.INFO, "Packing plan fetched from state: {0}", serializedPackingPlan);
        PackingPlan packedPlan = new PackingPlanProtoDeserializer().fromProto(serializedPackingPlan);
        // build the runtime config
        LauncherUtils launcherUtils = LauncherUtils.getInstance();
        Config runtime = Config.newBuilder().putAll(launcherUtils.createPrimaryRuntime(topology)).putAll(launcherUtils.createAdaptorRuntime(adaptor)).put(Key.SCHEDULER_SHUTDOWN, getShutdown()).put(Key.SCHEDULER_PROPERTIES, properties).build();
        Config ytruntime = launcherUtils.createConfigWithPackingDetails(runtime, packedPlan);
        // invoke scheduler
        scheduler = launcherUtils.getSchedulerInstance(config, ytruntime);
        if (scheduler == null) {
            return false;
        }
        isSuccessful = scheduler.onSchedule(packedPlan);
        if (!isSuccessful) {
            LOG.severe("Failed to schedule topology");
            return false;
        }
        // Failures in server initialization throw exceptions
        // get the scheduler server endpoint for receiving requests
        server = getServer(ytruntime, scheduler, schedulerServerPort);
        // start the server to manage runtime requests
        server.start();
        // write the scheduler location to state manager
        // Make sure it happens after IScheduler.onScheduler
        isSuccessful = SchedulerUtils.setSchedulerLocation(runtime, String.format("%s:%d", server.getHost(), server.getPort()), scheduler);
        if (isSuccessful) {
            // wait until kill request or some interrupt occurs if the scheduler starts successfully
            LOG.info("Waiting for termination... ");
            Runtime.schedulerShutdown(ytruntime).await();
        }
    } catch (IOException e) {
        LOG.log(Level.SEVERE, "Failed to start server", e);
        return false;
    } finally {
        // Clean the resources
        if (server != null) {
            server.stop();
        }
        // 4. Close the resources
        SysUtils.closeIgnoringExceptions(scheduler);
        SysUtils.closeIgnoringExceptions(statemgr);
    }
    return isSuccessful;
}
Also used : IStateManager(com.twitter.heron.spi.statemgr.IStateManager) Config(com.twitter.heron.spi.common.Config) SystemConfig(com.twitter.heron.common.config.SystemConfig) PackingPlan(com.twitter.heron.spi.packing.PackingPlan) IOException(java.io.IOException) LauncherUtils(com.twitter.heron.scheduler.utils.LauncherUtils) SchedulerStateManagerAdaptor(com.twitter.heron.spi.statemgr.SchedulerStateManagerAdaptor) PackingPlans(com.twitter.heron.proto.system.PackingPlans) PackingPlanProtoDeserializer(com.twitter.heron.spi.packing.PackingPlanProtoDeserializer) SchedulerServer(com.twitter.heron.scheduler.server.SchedulerServer) IScheduler(com.twitter.heron.spi.scheduler.IScheduler)

Example 13 with LauncherUtils

use of com.twitter.heron.scheduler.utils.LauncherUtils in project heron by twitter.

the class AuroraLauncherTest method testLaunch.

@Test
public void testLaunch() throws Exception {
    Config config = Config.newBuilder().build();
    AuroraLauncher launcher = Mockito.spy(AuroraLauncher.class);
    launcher.initialize(config, config);
    LauncherUtils mockLauncherUtils = Mockito.mock(LauncherUtils.class);
    PowerMockito.spy(LauncherUtils.class);
    PowerMockito.doReturn(mockLauncherUtils).when(LauncherUtils.class, "getInstance");
    // Failed to schedule
    Mockito.when(mockLauncherUtils.onScheduleAsLibrary(Mockito.any(Config.class), Mockito.any(Config.class), Mockito.any(IScheduler.class), Mockito.any(PackingPlan.class))).thenReturn(false);
    Assert.assertFalse(launcher.launch(Mockito.mock(PackingPlan.class)));
    Mockito.verify(mockLauncherUtils).onScheduleAsLibrary(Mockito.any(Config.class), Mockito.any(Config.class), Mockito.any(IScheduler.class), Mockito.any(PackingPlan.class));
    // Happy path
    Mockito.when(mockLauncherUtils.onScheduleAsLibrary(Mockito.any(Config.class), Mockito.any(Config.class), Mockito.any(IScheduler.class), Mockito.any(PackingPlan.class))).thenReturn(true);
    Assert.assertTrue(launcher.launch(Mockito.mock(PackingPlan.class)));
    Mockito.verify(mockLauncherUtils, Mockito.times(2)).onScheduleAsLibrary(Mockito.any(Config.class), Mockito.any(Config.class), Mockito.any(IScheduler.class), Mockito.any(PackingPlan.class));
    launcher.close();
}
Also used : Config(com.twitter.heron.spi.common.Config) PackingPlan(com.twitter.heron.spi.packing.PackingPlan) LauncherUtils(com.twitter.heron.scheduler.utils.LauncherUtils) IScheduler(com.twitter.heron.spi.scheduler.IScheduler) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 14 with LauncherUtils

use of com.twitter.heron.scheduler.utils.LauncherUtils in project heron by twitter.

the class MarathonLauncher method launch.

@Override
public boolean launch(PackingPlan packing) {
    LauncherUtils launcherUtils = LauncherUtils.getInstance();
    Config ytruntime = launcherUtils.createConfigWithPackingDetails(runtime, packing);
    return launcherUtils.onScheduleAsLibrary(config, ytruntime, getScheduler(), packing);
}
Also used : Config(com.twitter.heron.spi.common.Config) LauncherUtils(com.twitter.heron.scheduler.utils.LauncherUtils)

Example 15 with LauncherUtils

use of com.twitter.heron.scheduler.utils.LauncherUtils in project heron by twitter.

the class AuroraLauncher method launch.

@Override
public boolean launch(PackingPlan packing) {
    LauncherUtils launcherUtils = LauncherUtils.getInstance();
    Config ytruntime = launcherUtils.createConfigWithPackingDetails(runtime, packing);
    return launcherUtils.onScheduleAsLibrary(config, ytruntime, getScheduler(), packing);
}
Also used : Config(com.twitter.heron.spi.common.Config) LauncherUtils(com.twitter.heron.scheduler.utils.LauncherUtils)

Aggregations

LauncherUtils (com.twitter.heron.scheduler.utils.LauncherUtils)19 Config (com.twitter.heron.spi.common.Config)19 PackingPlan (com.twitter.heron.spi.packing.PackingPlan)11 IScheduler (com.twitter.heron.spi.scheduler.IScheduler)9 Test (org.junit.Test)7 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)7 SchedulerStateManagerAdaptor (com.twitter.heron.spi.statemgr.SchedulerStateManagerAdaptor)4 TopologyAPI (com.twitter.heron.api.generated.TopologyAPI)2 SystemConfig (com.twitter.heron.common.config.SystemConfig)2 PackingPlans (com.twitter.heron.proto.system.PackingPlans)2 SchedulerServer (com.twitter.heron.scheduler.server.SchedulerServer)2 IPacking (com.twitter.heron.spi.packing.IPacking)2 ContainerPlan (com.twitter.heron.spi.packing.PackingPlan.ContainerPlan)2 PackingPlanProtoDeserializer (com.twitter.heron.spi.packing.PackingPlanProtoDeserializer)2 ILauncher (com.twitter.heron.spi.scheduler.ILauncher)2 IStateManager (com.twitter.heron.spi.statemgr.IStateManager)2 IOException (java.io.IOException)2 HashSet (java.util.HashSet)2