[ Cmii ] [ Octopus ] - reformat agent-go - 2

This commit is contained in:
zeaslity
2024-03-29 15:04:27 +08:00
parent 1d32d7dd04
commit 77c689abd7
6 changed files with 128 additions and 76 deletions

View File

@@ -1,9 +1,25 @@
package a_agent package a_agent
import "wdd.io/agent-common/logger" import (
"wdd.io/agent-common/logger"
"wdd.io/agent-go/rabbitmq"
)
var log = logger.Log var log = logger.Log
func Activate() { func Activate() {
log.Info("Module [ AGENT ] activated !") log.Info("Module [ AGENT ] activated !")
for {
if octopusMessage, ok := <-rabbitmq.BusinessRuntimeQueue.ReceiveChan.ExecutorRChan; ok {
// 处理数
// 输出日志
log.InfoF("接收到查询Agent状态的请求结果为 => %s", octopusMessage)
} else {
// channel已关闭跳出循环
log.ErrorF("business queue [ AGENT ] receive chan has closed !")
break
}
}
} }

View File

@@ -3,11 +3,14 @@ package a_executor
import ( import (
"bufio" "bufio"
"bytes" "bytes"
"encoding/json"
"fmt" "fmt"
"os/exec" "os/exec"
"strconv" "strconv"
"strings" "strings"
"wdd.io/agent-common/logger" "wdd.io/agent-common/logger"
"wdd.io/agent-common/utils"
"wdd.io/agent-go/rabbitmq"
) )
type ExecutionMessage struct { type ExecutionMessage struct {
@@ -28,35 +31,45 @@ var AgentOsOperatorCache = &AgentOsOperator{}
func Activate() { func Activate() {
log.Info("Module [ EXECUTOR ] activated !") log.Info("Module [ EXECUTOR ] activated !")
//// 转换类型 // 死循环获取channel中的数据
//executionMsgString := octopusMessage.Content.(string) for {
// if octopusMessage, ok := <-rabbitmq.BusinessRuntimeQueue.ReceiveChan.ExecutorRChan; ok {
//// 解析 ExecutionMessage // 处理数据
//var executionMessage *a_executor.ExecutionMessage // 转换类型
//err := json.Unmarshal([]byte(executionMsgString), &executionMessage) executionMsgString := octopusMessage.Content.(string)
//if err != nil {
// log.Error(fmt.Sprintf("execution message convert to json is wrong! msg is => %s", executionMsgString)) //解析 ExecutionMessage
// return var executionMessage *ExecutionMessage
//} err := json.Unmarshal([]byte(executionMsgString), &executionMessage)
// if err != nil {
//// 执行命令 log.Error(fmt.Sprintf("execution message convert to json is wrong! msg is => %s", executionMsgString))
//ok, resultLog := a_executor.Execute(executionMessage) return
//if ok { }
// octopusMessage.ResultCode = "200"
//} else { // 执行命令
// octopusMessage.ResultCode = "300" ok, resultLog := Execute(executionMessage)
//} if ok {
// octopusMessage.ResultCode = "200"
//// 返回结果 } else {
//if executionMessage.NeedResultReplay { octopusMessage.ResultCode = "300"
// // send back the result log }
// octopusMessage.Result = resultLog
//} // 返回结果
//// 返回时间 if executionMessage.NeedResultReplay {
//octopusMessage.ACTime = utils.ParseDateTimeTime() // send back the result log
// octopusMessage.Result = resultLog
//// 返回结果 }
//octopusMessage.SendToOctopusServer() // 返回时间
octopusMessage.ACTime = utils.ParseDateTimeTime()
// 返回结果
octopusMessage.SendToOctopusServer()
} else {
// channel已关闭跳出循环
log.ErrorF("business queue [ EXECUTOR ] receive chan has closed !")
break
}
}
} }
func Execute(em *ExecutionMessage) (bool, []string) { func Execute(em *ExecutionMessage) (bool, []string) {

View File

@@ -22,8 +22,6 @@ var P = g.G.P
var log = logger.Log var log = logger.Log
//var AgentServerInfoCache = &register.AgentServerInfo{}
func INIT(octopusAgentConfigFileName string, agentServerInfoConf string) chan bool { func INIT(octopusAgentConfigFileName string, agentServerInfoConf string) chan bool {
// 获取系统的环境变量 // 获取系统的环境变量
@@ -153,6 +151,9 @@ func buildAndStartBusinessRuntimeQueue(agentTopicName string) chan bool {
// 开始处理Runtime的OM消息 // 开始处理Runtime的OM消息
businessForeverChan := octopusMsgQueue.Handle() businessForeverChan := octopusMsgQueue.Handle()
// cache it
rabbitmq.BusinessRuntimeQueue = octopusMsgQueue
return businessForeverChan return businessForeverChan
} }
@@ -160,11 +161,20 @@ func buildAndStartBusinessRuntimeQueue(agentTopicName string) chan bool {
func activatedOctopusAgentModules() { func activatedOctopusAgentModules() {
// Agent // Agent
a_agent.Activate() err := P.Submit(func() {
a_agent.Activate()
})
if err != nil {
return
}
// Executor // Executor
a_executor.Activate() _ = P.Submit(func() {
a_executor.Activate()
})
// Status // Status
a_status.Activate() _ = P.Submit(func() {
a_status.Activate()
})
} }
func buildAndSendInitMsgToServer(agentServerInfo *a_agent.AgentServerInfo, initToServerQueue *rabbitmq.RabbitQueue) { func buildAndSendInitMsgToServer(agentServerInfo *a_agent.AgentServerInfo, initToServerQueue *rabbitmq.RabbitQueue) {

View File

@@ -1,10 +1,14 @@
package a_status package a_status
import ( import (
"encoding/json"
"fmt" "fmt"
"strings"
"time" "time"
"wdd.io/agent-common/logger" "wdd.io/agent-common/logger"
"wdd.io/agent-common/utils"
"wdd.io/agent-go/g" "wdd.io/agent-go/g"
"wdd.io/agent-go/rabbitmq"
) )
var log = logger.Log var log = logger.Log
@@ -41,46 +45,53 @@ type AgentInfo struct {
func Activate() { func Activate() {
log.Info("Module [ STATUS ] activated !") log.Info("Module [ STATUS ] activated !")
//v, ok := (octopusMessage.Content).(string)
//if !ok { // 死循环获取channel中的数据
// log.ErrorF("convert to string is wrong %s", v) for {
//} if octopusMessage, ok := <-rabbitmq.BusinessRuntimeQueue.ReceiveChan.ExecutorRChan; ok {
// // 处理数据
//statusMsgString := octopusMessage.Content.(string)
// statusMsgString := octopusMessage.Content.(string)
//var statusMessage *a_status.StatusMessage
//err := json.Unmarshal([]byte(statusMsgString), &statusMessage) var statusMessage *StatusMessage
//if err != nil { err := json.Unmarshal([]byte(statusMsgString), &statusMessage)
// fmt.Println(err.Error()) if err != nil {
// log.Error(fmt.Sprintf("status message convert to json is wrong! msg is => %s", octopusMessage)) fmt.Println(err.Error())
// return log.Error(fmt.Sprintf("status message convert to json is wrong! msg is => %s", octopusMessage))
//} return
// }
//// OMessageStatusTypeEnum
//var statusRes string // OMessageStatusTypeEnum
//if strings.HasPrefix(statusMessage.StatusType, "PING") { var statusRes string
// // ping info if strings.HasPrefix(statusMessage.StatusType, "PING") {
// statusRes = a_status.Ping() // ping info
//} else if strings.HasPrefix(statusMessage.StatusType, "METRIC") { statusRes = Ping()
// // metric info } else if strings.HasPrefix(statusMessage.StatusType, "METRIC") {
// agentStatusString, _ := json.Marshal(a_status.ReportAgentMetric()) // metric info
// statusRes = string(agentStatusString) agentStatusString, _ := json.Marshal(ReportAgentMetric())
//} else if strings.HasPrefix(statusMessage.StatusType, "INFO") { statusRes = string(agentStatusString)
// log.InfoF("[statusOMHandler] - call for agent info !") } else if strings.HasPrefix(statusMessage.StatusType, "INFO") {
//} else { log.InfoF("[statusOMHandler] - call for agent info !")
// log.WarnF("[statusOMHandler] - error octopus status message type of %s", statusMessage.StatusType) } else {
//} log.WarnF("[statusOMHandler] - error octopus status message type of %s", statusMessage.StatusType)
// }
//// 返回消息
//// 组装消息 // 返回消息
//octopusMessage.ACTime = utils.ParseDateTimeTime() // 组装消息
//octopusMessage.Result = statusRes octopusMessage.ACTime = utils.ParseDateTimeTime()
//// 发送回去 octopusMessage.Result = statusRes
//statusOctopusReplayMessage, _ := json.Marshal(octopusMessage) // 发送回去
//OctopusToServerQueue.Send(statusOctopusReplayMessage) octopusMessage.SendToOctopusServer()
//
//// 输出日志 // 输出日志
//log.InfoF("接收到查询Agent状态的请求结果为 => %s", statusRes) log.InfoF("接收到查询Agent状态的请求结果为 => %s", statusRes)
} else {
// channel已关闭跳出循环
log.ErrorF("business queue [ STATUS ] receive chan has closed !")
break
}
}
} }
func Ping() string { func Ping() string {

View File

@@ -9,6 +9,8 @@ import (
"wdd.io/agent-common/logger" "wdd.io/agent-common/logger"
) )
var BusinessRuntimeQueue = &RabbitQueue{}
type RabbitMQ interface { type RabbitMQ interface {
RabbitSendWriter RabbitSendWriter
RabbitConnectCloser RabbitConnectCloser

View File

@@ -42,7 +42,7 @@ public class TestImageSyncScheduler {
)); ));
ArrayList<String> ImageFullNameList = new ArrayList<>(List.of( ArrayList<String> ImageFullNameList = new ArrayList<>(List.of(
"harbor.cdcyy.com.cn/cmii/cmii-uav-industrial-portfolio:5.4.0-cqly-032802" "harbor.cdcyy.com.cn/cmii/cmii-uav-industrial-portfolio:5.4.0-cqly-032901"
)); ));
Boolean downloadAndCompressOnly = true; Boolean downloadAndCompressOnly = true;