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