Search in sources :

Example 11 with Config

use of org.apache.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(org.apache.heron.spi.common.Config) Test(org.junit.Test)

Example 12 with Config

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

the class AuroraContextTest method testFallback.

@Test
public void testFallback() {
    Config config = Config.newBuilder().put(Key.HERON_CONF, "/test").build();
    Assert.assertEquals("Expected to use heron_conf/heron.aurora", "/test/heron.aurora", AuroraContext.getHeronAuroraPath(config));
}
Also used : Config(org.apache.heron.spi.common.Config) Test(org.junit.Test)

Example 13 with Config

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

the class AuroraSchedulerTest method testOnRestart.

@Test
public void testOnRestart() throws Exception {
    Config mockConfig = Mockito.mock(Config.class);
    PowerMockito.mockStatic(Config.class);
    when(Config.toClusterMode(mockConfig)).thenReturn(mockConfig);
    AuroraController controller = Mockito.mock(AuroraController.class);
    doReturn(controller).when(scheduler).getController();
    scheduler.initialize(mockConfig, Mockito.mock(Config.class));
    // Construct the RestartTopologyRequest
    int containerToRestart = 1;
    Scheduler.RestartTopologyRequest restartTopologyRequest = Scheduler.RestartTopologyRequest.newBuilder().setTopologyName(TOPOLOGY_NAME).setContainerIndex(containerToRestart).build();
    // Failed to kill job via controller
    doReturn(false).when(controller).restart(containerToRestart);
    Assert.assertFalse(scheduler.onRestart(restartTopologyRequest));
    Mockito.verify(controller).restart(containerToRestart);
    // Happy path
    doReturn(true).when(controller).restart(containerToRestart);
    assertTrue(scheduler.onRestart(restartTopologyRequest));
    Mockito.verify(controller, Mockito.times(2)).restart(containerToRestart);
}
Also used : Config(org.apache.heron.spi.common.Config) Scheduler(org.apache.heron.proto.scheduler.Scheduler) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 14 with Config

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

the class KubernetesSchedulerTest method testGetJobLinks.

@Test
public void testGetJobLinks() throws Exception {
    final String SCHEDULER_URI = "http://k8s.uri";
    final String JOB_LINK = SCHEDULER_URI + KubernetesConstants.JOB_LINK;
    Config c = Config.newBuilder().put(KubernetesContext.HERON_KUBERNETES_SCHEDULER_URI, SCHEDULER_URI).build();
    scheduler.initialize(c, mockRuntime);
    List<String> links = scheduler.getJobLinks();
    Assert.assertEquals(1, links.size());
    System.out.println(links.get(0));
    System.out.println(JOB_LINK);
    Assert.assertTrue(links.get(0).equals(JOB_LINK));
}
Also used : Config(org.apache.heron.spi.common.Config) Test(org.junit.Test)

Example 15 with Config

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

the class V1Controller method addVolumesIfPresent.

/**
 * Adds volume to the <code>Pod Spec</code> that Heron requires. Heron's values taking precedence.
 * @param spec <code>Pod Spec</code> to be configured.
 */
@VisibleForTesting
protected void addVolumesIfPresent(final V1PodSpec spec) {
    final Config config = getConfiguration();
    if (KubernetesContext.hasVolume(config)) {
        final V1Volume volumeFromConfig = Volumes.get().create(config);
        if (volumeFromConfig != null) {
            // Merge volumes. Deduplicate using volume's name with Heron defaults taking precedence.
            KubernetesUtils.V1ControllerUtils<V1Volume> utils = new KubernetesUtils.V1ControllerUtils<>();
            spec.setVolumes(utils.mergeListsDedupe(Collections.singletonList(volumeFromConfig), spec.getVolumes(), Comparator.comparing(V1Volume::getName), "Pod Template Volumes"));
            LOG.fine("Adding volume: " + volumeFromConfig);
        }
    }
}
Also used : V1Volume(io.kubernetes.client.openapi.models.V1Volume) Config(org.apache.heron.spi.common.Config) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

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