You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@zeppelin.apache.org by pd...@apache.org on 2021/03/04 14:45:33 UTC

[zeppelin] branch master updated: [ZEPPELIN-5277] Use RandomStringUtils from apache-commons-lang3

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

pdallig pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/zeppelin.git


The following commit(s) were added to refs/heads/master by this push:
     new b405ace  [ZEPPELIN-5277] Use RandomStringUtils from apache-commons-lang3
b405ace is described below

commit b405ace82b7e1547486f8599585226d191771eea
Author: Philipp Dallig <ph...@gmail.com>
AuthorDate: Wed Mar 3 15:42:38 2021 +0100

    [ZEPPELIN-5277] Use RandomStringUtils from apache-commons-lang3
    
    ### What is this PR for?
    This PR removes our own implementation of random string generation and switches to RandomStringUtils from apache-commons-lang3.
    
    ### What type of PR is it?
    - Refactoring
    
    ### What is the Jira issue?
    * https://issues.apache.org/jira/browse/ZEPPELIN-5277
    
    ### How should this be tested?
    * CI
    
    ### Questions:
    * Does the licenses files need update? No
    * Is there breaking changes for older versions? No
    * Does this needs documentation? No
    
    Author: Philipp Dallig <ph...@gmail.com>
    
    Closes #4069 from Reamer/pod_random_suffix and squashes the following commits:
    
    fd042b997 [Philipp Dallig] Use random method from org.apache.commons.lang3
---
 .../interpreter/launcher/K8sRemoteInterpreterProcess.java  |  4 +++-
 .../org/apache/zeppelin/interpreter/launcher/K8sUtils.java | 14 --------------
 2 files changed, 3 insertions(+), 15 deletions(-)

diff --git a/zeppelin-plugins/launcher/k8s-standard/src/main/java/org/apache/zeppelin/interpreter/launcher/K8sRemoteInterpreterProcess.java b/zeppelin-plugins/launcher/k8s-standard/src/main/java/org/apache/zeppelin/interpreter/launcher/K8sRemoteInterpreterProcess.java
index 13385d5..e0a87fa 100644
--- a/zeppelin-plugins/launcher/k8s-standard/src/main/java/org/apache/zeppelin/interpreter/launcher/K8sRemoteInterpreterProcess.java
+++ b/zeppelin-plugins/launcher/k8s-standard/src/main/java/org/apache/zeppelin/interpreter/launcher/K8sRemoteInterpreterProcess.java
@@ -29,6 +29,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
 
 import org.apache.commons.io.IOUtils;
 import org.apache.commons.lang3.ArrayUtils;
+import org.apache.commons.lang3.RandomStringUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.zeppelin.interpreter.remote.RemoteInterpreterManagedProcess;
 import org.apache.zeppelin.interpreter.remote.RemoteInterpreterUtils;
@@ -112,7 +113,8 @@ public class K8sRemoteInterpreterProcess extends RemoteInterpreterManagedProcess
     this.properties = properties;
     this.portForward = portForward;
     this.sparkImage = sparkImage;
-    this.podName = interpreterGroupName.toLowerCase() + "-" + K8sUtils.getRandomPodSuffix(6);
+    this.podName = interpreterGroupName.toLowerCase() + "-"
+        + RandomStringUtils.randomAlphabetic(6).toLowerCase();
     this.timeoutDuringPending = timeoutDuringPending;
   }
 
diff --git a/zeppelin-plugins/launcher/k8s-standard/src/main/java/org/apache/zeppelin/interpreter/launcher/K8sUtils.java b/zeppelin-plugins/launcher/k8s-standard/src/main/java/org/apache/zeppelin/interpreter/launcher/K8sUtils.java
index e09c517..dd0e05f 100644
--- a/zeppelin-plugins/launcher/k8s-standard/src/main/java/org/apache/zeppelin/interpreter/launcher/K8sUtils.java
+++ b/zeppelin-plugins/launcher/k8s-standard/src/main/java/org/apache/zeppelin/interpreter/launcher/K8sUtils.java
@@ -18,7 +18,6 @@
 
 package org.apache.zeppelin.interpreter.launcher;
 
-import java.util.Random;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
@@ -32,8 +31,6 @@ public class K8sUtils {
   private static final long T = G * K;
   private static final long MINIMUM_OVERHEAD = 384;
 
-  private static final Random rand = new Random();
-
   private K8sUtils() {
     // do nothing
   }
@@ -77,15 +74,4 @@ public class K8sUtils {
     }
     return memoryAmountBytes;
   }
-
-  public static String getRandomPodSuffix(int length) {
-    char[] chars = "abcdefghijklmnopqrstuvwxyz".toCharArray();
-
-    StringBuilder sb = new StringBuilder();
-    for (int i = 0; i < length; i++) {
-      char c = chars[rand.nextInt(chars.length)];
-      sb.append(c);
-    }
-    return sb.toString();
-  }
 }