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

This commit is contained in:
zeaslity
2024-03-29 15:35:10 +08:00
parent 77c689abd7
commit a564b4629f
3 changed files with 14 additions and 18 deletions

View File

@@ -28,20 +28,20 @@ func INIT(octopusAgentConfigFileName string, agentServerInfoConf string) chan bo
agentServerInfo := parseAgentServerInfo(agentServerInfoConf) agentServerInfo := parseAgentServerInfo(agentServerInfoConf)
// todo totally get from a_status module // todo totally get from a_status module
// 初始化Nacos的连接配置
agentConfig := parseOctopusAgentConf(octopusAgentConfigFileName)
a_agent.AgentConfig = agentConfig
// re-get agentInfo from status module // re-get agentInfo from status module
agentInfo := a_status.ReportAgentInfo() agentInfo := a_status.ReportAgentInfo()
refreshAgentInfoByStatusInfo(agentInfo, agentServerInfo) refreshAgentInfoByStatusInfo(agentInfo, agentServerInfo)
// build operator cache // build operator cache
BuildAgentOsOperator(agentInfo, agentServerInfo) buildAgentOsOperator(agentInfo, agentServerInfo)
// 缓存此内容 // 缓存此内容
a_agent.AgentServerInfoCache = agentServerInfo a_agent.AgentServerInfoCache = agentServerInfo
// 初始化Nacos的连接配置
agentConfig := ParseConfiguration(octopusAgentConfigFileName)
a_agent.AgentConfig = agentConfig
// build for octopus tcp connect info struct // build for octopus tcp connect info struct
rabbitTCPConnectInfo := BuildOctopusTCPConnect(agentConfig) rabbitTCPConnectInfo := BuildOctopusTCPConnect(agentConfig)
@@ -184,24 +184,18 @@ func buildAndSendInitMsgToServer(agentServerInfo *a_agent.AgentServerInfo, initT
initOmType, initOmType,
agentServerInfo, agentServerInfo,
) )
msgBytes, err := json.Marshal(octopusMsg)
if err != nil {
log.Error(fmt.Sprintf("octopus message convert to json is wrong! msg is => %v", octopusMsg))
}
// 发送OM至MQ中 // 发送OM至MQ中
P.Submit( _ = P.Submit(
func() { func() {
for g.G.AgentHasRegister == false { for g.G.AgentHasRegister == false {
log.Debug(fmt.Sprintf("Send init message to server! ==> %s", string(msgBytes))) log.InfoF("Send init message to server! ==> %s", octopusMsg)
//如果agent存活 而Server不存活 那么需要持续不断的向Server中发送消息 //如果agent存活 而Server不存活 那么需要持续不断的向Server中发送消息
initToServerQueue.Send( initToServerQueue.SendOMsg(octopusMsg)
msgBytes,
)
// 休眠 // 休眠
time.Sleep(10 * time.Minute) time.Sleep(5 * time.Minute)
} }
}) })
} }
@@ -346,7 +340,7 @@ func UniformAgentServerInfo(agentServerInfo *a_agent.AgentServerInfo) {
} }
func BuildAgentOsOperator(agentInfo *a_status.AgentInfo, agentServerInfo *a_agent.AgentServerInfo) { func buildAgentOsOperator(agentInfo *a_status.AgentInfo, agentServerInfo *a_agent.AgentServerInfo) {
// 2023年8月4日 pass through some key information // 2023年8月4日 pass through some key information
ossOfflinePrefix := "http://bastion.io" ossOfflinePrefix := "http://bastion.io"
@@ -355,6 +349,8 @@ func BuildAgentOsOperator(agentInfo *a_status.AgentInfo, agentServerInfo *a_agen
if !strings.HasSuffix(ossOfflinePrefix, "/") { if !strings.HasSuffix(ossOfflinePrefix, "/") {
ossOfflinePrefix += "/" ossOfflinePrefix += "/"
} }
} else {
log.WarnF("buildAgentOsOperator - agent oss offline prefix is null !")
} }
// call the init exec function // call the init exec function

View File

@@ -42,7 +42,7 @@ func BastionModeInit() {
// re-get agentInfo from status module // re-get agentInfo from status module
agentInfo := a_status.ReportAgentInfo() agentInfo := a_status.ReportAgentInfo()
refreshAgentInfoByStatusInfo(agentInfo, agentServerInfo) refreshAgentInfoByStatusInfo(agentInfo, agentServerInfo)
BuildAgentOsOperator(agentInfo, agentServerInfo) buildAgentOsOperator(agentInfo, agentServerInfo)
// install docker // install docker
agentOsOperator := a_executor.AgentOsOperatorCache agentOsOperator := a_executor.AgentOsOperatorCache

View File

@@ -5,7 +5,7 @@ import (
"github.com/spf13/viper" "github.com/spf13/viper"
) )
func ParseConfiguration(configFileName string) *viper.Viper { func parseOctopusAgentConf(configFileName string) *viper.Viper {
agentConfig := parseAgentConfigFile(configFileName, nil) agentConfig := parseAgentConfigFile(configFileName, nil)