Browse Source

fix AbstractTask's handle method exception (#1490)

* fix AbstractTask's handle method exception

* update ut
pull/2/head
DK.Pino 5 years ago committed by bao liang
parent
commit
15d5d66d05
  1. 1
      dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/worker/task/AbstractYarnTask.java
  2. 3
      dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/worker/task/dependent/DependentTask.java
  3. 11
      dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/worker/task/http/HttpTask.java
  4. 14
      dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/worker/task/processdure/ProcedureTask.java
  5. 1
      dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/worker/task/python/PythonTask.java
  6. 1
      dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/worker/task/shell/ShellTask.java
  7. 2
      dolphinscheduler-server/src/test/java/org/apache/dolphinscheduler/server/worker/task/dependent/DependentTaskTest.java

1
dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/worker/task/AbstractYarnTask.java

@ -68,6 +68,7 @@ public abstract class AbstractYarnTask extends AbstractTask {
} catch (Exception e) { } catch (Exception e) {
logger.error("yarn process failure", e); logger.error("yarn process failure", e);
exitStatusCode = -1; exitStatusCode = -1;
throw e;
} }
} }

3
dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/worker/task/dependent/DependentTask.java

@ -99,7 +99,7 @@ public class DependentTask extends AbstractTask {
} }
@Override @Override
public void handle(){ public void handle() throws Exception {
// set the name of the current thread // set the name of the current thread
String threadLoggerInfoName = String.format(Constants.TASK_LOG_INFO_FORMAT, taskProps.getTaskAppId()); String threadLoggerInfoName = String.format(Constants.TASK_LOG_INFO_FORMAT, taskProps.getTaskAppId());
Thread.currentThread().setName(threadLoggerInfoName); Thread.currentThread().setName(threadLoggerInfoName);
@ -135,6 +135,7 @@ public class DependentTask extends AbstractTask {
}catch (Exception e){ }catch (Exception e){
logger.error(e.getMessage(),e); logger.error(e.getMessage(),e);
exitStatusCode = -1; exitStatusCode = -1;
throw e;
} }
} }

11
dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/worker/task/http/HttpTask.java

@ -113,8 +113,9 @@ public class HttpTask extends AbstractTask {
long startTime = System.currentTimeMillis(); long startTime = System.currentTimeMillis();
String statusCode = null; String statusCode = null;
String body = null; String body = null;
try(CloseableHttpClient client = createHttpClient()) {
try(CloseableHttpResponse response = sendRequest(client)) { try(CloseableHttpClient client = createHttpClient();
CloseableHttpResponse response = sendRequest(client)) {
statusCode = String.valueOf(getStatusCode(response)); statusCode = String.valueOf(getStatusCode(response));
body = getResponseBody(response); body = getResponseBody(response);
exitStatusCode = validResponse(body, statusCode); exitStatusCode = validResponse(body, statusCode);
@ -125,11 +126,7 @@ public class HttpTask extends AbstractTask {
appendMessage(e.toString()); appendMessage(e.toString());
exitStatusCode = -1; exitStatusCode = -1;
logger.error("httpUrl[" + httpParameters.getUrl() + "] connection failed:"+output, e); logger.error("httpUrl[" + httpParameters.getUrl() + "] connection failed:"+output, e);
} throw e;
} catch (Exception e) {
appendMessage(e.toString());
exitStatusCode = -1;
logger.error("httpUrl[" + httpParameters.getUrl() + "] connection failed:"+output, e);
} }
} }

14
dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/worker/task/processdure/ProcedureTask.java

@ -97,14 +97,13 @@ public class ProcedureTask extends AbstractTask {
procedureParameters.getMethod(), procedureParameters.getMethod(),
procedureParameters.getLocalParams()); procedureParameters.getLocalParams());
// determine whether there is a data source DataSource dataSource = processDao.findDataSourceById(procedureParameters.getDatasource());
if (procedureParameters.getDatasource() == 0){ if (dataSource == null){
logger.error("datasource id not exists"); logger.error("datasource not exists");
exitStatusCode = -1; exitStatusCode = -1;
return; throw new IllegalArgumentException("datasource not found");
} }
DataSource dataSource = processDao.findDataSourceById(procedureParameters.getDatasource());
logger.info("datasource name : {} , type : {} , desc : {} , user_id : {} , parameter : {}", logger.info("datasource name : {} , type : {} , desc : {} , user_id : {} , parameter : {}",
dataSource.getName(), dataSource.getName(),
dataSource.getType(), dataSource.getType(),
@ -112,11 +111,6 @@ public class ProcedureTask extends AbstractTask {
dataSource.getUserId(), dataSource.getUserId(),
dataSource.getConnectionParams()); dataSource.getConnectionParams());
if (dataSource == null){
logger.error("datasource not exists");
exitStatusCode = -1;
return;
}
Connection connection = null; Connection connection = null;
CallableStatement stmt = null; CallableStatement stmt = null;
try { try {

1
dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/worker/task/python/PythonTask.java

@ -98,6 +98,7 @@ public class PythonTask extends AbstractTask {
} catch (Exception e) { } catch (Exception e) {
logger.error("python task failure", e); logger.error("python task failure", e);
exitStatusCode = -1; exitStatusCode = -1;
throw e;
} }
} }

1
dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/worker/task/shell/ShellTask.java

@ -106,6 +106,7 @@ public class ShellTask extends AbstractTask {
} catch (Exception e) { } catch (Exception e) {
logger.error("shell task failure", e); logger.error("shell task failure", e);
exitStatusCode = -1; exitStatusCode = -1;
throw e;
} }
} }

2
dolphinscheduler-server/src/test/java/org/apache/dolphinscheduler/server/worker/task/dependent/DependentTaskTest.java

@ -29,7 +29,7 @@ public class DependentTaskTest {
@Test @Test
public void testDependInit(){ public void testDependInit() throws Exception{
TaskProps taskProps = new TaskProps(); TaskProps taskProps = new TaskProps();

Loading…
Cancel
Save