api新增集群注册接口

Signed-off-by: devad <cossjie@foxmail.com>

Former-commit-id: 9c8ef50b78faca3795d6b34ca5fa232d6e304f95
This commit is contained in:
devad 2023-11-23 18:36:41 +08:00
parent e170538d86
commit 48ff9d1d4f
12 changed files with 320 additions and 2 deletions

View File

@ -17,6 +17,43 @@ type ControllerMetricsReq {
End string `form:"end"`
}
type (
RegisterClusterReq {
Name string `json:"name"` // 名称
Address string `json:"address"` // 地址
token string `json:"token"` // 数算集群token
Type string `json:"type"` // 参与者类型:CLOUD-数算集群;AI-智算集群HPC-超算集群
ParticipantId int64 `json:"name"` // participant id
MetricsUrl string `json:"metricsUrl"` //监控url
}
ListCloudResp{
Code string `json:"code"`
Msg string `json:"msg"`
Data []CloudResp `json:"data"`
}
ParticipantResp {
Id int64 `json:"id"` // id
Name string `json:"name"` // 名称
Address string `json:"address"` // 地址
token string `json:"token"` // 数算集群token
Type string `json:"type"` // 参与者类型:CLOUD-数算集群;AI-智算集群HPC-超算集群
ParticipantId int64 `json:"name"` // participant id
MetricsUrl string `json:"metricsUrl"` //监控url
}
CloudResp {
Code string `json:"code"`
Msg string `json:"msg"`
Data string `json:"data"`
}
UpdateTenantReq{
TenantName string `json:"nsID"`
clusters []string `json:"clusters"`
}
)
type ControllerMetricsResp {
Data interface{} `json:"data"`

View File

@ -145,6 +145,22 @@ service pcm {
@doc "控制器监控"
@handler controllerMetricsHandler
get /cloud/controller/Metrics (ControllerMetricsReq) returns (ControllerMetricsResp)
@doc "数算集群注册"
@handler registerClusterHandler
post /cloud/registerCluster (RegisterClusterReq) returns (CloudResp)
@doc "数算集群删除"
@handler deleteClusterHandler
post /cloud/deleteCluster (RegisterClusterReq) returns (CloudResp)
@doc "数算集群查询"
@handler listCloudClusterHandler
get /cloud/listCluster returns (ListCloudResp)
@doc "触发租户更新"
@handler noticeTenantHandler
get /cloud/noticeTenant returns (CloudResp)
}
//智算二级接口

View File

@ -0,0 +1,24 @@
package cloud
import (
"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"
"gitlink.org.cn/jcce-pcm/utils/result"
"net/http"
)
func DeleteClusterHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.RegisterClusterReq
if err := httpx.Parse(r, &req); err != nil {
result.ParamErrorResult(r, w, err)
return
}
l := cloud.NewDeleteClusterLogic(r.Context(), svcCtx)
resp, err := l.DeleteCluster(&req)
result.HttpResult(r, w, resp, err)
}
}

View File

@ -0,0 +1,24 @@
package cloud
import (
"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"
"gitlink.org.cn/jcce-pcm/utils/result"
"net/http"
)
func ListCloudClusterHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.ListClusterReq
if err := httpx.Parse(r, &req); err != nil {
result.ParamErrorResult(r, w, err)
return
}
l := cloud.NewListCloudClusterLogic(r.Context(), svcCtx)
resp, err := l.ListCloudCluster(&req)
result.HttpResult(r, w, resp, err)
}
}

View File

@ -0,0 +1,17 @@
package cloud
import (
"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/utils/result"
"net/http"
)
func NoticeTenantHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
l := cloud.NewNoticeTenantLogic(r.Context(), svcCtx)
resp, err := l.NoticeTenant()
result.HttpResult(r, w, resp, err)
}
}

View File

@ -0,0 +1,24 @@
package cloud
import (
"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"
"gitlink.org.cn/jcce-pcm/utils/result"
"net/http"
)
func RegisterClusterHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.RegisterClusterReq
if err := httpx.Parse(r, &req); err != nil {
result.ParamErrorResult(r, w, err)
return
}
l := cloud.NewRegisterClusterLogic(r.Context(), svcCtx)
resp, err := l.RegisterCluster(&req)
result.HttpResult(r, w, resp, err)
}
}

View File

@ -167,6 +167,26 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
Path: "/cloud/controller/Metrics",
Handler: cloud.ControllerMetricsHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/cloud/registerCluster",
Handler: cloud.RegisterClusterHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/cloud/deleteCluster",
Handler: cloud.DeleteClusterHandler(serverCtx),
},
{
Method: http.MethodGet,
Path: "/cloud/listCluster",
Handler: cloud.ListCloudClusterHandler(serverCtx),
},
{
Method: http.MethodGet,
Path: "/cloud/noticeTenant",
Handler: cloud.NoticeTenantHandler(serverCtx),
},
},
rest.WithPrefix("/pcm/v1"),
)

View File

@ -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 DeleteClusterLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewDeleteClusterLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeleteClusterLogic {
return &DeleteClusterLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *DeleteClusterLogic) DeleteCluster(req *types.RegisterClusterReq) (resp *types.CloudResp, err error) {
// todo: add your logic here and delete this line
return
}

View File

@ -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 ListCloudClusterLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewListCloudClusterLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ListCloudClusterLogic {
return &ListCloudClusterLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *ListCloudClusterLogic) ListCloudCluster(req *types.ListClusterReq) (resp *types.CloudListResp, err error) {
// todo: add your logic here and delete this line
return
}

View File

@ -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 NoticeTenantLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewNoticeTenantLogic(ctx context.Context, svcCtx *svc.ServiceContext) *NoticeTenantLogic {
return &NoticeTenantLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *NoticeTenantLogic) NoticeTenant() (resp *types.CloudResp, err error) {
// todo: add your logic here and delete this line
return
}

View File

@ -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 RegisterClusterLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewRegisterClusterLogic(ctx context.Context, svcCtx *svc.ServiceContext) *RegisterClusterLogic {
return &RegisterClusterLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *RegisterClusterLogic) RegisterCluster(req *types.RegisterClusterReq) (resp *types.CloudResp, err error) {
// todo: add your logic here and delete this line
return
}

View File

@ -3336,6 +3336,42 @@ type ControllerMetricsReq struct {
End string `form:"end"`
}
type RegisterClusterReq struct {
Name string `json:"name"` // 名称
Address string `json:"address"` // 地址
Token string `json:"token"` // 数算集群token
Type string `json:"type"` // 参与者类型:CLOUD-数算集群;AI-智算集群HPC-超算集群
ParticipantId int64 `json:"name"` // participant id
MetricsUrl string `json:"metricsUrl"` //监控url
}
type ListCloudResp struct {
Code string `json:"code"`
Msg string `json:"msg"`
Data []CloudResp `json:"data"`
}
type ParticipantResp struct {
Id int64 `json:"id"` // id
Name string `json:"name"` // 名称
Address string `json:"address"` // 地址
Token string `json:"token"` // 数算集群token
Type string `json:"type"` // 参与者类型:CLOUD-数算集群;AI-智算集群HPC-超算集群
ParticipantId int64 `json:"name"` // participant id
MetricsUrl string `json:"metricsUrl"` //监控url
}
type CloudResp struct {
Code string `json:"code"`
Msg string `json:"msg"`
Data string `json:"data"`
}
type UpdateTenantReq struct {
TenantName string `json:"nsID"`
Clusters []string `json:"clusters"`
}
type ControllerMetricsResp struct {
Data interface{} `json:"data"`
}