Signed-off-by: jagger <cossjie@foxmail.com>

Former-commit-id: 7ea02a9f7d
This commit is contained in:
jagger 2024-04-30 19:19:02 +08:00
parent cf52f868ce
commit ff7aae0a88
3 changed files with 36 additions and 20 deletions

View File

@ -111,17 +111,17 @@ type HpcInfo struct {
} }
type CloudInfo struct { type CloudInfo struct {
Id uint `json:"id,omitempty"` Id uint `json:"id,omitempty,optional"`
TaskId int64 `json:"taskId,omitempty"` TaskId int64 `json:"taskId,omitempty,optional"`
AdapterId uint `json:"adapterId,omitempty"` AdapterId uint `json:"adapterId,omitempty,optional"`
ClusterId uint `json:"clusterId,omitempty"` ClusterId uint `json:"clusterId,omitempty,optional"`
ClusterName string `json:"clusterName,omitempty"` ClusterName string `json:"clusterName,omitempty,optional"`
Kind string `json:"kind,omitempty"` Kind string `json:"kind,omitempty,optional"`
Status string `json:"status,omitempty"` Status string `json:"status,omitempty,optional"`
StartTime *time.Time `json:"startTime,omitempty"` StartTime *time.Time `json:"startTime,omitempty,optional,string"`
YamlString string `json:"yamlString,omitempty"` YamlString string `json:"yamlString,omitempty,optional"`
Result string `json:"result,omitempty"` Result string `json:"result,omitempty,optional"`
Namespace string `json:"namespace,omitempty"` Namespace string `json:"namespace,omitempty,optional"`
} }
type AiInfo struct { type AiInfo struct {

View File

@ -2,14 +2,15 @@ package core
import ( import (
"context" "context"
"github.com/pkg/errors"
"github.com/zeromicro/go-zero/core/logx"
clientCore "gitlink.org.cn/JointCloud/pcm-coordinator/api/client" clientCore "gitlink.org.cn/JointCloud/pcm-coordinator/api/client"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc"
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/constants" "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/constants"
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/models" "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/models"
"gorm.io/gorm" "gorm.io/gorm"
"strings" "strings"
"time"
"github.com/zeromicro/go-zero/core/logx"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc"
) )
type PushTaskInfoLogic struct { type PushTaskInfoLogic struct {
@ -33,9 +34,14 @@ func (l *PushTaskInfoLogic) PushTaskInfo(req *clientCore.PushTaskInfoReq) (*clie
switch kind { switch kind {
case 0: case 0:
for _, cloudInfo := range req.CloudInfoList { for _, cloudInfo := range req.CloudInfoList {
l.svcCtx.DbEngin.Exec("update cloud set status = ?,start_time = ?,result = ? where participant_id = ? and id = ?", var taskId uint
cloudInfo.Status, cloudInfo.StartTime, cloudInfo.Result, req.AdapterId, cloudInfo.Id) result := l.svcCtx.DbEngin.Table("task_cloud").Select("task_id").Where("cluster_name=? and adapter_id=? and kind=?", cloudInfo.ClusterName, cloudInfo.AdapterId, cloudInfo.Kind).Find(&taskId)
syncTask(l.svcCtx.DbEngin, cloudInfo.TaskId) if errors.Is(result.Error, gorm.ErrRecordNotFound) {
return nil, errors.New("Record does not exist")
}
l.svcCtx.DbEngin.Exec("update task_cloud set status = ?,start_time = ?,result = ? where cluster_name = ? and adapter_id = ?",
cloudInfo.Status, cloudInfo.StartTime, cloudInfo.Result, cloudInfo.ClusterName, cloudInfo.AdapterId)
syncTask(l.svcCtx.DbEngin, int64(taskId))
} }
case 2: case 2:
for _, hpcInfo := range req.HpcInfoList { for _, hpcInfo := range req.HpcInfoList {
@ -63,7 +69,7 @@ func (l *PushTaskInfoLogic) PushTaskInfo(req *clientCore.PushTaskInfoReq) (*clie
func syncTask(gorm *gorm.DB, taskId int64) { func syncTask(gorm *gorm.DB, taskId int64) {
var allStatus string var allStatus string
tx := gorm.Raw("SELECT CONCAT_WS(',',GROUP_CONCAT(DISTINCT h.status) ,GROUP_CONCAT(DISTINCT a.status) ,GROUP_CONCAT(DISTINCT c.status))as status from task t left join hpc h on t.id = h.task_id left join cloud c on t.id = c.task_id left join ai a on t.id = a.task_id where t.id = ?", taskId).Scan(&allStatus) tx := gorm.Raw("SELECT CONCAT_WS(',',GROUP_CONCAT(DISTINCT h.status) ,GROUP_CONCAT(DISTINCT a.status) ,GROUP_CONCAT(DISTINCT c.status))as status from task t left join hpc h on t.id = h.task_id left join task_cloud c on t.id = c.task_id left join ai a on t.id = a.task_id where t.id = ?", taskId).Scan(&allStatus)
if tx.Error != nil { if tx.Error != nil {
logx.Error(tx.Error) logx.Error(tx.Error)
} }
@ -79,7 +85,7 @@ func syncTask(gorm *gorm.DB, taskId int64) {
} }
if strings.Contains(allStatus, constants.Running) { if strings.Contains(allStatus, constants.Running) {
updateTask(gorm, taskId, constants.Running) updateTaskRunning(gorm, taskId, constants.Running)
} }
} }
@ -93,6 +99,16 @@ func updateTask(gorm *gorm.DB, taskId int64, status string) {
} }
} }
func updateTaskRunning(gorm *gorm.DB, taskId int64, status string) {
var task models.Task
gorm.Where("id = ? ", taskId).Find(&task)
if task.Status != status {
task.Status = status
task.StartTime = time.Now().Format("2006-01-02 15:04:05")
gorm.Updates(&task)
}
}
func removeRepeatedElement(arr []string) (newArr []string) { func removeRepeatedElement(arr []string) (newArr []string) {
newArr = make([]string, 0) newArr = make([]string, 0)
for i := 0; i < len(arr); i++ { for i := 0; i < len(arr); i++ {

View File

@ -13,7 +13,7 @@ type TaskCloudModel struct {
ClusterName string `json:"clusterName" gorm:"not null;comment:集群名称"` ClusterName string `json:"clusterName" gorm:"not null;comment:集群名称"`
Kind string `json:"kind" gorm:"comment:种类"` Kind string `json:"kind" gorm:"comment:种类"`
Status string `json:"status" gorm:"comment:状态"` Status string `json:"status" gorm:"comment:状态"`
StartTime *time.Time `json:"startTime" gorm:"comment:开始时间"` StartTime *time.Time `json:"startTime,string" gorm:"comment:开始时间"`
YamlString string `json:"yamlString" gorm:"not null;comment:入参"` YamlString string `json:"yamlString" gorm:"not null;comment:入参"`
Result string `json:"result" gorm:"comment:运行结果"` Result string `json:"result" gorm:"comment:运行结果"`
Namespace string `json:"namespace" gorm:"comment:命名空间"` Namespace string `json:"namespace" gorm:"comment:命名空间"`