exec

package
v1.12.0 Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2016 License: Apache-2.0 Imports: 10 Imported by: 469

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrRuntimeUnsupported encountered when a task requires a runtime
	// unsupported by the executor.
	ErrRuntimeUnsupported = errors.New("exec: unsupported runtime")

	// ErrTaskPrepared is called if the task is already prepared.
	ErrTaskPrepared = errors.New("exec: task already prepared")

	// ErrTaskStarted can be returned from any operation that cannot be
	// performed because the task has already been started. This does not imply
	// that the task is running but rather that it is no longer valid to call
	// Start.
	ErrTaskStarted = errors.New("exec: task already started")

	// ErrTaskUpdateRejected is returned if a task update is rejected by a controller.
	ErrTaskUpdateRejected = errors.New("exec: task update rejected")

	// ErrControllerClosed returned when a task controller has been closed.
	ErrControllerClosed = errors.New("exec: controller closed")

	// ErrTaskRetry is returned by Do when an operation failed by should be
	// retried. The status should still be reported in this case.
	ErrTaskRetry = errors.New("exec: task retry")

	// ErrTaskNoop returns when the a subsequent call to Do will not result in
	// advancing the task. Callers should avoid calling Do until the task has been updated.
	ErrTaskNoop = errors.New("exec: task noop")
)

Functions

func Do

func Do(ctx context.Context, task *api.Task, ctlr Controller) (*api.TaskStatus, error)

Do progresses the task state using the controller performing a single operation on the controller. The return TaskStatus should be marked as the new state of the task.

The returned status should be reported and placed back on to task before the next call. The operation can be cancelled by creating a cancelling context.

Errors from the task controller will reported on the returned status. Any errors coming from this function should not be reported as related to the individual task.

If ErrTaskNoop is returned, it means a second call to Do will result in no change. If ErrTaskDead is returned, calls to Do will no longer result in any action.

func IsTemporary

func IsTemporary(err error) bool

IsTemporary returns true if the error or a recursive cause returns true for temporary.

func MakeTemporary

func MakeTemporary(err error) error

MakeTemporary makes the error temporary.

Types

type ContainerStatuser

type ContainerStatuser interface {
	// ContainerStatus returns the status of the target container, if
	// available. When the container is not available, the status will be nil.
	ContainerStatus(ctx context.Context) (*api.ContainerStatus, error)
}

ContainerStatuser reports status of a container.

This can be implemented by controllers or error types.

type Controller

type Controller interface {
	// Update the task definition seen by the controller. Will return
	// ErrTaskUpdateFailed if the provided task definition changes fields that
	// cannot be changed.
	//
	// Will be ignored if the task has exited.
	Update(ctx context.Context, t *api.Task) error

	// Prepare the task for execution. This should ensure that all resources
	// are created such that a call to start should execute immediately.
	Prepare(ctx context.Context) error

	// Start the target and return when it has started successfully.
	Start(ctx context.Context) error

	// Wait blocks until the target has exited.
	Wait(ctx context.Context) error

	// Shutdown requests to exit the target gracefully.
	Shutdown(ctx context.Context) error

	// Terminate the target.
	Terminate(ctx context.Context) error

	// Remove all resources allocated by the controller.
	Remove(ctx context.Context) error

	// Close closes any ephemeral resources associated with controller instance.
	Close() error
}

Controller controls execution of a task.

func Resolve

func Resolve(ctx context.Context, task *api.Task, executor Executor) (Controller, *api.TaskStatus, error)

Resolve attempts to get a controller from the executor and reports the correct status depending on the tasks current state according to the result.

Unlike Do, if an error is returned, the status should still be reported. The error merely reports the failure at getting the controller.

type Executor

type Executor interface {
	// Describe returns the underlying node description.
	Describe(ctx context.Context) (*api.NodeDescription, error)

	// Configure uses the node object state to propagate node
	// state to the underlying executor.
	Configure(ctx context.Context, node *api.Node) error

	// Controller provides a controller for the given task.
	Controller(t *api.Task) (Controller, error)

	// SetNetworkBootstrapKeys passes the symmetric keys from the
	// manager to the executor.
	SetNetworkBootstrapKeys([]*api.EncryptionKey) error
}

Executor provides controllers for tasks.

type ExitCoder

type ExitCoder interface {
	// ExitCode returns the exit code.
	ExitCode() int
}

ExitCoder is implemented by errors that have an exit code.

type MockContainerStatuser

type MockContainerStatuser struct {
	// contains filtered or unexported fields
}

Mock of ContainerStatuser interface

func NewMockContainerStatuser

func NewMockContainerStatuser(ctrl *gomock.Controller) *MockContainerStatuser

func (*MockContainerStatuser) ContainerStatus

func (_m *MockContainerStatuser) ContainerStatus(ctx context.Context) (*api.ContainerStatus, error)

func (*MockContainerStatuser) EXPECT

func (_m *MockContainerStatuser) EXPECT() *_MockContainerStatuserRecorder

type MockController

type MockController struct {
	// contains filtered or unexported fields
}

Mock of Controller interface

func NewMockController

func NewMockController(ctrl *gomock.Controller) *MockController

func (*MockController) Close

func (_m *MockController) Close() error

func (*MockController) EXPECT

func (_m *MockController) EXPECT() *_MockControllerRecorder

func (*MockController) Prepare

func (_m *MockController) Prepare(ctx context.Context) error

func (*MockController) Remove

func (_m *MockController) Remove(ctx context.Context) error

func (*MockController) Shutdown

func (_m *MockController) Shutdown(ctx context.Context) error

func (*MockController) Start

func (_m *MockController) Start(ctx context.Context) error

func (*MockController) Terminate

func (_m *MockController) Terminate(ctx context.Context) error

func (*MockController) Update

func (_m *MockController) Update(ctx context.Context, t *api.Task) error

func (*MockController) Wait

func (_m *MockController) Wait(ctx context.Context) error

type Temporary

type Temporary interface {
	Temporary() bool
}

Temporary indicates whether or not the error condition is temporary.

If this is encountered in the controller, the failing operation will be retried when this returns true. Otherwise, the operation is considered fatal.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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