modelarts notebook接口bug调整

This commit is contained in:
tzwang 2023-05-12 18:26:31 +08:00
parent 14068d0ef9
commit e51990d7d8
9 changed files with 824 additions and 623 deletions

View File

@ -64,3 +64,8 @@ type Auth struct {
} `json:"scope"` } `json:"scope"`
} `json:"auth"` } `json:"auth"`
} }
type Error struct {
ErrorCode string `json:"error_code"`
ErrorMsg string `json:"error_msg"`
}

View File

@ -2,13 +2,11 @@ package logic
import ( import (
"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/modelarts"
"PCM/common/tool" "PCM/common/tool"
"context" "context"
"encoding/json" "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" "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) { 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 := "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() 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 { if err != nil {
return nil, err 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
} }

View File

@ -6,6 +6,7 @@ import (
"PCM/adaptor/PCM-AI/PCM-MODELARTS/rpc/modelarts" "PCM/adaptor/PCM-AI/PCM-MODELARTS/rpc/modelarts"
"PCM/common/tool" "PCM/common/tool"
"context" "context"
"encoding/json"
"github.com/zeromicro/go-zero/core/logx" "github.com/zeromicro/go-zero/core/logx"
) )
@ -32,7 +33,7 @@ func (l *ListNotebookLogic) ListNotebook(in *modelarts.ListNotebookReq) (*modela
queryMap := tool.ConvertStructToMap(in.Param) queryMap := tool.ConvertStructToMap(in.Param)
req := tool.GetACHttpRequest() req := tool.GetACHttpRequest()
_, err := req. res, err := req.
SetHeader("x-auth-token", token). SetHeader("x-auth-token", token).
SetPathParam("project_id", in.ProjectId). SetPathParam("project_id", in.ProjectId).
SetQueryParams(queryMap). SetQueryParams(queryMap).
@ -42,5 +43,21 @@ func (l *ListNotebookLogic) ListNotebook(in *modelarts.ListNotebookReq) (*modela
if err != nil { if err != nil {
return nil, err 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 return resp, nil
} }

File diff suppressed because it is too large Load Diff

View File

@ -1669,7 +1669,11 @@ message ListNotebookResp{
int32 pages = 3; // @gotags: copier:"Pages" int32 pages = 3; // @gotags: copier:"Pages"
int32 size = 4; // @gotags: copier:"Size" int32 size = 4; // @gotags: copier:"Size"
int64 total = 5; // @gotags: copier:"Total" 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{ message ListNotebookParam{
string feature = 1; // @gotags: copier:"Feature" string feature = 1; // @gotags: copier:"Feature"
int32 limit = 2; // @gotags: copier:"Limit" int32 limit = 2; // @gotags: copier:"Limit"
@ -1689,6 +1693,9 @@ message CreateNotebookReq{
} }
message CreateNotebookResp{ message CreateNotebookResp{
NotebookResp notebookResp = 1; // @gotags: copier:"NotebookResp" 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{ message CreateNotebookParam{
string description = 1; // @gotags: copier:"Description" string description = 1; // @gotags: copier:"Description"
@ -1713,6 +1720,9 @@ message StartNotebookReq{
} }
message StartNotebookResp{ message StartNotebookResp{
NotebookResp notebookResp = 1; // @gotags: copier:"NotebookResp" 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{ message StartNotebookParam{
int64 duration = 1; // @gotags: copier:"Duration" int64 duration = 1; // @gotags: copier:"Duration"
@ -1725,6 +1735,9 @@ message StopNotebookReq{
} }
message StopNotebookResp{ message StopNotebookResp{
NotebookResp notebookResp = 1; // @gotags: copier:"NotebookResp" 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{ message GetNotebookStorageReq{

View File

@ -37,7 +37,7 @@ type (
Datasets []DataSets `json:"data_sets" copier:"Datasets"` Datasets []DataSets `json:"data_sets" copier:"Datasets"`
Code int32 `json:"code,omitempty"` Code int32 `json:"code,omitempty"`
Msg string `json:"msg,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"` Pages int32 `json:"pages" copier:"Pages"`
Size int32 `json:"size" copier:"Size"` Size int32 `json:"size" copier:"Size"`
Total int64 `json:"total" copier:"Total"` Total int64 `json:"total" copier:"Total"`
Code int32 `json:"code,omitempty"`
Msg string `json:"msg,omitempty"`
ErrorMsg string `json:"error_msg,omitempty"`
} }
ListNotebookParam { ListNotebookParam {
Feature string `json:"feature,optional" copier:"Feature"` Feature string `json:"feature,optional" copier:"Feature"`
@ -1071,20 +1074,23 @@ type (
} }
CreateNotebookResp { CreateNotebookResp {
NotebookResp NotebookResp `json:"notebookResp" copier:"NotebookResp"` NotebookResp NotebookResp `json:"notebookResp" copier:"NotebookResp"`
Code int32 `json:"code,omitempty"`
Msg string `json:"msg,omitempty"`
ErrorMsg string `json:"error_msg,omitempty"`
} }
CreateNotebookParam { CreateNotebookParam {
Description string `json:"description" copier:"Description"` Description string `json:"description,optional" copier:"Description"`
Duration int64 `json:"duration" copier:"Duration"` Duration int64 `json:"duration,optional" copier:"Duration"`
Endpoints []EndpointsReq `json:"endpoints" copier:"Endpoints"` Endpoints []EndpointsReq `json:"endpoints,optional" copier:"Endpoints"`
Feature string `json:"feature" copier:"Feature"` Feature string `json:"feature,optional" copier:"Feature"`
Flavor string `json:"flavor" copier:"Flavor"` Flavor string `json:"flavor" copier:"Flavor"`
ImageId string `json:"image_id" copier:"ImageId"` ImageId string `json:"image_id" copier:"ImageId"`
Name string `json:"name" copier:"Name"` 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"` Volume VolumeReq `json:"volume" copier:"Volume"`
WorkspaceId string `json:"workspace_id" copier:"WorkspaceId"` WorkspaceId string `json:"workspace_id,optional" copier:"WorkspaceId"`
Hooks CustomHooks `json:"hooks" copier:"Hooks"` Hooks CustomHooks `json:"hooks,optional" copier:"Hooks"`
Lease LeaseReq `json:"lease" copier:"Lease"` Lease LeaseReq `json:"lease,optional" copier:"Lease"`
} }
StartNotebookReq { StartNotebookReq {
@ -1094,6 +1100,9 @@ type (
} }
StartNotebookResp { StartNotebookResp {
NotebookResp NotebookResp `json:"notebookResp" copier:"NotebookResp"` NotebookResp NotebookResp `json:"notebookResp" copier:"NotebookResp"`
Code int32 `json:"code,omitempty"`
Msg string `json:"msg,omitempty"`
ErrorMsg string `json:"error_msg,omitempty"`
} }
StartNotebookParam { StartNotebookParam {
Duration int64 `json:"duration" copier:"Duration"` Duration int64 `json:"duration" copier:"Duration"`
@ -1106,6 +1115,9 @@ type (
} }
StopNotebookResp { StopNotebookResp {
NotebookResp NotebookResp `json:"notebookResp" copier:"NotebookResp"` NotebookResp NotebookResp `json:"notebookResp" copier:"NotebookResp"`
Code int32 `json:"code,omitempty"`
Msg string `json:"msg,omitempty"`
ErrorMsg string `json:"error_msg,omitempty"`
} }
GetNotebookStorageReq { GetNotebookStorageReq {
@ -1220,10 +1232,10 @@ type (
SshKeys []string `json:"ssh_keys" copier:"SshKeys"` SshKeys []string `json:"ssh_keys" copier:"SshKeys"`
} }
VolumeReq { VolumeReq {
Capacity int64 `json:"capacity" copier:"Capacity"` Capacity int64 `json:"capacity,optional" copier:"Capacity"`
Category string `json:"category" copier:"Category"` Category string `json:"category" copier:"Category"`
Ownership string `json:"ownership" copier:"Ownership"` Ownership string `json:"ownership" copier:"Ownership"`
Uri string `json:"uri" copier:"Uri"` Uri string `json:"uri,optional" copier:"Uri"`
} }
CustomHooks { CustomHooks {
ContainerHooks ContainerHooks `json:"container_hooks" copier:"ContainerHooks"` ContainerHooks ContainerHooks `json:"container_hooks" copier:"ContainerHooks"`

View File

@ -1,7 +1,12 @@
package ai package ai
import ( import (
"PCM/adaptor/PCM-AI/PCM-MODELARTS/rpc/modelarts"
"PCM/common/tool"
"PCM/common/xerr"
"context" "context"
"github.com/jinzhu/copier"
"github.com/pkg/errors"
"PCM/adaptor/PCM-CORE/api/internal/svc" "PCM/adaptor/PCM-CORE/api/internal/svc"
"PCM/adaptor/PCM-CORE/api/internal/types" "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) { 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
} }

View File

@ -38,7 +38,7 @@ func (l *ListNotebookLogic) ListNotebook(req *types.ListNotebookReq) (resp *type
} }
resp = &types.ListNotebookResp{} 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 return resp, nil
} }

View File

@ -455,7 +455,7 @@ type DataSetResp struct {
Datasets []DataSets `json:"data_sets" copier:"Datasets"` Datasets []DataSets `json:"data_sets" copier:"Datasets"`
Code int32 `json:"code,omitempty"` Code int32 `json:"code,omitempty"`
Msg string `json:"msg,omitempty"` Msg string `json:"msg,omitempty"`
ErrorMsg string `json:"ErrorMsg,omitempty"` ErrorMsg string `json:"error_msg,omitempty"`
} }
type CreateDataSetReq struct { type CreateDataSetReq struct {
@ -1432,11 +1432,14 @@ type ListNotebookReq struct {
} }
type ListNotebookResp struct { type ListNotebookResp struct {
Current int32 `json:"current" copier:"Current"` Current int32 `json:"current" copier:"Current"`
Data []NotebookResp `json:"data" copier:"Data"` Data []NotebookResp `json:"data" copier:"Data"`
Pages int32 `json:"pages" copier:"Pages"` Pages int32 `json:"pages" copier:"Pages"`
Size int32 `json:"size" copier:"Size"` Size int32 `json:"size" copier:"Size"`
Total int64 `json:"total" copier:"Total"` 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 { type ListNotebookParam struct {
@ -1459,21 +1462,24 @@ type CreateNotebookReq struct {
type CreateNotebookResp struct { type CreateNotebookResp struct {
NotebookResp NotebookResp `json:"notebookResp" copier:"NotebookResp"` 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 { type CreateNotebookParam struct {
Description string `json:"description" copier:"Description"` Description string `json:"description,optional" copier:"Description"`
Duration int64 `json:"duration" copier:"Duration"` Duration int64 `json:"duration,optional" copier:"Duration"`
Endpoints []EndpointsReq `json:"endpoints" copier:"Endpoints"` Endpoints []EndpointsReq `json:"endpoints,optional" copier:"Endpoints"`
Feature string `json:"feature" copier:"Feature"` Feature string `json:"feature,optional" copier:"Feature"`
Flavor string `json:"flavor" copier:"Flavor"` Flavor string `json:"flavor" copier:"Flavor"`
ImageId string `json:"image_id" copier:"ImageId"` ImageId string `json:"image_id" copier:"ImageId"`
Name string `json:"name" copier:"Name"` 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"` Volume VolumeReq `json:"volume" copier:"Volume"`
WorkspaceId string `json:"workspace_id" copier:"WorkspaceId"` WorkspaceId string `json:"workspace_id,optional" copier:"WorkspaceId"`
Hooks CustomHooks `json:"hooks" copier:"Hooks"` Hooks CustomHooks `json:"hooks,optional" copier:"Hooks"`
Lease LeaseReq `json:"lease" copier:"Lease"` Lease LeaseReq `json:"lease,optional" copier:"Lease"`
} }
type StartNotebookReq struct { type StartNotebookReq struct {
@ -1484,6 +1490,9 @@ type StartNotebookReq struct {
type StartNotebookResp struct { type StartNotebookResp struct {
NotebookResp NotebookResp `json:"notebookResp" copier:"NotebookResp"` 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 { type StartNotebookParam struct {
@ -1498,6 +1507,9 @@ type StopNotebookReq struct {
type StopNotebookResp struct { type StopNotebookResp struct {
NotebookResp NotebookResp `json:"notebookResp" copier:"NotebookResp"` 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 { type GetNotebookStorageReq struct {
@ -1624,10 +1636,10 @@ type EndpointsReq struct {
} }
type VolumeReq struct { type VolumeReq struct {
Capacity int64 `json:"capacity" copier:"Capacity"` Capacity int64 `json:"capacity,optional" copier:"Capacity"`
Category string `json:"category" copier:"Category"` Category string `json:"category" copier:"Category"`
Ownership string `json:"ownership" copier:"Ownership"` Ownership string `json:"ownership" copier:"Ownership"`
Uri string `json:"uri" copier:"Uri"` Uri string `json:"uri,optional" copier:"Uri"`
} }
type CustomHooks struct { type CustomHooks struct {