Search in sources :

Example 36 with Config

use of org.apache.heron.spi.common.Config in project heron by twitter.

the class NomadSchedulerTest method setUp.

@Before
public void setUp() throws Exception {
    Config config = Config.newBuilder().put(Key.TOPOLOGY_NAME, TOPOLOGY_NAME).put(Key.TOPOLOGY_ID, TOPOLOGY_ID).put(NomadContext.HERON_NOMAD_SCHEDULER_URI, SCHEDULER_URI).put(NomadContext.HERON_NOMAD_CORE_FREQ_MAPPING, HERON_NOMAD_CORE_FREQ_MAPPING).put(Key.CORE_PACKAGE_URI, CORE_PACKAGE_URI).put(Key.USE_CORE_PACKAGE_URI, USE_CORE_PACKAGE_URI).put(Key.EXECUTOR_BINARY, EXECUTOR_BINARY).put(NomadContext.HERON_NOMAD_DRIVER, NomadConstants.NomadDriver.RAW_EXEC.getName()).put(NomadContext.HERON_NOMAD_NETWORK_MODE, "default").build();
    this.mockRuntime = config;
    this.mockConfig = config;
    scheduler = Mockito.spy(NomadScheduler.class);
}
Also used : Config(org.apache.heron.spi.common.Config) Before(org.junit.Before)

Example 37 with Config

use of org.apache.heron.spi.common.Config 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(org.apache.heron.spi.common.Config) PackingPlan(org.apache.heron.spi.packing.PackingPlan) LauncherUtils(org.apache.heron.scheduler.utils.LauncherUtils) IScheduler(org.apache.heron.spi.scheduler.IScheduler) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 38 with Config

use of org.apache.heron.spi.common.Config in project heron by twitter.

the class YarnLauncherTest method getHMDriverConfConstructsReefConfig.

// This test verifies if launcher correctly provides all heron specific configurations are to reef
// framework. It does so by ensuring required configs exist. The test fails if an unknown config
// is found. Presence of unknown config should be verified and then added to the test below
@Test
public void getHMDriverConfConstructsReefConfig() throws Exception {
    YarnLauncher launcher = new YarnLauncher();
    YarnLauncher spyLauncher = Mockito.spy(launcher);
    Mockito.doNothing().when(spyLauncher).addLibraryToClasspathSet(Mockito.anyString());
    // inputConf contains configs provided to the launcher
    Map<String, String> inputConf = new HashMap<>();
    // expected contains the reef configs launcher is expected to construct using testConfigs
    Map<String, String> expected = new HashMap<>();
    setConfigs(inputConf, expected, Key.TOPOLOGY_NAME, "topology", TopologyName.class);
    setConfigs(inputConf, expected, Key.TOPOLOGY_BINARY_FILE, "binary", TopologyJar.class);
    setConfigs(inputConf, expected, Key.TOPOLOGY_PACKAGE_FILE, "pack", TopologyPackageName.class);
    setConfigs(inputConf, expected, Key.CLUSTER, "cluster", Cluster.class);
    setConfigs(inputConf, expected, Key.ROLE, "role", Role.class);
    setConfigs(inputConf, expected, Key.ENVIRON, "env", Environ.class);
    setConfigs(inputConf, expected, YarnKey.HERON_SCHEDULER_YARN_QUEUE.value(), "q", JobQueue.class);
    setConfigs(inputConf, expected, YarnKey.YARN_SCHEDULER_DRIVER_MEMORY_MB.value(), "123", DriverMemory.class);
    setConfigs(inputConf, expected, Key.CORE_PACKAGE_URI, new File(".").getName(), HeronCorePackageName.class);
    // the following expected values are mostly specific to reef runtime
    expected.put(JobControlHandler.class.getSimpleName(), ClientManager.class.getName());
    expected.put(NodeDescriptorHandler.class.getSimpleName(), NodeDescriptorHandler.class.getName());
    expected.put(ResourceAllocationHandler.class.getSimpleName(), ResourceAllocationHandler.class.getName());
    expected.put(ResourceStatusHandler.class.getSimpleName(), ResourceStatusHandler.class.getName());
    expected.put(RuntimeParameters.RuntimeStatusHandler.class.getSimpleName(), ResourceManagerStatus.class.getName());
    expected.put(VerboseLogMode.class.getSimpleName(), "false");
    expected.put(HttpPort.class.getSimpleName(), "0");
    expected.put(DriverIdentifier.class.getSimpleName(), "topology");
    Config.Builder builder = new Config.Builder();
    for (String configName : inputConf.keySet()) {
        builder.put(configName, inputConf.get(configName));
    }
    builder.put(Key.STATE_MANAGER_CLASS, "statemanager");
    builder.put(Key.PACKING_CLASS, "packing");
    Config config = builder.build();
    spyLauncher.initialize(config, null);
    Configuration resultConf = spyLauncher.getHMDriverConf();
    for (NamedParameterNode<?> reefConfigNode : resultConf.getNamedParameters()) {
        String resultValue = resultConf.getNamedParameter(reefConfigNode);
        String expectedValue = expected.get(reefConfigNode.getName());
        if (expectedValue == null) {
            Assert.fail(String.format("Unknown config, %s:%s, provided to heron driver", reefConfigNode.getName(), resultConf.getNamedParameter(reefConfigNode)));
        } else {
            Assert.assertEquals(expectedValue, resultValue);
        }
        expected.remove(reefConfigNode.getName());
    }
    Assert.assertEquals(String.format("Missing expected configurations: %s", expected), 0, expected.size());
}
Also used : HttpPort(org.apache.heron.scheduler.yarn.HeronConfigurationOptions.HttpPort) ResourceAllocationHandler(org.apache.reef.runtime.common.driver.resourcemanager.ResourceAllocationHandler) Configuration(org.apache.reef.tang.Configuration) HashMap(java.util.HashMap) ResourceStatusHandler(org.apache.reef.runtime.common.driver.resourcemanager.ResourceStatusHandler) Config(org.apache.heron.spi.common.Config) JobControlHandler(org.apache.reef.runtime.common.driver.DriverRuntimeConfigurationOptions.JobControlHandler) DriverIdentifier(org.apache.reef.driver.parameters.DriverIdentifier) ResourceManagerStatus(org.apache.reef.runtime.common.driver.resourcemanager.ResourceManagerStatus) ClientManager(org.apache.reef.runtime.common.driver.client.ClientManager) NodeDescriptorHandler(org.apache.reef.runtime.common.driver.resourcemanager.NodeDescriptorHandler) File(java.io.File) VerboseLogMode(org.apache.heron.scheduler.yarn.HeronConfigurationOptions.VerboseLogMode) Test(org.junit.Test)

Example 39 with Config

use of org.apache.heron.spi.common.Config in project heron by twitter.

the class MesosSchedulerTest method before.

@Before
public void before() throws Exception {
    Config config = Mockito.mock(Config.class);
    Mockito.when(config.getStringValue(Key.TOPOLOGY_NAME)).thenReturn(TOPOLOGY_NAME);
    Mockito.when(config.getStringValue(Key.ROLE)).thenReturn(ROLE);
    Mockito.when(config.getStringValue(Key.CORE_PACKAGE_URI)).thenReturn(CORE_PACKAGE_URI);
    Config runtime = Mockito.mock(Config.class);
    Mockito.when(runtime.getLongValue(Key.NUM_CONTAINERS)).thenReturn(NUM_CONTAINER);
    Properties properties = new Properties();
    properties.put(Key.TOPOLOGY_PACKAGE_URI.value(), TOPOLOGY_PACKAGE_URI);
    Mockito.when(runtime.get(Key.SCHEDULER_PROPERTIES)).thenReturn(properties);
    mesosFramework = Mockito.mock(MesosFramework.class);
    SchedulerDriver driver = Mockito.mock(SchedulerDriver.class);
    baseContainer = Mockito.mock(BaseContainer.class);
    scheduler = Mockito.spy(MesosScheduler.class);
    Mockito.doReturn(mesosFramework).when(scheduler).getMesosFramework();
    Mockito.doReturn(driver).when(scheduler).getSchedulerDriver(Mockito.anyString(), Mockito.eq(mesosFramework));
    Mockito.doNothing().when(scheduler).startSchedulerDriver();
    scheduler.initialize(config, runtime);
}
Also used : BaseContainer(org.apache.heron.scheduler.mesos.framework.BaseContainer) MesosFramework(org.apache.heron.scheduler.mesos.framework.MesosFramework) Config(org.apache.heron.spi.common.Config) Properties(java.util.Properties) SchedulerDriver(org.apache.mesos.SchedulerDriver) Before(org.junit.Before)

Example 40 with Config

use of org.apache.heron.spi.common.Config in project heron by twitter.

the class SlurmSchedulerTest method testOnKill.

@Test
public void testOnKill() throws Exception {
    SlurmController controller = Mockito.mock(SlurmController.class);
    Mockito.doReturn(controller).when(scheduler).getController();
    Mockito.doReturn(SLURM_ID_FILE).when(scheduler).getJobIdFilePath();
    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);
    // Failed to kill job via controller
    Mockito.doReturn(false).when(controller).killJob(Mockito.anyString());
    Assert.assertFalse(scheduler.onKill(Scheduler.KillTopologyRequest.getDefaultInstance()));
    Mockito.verify(controller).killJob(Mockito.anyString());
    // Happy path
    Mockito.doReturn(true).when(controller).killJob(Mockito.anyString());
    Assert.assertTrue(scheduler.onKill(Scheduler.KillTopologyRequest.getDefaultInstance()));
    Mockito.verify(controller, Mockito.times(2)).killJob(Mockito.anyString());
}
Also used : Config(org.apache.heron.spi.common.Config) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

Config (org.apache.heron.spi.common.Config)140 Test (org.junit.Test)75 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)29 PackingPlan (org.apache.heron.spi.packing.PackingPlan)22 HashMap (java.util.HashMap)18 SchedulerStateManagerAdaptor (org.apache.heron.spi.statemgr.SchedulerStateManagerAdaptor)18 Pair (org.apache.heron.common.basics.Pair)16 TopologyAPI (org.apache.heron.api.generated.TopologyAPI)15 IOException (java.io.IOException)11 LauncherUtils (org.apache.heron.scheduler.utils.LauncherUtils)11 Map (java.util.Map)10 V1Volume (io.kubernetes.client.openapi.models.V1Volume)9 URI (java.net.URI)9 IScheduler (org.apache.heron.spi.scheduler.IScheduler)9 IStateManager (org.apache.heron.spi.statemgr.IStateManager)9 Before (org.junit.Before)9 File (java.io.File)7 LinkedList (java.util.LinkedList)7 Resource (org.apache.heron.spi.packing.Resource)7 CommandLine (org.apache.commons.cli.CommandLine)6