You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@heron.apache.org by sa...@apache.org on 2022/05/01 18:06:01 UTC

[incubator-heron] branch saadurrahman/3821-Remove-Deprecated-Volumes-K8s-dev updated (f254eb1d6c1 -> 2707cd95b53)

This is an automated email from the ASF dual-hosted git repository.

saadurrahman pushed a change to branch saadurrahman/3821-Remove-Deprecated-Volumes-K8s-dev
in repository https://gitbox.apache.org/repos/asf/incubator-heron.git


 discard f254eb1d6c1 [K8s] removed unused functions.
 discard 1528fbf8bd6 [K8s] Added support for Empty Directory.
     new b7999d2db4a [K8s] Added support for Empty Directory.
     new 2707cd95b53 [K8s] removed unused functions.

This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version.  This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:

 * -- * -- B -- O -- O -- O   (f254eb1d6c1)
            \
             N -- N -- N   refs/heads/saadurrahman/3821-Remove-Deprecated-Volumes-K8s-dev (2707cd95b53)

You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.

Any revisions marked "omit" are not gone; other references still
refer to them.  Any revisions marked "discard" are gone forever.

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../apache/heron/scheduler/kubernetes/VolumesTests.java    | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)


[incubator-heron] 02/02: [K8s] removed unused functions.

Posted by sa...@apache.org.
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 2707cd95b53df5d5abf68b646ab26341e470497e
Author: Saad Ur Rahman <sa...@apache.org>
AuthorDate: Sun May 1 12:52:09 2022 -0400

    [K8s] removed unused functions.
---
 .../apache/heron/scheduler/kubernetes/KubernetesContext.java | 12 ------------
 1 file changed, 12 deletions(-)

diff --git a/heron/schedulers/src/java/org/apache/heron/scheduler/kubernetes/KubernetesContext.java b/heron/schedulers/src/java/org/apache/heron/scheduler/kubernetes/KubernetesContext.java
index 091d3c25df4..8d9a8795070 100644
--- a/heron/schedulers/src/java/org/apache/heron/scheduler/kubernetes/KubernetesContext.java
+++ b/heron/schedulers/src/java/org/apache/heron/scheduler/kubernetes/KubernetesContext.java
@@ -147,18 +147,6 @@ public final class KubernetesContext extends Context {
             config.getStringValue(KUBERNETES_RESOURCE_REQUEST_MODE));
   }
 
-  static String getVolumeType(Config config) {
-    return config.getStringValue(KUBERNETES_VOLUME_TYPE);
-  }
-
-  static String getVolumeName(Config config) {
-    return config.getStringValue(KUBERNETES_VOLUME_NAME);
-  }
-
-  static boolean hasVolume(Config config) {
-    return isNotEmpty(getVolumeType(config));
-  }
-
   static String getContainerVolumeName(Config config) {
     return config.getStringValue(KUBERNETES_CONTAINER_VOLUME_MOUNT_NAME);
   }


[incubator-heron] 01/02: [K8s] Added support for Empty Directory.

Posted by sa...@apache.org.
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 b7999d2db4a4a500ff4c4d463420dc772b845cd5
Author: Saad Ur Rahman <sa...@apache.org>
AuthorDate: Sun May 1 14:04:35 2022 -0400

    [K8s] Added support for Empty Directory.
---
 .../apache/heron/scheduler/kubernetes/Volumes.java | 66 ++++++++++++++++++----
 .../heron/scheduler/kubernetes/VolumesTests.java   | 36 ++++++++++--
 2 files changed, 86 insertions(+), 16 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 a4d92cfc938..3b597338031 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
@@ -22,35 +22,81 @@ package org.apache.heron.scheduler.kubernetes;
 import java.util.HashMap;
 import java.util.Map;
 
-import org.apache.heron.spi.common.Config;
-
+import io.kubernetes.client.custom.Quantity;
 import io.kubernetes.client.openapi.models.V1Volume;
+import io.kubernetes.client.openapi.models.V1VolumeBuilder;
 
 final class Volumes {
 
-  private final Map<String, VolumeFactory> volumes = new HashMap<>();
+  public enum VolumeType {
+    EmptyDir,
+    Generic,
+    HostPath,
+    NetworkFileSystem,
+    PersistentVolumeClaim,
+    VolumeMount
+  }
+  private final Map<VolumeType, VolumeFactory> volumes = new HashMap<>();
 
   private Volumes() {
+    volumes.put(VolumeType.EmptyDir, new EmptyDirVolumeFactory());
   }
 
   static Volumes get() {
     return new Volumes();
   }
 
-  V1Volume create(Config config) {
-    final String volumeType = KubernetesContext.getVolumeType(config);
+  /**
+   * Creates <code>Generic</code>, <code>Empty Directory</code>, <code>Host Path</code>, and
+   * <code>Network File System</code> volumes.
+   * @param volumeType One of the supported volume types.
+   * @param volumeName The name of the volume to generate.
+   * @param configs A map of configurations.
+   * @return Fully configured <code>V1Volume</code>.
+   */
+  V1Volume create(VolumeType volumeType, String volumeName,
+                  Map<KubernetesConstants.VolumeConfigKeys, String> configs) {
     if (volumes.containsKey(volumeType)) {
-      return volumes.get(volumeType).create(config);
+      return volumes.get(volumeType).create(volumeName, configs);
     }
     return null;
   }
 
   interface VolumeFactory {
-    V1Volume create(Config config);
+    V1Volume create(String volumeName, Map<KubernetesConstants.VolumeConfigKeys, String> configs);
   }
 
-  private static V1Volume newVolume(Config config) {
-    final String volumeName = KubernetesContext.getVolumeName(config);
-    return new V1Volume().name(volumeName);
+  static class EmptyDirVolumeFactory implements VolumeFactory {
+
+    /**
+     * 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.
+     * @return A fully configured <code>Empty Directory</code> volume.
+     */
+    @Override
+    public V1Volume create(String volumeName,
+                           Map<KubernetesConstants.VolumeConfigKeys, String> configs) {
+      final V1Volume volume = new V1VolumeBuilder()
+          .withName(volumeName)
+          .withNewEmptyDir()
+          .endEmptyDir()
+          .build();
+
+      for (Map.Entry<KubernetesConstants.VolumeConfigKeys, String> config : configs.entrySet()) {
+        switch(config.getKey()) {
+          case medium:
+            volume.getEmptyDir().medium(config.getValue());
+            break;
+          case sizeLimit:
+            volume.getEmptyDir().sizeLimit(new Quantity(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 2609e70f177..316947f9267 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
@@ -19,19 +19,43 @@
 
 package org.apache.heron.scheduler.kubernetes;
 
+import java.util.Map;
+
+import com.google.common.collect.ImmutableMap;
+
 import org.junit.Assert;
 import org.junit.Test;
 
-import org.apache.heron.spi.common.Config;
-
 import io.kubernetes.client.openapi.models.V1Volume;
+import io.kubernetes.client.openapi.models.V1VolumeBuilder;
 
 public class VolumesTests {
 
   @Test
-  public void testNoVolume() {
-    final Config config = Config.newBuilder().build();
-    final V1Volume volume = Volumes.get().create(config);
-    Assert.assertNull(volume);
+  public void testEmptyDir() {
+    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";
+    final Map<KubernetesConstants.VolumeConfigKeys, String> configEmptyDir =
+        ImmutableMap.<KubernetesConstants.VolumeConfigKeys, String>builder()
+            .put(KubernetesConstants.VolumeConfigKeys.sizeLimit, sizeLimit)
+            .put(KubernetesConstants.VolumeConfigKeys.medium, medium)
+            .put(KubernetesConstants.VolumeConfigKeys.path, path)
+            .put(KubernetesConstants.VolumeConfigKeys.subPath, subPath)
+            .build();
+    final V1Volume expectedVolume = new V1VolumeBuilder()
+        .withName(volumeName)
+        .withNewEmptyDir()
+        .withMedium(medium)
+        .withNewSizeLimit(sizeLimit)
+        .endEmptyDir()
+        .build();
+
+    final V1Volume actualVolume = Volumes.get()
+        .create(Volumes.VolumeType.EmptyDir, volumeName, configEmptyDir);
+
+    Assert.assertEquals("Volume Factory Empty Directory", expectedVolume, actualVolume);
   }
 }