Ingress psrpc (#1295)

* add ingress psrpc codegen

* use psrpc for ingress

* merge entity/info update psrpc services

* split update/delete ingress methods

* add race helper test

* add race context cancel test

* sync race result with mutex
This commit is contained in:
Paul Wells
2023-01-12 11:00:43 -08:00
committed by GitHub
parent 81fb1c5ef0
commit a052ebd644
16 changed files with 1030 additions and 90 deletions
+227
View File
@@ -0,0 +1,227 @@
// Code generated by protoc-gen-psrpc v0.2.2, DO NOT EDIT.
// source: pkg/service/rpc/ingress.proto
package rpc
import context "context"
import psrpc1 "github.com/livekit/psrpc"
import livekit2 "github.com/livekit/protocol/livekit"
// ================================
// IngressInternal Client Interface
// ================================
type IngressInternalClient interface {
ListActiveIngress(context.Context, *ListActiveIngressRequest, ...psrpc1.RequestOption) (<-chan *psrpc1.Response[*ListActiveIngressResponse], error)
}
// ====================================
// IngressInternal ServerImpl Interface
// ====================================
type IngressInternalServerImpl interface {
ListActiveIngress(context.Context, *ListActiveIngressRequest) (*ListActiveIngressResponse, error)
}
// ================================
// IngressInternal Server Interface
// ================================
type IngressInternalServer interface {
// Close and wait for pending RPCs to complete
Shutdown()
// Close immediately, without waiting for pending RPCs
Kill()
}
// ======================
// IngressInternal Client
// ======================
type ingressInternalClient struct {
client *psrpc1.RPCClient
}
// NewIngressInternalClient creates a psrpc client that implements the IngressInternalClient interface.
func NewIngressInternalClient(clientID string, bus psrpc1.MessageBus, opts ...psrpc1.ClientOption) (IngressInternalClient, error) {
rpcClient, err := psrpc1.NewRPCClient("IngressInternal", clientID, bus, opts...)
if err != nil {
return nil, err
}
return &ingressInternalClient{
client: rpcClient,
}, nil
}
func (c *ingressInternalClient) ListActiveIngress(ctx context.Context, req *ListActiveIngressRequest, opts ...psrpc1.RequestOption) (<-chan *psrpc1.Response[*ListActiveIngressResponse], error) {
return psrpc1.RequestMulti[*ListActiveIngressResponse](ctx, c.client, "ListActiveIngress", "", req, opts...)
}
// ======================
// IngressInternal Server
// ======================
type ingressInternalServer struct {
svc IngressInternalServerImpl
rpc *psrpc1.RPCServer
}
// NewIngressInternalServer builds a RPCServer that will route requests
// to the corresponding method in the provided svc implementation.
func NewIngressInternalServer(serverID string, svc IngressInternalServerImpl, bus psrpc1.MessageBus, opts ...psrpc1.ServerOption) (IngressInternalServer, error) {
s := psrpc1.NewRPCServer("IngressInternal", serverID, bus, opts...)
var err error
err = psrpc1.RegisterHandler(s, "ListActiveIngress", "", svc.ListActiveIngress, nil)
if err != nil {
s.Close(false)
return nil, err
}
return &ingressInternalServer{
svc: svc,
rpc: s,
}, nil
}
func (s *ingressInternalServer) Shutdown() {
s.rpc.Close(false)
}
func (s *ingressInternalServer) Kill() {
s.rpc.Close(true)
}
// ===============================
// IngressHandler Client Interface
// ===============================
type IngressHandlerClient interface {
UpdateIngress(context.Context, string, *livekit2.UpdateIngressRequest, ...psrpc1.RequestOption) (*livekit2.IngressState, error)
DeleteIngress(context.Context, string, *livekit2.DeleteIngressRequest, ...psrpc1.RequestOption) (*livekit2.IngressState, error)
}
// ===================================
// IngressHandler ServerImpl Interface
// ===================================
type IngressHandlerServerImpl interface {
UpdateIngress(context.Context, *livekit2.UpdateIngressRequest) (*livekit2.IngressState, error)
DeleteIngress(context.Context, *livekit2.DeleteIngressRequest) (*livekit2.IngressState, error)
}
// ===============================
// IngressHandler Server Interface
// ===============================
type IngressHandlerServer interface {
RegisterUpdateIngressTopic(string) error
DeregisterUpdateIngressTopic(string)
RegisterDeleteIngressTopic(string) error
DeregisterDeleteIngressTopic(string)
// Close and wait for pending RPCs to complete
Shutdown()
// Close immediately, without waiting for pending RPCs
Kill()
}
// =====================
// IngressHandler Client
// =====================
type ingressHandlerClient struct {
client *psrpc1.RPCClient
}
// NewIngressHandlerClient creates a psrpc client that implements the IngressHandlerClient interface.
func NewIngressHandlerClient(clientID string, bus psrpc1.MessageBus, opts ...psrpc1.ClientOption) (IngressHandlerClient, error) {
rpcClient, err := psrpc1.NewRPCClient("IngressHandler", clientID, bus, opts...)
if err != nil {
return nil, err
}
return &ingressHandlerClient{
client: rpcClient,
}, nil
}
func (c *ingressHandlerClient) UpdateIngress(ctx context.Context, topic string, req *livekit2.UpdateIngressRequest, opts ...psrpc1.RequestOption) (*livekit2.IngressState, error) {
return psrpc1.RequestSingle[*livekit2.IngressState](ctx, c.client, "UpdateIngress", topic, req, opts...)
}
func (c *ingressHandlerClient) DeleteIngress(ctx context.Context, topic string, req *livekit2.DeleteIngressRequest, opts ...psrpc1.RequestOption) (*livekit2.IngressState, error) {
return psrpc1.RequestSingle[*livekit2.IngressState](ctx, c.client, "DeleteIngress", topic, req, opts...)
}
// =====================
// IngressHandler Server
// =====================
type ingressHandlerServer struct {
svc IngressHandlerServerImpl
rpc *psrpc1.RPCServer
}
// NewIngressHandlerServer builds a RPCServer that will route requests
// to the corresponding method in the provided svc implementation.
func NewIngressHandlerServer(serverID string, svc IngressHandlerServerImpl, bus psrpc1.MessageBus, opts ...psrpc1.ServerOption) (IngressHandlerServer, error) {
s := psrpc1.NewRPCServer("IngressHandler", serverID, bus, opts...)
return &ingressHandlerServer{
svc: svc,
rpc: s,
}, nil
}
func (s *ingressHandlerServer) RegisterUpdateIngressTopic(topic string) error {
return psrpc1.RegisterHandler(s.rpc, "UpdateIngress", topic, s.svc.UpdateIngress, nil)
}
func (s *ingressHandlerServer) DeregisterUpdateIngressTopic(topic string) {
s.rpc.DeregisterHandler("UpdateIngress", topic)
}
func (s *ingressHandlerServer) RegisterDeleteIngressTopic(topic string) error {
return psrpc1.RegisterHandler(s.rpc, "DeleteIngress", topic, s.svc.DeleteIngress, nil)
}
func (s *ingressHandlerServer) DeregisterDeleteIngressTopic(topic string) {
s.rpc.DeregisterHandler("DeleteIngress", topic)
}
func (s *ingressHandlerServer) Shutdown() {
s.rpc.Close(false)
}
func (s *ingressHandlerServer) Kill() {
s.rpc.Close(true)
}
var psrpcFileDescriptor1 = []byte{
// 269 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 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