fit:修改modelarts proto
This commit is contained in:
parent
ba8f9500da
commit
c487204e23
|
@ -0,0 +1,31 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"flag"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"PCM/adaptor/AIComputing/AICore/api/internal/config"
|
||||||
|
"PCM/adaptor/AIComputing/AICore/api/internal/handler"
|
||||||
|
"PCM/adaptor/AIComputing/AICore/api/internal/svc"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/core/conf"
|
||||||
|
"github.com/zeromicro/go-zero/rest"
|
||||||
|
)
|
||||||
|
|
||||||
|
var configFile = flag.String("f", "adaptor/AIComputing/AICore/api/etc/aicore-api.yaml", "the config file")
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
flag.Parse()
|
||||||
|
|
||||||
|
var c config.Config
|
||||||
|
conf.MustLoad(*configFile, &c)
|
||||||
|
|
||||||
|
server := rest.MustNewServer(c.RestConf)
|
||||||
|
defer server.Stop()
|
||||||
|
|
||||||
|
ctx := svc.NewServiceContext(c)
|
||||||
|
handler.RegisterHandlers(server, ctx)
|
||||||
|
|
||||||
|
fmt.Printf("Starting server at %s:%d...\n", c.Host, c.Port)
|
||||||
|
server.Start()
|
||||||
|
}
|
|
@ -0,0 +1,9 @@
|
||||||
|
Name: AICore-api
|
||||||
|
Host: 0.0.0.0
|
||||||
|
Port: 8888
|
||||||
|
|
||||||
|
#rpc
|
||||||
|
ModelartsRpcConf:
|
||||||
|
Endpoints:
|
||||||
|
- 127.0.0.1:2003
|
||||||
|
NonBlock: true
|
|
@ -0,0 +1,12 @@
|
||||||
|
package config
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/zeromicro/go-zero/rest"
|
||||||
|
"github.com/zeromicro/go-zero/zrpc"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Config struct {
|
||||||
|
rest.RestConf
|
||||||
|
|
||||||
|
ModelartsRpcConf zrpc.RpcClientConf
|
||||||
|
}
|
|
@ -0,0 +1,28 @@
|
||||||
|
package handler
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"PCM/adaptor/AIComputing/AICore/api/internal/logic"
|
||||||
|
"PCM/adaptor/AIComputing/AICore/api/internal/svc"
|
||||||
|
"PCM/adaptor/AIComputing/AICore/api/internal/types"
|
||||||
|
"github.com/zeromicro/go-zero/rest/httpx"
|
||||||
|
)
|
||||||
|
|
||||||
|
func listDataSetHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
var req types.ListDataSetReq
|
||||||
|
if err := httpx.Parse(r, &req); err != nil {
|
||||||
|
httpx.ErrorCtx(r.Context(), w, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
l := logic.NewListDataSetLogic(r.Context(), svcCtx)
|
||||||
|
resp, err := l.ListDataSet(&req)
|
||||||
|
if err != nil {
|
||||||
|
httpx.ErrorCtx(r.Context(), w, err)
|
||||||
|
} else {
|
||||||
|
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,22 @@
|
||||||
|
// Code generated by goctl. DO NOT EDIT.
|
||||||
|
package handler
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"PCM/adaptor/AIComputing/AICore/api/internal/svc"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/rest"
|
||||||
|
)
|
||||||
|
|
||||||
|
func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
||||||
|
server.AddRoutes(
|
||||||
|
[]rest.Route{
|
||||||
|
{
|
||||||
|
Method: http.MethodGet,
|
||||||
|
Path: "/listDataSet",
|
||||||
|
Handler: listDataSetHandler(serverCtx),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
|
@ -0,0 +1,21 @@
|
||||||
|
package svc
|
||||||
|
|
||||||
|
import (
|
||||||
|
"PCM/adaptor/AIComputing/AICore/api/internal/config"
|
||||||
|
"PCM/adaptor/AIComputing/modelarts/rpc/modelartsclient"
|
||||||
|
"github.com/zeromicro/go-zero/zrpc"
|
||||||
|
)
|
||||||
|
|
||||||
|
type ServiceContext struct {
|
||||||
|
Config config.Config
|
||||||
|
|
||||||
|
ModelArtsRpc modelartsclient.ModelArts
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewServiceContext(c config.Config) *ServiceContext {
|
||||||
|
return &ServiceContext{
|
||||||
|
Config: c,
|
||||||
|
|
||||||
|
ModelArtsRpc: modelartsclient.NewModelArts(zrpc.MustNewClient(c.ModelartsRpcConf)),
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,50 @@
|
||||||
|
package logic
|
||||||
|
|
||||||
|
import (
|
||||||
|
"PCM/adaptor/AIComputing/modelarts/rpc/internal/common"
|
||||||
|
"PCM/common/tool"
|
||||||
|
"context"
|
||||||
|
"k8s.io/apimachinery/pkg/util/json"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"PCM/adaptor/AIComputing/modelarts/rpc/internal/svc"
|
||||||
|
"PCM/adaptor/AIComputing/modelarts/rpc/modelarts"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
|
)
|
||||||
|
|
||||||
|
type CreateDataSetLogic struct {
|
||||||
|
ctx context.Context
|
||||||
|
svcCtx *svc.ServiceContext
|
||||||
|
logx.Logger
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewCreateDataSetLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateDataSetLogic {
|
||||||
|
return &CreateDataSetLogic{
|
||||||
|
ctx: ctx,
|
||||||
|
svcCtx: svcCtx,
|
||||||
|
Logger: logx.WithContext(ctx),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// create DateSet
|
||||||
|
func (l *CreateDataSetLogic) CreateDataSet(in *modelarts.CreateDataSetReq) (*modelarts.CreateDataSetResq, error) {
|
||||||
|
// todo: add your logic here and delete this line
|
||||||
|
var resp modelarts.CreateDataSetResq
|
||||||
|
url := "https://modelarts.cn-north-4.myhuaweicloud.com/v2/" + in.ProjectId + "/datasets"
|
||||||
|
reqByte, err := json.Marshal(in)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
payload := strings.NewReader(string(reqByte))
|
||||||
|
token := common.GetToken()
|
||||||
|
body, err := tool.HttpClient(tool.POST, url, payload, token)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
json.Unmarshal(body, &resp)
|
||||||
|
if &resp == nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return &resp, nil
|
||||||
|
}
|
Loading…
Reference in New Issue