| @@ -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 | ||||
| } | } | ||||
| @@ -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 | |||||
| } | } | ||||
| @@ -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 | |||||
| } | } | ||||
| @@ -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 | |||||
| } | } | ||||
| @@ -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"` | ||||
| } | } | ||||