From 7b7f2bcbfafb6b593e97c099e285d330661598f0 Mon Sep 17 00:00:00 2001 From: jagger Date: Fri, 17 Jan 2025 16:18:35 +0800 Subject: [PATCH] add hpc application center Signed-off-by: jagger --- desc/hpc/pcm-hpc.api | 27 +++++- desc/pcm.api | 4 + .../handler/hpc/listinstancecenterhandler.go | 24 +++++ internal/handler/routes.go | 5 + internal/logic/hpc/listinstancecenterlogic.go | 60 ++++++++++++ internal/types/types.go | 22 +++++ pkg/models/hpcinstancecentermodel.go | 29 ++++++ pkg/models/hpcinstancecentermodel_gen.go | 93 +++++++++++++++++++ 8 files changed, 263 insertions(+), 1 deletion(-) create mode 100644 internal/handler/hpc/listinstancecenterhandler.go create mode 100644 internal/logic/hpc/listinstancecenterlogic.go create mode 100755 pkg/models/hpcinstancecentermodel.go create mode 100755 pkg/models/hpcinstancecentermodel_gen.go diff --git a/desc/hpc/pcm-hpc.api b/desc/hpc/pcm-hpc.api index 3dcd70f79..d173232d7 100644 --- a/desc/hpc/pcm-hpc.api +++ b/desc/hpc/pcm-hpc.api @@ -151,4 +151,29 @@ type QueueAsset { QueMaxDcuPN string `json:"queMaxDcuPN,omitempty"` //队列单作业最大DCU卡数 QueFreeNcpus string `json:"queFreeNcpus"` //队列空闲cpu数 QueNcpus string `json:"queNcpus"` //队列cpu数 -} \ No newline at end of file +} + +type ( +/******************instance center*************************/ + HpcInstanceCenterReq{ + InstanceType int32 `form:"instanceType,optional"` + InstanceClass string `form:"instanceClass,optional"` + InstanceName string `form:"instanceName,optional"` + PageInfo + } + HpcInstanceCenterResp { + InstanceCenterList []HpcInstanceCenterList `json:"instanceCenterList" copier:"InstanceCenterList"` + TotalCount int `json:"totalCount"` + } + HpcInstanceCenterList { + LogoPath string `json:"logo_path"` + InstanceName string `json:"instance_name"` + InstanceType int32 `json:"instance_type"` + InstanceClass string `json:"instance_class"` + InstanceClassChinese string `json:"instance_class_chinese"` + Description string `json:"description"` + Version string `json:"version"` + } + +/******************instance center*************************/ +) \ No newline at end of file diff --git a/desc/pcm.api b/desc/pcm.api index cb824aa41..54f02fccf 100644 --- a/desc/pcm.api +++ b/desc/pcm.api @@ -213,6 +213,10 @@ service pcm { @doc "查看job状态" @handler jobInfoHandler get /hpc/jobInfo (jobInfoReq) returns (jobInfoResp) + + @doc "查询超算应用中心列表" + @handler ListInstanceCenter + get /hpc/ListInstanceCenter(HpcInstanceCenterReq) returns (PageResult) } //cloud二级接口 diff --git a/internal/handler/hpc/listinstancecenterhandler.go b/internal/handler/hpc/listinstancecenterhandler.go new file mode 100644 index 000000000..4bab6fbc9 --- /dev/null +++ b/internal/handler/hpc/listinstancecenterhandler.go @@ -0,0 +1,24 @@ +package hpc + +import ( + "github.com/zeromicro/go-zero/rest/httpx" + "gitlink.org.cn/JointCloud/pcm-coordinator/internal/logic/hpc" + "gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc" + "gitlink.org.cn/JointCloud/pcm-coordinator/internal/types" + "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/repository/result" + "net/http" +) + +func ListInstanceCenterHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + var req types.HpcInstanceCenterReq + if err := httpx.Parse(r, &req); err != nil { + result.ParamErrorResult(r, w, err) + return + } + + l := hpc.NewListInstanceCenterLogic(r.Context(), svcCtx) + resp, err := l.ListInstanceCenter(&req) + result.HttpResult(r, w, resp, err) + } +} diff --git a/internal/handler/routes.go b/internal/handler/routes.go index 34afb03ac..729f1f773 100644 --- a/internal/handler/routes.go +++ b/internal/handler/routes.go @@ -255,6 +255,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { Path: "/hpc/jobInfo", Handler: hpc.JobInfoHandler(serverCtx), }, + { + Method: http.MethodGet, + Path: "/hpc/ListInstanceCenter", + Handler: hpc.ListInstanceCenterHandler(serverCtx), + }, }, rest.WithPrefix("/pcm/v1"), ) diff --git a/internal/logic/hpc/listinstancecenterlogic.go b/internal/logic/hpc/listinstancecenterlogic.go new file mode 100644 index 000000000..cab9aa6a4 --- /dev/null +++ b/internal/logic/hpc/listinstancecenterlogic.go @@ -0,0 +1,60 @@ +package hpc + +import ( + "context" + "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/models" + + "github.com/zeromicro/go-zero/core/logx" + "gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc" + "gitlink.org.cn/JointCloud/pcm-coordinator/internal/types" +) + +type ListInstanceCenterLogic struct { + logx.Logger + ctx context.Context + svcCtx *svc.ServiceContext +} + +func NewListInstanceCenterLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ListInstanceCenterLogic { + return &ListInstanceCenterLogic{ + Logger: logx.WithContext(ctx), + ctx: ctx, + svcCtx: svcCtx, + } +} + +func (l *ListInstanceCenterLogic) ListInstanceCenter(req *types.HpcInstanceCenterReq) (resp *types.PageResult, err error) { + limit := req.PageSize + offset := req.PageSize * (req.PageNum - 1) + resp = &types.PageResult{} + var list *[]models.HpcInstanceCenter + db := l.svcCtx.DbEngin.Model(&models.HpcInstanceCenter{}).Table("hpc_instance_center") + + if req.InstanceName != "" { + db = db.Where("instance_name like ?", "%"+req.InstanceName+"%") + } + + if req.InstanceType != 0 { + db = db.Where("instance_type = ?", req.InstanceType) + } + + if req.InstanceClass != "" { + db = db.Where("instance_class = ?", req.InstanceClass) + } + var total int64 + err = db.Count(&total).Error + + if err != nil { + return resp, err + } + db = db.Where("deleted_at is null").Limit(limit).Offset(offset) + err = db.Order("created_at desc").Find(&list).Error + if err != nil { + return nil, err + } + resp.List = list + resp.PageSize = req.PageSize + resp.PageNum = req.PageNum + resp.Total = total + return +} diff --git a/internal/types/types.go b/internal/types/types.go index e612976e2..d552145a5 100644 --- a/internal/types/types.go +++ b/internal/types/types.go @@ -1423,6 +1423,28 @@ type QueueAsset struct { QueNcpus string `json:"queNcpus"` //队列cpu数 } +type HpcInstanceCenterReq struct { + InstanceType int32 `form:"instanceType,optional"` + InstanceClass string `form:"instanceClass,optional"` + InstanceName string `form:"instanceName,optional"` + PageInfo +} + +type HpcInstanceCenterResp struct { + InstanceCenterList []HpcInstanceCenterList `json:"instanceCenterList" copier:"InstanceCenterList"` + TotalCount int `json:"totalCount"` +} + +type HpcInstanceCenterList struct { + LogoPath string `json:"logo_path"` + InstanceName string `json:"instance_name"` + InstanceType int32 `json:"instance_type"` + InstanceClass string `json:"instance_class"` + InstanceClassChinese string `json:"instance_class_chinese"` + Description string `json:"description"` + Version string `json:"version"` +} + type DataSets struct { DatasetId string `json:"datasetId" copier:"DatasetId"` DataFormat string `json:"dataFormat" copier:"DataFormat"` diff --git a/pkg/models/hpcinstancecentermodel.go b/pkg/models/hpcinstancecentermodel.go new file mode 100755 index 000000000..c86b0fa86 --- /dev/null +++ b/pkg/models/hpcinstancecentermodel.go @@ -0,0 +1,29 @@ +package models + +import "github.com/zeromicro/go-zero/core/stores/sqlx" + +var _ HpcInstanceCenterModel = (*customHpcInstanceCenterModel)(nil) + +type ( + // HpcInstanceCenterModel is an interface to be customized, add more methods here, + // and implement the added methods in customHpcInstanceCenterModel. + HpcInstanceCenterModel interface { + hpcInstanceCenterModel + withSession(session sqlx.Session) HpcInstanceCenterModel + } + + customHpcInstanceCenterModel struct { + *defaultHpcInstanceCenterModel + } +) + +// NewHpcInstanceCenterModel returns a model for the database table. +func NewHpcInstanceCenterModel(conn sqlx.SqlConn) HpcInstanceCenterModel { + return &customHpcInstanceCenterModel{ + defaultHpcInstanceCenterModel: newHpcInstanceCenterModel(conn), + } +} + +func (m *customHpcInstanceCenterModel) withSession(session sqlx.Session) HpcInstanceCenterModel { + return NewHpcInstanceCenterModel(sqlx.NewSqlConnFromSession(session)) +} diff --git a/pkg/models/hpcinstancecentermodel_gen.go b/pkg/models/hpcinstancecentermodel_gen.go new file mode 100755 index 000000000..5a752084f --- /dev/null +++ b/pkg/models/hpcinstancecentermodel_gen.go @@ -0,0 +1,93 @@ +// Code generated by goctl. DO NOT EDIT. + +package models + +import ( + "context" + "database/sql" + "fmt" + "strings" + "time" + + "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 ( + hpcInstanceCenterFieldNames = builder.RawFieldNames(&HpcInstanceCenter{}) + hpcInstanceCenterRows = strings.Join(hpcInstanceCenterFieldNames, ",") + hpcInstanceCenterRowsExpectAutoSet = strings.Join(stringx.Remove(hpcInstanceCenterFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), ",") + hpcInstanceCenterRowsWithPlaceHolder = strings.Join(stringx.Remove(hpcInstanceCenterFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), "=?,") + "=?" +) + +type ( + hpcInstanceCenterModel interface { + Insert(ctx context.Context, data *HpcInstanceCenter) (sql.Result, error) + FindOne(ctx context.Context, id int64) (*HpcInstanceCenter, error) + Update(ctx context.Context, data *HpcInstanceCenter) error + Delete(ctx context.Context, id int64) error + } + + defaultHpcInstanceCenterModel struct { + conn sqlx.SqlConn + table string + } + + HpcInstanceCenter struct { + Id int64 `db:"id"` // 平台唯一id + LogoPath string `db:"logo_path"` // logo图像的位置 + InstanceName string `db:"instance_name"` // 实例名称 + InstanceType int64 `db:"instance_type"` // 实例类型(1是应用实例,2是模型实例) + InstanceClass string `db:"instance_class"` // 实例类别 + InstanceClassChinese string `db:"instance_class_chinese"` // 实例类别中文描述 + Description string `db:"description"` // 描述 + Version string `db:"version"` // 版本 + CreatedAt time.Time `db:"created_at"` // 创建时间 + UpdatedAt time.Time `db:"updated_at"` // 更新时间 + } +) + +func newHpcInstanceCenterModel(conn sqlx.SqlConn) *defaultHpcInstanceCenterModel { + return &defaultHpcInstanceCenterModel{ + conn: conn, + table: "`hpc_instance_center`", + } +} + +func (m *defaultHpcInstanceCenterModel) Delete(ctx context.Context, id int64) error { + query := fmt.Sprintf("delete from %s where `id` = ?", m.table) + _, err := m.conn.ExecCtx(ctx, query, id) + return err +} + +func (m *defaultHpcInstanceCenterModel) FindOne(ctx context.Context, id int64) (*HpcInstanceCenter, error) { + query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", hpcInstanceCenterRows, m.table) + var resp HpcInstanceCenter + err := m.conn.QueryRowCtx(ctx, &resp, query, id) + switch err { + case nil: + return &resp, nil + case sqlc.ErrNotFound: + return nil, ErrNotFound + default: + return nil, err + } +} + +func (m *defaultHpcInstanceCenterModel) Insert(ctx context.Context, data *HpcInstanceCenter) (sql.Result, error) { + query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?, ?, ?)", m.table, hpcInstanceCenterRowsExpectAutoSet) + ret, err := m.conn.ExecCtx(ctx, query, data.LogoPath, data.InstanceName, data.InstanceType, data.InstanceClass, data.InstanceClassChinese, data.Description, data.Version) + return ret, err +} + +func (m *defaultHpcInstanceCenterModel) Update(ctx context.Context, data *HpcInstanceCenter) error { + query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, hpcInstanceCenterRowsWithPlaceHolder) + _, err := m.conn.ExecCtx(ctx, query, data.LogoPath, data.InstanceName, data.InstanceType, data.InstanceClass, data.InstanceClassChinese, data.Description, data.Version, data.Id) + return err +} + +func (m *defaultHpcInstanceCenterModel) tableName() string { + return m.table +}