|
|
@ -17,6 +17,7 @@ |
|
|
|
|
|
|
|
|
|
|
|
package org.apache.dolphinscheduler.server.worker.processor; |
|
|
|
package org.apache.dolphinscheduler.server.worker.processor; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import org.apache.dolphinscheduler.common.enums.Event; |
|
|
|
import org.apache.dolphinscheduler.common.enums.ExecutionStatus; |
|
|
|
import org.apache.dolphinscheduler.common.enums.ExecutionStatus; |
|
|
|
import org.apache.dolphinscheduler.common.enums.TaskType; |
|
|
|
import org.apache.dolphinscheduler.common.enums.TaskType; |
|
|
|
import org.apache.dolphinscheduler.common.thread.ThreadUtils; |
|
|
|
import org.apache.dolphinscheduler.common.thread.ThreadUtils; |
|
|
@ -34,19 +35,18 @@ import org.apache.dolphinscheduler.remote.command.TaskExecuteRequestCommand; |
|
|
|
import org.apache.dolphinscheduler.remote.processor.NettyRequestProcessor; |
|
|
|
import org.apache.dolphinscheduler.remote.processor.NettyRequestProcessor; |
|
|
|
import org.apache.dolphinscheduler.server.entity.TaskExecutionContext; |
|
|
|
import org.apache.dolphinscheduler.server.entity.TaskExecutionContext; |
|
|
|
import org.apache.dolphinscheduler.server.utils.LogUtils; |
|
|
|
import org.apache.dolphinscheduler.server.utils.LogUtils; |
|
|
|
|
|
|
|
import org.apache.dolphinscheduler.server.worker.cache.ResponceCache; |
|
|
|
import org.apache.dolphinscheduler.server.worker.config.WorkerConfig; |
|
|
|
import org.apache.dolphinscheduler.server.worker.config.WorkerConfig; |
|
|
|
import org.apache.dolphinscheduler.server.worker.runner.TaskExecuteThread; |
|
|
|
import org.apache.dolphinscheduler.server.worker.runner.TaskExecuteThread; |
|
|
|
import org.apache.dolphinscheduler.service.bean.SpringApplicationContext; |
|
|
|
import org.apache.dolphinscheduler.service.bean.SpringApplicationContext; |
|
|
|
|
|
|
|
|
|
|
|
import java.util.Date; |
|
|
|
import java.util.Date; |
|
|
|
import java.util.Optional; |
|
|
|
import java.util.Optional; |
|
|
|
import java.util.concurrent.ExecutionException; |
|
|
|
|
|
|
|
import java.util.concurrent.ExecutorService; |
|
|
|
import java.util.concurrent.ExecutorService; |
|
|
|
|
|
|
|
|
|
|
|
import org.slf4j.Logger; |
|
|
|
import org.slf4j.Logger; |
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
|
|
|
|
|
|
|
|
import com.github.rholder.retry.RetryException; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import io.netty.channel.Channel; |
|
|
|
import io.netty.channel.Channel; |
|
|
|
|
|
|
|
|
|
|
@ -100,15 +100,16 @@ public class TaskExecuteProcessor implements NettyRequestProcessor { |
|
|
|
logger.error("task execution context is null"); |
|
|
|
logger.error("task execution context is null"); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
taskExecutionContext.setHost(NetUtils.getHost() + ":" + workerConfig.getListenPort()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// custom logger
|
|
|
|
// custom logger
|
|
|
|
Logger taskLogger = LoggerFactory.getLogger(LoggerUtils.buildTaskId(LoggerUtils.TASK_LOGGER_INFO_PREFIX, |
|
|
|
Logger taskLogger = LoggerFactory.getLogger(LoggerUtils.buildTaskId(LoggerUtils.TASK_LOGGER_INFO_PREFIX, |
|
|
|
taskExecutionContext.getProcessDefineId(), |
|
|
|
taskExecutionContext.getProcessDefineId(), |
|
|
|
taskExecutionContext.getProcessInstanceId(), |
|
|
|
taskExecutionContext.getProcessInstanceId(), |
|
|
|
taskExecutionContext.getTaskInstanceId())); |
|
|
|
taskExecutionContext.getTaskInstanceId())); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
taskExecutionContext.setHost(NetUtils.getHost() + ":" + workerConfig.getListenPort()); |
|
|
|
|
|
|
|
taskExecutionContext.setStartTime(new Date()); |
|
|
|
|
|
|
|
taskExecutionContext.setLogPath(LogUtils.getTaskLogPath(taskExecutionContext)); |
|
|
|
|
|
|
|
|
|
|
|
// local execute path
|
|
|
|
// local execute path
|
|
|
|
String execLocalPath = getExecLocalPath(taskExecutionContext); |
|
|
|
String execLocalPath = getExecLocalPath(taskExecutionContext); |
|
|
|
logger.info("task instance local execute path : {} ", execLocalPath); |
|
|
|
logger.info("task instance local execute path : {} ", execLocalPath); |
|
|
@ -126,27 +127,17 @@ public class TaskExecuteProcessor implements NettyRequestProcessor { |
|
|
|
taskCallbackService.addRemoteChannel(taskExecutionContext.getTaskInstanceId(), |
|
|
|
taskCallbackService.addRemoteChannel(taskExecutionContext.getTaskInstanceId(), |
|
|
|
new NettyRemoteChannel(channel, command.getOpaque())); |
|
|
|
new NettyRemoteChannel(channel, command.getOpaque())); |
|
|
|
|
|
|
|
|
|
|
|
if (DateUtils.getRemainTime(taskExecutionContext.getFirstSubmitTime(), taskExecutionContext.getDelayTime() * 60L) > 0) { |
|
|
|
this.doAck(taskExecutionContext); |
|
|
|
taskExecutionContext.setCurrentExecutionStatus(ExecutionStatus.DELAY_EXECUTION); |
|
|
|
|
|
|
|
taskExecutionContext.setStartTime(null); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
taskExecutionContext.setCurrentExecutionStatus(ExecutionStatus.RUNNING_EXECUTION); |
|
|
|
|
|
|
|
taskExecutionContext.setStartTime(new Date()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// tell master the status of this task (RUNNING_EXECUTION or DELAY_EXECUTION)
|
|
|
|
// submit task
|
|
|
|
final Command ackCommand = buildAckCommand(taskExecutionContext).convert2Command(); |
|
|
|
workerExecService.submit(new TaskExecuteThread(taskExecutionContext, taskCallbackService, taskLogger)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
private void doAck(TaskExecutionContext taskExecutionContext){ |
|
|
|
RetryerUtils.retryCall(() -> { |
|
|
|
// tell master that task is in executing
|
|
|
|
taskCallbackService.sendAck(taskExecutionContext.getTaskInstanceId(),ackCommand); |
|
|
|
TaskExecuteAckCommand ackCommand = buildAckCommand(taskExecutionContext); |
|
|
|
return Boolean.TRUE; |
|
|
|
ResponceCache.get().cache(taskExecutionContext.getTaskInstanceId(),ackCommand.convert2Command(),Event.ACK); |
|
|
|
}); |
|
|
|
taskCallbackService.sendAck(taskExecutionContext.getTaskInstanceId(), ackCommand.convert2Command()); |
|
|
|
// submit task
|
|
|
|
|
|
|
|
workerExecService.submit(new TaskExecuteThread(taskExecutionContext, taskCallbackService, taskLogger)); |
|
|
|
|
|
|
|
} catch (ExecutionException | RetryException e) { |
|
|
|
|
|
|
|
logger.error(e.getMessage(), e); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|