open-nomad/drivers/java/driver_pre09.go
Nick Ethier be976d9c9a
Merge branch 'master' into f-driver-upgradepath-test
* master: (23 commits)
  tests: avoid assertion in goroutine
  spell check
  ci: run checkscripts
  tests: deflake TestRktDriver_StartWaitRecoverWaitStop
  drivers/rkt: Remove unused github.com/rkt/rkt
  drivers/rkt: allow development on non-linux
  cli: Hide `nomad docker_logger` from help output
  api: test api and structs are in sync
  goimports until make check is happy
  nil check node resources to prevent panic
  tr: use context in as select statement
  move pluginutils -> helper/pluginutils
  vet
  goimports
  gofmt
  Split hclspec
  move hclutils
  Driver tests do not use hcl2/hcl, hclspec, or hclutils
  move reattach config
  loader and singleton
  ...
2019-01-23 21:01:24 -05:00

48 lines
1.3 KiB
Go

package java
import (
"fmt"
"time"
"github.com/hashicorp/nomad/client/state"
"github.com/hashicorp/nomad/drivers/shared/executor"
"github.com/hashicorp/nomad/helper/uuid"
"github.com/hashicorp/nomad/plugins/drivers"
pstructs "github.com/hashicorp/nomad/plugins/shared/structs"
)
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 := pstructs.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())
exec, pluginClient, err := executor.ReattachToPre09Executor(reattach,
d.logger.With("task_name", h.Config.Name, "alloc_id", h.Config.AllocID))
if err != nil {
d.logger.Error("failed to reattach to executor", "error", err, "task_name", h.Config.Name)
return fmt.Errorf("failed to reattach to executor: %v", err)
}
th := &taskHandle{
exec: exec,
pid: reattach.Pid,
pluginClient: pluginClient,
taskConfig: h.Config,
procState: drivers.TaskStateRunning,
startedAt: time.Now(),
exitResult: &drivers.ExitResult{},
}
d.tasks.Set(h.Config.ID, th)
go th.run()
return nil
}