diff --git a/configmanage/server/service/configinstance.go b/configmanage/server/service/configinstance.go index 8ebc5c34b3ae4454c5ef8c0f557f05290f3e3688..cd47bc993e536b9eeec60a7bf970774b8c8df64d 100644 --- a/configmanage/server/service/configinstance.go +++ b/configmanage/server/service/configinstance.go @@ -1,8 +1,6 @@ package service import ( - "encoding/json" - "gitee.com/openeuler/PilotGo/sdk/common" "openeuler.org/PilotGo/configmanage-plugin/db" "openeuler.org/PilotGo/configmanage-plugin/internal" @@ -74,7 +72,7 @@ type Config interface { // 单机采集数据 Collect() error // 依据agent uuid进行配置下发 - Apply() (json.RawMessage, error) + Apply() ([]NodeResult, error) } func (ci *ConfigInstance) Add() error { @@ -179,3 +177,12 @@ type Deploy struct { DeployFileName string `json:"deployname"` DeployText string `json:"deployfile"` } + +// 构造单机采集和配置下发结果结构 +type NodeResult struct { + Type string `json:"type"` // 指明配置类型 + NodeUUID string `json:"nodeuuid"` // 指明执行机器的uuid + Detail string `json:"detail"` // 执行详情 + Result bool `json:"result"` // 执行结果 + Err string `json:"err"` // 错误信息 +} diff --git a/configmanage/server/service/host.go b/configmanage/server/service/host.go index 1699c812c7f59a562185dcd8dcef4213141ccb25..98a73d7bd54629c9de12bcf21d521be76908ec73 100644 --- a/configmanage/server/service/host.go +++ b/configmanage/server/service/host.go @@ -13,6 +13,7 @@ import ( "gitee.com/openeuler/PilotGo/sdk/plugin/client" "gitee.com/openeuler/PilotGo/sdk/utils/httputils" "github.com/google/uuid" + "openeuler.org/PilotGo/configmanage-plugin/global" "openeuler.org/PilotGo/configmanage-plugin/internal" ) @@ -82,7 +83,7 @@ func (hc *HostConfig) Load() error { return nil } -func (hc *HostConfig) Apply() (json.RawMessage, error) { +func (hc *HostConfig) Apply() ([]NodeResult, error) { //从数据库获取下发的信息 hf, err := internal.GetHostFileByUUID(hc.UUID) if err != nil { @@ -106,21 +107,21 @@ func (hc *HostConfig) Apply() (json.RawMessage, error) { } //从hc中解析下发的文件内容,逐一进行下发 - Repofile := common.File{} - err = json.Unmarshal([]byte(hf.Content), &Repofile) + hostfile := common.File{} + err = json.Unmarshal([]byte(hf.Content), &hostfile) if err != nil { return nil, err } - result := "" + results := []NodeResult{} de := Deploy{ DeployBatch: common.Batch{ BatchIds: batchids, DepartmentIDs: departids, MachineUUIDs: nodes, }, - DeployPath: Repofile.Path, - DeployFileName: Repofile.Name, - DeployText: Repofile.Content, + DeployPath: hostfile.Path, + DeployFileName: hostfile.Name, + DeployText: hostfile.Content, } url := "http://" + client.GetClient().Server() + "/api/v1/pluginapi/file_deploy" r, err := httputils.Post(url, &httputils.Params{ @@ -148,17 +149,23 @@ func (hc *HostConfig) Apply() (json.RawMessage, error) { // 将执行失败的文件、机器信息和原因添加到结果字符串中 for _, d := range data { if d.Error != "" { - result = result + Repofile.Content + "文件" + d.UUID + ":" + d.Error + "\n" + results = append(results, NodeResult{ + Type: global.Host, + NodeUUID: d.UUID, + Detail: hostfile.Content, + Result: false, + Err: d.Error, + }) } } //TODO:部分成功如何修改数据库 - if result == "" { + if results == nil { //下发成功修改数据库应用版本 err = hf.UpdateByuuid() return nil, err } - return nil, errors.New(result + "failed to apply host config") + return results, errors.New("failed to apply host config") } func (hc *HostConfig) Collect() error {