From f2fb6bb4ec33b866af33dbf4269b98815d737416 Mon Sep 17 00:00:00 2001 From: qiwang <1364512070@qq.com> Date: Fri, 7 Jun 2024 09:12:05 +0800 Subject: [PATCH] fix: update vmInfo 060601 Former-commit-id: ccb597154a3af953b990f07aaac678966730cc44 --- api/client/types.go | 2 +- api/internal/logic/core/commitvmtasklogic.go | 1 + api/internal/logic/core/pushtaskinfologic.go | 68 +++++++++++--------- 3 files changed, 39 insertions(+), 32 deletions(-) diff --git a/api/client/types.go b/api/client/types.go index ddd96f4e..36336c62 100644 --- a/api/client/types.go +++ b/api/client/types.go @@ -169,7 +169,7 @@ type VmInfo struct { Platform string `json:"platform,omitempty"` Description string `json:"description,omitempty"` // 描述 AvailabilityZone string `json:"availability_zone,omitempty"` - MinCount string `json:"minCount,omitempty"` + MinCount int64 `json:"minCount,omitempty"` Uuid string `json:"uuid,omitempty"` StartTime string `json:"startTime,omitempty"` RunningTime string `json:"runningTime,omitempty"` diff --git a/api/internal/logic/core/commitvmtasklogic.go b/api/internal/logic/core/commitvmtasklogic.go index 80a52e1e..dd0908ca 100644 --- a/api/internal/logic/core/commitvmtasklogic.go +++ b/api/internal/logic/core/commitvmtasklogic.go @@ -120,6 +120,7 @@ func (l *CommitVmTaskLogic) CommitVmTask(req *types.CommitVmTaskReq) (resp *type //return errors.Errorf("the cluster does not match the drive resources. Check the data"), nil }*/ taskVm.Name = req.Name + taskVm.TaskId = taskModel.Id taskVm.Status = "Saved" taskVm.StartTime = time.Now().String() taskVm.MinCount = req.MinCount diff --git a/api/internal/logic/core/pushtaskinfologic.go b/api/internal/logic/core/pushtaskinfologic.go index 63169a86..0d5e8bd4 100644 --- a/api/internal/logic/core/pushtaskinfologic.go +++ b/api/internal/logic/core/pushtaskinfologic.go @@ -33,26 +33,46 @@ func (l *PushTaskInfoLogic) PushTaskInfo(req *clientCore.PushTaskInfoReq) (*clie l.svcCtx.DbEngin.Raw("select type as kind from t_adapter where id = ?", req.AdapterId).Scan(&kind) switch kind { case 0: - for _, cloudInfo := range req.CloudInfoList { - var taskId uint - result := l.svcCtx.DbEngin.Table("task_cloud").Select("task_id").Where("task_id = ?", cloudInfo.TaskId).Find(&taskId) - if errors.Is(result.Error, gorm.ErrRecordNotFound) { - return nil, errors.New("Record does not exist") + var resourceType int32 + l.svcCtx.DbEngin.Raw("select resource_type as resourceType from `t_adapter` where id = ?", req.AdapterId).Scan(&resourceType) + switch resourceType { + case 01: + for _, cloudInfo := range req.CloudInfoList { + var taskId uint + result := l.svcCtx.DbEngin.Table("task_cloud").Select("task_id").Where("task_id = ?", cloudInfo.TaskId).Find(&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 task_id = ?", + cloudInfo.Status, cloudInfo.StartTime, cloudInfo.Result, cloudInfo.TaskId) + var taskName string + l.svcCtx.DbEngin.Raw("select name as kind from task where id = ?", taskId).Scan(&taskName) + noticeInfo := clientCore.NoticeInfo{ + TaskId: cloudInfo.TaskId, + AdapterId: cloudInfo.AdapterId, + AdapterName: cloudInfo.AdapterName, + ClusterId: cloudInfo.ClusterId, + ClusterName: cloudInfo.ClusterName, + TaskName: taskName, + } + syncTask(l.svcCtx.DbEngin, noticeInfo) } - l.svcCtx.DbEngin.Exec("update task_cloud set status = ?,start_time = ?,result = ? where task_id = ?", - cloudInfo.Status, cloudInfo.StartTime, cloudInfo.Result, cloudInfo.TaskId) - var taskName string - l.svcCtx.DbEngin.Raw("select name as kind from task where id = ?", taskId).Scan(&taskName) - noticeInfo := clientCore.NoticeInfo{ - TaskId: cloudInfo.TaskId, - AdapterId: cloudInfo.AdapterId, - AdapterName: cloudInfo.AdapterName, - ClusterId: cloudInfo.ClusterId, - ClusterName: cloudInfo.ClusterName, - TaskName: taskName, + case 02: + for _, vmInfo := range req.VmInfoList { + l.svcCtx.DbEngin.Exec("update task_vm set status = ?,start_time = ? where participant_id = ? and task_id = ? and name = ?", + vmInfo.Status, vmInfo.StartTime, req.AdapterId, vmInfo.TaskId, vmInfo.Name) + noticeInfo := clientCore.NoticeInfo{ + TaskId: vmInfo.TaskId, + AdapterId: vmInfo.AdapterId, + AdapterName: vmInfo.AdapterName, + ClusterId: vmInfo.ClusterId, + ClusterName: vmInfo.ClusterName, + TaskName: vmInfo.Name, + } + syncTask(l.svcCtx.DbEngin, noticeInfo) } - syncTask(l.svcCtx.DbEngin, noticeInfo) } + case 2: for _, hpcInfo := range req.HpcInfoList { l.svcCtx.DbEngin.Exec("update task_hpc set status = ?,start_time = ?,job_id = ? where cluster_id = ? and task_id = ? and name = ?", @@ -81,20 +101,6 @@ func (l *PushTaskInfoLogic) PushTaskInfo(req *clientCore.PushTaskInfoReq) (*clie } syncTask(l.svcCtx.DbEngin, noticeInfo) } - case 3: - for _, vmInfo := range req.VmInfoList { - l.svcCtx.DbEngin.Exec("update task_vm set status = ?,start_time = ? where participant_id = ? and task_id = ? and name = ?", - vmInfo.Status, vmInfo.StartTime, req.AdapterId, vmInfo.TaskId, vmInfo.Name) - noticeInfo := clientCore.NoticeInfo{ - TaskId: vmInfo.TaskId, - AdapterId: vmInfo.AdapterId, - AdapterName: vmInfo.AdapterName, - ClusterId: vmInfo.ClusterId, - ClusterName: vmInfo.ClusterName, - TaskName: vmInfo.Name, - } - syncTask(l.svcCtx.DbEngin, noticeInfo) - } } return &resp, nil }