This is an automated email from the ASF dual-hosted git repository.
journey pushed a commit to branch refactor-architecture
in repository https://gitbox.apache.org/repos/asf/incubator-dolphinscheduler.git
The following commit(s) were added to refs/heads/refactor-architecture by this
push:
new 1e812ca add finally block to close channel (#1951)
1e812ca is described below
commit 1e812ca07884d384952573a654e47e098a2930dc
Author: Tboy <[email protected]>
AuthorDate: Thu Feb 13 21:29:11 2020 +0800
add finally block to close channel (#1951)
* move datasource classes to dao module
* fix send4LetterWord bug
* exclude jasper-compiler in case of runtime conflict
* add finally block to close channel
---
.../api/service/LoggerService.java | 27 ++++++++++++++++------
.../api/service/ProcessDefinitionServiceTest.java | 1 -
.../server/utils/ProcessUtils.java | 13 ++++++++---
.../service/log/LogClientService.java | 6 ++---
4 files changed, 33 insertions(+), 14 deletions(-)
diff --git
a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/LoggerService.java
b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/LoggerService.java
index 056af8e..bff54b6 100644
---
a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/LoggerService.java
+++
b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/LoggerService.java
@@ -64,11 +64,17 @@ public class LoggerService {
Result result = new Result(Status.SUCCESS.getCode(),
Status.SUCCESS.getMsg());
logger.info("log host : {} , logPath : {} , logServer port :
{}",host,taskInstance.getLogPath(),Constants.RPC_PORT);
-
- LogClientService logClient = new LogClientService(host,
Constants.RPC_PORT);
- String log =
logClient.rollViewLog(taskInstance.getLogPath(),skipLineNum,limit);
- result.setData(log);
- logger.info(log);
+ LogClientService logClient = null;
+ try {
+ logClient = new LogClientService(host, Constants.RPC_PORT);
+ String log =
logClient.rollViewLog(taskInstance.getLogPath(),skipLineNum,limit);
+ result.setData(log);
+ logger.info(log);
+ } finally {
+ if(logClient != null){
+ logClient.close();
+ }
+ }
return result;
}
@@ -86,7 +92,14 @@ public class LoggerService {
}
String host = taskInstance.getHost();
- LogClientService logClient = new LogClientService(host,
Constants.RPC_PORT);
- return logClient.getLogBytes(taskInstance.getLogPath());
+ LogClientService logClient = null;
+ try {
+ logClient = new LogClientService(host, Constants.RPC_PORT);
+ return logClient.getLogBytes(taskInstance.getLogPath());
+ } finally {
+ if(logClient != null){
+ logClient.close();
+ }
+ }
}
}
diff --git
a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProcessDefinitionServiceTest.java
b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProcessDefinitionServiceTest.java
index 3e9dcb0..ccbbc36 100644
---
a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProcessDefinitionServiceTest.java
+++
b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProcessDefinitionServiceTest.java
@@ -27,7 +27,6 @@ import org.apache.dolphinscheduler.common.enums.*;
import org.apache.dolphinscheduler.common.utils.DateUtils;
import org.apache.dolphinscheduler.common.utils.FileUtils;
import org.apache.dolphinscheduler.common.utils.JSONUtils;
-import org.apache.dolphinscheduler.dao.ProcessDao;
import org.apache.dolphinscheduler.dao.entity.*;
import org.apache.dolphinscheduler.dao.mapper.*;
import org.apache.dolphinscheduler.service.process.ProcessService;
diff --git
a/dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/utils/ProcessUtils.java
b/dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/utils/ProcessUtils.java
index 69284ee..90711e1 100644
---
a/dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/utils/ProcessUtils.java
+++
b/dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/utils/ProcessUtils.java
@@ -375,9 +375,16 @@ public class ProcessUtils {
public static void killYarnJob(TaskInstance taskInstance) {
try {
Thread.sleep(Constants.SLEEP_TIME_MILLIS);
- LogClientService logClient = new
LogClientService(taskInstance.getHost(), Constants.RPC_PORT);
-
- String log = logClient.viewLog(taskInstance.getLogPath());
+ LogClientService logClient = null;
+ String log = null;
+ try {
+ logClient = new LogClientService(taskInstance.getHost(),
Constants.RPC_PORT);
+ log = logClient.viewLog(taskInstance.getLogPath());
+ } finally {
+ if(logClient != null){
+ logClient.close();
+ }
+ }
if (StringUtils.isNotEmpty(log)) {
List<String> appIds = LoggerUtils.getAppIds(log, logger);
String workerDir = taskInstance.getExecutePath();
diff --git
a/dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/log/LogClientService.java
b/dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/log/LogClientService.java
index a316c70..aa6999e 100644
---
a/dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/log/LogClientService.java
+++
b/dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/log/LogClientService.java
@@ -64,11 +64,11 @@ public class LogClientService implements
NettyRequestProcessor {
}
/**
- * shutdown
+ * close
*/
- public void shutdown() {
+ public void close() {
this.client.close();
- logger.info("logger client shutdown");
+ logger.info("logger client closed");
}
/**