[ Service ] [ Executor ] 初步重构Executor部分的代码
This commit is contained in:
@@ -4,8 +4,7 @@ import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.ApiParam;
|
||||
import io.wdd.common.response.R;
|
||||
import io.wdd.rpc.execute.service.AsyncExecutionService;
|
||||
import io.wdd.rpc.execute.service.SyncExecutionService;
|
||||
import io.wdd.rpc.execute.ExecutionService;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
@@ -14,25 +13,19 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
import javax.annotation.Nullable;
|
||||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static io.wdd.rpc.status.CommonAndStatusCache.ALL_AGENT_TOPIC_NAME_LIST;
|
||||
import static io.wdd.rpc.status.CommonAndStatusCache.ALL_HEALTHY_AGENT_TOPIC_NAME_LIST;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/octopus/server/executor")
|
||||
@Api(value = "Agent执行命令的Controller", tags = "Execution")
|
||||
public class ExecutionController {
|
||||
|
||||
@Resource
|
||||
SyncExecutionService syncExecutionService;
|
||||
@Resource
|
||||
AsyncExecutionService asyncExecutionService;
|
||||
ExecutionService executionService;
|
||||
|
||||
@PostMapping("/command/one")
|
||||
@ApiOperation("[命令] [异步]- 单台主机")
|
||||
public R<String> patchCommandToAgent(
|
||||
public R<ArrayList<String>> patchCommandToAgent(
|
||||
@RequestParam(value = "topicName") @ApiParam(name = "topicName", value = "目标主机名称") String topicName,
|
||||
@RequestParam(value = "commandList", required = false) @Nullable List<String> commandList,
|
||||
@RequestParam(value = "completeCommandList", required = false)
|
||||
@@ -41,19 +34,7 @@ public class ExecutionController {
|
||||
@ApiParam(name = "isDurationTask", value = "是否是持久化任务") @RequestParam(value = "isDurationTask", defaultValue = "false", required = false) boolean isDurationTask
|
||||
) {
|
||||
|
||||
ArrayList<String> streamKeyList = asyncExecutionService
|
||||
.AsyncSendCommandToAgentComplete(
|
||||
topicName,
|
||||
type,
|
||||
commandList,
|
||||
completeCommandList,
|
||||
false,
|
||||
null,
|
||||
isDurationTask
|
||||
);
|
||||
|
||||
|
||||
return R.ok(streamKeyList.toString());
|
||||
return R.ok(null);
|
||||
}
|
||||
|
||||
@PostMapping("/command/batch")
|
||||
@@ -68,15 +49,7 @@ public class ExecutionController {
|
||||
@RequestParam(value = "type", required = false) @Nullable String type,
|
||||
@ApiParam(name = "isDurationTask", value = "是否是持久化任务") @RequestParam(value = "isDurationTask", defaultValue = "false", required = false) boolean isDurationTask
|
||||
) {
|
||||
|
||||
List<ArrayList<String>> arrayListList = asyncExecutionService.AsyncSendCommandToAgentComplete(
|
||||
topicNameList,
|
||||
type,
|
||||
commandList,
|
||||
completeCommandList,
|
||||
isDurationTask
|
||||
);
|
||||
return R.ok(arrayListList);
|
||||
return R.ok(null);
|
||||
}
|
||||
|
||||
|
||||
@@ -91,13 +64,7 @@ public class ExecutionController {
|
||||
@ApiParam(name = "isDurationTask", value = "是否是持久化任务") @RequestParam(value = "isDurationTask", defaultValue = "false", required = false) boolean isDurationTask
|
||||
) {
|
||||
|
||||
return R.ok(asyncExecutionService.AsyncSendCommandToAgentComplete(
|
||||
ALL_AGENT_TOPIC_NAME_LIST,
|
||||
type,
|
||||
commandList,
|
||||
completeCommandList,
|
||||
isDurationTask
|
||||
));
|
||||
return R.ok(null);
|
||||
}
|
||||
|
||||
@PostMapping("/command/healthy")
|
||||
@@ -111,15 +78,26 @@ public class ExecutionController {
|
||||
@ApiParam(name = "isDurationTask", value = "是否是持久化任务") @RequestParam(value = "isDurationTask", defaultValue = "false", required = false) boolean isDurationTask
|
||||
) {
|
||||
|
||||
return R.ok(asyncExecutionService.AsyncSendCommandToAgentComplete(
|
||||
ALL_HEALTHY_AGENT_TOPIC_NAME_LIST,
|
||||
type,
|
||||
commandList,
|
||||
completeCommandList,
|
||||
isDurationTask
|
||||
));
|
||||
// List<ArrayList<String>> pathResult = syncExecutionService
|
||||
// .SyncSendCommandToAgentComplete(
|
||||
// ALL_HEALTHY_AGENT_TOPIC_NAME_LIST,
|
||||
// type,
|
||||
// null,
|
||||
// commandList,
|
||||
// completeCommandList,
|
||||
// false,
|
||||
// null,
|
||||
// isDurationTask
|
||||
// );
|
||||
//
|
||||
//
|
||||
// return R.ok(pathResult);
|
||||
return R.ok(null);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("/command/sync/one")
|
||||
@ApiOperation("[命令] [同步] - 单机-等待命令结果")
|
||||
public R<List<String>> SyncPatchCommandToAgent(
|
||||
@@ -131,19 +109,25 @@ public class ExecutionController {
|
||||
@RequestParam(value = "type", required = false) @ApiParam(name = "type", value = "执行命令类型") @Nullable String type
|
||||
) {
|
||||
|
||||
return R.ok(
|
||||
Collections.singletonList(syncExecutionService.SyncSendCommandToAgentComplete(
|
||||
ArrayList<String> resultLog = executionService
|
||||
.SendCommandToAgent(
|
||||
topicName,
|
||||
type,
|
||||
null,
|
||||
commandList,
|
||||
completeCommandList
|
||||
))
|
||||
);
|
||||
completeCommandList,
|
||||
false,
|
||||
null,
|
||||
false
|
||||
);
|
||||
|
||||
return R.ok(resultLog);
|
||||
|
||||
}
|
||||
|
||||
@PostMapping("/command/sync/batch")
|
||||
@ApiOperation("[命令] [同步] - 批量-等待命令结果")
|
||||
public R<List<String>> SyncPatchCommandToAgentBatch(
|
||||
public R<List<ArrayList<String>>> SyncPatchCommandToAgentBatch(
|
||||
@RequestParam(value = "topicNameList")
|
||||
@ApiParam(name = "topicNameList", value = "目标机器列表") List<String> topicNameList,
|
||||
@RequestParam(value = "commandList", required = false)
|
||||
@@ -154,20 +138,28 @@ public class ExecutionController {
|
||||
@ApiParam(name = "isDurationTask", value = "是否是持久化任务") @RequestParam(value = "isDurationTask", defaultValue = "false", required = false) boolean isDurationTask
|
||||
) {
|
||||
|
||||
return R.ok(
|
||||
syncExecutionService.SyncSendCommandToAgentComplete(
|
||||
topicNameList,
|
||||
type,
|
||||
commandList,
|
||||
completeCommandList,
|
||||
isDurationTask
|
||||
)
|
||||
);
|
||||
// List<ArrayList<String>> pathResult = syncExecutionService
|
||||
// .SyncSendCommandToAgentComplete(
|
||||
// topicNameList,
|
||||
// type,
|
||||
// null,
|
||||
// commandList,
|
||||
// completeCommandList,
|
||||
// false,
|
||||
// null,
|
||||
// isDurationTask
|
||||
// );
|
||||
//
|
||||
//
|
||||
// return R.ok(pathResult);
|
||||
return R.ok(null);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@PostMapping("/command/sync/all")
|
||||
@ApiOperation("[命令] [同步] - 全部-同步等待命令结果")
|
||||
public R<List<String>> SyncPatchCommandToAgentAll(
|
||||
public R<List<ArrayList<String>>> SyncPatchCommandToAgentAll(
|
||||
@RequestParam(value = "commandList", required = false)
|
||||
@ApiParam(name = "commandList", value = "命令行") @Nullable List<String> commandList,
|
||||
@RequestParam(value = "completeCommandList", required = false)
|
||||
@@ -176,20 +168,59 @@ public class ExecutionController {
|
||||
@ApiParam(name = "isDurationTask", value = "是否是持久化任务") @RequestParam(value = "isDurationTask", defaultValue = "false", required = false) boolean isDurationTask
|
||||
) {
|
||||
|
||||
return R.ok(
|
||||
syncExecutionService.SyncSendCommandToAgentComplete(
|
||||
ALL_AGENT_TOPIC_NAME_LIST,
|
||||
type,
|
||||
commandList,
|
||||
completeCommandList,
|
||||
isDurationTask
|
||||
)
|
||||
);
|
||||
// List<ArrayList<String>> pathResult = syncExecutionService
|
||||
// .SyncSendCommandToAgentComplete(
|
||||
// ALL_AGENT_TOPIC_NAME_LIST,
|
||||
// type,
|
||||
// null,
|
||||
// commandList,
|
||||
// completeCommandList,
|
||||
// false,
|
||||
// null,
|
||||
// isDurationTask
|
||||
// );
|
||||
//
|
||||
//
|
||||
// return R.ok(pathResult);
|
||||
return R.ok(null);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@PostMapping("/command/sync/healthy")
|
||||
@ApiOperation("[命令] [同步] - 健康的主机")
|
||||
public R<List<ArrayList<String>>> SyncPatchCommandToHealthyAgent(
|
||||
@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) @Nullable String type,
|
||||
@ApiParam(name = "isDurationTask", value = "是否是持久化任务") @RequestParam(value = "isDurationTask", defaultValue = "false", required = false) boolean isDurationTask
|
||||
) {
|
||||
|
||||
// List<ArrayList<String>> pathResult = syncExecutionService
|
||||
// .SyncSendCommandToAgentComplete(
|
||||
// ALL_HEALTHY_AGENT_TOPIC_NAME_LIST,
|
||||
// type,
|
||||
// null,
|
||||
// commandList,
|
||||
// completeCommandList,
|
||||
// false,
|
||||
// null,
|
||||
// isDurationTask
|
||||
// );
|
||||
//
|
||||
//
|
||||
// return R.ok(pathResult);
|
||||
return R.ok(null);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("/agentStatusStream")
|
||||
@ApiOperation("切换Console查看Agent状态日志")
|
||||
@Deprecated
|
||||
public R<String> getAgentStatusStrem(
|
||||
@RequestParam(value = "streamKey") @ApiParam(value = "status的Stream Key") String streamKey
|
||||
) {
|
||||
@@ -199,82 +230,4 @@ public class ExecutionController {
|
||||
}
|
||||
|
||||
|
||||
// auth required
|
||||
// @PostMapping("/function/update")
|
||||
// @ApiOperation("升级")
|
||||
// public R<List<String>> AgentUpdate(
|
||||
// @RequestParam(value = "topicNameList")
|
||||
// @ApiParam(name = "topicNameList", value = "目标机器列表") List<String> topicNameList
|
||||
// ) {
|
||||
//
|
||||
// return R.ok(
|
||||
// syncExecutionService
|
||||
// .SyncSendCommandToAgent(
|
||||
// topicNameList,
|
||||
// "AgentUpdate",
|
||||
// null,
|
||||
// false,
|
||||
// null,
|
||||
// true
|
||||
// ));
|
||||
// }
|
||||
//
|
||||
// @PostMapping("/function/reboot")
|
||||
// @ApiOperation("重启")
|
||||
// public R<List<String>> AgentReboot(
|
||||
// @RequestParam(value = "topicNameList")
|
||||
// @ApiParam(name = "topicNameList", value = "目标机器列表") List<String> topicNameList
|
||||
// ) {
|
||||
//
|
||||
// return R.ok(
|
||||
// asyncExecutionService
|
||||
// .SyncSendCommandToAgent(
|
||||
// topicNameList,
|
||||
// "AgentReboot",
|
||||
// null,
|
||||
// false,
|
||||
// null,
|
||||
// true
|
||||
// ));
|
||||
// }
|
||||
//
|
||||
// @PostMapping("/function/shutdown")
|
||||
// @ApiOperation("关闭")
|
||||
// public R<List<String>> AgentShutdown(
|
||||
// @RequestParam(value = "topicNameList")
|
||||
// @ApiParam(name = "topicNameList", value = "目标机器列表") List<String> topicNameList
|
||||
// ) {
|
||||
//
|
||||
// return R.ok(
|
||||
// syncExecutionService
|
||||
// .SyncSendCommandToAgent(
|
||||
// topicNameList,
|
||||
// "AgentShutdown",
|
||||
// null,
|
||||
// false,
|
||||
// null,
|
||||
// true
|
||||
// ));
|
||||
// }
|
||||
//
|
||||
// @PostMapping("/function/bootUp")
|
||||
// @ApiOperation("重新部署")
|
||||
// public R<List<String>> AgentBootUp(
|
||||
// @RequestParam(value = "topicNameList")
|
||||
// @ApiParam(name = "topicNameList", value = "目标机器列表") List<String> topicNameList
|
||||
// ) {
|
||||
//
|
||||
// return R.ok(
|
||||
// asyncExecutionService
|
||||
// .SyncSendCommandToAgent(
|
||||
// topicNameList,
|
||||
// "AgentBootUp",
|
||||
// null,
|
||||
// false,
|
||||
// null,
|
||||
// true
|
||||
// ));
|
||||
// }
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user