diff --git a/configmanage/server/controller/configinstance.go b/configmanage/server/controller/configinstance.go index 34b4954c58aa35cc18a41cd5ad3e1e4135d1629f..a1657f50b1eb9b96a2b67e592ec50003c68ea286 100644 --- a/configmanage/server/controller/configinstance.go +++ b/configmanage/server/controller/configinstance.go @@ -88,8 +88,8 @@ func LoadConfigHandler(c *gin.Context) { } logger.Debug("load config") - //获取configinfo - ci, err := service.GetInfoByUUID(query.UUID) + //获取ConfigInstance + ci, err := service.GetConfigByUUID(query.UUID) if err != nil { logger.Error(err.Error()) response.Fail(c, "get configinfo fail:", err.Error()) @@ -109,8 +109,9 @@ func LoadConfigHandler(c *gin.Context) { response.Fail(c, "get repofile fail:", err.Error()) return } + ci.Config = repoconfig logger.Debug("load repoconfig success") - response.Success(c, repoconfig, "load repo config success") + response.Success(c, ci, "load repo config success") case global.Host: @@ -136,7 +137,7 @@ func ApplyConfigHandler(c *gin.Context) { return } - //获取configinfo + //获取Configinfo ci, err := service.GetInfoByUUID(query.UUID) if err != nil { logger.Error(err.Error()) diff --git a/configmanage/server/internal/confignode.go b/configmanage/server/internal/confignode.go index c45607096c60d41155c51ff9c451fa79b332dad1..366ff6983cf88254bdad88411323ba02350738f1 100644 --- a/configmanage/server/internal/confignode.go +++ b/configmanage/server/internal/confignode.go @@ -15,7 +15,7 @@ func (cn *ConfigNode) Add() error { func GetConfigNodesByUUID(uuid string) ([]string, error) { var nodes []string - err := db.MySQL().Where("config_info_uuid=?", uuid).Select("node_id").Find(&nodes).Error + err := db.MySQL().Model(&ConfigNode{}).Where("config_info_uuid=?", uuid).Select("node_id").Find(&nodes).Error return nodes, err } @@ -32,7 +32,7 @@ func (cb *ConfigBatch) Add() error { func GetConfigBatchByUUID(uuid string) ([]int, error) { var nodes []int - err := db.MySQL().Where("config_info_uuid=?", uuid).Select("batch_id").Find(&nodes).Error + err := db.MySQL().Model(&ConfigBatch{}).Where("config_info_uuid=?", uuid).Select("batch_id").Find(&nodes).Error return nodes, err } @@ -49,6 +49,6 @@ func (cd *ConfigDepart) Add() error { func GetConfigDepartByUUID(uuid string) ([]int, error) { var nodes []int - err := db.MySQL().Where("config_info_uuid=?", uuid).Select("depart_id").Find(&nodes).Error + err := db.MySQL().Model(&ConfigDepart{}).Where("config_info_uuid=?", uuid).Select("depart_id").Find(&nodes).Error return nodes, err } diff --git a/configmanage/server/internal/repofile.go b/configmanage/server/internal/repofile.go index 2b8c5f5fe85e867be16ca7d31f5a820c4c451b18..395d38b6a3ad631b4148c09083aae90fdf3fda1c 100644 --- a/configmanage/server/internal/repofile.go +++ b/configmanage/server/internal/repofile.go @@ -1,6 +1,7 @@ package internal import ( + "encoding/json" "time" "openeuler.org/PilotGo/configmanage-plugin/db" @@ -11,9 +12,9 @@ type RepoFile struct { UUID string `gorm:"primary_key;type:varchar(50)" json:"uuid"` ConfigInfo ConfigInfo `gorm:"Foreignkey:ConfigInfoUUID"` ConfigInfoUUID string - Content interface{} `gorm:"type:json" json:"content"` - Version string `gorm:"type:varchar(50)" json:"version"` - IsIndex bool `json:"isindex"` + Content json.RawMessage `gorm:"type:json" json:"content"` + Version string `gorm:"type:varchar(50)" json:"version"` + IsIndex bool `json:"isindex"` CreatedAt time.Time } diff --git a/configmanage/server/service/configinstance.go b/configmanage/server/service/configinstance.go index cbc011ac4e36b57af2edea35cb119aae887d5d42..4c1db156543a3329341c1112a3d079e5d926c862 100644 --- a/configmanage/server/service/configinstance.go +++ b/configmanage/server/service/configinstance.go @@ -84,6 +84,33 @@ func GetInfoByUUID(configuuid string) (ConfigInfo, error) { return internal.GetInfoByUUID(configuuid) } +func GetConfigByUUID(configuuid string) (*ConfigInstance, error) { + ci, err := GetInfoByUUID(configuuid) + if err != nil { + return nil, err + } + + nodes, err := internal.GetConfigNodesByUUID(configuuid) + if err != nil { + return nil, err + } + batchids, err := internal.GetConfigBatchByUUID(configuuid) + if err != nil { + return nil, err + } + departids, err := internal.GetConfigDepartByUUID(configuuid) + + config := &ConfigInstance{ + UUID: ci.UUID, + Type: ci.Type, + Description: ci.Description, + Nodes: nodes, + BatchIds: batchids, + DepartIds: departids, + } + return config, err +} + type Deploy struct { Deploy_BatchIds []int `json:"deploy_batches"` Deploy_DepartIds []int `json:"deploy_departs"` diff --git a/configmanage/server/service/repo.go b/configmanage/server/service/repo.go index e6b5af22e64befc55c827f90a7d4b62eb25fc39d..9a37482dd1dc9a3d036314fc97dcc55426f885ea 100644 --- a/configmanage/server/service/repo.go +++ b/configmanage/server/service/repo.go @@ -17,10 +17,10 @@ import ( type RepoFile = internal.RepoFile type RepoConfig struct { - UUID string `json:"uuid"` - ConfigInfoUUID string `json:"configinfouuid"` - Content interface{} `json:"content"` - Version string `json:"version"` + UUID string `json:"uuid"` + ConfigInfoUUID string `json:"configinfouuid"` + Content json.RawMessage `json:"content"` + Version string `json:"version"` //下发改变标志位 IsIndex bool `json:"isindex"` }