From c7432f5a1baf646ae7ef1ada02bd6cd6f9f3377a Mon Sep 17 00:00:00 2001 From: relee Date: Wed, 6 Nov 2024 02:19:39 +0800 Subject: [PATCH] fix #16768: Add schedule time parameter to sub-workflow instance --- .../trigger/SubWorkflowTrigger.java | 19 ++++++++++++++++--- .../trigger/SubWorkflowTriggerRequest.java | 10 ++++++++++ .../trigger/SubWorkflowTriggerResponse.java | 12 ++++++++---- 3 files changed, 34 insertions(+), 7 deletions(-) diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/task/subworkflow/trigger/SubWorkflowTrigger.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/task/subworkflow/trigger/SubWorkflowTrigger.java index 20523b48566b..00b592ca7a9d 100644 --- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/task/subworkflow/trigger/SubWorkflowTrigger.java +++ b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/task/subworkflow/trigger/SubWorkflowTrigger.java @@ -22,14 +22,15 @@ import org.apache.dolphinscheduler.common.enums.WarningType; import org.apache.dolphinscheduler.common.enums.WorkflowExecutionStatus; import org.apache.dolphinscheduler.common.utils.DateUtils; +import org.apache.dolphinscheduler.common.utils.JSONUtils; import org.apache.dolphinscheduler.dao.entity.Command; import org.apache.dolphinscheduler.dao.entity.WorkflowDefinition; import org.apache.dolphinscheduler.dao.entity.WorkflowInstance; import org.apache.dolphinscheduler.dao.utils.EnvironmentUtils; import org.apache.dolphinscheduler.dao.utils.WorkerGroupUtils; +import org.apache.dolphinscheduler.extract.master.command.RunWorkflowCommandParam; import org.apache.dolphinscheduler.server.master.engine.workflow.trigger.AbstractWorkflowTrigger; -import org.apache.commons.lang3.NotImplementedException; import org.apache.commons.lang3.ObjectUtils; import java.util.Date; @@ -87,12 +88,24 @@ protected WorkflowInstance constructWorkflowInstance(final SubWorkflowTriggerReq @Override protected Command constructTriggerCommand(final SubWorkflowTriggerRequest subWorkflowTriggerRequest, final WorkflowInstance workflowInstance) { - throw new NotImplementedException(); + final RunWorkflowCommandParam runWorkflowCommandParam = RunWorkflowCommandParam.builder() + .commandParams(subWorkflowTriggerRequest.getStartParamList()) + .startNodes(subWorkflowTriggerRequest.getStartNodes()) + .timeZone(DateUtils.getTimezone()) + .build(); + return Command.builder() + .commandType(CommandType.START_PROCESS) + .workflowDefinitionCode(subWorkflowTriggerRequest.getWorkflowDefinitionCode()) + .workflowDefinitionVersion(subWorkflowTriggerRequest.getWorkflowDefinitionVersion()) + .workflowInstanceId(workflowInstance.getId()) + .workflowInstancePriority(workflowInstance.getWorkflowInstancePriority()) + .commandParam(JSONUtils.toJsonString(runWorkflowCommandParam)) + .build(); } @Override protected SubWorkflowTriggerResponse onTriggerSuccess(WorkflowInstance workflowInstance) { - throw new NotImplementedException(); + return SubWorkflowTriggerResponse.success(workflowInstance.getId()); } } diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/task/subworkflow/trigger/SubWorkflowTriggerRequest.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/task/subworkflow/trigger/SubWorkflowTriggerRequest.java index 138efa40fa83..056a643e4ed2 100644 --- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/task/subworkflow/trigger/SubWorkflowTriggerRequest.java +++ b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/task/subworkflow/trigger/SubWorkflowTriggerRequest.java @@ -17,12 +17,22 @@ package org.apache.dolphinscheduler.server.master.runner.task.subworkflow.trigger; +import org.apache.dolphinscheduler.common.enums.FailureStrategy; +import org.apache.dolphinscheduler.common.enums.Flag; +import org.apache.dolphinscheduler.common.enums.Priority; +import org.apache.dolphinscheduler.common.enums.TaskDependType; +import org.apache.dolphinscheduler.common.enums.WarningType; import org.apache.dolphinscheduler.plugin.task.api.model.Property; import java.util.ArrayList; import java.util.Date; import java.util.List; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + @Data @Builder @NoArgsConstructor diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/task/subworkflow/trigger/SubWorkflowTriggerResponse.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/task/subworkflow/trigger/SubWorkflowTriggerResponse.java index f8a86a4408cc..1935ddd75eb8 100644 --- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/task/subworkflow/trigger/SubWorkflowTriggerResponse.java +++ b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/task/subworkflow/trigger/SubWorkflowTriggerResponse.java @@ -17,8 +17,6 @@ package org.apache.dolphinscheduler.server.master.runner.task.subworkflow.trigger; -import org.apache.commons.lang3.NotImplementedException; - import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; @@ -37,11 +35,17 @@ public class SubWorkflowTriggerResponse { private Integer workflowInstanceId; public static SubWorkflowTriggerResponse fail(String message) { - throw new NotImplementedException(); + return SubWorkflowTriggerResponse.builder() + .success(false) + .message(message) + .build(); } public static SubWorkflowTriggerResponse success(Integer workflowInstanceId) { - throw new NotImplementedException(); + return SubWorkflowTriggerResponse.builder() + .success(true) + .workflowInstanceId(workflowInstanceId) + .build(); } }