@ -16,6 +16,8 @@
* /
* /
package org.apache.dolphinscheduler.server.worker.task ;
package org.apache.dolphinscheduler.server.worker.task ;
import static ch.qos.logback.classic.ClassicConstants.FINALIZE_SESSION_MARKER ;
import org.apache.dolphinscheduler.common.Constants ;
import org.apache.dolphinscheduler.common.Constants ;
import org.apache.dolphinscheduler.common.enums.CommandType ;
import org.apache.dolphinscheduler.common.enums.CommandType ;
import org.apache.dolphinscheduler.common.enums.ExecutionStatus ;
import org.apache.dolphinscheduler.common.enums.ExecutionStatus ;
@ -23,27 +25,17 @@ import org.apache.dolphinscheduler.common.enums.TaskRecordStatus;
import org.apache.dolphinscheduler.common.enums.TaskType ;
import org.apache.dolphinscheduler.common.enums.TaskType ;
import org.apache.dolphinscheduler.common.process.Property ;
import org.apache.dolphinscheduler.common.process.Property ;
import org.apache.dolphinscheduler.common.task.AbstractParameters ;
import org.apache.dolphinscheduler.common.task.AbstractParameters ;
import org.apache.dolphinscheduler.common.task.conditions.ConditionsParameters ;
import org.apache.dolphinscheduler.common.utils.TaskParametersUtils ;
import org.apache.dolphinscheduler.common.task.datax.DataxParameters ;
import org.apache.dolphinscheduler.common.task.flink.FlinkParameters ;
import org.apache.dolphinscheduler.common.task.mr.MapreduceParameters ;
import org.apache.dolphinscheduler.common.task.procedure.ProcedureParameters ;
import org.apache.dolphinscheduler.common.task.python.PythonParameters ;
import org.apache.dolphinscheduler.common.task.shell.ShellParameters ;
import org.apache.dolphinscheduler.common.task.spark.SparkParameters ;
import org.apache.dolphinscheduler.common.task.sql.SqlParameters ;
import org.apache.dolphinscheduler.common.task.sqoop.SqoopParameters ;
import org.apache.dolphinscheduler.common.utils.JSONUtils ;
import org.apache.dolphinscheduler.dao.TaskRecordDao ;
import org.apache.dolphinscheduler.dao.TaskRecordDao ;
import org.apache.dolphinscheduler.server.entity.TaskExecutionContext ;
import org.apache.dolphinscheduler.server.entity.TaskExecutionContext ;
import org.apache.dolphinscheduler.server.utils.ParamUtils ;
import org.apache.dolphinscheduler.server.utils.ParamUtils ;
import org.apache.commons.lang.StringUtils ;
import org.apache.commons.lang.StringUtils ;
import org.slf4j.Logger ;
import java.util.List ;
import java.util.List ;
import java.util.Map ;
import java.util.Map ;
import static ch.qos.logback.classic.ClassicConstants.FINALIZE_SESSION_MARKER ;
import org.slf4j.Logger ;
/ * *
/ * *
* executive task
* executive task
@ -89,6 +81,7 @@ public abstract class AbstractTask {
/ * *
/ * *
* constructor
* constructor
*
* @param taskExecutionContext taskExecutionContext
* @param taskExecutionContext taskExecutionContext
* @param logger logger
* @param logger logger
* /
* /
@ -99,6 +92,7 @@ public abstract class AbstractTask {
/ * *
/ * *
* init task
* init task
*
* @throws Exception exception
* @throws Exception exception
* /
* /
public void init ( ) throws Exception {
public void init ( ) throws Exception {
@ -106,6 +100,7 @@ public abstract class AbstractTask {
/ * *
/ * *
* task handle
* task handle
*
* @throws Exception exception
* @throws Exception exception
* /
* /
public abstract void handle ( ) throws Exception ;
public abstract void handle ( ) throws Exception ;
@ -113,6 +108,7 @@ public abstract class AbstractTask {
/ * *
/ * *
* cancel application
* cancel application
*
* @param status status
* @param status status
* @throws Exception exception
* @throws Exception exception
* /
* /
@ -122,6 +118,7 @@ public abstract class AbstractTask {
/ * *
/ * *
* log handle
* log handle
*
* @param logs log list
* @param logs log list
* /
* /
public void logHandle ( List < String > logs ) {
public void logHandle ( List < String > logs ) {
@ -136,12 +133,14 @@ public abstract class AbstractTask {
public void setVarPool ( String varPool ) {
public void setVarPool ( String varPool ) {
this . varPool = varPool ;
this . varPool = varPool ;
}
}
public String getVarPool ( ) {
public String getVarPool ( ) {
return varPool ;
return varPool ;
}
}
/ * *
/ * *
* get exit status code
* get exit status code
*
* @return exit status code
* @return exit status code
* /
* /
public int getExitStatusCode ( ) {
public int getExitStatusCode ( ) {
@ -170,12 +169,12 @@ public abstract class AbstractTask {
/ * *
/ * *
* get task parameters
* get task parameters
*
* @return AbstractParameters
* @return AbstractParameters
* /
* /
public abstract AbstractParameters getParameters ( ) ;
public abstract AbstractParameters getParameters ( ) ;
/ * *
/ * *
* result processing
* result processing
* /
* /
@ -184,7 +183,7 @@ public abstract class AbstractTask {
// task recor flat : if true , start up qianfan
// task recor flat : if true , start up qianfan
if ( TaskRecordDao . getTaskRecordFlag ( )
if ( TaskRecordDao . getTaskRecordFlag ( )
& & TaskType . typeIsNormalTask ( taskExecutionContext . getTaskType ( ) ) ) {
& & TaskType . typeIsNormalTask ( taskExecutionContext . getTaskType ( ) ) ) {
AbstractParameters params = ( AbstractParameters ) JSONUtils . parseObject ( taskExecutionContext . getTaskParams ( ) , getCurTaskParamsClas s( ) ) ;
AbstractParameters params = TaskParametersUtils . getParameters ( taskExecutionContext . getTaskType ( ) , taskExecutionContext . getTaskParam s( ) ) ;
// replace placeholder
// replace placeholder
Map < String , Property > paramsMap = ParamUtils . convert ( ParamUtils . getUserDefParamsMap ( taskExecutionContext . getDefinedParams ( ) ) ,
Map < String , Property > paramsMap = ParamUtils . convert ( ParamUtils . getUserDefParamsMap ( taskExecutionContext . getDefinedParams ( ) ) ,
@ -213,56 +212,9 @@ public abstract class AbstractTask {
}
}
/ * *
* get current task parameter class
* @return Task Params Class
* /
private Class getCurTaskParamsClass ( ) {
Class paramsClass = null ;
// get task type
TaskType taskType = TaskType . valueOf ( taskExecutionContext . getTaskType ( ) ) ;
switch ( taskType ) {
case SHELL :
paramsClass = ShellParameters . class ;
break ;
case SQL :
paramsClass = SqlParameters . class ;
break ;
case PROCEDURE :
paramsClass = ProcedureParameters . class ;
break ;
case MR :
paramsClass = MapreduceParameters . class ;
break ;
case SPARK :
paramsClass = SparkParameters . class ;
break ;
case FLINK :
paramsClass = FlinkParameters . class ;
break ;
case PYTHON :
paramsClass = PythonParameters . class ;
break ;
case DATAX :
paramsClass = DataxParameters . class ;
break ;
case SQOOP :
paramsClass = SqoopParameters . class ;
break ;
case CONDITIONS :
paramsClass = ConditionsParameters . class ;
break ;
default :
logger . error ( "not support this task type: {}" , taskType ) ;
throw new IllegalArgumentException ( "not support this task type" ) ;
}
return paramsClass ;
}
/ * *
/ * *
* get exit status according to exitCode
* get exit status according to exitCode
*
* @return exit status
* @return exit status
* /
* /
public ExecutionStatus getExitStatus ( ) {
public ExecutionStatus getExitStatus ( ) {