2018-11-29 13:59:53 +00:00
|
|
|
package executor
|
2016-02-03 19:54:54 +00:00
|
|
|
|
|
|
|
import (
|
2018-12-05 16:03:56 +00:00
|
|
|
"context"
|
2016-02-03 19:54:54 +00:00
|
|
|
|
2018-09-24 18:37:45 +00:00
|
|
|
hclog "github.com/hashicorp/go-hclog"
|
2019-01-15 19:46:12 +00:00
|
|
|
plugin "github.com/hashicorp/go-plugin"
|
2018-12-07 02:13:45 +00:00
|
|
|
"github.com/hashicorp/nomad/drivers/shared/executor/proto"
|
2018-12-05 16:03:56 +00:00
|
|
|
"google.golang.org/grpc"
|
2016-02-03 19:54:54 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type ExecutorPlugin struct {
|
2018-12-08 06:52:06 +00:00
|
|
|
// TODO: support backwards compatibility with pre 0.9 NetRPC plugin
|
2018-12-05 16:03:56 +00:00
|
|
|
plugin.NetRPCUnsupportedPlugin
|
2018-09-24 18:37:45 +00:00
|
|
|
logger hclog.Logger
|
|
|
|
fsIsolation bool
|
2016-02-03 19:54:54 +00:00
|
|
|
}
|
|
|
|
|
2018-12-05 16:03:56 +00:00
|
|
|
func (p *ExecutorPlugin) GRPCServer(broker *plugin.GRPCBroker, s *grpc.Server) error {
|
|
|
|
if p.fsIsolation {
|
2018-12-07 02:13:45 +00:00
|
|
|
proto.RegisterExecutorServer(s, &grpcExecutorServer{impl: NewExecutorWithIsolation(p.logger)})
|
2018-12-05 16:03:56 +00:00
|
|
|
} else {
|
2018-12-07 02:13:45 +00:00
|
|
|
proto.RegisterExecutorServer(s, &grpcExecutorServer{impl: NewExecutor(p.logger)})
|
2016-02-08 19:56:48 +00:00
|
|
|
}
|
2018-12-05 16:03:56 +00:00
|
|
|
return nil
|
2016-02-03 19:54:54 +00:00
|
|
|
}
|
|
|
|
|
2018-12-05 16:03:56 +00:00
|
|
|
func (p *ExecutorPlugin) GRPCClient(ctx context.Context, broker *plugin.GRPCBroker, c *grpc.ClientConn) (interface{}, error) {
|
|
|
|
return &grpcExecutorClient{
|
|
|
|
client: proto.NewExecutorClient(c),
|
|
|
|
doneCtx: ctx,
|
2018-12-11 20:27:50 +00:00
|
|
|
logger: p.logger,
|
2018-12-05 16:03:56 +00:00
|
|
|
}, nil
|
2016-02-03 19:54:54 +00:00
|
|
|
}
|