This is an automated email from the ASF dual-hosted git repository. saadurrahman pushed a commit to branch saadurrahman/3821-Remove-Deprecated-Volumes-K8s-dev in repository https://gitbox.apache.org/repos/asf/incubator-heron.git
commit c13f0eedcd40dc2fe1826b9193f76ea67a488877 Author: Saad Ur Rahman <[email protected]> AuthorDate: Sun May 1 15:25:43 2022 -0400 [K8s] Added support for Network File System. --- .../apache/heron/scheduler/kubernetes/Volumes.java | 42 ++++++++++++++++++++-- .../heron/scheduler/kubernetes/VolumesTests.java | 31 ++++++++++++++++ 2 files changed, 71 insertions(+), 2 deletions(-) diff --git a/heron/schedulers/src/java/org/apache/heron/scheduler/kubernetes/Volumes.java b/heron/schedulers/src/java/org/apache/heron/scheduler/kubernetes/Volumes.java index 6dba3bf8547..8423ce79e20 100644 --- a/heron/schedulers/src/java/org/apache/heron/scheduler/kubernetes/Volumes.java +++ b/heron/schedulers/src/java/org/apache/heron/scheduler/kubernetes/Volumes.java @@ -41,6 +41,7 @@ final class Volumes { private Volumes() { volumes.put(VolumeType.EmptyDir, new EmptyDirVolumeFactory()); volumes.put(VolumeType.HostPath, new HostPathVolumeFactory()); + volumes.put(VolumeType.NetworkFileSystem, new NetworkFileSystemVolumeFactory()); } static Volumes get() { @@ -72,7 +73,7 @@ final class Volumes { /** * Generates an <code>Empty Directory</code> <code>V1 Volume</code>. * @param volumeName The name of the volume to generate. - * @param configs A map of configurations. + * @param configs A map of configurations. * @return A fully configured <code>Empty Directory</code> volume. */ @Override @@ -106,7 +107,7 @@ final class Volumes { /** * Generates an <code>Host Path</code> <code>V1 Volume</code>. * @param volumeName The name of the volume to generate. - * @param configs A map of configurations. + * @param configs A map of configurations. * @return A fully configured <code>Host Path</code> volume. */ @Override @@ -133,4 +134,41 @@ final class Volumes { return volume; } } + + static class NetworkFileSystemVolumeFactory implements VolumeFactory { + + /** + * Generates an <code>Network File System</code> <code>V1 Volume</code>. + * + * @param volumeName The name of the volume to generate. + * @param configs A map of configurations. + * @return A fully configured <code>Network File System</code> volume. + */ + @Override + public V1Volume create(String volumeName, + Map<KubernetesConstants.VolumeConfigKeys, String> configs) { + final V1Volume volume = new V1VolumeBuilder() + .withName(volumeName) + .withNewNfs() + .endNfs() + .build(); + + for (Map.Entry<KubernetesConstants.VolumeConfigKeys, String> config : configs.entrySet()) { + switch (config.getKey()) { + case server: + volume.getNfs().setServer(config.getValue()); + break; + case pathOnNFS: + volume.getNfs().setPath(config.getValue()); + break; + case readOnly: + volume.getNfs().setReadOnly(Boolean.parseBoolean(config.getValue())); + break; + default: + break; + } + } + return volume; + } + } } diff --git a/heron/schedulers/tests/java/org/apache/heron/scheduler/kubernetes/VolumesTests.java b/heron/schedulers/tests/java/org/apache/heron/scheduler/kubernetes/VolumesTests.java index 7e638a839d1..10bb4739bdf 100644 --- a/heron/schedulers/tests/java/org/apache/heron/scheduler/kubernetes/VolumesTests.java +++ b/heron/schedulers/tests/java/org/apache/heron/scheduler/kubernetes/VolumesTests.java @@ -86,4 +86,35 @@ public class VolumesTests { Assert.assertEquals("Volume Factory Host Path", expectedVolume, actualVolume); } + + @Test + public void testNetworkFileSystem() { + 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"; + final Map<KubernetesConstants.VolumeConfigKeys, String> config = + ImmutableMap.<KubernetesConstants.VolumeConfigKeys, String>builder() + .put(KubernetesConstants.VolumeConfigKeys.server, server) + .put(KubernetesConstants.VolumeConfigKeys.readOnly, readOnly) + .put(KubernetesConstants.VolumeConfigKeys.pathOnNFS, pathOnNFS) + .put(KubernetesConstants.VolumeConfigKeys.path, path) + .put(KubernetesConstants.VolumeConfigKeys.subPath, subPath) + .build(); + final V1Volume expectedVolume = new V1VolumeBuilder() + .withName(volumeName) + .withNewNfs() + .withServer(server) + .withPath(pathOnNFS) + .withReadOnly(Boolean.parseBoolean(readOnly)) + .endNfs() + .build(); + + final V1Volume actualVolume = Volumes.get() + .create(Volumes.VolumeType.NetworkFileSystem, volumeName, config); + + Assert.assertEquals("Volume Factory Network File System", expectedVolume, actualVolume); + } }
