fix:查询开发环境接口修改

Former-commit-id: 271f1e85ef8aa460de784df2d52986bccc69c2cd
This commit is contained in:
qiwang 2023-05-18 16:04:03 +08:00
parent 03d498f4d5
commit 9d0b9b4cae
1 changed files with 49 additions and 8 deletions

View File

@ -1,14 +1,19 @@
package logic 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/bitly/go-simplejson" "github.com/bitly/go-simplejson"
"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"
) )
@ -31,7 +36,11 @@ func (l *ListTrainingJobConfigLogic) ListTrainingJobConfig(in *modelarts.ListTra
var resp modelarts.ListTrainingJobConfigResp var resp modelarts.ListTrainingJobConfigResp
perPage := strconv.Itoa(int(in.PerPage)) perPage := strconv.Itoa(int(in.PerPage))
page := strconv.Itoa(int(in.Page)) page := strconv.Itoa(int(in.Page))
url := "https://modelarts.cn-north-4.myhuaweicloud.com/v1/" + in.ProjectId + "/training-job-configs?" + perPage + "&" + page //根据智算类型判断走华为智算还是南京智算
modelArtsType := in.ModelArtsType
if modelArtsType == l.svcCtx.Config.HaweiModelArtsType {
modelArtsUrl := l.svcCtx.Config.ModelArtsUrl
url := modelArtsUrl + "v1/" + in.ProjectId + "/training-job-configs?" + perPage + "&" + page
token := common.GetToken() token := common.GetToken()
body, err := tool.HttpClient(tool.GET, url, nil, token) body, err := tool.HttpClient(tool.GET, url, nil, token)
if err != nil { if err != nil {
@ -40,5 +49,37 @@ func (l *ListTrainingJobConfigLogic) ListTrainingJobConfig(in *modelarts.ListTra
jsonResult, err := simplejson.NewJson(body) jsonResult, err := simplejson.NewJson(body)
println(&jsonResult) println(&jsonResult)
json.Unmarshal(body, &resp) json.Unmarshal(body, &resp)
} 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+"/training-job-configs?"+perPage+"&"+page,
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
} }