Skip to content

Commit c3cc817

Browse files
authored
[Fix-17971] Fix local parameter defined in ProcedureTask not being passed correctly (#17973)
1 parent d1fddfb commit c3cc817

File tree

7 files changed

+75
-322
lines changed

7 files changed

+75
-322
lines changed

dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/expand/CuringParamsServiceImpl.java

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ public Map<String, Property> paramParsingPreparation(@NonNull TaskInstance taskI
198198
String timeZone = commandParam.getTimeZone();
199199

200200
// 1. Built-in parameters (lowest precedence)
201-
Map<String, String> builtInParams = setBuiltInParamsMap(
201+
Map<String, String> builtInParams = parseBuiltInParamsMap(
202202
taskInstance, workflowInstance, timeZone, projectName, workflowDefinitionName);
203203
safePutAll(prepareParamsMap, ParameterUtils.getUserDefParamsMap(builtInParams));
204204

@@ -211,7 +211,7 @@ public Map<String, Property> paramParsingPreparation(@NonNull TaskInstance taskI
211211
safePutAll(prepareParamsMap, globalParams);
212212

213213
// 4. Task-local parameters
214-
Map<String, Property> localParams = parameters.getInputLocalParametersMap();
214+
Map<String, Property> localParams = parseLocalParamsMap(parameters);
215215
safePutAll(prepareParamsMap, localParams);
216216

217217
// 5. Command-line / complement parameters
@@ -293,11 +293,11 @@ private void resolvePlaceholders(Map<String, Property> paramsMap) {
293293
* @param projectName
294294
* @param workflowDefinitionName
295295
*/
296-
private Map<String, String> setBuiltInParamsMap(@NonNull TaskInstance taskInstance,
297-
WorkflowInstance workflowInstance,
298-
String timeZone,
299-
String projectName,
300-
String workflowDefinitionName) {
296+
private Map<String, String> parseBuiltInParamsMap(@NonNull TaskInstance taskInstance,
297+
WorkflowInstance workflowInstance,
298+
String timeZone,
299+
String projectName,
300+
String workflowDefinitionName) {
301301
CommandType commandType = workflowInstance.getCmdTypeIfComplement();
302302
Date scheduleTime = workflowInstance.getScheduleTime();
303303

@@ -317,6 +317,15 @@ private Map<String, String> setBuiltInParamsMap(@NonNull TaskInstance taskInstan
317317
return params;
318318
}
319319

320+
private Map<String, Property> parseLocalParamsMap(AbstractParameters parameters) {
321+
Map<String, Property> localParametersMaps = new LinkedHashMap<>();
322+
if (CollectionUtils.isNotEmpty(parameters.getLocalParams())) {
323+
parameters.getLocalParams()
324+
.forEach(localParam -> localParametersMaps.put(localParam.getProp(), localParam));
325+
}
326+
return localParametersMaps;
327+
}
328+
320329
private Map<String, Property> parseGlobalParamsMap(WorkflowInstance workflowInstance) {
321330
final Map<String, Property> globalParametersMaps = new LinkedHashMap<>();
322331
if (StringUtils.isNotEmpty(workflowInstance.getGlobalParams())) {

dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/parameters/AbstractParameters.java

Lines changed: 4 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,8 @@
2828
import org.apache.commons.collections4.MapUtils;
2929

3030
import java.util.ArrayList;
31-
import java.util.LinkedHashMap;
3231
import java.util.List;
3332
import java.util.Map;
34-
import java.util.Objects;
3533
import java.util.stream.Collectors;
3634

3735
import lombok.Getter;
@@ -49,6 +47,7 @@ public abstract class AbstractParameters implements IParameters {
4947
@Setter
5048
public List<Property> localParams;
5149

50+
@Setter
5251
public List<Property> varPool = new ArrayList<>();
5352

5453
@Override
@@ -59,49 +58,16 @@ public List<ResourceInfo> getResourceFilesList() {
5958
return new ArrayList<>();
6059
}
6160

62-
public Map<String, Property> getLocalParametersMap() {
63-
Map<String, Property> localParametersMaps = new LinkedHashMap<>();
64-
if (localParams != null) {
65-
for (Property property : localParams) {
66-
localParametersMaps.put(property.getProp(), property);
67-
}
68-
}
69-
return localParametersMaps;
70-
}
71-
72-
/**
73-
* get input local parameters map if the param direct is IN
74-
*
75-
* @return parameters map
76-
*/
77-
public Map<String, Property> getInputLocalParametersMap() {
78-
Map<String, Property> localParametersMaps = new LinkedHashMap<>();
79-
if (localParams != null) {
80-
for (Property property : localParams) {
81-
// The direct of some tasks is empty, default IN
82-
if (property.getDirect() == null || Objects.equals(Direct.IN, property.getDirect())) {
83-
localParametersMaps.put(property.getProp(), property);
84-
}
85-
}
86-
}
87-
return localParametersMaps;
88-
}
89-
90-
public void setVarPool(List<Property> varPool) {
91-
this.varPool = varPool;
92-
}
93-
9461
public void dealOutParam(Map<String, String> taskOutputParams) {
9562
List<Property> outProperty = getOutProperty(localParams);
9663
if (CollectionUtils.isEmpty(outProperty)) {
9764
return;
9865
}
99-
if (CollectionUtils.isNotEmpty(outProperty) && MapUtils.isNotEmpty(taskOutputParams)) {
66+
if (MapUtils.isNotEmpty(taskOutputParams)) {
10067
// Inject the value
10168
for (Property info : outProperty) {
102-
String value = taskOutputParams.get(info.getProp());
103-
if (value != null) {
104-
info.setValue(value);
69+
if (taskOutputParams.containsKey(info.getProp())) {
70+
info.setValue(taskOutputParams.get(info.getProp()));
10571
}
10672
}
10773
}

dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/parameters/AbstractParametersTest.java

Lines changed: 0 additions & 139 deletions
This file was deleted.

dolphinscheduler-task-plugin/dolphinscheduler-task-grpc/src/test/java/org/apache/dolphinscheduler/plugin/task/grpc/GrpcParametersTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,6 @@ void testCheckValues() throws IOException {
9999
Assertions.assertEquals("{ \"username\":\"test username\" }", grpcParameters.getMessage());
100100
Assertions.assertEquals(GrpcCheckCondition.STATUS_CODE_DEFAULT, grpcParameters.getGrpcCheckCondition());
101101
Assertions.assertEquals("", grpcParameters.getCondition());
102-
Assertions.assertEquals(0, grpcParameters.getLocalParametersMap().size());
103102
Assertions.assertEquals(0, grpcParameters.getResourceFilesList().size());
104103
}
105104

dolphinscheduler-task-plugin/dolphinscheduler-task-http/src/test/java/org/apache/dolphinscheduler/plugin/task/http/HttpParametersTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ public void testCheckValues() {
6868
Assertions.assertEquals(HttpRequestMethod.GET, httpParameters.getHttpRequestMethod());
6969
Assertions.assertEquals(HttpCheckCondition.STATUS_CODE_DEFAULT, httpParameters.getHttpCheckCondition());
7070
Assertions.assertEquals("", httpParameters.getCondition());
71-
Assertions.assertEquals(0, httpParameters.getLocalParametersMap().size());
7271
Assertions.assertEquals(0, httpParameters.getResourceFilesList().size());
7372
}
7473

dolphinscheduler-task-plugin/dolphinscheduler-task-procedure/src/main/java/org/apache/dolphinscheduler/plugin/task/procedure/ProcedureParameters.java

Lines changed: 3 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,17 @@
1818
package org.apache.dolphinscheduler.plugin.task.procedure;
1919

2020
import org.apache.dolphinscheduler.plugin.task.api.enums.ResourceType;
21-
import org.apache.dolphinscheduler.plugin.task.api.model.Property;
22-
import org.apache.dolphinscheduler.plugin.task.api.model.ResourceInfo;
2321
import org.apache.dolphinscheduler.plugin.task.api.parameters.AbstractParameters;
2422
import org.apache.dolphinscheduler.plugin.task.api.parameters.resource.DataSourceParameters;
2523
import org.apache.dolphinscheduler.plugin.task.api.parameters.resource.ResourceParametersHelper;
2624

27-
import org.apache.commons.collections4.CollectionUtils;
2825
import org.apache.commons.lang3.StringUtils;
2926

30-
import java.util.ArrayList;
31-
import java.util.HashMap;
32-
import java.util.List;
33-
import java.util.Map;
3427
import java.util.Objects;
3528

36-
/**
37-
* procedure parameter
38-
*/
29+
import lombok.Data;
30+
31+
@Data
3932
public class ProcedureParameters extends AbstractParameters {
4033

4134
/**
@@ -48,85 +41,16 @@ public class ProcedureParameters extends AbstractParameters {
4841
*/
4942
private int datasource;
5043

51-
private Map<String, Property> outProperty;
52-
5344
/**
5445
* procedure name
5546
*/
5647
private String method;
5748

58-
public String getType() {
59-
return type;
60-
}
61-
62-
public void setType(String type) {
63-
this.type = type;
64-
}
65-
66-
public int getDatasource() {
67-
return datasource;
68-
}
69-
70-
public void setDatasource(int datasource) {
71-
this.datasource = datasource;
72-
}
73-
74-
public String getMethod() {
75-
return method;
76-
}
77-
78-
public void setMethod(String method) {
79-
this.method = method;
80-
}
81-
8249
@Override
8350
public boolean checkParameters() {
8451
return datasource != 0 && StringUtils.isNotEmpty(type) && StringUtils.isNotEmpty(method);
8552
}
8653

87-
@Override
88-
public List<ResourceInfo> getResourceFilesList() {
89-
return new ArrayList<>();
90-
}
91-
92-
@Override
93-
public String toString() {
94-
return "ProcessdureParam{"
95-
+ "type='" + type + '\''
96-
+ ", datasource=" + datasource
97-
+ ", method='" + method + '\''
98-
+ '}';
99-
}
100-
101-
public void dealOutParam4Procedure(Object result, String pop) {
102-
Map<String, Property> properties = getOutProperty();
103-
if (this.outProperty == null) {
104-
return;
105-
}
106-
properties.get(pop).setValue(String.valueOf(result));
107-
varPool.add(properties.get(pop));
108-
}
109-
110-
public Map<String, Property> getOutProperty() {
111-
if (this.outProperty != null) {
112-
return this.outProperty;
113-
}
114-
if (CollectionUtils.isEmpty(localParams)) {
115-
return null;
116-
}
117-
List<Property> outPropertyList = getOutProperty(localParams);
118-
Map<String, Property> outProperty = new HashMap<>();
119-
for (Property info : outPropertyList) {
120-
outProperty.put(info.getProp(), info);
121-
}
122-
this.outProperty = outProperty;
123-
return this.outProperty;
124-
}
125-
126-
public void setOutProperty(Map<String, Property> outProperty) {
127-
this.outProperty = outProperty;
128-
}
129-
13054
@Override
13155
public ResourceParametersHelper getResources() {
13256
ResourceParametersHelper resources = super.getResources();

0 commit comments

Comments
 (0)