列表查询

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

Former-commit-id: f0de1a71a21b8cd65a99493c6486a1dbc199f26f
This commit is contained in:
devad 2023-11-24 15:42:30 +08:00
parent 81f1a1ce1b
commit 4a9b9d3c06
9 changed files with 260 additions and 2 deletions

View File

@ -565,4 +565,48 @@ type Participant {
metricsUrl string `json:"metricsUrl"`
tenantName string `json:"tenantName"`
typeName string `json:"typeName"`
}
}
// apps列表参数
type (
AppListReq {
Namespace string `form:"namespace"`
}
AppListResp {
TotalCount int64 `json:"totalCount"` // 任务总数
Apps []App `json:"apps"` //应用列表
}
App {
Id int64 `json:"id"`
Name string `json:"name"`
Status string `json:"status"`
TaskType string `json:"taskType"`
StartTime string `json:"startTime"`
EndTime string `json:"endTime"`
ParticipantStatus string `json:"participantStatus"`
ParticipantId int64 `json:"participantId"`
ParticipantName string `json:"participantName"`
Storage string `json:"storage"`
CreateTime string `json:"createTime"`
}
)
//apps 详情参数
type (
AppDetailReq {
Name string `path:"name"`
NsID string `param:"nsID"`
}
AppDetailResp {
CpuCores float64 `json:"cpuCores"`
CpuRate float64 `json:"cpuRate"`
CpuLimit float64 `json:"cpuLimit"`
GpuCores float64 `json:"gpuCores"`
GpuRate float64 `json:"gpuRate"`
GpuLimit float64 `json:"gpuLimit"`
MemoryTotal float64 `json:"memoryTotal"`
MemoryRate float64 `json:"memoryRate"`
MemoryLimit float64 `json:"memoryLimit"`
}
)

View File

@ -519,4 +519,19 @@ service pcm {
@handler GetAISpecsHandler
get /storelink/getResourceSpecs (GetResourceSpecsReq) returns (GetResourceSpecsResp)
}
// 接口
@server(
prefix: pcm/v1
group : apps
)
service pcm {
@doc "应用列表"
@handler AppListHandler
get /apps/list (AppListReq) returns (AppListResp)
@doc "应用详情"
@handler AppDetailHandler
get /apps/detail (AppDetailReq) returns (AppDetailResp)
}

View File

@ -4,7 +4,7 @@ NacosConfig:
ServerConfigs:
# - IpAddr: 127.0.0.1
# Port: 8848
- IpAddr: nacos.jcce.dev
- IpAddr: 127.0.0.1
Port: 8848
ClientConfig:
NamespaceId: test

View File

@ -0,0 +1,24 @@
package apps
import (
"github.com/zeromicro/go-zero/rest/httpx"
"gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/logic/apps"
"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/utils/result"
"net/http"
)
func AppDetailHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.AppDetailReq
if err := httpx.Parse(r, &req); err != nil {
result.ParamErrorResult(r, w, err)
return
}
l := apps.NewAppDetailLogic(r.Context(), svcCtx)
resp, err := l.AppDetail(&req)
result.HttpResult(r, w, resp, err)
}
}

View File

@ -0,0 +1,24 @@
package apps
import (
"github.com/zeromicro/go-zero/rest/httpx"
"gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/logic/apps"
"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/utils/result"
"net/http"
)
func AppListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.AppListReq
if err := httpx.Parse(r, &req); err != nil {
result.ParamErrorResult(r, w, err)
return
}
l := apps.NewAppListLogic(r.Context(), svcCtx)
resp, err := l.AppList(&req)
result.HttpResult(r, w, resp, err)
}
}

View File

@ -5,6 +5,7 @@ import (
"net/http"
ai "gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/handler/ai"
apps "gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/handler/apps"
cloud "gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/handler/cloud"
core "gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/handler/core"
hpc "gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/handler/hpc"
@ -630,4 +631,20 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
},
rest.WithPrefix("/pcm/v1"),
)
server.AddRoutes(
[]rest.Route{
{
Method: http.MethodGet,
Path: "/apps/list",
Handler: apps.AppListHandler(serverCtx),
},
{
Method: http.MethodGet,
Path: "/apps/detail",
Handler: apps.AppDetailHandler(serverCtx),
},
},
rest.WithPrefix("/pcm/v1"),
)
}

View File

@ -0,0 +1,30 @@
package apps
import (
"context"
"gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/svc"
"gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type AppDetailLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewAppDetailLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AppDetailLogic {
return &AppDetailLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *AppDetailLogic) AppDetail(req *types.AppDetailReq) (resp *types.AppDetailResp, err error) {
// todo: add your logic here and delete this line
return
}

View File

@ -0,0 +1,64 @@
package apps
import (
"context"
"gorm.io/gorm"
"time"
"gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/svc"
"gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type AppListLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewAppListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AppListLogic {
return &AppListLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
type Task struct {
Id int64 `db:"id"` // id
Name string `db:"name"` // 作业名称
Description string `db:"description"` // 作业描述
Status string `db:"status"` // 作业状态
Strategy int64 `db:"strategy"` // 策略
SynergyStatus int64 `db:"synergy_status"` // 协同状态0-未协同、1-已协同)
CommitTime time.Time `db:"commit_time"` // 提交时间
StartTime string `db:"start_time"` // 开始时间
EndTime string `db:"end_time"` // 结束运行时间
RunningTime int64 `db:"running_time"` // 已运行时间(单位秒)
YamlString string `db:"yaml_string"`
Result string `db:"result"` // 作业结果
DeletedAt gorm.DeletedAt `gorm:"index"`
NsID string `db:"ns_id"`
PName string `db:"p_name"` // p端名称
PId int64 `db:"p_id"` // p端id
}
func (l *AppListLogic) AppList(req *types.AppListReq) (resp *types.AppListResp, err error) {
var tasks []Task
resp = &types.AppListResp{}
l.svcCtx.DbEngin.Raw("SELECT t.*,phy.name as p_name,phy.id as p_id FROM task t LEFT JOIN cloud c ON c.task_id = t.id join sc_participant_phy_info phy on c.participant_id = phy.id WHERE c.kind in ('Deployment', 'StatefulSet', 'Ingress', 'Service') AND t.`ns_id` = ? AND t.`deleted_at` IS NULL ORDER BY t.created_time Desc", req.Namespace).Scan(&tasks)
for _, task := range tasks {
resp.Apps = append(resp.Apps, types.App{
Id: task.Id,
Name: task.Name,
Status: task.Status,
StartTime: task.StartTime,
EndTime: task.EndTime,
CreateTime: task.CommitTime.Format("2006-01-02 15:04:05"),
ParticipantId: task.PId,
ParticipantName: task.PName,
})
}
return
}

View File

@ -532,6 +532,46 @@ type Participant struct {
TypeName string `json:"typeName"`
}
type AppListReq struct {
Namespace string `form:"namespace"`
}
type AppListResp struct {
TotalCount int64 `json:"totalCount"` // 任务总数
Apps []App `json:"apps"` //应用列表
}
type App struct {
Id int64 `json:"id"`
Name string `json:"name"`
Status string `json:"status"`
TaskType string `json:"taskType"`
StartTime string `json:"startTime"`
EndTime string `json:"endTime"`
ParticipantStatus string `json:"participantStatus"`
ParticipantId int64 `json:"participantId"`
ParticipantName string `json:"participantName"`
Storage string `json:"storage"`
CreateTime string `json:"createTime"`
}
type AppDetailReq struct {
Name string `path:"name"`
NsID string `param:"nsID"`
}
type AppDetailResp struct {
CpuCores float64 `json:"cpuCores"`
CpuRate float64 `json:"cpuRate"`
CpuLimit float64 `json:"cpuLimit"`
GpuCores float64 `json:"gpuCores"`
GpuRate float64 `json:"gpuRate"`
GpuLimit float64 `json:"gpuLimit"`
MemoryTotal float64 `json:"memoryTotal"`
MemoryRate float64 `json:"memoryRate"`
MemoryLimit float64 `json:"memoryLimit"`
}
type Job struct {
SlurmVersion string `json:"slurmVersion"`
Name string `json:"name"`