Merge pull request 'hpc resource overview' (#116) from zhouqunjie/pcm-coordinator:master into master
Former-commit-id: 1d127fdec9ee0ca86e65fefc6dcc35d77e45301b
This commit is contained in:
commit
01603bf170
|
@ -12,7 +12,7 @@ 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 string `json:"adapterId,optional"`
|
AdapterId string `json:"adapterId,optional"`
|
||||||
MatchLabels map[string]string `json:"matchLabels,optional"`
|
MatchLabels map[string]string `json:"matchLabels,optional"`
|
||||||
|
@ -99,15 +99,15 @@ type (
|
||||||
HPCResource HPCResource `json:"hpcResource"`
|
HPCResource HPCResource `json:"hpcResource"`
|
||||||
}
|
}
|
||||||
HPCResource {
|
HPCResource {
|
||||||
GPUCardsTotal int32 `json:"gpuCoresTotal"`
|
GPUCardsTotal float64 `json:"gpuCoresTotal"`
|
||||||
CPUCoresTotal int32 `json:"cpuCoresTotal"`
|
CPUCoresTotal float64 `json:"cpuCoresTotal"`
|
||||||
RAMTotal int32 `json:"ramTotal"`
|
RAMTotal float64 `json:"ramTotal"`
|
||||||
GPUCardsUsed int32 `json:"gpuCoresUsed"`
|
GPUCardsUsed float64 `json:"gpuCoresUsed"`
|
||||||
CPUCoresUsed int32 `json:"cpuCoresUsed"`
|
CPUCoresUsed float64 `json:"cpuCoresUsed"`
|
||||||
RAMUsed int32 `json:"ramUsed"`
|
RAMUsed float64 `json:"ramUsed"`
|
||||||
GPURate float32 `json:"gpuRate"`
|
GPURate float64 `json:"gpuRate"`
|
||||||
CPURate float32 `json:"cpuRate"`
|
CPURate float64 `json:"cpuRate"`
|
||||||
RAMRate float32 `json:"ramRate"`
|
RAMRate float64 `json:"ramRate"`
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,6 @@ package hpc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
"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"
|
||||||
|
|
||||||
|
@ -25,18 +24,29 @@ func NewResourceLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Resource
|
||||||
|
|
||||||
func (l *ResourceLogic) Resource(req *types.HpcResourceReq) (resp *types.HpcResourceResp, err error) {
|
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")
|
type hpcResourceOV struct {
|
||||||
|
CpuAvail float64 `json:"cpu_avail"`
|
||||||
|
CpuTotal float64 `json:"cpu_total"`
|
||||||
|
MemAvail float64 `json:"mem_avail"`
|
||||||
|
MemTotal float64 `json:"mem_total"`
|
||||||
|
DiskAvail float64 `json:"disk_avail"`
|
||||||
|
DiskTotal float64 `json:"disk_total"`
|
||||||
|
GpuAvail float64 `json:"gpu_avail"`
|
||||||
|
GpuTotal float64 `json:"gpu_total"`
|
||||||
|
}
|
||||||
|
var hrov hpcResourceOV
|
||||||
|
l.svcCtx.DbEngin.Raw("SELECT sum(cpu_avail) as cpu_avail,sum(cpu_total) as cpu_total,sum(mem_avail) as mem_avail,sum(mem_total) as mem_total,sum(disk_avail) as disk_avail,sum(disk_total) as disk_total,sum(gpu_avail) as gpu_avail,sum(gpu_total) as gpu_total FROM t_cluster_resource where cluster_type = 2").Scan(&hrov)
|
||||||
|
|
||||||
hpcResource := types.HPCResource{
|
hpcResource := types.HPCResource{
|
||||||
GPUCardsTotal: 0,
|
GPUCardsTotal: hrov.GpuTotal,
|
||||||
CPUCoresTotal: 0,
|
CPUCoresTotal: hrov.CpuTotal,
|
||||||
RAMTotal: 0,
|
RAMTotal: hrov.MemTotal,
|
||||||
GPUCardsUsed: 0,
|
GPUCardsUsed: hrov.GpuTotal - hrov.GpuAvail,
|
||||||
CPUCoresUsed: 0,
|
CPUCoresUsed: hrov.CpuTotal - hrov.CpuAvail,
|
||||||
RAMUsed: 0,
|
RAMUsed: hrov.MemTotal - hrov.MemAvail,
|
||||||
GPURate: 0,
|
GPURate: (hrov.GpuTotal - hrov.GpuAvail) / hrov.GpuTotal,
|
||||||
CPURate: 0,
|
CPURate: (hrov.CpuTotal - hrov.CpuAvail) / hrov.CpuTotal,
|
||||||
RAMRate: 0,
|
RAMRate: (hrov.MemTotal - hrov.MemAvail) / hrov.MemTotal,
|
||||||
}
|
}
|
||||||
|
|
||||||
resp = &types.HpcResourceResp{
|
resp = &types.HpcResourceResp{
|
||||||
|
|
|
@ -937,15 +937,15 @@ type HpcResourceResp struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type HPCResource struct {
|
type HPCResource struct {
|
||||||
GPUCardsTotal int32 `json:"gpuCoresTotal"`
|
GPUCardsTotal float64 `json:"gpuCoresTotal"`
|
||||||
CPUCoresTotal int32 `json:"cpuCoresTotal"`
|
CPUCoresTotal float64 `json:"cpuCoresTotal"`
|
||||||
RAMTotal int32 `json:"ramTotal"`
|
RAMTotal float64 `json:"ramTotal"`
|
||||||
GPUCardsUsed int32 `json:"gpuCoresUsed"`
|
GPUCardsUsed float64 `json:"gpuCoresUsed"`
|
||||||
CPUCoresUsed int32 `json:"cpuCoresUsed"`
|
CPUCoresUsed float64 `json:"cpuCoresUsed"`
|
||||||
RAMUsed int32 `json:"ramUsed"`
|
RAMUsed float64 `json:"ramUsed"`
|
||||||
GPURate float32 `json:"gpuRate"`
|
GPURate float64 `json:"gpuRate"`
|
||||||
CPURate float32 `json:"cpuRate"`
|
CPURate float64 `json:"cpuRate"`
|
||||||
RAMRate float32 `json:"ramRate"`
|
RAMRate float64 `json:"ramRate"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type QueueAssetsResp struct {
|
type QueueAssetsResp struct {
|
||||||
|
|
|
@ -0,0 +1,29 @@
|
||||||
|
package models
|
||||||
|
|
||||||
|
import "github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||||
|
|
||||||
|
var _ TClusterResourceModel = (*customTClusterResourceModel)(nil)
|
||||||
|
|
||||||
|
type (
|
||||||
|
// TClusterResourceModel is an interface to be customized, add more methods here,
|
||||||
|
// and implement the added methods in customTClusterResourceModel.
|
||||||
|
TClusterResourceModel interface {
|
||||||
|
tClusterResourceModel
|
||||||
|
withSession(session sqlx.Session) TClusterResourceModel
|
||||||
|
}
|
||||||
|
|
||||||
|
customTClusterResourceModel struct {
|
||||||
|
*defaultTClusterResourceModel
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
// NewTClusterResourceModel returns a model for the database table.
|
||||||
|
func NewTClusterResourceModel(conn sqlx.SqlConn) TClusterResourceModel {
|
||||||
|
return &customTClusterResourceModel{
|
||||||
|
defaultTClusterResourceModel: newTClusterResourceModel(conn),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *customTClusterResourceModel) withSession(session sqlx.Session) TClusterResourceModel {
|
||||||
|
return NewTClusterResourceModel(sqlx.NewSqlConnFromSession(session))
|
||||||
|
}
|
|
@ -0,0 +1,93 @@
|
||||||
|
// Code generated by goctl. DO NOT EDIT.
|
||||||
|
|
||||||
|
package models
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"database/sql"
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/core/stores/builder"
|
||||||
|
"github.com/zeromicro/go-zero/core/stores/sqlc"
|
||||||
|
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||||
|
"github.com/zeromicro/go-zero/core/stringx"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
tClusterResourceFieldNames = builder.RawFieldNames(&TClusterResource{})
|
||||||
|
tClusterResourceRows = strings.Join(tClusterResourceFieldNames, ",")
|
||||||
|
tClusterResourceRowsExpectAutoSet = strings.Join(stringx.Remove(tClusterResourceFieldNames, "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), ",")
|
||||||
|
tClusterResourceRowsWithPlaceHolder = strings.Join(stringx.Remove(tClusterResourceFieldNames, "`cluster_id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), "=?,") + "=?"
|
||||||
|
)
|
||||||
|
|
||||||
|
type (
|
||||||
|
tClusterResourceModel interface {
|
||||||
|
Insert(ctx context.Context, data *TClusterResource) (sql.Result, error)
|
||||||
|
FindOne(ctx context.Context, clusterId int64) (*TClusterResource, error)
|
||||||
|
Update(ctx context.Context, data *TClusterResource) error
|
||||||
|
Delete(ctx context.Context, clusterId int64) error
|
||||||
|
}
|
||||||
|
|
||||||
|
defaultTClusterResourceModel struct {
|
||||||
|
conn sqlx.SqlConn
|
||||||
|
table string
|
||||||
|
}
|
||||||
|
|
||||||
|
TClusterResource struct {
|
||||||
|
ClusterId int64 `db:"cluster_id"`
|
||||||
|
ClusterName string `db:"cluster_name"`
|
||||||
|
ClusterType int64 `db:"cluster_type"` // 类型0->容器,1->智算,2->超算,3-虚拟机
|
||||||
|
CpuAvail float64 `db:"cpu_avail"`
|
||||||
|
CpuTotal float64 `db:"cpu_total"`
|
||||||
|
MemAvail float64 `db:"mem_avail"`
|
||||||
|
MemTotal float64 `db:"mem_total"`
|
||||||
|
DiskAvail float64 `db:"disk_avail"`
|
||||||
|
DiskTotal float64 `db:"disk_total"`
|
||||||
|
GpuAvail float64 `db:"gpu_avail"`
|
||||||
|
GpuTotal float64 `db:"gpu_total"`
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
func newTClusterResourceModel(conn sqlx.SqlConn) *defaultTClusterResourceModel {
|
||||||
|
return &defaultTClusterResourceModel{
|
||||||
|
conn: conn,
|
||||||
|
table: "`t_cluster_resource`",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *defaultTClusterResourceModel) Delete(ctx context.Context, clusterId int64) error {
|
||||||
|
query := fmt.Sprintf("delete from %s where `cluster_id` = ?", m.table)
|
||||||
|
_, err := m.conn.ExecCtx(ctx, query, clusterId)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *defaultTClusterResourceModel) FindOne(ctx context.Context, clusterId int64) (*TClusterResource, error) {
|
||||||
|
query := fmt.Sprintf("select %s from %s where `cluster_id` = ? limit 1", tClusterResourceRows, m.table)
|
||||||
|
var resp TClusterResource
|
||||||
|
err := m.conn.QueryRowCtx(ctx, &resp, query, clusterId)
|
||||||
|
switch err {
|
||||||
|
case nil:
|
||||||
|
return &resp, nil
|
||||||
|
case sqlc.ErrNotFound:
|
||||||
|
return nil, ErrNotFound
|
||||||
|
default:
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *defaultTClusterResourceModel) Insert(ctx context.Context, data *TClusterResource) (sql.Result, error) {
|
||||||
|
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", m.table, tClusterResourceRowsExpectAutoSet)
|
||||||
|
ret, err := m.conn.ExecCtx(ctx, query, data.ClusterId, data.ClusterName, data.ClusterType, data.CpuAvail, data.CpuTotal, data.MemAvail, data.MemTotal, data.DiskAvail, data.DiskTotal, data.GpuAvail, data.GpuTotal)
|
||||||
|
return ret, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *defaultTClusterResourceModel) Update(ctx context.Context, data *TClusterResource) error {
|
||||||
|
query := fmt.Sprintf("update %s set %s where `cluster_id` = ?", m.table, tClusterResourceRowsWithPlaceHolder)
|
||||||
|
_, err := m.conn.ExecCtx(ctx, query, data.ClusterName, data.ClusterType, data.CpuAvail, data.CpuTotal, data.MemAvail, data.MemTotal, data.DiskAvail, data.DiskTotal, data.GpuAvail, data.GpuTotal, data.ClusterId)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *defaultTClusterResourceModel) tableName() string {
|
||||||
|
return m.table
|
||||||
|
}
|
Loading…
Reference in New Issue