From 749a9d2f43ef491944ba179d253a857c0ce71246 Mon Sep 17 00:00:00 2001 From: "Kevin.Shin" Date: Fri, 5 Aug 2022 11:55:12 +0800 Subject: [PATCH] fix dependent task when the dependent on process have forbidden tasks (#10952) * fix dependent task when the dependent on process have forbidden tasks * fix dependent task when the dependent on process have forbidden tasks Co-authored-by: shenk-b --- .../server/utils/DependentExecute.java | 25 +++++++++++-------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/utils/DependentExecute.java b/dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/utils/DependentExecute.java index a26e8c6e29..627d481aca 100644 --- a/dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/utils/DependentExecute.java +++ b/dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/utils/DependentExecute.java @@ -23,6 +23,7 @@ import org.apache.dolphinscheduler.common.enums.DependResult; import org.apache.dolphinscheduler.common.enums.DependentRelation; import org.apache.dolphinscheduler.common.enums.ExecutionStatus; import org.apache.dolphinscheduler.common.enums.TaskType; +import org.apache.dolphinscheduler.common.enums.Flag; import org.apache.dolphinscheduler.common.model.DateInterval; import org.apache.dolphinscheduler.common.model.DependentItem; import org.apache.dolphinscheduler.common.utils.DependentUtils; @@ -145,6 +146,7 @@ public class DependentExecute { Map definiteTask = taskDefinitionLogs.stream().filter(log -> !log.getTaskType().equals(TaskType.SUB_PROCESS.getDesc()) || !log.getTaskType().equals(TaskType.DEPENDENT.getDesc()) || !log.getTaskType().equals(TaskType.CONDITIONS.getDesc())) + .filter(log -> log.getFlag().equals(Flag.YES)) .collect(Collectors.toMap(TaskDefinition::getCode, TaskDefinitionLog::getName)); if (!definiteTask.isEmpty()) { List taskInstanceList = processService.findLastTaskInstanceListInterval(definiteTask.keySet(), dateInterval); @@ -194,25 +196,26 @@ public class DependentExecute { */ private DependResult getDependTaskResult(ProcessInstance processInstance, long taskCode, DateInterval dateInterval) { TaskInstance taskInstance = processService.findLastTaskInstanceInterval(taskCode, dateInterval); - DependResult result; if (taskInstance == null) { - if (!processInstance.getState().typeIsFinished()) { - logger.info("Wait for the dependent workflow to complete, taskCode:{}, processInstanceId:{}, processInstance state:{}", - taskCode, processInstance.getId(), processInstance.getState()); - return DependResult.WAITING; - } TaskDefinition taskDefinition = processService.findTaskDefinitionByCode(taskCode); if (taskDefinition == null) { logger.error("Cannot find the task definition, something error, taskCode: {}", taskCode); - } else { - logger.warn("Cannot find the task in the process instance when the ProcessInstance is finish, taskCode: {}, taskName: {}", taskCode, taskDefinition.getName()); + return DependResult.FAILED; } - result = DependResult.FAILED; + if (taskDefinition.getFlag() == Flag.NO) { + logger.warn("Cannot find the task instance, but the task is forbidden, so dependent success, taskCode: {}, taskName: {}", taskCode, taskDefinition.getName()); + return DependResult.SUCCESS; + } + if (!processInstance.getState().typeIsFinished()) { + logger.info("Wait for the dependent workflow to complete, taskCode:{}, processInstanceId:{}, processInstance state:{}", taskCode, processInstance.getId(), processInstance.getState()); + return DependResult.WAITING; + } + logger.warn("Cannot find the task in the process instance when the ProcessInstance is finish, taskCode: {}, taskName: {}", taskCode, taskDefinition.getName()); + return DependResult.FAILED; } else { logger.info("The running task, taskId:{}, taskCode:{}, taskName:{}", taskInstance.getId(), taskInstance.getTaskCode(), taskInstance.getName()); - result = getDependResultByState(taskInstance.getState()); + return getDependResultByState(taskInstance.getState()); } - return result; } /**