[ Agent ] [ Executor ] - 修改底层执行返回逻辑
This commit is contained in:
@@ -24,12 +24,12 @@ var log = logger2.Log
|
|||||||
|
|
||||||
var AgentOsOperatorCache = &AgentOsOperator{}
|
var AgentOsOperatorCache = &AgentOsOperator{}
|
||||||
|
|
||||||
func Execute(em *ExecutionMessage) ([]string, error) {
|
func Execute(em *ExecutionMessage) (bool, []string) {
|
||||||
|
|
||||||
var resultLog []string
|
var resultLog []string
|
||||||
var err error
|
var err error
|
||||||
var realCommand [][]string
|
|
||||||
ok := true
|
ok := true
|
||||||
|
executionContent := em.ExecutionType + "==" + strings.Join(em.FuncContent, "")
|
||||||
|
|
||||||
log.DebugF("em message is => %#v", em)
|
log.DebugF("em message is => %#v", em)
|
||||||
|
|
||||||
@@ -40,9 +40,6 @@ func Execute(em *ExecutionMessage) ([]string, error) {
|
|||||||
} else {
|
} else {
|
||||||
ok, resultLog = AgentOsOperatorCache.Exec(em.FuncContent[0])
|
ok, resultLog = AgentOsOperatorCache.Exec(em.FuncContent[0])
|
||||||
}
|
}
|
||||||
if ok {
|
|
||||||
return resultLog, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
} else if strings.HasPrefix(em.ExecutionType, "APP") {
|
} else if strings.HasPrefix(em.ExecutionType, "APP") {
|
||||||
// app function
|
// app function
|
||||||
@@ -51,39 +48,35 @@ func Execute(em *ExecutionMessage) ([]string, error) {
|
|||||||
} else {
|
} else {
|
||||||
ok, resultLog = AgentOsOperatorCache.Deploy(em.FuncContent[0])
|
ok, resultLog = AgentOsOperatorCache.Deploy(em.FuncContent[0])
|
||||||
}
|
}
|
||||||
if ok {
|
|
||||||
return resultLog, nil
|
|
||||||
} else {
|
|
||||||
return resultLog, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// shell command
|
// shell command
|
||||||
if em.PipeLineCommand != nil && len(em.PipeLineCommand) != 0 {
|
if em.PipeLineCommand != nil && len(em.PipeLineCommand) != 0 {
|
||||||
// 管道命令
|
// 管道命令
|
||||||
resultLog, err = PipeLineCommandExecutor(em.PipeLineCommand)
|
resultLog, err = PipeLineCommandExecutor(em.PipeLineCommand)
|
||||||
realCommand = em.PipeLineCommand
|
executionContent = fmt.Sprintf("%v", em.PipeLineCommand)
|
||||||
} else if em.MultiLineCommand != nil && len(em.MultiLineCommand) != 0 {
|
} else if em.MultiLineCommand != nil && len(em.MultiLineCommand) != 0 {
|
||||||
// 多行命令
|
// 多行命令
|
||||||
resultLog, err = MultiLineCommandExecutor(em.MultiLineCommand)
|
resultLog, err = MultiLineCommandExecutor(em.MultiLineCommand)
|
||||||
realCommand = em.MultiLineCommand
|
executionContent = fmt.Sprintf("%v", em.MultiLineCommand)
|
||||||
} else {
|
} else {
|
||||||
// 单行命令
|
// 单行命令
|
||||||
resultLog, err = FormatAllCommandExecutor(em.SingleLineCommand)
|
resultLog, err = FormatAllCommandExecutor(em.SingleLineCommand)
|
||||||
realCommand = [][]string{em.SingleLineCommand}
|
executionContent = fmt.Sprintf("%v", em.SingleLineCommand)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 归一化错误和日志
|
// 归一化错误和日志
|
||||||
if err != nil {
|
if err != nil {
|
||||||
resultLog = append(resultLog, "↓↓↓ 命令 Error 如下 ↓↓↓", err.Error())
|
resultLog = append(resultLog, " 命令执行错误如下 ", err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
resultLog = append(resultLog, fmt.Sprintf("命令 %s 执行结果为 %b", executionContent, ok))
|
||||||
// debug
|
// debug
|
||||||
commandResult := fmt.Sprintf("Excution Comand are=> %v, Executor Result: %v", realCommand, resultLog)
|
log.DebugF("%v", resultLog)
|
||||||
log.Debug(commandResult)
|
|
||||||
|
|
||||||
return resultLog, err
|
return ok, resultLog
|
||||||
}
|
}
|
||||||
|
|
||||||
func PipeLineCommandExecutor(pipeLineCommand [][]string) ([]string, error) {
|
func PipeLineCommandExecutor(pipeLineCommand [][]string) ([]string, error) {
|
||||||
|
|||||||
@@ -131,8 +131,8 @@ func executorOMHandler(octopusMessage *OctopusMessage) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 执行命令
|
// 执行命令
|
||||||
resultLog, err := executor.Execute(executionMessage)
|
ok, resultLog := executor.Execute(executionMessage)
|
||||||
if err == nil {
|
if ok {
|
||||||
octopusMessage.ResultCode = "200"
|
octopusMessage.ResultCode = "200"
|
||||||
} else {
|
} else {
|
||||||
octopusMessage.ResultCode = "300"
|
octopusMessage.ResultCode = "300"
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ public class ExecutionServiceImpl implements ExecutionService {
|
|||||||
|
|
||||||
private static final String MANUAL_COMMAND_TYPE = "manual-command";
|
private static final String MANUAL_COMMAND_TYPE = "manual-command";
|
||||||
|
|
||||||
private static final int COMMAND_MAX_WAIT_TIMEOUT = 15;
|
private static final int COMMAND_MAX_WAIT_TIMEOUT = 60;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
OMessageToAgentSender oMessageToAgentSender;
|
OMessageToAgentSender oMessageToAgentSender;
|
||||||
@@ -123,24 +123,6 @@ public class ExecutionServiceImpl implements ExecutionService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// 解析结果
|
|
||||||
if (StringUtils.isNotBlank(octopusMessage
|
|
||||||
.getResultCode()) && octopusMessage
|
|
||||||
.getResultCode()
|
|
||||||
.startsWith("200")) {
|
|
||||||
String firstLine = String.format(
|
|
||||||
"%s 执行结果为 true",
|
|
||||||
executionContent
|
|
||||||
);
|
|
||||||
if (commandResultLog == null) {
|
|
||||||
commandResultLog = new ArrayList<>();
|
|
||||||
}
|
|
||||||
commandResultLog.add(
|
|
||||||
0,
|
|
||||||
firstLine
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// debug
|
// debug
|
||||||
log.debug(
|
log.debug(
|
||||||
"执行命令 {} {} 在规定时间内结束, 结果为 {} 返回内容为 {}",
|
"执行命令 {} {} 在规定时间内结束, 结果为 {} 返回内容为 {}",
|
||||||
|
|||||||
Reference in New Issue
Block a user