diff --git a/internal/logic/ai/createalgorithmlogic.go b/internal/logic/ai/createalgorithmlogic.go index d04c5ad88..c618d0ba7 100644 --- a/internal/logic/ai/createalgorithmlogic.go +++ b/internal/logic/ai/createalgorithmlogic.go @@ -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 } diff --git a/internal/logic/ai/createdatasetlogic.go b/internal/logic/ai/createdatasetlogic.go index 9fbfc1b91..b1619d236 100644 --- a/internal/logic/ai/createdatasetlogic.go +++ b/internal/logic/ai/createdatasetlogic.go @@ -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 } diff --git a/internal/logic/ai/createmodellogic.go b/internal/logic/ai/createmodellogic.go index 08f73781d..f40e92568 100644 --- a/internal/logic/ai/createmodellogic.go +++ b/internal/logic/ai/createmodellogic.go @@ -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 } diff --git a/internal/logic/ai/taskresultsynclogic.go b/internal/logic/ai/taskresultsynclogic.go index 2c8019e72..3c490e85f 100644 --- a/internal/logic/ai/taskresultsynclogic.go +++ b/internal/logic/ai/taskresultsynclogic.go @@ -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 } diff --git a/internal/participant/model.go b/internal/participant/model.go index 43f87bba3..d0237973b 100644 --- a/internal/participant/model.go +++ b/internal/participant/model.go @@ -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"` }