drivers: add upgrade path for rawexec, java, rkt and qemu
This commit is contained in:
parent
8312829611
commit
ae77fbbe28
|
@ -2,6 +2,7 @@ package java
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
@ -242,6 +243,21 @@ func (d *Driver) RecoverTask(handle *drivers.TaskHandle) error {
|
||||||
return fmt.Errorf("handle cannot be nil")
|
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 already attached to handle there's nothing to recover.
|
||||||
if _, ok := d.tasks.Get(handle.Config.ID); ok {
|
if _, ok := d.tasks.Get(handle.Config.ID); ok {
|
||||||
d.logger.Debug("nothing to recover; task already exists",
|
d.logger.Debug("nothing to recover; task already exists",
|
||||||
|
|
|
@ -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
|
||||||
|
}
|
|
@ -2,6 +2,7 @@ package qemu
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
|
@ -240,6 +241,21 @@ func (d *Driver) RecoverTask(handle *drivers.TaskHandle) error {
|
||||||
return fmt.Errorf("error: handle cannot be nil")
|
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 already attached to handle there's nothing to recover.
|
||||||
if _, ok := d.tasks.Get(handle.Config.ID); ok {
|
if _, ok := d.tasks.Get(handle.Config.ID); ok {
|
||||||
d.logger.Trace("nothing to recover; task already exists",
|
d.logger.Trace("nothing to recover; task already exists",
|
||||||
|
|
|
@ -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
|
||||||
|
}
|
|
@ -2,6 +2,7 @@ package rawexec
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
@ -246,6 +247,21 @@ func (d *Driver) RecoverTask(handle *drivers.TaskHandle) error {
|
||||||
return fmt.Errorf("handle cannot be nil")
|
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 already attached to handle there's nothing to recover.
|
||||||
if _, ok := d.tasks.Get(handle.Config.ID); ok {
|
if _, ok := d.tasks.Get(handle.Config.ID); ok {
|
||||||
d.logger.Trace("nothing to recover; task already exists",
|
d.logger.Trace("nothing to recover; task already exists",
|
||||||
|
|
|
@ -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
|
||||||
|
}
|
|
@ -344,6 +344,21 @@ func (d *Driver) RecoverTask(handle *drivers.TaskHandle) error {
|
||||||
return fmt.Errorf("error: handle cannot be nil")
|
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 already attached to handle there's nothing to recover.
|
||||||
if _, ok := d.tasks.Get(handle.Config.ID); ok {
|
if _, ok := d.tasks.Get(handle.Config.ID); ok {
|
||||||
d.logger.Trace("nothing to recover; task already exists",
|
d.logger.Trace("nothing to recover; task already exists",
|
||||||
|
|
|
@ -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
|
||||||
|
}
|
Loading…
Reference in New Issue