exec

package
v0.0.0-...-f0983eb Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2016 License: Apache-2.0 Imports: 7 Imported by: 0

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

	// ErrTaskUpdateFailed is returned if a task controller update fails.
	ErrTaskUpdateFailed = errors.New("exec: task update failed")

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

Functions

func Do

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

Do progresses the task state using the controller by 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.

func Run

func Run(ctx context.Context, ctlr Controller, reporter Reporter) error

Run runs a controller, reporting state along the way. Under normal execution, this function blocks until the task is completed.

func Shutdown

func Shutdown(ctx context.Context, ctlr Controller, reporter Reporter) error

Shutdown the task using the controller and report on the status.

Types

type ContainerController

type ContainerController 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)
}

ContainerController controls execution of container tasks.

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.

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 propogate 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 ExitError

type ExitError struct {
	Code            int
	Cause           error
	ContainerStatus *api.ContainerStatus
}

ExitError is returned by controller methods after encountering an error after a task exits. It should require any data to report on a non-zero exit code.

func (*ExitError) Error

func (e *ExitError) Error() string

type MockContainerController

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

Mock of ContainerController interface

func NewMockContainerController

func NewMockContainerController(ctrl *gomock.Controller) *MockContainerController

func (*MockContainerController) ContainerStatus

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

func (*MockContainerController) EXPECT

func (_m *MockContainerController) EXPECT() *_MockContainerControllerRecorder

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 MockReporter

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

Mock of Reporter interface

func NewMockReporter

func NewMockReporter(ctrl *gomock.Controller) *MockReporter

func (*MockReporter) EXPECT

func (_m *MockReporter) EXPECT() *_MockReporterRecorder

func (*MockReporter) Report

func (_m *MockReporter) Report(ctx context.Context, state api.TaskState, msg string, cstatus *api.ContainerStatus) error

type Reporter

type Reporter interface {
	// Report the state of the task run. If an error is returned, execution
	// will be stopped.
	// TODO(aluzzardi): This interface leaks ContainerStatus and needs fixing.
	Report(ctx context.Context, state api.TaskState, msg string, cstatus *api.ContainerStatus) error
}

Reporter defines an interface for calling back into the task status reporting infrastructure. Typically, an instance is associated to a specific task.

The results of the "Report" are combined with a TaskStatus and sent to the dispatcher.

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