From 8bd1c02fe4825ecc447fec2c295c3676b35fe889 Mon Sep 17 00:00:00 2001 From: Jake <450705171@qq.com> Date: Tue, 26 Mar 2024 19:11:28 +0800 Subject: [PATCH] hpc overview interfaces Former-commit-id: cd54d2f170d84740a83d087579c16ecccae56ae0 --- api/client/types.go | 1 + api/desc/hpc/pcm-hpc.api | 90 ++++++++++++------- api/desc/participant/pcm-participant.api | 1 + api/desc/pcm.api | 16 ++-- api/etc/pcm.yaml | 2 +- ...jobhandler.go => adaptersummaryhandler.go} | 20 +++-- .../hpc/{listjobhandler.go => jobhandler.go} | 20 +++-- api/internal/handler/hpc/overviewhandler.go | 28 ++++++ api/internal/handler/routes.go | 13 ++- api/internal/logic/hpc/adaptersummarylogic.go | 37 ++++++++ api/internal/logic/hpc/joblogic.go | 36 ++++++++ api/internal/logic/hpc/listhistoryjoblogic.go | 77 ---------------- api/internal/logic/hpc/listjoblogic.go | 77 ---------------- api/internal/logic/hpc/overviewlogic.go | 37 ++++++++ api/internal/types/types.go | 89 ++++++++++++------ 15 files changed, 307 insertions(+), 237 deletions(-) rename api/internal/handler/hpc/{listhistoryjobhandler.go => adaptersummaryhandler.go} (53%) rename api/internal/handler/hpc/{listjobhandler.go => jobhandler.go} (55%) create mode 100644 api/internal/handler/hpc/overviewhandler.go create mode 100644 api/internal/logic/hpc/adaptersummarylogic.go create mode 100644 api/internal/logic/hpc/joblogic.go delete mode 100644 api/internal/logic/hpc/listhistoryjoblogic.go delete mode 100644 api/internal/logic/hpc/listjoblogic.go create mode 100644 api/internal/logic/hpc/overviewlogic.go diff --git a/api/client/types.go b/api/client/types.go index 758f6bcb..0b8250f8 100644 --- a/api/client/types.go +++ b/api/client/types.go @@ -37,6 +37,7 @@ type HpcInfo struct { Id int64 `json:"id"` // id TaskId int64 `json:"task_id"` // 任务id JobId string `json:"job_id"` // 作业id(在第三方系统中的作业id) + AdapterId int64 `json:"adapter_id"` // 执行任务的适配器id ClusterId int64 `json:"cluster_id"` // 执行任务的集群id ClusterType string `json:"cluster_type"` // 执行任务的集群类型 Name string `json:"name"` // 名称 diff --git a/api/desc/hpc/pcm-hpc.api b/api/desc/hpc/pcm-hpc.api index 2a971c4d..9ba36b70 100644 --- a/api/desc/hpc/pcm-hpc.api +++ b/api/desc/hpc/pcm-hpc.api @@ -8,29 +8,20 @@ info( version: "type version here" ) -type Job { - SlurmVersion string `json:"slurmVersion"` - name string `json:"name"` - JobStartTime string `json:"JobStartTime"` - JobRunTime string `json:"JobRunTime"` - StateofJob string `json:"StateofJob"` -} - - type ( commitHpcTaskReq { - Name string `json:"name"` // paratera:jobName + Name string `json:"name"` // paratera:jobName Description string `json:"description,optional"` tenantId int64 `json:"tenantId,optional"` TaskId int64 `json:"taskId,optional"` AdapterId int64 `json:"adapterId,optional"` MatchLabels map[string]string `json:"matchLabels,optional"` CardCount int64 `json:"cardCount,optional"` - WorkDir string `json:"workDir,optional"` //paratera:workingDir + WorkDir string `json:"workDir,optional"` //paratera:workingDir WallTime string `json:"wallTime,optional"` CmdScript string `json:"cmdScript,optional"` // paratera:bootScript AppType string `json:"appType,optional"` - AppName string `json:"appName,optional"` // paratera:jobGroupName ac:appname + AppName string `json:"appName,optional"` // paratera:jobGroupName ac:appname Queue string `json:"queue,optional"` NNode string `json:"nNode,optional"` SubmitType string `json:"submitType,optional"` @@ -40,9 +31,7 @@ type ( Environment map[string]string `json:"environment,optional"` ClusterType string `json:"clusterType,optional"` } -) -type ( commitHpcTaskResp { TaskId int64 `json:"taskId"` Code int32 `json:"code"` @@ -51,35 +40,76 @@ type ( ) type ( - listJobReq { + hpcOverViewReq { } - listJobResp { + hpcOverViewResp { Code int32 `json:"code"` Msg string `json:"msg"` - RecordCount int32 `json:"recordCount"` - Jobs []Job `json:"jobInfos"` + Data HPCOverView `json:"data"` + } + HPCOverView { + AdapterCount int32 `json:"adapterCount"` + StackCount int32 `json:"stackCount"` + ClusterCount int32 `json:"clusterCount"` + TaskCount int32 `json:"taskCount"` } ) -type HistoryJob { - SlurmVersion string `json:"slurmVersion"` - name string `json:"name"` - JobStartTime string `json:"JobStartTime"` - JobRunTime string `json:"JobRunTime"` - StateofJob string `json:"StateofJob"` -} - type ( - listHistoryJobReq { + hpcAdapterSummaryReq { } - listHistoryJobResp { + hpcAdapterSummaryResp { Code int32 `json:"code"` Msg string `json:"msg"` - RecordCount int32 `json:"recordCount"` - HistoryJobs []HistoryJob `json:"jobInfoDbs"` + Data []HPCAdapterSummary `json:"data"` + } + HPCAdapterSummary { + AdapterName string `json:"adapterName"` + StackCount int32 `json:"stackCount"` + ClusterCount int32 `json:"clusterCount"` + TaskCount int32 `json:"taskCount"` } ) +type ( + hpcJobReq { + } + hpcJobResp { + Code int32 `json:"code"` + Msg string `json:"msg"` + Data []Job `json:"data"` + } + Job { + JobName string `json:"jobName"` + JobDesc string `json:"jobDesc"` + SubmitTime string `json:"submitTime"` + JobStatus string `json:"jobStatus"` + AdapterName string `json:"adapterName"` + ClusterName string `json:"clusterName"` + ClusterType string `json:"clusterType"` + } +) + +type ( + hpcResourceReq { + } + hpcResourceResp { + Code int32 `json:"code"` + Msg string `json:"msg"` + HPCResource HPCResource `json:"hpcResource"` + } + HPCResource { + GPUCardsTotal int32 `json:"gpuCoresTotal"` + CPUCoresTotal int32 `json:"cpuCoresTotal"` + RAMTotal int32 `json:"ramTotal"` + GPUCardsUsed int32 `json:"gpuCoresUsed"` + CPUCoresUsed int32 `json:"cpuCoresUsed"` + RAMUsed int32 `json:"ramUsed"` + GPURate float32 `json:"gpuRate"` + CPURate float32 `json:"cpuRate"` + RAMRate float32 `json:"ramRate"` + } +) type QueueAssetsResp { QueueAssets []QueueAsset `json:"queueAsset"` diff --git a/api/desc/participant/pcm-participant.api b/api/desc/participant/pcm-participant.api index f77be78e..d9f5a7d1 100644 --- a/api/desc/participant/pcm-participant.api +++ b/api/desc/participant/pcm-participant.api @@ -23,6 +23,7 @@ type HpcInfo struct { Id int64 `json:"id"` // id TaskId int64 `json:"task_id"` // 任务id JobId string `json:"job_id"` // 作业id(在第三方系统中的作业id) + AdapterId int64 `json:"adapter_id"` // 执行任务的适配器id ClusterId int64 `json:"cluster_id"` // 执行任务的集群id ClusterType string `json:"cluster_type"` // 执行任务的集群类型 Name string `json:"name"` // 名称 diff --git a/api/desc/pcm.api b/api/desc/pcm.api index 63fe0d68..f18cb9d3 100644 --- a/api/desc/pcm.api +++ b/api/desc/pcm.api @@ -133,13 +133,17 @@ service pcm { @handler commitHpcTaskHandler post /hpc/commitHpcTask (commitHpcTaskReq) returns (commitHpcTaskResp) - @doc "超算查询任务列表" - @handler listJobHandler - get /hpc/listJob (listJobReq) returns (listJobResp) + @doc "超算总览" + @handler overViewHandler + get /hpc/overview (hpcOverViewReq) returns (hpcOverViewResp) - @doc "超算查询历史任务列表" - @handler listHistoryJobHandler - get /hpc/listHistoryJob (listHistoryJobReq) returns (listHistoryJobResp) + @doc "超算适配器列表" + @handler adapterSummaryHandler + get /hpc/adapterSummary (hpcAdapterSummaryReq) returns (hpcAdapterSummaryResp) + + @doc "超算查询任务列表" + @handler jobHandler + get /hpc/job (hpcJobReq) returns (hpcJobResp) @doc "超算查询资产列表" @handler queueAssetsHandler diff --git a/api/etc/pcm.yaml b/api/etc/pcm.yaml index 3e586ba2..2e86edae 100644 --- a/api/etc/pcm.yaml +++ b/api/etc/pcm.yaml @@ -5,7 +5,7 @@ Port: 8999 Timeout: 50000 DB: - DataSource: root:uJpLd6u-J?HC1@(10.206.0.12:3306)/pcm?parseTime=true&loc=Local + DataSource: root:uJpLd6u-J?HC1@(47.92.88.143:3306)/pcm?parseTime=true&loc=Local Redis: Host: 10.206.0.12:6379 diff --git a/api/internal/handler/hpc/listhistoryjobhandler.go b/api/internal/handler/hpc/adaptersummaryhandler.go similarity index 53% rename from api/internal/handler/hpc/listhistoryjobhandler.go rename to api/internal/handler/hpc/adaptersummaryhandler.go index f37ce3fc..f5178829 100644 --- a/api/internal/handler/hpc/listhistoryjobhandler.go +++ b/api/internal/handler/hpc/adaptersummaryhandler.go @@ -1,24 +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" - "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/repository/result" - "net/http" ) -func ListHistoryJobHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { +func AdapterSummaryHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - var req types.ListHistoryJobReq + var req types.HpcAdapterSummaryReq if err := httpx.Parse(r, &req); err != nil { - result.ParamErrorResult(r, w, err) + httpx.ErrorCtx(r.Context(), w, err) return } - l := hpc.NewListHistoryJobLogic(r.Context(), svcCtx) - resp, err := l.ListHistoryJob(&req) - result.HttpResult(r, w, resp, err) + l := hpc.NewAdapterSummaryLogic(r.Context(), svcCtx) + resp, err := l.AdapterSummary(&req) + if err != nil { + httpx.ErrorCtx(r.Context(), w, err) + } else { + httpx.OkJsonCtx(r.Context(), w, resp) + } } } diff --git a/api/internal/handler/hpc/listjobhandler.go b/api/internal/handler/hpc/jobhandler.go similarity index 55% rename from api/internal/handler/hpc/listjobhandler.go rename to api/internal/handler/hpc/jobhandler.go index 53a3b782..ce1725c1 100644 --- a/api/internal/handler/hpc/listjobhandler.go +++ b/api/internal/handler/hpc/jobhandler.go @@ -1,24 +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" - "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/repository/result" - "net/http" ) -func ListJobHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { +func JobHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - var req types.ListJobReq + var req types.HpcJobReq if err := httpx.Parse(r, &req); err != nil { - result.ParamErrorResult(r, w, err) + httpx.ErrorCtx(r.Context(), w, err) return } - l := hpc.NewListJobLogic(r.Context(), svcCtx) - resp, err := l.ListJob(&req) - result.HttpResult(r, w, resp, err) + l := hpc.NewJobLogic(r.Context(), svcCtx) + resp, err := l.Job(&req) + if err != nil { + httpx.ErrorCtx(r.Context(), w, err) + } else { + httpx.OkJsonCtx(r.Context(), w, resp) + } } } diff --git a/api/internal/handler/hpc/overviewhandler.go b/api/internal/handler/hpc/overviewhandler.go new file mode 100644 index 00000000..3cb75018 --- /dev/null +++ b/api/internal/handler/hpc/overviewhandler.go @@ -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 OverViewHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + var req types.HpcOverViewReq + if err := httpx.Parse(r, &req); err != nil { + httpx.ErrorCtx(r.Context(), w, err) + return + } + + l := hpc.NewOverViewLogic(r.Context(), svcCtx) + resp, err := l.OverView(&req) + if err != nil { + httpx.ErrorCtx(r.Context(), w, err) + } else { + httpx.OkJsonCtx(r.Context(), w, resp) + } + } +} diff --git a/api/internal/handler/routes.go b/api/internal/handler/routes.go index 50f31d6c..9a809c81 100644 --- a/api/internal/handler/routes.go +++ b/api/internal/handler/routes.go @@ -157,13 +157,18 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { }, { Method: http.MethodGet, - Path: "/hpc/listJob", - Handler: hpc.ListJobHandler(serverCtx), + Path: "/hpc/overview", + Handler: hpc.OverViewHandler(serverCtx), }, { Method: http.MethodGet, - Path: "/hpc/listHistoryJob", - Handler: hpc.ListHistoryJobHandler(serverCtx), + Path: "/hpc/adapterSummary", + Handler: hpc.AdapterSummaryHandler(serverCtx), + }, + { + Method: http.MethodGet, + Path: "/hpc/job", + Handler: hpc.JobHandler(serverCtx), }, { Method: http.MethodGet, diff --git a/api/internal/logic/hpc/adaptersummarylogic.go b/api/internal/logic/hpc/adaptersummarylogic.go new file mode 100644 index 00000000..2bdbe614 --- /dev/null +++ b/api/internal/logic/hpc/adaptersummarylogic.go @@ -0,0 +1,37 @@ +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 AdapterSummaryLogic struct { + logx.Logger + ctx context.Context + svcCtx *svc.ServiceContext +} + +func NewAdapterSummaryLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AdapterSummaryLogic { + return &AdapterSummaryLogic{ + Logger: logx.WithContext(ctx), + ctx: ctx, + svcCtx: svcCtx, + } +} + +func (l *AdapterSummaryLogic) AdapterSummary(req *types.HpcAdapterSummaryReq) (resp *types.HpcAdapterSummaryResp, err error) { + var hpcAdapterSummary []types.HPCAdapterSummary + + l.svcCtx.DbEngin.Raw("SELECT ta.NAME AS adapter_name,count( DISTINCT label ) as stack_count,count( DISTINCT tc.id ) as cluster_count,count( DISTINCT th.id) as task_count FROM t_adapter ta LEFT JOIN t_cluster tc ON ta.id = tc.adapter_id LEFT JOIN task_hpc th ON ta.id = th.adapter_id WHERE ta.type = 2 GROUP BY ta.id").Scan(&hpcAdapterSummary) + + resp = &types.HpcAdapterSummaryResp{ + Code: 200, + Msg: "success", + Data: hpcAdapterSummary, + } + return resp, nil +} diff --git a/api/internal/logic/hpc/joblogic.go b/api/internal/logic/hpc/joblogic.go new file mode 100644 index 00000000..29ac6ea9 --- /dev/null +++ b/api/internal/logic/hpc/joblogic.go @@ -0,0 +1,36 @@ +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 JobLogic struct { + logx.Logger + ctx context.Context + svcCtx *svc.ServiceContext +} + +func NewJobLogic(ctx context.Context, svcCtx *svc.ServiceContext) *JobLogic { + return &JobLogic{ + Logger: logx.WithContext(ctx), + ctx: ctx, + svcCtx: svcCtx, + } +} + +func (l *JobLogic) Job(req *types.HpcJobReq) (resp *types.HpcJobResp, err error) { + + var job []types.Job + 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").Scan(&job) + resp = &types.HpcJobResp{ + Code: 200, + Msg: "success", + Data: job, + } + return resp, nil +} diff --git a/api/internal/logic/hpc/listhistoryjoblogic.go b/api/internal/logic/hpc/listhistoryjoblogic.go deleted file mode 100644 index 7647ce56..00000000 --- a/api/internal/logic/hpc/listhistoryjoblogic.go +++ /dev/null @@ -1,77 +0,0 @@ -/* - - Copyright (c) [2023] [pcm] - [pcm-coordinator] is licensed under Mulan PSL v2. - You can use this software according to the terms and conditions of the Mulan PSL v2. - You may obtain a copy of Mulan PSL v2 at: - http://license.coscl.org.cn/MulanPSL2 - THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, - EITHER EXPaRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, - MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. - See the Mulan PSL v2 for more details. - -*/ - -package hpc - -import ( - "context" - "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/helper/enum" - "strings" - - "github.com/zeromicro/go-zero/core/logx" -) - -type ListHistoryJobLogic struct { - logx.Logger - ctx context.Context - svcCtx *svc.ServiceContext -} - -func NewListHistoryJobLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ListHistoryJobLogic { - return &ListHistoryJobLogic{ - Logger: logx.WithContext(ctx), - ctx: ctx, - svcCtx: svcCtx, - } -} - -func (l *ListHistoryJobLogic) ListHistoryJob(req *types.ListHistoryJobReq) (resp *types.ListHistoryJobResp, err error) { - - resp = &types.ListHistoryJobResp{} - - var tasks []types.HistoryJob - // 查询任务数据 - - tx := l.svcCtx.DbEngin.Raw("SELECT h.service_name as SlurmVersion,h.name,h.start_time as JobStartTime,h.running_time as JobRunTime,t.status as StateofJob from hpc h join task t on t.id = h.task_id and t.status = 'Completed'").Scan(&tasks) - if tx.Error != nil { - logx.Error(err) - return nil, tx.Error - } - for _, task := range tasks { - // 承接方转义 - if task.SlurmVersion != "" { - var names []string - servicesName := strings.Split(task.SlurmVersion, ",") - for _, name := range servicesName { - names = append(names, enum.Partner(name).String()) - } - task.SlurmVersion = strings.Join(names, ",") - } - resp.HistoryJobs = append(resp.HistoryJobs, types.HistoryJob{ - SlurmVersion: task.SlurmVersion, - Name: task.Name, - JobStartTime: task.JobStartTime, - JobRunTime: task.JobRunTime, - StateofJob: task.StateofJob, - }) - - } - resp.Code = 200 - resp.Msg = "success" - resp.RecordCount = int32(len(resp.HistoryJobs)) - - return resp, nil -} diff --git a/api/internal/logic/hpc/listjoblogic.go b/api/internal/logic/hpc/listjoblogic.go deleted file mode 100644 index d6a4905e..00000000 --- a/api/internal/logic/hpc/listjoblogic.go +++ /dev/null @@ -1,77 +0,0 @@ -/* - - Copyright (c) [2023] [pcm] - [pcm-coordinator] is licensed under Mulan PSL v2. - You can use this software according to the terms and conditions of the Mulan PSL v2. - You may obtain a copy of Mulan PSL v2 at: - http://license.coscl.org.cn/MulanPSL2 - THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, - EITHER EXPaRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, - MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. - See the Mulan PSL v2 for more details. - -*/ - -package hpc - -import ( - "context" - "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/helper/enum" - "strings" - - "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 ListJobLogic struct { - logx.Logger - ctx context.Context - svcCtx *svc.ServiceContext -} - -func NewListJobLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ListJobLogic { - return &ListJobLogic{ - Logger: logx.WithContext(ctx), - ctx: ctx, - svcCtx: svcCtx, - } -} - -func (l *ListJobLogic) ListJob(req *types.ListJobReq) (resp *types.ListJobResp, err error) { - - resp = &types.ListJobResp{} - - var tasks []types.Job - // 查询任务数据 - tx := l.svcCtx.DbEngin.Raw("SELECT h.service_name as SlurmVersion,h.name,h.start_time as JobStartTime,h.running_time as JobRunTime,t.status as StateofJob from hpc h join task t on t.id = h.task_id and t.status != 'Completed'").Scan(&tasks) - if tx.Error != nil { - logx.Error(err) - return nil, tx.Error - } - for _, task := range tasks { - // 承接方转义 - if task.SlurmVersion != "" { - var names []string - servicesName := strings.Split(task.SlurmVersion, ",") - for _, name := range servicesName { - names = append(names, enum.Partner(name).String()) - } - task.SlurmVersion = strings.Join(names, ",") - } - resp.Jobs = append(resp.Jobs, types.Job{ - SlurmVersion: task.SlurmVersion, - Name: task.Name, - JobStartTime: task.JobStartTime, - JobRunTime: task.JobRunTime + "s", - StateofJob: task.StateofJob, - }) - - } - resp.Code = 200 - resp.Msg = "success" - resp.RecordCount = int32(len(resp.Jobs)) - - return resp, nil -} diff --git a/api/internal/logic/hpc/overviewlogic.go b/api/internal/logic/hpc/overviewlogic.go new file mode 100644 index 00000000..b3a447ab --- /dev/null +++ b/api/internal/logic/hpc/overviewlogic.go @@ -0,0 +1,37 @@ +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 OverViewLogic struct { + logx.Logger + ctx context.Context + svcCtx *svc.ServiceContext +} + +func NewOverViewLogic(ctx context.Context, svcCtx *svc.ServiceContext) *OverViewLogic { + return &OverViewLogic{ + Logger: logx.WithContext(ctx), + ctx: ctx, + svcCtx: svcCtx, + } +} + +func (l *OverViewLogic) OverView(req *types.HpcOverViewReq) (resp *types.HpcOverViewResp, err error) { + + var overView types.HPCOverView + tx := l.svcCtx.DbEngin.Raw("SELECT count( DISTINCT a.id ) as adapter_count,count( DISTINCT label ) as stack_count,count( c.id ) as cluster_count,(select count(*) from task_hpc) as task_count FROM t_cluster c JOIN t_adapter a ON c.adapter_id = a.id AND a.type = 2 ").Scan(&overView) + + println(tx) + resp = &types.HpcOverViewResp{ + Code: 200, + Msg: "success", + Data: overView, + } + return resp, nil +} diff --git a/api/internal/types/types.go b/api/internal/types/types.go index a3bbb150..52af5b0d 100644 --- a/api/internal/types/types.go +++ b/api/internal/types/types.go @@ -841,14 +841,6 @@ type PageResult struct { PageSize int `json:"pageSize,omitempty"` } -type Job struct { - SlurmVersion string `json:"slurmVersion"` - Name string `json:"name"` - JobStartTime string `json:"JobStartTime"` - JobRunTime string `json:"JobRunTime"` - StateofJob string `json:"StateofJob"` -} - type CommitHpcTaskReq struct { Name string `json:"name"` // paratera:jobName Description string `json:"description,optional"` @@ -878,32 +870,76 @@ type CommitHpcTaskResp struct { Msg string `json:"msg"` } -type ListJobReq struct { +type HpcOverViewReq struct { } -type ListJobResp struct { - Code int32 `json:"code"` - Msg string `json:"msg"` - RecordCount int32 `json:"recordCount"` - Jobs []Job `json:"jobInfos"` +type HpcOverViewResp struct { + Code int32 `json:"code"` + Msg string `json:"msg"` + Data HPCOverView `json:"data"` } -type HistoryJob struct { - SlurmVersion string `json:"slurmVersion"` - Name string `json:"name"` - JobStartTime string `json:"JobStartTime"` - JobRunTime string `json:"JobRunTime"` - StateofJob string `json:"StateofJob"` +type HPCOverView struct { + AdapterCount int32 `json:"adapterCount"` + StackCount int32 `json:"stackCount"` + ClusterCount int32 `json:"clusterCount"` + TaskCount int32 `json:"taskCount"` } -type ListHistoryJobReq struct { +type HpcAdapterSummaryReq struct { } -type ListHistoryJobResp struct { - Code int32 `json:"code"` - Msg string `json:"msg"` - RecordCount int32 `json:"recordCount"` - HistoryJobs []HistoryJob `json:"jobInfoDbs"` +type HpcAdapterSummaryResp struct { + Code int32 `json:"code"` + Msg string `json:"msg"` + Data []HPCAdapterSummary `json:"data"` +} + +type HPCAdapterSummary struct { + AdapterName string `json:"adapterName"` + StackCount int32 `json:"stackCount"` + ClusterCount int32 `json:"clusterCount"` + TaskCount int32 `json:"taskCount"` +} + +type HpcJobReq struct { +} + +type HpcJobResp struct { + Code int32 `json:"code"` + Msg string `json:"msg"` + Data []Job `json:"data"` +} + +type Job struct { + JobName string `json:"jobName"` + JobDesc string `json:"jobDesc"` + SubmitTime string `json:"submitTime"` + JobStatus string `json:"jobStatus"` + AdapterName string `json:"adapterName"` + ClusterName string `json:"clusterName"` + ClusterType string `json:"clusterType"` +} + +type HpcResourceReq struct { +} + +type HpcResourceResp struct { + Code int32 `json:"code"` + Msg string `json:"msg"` + HPCResource HPCResource `json:"hpcResource"` +} + +type HPCResource struct { + GPUCardsTotal int32 `json:"gpuCoresTotal"` + CPUCoresTotal int32 `json:"cpuCoresTotal"` + RAMTotal int32 `json:"ramTotal"` + GPUCardsUsed int32 `json:"gpuCoresUsed"` + CPUCoresUsed int32 `json:"cpuCoresUsed"` + RAMUsed int32 `json:"ramUsed"` + GPURate float32 `json:"gpuRate"` + CPURate float32 `json:"cpuRate"` + RAMRate float32 `json:"ramRate"` } type QueueAssetsResp struct { @@ -5190,6 +5226,7 @@ type HpcInfo struct { Id int64 `json:"id"` // id TaskId int64 `json:"task_id"` // 任务id JobId string `json:"job_id"` // 作业id(在第三方系统中的作业id) + AdapterId int64 `json:"adapter_id"` // 执行任务的适配器id ClusterId int64 `json:"cluster_id"` // 执行任务的集群id ClusterType string `json:"cluster_type"` // 执行任务的集群类型 Name string `json:"name"` // 名称