From 129886bd571084a6a67c0ff8f24f31bbffc2a132 Mon Sep 17 00:00:00 2001 From: zeaslity Date: Mon, 14 Aug 2023 11:11:20 +0800 Subject: [PATCH] =?UTF-8?q?[=20Agent=20]=20[=20Executor=20]=20=E4=BC=98?= =?UTF-8?q?=E5=8C=96Executor=E9=83=A8=E5=88=86=E7=9A=84=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=20-=202?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- agent-go/executor/CommandExecutor.go | 27 ++++++++++--------- agent-go/executor/FunctionalExecutor.go | 2 +- .../rpc/controller/ExecutionController.java | 2 +- .../io/wdd/server/ServerApplicationTests.java | 4 --- 4 files changed, 17 insertions(+), 18 deletions(-) diff --git a/agent-go/executor/CommandExecutor.go b/agent-go/executor/CommandExecutor.go index d6a5872..71d106d 100644 --- a/agent-go/executor/CommandExecutor.go +++ b/agent-go/executor/CommandExecutor.go @@ -79,28 +79,31 @@ func PipeLineCommandExecutor(pipeLineCommand [][]string) ([]string, error) { var output []byte var err error - for i, command := range pipeLineCommand { - - cmd := exec.Command(command[0], command[1:]...) - cmd.Stdin = bytes.NewReader(output) - - output, err = cmd.Output() - if err != nil { - return strings.Split(string(output), "\n"), err + for _, pipeCommand := range pipeLineCommand { + if len(pipeCommand) == 0 { + continue } - if i == len(pipeLineCommand)-1 { - return strings.Split(string(output), "\n"), nil + command := exec.Command(pipeCommand[0], pipeCommand[1:]...) + if len(output) > 0 { + command.Stdin = bytes.NewBuffer(output) + } + + output, err = command.Output() + if err != nil { + log.ErrorF("Pipeline Command Exec Error => %v", err.Error()) + break } } - return []string{}, nil + + return []string{string(output)}, err } func MultiLineCommandExecutor(multiLineCommandExecutor [][]string) ([]string, error) { var res []string for _, singleLineCommand := range multiLineCommandExecutor { - singleLogs, err := SingleLineCommandExecutor(singleLineCommand) + singleLogs, err := AllOutputCommandExecutor(singleLineCommand) res = append(res, singleLogs...) if err != nil { diff --git a/agent-go/executor/FunctionalExecutor.go b/agent-go/executor/FunctionalExecutor.go index dc4091a..e040a7d 100644 --- a/agent-go/executor/FunctionalExecutor.go +++ b/agent-go/executor/FunctionalExecutor.go @@ -54,7 +54,7 @@ func AllOutputCommandExecutor(singleLineCommand []string) ([]string, error) { log.ErrorF("command %v runtime error => %v", singleLineCommand, err) } - resultSlice = append(resultSlice, "↓↓↓ 命令 输出 如下 ↓↓↓") + resultSlice = append(resultSlice, fmt.Sprintf("命令为 => %v", singleLineCommand), "↓↓↓ 命令 输出 如下 ↓↓↓") resultSlice = collectOutput(stdout, resultSlice) resultSlice = append(resultSlice, "↓↓↓ 命令 错误 如下 ↓↓↓") resultSlice = collectOutput(stderr, resultSlice) 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 a600fee..d3959fe 100644 --- a/server/src/main/java/io/wdd/rpc/controller/ExecutionController.java +++ b/server/src/main/java/io/wdd/rpc/controller/ExecutionController.java @@ -116,7 +116,7 @@ public class ExecutionController { null, commandList, completeCommandList, - false, + true, false ); diff --git a/server/src/test/java/io/wdd/server/ServerApplicationTests.java b/server/src/test/java/io/wdd/server/ServerApplicationTests.java index aa7b2b0..43fa760 100644 --- a/server/src/test/java/io/wdd/server/ServerApplicationTests.java +++ b/server/src/test/java/io/wdd/server/ServerApplicationTests.java @@ -3,14 +3,10 @@ package io.wdd.server; import org.junit.jupiter.api.Test; import org.springframework.boot.test.context.SpringBootTest; -import javax.annotation.Resource; - @SpringBootTest class ServerApplicationTests { - @Resource - AsyncExecutionService asyncExecutionService; @Test void testCoreExecutionCompleteScript() {