diff --git a/agent-go/executor/CommandExecutor.go b/agent-go/executor/CommandExecutor.go index 26aab03..d6a5872 100644 --- a/agent-go/executor/CommandExecutor.go +++ b/agent-go/executor/CommandExecutor.go @@ -64,7 +64,7 @@ func Execute(em *ExecutionMessage) ([]string, error) { // 归一化错误和日志 if err != nil { - resultLog = append(resultLog, fmt.Sprintf("Error: %s", err.Error())) + resultLog = append(resultLog, "↓↓↓ 命令 Error 如下 ↓↓↓", err.Error()) } commandResult := fmt.Sprintf("Excution Comand are=> %v, Executor Result: %v", realCommand, resultLog) diff --git a/agent-go/executor/FunctionalExecutor.go b/agent-go/executor/FunctionalExecutor.go index 514dbf1..dc4091a 100644 --- a/agent-go/executor/FunctionalExecutor.go +++ b/agent-go/executor/FunctionalExecutor.go @@ -36,33 +36,37 @@ func AllOutputCommandExecutor(singleLineCommand []string) ([]string, error) { // result var resultSlice []string + var resultError error cmd := exec.Command(singleLineCommand[0], singleLineCommand[1:]...) stdout, err := cmd.StdoutPipe() if err != nil { log.ErrorF("command %v stdout error => %v", singleLineCommand, err) + resultError = err } stderr, err := cmd.StderrPipe() if err != nil { log.ErrorF("command %v stderr error => %v", singleLineCommand, err) + resultError = err } if err := cmd.Start(); err != nil { log.ErrorF("command %v runtime error => %v", singleLineCommand, err) } - resultSlice = append(resultSlice, "👇👇👇 命令 输出 信息如下 👇👇👇") - resultSlice = append(resultSlice, collectOutput(stdout, resultSlice)...) - resultSlice = append(resultSlice, "👇👇👇 命令 错误 信息如下 👇👇👇") - resultSlice = append(resultSlice, collectOutput(stderr, resultSlice)...) + resultSlice = append(resultSlice, "↓↓↓ 命令 输出 如下 ↓↓↓") + resultSlice = collectOutput(stdout, resultSlice) + resultSlice = append(resultSlice, "↓↓↓ 命令 错误 如下 ↓↓↓") + resultSlice = collectOutput(stderr, resultSlice) if err := cmd.Wait(); err != nil { log.ErrorF("command %v result error => %v", singleLineCommand, err) + resultError = err } log.DebugF("real time exec result are %v", resultSlice) - return resultSlice, nil + return resultSlice, resultError } func realTimeOutput(r io.Reader) { diff --git a/agent-go/rabbitmq/OctopusMessage.go b/agent-go/rabbitmq/OctopusMessage.go index 2f5cfd0..1a3e3cf 100644 --- a/agent-go/rabbitmq/OctopusMessage.go +++ b/agent-go/rabbitmq/OctopusMessage.go @@ -128,14 +128,18 @@ func executorOMHandler(octopusMessage *OctopusMessage) { // 交给后端的实际处理器处理, 再次策略 resultLog, err := executor.Execute(executionMessage) - if err != nil { + if err == nil { octopusMessage.ResultCode = "200" } else { octopusMessage.ResultCode = "300" } - // send back the result log - octopusMessage.Result = resultLog + // 消息返回逻辑 + if executionMessage.NeedResultReplay { + // send back the result log + octopusMessage.Result = resultLog + } + octopusMessage.ACTime = utils.ParseDateTimeTime() // Send diff --git a/server/src/main/java/io/wdd/rpc/scheduler/service/script/AgentApplyScheduledScript.java b/server/src/main/java/io/wdd/rpc/scheduler/service/script/AgentApplyScheduledScript.java index 0abd277..0c09356 100644 --- a/server/src/main/java/io/wdd/rpc/scheduler/service/script/AgentApplyScheduledScript.java +++ b/server/src/main/java/io/wdd/rpc/scheduler/service/script/AgentApplyScheduledScript.java @@ -1,8 +1,7 @@ package io.wdd.rpc.scheduler.service.script; -import io.wdd.rpc.execute.ExecutionMessage; -import io.wdd.rpc.message.OctopusMessage; +import io.wdd.rpc.execute.service.ExecutionService; import io.wdd.rpc.scheduler.beans.ScriptSchedulerDTO; import io.wdd.rpc.scheduler.config.QuartzSchedulerUtils; import lombok.extern.slf4j.Slf4j; @@ -22,7 +21,7 @@ import java.util.stream.Collectors; public class AgentApplyScheduledScript { @Resource - AsyncExecutionService asyncExecutionService; + ExecutionService executionService; @Resource QuartzSchedulerUtils quartzSchedulerUtils; @@ -52,27 +51,25 @@ public class AgentApplyScheduledScript { .stream() .map( targetMachine -> { - OctopusMessage octopusMessage = asyncExecutionService - .AsyncCallSendCommandToAgent( - targetMachine, - finalScriptType, - null, - null, - completeCommandList, - false, - null, - false - ); +// OctopusMessage octopusMessage = executionService +// .SendCommandToAgent( +// targetMachine, +// finalScriptType, +// null, +// null, +// completeCommandList, +// false, +// false +// ); - String resultKey = ((ExecutionMessage) octopusMessage.getContent()).getResultKey(); // 构建Map futureResultKeyMap.put( targetMachine, - resultKey + "todo 2023年8月14日" ); - return resultKey; + return "todo 2023年8月14日"; } ) .collect(Collectors.toList());