api

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: May 6, 2015 License: Apache-2.0, BSD-2-Clause, BSD-3-Clause, + 1 more Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ECS_SERVICE = "ecs"

	EcsMaxReasonLength = 255

	RoundtripTimeout = 5 * time.Second
)
View Source
const DOCKER_MINIMUM_MEMORY = 4 * 1024 * 1024 // 4MB

Variables

This section is empty.

Functions

func PortBindingFromDockerPortBinding

func PortBindingFromDockerPortBinding(dockerPortBindings map[docker.Port][]docker.PortBinding) ([]PortBinding, NamedError)

PortBindingFromDockerPortBinding constructs a PortBinding slice from a docker NetworkSettings.Ports map.

Types

type APIError added in v1.0.0

type APIError struct {
	Retriable bool
	// contains filtered or unexported fields
}

Implements Error & Retriable

func NewAPIError added in v1.0.0

func NewAPIError(err error) *APIError

func (*APIError) Error added in v1.0.0

func (apiErr *APIError) Error() string

func (*APIError) Retry added in v1.0.0

func (apiErr *APIError) Retry() bool

type ApiECSClient

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

ApiECSClient implements ECSClient

func (*ApiECSClient) CreateCluster

func (client *ApiECSClient) CreateCluster(clusterName string) (string, error)

CreateCluster creates a cluster from a given name and returns its arn

func (*ApiECSClient) DiscoverPollEndpoint

func (client *ApiECSClient) DiscoverPollEndpoint(containerInstanceArn string) (string, error)

func (*ApiECSClient) RegisterContainerInstance

func (client *ApiECSClient) RegisterContainerInstance() (string, error)

func (*ApiECSClient) SetEC2MetadataClient added in v1.1.0

func (client *ApiECSClient) SetEC2MetadataClient(ec2MetadataClient ec2.EC2MetadataClient)

SetEC2MetadataClient overrides the EC2 Metadata Client to the given one. This is useful for injecting a test implementation

func (*ApiECSClient) SetSDK added in v1.1.0

func (client *ApiECSClient) SetSDK(sdk ECSSDK)

SetSDK overrides the SDK to the given one. This is useful for injecting a test implementation

func (*ApiECSClient) SubmitContainerStateChange

func (client *ApiECSClient) SubmitContainerStateChange(change ContainerStateChange) utils.RetriableError

func (*ApiECSClient) SubmitTaskStateChange

func (client *ApiECSClient) SubmitTaskStateChange(change TaskStateChange) utils.RetriableError

type Container

type Container struct {
	Name        string
	Image       string
	Command     []string
	Cpu         uint
	Memory      uint
	Links       []string
	VolumesFrom []VolumeFrom  `json:"volumesFrom"`
	MountPoints []MountPoint  `json:"mountPoints"`
	Ports       []PortBinding `json:"portMappings"`
	Essential   bool
	EntryPoint  *[]string
	Environment map[string]string  `json:"environment"`
	Overrides   ContainerOverrides `json:"overrides"`

	DesiredStatus ContainerStatus `json:"desiredStatus"`
	KnownStatus   ContainerStatus

	// RunDependencies is a list of containers that must be run before
	// this one is created
	RunDependencies []string
	// 'Internal' containers are ones that are not directly specified by task definitions, but created by the agent
	IsInternal bool

	AppliedStatus ContainerStatus
	// ApplyingError is an error that occured trying to transition the container to its desired state
	// It is propagated to the backend in the form 'Name: ErrorString' as the 'reason' field.
	ApplyingError *DefaultNamedError

	SentStatus ContainerStatus

	KnownExitCode     *int
	KnownPortBindings []PortBinding

	// Not upstream; todo move this out into a wrapper type
	StatusLock sync.Mutex
}

func (*Container) DesiredTerminal

func (c *Container) DesiredTerminal() bool

func (*Container) KnownTerminal

func (c *Container) KnownTerminal() bool

func (*Container) Overridden

func (c *Container) Overridden() *Container

Overriden returns

func (*Container) String

func (c *Container) String() string

type ContainerOverrides

type ContainerOverrides struct {
	Command *[]string `json:"command"`
}

func (*ContainerOverrides) UnmarshalJSON

func (overrides *ContainerOverrides) UnmarshalJSON(b []byte) error

This custom unmarshaller is needed because the json sent to us as a string rather than a fully typed object. We support both formats in the hopes that one day everything will be fully typed Note: the `json:",string"` tag DOES NOT apply here; it DOES NOT work with struct types, only ints/floats/etc. We're basically doing that though We also intentionally fail if there are any keys we were unable to unmarshal into our struct

type ContainerOverridesCopy

type ContainerOverridesCopy ContainerOverrides

A type alias that doesn't have a custom unmarshaller so we can unmarshal into something without recursing

type ContainerStateChange

type ContainerStateChange struct {
	TaskArn       string
	ContainerName string
	Status        ContainerStatus

	Reason       string
	ExitCode     *int
	PortBindings []PortBinding

	// This bit is a little hacky; a pointer to the container's sentstatus which
	// may be updated to indicate what status was sent. This is used to ensure
	// the same event is handled only once.
	SentStatus *ContainerStatus
}

type ContainerStatus

type ContainerStatus int32
const (
	ContainerStatusNone ContainerStatus = iota
	ContainerPulled
	ContainerCreated
	ContainerRunning
	ContainerStopped

	ContainerZombie // Impossible status to use as a virtual 'max'
)

func (*ContainerStatus) BackendRecognized added in v1.1.0

func (cs *ContainerStatus) BackendRecognized() bool

func (*ContainerStatus) MarshalJSON

func (cs *ContainerStatus) MarshalJSON() ([]byte, error)

func (*ContainerStatus) String

func (cs *ContainerStatus) String() string

func (*ContainerStatus) TaskStatus

func (cs *ContainerStatus) TaskStatus() TaskStatus

func (*ContainerStatus) Terminal

func (cs *ContainerStatus) Terminal() bool

func (*ContainerStatus) UnmarshalJSON

func (cs *ContainerStatus) UnmarshalJSON(b []byte) error

type DefaultNamedError added in v1.1.0

type DefaultNamedError struct {
	Err  string `json:"error"`
	Name string `json:"name"`
}

NamedError is a wrapper type for 'error' which adds an optional name and provides a symetric marshal/unmarshal

func NewNamedError added in v1.1.0

func NewNamedError(err error) *DefaultNamedError

NewNamedError creates a NamedError.

func (*DefaultNamedError) Error added in v1.1.0

func (err *DefaultNamedError) Error() string

Error implements error

func (*DefaultNamedError) ErrorName added in v1.1.0

func (err *DefaultNamedError) ErrorName() string

ErrorName implements NamedError

type DockerClientConfigError added in v1.1.0

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

func (*DockerClientConfigError) Error added in v1.1.0

func (err *DockerClientConfigError) Error() string

func (*DockerClientConfigError) ErrorName added in v1.1.0

func (err *DockerClientConfigError) ErrorName() string

type DockerContainer

type DockerContainer struct {
	DockerId   string
	DockerName string // needed for linking

	Container *Container
}

This is a mapping between containers-as-docker-knows-them and containers-as-we-know-them. This is primarily used in DockerState, but lives here such that tasks and containers know how to convert themselves into Docker's desired config format

func (*DockerContainer) String

func (dc *DockerContainer) String() string

type ECSClient

type ECSClient interface {
	// RegisterContainerInstance calculates the appropriate resources, creates
	// the default cluster if necessary, and returns the registered
	// ContainerInstanceARN if successful.
	RegisterContainerInstance() (string, error)
	// SubmitTaskStateChange sends a state change and returns an error
	// indicating if it was submitted
	SubmitTaskStateChange(change TaskStateChange) utils.RetriableError
	// SubmitContainerStateChange sends a state change and returns an error
	// indicating if it was submitted
	SubmitContainerStateChange(change ContainerStateChange) utils.RetriableError
	// DiscoverPollEndpoint takes a ContainerInstanceARN and returns the
	// endpoint at which this Agent should contact ACS
	DiscoverPollEndpoint(containerInstanceArn string) (string, error)
}

ECSClient is an interface over the ECSSDK interface which abstracts away some details around constructing the request and reading the response down to the parts the agent cares about. For example, the ever-present 'Cluster' member is abstracted out so that it may be configured once and used throughout transparently.

func NewECSClient

func NewECSClient(credentialProvider aws.CredentialsProvider, config *config.Config, insecureSkipVerify bool) ECSClient

type ECSSDK added in v1.1.0

ECSSDK is an interface that specifies the subset of the AWS Go SDK's ECS client that the Agent uses. This interface is meant to allow injecting a mock for testing.

type EmptyHostVolume

type EmptyHostVolume struct {
	HostPath string `json:"hostPath"`
}

func (*EmptyHostVolume) SourcePath

func (e *EmptyHostVolume) SourcePath() string

type FSHostVolume

type FSHostVolume struct {
	FSSourcePath string `json:"sourcePath"`
}

FSHostVolume is a simple type of HostVolume which references an arbitrary location on the host as the Volume.

func (*FSHostVolume) SourcePath

func (fs *FSHostVolume) SourcePath() string

SourcePath returns the path on the host filesystem that should be mounted

type HostConfigError added in v1.1.0

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

func (*HostConfigError) Error added in v1.1.0

func (err *HostConfigError) Error() string

func (*HostConfigError) ErrorName added in v1.1.0

func (err *HostConfigError) ErrorName() string

type HostVolume

type HostVolume interface {
	SourcePath() string
}

HostVolume is an interface for something that may be used as the host half of a docker volume mount

type MountPoint

type MountPoint struct {
	SourceVolume  string `json:"sourceVolume"`
	ContainerPath string `json:"containerPath"`
	ReadOnly      bool   `json:"readOnly"`
}

MountPoint describes the in-container location of a Volume and references that Volume by name.

type NamedError added in v1.1.0

type NamedError interface {
	error
	ErrorName() string
}

type PortBinding

type PortBinding struct {
	ContainerPort uint16
	HostPort      uint16
	BindIp        string
}

type Resource

type Resource struct {
	Name        string
	Type        string
	DoubleValue float64
	LongValue   int64
}

type Task

type Task struct {
	Arn        string
	Overrides  TaskOverrides `json:"-"`
	Family     string
	Version    string
	Containers []*Container
	Volumes    []TaskVolume `json:"volumes"`

	DesiredStatus   TaskStatus
	KnownStatus     TaskStatus
	KnownStatusTime time.Time `json:"KnownTime"`

	SentStatus TaskStatus

	StartSequenceNumber int64
	StopSequenceNumber  int64
	// contains filtered or unexported fields
}

func RemoveFromTaskArray

func RemoveFromTaskArray(arr []*Task, ndx int) []*Task

RemoveFromTaskArray removes the element at ndx from an array of task pointers, arr. If the ndx is out of bounds, it returns arr unchanged.

func TaskFromACS added in v1.0.0

func TaskFromACS(acsTask *ecsacs.Task, envelope *ecsacs.PayloadMessage) (*Task, error)

func (*Task) ContainerByName

func (task *Task) ContainerByName(name string) (*Container, bool)

func (*Task) DockerConfig

func (task *Task) DockerConfig(container *Container) (*docker.Config, *DockerClientConfigError)

DockerConfig converts the given container in this task to the format of GoDockerClient's 'Config' struct

func (*Task) DockerHostConfig

func (task *Task) DockerHostConfig(container *Container, dockerContainerMap map[string]*DockerContainer) (*docker.HostConfig, *HostConfigError)

func (*Task) HostVolumeByName

func (task *Task) HostVolumeByName(name string) (HostVolume, bool)

HostVolumeByName returns the task Volume for the given a volume name in that task. The second return value indicates the presense of that volume

func (*Task) Overridden

func (task *Task) Overridden() *Task

Overridden returns a copy of the task with all container's overridden and itself overridden as well

func (*Task) PostUnmarshalTask

func (task *Task) PostUnmarshalTask()

PostUnmarshalTask is run after a task has been unmarshalled, but before it has been run. It is possible it will be subsequently called after that and should be able to handle such an occurrence appropriately (e.g. behave idempotently).

func (*Task) SetKnownStatus added in v1.1.0

func (t *Task) SetKnownStatus(status TaskStatus)

func (*Task) String

func (t *Task) String() string

func (*Task) UpdateDesiredStatus added in v1.1.0

func (t *Task) UpdateDesiredStatus()

func (*Task) UpdateMountPoints

func (task *Task) UpdateMountPoints(cont *Container, vols map[string]string)

func (*Task) UpdateStatus added in v1.1.0

func (t *Task) UpdateStatus() bool

UpdateStatus updates a task's known and desired statuses to be compatible with all of its containers It will return a bool indicating if there was a change

type TaskOverrides

type TaskOverrides struct{}

type TaskStateChange added in v1.1.0

type TaskStateChange struct {
	TaskArn string
	Status  TaskStatus
	Reason  string

	// As above, this is the same sort of hacky.
	// This is a pointer to the task's sent-status that gives the event handler a
	// hook into storing metadata about the task on the task such that it follows
	// the lifecycle of the task and so on.
	SentStatus *TaskStatus
}

type TaskStatus

type TaskStatus int32
const (
	TaskStatusNone TaskStatus = iota
	TaskPulled
	TaskCreated
	TaskRunning
	TaskStopped
)

func (*TaskStatus) BackendRecognized added in v1.1.0

func (ts *TaskStatus) BackendRecognized() bool

func (*TaskStatus) BackendStatus added in v1.0.0

func (ts *TaskStatus) BackendStatus() string

Mapping task status in the agent to that in the backend

func (*TaskStatus) ContainerStatus

func (ts *TaskStatus) ContainerStatus() ContainerStatus

func (*TaskStatus) MarshalJSON

func (ts *TaskStatus) MarshalJSON() ([]byte, error)

func (*TaskStatus) String

func (ts *TaskStatus) String() string

func (*TaskStatus) Terminal

func (ts *TaskStatus) Terminal() bool

func (*TaskStatus) UnmarshalJSON

func (ts *TaskStatus) UnmarshalJSON(b []byte) error

type TaskVolume

type TaskVolume struct {
	Name   string `json:"name"`
	Volume HostVolume
}

TaskVolume is a definition of all the volumes available for containers to reference within a task. It must be named.

func (*TaskVolume) MarshalJSON

func (tv *TaskVolume) MarshalJSON() ([]byte, error)

func (*TaskVolume) UnmarshalJSON

func (tv *TaskVolume) UnmarshalJSON(b []byte) error

UnmarshalJSON for TaskVolume determines the name and volume type, and unmarshals it into the appropriate HostVolume fulfilling interfaces

type VolumeFrom

type VolumeFrom struct {
	SourceContainer string `json:"sourceContainer"`
	ReadOnly        bool   `json:"readOnly"`
}

VolumeFrom is a volume which references another container as its source.

Directories

Path Synopsis
Package testutils contains files that are used in tests but not elsewhere and thus can be excluded from the final executable.
Package testutils contains files that are used in tests but not elsewhere and thus can be excluded from the final executable.

Jump to

Keyboard shortcuts

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