[Agent] [init] update initializaiton

This commit is contained in:
zeaslity
2023-11-08 17:13:52 +08:00
parent 25f1dd029a
commit 11a1215cde
3 changed files with 31 additions and 31 deletions

View File

@@ -1,15 +1,13 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="go build agent-go" type="GoApplicationRunConfiguration"
factoryName="Go Application" nameIsGenerated="true">
<module name="ProjectOctopus"/>
<working_directory value="$PROJECT_DIR$/agent-go"/>
<useCustomBuildTags value="true"/>
<parameters
value="-version=dev -agentServerInfoConf=C:\Users\wdd\IdeaProjects\ProjectOctopus\agent-go\octopus-agent-dev.yaml"/>
<kind value="PACKAGE"/>
<package value="agent-go"/>
<directory value="$PROJECT_DIR$"/>
<filePath value="$PROJECT_DIR$/agent-go/main.go"/>
<method v="2"/>
<configuration default="false" name="go build agent-go" type="GoApplicationRunConfiguration" factoryName="Go Application" nameIsGenerated="true">
<module name="ProjectOctopus" />
<working_directory value="$PROJECT_DIR$/agent-go" />
<useCustomBuildTags value="true" />
<parameters value="-version=shanghai -agentServerInfoConf=$PROJECT_DIR$/agent-go/server-env.yaml" />
<kind value="PACKAGE" />
<package value="agent-go" />
<directory value="$PROJECT_DIR$" />
<filePath value="$PROJECT_DIR$/agent-go/main.go" />
<method v="2" />
</configuration>
</component>

View File

@@ -172,40 +172,41 @@ func shutdownRegisterQueueConnection(initFromServerQueue *rabbitmq.RabbitQueue,
func parseAgentServerInfo(agentServerInfoConf string) *register.AgentServerInfo {
// 约定文件地址为 /octopus-agent/octopus-agent.conf
var agentServerInfo register.AgentServerInfo
var agentServerInfo *register.AgentServerInfo
yamlFile, err := ioutil.ReadFile(agentServerInfoConf)
if err != nil {
panic(fmt.Errorf("failed to read YAML file: %v", err))
}
err = yaml.Unmarshal(yamlFile, agentServerInfo)
err = yaml.Unmarshal(yamlFile, &agentServerInfo)
if err != nil {
panic(fmt.Errorf("failed to unmarshal YAML: %v", err))
}
jsonFormat, err := json.Marshal(agentServerInfo)
if err != nil {
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)))
// uniform agent server info
UniformAgentServerInfo(agentServerInfo)
// build operator cache
BuildAgentOsOperator(agentServerInfo)
return &agentServerInfo
jsonFormat, err := json.Marshal(&agentServerInfo)
if err != nil {
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)))
return agentServerInfo
}
// UniformAgentServerInfo uniform deal with ip
func UniformAgentServerInfo(agentServerInfo register.AgentServerInfo) {
func UniformAgentServerInfo(agentServerInfo *register.AgentServerInfo) {
// reflect to iterator all field
log.Info("[Initialization] - UniformAgentServerInfo !")
value := reflect.ValueOf(agentServerInfo)
value := reflect.ValueOf(agentServerInfo).Elem()
for i := 0; i < value.NumField(); i++ {
field := value.Field(i)
if field.Kind() == reflect.String && field.CanSet() {
@@ -224,7 +225,7 @@ func UniformAgentServerInfo(agentServerInfo register.AgentServerInfo) {
}
func BuildAgentOsOperator(agentServerInfo register.AgentServerInfo) {
func BuildAgentOsOperator(agentServerInfo *register.AgentServerInfo) {
// 2023年8月4日 passthrough some key information
ossOfflinePrefix := g.G.AgentConfig.GetString("octopus.agent.executor.ossOfflinePrefix")
@@ -236,7 +237,7 @@ func BuildAgentOsOperator(agentServerInfo register.AgentServerInfo) {
agentOsOperator := executor.BuildAgentOsOperator(agentServerInfo.OSInfo, ossOfflinePrefix)
// assign the agentServerInfo
agentOsOperator.AgentServerInfo = &agentServerInfo
agentOsOperator.AgentServerInfo = agentServerInfo
// debug
marshal, _ := json.Marshal(agentOsOperator)

View File

@@ -12,11 +12,12 @@ memoryTotal: "7.6 GB"
diskTotal: "914.9 GB"
diskUsage: "12.3 GB"
archInfo: "x86_64 (64 Bit)"
osInfo: "Ubuntu 20.04.5 LTS"
osInfo: "
Ubuntu 20.04.5 LTS"
osKernelInfo: "5.4.0-135-generic"
tcpControl: "cubic"
tcpControl: "cubic "
virtualization: "Dedicated"
ioSpeed: "150 MB/s"
machineId: "fakemachinid123"
ioSpeed: "150 MB/s "
machineId: "fakemachinid123 "
agentVersion: ""
topicName: ""