Signed-off-by: jagger <cossjie@foxmail.com>pull/531/head
| @@ -1416,6 +1416,7 @@ type ResourceSpecReq { | |||||
| type FetchResourceSpecReq { | type FetchResourceSpecReq { | ||||
| ClusterId string `form:"clusterId,optional"` | ClusterId string `form:"clusterId,optional"` | ||||
| Tag string `form:"tag,optional"` | Tag string `form:"tag,optional"` | ||||
| UserId int64 `form:"userId,optional"` | |||||
| } | } | ||||
| type IdReq { | type IdReq { | ||||
| @@ -1483,4 +1484,5 @@ type EditResourceReq { | |||||
| type SyncResourceReq { | type SyncResourceReq { | ||||
| Id string `json:"id"` | Id string `json:"id"` | ||||
| UserId int64 `json:"userId"` | |||||
| } | } | ||||
| @@ -6,6 +6,7 @@ import ( | |||||
| "gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc" | "gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc" | ||||
| "gitlink.org.cn/JointCloud/pcm-coordinator/internal/types" | "gitlink.org.cn/JointCloud/pcm-coordinator/internal/types" | ||||
| "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/repository/result" | "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/repository/result" | ||||
| "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/utils" | |||||
| "net/http" | "net/http" | ||||
| ) | ) | ||||
| @@ -16,7 +17,14 @@ func CompareResourceSpecHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { | |||||
| result.ParamErrorResult(r, w, err) | result.ParamErrorResult(r, w, err) | ||||
| return | return | ||||
| } | } | ||||
| token := r.Header.Get("Authorization") | |||||
| // 获取用户信息 | |||||
| jccUserInfo, err := utils.ParseTokenWithoutVerify(token) | |||||
| if err != nil { | |||||
| result.ParamErrorResult(r, w, err) | |||||
| return | |||||
| } | |||||
| req.UserId = jccUserInfo.Id | |||||
| l := core.NewCompareResourceSpecLogic(r.Context(), svcCtx) | l := core.NewCompareResourceSpecLogic(r.Context(), svcCtx) | ||||
| resp, err := l.CompareResourceSpec(&req) | resp, err := l.CompareResourceSpec(&req) | ||||
| result.HttpResult(r, w, resp, err) | result.HttpResult(r, w, resp, err) | ||||
| @@ -6,6 +6,7 @@ import ( | |||||
| "gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc" | "gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc" | ||||
| "gitlink.org.cn/JointCloud/pcm-coordinator/internal/types" | "gitlink.org.cn/JointCloud/pcm-coordinator/internal/types" | ||||
| "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/repository/result" | "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/repository/result" | ||||
| "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/utils" | |||||
| "net/http" | "net/http" | ||||
| ) | ) | ||||
| @@ -17,6 +18,14 @@ func SyncResourceSpecHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { | |||||
| return | return | ||||
| } | } | ||||
| token := r.Header.Get("Authorization") | |||||
| // 获取用户信息 | |||||
| jccUserInfo, err := utils.ParseTokenWithoutVerify(token) | |||||
| if err != nil { | |||||
| result.ParamErrorResult(r, w, err) | |||||
| return | |||||
| } | |||||
| req.UserId = jccUserInfo.Id | |||||
| l := core.NewSyncResourceSpecLogic(r.Context(), svcCtx) | l := core.NewSyncResourceSpecLogic(r.Context(), svcCtx) | ||||
| resp, err := l.SyncResourceSpec(&req) | resp, err := l.SyncResourceSpec(&req) | ||||
| result.HttpResult(r, w, resp, err) | result.HttpResult(r, w, resp, err) | ||||
| @@ -79,7 +79,7 @@ func (l *CompareResourceSpecLogic) CompareResourceSpec(req *types.FetchResourceS | |||||
| } | } | ||||
| // 同步资源到数据库 | // 同步资源到数据库 | ||||
| if err := l.syncResourcesToDB(apiResources); err != nil { | |||||
| if err := l.syncResourcesToDB(apiResources, req.UserId); err != nil { | |||||
| return nil, fmt.Errorf("failed to sync resources: %w", err) | return nil, fmt.Errorf("failed to sync resources: %w", err) | ||||
| } | } | ||||
| @@ -135,10 +135,10 @@ func decodeAPIResponse(input interface{}, output *[]APIResponse) error { | |||||
| return nil | return nil | ||||
| } | } | ||||
| func (l *CompareResourceSpecLogic) syncResourcesToDB(apiResponses []APIResponse) error { | |||||
| func (l *CompareResourceSpecLogic) syncResourcesToDB(apiResponses []APIResponse, userId int64) error { | |||||
| for _, response := range apiResponses { | for _, response := range apiResponses { | ||||
| // 转换API响应到数据库模型 | // 转换API响应到数据库模型 | ||||
| dbSpecs, apiSpecs, err := l.processAPIResponse(response) | |||||
| dbSpecs, apiSpecs, err := l.processAPIResponse(response, userId) | |||||
| if err != nil { | if err != nil { | ||||
| return err | return err | ||||
| } | } | ||||
| @@ -151,7 +151,7 @@ func (l *CompareResourceSpecLogic) syncResourcesToDB(apiResponses []APIResponse) | |||||
| return nil | return nil | ||||
| } | } | ||||
| func (l *CompareResourceSpecLogic) processAPIResponse(response APIResponse) ([]models.TResourceSpec, []models.TResourceSpec, error) { | |||||
| func (l *CompareResourceSpecLogic) processAPIResponse(response APIResponse, userId int64) ([]models.TResourceSpec, []models.TResourceSpec, error) { | |||||
| ClusterId := utils.StringToInt64(response.ClusterId) | ClusterId := utils.StringToInt64(response.ClusterId) | ||||
| var dbSpecs []models.TResourceSpec | var dbSpecs []models.TResourceSpec | ||||
| if err := l.svcCtx.DbEngin.Model(models.TResourceSpec{}).Preload("BaseResourceSpecs"). | if err := l.svcCtx.DbEngin.Model(models.TResourceSpec{}).Preload("BaseResourceSpecs"). | ||||
| @@ -167,7 +167,7 @@ func (l *CompareResourceSpecLogic) processAPIResponse(response APIResponse) ([]m | |||||
| if res.Resource.Name == "" || res.Resource.Type == "" { | if res.Resource.Name == "" || res.Resource.Type == "" { | ||||
| continue | continue | ||||
| } | } | ||||
| spec := l.convertToResourceSpec(ClusterId, res, response.Tag) | |||||
| spec := l.convertToResourceSpec(ClusterId, res, response.Tag, userId) | |||||
| apiSpecs = append(apiSpecs, spec) | apiSpecs = append(apiSpecs, spec) | ||||
| } | } | ||||
| @@ -333,7 +333,7 @@ func (l *CompareResourceSpecLogic) isSpecChanged(old, new models.TResourceSpec) | |||||
| return len(oldBaseMap) > 0 | return len(oldBaseMap) > 0 | ||||
| } | } | ||||
| func (l *CompareResourceSpecLogic) convertToResourceSpec(ClusterId int64, res Resource, tag string) models.TResourceSpec { | |||||
| func (l *CompareResourceSpecLogic) convertToResourceSpec(ClusterId int64, res Resource, tag string, userId int64) models.TResourceSpec { | |||||
| spec := models.TResourceSpec{ | spec := models.TResourceSpec{ | ||||
| SourceKey: resourceKey(res.Resource.Type, res.Resource.Name, tag), | SourceKey: resourceKey(res.Resource.Type, res.Resource.Name, tag), | ||||
| Type: res.Resource.Type, | Type: res.Resource.Type, | ||||
| @@ -344,6 +344,7 @@ func (l *CompareResourceSpecLogic) convertToResourceSpec(ClusterId int64, res Re | |||||
| ClusterId: ClusterId, | ClusterId: ClusterId, | ||||
| CreateTime: time.Now(), | CreateTime: time.Now(), | ||||
| UpdateTime: time.Now(), | UpdateTime: time.Now(), | ||||
| UserId: userId, | |||||
| ChangeType: ChangeTypeNormal, | ChangeType: ChangeTypeNormal, | ||||
| } | } | ||||
| @@ -355,6 +356,7 @@ func (l *CompareResourceSpecLogic) convertToResourceSpec(ClusterId int64, res Re | |||||
| TotalUnit: br.Total.Unit, | TotalUnit: br.Total.Unit, | ||||
| AvailableValue: br.Available.Value, | AvailableValue: br.Available.Value, | ||||
| AvailableUnit: br.Available.Unit, | AvailableUnit: br.Available.Unit, | ||||
| UserId: userId, | |||||
| CreateTime: time.Now(), | CreateTime: time.Now(), | ||||
| UpdateTime: time.Now(), | UpdateTime: time.Now(), | ||||
| }) | }) | ||||
| @@ -51,7 +51,7 @@ func (l *SyncResourceSpecLogic) SyncResourceSpec(req *types.SyncResourceReq) (re | |||||
| } | } | ||||
| for _, response := range apiResources { | for _, response := range apiResources { | ||||
| // 转换API响应到数据库模型 | // 转换API响应到数据库模型 | ||||
| _, apiSpecs, err := compareLogic.processAPIResponse(response) | |||||
| _, apiSpecs, err := compareLogic.processAPIResponse(response, req.UserId) | |||||
| if err != nil { | if err != nil { | ||||
| return nil, err | return nil, err | ||||
| } | } | ||||
| @@ -162,8 +162,14 @@ func (m *ModelArtsLink) SubmitTask(ctx context.Context, imageId string, cmd stri | |||||
| outputs := make([]*modelarts.OutputTraining, 0) | outputs := make([]*modelarts.OutputTraining, 0) | ||||
| outputValue := "" | outputValue := "" | ||||
| for _, env := range envs { | for _, env := range envs { | ||||
| s := strings.Split(env, COMMA) | |||||
| environments[s[0]] = s[1] | |||||
| // 找到第一个逗号位置 | |||||
| idx := strings.Index(env, COMMA) | |||||
| if idx == -1 { | |||||
| continue | |||||
| } | |||||
| key := strings.TrimSpace(env[:idx]) | |||||
| value := strings.TrimSpace(env[idx+1:]) | |||||
| environments[key] = value | |||||
| } | } | ||||
| for _, param := range params { | for _, param := range params { | ||||
| s := strings.Split(param, COMMA) | s := strings.Split(param, COMMA) | ||||
| @@ -2283,6 +2283,7 @@ type Fault struct { | |||||
| type FetchResourceSpecReq struct { | type FetchResourceSpecReq struct { | ||||
| ClusterId string `form:"clusterId,optional"` | ClusterId string `form:"clusterId,optional"` | ||||
| Tag string `form:"tag,optional"` | Tag string `form:"tag,optional"` | ||||
| UserId int64 `form:"userId,optional"` | |||||
| } | } | ||||
| type Fields struct { | type Fields struct { | ||||
| @@ -5566,7 +5567,8 @@ type SyncClusterAlertReq struct { | |||||
| } | } | ||||
| type SyncResourceReq struct { | type SyncResourceReq struct { | ||||
| Id string `json:"id"` | |||||
| Id string `json:"id"` | |||||
| UserId int64 `json:"userId"` | |||||
| } | } | ||||
| type Tags struct { | type Tags struct { | ||||