Merge pull request 'update create methods' (#526) from tzwang/pcm-coordinator:master into master

This commit is contained in:
tzwang 2025-07-18 11:44:00 +08:00
commit 1ec0a6709a
5 changed files with 55 additions and 55 deletions

View File

@ -16,10 +16,12 @@ package ai
import (
"context"
"errors"
"github.com/zeromicro/go-zero/core/logx"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/participant"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
algorithm "gitlink.org.cn/JointCloud/pcm-coordinator/internal/types/ai"
"net/http"
)
type CreateAlgorithmLogic struct {
@ -47,6 +49,9 @@ func (l *CreateAlgorithmLogic) CreateAlgorithm(req *algorithm.CreateAlgorithmReq
if err != nil {
return nil, err
}
if create.Code != http.StatusOK {
return nil, errors.New(create.Message)
}
resp = create.Data
return
}

View File

@ -16,12 +16,12 @@ package ai
import (
"context"
"github.com/go-resty/resty/v2"
"github.com/pkg/errors"
"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"
dataset "gitlink.org.cn/JointCloud/pcm-coordinator/internal/types/ai"
"net/http"
)
type CreateDataSetLogic struct {
@ -38,22 +38,21 @@ func NewCreateDataSetLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Cre
}
}
func (l *CreateDataSetLogic) CreateDataSet(req *dataset.CreateDatasetReq) (resp *dataset.CreateDatasetResp, 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 *CreateDataSetLogic) CreateDataSet(req *dataset.CreateDatasetReq) (resp interface{}, err error) {
param := &participant.CreateParam{
Name: req.Name,
Desc: req.Desc,
Src: req.Src,
Param: req.Param,
}
httpClient := resty.New().R()
createDatasetResp := &dataset.CreateDatasetResp{}
_, err = httpClient.SetHeader("Content-Type", "application/json").
SetQueryParams(map[string]string{"pfId": cluster.ClusterInfo.Id}).
SetBody(req).
SetResult(&createDatasetResp).
Post(cluster.ClusterInfo.Server + "/ai/dataset/create")
return createDatasetResp, err
create, err := l.svcCtx.Ai.DatasetCreateById(req.ClusterId, param)
if err != nil {
return nil, err
}
if create.Code != http.StatusOK {
return nil, errors.New(create.Message)
}
resp = create.Data
return
}

View File

@ -16,12 +16,12 @@ package ai
import (
"context"
"github.com/go-resty/resty/v2"
"github.com/pkg/errors"
"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"
model "gitlink.org.cn/JointCloud/pcm-coordinator/internal/types/ai"
"net/http"
)
type CreateModelLogic struct {
@ -38,22 +38,20 @@ func NewCreateModelLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Creat
}
}
func (l *CreateModelLogic) CreateModel(req *model.CreateModelReq) (resp *model.CreateModelResp, 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 *CreateModelLogic) CreateModel(req *model.CreateModelReq) (resp interface{}, err error) {
param := &participant.CreateParam{
Name: req.Name,
Desc: req.Desc,
Src: req.Src,
Param: req.Param,
}
httpClient := resty.New().R()
createModelResp := &model.CreateModelResp{}
_, err = httpClient.SetHeader("Content-Type", "application/json").
SetQueryParams(map[string]string{"pfId": cluster.ClusterInfo.Id}).
SetBody(req).
SetResult(&createModelResp).
Post(cluster.ClusterInfo.Server + "/ai/model/create")
return createModelResp, err
create, err := l.svcCtx.Ai.ModelCreateById(req.ClusterId, param)
if err != nil {
return nil, err
}
if create.Code != http.StatusOK {
return nil, errors.New(create.Message)
}
resp = create.Data
return
}

View File

@ -16,12 +16,12 @@ package ai
import (
"context"
"github.com/go-resty/resty/v2"
"github.com/pkg/errors"
"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"
sync "gitlink.org.cn/JointCloud/pcm-coordinator/internal/types/ai"
"net/http"
)
type TaskResultSyncLogic struct {
@ -38,22 +38,20 @@ func NewTaskResultSyncLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Ta
}
}
func (l *TaskResultSyncLogic) TaskResultSync(req *sync.ResultSyncReq) (resp *sync.ResultSyncResp, err error) {
func (l *TaskResultSyncLogic) TaskResultSync(req *sync.ResultSyncReq) (resp interface{}, 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")
param := &participant.TaskResultSyncParam{
Src: req.Src,
Param: req.Param,
}
httpClient := resty.New().R()
createModelResp := &sync.ResultSyncResp{}
_, err = httpClient.SetHeader("Content-Type", "application/json").
SetQueryParams(map[string]string{"pfId": cluster.ClusterInfo.Id}).
SetBody(req).
SetResult(&createModelResp).
Post(cluster.ClusterInfo.Server + "/ai/task/sync")
return createModelResp, err
rs, err := l.svcCtx.Ai.TaskResultSync(req.ClusterId, param)
if err != nil {
return nil, err
}
if rs.Code != http.StatusOK {
return nil, errors.New(rs.Message)
}
resp = rs.Data
return
}

View File

@ -7,7 +7,7 @@ type RespErr struct {
type Resp struct {
Code int32 `json:"code"`
Message string `json:"message"`
Message string `json:"msg"`
Data interface{} `json:"data"`
}