131 lines
3.7 KiB
Go
131 lines
3.7 KiB
Go
package corrpc
|
||
|
||
import (
|
||
context "context"
|
||
|
||
"gitlink.org.cn/cloudream/jcs-pub/common/pkgs/rpc"
|
||
jcstypes "gitlink.org.cn/cloudream/jcs-pub/common/types"
|
||
)
|
||
|
||
type HubService interface {
|
||
GetHubConfig(ctx context.Context, msg *GetHubConfig) (*GetHubConfigResp, *rpc.CodeError)
|
||
|
||
GetHubs(ctx context.Context, msg *GetHubs) (*GetHubsResp, *rpc.CodeError)
|
||
|
||
GetHubConnectivities(ctx context.Context, msg *GetHubConnectivities) (*GetHubConnectivitiesResp, *rpc.CodeError)
|
||
|
||
ReportHubConnectivity(ctx context.Context, msg *ReportHubConnectivity) (*ReportHubConnectivityResp, *rpc.CodeError)
|
||
}
|
||
|
||
type GetHubConfig struct {
|
||
HubID jcstypes.HubID `json:"hubID"`
|
||
}
|
||
type GetHubConfigResp struct {
|
||
Hub jcstypes.Hub `json:"hub"`
|
||
}
|
||
|
||
func ReqGetHubConfig(hubID jcstypes.HubID) *GetHubConfig {
|
||
return &GetHubConfig{
|
||
HubID: hubID,
|
||
}
|
||
}
|
||
func RespGetHubConfig(hub jcstypes.Hub) *GetHubConfigResp {
|
||
return &GetHubConfigResp{
|
||
Hub: hub,
|
||
}
|
||
}
|
||
func (c *Client) GetHubConfig(ctx context.Context, msg *GetHubConfig) (*GetHubConfigResp, *rpc.CodeError) {
|
||
if c.fusedErr != nil {
|
||
return nil, c.fusedErr
|
||
}
|
||
return rpc.UnaryClient[*GetHubConfigResp](c.cli.GetHubConfig, ctx, msg)
|
||
}
|
||
func (s *Server) GetHubConfig(ctx context.Context, req *rpc.Request) (*rpc.Response, error) {
|
||
return rpc.UnaryServer(s.svrImpl.GetHubConfig, ctx, req)
|
||
}
|
||
|
||
// 获取指定节点的信息。如果HubIDs为nil,则返回所有Hub
|
||
type GetHubs struct {
|
||
HubIDs []jcstypes.HubID `json:"hubIDs"`
|
||
}
|
||
type GetHubsResp struct {
|
||
Hubs []*jcstypes.Hub `json:"hubs"`
|
||
}
|
||
|
||
var _ = TokenAuth(Coordinator_GetHubs_FullMethodName)
|
||
|
||
func NewGetHubs(hubIDs []jcstypes.HubID) *GetHubs {
|
||
return &GetHubs{
|
||
HubIDs: hubIDs,
|
||
}
|
||
}
|
||
func NewGetHubsResp(hubs []*jcstypes.Hub) *GetHubsResp {
|
||
return &GetHubsResp{
|
||
Hubs: hubs,
|
||
}
|
||
}
|
||
func (r *GetHubsResp) GetHub(id jcstypes.HubID) *jcstypes.Hub {
|
||
for _, n := range r.Hubs {
|
||
if n.HubID == id {
|
||
return n
|
||
}
|
||
}
|
||
|
||
return nil
|
||
}
|
||
func (c *Client) GetHubs(ctx context.Context, msg *GetHubs) (*GetHubsResp, *rpc.CodeError) {
|
||
if c.fusedErr != nil {
|
||
return nil, c.fusedErr
|
||
}
|
||
return rpc.UnaryClient[*GetHubsResp](c.cli.GetHubs, ctx, msg)
|
||
}
|
||
func (s *Server) GetHubs(ctx context.Context, req *rpc.Request) (*rpc.Response, error) {
|
||
return rpc.UnaryServer(s.svrImpl.GetHubs, ctx, req)
|
||
}
|
||
|
||
// 获取节点连通性信息
|
||
|
||
type GetHubConnectivities struct {
|
||
HubIDs []jcstypes.HubID `json:"hubIDs"`
|
||
}
|
||
type GetHubConnectivitiesResp struct {
|
||
Connectivities []jcstypes.HubConnectivity `json:"hubs"`
|
||
}
|
||
|
||
func ReqGetHubConnectivities(hubIDs []jcstypes.HubID) *GetHubConnectivities {
|
||
return &GetHubConnectivities{
|
||
HubIDs: hubIDs,
|
||
}
|
||
}
|
||
func RespGetHubConnectivities(cons []jcstypes.HubConnectivity) *GetHubConnectivitiesResp {
|
||
return &GetHubConnectivitiesResp{
|
||
Connectivities: cons,
|
||
}
|
||
}
|
||
func (c *Client) GetHubConnectivities(ctx context.Context, msg *GetHubConnectivities) (*GetHubConnectivitiesResp, *rpc.CodeError) {
|
||
if c.fusedErr != nil {
|
||
return nil, c.fusedErr
|
||
}
|
||
return rpc.UnaryClient[*GetHubConnectivitiesResp](c.cli.GetHubConnectivities, ctx, msg)
|
||
}
|
||
func (s *Server) GetHubConnectivities(ctx context.Context, req *rpc.Request) (*rpc.Response, error) {
|
||
return rpc.UnaryServer(s.svrImpl.GetHubConnectivities, ctx, req)
|
||
}
|
||
|
||
// 上报节点连通性信息
|
||
type ReportHubConnectivity struct {
|
||
Connecttivities []jcstypes.HubConnectivity
|
||
}
|
||
type ReportHubConnectivityResp struct {
|
||
}
|
||
|
||
func (c *Client) ReportHubConnectivity(ctx context.Context, msg *ReportHubConnectivity) (*ReportHubConnectivityResp, *rpc.CodeError) {
|
||
if c.fusedErr != nil {
|
||
return nil, c.fusedErr
|
||
}
|
||
return rpc.UnaryClient[*ReportHubConnectivityResp](c.cli.ReportHubConnectivity, ctx, msg)
|
||
}
|
||
func (s *Server) ReportHubConnectivity(ctx context.Context, req *rpc.Request) (*rpc.Response, error) {
|
||
return rpc.UnaryServer(s.svrImpl.ReportHubConnectivity, ctx, req)
|
||
}
|