|
@@ -26,6 +26,7 @@ import org.apache.dolphinscheduler.common.enums.TaskTimeoutStrategy;
|
|
import org.apache.dolphinscheduler.common.model.TaskNode;
|
|
import org.apache.dolphinscheduler.common.model.TaskNode;
|
|
import org.apache.dolphinscheduler.common.task.TaskTimeoutParameter;
|
|
import org.apache.dolphinscheduler.common.task.TaskTimeoutParameter;
|
|
import org.apache.dolphinscheduler.common.thread.Stopper;
|
|
import org.apache.dolphinscheduler.common.thread.Stopper;
|
|
|
|
+import org.apache.dolphinscheduler.common.utils.CollectionUtils;
|
|
import org.apache.dolphinscheduler.dao.entity.ProcessDefinition;
|
|
import org.apache.dolphinscheduler.dao.entity.ProcessDefinition;
|
|
import org.apache.dolphinscheduler.dao.entity.TaskInstance;
|
|
import org.apache.dolphinscheduler.dao.entity.TaskInstance;
|
|
import org.apache.dolphinscheduler.remote.command.TaskKillRequestCommand;
|
|
import org.apache.dolphinscheduler.remote.command.TaskKillRequestCommand;
|
|
@@ -35,9 +36,12 @@ import org.apache.dolphinscheduler.server.master.cache.impl.TaskInstanceCacheMan
|
|
import org.apache.dolphinscheduler.server.master.dispatch.context.ExecutionContext;
|
|
import org.apache.dolphinscheduler.server.master.dispatch.context.ExecutionContext;
|
|
import org.apache.dolphinscheduler.server.master.dispatch.enums.ExecutorType;
|
|
import org.apache.dolphinscheduler.server.master.dispatch.enums.ExecutorType;
|
|
import org.apache.dolphinscheduler.server.master.dispatch.executor.NettyExecutorManager;
|
|
import org.apache.dolphinscheduler.server.master.dispatch.executor.NettyExecutorManager;
|
|
|
|
+import org.apache.dolphinscheduler.server.registry.ZookeeperRegistryCenter;
|
|
import org.apache.dolphinscheduler.service.bean.SpringApplicationContext;
|
|
import org.apache.dolphinscheduler.service.bean.SpringApplicationContext;
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
|
import java.util.Date;
|
|
import java.util.Date;
|
|
|
|
+import java.util.Set;
|
|
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -53,6 +57,12 @@ public class MasterTaskExecThread extends MasterBaseTaskExecThread {
|
|
|
|
|
|
private NettyExecutorManager nettyExecutorManager;
|
|
private NettyExecutorManager nettyExecutorManager;
|
|
|
|
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * zookeeper register center
|
|
|
|
+ */
|
|
|
|
+ private ZookeeperRegistryCenter zookeeperRegistryCenter;
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* constructor of MasterTaskExecThread
|
|
* constructor of MasterTaskExecThread
|
|
* @param taskInstance task instance
|
|
* @param taskInstance task instance
|
|
@@ -61,6 +71,7 @@ public class MasterTaskExecThread extends MasterBaseTaskExecThread {
|
|
super(taskInstance);
|
|
super(taskInstance);
|
|
this.taskInstanceCacheManager = SpringApplicationContext.getBean(TaskInstanceCacheManagerImpl.class);
|
|
this.taskInstanceCacheManager = SpringApplicationContext.getBean(TaskInstanceCacheManagerImpl.class);
|
|
this.nettyExecutorManager = SpringApplicationContext.getBean(NettyExecutorManager.class);
|
|
this.nettyExecutorManager = SpringApplicationContext.getBean(NettyExecutorManager.class);
|
|
|
|
+ this.zookeeperRegistryCenter = SpringApplicationContext.getBean(ZookeeperRegistryCenter.class);
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -175,6 +186,16 @@ public class MasterTaskExecThread extends MasterBaseTaskExecThread {
|
|
}
|
|
}
|
|
alreadyKilled = true;
|
|
alreadyKilled = true;
|
|
|
|
|
|
|
|
+ String taskInstanceWorkerGroup = taskInstance.getWorkerGroup();
|
|
|
|
+
|
|
|
|
+ // not exists
|
|
|
|
+ if (!existsValidWorkerGroup(taskInstanceWorkerGroup)){
|
|
|
|
+ taskInstance.setState(ExecutionStatus.KILL);
|
|
|
|
+ taskInstance.setEndTime(new Date());
|
|
|
|
+ processService.updateTaskInstance(taskInstance);
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
TaskKillRequestCommand killCommand = new TaskKillRequestCommand();
|
|
TaskKillRequestCommand killCommand = new TaskKillRequestCommand();
|
|
killCommand.setTaskInstanceId(taskInstance.getId());
|
|
killCommand.setTaskInstanceId(taskInstance.getId());
|
|
|
|
|
|
@@ -185,10 +206,33 @@ public class MasterTaskExecThread extends MasterBaseTaskExecThread {
|
|
|
|
|
|
nettyExecutorManager.executeDirectly(executionContext);
|
|
nettyExecutorManager.executeDirectly(executionContext);
|
|
|
|
|
|
- logger.info("master add kill task :{} id:{} to kill queue",
|
|
|
|
|
|
+ logger.info("master kill taskInstance name :{} taskInstance id:{}",
|
|
taskInstance.getName(), taskInstance.getId() );
|
|
taskInstance.getName(), taskInstance.getId() );
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * whether exists valid worker group
|
|
|
|
+ * @param taskInstanceWorkerGroup taskInstanceWorkerGroup
|
|
|
|
+ * @return whether exists
|
|
|
|
+ */
|
|
|
|
+ public Boolean existsValidWorkerGroup(String taskInstanceWorkerGroup){
|
|
|
|
+ Set<String> workerGroups = zookeeperRegistryCenter.getWorkerGroupDirectly();
|
|
|
|
+ // not worker group
|
|
|
|
+ if (CollectionUtils.isEmpty(workerGroups)){
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // has worker group , but not taskInstance assigned worker group
|
|
|
|
+ if (!workerGroups.contains(taskInstanceWorkerGroup)){
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ Set<String> workers = zookeeperRegistryCenter.getWorkerGroupNodesDirectly(taskInstanceWorkerGroup);
|
|
|
|
+ if (CollectionUtils.isEmpty(workers)) {
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* get task timeout parameter
|
|
* get task timeout parameter
|
|
* @return TaskTimeoutParameter
|
|
* @return TaskTimeoutParameter
|