drivers: add upgrade path for rawexec, java, rkt and qemu

This commit is contained in:
Nick Ethier 2019-01-16 11:19:25 -05:00
parent 04772aac7c
commit 9dd4eb3581
No known key found for this signature in database
GPG key ID: 07C1A3ECED90D24A
8 changed files with 207 additions and 0 deletions

View file

@ -2,6 +2,7 @@ package java
import (
"context"
"encoding/json"
"fmt"
"os"
"os/exec"
@ -242,6 +243,21 @@ func (d *Driver) RecoverTask(handle *drivers.TaskHandle) error {
return fmt.Errorf("handle cannot be nil")
}
// pre 0.9 upgrade path check
if handle.Version == 0 {
var reattach shared.ReattachConfig
d.logger.Debug("parsing pre09 driver state", "state", string(handle.DriverState))
if err := json.Unmarshal(handle.DriverState, &reattach); err != nil {
return err
}
reattachConfig, err := shared.ReattachConfigToGoPlugin(&reattach)
if err != nil {
return err
}
return d.recoverPre0_9Task(handle.Config, reattachConfig)
}
// If already attached to handle there's nothing to recover.
if _, ok := d.tasks.Get(handle.Config.ID); ok {
d.logger.Debug("nothing to recover; task already exists",

View file

@ -0,0 +1,36 @@
package java
import (
"fmt"
"time"
plugin "github.com/hashicorp/go-plugin"
"github.com/hashicorp/nomad/drivers/shared/executor"
"github.com/hashicorp/nomad/helper/uuid"
"github.com/hashicorp/nomad/plugins/drivers"
)
func (d *Driver) recoverPre0_9Task(config *drivers.TaskConfig, reattach *plugin.ReattachConfig) error {
config.ID = fmt.Sprintf("pre09-%s", uuid.Generate())
exec, pluginClient, err := executor.ReattachToPre09Executor(reattach,
d.logger.With("task_name", config.Name, "alloc_id", config.AllocID))
if err != nil {
d.logger.Error("failed to reattach to executor", "error", err, "task_name", config.Name)
return fmt.Errorf("failed to reattach to executor: %v", err)
}
h := &taskHandle{
exec: exec,
pid: reattach.Pid,
pluginClient: pluginClient,
taskConfig: config,
procState: drivers.TaskStateRunning,
startedAt: time.Now(),
exitResult: &drivers.ExitResult{},
}
d.tasks.Set(config.ID, h)
go h.run()
return nil
}

View file

@ -2,6 +2,7 @@ package qemu
import (
"context"
"encoding/json"
"errors"
"fmt"
"net"
@ -240,6 +241,21 @@ func (d *Driver) RecoverTask(handle *drivers.TaskHandle) error {
return fmt.Errorf("error: handle cannot be nil")
}
// pre 0.9 upgrade path check
if handle.Version == 0 {
var reattach shared.ReattachConfig
d.logger.Debug("parsing pre09 driver state", "state", string(handle.DriverState))
if err := json.Unmarshal(handle.DriverState, &reattach); err != nil {
return err
}
reattachConfig, err := shared.ReattachConfigToGoPlugin(&reattach)
if err != nil {
return err
}
return d.recoverPre0_9Task(handle.Config, reattachConfig)
}
// If already attached to handle there's nothing to recover.
if _, ok := d.tasks.Get(handle.Config.ID); ok {
d.logger.Trace("nothing to recover; task already exists",

View file

@ -0,0 +1,36 @@
package qemu
import (
"fmt"
"time"
plugin "github.com/hashicorp/go-plugin"
"github.com/hashicorp/nomad/drivers/shared/executor"
"github.com/hashicorp/nomad/helper/uuid"
"github.com/hashicorp/nomad/plugins/drivers"
)
func (d *Driver) recoverPre0_9Task(config *drivers.TaskConfig, reattach *plugin.ReattachConfig) error {
config.ID = fmt.Sprintf("pre09-%s", uuid.Generate())
exec, pluginClient, err := executor.ReattachToPre09Executor(reattach,
d.logger.With("task_name", config.Name, "alloc_id", config.AllocID))
if err != nil {
d.logger.Error("failed to reattach to executor", "error", err, "task_name", config.Name)
return fmt.Errorf("failed to reattach to executor: %v", err)
}
h := &taskHandle{
exec: exec,
pid: reattach.Pid,
pluginClient: pluginClient,
taskConfig: config,
procState: drivers.TaskStateRunning,
startedAt: time.Now(),
exitResult: &drivers.ExitResult{},
}
d.tasks.Set(config.ID, h)
go h.run()
return nil
}

View file

@ -2,6 +2,7 @@ package rawexec
import (
"context"
"encoding/json"
"fmt"
"os"
"path/filepath"
@ -246,6 +247,21 @@ func (d *Driver) RecoverTask(handle *drivers.TaskHandle) error {
return fmt.Errorf("handle cannot be nil")
}
// pre 0.9 upgrade path check
if handle.Version == 0 {
var reattach shared.ReattachConfig
d.logger.Debug("parsing pre09 driver state", "state", string(handle.DriverState))
if err := json.Unmarshal(handle.DriverState, &reattach); err != nil {
return err
}
reattachConfig, err := shared.ReattachConfigToGoPlugin(&reattach)
if err != nil {
return err
}
return d.recoverPre0_9Task(handle.Config, reattachConfig)
}
// If already attached to handle there's nothing to recover.
if _, ok := d.tasks.Get(handle.Config.ID); ok {
d.logger.Trace("nothing to recover; task already exists",

View file

@ -0,0 +1,36 @@
package rawexec
import (
"fmt"
"time"
plugin "github.com/hashicorp/go-plugin"
"github.com/hashicorp/nomad/drivers/shared/executor"
"github.com/hashicorp/nomad/helper/uuid"
"github.com/hashicorp/nomad/plugins/drivers"
)
func (d *Driver) recoverPre0_9Task(config *drivers.TaskConfig, reattach *plugin.ReattachConfig) error {
config.ID = fmt.Sprintf("pre09-%s", uuid.Generate())
exec, pluginClient, err := executor.ReattachToPre09Executor(reattach,
d.logger.With("task_name", config.Name, "alloc_id", config.AllocID))
if err != nil {
d.logger.Error("failed to reattach to executor", "error", err, "task_name", config.Name)
return fmt.Errorf("failed to reattach to executor: %v", err)
}
h := &taskHandle{
exec: exec,
pid: reattach.Pid,
pluginClient: pluginClient,
taskConfig: config,
procState: drivers.TaskStateRunning,
startedAt: time.Now(),
exitResult: &drivers.ExitResult{},
}
d.tasks.Set(config.ID, h)
go h.run()
return nil
}

View file

@ -354,6 +354,21 @@ func (d *Driver) RecoverTask(handle *drivers.TaskHandle) error {
return fmt.Errorf("error: handle cannot be nil")
}
// pre 0.9 upgrade path check
if handle.Version == 0 {
var reattach shared.ReattachConfig
d.logger.Debug("parsing pre09 driver state", "state", string(handle.DriverState))
if err := json.Unmarshal(handle.DriverState, &reattach); err != nil {
return err
}
reattachConfig, err := shared.ReattachConfigToGoPlugin(&reattach)
if err != nil {
return err
}
return d.recoverPre0_9Task(handle.Config, reattachConfig)
}
// If already attached to handle there's nothing to recover.
if _, ok := d.tasks.Get(handle.Config.ID); ok {
d.logger.Trace("nothing to recover; task already exists",

View file

@ -0,0 +1,36 @@
package rkt
import (
"fmt"
"time"
plugin "github.com/hashicorp/go-plugin"
"github.com/hashicorp/nomad/drivers/shared/executor"
"github.com/hashicorp/nomad/helper/uuid"
"github.com/hashicorp/nomad/plugins/drivers"
)
func (d *Driver) recoverPre0_9Task(config *drivers.TaskConfig, reattach *plugin.ReattachConfig) error {
config.ID = fmt.Sprintf("pre09-%s", uuid.Generate())
exec, pluginClient, err := executor.ReattachToPre09Executor(reattach,
d.logger.With("task_name", config.Name, "alloc_id", config.AllocID))
if err != nil {
d.logger.Error("failed to reattach to executor", "error", err, "task_name", config.Name)
return fmt.Errorf("failed to reattach to executor: %v", err)
}
h := &taskHandle{
exec: exec,
pid: reattach.Pid,
pluginClient: pluginClient,
taskConfig: config,
procState: drivers.TaskStateRunning,
startedAt: time.Now(),
exitResult: &drivers.ExitResult{},
}
d.tasks.Set(config.ID, h)
go h.run()
return nil
}