updated getimagelist logic

This commit is contained in:
tzwang 2024-09-20 15:22:28 +08:00
parent 5ad743bd7d
commit a61107c056
1 changed files with 48 additions and 2 deletions

View File

@ -1,7 +1,12 @@
package logic package logic
import ( import (
"bytes"
"context" "context"
"encoding/json"
"errors"
"gitlink.org.cn/JointCloud/pcm-ac/internal/common"
"net/http"
"gitlink.org.cn/JointCloud/pcm-ac/hpcAC" "gitlink.org.cn/JointCloud/pcm-ac/hpcAC"
"gitlink.org.cn/JointCloud/pcm-ac/internal/svc" "gitlink.org.cn/JointCloud/pcm-ac/internal/svc"
@ -24,7 +29,48 @@ func NewGetImageListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetI
} }
func (l *GetImageListLogic) GetImageList(in *hpcAC.GetImageListReq) (*hpcAC.GetImageListResp, error) { func (l *GetImageListLogic) GetImageList(in *hpcAC.GetImageListReq) (*hpcAC.GetImageListResp, error) {
// todo: add your logic here and delete this line resp := &hpcAC.GetImageListResp{}
asv, found := l.svcCtx.AuthServiceMap[common.CLUSTER_AVAIL_TMP]
if !found {
return nil, errors.New("可用区域不存在")
}
token := asv.GetToken()
if token == "" {
return nil, errors.New("获取token失败")
}
return &hpcAC.GetImageListResp{}, nil aiCenterUrlPrefix := asv.GetAiCenterUrlPrefix()
if aiCenterUrlPrefix == "" {
return nil, errors.New("aiCenterUrlPrefix is empty")
}
var reqUrl = aiCenterUrlPrefix + l.svcCtx.Config.ContainerConf.GetImageList
s := struct {
AcceleratorType string `json:"acceleratorType"`
ImageType string `json:"imageType"`
}{
AcceleratorType: in.AcceleratorType,
ImageType: in.ImageType,
}
b, _ := json.Marshal(s)
byt := bytes.NewBuffer(b)
req := common.GetRestyRequest(common.TIMEOUT)
r, _ := http.NewRequest("", reqUrl, byt)
req.RawRequest = r
req.URL = reqUrl
_, err := req.
SetHeader("Content-Type", "application/json").
SetHeader("token", token).
SetBody(byt).
SetResult(resp).
Send()
if err != nil {
return nil, err
}
return resp, nil
} }