删除无用字段

Former-commit-id: 92e6cce35c0193a5d8a6d161ee8391156135667c
This commit is contained in:
zhangwei 2023-12-12 16:20:48 +08:00
parent 767c692a36
commit 4a1428fa65
3 changed files with 22 additions and 143 deletions

View File

@ -1,41 +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 models
import (
"github.com/zeromicro/go-zero/core/stores/cache"
"github.com/zeromicro/go-zero/core/stores/sqlx"
)
var _ ScQueuePhyInfoModel = (*customScQueuePhyInfoModel)(nil)
type (
// ScQueuePhyInfoModel is an interface to be customized, add more methods here,
// and implement the added methods in customScQueuePhyInfoModel.
ScQueuePhyInfoModel interface {
scQueuePhyInfoModel
}
customScQueuePhyInfoModel struct {
*defaultScQueuePhyInfoModel
}
)
// NewScQueuePhyInfoModel returns a models for the database table.
func NewScQueuePhyInfoModel(conn sqlx.SqlConn, c cache.CacheConf, opts ...cache.Option) ScQueuePhyInfoModel {
return &customScQueuePhyInfoModel{
defaultScQueuePhyInfoModel: newScQueuePhyInfoModel(conn, c, opts...),
}
}

View File

@ -5,14 +5,10 @@ package models
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"
)
@ -39,102 +35,27 @@ type (
}
ScQueuePhyInfo struct {
Id int64 `db:"id"` // id
AclHosts string `db:"aclHosts"` // 可用节点,多个节点用逗号隔开
QueueId string `db:"queue_id"` // 队列名称
Text string `db:"text"` // 队列名称
QueueName string `db:"queue_name"` // 队列名称
QueNodes string `db:"que_nodes"` // 队列节点总数
QueMinNodect string `db:"que_min_nodect"` // 队列最小节点数
QueMaxNgpus string `db:"que_max_ngpus"` // 队列最大GPU卡数
QueMaxPpn string `db:"que_max_ppn"` // 使用该队列作业最大CPU核心数
QueChargeRate string `db:"que_charge_rate"` // 费率
QueMaxNcpus string `db:"que_max_ncpus"` // 用户最大可用核心数
QueMaxNdcus string `db:"que_max_ndcus"` // 队列总DCU卡数
QueMinNcpus string `db:"que_min_ncpus"` // 队列最小CPU核数
QueFreeNodes string `db:"que_free_nodes"` // 队列空闲节点数
QueMaxNodect string `db:"que_max_nodect"` // 队列作业最大节点数
QueMaxGpuPN string `db:"que_max_gpu_PN"` // 队列单作业最大GPU卡数
QueMaxWalltime string `db:"que_max_walltime"` // 队列最大运行时间
QueMaxDcuPN string `db:"que_max_dcu_PN"` // 队列单作业最大DCU卡数
ParticipantId int64 `db:"participant_id"` // 集群动态信息id
DeletedFlag int64 `db:"deleted_flag"` // 是否删除
QueNcpus string `db:"que_ncpus"`
QueFreeNcpus string `db:"que_free_ncpus"`
CreatedBy sql.NullInt64 `db:"created_by"` // 创建人
CreatedTime time.Time `db:"created_time"` // 创建时间
UpdatedBy sql.NullInt64 `db:"updated_by"` // 更新人
UpdatedTime sql.NullTime `db:"updated_time"` // 更新时间
Id int64 `db:"id"` // id
AclHosts string `db:"aclHosts"` // 可用节点,多个节点用逗号隔开
QueueId string `db:"queue_id"` // 队列名称
Text string `db:"text"` // 队列名称
QueueName string `db:"queue_name"` // 队列名称
QueNodes string `db:"que_nodes"` // 队列节点总数
QueMinNodect string `db:"que_min_nodect"` // 队列最小节点数
QueMaxNgpus string `db:"que_max_ngpus"` // 队列最大GPU卡数
QueMaxPpn string `db:"que_max_ppn"` // 使用该队列作业最大CPU核心数
QueChargeRate string `db:"que_charge_rate"` // 费率
QueMaxNcpus string `db:"que_max_ncpus"` // 用户最大可用核心数
QueMaxNdcus string `db:"que_max_ndcus"` // 队列总DCU卡数
QueMinNcpus string `db:"que_min_ncpus"` // 队列最小CPU核数
QueFreeNodes string `db:"que_free_nodes"` // 队列空闲节点数
QueMaxNodect string `db:"que_max_nodect"` // 队列作业最大节点数
QueMaxGpuPN string `db:"que_max_gpu_PN"` // 队列单作业最大GPU卡数
QueMaxWalltime string `db:"que_max_walltime"` // 队列最大运行时间
QueMaxDcuPN string `db:"que_max_dcu_PN"` // 队列单作业最大DCU卡数
ParticipantId int64 `db:"participant_id"` // 集群动态信息id
DeletedFlag int64 `db:"deleted_flag"` // 是否删除
QueNcpus string `db:"que_ncpus"`
QueFreeNcpus string `db:"que_free_ncpus"`
}
)
func newScQueuePhyInfoModel(conn sqlx.SqlConn, c cache.CacheConf, opts ...cache.Option) *defaultScQueuePhyInfoModel {
return &defaultScQueuePhyInfoModel{
CachedConn: sqlc.NewConn(conn, c, opts...),
table: "`sc_queue_phy_info`",
}
}
func (m *defaultScQueuePhyInfoModel) withSession(session sqlx.Session) *defaultScQueuePhyInfoModel {
return &defaultScQueuePhyInfoModel{
CachedConn: m.CachedConn.WithSession(session),
table: "`sc_queue_phy_info`",
}
}
func (m *defaultScQueuePhyInfoModel) Delete(ctx context.Context, id int64) error {
pcmScQueuePhyInfoIdKey := fmt.Sprintf("%s%v", cachePcmScQueuePhyInfoIdPrefix, 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)
}, pcmScQueuePhyInfoIdKey)
return err
}
func (m *defaultScQueuePhyInfoModel) FindOne(ctx context.Context, id int64) (*ScQueuePhyInfo, error) {
pcmScQueuePhyInfoIdKey := fmt.Sprintf("%s%v", cachePcmScQueuePhyInfoIdPrefix, id)
var resp ScQueuePhyInfo
err := m.QueryRowCtx(ctx, &resp, pcmScQueuePhyInfoIdKey, func(ctx context.Context, conn sqlx.SqlConn, v any) error {
query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", scQueuePhyInfoRows, 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 *defaultScQueuePhyInfoModel) Insert(ctx context.Context, data *ScQueuePhyInfo) (sql.Result, error) {
pcmScQueuePhyInfoIdKey := fmt.Sprintf("%s%v", cachePcmScQueuePhyInfoIdPrefix, 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, scQueuePhyInfoRowsExpectAutoSet)
return conn.ExecCtx(ctx, query, data.Id, data.AclHosts, data.QueueId, data.Text, data.QueueName, data.QueNodes, data.QueMinNodect, data.QueMaxNgpus, data.QueMaxPpn, data.QueChargeRate, data.QueMaxNcpus, data.QueMaxNdcus, data.QueMinNcpus, data.QueFreeNodes, data.QueMaxNodect, data.QueMaxGpuPN, data.QueMaxWalltime, data.QueMaxDcuPN, data.ParticipantId, data.DeletedFlag, data.CreatedBy, data.CreatedTime, data.UpdatedBy, data.UpdatedTime)
}, pcmScQueuePhyInfoIdKey)
return ret, err
}
func (m *defaultScQueuePhyInfoModel) Update(ctx context.Context, data *ScQueuePhyInfo) error {
pcmScQueuePhyInfoIdKey := fmt.Sprintf("%s%v", cachePcmScQueuePhyInfoIdPrefix, 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, scQueuePhyInfoRowsWithPlaceHolder)
return conn.ExecCtx(ctx, query, data.AclHosts, data.QueueId, data.Text, data.QueueName, data.QueNodes, data.QueMinNodect, data.QueMaxNgpus, data.QueMaxPpn, data.QueChargeRate, data.QueMaxNcpus, data.QueMaxNdcus, data.QueMinNcpus, data.QueFreeNodes, data.QueMaxNodect, data.QueMaxGpuPN, data.QueMaxWalltime, data.QueMaxDcuPN, data.ParticipantId, data.DeletedFlag, data.CreatedBy, data.CreatedTime, data.UpdatedBy, data.UpdatedTime, data.Id)
}, pcmScQueuePhyInfoIdKey)
return err
}
func (m *defaultScQueuePhyInfoModel) formatPrimary(primary any) string {
return fmt.Sprintf("%s%v", cachePcmScQueuePhyInfoIdPrefix, primary)
}
func (m *defaultScQueuePhyInfoModel) queryPrimary(ctx context.Context, conn sqlx.SqlConn, v, primary any) error {
query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", scQueuePhyInfoRows, m.table)
return conn.QueryRowCtx(ctx, v, query, primary)
}
func (m *defaultScQueuePhyInfoModel) tableName() string {
return m.table
}

View File

@ -88,7 +88,6 @@ func (l *RegisterParticipantLogic) RegisterParticipant(in *pcmCore.ParticipantPh
for _, info := range in.QueueInfo {
queueInfo := &models2.ScQueuePhyInfo{}
utils.Convert(info, queueInfo)
queueInfo.CreatedTime = time.Now()
queueInfo.ParticipantId = participantInfo.Id
//查询队列name与ParticipantId是否存在
queueErr := db.Where(&models2.ScQueuePhyInfo{QueueName: queueInfo.QueueName, ParticipantId: in.ParticipantId}).Take(queueInfo)