From efc4249f8527ec52dc50b1801e31609cde1479c0 Mon Sep 17 00:00:00 2001 From: Mahmood Ali Date: Sun, 28 Apr 2019 17:27:23 -0400 Subject: [PATCH] executor: scaffolding for executor grpc handling Prepare executor to handle streaming exec API calls that reuse drivers protobuf structs. --- drivers/shared/executor/client.go | 73 +++++++ drivers/shared/executor/executor.go | 3 + drivers/shared/executor/proto/executor.pb.go | 219 ++++++++++++------- drivers/shared/executor/proto/executor.proto | 1 + drivers/shared/executor/server.go | 16 ++ 5 files changed, 236 insertions(+), 76 deletions(-) diff --git a/drivers/shared/executor/client.go b/drivers/shared/executor/client.go index 101583605..dec2c9b3a 100644 --- a/drivers/shared/executor/client.go +++ b/drivers/shared/executor/client.go @@ -13,7 +13,9 @@ import ( hclog "github.com/hashicorp/go-hclog" cstructs "github.com/hashicorp/nomad/client/structs" "github.com/hashicorp/nomad/drivers/shared/executor/proto" + "github.com/hashicorp/nomad/helper/pluginutils/grpcutils" "github.com/hashicorp/nomad/plugins/drivers" + dproto "github.com/hashicorp/nomad/plugins/drivers/proto" ) var _ Executor = (*grpcExecutorClient)(nil) @@ -181,3 +183,74 @@ func (c *grpcExecutorClient) Exec(deadline time.Time, cmd string, args []string) return resp.Output, int(resp.ExitCode), nil } + +func (d *grpcExecutorClient) ExecStreaming(ctx context.Context, + command []string, + tty bool, + execStream drivers.ExecTaskStream) error { + + err := d.execStreaming(ctx, command, tty, execStream) + if err != nil { + return grpcutils.HandleGrpcErr(err, d.doneCtx) + } + return nil +} + +func (d *grpcExecutorClient) execStreaming(ctx context.Context, + command []string, + tty bool, + execStream drivers.ExecTaskStream) error { + + stream, err := d.client.ExecStreaming(ctx) + if err != nil { + return err + } + + err = stream.Send(&dproto.ExecTaskStreamingRequest{ + Setup: &dproto.ExecTaskStreamingRequest_Setup{ + Command: command, + Tty: tty, + }, + }) + if err != nil { + return err + } + + errCh := make(chan error, 1) + go func() { + for { + m, err := execStream.Recv() + if err == io.EOF { + return + } else if err != nil { + errCh <- err + return + } + + if err := stream.Send(m); err != nil { + errCh <- err + return + } + + } + }() + + for { + select { + case err := <-errCh: + return err + default: + } + + m, err := stream.Recv() + if err == io.EOF { + return nil + } else if err != nil { + return err + } + + if err := execStream.Send(m); err != nil { + return err + } + } +} diff --git a/drivers/shared/executor/executor.go b/drivers/shared/executor/executor.go index 699d3247a..f077bd488 100644 --- a/drivers/shared/executor/executor.go +++ b/drivers/shared/executor/executor.go @@ -77,6 +77,9 @@ type Executor interface { // Exec executes the given command and args inside the executor context // and returns the output and exit code. Exec(deadline time.Time, cmd string, args []string) ([]byte, int, error) + + ExecStreaming(ctx context.Context, cmd []string, tty bool, + stream drivers.ExecTaskStream) error } // ExecCommand holds the user command, args, and other isolation related diff --git a/drivers/shared/executor/proto/executor.pb.go b/drivers/shared/executor/proto/executor.pb.go index a108c7f5b..5b281f34c 100644 --- a/drivers/shared/executor/proto/executor.pb.go +++ b/drivers/shared/executor/proto/executor.pb.go @@ -47,7 +47,7 @@ func (m *LaunchRequest) Reset() { *m = LaunchRequest{} } func (m *LaunchRequest) String() string { return proto.CompactTextString(m) } func (*LaunchRequest) ProtoMessage() {} func (*LaunchRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_executor_1eb9aa6040002cd3, []int{0} + return fileDescriptor_executor_5ea6ca9df3b0f07e, []int{0} } func (m *LaunchRequest) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_LaunchRequest.Unmarshal(m, b) @@ -162,7 +162,7 @@ func (m *LaunchResponse) Reset() { *m = LaunchResponse{} } func (m *LaunchResponse) String() string { return proto.CompactTextString(m) } func (*LaunchResponse) ProtoMessage() {} func (*LaunchResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_executor_1eb9aa6040002cd3, []int{1} + return fileDescriptor_executor_5ea6ca9df3b0f07e, []int{1} } func (m *LaunchResponse) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_LaunchResponse.Unmarshal(m, b) @@ -199,7 +199,7 @@ func (m *WaitRequest) Reset() { *m = WaitRequest{} } func (m *WaitRequest) String() string { return proto.CompactTextString(m) } func (*WaitRequest) ProtoMessage() {} func (*WaitRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_executor_1eb9aa6040002cd3, []int{2} + return fileDescriptor_executor_5ea6ca9df3b0f07e, []int{2} } func (m *WaitRequest) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_WaitRequest.Unmarshal(m, b) @@ -230,7 +230,7 @@ func (m *WaitResponse) Reset() { *m = WaitResponse{} } func (m *WaitResponse) String() string { return proto.CompactTextString(m) } func (*WaitResponse) ProtoMessage() {} func (*WaitResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_executor_1eb9aa6040002cd3, []int{3} + return fileDescriptor_executor_5ea6ca9df3b0f07e, []int{3} } func (m *WaitResponse) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_WaitResponse.Unmarshal(m, b) @@ -269,7 +269,7 @@ func (m *ShutdownRequest) Reset() { *m = ShutdownRequest{} } func (m *ShutdownRequest) String() string { return proto.CompactTextString(m) } func (*ShutdownRequest) ProtoMessage() {} func (*ShutdownRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_executor_1eb9aa6040002cd3, []int{4} + return fileDescriptor_executor_5ea6ca9df3b0f07e, []int{4} } func (m *ShutdownRequest) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_ShutdownRequest.Unmarshal(m, b) @@ -313,7 +313,7 @@ func (m *ShutdownResponse) Reset() { *m = ShutdownResponse{} } func (m *ShutdownResponse) String() string { return proto.CompactTextString(m) } func (*ShutdownResponse) ProtoMessage() {} func (*ShutdownResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_executor_1eb9aa6040002cd3, []int{5} + return fileDescriptor_executor_5ea6ca9df3b0f07e, []int{5} } func (m *ShutdownResponse) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_ShutdownResponse.Unmarshal(m, b) @@ -344,7 +344,7 @@ func (m *UpdateResourcesRequest) Reset() { *m = UpdateResourcesRequest{} func (m *UpdateResourcesRequest) String() string { return proto.CompactTextString(m) } func (*UpdateResourcesRequest) ProtoMessage() {} func (*UpdateResourcesRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_executor_1eb9aa6040002cd3, []int{6} + return fileDescriptor_executor_5ea6ca9df3b0f07e, []int{6} } func (m *UpdateResourcesRequest) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_UpdateResourcesRequest.Unmarshal(m, b) @@ -381,7 +381,7 @@ func (m *UpdateResourcesResponse) Reset() { *m = UpdateResourcesResponse func (m *UpdateResourcesResponse) String() string { return proto.CompactTextString(m) } func (*UpdateResourcesResponse) ProtoMessage() {} func (*UpdateResourcesResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_executor_1eb9aa6040002cd3, []int{7} + return fileDescriptor_executor_5ea6ca9df3b0f07e, []int{7} } func (m *UpdateResourcesResponse) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_UpdateResourcesResponse.Unmarshal(m, b) @@ -411,7 +411,7 @@ func (m *VersionRequest) Reset() { *m = VersionRequest{} } func (m *VersionRequest) String() string { return proto.CompactTextString(m) } func (*VersionRequest) ProtoMessage() {} func (*VersionRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_executor_1eb9aa6040002cd3, []int{8} + return fileDescriptor_executor_5ea6ca9df3b0f07e, []int{8} } func (m *VersionRequest) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_VersionRequest.Unmarshal(m, b) @@ -442,7 +442,7 @@ func (m *VersionResponse) Reset() { *m = VersionResponse{} } func (m *VersionResponse) String() string { return proto.CompactTextString(m) } func (*VersionResponse) ProtoMessage() {} func (*VersionResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_executor_1eb9aa6040002cd3, []int{9} + return fileDescriptor_executor_5ea6ca9df3b0f07e, []int{9} } func (m *VersionResponse) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_VersionResponse.Unmarshal(m, b) @@ -480,7 +480,7 @@ func (m *StatsRequest) Reset() { *m = StatsRequest{} } func (m *StatsRequest) String() string { return proto.CompactTextString(m) } func (*StatsRequest) ProtoMessage() {} func (*StatsRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_executor_1eb9aa6040002cd3, []int{10} + return fileDescriptor_executor_5ea6ca9df3b0f07e, []int{10} } func (m *StatsRequest) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_StatsRequest.Unmarshal(m, b) @@ -518,7 +518,7 @@ func (m *StatsResponse) Reset() { *m = StatsResponse{} } func (m *StatsResponse) String() string { return proto.CompactTextString(m) } func (*StatsResponse) ProtoMessage() {} func (*StatsResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_executor_1eb9aa6040002cd3, []int{11} + return fileDescriptor_executor_5ea6ca9df3b0f07e, []int{11} } func (m *StatsResponse) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_StatsResponse.Unmarshal(m, b) @@ -556,7 +556,7 @@ func (m *SignalRequest) Reset() { *m = SignalRequest{} } func (m *SignalRequest) String() string { return proto.CompactTextString(m) } func (*SignalRequest) ProtoMessage() {} func (*SignalRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_executor_1eb9aa6040002cd3, []int{12} + return fileDescriptor_executor_5ea6ca9df3b0f07e, []int{12} } func (m *SignalRequest) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_SignalRequest.Unmarshal(m, b) @@ -593,7 +593,7 @@ func (m *SignalResponse) Reset() { *m = SignalResponse{} } func (m *SignalResponse) String() string { return proto.CompactTextString(m) } func (*SignalResponse) ProtoMessage() {} func (*SignalResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_executor_1eb9aa6040002cd3, []int{13} + return fileDescriptor_executor_5ea6ca9df3b0f07e, []int{13} } func (m *SignalResponse) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_SignalResponse.Unmarshal(m, b) @@ -626,7 +626,7 @@ func (m *ExecRequest) Reset() { *m = ExecRequest{} } func (m *ExecRequest) String() string { return proto.CompactTextString(m) } func (*ExecRequest) ProtoMessage() {} func (*ExecRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_executor_1eb9aa6040002cd3, []int{14} + return fileDescriptor_executor_5ea6ca9df3b0f07e, []int{14} } func (m *ExecRequest) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_ExecRequest.Unmarshal(m, b) @@ -679,7 +679,7 @@ func (m *ExecResponse) Reset() { *m = ExecResponse{} } func (m *ExecResponse) String() string { return proto.CompactTextString(m) } func (*ExecResponse) ProtoMessage() {} func (*ExecResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_executor_1eb9aa6040002cd3, []int{15} + return fileDescriptor_executor_5ea6ca9df3b0f07e, []int{15} } func (m *ExecResponse) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_ExecResponse.Unmarshal(m, b) @@ -727,7 +727,7 @@ func (m *ProcessState) Reset() { *m = ProcessState{} } func (m *ProcessState) String() string { return proto.CompactTextString(m) } func (*ProcessState) ProtoMessage() {} func (*ProcessState) Descriptor() ([]byte, []int) { - return fileDescriptor_executor_1eb9aa6040002cd3, []int{16} + return fileDescriptor_executor_5ea6ca9df3b0f07e, []int{16} } func (m *ProcessState) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_ProcessState.Unmarshal(m, b) @@ -815,6 +815,7 @@ type ExecutorClient interface { Stats(ctx context.Context, in *StatsRequest, opts ...grpc.CallOption) (Executor_StatsClient, error) Signal(ctx context.Context, in *SignalRequest, opts ...grpc.CallOption) (*SignalResponse, error) Exec(ctx context.Context, in *ExecRequest, opts ...grpc.CallOption) (*ExecResponse, error) + ExecStreaming(ctx context.Context, opts ...grpc.CallOption) (Executor_ExecStreamingClient, error) } type executorClient struct { @@ -920,6 +921,37 @@ func (c *executorClient) Exec(ctx context.Context, in *ExecRequest, opts ...grpc return out, nil } +func (c *executorClient) ExecStreaming(ctx context.Context, opts ...grpc.CallOption) (Executor_ExecStreamingClient, error) { + stream, err := c.cc.NewStream(ctx, &_Executor_serviceDesc.Streams[1], "/hashicorp.nomad.plugins.executor.proto.Executor/ExecStreaming", opts...) + if err != nil { + return nil, err + } + x := &executorExecStreamingClient{stream} + return x, nil +} + +type Executor_ExecStreamingClient interface { + Send(*proto1.ExecTaskStreamingRequest) error + Recv() (*proto1.ExecTaskStreamingResponse, error) + grpc.ClientStream +} + +type executorExecStreamingClient struct { + grpc.ClientStream +} + +func (x *executorExecStreamingClient) Send(m *proto1.ExecTaskStreamingRequest) error { + return x.ClientStream.SendMsg(m) +} + +func (x *executorExecStreamingClient) Recv() (*proto1.ExecTaskStreamingResponse, error) { + m := new(proto1.ExecTaskStreamingResponse) + if err := x.ClientStream.RecvMsg(m); err != nil { + return nil, err + } + return m, nil +} + // ExecutorServer is the server API for Executor service. type ExecutorServer interface { Launch(context.Context, *LaunchRequest) (*LaunchResponse, error) @@ -930,6 +962,7 @@ type ExecutorServer interface { Stats(*StatsRequest, Executor_StatsServer) error Signal(context.Context, *SignalRequest) (*SignalResponse, error) Exec(context.Context, *ExecRequest) (*ExecResponse, error) + ExecStreaming(Executor_ExecStreamingServer) error } func RegisterExecutorServer(s *grpc.Server, srv ExecutorServer) { @@ -1083,6 +1116,32 @@ func _Executor_Exec_Handler(srv interface{}, ctx context.Context, dec func(inter return interceptor(ctx, in, info, handler) } +func _Executor_ExecStreaming_Handler(srv interface{}, stream grpc.ServerStream) error { + return srv.(ExecutorServer).ExecStreaming(&executorExecStreamingServer{stream}) +} + +type Executor_ExecStreamingServer interface { + Send(*proto1.ExecTaskStreamingResponse) error + Recv() (*proto1.ExecTaskStreamingRequest, error) + grpc.ServerStream +} + +type executorExecStreamingServer struct { + grpc.ServerStream +} + +func (x *executorExecStreamingServer) Send(m *proto1.ExecTaskStreamingResponse) error { + return x.ServerStream.SendMsg(m) +} + +func (x *executorExecStreamingServer) Recv() (*proto1.ExecTaskStreamingRequest, error) { + m := new(proto1.ExecTaskStreamingRequest) + if err := x.ServerStream.RecvMsg(m); err != nil { + return nil, err + } + return m, nil +} + var _Executor_serviceDesc = grpc.ServiceDesc{ ServiceName: "hashicorp.nomad.plugins.executor.proto.Executor", HandlerType: (*ExecutorServer)(nil), @@ -1122,70 +1181,78 @@ var _Executor_serviceDesc = grpc.ServiceDesc{ Handler: _Executor_Stats_Handler, ServerStreams: true, }, + { + StreamName: "ExecStreaming", + Handler: _Executor_ExecStreaming_Handler, + ServerStreams: true, + ClientStreams: true, + }, }, Metadata: "drivers/shared/executor/proto/executor.proto", } func init() { - proto.RegisterFile("drivers/shared/executor/proto/executor.proto", fileDescriptor_executor_1eb9aa6040002cd3) + proto.RegisterFile("drivers/shared/executor/proto/executor.proto", fileDescriptor_executor_5ea6ca9df3b0f07e) } -var fileDescriptor_executor_1eb9aa6040002cd3 = []byte{ - // 885 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x55, 0x4b, 0x6f, 0xe4, 0x44, - 0x10, 0x5e, 0xc7, 0x99, 0x57, 0xcd, 0xe4, 0xa1, 0x16, 0x0a, 0x5e, 0x73, 0xd8, 0xc1, 0x07, 0x76, - 0x04, 0x8b, 0x27, 0xca, 0xbe, 0xb8, 0x00, 0x12, 0xc9, 0xc2, 0x25, 0xac, 0x22, 0x67, 0x61, 0x25, - 0x0e, 0x0c, 0x1d, 0xbb, 0xb1, 0x5b, 0x99, 0x71, 0x9b, 0xee, 0xf6, 0x30, 0x48, 0x48, 0x9c, 0xf8, - 0x07, 0xfc, 0x52, 0x8e, 0x9c, 0x50, 0xbf, 0x9c, 0x99, 0xec, 0x12, 0x79, 0x40, 0x9c, 0xa6, 0xab, - 0x5c, 0xdf, 0x57, 0x55, 0xdd, 0x55, 0xdf, 0xc0, 0xa3, 0x8c, 0xd3, 0x25, 0xe1, 0x62, 0x2a, 0x0a, - 0xcc, 0x49, 0x36, 0x25, 0x2b, 0x92, 0xd6, 0x92, 0xf1, 0x69, 0xc5, 0x99, 0x64, 0x8d, 0x19, 0x6b, - 0x13, 0x7d, 0x50, 0x60, 0x51, 0xd0, 0x94, 0xf1,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xad, - 0x61, 0xfb, 0xf9, 0x5f, 0xd3, 0xbb, 0xf6, 0xf3, 0xbf, 0xae, 0x5b, 0xd1, 0xbd, 0x2f, 0x7a, 0xdf, - 0x75, 0x8c, 0x30, 0x74, 0xf5, 0xcf, 0xe3, 0xbf, 0x03, 0x00, 0x00, 0xff, 0xff, 0x2f, 0x08, 0xfe, - 0x1f, 0xaa, 0x0a, 0x00, 0x00, +var fileDescriptor_executor_5ea6ca9df3b0f07e = []byte{ + // 919 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x55, 0x5f, 0x6f, 0xdc, 0x44, + 0x10, 0xaf, 0xeb, 0xdc, 0xbf, 0xb9, 0xbb, 0x24, 0x5a, 0xa1, 0xe0, 0x9a, 0x87, 0x1e, 0x7e, 0xa0, + 0x27, 0x28, 0xbe, 0x28, 0xfd, 0xc7, 0x0b, 0x14, 0x91, 0x14, 0x5e, 0x42, 0x15, 0x39, 0x85, 0x4a, + 0x3c, 0x70, 0x6c, 0xec, 0xc5, 0x5e, 0xe5, 0xce, 0x6b, 0x76, 0xd7, 0x47, 0x90, 0x90, 0x78, 0xe2, + 0x1b, 0x80, 0xc4, 0xe7, 0xe4, 0x13, 0xa0, 0xfd, 0xe7, 0xdc, 0xa5, 0xa5, 0xf2, 0x15, 0xf1, 0x74, + 0x3b, 0xe3, 0xf9, 0xfd, 0x66, 0x66, 0x77, 0xe6, 0x77, 0x70, 0x3f, 0xe3, 0x74, 0x45, 0xb8, 0x98, + 0x89, 0x02, 0x73, 0x92, 0xcd, 0xc8, 0x15, 0x49, 0x6b, 0xc9, 0xf8, 0xac, 0xe2, 0x4c, 0xb2, 0xc6, + 0x8c, 0xb5, 0x89, 0x3e, 0x28, 0xb0, 0x28, 0x68, 0xca, 0x78, 0x15, 0x97, 0x6c, 0x89, 0xb3, 0xb8, + 0x5a, 0xd4, 0x39, 0x2d, 0x45, 0xbc, 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0x5d, 0xb7, 0xa2, 0x5b, 0xe8, + 0x2f, 0x0f, 0xc6, 0xca, 0x75, 0x2e, 0x39, 0xc1, 0x4b, 0x5a, 0xe6, 0xe8, 0x69, 0x4b, 0xf1, 0x56, + 0x28, 0x23, 0xe0, 0x16, 0xe9, 0x4a, 0xf9, 0xfc, 0xed, 0x09, 0x5c, 0x59, 0x53, 0xef, 0xd0, 0xfb, + 0xa2, 0xf7, 0x5d, 0xc7, 0x68, 0x56, 0x57, 0xff, 0x3c, 0xf8, 0x27, 0x00, 0x00, 0xff, 0xff, 0xe4, + 0x09, 0xe7, 0x2c, 0x45, 0x0b, 0x00, 0x00, } diff --git a/drivers/shared/executor/proto/executor.proto b/drivers/shared/executor/proto/executor.proto index 7d721c400..438b5e680 100644 --- a/drivers/shared/executor/proto/executor.proto +++ b/drivers/shared/executor/proto/executor.proto @@ -14,6 +14,7 @@ service Executor { rpc Stats(StatsRequest) returns (stream StatsResponse) {} rpc Signal(SignalRequest) returns (SignalResponse) {} rpc Exec(ExecRequest) returns (ExecResponse) {} + rpc ExecStreaming(stream hashicorp.nomad.plugins.drivers.proto.ExecTaskStreamingRequest) returns (stream hashicorp.nomad.plugins.drivers.proto.ExecTaskStreamingResponse) {} } message LaunchRequest { diff --git a/drivers/shared/executor/server.go b/drivers/shared/executor/server.go index a9028219b..df3b6b4bc 100644 --- a/drivers/shared/executor/server.go +++ b/drivers/shared/executor/server.go @@ -1,6 +1,7 @@ package executor import ( + "fmt" "syscall" "time" @@ -154,3 +155,18 @@ func (s *grpcExecutorServer) Exec(ctx context.Context, req *proto.ExecRequest) ( ExitCode: int32(exit), }, nil } + +func (s *grpcExecutorServer) ExecStreaming(server proto.Executor_ExecStreamingServer) error { + msg, err := server.Recv() + if err != nil { + return fmt.Errorf("failed to receive initial message: %v", err) + } + + if msg.Setup == nil { + return fmt.Errorf("first message should always be setup") + } + + return s.impl.ExecStreaming(server.Context(), + msg.Setup.Command, msg.Setup.Tty, + server) +}