2018-09-26 17:33:37 +00:00
|
|
|
package drivers
|
|
|
|
|
|
|
|
import (
|
2018-09-25 18:12:58 +00:00
|
|
|
"github.com/hashicorp/nomad/plugins/base"
|
2018-09-26 17:33:37 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// TaskHandle is the state shared between a driver and the client.
|
|
|
|
// It is returned to the client after starting the task and used
|
|
|
|
// for recovery of tasks during a driver restart.
|
|
|
|
type TaskHandle struct {
|
2019-01-13 21:05:07 +00:00
|
|
|
// Version is set by the driver an allows it to handle upgrading from
|
|
|
|
// an older DriverState struct. Prior to 0.9 the only state stored for
|
|
|
|
// driver was the reattach config for the executor. To allow upgrading to
|
|
|
|
// 0.9, Version 0 is handled as if it is the json encoded reattach config.
|
|
|
|
Version int
|
2018-09-26 17:33:37 +00:00
|
|
|
Config *TaskConfig
|
|
|
|
State TaskState
|
2018-10-18 20:39:02 +00:00
|
|
|
DriverState []byte
|
2018-09-26 17:33:37 +00:00
|
|
|
}
|
|
|
|
|
2019-01-13 21:05:07 +00:00
|
|
|
func NewTaskHandle(version int) *TaskHandle {
|
|
|
|
return &TaskHandle{Version: version}
|
2018-09-26 17:33:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (h *TaskHandle) SetDriverState(v interface{}) error {
|
2018-10-18 20:39:02 +00:00
|
|
|
h.DriverState = []byte{}
|
|
|
|
return base.MsgPackEncode(&h.DriverState, v)
|
2018-09-26 17:33:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (h *TaskHandle) GetDriverState(v interface{}) error {
|
2018-10-18 20:39:02 +00:00
|
|
|
return base.MsgPackDecode(h.DriverState, v)
|
2018-09-26 17:33:37 +00:00
|
|
|
|
|
|
|
}
|
2018-10-11 00:07:52 +00:00
|
|
|
|
|
|
|
func (h *TaskHandle) Copy() *TaskHandle {
|
2018-10-18 00:14:27 +00:00
|
|
|
if h == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2018-10-11 00:07:52 +00:00
|
|
|
handle := new(TaskHandle)
|
2019-01-13 21:05:07 +00:00
|
|
|
handle.Version = h.Version
|
2018-10-11 00:07:52 +00:00
|
|
|
handle.Config = h.Config.Copy()
|
2018-10-18 20:39:02 +00:00
|
|
|
handle.State = h.State
|
|
|
|
handle.DriverState = make([]byte, len(h.DriverState))
|
|
|
|
copy(handle.DriverState, h.DriverState)
|
2018-10-11 00:07:52 +00:00
|
|
|
return handle
|
|
|
|
}
|