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

View File

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

View File

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