[server][ executor]- 完成底层的代码

This commit is contained in:
zeaslity
2023-02-28 21:30:00 +08:00
parent 371fa71b50
commit c183b3c474
6 changed files with 114 additions and 14 deletions

View File

@@ -117,14 +117,20 @@ public class CommandExecLogCache {
); );
String execTimeString = String.format( String execTimeString = String.format(
"execution time is => [ %s ]", "execution date time is => [ %s ]",
TimeUtils.currentTimeString() TimeUtils.currentTimeString()
); );
String execMachineString = String.format(
"execution machine is => [ %s ]",
streamKey.split("-Execution")[0]
);
// add the command // add the command
commandCachedLog.add(execCommandString); commandCachedLog.add(execCommandString);
commandCachedLog.add(execTimeString); commandCachedLog.add(execTimeString);
commandCachedLog.add(execMachineString);
commandCachedLog.add("--------------- command result are as below --------------------"); commandCachedLog.add("--------------- command result are as below --------------------");
commandCachedLog.add(""); commandCachedLog.add("");
@@ -248,7 +254,7 @@ public class CommandExecLogCache {
addCommandExecTailInfo( addCommandExecTailInfo(
commandExecWaitTimeout, commandExecWaitTimeout,
streamKey, streamKey,
process.exitValue() 233
); );
} }

View File

@@ -14,6 +14,7 @@ import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import static io.wdd.rpc.execute.result.RedisStreamReaderConfig.AGENT_STATUS_REDIS_STREAM_LISTENER_CONTAINER; import static io.wdd.rpc.execute.result.RedisStreamReaderConfig.AGENT_STATUS_REDIS_STREAM_LISTENER_CONTAINER;
@@ -88,22 +89,27 @@ public class ExecutionController {
public R<List<String>> patchCommandToHealthyAgent( public R<List<String>> patchCommandToHealthyAgent(
@RequestParam(value = "commandList", required = false) @RequestParam(value = "commandList", required = false)
@ApiParam(name = "commandList", value = "命令行") @Nullable List<String> commandList, @ApiParam(name = "commandList", value = "命令行") @Nullable List<String> commandList,
@RequestParam(value = "completeCommandList", required = false)
@ApiParam(name = "completeCommandList", value = "完整命令行,优先,可为空") @Nullable List<List<String>> completeCommandList,
@RequestParam(value = "type", required = false) @Nullable String type @RequestParam(value = "type", required = false) @Nullable String type
) { ) {
return R.ok(asyncExecutionService.SendCommandToAgent( return R.ok(asyncExecutionService.SendCommandToAgentComplete(
ALL_HEALTHY_AGENT_TOPIC_NAME_LIST, ALL_HEALTHY_AGENT_TOPIC_NAME_LIST,
type, type,
commandList commandList,
completeCommandList
)); ));
} }
@PostMapping("/command/sync/one") @PostMapping("/command/sync/one")
@ApiOperation("[命令] [同步] - 同步等待命令结果") @ApiOperation("[命令] [同步] - 单机-等待命令结果")
public R<List<String>> SyncPatchCommandToAgent( public R<List<String>> SyncPatchCommandToAgent(
@RequestParam(value = "topicName") @ApiParam(name = "topicName", value = "目标主机名称") String topicName, @RequestParam(value = "topicName") @ApiParam(name = "topicName", value = "目标主机名称") String topicName,
@RequestParam(value = "commandList", required = false) @RequestParam(value = "commandList", required = false)
@ApiParam(name = "commandList", value = "命令行") @Nullable List<String> commandList, @ApiParam(name = "commandList", value = "命令行") @Nullable List<String> commandList,
@RequestParam(value = "completeCommandList", required = false)
@ApiParam(name = "completeCommandList", value = "完整命令行,优先,可为空") @Nullable List<List<String>> completeCommandList,
@RequestParam(value = "type", required = false) @ApiParam(name = "type", value = "执行命令类型") @Nullable String type @RequestParam(value = "type", required = false) @ApiParam(name = "type", value = "执行命令类型") @Nullable String type
) { ) {
@@ -111,7 +117,50 @@ public class ExecutionController {
syncExecutionService.SyncSendCommandToAgent( syncExecutionService.SyncSendCommandToAgent(
topicName, topicName,
type, type,
commandList commandList,
completeCommandList
)
);
}
@PostMapping("/command/sync/batch")
@ApiOperation("[命令] [同步] - 批量-等待命令结果")
public R<List<ArrayList<String>>> SyncPatchCommandToAgentBatch(
@RequestParam(value = "topicNameList")
@ApiParam(name = "topicNameList", value = "目标机器列表") List<String> topicNameList,
@RequestParam(value = "commandList", required = false)
@ApiParam(name = "commandList", value = "命令行") @Nullable List<String> commandList,
@RequestParam(value = "completeCommandList", required = false)
@ApiParam(name = "completeCommandList", value = "完整命令行,优先,可为空") @Nullable List<List<String>> completeCommandList,
@RequestParam(value = "type", required = false) @ApiParam(name = "type", value = "执行命令类型") @Nullable String type
) {
return R.ok(
syncExecutionService.SyncSendCommandToAgentComplete(
topicNameList,
type,
commandList,
completeCommandList
)
);
}
@PostMapping("/command/sync/all")
@ApiOperation("[命令] [同步] - 全部-同步等待命令结果")
public R<List<ArrayList<String>>> SyncPatchCommandToAgentAll(
@RequestParam(value = "commandList", required = false)
@ApiParam(name = "commandList", value = "命令行") @Nullable List<String> commandList,
@RequestParam(value = "completeCommandList", required = false)
@ApiParam(name = "completeCommandList", value = "完整命令行,优先,可为空") @Nullable List<List<String>> completeCommandList,
@RequestParam(value = "type", required = false) @ApiParam(name = "type", value = "执行命令类型") @Nullable String type
) {
return R.ok(
syncExecutionService.SyncSendCommandToAgentComplete(
ALL_AGENT_TOPIC_NAME_LIST,
type,
commandList,
completeCommandList
) )
); );
} }

View File

@@ -41,7 +41,9 @@ public interface AsyncExecutionService {
* ------------------------------------------------- * -------------------------------------------------
*/ */
String SendCommandToAgent(String agentTopicName, String type, List<String> commandList, List<List<String>> commandListComplete); String SendCommandToAgentComplete(String agentTopicName, String type, List<String> commandList, List<List<String>> commandListComplete);
List<String> SendCommandToAgentComplete(List<String> agentTopicNameList, String type, List<String> commandList, List<List<String>> commandListComplete);
/** /**
* 通常为 页面定时脚本任务调用 * 通常为 页面定时脚本任务调用

View File

@@ -79,17 +79,37 @@ public class AsyncExecutionServiceImpl implements AsyncExecutionService {
} }
@Override @Override
public String SendCommandToAgent(String agentTopicName, String type, List<String> commandList, List<List<String>> commandListComplete) { public String SendCommandToAgentComplete(String agentTopicName, String type, List<String> commandList, List<List<String>> commandListComplete) {
return this.SendCommandToAgent( return this.SendCommandToAgent(
agentTopicName, agentTopicName,
type, type,
commandList, commandList,
commandListComplete, commandListComplete,
null false,
null,
false
); );
} }
@Override
public List<String> SendCommandToAgentComplete(List<String> agentTopicNameList, String type, List<String> commandList, List<List<String>> commandListComplete) {
return agentTopicNameList
.stream()
.map(
agentTopicName -> this.SendCommandToAgent(
agentTopicName,
type,
commandList,
commandListComplete,
false,
null,
false
)
)
.collect(Collectors.toList());
}
@Override @Override
public String SendCommandToAgent(String agentTopicName, String type, List<String> commandList, List<List<String>> commandListComplete, String futureKey) { public String SendCommandToAgent(String agentTopicName, String type, List<String> commandList, List<List<String>> commandListComplete, String futureKey) {
@@ -265,7 +285,7 @@ public class AsyncExecutionServiceImpl implements AsyncExecutionService {
return agentTopicNameList return agentTopicNameList
.stream() .stream()
.map( .map(
agentTopicName -> this.SendCommandToAgent( agentTopicName -> this.SendCommandToAgentComplete(
agentTopicName, agentTopicName,
type, type,
null, null,
@@ -287,7 +307,10 @@ public class AsyncExecutionServiceImpl implements AsyncExecutionService {
type, type,
null, null,
completeCommandList, completeCommandList,
atnFutureKey.get(agentTopicName) atnFutureKey.getOrDefault(
agentTopicName,
null
)
) )
) )
.collect(Collectors.toList()); .collect(Collectors.toList());

View File

@@ -44,7 +44,9 @@ public interface SyncExecutionService {
* ------------------------------------------------- * -------------------------------------------------
*/ */
ArrayList<String> SyncSendCommandToAgent(String agentTopicName, String type, List<String> commandList, List<List<String>> commandListComplete); ArrayList<String> SyncSendCommandToAgent(String agentTopicName, String type, List<String> commandList, List<List<String>> completeCommandList);
List<ArrayList<String>> SyncSendCommandToAgentComplete(List<String> agentTopicNameList, String type, List<String> commandList, List<List<String>> completeCommandList);
/** /**
* 通常为 页面定时脚本任务调用 * 通常为 页面定时脚本任务调用

View File

@@ -96,18 +96,36 @@ public class SyncExecutionServiceImpl implements SyncExecutionService {
} }
@Override @Override
public ArrayList<String> SyncSendCommandToAgent(String agentTopicName, String type, List<String> commandList, List<List<String>> commandListComplete) { public ArrayList<String> SyncSendCommandToAgent(String agentTopicName, String type, List<String> commandList, List<List<String>> completeCommandList) {
return this.SyncSendCommandToAgent( return this.SyncSendCommandToAgent(
agentTopicName, agentTopicName,
type, type,
commandList, commandList,
commandListComplete, completeCommandList,
COMMAND_EXEC_NEED_REPLAY, COMMAND_EXEC_NEED_REPLAY,
null, null,
false false
); );
} }
@Override
public List<ArrayList<String>> SyncSendCommandToAgentComplete(List<String> agentTopicNameList, String type, List<String> commandList, List<List<String>> completeCommandList) {
return agentTopicNameList
.stream()
.map(
agentTopicName -> this.SyncSendCommandToAgent(
agentTopicName,
type,
commandList,
completeCommandList,
COMMAND_EXEC_NEED_REPLAY,
null,
false
)
)
.collect(Collectors.toList());
}
@Override @Override
public List<ArrayList<String>> SyncSendCommandToAgentComplete(List<String> agentTopicNameList, String type, List<List<String>> completeCommandList) { public List<ArrayList<String>> SyncSendCommandToAgentComplete(List<String> agentTopicNameList, String type, List<List<String>> completeCommandList) {