[agent][executor]- bug - 5
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package io.wdd.agent.executor.thread;
|
||||
|
||||
|
||||
import io.wdd.agent.config.utils.AgentCommonThreadPool;
|
||||
import io.wdd.common.handler.MyRuntimeException;
|
||||
import io.wdd.common.utils.TimeUtils;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -8,7 +9,6 @@ import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
@@ -38,48 +38,24 @@ public class CommandExecLogCache {
|
||||
*/
|
||||
public void cacheLog(String streamKey, Process process) {
|
||||
|
||||
log.debug(
|
||||
"开始缓存命令执行日志! process is {}",
|
||||
process.info()
|
||||
);
|
||||
ProcessHandle.Info info = process.info();
|
||||
|
||||
if (ObjectUtils.isEmpty(process.info())) {
|
||||
if (ObjectUtils.isEmpty(info)) {
|
||||
log.error("process is null ! cache log error !");
|
||||
throw new MyRuntimeException();
|
||||
}
|
||||
|
||||
ArrayList<String> commandCachedLog = new ArrayList<>(128);
|
||||
|
||||
String execCommandString = String.format(
|
||||
"execution command are => [ %s ]",
|
||||
process
|
||||
.info()
|
||||
.commandLine()
|
||||
.get()
|
||||
);
|
||||
|
||||
String execTimeString = String.format(
|
||||
"execution time is => [ %s ]",
|
||||
TimeUtils.currentTimeString()
|
||||
);
|
||||
|
||||
// add the command
|
||||
commandCachedLog.add("");
|
||||
commandCachedLog.add(execCommandString);
|
||||
commandCachedLog.add(execTimeString);
|
||||
commandCachedLog.add("--------------- command result are as below --------------------");
|
||||
commandCachedLog.add("");
|
||||
|
||||
log.debug(
|
||||
"命令执行结果头信息操作完成,内容为 {}",
|
||||
commandCachedLog
|
||||
"开始缓存命令执行日志! process is {}",
|
||||
info
|
||||
);
|
||||
|
||||
// cache the real command logs
|
||||
// 这里需要采用异步的方式执行
|
||||
AgentCommonThreadPool.pool.submit(
|
||||
() -> // cache the real command logs
|
||||
doCacheLog(
|
||||
streamKey,
|
||||
process.getInputStream(),
|
||||
commandCachedLog
|
||||
process
|
||||
)
|
||||
);
|
||||
|
||||
}
|
||||
@@ -145,15 +121,41 @@ public class CommandExecLogCache {
|
||||
* 实际执行命令缓存操作
|
||||
*
|
||||
* @param streamKey
|
||||
* @param commandLogStream
|
||||
* @param commandCachedLog
|
||||
*/
|
||||
private void doCacheLog(String streamKey, InputStream commandLogStream, ArrayList<String> commandCachedLog) {
|
||||
private void doCacheLog(String streamKey, Process process) {
|
||||
|
||||
log.debug("开始从process的结果中获取日志缓存");
|
||||
ArrayList<String> commandCachedLog = new ArrayList<>(128);
|
||||
|
||||
String execCommandString = String.format(
|
||||
"execution command are => [ %s ]",
|
||||
process
|
||||
.info()
|
||||
.commandLine()
|
||||
.get()
|
||||
);
|
||||
|
||||
String execTimeString = String.format(
|
||||
"execution time is => [ %s ]",
|
||||
TimeUtils.currentTimeString()
|
||||
);
|
||||
|
||||
// add the command
|
||||
commandCachedLog.add("");
|
||||
commandCachedLog.add(execCommandString);
|
||||
commandCachedLog.add(execTimeString);
|
||||
commandCachedLog.add("--------------- command result are as below --------------------");
|
||||
commandCachedLog.add("");
|
||||
|
||||
log.debug(
|
||||
"命令执行结果头信息操作完成,内容为 {}",
|
||||
commandCachedLog
|
||||
);
|
||||
|
||||
|
||||
log.debug("doCacheLog 开始从process的结果中获取日志缓存");
|
||||
|
||||
// read from input stream and store to the cacheArrayList
|
||||
new BufferedReader(new InputStreamReader(commandLogStream))
|
||||
new BufferedReader(new InputStreamReader(process.getInputStream()))
|
||||
.lines()
|
||||
.forEach(
|
||||
commandCachedLog::add
|
||||
|
||||
Reference in New Issue
Block a user