Search in sources :

Example 1 with TaskExecutionContext

use of org.apache.dolphinscheduler.server.entity.TaskExecutionContext in project dolphinscheduler by apache.

the class TaskExecuteThreadTest method init.

@Before
public void init() throws Exception {
    taskExecutionContext = PowerMockito.mock(TaskExecutionContext.class);
    taskCallbackService = PowerMockito.mock(TaskCallbackService.class);
    applicationContext = PowerMockito.mock(ApplicationContext.class);
    SpringApplicationContext springApplicationContext = new SpringApplicationContext();
    springApplicationContext.setApplicationContext(applicationContext);
    taskExecutionContextCacheManager = new TaskExecutionContextCacheManagerImpl();
    Mockito.when(applicationContext.getBean(TaskExecutionContextCacheManagerImpl.class)).thenReturn(taskExecutionContextCacheManager);
}
Also used : SpringApplicationContext(org.apache.dolphinscheduler.service.bean.SpringApplicationContext) ApplicationContext(org.springframework.context.ApplicationContext) TaskExecutionContextCacheManagerImpl(org.apache.dolphinscheduler.server.worker.cache.impl.TaskExecutionContextCacheManagerImpl) TaskExecutionContext(org.apache.dolphinscheduler.server.entity.TaskExecutionContext) TaskCallbackService(org.apache.dolphinscheduler.server.worker.processor.TaskCallbackService) SpringApplicationContext(org.apache.dolphinscheduler.service.bean.SpringApplicationContext) Before(org.junit.Before)

Example 2 with TaskExecutionContext

use of org.apache.dolphinscheduler.server.entity.TaskExecutionContext in project dolphinscheduler by apache.

the class TaskExecuteThreadTest method testTaskClearExecPath.

@Test
public void testTaskClearExecPath() throws Exception {
    processService = mock(ProcessService.class);
    ApplicationContext applicationContext = Mockito.mock(ApplicationContext.class);
    SpringApplicationContext springApplicationContext = new SpringApplicationContext();
    springApplicationContext.setApplicationContext(applicationContext);
    Mockito.when(applicationContext.getBean(ProcessService.class)).thenReturn(processService);
    TaskExecutionContext taskExecutionContext = Mockito.mock(TaskExecutionContext.class);
    TaskCallbackService taskCallbackService = Mockito.mock(TaskCallbackService.class);
    TaskExecuteThread taskExecuteThread = PowerMockito.spy(new TaskExecuteThread(taskExecutionContext, taskCallbackService, logger));
    Mockito.when(taskExecutionContext.getExecutePath()).thenReturn("/");
    Assert.assertTrue(true);
}
Also used : SpringApplicationContext(org.apache.dolphinscheduler.service.bean.SpringApplicationContext) ApplicationContext(org.springframework.context.ApplicationContext) TaskExecutionContext(org.apache.dolphinscheduler.server.entity.TaskExecutionContext) ProcessService(org.apache.dolphinscheduler.service.process.ProcessService) TaskCallbackService(org.apache.dolphinscheduler.server.worker.processor.TaskCallbackService) SpringApplicationContext(org.apache.dolphinscheduler.service.bean.SpringApplicationContext) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 3 with TaskExecutionContext

use of org.apache.dolphinscheduler.server.entity.TaskExecutionContext in project dolphinscheduler by apache.

the class TaskExecuteProcessor method process.

@Override
public void process(Channel channel, Command command) {
    Preconditions.checkArgument(CommandType.TASK_EXECUTE_REQUEST == command.getType(), String.format("invalid command type : %s", command.getType()));
    TaskExecuteRequestCommand taskRequestCommand = FastJsonSerializer.deserialize(command.getBody(), TaskExecuteRequestCommand.class);
    logger.info("received command : {}", taskRequestCommand);
    if (taskRequestCommand == null) {
        logger.error("task execute request command is null");
        return;
    }
    String contextJson = taskRequestCommand.getTaskExecutionContext();
    TaskExecutionContext taskExecutionContext = JSONObject.parseObject(contextJson, TaskExecutionContext.class);
    if (taskExecutionContext == null) {
        logger.error("task execution context is null");
        return;
    }
    setTaskCache(taskExecutionContext);
    // custom logger
    Logger taskLogger = LoggerFactory.getLogger(LoggerUtils.buildTaskId(LoggerUtils.TASK_LOGGER_INFO_PREFIX, taskExecutionContext.getProcessDefineId(), taskExecutionContext.getProcessInstanceId(), taskExecutionContext.getTaskInstanceId()));
    taskExecutionContext.setHost(OSUtils.getHost() + ":" + workerConfig.getListenPort());
    taskExecutionContext.setStartTime(new Date());
    taskExecutionContext.setLogPath(getTaskLogPath(taskExecutionContext));
    // local execute path
    String execLocalPath = getExecLocalPath(taskExecutionContext);
    logger.info("task instance  local execute path : {} ", execLocalPath);
    FileUtils.taskLoggerThreadLocal.set(taskLogger);
    try {
        FileUtils.createWorkDirAndUserIfAbsent(execLocalPath, taskExecutionContext.getTenantCode());
    } catch (Throwable ex) {
        String errorLog = String.format("create execLocalPath : %s", execLocalPath);
        LoggerUtils.logError(Optional.ofNullable(logger), errorLog, ex);
        LoggerUtils.logError(Optional.ofNullable(taskLogger), errorLog, ex);
        taskExecutionContextCacheManager.removeByTaskInstanceId(taskExecutionContext.getTaskInstanceId());
    }
    FileUtils.taskLoggerThreadLocal.remove();
    taskCallbackService.addRemoteChannel(taskExecutionContext.getTaskInstanceId(), new NettyRemoteChannel(channel, command.getOpaque()));
    this.doAck(taskExecutionContext);
    // submit task
    workerExecService.submit(new TaskExecuteThread(taskExecutionContext, taskCallbackService, taskLogger));
}
Also used : TaskExecuteRequestCommand(org.apache.dolphinscheduler.remote.command.TaskExecuteRequestCommand) TaskExecutionContext(org.apache.dolphinscheduler.server.entity.TaskExecutionContext) Logger(org.slf4j.Logger) TaskExecuteThread(org.apache.dolphinscheduler.server.worker.runner.TaskExecuteThread) Date(java.util.Date)

Example 4 with TaskExecutionContext

use of org.apache.dolphinscheduler.server.entity.TaskExecutionContext in project dolphinscheduler by apache.

the class ExecutionContextTestUtils method getExecutionContext.

public static ExecutionContext getExecutionContext(int port) {
    TaskInstance taskInstance = Mockito.mock(TaskInstance.class);
    ProcessDefinition processDefinition = Mockito.mock(ProcessDefinition.class);
    ProcessInstance processInstance = new ProcessInstance();
    processInstance.setCommandType(CommandType.COMPLEMENT_DATA);
    taskInstance.setProcessInstance(processInstance);
    TaskExecutionContext context = TaskExecutionContextBuilder.get().buildTaskInstanceRelatedInfo(taskInstance).buildProcessInstanceRelatedInfo(processInstance).buildProcessDefinitionRelatedInfo(processDefinition).create();
    ExecutionContext executionContext = new ExecutionContext(context.toCommand(), ExecutorType.WORKER);
    executionContext.setHost(Host.of(OSUtils.getHost() + ":" + port));
    return executionContext;
}
Also used : TaskInstance(org.apache.dolphinscheduler.dao.entity.TaskInstance) TaskExecutionContext(org.apache.dolphinscheduler.server.entity.TaskExecutionContext) ExecutionContext(org.apache.dolphinscheduler.server.master.dispatch.context.ExecutionContext) ProcessDefinition(org.apache.dolphinscheduler.dao.entity.ProcessDefinition) ProcessInstance(org.apache.dolphinscheduler.dao.entity.ProcessInstance) TaskExecutionContext(org.apache.dolphinscheduler.server.entity.TaskExecutionContext)

Example 5 with TaskExecutionContext

use of org.apache.dolphinscheduler.server.entity.TaskExecutionContext in project dolphinscheduler by apache.

the class TaskPriorityQueueConsumerTest method testGetTaskExecutionContext.

@Test
public void testGetTaskExecutionContext() throws Exception {
    TaskInstance taskInstance = new TaskInstance();
    taskInstance.setId(1);
    taskInstance.setTaskType("SHELL");
    taskInstance.setProcessDefinitionId(1);
    taskInstance.setProcessInstanceId(1);
    taskInstance.setState(ExecutionStatus.KILL);
    taskInstance.setTaskJson("{\"conditionResult\":\"{\\\"successNode\\\":[\\\"\\\"],\\\"failedNode\\\":[\\\"\\\"]}\"," + "\"conditionsTask\":false," + "\"depList\":[]," + "\"dependence\":\"{}\"," + "\"forbidden\":false," + "\"id\":\"tasks-55201\"," + "\"maxRetryTimes\":0," + "\"name\":\"测试任务\"," + "\"params\":\"{\\\"rawScript\\\":\\\"echo \\\\\\\"测试任务\\\\\\\"\\\",\\\"localParams\\\":[],\\\"resourceList\\\":[]}\"," + "\"preTasks\":\"[]\"," + "\"retryInterval\":1," + "\"runFlag\":\"NORMAL\"," + "\"taskInstancePriority\":\"MEDIUM\"," + "\"taskTimeoutParameter\":{\"enable\":false,\"interval\":0}," + "\"timeout\":\"{\\\"enable\\\":false," + "\\\"strategy\\\":\\\"\\\"}\"," + "\"type\":\"SHELL\"," + "\"workerGroup\":\"NoWorkGroup\"}");
    taskInstance.setProcessInstancePriority(Priority.MEDIUM);
    taskInstance.setWorkerGroup("NoWorkGroup");
    taskInstance.setExecutorId(2);
    ProcessInstance processInstance = new ProcessInstance();
    processInstance.setId(1);
    processInstance.setTenantId(1);
    processInstance.setCommandType(CommandType.START_PROCESS);
    taskInstance.setProcessInstance(processInstance);
    taskInstance.setState(ExecutionStatus.SUBMITTED_SUCCESS);
    ProcessDefinition processDefinition = new ProcessDefinition();
    processDefinition.setUserId(2);
    processDefinition.setProjectId(1);
    taskInstance.setProcessDefine(processDefinition);
    Mockito.doReturn(taskInstance).when(processService).getTaskInstanceDetailByTaskId(1);
    Mockito.doReturn(taskInstance).when(processService).findTaskInstanceById(1);
    TaskExecutionContext taskExecutionContext = taskPriorityQueueConsumer.getTaskExecutionContext(1);
    Assert.assertNotNull(taskExecutionContext);
}
Also used : DataxTaskExecutionContext(org.apache.dolphinscheduler.server.entity.DataxTaskExecutionContext) TaskExecutionContext(org.apache.dolphinscheduler.server.entity.TaskExecutionContext) Test(org.junit.Test)

Aggregations

TaskExecutionContext (org.apache.dolphinscheduler.server.entity.TaskExecutionContext)17 Test (org.junit.Test)6 SpringApplicationContext (org.apache.dolphinscheduler.service.bean.SpringApplicationContext)5 ApplicationContext (org.springframework.context.ApplicationContext)5 Date (java.util.Date)4 ProcessInstance (org.apache.dolphinscheduler.dao.entity.ProcessInstance)4 TaskInstance (org.apache.dolphinscheduler.dao.entity.TaskInstance)4 ProcessService (org.apache.dolphinscheduler.service.process.ProcessService)4 ProcessDefinition (org.apache.dolphinscheduler.dao.entity.ProcessDefinition)3 SqoopTaskExecutionContext (org.apache.dolphinscheduler.server.entity.SqoopTaskExecutionContext)3 ExecutionContext (org.apache.dolphinscheduler.server.master.dispatch.context.ExecutionContext)3 Before (org.junit.Before)3 DataxTaskExecutionContext (org.apache.dolphinscheduler.server.entity.DataxTaskExecutionContext)2 TaskCallbackService (org.apache.dolphinscheduler.server.worker.processor.TaskCallbackService)2 ShellCommandExecutor (org.apache.dolphinscheduler.server.worker.task.ShellCommandExecutor)2 TaskProps (org.apache.dolphinscheduler.server.worker.task.TaskProps)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 IOException (java.io.IOException)1 SqoopParameters (org.apache.dolphinscheduler.common.task.sqoop.SqoopParameters)1 NettyRemotingServer (org.apache.dolphinscheduler.remote.NettyRemotingServer)1