taskrunner

package
v0.9.4-rc1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 23, 2019 License: MPL-2.0 Imports: 46 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// HookNameDevices is the name of the devices hook
	HookNameDevices = "devices"
)
View Source
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

View Source
var (
	ErrTaskNotRunning = errors.New(errTaskNotRunning)
)

Functions

func NewHookError

func NewHookError(err error, taskEvent *structs.TaskEvent) error

NewHookError contains an underlying err and a pre-formatted task event.

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

	// ServersContactedCh is closed when the first GetClientAllocs call to
	// servers succeeds and allocs are synced.
	ServersContactedCh chan struct{}
}

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) Exec

func (h *DriverHandle) Exec(timeout time.Duration, cmd string, args []string) ([]byte, int, error)

Exec is the handled used by client endpoint handler to invoke the appropriate task driver exec.

func (*DriverHandle) ExecStreaming added in v0.9.2

func (h *DriverHandle) ExecStreaming(ctx context.Context,
	command []string,
	tty bool,
	stream drivers.ExecTaskStream) error

ExecStreaming is the handled used by client endpoint handler to invoke the appropriate task driver exec. while allowing to stream input and output

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) Update

func (h *DriverHandle) Update(task *structs.Task) error

func (*DriverHandle) WaitCh

func (h *DriverHandle) WaitCh(ctx context.Context) (<-chan *drivers.ExitResult, error)

type LazyHandle

type LazyHandle struct {
	sync.Mutex
	// contains filtered or unexported fields
}

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) Exec

func (l *LazyHandle) Exec(timeout time.Duration, cmd string, args []string) ([]byte, int, error)

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) DriverCapabilities added in v0.9.2

func (tr *TaskRunner) DriverCapabilities() (*drivers.Capabilities, error)

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

func (tr *TaskRunner) Kill(ctx context.Context, event *structs.TaskEvent) error

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) MarkFailedDead added in v0.9.4

func (tr *TaskRunner) MarkFailedDead(reason string)

Mark a task as failed and not to run. Aimed to be invoked when alloc runner prestart hooks failed. Should never be called with Run().

func (*TaskRunner) Restart

func (tr *TaskRunner) Restart(ctx context.Context, event *structs.TaskEvent, failure bool) error

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) Signal

func (tr *TaskRunner) Signal(event *structs.TaskEvent, s string) error

func (*TaskRunner) Task

func (tr *TaskRunner) Task() *structs.Task

func (*TaskRunner) TaskExecHandler added in v0.9.2

func (tr *TaskRunner) TaskExecHandler() drivermanager.TaskExecHandler

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.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL