modelarts notebook接口bug调整
This commit is contained in:
parent
14068d0ef9
commit
e51990d7d8
|
@ -64,3 +64,8 @@ type Auth struct {
|
|||
} `json:"scope"`
|
||||
} `json:"auth"`
|
||||
}
|
||||
|
||||
type Error struct {
|
||||
ErrorCode string `json:"error_code"`
|
||||
ErrorMsg string `json:"error_msg"`
|
||||
}
|
||||
|
|
|
@ -2,13 +2,11 @@ package logic
|
|||
|
||||
import (
|
||||
"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"
|
||||
"encoding/json"
|
||||
"strings"
|
||||
|
||||
"PCM/adaptor/PCM-AI/PCM-MODELARTS/rpc/internal/svc"
|
||||
"PCM/adaptor/PCM-AI/PCM-MODELARTS/rpc/modelarts"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
@ -28,19 +26,37 @@ func NewCreateNotebookLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Cr
|
|||
}
|
||||
|
||||
func (l *CreateNotebookLogic) CreateNotebook(in *modelarts.CreateNotebookReq) (*modelarts.CreateNotebookResp, error) {
|
||||
var resp modelarts.CreateNotebookResp
|
||||
resp := &modelarts.CreateNotebookResp{}
|
||||
createUrl := "https://modelarts.cn-north-4.myhuaweicloud.com/v1/{project_id}/notebooks"
|
||||
createUrl = strings.Replace(createUrl, "{project_id}", in.ProjectId, -1)
|
||||
reqByte, err := json.Marshal(in.Param)
|
||||
if err != nil {
|
||||
panic(err.Error())
|
||||
}
|
||||
payload := strings.NewReader(string(reqByte))
|
||||
|
||||
token := common.GetToken()
|
||||
body, err := tool.HttpClient(tool.POST, createUrl, payload, token)
|
||||
|
||||
req := tool.GetACHttpRequest()
|
||||
res, err := req.
|
||||
SetHeader("x-auth-token", token).
|
||||
SetPathParam("project_id", in.ProjectId).
|
||||
SetBody(in.Param).
|
||||
SetResult(resp.NotebookResp).
|
||||
Post(createUrl)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
json.Unmarshal(body, &resp.NotebookResp)
|
||||
return &resp, nil
|
||||
|
||||
if res.StatusCode() != 200 || res.StatusCode() != 201 {
|
||||
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 {
|
||||
resp.Code = int32(res.StatusCode())
|
||||
resp.Msg = "Success"
|
||||
}
|
||||
|
||||
return resp, nil
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ import (
|
|||
"PCM/adaptor/PCM-AI/PCM-MODELARTS/rpc/modelarts"
|
||||
"PCM/common/tool"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
|
@ -32,7 +33,7 @@ func (l *ListNotebookLogic) ListNotebook(in *modelarts.ListNotebookReq) (*modela
|
|||
queryMap := tool.ConvertStructToMap(in.Param)
|
||||
|
||||
req := tool.GetACHttpRequest()
|
||||
_, err := req.
|
||||
res, err := req.
|
||||
SetHeader("x-auth-token", token).
|
||||
SetPathParam("project_id", in.ProjectId).
|
||||
SetQueryParams(queryMap).
|
||||
|
@ -42,5 +43,21 @@ func (l *ListNotebookLogic) ListNotebook(in *modelarts.ListNotebookReq) (*modela
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if res.StatusCode() != 200 {
|
||||
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 {
|
||||
resp.Code = int32(res.StatusCode())
|
||||
resp.Msg = "Success"
|
||||
}
|
||||
|
||||
return resp, nil
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1669,7 +1669,11 @@ message ListNotebookResp{
|
|||
int32 pages = 3; // @gotags: copier:"Pages"
|
||||
int32 size = 4; // @gotags: copier:"Size"
|
||||
int64 total = 5; // @gotags: copier:"Total"
|
||||
int32 code = 6; // @gotags: copier:"Code"
|
||||
string msg = 7; // @gotags: copier:"Msg"
|
||||
string error_msg =8;// @gotags: copier:"ErrorMsg"
|
||||
}
|
||||
|
||||
message ListNotebookParam{
|
||||
string feature = 1; // @gotags: copier:"Feature"
|
||||
int32 limit = 2; // @gotags: copier:"Limit"
|
||||
|
@ -1689,6 +1693,9 @@ message CreateNotebookReq{
|
|||
}
|
||||
message CreateNotebookResp{
|
||||
NotebookResp notebookResp = 1; // @gotags: copier:"NotebookResp"
|
||||
int32 code = 2; // @gotags: copier:"Code"
|
||||
string msg = 3; // @gotags: copier:"Msg"
|
||||
string error_msg =4;// @gotags: copier:"ErrorMsg"
|
||||
}
|
||||
message CreateNotebookParam{
|
||||
string description = 1; // @gotags: copier:"Description"
|
||||
|
@ -1713,6 +1720,9 @@ message StartNotebookReq{
|
|||
}
|
||||
message StartNotebookResp{
|
||||
NotebookResp notebookResp = 1; // @gotags: copier:"NotebookResp"
|
||||
int32 code = 2; // @gotags: copier:"Code"
|
||||
string msg = 3; // @gotags: copier:"Msg"
|
||||
string error_msg =4;// @gotags: copier:"ErrorMsg"
|
||||
}
|
||||
message StartNotebookParam{
|
||||
int64 duration = 1; // @gotags: copier:"Duration"
|
||||
|
@ -1725,6 +1735,9 @@ message StopNotebookReq{
|
|||
}
|
||||
message StopNotebookResp{
|
||||
NotebookResp notebookResp = 1; // @gotags: copier:"NotebookResp"
|
||||
int32 code = 2; // @gotags: copier:"Code"
|
||||
string msg = 3; // @gotags: copier:"Msg"
|
||||
string error_msg =4;// @gotags: copier:"ErrorMsg"
|
||||
}
|
||||
|
||||
message GetNotebookStorageReq{
|
||||
|
|
|
@ -37,7 +37,7 @@ type (
|
|||
Datasets []DataSets `json:"data_sets" copier:"Datasets"`
|
||||
Code int32 `json:"code,omitempty"`
|
||||
Msg string `json:"msg,omitempty"`
|
||||
ErrorMsg string `json:"ErrorMsg,omitempty"`
|
||||
ErrorMsg string `json:"error_msg,omitempty"`
|
||||
}
|
||||
)
|
||||
|
||||
|
@ -1052,6 +1052,9 @@ type (
|
|||
Pages int32 `json:"pages" copier:"Pages"`
|
||||
Size int32 `json:"size" copier:"Size"`
|
||||
Total int64 `json:"total" copier:"Total"`
|
||||
Code int32 `json:"code,omitempty"`
|
||||
Msg string `json:"msg,omitempty"`
|
||||
ErrorMsg string `json:"error_msg,omitempty"`
|
||||
}
|
||||
ListNotebookParam {
|
||||
Feature string `json:"feature,optional" copier:"Feature"`
|
||||
|
@ -1071,20 +1074,23 @@ type (
|
|||
}
|
||||
CreateNotebookResp {
|
||||
NotebookResp NotebookResp `json:"notebookResp" copier:"NotebookResp"`
|
||||
Code int32 `json:"code,omitempty"`
|
||||
Msg string `json:"msg,omitempty"`
|
||||
ErrorMsg string `json:"error_msg,omitempty"`
|
||||
}
|
||||
CreateNotebookParam {
|
||||
Description string `json:"description" copier:"Description"`
|
||||
Duration int64 `json:"duration" copier:"Duration"`
|
||||
Endpoints []EndpointsReq `json:"endpoints" copier:"Endpoints"`
|
||||
Feature string `json:"feature" copier:"Feature"`
|
||||
Description string `json:"description,optional" copier:"Description"`
|
||||
Duration int64 `json:"duration,optional" copier:"Duration"`
|
||||
Endpoints []EndpointsReq `json:"endpoints,optional" copier:"Endpoints"`
|
||||
Feature string `json:"feature,optional" copier:"Feature"`
|
||||
Flavor string `json:"flavor" copier:"Flavor"`
|
||||
ImageId string `json:"image_id" copier:"ImageId"`
|
||||
Name string `json:"name" copier:"Name"`
|
||||
PoolId string `json:"pool_id" copier:"PoolId"`
|
||||
PoolId string `json:"pool_id,optional" copier:"PoolId"`
|
||||
Volume VolumeReq `json:"volume" copier:"Volume"`
|
||||
WorkspaceId string `json:"workspace_id" copier:"WorkspaceId"`
|
||||
Hooks CustomHooks `json:"hooks" copier:"Hooks"`
|
||||
Lease LeaseReq `json:"lease" copier:"Lease"`
|
||||
WorkspaceId string `json:"workspace_id,optional" copier:"WorkspaceId"`
|
||||
Hooks CustomHooks `json:"hooks,optional" copier:"Hooks"`
|
||||
Lease LeaseReq `json:"lease,optional" copier:"Lease"`
|
||||
}
|
||||
|
||||
StartNotebookReq {
|
||||
|
@ -1094,6 +1100,9 @@ type (
|
|||
}
|
||||
StartNotebookResp {
|
||||
NotebookResp NotebookResp `json:"notebookResp" copier:"NotebookResp"`
|
||||
Code int32 `json:"code,omitempty"`
|
||||
Msg string `json:"msg,omitempty"`
|
||||
ErrorMsg string `json:"error_msg,omitempty"`
|
||||
}
|
||||
StartNotebookParam {
|
||||
Duration int64 `json:"duration" copier:"Duration"`
|
||||
|
@ -1106,6 +1115,9 @@ type (
|
|||
}
|
||||
StopNotebookResp {
|
||||
NotebookResp NotebookResp `json:"notebookResp" copier:"NotebookResp"`
|
||||
Code int32 `json:"code,omitempty"`
|
||||
Msg string `json:"msg,omitempty"`
|
||||
ErrorMsg string `json:"error_msg,omitempty"`
|
||||
}
|
||||
|
||||
GetNotebookStorageReq {
|
||||
|
@ -1220,10 +1232,10 @@ type (
|
|||
SshKeys []string `json:"ssh_keys" copier:"SshKeys"`
|
||||
}
|
||||
VolumeReq {
|
||||
Capacity int64 `json:"capacity" copier:"Capacity"`
|
||||
Capacity int64 `json:"capacity,optional" copier:"Capacity"`
|
||||
Category string `json:"category" copier:"Category"`
|
||||
Ownership string `json:"ownership" copier:"Ownership"`
|
||||
Uri string `json:"uri" copier:"Uri"`
|
||||
Uri string `json:"uri,optional" copier:"Uri"`
|
||||
}
|
||||
CustomHooks {
|
||||
ContainerHooks ContainerHooks `json:"container_hooks" copier:"ContainerHooks"`
|
||||
|
|
|
@ -1,7 +1,12 @@
|
|||
package ai
|
||||
|
||||
import (
|
||||
"PCM/adaptor/PCM-AI/PCM-MODELARTS/rpc/modelarts"
|
||||
"PCM/common/tool"
|
||||
"PCM/common/xerr"
|
||||
"context"
|
||||
"github.com/jinzhu/copier"
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"PCM/adaptor/PCM-CORE/api/internal/svc"
|
||||
"PCM/adaptor/PCM-CORE/api/internal/types"
|
||||
|
@ -24,7 +29,15 @@ func NewCreateNotebookLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Cr
|
|||
}
|
||||
|
||||
func (l *CreateNotebookLogic) CreateNotebook(req *types.CreateNotebookReq) (resp *types.CreateNotebookResp, err error) {
|
||||
// todo: add your logic here and delete this line
|
||||
modelartsReq := &modelarts.CreateNotebookReq{}
|
||||
err = copier.CopyWithOption(modelartsReq, req, copier.Option{Converters: tool.Converters})
|
||||
createNotebookResp, err := l.svcCtx.ModelArtsRpc.CreateNotebook(l.ctx, modelartsReq)
|
||||
|
||||
return
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrMsg("Failed to create notebook"), "Failed to create notebook err : %v ,req:%+v", err, req)
|
||||
}
|
||||
resp = &types.CreateNotebookResp{}
|
||||
err = copier.CopyWithOption(resp, createNotebookResp, copier.Option{Converters: tool.Converters})
|
||||
|
||||
return resp, nil
|
||||
}
|
||||
|
|
|
@ -38,7 +38,7 @@ func (l *ListNotebookLogic) ListNotebook(req *types.ListNotebookReq) (resp *type
|
|||
}
|
||||
|
||||
resp = &types.ListNotebookResp{}
|
||||
err = copier.CopyWithOption(&resp, &listNotebookResp, copier.Option{Converters: tool.Converters})
|
||||
err = copier.CopyWithOption(resp, listNotebookResp, copier.Option{Converters: tool.Converters})
|
||||
|
||||
return resp, nil
|
||||
}
|
||||
|
|
|
@ -455,7 +455,7 @@ type DataSetResp struct {
|
|||
Datasets []DataSets `json:"data_sets" copier:"Datasets"`
|
||||
Code int32 `json:"code,omitempty"`
|
||||
Msg string `json:"msg,omitempty"`
|
||||
ErrorMsg string `json:"ErrorMsg,omitempty"`
|
||||
ErrorMsg string `json:"error_msg,omitempty"`
|
||||
}
|
||||
|
||||
type CreateDataSetReq struct {
|
||||
|
@ -1432,11 +1432,14 @@ type ListNotebookReq struct {
|
|||
}
|
||||
|
||||
type ListNotebookResp struct {
|
||||
Current int32 `json:"current" copier:"Current"`
|
||||
Data []NotebookResp `json:"data" copier:"Data"`
|
||||
Pages int32 `json:"pages" copier:"Pages"`
|
||||
Size int32 `json:"size" copier:"Size"`
|
||||
Total int64 `json:"total" copier:"Total"`
|
||||
Current int32 `json:"current" copier:"Current"`
|
||||
Data []NotebookResp `json:"data" copier:"Data"`
|
||||
Pages int32 `json:"pages" copier:"Pages"`
|
||||
Size int32 `json:"size" copier:"Size"`
|
||||
Total int64 `json:"total" copier:"Total"`
|
||||
Code int32 `json:"code,omitempty"`
|
||||
Msg string `json:"msg,omitempty"`
|
||||
ErrorMsg string `json:"error_msg,omitempty"`
|
||||
}
|
||||
|
||||
type ListNotebookParam struct {
|
||||
|
@ -1459,21 +1462,24 @@ type CreateNotebookReq struct {
|
|||
|
||||
type CreateNotebookResp struct {
|
||||
NotebookResp NotebookResp `json:"notebookResp" copier:"NotebookResp"`
|
||||
Code int32 `json:"code,omitempty"`
|
||||
Msg string `json:"msg,omitempty"`
|
||||
ErrorMsg string `json:"error_msg,omitempty"`
|
||||
}
|
||||
|
||||
type CreateNotebookParam struct {
|
||||
Description string `json:"description" copier:"Description"`
|
||||
Duration int64 `json:"duration" copier:"Duration"`
|
||||
Endpoints []EndpointsReq `json:"endpoints" copier:"Endpoints"`
|
||||
Feature string `json:"feature" copier:"Feature"`
|
||||
Description string `json:"description,optional" copier:"Description"`
|
||||
Duration int64 `json:"duration,optional" copier:"Duration"`
|
||||
Endpoints []EndpointsReq `json:"endpoints,optional" copier:"Endpoints"`
|
||||
Feature string `json:"feature,optional" copier:"Feature"`
|
||||
Flavor string `json:"flavor" copier:"Flavor"`
|
||||
ImageId string `json:"image_id" copier:"ImageId"`
|
||||
Name string `json:"name" copier:"Name"`
|
||||
PoolId string `json:"pool_id" copier:"PoolId"`
|
||||
PoolId string `json:"pool_id,optional" copier:"PoolId"`
|
||||
Volume VolumeReq `json:"volume" copier:"Volume"`
|
||||
WorkspaceId string `json:"workspace_id" copier:"WorkspaceId"`
|
||||
Hooks CustomHooks `json:"hooks" copier:"Hooks"`
|
||||
Lease LeaseReq `json:"lease" copier:"Lease"`
|
||||
WorkspaceId string `json:"workspace_id,optional" copier:"WorkspaceId"`
|
||||
Hooks CustomHooks `json:"hooks,optional" copier:"Hooks"`
|
||||
Lease LeaseReq `json:"lease,optional" copier:"Lease"`
|
||||
}
|
||||
|
||||
type StartNotebookReq struct {
|
||||
|
@ -1484,6 +1490,9 @@ type StartNotebookReq struct {
|
|||
|
||||
type StartNotebookResp struct {
|
||||
NotebookResp NotebookResp `json:"notebookResp" copier:"NotebookResp"`
|
||||
Code int32 `json:"code,omitempty"`
|
||||
Msg string `json:"msg,omitempty"`
|
||||
ErrorMsg string `json:"error_msg,omitempty"`
|
||||
}
|
||||
|
||||
type StartNotebookParam struct {
|
||||
|
@ -1498,6 +1507,9 @@ type StopNotebookReq struct {
|
|||
|
||||
type StopNotebookResp struct {
|
||||
NotebookResp NotebookResp `json:"notebookResp" copier:"NotebookResp"`
|
||||
Code int32 `json:"code,omitempty"`
|
||||
Msg string `json:"msg,omitempty"`
|
||||
ErrorMsg string `json:"error_msg,omitempty"`
|
||||
}
|
||||
|
||||
type GetNotebookStorageReq struct {
|
||||
|
@ -1624,10 +1636,10 @@ type EndpointsReq struct {
|
|||
}
|
||||
|
||||
type VolumeReq struct {
|
||||
Capacity int64 `json:"capacity" copier:"Capacity"`
|
||||
Capacity int64 `json:"capacity,optional" copier:"Capacity"`
|
||||
Category string `json:"category" copier:"Category"`
|
||||
Ownership string `json:"ownership" copier:"Ownership"`
|
||||
Uri string `json:"uri" copier:"Uri"`
|
||||
Uri string `json:"uri,optional" copier:"Uri"`
|
||||
}
|
||||
|
||||
type CustomHooks struct {
|
||||
|
|
Loading…
Reference in New Issue