[agent-go] 初步完成Executor部分的代码- 1

This commit is contained in:
zeaslity
2023-03-24 15:46:00 +08:00
parent 1af25d3992
commit 7e2450d30a
12 changed files with 60 additions and 41 deletions

View File

@@ -1,6 +1,7 @@
package register
import (
"agent-go/config"
"agent-go/g"
"agent-go/rabbitmq"
"encoding/json"
@@ -9,14 +10,13 @@ import (
"io/ioutil"
)
var log = g.G.LOG
var omType = g.InitOmType
var agentServerInfo = g.G.AgentServerInfo
var log = g.G.LOG
func INIT() {
func INIT() *config.AgentServerInfo {
// 获取系统的环境变量
g.G.AgentServerInfo = parseAgentServerInfo()
agentServerInfo := parseAgentServerInfo()
nacosConfig := g.G.NacosConfig
@@ -37,6 +37,7 @@ func INIT() {
// 建立RabbitMQ的连接
// defer 关闭初始化连接
initToServer, err := rabbitmq.NewRabbitMQConn(
initToServerProp,
)
if err != nil {
@@ -55,7 +56,7 @@ func INIT() {
defer rabbitmq.CloseChannel(initFromServer)
// 组装OctopusMessage
var octopusMsg *rabbitmq.OctopusMessage
var octopusMsg *config.OctopusMessage
octopusMsg = octopusMsg.BuildOctopusMsg(
omType,
agentServerInfo,
@@ -75,6 +76,8 @@ func INIT() {
// 建立运行时RabbitMQ连接
handleInitMsgFromServer(initFromServer, initFromServerProp, initToServer, initToServerProp)
return agentServerInfo
}
// handleInitMsgFromServer 处理从Server接收的注册信息
@@ -85,7 +88,7 @@ func handleInitMsgFromServer(initFromServer *rabbitmq.RabbitMQConn, initFromServ
// 同步很多抢占注册的情况
for delivery := range deliveries {
var om *rabbitmq.OctopusMessage
var om *config.OctopusMessage
err := json.Unmarshal(delivery.Body, &om)
if err != nil {
log.Error(fmt.Sprintf("parse init message from server wroong, message is => %s ",
@@ -120,11 +123,11 @@ func shutdownRegisterQueueConnection(initFromServer *rabbitmq.RabbitMQConn, init
}
func parseAgentServerInfo() *AgentServerInfo {
func parseAgentServerInfo() *config.AgentServerInfo {
// 约定文件地址为 /etc/environment.d/octopus-agent.conf
// 目前使用
var agentServerInfo *AgentServerInfo
var agentServerInfo *config.AgentServerInfo
yamlFile, err := ioutil.ReadFile("C:\\Users\\wdd\\IdeaProjects\\ProjectOctopus\\agent-go\\server-env.yaml")
if err != nil {
panic(fmt.Errorf("failed to read YAML file: %v", err))