From c183b3c474dfcb75aeab6dc2e2c080604f601ee4 Mon Sep 17 00:00:00 2001 From: zeaslity Date: Tue, 28 Feb 2023 21:30:00 +0800 Subject: [PATCH] =?UTF-8?q?[server][=20executor]-=20=E5=AE=8C=E6=88=90?= =?UTF-8?q?=E5=BA=95=E5=B1=82=E7=9A=84=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../executor/thread/CommandExecLogCache.java | 10 +++- .../rpc/controller/ExecutionController.java | 57 +++++++++++++++++-- .../service/AsyncExecutionService.java | 4 +- .../service/AsyncExecutionServiceImpl.java | 31 ++++++++-- .../execute/service/SyncExecutionService.java | 4 +- .../service/SyncExecutionServiceImpl.java | 22 ++++++- 6 files changed, 114 insertions(+), 14 deletions(-) diff --git a/agent/src/main/java/io/wdd/agent/executor/thread/CommandExecLogCache.java b/agent/src/main/java/io/wdd/agent/executor/thread/CommandExecLogCache.java index 0606658..dcea5fc 100644 --- a/agent/src/main/java/io/wdd/agent/executor/thread/CommandExecLogCache.java +++ b/agent/src/main/java/io/wdd/agent/executor/thread/CommandExecLogCache.java @@ -117,14 +117,20 @@ public class CommandExecLogCache { ); String execTimeString = String.format( - "execution time is => [ %s ]", + "execution date time is => [ %s ]", TimeUtils.currentTimeString() ); + String execMachineString = String.format( + "execution machine is => [ %s ]", + streamKey.split("-Execution")[0] + ); + // add the command commandCachedLog.add(execCommandString); commandCachedLog.add(execTimeString); + commandCachedLog.add(execMachineString); commandCachedLog.add("--------------- command result are as below --------------------"); commandCachedLog.add(""); @@ -248,7 +254,7 @@ public class CommandExecLogCache { addCommandExecTailInfo( commandExecWaitTimeout, streamKey, - process.exitValue() + 233 ); } diff --git a/server/src/main/java/io/wdd/rpc/controller/ExecutionController.java b/server/src/main/java/io/wdd/rpc/controller/ExecutionController.java index 9a6156f..5409272 100644 --- a/server/src/main/java/io/wdd/rpc/controller/ExecutionController.java +++ b/server/src/main/java/io/wdd/rpc/controller/ExecutionController.java @@ -14,6 +14,7 @@ import org.springframework.web.bind.annotation.RestController; import javax.annotation.Nullable; import javax.annotation.Resource; +import java.util.ArrayList; import java.util.List; import static io.wdd.rpc.execute.result.RedisStreamReaderConfig.AGENT_STATUS_REDIS_STREAM_LISTENER_CONTAINER; @@ -88,22 +89,27 @@ public class ExecutionController { public R> patchCommandToHealthyAgent( @RequestParam(value = "commandList", required = false) @ApiParam(name = "commandList", value = "命令行") @Nullable List commandList, + @RequestParam(value = "completeCommandList", required = false) + @ApiParam(name = "completeCommandList", value = "完整命令行,优先,可为空") @Nullable List> completeCommandList, @RequestParam(value = "type", required = false) @Nullable String type ) { - return R.ok(asyncExecutionService.SendCommandToAgent( + return R.ok(asyncExecutionService.SendCommandToAgentComplete( ALL_HEALTHY_AGENT_TOPIC_NAME_LIST, type, - commandList + commandList, + completeCommandList )); } @PostMapping("/command/sync/one") - @ApiOperation("[命令] [同步] - 同步等待命令结果") + @ApiOperation("[命令] [同步] - 单机-等待命令结果") public R> SyncPatchCommandToAgent( @RequestParam(value = "topicName") @ApiParam(name = "topicName", value = "目标主机名称") String topicName, @RequestParam(value = "commandList", required = false) @ApiParam(name = "commandList", value = "命令行") @Nullable List commandList, + @RequestParam(value = "completeCommandList", required = false) + @ApiParam(name = "completeCommandList", value = "完整命令行,优先,可为空") @Nullable List> completeCommandList, @RequestParam(value = "type", required = false) @ApiParam(name = "type", value = "执行命令类型") @Nullable String type ) { @@ -111,7 +117,50 @@ public class ExecutionController { syncExecutionService.SyncSendCommandToAgent( topicName, type, - commandList + commandList, + completeCommandList + ) + ); + } + + @PostMapping("/command/sync/batch") + @ApiOperation("[命令] [同步] - 批量-等待命令结果") + public R>> SyncPatchCommandToAgentBatch( + @RequestParam(value = "topicNameList") + @ApiParam(name = "topicNameList", value = "目标机器列表") List topicNameList, + @RequestParam(value = "commandList", required = false) + @ApiParam(name = "commandList", value = "命令行") @Nullable List commandList, + @RequestParam(value = "completeCommandList", required = false) + @ApiParam(name = "completeCommandList", value = "完整命令行,优先,可为空") @Nullable List> 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>> SyncPatchCommandToAgentAll( + @RequestParam(value = "commandList", required = false) + @ApiParam(name = "commandList", value = "命令行") @Nullable List commandList, + @RequestParam(value = "completeCommandList", required = false) + @ApiParam(name = "completeCommandList", value = "完整命令行,优先,可为空") @Nullable List> 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 ) ); } diff --git a/server/src/main/java/io/wdd/rpc/execute/service/AsyncExecutionService.java b/server/src/main/java/io/wdd/rpc/execute/service/AsyncExecutionService.java index f068d07..8795595 100644 --- a/server/src/main/java/io/wdd/rpc/execute/service/AsyncExecutionService.java +++ b/server/src/main/java/io/wdd/rpc/execute/service/AsyncExecutionService.java @@ -41,7 +41,9 @@ public interface AsyncExecutionService { * ------------------------------------------------- */ - String SendCommandToAgent(String agentTopicName, String type, List commandList, List> commandListComplete); + String SendCommandToAgentComplete(String agentTopicName, String type, List commandList, List> commandListComplete); + + List SendCommandToAgentComplete(List agentTopicNameList, String type, List commandList, List> commandListComplete); /** * 通常为 页面定时脚本任务调用 diff --git a/server/src/main/java/io/wdd/rpc/execute/service/AsyncExecutionServiceImpl.java b/server/src/main/java/io/wdd/rpc/execute/service/AsyncExecutionServiceImpl.java index fb70cf3..9097269 100644 --- a/server/src/main/java/io/wdd/rpc/execute/service/AsyncExecutionServiceImpl.java +++ b/server/src/main/java/io/wdd/rpc/execute/service/AsyncExecutionServiceImpl.java @@ -79,17 +79,37 @@ public class AsyncExecutionServiceImpl implements AsyncExecutionService { } @Override - public String SendCommandToAgent(String agentTopicName, String type, List commandList, List> commandListComplete) { + public String SendCommandToAgentComplete(String agentTopicName, String type, List commandList, List> commandListComplete) { return this.SendCommandToAgent( agentTopicName, type, commandList, commandListComplete, - null + false, + null, + false ); } + @Override + public List SendCommandToAgentComplete(List agentTopicNameList, String type, List commandList, List> commandListComplete) { + return agentTopicNameList + .stream() + .map( + agentTopicName -> this.SendCommandToAgent( + agentTopicName, + type, + commandList, + commandListComplete, + false, + null, + false + ) + ) + .collect(Collectors.toList()); + } + @Override public String SendCommandToAgent(String agentTopicName, String type, List commandList, List> commandListComplete, String futureKey) { @@ -265,7 +285,7 @@ public class AsyncExecutionServiceImpl implements AsyncExecutionService { return agentTopicNameList .stream() .map( - agentTopicName -> this.SendCommandToAgent( + agentTopicName -> this.SendCommandToAgentComplete( agentTopicName, type, null, @@ -287,7 +307,10 @@ public class AsyncExecutionServiceImpl implements AsyncExecutionService { type, null, completeCommandList, - atnFutureKey.get(agentTopicName) + atnFutureKey.getOrDefault( + agentTopicName, + null + ) ) ) .collect(Collectors.toList()); diff --git a/server/src/main/java/io/wdd/rpc/execute/service/SyncExecutionService.java b/server/src/main/java/io/wdd/rpc/execute/service/SyncExecutionService.java index 5bd7e39..f46d593 100644 --- a/server/src/main/java/io/wdd/rpc/execute/service/SyncExecutionService.java +++ b/server/src/main/java/io/wdd/rpc/execute/service/SyncExecutionService.java @@ -44,7 +44,9 @@ public interface SyncExecutionService { * ------------------------------------------------- */ - ArrayList SyncSendCommandToAgent(String agentTopicName, String type, List commandList, List> commandListComplete); + ArrayList SyncSendCommandToAgent(String agentTopicName, String type, List commandList, List> completeCommandList); + + List> SyncSendCommandToAgentComplete(List agentTopicNameList, String type, List commandList, List> completeCommandList); /** * 通常为 页面定时脚本任务调用 diff --git a/server/src/main/java/io/wdd/rpc/execute/service/SyncExecutionServiceImpl.java b/server/src/main/java/io/wdd/rpc/execute/service/SyncExecutionServiceImpl.java index 5949c89..22d6ed9 100644 --- a/server/src/main/java/io/wdd/rpc/execute/service/SyncExecutionServiceImpl.java +++ b/server/src/main/java/io/wdd/rpc/execute/service/SyncExecutionServiceImpl.java @@ -96,18 +96,36 @@ public class SyncExecutionServiceImpl implements SyncExecutionService { } @Override - public ArrayList SyncSendCommandToAgent(String agentTopicName, String type, List commandList, List> commandListComplete) { + public ArrayList SyncSendCommandToAgent(String agentTopicName, String type, List commandList, List> completeCommandList) { return this.SyncSendCommandToAgent( agentTopicName, type, commandList, - commandListComplete, + completeCommandList, COMMAND_EXEC_NEED_REPLAY, null, false ); } + @Override + public List> SyncSendCommandToAgentComplete(List agentTopicNameList, String type, List commandList, List> completeCommandList) { + return agentTopicNameList + .stream() + .map( + agentTopicName -> this.SyncSendCommandToAgent( + agentTopicName, + type, + commandList, + completeCommandList, + COMMAND_EXEC_NEED_REPLAY, + null, + false + ) + ) + .collect(Collectors.toList()); + } + @Override public List> SyncSendCommandToAgentComplete(List agentTopicNameList, String type, List> completeCommandList) {