[agent][executor]- 优化command executor的代码

This commit is contained in:
zeaslity
2023-02-23 21:12:11 +08:00
parent 24033bacc1
commit 28a26f8341
13 changed files with 330 additions and 151 deletions

View File

@@ -10,40 +10,43 @@ public interface CoreExecutionService {
String SendCommandToAgent(String agentTopicName, List<String> commandList);
/**
* 调用 单行命令脚本的 最底层函数
*
* @param agentTopicName agent唯一表示名
* @param type 任务执行类型
* @param commandList 任务列表内容
* @return redis中的 result key
*/
String SendCommandToAgent(String agentTopicName, String type, List<String> commandList);
String SendCommandToAgent(String agentTopicName, String type, List<String> commandList, List<List<String>> commandListComplete);
/**
*
* 调用 完整脚本的 最底层函数
*
* @param agentTopicName
* @param type
* @param commandList
* @param commandListComplete
* @param futureKey
* @return resultKey 本次操作在Redis中记录的结果Key
*/
String SendCommandToAgent(String agentTopicName, String type, List<String> commandList, List<List<String>> commandListComplete, String futureKey);
List<String> SendCommandToAgent(List<String> agentTopicNameList, String type, List<String> command);
/**
* 通常为 页面定时脚本任务调用
* 调用 单行命令脚本的 最底层函数
*
* @param agentTopicNameList 目标Agent的TopicName列表
* @param type 任务类型
* @param agentTopicName
* @param type
* @param commandList
* @param needResultReplay
* @param futureKey
* @param durationTask
* @return
*/
String SendCommandToAgent(
String agentTopicName,
String type,
List<String> commandList,
boolean needResultReplay,
String futureKey,
boolean durationTask
);
/** ------------------------------------------------- */
String SendCommandToAgent(String agentTopicName, String type, List<String> commandList, List<List<String>> commandListComplete);
/**
* 通常为 页面定时脚本任务调用
*
* @param agentTopicNameList 目标Agent的TopicName列表
* @param type 任务类型
* @param completeCommandList 完整的类型
* @return 每个Agent只返回一个 ResultKeyScript脚本的结果全部拼接到一起全部的resultKey
*/
@@ -51,24 +54,39 @@ public interface CoreExecutionService {
/**
* 通常为 页面定时脚本任务调用
* 通常为 页面定时脚本任务调用
*
* @param agentTopicNameList 目标Agent的TopicName列表
* @param type 任务类型
* @param agentTopicNameList 目标Agent的TopicName列表
* @param type 任务类型
* @param completeCommandList 完整的类型
* @param atnFutureKey 由于脚本任务为延迟调用,故需要提前生成未来的ResultKey
* @param atnFutureKey 由于脚本任务为延迟调用,故需要提前生成未来的ResultKey
* @return 每个Agent只返回一个 ResultKeyScript脚本的结果全部拼接到一起全部的resultKey
*/
List<String> SendCommandToAgentComplete(List<String> agentTopicNameList, String type, List<List<String>> completeCommandList, HashMap<String, String> atnFutureKey);
String SendCommandToAgent(String agentTopicName, String type, List<String> commandList, List<List<String>> commandListComplete, String futureKey);
/**
* 向所有的Agent发送命令
* 调用 完整脚本的 最底层函数
*
* @param agentTopicName
* @param type
* @param commandList
* @return
* @param commandListComplete
* @param futureKey
* @param durationTask
* @return resultKey 本次操作在Redis中记录的结果Key
*/
@Deprecated
List<String> SendCommandToAgentAll(String type, List<String> commandList);
String SendCommandToAgent(
String agentTopicName,
String type,
List<String> commandList,
List<List<String>> commandListComplete,
boolean needResultReplay,
String futureKey,
boolean durationTask
);
}

View File

@@ -61,11 +61,27 @@ public class CoreExecutionServiceImpl implements CoreExecutionService {
agentTopicName,
type,
commandList,
null
false,
null,
false
);
}
@Override
public String SendCommandToAgent(String agentTopicName, String type, List<String> commandList, boolean needResultReplay, String futureKey, boolean durationTask) {
return this.SendCommandToAgent(
agentTopicName,
type,
commandList,
null,
needResultReplay,
futureKey,
durationTask
);
}
@Override
public String SendCommandToAgent(String agentTopicName, String type, List<String> commandList, List<List<String>> commandListComplete) {
@@ -81,6 +97,21 @@ public class CoreExecutionServiceImpl implements CoreExecutionService {
@Override
public String SendCommandToAgent(String agentTopicName, String type, List<String> commandList, List<List<String>> commandListComplete, String futureKey) {
return this.SendCommandToAgent(
agentTopicName,
type,
commandList,
commandListComplete,
false,
futureKey,
false
);
}
@Override
public String SendCommandToAgent(String agentTopicName, String type, List<String> commandList, List<List<String>> commandListComplete, boolean needResultReplay, String futureKey, boolean durationTask) {
// 检查agentTopicName是否存在
if (!ALL_AGENT_TOPIC_NAME_SET.contains(agentTopicName)) {
log.error(
@@ -92,7 +123,6 @@ public class CoreExecutionServiceImpl implements CoreExecutionService {
}
// 归一化type类型 不行
String resultKey = futureKey;
// 判定是否是 FutureKey
if (null == futureKey) {
@@ -105,7 +135,9 @@ public class CoreExecutionServiceImpl implements CoreExecutionService {
type,
commandList,
resultKey,
commandListComplete
commandListComplete,
needResultReplay,
durationTask
);
OctopusMessage octopusMessage = this.generateOctopusMessage(
agentTopicName,
@@ -122,6 +154,7 @@ public class CoreExecutionServiceImpl implements CoreExecutionService {
resultKey,
resultKey
);
log.debug(
"set consumer group [{}] for the stream key with => [ {} ]",
group,
@@ -132,10 +165,10 @@ public class CoreExecutionServiceImpl implements CoreExecutionService {
// createStreamReader.registerStreamReader(COMMAND_RESULT_REDIS_STREAM_LISTENER_CONTAINER, resultKey);
// construct the persistent Bean
ExecutionLog executionLog = buildPersistentLogBeanFromOctopusMessage(
/*ExecutionLog executionLog = buildPersistentLogBeanFromOctopusMessage(
octopusMessage,
executionMessage
);
);*/
// send resultKey to ExecutionResultDaemonHandler
// 当批量执行,产生大量的resultKey的时候,会出现线程爆炸,导致所有的全部失效
/*WAIT_EXECUTION_RESULT_LIST.put(
@@ -148,6 +181,7 @@ public class CoreExecutionServiceImpl implements CoreExecutionService {
octopusMessage = null;
return resultKey;
}
private OctopusMessage generateOctopusMessage(String agentTopicName, ExecutionMessage executionMessage) {
@@ -174,7 +208,7 @@ public class CoreExecutionServiceImpl implements CoreExecutionService {
ExecutionLog executionLog = new ExecutionLog();
executionLog.setAgentTopicName(octopusMessage.getUuid());
executionLog.setResultKey((String) octopusMessage.getContent());
executionLog.setCommandList(String.valueOf(executionMessage.getCommandList()));
executionLog.setCommandList(String.valueOf(executionMessage.getSingleLineCommand()));
executionLog.setType(executionMessage.getType());
executionLog.setResultKey(executionMessage.getResultKey());
return executionLog;
@@ -238,12 +272,6 @@ public class CoreExecutionServiceImpl implements CoreExecutionService {
.collect(Collectors.toList());
}
@Override
public List<String> SendCommandToAgentAll(String type, List<String> commandList) {
return null;
}
@Deprecated
private OctopusMessage generateOctopusMessage(String agentTopicName, String resultKey, String type, List<String> commandList, List<List<String>> commandListComplete) {
@@ -253,7 +281,9 @@ public class CoreExecutionServiceImpl implements CoreExecutionService {
type,
commandList,
resultKey,
commandListComplete
commandListComplete,
false,
false
);
String executionMessageString;
@@ -274,14 +304,16 @@ public class CoreExecutionServiceImpl implements CoreExecutionService {
.build();
}
private ExecutionMessage generateExecutionMessage(String type, List<String> commandList, String resultKey, List<List<String>> commandListComplete) {
private ExecutionMessage generateExecutionMessage(String type, List<String> commandList, String resultKey, List<List<String>> commandListComplete, boolean needResultReplay, boolean durationTask) {
return ExecutionMessage
.builder()
.resultKey(resultKey)
.type(type)
.commandList(commandList)
.scriptCommandList(commandListComplete)
.singleLineCommand(commandList)
.multiLineCommand(commandListComplete)
.needResultReplay(needResultReplay)
.durationTask(durationTask)
.build();
}