2019-01-16 16:19:25 +00:00
|
|
|
package rkt
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"time"
|
|
|
|
|
2019-01-23 19:44:42 +00:00
|
|
|
"github.com/hashicorp/nomad/client/state"
|
2019-01-16 16:19:25 +00:00
|
|
|
"github.com/hashicorp/nomad/drivers/shared/executor"
|
|
|
|
"github.com/hashicorp/nomad/helper/uuid"
|
|
|
|
"github.com/hashicorp/nomad/plugins/drivers"
|
2019-01-23 19:44:42 +00:00
|
|
|
"github.com/hashicorp/nomad/plugins/shared"
|
2019-01-16 16:19:25 +00:00
|
|
|
)
|
|
|
|
|
2019-01-23 19:44:42 +00:00
|
|
|
func (d *Driver) recoverPre09Task(h *drivers.TaskHandle) error {
|
|
|
|
handle, err := state.UnmarshalPre09HandleID(h.DriverState)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("failed to decode pre09 driver handle: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
reattach, err := shared.ReattachConfigToGoPlugin(handle.ReattachConfig())
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("failed to decode reattach config from pre09 handle: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
h.Config.ID = fmt.Sprintf("pre09-%s", uuid.Generate())
|
2019-01-16 16:19:25 +00:00
|
|
|
exec, pluginClient, err := executor.ReattachToPre09Executor(reattach,
|
2019-01-23 19:44:42 +00:00
|
|
|
d.logger.With("task_name", h.Config.Name, "alloc_id", h.Config.AllocID))
|
2019-01-16 16:19:25 +00:00
|
|
|
if err != nil {
|
2019-01-23 19:44:42 +00:00
|
|
|
d.logger.Error("failed to reattach to executor", "error", err, "task_name", h.Config.Name)
|
2019-01-16 16:19:25 +00:00
|
|
|
return fmt.Errorf("failed to reattach to executor: %v", err)
|
|
|
|
}
|
|
|
|
|
2019-01-23 19:44:42 +00:00
|
|
|
th := &taskHandle{
|
2019-01-16 16:19:25 +00:00
|
|
|
exec: exec,
|
|
|
|
pid: reattach.Pid,
|
|
|
|
pluginClient: pluginClient,
|
2019-01-23 19:44:42 +00:00
|
|
|
taskConfig: h.Config,
|
2019-01-16 16:19:25 +00:00
|
|
|
procState: drivers.TaskStateRunning,
|
|
|
|
startedAt: time.Now(),
|
|
|
|
exitResult: &drivers.ExitResult{},
|
|
|
|
}
|
|
|
|
|
2019-01-23 19:44:42 +00:00
|
|
|
d.tasks.Set(h.Config.ID, th)
|
2019-01-16 16:19:25 +00:00
|
|
|
|
2019-01-23 19:44:42 +00:00
|
|
|
go th.run()
|
2019-01-16 16:19:25 +00:00
|
|
|
return nil
|
|
|
|
}
|