任务列表接口已完成
Former-commit-id: 1c63965ba59fc5ea1e20aa61a697222285fc190f
This commit is contained in:
parent
a38cb5d4b5
commit
80476d3582
|
@ -260,6 +260,9 @@ type (
|
||||||
CpuCores float64 `json:"cpuCores"`
|
CpuCores float64 `json:"cpuCores"`
|
||||||
CpuRate float64 `json:"cpuRate"`
|
CpuRate float64 `json:"cpuRate"`
|
||||||
CpuLimit float64 `json:"cpuLimit"`
|
CpuLimit float64 `json:"cpuLimit"`
|
||||||
|
GpuCores float64 `json:"gpuCores"`
|
||||||
|
GpuRate float64 `json:"gpuRate"`
|
||||||
|
GpuLimit float64 `json:"gpuLimit"`
|
||||||
MemoryTotal float64 `json:"memoryTotal"`
|
MemoryTotal float64 `json:"memoryTotal"`
|
||||||
MemoryRate float64 `json:"memoryRate"`
|
MemoryRate float64 `json:"memoryRate"`
|
||||||
MemoryLimit float64 `json:"memoryLimit"`
|
MemoryLimit float64 `json:"memoryLimit"`
|
||||||
|
|
|
@ -39,7 +39,7 @@ func (l *ScheduleTaskByYamlLogic) ScheduleTaskByYaml(req *types.ScheduleTaskByYa
|
||||||
Description: req.Description,
|
Description: req.Description,
|
||||||
Name: req.Name,
|
Name: req.Name,
|
||||||
YamlString: string(bytes),
|
YamlString: string(bytes),
|
||||||
CommitTime: time.Now().String(),
|
CommitTime: time.Now(),
|
||||||
}
|
}
|
||||||
// 保存任务数据到数据库
|
// 保存任务数据到数据库
|
||||||
tx := l.svcCtx.DbEngin.Create(&taskModel)
|
tx := l.svcCtx.DbEngin.Create(&taskModel)
|
||||||
|
|
|
@ -43,7 +43,7 @@ func (l *ScheduleTaskLogic) ScheduleTask(req *types.ScheduleTaskReq) (err error)
|
||||||
Description: req.Description,
|
Description: req.Description,
|
||||||
Name: req.Name,
|
Name: req.Name,
|
||||||
YamlString: string(bytes),
|
YamlString: string(bytes),
|
||||||
CommitTime: time.Now().String(),
|
CommitTime: time.Now(),
|
||||||
}
|
}
|
||||||
// save the task in mysql and return id
|
// save the task in mysql and return id
|
||||||
tx := l.svcCtx.DbEngin.Create(&taskModel)
|
tx := l.svcCtx.DbEngin.Create(&taskModel)
|
||||||
|
|
|
@ -2,6 +2,10 @@ package core
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"gitlink.org.cn/jcce-pcm/pcm-coordinator/pkg/models"
|
||||||
|
"strconv"
|
||||||
|
"time"
|
||||||
|
|
||||||
"gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/svc"
|
"gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/svc"
|
||||||
"gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/types"
|
"gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/types"
|
||||||
|
@ -24,7 +28,71 @@ func NewTaskListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *TaskList
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *TaskListLogic) TaskList(req *types.TaskListReq) (resp *types.TaskListResp, err error) {
|
func (l *TaskListLogic) TaskList(req *types.TaskListReq) (resp *types.TaskListResp, err error) {
|
||||||
// todo: add your logic here and delete this line
|
resp = &types.TaskListResp{}
|
||||||
|
|
||||||
|
// 查询任务数据
|
||||||
|
var tasks []models.Task
|
||||||
|
offset := (req.PageNum - 1) * req.PageSize
|
||||||
|
tx := l.svcCtx.DbEngin.Order("created_time desc").Offset(offset).Limit(req.PageSize).Find(&tasks)
|
||||||
|
if tx.Error != nil {
|
||||||
|
logx.Error(err)
|
||||||
|
return nil, tx.Error
|
||||||
|
}
|
||||||
|
if len(tasks) == 0 {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
// 查询任务总数
|
||||||
|
l.svcCtx.DbEngin.Model(&models.Task{}).Count(&resp.TotalCount)
|
||||||
|
|
||||||
|
// 查询任务异常数
|
||||||
|
l.svcCtx.DbEngin.Model(&models.Task{}).Where("status = ?", "Failed").Count(&resp.AlarmCount)
|
||||||
|
|
||||||
|
// 正常任务数
|
||||||
|
resp.NormalCount = resp.TotalCount - resp.AlarmCount
|
||||||
|
for _, task := range tasks {
|
||||||
|
type PInfo struct {
|
||||||
|
Id int64
|
||||||
|
Name string
|
||||||
|
Address string
|
||||||
|
}
|
||||||
|
pInfo := PInfo{}
|
||||||
|
tx := l.svcCtx.DbEngin.Raw("SELECT id,name,address from sc_participant_phy_info where id in (SELECT CONCAT_WS(',',GROUP_CONCAT(DISTINCT h.participant_id) ,GROUP_CONCAT(DISTINCT a.participant_id) ,GROUP_CONCAT(DISTINCT c.participant_id))as service_name 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 = ?)", task.Id).Scan(&pInfo)
|
||||||
|
if tx.Error != nil {
|
||||||
|
logx.Error(err)
|
||||||
|
return nil, tx.Error
|
||||||
|
}
|
||||||
|
// 获取p端状态
|
||||||
|
var pStatus string
|
||||||
|
key := fmt.Sprintf("ps_%s-%d", pInfo.Address, pInfo.Id)
|
||||||
|
hGetAll := l.svcCtx.RedisClient.HGetAll(l.ctx, key)
|
||||||
|
if hGetAll.Err() != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if len(hGetAll.Val()) != 0 {
|
||||||
|
parseInt, err := strconv.ParseInt(hGetAll.Val()["lastHeartbeat"], 10, 64)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if (time.Now().Unix() - parseInt) > 15 {
|
||||||
|
pStatus = "Unknown"
|
||||||
|
} else {
|
||||||
|
pStatus = "Normal"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
resp.Tasks = append(resp.Tasks, types.Task{
|
||||||
|
Id: task.Id,
|
||||||
|
Name: task.Name,
|
||||||
|
Status: task.Status,
|
||||||
|
StartTime: task.StartTime,
|
||||||
|
EndTime: task.EndTime,
|
||||||
|
ParticipantId: pInfo.Id,
|
||||||
|
ParticipantName: pInfo.Name,
|
||||||
|
ParticipantStatus: pStatus,
|
||||||
|
})
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -237,6 +237,9 @@ type TaskDetailResp struct {
|
||||||
CpuCores float64 `json:"cpuCores"`
|
CpuCores float64 `json:"cpuCores"`
|
||||||
CpuRate float64 `json:"cpuRate"`
|
CpuRate float64 `json:"cpuRate"`
|
||||||
CpuLimit float64 `json:"cpuLimit"`
|
CpuLimit float64 `json:"cpuLimit"`
|
||||||
|
GpuCores float64 `json:"gpuCores"`
|
||||||
|
GpuRate float64 `json:"gpuRate"`
|
||||||
|
GpuLimit float64 `json:"gpuLimit"`
|
||||||
MemoryTotal float64 `json:"memoryTotal"`
|
MemoryTotal float64 `json:"memoryTotal"`
|
||||||
MemoryRate float64 `json:"memoryRate"`
|
MemoryRate float64 `json:"memoryRate"`
|
||||||
MemoryLimit float64 `json:"memoryLimit"`
|
MemoryLimit float64 `json:"memoryLimit"`
|
||||||
|
|
|
@ -7,6 +7,7 @@ import (
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/core/stores/builder"
|
"github.com/zeromicro/go-zero/core/stores/builder"
|
||||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||||
|
@ -40,7 +41,7 @@ type (
|
||||||
Status string `db:"status"` // 作业状态
|
Status string `db:"status"` // 作业状态
|
||||||
Strategy int64 `db:"strategy"` // 策略
|
Strategy int64 `db:"strategy"` // 策略
|
||||||
SynergyStatus int64 `db:"synergy_status"` // 协同状态(0-未协同、1-已协同)
|
SynergyStatus int64 `db:"synergy_status"` // 协同状态(0-未协同、1-已协同)
|
||||||
CommitTime string `db:"commit_time"` // 提交时间
|
CommitTime time.Time `db:"commit_time"` // 提交时间
|
||||||
StartTime string `db:"start_time"` // 开始时间
|
StartTime string `db:"start_time"` // 开始时间
|
||||||
EndTime string `db:"end_time"` // 结束运行时间
|
EndTime string `db:"end_time"` // 结束运行时间
|
||||||
RunningTime int64 `db:"running_time"` // 已运行时间(单位秒)
|
RunningTime int64 `db:"running_time"` // 已运行时间(单位秒)
|
||||||
|
|
|
@ -32,13 +32,16 @@ func (l *ReportHeartbeatLogic) ReportHeartbeat(in *pcmCore.ParticipantHeartbeatR
|
||||||
key := fmt.Sprintf("ps_%s-%d", in.Address, in.ParticipantId)
|
key := fmt.Sprintf("ps_%s-%d", in.Address, in.ParticipantId)
|
||||||
clientsMutex.Lock()
|
clientsMutex.Lock()
|
||||||
defer clientsMutex.Unlock()
|
defer clientsMutex.Unlock()
|
||||||
l.svcCtx.RedisClient.HSet(context.Background(), key,
|
setResult := l.svcCtx.RedisClient.HSet(context.Background(), key,
|
||||||
map[string]interface{}{
|
map[string]interface{}{
|
||||||
"address": in.Address,
|
"address": in.Address,
|
||||||
"participantId": in.ParticipantId,
|
"participantId": in.ParticipantId,
|
||||||
"lastHeartbeat": time.Now().Unix(),
|
"lastHeartbeat": time.Now().Unix(),
|
||||||
"clientState": "TRUE",
|
"clientState": "TRUE",
|
||||||
})
|
})
|
||||||
|
if setResult.Err() != nil {
|
||||||
|
return nil, setResult.Err()
|
||||||
|
}
|
||||||
l.svcCtx.RedisClient.Expire(context.Background(), key, 30*time.Second)
|
l.svcCtx.RedisClient.Expire(context.Background(), key, 30*time.Second)
|
||||||
return &pcmCore.HealthCheckResp{
|
return &pcmCore.HealthCheckResp{
|
||||||
Code: 200,
|
Code: 200,
|
||||||
|
|
Loading…
Reference in New Issue