Skip to content

Commit

Permalink
Add support for SDK gRPC server extensions (libopenstorage#1094)
Browse files Browse the repository at this point in the history
Signed-off-by: Grant Griffiths <[email protected]>
  • Loading branch information
ggriffiths committed May 13, 2019
1 parent dce1e75 commit aad56d6
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions api/server/sdk/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,18 @@ type ServerConfig struct {
StoragePolicy policy.PolicyManager
// Security configuration
Security *SecurityConfig
// ServerExtensions allows you to extend the SDK gRPC server
// with callback functions that are sequentially executed
// at the end of Server.Start()
//
// To add your own service to the SDK gRPC server,
// just append a function callback that registers it:
//
// s.config.ServerExtensions = append(s.config.ServerExtensions,
// func(gs *grpc.Server) {
// api.RegisterCustomService(gs, customHandler)
// })
ServerExtensions []func(s *grpc.Server)
}

// Server is an implementation of the gRPC SDK interface
Expand Down Expand Up @@ -451,6 +463,9 @@ func (s *sdkGrpcServer) Start() error {
if s.config.Security.Role != nil {
api.RegisterOpenStorageRoleServer(grpcServer, s.roleServer)
}

s.RegisterServerExtensions(grpcServer)

return grpcServer
})
if err != nil {
Expand All @@ -460,6 +475,12 @@ func (s *sdkGrpcServer) Start() error {
return nil
}

func (s *sdkGrpcServer) RegisterServerExtensions(grpcServer *grpc.Server) {
for _, ext := range s.config.ServerExtensions {
ext(grpcServer)
}
}

func (s *sdkGrpcServer) useCluster(c cluster.Cluster) {
s.lock.Lock()
defer s.lock.Unlock()
Expand Down

0 comments on commit aad56d6

Please sign in to comment.