Former-commit-id: 7b49a92d6af20441eb109b7340f15f8e61400d8b
This commit is contained in:
tzwang 2024-06-07 14:48:30 +08:00
commit 11e01683a2
4 changed files with 45 additions and 36 deletions

View File

@ -168,8 +168,8 @@ type VmInfo struct {
Status string `json:"status,omitempty"` Status string `json:"status,omitempty"`
Platform string `json:"platform,omitempty"` Platform string `json:"platform,omitempty"`
Description string `json:"description,omitempty"` // 描述 Description string `json:"description,omitempty"` // 描述
AvailabilityZone string `json:"availability_zone,omitempty"` AvailabilityZone string `json:"availabilityZone,omitempty"`
MinCount string `json:"minCount,omitempty"` MinCount int64 `json:"minCount,omitempty"`
Uuid string `json:"uuid,omitempty"` Uuid string `json:"uuid,omitempty"`
StartTime string `json:"startTime,omitempty"` StartTime string `json:"startTime,omitempty"`
RunningTime string `json:"runningTime,omitempty"` RunningTime string `json:"runningTime,omitempty"`

View File

@ -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 //return errors.Errorf("the cluster does not match the drive resources. Check the data"), nil
}*/ }*/
taskVm.Name = req.Name taskVm.Name = req.Name
taskVm.TaskId = taskModel.Id
taskVm.Status = "Saved" taskVm.Status = "Saved"
taskVm.StartTime = time.Now().String() taskVm.StartTime = time.Now().String()
taskVm.MinCount = req.MinCount taskVm.MinCount = req.MinCount

View File

@ -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) l.svcCtx.DbEngin.Raw("select type as kind from t_adapter where id = ?", req.AdapterId).Scan(&kind)
switch kind { switch kind {
case 0: case 0:
for _, cloudInfo := range req.CloudInfoList { var resourceType int32
var taskId uint l.svcCtx.DbEngin.Raw("select resource_type as resourceType from `t_adapter` where id = ?", req.AdapterId).Scan(&resourceType)
result := l.svcCtx.DbEngin.Table("task_cloud").Select("task_id").Where("task_id = ?", cloudInfo.TaskId).Find(&taskId) switch resourceType {
if errors.Is(result.Error, gorm.ErrRecordNotFound) { case 01:
return nil, errors.New("Record does not exist") 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 = ?", case 02:
cloudInfo.Status, cloudInfo.StartTime, cloudInfo.Result, cloudInfo.TaskId) for _, vmInfo := range req.VmInfoList {
var taskName string l.svcCtx.DbEngin.Exec("update task_vm set status = ?,start_time = ? where participant_id = ? and task_id = ? and name = ?",
l.svcCtx.DbEngin.Raw("select name as kind from task where id = ?", taskId).Scan(&taskName) vmInfo.Status, vmInfo.StartTime, req.AdapterId, vmInfo.TaskId, vmInfo.Name)
noticeInfo := clientCore.NoticeInfo{ noticeInfo := clientCore.NoticeInfo{
TaskId: cloudInfo.TaskId, TaskId: vmInfo.TaskId,
AdapterId: cloudInfo.AdapterId, AdapterId: vmInfo.AdapterId,
AdapterName: cloudInfo.AdapterName, AdapterName: vmInfo.AdapterName,
ClusterId: cloudInfo.ClusterId, ClusterId: vmInfo.ClusterId,
ClusterName: cloudInfo.ClusterName, ClusterName: vmInfo.ClusterName,
TaskName: taskName, TaskName: vmInfo.Name,
}
syncTask(l.svcCtx.DbEngin, noticeInfo)
} }
syncTask(l.svcCtx.DbEngin, noticeInfo)
} }
case 2: case 2:
for _, hpcInfo := range req.HpcInfoList { 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 = ?", 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) 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 return &resp, nil
} }

View File

@ -25,9 +25,11 @@ func NewSyncClusterLoadLogic(ctx context.Context, svcCtx *svc.ServiceContext) *S
func (l *SyncClusterLoadLogic) SyncClusterLoad(req *types.SyncClusterLoadReq) error { func (l *SyncClusterLoadLogic) SyncClusterLoad(req *types.SyncClusterLoadReq) error {
if nil != req.ClusterLoadRecords { if nil != req.ClusterLoadRecords {
var param tracker.ClusterLoadRecord for _, record := range req.ClusterLoadRecords {
tool.Convert(req, &param) var param tracker.ClusterLoadRecord
tracker.SyncClusterLoad(param) tool.Convert(record, &param)
tracker.SyncClusterLoad(param)
}
} }
return nil return nil
} }