Center Resources top3
Former-commit-id: a0a1dc23afef71e8a659c4c37467b49e22ab1f31
This commit is contained in:
commit
0435a6c5aa
|
@ -8,6 +8,7 @@ info(
|
||||||
)
|
)
|
||||||
/******************find datasetList start*************************/
|
/******************find datasetList start*************************/
|
||||||
|
|
||||||
|
|
||||||
type ControllerMetricsReq {
|
type ControllerMetricsReq {
|
||||||
Metrics []string `form:"metrics"`
|
Metrics []string `form:"metrics"`
|
||||||
ParticipantId int64 `form:"participantId"`
|
ParticipantId int64 `form:"participantId"`
|
||||||
|
|
|
@ -154,6 +154,32 @@ type (
|
||||||
SoftStackSum int64 `json:"softStackSum"`
|
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 (
|
type (
|
||||||
listRegionResp {
|
listRegionResp {
|
||||||
|
@ -174,7 +200,7 @@ type deleteTaskReq {
|
||||||
Id int64 `path:"id"`
|
Id int64 `path:"id"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type commitTaskReq{
|
type commitTaskReq {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
NsID string `json:"nsID"`
|
NsID string `json:"nsID"`
|
||||||
Replicas int64 `json:"replicas,optional"`
|
Replicas int64 `json:"replicas,optional"`
|
||||||
|
|
|
@ -115,6 +115,10 @@ service pcm {
|
||||||
@doc "获取hashcat"
|
@doc "获取hashcat"
|
||||||
@handler getHashcatHandler
|
@handler getHashcatHandler
|
||||||
get /core/getHashcat/:crackTaskId (getHashcatHandlerReq) returns (getHashcatHandlerResp)
|
get /core/getHashcat/:crackTaskId (getHashcatHandlerReq) returns (getHashcatHandlerResp)
|
||||||
|
|
||||||
|
@doc "Center Resources top3"
|
||||||
|
@handler centerResourcesHandler
|
||||||
|
get /core/centerResources returns (centerResourcesResp)
|
||||||
}
|
}
|
||||||
|
|
||||||
//hpc二级接口
|
//hpc二级接口
|
||||||
|
@ -169,6 +173,11 @@ service pcm {
|
||||||
@doc "租户更新"
|
@doc "租户更新"
|
||||||
@handler updateTenantHandler
|
@handler updateTenantHandler
|
||||||
post /cloud/updateTenant (UpdateTenantReq) returns (CloudResp)
|
post /cloud/updateTenant (UpdateTenantReq) returns (CloudResp)
|
||||||
|
|
||||||
|
@doc "Obtain cluster list information according to adapterId"
|
||||||
|
@handler getClusterListHandler
|
||||||
|
get /core/clusterList (getClusterListReq) returns (getClusterListResp)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//智算二级接口
|
//智算二级接口
|
||||||
|
|
|
@ -16,7 +16,6 @@ package config
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
"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/core/stores/redis"
|
||||||
"github.com/zeromicro/go-zero/rest"
|
"github.com/zeromicro/go-zero/rest"
|
||||||
"github.com/zeromicro/go-zero/zrpc"
|
"github.com/zeromicro/go-zero/zrpc"
|
||||||
|
@ -28,7 +27,6 @@ type Config struct {
|
||||||
DataSource string
|
DataSource string
|
||||||
}
|
}
|
||||||
Redis redis.RedisConf
|
Redis redis.RedisConf
|
||||||
Cache cache.CacheConf
|
|
||||||
LogConf logx.LogConf
|
LogConf logx.LogConf
|
||||||
K8sNativeConf zrpc.RpcClientConf
|
K8sNativeConf zrpc.RpcClientConf
|
||||||
ACRpcConf zrpc.RpcClientConf
|
ACRpcConf zrpc.RpcClientConf
|
||||||
|
|
|
@ -0,0 +1,28 @@
|
||||||
|
package cloud
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/rest/httpx"
|
||||||
|
"gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/logic/cloud"
|
||||||
|
"gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/svc"
|
||||||
|
"gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/types"
|
||||||
|
)
|
||||||
|
|
||||||
|
func GetClusterListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
var req types.GetClusterListReq
|
||||||
|
if err := httpx.Parse(r, &req); err != nil {
|
||||||
|
httpx.ErrorCtx(r.Context(), w, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
l := cloud.NewGetClusterListLogic(r.Context(), svcCtx)
|
||||||
|
resp, err := l.GetClusterList(&req)
|
||||||
|
if err != nil {
|
||||||
|
httpx.ErrorCtx(r.Context(), w, err)
|
||||||
|
} else {
|
||||||
|
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -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)
|
||||||
|
}
|
||||||
|
}
|
|
@ -137,6 +137,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
||||||
Path: "/core/getHashcat/:crackTaskId",
|
Path: "/core/getHashcat/:crackTaskId",
|
||||||
Handler: core.GetHashcatHandler(serverCtx),
|
Handler: core.GetHashcatHandler(serverCtx),
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Method: http.MethodGet,
|
||||||
|
Path: "/core/centerResources",
|
||||||
|
Handler: core.CenterResourcesHandler(serverCtx),
|
||||||
|
},
|
||||||
},
|
},
|
||||||
rest.WithPrefix("/pcm/v1"),
|
rest.WithPrefix("/pcm/v1"),
|
||||||
)
|
)
|
||||||
|
@ -199,6 +204,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
||||||
Path: "/cloud/updateTenant",
|
Path: "/cloud/updateTenant",
|
||||||
Handler: cloud.UpdateTenantHandler(serverCtx),
|
Handler: cloud.UpdateTenantHandler(serverCtx),
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Method: http.MethodGet,
|
||||||
|
Path: "/core/clusterList",
|
||||||
|
Handler: cloud.GetClusterListHandler(serverCtx),
|
||||||
|
},
|
||||||
},
|
},
|
||||||
rest.WithPrefix("/pcm/v1"),
|
rest.WithPrefix("/pcm/v1"),
|
||||||
)
|
)
|
||||||
|
|
|
@ -0,0 +1,30 @@
|
||||||
|
package cloud
|
||||||
|
|
||||||
|
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 GetClusterListLogic struct {
|
||||||
|
logx.Logger
|
||||||
|
ctx context.Context
|
||||||
|
svcCtx *svc.ServiceContext
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewGetClusterListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetClusterListLogic {
|
||||||
|
return &GetClusterListLogic{
|
||||||
|
Logger: logx.WithContext(ctx),
|
||||||
|
ctx: ctx,
|
||||||
|
svcCtx: svcCtx,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *GetClusterListLogic) GetClusterList(req *types.GetClusterListReq) (resp *types.GetClusterListResp, err error) {
|
||||||
|
resp = &types.GetClusterListResp{}
|
||||||
|
//clusters := []models.ScParticipantPhyInfo{}
|
||||||
|
l.svcCtx.DbEngin.Find(resp.Clusters).Where("id", req.Id)
|
||||||
|
return resp, nil
|
||||||
|
}
|
|
@ -2,13 +2,11 @@ package cloud
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/svc"
|
||||||
|
"gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/types"
|
||||||
"gitlink.org.cn/jcce-pcm/pcm-coordinator/pkg/models"
|
"gitlink.org.cn/jcce-pcm/pcm-coordinator/pkg/models"
|
||||||
"gitlink.org.cn/jcce-pcm/pcm-coordinator/pkg/utils"
|
"gitlink.org.cn/jcce-pcm/pcm-coordinator/pkg/utils"
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
|
||||||
|
|
||||||
"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"
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
)
|
)
|
||||||
|
@ -39,31 +37,30 @@ func (l *RegisterClusterLogic) RegisterCluster(req *types.RegisterClusterReq) (*
|
||||||
return &resp, nil
|
return &resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
participant := models.ScParticipantPhyInfo{}
|
participant := models.ScParticipantPhyInfo{
|
||||||
participant.Token = req.Token
|
Token: req.Token,
|
||||||
participant.Name = req.Name
|
Name: req.Name,
|
||||||
participant.Address = req.Address
|
Address: req.Address,
|
||||||
participant.Type = "CLOUD"
|
Type: "CLOUD",
|
||||||
participant.Id = utils.GenSnowflakeID()
|
Id: utils.GenSnowflakeID(),
|
||||||
participant.MetricsUrl = req.MetricsUrl
|
MetricsUrl: req.MetricsUrl,
|
||||||
participant.CreatedTime = time.Now()
|
}
|
||||||
participant.UpdatedTime = time.Now()
|
|
||||||
|
|
||||||
labelInfo := models.ScParticipantLabelInfo{}
|
|
||||||
labelInfo.Id = utils.GenSnowflakeID()
|
|
||||||
labelInfo.ParticipantId = participant.Id
|
|
||||||
labelInfo.CreatedTime = time.Now()
|
|
||||||
labelInfo.Key = "cloud"
|
|
||||||
labelInfo.Value = "sealos"
|
|
||||||
|
|
||||||
tx := l.svcCtx.DbEngin.Create(&participant)
|
tx := l.svcCtx.DbEngin.Create(&participant)
|
||||||
if tx.Error != nil {
|
if tx.Error != nil {
|
||||||
return nil, tx.Error
|
return nil, tx.Error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
labelInfo := models.ScParticipantLabelInfo{
|
||||||
|
Id: utils.GenSnowflakeID(),
|
||||||
|
ParticipantId: participant.Id,
|
||||||
|
Key: "cloud",
|
||||||
|
Value: "sealos",
|
||||||
|
}
|
||||||
tx2 := l.svcCtx.DbEngin.Create(&labelInfo)
|
tx2 := l.svcCtx.DbEngin.Create(&labelInfo)
|
||||||
if tx2.Error != nil {
|
if tx2.Error != nil {
|
||||||
return nil, tx.Error
|
return nil, tx.Error
|
||||||
}
|
}
|
||||||
|
|
||||||
resp.Code = string(200)
|
resp.Code = string(200)
|
||||||
resp.Msg = "success"
|
resp.Msg = "success"
|
||||||
resp.Data = "participantId:" + strconv.FormatInt(participant.Id, 10)
|
resp.Data = "participantId:" + strconv.FormatInt(participant.Id, 10)
|
||||||
|
|
|
@ -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
|
||||||
|
}
|
|
@ -138,6 +138,33 @@ type RegionNum struct {
|
||||||
SoftStackSum int64 `json:"softStackSum"`
|
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 {
|
type ListRegionResp struct {
|
||||||
Code int32 `json:"code"`
|
Code int32 `json:"code"`
|
||||||
Msg string `json:"msg"`
|
Msg string `json:"msg"`
|
||||||
|
|
4
go.mod
4
go.mod
|
@ -1,6 +1,8 @@
|
||||||
module gitlink.org.cn/jcce-pcm/pcm-coordinator
|
module gitlink.org.cn/jcce-pcm/pcm-coordinator
|
||||||
|
|
||||||
go 1.20
|
go 1.21
|
||||||
|
|
||||||
|
toolchain go1.21.0
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/JCCE-nudt/zero-contrib/zrpc/registry/nacos v0.0.0-20230419021610-13bbc83fbc3c
|
github.com/JCCE-nudt/zero-contrib/zrpc/registry/nacos v0.0.0-20230419021610-13bbc83fbc3c
|
||||||
|
|
Loading…
Reference in New Issue