diff --git a/api/desc/cloud/pcm-cloud.api b/api/desc/cloud/pcm-cloud.api index 8fdb4274..de7b6b92 100644 --- a/api/desc/cloud/pcm-cloud.api +++ b/api/desc/cloud/pcm-cloud.api @@ -7,21 +7,7 @@ info( email: "" ) /******************find datasetList start*************************/ -type ( - getClusterListReq { - Id int64 `form:"id"` - } - getClusterListResp { - clusters []ClusterInfo `json:"clusters"` - } - ClusterInfo { - Id int64 `json:"id"` - Name string `json:"name"` - Address string `json:"address"` - Token string `json:"token"` - MetricsUrl string `json:"metricsUrl"` - } -) + type ControllerMetricsReq { Metrics []string `form:"metrics"` diff --git a/api/desc/core/pcm-core.api b/api/desc/core/pcm-core.api index fd682238..3aa75ddc 100644 --- a/api/desc/core/pcm-core.api +++ b/api/desc/core/pcm-core.api @@ -154,6 +154,32 @@ type ( SoftStackSum int64 `json:"softStackSum"` } ) +type ( + centerResourcesResp { + CentersIndex []CenterIndex `json:"centersIndex"` + } + CenterIndex{ + name string `json:"name"` + cpu float32 `json:"cpu"` + memory float32 `json:"memory"` + storage float32 `json:"storage"` + } +) +type ( + getClusterListReq { + Id int64 `form:"id"` + } + getClusterListResp { + clusters []ClusterInfo `json:"clusters"` + } + ClusterInfo { + Id int64 `json:"id"` + Name string `json:"name"` + Address string `json:"address"` + Token string `json:"token"` + MetricsUrl string `json:"metricsUrl"` + } +) type ( listRegionResp { diff --git a/api/desc/pcm.api b/api/desc/pcm.api index a54818b1..b5f37900 100644 --- a/api/desc/pcm.api +++ b/api/desc/pcm.api @@ -115,6 +115,10 @@ service pcm { @doc "获取hashcat" @handler getHashcatHandler get /core/getHashcat/:crackTaskId (getHashcatHandlerReq) returns (getHashcatHandlerResp) + + @doc "Center Resources top3" + @handler centerResourcesHandler + get /core/centerResources returns (centerResourcesResp) } //hpc二级接口 @@ -170,9 +174,10 @@ service pcm { @handler updateTenantHandler post /cloud/updateTenant (UpdateTenantReq) returns (CloudResp) - @doc "Obtain cluster list information according to participantId" + @doc "Obtain cluster list information according to adapterId" @handler getClusterListHandler get /core/clusterList (getClusterListReq) returns (getClusterListResp) + } //智算二级接口 diff --git a/api/internal/config/config.go b/api/internal/config/config.go index 7f4b6dee..dee5d7ed 100644 --- a/api/internal/config/config.go +++ b/api/internal/config/config.go @@ -16,7 +16,6 @@ package config import ( "github.com/zeromicro/go-zero/core/logx" - "github.com/zeromicro/go-zero/core/stores/cache" "github.com/zeromicro/go-zero/core/stores/redis" "github.com/zeromicro/go-zero/rest" "github.com/zeromicro/go-zero/zrpc" @@ -28,7 +27,6 @@ type Config struct { DataSource string } Redis redis.RedisConf - Cache cache.CacheConf LogConf logx.LogConf K8sNativeConf zrpc.RpcClientConf ACRpcConf zrpc.RpcClientConf diff --git a/api/internal/handler/core/centerresourceshandler.go b/api/internal/handler/core/centerresourceshandler.go new file mode 100644 index 00000000..f926bd36 --- /dev/null +++ b/api/internal/handler/core/centerresourceshandler.go @@ -0,0 +1,17 @@ +package core + +import ( + "gitlink.org.cn/jcce-pcm/pcm-coordinator/pkg/repository/result" + "net/http" + + "gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/logic/core" + "gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/svc" +) + +func CenterResourcesHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + l := core.NewCenterResourcesLogic(r.Context(), svcCtx) + resp, err := l.CenterResources() + result.HttpResult(r, w, resp, err) + } +} diff --git a/api/internal/handler/routes.go b/api/internal/handler/routes.go index 6294c2c6..3a772257 100644 --- a/api/internal/handler/routes.go +++ b/api/internal/handler/routes.go @@ -136,6 +136,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { Path: "/core/getHashcat/:crackTaskId", Handler: core.GetHashcatHandler(serverCtx), }, + { + Method: http.MethodGet, + Path: "/core/centerResources", + Handler: core.CenterResourcesHandler(serverCtx), + }, }, rest.WithPrefix("/pcm/v1"), ) diff --git a/api/internal/logic/core/centerresourceslogic.go b/api/internal/logic/core/centerresourceslogic.go new file mode 100644 index 00000000..6ec5c601 --- /dev/null +++ b/api/internal/logic/core/centerresourceslogic.go @@ -0,0 +1,51 @@ +package core + +import ( + "context" + + "gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/svc" + "gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/types" + + "github.com/zeromicro/go-zero/core/logx" +) + +type CenterResourcesLogic struct { + logx.Logger + ctx context.Context + svcCtx *svc.ServiceContext +} + +func NewCenterResourcesLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CenterResourcesLogic { + return &CenterResourcesLogic{ + Logger: logx.WithContext(ctx), + ctx: ctx, + svcCtx: svcCtx, + } +} + +func (l *CenterResourcesLogic) CenterResources() (resp *types.CenterResourcesResp, err error) { + // todo: add your logic here and delete this line + centerIndex1 := types.CenterIndex{ + Name: "阿里云", + Cpu: float32(12.33), + Memory: float32(64.55), + Storage: float32(33.90), + } + centerIndex2 := types.CenterIndex{ + Name: "A超算中心", + Cpu: float32(42.36), + Memory: float32(66.55), + Storage: float32(23.231), + } + centerIndex3 := types.CenterIndex{ + Name: "智算中心", + Cpu: float32(78.33), + Memory: float32(36.55), + Storage: float32(88.93), + } + resp = &types.CenterResourcesResp{} + resp.CentersIndex = append(resp.CentersIndex, centerIndex1) + resp.CentersIndex = append(resp.CentersIndex, centerIndex2) + resp.CentersIndex = append(resp.CentersIndex, centerIndex3) + return resp, nil +} diff --git a/api/internal/types/types.go b/api/internal/types/types.go index 76ef5b7d..f06e315e 100644 --- a/api/internal/types/types.go +++ b/api/internal/types/types.go @@ -138,6 +138,33 @@ type RegionNum struct { SoftStackSum int64 `json:"softStackSum"` } +type CenterResourcesResp struct { + CentersIndex []CenterIndex `json:"centersIndex"` +} + +type CenterIndex struct { + Name string `json:"name"` + Cpu float32 `json:"cpu"` + Memory float32 `json:"memory"` + Storage float32 `json:"storage"` +} + +type GetClusterListReq struct { + Id int64 `form:"id"` +} + +type GetClusterListResp struct { + Clusters []ClusterInfo `json:"clusters"` +} + +type ClusterInfo struct { + Id int64 `json:"id"` + Name string `json:"name"` + Address string `json:"address"` + Token string `json:"token"` + MetricsUrl string `json:"metricsUrl"` +} + type ListRegionResp struct { Code int32 `json:"code"` Msg string `json:"msg"` @@ -3463,22 +3490,6 @@ type ShowNodeDetailsResp struct { ErrorMsg string `json:"errorMsg,omitempty"` } -type GetClusterListReq struct { - Id int64 `form:"id"` -} - -type GetClusterListResp struct { - Clusters []ClusterInfo `json:"clusters"` -} - -type ClusterInfo struct { - Id int64 `json:"id"` - Name string `json:"name"` - Address string `json:"address"` - Token string `json:"token"` - MetricsUrl string `json:"metricsUrl"` -} - type ControllerMetricsReq struct { Metrics []string `form:"metrics"` ParticipantId int64 `form:"participantId"`