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
|
|
|
"github.com/ugorji/go/codec"
|
|
|
|
)
|
|
|
|
|
|
|
|
// 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 {
|
|
|
|
Driver string
|
|
|
|
Config *TaskConfig
|
|
|
|
State TaskState
|
|
|
|
driverState []byte
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewTaskHandle(driver string) *TaskHandle {
|
|
|
|
return &TaskHandle{Driver: driver}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *TaskHandle) SetDriverState(v interface{}) error {
|
|
|
|
h.driverState = []byte{}
|
2018-09-25 18:12:58 +00:00
|
|
|
return codec.NewEncoderBytes(&h.driverState, base.MsgpackHandle).Encode(v)
|
2018-09-26 17:33:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (h *TaskHandle) GetDriverState(v interface{}) error {
|
2018-09-25 18:12:58 +00:00
|
|
|
return codec.NewDecoderBytes(h.driverState, base.MsgpackHandle).Decode(v)
|
2018-09-26 17:33:37 +00:00
|
|
|
|
|
|
|
}
|