You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@inlong.apache.org by GitBox <gi...@apache.org> on 2022/09/05 06:35:14 UTC

[GitHub] [inlong] pocozh opened a new pull request, #5778: [INLONG-5770][DataProxy] Optimize the method of obtaining the local IP address

pocozh opened a new pull request, #5778:
URL: https://github.com/apache/inlong/pull/5778

   
   ### Prepare a Pull Request
   *(Change the title refer to the following example)*
   
   - [INLONG-5770][DataProxy] Optimize the method of obtaining the local IP address
   
   *(The following *XYZ* should be replaced by the actual [GitHub Issue](https://github.com/apache/inlong/issues) number)*
   
   - Fixes #5770
   
   ### Motivation
   
   *Explain here the context, and why you're making that change. What is the problem you're trying to solve?*
   
   ### Modifications
   
   *Describe the modifications you've done.*
   
   ### Verifying this change
   
   *(Please pick either of the following options)*
   
   - [ ] This change is a trivial rework/code cleanup without any test coverage.
   
   - [ ] This change is already covered by existing tests, such as:
     *(please describe tests)*
   
   - [ ] This change added tests and can be verified as follows:
   
     *(example:)*
     - *Added integration tests for end-to-end deployment with large payloads (10MB)*
     - *Extended integration test for recovery after broker failure*
   
   ### Documentation
   
     - Does this pull request introduce a new feature? (yes / no)
     - If yes, how is the feature documented? (not applicable / docs / JavaDocs / not documented)
     - If a feature is not applicable for documentation, explain why?
     - If a feature is not documented yet in this PR, please create a follow-up issue for adding the documentation
   


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@inlong.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [inlong] dockerzhang merged pull request #5778: [INLONG-5770][DataProxy] Optimize the method of obtaining the local IP address

Posted by GitBox <gi...@apache.org>.
dockerzhang merged PR #5778:
URL: https://github.com/apache/inlong/pull/5778


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@inlong.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [inlong] healchow commented on a diff in pull request #5778: [INLONG-5770][DataProxy] Optimize the method of obtaining the local IP address

Posted by GitBox <gi...@apache.org>.
healchow commented on code in PR #5778:
URL: https://github.com/apache/inlong/pull/5778#discussion_r962847373


##########
inlong-common/src/main/java/org/apache/inlong/common/util/NetworkUtils.java:
##########
@@ -17,59 +17,55 @@
 
 package org.apache.inlong.common.util;
 
+import org.apache.commons.lang3.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
 import java.net.InetAddress;
 import java.net.NetworkInterface;
 import java.net.SocketException;
 import java.util.Enumeration;
 
 public class NetworkUtils {
-    public static String INNER_NETWORK_INTERFACE = "eth1";
 
-    private static String localIp = null;
+    private static final Logger LOGGER = LoggerFactory.getLogger(NetworkUtils.class);
+    private static String localIp;
 
     static {
         localIp = getLocalIp();
     }
 
     /**
      * get local ip
-     * @return
      */
     public static String getLocalIp() {
-        if (localIp == null) {
-            String ip = null;
-            Enumeration<NetworkInterface> allInterface;
-            try {
-                allInterface = NetworkInterface.getNetworkInterfaces();
-                for (; allInterface.hasMoreElements(); ) {
-                    NetworkInterface oneInterface = allInterface.nextElement();
-                    String interfaceName = oneInterface.getName();
-                    if (oneInterface.isLoopback()
-                            || !oneInterface.isUp()
-                            || !interfaceName
-                            .equalsIgnoreCase(INNER_NETWORK_INTERFACE)) {
-                        continue;
-                    }
+        if (!StringUtils.isEmpty(localIp)) {

Review Comment:
   Suggest using `StringUtils.isNotBlank()`.



-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@inlong.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [inlong] pocozh commented on a diff in pull request #5778: [INLONG-5770][DataProxy] Optimize the method of obtaining the local IP address

Posted by GitBox <gi...@apache.org>.
pocozh commented on code in PR #5778:
URL: https://github.com/apache/inlong/pull/5778#discussion_r963198196


##########
inlong-common/src/main/java/org/apache/inlong/common/util/NetworkUtils.java:
##########
@@ -17,59 +17,55 @@
 
 package org.apache.inlong.common.util;
 
+import org.apache.commons.lang3.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
 import java.net.InetAddress;
 import java.net.NetworkInterface;
 import java.net.SocketException;
 import java.util.Enumeration;
 
 public class NetworkUtils {
-    public static String INNER_NETWORK_INTERFACE = "eth1";
 
-    private static String localIp = null;
+    private static final Logger LOGGER = LoggerFactory.getLogger(NetworkUtils.class);
+    private static String localIp;
 
     static {
         localIp = getLocalIp();
     }
 
     /**
      * get local ip
-     * @return
      */
     public static String getLocalIp() {
-        if (localIp == null) {
-            String ip = null;
-            Enumeration<NetworkInterface> allInterface;
-            try {
-                allInterface = NetworkInterface.getNetworkInterfaces();
-                for (; allInterface.hasMoreElements(); ) {
-                    NetworkInterface oneInterface = allInterface.nextElement();
-                    String interfaceName = oneInterface.getName();
-                    if (oneInterface.isLoopback()
-                            || !oneInterface.isUp()
-                            || !interfaceName
-                            .equalsIgnoreCase(INNER_NETWORK_INTERFACE)) {
-                        continue;
-                    }
+        if (!StringUtils.isEmpty(localIp)) {
+            return localIp;
+        }
+        Enumeration<NetworkInterface> allInterface;
+        String ip = "127.0.0.1";
+        try {
+            allInterface = NetworkInterface.getNetworkInterfaces();
+            for (; allInterface.hasMoreElements(); ) {

Review Comment:
   > Suggest changing the `for` to `while` or `forEach`.
   
   done



##########
inlong-common/src/main/java/org/apache/inlong/common/util/NetworkUtils.java:
##########
@@ -17,59 +17,55 @@
 
 package org.apache.inlong.common.util;
 
+import org.apache.commons.lang3.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
 import java.net.InetAddress;
 import java.net.NetworkInterface;
 import java.net.SocketException;
 import java.util.Enumeration;
 
 public class NetworkUtils {
-    public static String INNER_NETWORK_INTERFACE = "eth1";
 
-    private static String localIp = null;
+    private static final Logger LOGGER = LoggerFactory.getLogger(NetworkUtils.class);
+    private static String localIp;
 
     static {
         localIp = getLocalIp();
     }
 
     /**
      * get local ip
-     * @return
      */
     public static String getLocalIp() {
-        if (localIp == null) {
-            String ip = null;
-            Enumeration<NetworkInterface> allInterface;
-            try {
-                allInterface = NetworkInterface.getNetworkInterfaces();
-                for (; allInterface.hasMoreElements(); ) {
-                    NetworkInterface oneInterface = allInterface.nextElement();
-                    String interfaceName = oneInterface.getName();
-                    if (oneInterface.isLoopback()
-                            || !oneInterface.isUp()
-                            || !interfaceName
-                            .equalsIgnoreCase(INNER_NETWORK_INTERFACE)) {
-                        continue;
-                    }
+        if (!StringUtils.isEmpty(localIp)) {

Review Comment:
   > Suggest using `StringUtils.isNotBlank()`.
   
   done



-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@inlong.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [inlong] healchow commented on a diff in pull request #5778: [INLONG-5770][DataProxy] Optimize the method of obtaining the local IP address

Posted by GitBox <gi...@apache.org>.
healchow commented on code in PR #5778:
URL: https://github.com/apache/inlong/pull/5778#discussion_r963186036


##########
inlong-common/src/main/java/org/apache/inlong/common/util/NetworkUtils.java:
##########
@@ -17,59 +17,55 @@
 
 package org.apache.inlong.common.util;
 
+import org.apache.commons.lang3.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
 import java.net.InetAddress;
 import java.net.NetworkInterface;
 import java.net.SocketException;
 import java.util.Enumeration;
 
 public class NetworkUtils {
-    public static String INNER_NETWORK_INTERFACE = "eth1";
 
-    private static String localIp = null;
+    private static final Logger LOGGER = LoggerFactory.getLogger(NetworkUtils.class);
+    private static String localIp;
 
     static {
         localIp = getLocalIp();
     }
 
     /**
      * get local ip
-     * @return
      */
     public static String getLocalIp() {
-        if (localIp == null) {
-            String ip = null;
-            Enumeration<NetworkInterface> allInterface;
-            try {
-                allInterface = NetworkInterface.getNetworkInterfaces();
-                for (; allInterface.hasMoreElements(); ) {
-                    NetworkInterface oneInterface = allInterface.nextElement();
-                    String interfaceName = oneInterface.getName();
-                    if (oneInterface.isLoopback()
-                            || !oneInterface.isUp()
-                            || !interfaceName
-                            .equalsIgnoreCase(INNER_NETWORK_INTERFACE)) {
-                        continue;
-                    }
+        if (!StringUtils.isEmpty(localIp)) {

Review Comment:
   Suggest using `StringUtils.isNotBlank()`.



##########
inlong-common/src/main/java/org/apache/inlong/common/util/NetworkUtils.java:
##########
@@ -17,59 +17,55 @@
 
 package org.apache.inlong.common.util;
 
+import org.apache.commons.lang3.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
 import java.net.InetAddress;
 import java.net.NetworkInterface;
 import java.net.SocketException;
 import java.util.Enumeration;
 
 public class NetworkUtils {
-    public static String INNER_NETWORK_INTERFACE = "eth1";
 
-    private static String localIp = null;
+    private static final Logger LOGGER = LoggerFactory.getLogger(NetworkUtils.class);
+    private static String localIp;
 
     static {
         localIp = getLocalIp();
     }
 
     /**
      * get local ip
-     * @return
      */
     public static String getLocalIp() {
-        if (localIp == null) {
-            String ip = null;
-            Enumeration<NetworkInterface> allInterface;
-            try {
-                allInterface = NetworkInterface.getNetworkInterfaces();
-                for (; allInterface.hasMoreElements(); ) {
-                    NetworkInterface oneInterface = allInterface.nextElement();
-                    String interfaceName = oneInterface.getName();
-                    if (oneInterface.isLoopback()
-                            || !oneInterface.isUp()
-                            || !interfaceName
-                            .equalsIgnoreCase(INNER_NETWORK_INTERFACE)) {
-                        continue;
-                    }
+        if (!StringUtils.isEmpty(localIp)) {
+            return localIp;
+        }
+        Enumeration<NetworkInterface> allInterface;
+        String ip = "127.0.0.1";
+        try {
+            allInterface = NetworkInterface.getNetworkInterfaces();
+            for (; allInterface.hasMoreElements(); ) {

Review Comment:
   Suggest changing the `for` to `while` or `forEach`.



-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@inlong.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org