From a61107c05665bcf7f7ad33cb80546b2c075b8d43 Mon Sep 17 00:00:00 2001 From: tzwang Date: Fri, 20 Sep 2024 15:22:28 +0800 Subject: [PATCH] updated getimagelist logic --- internal/logic/getimagelistlogic.go | 50 +++++++++++++++++++++++++++-- 1 file changed, 48 insertions(+), 2 deletions(-) diff --git a/internal/logic/getimagelistlogic.go b/internal/logic/getimagelistlogic.go index 2445978..def899c 100644 --- a/internal/logic/getimagelistlogic.go +++ b/internal/logic/getimagelistlogic.go @@ -1,7 +1,12 @@ package logic import ( + "bytes" "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/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) { - // 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 }