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

This commit is contained in:
zeaslity
2024-03-29 14:46:11 +08:00
parent 1be48aaac2
commit 1d32d7dd04
6 changed files with 42 additions and 39 deletions

View File

@@ -73,31 +73,33 @@ func INIT(octopusAgentConfigFileName string, agentServerInfoConf string) chan bo
// 监听初始化连接中的信息
initFromServerQueue := &rabbitmq.RabbitQueue{
RabbitProp: initFromServerProp,
RabbitProp: initFromServerProp,
RabbitConnectInfo: rabbitTCPConnectInfo,
}
//defer initFromServerQueue.Close()
// 建立连接
initFromServerQueue.Connect()
initForeverHandle := initFromServerQueue.Handle()
initFromServerQueue.Handle()
buildAndSendInitMsgToServer(agentServerInfo, initToServerQueue)
// receive from server
for g.G.AgentHasRegister == false {
select {
case <-initFromServerQueue.ReceiveChan.InitRChan:
initFromServerMsg := <-initFromServerQueue.ReceiveChan.InitRChan
handleInitMsgFromServer(initFromServerMsg, initToServerQueue, agentServerInfo)
case initFromServerMsg := <-initFromServerQueue.ReceiveChan.InitRChan:
if handleInitMsgFromServer(initFromServerMsg, initToServerQueue, agentServerInfo) {
break
}
default:
//log.Debug("")
log.Debug("agent init not received from server ! start to waiting !")
time.Sleep(time.Second * 10)
}
}
<-initForeverHandle
close(initFromServerQueue.ReceiveChan.InitRChan)
//<-initForeverHandle
//close(initFromServerQueue.ReceiveChan.InitRChan)
// 建立 运行时 RabbitMQ连接
runtimeConnectorQueue := buildAndStartBusinessRuntimeQueue(a_agent.AgentServerInfoCache.TopicName)
@@ -194,7 +196,7 @@ func buildAndSendInitMsgToServer(agentServerInfo *a_agent.AgentServerInfo, initT
})
}
func BuildOctopusTCPConnect(agentConfig *viper.Viper) rabbitmq.RabbitTCPConnectInfo {
func BuildOctopusTCPConnect(agentConfig *viper.Viper) *rabbitmq.RabbitTCPConnectInfo {
host := agentConfig.GetString("spring.rabbitmq.host")
port := agentConfig.GetString("spring.rabbitmq.port")
username := agentConfig.GetString("spring.rabbitmq.username")
@@ -202,7 +204,7 @@ func BuildOctopusTCPConnect(agentConfig *viper.Viper) rabbitmq.RabbitTCPConnectI
virtualHost := agentConfig.GetString("spring.rabbitmq.virtual-host")
//todo
return rabbitmq.RabbitTCPConnectInfo{
return &rabbitmq.RabbitTCPConnectInfo{
UserName: username,
Password: password,
Host: host,
@@ -227,7 +229,7 @@ func handleInitMsgFromServer(initFromServerMsg *rabbitmq.OctopusMessage, initToS
//initOctopusMessageDeliveries := initFromServerQueue.Read(false)
log.Debug(fmt.Sprintf("message received from server is %s", &initFromServerMsg))
log.DebugF("message received from server is %s", initFromServerMsg)
var serverInfo a_agent.AgentServerInfo

View File

@@ -0,0 +1,55 @@
package a_init
import (
"wdd.io/agent-go/a_agent"
"wdd.io/agent-go/a_executor"
"wdd.io/agent-go/a_status"
)
func BastionModeInit() {
// Build For Operator
agentServerInfo := &a_agent.AgentServerInfo{
ServerName: "BastionSingle",
ServerIPPbV4: "127.0.0.1",
ServerIPInV4: "127.0.0.1",
ServerIPPbV6: "",
ServerIPInV6: "",
Location: "Bastion",
Provider: "Bastion",
ManagePort: "22",
CPUCore: "",
CPUBrand: "",
OSInfo: "",
OSKernelInfo: "",
TCPControl: "",
Virtualization: "",
Platform: "",
PlatformFamily: "",
PlatformVersion: "",
KernelVersion: "",
KernelArch: "",
IoSpeed: "",
MemoryTotal: "",
DiskTotal: "",
DiskUsage: "",
Comment: "",
MachineID: "",
AgentVersion: "",
TopicName: "BastionNode",
}
// re-get agentInfo from status module
agentInfo := a_status.ReportAgentInfo()
refreshAgentInfoByStatusInfo(agentInfo, agentServerInfo)
BuildAgentOsOperator(agentInfo, agentServerInfo)
// install docker
agentOsOperator := a_executor.AgentOsOperatorCache
// boot up minio & rabbitmq
agentOsOperator.InstallDockerFromLocalExec(nil)
agentOsOperator.InstallDockerComposeFromLocalExec()
// build for socks server
}