Browse Source

Optimize ParameterUtils.curingGlobalParams() execution efficiency (#2090)

* Optimize ParameterUtils.curingGlobalParams() execution efficiency

* Remove excess null check
dailidong 5 years ago
parent
commit
1f92b4c4db

+ 16 - 20
dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/ParameterUtils.java

@@ -119,10 +119,15 @@ public class ParameterUtils {
    */
   public static String curingGlobalParams(Map<String,String> globalParamMap, List<Property> globalParamList,
                                    CommandType commandType, Date scheduleTime){
-      Map<String, String> globalMap = new HashMap<>();
-      if(globalParamMap!= null){
-        globalMap.putAll(globalParamMap);
-      }
+
+    if (globalParamList == null || globalParamList.isEmpty()) {
+      return null;
+    }
+
+    Map<String, String> globalMap = new HashMap<>();
+    if (globalParamMap!= null){
+      globalMap.putAll(globalParamMap);
+    }
     Map<String,String> allParamMap = new HashMap<>();
     //If it is a complement, a complement time needs to be passed in, according to the task type
     Map<String,String> timeParams = BusinessTimeUtils
@@ -132,9 +137,7 @@ public class ParameterUtils {
       allParamMap.putAll(timeParams);
     }
 
-    if (globalMap != null) {
-      allParamMap.putAll(globalMap);
-    }
+    allParamMap.putAll(globalMap);
 
     Set<Map.Entry<String, String>> entries = allParamMap.entrySet();
 
@@ -146,22 +149,15 @@ public class ParameterUtils {
         resolveMap.put(entry.getKey(),str);
       }
     }
+    globalMap.putAll(resolveMap);
 
-    if (globalMap != null){
-      globalMap.putAll(resolveMap);
-    }
-
-    if (globalParamList != null && globalParamList.size() > 0){
-
-      for (Property property : globalParamList){
-        String val = globalMap.get(property.getProp());
-        if (val != null){
-          property.setValue(val);
-        }
+    for (Property property : globalParamList){
+      String val = globalMap.get(property.getProp());
+      if (val != null){
+        property.setValue(val);
       }
-      return JSONObject.toJSONString(globalParamList);
     }
-    return null;
+    return JSONObject.toJSONString(globalParamList);
   }