fix:创建开发环境接口修改

Former-commit-id: 3a39965b5425041431a41e716a3f949c51e5eb99
This commit is contained in:
qiwang 2023-05-18 16:45:22 +08:00
parent a55cc27689
commit 8fc3939653
1 changed files with 67 additions and 26 deletions

View File

@ -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,7 +31,12 @@ 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
createUrl := modelArtsUrl + "v1/{project_id}/notebooks"
token := common.GetToken()
@ -59,6 +69,37 @@ func (l *CreateNotebookLogic) CreateNotebook(in *modelarts.CreateNotebookReq) (*
}
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
}