ruanwenjun commented on code in PR #13948:
URL: 
https://github.com/apache/dolphinscheduler/pull/13948#discussion_r1176651789


##########
dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/execute/MasterTaskExecuteRunnable.java:
##########
@@ -0,0 +1,184 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.dolphinscheduler.server.master.runner.execute;
+
+import static ch.qos.logback.classic.ClassicConstants.FINALIZE_SESSION_MARKER;
+import static 
org.apache.dolphinscheduler.common.constants.Constants.DRY_RUN_FLAG_YES;
+
+import org.apache.dolphinscheduler.common.log.remote.RemoteLogUtils;
+import org.apache.dolphinscheduler.common.utils.JSONUtils;
+import org.apache.dolphinscheduler.plugin.task.api.TaskExecutionContext;
+import 
org.apache.dolphinscheduler.plugin.task.api.TaskExecutionContextCacheManager;
+import org.apache.dolphinscheduler.plugin.task.api.enums.TaskExecutionStatus;
+import org.apache.dolphinscheduler.plugin.task.api.log.TaskInstanceLogHeader;
+import org.apache.dolphinscheduler.plugin.task.api.utils.LogUtils;
+import org.apache.dolphinscheduler.remote.exceptions.RemotingException;
+import 
org.apache.dolphinscheduler.server.master.exception.LogicTaskFactoryNotFoundException;
+import 
org.apache.dolphinscheduler.server.master.exception.LogicTaskInitializeException;
+import 
org.apache.dolphinscheduler.server.master.exception.MasterTaskExecuteException;
+import 
org.apache.dolphinscheduler.server.master.runner.message.MasterMessageSenderManager;
+import org.apache.dolphinscheduler.server.master.runner.task.ILogicTask;
+import 
org.apache.dolphinscheduler.server.master.runner.task.LogicTaskPluginFactoryBuilder;
+
+import lombok.extern.slf4j.Slf4j;
+
+@Slf4j
+public abstract class MasterTaskExecuteRunnable implements Runnable {
+
+    protected final TaskExecutionContext taskExecutionContext;
+    protected final LogicTaskPluginFactoryBuilder 
logicTaskPluginFactoryBuilder;
+    protected final MasterMessageSenderManager masterMessageSenderManager;
+    protected ILogicTask logicTask;
+
+    public MasterTaskExecuteRunnable(TaskExecutionContext taskExecutionContext,
+                                     LogicTaskPluginFactoryBuilder 
logicTaskPluginFactoryBuilder,
+                                     MasterMessageSenderManager 
masterMessageSenderManager) {
+        this.taskExecutionContext = taskExecutionContext;
+        this.logicTaskPluginFactoryBuilder = logicTaskPluginFactoryBuilder;
+        this.masterMessageSenderManager = masterMessageSenderManager;
+    }
+
+    protected abstract void executeTask() throws MasterTaskExecuteException;
+
+    protected abstract void afterExecute() throws MasterTaskExecuteException;
+
+    protected void afterThrowing(Throwable throwable) {
+        try {
+            cancelTask();
+            log.info("Get a exception when execute the task, canceled the 
task");
+        } catch (Exception e) {
+            // todo: if the task cancel failed, do we need to set the task 
status to failure?
+            log.error("Cancel task failed,", e);
+        }
+        
taskExecutionContext.setCurrentExecutionStatus(TaskExecutionStatus.FAILURE);
+        sendTaskResult();
+        log.info(
+                "Get a exception when execute the task, sent the task execute 
result to master, the current task execute result is {}",
+                taskExecutionContext.getCurrentExecutionStatus());
+        
TaskExecutionContextCacheManager.removeByTaskInstanceId(taskExecutionContext.getTaskInstanceId());
+        log.info("Get a exception when execute the task, removed the 
TaskExecutionContext");
+    }
+
+    public void cancelTask() throws MasterTaskExecuteException {
+        if (logicTask != null) {
+            logicTask.kill();
+        }
+    }
+
+    public void pauseTask() throws MasterTaskExecuteException {
+        if (logicTask != null) {
+            logicTask.pause();
+        }
+    }
+
+    public TaskExecutionContext getTaskExecutionContext() {
+        return taskExecutionContext;
+    }
+
+    @Override
+    public void run() {
+        try (
+                final LogUtils.MDCAutoClosableContext mdcAutoClosableContext = 
LogUtils.setWorkflowAndTaskInstanceIDMDC(
+                        taskExecutionContext.getProcessInstanceId(), 
taskExecutionContext.getTaskInstanceId());
+                final LogUtils.MDCAutoClosableContext mdcAutoClosableContext1 =
+                        
LogUtils.setTaskInstanceLogFullPathMDC(taskExecutionContext.getLogPath())) {
+            TaskInstanceLogHeader.printInitializeTaskContextHeader();
+            initializeTask();
+
+            if (DRY_RUN_FLAG_YES == taskExecutionContext.getDryRun()) {

Review Comment:
   OK, I removed dry run in master task.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to