|
|
@ -45,6 +45,7 @@ import org.apache.dolphinscheduler.service.bean.SpringApplicationContext; |
|
|
|
import org.apache.dolphinscheduler.service.process.ProcessService; |
|
|
|
import org.apache.dolphinscheduler.service.process.ProcessService; |
|
|
|
import org.apache.dolphinscheduler.service.queue.entity.TaskExecutionContext; |
|
|
|
import org.apache.dolphinscheduler.service.queue.entity.TaskExecutionContext; |
|
|
|
import org.apache.dolphinscheduler.spi.enums.ResourceType; |
|
|
|
import org.apache.dolphinscheduler.spi.enums.ResourceType; |
|
|
|
|
|
|
|
import org.apache.dolphinscheduler.spi.task.TaskConstants; |
|
|
|
import org.apache.dolphinscheduler.spi.task.request.DataxTaskExecutionContext; |
|
|
|
import org.apache.dolphinscheduler.spi.task.request.DataxTaskExecutionContext; |
|
|
|
import org.apache.dolphinscheduler.spi.task.request.ProcedureTaskExecutionContext; |
|
|
|
import org.apache.dolphinscheduler.spi.task.request.ProcedureTaskExecutionContext; |
|
|
|
import org.apache.dolphinscheduler.spi.task.request.SQLTaskExecutionContext; |
|
|
|
import org.apache.dolphinscheduler.spi.task.request.SQLTaskExecutionContext; |
|
|
@ -69,7 +70,7 @@ import com.google.common.base.Strings; |
|
|
|
|
|
|
|
|
|
|
|
public abstract class BaseTaskProcessor implements ITaskProcessor { |
|
|
|
public abstract class BaseTaskProcessor implements ITaskProcessor { |
|
|
|
|
|
|
|
|
|
|
|
protected Logger logger = LoggerFactory.getLogger(getClass()); |
|
|
|
protected final Logger logger = LoggerFactory.getLogger(String.format(TaskConstants.TASK_LOG_LOGGER_NAME_FORMAT, getClass())); |
|
|
|
|
|
|
|
|
|
|
|
protected boolean killed = false; |
|
|
|
protected boolean killed = false; |
|
|
|
|
|
|
|
|
|
|
@ -85,12 +86,12 @@ public abstract class BaseTaskProcessor implements ITaskProcessor { |
|
|
|
|
|
|
|
|
|
|
|
protected int commitInterval; |
|
|
|
protected int commitInterval; |
|
|
|
|
|
|
|
|
|
|
|
protected boolean isTaskLogger; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected ProcessService processService = SpringApplicationContext.getBean(ProcessService.class); |
|
|
|
protected ProcessService processService = SpringApplicationContext.getBean(ProcessService.class); |
|
|
|
|
|
|
|
|
|
|
|
protected MasterConfig masterConfig = SpringApplicationContext.getBean(MasterConfig.class); |
|
|
|
protected MasterConfig masterConfig = SpringApplicationContext.getBean(MasterConfig.class); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected String threadLoggerInfoName; |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void init(TaskInstance taskInstance, ProcessInstance processInstance) { |
|
|
|
public void init(TaskInstance taskInstance, ProcessInstance processInstance) { |
|
|
|
if (processService == null) { |
|
|
|
if (processService == null) { |
|
|
@ -103,7 +104,6 @@ public abstract class BaseTaskProcessor implements ITaskProcessor { |
|
|
|
this.processInstance = processInstance; |
|
|
|
this.processInstance = processInstance; |
|
|
|
this.maxRetryTimes = masterConfig.getTaskCommitRetryTimes(); |
|
|
|
this.maxRetryTimes = masterConfig.getTaskCommitRetryTimes(); |
|
|
|
this.commitInterval = masterConfig.getTaskCommitInterval(); |
|
|
|
this.commitInterval = masterConfig.getTaskCommitInterval(); |
|
|
|
this.isTaskLogger = masterConfig.isTaskLogger(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -133,13 +133,15 @@ public abstract class BaseTaskProcessor implements ITaskProcessor { |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* dispatch task |
|
|
|
* dispatch task |
|
|
|
* @return |
|
|
|
|
|
|
|
*/ |
|
|
|
*/ |
|
|
|
protected abstract boolean dispatchTask(); |
|
|
|
protected abstract boolean dispatchTask(); |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public boolean action(TaskAction taskAction) { |
|
|
|
public boolean action(TaskAction taskAction) { |
|
|
|
|
|
|
|
String threadName = Thread.currentThread().getName(); |
|
|
|
|
|
|
|
if (StringUtils.isNotEmpty(threadLoggerInfoName)) { |
|
|
|
|
|
|
|
Thread.currentThread().setName(threadLoggerInfoName); |
|
|
|
|
|
|
|
} |
|
|
|
switch (taskAction) { |
|
|
|
switch (taskAction) { |
|
|
|
case STOP: |
|
|
|
case STOP: |
|
|
|
return stop(); |
|
|
|
return stop(); |
|
|
@ -155,8 +157,9 @@ public abstract class BaseTaskProcessor implements ITaskProcessor { |
|
|
|
return dispatch(); |
|
|
|
return dispatch(); |
|
|
|
default: |
|
|
|
default: |
|
|
|
logger.error("unknown task action: {}", taskAction); |
|
|
|
logger.error("unknown task action: {}", taskAction); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// reset thread name
|
|
|
|
|
|
|
|
Thread.currentThread().setName(threadName); |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -205,6 +208,18 @@ public abstract class BaseTaskProcessor implements ITaskProcessor { |
|
|
|
return this.taskInstance.getState(); |
|
|
|
return this.taskInstance.getState(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* set master task running logger. |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public void setTaskExecutionLogger() { |
|
|
|
|
|
|
|
threadLoggerInfoName = LoggerUtils.buildTaskId(taskInstance.getFirstSubmitTime(), |
|
|
|
|
|
|
|
processInstance.getProcessDefinitionCode(), |
|
|
|
|
|
|
|
processInstance.getProcessDefinitionVersion(), |
|
|
|
|
|
|
|
taskInstance.getProcessInstanceId(), |
|
|
|
|
|
|
|
taskInstance.getId()); |
|
|
|
|
|
|
|
Thread.currentThread().setName(threadLoggerInfoName); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* get TaskExecutionContext |
|
|
|
* get TaskExecutionContext |
|
|
|
* |
|
|
|
* |
|
|
@ -267,21 +282,6 @@ public abstract class BaseTaskProcessor implements ITaskProcessor { |
|
|
|
.create(); |
|
|
|
.create(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* set master task running logger. |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public void setTaskExecutionLogger(boolean isTaskLogger) { |
|
|
|
|
|
|
|
if (!isTaskLogger) { |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
logger = LoggerFactory.getLogger(LoggerUtils.buildTaskId(LoggerUtils.TASK_LOGGER_INFO_PREFIX, |
|
|
|
|
|
|
|
taskInstance.getFirstSubmitTime(), |
|
|
|
|
|
|
|
processInstance.getProcessDefinitionCode(), |
|
|
|
|
|
|
|
processInstance.getProcessDefinitionVersion(), |
|
|
|
|
|
|
|
taskInstance.getProcessInstanceId(), |
|
|
|
|
|
|
|
taskInstance.getId())); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* set procedure task relation |
|
|
|
* set procedure task relation |
|
|
|
* |
|
|
|
* |
|
|
|