|
|
|
@ -26,12 +26,11 @@ import org.apache.dolphinscheduler.common.model.DependentTaskModel;
|
|
|
|
|
import org.apache.dolphinscheduler.common.task.dependent.DependentParameters; |
|
|
|
|
import org.apache.dolphinscheduler.common.thread.Stopper; |
|
|
|
|
import org.apache.dolphinscheduler.common.utils.DependentUtils; |
|
|
|
|
import org.apache.dolphinscheduler.common.utils.JSONUtils; |
|
|
|
|
import org.apache.dolphinscheduler.common.utils.LoggerUtils; |
|
|
|
|
import org.apache.dolphinscheduler.common.utils.NetUtils; |
|
|
|
|
import org.apache.dolphinscheduler.dao.entity.TaskInstance; |
|
|
|
|
import org.apache.dolphinscheduler.server.utils.LogUtils; |
|
|
|
|
import org.apache.dolphinscheduler.server.utils.DependentExecute; |
|
|
|
|
import org.apache.dolphinscheduler.server.utils.LogUtils; |
|
|
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
|
|
import java.util.Date; |
|
|
|
@ -62,7 +61,7 @@ public class DependentTaskExecThread extends MasterBaseTaskExecThread {
|
|
|
|
|
/** |
|
|
|
|
* dependent date |
|
|
|
|
*/ |
|
|
|
|
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone="GMT+8") |
|
|
|
|
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") |
|
|
|
|
private Date dependentDate; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@ -78,7 +77,7 @@ public class DependentTaskExecThread extends MasterBaseTaskExecThread {
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public Boolean submitWaitComplete() { |
|
|
|
|
try{ |
|
|
|
|
try { |
|
|
|
|
logger.info("dependent task start"); |
|
|
|
|
this.taskInstance = submit(); |
|
|
|
|
logger = LoggerFactory.getLogger(LoggerUtils.buildTaskId(LoggerUtils.TASK_LOGGER_INFO_PREFIX, |
|
|
|
@ -92,8 +91,8 @@ public class DependentTaskExecThread extends MasterBaseTaskExecThread {
|
|
|
|
|
initDependParameters(); |
|
|
|
|
waitTaskQuit(); |
|
|
|
|
updateTaskState(); |
|
|
|
|
}catch (Exception e){ |
|
|
|
|
logger.error("dependent task run exception" , e); |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
logger.error("dependent task run exception", e); |
|
|
|
|
} |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
@ -102,16 +101,13 @@ public class DependentTaskExecThread extends MasterBaseTaskExecThread {
|
|
|
|
|
* init dependent parameters |
|
|
|
|
*/ |
|
|
|
|
private void initDependParameters() { |
|
|
|
|
|
|
|
|
|
this.dependentParameters = taskInstance.getDependency(); |
|
|
|
|
|
|
|
|
|
for(DependentTaskModel taskModel : dependentParameters.getDependTaskList()){ |
|
|
|
|
this.dependentTaskList.add(new DependentExecute( |
|
|
|
|
taskModel.getDependItemList(), taskModel.getRelation())); |
|
|
|
|
for (DependentTaskModel taskModel : dependentParameters.getDependTaskList()) { |
|
|
|
|
this.dependentTaskList.add(new DependentExecute(taskModel.getDependItemList(), taskModel.getRelation())); |
|
|
|
|
} |
|
|
|
|
if(this.processInstance.getScheduleTime() != null){ |
|
|
|
|
if (this.processInstance.getScheduleTime() != null) { |
|
|
|
|
this.dependentDate = this.processInstance.getScheduleTime(); |
|
|
|
|
}else{ |
|
|
|
|
} else { |
|
|
|
|
this.dependentDate = new Date(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -121,9 +117,9 @@ public class DependentTaskExecThread extends MasterBaseTaskExecThread {
|
|
|
|
|
*/ |
|
|
|
|
private void updateTaskState() { |
|
|
|
|
ExecutionStatus status; |
|
|
|
|
if(this.cancel){ |
|
|
|
|
if (this.cancel) { |
|
|
|
|
status = ExecutionStatus.KILL; |
|
|
|
|
}else{ |
|
|
|
|
} else { |
|
|
|
|
DependResult result = getTaskDependResult(); |
|
|
|
|
status = (result == DependResult.SUCCESS) ? ExecutionStatus.SUCCESS : ExecutionStatus.FAILURE; |
|
|
|
|
} |
|
|
|
@ -144,8 +140,8 @@ public class DependentTaskExecThread extends MasterBaseTaskExecThread {
|
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
while (Stopper.isRunning()) { |
|
|
|
|
try{ |
|
|
|
|
if(this.processInstance == null){ |
|
|
|
|
try { |
|
|
|
|
if (this.processInstance == null) { |
|
|
|
|
logger.error("process instance not exists , master task exec thread exit"); |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
@ -153,12 +149,12 @@ public class DependentTaskExecThread extends MasterBaseTaskExecThread {
|
|
|
|
|
this.checkTimeoutFlag = !alertTimeout(); |
|
|
|
|
handleTimeoutFailed(); |
|
|
|
|
} |
|
|
|
|
if(this.cancel || this.processInstance.getState() == ExecutionStatus.READY_STOP){ |
|
|
|
|
if (this.cancel || this.processInstance.getState() == ExecutionStatus.READY_STOP) { |
|
|
|
|
cancelTaskInstance(); |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if ( allDependentTaskFinish() || taskInstance.getState().typeIsFinished()){ |
|
|
|
|
if (allDependentTaskFinish() || taskInstance.getState().typeIsFinished()) { |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
// update process task
|
|
|
|
@ -166,7 +162,7 @@ public class DependentTaskExecThread extends MasterBaseTaskExecThread {
|
|
|
|
|
processInstance = processService.findProcessInstanceById(processInstance.getId()); |
|
|
|
|
Thread.sleep(Constants.SLEEP_TIME_MILLIS); |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
logger.error("exception",e); |
|
|
|
|
logger.error("exception", e); |
|
|
|
|
if (processInstance != null) { |
|
|
|
|
logger.error("wait task quit failed, instance id:{}, task id:{}", |
|
|
|
|
processInstance.getId(), taskInstance.getId()); |
|
|
|
@ -196,20 +192,20 @@ public class DependentTaskExecThread extends MasterBaseTaskExecThread {
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* judge all dependent tasks finish |
|
|
|
|
* |
|
|
|
|
* @return whether all dependent tasks finish |
|
|
|
|
*/ |
|
|
|
|
private boolean allDependentTaskFinish(){ |
|
|
|
|
private boolean allDependentTaskFinish() { |
|
|
|
|
boolean finish = true; |
|
|
|
|
for(DependentExecute dependentExecute : dependentTaskList){ |
|
|
|
|
for(Map.Entry<String, DependResult> entry: dependentExecute.getDependResultMap().entrySet()) { |
|
|
|
|
if(!dependResultMap.containsKey(entry.getKey())){ |
|
|
|
|
for (DependentExecute dependentExecute : dependentTaskList) { |
|
|
|
|
for (Map.Entry<String, DependResult> entry : dependentExecute.getDependResultMap().entrySet()) { |
|
|
|
|
if (!dependResultMap.containsKey(entry.getKey())) { |
|
|
|
|
dependResultMap.put(entry.getKey(), entry.getValue()); |
|
|
|
|
//save depend result to log
|
|
|
|
|
logger.info("dependent item complete {} {},{}", |
|
|
|
|
DEPENDENT_SPLIT, entry.getKey(), entry.getValue()); |
|
|
|
|
logger.info("dependent item complete {} {},{}", DEPENDENT_SPLIT, entry.getKey(), entry.getValue()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if(!dependentExecute.finish(dependentDate)){ |
|
|
|
|
if (!dependentExecute.finish(dependentDate)) { |
|
|
|
|
finish = false; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -218,17 +214,16 @@ public class DependentTaskExecThread extends MasterBaseTaskExecThread {
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* get dependent result |
|
|
|
|
* |
|
|
|
|
* @return DependResult |
|
|
|
|
*/ |
|
|
|
|
private DependResult getTaskDependResult(){ |
|
|
|
|
private DependResult getTaskDependResult() { |
|
|
|
|
List<DependResult> dependResultList = new ArrayList<>(); |
|
|
|
|
for(DependentExecute dependentExecute : dependentTaskList){ |
|
|
|
|
for (DependentExecute dependentExecute : dependentTaskList) { |
|
|
|
|
DependResult dependResult = dependentExecute.getModelDependResult(dependentDate); |
|
|
|
|
dependResultList.add(dependResult); |
|
|
|
|
} |
|
|
|
|
DependResult result = DependentUtils.getDependResultForRelation( |
|
|
|
|
this.dependentParameters.getRelation(), dependResultList |
|
|
|
|
); |
|
|
|
|
DependResult result = DependentUtils.getDependResultForRelation(this.dependentParameters.getRelation(), dependResultList); |
|
|
|
|
logger.info("dependent task completed, dependent result:{}", result); |
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
|