fix:查询获取训练作业支持的公共规格接口
Former-commit-id: aaf29aa556ca567311d2735b47ffddae03be59dd
This commit is contained in:
parent
f9bf686ede
commit
99b841b078
|
@ -0,0 +1,88 @@
|
|||
package logic
|
||||
|
||||
import (
|
||||
"APIGW-go-sdk/core"
|
||||
"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/modelarts"
|
||||
"PCM/common/tool"
|
||||
"context"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"k8s.io/apimachinery/pkg/util/json"
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type GetTrainingJobFlavorsLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewGetTrainingJobFlavorsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetTrainingJobFlavorsLogic {
|
||||
return &GetTrainingJobFlavorsLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
// training-job-flavors 获取训练作业支持的公共规格
|
||||
func (l *GetTrainingJobFlavorsLogic) GetTrainingJobFlavors(in *modelarts.TrainingJobFlavorsReq) (*modelarts.TrainingJobFlavorsResp, error) {
|
||||
// todo: add your logic here and delete this line
|
||||
var resp modelarts.TrainingJobFlavorsResp
|
||||
//根据智算类型判断走华为智算还是南京智算
|
||||
modelArtsType := in.ModelArtsType
|
||||
if modelArtsType == l.svcCtx.Config.HaweiModelArtsType {
|
||||
modelArtsUrl := l.svcCtx.Config.ModelArtsUrl
|
||||
url := modelArtsUrl + "v2/" + in.ProjectId + "/training-job-flavors?flavor_type=" + in.FlavorType
|
||||
token := common.GetToken()
|
||||
statusCode, body, err := tool.HttpClientWithBodyAndCode(tool.GET, url, nil, token)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if statusCode == 200 {
|
||||
json.Unmarshal(body, &resp)
|
||||
resp.Code = 200
|
||||
resp.Msg = "Success"
|
||||
} else if statusCode != 200 {
|
||||
json.Unmarshal(body, &resp)
|
||||
resp.Code = 400
|
||||
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
|
||||
XDomainId := l.svcCtx.Config.XDomainId
|
||||
s := core.Signer{
|
||||
Key: AK,
|
||||
Secret: SK,
|
||||
}
|
||||
r, err := http.NewRequest("GET", NanjingModelArtsUrl+"v2/"+in.ProjectId+"/training-job-flavors?flavor_type="+in.FlavorType,
|
||||
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-Domain-Id", XDomainId)
|
||||
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
|
||||
}
|
Loading…
Reference in New Issue