查询队列资源信息
Former-commit-id: 0ca3552e497b953d07121f8439c4aac6b21d8d24
This commit is contained in:
parent
a49f365a41
commit
bf4d6eee35
|
@ -425,20 +425,20 @@ type ResultData struct {
|
|||
Data MetricData `json:"data"`
|
||||
}
|
||||
|
||||
type NodeAssetsResp{
|
||||
NodeAssets []NodeAsset `json:"nodeAssets"`
|
||||
|
||||
type NodeAssetsResp {
|
||||
NodeAssets []NodeAsset `json:"nodeAssets"`
|
||||
}
|
||||
|
||||
type NodeAsset{
|
||||
NodeName string `db:"node_name"` // 节点名称
|
||||
CpuTotal int64 `db:"cpu_total"` // cpu核数
|
||||
CpuUsable float64 `db:"cpu_usable"` // cpu可用率
|
||||
DiskTotal int64 `db:"disk_total"` // 磁盘空间
|
||||
DiskAvail int64 `db:"disk_avail"` // 磁盘可用空间
|
||||
MemTotal int64 `db:"mem_total"` // 内存总数
|
||||
MemAvail int64 `db:"mem_avail"` // 内存可用数
|
||||
GpuTotal int64 `db:"gpu_total"` // gpu总数
|
||||
GpuAvail int64 `db:"gpu_avail"` // gpu可用数
|
||||
ParticipantId int64 `db:"participant_id"` // 集群动态信息id
|
||||
type NodeAsset {
|
||||
TenantName string `json:"tenantName"` //租户名称
|
||||
NodeName string `json:"NodeName"` // 节点名称
|
||||
CpuTotal int64 `json:"CpuTotal"` // cpu核数
|
||||
CpuUsable float64 `json:"CpuUsable"` // cpu可用率
|
||||
DiskTotal int64 `json:"DiskTotal"` // 磁盘空间
|
||||
DiskAvail int64 `json:"DiskAvail"` // 磁盘可用空间
|
||||
MemTotal int64 `json:"MemTotal"` // 内存总数
|
||||
MemAvail int64 `json:"MemAvail"` // 内存可用数
|
||||
GpuTotal int64 `json:"GpuTotal"` // gpu总数
|
||||
GpuAvail int64 `json:"GpuAvail"` // gpu可用数
|
||||
ParticipantId int64 `json:"ParticipantId"` // 集群动态信息id
|
||||
}
|
|
@ -49,11 +49,11 @@ type (
|
|||
|
||||
type QueueAssetsResp {
|
||||
QueueAssets []QueueAsset `json:"queueAsset"`
|
||||
|
||||
}
|
||||
type QueueAsset{
|
||||
type QueueAsset {
|
||||
TenantName string `json:"tenantName"` //租户名称
|
||||
ParticipantId int64 `json:"participantId"`
|
||||
AclHosts string `json:"aclHosts"`
|
||||
AclHosts string `json:"aclHosts"` // 可用节点,多个节点用逗号隔开
|
||||
QueNodes string `json:"queNodes"` //队列节点总数
|
||||
QueMinNodect string `json:"queMinNodect,omitempty"` //队列最小节点数
|
||||
QueMaxNgpus string `json:"queMaxNgpus,omitempty"` //队列最大GPU卡数
|
||||
|
|
|
@ -2,8 +2,6 @@ package core
|
|||
|
||||
import (
|
||||
"context"
|
||||
"gitlink.org.cn/jcce-pcm/pcm-coordinator/model"
|
||||
|
||||
"gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/svc"
|
||||
"gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/types"
|
||||
|
||||
|
@ -25,17 +23,13 @@ func NewNodeAssetsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *NodeAs
|
|||
}
|
||||
|
||||
func (l *NodeAssetsLogic) NodeAssets() (resp *types.NodeAssetsResp, err error) {
|
||||
// todo: add your logic here and delete this line
|
||||
// 查询数据库系节点动态资源信息
|
||||
var nodeAvailInfos []model.ScNodeAvailInfo
|
||||
tx := l.svcCtx.DbEngin.Find(&nodeAvailInfos).Group("participant_id")
|
||||
|
||||
nodeResp := types.NodeAssetsResp{}
|
||||
tx := l.svcCtx.DbEngin.Raw("SELECT nai.*,ti.tenant_name FROM sc_node_avail_info nai left join sc_participant_phy_info ppi on ppi.id = nai.participant_id left JOIN sc_tenant_info ti on ti.id = ppi.tenant_id WHERE nai.created_time IN ( SELECT MAX( created_time ) FROM sc_node_avail_info WHERE deleted_flag = 0 GROUP BY participant_id, node_name ) ").Scan(&nodeResp.NodeAssets)
|
||||
if tx.Error != nil {
|
||||
logx.Error(err)
|
||||
return nil, tx.Error
|
||||
}
|
||||
|
||||
//queueResp := types.QueueAssetsResp{}
|
||||
//tool.Convert(queuePhyInfos, &queueResp.QueueAssets)
|
||||
//return &queueResp, nil
|
||||
return
|
||||
return &nodeResp, nil
|
||||
}
|
||||
|
|
|
@ -2,9 +2,6 @@ package hpc
|
|||
|
||||
import (
|
||||
"context"
|
||||
"gitlink.org.cn/jcce-pcm/pcm-coordinator/model"
|
||||
"gitlink.org.cn/jcce-pcm/utils/tool"
|
||||
|
||||
"gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/svc"
|
||||
"gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/types"
|
||||
|
||||
|
@ -27,14 +24,11 @@ func NewQueueAssetsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Queue
|
|||
|
||||
func (l *QueueAssetsLogic) QueueAssets() (resp *types.QueueAssetsResp, err error) {
|
||||
// 查询数据库队列资源信息
|
||||
var queuePhyInfos []model.ScQueuePhyInfo
|
||||
tx := l.svcCtx.DbEngin.Find(&queuePhyInfos)
|
||||
var queueAssetsResp types.QueueAssetsResp
|
||||
tx := l.svcCtx.DbEngin.Raw("SELECT qpi.*,ti.tenant_name FROM sc_queue_phy_info qpi left join sc_participant_phy_info ppi on ppi.id = qpi.participant_id left JOIN sc_tenant_info ti on ti.id = ppi.tenant_id WHERE qpi.created_time IN ( SELECT MAX( created_time ) FROM sc_queue_phy_info WHERE deleted_flag = 0 GROUP BY participant_id, queue_name ) ").Scan(&queueAssetsResp.QueueAssets)
|
||||
if tx.Error != nil {
|
||||
logx.Error(err)
|
||||
return nil, tx.Error
|
||||
}
|
||||
|
||||
queueResp := types.QueueAssetsResp{}
|
||||
tool.Convert(queuePhyInfos, &queueResp.QueueAssets)
|
||||
return &queueResp, nil
|
||||
return &queueAssetsResp, nil
|
||||
}
|
||||
|
|
|
@ -400,16 +400,17 @@ type NodeAssetsResp struct {
|
|||
}
|
||||
|
||||
type NodeAsset struct {
|
||||
NodeName string `db:"node_name"` // 节点名称
|
||||
CpuTotal int64 `db:"cpu_total"` // cpu核数
|
||||
CpuUsable float64 `db:"cpu_usable"` // cpu可用率
|
||||
DiskTotal int64 `db:"disk_total"` // 磁盘空间
|
||||
DiskAvail int64 `db:"disk_avail"` // 磁盘可用空间
|
||||
MemTotal int64 `db:"mem_total"` // 内存总数
|
||||
MemAvail int64 `db:"mem_avail"` // 内存可用数
|
||||
GpuTotal int64 `db:"gpu_total"` // gpu总数
|
||||
GpuAvail int64 `db:"gpu_avail"` // gpu可用数
|
||||
ParticipantId int64 `db:"participant_id"` // 集群动态信息id
|
||||
TenantName string `json:"tenantName"` //租户名称
|
||||
NodeName string `json:"NodeName"` // 节点名称
|
||||
CpuTotal int64 `json:"CpuTotal"` // cpu核数
|
||||
CpuUsable float64 `json:"CpuUsable"` // cpu可用率
|
||||
DiskTotal int64 `json:"DiskTotal"` // 磁盘空间
|
||||
DiskAvail int64 `json:"DiskAvail"` // 磁盘可用空间
|
||||
MemTotal int64 `json:"MemTotal"` // 内存总数
|
||||
MemAvail int64 `json:"MemAvail"` // 内存可用数
|
||||
GpuTotal int64 `json:"GpuTotal"` // gpu总数
|
||||
GpuAvail int64 `json:"GpuAvail"` // gpu可用数
|
||||
ParticipantId int64 `json:"ParticipantId"` // 集群动态信息id
|
||||
}
|
||||
|
||||
type Job struct {
|
||||
|
@ -453,8 +454,9 @@ type QueueAssetsResp struct {
|
|||
}
|
||||
|
||||
type QueueAsset struct {
|
||||
TenantName string `json:"tenantName"` //租户名称
|
||||
ParticipantId int64 `json:"participantId"`
|
||||
AclHosts string `json:"aclHosts"`
|
||||
AclHosts string `json:"aclHosts"` // 可用节点,多个节点用逗号隔开
|
||||
QueNodes string `json:"queNodes"` //队列节点总数
|
||||
QueMinNodect string `json:"queMinNodect,omitempty"` //队列最小节点数
|
||||
QueMaxNgpus string `json:"queMaxNgpus,omitempty"` //队列最大GPU卡数
|
||||
|
|
|
@ -1,27 +0,0 @@
|
|||
package model
|
||||
|
||||
import (
|
||||
"github.com/zeromicro/go-zero/core/stores/cache"
|
||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||
)
|
||||
|
||||
var _ ScNodeAvailInfoModel = (*customScNodeAvailInfoModel)(nil)
|
||||
|
||||
type (
|
||||
// ScNodeAvailInfoModel is an interface to be customized, add more methods here,
|
||||
// and implement the added methods in customScNodeAvailInfoModel.
|
||||
ScNodeAvailInfoModel interface {
|
||||
scNodeAvailInfoModel
|
||||
}
|
||||
|
||||
customScNodeAvailInfoModel struct {
|
||||
*defaultScNodeAvailInfoModel
|
||||
}
|
||||
)
|
||||
|
||||
// NewScNodeAvailInfoModel returns a model for the database table.
|
||||
func NewScNodeAvailInfoModel(conn sqlx.SqlConn, c cache.CacheConf, opts ...cache.Option) ScNodeAvailInfoModel {
|
||||
return &customScNodeAvailInfoModel{
|
||||
defaultScNodeAvailInfoModel: newScNodeAvailInfoModel(conn, c, opts...),
|
||||
}
|
||||
}
|
|
@ -3,41 +3,11 @@
|
|||
package model
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/stores/builder"
|
||||
"github.com/zeromicro/go-zero/core/stores/cache"
|
||||
"github.com/zeromicro/go-zero/core/stores/sqlc"
|
||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||
"github.com/zeromicro/go-zero/core/stringx"
|
||||
)
|
||||
|
||||
var (
|
||||
scNodeAvailInfoFieldNames = builder.RawFieldNames(&ScNodeAvailInfo{})
|
||||
scNodeAvailInfoRows = strings.Join(scNodeAvailInfoFieldNames, ",")
|
||||
scNodeAvailInfoRowsExpectAutoSet = strings.Join(stringx.Remove(scNodeAvailInfoFieldNames, "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), ",")
|
||||
scNodeAvailInfoRowsWithPlaceHolder = strings.Join(stringx.Remove(scNodeAvailInfoFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), "=?,") + "=?"
|
||||
|
||||
cachePcmScNodeAvailInfoIdPrefix = "cache:pcm:scNodeAvailInfo:id:"
|
||||
)
|
||||
|
||||
type (
|
||||
scNodeAvailInfoModel interface {
|
||||
Insert(ctx context.Context, data *ScNodeAvailInfo) (sql.Result, error)
|
||||
FindOne(ctx context.Context, id int64) (*ScNodeAvailInfo, error)
|
||||
Update(ctx context.Context, data *ScNodeAvailInfo) error
|
||||
Delete(ctx context.Context, id int64) error
|
||||
}
|
||||
|
||||
defaultScNodeAvailInfoModel struct {
|
||||
sqlc.CachedConn
|
||||
table string
|
||||
}
|
||||
|
||||
ScNodeAvailInfo struct {
|
||||
Id int64 `db:"id"` // id
|
||||
NodeName string `db:"node_name"` // 节点名称
|
||||
|
@ -57,74 +27,3 @@ type (
|
|||
UpdatedTime sql.NullTime `db:"updated_time"` // 更新时间
|
||||
}
|
||||
)
|
||||
|
||||
func newScNodeAvailInfoModel(conn sqlx.SqlConn, c cache.CacheConf, opts ...cache.Option) *defaultScNodeAvailInfoModel {
|
||||
return &defaultScNodeAvailInfoModel{
|
||||
CachedConn: sqlc.NewConn(conn, c, opts...),
|
||||
table: "`sc_node_avail_info`",
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultScNodeAvailInfoModel) withSession(session sqlx.Session) *defaultScNodeAvailInfoModel {
|
||||
return &defaultScNodeAvailInfoModel{
|
||||
CachedConn: m.CachedConn.WithSession(session),
|
||||
table: "`sc_node_avail_info`",
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultScNodeAvailInfoModel) Delete(ctx context.Context, id int64) error {
|
||||
pcmScNodeAvailInfoIdKey := fmt.Sprintf("%s%v", cachePcmScNodeAvailInfoIdPrefix, id)
|
||||
_, err := m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
|
||||
query := fmt.Sprintf("delete from %s where `id` = ?", m.table)
|
||||
return conn.ExecCtx(ctx, query, id)
|
||||
}, pcmScNodeAvailInfoIdKey)
|
||||
return err
|
||||
}
|
||||
|
||||
func (m *defaultScNodeAvailInfoModel) FindOne(ctx context.Context, id int64) (*ScNodeAvailInfo, error) {
|
||||
pcmScNodeAvailInfoIdKey := fmt.Sprintf("%s%v", cachePcmScNodeAvailInfoIdPrefix, id)
|
||||
var resp ScNodeAvailInfo
|
||||
err := m.QueryRowCtx(ctx, &resp, pcmScNodeAvailInfoIdKey, func(ctx context.Context, conn sqlx.SqlConn, v any) error {
|
||||
query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", scNodeAvailInfoRows, m.table)
|
||||
return conn.QueryRowCtx(ctx, v, query, id)
|
||||
})
|
||||
switch err {
|
||||
case nil:
|
||||
return &resp, nil
|
||||
case sqlc.ErrNotFound:
|
||||
return nil, ErrNotFound
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultScNodeAvailInfoModel) Insert(ctx context.Context, data *ScNodeAvailInfo) (sql.Result, error) {
|
||||
pcmScNodeAvailInfoIdKey := fmt.Sprintf("%s%v", cachePcmScNodeAvailInfoIdPrefix, data.Id)
|
||||
ret, err := m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
|
||||
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", m.table, scNodeAvailInfoRowsExpectAutoSet)
|
||||
return conn.ExecCtx(ctx, query, data.Id, data.NodeName, data.CpuTotal, data.CpuUsable, data.DiskTotal, data.DiskAvail, data.MemTotal, data.MemAvail, data.GpuTotal, data.GpuAvail, data.ParticipantId, data.DeletedFlag, data.CreatedBy, data.CreatedTime, data.UpdatedBy, data.UpdatedTime)
|
||||
}, pcmScNodeAvailInfoIdKey)
|
||||
return ret, err
|
||||
}
|
||||
|
||||
func (m *defaultScNodeAvailInfoModel) Update(ctx context.Context, data *ScNodeAvailInfo) error {
|
||||
pcmScNodeAvailInfoIdKey := fmt.Sprintf("%s%v", cachePcmScNodeAvailInfoIdPrefix, data.Id)
|
||||
_, err := m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
|
||||
query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, scNodeAvailInfoRowsWithPlaceHolder)
|
||||
return conn.ExecCtx(ctx, query, data.NodeName, data.CpuTotal, data.CpuUsable, data.DiskTotal, data.DiskAvail, data.MemTotal, data.MemAvail, data.GpuTotal, data.GpuAvail, data.ParticipantId, data.DeletedFlag, data.CreatedBy, data.CreatedTime, data.UpdatedBy, data.UpdatedTime, data.Id)
|
||||
}, pcmScNodeAvailInfoIdKey)
|
||||
return err
|
||||
}
|
||||
|
||||
func (m *defaultScNodeAvailInfoModel) formatPrimary(primary any) string {
|
||||
return fmt.Sprintf("%s%v", cachePcmScNodeAvailInfoIdPrefix, primary)
|
||||
}
|
||||
|
||||
func (m *defaultScNodeAvailInfoModel) queryPrimary(ctx context.Context, conn sqlx.SqlConn, v, primary any) error {
|
||||
query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", scNodeAvailInfoRows, m.table)
|
||||
return conn.QueryRowCtx(ctx, v, query, primary)
|
||||
}
|
||||
|
||||
func (m *defaultScNodeAvailInfoModel) tableName() string {
|
||||
return m.table
|
||||
}
|
||||
|
|
|
@ -75,7 +75,7 @@ func (l *ReportAvailableLogic) ReportAvailable(in *pcmCore.ParticipantAvailReq)
|
|||
nodeInfo := &model.ScNodeAvailInfo{}
|
||||
tool.Convert(info, nodeInfo)
|
||||
nodeInfo.CreatedTime = time.Now()
|
||||
nodeInfo.ParticipantId = participantAvailInfo.Id
|
||||
nodeInfo.ParticipantId = participantAvailInfo.ParticipantId
|
||||
if nodeInfo.Id == 0 {
|
||||
nodeInfo.Id = tool.GenSnowflakeID()
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue