Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

grpc shutdown and child process handling #88

Merged
merged 9 commits into from
Dec 12, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
use the new grpc controller
  • Loading branch information
jbardin committed Dec 11, 2018
commit 156630832e454a94f295ad45eb7066e97d21cee3
18 changes: 12 additions & 6 deletions grpc_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,15 @@ func newGRPCClient(doneCtx context.Context, c *Client) (*GRPCClient, error) {
go broker.Run()
go brokerGRPCClient.StartStream()

return &GRPCClient{
Conn: conn,
Plugins: c.config.Plugins,
doneCtx: doneCtx,
broker: broker,
}, nil
cl := &GRPCClient{
Conn: conn,
Plugins: c.config.Plugins,
doneCtx: doneCtx,
broker: broker,
controller: NewGRPCControllerClient(conn),
}

return cl, nil
}

// GRPCClient connects to a GRPCServer over gRPC to dispense plugin types.
Expand All @@ -70,11 +73,14 @@ type GRPCClient struct {

doneCtx context.Context
broker *GRPCBroker

controller GRPCControllerClient
}

// ClientProtocol impl.
func (c *GRPCClient) Close() error {
c.broker.Close()
c.controller.Shutdown(c.doneCtx, &Empty{})
return c.Conn.Close()
}

Expand Down
6 changes: 6 additions & 0 deletions grpc_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@ func (s *GRPCServer) Init() error {
s.broker = newGRPCBroker(brokerServer, s.TLS)
go s.broker.Run()

// Register the controller
controllerServer := &grpcControllerServer{
server: s,
}
RegisterGRPCControllerServer(s.server, controllerServer)

// Register all our plugins onto the gRPC server.
for k, raw := range s.Plugins {
p, ok := raw.(GRPCPlugin)
Expand Down
10 changes: 6 additions & 4 deletions testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ func TestPluginGRPCConn(t testing.T, ps map[string]Plugin) (*GRPCClient, *GRPCSe
// Start up the server
server := &GRPCServer{
Plugins: ps,
DoneCh: make(chan struct{}),
Server: DefaultGRPCServer,
Stdout: new(bytes.Buffer),
Stderr: new(bytes.Buffer),
Expand All @@ -165,10 +166,11 @@ func TestPluginGRPCConn(t testing.T, ps map[string]Plugin) (*GRPCClient, *GRPCSe

// Create the client
client := &GRPCClient{
Conn: conn,
Plugins: ps,
broker: broker,
doneCtx: context.Background(),
Conn: conn,
Plugins: ps,
broker: broker,
doneCtx: context.Background(),
controller: NewGRPCControllerClient(conn),
}

return client, server
Expand Down