cpu可用率修改
Former-commit-id: 047ee6a804d13ab22b2b27202239582f1dd92160
This commit is contained in:
parent
f6a956b9e1
commit
d46dcbaf2a
|
@ -1,12 +1,5 @@
|
|||
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.
|
||||
|
@ -18,10 +11,3 @@ type (
|
|||
*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...),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,7 +5,6 @@ package model
|
|||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
|
@ -42,7 +41,7 @@ type (
|
|||
Id int64 `db:"id"` // id
|
||||
NodeName string `db:"node_name"` // 节点名称
|
||||
CpuTotal int64 `db:"cpu_total"` // cpu核数
|
||||
CpuAvail int64 `db:"cpu_avail"` // cpu可用核数
|
||||
CpuUsable float64 `db:"cpu_usable"` // cpu可用率
|
||||
DiskTotal int64 `db:"disk_total"` // 磁盘空间
|
||||
DiskAvail int64 `db:"disk_avail"` // 磁盘可用空间
|
||||
MemTotal int64 `db:"mem_total"` // 内存总数
|
||||
|
@ -71,60 +70,6 @@ func (m *defaultScNodeAvailInfoModel) withSession(session sqlx.Session) *default
|
|||
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.CpuAvail, data.DiskTotal, data.DiskAvail, data.MemTotal, data.MemAvail, data.GpuTotal, data.GpuAvail, data.ClusterLogicId, 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.CpuAvail, data.DiskTotal, data.DiskAvail, data.MemTotal, data.MemAvail, data.GpuTotal, data.GpuAvail, data.ClusterLogicId, 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
|
||||
}
|
||||
|
|
|
@ -46,7 +46,7 @@ type (
|
|||
ArchType string `db:"arch_type"` // 架构类型
|
||||
ArchName string `db:"arch_name"` // 架构名称
|
||||
ArchFreq string `db:"arch_freq"` // 架构频率
|
||||
ParticipantId int64 `db:"cluster_id"` // 集群静态信息id
|
||||
ParticipantId int64 `db:"participant_id"` // 集群静态信息id
|
||||
DeletedFlag int64 `db:"deleted_flag"` // 是否删除
|
||||
CreatedBy int64 `db:"created_by"` // 创建人
|
||||
CreatedTime time.Time `db:"created_time"` // 创建时间
|
||||
|
|
|
@ -39,13 +39,13 @@ type (
|
|||
|
||||
ScParticipantAvailInfo struct {
|
||||
Id int64 `db:"id"` // id
|
||||
Host sql.NullString `db:"host"` // 集群p端host
|
||||
Port sql.NullString `db:"port"` // 集群p端端口
|
||||
AvailStorageSpace sql.NullInt64 `db:"avail_storage_space"` // 集群存储可用空间
|
||||
UserNum sql.NullInt64 `db:"user_num"` // 用户数量
|
||||
PendingJobNum sql.NullInt64 `db:"pending_job_num"` // 待处理作业数量
|
||||
Host string `db:"host"` // 集群p端host
|
||||
Port string `db:"port"` // 集群p端端口
|
||||
AvailStorageSpace int64 `db:"avail_storage_space"` // 集群存储可用空间
|
||||
UserNum int64 `db:"user_num"` // 用户数量
|
||||
PendingJobNum int64 `db:"pending_job_num"` // 待处理作业数量
|
||||
RunningJobNum int64 `db:"running_job_num"` // 运行作业数量
|
||||
ParticipantId int64 `db:"cluster_logic_id"` // 集群静态信息id
|
||||
ParticipantId int64 `db:"participant_id"` // 集群静态信息id
|
||||
DeletedFlag int64 `db:"deleted_flag"` // 是否删除
|
||||
CreatedBy sql.NullInt64 `db:"created_by"` // 创建人
|
||||
CreatedTime time.Time `db:"created_time"` // 创建时间
|
||||
|
|
Loading…
Reference in New Issue