From dbb3570d5934e66f03bfcad984d5ccdee29ffe6a Mon Sep 17 00:00:00 2001 From: Diptanu Choudhury Date: Tue, 2 Feb 2016 14:36:11 -0800 Subject: [PATCH] Fixed the executor command --- client/driver/exec.go | 9 ++++++- client/driver/plugins/executor.go | 4 +++- client/driver/plugins/executor_basic.go | 32 +++++++++++++++++++++++++ command/executor_plugin.go | 8 +++---- commands.go | 5 ++++ 5 files changed, 52 insertions(+), 6 deletions(-) create mode 100644 client/driver/plugins/executor_basic.go diff --git a/client/driver/exec.go b/client/driver/exec.go index aff405a71..ca8059c4f 100644 --- a/client/driver/exec.go +++ b/client/driver/exec.go @@ -18,6 +18,8 @@ import ( //"github.com/hashicorp/nomad/client/getter" "github.com/hashicorp/nomad/nomad/structs" //"github.com/mitchellh/mapstructure" + + "github.com/hashicorp/nomad/helper/discover" ) // ExecDriver fork/execs tasks using as many of the underlying OS's isolation @@ -117,10 +119,15 @@ func (d *ExecDriver) Start(ctx *ExecContext, task *structs.Task) (DriverHandle, // return nil, fmt.Errorf("failed to start command: %v", err) // } // + + bin, err := discover.NomadExecutable() + if err != nil { + return nil, fmt.Errorf("unable to find the nomad binary: %v", err) + } executorClient := plugin.NewClient(&plugin.ClientConfig{ HandshakeConfig: plugins.HandshakeConfig, Plugins: plugins.PluginMap, - Cmd: exec.Command("/home/diptanuc/Projects/gocode/bin/nomad"), + Cmd: exec.Command(bin, "executor"), }) rpcClient, err := executorClient.Client() diff --git a/client/driver/plugins/executor.go b/client/driver/plugins/executor.go index 53aacb938..a8c918036 100644 --- a/client/driver/plugins/executor.go +++ b/client/driver/plugins/executor.go @@ -9,7 +9,9 @@ import ( ) var HandshakeConfig = plugin.HandshakeConfig{ - ProtocolVersion: 1, + ProtocolVersion: 1, + MagicCookieKey: "executor_plugin", + MagicCookieValue: "value", } var PluginMap = map[string]plugin.Plugin{ diff --git a/client/driver/plugins/executor_basic.go b/client/driver/plugins/executor_basic.go new file mode 100644 index 000000000..a2e59373d --- /dev/null +++ b/client/driver/plugins/executor_basic.go @@ -0,0 +1,32 @@ +// +build !linux + +package plugins + +import ( + "os/exec" + "time" +) + +type BasicExecutor struct { +} + +func NewExecutor() Executor { + return &BasicExecutor{} +} + +func (e *BasicExecutor) LaunchCmd(cmd *exec.Cmd, ctx *ExecutorContext) (*ProcessState, error) { + return &ProcessState{Pid: 5, ExitCode: -1, Time: time.Now()}, nil +} + +func (e *BasicExecutor) Wait() (*ProcessState, error) { + time.Sleep(5 * time.Second) + return &ProcessState{Pid: 0, ExitCode: 0, Time: time.Now()}, nil +} + +func (e *BasicExecutor) Exit() (*ProcessState, error) { + return &ProcessState{Pid: 0, ExitCode: 0, Time: time.Now()}, nil +} + +func (e *BasicExecutor) ShutDown() (*ProcessState, error) { + return &ProcessState{Pid: 0, ExitCode: 0, Time: time.Now()}, nil +} diff --git a/command/executor_plugin.go b/command/executor_plugin.go index 839a3ede3..44f86836a 100644 --- a/command/executor_plugin.go +++ b/command/executor_plugin.go @@ -8,22 +8,22 @@ import ( "github.com/hashicorp/nomad/client/driver/plugins" ) -type ExecutorPlugin struct { +type ExecutorPluginCommand struct { Meta } -func (e *ExecutorPlugin) Help() string { +func (e *ExecutorPluginCommand) Help() string { helpText := ` This is a command used by Nomad internally to launch an executor plugin" ` return strings.TrimSpace(helpText) } -func (e *ExecutorPlugin) Synopsis() string { +func (e *ExecutorPluginCommand) Synopsis() string { return "internal - launch an executor plugin" } -func (e *ExecutorPlugin) Run(args []string) int { +func (e *ExecutorPluginCommand) Run(args []string) int { plugin.Serve(&plugin.ServeConfig{ HandshakeConfig: plugins.HandshakeConfig, Plugins: plugins.PluginMap, diff --git a/commands.go b/commands.go index 1b69883c8..9f5fedb12 100644 --- a/commands.go +++ b/commands.go @@ -57,6 +57,11 @@ func Commands(metaPtr *command.Meta) map[string]cli.CommandFactory { Meta: meta, }, nil }, + "executor": func() (cli.Command, error) { + return &command.ExecutorPluginCommand{ + Meta: meta, + }, nil + }, "fs ls": func() (cli.Command, error) { return &command.FSListCommand{ Meta: meta,