forked from JointCloud/pcm-coordinator
add hpc application center
Signed-off-by: jagger <cossjie@foxmail.com>
This commit is contained in:
parent
9bc0bce2eb
commit
7b7f2bcbfa
|
@ -151,4 +151,29 @@ type QueueAsset {
|
|||
QueMaxDcuPN string `json:"queMaxDcuPN,omitempty"` //队列单作业最大DCU卡数
|
||||
QueFreeNcpus string `json:"queFreeNcpus"` //队列空闲cpu数
|
||||
QueNcpus string `json:"queNcpus"` //队列cpu数
|
||||
}
|
||||
}
|
||||
|
||||
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*************************/
|
||||
)
|
|
@ -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二级接口
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
|
@ -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"),
|
||||
)
|
||||
|
|
|
@ -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
|
||||
}
|
|
@ -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"`
|
||||
|
|
|
@ -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))
|
||||
}
|
|
@ -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
|
||||
}
|
Loading…
Reference in New Issue