[agent-go] 初步完成Executor部分的代码- 1
This commit is contained in:
@@ -6,6 +6,19 @@ import (
|
||||
"github.com/streadway/amqp"
|
||||
)
|
||||
|
||||
// RabbitMQConn is a struct that holds the connection and channel objects
|
||||
type RabbitMQConn struct {
|
||||
Connection *amqp.Connection
|
||||
Channel *amqp.Channel
|
||||
}
|
||||
|
||||
type ConnectProperty struct {
|
||||
ExchangeName string
|
||||
QueueName string
|
||||
ExchangeType string
|
||||
TopicKey string
|
||||
}
|
||||
|
||||
// Send 向RabbitMQ中发送消息
|
||||
func Send(conn *RabbitMQConn, connProp *ConnectProperty, message []byte) {
|
||||
// 往哪里发
|
||||
|
||||
@@ -1,41 +0,0 @@
|
||||
package rabbitmq
|
||||
|
||||
import (
|
||||
"agent-go/g"
|
||||
"time"
|
||||
)
|
||||
|
||||
type OctopusMessage struct {
|
||||
UUID string `json:"uuid"`
|
||||
InitTime time.Time `json:"init_time" format:"2023-03-21 16:38:30"`
|
||||
Type string `json:"type"`
|
||||
Content interface{} `json:"content"`
|
||||
Result interface{} `json:"result"`
|
||||
ACTime time.Time `json:"ac_time" format:"2023-03-21 16:38:30"`
|
||||
}
|
||||
|
||||
type ExecutionMessage struct {
|
||||
NeedResultReplay bool `json:"needResultReplay"`
|
||||
DurationTask bool `json:"durationTask,default:false"`
|
||||
Type string `json:"type"`
|
||||
SingleLineCommand []string `json:"singleLineCommand"`
|
||||
MultiLineCommand [][]string `json:"multiLineCommand"`
|
||||
PipeLineCommand [][]string `json:"pipeLineCommand"`
|
||||
ResultKey string `json:"resultKey"`
|
||||
}
|
||||
|
||||
// BuildOctopusMsg 生成OctopusMessage
|
||||
func (m *OctopusMessage) BuildOctopusMsg(omType string, content interface{}) *OctopusMessage {
|
||||
|
||||
// 当前时间
|
||||
curTimeString := g.CurTimeString()
|
||||
|
||||
return &OctopusMessage{
|
||||
UUID: curTimeString,
|
||||
InitTime: time.Now(),
|
||||
Type: omType,
|
||||
Content: content,
|
||||
Result: nil,
|
||||
ACTime: time.Time{},
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,14 @@
|
||||
package rabbitmq
|
||||
|
||||
import (
|
||||
"agent-go/config"
|
||||
"agent-go/executor"
|
||||
"agent-go/g"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func HandleOMsg(initOMsgFromServer *OctopusMessage) {
|
||||
func HandleOMsg(initOMsgFromServer *config.OctopusMessage) {
|
||||
|
||||
agentTopicName := initOMsgFromServer.UUID
|
||||
OctopusExchange := g.G.NacosConfig.GetString("octopus.message.octopus_exchange")
|
||||
@@ -43,7 +44,7 @@ func HandleOMsg(initOMsgFromServer *OctopusMessage) {
|
||||
// 死循环,处理Ocotpus Message
|
||||
for delivery := range deliveries {
|
||||
|
||||
var om *OctopusMessage
|
||||
var om *config.OctopusMessage
|
||||
err := json.Unmarshal(delivery.Body, &om)
|
||||
if err != nil {
|
||||
log.Error("Octopus Message Parse Error !")
|
||||
@@ -57,7 +58,7 @@ func HandleOMsg(initOMsgFromServer *OctopusMessage) {
|
||||
|
||||
}
|
||||
|
||||
func doHandleOctopusMessage(octopusMessage *OctopusMessage) {
|
||||
func doHandleOctopusMessage(octopusMessage *config.OctopusMessage) {
|
||||
|
||||
switch octopusMessage.Type {
|
||||
case g.InitOmType:
|
||||
@@ -72,11 +73,11 @@ func doHandleOctopusMessage(octopusMessage *OctopusMessage) {
|
||||
|
||||
}
|
||||
|
||||
func executorOMHandler(octopusMessage *OctopusMessage) {
|
||||
func executorOMHandler(octopusMessage *config.OctopusMessage) {
|
||||
|
||||
executionMsgString := octopusMessage.Content.(string)
|
||||
|
||||
var executionMessage *ExecutionMessage
|
||||
var executionMessage *config.ExecutionMessage
|
||||
err := json.Unmarshal([]byte(executionMsgString), &executionMessage)
|
||||
if err != nil {
|
||||
return
|
||||
@@ -87,10 +88,10 @@ func executorOMHandler(octopusMessage *OctopusMessage) {
|
||||
|
||||
}
|
||||
|
||||
func statusOMHandler(octopusMessage *OctopusMessage) {
|
||||
func statusOMHandler(octopusMessage *config.OctopusMessage) {
|
||||
|
||||
}
|
||||
|
||||
func blackHoleOMHandler(octopusMessage *OctopusMessage) {
|
||||
func blackHoleOMHandler(octopusMessage *config.OctopusMessage) {
|
||||
log.Error(fmt.Sprintf("octopusMessage type wrong! msg is => %v", octopusMessage))
|
||||
}
|
||||
|
||||
@@ -10,19 +10,6 @@ import (
|
||||
|
||||
var log = g.G.LOG
|
||||
|
||||
// RabbitMQConn is a struct that holds the connection and channel objects
|
||||
type RabbitMQConn struct {
|
||||
Connection *amqp.Connection
|
||||
Channel *amqp.Channel
|
||||
}
|
||||
|
||||
type ConnectProperty struct {
|
||||
ExchangeName string
|
||||
QueueName string
|
||||
ExchangeType string
|
||||
TopicKey string
|
||||
}
|
||||
|
||||
// 定义全局唯一的 Singleton 实例
|
||||
var instance *amqp.Connection
|
||||
|
||||
|
||||
Reference in New Issue
Block a user