fix:创建开发环境接口修改
Former-commit-id: 3a39965b5425041431a41e716a3f949c51e5eb99
This commit is contained in:
parent
a55cc27689
commit
8fc3939653
|
@ -1,13 +1,18 @@
|
|||
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"
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"io/ioutil"
|
||||
"k8s.io/apimachinery/pkg/util/json"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type CreateNotebookLogic struct {
|
||||
|
@ -26,38 +31,74 @@ func NewCreateNotebookLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Cr
|
|||
|
||||
func (l *CreateNotebookLogic) CreateNotebook(in *modelarts.CreateNotebookReq) (*modelarts.CreateNotebookResp, error) {
|
||||
resp := &modelarts.CreateNotebookResp{}
|
||||
createUrl := "https://modelarts.cn-north-4.myhuaweicloud.com/v1/{project_id}/notebooks"
|
||||
//根据智算类型判断走华为智算还是南京智算
|
||||
modelArtsType := in.ModelArtsType
|
||||
if modelArtsType == l.svcCtx.Config.HaweiModelArtsType {
|
||||
modelArtsUrl := l.svcCtx.Config.ModelArtsUrl
|
||||
|
||||
token := common.GetToken()
|
||||
createUrl := modelArtsUrl + "v1/{project_id}/notebooks"
|
||||
|
||||
var createResp modelarts.NotebookResp
|
||||
token := common.GetToken()
|
||||
|
||||
req := tool.GetACHttpRequest()
|
||||
res, err := req.
|
||||
SetHeader("x-auth-token", token).
|
||||
SetPathParam("project_id", in.ProjectId).
|
||||
SetBody(in.Param).
|
||||
SetResult(&createResp).
|
||||
Post(createUrl)
|
||||
var createResp modelarts.NotebookResp
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
req := tool.GetACHttpRequest()
|
||||
res, err := req.
|
||||
SetHeader("x-auth-token", token).
|
||||
SetPathParam("project_id", in.ProjectId).
|
||||
SetBody(in.Param).
|
||||
SetResult(&createResp).
|
||||
Post(createUrl)
|
||||
|
||||
if res.StatusCode() == 200 || res.StatusCode() == 201 {
|
||||
resp.NotebookResp = &createResp
|
||||
resp.Code = int32(res.StatusCode())
|
||||
resp.Msg = "Success"
|
||||
} else {
|
||||
resp.Code = int32(res.StatusCode())
|
||||
resp.Msg = "Failure"
|
||||
|
||||
var errMsg common.Error
|
||||
err := json.Unmarshal(res.Body(), &errMsg)
|
||||
if err != nil {
|
||||
errMsg.ErrorMsg = ""
|
||||
return nil, err
|
||||
}
|
||||
resp.ErrorMsg = errMsg.ErrorMsg
|
||||
|
||||
if res.StatusCode() == 200 || res.StatusCode() == 201 {
|
||||
resp.NotebookResp = &createResp
|
||||
resp.Code = int32(res.StatusCode())
|
||||
resp.Msg = "Success"
|
||||
} else {
|
||||
resp.Code = int32(res.StatusCode())
|
||||
resp.Msg = "Failure"
|
||||
|
||||
var errMsg common.Error
|
||||
err := json.Unmarshal(res.Body(), &errMsg)
|
||||
if err != nil {
|
||||
errMsg.ErrorMsg = ""
|
||||
}
|
||||
resp.ErrorMsg = errMsg.ErrorMsg
|
||||
}
|
||||
} 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,
|
||||
}
|
||||
reqByte, err := json.Marshal(in)
|
||||
r, err := http.NewRequest("POST", NanjingModelArtsUrl+"v1/"+in.ProjectId+"/notebooks",
|
||||
bytes.NewBuffer(reqByte))
|
||||
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
|
||||
|
|
Loading…
Reference in New Issue