| @@ -10,7 +10,7 @@ ScheduleHpcConf: | |||||
| CloudTopic: Schedule-Cloud-Topic | CloudTopic: Schedule-Cloud-Topic | ||||
| DB: | DB: | ||||
| DataSource: root:uJpLd6u-J?HC1@(106.53.150.192:3306)/pcm?parseTime=true | |||||
| DataSource: | |||||
| Redis: | Redis: | ||||
| Host: localhost:6379 | Host: localhost:6379 | ||||
| @@ -0,0 +1,21 @@ | |||||
| package handler | |||||
| import ( | |||||
| "net/http" | |||||
| "PCM/adaptor/PCM-CORE/api/internal/logic" | |||||
| "PCM/adaptor/PCM-CORE/api/internal/svc" | |||||
| "github.com/zeromicro/go-zero/rest/httpx" | |||||
| ) | |||||
| func listCenterHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { | |||||
| return func(w http.ResponseWriter, r *http.Request) { | |||||
| l := logic.NewListCenterLogic(r.Context(), svcCtx) | |||||
| resp, err := l.ListCenter() | |||||
| if err != nil { | |||||
| httpx.ErrorCtx(r.Context(), w, err) | |||||
| } else { | |||||
| httpx.OkJsonCtx(r.Context(), w, resp) | |||||
| } | |||||
| } | |||||
| } | |||||
| @@ -22,6 +22,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { | |||||
| Path: "/taskList", | Path: "/taskList", | ||||
| Handler: TaskListHandler(serverCtx), | Handler: TaskListHandler(serverCtx), | ||||
| }, | }, | ||||
| { | |||||
| Method: http.MethodGet, | |||||
| Path: "/listCenter", | |||||
| Handler: listCenterHandler(serverCtx), | |||||
| }, | |||||
| }, | }, | ||||
| ) | ) | ||||
| } | } | ||||
| @@ -0,0 +1,85 @@ | |||||
| package logic | |||||
| import ( | |||||
| "PCM/adaptor/PCM-CORE/api/internal/svc" | |||||
| "PCM/adaptor/PCM-CORE/api/internal/types" | |||||
| "PCM/adaptor/PCM-CORE/model" | |||||
| "context" | |||||
| "github.com/zeromicro/go-zero/core/logx" | |||||
| ) | |||||
| type ListCenterLogic struct { | |||||
| logx.Logger | |||||
| ctx context.Context | |||||
| svcCtx *svc.ServiceContext | |||||
| } | |||||
| func NewListCenterLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ListCenterLogic { | |||||
| return &ListCenterLogic{ | |||||
| Logger: logx.WithContext(ctx), | |||||
| ctx: ctx, | |||||
| svcCtx: svcCtx, | |||||
| } | |||||
| } | |||||
| func (l *ListCenterLogic) ListCenter() (*types.ListCenterResp, error) { | |||||
| var centers []types.Center | |||||
| var centersModel *[]model.CenterOverview | |||||
| //var centersModel []model.ComputeCenter | |||||
| var resp types.ListCenterResp | |||||
| centersModel, _ = l.svcCtx.CenterOverviewModel.FindAll(l.ctx) | |||||
| var centerModelV = *centersModel | |||||
| for _, overview := range centerModelV { | |||||
| var center types.Center | |||||
| center.Id = overview.Id.Int64 | |||||
| center.CenterSource = overview.CenterSource.String | |||||
| center.SourceId = overview.SourceId.String | |||||
| center.Name = overview.Name.String | |||||
| center.Description = overview.Description.String | |||||
| center.Type = overview.Type.String | |||||
| center.Area = overview.Area.String | |||||
| center.City = overview.City.String | |||||
| center.Longitude = overview.Longitude.Float64 | |||||
| center.Latitude = overview.Latitude.Float64 | |||||
| center.Status = overview.Status.String | |||||
| center.UserNum = overview.UserNum.Int64 | |||||
| center.CloudClusterNum = overview.CloudClusterNum.Int64 | |||||
| center.AiClusterNum = overview.AiClusterNum.Int64 | |||||
| center.HpcClusterNum = overview.HpcClusterNum.Int64 | |||||
| center.CloudNodeNum = overview.CloudNodeNum.Int64 | |||||
| center.AiNodeNum = overview.AiNodeNum.Int64 | |||||
| center.HpcNodeNum = overview.HpcNodeNum.Int64 | |||||
| center.CloudCpuNum = overview.CloudCpuNum.Int64 | |||||
| center.AiCpuNum = overview.AiCpuNum.Int64 | |||||
| center.HpcCpuNum = overview.HpcCpuNum.Int64 | |||||
| center.CloudGpuNum = overview.CloudGpuNum.Int64 | |||||
| center.AiGpuNum = overview.AiGpuNum.Int64 | |||||
| center.HpcGpuNum = overview.HpcGpuNum.Int64 | |||||
| center.CloudMngFlops = overview.CloudMngFlops.Int64 | |||||
| center.AiMngFlops = overview.AiMngFlops.Int64 | |||||
| center.HpcMngFlops = overview.HpcMngFlops.Int64 | |||||
| center.CloudUmngFlops = overview.CloudUmngFlops.Int64 | |||||
| center.AiUmngFlops = overview.AiUmngFlops.Int64 | |||||
| center.HpcUmngFlops = overview.HpcUmngFlops.Int64 | |||||
| center.CloudMngStorage = overview.CloudMngStorage.Int64 | |||||
| center.AiMngStorage = overview.AiMngStorage.Int64 | |||||
| center.HpcMngStorage = overview.HpcMngStorage.Int64 | |||||
| center.CloudUmngStorage = overview.CloudUmngStorage.Int64 | |||||
| center.AiUmngStorage = overview.AiUmngStorage.Int64 | |||||
| center.HpcUmngStorage = overview.HpcUmngStorage.Int64 | |||||
| center.Edwc = overview.Edwc.Bool | |||||
| center.Ydyl = overview.Ydyl.Bool | |||||
| center.DeletedFlag = overview.DeletedFlag.Int64 | |||||
| centers = append(centers, center) | |||||
| } | |||||
| resp.Code = 200 | |||||
| resp.Msg = "success" | |||||
| resp.Data.TotalCount = len(centers) | |||||
| resp.Data.Centers = centers | |||||
| return &resp, nil | |||||
| } | |||||
| @@ -15,6 +15,7 @@ type ServiceContext struct { | |||||
| RedisClient *redis.Client | RedisClient *redis.Client | ||||
| ScheduleCloudClient *kq.Pusher | ScheduleCloudClient *kq.Pusher | ||||
| TaskModel model.TaskModel | TaskModel model.TaskModel | ||||
| CenterOverviewModel model.CenterOverviewModel | |||||
| SqlConn sqlx.SqlConn | SqlConn sqlx.SqlConn | ||||
| Db *sql.DB | Db *sql.DB | ||||
| } | } | ||||
| @@ -30,6 +31,7 @@ func NewServiceContext(c config.Config) *ServiceContext { | |||||
| }), | }), | ||||
| SqlConn: sqlx.NewMysql(c.DB.DataSource), | SqlConn: sqlx.NewMysql(c.DB.DataSource), | ||||
| TaskModel: model.NewTaskModel(sqlConn, c.Cache), | TaskModel: model.NewTaskModel(sqlConn, c.Cache), | ||||
| CenterOverviewModel: model.NewCenterOverviewModel(sqlConn, c.Cache), | |||||
| ScheduleHpcClient: kq.NewPusher(c.ScheduleHpcConf.Brokers, c.ScheduleHpcConf.HpcTopic), | ScheduleHpcClient: kq.NewPusher(c.ScheduleHpcConf.Brokers, c.ScheduleHpcConf.HpcTopic), | ||||
| ScheduleCloudClient: kq.NewPusher(c.ScheduleHpcConf.Brokers, c.ScheduleHpcConf.CloudTopic), | ScheduleCloudClient: kq.NewPusher(c.ScheduleHpcConf.Brokers, c.ScheduleHpcConf.CloudTopic), | ||||
| } | } | ||||
| @@ -34,3 +34,56 @@ type Task struct { | |||||
| ServiceName string `json:"serviceName"` | ServiceName string `json:"serviceName"` | ||||
| SynergyStatus string `json:"synergyStatus"` | SynergyStatus string `json:"synergyStatus"` | ||||
| } | } | ||||
| type ListCenterResp struct { | |||||
| Code int32 `json:"code"` | |||||
| Msg string `json:"msg"` | |||||
| Data CenterData `json:"data"` | |||||
| } | |||||
| type CenterData struct { | |||||
| TotalCount int `json:"totalCount"` | |||||
| Centers []Center `json:"centers"` | |||||
| } | |||||
| type Center struct { | |||||
| Id int64 `json:"id"` | |||||
| CenterSource string `json:"centerSource"` | |||||
| SourceId string `json:"sourceId"` | |||||
| Name string `json:"name"` | |||||
| Description string `json:"description"` | |||||
| Type string `json:"type"` | |||||
| Area string `json:"area"` | |||||
| City string `json:"city"` | |||||
| Longitude float64 `json:"longitude"` | |||||
| Latitude float64 `json:"latitude"` | |||||
| Status string `json:"status"` | |||||
| UserNum int64 `json:"userNum"` | |||||
| DeletedFlag int64 `json:"deletedFlag"` | |||||
| CloudClusterNum int64 `json:"cloudClusterNum"` | |||||
| CloudNodeNum int64 `json:"cloudNodeNum"` | |||||
| CloudCpuNum int64 `json:"cloudCpuNum"` | |||||
| CloudGpuNum int64 `json:"cloudGpuNum"` | |||||
| CloudMngFlops int64 `json:"cloudMngFlops"` | |||||
| CloudUmngFlops int64 `json:"cloudUmngFlops"` | |||||
| CloudMngStorage int64 `json:"cloudMngStorage"` | |||||
| CloudUmngStorage int64 `json:"cloudUmngStorage"` | |||||
| AiClusterNum int64 `json:"aiClusterNum"` | |||||
| AiNodeNum int64 `json:"aiNodeNum"` | |||||
| AiCpuNum int64 `json:"aiCpuNum"` | |||||
| AiGpuNum int64 `json:"aiGpuNum"` | |||||
| AiMngFlops int64 `json:"aiMngFlops"` | |||||
| AiUmngFlops int64 `json:"aiUmngFlops"` | |||||
| AiMngStorage int64 `json:"aiMngStorage"` | |||||
| AiUmngStorage int64 `json:"aiUmngStorage"` | |||||
| HpcClusterNum int64 `json:"hpcClusterNum"` | |||||
| HpcNodeNum int64 `json:"hpcNodeNum"` | |||||
| HpcCpuNum int64 `json:"hpcCpuNum"` | |||||
| HpcGpuNum int64 `json:"hpcGpuNum"` | |||||
| HpcMngFlops int64 `json:"hpcMngFlops"` | |||||
| HpcUmngFlops int64 `json:"hpcUmngFlops"` | |||||
| HpcMngStorage int64 `json:"hpcMngStorage"` | |||||
| HpcUmngStorage int64 `json:"hpcUmngStorage"` | |||||
| Edwc bool `json:"edwc"` | |||||
| Ydyl bool `json:"ydyl"` | |||||
| } | |||||
| @@ -42,10 +42,66 @@ type ( | |||||
| } | } | ||||
| ) | ) | ||||
| type ( | |||||
| listCenterResp { | |||||
| Code int32 `json:"code"` | |||||
| Msg string `json:"msg"` | |||||
| Data CenterData `json:"data"` | |||||
| } | |||||
| CenterData { | |||||
| TotalCount int `json:"totalCount"` | |||||
| Centers []Center `json:"centers"` | |||||
| } | |||||
| Center { | |||||
| Id int64 `json:"id"` | |||||
| CenterSource string `json:"centerSource"` | |||||
| SourceId string `json:"sourceId"` | |||||
| Name string `json:"name"` | |||||
| Description string `json:"description"` | |||||
| Type string `json:"type"` | |||||
| Area string `json:"area"` | |||||
| City string `json:"city"` | |||||
| Longitude float64 `json:"longitude"` | |||||
| Latitude float64 `json:"latitude"` | |||||
| Status string `json:"status"` | |||||
| UserNum int64 `json:"userNum"` | |||||
| DeletedFlag int64 `json:"deletedFlag"` | |||||
| CloudClusterNum int64 `json:"cloudClusterNum"` | |||||
| CloudNodeNum int64 `json:"cloudNodeNum"` | |||||
| CloudCpuNum int64 `json:"cloudCpuNum"` | |||||
| CloudGpuNum int64 `json:"cloudGpuNum"` | |||||
| CloudMngFlops int64 `json:"cloudMngFlops"` | |||||
| CloudUmngFlops int64 `json:"cloudUmngFlops"` | |||||
| CloudMngStorage int64 `json:"cloudMngStorage"` | |||||
| CloudUmngStorage int64 `json:"cloudUmngStorage"` | |||||
| AiClusterNum int64 `json:"aiClusterNum"` | |||||
| AiNodeNum int64 `json:"aiNodeNum"` | |||||
| AiCpuNum int64 `json:"aiCpuNum"` | |||||
| AiGpuNum int64 `json:"aiGpuNum"` | |||||
| AiMngFlops int64 `json:"aiMngFlops"` | |||||
| AiUmngFlops int64 `json:"aiUmngFlops"` | |||||
| AiMngStorage int64 `json:"aiMngStorage"` | |||||
| AiUmngStorage int64 `json:"aiUmngStorage"` | |||||
| HpcClusterNum int64 `json:"hpcClusterNum"` | |||||
| HpcNodeNum int64 `json:"hpcNodeNum"` | |||||
| HpcCpuNum int64 `json:"hpcCpuNum"` | |||||
| HpcGpuNum int64 `json:"hpcGpuNum"` | |||||
| HpcMngFlops int64 `json:"hpcMngFlops"` | |||||
| HpcUmngFlops int64 `json:"hpcUmngFlops"` | |||||
| HpcMngStorage int64 `json:"hpcMngStorage"` | |||||
| HpcUmngStorage int64 `json:"hpcUmngStorage"` | |||||
| Edwc bool `json:"edwc"` | |||||
| Ydyl bool `json:"ydyl"` | |||||
| } | |||||
| ) | |||||
| service pcmcore-api { | service pcmcore-api { | ||||
| @handler scheduleTaskHandler | @handler scheduleTaskHandler | ||||
| post /scheduleTask (scheduleTaskReq) returns (scheduleTaskResp) | post /scheduleTask (scheduleTaskReq) returns (scheduleTaskResp) | ||||
| @handler TaskListHandler | @handler TaskListHandler | ||||
| get /taskList () returns (taskListResp) | get /taskList () returns (taskListResp) | ||||
| @handler listCenterHandler | |||||
| get /listCenter () returns (listCenterResp) | |||||
| } | } | ||||
| @@ -0,0 +1,27 @@ | |||||
| package model | |||||
| import ( | |||||
| "github.com/zeromicro/go-zero/core/stores/cache" | |||||
| "github.com/zeromicro/go-zero/core/stores/sqlx" | |||||
| ) | |||||
| var _ AiCenterModel = (*customAiCenterModel)(nil) | |||||
| type ( | |||||
| // AiCenterModel is an interface to be customized, add more methods here, | |||||
| // and implement the added methods in customAiCenterModel. | |||||
| AiCenterModel interface { | |||||
| aiCenterModel | |||||
| } | |||||
| customAiCenterModel struct { | |||||
| *defaultAiCenterModel | |||||
| } | |||||
| ) | |||||
| // NewAiCenterModel returns a model for the database table. | |||||
| func NewAiCenterModel(conn sqlx.SqlConn, c cache.CacheConf) AiCenterModel { | |||||
| return &customAiCenterModel{ | |||||
| defaultAiCenterModel: newAiCenterModel(conn, c), | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,115 @@ | |||||
| // Code generated by goctl. DO NOT EDIT. | |||||
| package model | |||||
| import ( | |||||
| "context" | |||||
| "database/sql" | |||||
| "fmt" | |||||
| "strings" | |||||
| "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 ( | |||||
| aiCenterFieldNames = builder.RawFieldNames(&AiCenter{}) | |||||
| aiCenterRows = strings.Join(aiCenterFieldNames, ",") | |||||
| aiCenterRowsExpectAutoSet = strings.Join(stringx.Remove(aiCenterFieldNames, "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), ",") | |||||
| aiCenterRowsWithPlaceHolder = strings.Join(stringx.Remove(aiCenterFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), "=?,") + "=?" | |||||
| cachePcmAiCenterIdPrefix = "cache:pcm:aiCenter:id:" | |||||
| ) | |||||
| type ( | |||||
| aiCenterModel interface { | |||||
| Insert(ctx context.Context, data *AiCenter) (sql.Result, error) | |||||
| FindOne(ctx context.Context, id int64) (*AiCenter, error) | |||||
| Update(ctx context.Context, data *AiCenter) error | |||||
| Delete(ctx context.Context, id int64) error | |||||
| } | |||||
| defaultAiCenterModel struct { | |||||
| sqlc.CachedConn | |||||
| table string | |||||
| } | |||||
| AiCenter struct { | |||||
| Id int64 `db:"id"` // 平台唯一id | |||||
| ClusterNum sql.NullInt64 `db:"cluster_num"` // 集群数量 | |||||
| NodeNum sql.NullInt64 `db:"node_num"` // 节点数量 | |||||
| CpuNum sql.NullInt64 `db:"cpu_num"` // CPU核数 | |||||
| GpuNum sql.NullInt64 `db:"gpu_num"` // GPU卡数 | |||||
| ManagedFlops sql.NullString `db:"managed_flops"` // 已接入算力 | |||||
| UnmanagedFlops sql.NullString `db:"unmanaged_flops"` // 未接入算力 | |||||
| ManagedStorage sql.NullString `db:"managed_storage"` // 已接入存储 | |||||
| UnmanagedStorage sql.NullString `db:"unmanaged_storage"` // 未接入存储 | |||||
| } | |||||
| ) | |||||
| func newAiCenterModel(conn sqlx.SqlConn, c cache.CacheConf) *defaultAiCenterModel { | |||||
| return &defaultAiCenterModel{ | |||||
| CachedConn: sqlc.NewConn(conn, c), | |||||
| table: "`ai_center`", | |||||
| } | |||||
| } | |||||
| func (m *defaultAiCenterModel) Delete(ctx context.Context, id int64) error { | |||||
| pcmAiCenterIdKey := fmt.Sprintf("%s%v", cachePcmAiCenterIdPrefix, 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) | |||||
| }, pcmAiCenterIdKey) | |||||
| return err | |||||
| } | |||||
| func (m *defaultAiCenterModel) FindOne(ctx context.Context, id int64) (*AiCenter, error) { | |||||
| pcmAiCenterIdKey := fmt.Sprintf("%s%v", cachePcmAiCenterIdPrefix, id) | |||||
| var resp AiCenter | |||||
| err := m.QueryRowCtx(ctx, &resp, pcmAiCenterIdKey, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) error { | |||||
| query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", aiCenterRows, 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 *defaultAiCenterModel) Insert(ctx context.Context, data *AiCenter) (sql.Result, error) { | |||||
| pcmAiCenterIdKey := fmt.Sprintf("%s%v", cachePcmAiCenterIdPrefix, 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, aiCenterRowsExpectAutoSet) | |||||
| return conn.ExecCtx(ctx, query, data.Id, data.ClusterNum, data.NodeNum, data.CpuNum, data.GpuNum, data.ManagedFlops, data.UnmanagedFlops, data.ManagedStorage, data.UnmanagedStorage) | |||||
| }, pcmAiCenterIdKey) | |||||
| return ret, err | |||||
| } | |||||
| func (m *defaultAiCenterModel) Update(ctx context.Context, data *AiCenter) error { | |||||
| pcmAiCenterIdKey := fmt.Sprintf("%s%v", cachePcmAiCenterIdPrefix, 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, aiCenterRowsWithPlaceHolder) | |||||
| return conn.ExecCtx(ctx, query, data.ClusterNum, data.NodeNum, data.CpuNum, data.GpuNum, data.ManagedFlops, data.UnmanagedFlops, data.ManagedStorage, data.UnmanagedStorage, data.Id) | |||||
| }, pcmAiCenterIdKey) | |||||
| return err | |||||
| } | |||||
| func (m *defaultAiCenterModel) formatPrimary(primary interface{}) string { | |||||
| return fmt.Sprintf("%s%v", cachePcmAiCenterIdPrefix, primary) | |||||
| } | |||||
| func (m *defaultAiCenterModel) queryPrimary(ctx context.Context, conn sqlx.SqlConn, v, primary interface{}) error { | |||||
| query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", aiCenterRows, m.table) | |||||
| return conn.QueryRowCtx(ctx, v, query, primary) | |||||
| } | |||||
| func (m *defaultAiCenterModel) tableName() string { | |||||
| return m.table | |||||
| } | |||||
| @@ -0,0 +1,27 @@ | |||||
| package model | |||||
| import ( | |||||
| "github.com/zeromicro/go-zero/core/stores/cache" | |||||
| "github.com/zeromicro/go-zero/core/stores/sqlx" | |||||
| ) | |||||
| var _ CenterOverviewModel = (*customCenterOverviewModel)(nil) | |||||
| type ( | |||||
| // CenterOverviewModel is an interface to be customized, add more methods here, | |||||
| // and implement the added methods in customCenterOverviewModel. | |||||
| CenterOverviewModel interface { | |||||
| centerOverviewModel | |||||
| } | |||||
| customCenterOverviewModel struct { | |||||
| *defaultCenterOverviewModel | |||||
| } | |||||
| ) | |||||
| // NewCenterOverviewModel returns a model for the database table. | |||||
| func NewCenterOverviewModel(conn sqlx.SqlConn, c cache.CacheConf) CenterOverviewModel { | |||||
| return &customCenterOverviewModel{ | |||||
| defaultCenterOverviewModel: newCenterOverviewModel(conn, c), | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,91 @@ | |||||
| package model | |||||
| import ( | |||||
| "context" | |||||
| "database/sql" | |||||
| "github.com/Masterminds/squirrel" | |||||
| "github.com/zeromicro/go-zero/core/stores/cache" | |||||
| "github.com/zeromicro/go-zero/core/stores/sqlc" | |||||
| "github.com/zeromicro/go-zero/core/stores/sqlx" | |||||
| ) | |||||
| type ( | |||||
| centerOverviewModel interface { | |||||
| FindAll(ctx context.Context) (*[]CenterOverview, error) | |||||
| } | |||||
| defaultCenterOverviewModel struct { | |||||
| sqlc.CachedConn | |||||
| table string | |||||
| } | |||||
| CenterOverview struct { | |||||
| Id sql.NullInt64 `json:"id"` | |||||
| CenterSource sql.NullString `json:"centerSource"` | |||||
| SourceId sql.NullString `json:"sourceId"` | |||||
| Name sql.NullString `json:"name"` | |||||
| Description sql.NullString `json:"description"` | |||||
| Type sql.NullString `json:"type"` | |||||
| Area sql.NullString `json:"area"` | |||||
| City sql.NullString `json:"city"` | |||||
| Longitude sql.NullFloat64 `json:"longitude"` | |||||
| Latitude sql.NullFloat64 `json:"latitude"` | |||||
| Status sql.NullString `json:"status"` | |||||
| UserNum sql.NullInt64 `json:"userNum"` | |||||
| DeletedFlag sql.NullInt64 `json:"deletedFlag"` | |||||
| CloudClusterNum sql.NullInt64 `json:"cloudClusterNum"` | |||||
| CloudNodeNum sql.NullInt64 `json:"cloudNodeNum"` | |||||
| CloudCpuNum sql.NullInt64 `json:"cloudCpuNum"` | |||||
| CloudGpuNum sql.NullInt64 `json:"cloudGpuNum"` | |||||
| CloudMngFlops sql.NullInt64 `json:"cloudMngFlops"` | |||||
| CloudUmngFlops sql.NullInt64 `json:"cloudUmngFlops"` | |||||
| CloudMngStorage sql.NullInt64 `json:"CloudMngStorage"` | |||||
| CloudUmngStorage sql.NullInt64 `json:"CloudUmngStorage"` | |||||
| AiClusterNum sql.NullInt64 `json:"aiClusterNum"` | |||||
| AiNodeNum sql.NullInt64 `json:"aiNodeNum"` | |||||
| AiCpuNum sql.NullInt64 `json:"aiCpuNum"` | |||||
| AiGpuNum sql.NullInt64 `json:"aiGpuNum"` | |||||
| AiMngFlops sql.NullInt64 `json:"aiMngFlops"` | |||||
| AiUmngFlops sql.NullInt64 `json:"aiUmngFlops"` | |||||
| AiMngStorage sql.NullInt64 `json:"aiMngStorage"` | |||||
| AiUmngStorage sql.NullInt64 `json:"aiUmngStorage"` | |||||
| HpcClusterNum sql.NullInt64 `json:"hpcClusterNum"` | |||||
| HpcNodeNum sql.NullInt64 `json:"hpcNodeNum"` | |||||
| HpcCpuNum sql.NullInt64 `json:"hpcCpuNum"` | |||||
| HpcGpuNum sql.NullInt64 `json:"hpcGpuNum"` | |||||
| HpcMngFlops sql.NullInt64 `json:"hpcMngFlops"` | |||||
| HpcUmngFlops sql.NullInt64 `json:"hpcUmngFlops"` | |||||
| HpcMngStorage sql.NullInt64 `json:"hpcMngStorage"` | |||||
| HpcUmngStorage sql.NullInt64 `json:"hpcUmngStorage"` | |||||
| Edwc sql.NullBool `json:"edwc"` | |||||
| Ydyl sql.NullBool `json:"ydyl"` | |||||
| } | |||||
| ) | |||||
| func newCenterOverviewModel(conn sqlx.SqlConn, c cache.CacheConf) *defaultCenterOverviewModel { | |||||
| return &defaultCenterOverviewModel{ | |||||
| CachedConn: sqlc.NewConn(conn, c), | |||||
| table: "`compute_center`", | |||||
| } | |||||
| } | |||||
| func (m *defaultCenterOverviewModel) FindAll(ctx context.Context) (*[]CenterOverview, error) { | |||||
| var centers []CenterOverview | |||||
| centerSelect := squirrel.Select(`cc.*`, `ac.cluster_num`, `ac.node_num`, `ac.cpu_num`, `ac.gpu_num`, `ac.managed_flops`, `ac.unmanaged_flops`, `ac.managed_storage`, `ac.unmanaged_storage`, `hc.cluster_num`, `c.node_num`, `hc.cpu_num`, `hc.gpu_num`, `hc.managed_flops`, `hc.unmanaged_flops`, `hc.managed_storage`, `hc.unmanaged_storage`, `c.cluster_num`, `c.node_num`, `c.cpu_num`, `c.gpu_num`, `c.managed_flops`, `c.unmanaged_flops`, `c.managed_storage`, `c.unmanaged_storage`, `ct.edwc`, `ct.ydyl`). | |||||
| From("compute_center cc"). | |||||
| LeftJoin(`ai_center ac on cc.id = ac.id`). | |||||
| LeftJoin(`hpc_center hc on cc.id = hc.id`). | |||||
| LeftJoin(`cloud_center c on cc.id = c.id`). | |||||
| LeftJoin(`center_tag ct on cc.id = ct.id`). | |||||
| Where(`cc.deleted_flag = 0`) | |||||
| query, values, _ := centerSelect.ToSql() | |||||
| err := m.QueryRowsNoCacheCtx(ctx, ¢ers, query, values...) | |||||
| if err != nil { | |||||
| return nil, err | |||||
| } | |||||
| return ¢ers, nil | |||||
| } | |||||
| @@ -0,0 +1,27 @@ | |||||
| package model | |||||
| import ( | |||||
| "github.com/zeromicro/go-zero/core/stores/cache" | |||||
| "github.com/zeromicro/go-zero/core/stores/sqlx" | |||||
| ) | |||||
| var _ CenterTagModel = (*customCenterTagModel)(nil) | |||||
| type ( | |||||
| // CenterTagModel is an interface to be customized, add more methods here, | |||||
| // and implement the added methods in customCenterTagModel. | |||||
| CenterTagModel interface { | |||||
| centerTagModel | |||||
| } | |||||
| customCenterTagModel struct { | |||||
| *defaultCenterTagModel | |||||
| } | |||||
| ) | |||||
| // NewCenterTagModel returns a model for the database table. | |||||
| func NewCenterTagModel(conn sqlx.SqlConn, c cache.CacheConf) CenterTagModel { | |||||
| return &customCenterTagModel{ | |||||
| defaultCenterTagModel: newCenterTagModel(conn, c), | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,109 @@ | |||||
| // Code generated by goctl. DO NOT EDIT. | |||||
| package model | |||||
| import ( | |||||
| "context" | |||||
| "database/sql" | |||||
| "fmt" | |||||
| "strings" | |||||
| "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 ( | |||||
| centerTagFieldNames = builder.RawFieldNames(&CenterTag{}) | |||||
| centerTagRows = strings.Join(centerTagFieldNames, ",") | |||||
| centerTagRowsExpectAutoSet = strings.Join(stringx.Remove(centerTagFieldNames, "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), ",") | |||||
| centerTagRowsWithPlaceHolder = strings.Join(stringx.Remove(centerTagFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), "=?,") + "=?" | |||||
| cachePcmCenterTagIdPrefix = "cache:pcm:centerTag:id:" | |||||
| ) | |||||
| type ( | |||||
| centerTagModel interface { | |||||
| Insert(ctx context.Context, data *CenterTag) (sql.Result, error) | |||||
| FindOne(ctx context.Context, id int64) (*CenterTag, error) | |||||
| Update(ctx context.Context, data *CenterTag) error | |||||
| Delete(ctx context.Context, id int64) error | |||||
| } | |||||
| defaultCenterTagModel struct { | |||||
| sqlc.CachedConn | |||||
| table string | |||||
| } | |||||
| CenterTag struct { | |||||
| Id int64 `db:"id"` // 平台唯一id | |||||
| Ydyl sql.NullInt64 `db:"ydyl"` // 一带一路标识 | |||||
| Edwc sql.NullInt64 `db:"edwc"` // 东数西算标识 | |||||
| } | |||||
| ) | |||||
| func newCenterTagModel(conn sqlx.SqlConn, c cache.CacheConf) *defaultCenterTagModel { | |||||
| return &defaultCenterTagModel{ | |||||
| CachedConn: sqlc.NewConn(conn, c), | |||||
| table: "`center_tag`", | |||||
| } | |||||
| } | |||||
| func (m *defaultCenterTagModel) Delete(ctx context.Context, id int64) error { | |||||
| pcmCenterTagIdKey := fmt.Sprintf("%s%v", cachePcmCenterTagIdPrefix, 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) | |||||
| }, pcmCenterTagIdKey) | |||||
| return err | |||||
| } | |||||
| func (m *defaultCenterTagModel) FindOne(ctx context.Context, id int64) (*CenterTag, error) { | |||||
| pcmCenterTagIdKey := fmt.Sprintf("%s%v", cachePcmCenterTagIdPrefix, id) | |||||
| var resp CenterTag | |||||
| err := m.QueryRowCtx(ctx, &resp, pcmCenterTagIdKey, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) error { | |||||
| query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", centerTagRows, 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 *defaultCenterTagModel) Insert(ctx context.Context, data *CenterTag) (sql.Result, error) { | |||||
| pcmCenterTagIdKey := fmt.Sprintf("%s%v", cachePcmCenterTagIdPrefix, 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, centerTagRowsExpectAutoSet) | |||||
| return conn.ExecCtx(ctx, query, data.Id, data.Ydyl, data.Edwc) | |||||
| }, pcmCenterTagIdKey) | |||||
| return ret, err | |||||
| } | |||||
| func (m *defaultCenterTagModel) Update(ctx context.Context, data *CenterTag) error { | |||||
| pcmCenterTagIdKey := fmt.Sprintf("%s%v", cachePcmCenterTagIdPrefix, 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, centerTagRowsWithPlaceHolder) | |||||
| return conn.ExecCtx(ctx, query, data.Ydyl, data.Edwc, data.Id) | |||||
| }, pcmCenterTagIdKey) | |||||
| return err | |||||
| } | |||||
| func (m *defaultCenterTagModel) formatPrimary(primary interface{}) string { | |||||
| return fmt.Sprintf("%s%v", cachePcmCenterTagIdPrefix, primary) | |||||
| } | |||||
| func (m *defaultCenterTagModel) queryPrimary(ctx context.Context, conn sqlx.SqlConn, v, primary interface{}) error { | |||||
| query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", centerTagRows, m.table) | |||||
| return conn.QueryRowCtx(ctx, v, query, primary) | |||||
| } | |||||
| func (m *defaultCenterTagModel) tableName() string { | |||||
| return m.table | |||||
| } | |||||
| @@ -0,0 +1,27 @@ | |||||
| package model | |||||
| import ( | |||||
| "github.com/zeromicro/go-zero/core/stores/cache" | |||||
| "github.com/zeromicro/go-zero/core/stores/sqlx" | |||||
| ) | |||||
| var _ CloudCenterModel = (*customCloudCenterModel)(nil) | |||||
| type ( | |||||
| // CloudCenterModel is an interface to be customized, add more methods here, | |||||
| // and implement the added methods in customCloudCenterModel. | |||||
| CloudCenterModel interface { | |||||
| cloudCenterModel | |||||
| } | |||||
| customCloudCenterModel struct { | |||||
| *defaultCloudCenterModel | |||||
| } | |||||
| ) | |||||
| // NewCloudCenterModel returns a model for the database table. | |||||
| func NewCloudCenterModel(conn sqlx.SqlConn, c cache.CacheConf) CloudCenterModel { | |||||
| return &customCloudCenterModel{ | |||||
| defaultCloudCenterModel: newCloudCenterModel(conn, c), | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,115 @@ | |||||
| // Code generated by goctl. DO NOT EDIT. | |||||
| package model | |||||
| import ( | |||||
| "context" | |||||
| "database/sql" | |||||
| "fmt" | |||||
| "strings" | |||||
| "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 ( | |||||
| cloudCenterFieldNames = builder.RawFieldNames(&CloudCenter{}) | |||||
| cloudCenterRows = strings.Join(cloudCenterFieldNames, ",") | |||||
| cloudCenterRowsExpectAutoSet = strings.Join(stringx.Remove(cloudCenterFieldNames, "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), ",") | |||||
| cloudCenterRowsWithPlaceHolder = strings.Join(stringx.Remove(cloudCenterFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), "=?,") + "=?" | |||||
| cachePcmCloudCenterIdPrefix = "cache:pcm:cloudCenter:id:" | |||||
| ) | |||||
| type ( | |||||
| cloudCenterModel interface { | |||||
| Insert(ctx context.Context, data *CloudCenter) (sql.Result, error) | |||||
| FindOne(ctx context.Context, id int64) (*CloudCenter, error) | |||||
| Update(ctx context.Context, data *CloudCenter) error | |||||
| Delete(ctx context.Context, id int64) error | |||||
| } | |||||
| defaultCloudCenterModel struct { | |||||
| sqlc.CachedConn | |||||
| table string | |||||
| } | |||||
| CloudCenter struct { | |||||
| Id int64 `db:"id"` // 平台唯一id | |||||
| ClusterNum sql.NullInt64 `db:"cluster_num"` // 集群数量 | |||||
| NodeNum sql.NullInt64 `db:"node_num"` // 节点数量 | |||||
| CpuNum sql.NullInt64 `db:"cpu_num"` // CPU核数 | |||||
| GpuNum sql.NullInt64 `db:"gpu_num"` // GPU卡数 | |||||
| ManagedFlops sql.NullString `db:"managed_flops"` // 已接入算力 | |||||
| UnmanagedFlops sql.NullString `db:"unmanaged_flops"` // 未接入算力 | |||||
| ManagedStorage sql.NullString `db:"managed_storage"` // 已接入存储 | |||||
| UnmanagedStorage sql.NullString `db:"unmanaged_storage"` // 未接入存储 | |||||
| } | |||||
| ) | |||||
| func newCloudCenterModel(conn sqlx.SqlConn, c cache.CacheConf) *defaultCloudCenterModel { | |||||
| return &defaultCloudCenterModel{ | |||||
| CachedConn: sqlc.NewConn(conn, c), | |||||
| table: "`cloud_center`", | |||||
| } | |||||
| } | |||||
| func (m *defaultCloudCenterModel) Delete(ctx context.Context, id int64) error { | |||||
| pcmCloudCenterIdKey := fmt.Sprintf("%s%v", cachePcmCloudCenterIdPrefix, 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) | |||||
| }, pcmCloudCenterIdKey) | |||||
| return err | |||||
| } | |||||
| func (m *defaultCloudCenterModel) FindOne(ctx context.Context, id int64) (*CloudCenter, error) { | |||||
| pcmCloudCenterIdKey := fmt.Sprintf("%s%v", cachePcmCloudCenterIdPrefix, id) | |||||
| var resp CloudCenter | |||||
| err := m.QueryRowCtx(ctx, &resp, pcmCloudCenterIdKey, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) error { | |||||
| query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", cloudCenterRows, 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 *defaultCloudCenterModel) Insert(ctx context.Context, data *CloudCenter) (sql.Result, error) { | |||||
| pcmCloudCenterIdKey := fmt.Sprintf("%s%v", cachePcmCloudCenterIdPrefix, 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, cloudCenterRowsExpectAutoSet) | |||||
| return conn.ExecCtx(ctx, query, data.Id, data.ClusterNum, data.NodeNum, data.CpuNum, data.GpuNum, data.ManagedFlops, data.UnmanagedFlops, data.ManagedStorage, data.UnmanagedStorage) | |||||
| }, pcmCloudCenterIdKey) | |||||
| return ret, err | |||||
| } | |||||
| func (m *defaultCloudCenterModel) Update(ctx context.Context, data *CloudCenter) error { | |||||
| pcmCloudCenterIdKey := fmt.Sprintf("%s%v", cachePcmCloudCenterIdPrefix, 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, cloudCenterRowsWithPlaceHolder) | |||||
| return conn.ExecCtx(ctx, query, data.ClusterNum, data.NodeNum, data.CpuNum, data.GpuNum, data.ManagedFlops, data.UnmanagedFlops, data.ManagedStorage, data.UnmanagedStorage, data.Id) | |||||
| }, pcmCloudCenterIdKey) | |||||
| return err | |||||
| } | |||||
| func (m *defaultCloudCenterModel) formatPrimary(primary interface{}) string { | |||||
| return fmt.Sprintf("%s%v", cachePcmCloudCenterIdPrefix, primary) | |||||
| } | |||||
| func (m *defaultCloudCenterModel) queryPrimary(ctx context.Context, conn sqlx.SqlConn, v, primary interface{}) error { | |||||
| query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", cloudCenterRows, m.table) | |||||
| return conn.QueryRowCtx(ctx, v, query, primary) | |||||
| } | |||||
| func (m *defaultCloudCenterModel) tableName() string { | |||||
| return m.table | |||||
| } | |||||
| @@ -0,0 +1,27 @@ | |||||
| package model | |||||
| import ( | |||||
| "github.com/zeromicro/go-zero/core/stores/cache" | |||||
| "github.com/zeromicro/go-zero/core/stores/sqlx" | |||||
| ) | |||||
| var _ ComputeCenterModel = (*customComputeCenterModel)(nil) | |||||
| type ( | |||||
| // ComputeCenterModel is an interface to be customized, add more methods here, | |||||
| // and implement the added methods in customComputeCenterModel. | |||||
| ComputeCenterModel interface { | |||||
| computeCenterModel | |||||
| } | |||||
| customComputeCenterModel struct { | |||||
| *defaultComputeCenterModel | |||||
| } | |||||
| ) | |||||
| // NewComputeCenterModel returns a model for the database table. | |||||
| func NewComputeCenterModel(conn sqlx.SqlConn, c cache.CacheConf) ComputeCenterModel { | |||||
| return &customComputeCenterModel{ | |||||
| defaultComputeCenterModel: newComputeCenterModel(conn, c), | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,119 @@ | |||||
| // Code generated by goctl. DO NOT EDIT. | |||||
| package model | |||||
| import ( | |||||
| "context" | |||||
| "database/sql" | |||||
| "fmt" | |||||
| "strings" | |||||
| "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 ( | |||||
| computeCenterFieldNames = builder.RawFieldNames(&ComputeCenter{}) | |||||
| computeCenterRows = strings.Join(computeCenterFieldNames, ",") | |||||
| computeCenterRowsExpectAutoSet = strings.Join(stringx.Remove(computeCenterFieldNames, "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), ",") | |||||
| computeCenterRowsWithPlaceHolder = strings.Join(stringx.Remove(computeCenterFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), "=?,") + "=?" | |||||
| cachePcmComputeCenterIdPrefix = "cache:pcm:computeCenter:id:" | |||||
| ) | |||||
| type ( | |||||
| computeCenterModel interface { | |||||
| Insert(ctx context.Context, data *ComputeCenter) (sql.Result, error) | |||||
| FindOne(ctx context.Context, id int64) (*ComputeCenter, error) | |||||
| Update(ctx context.Context, data *ComputeCenter) error | |||||
| Delete(ctx context.Context, id int64) error | |||||
| } | |||||
| defaultComputeCenterModel struct { | |||||
| sqlc.CachedConn | |||||
| table string | |||||
| } | |||||
| ComputeCenter struct { | |||||
| Id int64 `db:"id"` // 平台唯一id | |||||
| CenterSource sql.NullString `db:"center_source"` // 中心来源(鹏城,nudt,公有云等) | |||||
| SourceId sql.NullString `db:"source_id"` // 数据来源原id | |||||
| Name sql.NullString `db:"name"` // 中心名称 | |||||
| Description sql.NullString `db:"description"` // 详细描述 | |||||
| Type sql.NullString `db:"type"` // 中心类型(云算、智算 or 超算) | |||||
| Area sql.NullString `db:"area"` // 资源区域 | |||||
| City sql.NullString `db:"city"` // 所在城市 | |||||
| Longitude sql.NullFloat64 `db:"longitude"` // 经度 | |||||
| Latitude sql.NullFloat64 `db:"latitude"` // 纬度 | |||||
| Status sql.NullString `db:"status"` // 接入状态 | |||||
| UserNum sql.NullInt64 `db:"user_num"` // 用户数量 | |||||
| DeletedFlag sql.NullInt64 `db:"deleted_flag"` // 是否删除(0-否,1-是) | |||||
| } | |||||
| ) | |||||
| func newComputeCenterModel(conn sqlx.SqlConn, c cache.CacheConf) *defaultComputeCenterModel { | |||||
| return &defaultComputeCenterModel{ | |||||
| CachedConn: sqlc.NewConn(conn, c), | |||||
| table: "`compute_center`", | |||||
| } | |||||
| } | |||||
| func (m *defaultComputeCenterModel) Delete(ctx context.Context, id int64) error { | |||||
| pcmComputeCenterIdKey := fmt.Sprintf("%s%v", cachePcmComputeCenterIdPrefix, 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) | |||||
| }, pcmComputeCenterIdKey) | |||||
| return err | |||||
| } | |||||
| func (m *defaultComputeCenterModel) FindOne(ctx context.Context, id int64) (*ComputeCenter, error) { | |||||
| pcmComputeCenterIdKey := fmt.Sprintf("%s%v", cachePcmComputeCenterIdPrefix, id) | |||||
| var resp ComputeCenter | |||||
| err := m.QueryRowCtx(ctx, &resp, pcmComputeCenterIdKey, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) error { | |||||
| query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", computeCenterRows, 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 *defaultComputeCenterModel) Insert(ctx context.Context, data *ComputeCenter) (sql.Result, error) { | |||||
| pcmComputeCenterIdKey := fmt.Sprintf("%s%v", cachePcmComputeCenterIdPrefix, 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, computeCenterRowsExpectAutoSet) | |||||
| return conn.ExecCtx(ctx, query, data.Id, data.CenterSource, data.SourceId, data.Name, data.Description, data.Type, data.Area, data.City, data.Longitude, data.Latitude, data.Status, data.UserNum, data.DeletedFlag) | |||||
| }, pcmComputeCenterIdKey) | |||||
| return ret, err | |||||
| } | |||||
| func (m *defaultComputeCenterModel) Update(ctx context.Context, data *ComputeCenter) error { | |||||
| pcmComputeCenterIdKey := fmt.Sprintf("%s%v", cachePcmComputeCenterIdPrefix, 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, computeCenterRowsWithPlaceHolder) | |||||
| return conn.ExecCtx(ctx, query, data.CenterSource, data.SourceId, data.Name, data.Description, data.Type, data.Area, data.City, data.Longitude, data.Latitude, data.Status, data.UserNum, data.DeletedFlag, data.Id) | |||||
| }, pcmComputeCenterIdKey) | |||||
| return err | |||||
| } | |||||
| func (m *defaultComputeCenterModel) formatPrimary(primary interface{}) string { | |||||
| return fmt.Sprintf("%s%v", cachePcmComputeCenterIdPrefix, primary) | |||||
| } | |||||
| func (m *defaultComputeCenterModel) queryPrimary(ctx context.Context, conn sqlx.SqlConn, v, primary interface{}) error { | |||||
| query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", computeCenterRows, m.table) | |||||
| return conn.QueryRowCtx(ctx, v, query, primary) | |||||
| } | |||||
| func (m *defaultComputeCenterModel) tableName() string { | |||||
| return m.table | |||||
| } | |||||
| @@ -0,0 +1,27 @@ | |||||
| package model | |||||
| import ( | |||||
| "github.com/zeromicro/go-zero/core/stores/cache" | |||||
| "github.com/zeromicro/go-zero/core/stores/sqlx" | |||||
| ) | |||||
| var _ HpcCenterModel = (*customHpcCenterModel)(nil) | |||||
| type ( | |||||
| // HpcCenterModel is an interface to be customized, add more methods here, | |||||
| // and implement the added methods in customHpcCenterModel. | |||||
| HpcCenterModel interface { | |||||
| hpcCenterModel | |||||
| } | |||||
| customHpcCenterModel struct { | |||||
| *defaultHpcCenterModel | |||||
| } | |||||
| ) | |||||
| // NewHpcCenterModel returns a model for the database table. | |||||
| func NewHpcCenterModel(conn sqlx.SqlConn, c cache.CacheConf) HpcCenterModel { | |||||
| return &customHpcCenterModel{ | |||||
| defaultHpcCenterModel: newHpcCenterModel(conn, c), | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,115 @@ | |||||
| // Code generated by goctl. DO NOT EDIT. | |||||
| package model | |||||
| import ( | |||||
| "context" | |||||
| "database/sql" | |||||
| "fmt" | |||||
| "strings" | |||||
| "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 ( | |||||
| hpcCenterFieldNames = builder.RawFieldNames(&HpcCenter{}) | |||||
| hpcCenterRows = strings.Join(hpcCenterFieldNames, ",") | |||||
| hpcCenterRowsExpectAutoSet = strings.Join(stringx.Remove(hpcCenterFieldNames, "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), ",") | |||||
| hpcCenterRowsWithPlaceHolder = strings.Join(stringx.Remove(hpcCenterFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), "=?,") + "=?" | |||||
| cachePcmHpcCenterIdPrefix = "cache:pcm:hpcCenter:id:" | |||||
| ) | |||||
| type ( | |||||
| hpcCenterModel interface { | |||||
| Insert(ctx context.Context, data *HpcCenter) (sql.Result, error) | |||||
| FindOne(ctx context.Context, id int64) (*HpcCenter, error) | |||||
| Update(ctx context.Context, data *HpcCenter) error | |||||
| Delete(ctx context.Context, id int64) error | |||||
| } | |||||
| defaultHpcCenterModel struct { | |||||
| sqlc.CachedConn | |||||
| table string | |||||
| } | |||||
| HpcCenter struct { | |||||
| Id int64 `db:"id"` // 平台唯一id | |||||
| ClusterNum sql.NullInt64 `db:"cluster_num"` // 集群数量 | |||||
| NodeNum sql.NullInt64 `db:"node_num"` // 节点数量 | |||||
| CpuNum sql.NullInt64 `db:"cpu_num"` // CPU核数 | |||||
| GpuNum sql.NullInt64 `db:"gpu_num"` // GPU卡数 | |||||
| ManagedFlops sql.NullString `db:"managed_flops"` // 已接入算力 | |||||
| UnmanagedFlops sql.NullString `db:"unmanaged_flops"` // 未接入算力 | |||||
| ManagedStorage sql.NullString `db:"managed_storage"` // 已接入存储 | |||||
| UnmanagedStorage sql.NullString `db:"unmanaged_storage"` // 未接入存储 | |||||
| } | |||||
| ) | |||||
| func newHpcCenterModel(conn sqlx.SqlConn, c cache.CacheConf) *defaultHpcCenterModel { | |||||
| return &defaultHpcCenterModel{ | |||||
| CachedConn: sqlc.NewConn(conn, c), | |||||
| table: "`hpc_center`", | |||||
| } | |||||
| } | |||||
| func (m *defaultHpcCenterModel) Delete(ctx context.Context, id int64) error { | |||||
| pcmHpcCenterIdKey := fmt.Sprintf("%s%v", cachePcmHpcCenterIdPrefix, 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) | |||||
| }, pcmHpcCenterIdKey) | |||||
| return err | |||||
| } | |||||
| func (m *defaultHpcCenterModel) FindOne(ctx context.Context, id int64) (*HpcCenter, error) { | |||||
| pcmHpcCenterIdKey := fmt.Sprintf("%s%v", cachePcmHpcCenterIdPrefix, id) | |||||
| var resp HpcCenter | |||||
| err := m.QueryRowCtx(ctx, &resp, pcmHpcCenterIdKey, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) error { | |||||
| query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", hpcCenterRows, 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 *defaultHpcCenterModel) Insert(ctx context.Context, data *HpcCenter) (sql.Result, error) { | |||||
| pcmHpcCenterIdKey := fmt.Sprintf("%s%v", cachePcmHpcCenterIdPrefix, 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, hpcCenterRowsExpectAutoSet) | |||||
| return conn.ExecCtx(ctx, query, data.Id, data.ClusterNum, data.NodeNum, data.CpuNum, data.GpuNum, data.ManagedFlops, data.UnmanagedFlops, data.ManagedStorage, data.UnmanagedStorage) | |||||
| }, pcmHpcCenterIdKey) | |||||
| return ret, err | |||||
| } | |||||
| func (m *defaultHpcCenterModel) Update(ctx context.Context, data *HpcCenter) error { | |||||
| pcmHpcCenterIdKey := fmt.Sprintf("%s%v", cachePcmHpcCenterIdPrefix, 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, hpcCenterRowsWithPlaceHolder) | |||||
| return conn.ExecCtx(ctx, query, data.ClusterNum, data.NodeNum, data.CpuNum, data.GpuNum, data.ManagedFlops, data.UnmanagedFlops, data.ManagedStorage, data.UnmanagedStorage, data.Id) | |||||
| }, pcmHpcCenterIdKey) | |||||
| return err | |||||
| } | |||||
| func (m *defaultHpcCenterModel) formatPrimary(primary interface{}) string { | |||||
| return fmt.Sprintf("%s%v", cachePcmHpcCenterIdPrefix, primary) | |||||
| } | |||||
| func (m *defaultHpcCenterModel) queryPrimary(ctx context.Context, conn sqlx.SqlConn, v, primary interface{}) error { | |||||
| query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", hpcCenterRows, m.table) | |||||
| return conn.QueryRowCtx(ctx, v, query, primary) | |||||
| } | |||||
| func (m *defaultHpcCenterModel) tableName() string { | |||||
| return m.table | |||||
| } | |||||
| @@ -8,8 +8,8 @@ ListenOn: 127.0.0.1:2001 | |||||
| ClusterUrl: "https://api01.hpccube.com:65106/hpc/openapi/v2/cluster" | ClusterUrl: "https://api01.hpccube.com:65106/hpc/openapi/v2/cluster" | ||||
| TokenUrl: "https://api01.hpccube.com:65102/ac/openapi/v2/tokens" | TokenUrl: "https://api01.hpccube.com:65102/ac/openapi/v2/tokens" | ||||
| StateUrl: "https://api01.hpccube.com:65102/ac/openapi/v2/tokens/state" | StateUrl: "https://api01.hpccube.com:65102/ac/openapi/v2/tokens/state" | ||||
| User: "zhijiang" | |||||
| Password: "111111a" | |||||
| OrgId: "313ae32df03bc116255e6808949fcf57" | |||||
| User: "" | |||||
| Password: "" | |||||
| OrgId: "" | |||||
| Layout: "2006-01-02 15:04:05" | Layout: "2006-01-02 15:04:05" | ||||
| EndPoint: https://api01.hpccube.com:65106 | EndPoint: https://api01.hpccube.com:65106 | ||||
| @@ -10,7 +10,7 @@ import ( | |||||
| "github.com/zeromicro/go-zero/rest" | "github.com/zeromicro/go-zero/rest" | ||||
| ) | ) | ||||
| var configFile = flag.String("f", "adaptor/PCM-HPC/PCM-HPC-CORE/api/etc/hpccore.yaml", "the config file") | |||||
| var configFile = flag.String("f", "adaptor/PCM-HPC/PCM-HPC-CORE/api/etc/hpc-core-api-template.yaml", "the config file") | |||||
| func main() { | func main() { | ||||
| flag.Parse() | flag.Parse() | ||||
| @@ -28,4 +28,4 @@ THRpcConf: | |||||
| Key: hpcth.rpc | Key: hpcth.rpc | ||||
| DB: | DB: | ||||
| DataSource: root:uJpLd6u-J?HC1@(106.53.150.192:3306)/pcm | |||||
| DataSource: | |||||
| @@ -19,7 +19,7 @@ import ( | |||||
| "google.golang.org/grpc/reflection" | "google.golang.org/grpc/reflection" | ||||
| ) | ) | ||||
| var configFile = flag.String("f", "adaptor/PCM-HPC/PCM-HPC-CORE/rpc/etc/pcmhpccore.yaml", "the config file") | |||||
| var configFile = flag.String("f", "adaptor/PCM-HPC/PCM-HPC-CORE/rpc/etc/hpc-core-rpc-template.yaml", "the config file") | |||||
| func main() { | func main() { | ||||
| flag.Parse() | flag.Parse() | ||||
| @@ -0,0 +1,6 @@ | |||||
| Name: hpcth.rpc | |||||
| ListenOn: 0.0.0.0:8881 | |||||
| Etcd: | |||||
| Hosts: | |||||
| - localhost:2379 | |||||
| Key: hpcth.rpc | |||||
| @@ -1,2 +0,0 @@ | |||||
| Name: hpcth.rpc | |||||
| ListenOn: 0.0.0.0:2002 | |||||
| @@ -16,7 +16,7 @@ import ( | |||||
| "google.golang.org/grpc/reflection" | "google.golang.org/grpc/reflection" | ||||
| ) | ) | ||||
| var configFile = flag.String("f", "adaptor/PCM-HPC/PCM-TH/rpc/etc/hpcth.yaml", "the config file") | |||||
| var configFile = flag.String("f", "adaptor/PCM-HPC/PCM-TH/rpc/etc/hpc-th-template.yaml", "the config file") | |||||
| func main() { | func main() { | ||||
| flag.Parse() | flag.Parse() | ||||
| @@ -3,6 +3,7 @@ module PCM | |||||
| go 1.19 | go 1.19 | ||||
| require ( | require ( | ||||
| github.com/Masterminds/squirrel v1.5.4 | |||||
| github.com/bitly/go-simplejson v0.5.0 | github.com/bitly/go-simplejson v0.5.0 | ||||
| github.com/go-redis/redis/v8 v8.11.5 | github.com/go-redis/redis/v8 v8.11.5 | ||||
| github.com/go-resty/resty/v2 v2.7.0 | github.com/go-resty/resty/v2 v2.7.0 | ||||
| @@ -57,6 +58,8 @@ require ( | |||||
| github.com/josharian/intern v1.0.0 // indirect | github.com/josharian/intern v1.0.0 // indirect | ||||
| github.com/json-iterator/go v1.1.12 // indirect | github.com/json-iterator/go v1.1.12 // indirect | ||||
| github.com/klauspost/compress v1.15.15 // indirect | github.com/klauspost/compress v1.15.15 // indirect | ||||
| github.com/lann/builder v0.0.0-20180802200727-47ae307949d0 // indirect | |||||
| github.com/lann/ps v0.0.0-20150810152359-62de8c46ede0 // indirect | |||||
| github.com/mailru/easyjson v0.7.6 // indirect | github.com/mailru/easyjson v0.7.6 // indirect | ||||
| github.com/mattn/go-colorable v0.1.13 // indirect | github.com/mattn/go-colorable v0.1.13 // indirect | ||||
| github.com/mattn/go-isatty v0.0.17 // indirect | github.com/mattn/go-isatty v0.0.17 // indirect | ||||
| @@ -373,6 +373,8 @@ github.com/ClickHouse/clickhouse-go v1.5.4/go.mod h1:EaI/sW7Azgz9UATzd5ZdZHRUhHg | |||||
| github.com/ClickHouse/clickhouse-go/v2 v2.0.14/go.mod h1:iq2DUGgpA4BBki2CVwrF8x43zqBjdgHtbexkFkh5a6M= | github.com/ClickHouse/clickhouse-go/v2 v2.0.14/go.mod h1:iq2DUGgpA4BBki2CVwrF8x43zqBjdgHtbexkFkh5a6M= | ||||
| github.com/DATA-DOG/go-sqlmock v1.5.0 h1:Shsta01QNfFxHCfpW6YH2STWB0MudeXXEWMr20OEh60= | github.com/DATA-DOG/go-sqlmock v1.5.0 h1:Shsta01QNfFxHCfpW6YH2STWB0MudeXXEWMr20OEh60= | ||||
| github.com/DATA-DOG/go-sqlmock v1.5.0/go.mod h1:f/Ixk793poVmq4qj/V1dPUg2JEAKC73Q5eFN3EC/SaM= | github.com/DATA-DOG/go-sqlmock v1.5.0/go.mod h1:f/Ixk793poVmq4qj/V1dPUg2JEAKC73Q5eFN3EC/SaM= | ||||
| github.com/Masterminds/squirrel v1.5.4 h1:uUcX/aBc8O7Fg9kaISIUsHXdKuqehiXAMQTYX8afzqM= | |||||
| github.com/Masterminds/squirrel v1.5.4/go.mod h1:NNaOrjSoIDfDA40n7sr2tPNZRfjzjA400rg+riTZj10= | |||||
| github.com/NYTimes/gziphandler v0.0.0-20170623195520-56545f4a5d46/go.mod h1:3wb06e3pkSAbeQ52E9H9iFoQsEEwGN64994WTCIhntQ= | github.com/NYTimes/gziphandler v0.0.0-20170623195520-56545f4a5d46/go.mod h1:3wb06e3pkSAbeQ52E9H9iFoQsEEwGN64994WTCIhntQ= | ||||
| github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= | github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= | ||||
| github.com/PuerkitoBio/purell v1.1.1/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0= | github.com/PuerkitoBio/purell v1.1.1/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0= | ||||
| @@ -697,6 +699,10 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= | |||||
| github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= | github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= | ||||
| github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= | github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= | ||||
| github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= | github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= | ||||
| github.com/lann/builder v0.0.0-20180802200727-47ae307949d0 h1:SOEGU9fKiNWd/HOJuq6+3iTQz8KNCLtVX6idSoTLdUw= | |||||
| github.com/lann/builder v0.0.0-20180802200727-47ae307949d0/go.mod h1:dXGbAdH5GtBTC4WfIxhKZfyBF/HBFgRZSWwZ9g/He9o= | |||||
| github.com/lann/ps v0.0.0-20150810152359-62de8c46ede0 h1:P6pPBnrTSX3DEVR4fDembhRWSsG5rVo6hYhAB/ADZrk= | |||||
| github.com/lann/ps v0.0.0-20150810152359-62de8c46ede0/go.mod h1:vmVJ0l/dxyfGW6FmdpVm2joNMFikkuWg0EoCKLGUMNw= | |||||
| github.com/lib/pq v1.0.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= | github.com/lib/pq v1.0.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= | ||||
| github.com/lib/pq v1.2.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= | github.com/lib/pq v1.2.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= | ||||
| github.com/lib/pq v1.10.7 h1:p7ZhMD+KsSRozJr34udlUrhboJwWAgCg34+/ZZNvZZw= | github.com/lib/pq v1.10.7 h1:p7ZhMD+KsSRozJr34udlUrhboJwWAgCg34+/ZZNvZZw= | ||||