feat: Task Management - Task list
Signed-off-by: jagger <cossjie@foxmail.com> Former-commit-id: 1dfdd0b3de39938c059b9d2c05bda7597f10c647
This commit is contained in:
parent
5d3d48faee
commit
6d6ee06022
|
@ -235,6 +235,30 @@ type (
|
||||||
ParticipantId int64 `json:"participantId"`
|
ParticipantId int64 `json:"participantId"`
|
||||||
ParticipantName string `json:"participantName"`
|
ParticipantName string `json:"participantName"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pageTaskReq {
|
||||||
|
Name string `form:"name,optional"`
|
||||||
|
PageInfo
|
||||||
|
}
|
||||||
|
|
||||||
|
TaskModel {
|
||||||
|
Id int64 `json:"id,omitempty" db:"id"` // id
|
||||||
|
Name string `json:"name,omitempty" db:"name"` // 作业名称
|
||||||
|
Description string `json:"description,omitempty" db:"description"` // 作业描述
|
||||||
|
Status string `json:"status,omitempty" db:"status"` // 作业状态
|
||||||
|
Strategy int64 `json:"strategy" db:"strategy"` // 策略
|
||||||
|
SynergyStatus int64 `json:"synergyStatus" db:"synergy_status"`// 协同状态(0-未协同、1-已协同)
|
||||||
|
CommitTime string `json:"commitTime,omitempty" db:"commit_time"` // 提交时间
|
||||||
|
StartTime string `json:"startTime,omitempty" db:"start_time"` // 开始时间
|
||||||
|
EndTime string `json:"endTime,omitempty" db:"end_time"` // 结束运行时间
|
||||||
|
RunningTime int64 `json:"runningTime" db:"running_time"` // 已运行时间(单位秒)
|
||||||
|
YamlString string `json:"yamlString,omitempty" db:"yaml_string"`
|
||||||
|
Result string `json:"result,omitempty" db:"result"` // 作业结果
|
||||||
|
DeletedAt string `json:"deletedAt,omitempty" gorm:"index" db:"deleted_at"`
|
||||||
|
NsID string `json:"nsId,omitempty" db:"ns_id"`
|
||||||
|
tenantId string `json:"tenantId,omitempty" db:"tenant_id"`
|
||||||
|
createTime string `json:"createTime,omitempty" db:"create_time" gorm:"autoCreateTime"`
|
||||||
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
// 任务列表参数
|
// 任务列表参数
|
||||||
|
|
|
@ -129,6 +129,10 @@ service pcm {
|
||||||
@doc "cluster resource load"
|
@doc "cluster resource load"
|
||||||
@handler clustersLoadHandler
|
@handler clustersLoadHandler
|
||||||
get /core/cluster/load (clustersLoadReq) returns (clustersLoadResp)
|
get /core/cluster/load (clustersLoadReq) returns (clustersLoadResp)
|
||||||
|
|
||||||
|
@doc "paging queries the task list"
|
||||||
|
@handler pageListTaskHandler
|
||||||
|
get /core/task/list (pageTaskReq) returns(PageResult)
|
||||||
}
|
}
|
||||||
|
|
||||||
//hpc二级接口
|
//hpc二级接口
|
||||||
|
|
|
@ -0,0 +1,24 @@
|
||||||
|
package core
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/zeromicro/go-zero/rest/httpx"
|
||||||
|
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/logic/core"
|
||||||
|
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc"
|
||||||
|
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types"
|
||||||
|
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/repository/result"
|
||||||
|
"net/http"
|
||||||
|
)
|
||||||
|
|
||||||
|
func PageListTaskHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
var req types.PageTaskReq
|
||||||
|
if err := httpx.Parse(r, &req); err != nil {
|
||||||
|
result.ParamErrorResult(r, w, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
l := core.NewPageListTaskLogic(r.Context(), svcCtx)
|
||||||
|
resp, err := l.PageListTask(&req)
|
||||||
|
result.HttpResult(r, w, resp, err)
|
||||||
|
}
|
||||||
|
}
|
|
@ -154,6 +154,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
||||||
Path: "/core/cluster/load",
|
Path: "/core/cluster/load",
|
||||||
Handler: core.ClustersLoadHandler(serverCtx),
|
Handler: core.ClustersLoadHandler(serverCtx),
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Method: http.MethodGet,
|
||||||
|
Path: "/core/task/list",
|
||||||
|
Handler: core.PageListTaskHandler(serverCtx),
|
||||||
|
},
|
||||||
},
|
},
|
||||||
rest.WithPrefix("/pcm/v1"),
|
rest.WithPrefix("/pcm/v1"),
|
||||||
)
|
)
|
||||||
|
|
|
@ -0,0 +1,56 @@
|
||||||
|
package core
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/repository/result"
|
||||||
|
|
||||||
|
"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 PageListTaskLogic struct {
|
||||||
|
logx.Logger
|
||||||
|
ctx context.Context
|
||||||
|
svcCtx *svc.ServiceContext
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewPageListTaskLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PageListTaskLogic {
|
||||||
|
return &PageListTaskLogic{
|
||||||
|
Logger: logx.WithContext(ctx),
|
||||||
|
ctx: ctx,
|
||||||
|
svcCtx: svcCtx,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *PageListTaskLogic) PageListTask(req *types.PageTaskReq) (resp *types.PageResult, err error) {
|
||||||
|
limit := req.PageSize
|
||||||
|
offset := req.PageSize * (req.PageNum - 1)
|
||||||
|
resp = &types.PageResult{}
|
||||||
|
var list []types.TaskModel
|
||||||
|
db := l.svcCtx.DbEngin.Model(&types.TaskModel{}).Table("task")
|
||||||
|
if req.Name != "" {
|
||||||
|
db = db.Where("name LIKE ?", "%"+req.Name+"%")
|
||||||
|
}
|
||||||
|
db = db.Where("deleted_at is null").Limit(limit).Offset(offset)
|
||||||
|
|
||||||
|
//count total
|
||||||
|
var total int64
|
||||||
|
err = db.Count(&total).Error
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return resp, err
|
||||||
|
}
|
||||||
|
err = db.Order("created_time desc").Find(&list).Error
|
||||||
|
if err != nil {
|
||||||
|
return nil, result.NewDefaultError(err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
resp.List = list
|
||||||
|
resp.PageSize = req.PageSize
|
||||||
|
resp.PageNum = req.PageNum
|
||||||
|
resp.Total = total
|
||||||
|
|
||||||
|
return resp, nil
|
||||||
|
}
|
|
@ -222,6 +222,30 @@ type Task struct {
|
||||||
ParticipantName string `json:"participantName"`
|
ParticipantName string `json:"participantName"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type PageTaskReq struct {
|
||||||
|
Name string `form:"name,optional"`
|
||||||
|
PageInfo
|
||||||
|
}
|
||||||
|
|
||||||
|
type TaskModel struct {
|
||||||
|
Id int64 `json:"id,omitempty" db:"id"` // id
|
||||||
|
Name string `json:"name,omitempty" db:"name"` // 作业名称
|
||||||
|
Description string `json:"description,omitempty" db:"description"` // 作业描述
|
||||||
|
Status string `json:"status,omitempty" db:"status"` // 作业状态
|
||||||
|
Strategy int64 `json:"strategy" db:"strategy"` // 策略
|
||||||
|
SynergyStatus int64 `json:"synergyStatus" db:"synergy_status"` // 协同状态(0-未协同、1-已协同)
|
||||||
|
CommitTime string `json:"commitTime,omitempty" db:"commit_time"` // 提交时间
|
||||||
|
StartTime string `json:"startTime,omitempty" db:"start_time"` // 开始时间
|
||||||
|
EndTime string `json:"endTime,omitempty" db:"end_time"` // 结束运行时间
|
||||||
|
RunningTime int64 `json:"runningTime" db:"running_time"` // 已运行时间(单位秒)
|
||||||
|
YamlString string `json:"yamlString,omitempty" db:"yaml_string"`
|
||||||
|
Result string `json:"result,omitempty" db:"result"` // 作业结果
|
||||||
|
DeletedAt string `json:"deletedAt,omitempty" gorm:"index" db:"deleted_at"`
|
||||||
|
NsID string `json:"nsId,omitempty" db:"ns_id"`
|
||||||
|
TenantId string `json:"tenantId,omitempty" db:"tenant_id"`
|
||||||
|
CreateTime string `json:"createTime,omitempty" db:"create_time" gorm:"autoCreateTime"`
|
||||||
|
}
|
||||||
|
|
||||||
type TaskDetailReq struct {
|
type TaskDetailReq struct {
|
||||||
TaskId int64 `path:"taskId"`
|
TaskId int64 `path:"taskId"`
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue