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"
|
2016-02-03 19:54:54 +00:00
|
|
|
"github.com/hashicorp/go-plugin"
|
2018-11-28 16:05:10 +00:00
|
|
|
"github.com/hashicorp/nomad/drivers/shared/executor"
|
2018-12-05 16:03:56 +00:00
|
|
|
"github.com/hashicorp/nomad/plugins/executor/proto"
|
|
|
|
"google.golang.org/grpc"
|
2016-02-03 19:54:54 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type ExecutorPlugin struct {
|
2018-12-05 16:03:56 +00:00
|
|
|
// TODO: support backwards compatability with pre 0.9 NetRPC plugin
|
|
|
|
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 {
|
|
|
|
proto.RegisterExecutorServer(s, &grpcExecutorServer{impl: executor.NewExecutorWithIsolation(p.logger)})
|
|
|
|
} else {
|
|
|
|
proto.RegisterExecutorServer(s, &grpcExecutorServer{impl: executor.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,
|
|
|
|
}, nil
|
2016-02-03 19:54:54 +00:00
|
|
|
}
|