felix-thinkingdata commented on a change in pull request #3695:
URL:
https://github.com/apache/incubator-dolphinscheduler/pull/3695#discussion_r486387794
##########
File path:
dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/NetUtils.java
##########
@@ -227,4 +230,72 @@ private static boolean
isSpecifyNetworkInterface(NetworkInterface networkInterfa
String preferredNetworkInterface =
System.getProperty(DOLPHIN_SCHEDULER_PREFERRED_NETWORK_INTERFACE);
return Objects.equals(networkInterface.getDisplayName(),
preferredNetworkInterface);
}
+
+ private static NetworkInterface findAddress(List<NetworkInterface>
validNetworkInterfaces) {
+ if (validNetworkInterfaces.isEmpty()) {
+ return null;
+ }
+ String networkPriority =
PropertyUtils.getString(Constants.NETWORK_PRIORITY_STRATEGY,
NETWORK_PRIORITY_DEFAULT);
+ if (NETWORK_PRIORITY_DEFAULT.equalsIgnoreCase(networkPriority)) {
+ return findAddressByDefaultPolicy(validNetworkInterfaces);
+ } else if (NETWORK_PRIORITY_INNER.equalsIgnoreCase(networkPriority)) {
+ return findInnerAddress(validNetworkInterfaces);
+ } else if (NETWORK_PRIORITY_OUTER.equalsIgnoreCase(networkPriority)) {
+ return findOuterAddress(validNetworkInterfaces);
+ } else {
+ logger.error("There is no matching network card acquisition
policy!");
+ return null;
+ }
+ }
+
+ private static NetworkInterface
findAddressByDefaultPolicy(List<NetworkInterface> validNetworkInterfaces) {
+ NetworkInterface networkInterface;
+ networkInterface = findInnerAddress(validNetworkInterfaces);
+ if (networkInterface == null) {
+ networkInterface = findOuterAddress(validNetworkInterfaces);
+ if (networkInterface == null) {
+ networkInterface = validNetworkInterfaces.get(0);
+ }
+ }
+ return networkInterface;
+ }
+
+ /**
+ * Get the Intranet IP
+ *
+ * @return If no {@link NetworkInterface} is available , return
<code>null</code>
+ */
+ private static NetworkInterface findInnerAddress(List<NetworkInterface>
validNetworkInterfaces) {
+
+ NetworkInterface networkInterface = null;
+ for (NetworkInterface ni : validNetworkInterfaces) {
+ Enumeration<InetAddress> address = ni.getInetAddresses();
+ while (address.hasMoreElements()) {
+ InetAddress ip = address.nextElement();
+ if (ip.isSiteLocalAddress()
+ && !ip.isLoopbackAddress()
+ && !ip.getHostAddress().contains(":")) {
+ networkInterface = ni;
+ }
+ }
+ }
+ return networkInterface;
+ }
+
+ private static NetworkInterface findOuterAddress(List<NetworkInterface>
validNetworkInterfaces) {
+ NetworkInterface networkInterface = null;
+ for (NetworkInterface ni : validNetworkInterfaces) {
+ Enumeration<InetAddress> address = ni.getInetAddresses();
+ while (address.hasMoreElements()) {
+ InetAddress ip = address.nextElement();
+ if (!ip.isSiteLocalAddress()
+ && !ip.isLoopbackAddress()
+ && !ip.getHostAddress().contains(":")) {
+ networkInterface = ni;
Review comment:
yes i will support ipv6 --x:--x:--x:--x:--x:--x:--x:--x,remove &&
!ip.getHostAddress().contains(":")
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]