mirror of
https://github.com/kemko/nomad.git
synced 2026-01-08 03:15:42 +03:00
Driver plugin framework to facilitate development of driver plugins.
Implementing plugins only need to implement the DriverPlugin interface.
The framework proxies this interface to the go-plugin GRPC interface generated
from the driver.proto spec.
A testing harness is provided to allow implementing drivers to test the full
lifecycle of the driver plugin. An example use:
func TestMyDriver(t *testing.T) {
harness := NewDriverHarness(t, &MyDiverPlugin{})
// The harness implements the DriverPlugin interface and can be used as such
taskHandle, err := harness.StartTask(...)
}
31 lines
795 B
Go
31 lines
795 B
Go
package drivers
|
|
|
|
import (
|
|
"github.com/hashicorp/nomad/nomad/structs"
|
|
"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{}
|
|
return codec.NewEncoderBytes(&h.driverState, structs.MsgpackHandle).Encode(v)
|
|
}
|
|
|
|
func (h *TaskHandle) GetDriverState(v interface{}) error {
|
|
return codec.NewDecoderBytes(h.driverState, structs.MsgpackHandle).Decode(v)
|
|
|
|
}
|