You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dolphinscheduler.apache.org by we...@apache.org on 2025/10/20 03:43:19 UTC
(dolphinscheduler) branch dev updated: [Fix-17579][Workflow] Fix view variable error after setting startup parameters for workflow instance (#17583)
This is an automated email from the ASF dual-hosted git repository.
wenjun pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/dolphinscheduler.git
The following commit(s) were added to refs/heads/dev by this push:
new 0862515eee [Fix-17579][Workflow] Fix view variable error after setting startup parameters for workflow instance (#17583)
0862515eee is described below
commit 0862515eee0af4feefb6d5dd24a98980c242e05d
Author: huangsheng <hu...@163.com>
AuthorDate: Mon Oct 20 11:43:13 2025 +0800
[Fix-17579][Workflow] Fix view variable error after setting startup parameters for workflow instance (#17583)
---
.../service/impl/WorkflowInstanceServiceImpl.java | 18 +++----
.../api/service/WorkflowInstanceServiceTest.java | 55 ++++++++++++++++++++++
2 files changed, 65 insertions(+), 8 deletions(-)
diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/WorkflowInstanceServiceImpl.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/WorkflowInstanceServiceImpl.java
index 1b3a63fec4..ecc9c712a6 100644
--- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/WorkflowInstanceServiceImpl.java
+++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/WorkflowInstanceServiceImpl.java
@@ -25,6 +25,7 @@ import static org.apache.dolphinscheduler.common.constants.Constants.GLOBAL_PARA
import static org.apache.dolphinscheduler.common.constants.Constants.LOCAL_PARAMS;
import static org.apache.dolphinscheduler.common.constants.Constants.TASK_LIST;
import static org.apache.dolphinscheduler.common.constants.Constants.WORKFLOW_INSTANCE_STATE;
+import static org.apache.dolphinscheduler.common.utils.JSONUtils.parseObject;
import static org.apache.dolphinscheduler.plugin.task.api.TaskPluginManager.checkTaskParameters;
import org.apache.dolphinscheduler.api.constants.ApiFuncIdentificationConstant;
@@ -79,6 +80,7 @@ import org.apache.dolphinscheduler.dao.repository.TaskInstanceDao;
import org.apache.dolphinscheduler.dao.repository.WorkflowInstanceDao;
import org.apache.dolphinscheduler.dao.repository.WorkflowInstanceMapDao;
import org.apache.dolphinscheduler.dao.utils.WorkflowUtils;
+import org.apache.dolphinscheduler.extract.master.command.ICommandParam;
import org.apache.dolphinscheduler.plugin.task.api.model.Property;
import org.apache.dolphinscheduler.plugin.task.api.utils.ParameterUtils;
import org.apache.dolphinscheduler.plugin.task.api.utils.TaskTypeUtils;
@@ -663,13 +665,12 @@ public class WorkflowInstanceServiceImpl extends BaseServiceImpl implements Work
return result;
}
- //
- Map<String, String> commandParamMap = JSONUtils.toMap(workflowInstance.getCommandParam());
- String timezoneId = null;
- if (commandParamMap == null || StringUtils.isBlank(commandParamMap.get(Constants.SCHEDULE_TIMEZONE))) {
+ String timezoneId;
+ final ICommandParam commandParam = parseObject(workflowInstance.getCommandParam(), ICommandParam.class);
+ if (commandParam == null || StringUtils.isEmpty(commandParam.getTimeZone())) {
timezoneId = loginUser.getTimeZone();
} else {
- timezoneId = commandParamMap.get(Constants.SCHEDULE_TIMEZONE);
+ timezoneId = commandParam.getTimeZone();
}
setWorkflowInstance(workflowInstance, scheduleTime, globalParams, timeout, timezoneId);
@@ -873,11 +874,12 @@ public class WorkflowInstanceServiceImpl extends BaseServiceImpl implements Work
return result;
}
- Map<String, String> commandParam = JSONUtils.toMap(workflowInstance.getCommandParam());
String timezone = null;
- if (commandParam != null) {
- timezone = commandParam.get(Constants.SCHEDULE_TIMEZONE);
+ final ICommandParam commandParam = parseObject(workflowInstance.getCommandParam(), ICommandParam.class);
+ if (commandParam != null && StringUtils.isNotEmpty(commandParam.getTimeZone())) {
+ timezone = commandParam.getTimeZone();
}
+
Map<String, String> timeParams = BusinessTimeUtils
.getBusinessTime(workflowInstance.getCmdTypeIfComplement(),
workflowInstance.getScheduleTime(), timezone);
diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/WorkflowInstanceServiceTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/WorkflowInstanceServiceTest.java
index e5d953a0ac..138de28886 100644
--- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/WorkflowInstanceServiceTest.java
+++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/WorkflowInstanceServiceTest.java
@@ -67,9 +67,13 @@ import org.apache.dolphinscheduler.dao.repository.TaskInstanceContextDao;
import org.apache.dolphinscheduler.dao.repository.TaskInstanceDao;
import org.apache.dolphinscheduler.dao.repository.WorkflowInstanceDao;
import org.apache.dolphinscheduler.dao.repository.WorkflowInstanceMapDao;
+import org.apache.dolphinscheduler.extract.master.command.RunWorkflowCommandParam;
import org.apache.dolphinscheduler.plugin.task.api.TaskPluginManager;
+import org.apache.dolphinscheduler.plugin.task.api.enums.DataType;
import org.apache.dolphinscheduler.plugin.task.api.enums.DependResult;
+import org.apache.dolphinscheduler.plugin.task.api.enums.Direct;
import org.apache.dolphinscheduler.plugin.task.api.enums.TaskExecutionStatus;
+import org.apache.dolphinscheduler.plugin.task.api.model.Property;
import org.apache.dolphinscheduler.service.expand.CuringParamsService;
import org.apache.dolphinscheduler.service.model.TaskNode;
import org.apache.dolphinscheduler.service.process.ProcessService;
@@ -643,6 +647,21 @@ public class WorkflowInstanceServiceTest {
taskRelationJson, taskDefinitionJson, "2020-02-21 00:00:00", true, "", "", 0);
Assertions.assertEquals(Status.SUCCESS, processInstanceFinishRes.get(Constants.STATUS));
+ final RunWorkflowCommandParam runWorkflowCommandParam = RunWorkflowCommandParam.builder()
+ .commandParams(Lists.newArrayList(Property.builder()
+ .prop("name")
+ .direct(Direct.IN)
+ .type(DataType.VARCHAR)
+ .value("commandParam")
+ .build()))
+ .timeZone("Asia/Shanghai")
+ .build();
+ workflowInstance.setCommandParam(JSONUtils.toJsonString(runWorkflowCommandParam));
+ Map<String, Object> processInstanceFinishRes2 =
+ workflowInstanceService.updateWorkflowInstance(loginUser, projectCode, 1,
+ taskRelationJson, taskDefinitionJson, "2020-02-21 00:00:00", true, "", "", 0);
+ Assertions.assertEquals(Status.SUCCESS, processInstanceFinishRes2.get(Constants.STATUS));
+
// success
when(workflowDefinitionMapper.queryByCode(46L)).thenReturn(workflowDefinition);
putMsg(result, Status.SUCCESS, projectCode);
@@ -798,6 +817,42 @@ public class WorkflowInstanceServiceTest {
Assertions.assertEquals(Status.WORKFLOW_INSTANCE_NOT_EXIST, processNotExist.get(Constants.STATUS));
}
+ @Test
+ public void testViewVariablesWithStartingParam() {
+ final RunWorkflowCommandParam runWorkflowCommandParam = RunWorkflowCommandParam.builder()
+ .commandParams(Lists.newArrayList(Property.builder()
+ .prop("name")
+ .direct(Direct.IN)
+ .type(DataType.VARCHAR)
+ .value("commandParam")
+ .build()))
+ .timeZone("Asia/Shanghai")
+ .build();
+ WorkflowInstance workflowInstance = getProcessInstance();
+ workflowInstance.setCommandType(CommandType.SCHEDULER);
+ workflowInstance.setScheduleTime(new Date());
+ workflowInstance.setCommandParam(JSONUtils.toJsonString(runWorkflowCommandParam));
+
+ when(workflowInstanceMapper.queryDetailById(1)).thenReturn(workflowInstance);
+ Map<String, Object> successRes = workflowInstanceService.viewVariables(1L, 1);
+ Assertions.assertEquals(Status.SUCCESS, successRes.get(Constants.STATUS));
+
+ final RunWorkflowCommandParam commandParamWithEmptyTimeZone = RunWorkflowCommandParam.builder()
+ .commandParams(Lists.newArrayList(Property.builder()
+ .prop("name")
+ .direct(Direct.IN)
+ .type(DataType.VARCHAR)
+ .value("commandParam")
+ .build()))
+ .build();
+ workflowInstance.setCommandType(CommandType.SCHEDULER);
+ workflowInstance.setScheduleTime(new Date());
+ workflowInstance.setCommandParam(JSONUtils.toJsonString(commandParamWithEmptyTimeZone));
+ Map<String, Object> successRes2 = workflowInstanceService.viewVariables(1L, 1);
+ Assertions.assertEquals(Status.SUCCESS, successRes2.get(Constants.STATUS));
+
+ }
+
/**
* get Mock Admin User
*