forked from JointCloud/pcm-coordinator
add UserId field to resource spec requests and handlers; enhance user tracking in resource synchronization
Signed-off-by: jagger <cossjie@foxmail.com>
This commit is contained in:
parent
e702c27355
commit
d672a1e0b8
|
@ -1416,6 +1416,7 @@ type ResourceSpecReq {
|
|||
type FetchResourceSpecReq {
|
||||
ClusterId string `form:"clusterId,optional"`
|
||||
Tag string `form:"tag,optional"`
|
||||
UserId int64 `form:"userId,optional"`
|
||||
}
|
||||
|
||||
type IdReq {
|
||||
|
@ -1483,4 +1484,5 @@ type EditResourceReq {
|
|||
|
||||
type SyncResourceReq {
|
||||
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/types"
|
||||
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/repository/result"
|
||||
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/utils"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
|
@ -16,7 +17,14 @@ func CompareResourceSpecHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
|||
result.ParamErrorResult(r, w, err)
|
||||
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)
|
||||
resp, err := l.CompareResourceSpec(&req)
|
||||
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/types"
|
||||
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/repository/result"
|
||||
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/utils"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
|
@ -17,6 +18,14 @@ func SyncResourceSpecHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
|||
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)
|
||||
resp, err := l.SyncResourceSpec(&req)
|
||||
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)
|
||||
}
|
||||
|
||||
|
@ -135,10 +135,10 @@ func decodeAPIResponse(input interface{}, output *[]APIResponse) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (l *CompareResourceSpecLogic) syncResourcesToDB(apiResponses []APIResponse) error {
|
||||
func (l *CompareResourceSpecLogic) syncResourcesToDB(apiResponses []APIResponse, userId int64) error {
|
||||
for _, response := range apiResponses {
|
||||
// 转换API响应到数据库模型
|
||||
dbSpecs, apiSpecs, err := l.processAPIResponse(response)
|
||||
dbSpecs, apiSpecs, err := l.processAPIResponse(response, userId)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -151,7 +151,7 @@ func (l *CompareResourceSpecLogic) syncResourcesToDB(apiResponses []APIResponse)
|
|||
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)
|
||||
var dbSpecs []models.TResourceSpec
|
||||
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 == "" {
|
||||
continue
|
||||
}
|
||||
spec := l.convertToResourceSpec(ClusterId, res, response.Tag)
|
||||
spec := l.convertToResourceSpec(ClusterId, res, response.Tag, userId)
|
||||
apiSpecs = append(apiSpecs, spec)
|
||||
}
|
||||
|
||||
|
@ -333,7 +333,7 @@ func (l *CompareResourceSpecLogic) isSpecChanged(old, new models.TResourceSpec)
|
|||
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{
|
||||
SourceKey: resourceKey(res.Resource.Type, res.Resource.Name, tag),
|
||||
Type: res.Resource.Type,
|
||||
|
@ -344,6 +344,7 @@ func (l *CompareResourceSpecLogic) convertToResourceSpec(ClusterId int64, res Re
|
|||
ClusterId: ClusterId,
|
||||
CreateTime: time.Now(),
|
||||
UpdateTime: time.Now(),
|
||||
UserId: userId,
|
||||
ChangeType: ChangeTypeNormal,
|
||||
}
|
||||
|
||||
|
@ -355,6 +356,7 @@ func (l *CompareResourceSpecLogic) convertToResourceSpec(ClusterId int64, res Re
|
|||
TotalUnit: br.Total.Unit,
|
||||
AvailableValue: br.Available.Value,
|
||||
AvailableUnit: br.Available.Unit,
|
||||
UserId: userId,
|
||||
CreateTime: time.Now(),
|
||||
UpdateTime: time.Now(),
|
||||
})
|
||||
|
|
|
@ -51,7 +51,7 @@ func (l *SyncResourceSpecLogic) SyncResourceSpec(req *types.SyncResourceReq) (re
|
|||
}
|
||||
for _, response := range apiResources {
|
||||
// 转换API响应到数据库模型
|
||||
_, apiSpecs, err := compareLogic.processAPIResponse(response)
|
||||
_, apiSpecs, err := compareLogic.processAPIResponse(response, req.UserId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -162,8 +162,14 @@ func (m *ModelArtsLink) SubmitTask(ctx context.Context, imageId string, cmd stri
|
|||
outputs := make([]*modelarts.OutputTraining, 0)
|
||||
outputValue := ""
|
||||
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 {
|
||||
s := strings.Split(param, COMMA)
|
||||
|
|
|
@ -2283,6 +2283,7 @@ type Fault struct {
|
|||
type FetchResourceSpecReq struct {
|
||||
ClusterId string `form:"clusterId,optional"`
|
||||
Tag string `form:"tag,optional"`
|
||||
UserId int64 `form:"userId,optional"`
|
||||
}
|
||||
|
||||
type Fields struct {
|
||||
|
@ -5566,7 +5567,8 @@ type SyncClusterAlertReq struct {
|
|||
}
|
||||
|
||||
type SyncResourceReq struct {
|
||||
Id string `json:"id"`
|
||||
Id string `json:"id"`
|
||||
UserId int64 `json:"userId"`
|
||||
}
|
||||
|
||||
type Tags struct {
|
||||
|
|
Loading…
Reference in New Issue