Fixed the executor command

This commit is contained in:
Diptanu Choudhury
2016-02-02 14:36:11 -08:00
parent d0f53c8586
commit dbb3570d59
5 changed files with 52 additions and 6 deletions

View File

@@ -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()

View File

@@ -9,7 +9,9 @@ import (
)
var HandshakeConfig = plugin.HandshakeConfig{
ProtocolVersion: 1,
ProtocolVersion: 1,
MagicCookieKey: "executor_plugin",
MagicCookieValue: "value",
}
var PluginMap = map[string]plugin.Plugin{

View File

@@ -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
}

View File

@@ -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,

View File

@@ -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,