mirror of
https://github.com/kemko/nomad.git
synced 2026-01-08 03:15:42 +03:00
Fixing the id generation logic for the java and qemu drivers
This commit is contained in:
@@ -151,7 +151,6 @@ func (d *ExecDriver) Open(ctx *ExecContext, handleID string) (DriverHandle, erro
|
||||
}
|
||||
|
||||
reattachConfig := id.PluginConfig.PluginConfig()
|
||||
|
||||
pluginConfig := &plugin.ClientConfig{
|
||||
Reattach: reattachConfig,
|
||||
}
|
||||
|
||||
@@ -149,11 +149,7 @@ func (d *JavaDriver) Start(ctx *ExecContext, task *structs.Task) (DriverHandle,
|
||||
return nil, fmt.Errorf("unable to find the nomad binary: %v", err)
|
||||
}
|
||||
pluginConfig := &plugin.ClientConfig{
|
||||
HandshakeConfig: plugins.HandshakeConfig,
|
||||
Plugins: plugins.PluginMap,
|
||||
Cmd: exec.Command(bin, "executor"),
|
||||
SyncStdout: d.config.LogOutput,
|
||||
SyncStderr: d.config.LogOutput,
|
||||
Cmd: exec.Command(bin, "executor"),
|
||||
}
|
||||
|
||||
executor, pluginClient, err := d.executor(pluginConfig)
|
||||
@@ -189,12 +185,16 @@ func (d *JavaDriver) Start(ctx *ExecContext, task *structs.Task) (DriverHandle,
|
||||
}
|
||||
|
||||
func (d *JavaDriver) executor(config *plugin.ClientConfig) (plugins.Executor, *plugin.Client, error) {
|
||||
config.HandshakeConfig = plugins.HandshakeConfig
|
||||
config.Plugins = plugins.PluginMap
|
||||
config.SyncStdout = d.config.LogOutput
|
||||
config.SyncStderr = d.config.LogOutput
|
||||
|
||||
executorClient := plugin.NewClient(config)
|
||||
rpcClient, err := executorClient.Client()
|
||||
if err != nil {
|
||||
return nil, nil, fmt.Errorf("error creating rpc client for executor plugin: %v", err)
|
||||
}
|
||||
rpcClient.SyncStreams(d.config.LogOutput, d.config.LogOutput)
|
||||
|
||||
raw, err := rpcClient.Dispense("executor")
|
||||
if err != nil {
|
||||
@@ -206,7 +206,7 @@ func (d *JavaDriver) executor(config *plugin.ClientConfig) (plugins.Executor, *p
|
||||
|
||||
type javaId struct {
|
||||
KillTimeout time.Duration
|
||||
PluginConfig *plugin.ReattachConfig
|
||||
PluginConfig *plugins.ExecutorReattachConfig
|
||||
UserPid int
|
||||
}
|
||||
|
||||
@@ -216,18 +216,9 @@ func (d *JavaDriver) Open(ctx *ExecContext, handleID string) (DriverHandle, erro
|
||||
return nil, fmt.Errorf("Failed to parse handle '%s': %v", handleID, err)
|
||||
}
|
||||
|
||||
bin, err := discover.NomadExecutable()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to find the nomad binary: %v", err)
|
||||
}
|
||||
|
||||
reattachConfig := id.PluginConfig.PluginConfig()
|
||||
pluginConfig := &plugin.ClientConfig{
|
||||
HandshakeConfig: plugins.HandshakeConfig,
|
||||
Plugins: plugins.PluginMap,
|
||||
Cmd: exec.Command(bin, "executor"),
|
||||
Reattach: id.PluginConfig,
|
||||
SyncStdout: d.config.LogOutput,
|
||||
SyncStderr: d.config.LogOutput,
|
||||
Reattach: reattachConfig,
|
||||
}
|
||||
executor, client, err := d.executor(pluginConfig)
|
||||
if err != nil {
|
||||
@@ -252,7 +243,7 @@ func (d *JavaDriver) Open(ctx *ExecContext, handleID string) (DriverHandle, erro
|
||||
func (h *javaHandle) ID() string {
|
||||
id := javaId{
|
||||
KillTimeout: h.killTimeout,
|
||||
PluginConfig: h.pluginClient.ReattachConfig(),
|
||||
PluginConfig: plugins.NewExecutorReattachConfig(h.pluginClient.ReattachConfig()),
|
||||
UserPid: h.userPid,
|
||||
}
|
||||
|
||||
|
||||
@@ -87,6 +87,7 @@ func TestJavaDriver_StartOpen_Wait(t *testing.T) {
|
||||
// There is a race condition between the handle waiting and killing. One
|
||||
// will return an error.
|
||||
handle.Kill()
|
||||
handle2.Kill()
|
||||
}
|
||||
|
||||
func TestJavaDriver_Start_Wait(t *testing.T) {
|
||||
|
||||
@@ -142,6 +142,9 @@ func (e *UniversalExecutor) wait() {
|
||||
|
||||
func (e *UniversalExecutor) Exit() error {
|
||||
e.logger.Printf("[INFO] Exiting plugin for task %q", e.ctx.TaskName)
|
||||
if e.cmd.Process == nil {
|
||||
return fmt.Errorf("executor.exit error: no process found")
|
||||
}
|
||||
proc, err := os.FindProcess(e.cmd.Process.Pid)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failied to find user process %v: %v", e.cmd.Process.Pid, err)
|
||||
@@ -159,6 +162,9 @@ func (e *UniversalExecutor) Exit() error {
|
||||
}
|
||||
|
||||
func (e *UniversalExecutor) ShutDown() error {
|
||||
if e.cmd.Process == nil {
|
||||
return fmt.Errorf("executor.shutdown error: no process found")
|
||||
}
|
||||
proc, err := os.FindProcess(e.cmd.Process.Pid)
|
||||
if err != nil {
|
||||
return fmt.Errorf("executor.shutdown error: %v", err)
|
||||
|
||||
@@ -193,11 +193,7 @@ func (d *QemuDriver) Start(ctx *ExecContext, task *structs.Task) (DriverHandle,
|
||||
return nil, fmt.Errorf("unable to find the nomad binary: %v", err)
|
||||
}
|
||||
pluginConfig := &plugin.ClientConfig{
|
||||
HandshakeConfig: plugins.HandshakeConfig,
|
||||
Plugins: plugins.PluginMap,
|
||||
Cmd: exec.Command(bin, "executor"),
|
||||
SyncStdout: d.config.LogOutput,
|
||||
SyncStderr: d.config.LogOutput,
|
||||
Cmd: exec.Command(bin, "executor"),
|
||||
}
|
||||
|
||||
executor, pluginClient, err := d.executor(pluginConfig)
|
||||
@@ -234,6 +230,10 @@ func (d *QemuDriver) Start(ctx *ExecContext, task *structs.Task) (DriverHandle,
|
||||
}
|
||||
|
||||
func (d *QemuDriver) executor(config *plugin.ClientConfig) (plugins.Executor, *plugin.Client, error) {
|
||||
config.HandshakeConfig = plugins.HandshakeConfig
|
||||
config.Plugins = plugins.PluginMap
|
||||
config.SyncStdout = d.config.LogOutput
|
||||
config.SyncStderr = d.config.LogOutput
|
||||
executorClient := plugin.NewClient(config)
|
||||
rpcClient, err := executorClient.Client()
|
||||
if err != nil {
|
||||
@@ -251,8 +251,8 @@ func (d *QemuDriver) executor(config *plugin.ClientConfig) (plugins.Executor, *p
|
||||
|
||||
type qemuId struct {
|
||||
KillTimeout time.Duration
|
||||
PluginConfig *plugin.ReattachConfig
|
||||
UserPid int
|
||||
PluginConfig *plugins.ExecutorReattachConfig
|
||||
}
|
||||
|
||||
func (d *QemuDriver) Open(ctx *ExecContext, handleID string) (DriverHandle, error) {
|
||||
@@ -261,18 +261,11 @@ func (d *QemuDriver) Open(ctx *ExecContext, handleID string) (DriverHandle, erro
|
||||
return nil, fmt.Errorf("Failed to parse handle '%s': %v", handleID, err)
|
||||
}
|
||||
|
||||
bin, err := discover.NomadExecutable()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to find the nomad binary: %v", err)
|
||||
}
|
||||
reattachConfig := id.PluginConfig.PluginConfig()
|
||||
pluginConfig := &plugin.ClientConfig{
|
||||
HandshakeConfig: plugins.HandshakeConfig,
|
||||
Plugins: plugins.PluginMap,
|
||||
Cmd: exec.Command(bin, "executor"),
|
||||
Reattach: id.PluginConfig,
|
||||
SyncStdout: d.config.LogOutput,
|
||||
SyncStderr: d.config.LogOutput,
|
||||
Reattach: reattachConfig,
|
||||
}
|
||||
|
||||
executor, client, err := d.executor(pluginConfig)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error connecting to plugin: %v", err)
|
||||
@@ -295,7 +288,7 @@ func (d *QemuDriver) Open(ctx *ExecContext, handleID string) (DriverHandle, erro
|
||||
func (h *qemuHandle) ID() string {
|
||||
id := qemuId{
|
||||
KillTimeout: h.killTimeout,
|
||||
PluginConfig: h.pluginClient.ReattachConfig(),
|
||||
PluginConfig: plugins.NewExecutorReattachConfig(h.pluginClient.ReattachConfig()),
|
||||
UserPid: h.userPid,
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user