Skip to content

Commit 1e94e72

Browse files
author
苏义超
committed
add it test case
1 parent c6a4a37 commit 1e94e72

File tree

3 files changed

+161
-63
lines changed

3 files changed

+161
-63
lines changed

dolphinscheduler-master/src/test/java/org/apache/dolphinscheduler/server/master/integration/cases/WorkflowStartTestCase.java

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -751,6 +751,50 @@ public void testStartWorkflow_fakeTask_usingLocalParamOverWriteByVarPool() {
751751
masterContainer.assertAllResourceReleased();
752752
}
753753

754+
@Test
755+
@DisplayName("Test start a workflow which using null key params")
756+
public void testStartWorkflow_usingNullKeyParam() {
757+
final String yaml = "/it/start/workflow_with_null_key_param.yaml";
758+
final WorkflowTestCaseContext context = workflowTestCaseContextFactory.initializeContextFromYaml(yaml);
759+
final WorkflowDefinition workflow = context.getOneWorkflow();
760+
761+
final RunWorkflowCommandParam runWorkflowCommandParam = RunWorkflowCommandParam.builder()
762+
.commandParams(Lists.newArrayList(Property.builder()
763+
.prop(null)
764+
.direct(Direct.IN)
765+
.type(DataType.VARCHAR)
766+
.value("commandParam")
767+
.build()))
768+
.build();
769+
770+
final WorkflowOperator.WorkflowTriggerDTO workflowTriggerDTO = WorkflowOperator.WorkflowTriggerDTO.builder()
771+
.workflowDefinition(workflow)
772+
.runWorkflowCommandParam(runWorkflowCommandParam)
773+
.build();
774+
workflowOperator.manualTriggerWorkflow(workflowTriggerDTO);
775+
776+
await()
777+
.atMost(Duration.ofMinutes(1))
778+
.untilAsserted(() -> {
779+
Assertions
780+
.assertThat(repository.queryWorkflowInstance(workflow))
781+
.satisfiesExactly(workflowInstance -> assertThat(workflowInstance.getState())
782+
.isEqualTo(WorkflowExecutionStatus.SUCCESS));
783+
Assertions
784+
.assertThat(repository.queryTaskInstance(workflow))
785+
.hasSize(2)
786+
.anySatisfy(taskInstance -> {
787+
assertThat(taskInstance.getName()).isEqualTo("A");
788+
assertThat(taskInstance.getState()).isEqualTo(TaskExecutionStatus.SUCCESS);
789+
})
790+
.anySatisfy(taskInstance -> {
791+
assertThat(taskInstance.getName()).isEqualTo("B");
792+
assertThat(taskInstance.getState()).isEqualTo(TaskExecutionStatus.SUCCESS);
793+
});
794+
});
795+
masterContainer.assertAllResourceReleased();
796+
}
797+
754798
@Test
755799
@DisplayName("Test start a workflow with one fake task(A) failed")
756800
public void testStartWorkflow_with_oneFailedTask() {
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
#
2+
# Licensed to the Apache Software Foundation (ASF) under one or more
3+
# contributor license agreements. See the NOTICE file distributed with
4+
# this work for additional information regarding copyright ownership.
5+
# The ASF licenses this file to You under the Apache License, Version 2.0
6+
# (the "License"); you may not use this file except in compliance with
7+
# the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
#
17+
18+
project:
19+
name: MasterIntegrationTest
20+
code: 1
21+
description: This is a fake project
22+
userId: 1
23+
userName: admin
24+
createTime: 2024-08-12 00:00:00
25+
updateTime: 2024-08-12 00:00:00
26+
27+
workflows:
28+
- name: workflow_with_one_fake_task_success
29+
code: 1
30+
version: 1
31+
projectCode: 1
32+
description: This is a fake workflow with single task
33+
releaseState: ONLINE
34+
createTime: 2024-08-12 00:00:00
35+
updateTime: 2024-08-12 00:00:00
36+
userId: 1
37+
globalParams: '[{"prop":null,"value":"workflowParam","direct":"IN","type":"VARCHAR"}]'
38+
executionType: PARALLEL
39+
40+
tasks:
41+
- name: A
42+
code: 1
43+
version: 1
44+
projectCode: 1
45+
userId: 1
46+
taskType: LogicFakeTask
47+
taskParams: >
48+
{
49+
"localParams": [
50+
{
51+
"prop": "",
52+
"direct": "IN",
53+
"type": "VARCHAR",
54+
"value": ""
55+
}
56+
],
57+
"shellScript": "echo 111",
58+
"resourceList": []
59+
}
60+
workerGroup: default
61+
createTime: 2024-08-12 00:00:00
62+
updateTime: 2024-08-12 00:00:00
63+
taskExecuteType: BATCH
64+
- name: B
65+
code: 2
66+
version: 1
67+
projectCode: 1
68+
userId: 1
69+
taskType: LogicFakeTask
70+
taskParams: >
71+
{
72+
"localParams": [
73+
{
74+
"prop": null,
75+
"direct": "IN",
76+
"type": "VARCHAR",
77+
"value": ""
78+
}
79+
],
80+
"shellScript": "echo 111",
81+
"resourceList": []
82+
}
83+
workerGroup: default
84+
createTime: 2024-08-12 00:00:00
85+
updateTime: 2024-08-12 00:00:00
86+
taskExecuteType: BATCH
87+
88+
89+
90+
taskRelations:
91+
- projectCode: 1
92+
workflowDefinitionCode: 1
93+
workflowDefinitionVersion: 1
94+
preTaskCode: 0
95+
preTaskVersion: 0
96+
postTaskCode: 1
97+
postTaskVersion: 1
98+
createTime: 2024-08-12 00:00:00
99+
updateTime: 2024-08-12 00:00:00
100+
- projectCode: 1
101+
workflowDefinitionCode: 1
102+
workflowDefinitionVersion: 1
103+
preTaskCode: 0
104+
preTaskVersion: 0
105+
postTaskCode: 2
106+
postTaskVersion: 1
107+
createTime: 2024-08-12 00:00:00
108+
updateTime: 2024-08-12 00:00:00

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

Lines changed: 9 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -169,35 +169,16 @@ public Map<String, Property> parseWorkflowFatherParam(@Nullable Map<String, Stri
169169
* <li>Values are non-null {@link Property} objects</li>
170170
* </ul>
171171
*
172-
* <p><strong>Parameter Precedence (highest to lowest):</strong>
173-
* <ol>
174-
* <li>Business/scheduling time parameters (e.g., {@code ${system.datetime}})</li>
175-
* <li>Command-line or runtime complement parameters</li>
176-
* <li>Task-local parameters</li>
177-
* <li>Workflow global parameters (solidified at instance creation)</li>
178-
* <li>Project-level parameters</li>
179-
* <li>Built-in system parameters (e.g., {@code ${task.id}})</li>
180-
* </ol>
172+
* <p> The priority of the parameters is as follows:
173+
* <p> varpool > command parameters > local parameters > global parameters > project parameters > built-in parameters
174+
* todo: Use TaskRuntimeParams to represent this.
181175
*
182-
* <p><strong>Important Notes:</strong>
183-
* <ul>
184-
* <li>All parameter sources are sanitized via {@link #safePutAll(Map, Map)} to prevent {@code null}
185-
* or blank keys, which would cause JSON serialization failures (e.g., Jackson's
186-
* "Null key for a Map not allowed in JSON").</li>
187-
* <li>Placeholders (e.g., {@code "${var}"}) in parameter values are resolved after all sources
188-
* are merged, using the consolidated parameter map. Global parameters are already
189-
* <em>solidified</em> (fully resolved at workflow instance creation), so no recursive
190-
* placeholder expansion is required.</li>
191-
* <li>{@code VarPool} values (from upstream tasks) only override parameters marked as
192-
* {@link Direct#IN}; output or constant parameters remain unchanged.</li>
193-
* </ul>
194-
*
195-
* @param taskInstance the current task instance (must not be null)
196-
* @param parameters the parsed task-specific parameters (must not be null)
197-
* @param workflowInstance the parent workflow instance (must not be null)
198-
* @param projectName name of the project containing the workflow
199-
* @param workflowDefinitionName name of the workflow definition
200-
* @return a safe, fully resolved map of parameter name to {@link Property}, ready for task execution
176+
* @param taskInstance
177+
* @param parameters
178+
* @param workflowInstance
179+
* @param projectName
180+
* @param workflowDefinitionName
181+
* @return
201182
*/
202183
@Override
203184
public Map<String, Property> paramParsingPreparation(@NonNull TaskInstance taskInstance,
@@ -273,21 +254,6 @@ public Map<String, Property> paramParsingPreparation(@NonNull TaskInstance taskI
273254
* Safely merges entries from the {@code source} map into the {@code target} map,
274255
* skipping any entry with a {@code null}, empty, or blank key, or a {@code null} value.
275256
*
276-
* <p>This method ensures the resulting parameter map can be safely serialized to JSON
277-
* (e.g., by Jackson), which prohibits {@code null} keys in maps. Invalid entries are
278-
* logged as warnings to aid in debugging misconfigured parameters.
279-
*
280-
* <p>Examples of skipped entries:
281-
* <pre>
282-
* key = null → skipped
283-
* key = "" → skipped
284-
* key = " \t\n" → skipped
285-
* value = null → skipped
286-
* </pre>
287-
*
288-
* <p>All valid entries (non-blank key and non-null value) are added to {@code target}
289-
* using standard {@link Map#put(Object, Object)} semantics (later values overwrite earlier ones).
290-
*
291257
* @param target the destination map to merge into (must not be null)
292258
* @param source the source map whose valid entries will be copied (may be null or empty)
293259
*/
@@ -308,26 +274,6 @@ private void safePutAll(Map<String, Property> target, Map<String, Property> sour
308274
* Resolves placeholder expressions (e.g., "${var}") in parameter values by substituting them
309275
* with actual values from the current {@code paramsMap}.
310276
*
311-
* <p>This supports references where a local task parameter refers to another parameter
312-
* (e.g., a global workflow parameter). For example:
313-
* <pre>
314-
* Global parameters (solidified at workflow instance creation):
315-
* "output_dir" → "/data/20251119"
316-
*
317-
* Local task parameter definition:
318-
* "log_path" → "${output_dir}/task.log"
319-
*
320-
* After resolution:
321-
* "log_path" → "/data/20251119/task.log"
322-
* </pre>
323-
*
324-
* <p><strong>Note:</strong> Global parameters in {@code paramsMap} are already solidified
325-
* (i.e., contain no unresolved placeholders). Therefore, this method only needs to perform
326-
* iterative substitution within the current context without recursive expansion.
327-
*
328-
* <p>Only values containing {@link Constants#FUNCTION_START_WITH} (typically "${") are processed.
329-
* Substitution is performed in-place.
330-
*
331277
* @param paramsMap the map of parameters (key: parameter name, value: {@link Property}) to resolve
332278
*/
333279
private void resolvePlaceholders(Map<String, Property> paramsMap) {

0 commit comments

Comments
 (0)