Browse Source

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

pull/527/head
tzwang 4 months ago
parent
commit
1ec0a6709a
5 changed files with 55 additions and 55 deletions
  1. +5
    -0
      internal/logic/ai/createalgorithmlogic.go
  2. +17
    -18
      internal/logic/ai/createdatasetlogic.go
  3. +17
    -19
      internal/logic/ai/createmodellogic.go
  4. +15
    -17
      internal/logic/ai/taskresultsynclogic.go
  5. +1
    -1
      internal/participant/model.go

+ 5
- 0
internal/logic/ai/createalgorithmlogic.go View File

@@ -16,10 +16,12 @@ package ai


import ( import (
"context" "context"
"errors"
"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/participant"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc" "gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
algorithm "gitlink.org.cn/JointCloud/pcm-coordinator/internal/types/ai" algorithm "gitlink.org.cn/JointCloud/pcm-coordinator/internal/types/ai"
"net/http"
) )


type CreateAlgorithmLogic struct { type CreateAlgorithmLogic struct {
@@ -47,6 +49,9 @@ func (l *CreateAlgorithmLogic) CreateAlgorithm(req *algorithm.CreateAlgorithmReq
if err != nil { if err != nil {
return nil, err return nil, err
} }
if create.Code != http.StatusOK {
return nil, errors.New(create.Message)
}
resp = create.Data resp = create.Data
return return
} }

+ 17
- 18
internal/logic/ai/createdatasetlogic.go View File

@@ -16,12 +16,12 @@ package ai


import ( import (
"context" "context"
"github.com/go-resty/resty/v2"
"github.com/pkg/errors" "github.com/pkg/errors"
"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"
dataset "gitlink.org.cn/JointCloud/pcm-coordinator/internal/types/ai" dataset "gitlink.org.cn/JointCloud/pcm-coordinator/internal/types/ai"
"net/http"
) )


type CreateDataSetLogic struct { 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


} }

+ 17
- 19
internal/logic/ai/createmodellogic.go View File

@@ -16,12 +16,12 @@ package ai


import ( import (
"context" "context"
"github.com/go-resty/resty/v2"
"github.com/pkg/errors" "github.com/pkg/errors"
"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"
model "gitlink.org.cn/JointCloud/pcm-coordinator/internal/types/ai" model "gitlink.org.cn/JointCloud/pcm-coordinator/internal/types/ai"
"net/http"
) )


type CreateModelLogic struct { 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
} }

+ 15
- 17
internal/logic/ai/taskresultsynclogic.go View File

@@ -16,12 +16,12 @@ package ai


import ( import (
"context" "context"
"github.com/go-resty/resty/v2"
"github.com/pkg/errors" "github.com/pkg/errors"
"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"
sync "gitlink.org.cn/JointCloud/pcm-coordinator/internal/types/ai" sync "gitlink.org.cn/JointCloud/pcm-coordinator/internal/types/ai"
"net/http"
) )


type TaskResultSyncLogic struct { 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


} }

+ 1
- 1
internal/participant/model.go View File

@@ -7,7 +7,7 @@ type RespErr struct {


type Resp struct { type Resp struct {
Code int32 `json:"code"` Code int32 `json:"code"`
Message string `json:"message"`
Message string `json:"msg"`
Data interface{} `json:"data"` Data interface{} `json:"data"`
} }




Loading…
Cancel
Save