Merge pull request 'fix bug' (#143) from zhouqunjie/pcm-coordinator:master into master
Former-commit-id: f13989d5a68b0116ca452c6ce819a5949efe62d9
This commit is contained in:
commit
6a6ab03c68
|
@ -1,65 +0,0 @@
|
||||||
package core
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"gitlink.org.cn/JointCloud/pcm-coordinator/api/pkg/response"
|
|
||||||
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/constants"
|
|
||||||
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/models"
|
|
||||||
tool "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/utils"
|
|
||||||
"k8s.io/apimachinery/pkg/util/json"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc"
|
|
||||||
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types"
|
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
|
||||||
)
|
|
||||||
|
|
||||||
type CommitHpcTaskLogic struct {
|
|
||||||
logx.Logger
|
|
||||||
ctx context.Context
|
|
||||||
svcCtx *svc.ServiceContext
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewCommitHpcTaskLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CommitHpcTaskLogic {
|
|
||||||
return &CommitHpcTaskLogic{
|
|
||||||
Logger: logx.WithContext(ctx),
|
|
||||||
ctx: ctx,
|
|
||||||
svcCtx: svcCtx,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (l *CommitHpcTaskLogic) CommitHpcTask(req *types.CommitHpcTaskReq) (resp *types.CommitHpcTaskResp, err error) {
|
|
||||||
// 构建主任务结构体
|
|
||||||
taskModel := models.Task{
|
|
||||||
Status: constants.Saved,
|
|
||||||
Description: req.Description,
|
|
||||||
Name: req.Name,
|
|
||||||
CommitTime: time.Now(),
|
|
||||||
}
|
|
||||||
// 保存任务数据到数据库
|
|
||||||
tx := l.svcCtx.DbEngin.Create(&taskModel)
|
|
||||||
if tx.Error != nil {
|
|
||||||
return nil, tx.Error
|
|
||||||
}
|
|
||||||
hpc := models.Hpc{}
|
|
||||||
tool.Convert(req, &hpc)
|
|
||||||
mqInfo := response.TaskInfo{
|
|
||||||
TaskId: taskModel.Id,
|
|
||||||
TaskType: "hpc",
|
|
||||||
MatchLabels: req.MatchLabels,
|
|
||||||
//Metadata: hpc,
|
|
||||||
}
|
|
||||||
req.TaskId = taskModel.Id
|
|
||||||
// 将任务数据转换成消息体
|
|
||||||
reqMessage, err := json.Marshal(mqInfo)
|
|
||||||
if err != nil {
|
|
||||||
logx.Error(err)
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
publish := l.svcCtx.RedisClient.Publish(context.Background(), mqInfo.TaskType, reqMessage)
|
|
||||||
if publish.Err() != nil {
|
|
||||||
return nil, publish.Err()
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
|
@ -32,11 +32,15 @@ func (l *CommitHpcTaskLogic) CommitHpcTask(req *types.CommitHpcTaskReq) (resp *t
|
||||||
|
|
||||||
// 构建主任务结构体
|
// 构建主任务结构体
|
||||||
taskModel := models.Task{
|
taskModel := models.Task{
|
||||||
Status: constants.Saved,
|
Name: req.Name,
|
||||||
Description: req.Description,
|
Description: req.Description,
|
||||||
Name: req.Name,
|
Status: constants.Saved,
|
||||||
CommitTime: time.Now(),
|
Strategy: 0,
|
||||||
|
SynergyStatus: 0,
|
||||||
|
CommitTime: time.Now(),
|
||||||
|
AdapterTypeDict: 2,
|
||||||
}
|
}
|
||||||
|
|
||||||
// 保存任务数据到数据库
|
// 保存任务数据到数据库
|
||||||
tx := l.svcCtx.DbEngin.Create(&taskModel)
|
tx := l.svcCtx.DbEngin.Create(&taskModel)
|
||||||
if tx.Error != nil {
|
if tx.Error != nil {
|
||||||
|
@ -49,7 +53,9 @@ func (l *CommitHpcTaskLogic) CommitHpcTask(req *types.CommitHpcTaskReq) (resp *t
|
||||||
env, _ := json.Marshal(req.Environment)
|
env, _ := json.Marshal(req.Environment)
|
||||||
|
|
||||||
if len(clusterIds) == 0 || clusterIds == nil {
|
if len(clusterIds) == 0 || clusterIds == nil {
|
||||||
return nil, nil
|
resp.Code = 400
|
||||||
|
resp.Msg = "no cluster found"
|
||||||
|
return resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
hpcInfo := models.TaskHpc{
|
hpcInfo := models.TaskHpc{
|
||||||
|
|
Loading…
Reference in New Issue