github.com/iqoqo/nomad@v0.11.3-0.20200911112621-d7021c74d101/drivers/qemu/driver_pre09.go (about) 1 package qemu 2 3 import ( 4 "fmt" 5 "time" 6 7 "github.com/hashicorp/nomad/client/state" 8 "github.com/hashicorp/nomad/drivers/shared/executor" 9 "github.com/hashicorp/nomad/plugins/drivers" 10 pstructs "github.com/hashicorp/nomad/plugins/shared/structs" 11 ) 12 13 func (d *Driver) recoverPre09Task(h *drivers.TaskHandle) error { 14 handle, err := state.UnmarshalPre09HandleID(h.DriverState) 15 if err != nil { 16 return fmt.Errorf("failed to decode pre09 driver handle: %v", err) 17 } 18 19 reattach, err := pstructs.ReattachConfigToGoPlugin(handle.ReattachConfig()) 20 if err != nil { 21 return fmt.Errorf("failed to decode reattach config from pre09 handle: %v", err) 22 } 23 24 exec, pluginClient, err := executor.ReattachToPre09Executor(reattach, 25 d.logger.With("task_name", h.Config.Name, "alloc_id", h.Config.AllocID)) 26 if err != nil { 27 d.logger.Error("failed to reattach to executor", "error", err, "task_name", h.Config.Name) 28 return fmt.Errorf("failed to reattach to executor: %v", err) 29 } 30 31 th := &taskHandle{ 32 exec: exec, 33 pid: reattach.Pid, 34 pluginClient: pluginClient, 35 taskConfig: h.Config, 36 procState: drivers.TaskStateRunning, 37 startedAt: time.Now(), 38 exitResult: &drivers.ExitResult{}, 39 logger: d.logger, 40 } 41 42 d.tasks.Set(h.Config.ID, th) 43 44 go th.run() 45 return nil 46 }