From 61481e7543fc0e98f6e9c80621159d24082c0e8f Mon Sep 17 00:00:00 2001 From: zeaslity Date: Thu, 30 Mar 2023 16:10:34 +0800 Subject: [PATCH] [agent-go] fix-bugs --- agent-go/executor/CommandExecutor.go | 6 ++---- agent-go/rabbitmq/OMsgConnector.go | 4 +++- agent-go/register/AgentInitialization.go | 4 ++++ agent-go/tmp/executor-om-multiline.json | 8 ++++++++ agent-go/tmp/executor-om-pipeline.json | 9 +++++++++ agent-go/tmp/executor-om-single.json | 2 +- 6 files changed, 27 insertions(+), 6 deletions(-) create mode 100644 agent-go/tmp/executor-om-multiline.json create mode 100644 agent-go/tmp/executor-om-pipeline.json diff --git a/agent-go/executor/CommandExecutor.go b/agent-go/executor/CommandExecutor.go index a972fee..26f1c61 100644 --- a/agent-go/executor/CommandExecutor.go +++ b/agent-go/executor/CommandExecutor.go @@ -74,7 +74,6 @@ func PipeLineCommandExecutor(pipeLineCommand [][]string) ([]string, error) { lastCmd := cmds[len(cmds)-1] var out bytes.Buffer - lastCmd.Stdout = &out lastCmd.Stderr = &out err := lastCmd.Run() @@ -95,13 +94,12 @@ func PipeLineCommandExecutor(pipeLineCommand [][]string) ([]string, error) { func MultiLineCommandExecutor(multiLineCommandExecutor [][]string) ([]string, error) { var res []string - for _, singleLineCommand := range multiLineCommandExecutor { - singleLogs, err := SingleLineCommandExecutor(singleLineCommand) - res := append(res, singleLogs...) + res = append(res, singleLogs...) if err != nil { + log.Error(fmt.Sprintf("Execution error ! command is %v, error is %v", singleLineCommand, err)) return res, err } diff --git a/agent-go/rabbitmq/OMsgConnector.go b/agent-go/rabbitmq/OMsgConnector.go index 2be7108..5d28d25 100644 --- a/agent-go/rabbitmq/OMsgConnector.go +++ b/agent-go/rabbitmq/OMsgConnector.go @@ -65,7 +65,9 @@ func BuildOMsgRuntimeConnectorQueue(agentTopicName string) { } // 策略模式 处理消息 - om.Handle() + P.Submit(func() { + om.Handle() + }) } }) diff --git a/agent-go/register/AgentInitialization.go b/agent-go/register/AgentInitialization.go index 436537a..c762d0c 100644 --- a/agent-go/register/AgentInitialization.go +++ b/agent-go/register/AgentInitialization.go @@ -140,6 +140,10 @@ func handleInitMsgFromServer(initFromServerQueue *rabbitmq.RabbitQueue, initToSe // 不是自身的 注册回复信息 -- 拒绝 log.Warn(fmt.Sprintf("OctopusMessage INIT from server not this agent ! => %v, ==>%s", initOctopusMsg, delivery.Body)) delivery.Nack(false, true) + + // 需要休眠等待不再获取相应的信息 + time.Sleep(5 * time.Second) + } } diff --git a/agent-go/tmp/executor-om-multiline.json b/agent-go/tmp/executor-om-multiline.json new file mode 100644 index 0000000..c6b9377 --- /dev/null +++ b/agent-go/tmp/executor-om-multiline.json @@ -0,0 +1,8 @@ +{ + "uuid": "2023-03-27 14:38:49", + "init_time": "2023-03-27T14:38:49.8162801+08:00", + "type": "EXECUTOR", + "content": "{\n \"needResultReplay\": true,\n \"durationTask,default:false\": false,\n \"type\": \"pipeline\",\n \"singleLineCommand\": null,\n \"multiLineCommand\": [[\"ls\",\"-l\"],[\"pwd\"]],\n \"pipeLineCommand\": null,\n \"resultKey\": \"output\"\n}", + "result": "", + "ac_time": "0001-01-01T00:00:00Z" +} diff --git a/agent-go/tmp/executor-om-pipeline.json b/agent-go/tmp/executor-om-pipeline.json new file mode 100644 index 0000000..36044a2 --- /dev/null +++ b/agent-go/tmp/executor-om-pipeline.json @@ -0,0 +1,9 @@ +{ + "uuid": "2023-03-27 14:38:49", + "init_time": "2023-03-27T14:38:49.8162801+08:00", + "type": "EXECUTOR", + "content": "{\n \"needResultReplay\": true,\n \"durationTask,default:false\": false,\n \"type\": \"pipeline\",\n \"singleLineCommand\": null,\n \"multiLineCommand\": null,\n \"pipeLineCommand\": [[\"echo\",\"yes china\"],[\"awk\",\"'{print$2}'\"]],\n \"resultKey\": \"output\"\n}\n", + "result": "", + "ac_time": "0001-01-01T00:00:00Z" +} + diff --git a/agent-go/tmp/executor-om-single.json b/agent-go/tmp/executor-om-single.json index f48b02e..fa14caa 100644 --- a/agent-go/tmp/executor-om-single.json +++ b/agent-go/tmp/executor-om-single.json @@ -2,7 +2,7 @@ "uuid": "2023-03-27 14:38:49", "init_time": "2023-03-27T14:38:49.8162801+08:00", "type": "EXECUTOR", - "content": "{\n \"needResultReplay\": true,\n \"durationTask,default:false\": false,\n \"type\": \"command\",\n \"singleLineCommand\": [\n \"ls\",\n \"-la\"\n ],\n \"multiLineCommand\": null,\n \"pipeLineCommand\": null,\n \"resultKey\": \"output\"\n}\n", + "content": "{\n \"needResultReplay\": true,\n \"durationTask,default:false\": false,\n \"type\": \"command\",\n \"singleLineCommand\": [\n \"ls\",\n \"-l\"\n ],\n \"multiLineCommand\": null,\n \"pipeLineCommand\": null,\n \"resultKey\": \"output\"\n}\n", "result": "", "ac_time": "0001-01-01T00:00:00Z" }