Search in sources :

Example 21 with Config

use of org.apache.heron.spi.common.Config 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 22 with Config

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

the class KubernetesContextTest method createVolumeClaimTemplatesErrors.

/**
 * Create test cases for <code>Volume Claim Templates</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 createVolumeClaimTemplatesErrors(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_CLAIM_PREFIX + "%%s.%%s", processName);
    // Required Claim Name.
    final Config configRequiredClaimName = Config.newBuilder().put(String.format(keyPattern, volumeNameValid, "path"), passingValue).build();
    testCases.add(new TestTuple<>(processName + ": Missing Claim Name should trigger exception", new Pair<>(configRequiredClaimName, isExecutor), "require a `claimName`"));
    // Invalid Claim Name.
    final Config configInvalidClaimName = Config.newBuilder().put(String.format(keyPattern, volumeNameValid, "path"), passingValue).put(String.format(keyPattern, volumeNameValid, "claimName"), failureValue).build();
    testCases.add(new TestTuple<>(processName + ": Invalid Claim Name should trigger exception", new Pair<>(configInvalidClaimName, isExecutor), String.format("Volume `%s`: `claimName`", volumeNameValid)));
    // Invalid Storage Class Name.
    final Config configInvalidStorageClassName = Config.newBuilder().put(String.format(keyPattern, volumeNameValid, "claimName"), passingValue).put(String.format(keyPattern, volumeNameValid, "path"), passingValue).put(String.format(keyPattern, volumeNameValid, "storageClassName"), failureValue).build();
    testCases.add(new TestTuple<>(processName + ": Invalid Storage Class Name should trigger exception", new Pair<>(configInvalidStorageClassName, isExecutor), String.format("Volume `%s`: `storageClassName`", volumeNameValid)));
    // Invalid Storage Class Name.
    final Config configInvalidOption = 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, "server"), passingValue).build();
    testCases.add(new TestTuple<>(processName + ": Invalid option should trigger exception", new Pair<>(configInvalidOption, isExecutor), String.format("Volume `%s`: Invalid Persistent", volumeNameValid)));
}
Also used : Config(org.apache.heron.spi.common.Config) Pair(org.apache.heron.common.basics.Pair)

Example 23 with Config

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

the class KubernetesContextTest method createVolumeNFSError.

/**
 * Create test cases for <code>NFS</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 createVolumeNFSError(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_NFS_PREFIX + "%%s.%%s", processName);
    // Server is missing.
    final Config configNoServer = Config.newBuilder().put(String.format(keyPattern, volumeNameValid, "readOnly"), "false").put(String.format(keyPattern, volumeNameValid, "path"), passingValue).put(String.format(keyPattern, volumeNameValid, "pathOnNFS"), passingValue).put(String.format(keyPattern, volumeNameValid, "subPath"), passingValue).build();
    testCases.add(new TestTuple<>(processName + ": No `server` should trigger exception", new Pair<>(configNoServer, isExecutor), "`NFS` volumes require a"));
    // Server is invalid.
    final Config configInvalidServer = Config.newBuilder().put(String.format(keyPattern, volumeNameValid, "server"), "").put(String.format(keyPattern, volumeNameValid, "readOnly"), "false").put(String.format(keyPattern, volumeNameValid, "pathOnNFS"), passingValue).put(String.format(keyPattern, volumeNameValid, "path"), passingValue).put(String.format(keyPattern, volumeNameValid, "subPath"), passingValue).build();
    testCases.add(new TestTuple<>(processName + ": Invalid `server` should trigger exception", new Pair<>(configInvalidServer, isExecutor), "`NFS` volumes require a"));
    // Path on NFS missing.
    final Config configNoNFSPath = Config.newBuilder().put(String.format(keyPattern, volumeNameValid, "server"), "nfs-server.default.local").put(String.format(keyPattern, volumeNameValid, "readOnly"), "false").put(String.format(keyPattern, volumeNameValid, "path"), passingValue).put(String.format(keyPattern, volumeNameValid, "subPath"), passingValue).build();
    testCases.add(new TestTuple<>(processName + ": No path on NFS should trigger exception", new Pair<>(configNoNFSPath, isExecutor), "NFS requires a path on"));
    // Path on NFS is empty.
    final Config configEmptyNFSPath = Config.newBuilder().put(String.format(keyPattern, volumeNameValid, "server"), "nfs-server.default.local").put(String.format(keyPattern, volumeNameValid, "readOnly"), "false").put(String.format(keyPattern, volumeNameValid, "pathOnNFS"), "").put(String.format(keyPattern, volumeNameValid, "path"), passingValue).put(String.format(keyPattern, volumeNameValid, "subPath"), passingValue).build();
    testCases.add(new TestTuple<>(processName + ": No path on NFS should trigger exception", new Pair<>(configEmptyNFSPath, isExecutor), "NFS requires a path on"));
    // Invalid option.
    final Config configInvalidOption = Config.newBuilder().put(String.format(keyPattern, volumeNameValid, "server"), "nfs-server.default.local").put(String.format(keyPattern, volumeNameValid, "readOnly"), "false").put(String.format(keyPattern, volumeNameValid, "pathOnNFS"), passingValue).put(String.format(keyPattern, volumeNameValid, "path"), passingValue).put(String.format(keyPattern, volumeNameValid, "subPath"), passingValue).put(String.format(keyPattern, volumeNameValid, "accessModes"), passingValue).build();
    testCases.add(new TestTuple<>(processName + ": Invalid option should trigger exception", new Pair<>(configInvalidOption, isExecutor), "Invalid NFS option"));
}
Also used : Config(org.apache.heron.spi.common.Config) Pair(org.apache.heron.common.basics.Pair)

Example 24 with Config

use of org.apache.heron.spi.common.Config 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 25 with Config

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

the class VolumesTests method testNfsVolume.

@Test
public void testNfsVolume() {
    final String path = "/test/dir1";
    final String server = "10.10.10.10";
    final Config config = Config.newBuilder().put(KubernetesContext.KUBERNETES_VOLUME_TYPE, "nfs").put(KubernetesContext.KUBERNETES_VOLUME_NFS_PATH, path).put(KubernetesContext.KUBERNETES_VOLUME_NFS_SERVER, server).build();
    final V1Volume volume = Volumes.get().create(config);
    Assert.assertNotNull(volume);
    Assert.assertNotNull(volume.getNfs());
    Assert.assertEquals(volume.getNfs().getPath(), path);
    Assert.assertEquals(volume.getNfs().getServer(), server);
}
Also used : V1Volume(io.kubernetes.client.openapi.models.V1Volume) Config(org.apache.heron.spi.common.Config) 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