fix:查询专属资源池接口修改
Former-commit-id: 34598e026ac64b7c455fb3aea0f7414434e95d24
This commit is contained in:
parent
0b8fa4a3a3
commit
1fe54bcf5b
|
@ -6,10 +6,15 @@ package logic
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"APIGW-go-sdk/core"
|
||||||
"PCM/adaptor/PCM-AI/PCM-MODELARTS/rpc/internal/common"
|
"PCM/adaptor/PCM-AI/PCM-MODELARTS/rpc/internal/common"
|
||||||
"PCM/common/tool"
|
"PCM/common/tool"
|
||||||
"context"
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
"k8s.io/apimachinery/pkg/util/json"
|
"k8s.io/apimachinery/pkg/util/json"
|
||||||
|
"net/http"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
"PCM/adaptor/PCM-AI/PCM-MODELARTS/rpc/internal/svc"
|
"PCM/adaptor/PCM-AI/PCM-MODELARTS/rpc/internal/svc"
|
||||||
"PCM/adaptor/PCM-AI/PCM-MODELARTS/rpc/modelarts"
|
"PCM/adaptor/PCM-AI/PCM-MODELARTS/rpc/modelarts"
|
||||||
|
@ -34,17 +39,60 @@ func NewListClustersLogic(ctx context.Context, svcCtx *svc.ServiceContext) *List
|
||||||
func (l *ListClustersLogic) ListClusters(in *modelarts.ListClustersReq) (*modelarts.ListClustersResp, error) {
|
func (l *ListClustersLogic) ListClusters(in *modelarts.ListClustersReq) (*modelarts.ListClustersResp, error) {
|
||||||
// todo: add your logic here and delete this line
|
// todo: add your logic here and delete this line
|
||||||
var resp modelarts.ListClustersResp
|
var resp modelarts.ListClustersResp
|
||||||
url := "https://modelarts.cn-north-4.myhuaweicloud.com/v1/" + in.ProjectId + "/clusters"
|
judgeLimit := strconv.Itoa(int(in.Limit))
|
||||||
token := common.GetToken()
|
offset := strconv.Itoa(int(in.Offset))
|
||||||
statusCode, body, err := tool.HttpClientWithBodyAndCode(tool.GET, url, nil, token)
|
var limit string
|
||||||
if err != nil {
|
if judgeLimit != "0" {
|
||||||
return nil, err
|
limit = strconv.Itoa(int(in.Limit))
|
||||||
}
|
|
||||||
json.Unmarshal(body, &resp)
|
|
||||||
if statusCode == 200 {
|
|
||||||
json.Unmarshal(body, &resp.Resp200)
|
|
||||||
} else {
|
} else {
|
||||||
json.Unmarshal(body, &resp.Resp400)
|
limit = "10"
|
||||||
|
}
|
||||||
|
//根据智算类型判断走华为智算还是南京智算
|
||||||
|
modelArtsType := in.ModelArtsType
|
||||||
|
if modelArtsType == l.svcCtx.Config.HaweiModelArtsType {
|
||||||
|
modelArtsUrl := l.svcCtx.Config.ModelArtsUrl
|
||||||
|
url := modelArtsUrl + "v1/" + in.ProjectId + "/clusters?limit=" + limit + "&offset=" + offset
|
||||||
|
token := common.GetToken()
|
||||||
|
statusCode, body, err := tool.HttpClientWithBodyAndCode(tool.GET, url, nil, token)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
json.Unmarshal(body, &resp)
|
||||||
|
if statusCode == 200 {
|
||||||
|
json.Unmarshal(body, &resp.Resp200)
|
||||||
|
} else {
|
||||||
|
json.Unmarshal(body, &resp.Resp400)
|
||||||
|
}
|
||||||
|
} else if modelArtsType == l.svcCtx.Config.NanjingModelArtsType {
|
||||||
|
AK := l.svcCtx.Config.AK
|
||||||
|
SK := l.svcCtx.Config.SK
|
||||||
|
NanjingModelArtsUrl := l.svcCtx.Config.NanjingModelArtsUrl
|
||||||
|
XProjectId := l.svcCtx.Config.XProjectId
|
||||||
|
s := core.Signer{
|
||||||
|
Key: AK,
|
||||||
|
Secret: SK,
|
||||||
|
}
|
||||||
|
r, err := http.NewRequest("GET", NanjingModelArtsUrl+"v1/"+in.ProjectId+"/clusters?offset="+offset+"&"+"limit="+limit,
|
||||||
|
nil)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
}
|
||||||
|
r.Header.Add("content-type", "application/json;charset=UTF-8")
|
||||||
|
r.Header.Add("X-Project-Id", XProjectId)
|
||||||
|
r.Header.Add("x-stage", "RELEASE")
|
||||||
|
s.Sign(r)
|
||||||
|
client := http.DefaultClient
|
||||||
|
res, err := client.Do(r)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
}
|
||||||
|
defer res.Body.Close()
|
||||||
|
body, err := ioutil.ReadAll(res.Body)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
}
|
||||||
|
json.Unmarshal(body, &resp)
|
||||||
|
|
||||||
}
|
}
|
||||||
return &resp, nil
|
return &resp, nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue