Search in sources :

Example 1 with VolumeConfigKeys

use of org.apache.heron.scheduler.kubernetes.KubernetesConstants.VolumeConfigKeys in project heron by twitter.

the class KubernetesContextTest method createVolumeClaimTemplates.

/**
 * Create test cases for <code>Volume Claim Templates</code>.
 * @param testCases Test case container.
 *                  Input: [0] Config, [1] Boolean to indicate Manager/Executor.
 *                  Output: <code>Map<String, Map<VolumeConfigKeys, String></code>
 * @param isExecutor Boolean to indicate Manager/Executor test case generation.
 */
private void createVolumeClaimTemplates(List<TestTuple<Pair<Config, Boolean>, Map<String, Map<VolumeConfigKeys, String>>>> testCases, boolean isExecutor) {
    final String volumeNameValid = "volume-name-valid";
    final String passingValue = "should-pass";
    final String processName = isExecutor ? KubernetesConstants.EXECUTOR_NAME : KubernetesConstants.MANAGER_NAME;
    final String keyPattern = String.format(KubernetesContext.KUBERNETES_VOLUME_CLAIM_PREFIX + "%%s.%%s", processName);
    // With Storage Class Name.
    final Map<String, Map<VolumeConfigKeys, String>> expectedWithStorageClassName = ImmutableMap.of(volumeNameValid, new HashMap<VolumeConfigKeys, String>() {

        {
            put(VolumeConfigKeys.claimName, passingValue);
            put(VolumeConfigKeys.storageClassName, passingValue);
            put(VolumeConfigKeys.sizeLimit, passingValue);
            put(VolumeConfigKeys.accessModes, passingValue);
            put(VolumeConfigKeys.volumeMode, passingValue);
            put(VolumeConfigKeys.path, passingValue);
            put(VolumeConfigKeys.subPath, passingValue);
            put(VolumeConfigKeys.readOnly, passingValue);
        }
    });
    final Config configWithStorageClass = Config.newBuilder().put(String.format(keyPattern, volumeNameValid, "claimName"), passingValue).put(String.format(keyPattern, volumeNameValid, "storageClassName"), passingValue).put(String.format(keyPattern, volumeNameValid, "sizeLimit"), passingValue).put(String.format(keyPattern, volumeNameValid, "accessModes"), passingValue).put(String.format(keyPattern, volumeNameValid, "volumeMode"), passingValue).put(String.format(keyPattern, volumeNameValid, "path"), passingValue).put(String.format(keyPattern, volumeNameValid, "subPath"), passingValue).put(String.format(keyPattern, volumeNameValid, "readOnly"), passingValue).build();
    testCases.add(new TestTuple<>(processName + ": PVC with Storage Class name", new Pair<>(configWithStorageClass, isExecutor), expectedWithStorageClassName));
    // Without Storage Class Name.
    final Map<String, Map<VolumeConfigKeys, String>> expectedWithoutStorageClassName = ImmutableMap.of(volumeNameValid, new HashMap<VolumeConfigKeys, String>() {

        {
            put(VolumeConfigKeys.claimName, passingValue);
            put(VolumeConfigKeys.sizeLimit, passingValue);
            put(VolumeConfigKeys.accessModes, passingValue);
            put(VolumeConfigKeys.volumeMode, passingValue);
            put(VolumeConfigKeys.path, passingValue);
            put(VolumeConfigKeys.subPath, passingValue);
            put(VolumeConfigKeys.readOnly, passingValue);
        }
    });
    final Config configWithoutStorageClass = Config.newBuilder().put(String.format(keyPattern, volumeNameValid, "claimName"), passingValue).put(String.format(keyPattern, volumeNameValid, "sizeLimit"), passingValue).put(String.format(keyPattern, volumeNameValid, "accessModes"), passingValue).put(String.format(keyPattern, volumeNameValid, "volumeMode"), passingValue).put(String.format(keyPattern, volumeNameValid, "path"), passingValue).put(String.format(keyPattern, volumeNameValid, "subPath"), passingValue).put(String.format(keyPattern, volumeNameValid, "readOnly"), passingValue).build();
    testCases.add(new TestTuple<>(processName + ": PVC with Storage Class name", new Pair<>(configWithoutStorageClass, isExecutor), expectedWithoutStorageClassName));
    // Ignored.
    final Config configIgnored = Config.newBuilder().put(String.format(keyPattern, volumeNameValid, "claimName"), passingValue).put(String.format(keyPattern, volumeNameValid, "storageClassName"), passingValue).put(String.format(keyPattern, volumeNameValid, "sizeLimit"), passingValue).put(String.format(keyPattern, volumeNameValid, "accessModes"), passingValue).put(String.format(keyPattern, volumeNameValid, "volumeMode"), passingValue).put(String.format(keyPattern, volumeNameValid, "path"), passingValue).put(String.format(keyPattern, volumeNameValid, "subPath"), passingValue).put(String.format(keyPattern, volumeNameValid, "readOnly"), passingValue).build();
    testCases.add(new TestTuple<>(processName + ": PVC with ignored keys", new Pair<>(configIgnored, !isExecutor), new HashMap<>()));
}
Also used : VolumeConfigKeys(org.apache.heron.scheduler.kubernetes.KubernetesConstants.VolumeConfigKeys) HashMap(java.util.HashMap) Config(org.apache.heron.spi.common.Config) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) Map(java.util.Map) Pair(org.apache.heron.common.basics.Pair)

Example 2 with VolumeConfigKeys

use of org.apache.heron.scheduler.kubernetes.KubernetesConstants.VolumeConfigKeys in project heron by twitter.

the class KubernetesContextTest method createVolumeHostPath.

/**
 * Create test cases for <code>Host Path</code>.
 * @param testCases Test case container.
 *                  Input: [0] Config, [1] Boolean to indicate Manager/Executor.
 *                  Output: <code>Map<String, Map<VolumeConfigKeys, String></code>
 * @param isExecutor Boolean to indicate Manager/Executor test case generation.
 */
private void createVolumeHostPath(List<TestTuple<Pair<Config, Boolean>, Map<String, Map<VolumeConfigKeys, String>>>> testCases, boolean isExecutor) {
    final String volumeNameValid = "volume-name-valid";
    final String passingValue = "should-pass";
    final String processName = isExecutor ? KubernetesConstants.EXECUTOR_NAME : KubernetesConstants.MANAGER_NAME;
    final String keyPattern = String.format(KubernetesContext.KUBERNETES_VOLUME_HOSTPATH_PREFIX + "%%s.%%s", processName);
    // With type.
    final Map<String, Map<VolumeConfigKeys, String>> expectedWithType = ImmutableMap.of(volumeNameValid, new HashMap<VolumeConfigKeys, String>() {

        {
            put(VolumeConfigKeys.type, "DirectoryOrCreate");
            put(VolumeConfigKeys.path, passingValue);
            put(VolumeConfigKeys.pathOnHost, passingValue);
            put(VolumeConfigKeys.subPath, passingValue);
            put(VolumeConfigKeys.readOnly, passingValue);
        }
    });
    final Config configWithType = Config.newBuilder().put(String.format(keyPattern, volumeNameValid, "type"), "DirectoryOrCreate").put(String.format(keyPattern, volumeNameValid, "pathOnHost"), passingValue).put(String.format(keyPattern, volumeNameValid, "path"), passingValue).put(String.format(keyPattern, volumeNameValid, "subPath"), passingValue).put(String.format(keyPattern, volumeNameValid, "readOnly"), passingValue).build();
    testCases.add(new TestTuple<>(processName + ": 'hostPath' with 'type'", new Pair<>(configWithType, isExecutor), expectedWithType));
    // Without type.
    final Map<String, Map<VolumeConfigKeys, String>> expectedWithoutType = ImmutableMap.of(volumeNameValid, new HashMap<VolumeConfigKeys, String>() {

        {
            put(VolumeConfigKeys.pathOnHost, passingValue);
            put(VolumeConfigKeys.path, passingValue);
            put(VolumeConfigKeys.subPath, passingValue);
            put(VolumeConfigKeys.readOnly, passingValue);
        }
    });
    final Config configWithoutType = Config.newBuilder().put(String.format(keyPattern, volumeNameValid, "pathOnHost"), passingValue).put(String.format(keyPattern, volumeNameValid, "path"), passingValue).put(String.format(keyPattern, volumeNameValid, "subPath"), passingValue).put(String.format(keyPattern, volumeNameValid, "readOnly"), passingValue).build();
    testCases.add(new TestTuple<>(processName + ": 'hostPath' without 'type'", new Pair<>(configWithoutType, isExecutor), expectedWithoutType));
    // Ignored.
    final Config configIgnored = Config.newBuilder().put(String.format(keyPattern, volumeNameValid, "type"), "BlockDevice").put(String.format(keyPattern, volumeNameValid, "pathOnHost"), passingValue).put(String.format(keyPattern, volumeNameValid, "path"), passingValue).put(String.format(keyPattern, volumeNameValid, "subPath"), passingValue).put(String.format(keyPattern, volumeNameValid, "readOnly"), passingValue).build();
    testCases.add(new TestTuple<>(processName + ": 'hostPath' ignored", new Pair<>(configIgnored, !isExecutor), new HashMap<>()));
}
Also used : VolumeConfigKeys(org.apache.heron.scheduler.kubernetes.KubernetesConstants.VolumeConfigKeys) HashMap(java.util.HashMap) Config(org.apache.heron.spi.common.Config) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) Map(java.util.Map) Pair(org.apache.heron.common.basics.Pair)

Example 3 with VolumeConfigKeys

use of org.apache.heron.scheduler.kubernetes.KubernetesConstants.VolumeConfigKeys in project heron by twitter.

the class V1ControllerTest method testCreateVolumeAndMountsNFSCLI.

@Test
public void testCreateVolumeAndMountsNFSCLI() {
    final String volumeName = "volume-name-nfs";
    final String server = "nfs.server.address";
    final String pathOnNFS = "path.on.host";
    final String readOnly = "true";
    final String path = "/path/to/mount";
    final String subPath = "/sub/path/to/mount";
    // NFS.
    final Map<String, Map<VolumeConfigKeys, String>> config = ImmutableMap.of(volumeName, new HashMap<VolumeConfigKeys, String>() {

        {
            put(VolumeConfigKeys.server, server);
            put(VolumeConfigKeys.readOnly, readOnly);
            put(VolumeConfigKeys.pathOnNFS, pathOnNFS);
            put(VolumeConfigKeys.path, path);
            put(VolumeConfigKeys.subPath, subPath);
        }
    });
    final List<V1Volume> expectedVolumes = Collections.singletonList(new V1VolumeBuilder().withName(volumeName).withNewNfs().withServer(server).withPath(pathOnNFS).withReadOnly(Boolean.parseBoolean(readOnly)).endNfs().build());
    final List<V1VolumeMount> expectedMounts = Collections.singletonList(new V1VolumeMountBuilder().withName(volumeName).withMountPath(path).withSubPath(subPath).withReadOnly(true).build());
    List<V1Volume> actualVolumes = new LinkedList<>();
    List<V1VolumeMount> actualMounts = new LinkedList<>();
    v1ControllerPodTemplate.createVolumeAndMountsNFSCLI(config, actualVolumes, actualMounts);
    Assert.assertEquals("NFS Volume populated", expectedVolumes, actualVolumes);
    Assert.assertEquals("NFS Volume Mount populated", expectedMounts, actualMounts);
}
Also used : V1VolumeBuilder(io.kubernetes.client.openapi.models.V1VolumeBuilder) VolumeConfigKeys(org.apache.heron.scheduler.kubernetes.KubernetesConstants.VolumeConfigKeys) V1Volume(io.kubernetes.client.openapi.models.V1Volume) Matchers.anyString(org.mockito.Matchers.anyString) V1VolumeMountBuilder(io.kubernetes.client.openapi.models.V1VolumeMountBuilder) HashMap(java.util.HashMap) V1ConfigMap(io.kubernetes.client.openapi.models.V1ConfigMap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) LinkedList(java.util.LinkedList) V1VolumeMount(io.kubernetes.client.openapi.models.V1VolumeMount) Test(org.junit.Test)

Example 4 with VolumeConfigKeys

use of org.apache.heron.scheduler.kubernetes.KubernetesConstants.VolumeConfigKeys in project heron by twitter.

the class V1ControllerTest method testCreateVolumeAndMountsEmptyDirCLI.

@Test
public void testCreateVolumeAndMountsEmptyDirCLI() {
    final String volumeName = "volume-name-empty-dir";
    final String medium = "Memory";
    final String sizeLimit = "1Gi";
    final String path = "/path/to/mount";
    final String subPath = "/sub/path/to/mount";
    // Empty Dir.
    final Map<String, Map<VolumeConfigKeys, String>> config = ImmutableMap.of(volumeName, new HashMap<VolumeConfigKeys, String>() {

        {
            put(VolumeConfigKeys.sizeLimit, sizeLimit);
            put(VolumeConfigKeys.medium, "Memory");
            put(VolumeConfigKeys.path, path);
            put(VolumeConfigKeys.subPath, subPath);
        }
    });
    final List<V1Volume> expectedVolumes = Collections.singletonList(new V1VolumeBuilder().withName(volumeName).withNewEmptyDir().withMedium(medium).withNewSizeLimit(sizeLimit).endEmptyDir().build());
    final List<V1VolumeMount> expectedMounts = Collections.singletonList(new V1VolumeMountBuilder().withName(volumeName).withMountPath(path).withSubPath(subPath).build());
    List<V1Volume> actualVolumes = new LinkedList<>();
    List<V1VolumeMount> actualMounts = new LinkedList<>();
    v1ControllerPodTemplate.createVolumeAndMountsEmptyDirCLI(config, actualVolumes, actualMounts);
    Assert.assertEquals("Empty Dir Volume populated", expectedVolumes, actualVolumes);
    Assert.assertEquals("Empty Dir Volume Mount populated", expectedMounts, actualMounts);
}
Also used : V1VolumeBuilder(io.kubernetes.client.openapi.models.V1VolumeBuilder) VolumeConfigKeys(org.apache.heron.scheduler.kubernetes.KubernetesConstants.VolumeConfigKeys) V1Volume(io.kubernetes.client.openapi.models.V1Volume) Matchers.anyString(org.mockito.Matchers.anyString) V1VolumeMountBuilder(io.kubernetes.client.openapi.models.V1VolumeMountBuilder) HashMap(java.util.HashMap) V1ConfigMap(io.kubernetes.client.openapi.models.V1ConfigMap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) LinkedList(java.util.LinkedList) V1VolumeMount(io.kubernetes.client.openapi.models.V1VolumeMount) Test(org.junit.Test)

Example 5 with VolumeConfigKeys

use of org.apache.heron.scheduler.kubernetes.KubernetesConstants.VolumeConfigKeys in project heron by twitter.

the class V1ControllerTest method testCreatePersistentVolumeClaimVolumesAndMounts.

@Test
public void testCreatePersistentVolumeClaimVolumesAndMounts() {
    final String volumeNameOne = "VolumeNameONE";
    final String volumeNameTwo = "VolumeNameTWO";
    final String claimNameOne = "claim-name-one";
    final String claimNameTwo = "OnDemand";
    final String mountPathOne = "/mount/path/ONE";
    final String mountPathTwo = "/mount/path/TWO";
    final String mountSubPathTwo = "/mount/sub/path/TWO";
    Map<String, Map<VolumeConfigKeys, String>> mapOfOpts = ImmutableMap.of(volumeNameOne, ImmutableMap.of(VolumeConfigKeys.claimName, claimNameOne, VolumeConfigKeys.path, mountPathOne), volumeNameTwo, ImmutableMap.of(VolumeConfigKeys.claimName, claimNameTwo, VolumeConfigKeys.path, mountPathTwo, VolumeConfigKeys.subPath, mountSubPathTwo));
    final V1Volume volumeOne = new V1VolumeBuilder().withName(volumeNameOne).withNewPersistentVolumeClaim().withClaimName(claimNameOne).endPersistentVolumeClaim().build();
    final V1Volume volumeTwo = new V1VolumeBuilder().withName(volumeNameTwo).withNewPersistentVolumeClaim().withClaimName(claimNameTwo).endPersistentVolumeClaim().build();
    final V1VolumeMount volumeMountOne = new V1VolumeMountBuilder().withName(volumeNameOne).withMountPath(mountPathOne).build();
    final V1VolumeMount volumeMountTwo = new V1VolumeMountBuilder().withName(volumeNameTwo).withMountPath(mountPathTwo).withSubPath(mountSubPathTwo).build();
    // Test case container.
    // Input: Map of Volume configurations.
    // Output: The expected lists of Volumes and Volume Mounts.
    final List<TestTuple<Map<String, Map<VolumeConfigKeys, String>>, Pair<List<V1Volume>, List<V1VolumeMount>>>> testCases = new LinkedList<>();
    // Default case: No PVC provided.
    testCases.add(new TestTuple<>("Generated an empty list of Volumes", new HashMap<>(), new Pair<>(new LinkedList<>(), new LinkedList<>())));
    // PVC Provided.
    final Pair<List<V1Volume>, List<V1VolumeMount>> expectedFull = new Pair<>(new LinkedList<>(Arrays.asList(volumeOne, volumeTwo)), new LinkedList<>(Arrays.asList(volumeMountOne, volumeMountTwo)));
    testCases.add(new TestTuple<>("Generated a list of Volumes", mapOfOpts, new Pair<>(expectedFull.first, expectedFull.second)));
    // Testing loop.
    for (TestTuple<Map<String, Map<VolumeConfigKeys, String>>, Pair<List<V1Volume>, List<V1VolumeMount>>> testCase : testCases) {
        List<V1Volume> actualVolume = new LinkedList<>();
        List<V1VolumeMount> actualVolumeMount = new LinkedList<>();
        v1ControllerPodTemplate.createVolumeAndMountsPersistentVolumeClaimCLI(testCase.input, actualVolume, actualVolumeMount);
        Assert.assertTrue(testCase.description, (testCase.expected.first).containsAll(actualVolume));
        Assert.assertTrue(testCase.description + " Mounts", (testCase.expected.second).containsAll(actualVolumeMount));
    }
}
Also used : VolumeConfigKeys(org.apache.heron.scheduler.kubernetes.KubernetesConstants.VolumeConfigKeys) HashMap(java.util.HashMap) Matchers.anyString(org.mockito.Matchers.anyString) LinkedList(java.util.LinkedList) V1VolumeMount(io.kubernetes.client.openapi.models.V1VolumeMount) V1VolumeBuilder(io.kubernetes.client.openapi.models.V1VolumeBuilder) V1Volume(io.kubernetes.client.openapi.models.V1Volume) TestTuple(org.apache.heron.scheduler.kubernetes.KubernetesUtils.TestTuple) LinkedList(java.util.LinkedList) List(java.util.List) V1VolumeMountBuilder(io.kubernetes.client.openapi.models.V1VolumeMountBuilder) HashMap(java.util.HashMap) V1ConfigMap(io.kubernetes.client.openapi.models.V1ConfigMap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) Pair(org.apache.heron.common.basics.Pair) Test(org.junit.Test)

Aggregations

VolumeConfigKeys (org.apache.heron.scheduler.kubernetes.KubernetesConstants.VolumeConfigKeys)11 ImmutableMap (com.google.common.collect.ImmutableMap)10 HashMap (java.util.HashMap)10 Map (java.util.Map)10 LinkedList (java.util.LinkedList)7 Pair (org.apache.heron.common.basics.Pair)7 V1ConfigMap (io.kubernetes.client.openapi.models.V1ConfigMap)6 Test (org.junit.Test)6 Matchers.anyString (org.mockito.Matchers.anyString)6 V1VolumeMount (io.kubernetes.client.openapi.models.V1VolumeMount)5 V1VolumeMountBuilder (io.kubernetes.client.openapi.models.V1VolumeMountBuilder)5 Config (org.apache.heron.spi.common.Config)5 V1Volume (io.kubernetes.client.openapi.models.V1Volume)4 V1VolumeBuilder (io.kubernetes.client.openapi.models.V1VolumeBuilder)4 TestTuple (org.apache.heron.scheduler.kubernetes.KubernetesUtils.TestTuple)2 Quantity (io.kubernetes.client.custom.Quantity)1 V1PersistentVolumeClaim (io.kubernetes.client.openapi.models.V1PersistentVolumeClaim)1 V1PersistentVolumeClaimBuilder (io.kubernetes.client.openapi.models.V1PersistentVolumeClaimBuilder)1 List (java.util.List)1