Documentation ¶
Index ¶
- Constants
- Variables
- func NewHookError(err error, taskEvent *structs.TaskEvent) error
- type Config
- type DriverHandle
- func (h *DriverHandle) Exec(timeout time.Duration, cmd string, args []string) ([]byte, int, error)
- func (h *DriverHandle) ID() string
- func (h *DriverHandle) Kill() error
- func (h *DriverHandle) Network() *drivers.DriverNetwork
- func (h *DriverHandle) Signal(s string) error
- func (h *DriverHandle) Stats(ctx context.Context, interval time.Duration) (<-chan *cstructs.TaskResourceUsage, error)
- func (h *DriverHandle) Update(task *structs.Task) error
- func (h *DriverHandle) WaitCh(ctx context.Context) (<-chan *drivers.ExitResult, error)
- type LazyHandle
- type StatsUpdater
- type TaskRunner
- func (tr *TaskRunner) Alloc() *structs.Allocation
- func (tr *TaskRunner) AppendEvent(event *structs.TaskEvent)
- func (tr *TaskRunner) EmitEvent(event *structs.TaskEvent)
- func (tr *TaskRunner) IsLeader() bool
- func (tr *TaskRunner) Kill(ctx context.Context, event *structs.TaskEvent) error
- func (tr *TaskRunner) LatestResourceUsage() *cstructs.TaskResourceUsage
- func (tr *TaskRunner) Restart(ctx context.Context, event *structs.TaskEvent, failure bool) error
- func (tr *TaskRunner) Restore() error
- func (tr *TaskRunner) Run()
- func (tr *TaskRunner) Shutdown()
- func (tr *TaskRunner) Signal(event *structs.TaskEvent, s string) error
- func (tr *TaskRunner) Task() *structs.Task
- func (tr *TaskRunner) TaskState() *structs.TaskState
- func (tr *TaskRunner) Update(update *structs.Allocation)
- func (tr *TaskRunner) UpdateState(state string, event *structs.TaskEvent)
- func (tr *TaskRunner) UpdateStats(ru *cstructs.TaskResourceUsage)
- func (tr *TaskRunner) WaitCh() <-chan struct{}
Constants ¶
const (
// HookNameDevices is the name of the devices hook
HookNameDevices = "devices"
)
const ( // TaskDirHookIsDoneDataKey is used to mark whether the hook is done. We // do not use the Done response value because we still need to set the // environment variables every time a task starts. // TODO(0.9.1): Use the resp.Env map and switch to resp.Done. We need to // remove usage of the envBuilder TaskDirHookIsDoneDataKey = "is_done" )
Variables ¶
var (
ErrTaskNotRunning = errors.New(errTaskNotRunning)
)
Functions ¶
Types ¶
type Config ¶
type Config struct { Alloc *structs.Allocation ClientConfig *config.Config Consul consul.ConsulServiceAPI Task *structs.Task TaskDir *allocdir.TaskDir Logger log.Logger // Vault is the client to use to derive and renew Vault tokens Vault vaultclient.VaultClient // StateDB is used to store and restore state. StateDB cstate.StateDB // StateUpdater is used to emit updated task state StateUpdater interfaces.TaskStateHandler // deviceStatsReporter is used to lookup resource usage for alloc devices DeviceStatsReporter cinterfaces.DeviceStatsReporter // DeviceManager is used to mount devices as well as lookup device // statistics DeviceManager devicemanager.Manager // DriverManager is used to dispense driver plugins and register event // handlers DriverManager drivermanager.Manager }
type DriverHandle ¶
type DriverHandle struct {
// contains filtered or unexported fields
}
DriverHandle encapsulates a driver plugin client and task identifier and exposes an api to perform driver operations on the task
func NewDriverHandle ¶
func NewDriverHandle(driver drivers.DriverPlugin, taskID string, task *structs.Task, net *drivers.DriverNetwork) *DriverHandle
NewDriverHandle returns a handle for task operations on a specific task
func (*DriverHandle) ID ¶
func (h *DriverHandle) ID() string
func (*DriverHandle) Kill ¶
func (h *DriverHandle) Kill() error
func (*DriverHandle) Network ¶
func (h *DriverHandle) Network() *drivers.DriverNetwork
func (*DriverHandle) Signal ¶
func (h *DriverHandle) Signal(s string) error
func (*DriverHandle) Stats ¶
func (h *DriverHandle) Stats(ctx context.Context, interval time.Duration) (<-chan *cstructs.TaskResourceUsage, error)
func (*DriverHandle) WaitCh ¶
func (h *DriverHandle) WaitCh(ctx context.Context) (<-chan *drivers.ExitResult, error)
type LazyHandle ¶
LazyHandle is used to front calls to a DriverHandle where it is expected the existing handle may no longer be valid because the backing plugin has shutdown. LazyHandle detects the plugin shutting down and retrieves a new handle so that the consumer does not need to worry whether the handle is to the latest driver instance.
func NewLazyHandle ¶
func NewLazyHandle(shutdownCtx context.Context, fn retrieveHandleFn, logger log.Logger) *LazyHandle
NewLazyHandle takes the function to receive the latest handle and a logger and returns a LazyHandle
func (*LazyHandle) Stats ¶
func (l *LazyHandle) Stats(ctx context.Context, interval time.Duration) (<-chan *cstructs.TaskResourceUsage, error)
type StatsUpdater ¶
type StatsUpdater interface {
UpdateStats(*cstructs.TaskResourceUsage)
}
StatsUpdater is the interface required by the StatsHook to update stats. Satisfied by TaskRunner.
type TaskRunner ¶
type TaskRunner struct {
// contains filtered or unexported fields
}
func NewTaskRunner ¶
func NewTaskRunner(config *Config) (*TaskRunner, error)
func (*TaskRunner) Alloc ¶
func (tr *TaskRunner) Alloc() *structs.Allocation
func (*TaskRunner) AppendEvent ¶
func (tr *TaskRunner) AppendEvent(event *structs.TaskEvent)
AppendEvent appends a new TaskEvent to this task's TaskState. The actual TaskState.State (pending, running, dead) is not changed. Use UpdateState to transition states. Events are persisted locally and errors are simply logged. Use EmitEvent also update AllocRunner.
func (*TaskRunner) EmitEvent ¶
func (tr *TaskRunner) EmitEvent(event *structs.TaskEvent)
EmitEvent appends a new TaskEvent to this task's TaskState. The actual TaskState.State (pending, running, dead) is not changed. Use UpdateState to transition states. Events are persisted locally and sent to the server, but errors are simply logged. Use AppendEvent to simply add a new event.
func (*TaskRunner) IsLeader ¶
func (tr *TaskRunner) IsLeader() bool
IsLeader returns true if this task is the leader of its task group.
func (*TaskRunner) Kill ¶
Kill a task. Blocks until task exits or context is canceled. State is set to dead.
func (*TaskRunner) LatestResourceUsage ¶
func (tr *TaskRunner) LatestResourceUsage() *cstructs.TaskResourceUsage
LatestResourceUsage returns the last resource utilization datapoint collected. May return nil if the task is not running or no resource utilization has been collected yet.
func (*TaskRunner) Restart ¶
Restart a task. Returns immediately if no task is running. Blocks until existing task exits or passed-in context is canceled.
func (*TaskRunner) Restore ¶
func (tr *TaskRunner) Restore() error
Restore task runner state. Called by AllocRunner.Restore after NewTaskRunner but before Run so no locks need to be acquired.
func (*TaskRunner) Run ¶
func (tr *TaskRunner) Run()
Run the TaskRunner. Starts the user's task or reattaches to a restored task. Run closes WaitCh when it exits. Should be started in a goroutine.
func (*TaskRunner) Shutdown ¶
func (tr *TaskRunner) Shutdown()
Shutdown TaskRunner gracefully without affecting the state of the task. Shutdown blocks until the main Run loop exits.
func (*TaskRunner) Task ¶
func (tr *TaskRunner) Task() *structs.Task
func (*TaskRunner) TaskState ¶
func (tr *TaskRunner) TaskState() *structs.TaskState
func (*TaskRunner) Update ¶
func (tr *TaskRunner) Update(update *structs.Allocation)
Update the running allocation with a new version received from the server. Calls Update hooks asynchronously with Run.
This method is safe for calling concurrently with Run and does not modify the passed in allocation.
func (*TaskRunner) UpdateState ¶
func (tr *TaskRunner) UpdateState(state string, event *structs.TaskEvent)
UpdateState sets the task runners allocation state and triggers a server update.
func (*TaskRunner) UpdateStats ¶
func (tr *TaskRunner) UpdateStats(ru *cstructs.TaskResourceUsage)
UpdateStats updates and emits the latest stats from the driver.
func (*TaskRunner) WaitCh ¶
func (tr *TaskRunner) WaitCh() <-chan struct{}
WaitCh is closed when TaskRunner.Run exits.