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/03/06 10:53:47 UTC

[GitHub] [incubator-inlong] EMsnap commented on a change in pull request #2948: [INLONG-2908] fix uuid blank space

EMsnap commented on a change in pull request #2948:
URL: https://github.com/apache/incubator-inlong/pull/2948#discussion_r820214664



##########
File path: inlong-agent/agent-common/src/main/java/org/apache/inlong/agent/utils/AgentUtils.java
##########
@@ -344,8 +344,19 @@ public static String fetchLocalIp() {
      * check agent uuid from manager
      */
     public static String  fetchLocalUuid() {
-        String result = ExcuteLinux.exeCmd("dmidecode | grep UUID");
-        return AgentConfiguration.getAgentConf().get(AGENT_LOCAL_UUID, result);
+        String uuid = null;
+        try {
+            String result = ExcuteLinux.exeCmd("dmidecode | grep UUID");
+            if (!StringUtils.isEmpty(result) && StringUtils.containsIgnoreCase(result,"UUID")) {
+                String uuidResult = result.split(":")[1].trim();
+                 uuid = AgentConfiguration.getAgentConf().get(AGENT_LOCAL_UUID, uuidResult);

Review comment:
       extra blank space ?

##########
File path: inlong-agent/agent-common/src/main/java/org/apache/inlong/agent/utils/AgentUtils.java
##########
@@ -344,8 +344,19 @@ public static String fetchLocalIp() {
      * check agent uuid from manager
      */
     public static String  fetchLocalUuid() {
-        String result = ExcuteLinux.exeCmd("dmidecode | grep UUID");
-        return AgentConfiguration.getAgentConf().get(AGENT_LOCAL_UUID, result);
+        String uuid = null;
+        try {
+            String result = ExcuteLinux.exeCmd("dmidecode | grep UUID");
+            if (!StringUtils.isEmpty(result) && StringUtils.containsIgnoreCase(result,"UUID")) {
+                String uuidResult = result.split(":")[1].trim();
+                 uuid = AgentConfiguration.getAgentConf().get(AGENT_LOCAL_UUID, uuidResult);
+                return uuid;
+            }
+        } catch (Exception e) {
+            LOGGER.error("fetch uuid  error");
+            e.printStackTrace();
+        }
+        return uuid;

Review comment:
       If agent conf has configured uuid,  your method still return null

##########
File path: inlong-agent/agent-common/src/main/java/org/apache/inlong/agent/utils/AgentUtils.java
##########
@@ -344,8 +344,19 @@ public static String fetchLocalIp() {
      * check agent uuid from manager
      */
     public static String  fetchLocalUuid() {
-        String result = ExcuteLinux.exeCmd("dmidecode | grep UUID");
-        return AgentConfiguration.getAgentConf().get(AGENT_LOCAL_UUID, result);
+        String uuid = null;
+        try {
+            String result = ExcuteLinux.exeCmd("dmidecode | grep UUID");
+            if (!StringUtils.isEmpty(result) && StringUtils.containsIgnoreCase(result,"UUID")) {
+                String uuidResult = result.split(":")[1].trim();
+                 uuid = AgentConfiguration.getAgentConf().get(AGENT_LOCAL_UUID, uuidResult);
+                return uuid;
+            }
+        } catch (Exception e) {
+            LOGGER.error("fetch uuid  error");
+            e.printStackTrace();
+        }
+        return uuid;

Review comment:
        optional or emty string would be better




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