Obtain cluster list information according to participantId
Former-commit-id: 5af0d344affc9e7e7421eae46fe60d4636487d92
This commit is contained in:
parent
cd56cd79d0
commit
356d4e6176
|
@ -7,6 +7,21 @@ info(
|
||||||
email: ""
|
email: ""
|
||||||
)
|
)
|
||||||
/******************find datasetList start*************************/
|
/******************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 {
|
type ControllerMetricsReq {
|
||||||
Metrics []string `form:"metrics"`
|
Metrics []string `form:"metrics"`
|
||||||
|
|
|
@ -174,7 +174,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"`
|
||||||
|
@ -237,27 +237,27 @@ type (
|
||||||
platform string `json:"platform,optional"`
|
platform string `json:"platform,optional"`
|
||||||
}
|
}
|
||||||
ServerCommit {
|
ServerCommit {
|
||||||
allCardRunTime string `json:"allCardRunTime"`
|
allCardRunTime string `json:"allCardRunTime"`
|
||||||
flavorRef string `json:"flavorRef,optional"`
|
flavorRef string `json:"flavorRef,optional"`
|
||||||
name string `json:"name,optional"`
|
name string `json:"name,optional"`
|
||||||
imageRef string `json:"imageRef,optional"`
|
imageRef string `json:"imageRef,optional"`
|
||||||
accessIPv4 string `json:"accessIPv4,optional"`
|
accessIPv4 string `json:"accessIPv4,optional"`
|
||||||
accessIPv6 string `json:"accessIPv6,optional"`
|
accessIPv6 string `json:"accessIPv6,optional"`
|
||||||
adminPass string `json:"adminPass,optional"`
|
adminPass string `json:"adminPass,optional"`
|
||||||
availability_zone string `json:"availability_zone,optional"`
|
availability_zone string `json:"availability_zone,optional"`
|
||||||
key_name string `json:"key_name,optional"`
|
key_name string `json:"key_name,optional"`
|
||||||
hostname string `json:"hostname,optional"`
|
hostname string `json:"hostname,optional"`
|
||||||
host string `json:"host,optional"`
|
host string `json:"host,optional"`
|
||||||
networks []Networks `json:"networks,optional"`
|
networks []Networks `json:"networks,optional"`
|
||||||
}
|
}
|
||||||
Networks {
|
Networks {
|
||||||
uuid string `json:"uuid,optional"`
|
uuid string `json:"uuid,optional"`
|
||||||
port string `json:"port,optional"`
|
port string `json:"port,optional"`
|
||||||
fixed_ip string `json:"fixed_ip,optional"`
|
fixed_ip string `json:"fixed_ip,optional"`
|
||||||
tag string `json:"tag,optional"`
|
tag string `json:"tag,optional"`
|
||||||
}
|
}
|
||||||
Block_device_mapping_v2Commit {
|
Block_device_mapping_v2Commit {
|
||||||
uuid string `json:"uuid,optional"`
|
uuid string `json:"uuid,optional"`
|
||||||
}
|
}
|
||||||
commitVmTaskResp {
|
commitVmTaskResp {
|
||||||
|
|
||||||
|
|
|
@ -169,6 +169,10 @@ 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 participantId"
|
||||||
|
@handler getClusterListHandler
|
||||||
|
get /core/clusterList (getClusterListReq) returns (getClusterListResp)
|
||||||
}
|
}
|
||||||
|
|
||||||
//智算二级接口
|
//智算二级接口
|
||||||
|
|
|
@ -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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -198,6 +198,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)
|
||||||
|
|
|
@ -3463,6 +3463,22 @@ type ShowNodeDetailsResp struct {
|
||||||
ErrorMsg string `json:"errorMsg,omitempty"`
|
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 {
|
type ControllerMetricsReq struct {
|
||||||
Metrics []string `form:"metrics"`
|
Metrics []string `form:"metrics"`
|
||||||
ParticipantId int64 `form:"participantId"`
|
ParticipantId int64 `form:"participantId"`
|
||||||
|
|
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