[AGENT][Executor] 修复机器重启的Bug

This commit is contained in:
zeaslity
2023-03-02 14:08:01 +08:00
parent c3b2ce84a3
commit 8ca593862e
6 changed files with 64 additions and 38 deletions

View File

@@ -94,16 +94,22 @@ public class OctopusAgentInitService {
} catch (Exception e) { } catch (Exception e) {
// reject the message // 拒绝信息,然后重新发送回队列
channel.basicNack(deliveryTag, false, true); channel.basicNack(
deliveryTag,
false,
true
);
// long deliveryTag, boolean requeue // long deliveryTag, boolean requeue
// channel.basicReject(deliveryTag,true); // channel.basicReject(deliveryTag,true);
log.error("Octopus Agent Initialization Error, please check ! Waiting for 5 seconds"); log.error("Octopus Agent Initialization Error, please check ! Waiting for 5 seconds");
// 这里只是便于出现死循环时查看 // 等待5秒钟让其他的主机能够找到自己的信息
TimeUnit.SECONDS.sleep(5); TimeUnit.SECONDS.sleep(5);
// 需要返回 重新获取
return;
} }
// handle init message ok // handle init message ok

View File

@@ -40,7 +40,8 @@ public class ExecutionController {
@RequestParam(value = "commandList", required = false) @Nullable List<String> commandList, @RequestParam(value = "commandList", required = false) @Nullable List<String> commandList,
@RequestParam(value = "completeCommandList", required = false) @RequestParam(value = "completeCommandList", required = false)
@ApiParam(name = "completeCommandList", value = "完整命令行,优先,可为空") @Nullable List<List<String>> completeCommandList, @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,
@ApiParam(name = "isDurationTask", value = "是否是持久化任务") @RequestParam(value = "isDurationTask", defaultValue = "false", required = false) boolean isDurationTask
) { ) {
String streamKey = asyncExecutionService String streamKey = asyncExecutionService
@@ -51,7 +52,7 @@ public class ExecutionController {
completeCommandList, completeCommandList,
false, false,
null, null,
false isDurationTask
); );
return R.ok(streamKey); return R.ok(streamKey);
@@ -66,14 +67,16 @@ public class ExecutionController {
@ApiParam(name = "commandList", value = "命令行") @Nullable List<String> commandList, @ApiParam(name = "commandList", value = "命令行") @Nullable List<String> commandList,
@RequestParam(value = "completeCommandList", required = false) @RequestParam(value = "completeCommandList", required = false)
@ApiParam(name = "completeCommandList", value = "完整命令行,优先,可为空") @Nullable List<List<String>> completeCommandList, @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,
@ApiParam(name = "isDurationTask", value = "是否是持久化任务") @RequestParam(value = "isDurationTask", defaultValue = "false", required = false) boolean isDurationTask
) { ) {
return R.ok(asyncExecutionService.SendCommandToAgentComplete( return R.ok(asyncExecutionService.SendCommandToAgentComplete(
topicNameList, topicNameList,
type, type,
commandList, commandList,
completeCommandList completeCommandList,
isDurationTask
)); ));
} }
@@ -85,14 +88,16 @@ public class ExecutionController {
@ApiParam(name = "commandList", value = "命令行") @Nullable List<String> commandList, @ApiParam(name = "commandList", value = "命令行") @Nullable List<String> commandList,
@RequestParam(value = "completeCommandList", required = false) @RequestParam(value = "completeCommandList", required = false)
@ApiParam(name = "completeCommandList", value = "完整命令行,优先,可为空") @Nullable List<List<String>> completeCommandList, @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,
@ApiParam(name = "isDurationTask", value = "是否是持久化任务") @RequestParam(value = "isDurationTask", defaultValue = "false", required = false) boolean isDurationTask
) { ) {
return R.ok(asyncExecutionService.SendCommandToAgentComplete( return R.ok(asyncExecutionService.SendCommandToAgentComplete(
ALL_AGENT_TOPIC_NAME_LIST, ALL_AGENT_TOPIC_NAME_LIST,
type, type,
commandList, commandList,
completeCommandList completeCommandList,
isDurationTask
)); ));
} }
@@ -103,14 +108,16 @@ public class ExecutionController {
@ApiParam(name = "commandList", value = "命令行") @Nullable List<String> commandList, @ApiParam(name = "commandList", value = "命令行") @Nullable List<String> commandList,
@RequestParam(value = "completeCommandList", required = false) @RequestParam(value = "completeCommandList", required = false)
@ApiParam(name = "completeCommandList", value = "完整命令行,优先,可为空") @Nullable List<List<String>> completeCommandList, @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,
@ApiParam(name = "isDurationTask", value = "是否是持久化任务") @RequestParam(value = "isDurationTask", defaultValue = "false", required = false) boolean isDurationTask
) { ) {
return R.ok(asyncExecutionService.SendCommandToAgentComplete( return R.ok(asyncExecutionService.SendCommandToAgentComplete(
ALL_HEALTHY_AGENT_TOPIC_NAME_LIST, ALL_HEALTHY_AGENT_TOPIC_NAME_LIST,
type, type,
commandList, commandList,
completeCommandList completeCommandList,
isDurationTask
)); ));
} }
@@ -144,7 +151,8 @@ public class ExecutionController {
@ApiParam(name = "commandList", value = "命令行") @Nullable List<String> commandList, @ApiParam(name = "commandList", value = "命令行") @Nullable List<String> commandList,
@RequestParam(value = "completeCommandList", required = false) @RequestParam(value = "completeCommandList", required = false)
@ApiParam(name = "completeCommandList", value = "完整命令行,优先,可为空") @Nullable List<List<String>> completeCommandList, @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,
@ApiParam(name = "isDurationTask", value = "是否是持久化任务") @RequestParam(value = "isDurationTask", defaultValue = "false", required = false) boolean isDurationTask
) { ) {
return R.ok( return R.ok(
@@ -152,7 +160,8 @@ public class ExecutionController {
topicNameList, topicNameList,
type, type,
commandList, commandList,
completeCommandList completeCommandList,
isDurationTask
) )
); );
} }
@@ -164,7 +173,8 @@ public class ExecutionController {
@ApiParam(name = "commandList", value = "命令行") @Nullable List<String> commandList, @ApiParam(name = "commandList", value = "命令行") @Nullable List<String> commandList,
@RequestParam(value = "completeCommandList", required = false) @RequestParam(value = "completeCommandList", required = false)
@ApiParam(name = "completeCommandList", value = "完整命令行,优先,可为空") @Nullable List<List<String>> completeCommandList, @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,
@ApiParam(name = "isDurationTask", value = "是否是持久化任务") @RequestParam(value = "isDurationTask", defaultValue = "false", required = false) boolean isDurationTask
) { ) {
return R.ok( return R.ok(
@@ -172,7 +182,8 @@ public class ExecutionController {
ALL_AGENT_TOPIC_NAME_LIST, ALL_AGENT_TOPIC_NAME_LIST,
type, type,
commandList, commandList,
completeCommandList completeCommandList,
isDurationTask
) )
); );
} }
@@ -207,7 +218,10 @@ public class ExecutionController {
.SendCommandToAgent( .SendCommandToAgent(
topicNameList, topicNameList,
"AgentUpdate", "AgentUpdate",
null null,
false,
null,
true
)); ));
} }
@@ -223,7 +237,10 @@ public class ExecutionController {
.SendCommandToAgent( .SendCommandToAgent(
topicNameList, topicNameList,
"AgentReboot", "AgentReboot",
null null,
false,
null,
true
)); ));
} }
@@ -239,7 +256,10 @@ public class ExecutionController {
.SendCommandToAgent( .SendCommandToAgent(
topicNameList, topicNameList,
"AgentShutdown", "AgentShutdown",
null null,
false,
null,
true
)); ));
} }
@@ -255,7 +275,10 @@ public class ExecutionController {
.SendCommandToAgent( .SendCommandToAgent(
topicNameList, topicNameList,
"AgentBootUp", "AgentBootUp",
null null,
false,
null,
true
)); ));
} }

View File

@@ -14,7 +14,7 @@ public interface AsyncExecutionService {
String SendCommandToAgent(String agentTopicName, String type, List<String> commandList); String SendCommandToAgent(String agentTopicName, String type, List<String> commandList);
List<String> SendCommandToAgent(List<String> agentTopicNameList, String type, List<String> command); List<String> SendCommandToAgent(List<String> agentTopicNameList, String type, List<String> commandList, boolean needResultReplay, String futureKey, boolean durationTask);
/** /**
* 调用 单行命令脚本的 最底层函数 * 调用 单行命令脚本的 最底层函数
@@ -43,19 +43,12 @@ public interface AsyncExecutionService {
String SendCommandToAgentComplete(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);
/** List<String> SendCommandToAgentComplete(List<String> agentTopicNameList, String type, List<String> commandList, List<List<String>> commandListComplete, boolean isDurationTask);
* 通常为 页面定时脚本任务调用
*
* @param agentTopicNameList 目标Agent的TopicName列表
* @param type 任务类型
* @param completeCommandList 完整的类型
* @return 每个Agent只返回一个 ResultKeyScript脚本的结果全部拼接到一起全部的resultKey
*/
List<String> SendCommandToAgentComplete(List<String> agentTopicNameList, String type, List<List<String>> completeCommandList); List<String> SendCommandToAgentComplete(List<String> agentTopicNameList, String type, List<List<String>> completeCommandList);
/** /**
* 通常为 页面定时脚本任务调用 * 通常为 页面定时脚本任务调用
* *

View File

@@ -93,7 +93,7 @@ public class AsyncExecutionServiceImpl implements AsyncExecutionService {
} }
@Override @Override
public List<String> SendCommandToAgentComplete(List<String> agentTopicNameList, String type, List<String> commandList, List<List<String>> commandListComplete) { public List<String> SendCommandToAgentComplete(List<String> agentTopicNameList, String type, List<String> commandList, List<List<String>> commandListComplete, boolean isDurationTask) {
return agentTopicNameList return agentTopicNameList
.stream() .stream()
.map( .map(
@@ -104,7 +104,7 @@ public class AsyncExecutionServiceImpl implements AsyncExecutionService {
commandListComplete, commandListComplete,
false, false,
null, null,
false isDurationTask
) )
) )
.collect(Collectors.toList()); .collect(Collectors.toList());
@@ -257,7 +257,7 @@ public class AsyncExecutionServiceImpl implements AsyncExecutionService {
@Override @Override
public List<String> SendCommandToAgent(List<String> agentagentTopicNameList, String type, List<String> command) { public List<String> SendCommandToAgent(List<String> agentagentTopicNameList, String type, List<String> commandList, boolean needResultReplay, String futureKey, boolean durationTask) {
return agentagentTopicNameList return agentagentTopicNameList
.stream() .stream()
@@ -267,7 +267,11 @@ public class AsyncExecutionServiceImpl implements AsyncExecutionService {
( (
agentTopicName, agentTopicName,
type, type,
command commandList,
null,
needResultReplay,
futureKey,
durationTask
) )
) )
.collect(Collectors.toList()); .collect(Collectors.toList());

View File

@@ -46,7 +46,7 @@ public interface SyncExecutionService {
ArrayList<String> SyncSendCommandToAgent(String agentTopicName, String type, List<String> commandList, List<List<String>> completeCommandList); 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); List<ArrayList<String>> SyncSendCommandToAgentComplete(List<String> agentTopicNameList, String type, List<String> commandList, List<List<String>> completeCommandList, boolean isDurationTask);
/** /**
* 通常为 页面定时脚本任务调用 * 通常为 页面定时脚本任务调用

View File

@@ -109,7 +109,7 @@ public class SyncExecutionServiceImpl implements SyncExecutionService {
} }
@Override @Override
public List<ArrayList<String>> SyncSendCommandToAgentComplete(List<String> agentTopicNameList, String type, List<String> commandList, List<List<String>> completeCommandList) { public List<ArrayList<String>> SyncSendCommandToAgentComplete(List<String> agentTopicNameList, String type, List<String> commandList, List<List<String>> completeCommandList, boolean isDurationTask) {
return agentTopicNameList return agentTopicNameList
.stream() .stream()
.map( .map(
@@ -120,7 +120,7 @@ public class SyncExecutionServiceImpl implements SyncExecutionService {
completeCommandList, completeCommandList,
COMMAND_EXEC_NEED_REPLAY, COMMAND_EXEC_NEED_REPLAY,
null, null,
false isDurationTask
) )
) )
.collect(Collectors.toList()); .collect(Collectors.toList());