fix:查询服务列表接口修改
Former-commit-id: 0304504ef7e06db422beca6775db52b6b740b6ec
This commit is contained in:
parent
e50484ad40
commit
7cf365c9bf
|
@ -6,13 +6,18 @@ 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/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"
|
||||||
"PCM/common/tool"
|
"PCM/common/tool"
|
||||||
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
|
"fmt"
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
|
"io/ioutil"
|
||||||
"k8s.io/apimachinery/pkg/util/json"
|
"k8s.io/apimachinery/pkg/util/json"
|
||||||
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -32,9 +37,19 @@ func NewListServicesLogic(ctx context.Context, svcCtx *svc.ServiceContext) *List
|
||||||
|
|
||||||
func (l *ListServicesLogic) ListServices(in *modelarts.ListServicesReq) (*modelarts.ListServicesResp, error) {
|
func (l *ListServicesLogic) ListServices(in *modelarts.ListServicesReq) (*modelarts.ListServicesResp, error) {
|
||||||
var resp modelarts.ListServicesResp
|
var resp modelarts.ListServicesResp
|
||||||
limit := strconv.Itoa(int(in.Limit))
|
judgeLimit := strconv.Itoa(int(in.Limit))
|
||||||
offset := strconv.Itoa(int(in.OffSet))
|
offset := strconv.Itoa(int(in.OffSet))
|
||||||
url := "https://modelarts.cn-north-4.myhuaweicloud.com/v1/" + in.ProjectId + "/services?limit=" + limit + "&offset=" + offset
|
var limit string
|
||||||
|
if judgeLimit != "0" {
|
||||||
|
limit = strconv.Itoa(int(in.Limit))
|
||||||
|
} else {
|
||||||
|
limit = "10"
|
||||||
|
}
|
||||||
|
//根据智算类型判断走华为智算还是南京智算
|
||||||
|
modelArtsType := in.ModelArtsType
|
||||||
|
if modelArtsType == l.svcCtx.Config.HaweiModelArtsType {
|
||||||
|
modelArtsUrl := l.svcCtx.Config.ModelArtsUrl
|
||||||
|
url := modelArtsUrl + "v1/" + in.ProjectId + "/services?limit=" + limit + "&offset=" + offset
|
||||||
token := common.GetToken()
|
token := common.GetToken()
|
||||||
statusCode, body, err := tool.HttpClientWithBodyAndCode(tool.GET, url, nil, token)
|
statusCode, body, err := tool.HttpClientWithBodyAndCode(tool.GET, url, nil, token)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -49,5 +64,36 @@ func (l *ListServicesLogic) ListServices(in *modelarts.ListServicesReq) (*modela
|
||||||
resp.Code = 400
|
resp.Code = 400
|
||||||
resp.Msg = "Failure"
|
resp.Msg = "Failure"
|
||||||
}
|
}
|
||||||
|
} 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+"/services?offset="+offset+"&"+"limit="+limit,
|
||||||
|
bytes.NewBuffer([]byte("foo=bar")))
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
//return
|
||||||
|
}
|
||||||
|
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