From 47b50067ef26b599a7a1a47594c0c393fddcdfd0 Mon Sep 17 00:00:00 2001 From: Wenjun Ruan Date: Fri, 12 Aug 2022 09:38:48 +0800 Subject: [PATCH] Clear thread name in BaseTaskProcessor (#11422) --- .../master/runner/task/BaseTaskProcessor.java | 100 ++++++++++-------- 1 file changed, 54 insertions(+), 46 deletions(-) diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/task/BaseTaskProcessor.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/task/BaseTaskProcessor.java index 112e4916a3..7b5f7c66f7 100644 --- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/task/BaseTaskProcessor.java +++ b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/task/BaseTaskProcessor.java @@ -17,24 +17,9 @@ package org.apache.dolphinscheduler.server.master.runner.task; -import static org.apache.dolphinscheduler.common.Constants.ADDRESS; -import static org.apache.dolphinscheduler.common.Constants.DATABASE; -import static org.apache.dolphinscheduler.common.Constants.JDBC_URL; -import static org.apache.dolphinscheduler.common.Constants.OTHER; -import static org.apache.dolphinscheduler.common.Constants.PASSWORD; -import static org.apache.dolphinscheduler.common.Constants.SINGLE_SLASH; -import static org.apache.dolphinscheduler.common.Constants.USER; -import static org.apache.dolphinscheduler.plugin.task.api.TaskConstants.CLUSTER; -import static org.apache.dolphinscheduler.plugin.task.api.TaskConstants.TASK_TYPE_DATA_QUALITY; -import static org.apache.dolphinscheduler.plugin.task.api.TaskConstants.TASK_TYPE_K8S; -import static org.apache.dolphinscheduler.plugin.task.api.utils.DataQualityConstants.COMPARISON_NAME; -import static org.apache.dolphinscheduler.plugin.task.api.utils.DataQualityConstants.COMPARISON_TABLE; -import static org.apache.dolphinscheduler.plugin.task.api.utils.DataQualityConstants.COMPARISON_TYPE; -import static org.apache.dolphinscheduler.plugin.task.api.utils.DataQualityConstants.SRC_CONNECTOR_TYPE; -import static org.apache.dolphinscheduler.plugin.task.api.utils.DataQualityConstants.SRC_DATASOURCE_ID; -import static org.apache.dolphinscheduler.plugin.task.api.utils.DataQualityConstants.TARGET_CONNECTOR_TYPE; -import static org.apache.dolphinscheduler.plugin.task.api.utils.DataQualityConstants.TARGET_DATASOURCE_ID; - +import com.zaxxer.hikari.HikariDataSource; +import lombok.NonNull; +import org.apache.commons.collections.CollectionUtils; import org.apache.dolphinscheduler.common.Constants; import org.apache.dolphinscheduler.common.utils.HadoopUtils; import org.apache.dolphinscheduler.common.utils.JSONUtils; @@ -80,8 +65,8 @@ import org.apache.dolphinscheduler.service.task.TaskPluginManager; import org.apache.dolphinscheduler.spi.enums.DbType; import org.apache.dolphinscheduler.spi.enums.ResourceType; import org.apache.dolphinscheduler.spi.utils.StringUtils; - -import org.apache.commons.collections.CollectionUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.util.ArrayList; import java.util.HashMap; @@ -93,12 +78,23 @@ import java.util.Set; import java.util.stream.Collectors; import java.util.stream.Stream; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.zaxxer.hikari.HikariDataSource; - -import lombok.NonNull; +import static org.apache.dolphinscheduler.common.Constants.ADDRESS; +import static org.apache.dolphinscheduler.common.Constants.DATABASE; +import static org.apache.dolphinscheduler.common.Constants.JDBC_URL; +import static org.apache.dolphinscheduler.common.Constants.OTHER; +import static org.apache.dolphinscheduler.common.Constants.PASSWORD; +import static org.apache.dolphinscheduler.common.Constants.SINGLE_SLASH; +import static org.apache.dolphinscheduler.common.Constants.USER; +import static org.apache.dolphinscheduler.plugin.task.api.TaskConstants.CLUSTER; +import static org.apache.dolphinscheduler.plugin.task.api.TaskConstants.TASK_TYPE_DATA_QUALITY; +import static org.apache.dolphinscheduler.plugin.task.api.TaskConstants.TASK_TYPE_K8S; +import static org.apache.dolphinscheduler.plugin.task.api.utils.DataQualityConstants.COMPARISON_NAME; +import static org.apache.dolphinscheduler.plugin.task.api.utils.DataQualityConstants.COMPARISON_TABLE; +import static org.apache.dolphinscheduler.plugin.task.api.utils.DataQualityConstants.COMPARISON_TYPE; +import static org.apache.dolphinscheduler.plugin.task.api.utils.DataQualityConstants.SRC_CONNECTOR_TYPE; +import static org.apache.dolphinscheduler.plugin.task.api.utils.DataQualityConstants.SRC_DATASOURCE_ID; +import static org.apache.dolphinscheduler.plugin.task.api.utils.DataQualityConstants.TARGET_CONNECTOR_TYPE; +import static org.apache.dolphinscheduler.plugin.task.api.utils.DataQualityConstants.TARGET_DATASOURCE_ID; public abstract class BaseTaskProcessor implements ITaskProcessor { @@ -185,27 +181,39 @@ public abstract class BaseTaskProcessor implements ITaskProcessor { if (StringUtils.isNotEmpty(threadLoggerInfoName)) { Thread.currentThread().setName(threadLoggerInfoName); } - switch (taskAction) { - case STOP: - return stop(); - case PAUSE: - return pause(); - case TIMEOUT: - return timeout(); - case SUBMIT: - return submit(); - case RUN: - return run(); - case DISPATCH: - return dispatch(); - case RESUBMIT: - return resubmit(); - default: - logger.error("unknown task action: {}", taskAction); + boolean result = false; + try { + switch (taskAction) { + case STOP: + result = stop(); + break; + case PAUSE: + result = pause(); + break; + case TIMEOUT: + result = timeout(); + break; + case SUBMIT: + result = submit(); + break; + case RUN: + result = run(); + break; + case DISPATCH: + result = dispatch(); + break; + case RESUBMIT: + result = resubmit(); + break; + default: + logger.error("unknown task action: {}", taskAction); + } + return result; + } finally { + // reset thread name + Thread.currentThread().setName(threadName); + } - // reset thread name - Thread.currentThread().setName(threadName); - return false; } protected boolean resubmit() {