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

journey pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/incubator-dolphinscheduler.git


The following commit(s) were added to refs/heads/dev by this push:
     new 6f9970b  [Feature-2574][Server]Specify Network Interface (#3186)
6f9970b is described below

commit 6f9970b189d71d043e79200a70a95f2f33ad10f4
Author: CalvinKirs <[email protected]>
AuthorDate: Mon Jul 13 18:51:38 2020 +0800

    [Feature-2574][Server]Specify Network Interface (#3186)
    
    * [Feature-2574][Server]Specify Network Interface
    This closes #2574
    
    * code smell
    
    * code smell
    
    * move DOLPHIN_SCHEDULER_PREFERRED_NETWORK_INTERFACE to Constants.java
---
 .../apache/dolphinscheduler/common/Constants.java  |  5 +++++
 .../dolphinscheduler/common/utils/NetUtils.java    | 22 +++++++++++++++++-----
 2 files changed, 22 insertions(+), 5 deletions(-)

diff --git 
a/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/Constants.java
 
b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/Constants.java
index 2432b7e..57491c9 100644
--- 
a/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/Constants.java
+++ 
b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/Constants.java
@@ -978,5 +978,10 @@ public final class Constants {
     public static final int NORAML_NODE_STATUS = 0;
     public static final int ABNORMAL_NODE_STATUS = 1;
 
+    /**
+     * net system properties
+     */
+    public static final String DOLPHIN_SCHEDULER_PREFERRED_NETWORK_INTERFACE = 
"dolphin.scheduler.network.interface.preferred";
+
 
 }
diff --git 
a/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/NetUtils.java
 
b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/NetUtils.java
index 3bc80c7..13a25dc 100644
--- 
a/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/NetUtils.java
+++ 
b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/NetUtils.java
@@ -21,13 +21,11 @@ import org.slf4j.LoggerFactory;
 
 import java.io.IOException;
 import java.net.*;
-import java.util.Enumeration;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Optional;
+import java.util.*;
 import java.util.regex.Pattern;
 
 import static java.util.Collections.emptyList;
+import static 
org.apache.dolphinscheduler.common.Constants.DOLPHIN_SCHEDULER_PREFERRED_NETWORK_INTERFACE;
 
 /**
  * NetUtils
@@ -171,9 +169,19 @@ public class NetUtils {
             logger.warn("ValidNetworkInterfaces exception", e);
         }
 
+        NetworkInterface result = null;
+        // Try to specify config NetWork Interface
+        for (NetworkInterface networkInterface : validNetworkInterfaces) {
+            if (isSpecifyNetworkInterface(networkInterface)) {
+                result = networkInterface;
+                break;
+            }
+        }
 
+        if (null != result) {
+            return result;
+        }
         return validNetworkInterfaces.get(0);
-
     }
 
     /**
@@ -206,4 +214,8 @@ public class NetUtils {
                 || !networkInterface.isUp();
     }
 
+    private static boolean isSpecifyNetworkInterface(NetworkInterface 
networkInterface) {
+        String preferredNetworkInterface = 
System.getProperty(DOLPHIN_SCHEDULER_PREFERRED_NETWORK_INTERFACE);
+        return Objects.equals(networkInterface.getDisplayName(), 
preferredNetworkInterface);
+    }
 }

Reply via email to