hpc resource overview

Former-commit-id: 6fe283469de83c72964bbab474109026c36f018b
This commit is contained in:
Jake 2024-04-11 17:45:32 +08:00
parent ef8369baeb
commit 7fce97fb6f
7 changed files with 136 additions and 7 deletions

View File

@ -9,5 +9,5 @@ type TaskOptions struct {
type Task interface {
PullTaskInfo(pullTaskInfoReq PullTaskInfoReq) (*PullTaskInfoResp, error)
PushTaskInfo(pushTaskInfoReq PushTaskInfoReq) (*PushTaskInfoResp, error)
PushResourceInfo(pushResourceInfoReq PushResourceInfoReq) error
PushResourceInfo(pushResourceInfoReq PushResourceInfoReq) (*PushResourceInfoResp, error)
}

View File

@ -50,8 +50,8 @@ func (t *task) PushTaskInfo(pushTaskInfoReq PushTaskInfoReq) (*PushTaskInfoResp,
url := t.client.url + "/pcm/v1/core/pushTaskInfo"
method := "POST"
infoReq := PullTaskInfoReq{AdapterId: pushTaskInfoReq.AdapterId}
jsonStr, _ := json.Marshal(infoReq)
//infoReq := PullTaskInfoReq{AdapterId: pushTaskInfoReq.AdapterId}
jsonStr, _ := json.Marshal(pushTaskInfoReq)
payload := strings.NewReader(string(jsonStr))
client := &http.Client{}
@ -66,7 +66,22 @@ func (t *task) PushTaskInfo(pushTaskInfoReq PushTaskInfoReq) (*PushTaskInfoResp,
return &resp, nil
}
func (t *task) PushResourceInfo(pushResourceInfoReq PushResourceInfoReq) error {
//TODO implement me
panic("implement me")
func (t *task) PushResourceInfo(pushResourceInfoReq PushResourceInfoReq) (*PushResourceInfoResp, error) {
url := t.client.url + "/pcm/v1/core/pushResourceInfo"
method := "POST"
//infoReq := PushResourceInfoReq{AdapterId: pushResourceInfoReq.AdapterId}
jsonStr, _ := json.Marshal(pushResourceInfoReq)
payload := strings.NewReader(string(jsonStr))
client := &http.Client{}
req, _ := http.NewRequest(method, url, payload)
req.Header.Add("Content-Type", "application/json")
res, _ := client.Do(req)
defer res.Body.Close()
body, _ := ioutil.ReadAll(res.Body)
var resp PushResourceInfoResp
json.Unmarshal(body, &resp)
return &resp, nil
}

View File

@ -30,9 +30,14 @@ type PushTaskInfoResp struct {
}
type PushResourceInfoReq struct {
AdapterId int64 `json:"adapterId"`
AdapterId int64 `json:"adapterId"`
ResourceStats []ResourceStats `json:"resourceStats"`
}
type PushResourceInfoResp struct {
Code int64
Msg string
}
type HpcInfo struct {
Id int64 `json:"id"` // id
TaskId int64 `json:"task_id"` // 任务id
@ -121,3 +126,27 @@ type VmInfo struct {
DeleteOnTermination bool `json:"delete_on_termination,omitempty"`
State string `json:"state,omitempty"`
}
type ResourceStats struct {
ClusterId int64
Name string
CpuCoreAvail int64
CpuCoreTotal int64
MemAvail float64
MemTotal float64
DiskAvail float64
DiskTotal float64
GpuAvail int64
CardsAvail []*Card
CpuCoreHours float64
Balance float64
}
type Card struct {
Platform string
Type string
Name string
TOpsAtFp16 float64
CardHours float64
CardNum int32
}

View File

@ -150,6 +150,10 @@ service pcm {
@handler jobHandler
get /hpc/job (hpcJobReq) returns (hpcJobResp)
@doc "超算资源总览"
@handler resourceHandler
get /hpc/resource (hpcResourceReq) returns (hpcResourceResp)
@doc "超算查询资产列表"
@handler queueAssetsHandler
get /hpc/queueAssets returns (QueueAssetsResp)

View File

@ -0,0 +1,28 @@
package hpc
import (
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/logic/hpc"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types"
)
func ResourceHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.HpcResourceReq
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := hpc.NewResourceLogic(r.Context(), svcCtx)
resp, err := l.Resource(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}

View File

@ -176,6 +176,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
Path: "/hpc/job",
Handler: hpc.JobHandler(serverCtx),
},
{
Method: http.MethodGet,
Path: "/hpc/resource",
Handler: hpc.ResourceHandler(serverCtx),
},
{
Method: http.MethodGet,
Path: "/hpc/queueAssets",

View File

@ -0,0 +1,48 @@
package hpc
import (
"context"
"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 ResourceLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewResourceLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ResourceLogic {
return &ResourceLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *ResourceLogic) Resource(req *types.HpcResourceReq) (resp *types.HpcResourceResp, err error) {
l.svcCtx.DbEngin.Raw("SELECT th.NAME as job_name,t.description as job_desc,t.commit_time as submit_time,th.STATUS as job_status,ta.name as adapter_name,tc.name as cluster_name,tc.label as cluster_type FROM task_hpc th LEFT JOIN task t ON t.id = th.task_id JOIN t_cluster tc on th.cluster_id = tc.id JOIN t_adapter ta on tc.adapter_id = ta.id")
hpcResource := types.HPCResource{
GPUCardsTotal: 0,
CPUCoresTotal: 0,
RAMTotal: 0,
GPUCardsUsed: 0,
CPUCoresUsed: 0,
RAMUsed: 0,
GPURate: 0,
CPURate: 0,
RAMRate: 0,
}
resp = &types.HpcResourceResp{
Code: 200,
Msg: "success",
HPCResource: hpcResource,
}
return resp, nil
}