未验证 提交 513eb769 编写于 作者: L luoyuan 提交者: GitHub

[Improvement-5147][Service]This judgment always returns true (#5156)

* this expression which always evaluates "true"

* delete unused variables

* LogClientService add AutoCloseable

* reformat code

* reformat code

* reformat code

* add log in ProcessService

* reformat code

* Optimize the code

* Optimize the code

* [improvement]modify all methods that refer to LogClientService in the code.

* delete unused code
上级 fe144e46
...@@ -23,7 +23,6 @@ import org.apache.dolphinscheduler.common.model.TaskNode; ...@@ -23,7 +23,6 @@ import org.apache.dolphinscheduler.common.model.TaskNode;
import org.apache.dolphinscheduler.common.task.TaskTimeoutParameter; import org.apache.dolphinscheduler.common.task.TaskTimeoutParameter;
import org.apache.dolphinscheduler.common.utils.JSONUtils; import org.apache.dolphinscheduler.common.utils.JSONUtils;
import org.apache.dolphinscheduler.dao.AlertDao; import org.apache.dolphinscheduler.dao.AlertDao;
import org.apache.dolphinscheduler.dao.entity.ProcessDefinition;
import org.apache.dolphinscheduler.dao.entity.ProcessInstance; import org.apache.dolphinscheduler.dao.entity.ProcessInstance;
import org.apache.dolphinscheduler.dao.entity.TaskInstance; import org.apache.dolphinscheduler.dao.entity.TaskInstance;
import org.apache.dolphinscheduler.server.master.config.MasterConfig; import org.apache.dolphinscheduler.server.master.config.MasterConfig;
...@@ -283,7 +282,6 @@ public class MasterBaseTaskExecThread implements Callable<Boolean> { ...@@ -283,7 +282,6 @@ public class MasterBaseTaskExecThread implements Callable<Boolean> {
logger.warn("process id:{} process name:{} task id: {},name:{} execution time out", logger.warn("process id:{} process name:{} task id: {},name:{} execution time out",
processInstance.getId(), processInstance.getName(), taskInstance.getId(), taskInstance.getName()); processInstance.getId(), processInstance.getName(), taskInstance.getId(), taskInstance.getName());
// send warn mail // send warn mail
ProcessDefinition processDefine = processService.findProcessDefineById(processInstance.getProcessDefinitionId());
alertDao.sendTaskTimeoutAlert(processInstance.getWarningGroupId(), processInstance.getId(), processInstance.getName(), alertDao.sendTaskTimeoutAlert(processInstance.getWarningGroupId(), processInstance.getId(), processInstance.getName(),
taskInstance.getId(), taskInstance.getName()); taskInstance.getId(), taskInstance.getName());
return true; return true;
......
...@@ -442,17 +442,11 @@ public class ProcessUtils { ...@@ -442,17 +442,11 @@ public class ProcessUtils {
public static List<String> killYarnJob(TaskExecutionContext taskExecutionContext) { public static List<String> killYarnJob(TaskExecutionContext taskExecutionContext) {
try { try {
Thread.sleep(Constants.SLEEP_TIME_MILLIS); Thread.sleep(Constants.SLEEP_TIME_MILLIS);
LogClientService logClient = null;
String log; String log;
try { try (LogClientService logClient = new LogClientService()) {
logClient = new LogClientService();
log = logClient.viewLog(Host.of(taskExecutionContext.getHost()).getIp(), log = logClient.viewLog(Host.of(taskExecutionContext.getHost()).getIp(),
Constants.RPC_PORT, Constants.RPC_PORT,
taskExecutionContext.getLogPath()); taskExecutionContext.getLogPath());
} finally {
if (logClient != null) {
logClient.close();
}
} }
if (StringUtils.isNotEmpty(log)) { if (StringUtils.isNotEmpty(log)) {
List<String> appIds = LoggerUtils.getAppIds(log, logger); List<String> appIds = LoggerUtils.getAppIds(log, logger);
......
...@@ -107,7 +107,6 @@ public class TaskKillProcessor implements NettyRequestProcessor { ...@@ -107,7 +107,6 @@ public class TaskKillProcessor implements NettyRequestProcessor {
/** /**
* do kill * do kill
* *
* @param killCommand
* @return kill result * @return kill result
*/ */
private Pair<Boolean, List<String>> doKill(TaskKillRequestCommand killCommand) { private Pair<Boolean, List<String>> doKill(TaskKillRequestCommand killCommand) {
...@@ -172,12 +171,10 @@ public class TaskKillProcessor implements NettyRequestProcessor { ...@@ -172,12 +171,10 @@ public class TaskKillProcessor implements NettyRequestProcessor {
* @param logPath logPath * @param logPath logPath
* @param executePath executePath * @param executePath executePath
* @param tenantCode tenantCode * @param tenantCode tenantCode
* @return Pair<Boolean, List<String>> yarn kill result * @return Pair<Boolean, List < String>> yarn kill result
*/ */
private Pair<Boolean, List<String>> killYarnJob(String host, String logPath, String executePath, String tenantCode) { private Pair<Boolean, List<String>> killYarnJob(String host, String logPath, String executePath, String tenantCode) {
LogClientService logClient = null; try (LogClientService logClient = new LogClientService();) {
try {
logClient = new LogClientService();
logger.info("view log host : {},logPath : {}", host, logPath); logger.info("view log host : {},logPath : {}", host, logPath);
String log = logClient.viewLog(host, Constants.RPC_PORT, logPath); String log = logClient.viewLog(host, Constants.RPC_PORT, logPath);
List<String> appIds = Collections.emptyList(); List<String> appIds = Collections.emptyList();
...@@ -194,10 +191,6 @@ public class TaskKillProcessor implements NettyRequestProcessor { ...@@ -194,10 +191,6 @@ public class TaskKillProcessor implements NettyRequestProcessor {
return Pair.of(true, appIds); return Pair.of(true, appIds);
} catch (Exception e) { } catch (Exception e) {
logger.error("kill yarn job error", e); logger.error("kill yarn job error", e);
} finally {
if (logClient != null) {
logClient.close();
}
} }
return Pair.of(false, Collections.emptyList()); return Pair.of(false, Collections.emptyList());
} }
......
...@@ -39,7 +39,7 @@ import org.slf4j.LoggerFactory; ...@@ -39,7 +39,7 @@ import org.slf4j.LoggerFactory;
/** /**
* log client * log client
*/ */
public class LogClientService { public class LogClientService implements AutoCloseable {
private static final Logger logger = LoggerFactory.getLogger(LogClientService.class); private static final Logger logger = LoggerFactory.getLogger(LogClientService.class);
...@@ -67,6 +67,7 @@ public class LogClientService { ...@@ -67,6 +67,7 @@ public class LogClientService {
/** /**
* close * close
*/ */
@Override
public void close() { public void close() {
this.client.close(); this.client.close();
this.isRunning = false; this.isRunning = false;
......
...@@ -384,17 +384,11 @@ public class ProcessService { ...@@ -384,17 +384,11 @@ public class ProcessService {
* @param processInstanceId processInstanceId * @param processInstanceId processInstanceId
*/ */
public void removeTaskLogFile(Integer processInstanceId) { public void removeTaskLogFile(Integer processInstanceId) {
LogClientService logClient = null;
try {
logClient = new LogClientService();
List<TaskInstance> taskInstanceList = findValidTaskListByProcessId(processInstanceId); List<TaskInstance> taskInstanceList = findValidTaskListByProcessId(processInstanceId);
if (CollectionUtils.isEmpty(taskInstanceList)) { if (CollectionUtils.isEmpty(taskInstanceList)) {
return; return;
} }
try (LogClientService logClient = new LogClientService()) {
for (TaskInstance taskInstance : taskInstanceList) { for (TaskInstance taskInstance : taskInstanceList) {
String taskLogPath = taskInstance.getLogPath(); String taskLogPath = taskInstance.getLogPath();
if (StringUtils.isEmpty(taskInstance.getHost())) { if (StringUtils.isEmpty(taskInstance.getHost())) {
...@@ -408,14 +402,9 @@ public class ProcessService { ...@@ -408,14 +402,9 @@ public class ProcessService {
// compatible old version // compatible old version
ip = taskInstance.getHost(); ip = taskInstance.getHost();
} }
// remove task log from loggerserver // remove task log from loggerserver
logClient.removeTaskLog(ip, port, taskLogPath); logClient.removeTaskLog(ip, port, taskLogPath);
} }
} finally {
if (logClient != null) {
logClient.close();
}
} }
} }
...@@ -569,7 +558,7 @@ public class ProcessService { ...@@ -569,7 +558,7 @@ public class ProcessService {
processInstance.setConnects(processDefinition.getConnects()); processInstance.setConnects(processDefinition.getConnects());
// reset global params while there are start parameters // reset global params while there are start parameters
setGlobalParamIfCommanded(processDefinition,cmdParam); setGlobalParamIfCommanded(processDefinition, cmdParam);
// curing global params // curing global params
processInstance.setGlobalParams(ParameterUtils.curingGlobalParams( processInstance.setGlobalParams(ParameterUtils.curingGlobalParams(
...@@ -1067,7 +1056,7 @@ public class ProcessService { ...@@ -1067,7 +1056,7 @@ public class ProcessService {
/** /**
* complement data needs transform parent parameter to child. * complement data needs transform parent parameter to child.
*/ */
private String getSubWorkFlowParam(ProcessInstanceMap instanceMap, ProcessInstance parentProcessInstance,Map<String,String> fatherParams) { private String getSubWorkFlowParam(ProcessInstanceMap instanceMap, ProcessInstance parentProcessInstance, Map<String, String> fatherParams) {
// set sub work process command // set sub work process command
String processMapStr = JSONUtils.toJsonString(instanceMap); String processMapStr = JSONUtils.toJsonString(instanceMap);
Map<String, String> cmdParam = JSONUtils.toMap(processMapStr); Map<String, String> cmdParam = JSONUtils.toMap(processMapStr);
...@@ -1111,13 +1100,13 @@ public class ProcessService { ...@@ -1111,13 +1100,13 @@ public class ProcessService {
Object localParams = subProcessParam.get(Constants.LOCAL_PARAMS); Object localParams = subProcessParam.get(Constants.LOCAL_PARAMS);
List<Property> allParam = JSONUtils.toList(JSONUtils.toJsonString(localParams), Property.class); List<Property> allParam = JSONUtils.toList(JSONUtils.toJsonString(localParams), Property.class);
Map<String, String> globalMap = this.getGlobalParamMap(parentProcessInstance.getGlobalParams()); Map<String, String> globalMap = this.getGlobalParamMap(parentProcessInstance.getGlobalParams());
Map<String,String> fatherParams = new HashMap<>(); Map<String, String> fatherParams = new HashMap<>();
if (CollectionUtils.isNotEmpty(allParam)) { if (CollectionUtils.isNotEmpty(allParam)) {
for (Property info : allParam) { for (Property info : allParam) {
fatherParams.put(info.getProp(), globalMap.get(info.getProp())); fatherParams.put(info.getProp(), globalMap.get(info.getProp()));
} }
} }
String processParam = getSubWorkFlowParam(instanceMap, parentProcessInstance,fatherParams); String processParam = getSubWorkFlowParam(instanceMap, parentProcessInstance, fatherParams);
return new Command( return new Command(
commandType, commandType,
...@@ -2124,8 +2113,6 @@ public class ProcessService { ...@@ -2124,8 +2113,6 @@ public class ProcessService {
/** /**
* solve the branch rename bug * solve the branch rename bug
* *
* @param processData
* @param oldJson
* @return String * @return String
*/ */
public String changeJson(ProcessData processData, String oldJson) { public String changeJson(ProcessData processData, String oldJson) {
...@@ -2180,6 +2167,7 @@ public class ProcessService { ...@@ -2180,6 +2167,7 @@ public class ProcessService {
/** /**
* add authorized resources * add authorized resources
*
* @param ownResources own resources * @param ownResources own resources
* @param userId userId * @param userId userId
*/ */
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册