[agent-go] 初步完成Executor部分的代码
This commit is contained in:
@@ -11,11 +11,12 @@ import (
|
||||
|
||||
var log = g.G.LOG
|
||||
var omType = g.InitOmType
|
||||
var agentServerInfo = g.G.AgentServerInfo
|
||||
|
||||
func INIT() {
|
||||
|
||||
// 获取系统的环境变量
|
||||
agentServerInfo := parseAgentServerInfo()
|
||||
g.G.AgentServerInfo = parseAgentServerInfo()
|
||||
|
||||
nacosConfig := g.G.NacosConfig
|
||||
|
||||
@@ -72,19 +73,58 @@ func INIT() {
|
||||
|
||||
// 监听初始化连接中的信息
|
||||
// 建立运行时RabbitMQ连接
|
||||
handleInitMsgFromServer()
|
||||
handleInitMsgFromServer(initFromServer, initFromServerProp, initToServer, initToServerProp)
|
||||
|
||||
}
|
||||
|
||||
func handleInitMsgFromServer() {
|
||||
// handleInitMsgFromServer 处理从Server接收的注册信息
|
||||
func handleInitMsgFromServer(initFromServer *rabbitmq.RabbitMQConn, initFromServerProp *rabbitmq.ConnectProperty, initToServer *rabbitmq.RabbitMQConn, initToServerProp *rabbitmq.ConnectProperty) {
|
||||
|
||||
deliveries := rabbitmq.Read(initFromServer, initFromServerProp, false)
|
||||
|
||||
// 同步很多抢占注册的情况
|
||||
for delivery := range deliveries {
|
||||
|
||||
var om *rabbitmq.OctopusMessage
|
||||
err := json.Unmarshal(delivery.Body, &om)
|
||||
if err != nil {
|
||||
log.Error(fmt.Sprintf("parse init message from server wroong, message is => %s ",
|
||||
string(delivery.Body)))
|
||||
}
|
||||
|
||||
// 处理OM信息
|
||||
if om.UUID == g.G.AgentServerInfo.AgentTopicName {
|
||||
// 是本机的注册回复信息
|
||||
|
||||
// 建立运行时RabbitMQ连接
|
||||
rabbitmq.HandleOMsg(om)
|
||||
|
||||
// 手动确认信息
|
||||
delivery.Ack(false)
|
||||
|
||||
// 手动关闭 注册队列的连接
|
||||
shutdownRegisterQueueConnection(initFromServer, initFromServerProp, initToServer, initToServerProp)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// 不是自身的 注册回复信息 -- 拒绝
|
||||
log.Warn(fmt.Sprintf("OctopusMessage INIT from server not this agent ! => %v", om))
|
||||
delivery.Nack(false, true)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func parseAgentServerInfo() AgentServerInfo {
|
||||
// shutdownRegisterQueueConnection 关闭初始化连接的两个队列
|
||||
func shutdownRegisterQueueConnection(initFromServer *rabbitmq.RabbitMQConn, initFromServerProp *rabbitmq.ConnectProperty, initToServer *rabbitmq.RabbitMQConn, initToServerProp *rabbitmq.ConnectProperty) {
|
||||
|
||||
}
|
||||
|
||||
func parseAgentServerInfo() *AgentServerInfo {
|
||||
|
||||
// 约定文件地址为 /etc/environment.d/octopus-agent.conf
|
||||
// 目前使用
|
||||
var agentServerInfo AgentServerInfo
|
||||
var agentServerInfo *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))
|
||||
@@ -97,7 +137,8 @@ func parseAgentServerInfo() AgentServerInfo {
|
||||
|
||||
jsonFormat, err := json.Marshal(agentServerInfo)
|
||||
if err != nil {
|
||||
return AgentServerInfo{}
|
||||
log.Error(fmt.Sprintf("agent server info convert error ! agentserverinfo is %v", agentServerInfo))
|
||||
panic(err)
|
||||
}
|
||||
log.Info(fmt.Sprintf("agent server info is %v", string(jsonFormat)))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user