Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,11 @@ public String logTaskInstanceInDetail(TaskInstance taskInstance) {
.append(Strings.repeat("*", horizontalLineLength)).append("\n")
.append("Task Name: ").append(taskInstance.getName()).append("\n")
.append("Workflow Instance Name: ").append(taskInstance.getWorkflowInstance().getName()).append("\n")
.append("Task Execute Type: ").append(taskInstance.getTaskExecuteType().getDesc()).append("\n")
.append("Task Execute Type: ")
.append(taskInstance.getTaskExecuteType() == null
? "N/A"
: taskInstance.getTaskExecuteType().getDesc())
.append("\n")
.append("Execute State: ").append(taskInstance.getState().getDesc()).append("\n")
.append("Host: ").append(taskInstance.getHost()).append("\n")
.append("Task Type: ").append(taskInstance.getTaskType()).append("\n")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,25 @@ public void testLogTaskInstanceInDetails() {
+ "Start Time: 2023-08-01\n"
+ "End Time: 2023-08-01\n", WorkflowInstanceUtils.logTaskInstanceInDetail(taskInstance));
}

@Test
public void testLogTaskInstanceInDetailWithNullTaskExecuteType() {
// taskExecuteType is null when the task definition was created via workflow
// export/import; the log helper must not throw NPE on the task finish path
WorkflowInstance workflowInstance = new WorkflowInstance();
workflowInstance.setName("test_process");
workflowInstance.setTenantCode("default");

TaskInstance taskInstance = new TaskInstance();
taskInstance.setName("test_task");
taskInstance.setWorkflowInstance(workflowInstance);
taskInstance.setState(TaskExecutionStatus.SUCCESS);
taskInstance.setTaskExecuteType(null);
taskInstance.setHost("127.0.0.1");
taskInstance.setTaskType("SHELL");
taskInstance.setTaskInstancePriority(Priority.MEDIUM);

String detail = WorkflowInstanceUtils.logTaskInstanceInDetail(taskInstance);
Assertions.assertTrue(detail.contains("Task Execute Type: N/A"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.apache.dolphinscheduler.common.enums.AuthorizationType;
import org.apache.dolphinscheduler.common.enums.Flag;
import org.apache.dolphinscheduler.common.enums.ReleaseState;
import org.apache.dolphinscheduler.common.enums.TaskExecuteType;
import org.apache.dolphinscheduler.common.enums.TimeoutFlag;
import org.apache.dolphinscheduler.common.enums.WorkflowExecutionStatus;
import org.apache.dolphinscheduler.common.graph.DAG;
Expand Down Expand Up @@ -438,6 +439,11 @@ public int saveTaskDefine(User operator, long projectCode, List<TaskDefinitionLo
taskDefinitionLog.setUpdateTime(now);
taskDefinitionLog.setOperateTime(now);
taskDefinitionLog.setOperator(operator.getId());
if (taskDefinitionLog.getTaskExecuteType() == null) {
// taskExecuteType is missing when the task definition comes from
// workflow export/import, default it to BATCH instead of persisting null
taskDefinitionLog.setTaskExecuteType(TaskExecuteType.BATCH);
}
if (taskDefinitionLog.getCode() == 0) {
taskDefinitionLog.setCode(CodeGenerateUtils.genCode());
}
Expand Down
Loading