You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dolphinscheduler.apache.org by ki...@apache.org on 2021/07/19 09:10:37 UTC

[dolphinscheduler] 01/01: [1.3.7-prepare#5468][Improvement][Common] Fix obtaining IP is incorrect pr#5594 issue #5468

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

kirs pushed a commit to branch 1.3.7-prepare-#5468
in repository https://gitbox.apache.org/repos/asf/dolphinscheduler.git

commit f4eb0d9752119d68308d2dc104eed8f53a129ec8
Author: CalvinKirs <ki...@apache.org>
AuthorDate: Mon Jul 19 17:10:19 2021 +0800

    [1.3.7-prepare#5468][Improvement][Common] Fix obtaining IP is incorrect
    pr#5594
    issue #5468
---
 .../build/conf/dolphinscheduler/common.properties.tpl   |  6 ++++++
 .../org/apache/dolphinscheduler/common/Constants.java   |  6 +++---
 .../apache/dolphinscheduler/common/utils/NetUtils.java  | 17 +++++------------
 .../src/main/resources/common.properties                |  6 ++++++
 4 files changed, 20 insertions(+), 15 deletions(-)

diff --git a/docker/build/conf/dolphinscheduler/common.properties.tpl b/docker/build/conf/dolphinscheduler/common.properties.tpl
index 83f7307..84a4496 100644
--- a/docker/build/conf/dolphinscheduler/common.properties.tpl
+++ b/docker/build/conf/dolphinscheduler/common.properties.tpl
@@ -66,5 +66,11 @@ yarn.application.status.address=${YARN_APPLICATION_STATUS_ADDRESS}
 # system env path
 #dolphinscheduler.env.path=env/dolphinscheduler_env.sh
 
+# network interface preferred like eth0, default: empty
+#dolphin.scheduler.network.interface.preferred=
+
+# network IP gets priority, default: inner outer
+#dolphin.scheduler.network.priority.strategy=default
+
 # development state
 development.state=false
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 fe83fa1..0094375 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
@@ -991,12 +991,12 @@ public final class Constants {
     /**
      * Network system properties
      */
-    public static final String DOLPHIN_SCHEDULER_PREFERRED_NETWORK_INTERFACE = "dolphin.scheduler.network.interface.preferred";
+    public static final String DOLPHIN_SCHEDULER_NETWORK_INTERFACE_PREFERRED = "dolphin.scheduler.network.interface.preferred";
 
     /**
-     * Network IP gets priority, default inner outer
+     * network IP gets priority, default inner outer
      */
-    public static final String NETWORK_PRIORITY_STRATEGY = "dolphin.scheduler.network.priority.strategy";
+    public static final String DOLPHIN_SCHEDULER_NETWORK_PRIORITY_STRATEGY = "dolphin.scheduler.network.priority.strategy";
 
 
     /**
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 4314089..397dc58 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
@@ -17,8 +17,6 @@
 
 package org.apache.dolphinscheduler.common.utils;
 
-import static org.apache.dolphinscheduler.common.Constants.DOLPHIN_SCHEDULER_PREFERRED_NETWORK_INTERFACE;
-
 import static java.util.Collections.emptyList;
 
 import org.apache.dolphinscheduler.common.Constants;
@@ -44,7 +42,6 @@ import org.slf4j.LoggerFactory;
  */
 public class NetUtils {
 
-    private static final Pattern STS_PATTERN = Pattern.compile("-\\d+$"); // StatefulSet pattern
     private static final Pattern IP_PATTERN = Pattern.compile("\\d{1,3}(\\.\\d{1,3}){3,5}$");
     private static final String NETWORK_PRIORITY_DEFAULT = "default";
     private static final String NETWORK_PRIORITY_INNER = "inner";
@@ -81,13 +78,8 @@ public class NetUtils {
         if (inetAddress != null) {
             if (Constants.KUBERNETES_MODE) {
                 String canonicalHost = inetAddress.getCanonicalHostName();
-                if (!canonicalHost.contains(".") || IP_PATTERN.matcher(canonicalHost).matches()) {
-                    String host = inetAddress.getHostName();
-                    if (STS_PATTERN.matcher(host).find()) {
-                        return String.format("%s.%s", host, host.replaceFirst("\\d+$", "headless"));
-                    }
-                } else if (canonicalHost.contains(".")) {
                     String[] items = canonicalHost.split("\\.");
+                if (items.length == 6 && "svc".equals(items[3])) {
                     return String.format("%s.%s", items[0], items[1]);
                 }
                 return canonicalHost;
@@ -136,7 +128,7 @@ public class NetUtils {
                     Optional<InetAddress> addressOp = toValidAddress(addresses.nextElement());
                     if (addressOp.isPresent()) {
                         try {
-                            if (addressOp.get().isReachable(100)) {
+                            if (addressOp.get().isReachable(200)) {
                                 LOCAL_ADDRESS = addressOp.get();
                                 return LOCAL_ADDRESS;
                             }
@@ -266,7 +258,8 @@ public class NetUtils {
     }
 
     private static boolean isSpecifyNetworkInterface(NetworkInterface networkInterface) {
-        String preferredNetworkInterface = System.getProperty(DOLPHIN_SCHEDULER_PREFERRED_NETWORK_INTERFACE);
+        String preferredNetworkInterface = PropertyUtils.getString(Constants.DOLPHIN_SCHEDULER_NETWORK_INTERFACE_PREFERRED,
+                System.getProperty(Constants.DOLPHIN_SCHEDULER_NETWORK_INTERFACE_PREFERRED));
         return Objects.equals(networkInterface.getDisplayName(), preferredNetworkInterface);
     }
 
@@ -274,7 +267,7 @@ public class NetUtils {
         if (validNetworkInterfaces.isEmpty()) {
             return null;
         }
-        String networkPriority = PropertyUtils.getString(Constants.NETWORK_PRIORITY_STRATEGY, NETWORK_PRIORITY_DEFAULT);
+        String networkPriority = PropertyUtils.getString(Constants.DOLPHIN_SCHEDULER_NETWORK_PRIORITY_STRATEGY, NETWORK_PRIORITY_DEFAULT);
         if (NETWORK_PRIORITY_DEFAULT.equalsIgnoreCase(networkPriority)) {
             return findAddressByDefaultPolicy(validNetworkInterfaces);
         } else if (NETWORK_PRIORITY_INNER.equalsIgnoreCase(networkPriority)) {
diff --git a/dolphinscheduler-common/src/main/resources/common.properties b/dolphinscheduler-common/src/main/resources/common.properties
index 5bb7c39..9cd7355 100644
--- a/dolphinscheduler-common/src/main/resources/common.properties
+++ b/dolphinscheduler-common/src/main/resources/common.properties
@@ -63,6 +63,12 @@ yarn.resourcemanager.ha.rm.ids=192.168.xx.xx,192.168.xx.xx
 # if resourcemanager HA is enabled or not use resourcemanager, please keep the default value; If resourcemanager is single, you only need to replace ds1 to actual resourcemanager hostname
 yarn.application.status.address=http://ds1:8088/ws/v1/cluster/apps/%s
 
+# network interface preferred like eth0, default: empty
+#dolphin.scheduler.network.interface.preferred=
+
+# network IP gets priority, default: inner outer
+#dolphin.scheduler.network.priority.strategy=default
+
 # system env path
 #dolphinscheduler.env.path=env/dolphinscheduler_env.sh