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

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

commit 6ed28c84d4b0ba95660332663a687bdccedaa699
Author: Piotr Nowojski <[email protected]>
AuthorDate: Wed Apr 24 18:06:46 2019 +0200

    [hotfix][runtime] Deduplicate and simplify environment variables handling 
in FlinkDistributionOverlay
---
 .../overlays/FlinkDistributionOverlay.java         | 32 +++++++---------------
 1 file changed, 10 insertions(+), 22 deletions(-)

diff --git 
a/flink-runtime/src/main/java/org/apache/flink/runtime/clusterframework/overlays/FlinkDistributionOverlay.java
 
b/flink-runtime/src/main/java/org/apache/flink/runtime/clusterframework/overlays/FlinkDistributionOverlay.java
index 0655554..baebd8c 100644
--- 
a/flink-runtime/src/main/java/org/apache/flink/runtime/clusterframework/overlays/FlinkDistributionOverlay.java
+++ 
b/flink-runtime/src/main/java/org/apache/flink/runtime/clusterframework/overlays/FlinkDistributionOverlay.java
@@ -33,6 +33,7 @@ import static 
org.apache.flink.configuration.ConfigConstants.ENV_FLINK_CONF_DIR;
 import static 
org.apache.flink.configuration.ConfigConstants.ENV_FLINK_HOME_DIR;
 import static org.apache.flink.configuration.ConfigConstants.ENV_FLINK_LIB_DIR;
 import static org.apache.flink.util.Preconditions.checkNotNull;
+import static org.apache.flink.util.Preconditions.checkState;
 
 /**
  * Overlays Flink into a container, based on supplied bin/conf/lib directories.
@@ -93,28 +94,9 @@ public class FlinkDistributionOverlay extends 
AbstractContainerOverlay {
                 * @param globalConfiguration the current configuration.
                 */
                public Builder fromEnvironment(Configuration 
globalConfiguration) {
-
-                       Map<String,String> env = System.getenv();
-                       if(env.containsKey(ENV_FLINK_BIN_DIR)) {
-                               flinkBinPath = new 
File(System.getenv(ENV_FLINK_BIN_DIR));
-                       }
-                       else {
-                               throw new 
IllegalStateException(String.format("the %s environment variable must be set", 
ENV_FLINK_BIN_DIR));
-                       }
-
-                       if(env.containsKey(ENV_FLINK_CONF_DIR)) {
-                               flinkConfPath = new 
File(System.getenv(ENV_FLINK_CONF_DIR));
-                       }
-                       else {
-                               throw new 
IllegalStateException(String.format("the %s environment variable must be set", 
ENV_FLINK_CONF_DIR));
-                       }
-
-                       if(env.containsKey(ENV_FLINK_LIB_DIR)) {
-                               flinkLibPath = new 
File(System.getenv(ENV_FLINK_LIB_DIR));
-                       }
-                       else {
-                               throw new 
IllegalStateException(String.format("the %s environment variable must be set", 
ENV_FLINK_LIB_DIR));
-                       }
+                       flinkBinPath = 
getObligatoryFileFromEnvironment(ENV_FLINK_BIN_DIR);
+                       flinkConfPath = 
getObligatoryFileFromEnvironment(ENV_FLINK_CONF_DIR);
+                       flinkLibPath = 
getObligatoryFileFromEnvironment(ENV_FLINK_LIB_DIR);
 
                        return this;
                }
@@ -122,5 +104,11 @@ public class FlinkDistributionOverlay extends 
AbstractContainerOverlay {
                public FlinkDistributionOverlay build() {
                        return new FlinkDistributionOverlay(flinkBinPath, 
flinkConfPath, flinkLibPath);
                }
+
+               private static File getObligatoryFileFromEnvironment(String 
envVariableName) {
+                       String directory = System.getenv(envVariableName);
+                       checkState(directory != null, "the %s environment 
variable must be set", envVariableName);
+                       return new File(directory);
+               }
        }
 }

Reply via email to