Search in sources :

Example 91 with Config

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

the class KubernetesContextTest method createVolumeEmptyDirError.

/**
 * Create test cases for <code>Empty Directory</code> errors.
 * @param testCases Test case container.
 *                  Input: [0] Config, [1] Boolean to indicate Manager/Executor.
 *                  Output: Error message
 * @param isExecutor Boolean to indicate Manager/Executor test case generation.
 */
private void createVolumeEmptyDirError(List<TestTuple<Pair<Config, Boolean>, String>> testCases, boolean isExecutor) {
    final String volumeNameValid = "volume-name-valid";
    final String passingValue = "should-pass";
    final String failureValue = "Should-Fail";
    final String processName = isExecutor ? KubernetesConstants.EXECUTOR_NAME : KubernetesConstants.MANAGER_NAME;
    final String keyPattern = String.format(KubernetesContext.KUBERNETES_VOLUME_EMPTYDIR_PREFIX + "%%s.%%s", processName);
    // Medium is invalid.
    final Config configInvalidMedium = Config.newBuilder().put(String.format(keyPattern, volumeNameValid, "path"), passingValue).put(String.format(keyPattern, volumeNameValid, "sizeLimit"), passingValue).put(String.format(keyPattern, volumeNameValid, "medium"), failureValue).build();
    testCases.add(new TestTuple<>(processName + ": Invalid 'medium' should trigger exception", new Pair<>(configInvalidMedium, isExecutor), "must be 'Memory' or empty."));
    // Invalid option.
    final Config configInvalidOption = Config.newBuilder().put(String.format(keyPattern, volumeNameValid, "path"), passingValue).put(String.format(keyPattern, volumeNameValid, "subPath"), passingValue).put(String.format(keyPattern, volumeNameValid, "sizeLimit"), passingValue).put(String.format(keyPattern, volumeNameValid, "medium"), "Memory").put(String.format(keyPattern, volumeNameValid, "accessModes"), passingValue).build();
    testCases.add(new TestTuple<>(processName + ": Invalid option should trigger exception", new Pair<>(configInvalidOption, isExecutor), "Directory type option"));
}
Also used : Config(org.apache.heron.spi.common.Config) Pair(org.apache.heron.common.basics.Pair)

Example 92 with Config

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

the class V1Controller method mountVolumeIfPresent.

/**
 * Adds volume mounts to the <code>container</code> that Heron requires. Heron's values taking precedence.
 * @param container <code>container</code> to be configured.
 */
@VisibleForTesting
protected void mountVolumeIfPresent(final V1Container container) {
    final Config config = getConfiguration();
    if (KubernetesContext.hasContainerVolume(config)) {
        final V1VolumeMount mount = new V1VolumeMount().name(KubernetesContext.getContainerVolumeName(config)).mountPath(KubernetesContext.getContainerVolumeMountPath(config));
        // Merge volume mounts. Deduplicate using mount's name with Heron defaults taking precedence.
        KubernetesUtils.V1ControllerUtils<V1VolumeMount> utils = new KubernetesUtils.V1ControllerUtils<>();
        container.setVolumeMounts(utils.mergeListsDedupe(Collections.singletonList(mount), container.getVolumeMounts(), Comparator.comparing(V1VolumeMount::getName), "Pod Template Volume Mounts"));
    }
}
Also used : Config(org.apache.heron.spi.common.Config) V1VolumeMount(io.kubernetes.client.openapi.models.V1VolumeMount) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 93 with Config

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

the class V1Controller method getExecutorCommand.

/**
 * Generates the command to start Heron within the <code>container</code>.
 * @param containerId Passed down to <>SchedulerUtils</> to generate executor command.
 * @param numOfInstances Used to configure the debugging ports.
 * @param isExecutor Flag used to generate the correct <code>shard_id</code>.
 * @return The complete command to start Heron in a <code>container</code>.
 */
protected List<String> getExecutorCommand(String containerId, int numOfInstances, boolean isExecutor) {
    final Config configuration = getConfiguration();
    final Config runtimeConfiguration = getRuntimeConfiguration();
    final Map<ExecutorPort, String> ports = KubernetesConstants.EXECUTOR_PORTS.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, e -> e.getValue().toString()));
    if (TopologyUtils.getTopologyRemoteDebuggingEnabled(Runtime.topology(runtimeConfiguration)) && numOfInstances != 0) {
        List<String> remoteDebuggingPorts = new LinkedList<>();
        IntStream.range(0, numOfInstances).forEach(i -> {
            int port = KubernetesConstants.JVM_REMOTE_DEBUGGER_PORT + i;
            remoteDebuggingPorts.add(String.valueOf(port));
        });
        ports.put(ExecutorPort.JVM_REMOTE_DEBUGGER_PORTS, String.join(",", remoteDebuggingPorts));
    }
    final String[] executorCommand = SchedulerUtils.getExecutorCommand(configuration, runtimeConfiguration, containerId, ports);
    return Arrays.asList("sh", "-c", KubernetesUtils.getConfCommand(configuration) + " && " + KubernetesUtils.getFetchCommand(configuration, runtimeConfiguration) + " && " + setShardIdEnvironmentVariableCommand(isExecutor) + " && " + String.join(" ", executorCommand));
}
Also used : Arrays(java.util.Arrays) V1Toleration(io.kubernetes.client.openapi.models.V1Toleration) V1ResourceRequirements(io.kubernetes.client.openapi.models.V1ResourceRequirements) V1VolumeBuilder(io.kubernetes.client.openapi.models.V1VolumeBuilder) PackingPlan(org.apache.heron.spi.packing.PackingPlan) V1Patch(io.kubernetes.client.custom.V1Patch) Configuration(io.kubernetes.client.openapi.Configuration) V1EnvVar(io.kubernetes.client.openapi.models.V1EnvVar) Map(java.util.Map) V1StatefulSet(io.kubernetes.client.openapi.models.V1StatefulSet) Quantity(io.kubernetes.client.custom.Quantity) V1ObjectFieldSelector(io.kubernetes.client.openapi.models.V1ObjectFieldSelector) V1VolumeMount(io.kubernetes.client.openapi.models.V1VolumeMount) V1PersistentVolumeClaimBuilder(io.kubernetes.client.openapi.models.V1PersistentVolumeClaimBuilder) V1Volume(io.kubernetes.client.openapi.models.V1Volume) Pair(org.apache.heron.common.basics.Pair) TopologyRuntimeManagementException(org.apache.heron.scheduler.TopologyRuntimeManagementException) SchedulerUtils(org.apache.heron.scheduler.utils.SchedulerUtils) Set(java.util.Set) V1LabelSelector(io.kubernetes.client.openapi.models.V1LabelSelector) Logger(java.util.logging.Logger) Runtime(org.apache.heron.scheduler.utils.Runtime) V1Status(io.kubernetes.client.openapi.models.V1Status) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) List(java.util.List) V1PodTemplate(io.kubernetes.client.openapi.models.V1PodTemplate) V1PersistentVolumeClaim(io.kubernetes.client.openapi.models.V1PersistentVolumeClaim) V1SecretKeySelector(io.kubernetes.client.openapi.models.V1SecretKeySelector) V1ServiceSpec(io.kubernetes.client.openapi.models.V1ServiceSpec) V1EnvVarSource(io.kubernetes.client.openapi.models.V1EnvVarSource) ExecutorPort(org.apache.heron.scheduler.utils.SchedulerUtils.ExecutorPort) PatchUtils(io.kubernetes.client.util.PatchUtils) HTTP_NOT_FOUND(java.net.HttpURLConnection.HTTP_NOT_FOUND) IntStream(java.util.stream.IntStream) HashMap(java.util.HashMap) V1PodTemplateSpec(io.kubernetes.client.openapi.models.V1PodTemplateSpec) AppsV1Api(io.kubernetes.client.openapi.apis.AppsV1Api) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) ApiClient(io.kubernetes.client.openapi.ApiClient) ApiException(io.kubernetes.client.openapi.ApiException) V1VolumeMountBuilder(io.kubernetes.client.openapi.models.V1VolumeMountBuilder) V1StatefulSetSpec(io.kubernetes.client.openapi.models.V1StatefulSetSpec) V1ConfigMap(io.kubernetes.client.openapi.models.V1ConfigMap) V1ObjectMeta(io.kubernetes.client.openapi.models.V1ObjectMeta) Resource(org.apache.heron.spi.packing.Resource) Response(okhttp3.Response) V1ContainerPort(io.kubernetes.client.openapi.models.V1ContainerPort) V1SecretVolumeSourceBuilder(io.kubernetes.client.openapi.models.V1SecretVolumeSourceBuilder) LinkedList(java.util.LinkedList) V1Container(io.kubernetes.client.openapi.models.V1Container) IOException(java.io.IOException) CoreV1Api(io.kubernetes.client.openapi.apis.CoreV1Api) Yaml(io.kubernetes.client.util.Yaml) Config(org.apache.heron.spi.common.Config) V1PodSpec(io.kubernetes.client.openapi.models.V1PodSpec) TopologyUtils(org.apache.heron.api.utils.TopologyUtils) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Comparator(java.util.Comparator) Collections(java.util.Collections) TopologySubmissionException(org.apache.heron.scheduler.TopologySubmissionException) V1Service(io.kubernetes.client.openapi.models.V1Service) Config(org.apache.heron.spi.common.Config) ExecutorPort(org.apache.heron.scheduler.utils.SchedulerUtils.ExecutorPort) Map(java.util.Map) HashMap(java.util.HashMap) V1ConfigMap(io.kubernetes.client.openapi.models.V1ConfigMap) LinkedList(java.util.LinkedList)

Example 94 with Config

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

the class LauncherUtilsTest method constructsConfigWithTopologyInfo.

@Test
public void constructsConfigWithTopologyInfo() throws Exception {
    TopologyAPI.Topology mockTopology = PowerMockito.mock(TopologyAPI.Topology.class);
    PowerMockito.when(mockTopology.getId()).thenReturn("testTopologyId");
    PowerMockito.when(mockTopology.getName()).thenReturn("testTopologyName");
    SchedulerStateManagerAdaptor mockStMgr = Mockito.mock(SchedulerStateManagerAdaptor.class);
    PowerMockito.spy(TopologyUtils.class);
    PowerMockito.doReturn(456).when(TopologyUtils.class, "getNumContainers", mockTopology);
    Config runtime = Config.newBuilder().putAll(LauncherUtils.getInstance().createPrimaryRuntime(mockTopology)).putAll(LauncherUtils.getInstance().createAdaptorRuntime(mockStMgr)).build();
    Assert.assertEquals("testTopologyId", Runtime.topologyId(runtime));
    Assert.assertEquals("testTopologyName", Runtime.topologyName(runtime));
    Assert.assertEquals(mockTopology, Runtime.topology(runtime));
    Assert.assertEquals(mockStMgr, Runtime.schedulerStateManagerAdaptor(runtime));
    Assert.assertEquals(456 + 1, Runtime.numContainers(runtime).longValue());
}
Also used : Config(org.apache.heron.spi.common.Config) TopologyAPI(org.apache.heron.api.generated.TopologyAPI) SchedulerStateManagerAdaptor(org.apache.heron.spi.statemgr.SchedulerStateManagerAdaptor) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 95 with Config

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

the class KubernetesLauncherTest method testLaunch.

@Test
public void testLaunch() throws Exception {
    Config config = Config.newBuilder().build();
    KubernetesLauncher launcher = Mockito.spy(KubernetesLauncher.class);
    launcher.initialize(config, config);
    LauncherUtils mockLauncherUtils = Mockito.mock(LauncherUtils.class);
    PowerMockito.spy(LauncherUtils.class);
    PowerMockito.doReturn(mockLauncherUtils).when(LauncherUtils.class, "getInstance");
    // Launched successfully
    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).onScheduleAsLibrary(Mockito.any(Config.class), Mockito.any(Config.class), Mockito.any(IScheduler.class), Mockito.any(PackingPlan.class));
    // Failed to launch
    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, 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(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) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

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