update createalgorithmlogic #525
|
@ -16,11 +16,9 @@ package ai
|
|||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"github.com/go-resty/resty/v2"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/participant"
|
||||
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
|
||||
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/types"
|
||||
algorithm "gitlink.org.cn/JointCloud/pcm-coordinator/internal/types/ai"
|
||||
)
|
||||
|
||||
|
@ -38,21 +36,17 @@ func NewCreateAlgorithmLogic(ctx context.Context, svcCtx *svc.ServiceContext) *C
|
|||
}
|
||||
}
|
||||
|
||||
func (l *CreateAlgorithmLogic) CreateAlgorithm(req *algorithm.CreateAlgorithmReq) (resp *algorithm.CreateAlgorithmResp, err error) {
|
||||
|
||||
cluster := &types.GetClusterByIdResp{}
|
||||
tx := l.svcCtx.DbEngin.Raw("select * from t_cluster where id = ?", req.ClusterId).Scan(&cluster.ClusterInfo)
|
||||
if tx.Error != nil {
|
||||
logx.Errorf(tx.Error.Error())
|
||||
return nil, errors.New("cluster create failed")
|
||||
func (l *CreateAlgorithmLogic) CreateAlgorithm(req *algorithm.CreateAlgorithmReq) (resp interface{}, err error) {
|
||||
param := &participant.CreateParam{
|
||||
Name: req.Name,
|
||||
Desc: req.Desc,
|
||||
Src: req.Src,
|
||||
Param: req.Param,
|
||||
}
|
||||
|
||||
httpClient := resty.New().R()
|
||||
createAlgorithmResp := &algorithm.CreateAlgorithmResp{}
|
||||
_, err = httpClient.SetHeader("Content-Type", "application/json").
|
||||
SetQueryParams(map[string]string{"pfId": cluster.ClusterInfo.Id}).
|
||||
SetBody(req).
|
||||
SetResult(&createAlgorithmResp).
|
||||
Post(cluster.ClusterInfo.Server + "/ai/algorithm/create")
|
||||
return createAlgorithmResp, err
|
||||
create, err := l.svcCtx.Ai.AlgorithmCreateById(req.ClusterId, param)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resp = create.Data
|
||||
return
|
||||
}
|
||||
|
|
|
@ -16,12 +16,6 @@ package ai
|
|||
|
||||
import (
|
||||
"context"
|
||||
"github.com/jinzhu/copier"
|
||||
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/repository/result"
|
||||
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/utils"
|
||||
"gitlink.org.cn/JointCloud/pcm-modelarts/modelarts"
|
||||
"k8s.io/apimachinery/pkg/util/json"
|
||||
|
||||
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
|
||||
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/types"
|
||||
|
||||
|
@ -42,18 +36,11 @@ func NewListAlgorithmsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Li
|
|||
}
|
||||
}
|
||||
|
||||
func (l *ListAlgorithmsLogic) ListAlgorithms(req *types.ListAlgorithmsReq) (resp *types.ListAlgorithmsResp, err error) {
|
||||
modelartsReq := &modelarts.ListAlgorithmsReq{}
|
||||
err = copier.CopyWithOption(modelartsReq, req, copier.Option{IgnoreEmpty: false, DeepCopy: true, Converters: utils.Converters})
|
||||
ListAlgorithmsResp, err := l.svcCtx.ModelArtsRpc.ListAlgorithms(l.ctx, modelartsReq)
|
||||
func (l *ListAlgorithmsLogic) ListAlgorithms(req *types.ListAlgorithmsReq) (resp interface{}, err error) {
|
||||
list, err := l.svcCtx.Ai.AlgorithmById(req.ProjectId)
|
||||
if err != nil {
|
||||
return nil, result.NewDefaultError(err.Error())
|
||||
return nil, err
|
||||
}
|
||||
marshal, err := json.Marshal(&ListAlgorithmsResp)
|
||||
if err != nil {
|
||||
return nil, result.NewDefaultError(err.Error())
|
||||
}
|
||||
json.Unmarshal(marshal, &resp)
|
||||
err = copier.CopyWithOption(&resp, &ListAlgorithmsResp, copier.Option{Converters: utils.Converters})
|
||||
return resp, nil
|
||||
resp = list.Data
|
||||
return
|
||||
}
|
||||
|
|
|
@ -11,8 +11,8 @@ type CreateAlgorithmParameter interface {
|
|||
|
||||
type CreateAlgorithmReq struct {
|
||||
Name string `json:"name" binding:"required"`
|
||||
ClusterId string `json:"clusterId"`
|
||||
Desc string `json:"desc"`
|
||||
ClusterId string `json:"clusterId,omitempty"`
|
||||
Desc string `json:"desc,omitempty"`
|
||||
Src Source `json:"src,omitempty"`
|
||||
Param CreateAlgorithmParameter `json:"param,omitempty"`
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue