Merge pull request 'Resource Center Data Display' (#9) from zhangweiii/pcm-coordinator:v0.1.0-xjlab-alpha1 into v0.1.0-xjlab-alpha1
Former-commit-id: a7889f9a572557cc238f96fa76693f5f03a95c92
This commit is contained in:
commit
39e8759eab
|
@ -6,6 +6,39 @@ info(
|
|||
author: "zhouqj"
|
||||
email: "450705171@qq.com"
|
||||
)
|
||||
type (
|
||||
resourceCenterInfoReq {
|
||||
participantId int64 `path:"participantId"`
|
||||
}
|
||||
resourceCenterInfoResp {
|
||||
tasksName []string `json:"tasksName"`
|
||||
runningTasksNum int64 `json:"runningTasksNum"`
|
||||
resourceUsage ResourceUsage `json:"resourceUsage"`
|
||||
resourceTotal ResourceTotal `json:"resourceTotal"`
|
||||
}
|
||||
|
||||
ResourceUsage {
|
||||
cpu float64 `json:"cpu"`
|
||||
memory float64 `json:"memory"`
|
||||
storage float64 `json:"storage"`
|
||||
}
|
||||
|
||||
ResourceTotal {
|
||||
cpu int64 `json:"cpu"`
|
||||
memory int64 `json:"memory"`
|
||||
storage int64 `json:"storage"`
|
||||
}
|
||||
)
|
||||
type (
|
||||
tasksNumReq {
|
||||
|
||||
}
|
||||
tasksNumResp {
|
||||
totalNum int64 `json:"totalNum"`
|
||||
runningNum int64 `json:"runningNum"`
|
||||
completedNum int64 `json:"completedNum"`
|
||||
}
|
||||
)
|
||||
|
||||
type (
|
||||
tasksNumReq {
|
||||
|
|
|
@ -43,7 +43,7 @@ service pcm {
|
|||
|
||||
@doc "查询任务列表"
|
||||
@handler TaskListHandler
|
||||
get /core/taskList (taskListReq)returns (taskListResp)
|
||||
get /core/taskList (taskListReq) returns (taskListResp)
|
||||
|
||||
@doc "查询任务详情"
|
||||
@handler TaskDetailHandler
|
||||
|
@ -112,6 +112,14 @@ service pcm {
|
|||
@doc "获取hashcat"
|
||||
@handler getHashcatHandler
|
||||
get /core/getHashcat/:crackTaskId (getHashcatHandlerReq) returns (getHashcatHandlerResp)
|
||||
|
||||
@doc "Task Count Statistics"
|
||||
@handler tasksNumHandler
|
||||
get /core/tasks/num (tasksNumReq) returns (tasksNumResp)
|
||||
|
||||
@doc "Resource Center Information"
|
||||
@handler resourceCenterInfoHandler
|
||||
get /core/center/resource/:participantId (resourceCenterInfoReq) returns (resourceCenterInfoResp)
|
||||
}
|
||||
|
||||
//hpc二级接口
|
||||
|
@ -471,7 +479,7 @@ service pcm {
|
|||
|
||||
@doc "查询节点详情"
|
||||
@handler ShowNodeDetailsHandler
|
||||
get /vm/showNodeDetails (ShowNodeDetailsReq) returns (ShowNodeDetailsResp)
|
||||
get /vm/showNodeDetails (ShowNodeDetailsReq) returns (ShowNodeDetailsResp)
|
||||
}
|
||||
|
||||
//存算联动 接口
|
||||
|
|
|
@ -16,7 +16,6 @@ package config
|
|||
|
||||
import (
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"github.com/zeromicro/go-zero/core/stores/cache"
|
||||
"github.com/zeromicro/go-zero/core/stores/redis"
|
||||
"github.com/zeromicro/go-zero/rest"
|
||||
"github.com/zeromicro/go-zero/zrpc"
|
||||
|
@ -28,7 +27,6 @@ type Config struct {
|
|||
DataSource string
|
||||
}
|
||||
Redis redis.RedisConf
|
||||
Cache cache.CacheConf
|
||||
LogConf logx.LogConf
|
||||
K8sNativeConf zrpc.RpcClientConf
|
||||
ACRpcConf zrpc.RpcClientConf
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
package core
|
||||
|
||||
import (
|
||||
"gitlink.org.cn/jcce-pcm/pcm-coordinator/pkg/repository/result"
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/logic/core"
|
||||
"gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/svc"
|
||||
"gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/types"
|
||||
)
|
||||
|
||||
func ResourceCenterInfoHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.ResourceCenterInfoReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
return
|
||||
}
|
||||
|
||||
l := core.NewResourceCenterInfoLogic(r.Context(), svcCtx)
|
||||
resp, err := l.ResourceCenterInfo(&req)
|
||||
result.HttpResult(r, w, resp, err)
|
||||
}
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
package core
|
||||
|
||||
import (
|
||||
"gitlink.org.cn/jcce-pcm/pcm-coordinator/pkg/repository/result"
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/logic/core"
|
||||
"gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/svc"
|
||||
"gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/types"
|
||||
)
|
||||
|
||||
func TasksNumHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.TasksNumReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
return
|
||||
}
|
||||
|
||||
l := core.NewTasksNumLogic(r.Context(), svcCtx)
|
||||
resp, err := l.TasksNum(&req)
|
||||
result.HttpResult(r, w, resp, err)
|
||||
}
|
||||
}
|
|
@ -125,6 +125,16 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
|||
Path: "/core/getHashcat/:crackTaskId",
|
||||
Handler: core.GetHashcatHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodGet,
|
||||
Path: "/core/tasks/num",
|
||||
Handler: core.TasksNumHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodGet,
|
||||
Path: "/core/center/resource/:participantId",
|
||||
Handler: core.ResourceCenterInfoHandler(serverCtx),
|
||||
},
|
||||
},
|
||||
rest.WithPrefix("/pcm/v1"),
|
||||
)
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
package core
|
||||
|
||||
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 ResourceCenterInfoLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewResourceCenterInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ResourceCenterInfoLogic {
|
||||
return &ResourceCenterInfoLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *ResourceCenterInfoLogic) ResourceCenterInfo(req *types.ResourceCenterInfoReq) (resp *types.ResourceCenterInfoResp, err error) {
|
||||
// todo: add your logic here and delete this line
|
||||
resp = &types.ResourceCenterInfoResp{}
|
||||
l.svcCtx.DbEngin.Raw("select count(t.id) from task t,cloud c where c.task_id = t.id and c.participant_id = ? and t.status = ?", req.ParticipantId, "Running").Scan(&resp.RunningTasksNum)
|
||||
|
||||
l.svcCtx.DbEngin.Raw("select t.name from task t,cloud c where c.task_id = t.id and c.participant_id = ?", req.ParticipantId).Scan(&resp.TasksName)
|
||||
|
||||
l.svcCtx.DbEngin.Raw("select SUm(cpu_total) as cpu,sum(mem_total) as memory,SUM(disk_total) as storage FROM sc_node_avail_info where participant_id = ? GROUP BY created_time ORDER BY created_time desc LIMIT 1", req.ParticipantId).Scan(&resp.ResourceTotal)
|
||||
|
||||
l.svcCtx.DbEngin.Raw("select IFNULL(SUM(cpu_usable)/COUNT(*),0)as cpu,IFNULL(sum(mem_avail)/SUM(mem_total),0) as memory,IFNULL(sum(disk_avail)/SUM(disk_total),0) as storage FROM sc_node_avail_info where cpu_total != 0 and participant_id = ? GROUP BY created_time ORDER BY created_time desc LIMIT 1", req.ParticipantId).Scan(&resp.ResourceUsage)
|
||||
return
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
package core
|
||||
|
||||
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 TasksNumLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewTasksNumLogic(ctx context.Context, svcCtx *svc.ServiceContext) *TasksNumLogic {
|
||||
return &TasksNumLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *TasksNumLogic) TasksNum(req *types.TasksNumReq) (resp *types.TasksNumResp, err error) {
|
||||
resp = &types.TasksNumResp{}
|
||||
l.svcCtx.DbEngin.Raw("select count(*) from task ").Scan(&resp.TotalNum)
|
||||
l.svcCtx.DbEngin.Raw("select count(*) from task where status ='Running' ").Scan(&resp.RunningNum)
|
||||
l.svcCtx.DbEngin.Raw("select count(*) from task where status ='Completed' ").Scan(&resp.CompletedNum)
|
||||
return resp, nil
|
||||
}
|
|
@ -1,6 +1,38 @@
|
|||
// Code generated by goctl. DO NOT EDIT.
|
||||
package types
|
||||
|
||||
type ResourceCenterInfoReq struct {
|
||||
ParticipantId int64 `path:"participantId"`
|
||||
}
|
||||
|
||||
type ResourceCenterInfoResp struct {
|
||||
TasksName []string `json:"tasksName"`
|
||||
RunningTasksNum int64 `json:"runningTasksNum"`
|
||||
ResourceUsage ResourceUsage `json:"resourceUsage"`
|
||||
ResourceTotal ResourceTotal `json:"resourceTotal"`
|
||||
}
|
||||
|
||||
type ResourceUsage struct {
|
||||
Cpu float64 `json:"cpu"`
|
||||
Memory float64 `json:"memory"`
|
||||
Storage float64 `json:"storage"`
|
||||
}
|
||||
|
||||
type ResourceTotal struct {
|
||||
Cpu int64 `json:"cpu"`
|
||||
Memory int64 `json:"memory"`
|
||||
Storage int64 `json:"storage"`
|
||||
}
|
||||
|
||||
type TasksNumReq struct {
|
||||
}
|
||||
|
||||
type TasksNumResp struct {
|
||||
TotalNum int64 `json:"totalNum"`
|
||||
RunningNum int64 `json:"runningNum"`
|
||||
CompletedNum int64 `json:"completedNum"`
|
||||
}
|
||||
|
||||
type SubmitJobReq struct {
|
||||
SlurmVersion string `json:"slurmVersion"`
|
||||
Apptype string `json:"apptype,optional"`
|
||||
|
|
Loading…
Reference in New Issue