Merge pull request 'hpc overview interfaces' (#75) from zhouqunjie/pcm-coordinator:master into master
Former-commit-id: ce9d470a5b26afff12df893f6f923dd54b811902
This commit is contained in:
commit
4ba32bb014
|
@ -37,6 +37,7 @@ type HpcInfo struct {
|
||||||
Id int64 `json:"id"` // id
|
Id int64 `json:"id"` // id
|
||||||
TaskId int64 `json:"task_id"` // 任务id
|
TaskId int64 `json:"task_id"` // 任务id
|
||||||
JobId string `json:"job_id"` // 作业id(在第三方系统中的作业id)
|
JobId string `json:"job_id"` // 作业id(在第三方系统中的作业id)
|
||||||
|
AdapterId int64 `json:"adapter_id"` // 执行任务的适配器id
|
||||||
ClusterId int64 `json:"cluster_id"` // 执行任务的集群id
|
ClusterId int64 `json:"cluster_id"` // 执行任务的集群id
|
||||||
ClusterType string `json:"cluster_type"` // 执行任务的集群类型
|
ClusterType string `json:"cluster_type"` // 执行任务的集群类型
|
||||||
Name string `json:"name"` // 名称
|
Name string `json:"name"` // 名称
|
||||||
|
|
|
@ -8,29 +8,20 @@ info(
|
||||||
version: "type version here"
|
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 (
|
type (
|
||||||
commitHpcTaskReq {
|
commitHpcTaskReq {
|
||||||
Name string `json:"name"` // paratera:jobName
|
Name string `json:"name"` // paratera:jobName
|
||||||
Description string `json:"description,optional"`
|
Description string `json:"description,optional"`
|
||||||
tenantId int64 `json:"tenantId,optional"`
|
tenantId int64 `json:"tenantId,optional"`
|
||||||
TaskId int64 `json:"taskId,optional"`
|
TaskId int64 `json:"taskId,optional"`
|
||||||
AdapterId int64 `json:"adapterId,optional"`
|
AdapterId int64 `json:"adapterId,optional"`
|
||||||
MatchLabels map[string]string `json:"matchLabels,optional"`
|
MatchLabels map[string]string `json:"matchLabels,optional"`
|
||||||
CardCount int64 `json:"cardCount,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"`
|
WallTime string `json:"wallTime,optional"`
|
||||||
CmdScript string `json:"cmdScript,optional"` // paratera:bootScript
|
CmdScript string `json:"cmdScript,optional"` // paratera:bootScript
|
||||||
AppType string `json:"appType,optional"`
|
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"`
|
Queue string `json:"queue,optional"`
|
||||||
NNode string `json:"nNode,optional"`
|
NNode string `json:"nNode,optional"`
|
||||||
SubmitType string `json:"submitType,optional"`
|
SubmitType string `json:"submitType,optional"`
|
||||||
|
@ -40,9 +31,7 @@ type (
|
||||||
Environment map[string]string `json:"environment,optional"`
|
Environment map[string]string `json:"environment,optional"`
|
||||||
ClusterType string `json:"clusterType,optional"`
|
ClusterType string `json:"clusterType,optional"`
|
||||||
}
|
}
|
||||||
)
|
|
||||||
|
|
||||||
type (
|
|
||||||
commitHpcTaskResp {
|
commitHpcTaskResp {
|
||||||
TaskId int64 `json:"taskId"`
|
TaskId int64 `json:"taskId"`
|
||||||
Code int32 `json:"code"`
|
Code int32 `json:"code"`
|
||||||
|
@ -51,35 +40,76 @@ type (
|
||||||
)
|
)
|
||||||
|
|
||||||
type (
|
type (
|
||||||
listJobReq {
|
hpcOverViewReq {
|
||||||
}
|
}
|
||||||
listJobResp {
|
hpcOverViewResp {
|
||||||
Code int32 `json:"code"`
|
Code int32 `json:"code"`
|
||||||
Msg string `json:"msg"`
|
Msg string `json:"msg"`
|
||||||
RecordCount int32 `json:"recordCount"`
|
Data HPCOverView `json:"data"`
|
||||||
Jobs []Job `json:"jobInfos"`
|
}
|
||||||
|
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 (
|
type (
|
||||||
listHistoryJobReq {
|
hpcAdapterSummaryReq {
|
||||||
}
|
}
|
||||||
listHistoryJobResp {
|
hpcAdapterSummaryResp {
|
||||||
Code int32 `json:"code"`
|
Code int32 `json:"code"`
|
||||||
Msg string `json:"msg"`
|
Msg string `json:"msg"`
|
||||||
RecordCount int32 `json:"recordCount"`
|
Data []HPCAdapterSummary `json:"data"`
|
||||||
HistoryJobs []HistoryJob `json:"jobInfoDbs"`
|
}
|
||||||
|
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 {
|
type QueueAssetsResp {
|
||||||
QueueAssets []QueueAsset `json:"queueAsset"`
|
QueueAssets []QueueAsset `json:"queueAsset"`
|
||||||
|
|
|
@ -23,6 +23,7 @@ type HpcInfo struct {
|
||||||
Id int64 `json:"id"` // id
|
Id int64 `json:"id"` // id
|
||||||
TaskId int64 `json:"task_id"` // 任务id
|
TaskId int64 `json:"task_id"` // 任务id
|
||||||
JobId string `json:"job_id"` // 作业id(在第三方系统中的作业id)
|
JobId string `json:"job_id"` // 作业id(在第三方系统中的作业id)
|
||||||
|
AdapterId int64 `json:"adapter_id"` // 执行任务的适配器id
|
||||||
ClusterId int64 `json:"cluster_id"` // 执行任务的集群id
|
ClusterId int64 `json:"cluster_id"` // 执行任务的集群id
|
||||||
ClusterType string `json:"cluster_type"` // 执行任务的集群类型
|
ClusterType string `json:"cluster_type"` // 执行任务的集群类型
|
||||||
Name string `json:"name"` // 名称
|
Name string `json:"name"` // 名称
|
||||||
|
|
|
@ -141,13 +141,17 @@ service pcm {
|
||||||
@handler commitHpcTaskHandler
|
@handler commitHpcTaskHandler
|
||||||
post /hpc/commitHpcTask (commitHpcTaskReq) returns (commitHpcTaskResp)
|
post /hpc/commitHpcTask (commitHpcTaskReq) returns (commitHpcTaskResp)
|
||||||
|
|
||||||
@doc "超算查询任务列表"
|
@doc "超算总览"
|
||||||
@handler listJobHandler
|
@handler overViewHandler
|
||||||
get /hpc/listJob (listJobReq) returns (listJobResp)
|
get /hpc/overview (hpcOverViewReq) returns (hpcOverViewResp)
|
||||||
|
|
||||||
@doc "超算查询历史任务列表"
|
@doc "超算适配器列表"
|
||||||
@handler listHistoryJobHandler
|
@handler adapterSummaryHandler
|
||||||
get /hpc/listHistoryJob (listHistoryJobReq) returns (listHistoryJobResp)
|
get /hpc/adapterSummary (hpcAdapterSummaryReq) returns (hpcAdapterSummaryResp)
|
||||||
|
|
||||||
|
@doc "超算查询任务列表"
|
||||||
|
@handler jobHandler
|
||||||
|
get /hpc/job (hpcJobReq) returns (hpcJobResp)
|
||||||
|
|
||||||
@doc "超算查询资产列表"
|
@doc "超算查询资产列表"
|
||||||
@handler queueAssetsHandler
|
@handler queueAssetsHandler
|
||||||
|
|
|
@ -5,7 +5,7 @@ Port: 8999
|
||||||
Timeout: 50000
|
Timeout: 50000
|
||||||
|
|
||||||
DB:
|
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:
|
Redis:
|
||||||
Host: 10.206.0.12:6379
|
Host: 10.206.0.12:6379
|
||||||
|
|
|
@ -1,24 +1,28 @@
|
||||||
package hpc
|
package hpc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"net/http"
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/rest/httpx"
|
"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/logic/hpc"
|
||||||
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc"
|
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc"
|
||||||
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types"
|
"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) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
var req types.ListHistoryJobReq
|
var req types.HpcAdapterSummaryReq
|
||||||
if err := httpx.Parse(r, &req); err != nil {
|
if err := httpx.Parse(r, &req); err != nil {
|
||||||
result.ParamErrorResult(r, w, err)
|
httpx.ErrorCtx(r.Context(), w, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
l := hpc.NewListHistoryJobLogic(r.Context(), svcCtx)
|
l := hpc.NewAdapterSummaryLogic(r.Context(), svcCtx)
|
||||||
resp, err := l.ListHistoryJob(&req)
|
resp, err := l.AdapterSummary(&req)
|
||||||
result.HttpResult(r, w, resp, err)
|
if err != nil {
|
||||||
|
httpx.ErrorCtx(r.Context(), w, err)
|
||||||
|
} else {
|
||||||
|
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,24 +1,28 @@
|
||||||
package hpc
|
package hpc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"net/http"
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/rest/httpx"
|
"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/logic/hpc"
|
||||||
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc"
|
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc"
|
||||||
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types"
|
"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) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
var req types.ListJobReq
|
var req types.HpcJobReq
|
||||||
if err := httpx.Parse(r, &req); err != nil {
|
if err := httpx.Parse(r, &req); err != nil {
|
||||||
result.ParamErrorResult(r, w, err)
|
httpx.ErrorCtx(r.Context(), w, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
l := hpc.NewListJobLogic(r.Context(), svcCtx)
|
l := hpc.NewJobLogic(r.Context(), svcCtx)
|
||||||
resp, err := l.ListJob(&req)
|
resp, err := l.Job(&req)
|
||||||
result.HttpResult(r, w, resp, err)
|
if err != nil {
|
||||||
|
httpx.ErrorCtx(r.Context(), w, err)
|
||||||
|
} else {
|
||||||
|
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -167,13 +167,18 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Method: http.MethodGet,
|
Method: http.MethodGet,
|
||||||
Path: "/hpc/listJob",
|
Path: "/hpc/overview",
|
||||||
Handler: hpc.ListJobHandler(serverCtx),
|
Handler: hpc.OverViewHandler(serverCtx),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Method: http.MethodGet,
|
Method: http.MethodGet,
|
||||||
Path: "/hpc/listHistoryJob",
|
Path: "/hpc/adapterSummary",
|
||||||
Handler: hpc.ListHistoryJobHandler(serverCtx),
|
Handler: hpc.AdapterSummaryHandler(serverCtx),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Method: http.MethodGet,
|
||||||
|
Path: "/hpc/job",
|
||||||
|
Handler: hpc.JobHandler(serverCtx),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Method: http.MethodGet,
|
Method: http.MethodGet,
|
||||||
|
|
|
@ -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
|
||||||
|
}
|
|
@ -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
|
||||||
|
}
|
|
@ -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
|
|
||||||
}
|
|
|
@ -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
|
|
||||||
}
|
|
|
@ -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
|
||||||
|
}
|
|
@ -835,14 +835,6 @@ type PageResult struct {
|
||||||
PageSize int `json:"pageSize,omitempty"`
|
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 {
|
type CommitHpcTaskReq struct {
|
||||||
Name string `json:"name"` // paratera:jobName
|
Name string `json:"name"` // paratera:jobName
|
||||||
Description string `json:"description,optional"`
|
Description string `json:"description,optional"`
|
||||||
|
@ -872,32 +864,76 @@ type CommitHpcTaskResp struct {
|
||||||
Msg string `json:"msg"`
|
Msg string `json:"msg"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ListJobReq struct {
|
type HpcOverViewReq struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type ListJobResp struct {
|
type HpcOverViewResp struct {
|
||||||
Code int32 `json:"code"`
|
Code int32 `json:"code"`
|
||||||
Msg string `json:"msg"`
|
Msg string `json:"msg"`
|
||||||
RecordCount int32 `json:"recordCount"`
|
Data HPCOverView `json:"data"`
|
||||||
Jobs []Job `json:"jobInfos"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type HistoryJob struct {
|
type HPCOverView struct {
|
||||||
SlurmVersion string `json:"slurmVersion"`
|
AdapterCount int32 `json:"adapterCount"`
|
||||||
Name string `json:"name"`
|
StackCount int32 `json:"stackCount"`
|
||||||
JobStartTime string `json:"JobStartTime"`
|
ClusterCount int32 `json:"clusterCount"`
|
||||||
JobRunTime string `json:"JobRunTime"`
|
TaskCount int32 `json:"taskCount"`
|
||||||
StateofJob string `json:"StateofJob"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type ListHistoryJobReq struct {
|
type HpcAdapterSummaryReq struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type ListHistoryJobResp struct {
|
type HpcAdapterSummaryResp struct {
|
||||||
Code int32 `json:"code"`
|
Code int32 `json:"code"`
|
||||||
Msg string `json:"msg"`
|
Msg string `json:"msg"`
|
||||||
RecordCount int32 `json:"recordCount"`
|
Data []HPCAdapterSummary `json:"data"`
|
||||||
HistoryJobs []HistoryJob `json:"jobInfoDbs"`
|
}
|
||||||
|
|
||||||
|
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 {
|
type QueueAssetsResp struct {
|
||||||
|
@ -5184,6 +5220,7 @@ type HpcInfo struct {
|
||||||
Id int64 `json:"id"` // id
|
Id int64 `json:"id"` // id
|
||||||
TaskId int64 `json:"task_id"` // 任务id
|
TaskId int64 `json:"task_id"` // 任务id
|
||||||
JobId string `json:"job_id"` // 作业id(在第三方系统中的作业id)
|
JobId string `json:"job_id"` // 作业id(在第三方系统中的作业id)
|
||||||
|
AdapterId int64 `json:"adapter_id"` // 执行任务的适配器id
|
||||||
ClusterId int64 `json:"cluster_id"` // 执行任务的集群id
|
ClusterId int64 `json:"cluster_id"` // 执行任务的集群id
|
||||||
ClusterType string `json:"cluster_type"` // 执行任务的集群类型
|
ClusterType string `json:"cluster_type"` // 执行任务的集群类型
|
||||||
Name string `json:"name"` // 名称
|
Name string `json:"name"` // 名称
|
||||||
|
|
Loading…
Reference in New Issue