[ Cmii ] [ Octopus ] - fix a lot of bugs

This commit is contained in:
zeaslity
2024-04-08 15:19:15 +08:00
parent fcca3d5275
commit 8e2385e4ac
14 changed files with 270 additions and 75 deletions

View File

@@ -6,6 +6,7 @@ import (
"github.com/spf13/viper"
"gopkg.in/yaml.v3"
"io/ioutil"
"math/rand"
"reflect"
"strings"
"time"
@@ -66,11 +67,13 @@ func INIT(octopusAgentConfigFileName string, agentServerInfoConf string) chan bo
case initFromServerMsg := <-initFromServerQueue.ReceiveChan.InitRChan:
if handleInitMsgFromServer(initFromServerMsg, initToServerQueue, agentServerInfo) {
log.InfoF("[INIT] - agent has registered !")
// 手动关闭 注册队列的连接
shutdownRegisterQueueConnection(initFromServerQueue, initToServerQueue)
break
}
default:
log.Debug("agent init not received from server ! start to waiting !")
time.Sleep(time.Second * 10)
time.Sleep(time.Millisecond * 500)
}
}
@@ -192,7 +195,11 @@ func buildAndSendInitMsgToServer(agentServerInfo *a_agent.AgentServerInfo, initT
_ = P.Submit(
func() {
agentRegisterCount := 0
for g.G.AgentHasRegister == false && agentRegisterCount < g.AgentRegisterFailedCount {
for g.G.AgentHasRegister == false {
if agentRegisterCount > g.AgentRegisterFailedCount {
log.ErrorF("Agent Register Failed after %d times tryings !", g.AgentRegisterFailedCount)
return
}
log.InfoF("[INIT] - Send init message to server! ==> %s", octopusMsg)
@@ -263,9 +270,6 @@ func handleInitMsgFromServer(initFromServerMsg *rabbitmq.OctopusMessage, initToS
// 保存真实的AgentTopicName
a_agent.AgentServerInfoCache.TopicName = serverInfo.TopicName
// 手动关闭 注册队列的连接
//shutdownRegisterQueueConnection(initFromServerQueue, initToServerQueue)
} else {
// 不是自身的 注册回复信息 -- 拒绝 2023年6月19日 此处存在错误! 会死循环Nack 导致异常
log.WarnF("OctopusMessage INIT from server not this agent ! => %v ", &initFromServerMsg)
@@ -273,9 +277,13 @@ func handleInitMsgFromServer(initFromServerMsg *rabbitmq.OctopusMessage, initToS
// 需要休眠等待不再获取相应的信息
_ = P.Submit(func() {
time.Sleep(time.Second * 5)
// 生成一个1到5之间的随机整数
seconds := rand.Intn(5) + 1
initToServerQueue.SendOMsg(initFromServerMsg)
// 谦让型 多并发模型 等待其他Agent注册成功
time.Sleep(time.Duration(seconds) * time.Second)
})
}
@@ -286,10 +294,10 @@ func handleInitMsgFromServer(initFromServerMsg *rabbitmq.OctopusMessage, initToS
// shutdownRegisterQueueConnection 关闭初始化连接的两个队列
func shutdownRegisterQueueConnection(initFromServerQueue *rabbitmq.RabbitQueue, initToServerQueue *rabbitmq.RabbitQueue) {
initFromServerQueue.Close()
initToServerQueue.Close()
_ = initFromServerQueue.Close()
_ = initToServerQueue.Close()
log.InfoF("Pretend to Shutdown register queue connection !")
log.InfoF("Octopus Agent Init Queue has disconnected!")
}
func parseAgentServerInfo(agentServerInfoConf string) *a_agent.AgentServerInfo {