@ -14,6 +14,7 @@
* See the License for the specific language governing permissions and
* See the License for the specific language governing permissions and
* limitations under the License .
* limitations under the License .
* /
* /
package org.apache.dolphinscheduler.server.worker.runner ;
package org.apache.dolphinscheduler.server.worker.runner ;
import org.apache.dolphinscheduler.common.Constants ;
import org.apache.dolphinscheduler.common.Constants ;
@ -23,11 +24,11 @@ import org.apache.dolphinscheduler.common.enums.TaskType;
import org.apache.dolphinscheduler.common.model.TaskNode ;
import org.apache.dolphinscheduler.common.model.TaskNode ;
import org.apache.dolphinscheduler.common.process.Property ;
import org.apache.dolphinscheduler.common.process.Property ;
import org.apache.dolphinscheduler.common.task.TaskTimeoutParameter ;
import org.apache.dolphinscheduler.common.task.TaskTimeoutParameter ;
import org.apache.dolphinscheduler.common.thread.ThreadUtils ;
import org.apache.dolphinscheduler.common.utils.CommonUtils ;
import org.apache.dolphinscheduler.common.utils.CommonUtils ;
import org.apache.dolphinscheduler.common.utils.DateUtils ;
import org.apache.dolphinscheduler.common.utils.DateUtils ;
import org.apache.dolphinscheduler.common.utils.HadoopUtils ;
import org.apache.dolphinscheduler.common.utils.HadoopUtils ;
import org.apache.dolphinscheduler.common.utils.JSONUtils ;
import org.apache.dolphinscheduler.common.utils.JSONUtils ;
import org.apache.dolphinscheduler.common.utils.OSUtils ;
import org.apache.dolphinscheduler.common.utils.RetryerUtils ;
import org.apache.dolphinscheduler.common.utils.RetryerUtils ;
import org.apache.dolphinscheduler.remote.command.Command ;
import org.apache.dolphinscheduler.remote.command.Command ;
import org.apache.dolphinscheduler.remote.command.TaskExecuteAckCommand ;
import org.apache.dolphinscheduler.remote.command.TaskExecuteAckCommand ;
@ -57,7 +58,6 @@ import org.slf4j.LoggerFactory;
import com.github.rholder.retry.RetryException ;
import com.github.rholder.retry.RetryException ;
/ * *
/ * *
* task scheduler thread
* task scheduler thread
* /
* /
@ -113,6 +113,15 @@ public class TaskExecuteThread implements Runnable {
TaskExecuteResponseCommand responseCommand = new TaskExecuteResponseCommand ( taskExecutionContext . getTaskInstanceId ( ) ) ;
TaskExecuteResponseCommand responseCommand = new TaskExecuteResponseCommand ( taskExecutionContext . getTaskInstanceId ( ) ) ;
try {
try {
logger . info ( "script path : {}" , taskExecutionContext . getExecutePath ( ) ) ;
logger . info ( "script path : {}" , taskExecutionContext . getExecutePath ( ) ) ;
// check if the OS user exists
if ( ! OSUtils . getUserList ( ) . contains ( taskExecutionContext . getTenantCode ( ) ) ) {
String errorLog = String . format ( "tenantCode: %s does not exist" , taskExecutionContext . getTenantCode ( ) ) ;
taskLogger . error ( errorLog ) ;
responseCommand . setStatus ( ExecutionStatus . FAILURE . getCode ( ) ) ;
responseCommand . setEndTime ( new Date ( ) ) ;
return ;
}
// task node
// task node
TaskNode taskNode = JSONUtils . parseObject ( taskExecutionContext . getTaskJson ( ) , TaskNode . class ) ;
TaskNode taskNode = JSONUtils . parseObject ( taskExecutionContext . getTaskJson ( ) , TaskNode . class ) ;
@ -199,10 +208,10 @@ public class TaskExecuteThread implements Runnable {
// the default timeout is the maximum value of the integer
// the default timeout is the maximum value of the integer
taskExecutionContext . setTaskTimeout ( Integer . MAX_VALUE ) ;
taskExecutionContext . setTaskTimeout ( Integer . MAX_VALUE ) ;
TaskTimeoutParameter taskTimeoutParameter = taskNode . getTaskTimeoutParameter ( ) ;
TaskTimeoutParameter taskTimeoutParameter = taskNode . getTaskTimeoutParameter ( ) ;
if ( taskTimeoutParameter . getEnable ( ) ) {
if ( taskTimeoutParameter . getEnable ( ) ) {
// get timeout strategy
// get timeout strategy
taskExecutionContext . setTaskTimeoutStrategy ( taskTimeoutParameter . getStrategy ( ) . getCode ( ) ) ;
taskExecutionContext . setTaskTimeoutStrategy ( taskTimeoutParameter . getStrategy ( ) . getCode ( ) ) ;
switch ( taskTimeoutParameter . getStrategy ( ) ) {
switch ( taskTimeoutParameter . getStrategy ( ) ) {
case WARN :
case WARN :
break ;
break ;
case FAILED :
case FAILED :
@ -223,21 +232,19 @@ public class TaskExecuteThread implements Runnable {
}
}
}
}
/ * *
/ * *
* kill task
* kill task
* /
* /
public void kill ( ) {
public void kill ( ) {
if ( task ! = null ) {
if ( task ! = null ) {
try {
try {
task . cancelApplication ( true ) ;
task . cancelApplication ( true ) ;
} catch ( Exception e ) {
} catch ( Exception e ) {
logger . error ( e . getMessage ( ) , e ) ;
logger . error ( e . getMessage ( ) , e ) ;
}
}
}
}
}
}
/ * *
/ * *
* download resource file
* download resource file
*
*
@ -248,7 +255,7 @@ public class TaskExecuteThread implements Runnable {
private void downloadResource ( String execLocalPath ,
private void downloadResource ( String execLocalPath ,
Map < String , String > projectRes ,
Map < String , String > projectRes ,
Logger logger ) throws Exception {
Logger logger ) throws Exception {
if ( MapUtils . isEmpty ( projectRes ) ) {
if ( MapUtils . isEmpty ( projectRes ) ) {
return ;
return ;
}
}
@ -265,7 +272,7 @@ public class TaskExecuteThread implements Runnable {
logger . info ( "get resource file from hdfs :{}" , resHdfsPath ) ;
logger . info ( "get resource file from hdfs :{}" , resHdfsPath ) ;
HadoopUtils . getInstance ( ) . copyHdfsToLocal ( resHdfsPath , execLocalPath + File . separator + fullName , false , true ) ;
HadoopUtils . getInstance ( ) . copyHdfsToLocal ( resHdfsPath , execLocalPath + File . separator + fullName , false , true ) ;
} catch ( Exception e ) {
} catch ( Exception e ) {
logger . error ( e . getMessage ( ) , e ) ;
logger . error ( e . getMessage ( ) , e ) ;
throw new RuntimeException ( e . getMessage ( ) ) ;
throw new RuntimeException ( e . getMessage ( ) ) ;
}
}