SbloodyS commented on code in PR #17945:
URL: 
https://github.com/apache/dolphinscheduler/pull/17945#discussion_r2771847004


##########
dolphinscheduler-task-plugin/dolphinscheduler-task-dinky/src/main/java/org/apache/dolphinscheduler/plugin/task/dinky/DinkyTask.java:
##########
@@ -338,23 +339,48 @@ public void cancelApplication() throws TaskException {
 
     private Map<String, String> generateVariables() {
         Map<String, String> variables = new ConcurrentHashMap<>();
-        List<Property> propertyList = 
JSONUtils.toList(taskExecutionContext.getGlobalParams(), Property.class);
-        if (propertyList != null && !propertyList.isEmpty()) {
-            for (Property property : propertyList) {
-                variables.put(property.getProp(), property.getValue());
+        Map<String, Property> prepareParamsMap = 
taskExecutionContext.getPrepareParamsMap();
+
+        // 全量参数,先统一插入到variables,有些key可能是没值的
+        // 
后面从取taskParams和prepareParamsMap交集,交集key先从localParams获取value,有值的放到variables;没值的从globalParams获取

Review Comment:
   ```suggestion
   ```
   
   Remove this.



##########
dolphinscheduler-task-plugin/dolphinscheduler-task-dinky/src/main/java/org/apache/dolphinscheduler/plugin/task/dinky/DinkyTask.java:
##########
@@ -338,23 +339,48 @@ public void cancelApplication() throws TaskException {
 
     private Map<String, String> generateVariables() {
         Map<String, String> variables = new ConcurrentHashMap<>();
-        List<Property> propertyList = 
JSONUtils.toList(taskExecutionContext.getGlobalParams(), Property.class);
-        if (propertyList != null && !propertyList.isEmpty()) {
-            for (Property property : propertyList) {
-                variables.put(property.getProp(), property.getValue());
+        Map<String, Property> prepareParamsMap = 
taskExecutionContext.getPrepareParamsMap();
+
+        // 全量参数,先统一插入到variables,有些key可能是没值的
+        // 
后面从取taskParams和prepareParamsMap交集,交集key先从localParams获取value,有值的放到variables;没值的从globalParams获取
+        prepareParamsMap.forEach((key, property) -> {
+            if (Objects.nonNull(property) && 
Objects.nonNull(property.getValue())) {
+                variables.put(key, property.getValue());
             }
-        }
+        });
+
         List<Property> localParams = this.dinkyParameters.getLocalParams();
-        Map<String, Property> prepareParamsMap = 
taskExecutionContext.getPrepareParamsMap();
-        if (localParams == null || localParams.isEmpty()) {
-            return variables;
-        }
-        Map<String, String> convertMap = 
ParameterUtils.convert(prepareParamsMap);
-        for (Property property : localParams) {
-            String propertyValue = property.getValue();
-            String value = PlaceholderUtils.replacePlaceholders(propertyValue, 
convertMap, true);
-            variables.put(property.getProp(), value);
+        List<Property> globalParams = 
JSONUtils.toList(taskExecutionContext.getGlobalParams(), Property.class);
+
+        if (!localParams.isEmpty()) {
+            for (Property localParam : localParams) {
+                // 如果variables没有这个key || value空的,从局部、全局 解析值,插入variables

Review Comment:
   ```suggestion
   ```



##########
dolphinscheduler-task-plugin/dolphinscheduler-task-dinky/src/main/java/org/apache/dolphinscheduler/plugin/task/dinky/DinkyTask.java:
##########
@@ -338,23 +339,48 @@ public void cancelApplication() throws TaskException {
 
     private Map<String, String> generateVariables() {
         Map<String, String> variables = new ConcurrentHashMap<>();
-        List<Property> propertyList = 
JSONUtils.toList(taskExecutionContext.getGlobalParams(), Property.class);
-        if (propertyList != null && !propertyList.isEmpty()) {
-            for (Property property : propertyList) {
-                variables.put(property.getProp(), property.getValue());
+        Map<String, Property> prepareParamsMap = 
taskExecutionContext.getPrepareParamsMap();
+
+        // 全量参数,先统一插入到variables,有些key可能是没值的
+        // 
后面从取taskParams和prepareParamsMap交集,交集key先从localParams获取value,有值的放到variables;没值的从globalParams获取
+        prepareParamsMap.forEach((key, property) -> {
+            if (Objects.nonNull(property) && 
Objects.nonNull(property.getValue())) {
+                variables.put(key, property.getValue());
             }
-        }
+        });
+
         List<Property> localParams = this.dinkyParameters.getLocalParams();
-        Map<String, Property> prepareParamsMap = 
taskExecutionContext.getPrepareParamsMap();
-        if (localParams == null || localParams.isEmpty()) {
-            return variables;
-        }
-        Map<String, String> convertMap = 
ParameterUtils.convert(prepareParamsMap);
-        for (Property property : localParams) {
-            String propertyValue = property.getValue();
-            String value = PlaceholderUtils.replacePlaceholders(propertyValue, 
convertMap, true);
-            variables.put(property.getProp(), value);
+        List<Property> globalParams = 
JSONUtils.toList(taskExecutionContext.getGlobalParams(), Property.class);
+
+        if (!localParams.isEmpty()) {
+            for (Property localParam : localParams) {
+                // 如果variables没有这个key || value空的,从局部、全局 解析值,插入variables
+                if (Objects.isNull(variables.get(localParam.getProp())) || 
variables.get(localParam.getProp()).isEmpty()) {
+                    if (localParam.getValue() != null && 
!localParam.getValue().isEmpty()) {
+                        // 解析value

Review Comment:
   ```suggestion
   ```



##########
dolphinscheduler-task-plugin/dolphinscheduler-task-dinky/src/main/java/org/apache/dolphinscheduler/plugin/task/dinky/DinkyTask.java:
##########
@@ -338,23 +339,48 @@ public void cancelApplication() throws TaskException {
 
     private Map<String, String> generateVariables() {
         Map<String, String> variables = new ConcurrentHashMap<>();
-        List<Property> propertyList = 
JSONUtils.toList(taskExecutionContext.getGlobalParams(), Property.class);
-        if (propertyList != null && !propertyList.isEmpty()) {
-            for (Property property : propertyList) {
-                variables.put(property.getProp(), property.getValue());
+        Map<String, Property> prepareParamsMap = 
taskExecutionContext.getPrepareParamsMap();
+
+        // 全量参数,先统一插入到variables,有些key可能是没值的
+        // 
后面从取taskParams和prepareParamsMap交集,交集key先从localParams获取value,有值的放到variables;没值的从globalParams获取
+        prepareParamsMap.forEach((key, property) -> {
+            if (Objects.nonNull(property) && 
Objects.nonNull(property.getValue())) {
+                variables.put(key, property.getValue());
             }
-        }
+        });
+
         List<Property> localParams = this.dinkyParameters.getLocalParams();
-        Map<String, Property> prepareParamsMap = 
taskExecutionContext.getPrepareParamsMap();
-        if (localParams == null || localParams.isEmpty()) {
-            return variables;
-        }
-        Map<String, String> convertMap = 
ParameterUtils.convert(prepareParamsMap);
-        for (Property property : localParams) {
-            String propertyValue = property.getValue();
-            String value = PlaceholderUtils.replacePlaceholders(propertyValue, 
convertMap, true);
-            variables.put(property.getProp(), value);
+        List<Property> globalParams = 
JSONUtils.toList(taskExecutionContext.getGlobalParams(), Property.class);
+
+        if (!localParams.isEmpty()) {
+            for (Property localParam : localParams) {
+                // 如果variables没有这个key || value空的,从局部、全局 解析值,插入variables
+                if (Objects.isNull(variables.get(localParam.getProp())) || 
variables.get(localParam.getProp()).isEmpty()) {
+                    if (localParam.getValue() != null && 
!localParam.getValue().isEmpty()) {
+                        // 解析value
+                        String value = 
ParameterUtils.convertParameterPlaceholders(localParam.getValue(), variables);
+                        if (StringUtils.isNotBlank(value)) {
+                            variables.put(localParam.getProp(), value);
+                        }
+                    } else {
+                        if (!globalParams.isEmpty()) {
+                            for (Property globalParam : globalParams) {
+                                if 
(globalParam.getProp().equals(localParam.getProp())) {
+                                    if (globalParam.getValue() != null && 
!globalParam.getValue().isEmpty()) {
+                                        // 解析value

Review Comment:
   ```suggestion
   ```



##########
dolphinscheduler-task-plugin/dolphinscheduler-task-dinky/src/main/java/org/apache/dolphinscheduler/plugin/task/dinky/DinkyTask.java:
##########
@@ -338,23 +339,48 @@ public void cancelApplication() throws TaskException {
 
     private Map<String, String> generateVariables() {
         Map<String, String> variables = new ConcurrentHashMap<>();
-        List<Property> propertyList = 
JSONUtils.toList(taskExecutionContext.getGlobalParams(), Property.class);
-        if (propertyList != null && !propertyList.isEmpty()) {
-            for (Property property : propertyList) {
-                variables.put(property.getProp(), property.getValue());
+        Map<String, Property> prepareParamsMap = 
taskExecutionContext.getPrepareParamsMap();
+
+        // 全量参数,先统一插入到variables,有些key可能是没值的
+        // 
后面从取taskParams和prepareParamsMap交集,交集key先从localParams获取value,有值的放到variables;没值的从globalParams获取
+        prepareParamsMap.forEach((key, property) -> {
+            if (Objects.nonNull(property) && 
Objects.nonNull(property.getValue())) {
+                variables.put(key, property.getValue());
             }
-        }
+        });
+
         List<Property> localParams = this.dinkyParameters.getLocalParams();
-        Map<String, Property> prepareParamsMap = 
taskExecutionContext.getPrepareParamsMap();
-        if (localParams == null || localParams.isEmpty()) {
-            return variables;
-        }
-        Map<String, String> convertMap = 
ParameterUtils.convert(prepareParamsMap);
-        for (Property property : localParams) {
-            String propertyValue = property.getValue();
-            String value = PlaceholderUtils.replacePlaceholders(propertyValue, 
convertMap, true);
-            variables.put(property.getProp(), value);
+        List<Property> globalParams = 
JSONUtils.toList(taskExecutionContext.getGlobalParams(), Property.class);
+
+        if (!localParams.isEmpty()) {
+            for (Property localParam : localParams) {
+                // 如果variables没有这个key || value空的,从局部、全局 解析值,插入variables
+                if (Objects.isNull(variables.get(localParam.getProp())) || 
variables.get(localParam.getProp()).isEmpty()) {
+                    if (localParam.getValue() != null && 
!localParam.getValue().isEmpty()) {
+                        // 解析value
+                        String value = 
ParameterUtils.convertParameterPlaceholders(localParam.getValue(), variables);
+                        if (StringUtils.isNotBlank(value)) {
+                            variables.put(localParam.getProp(), value);
+                        }
+                    } else {
+                        if (!globalParams.isEmpty()) {
+                            for (Property globalParam : globalParams) {
+                                if 
(globalParam.getProp().equals(localParam.getProp())) {
+                                    if (globalParam.getValue() != null && 
!globalParam.getValue().isEmpty()) {
+                                        // 解析value
+                                        String value = 
ParameterUtils.convertParameterPlaceholders(globalParam.getValue(), variables);
+                                        if (StringUtils.isNotBlank(value)) {
+                                            
variables.put(localParam.getProp(), value);
+                                        }
+                                    }
+                                }
+                            }
+                        }
+                    }
+                }
+            }
         }
+        log.info("will send variables to dinky: {}", variables);

Review Comment:
   ```suggestion
           log.debug("sending variables to dinky: {}", variables);
   ```



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to