api

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2015 License: Apache-2.0, BSD-2-Clause, BSD-3-Clause, + 1 more Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ECS_SERVICE = "ecs"

	EcsMaxReasonLength = 255

	RoundtripTimeout = 5 * time.Second
)
View Source
const (
	UnrecognizedTransportProtocolErrorName = "UnrecognizedTransportProtocol"
	UnparseablePortErrorName               = "UnparsablePort"
)
View Source
const DOCKER_MINIMUM_MEMORY = 4 * 1024 * 1024 // 4MB
View Source
const INSTANCE_TYPE_CHANGED_ERROR_MESSAGE = "Container instance type changes are not supported."

Variables

This section is empty.

Functions

func IsInstanceTypeChangedError added in v1.3.1

func IsInstanceTypeChangedError(err awserr.Error) bool

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 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) DiscoverTelemetryEndpoint added in v1.2.0

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

func (*ApiECSClient) RegisterContainerInstance

func (client *ApiECSClient) RegisterContainerInstance(containerInstanceArn string, attributes []string) (string, error)

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) SetSubmitStateChangeSDK added in v1.4.0

func (client *ApiECSClient) SetSubmitStateChangeSDK(sdk ECSSubmitStateSDK)

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

func (*ApiECSClient) SubmitContainerStateChange

func (client *ApiECSClient) SubmitContainerStateChange(change ContainerStateChange) error

func (*ApiECSClient) SubmitTaskStateChange

func (client *ApiECSClient) SubmitTaskStateChange(change TaskStateChange) error

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"`
	DockerConfig DockerConfig       `json:"dockerConfig"`

	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
}

func (*ContainerStateChange) String added in v1.3.1

func (c *ContainerStateChange) String() string

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 DockerConfig added in v1.5.0

type DockerConfig struct {
	Config     *string `json:"config"`
	HostConfig *string `json:"hostConfig"`
	Version    *string `json:"version"`
}

DockerConfig represents additional metadata about a container to run. It's remodeled from the `ecsacs` api model file. Eventually it should not exist once this remodeling is refactored out.

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. Supplying a non-empty container
	// instance ARN allows a container instance to update its registered
	// resources.
	RegisterContainerInstance(existingContainerInstanceArn string, attributes []string) (string, error)
	// SubmitTaskStateChange sends a state change and returns an error
	// indicating if it was submitted
	SubmitTaskStateChange(change TaskStateChange) error
	// SubmitContainerStateChange sends a state change and returns an error
	// indicating if it was submitted
	SubmitContainerStateChange(change ContainerStateChange) error
	// DiscoverPollEndpoint takes a ContainerInstanceARN and returns the
	// endpoint at which this Agent should contact ACS
	DiscoverPollEndpoint(containerInstanceArn string) (string, error)
	// DiscoverTelemetryEndpoint takes a ContainerInstanceARN and returns the
	// endpoint at which this Agent should contact Telemetry Service
	DiscoverTelemetryEndpoint(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 *credentials.Credentials, config *config.Config, httpClient *http.Client, ec2MetadataClient ec2.EC2MetadataClient) 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 ECSSubmitStateSDK added in v1.4.0

type ECSSubmitStateSDK interface {
	SubmitContainerStateChange(*ecs.SubmitContainerStateChangeInput) (*ecs.SubmitContainerStateChangeOutput, error)
	SubmitTaskStateChange(*ecs.SubmitTaskStateChangeInput) (*ecs.SubmitTaskStateChangeOutput, error)
}

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
	Protocol      TransportProtocol
}

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
}

func (*TaskStateChange) String added in v1.3.1

func (t *TaskStateChange) String() string

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 TransportProtocol added in v1.2.0

type TransportProtocol int32
const (
	TransportProtocolTCP TransportProtocol = iota
	TransportProtocolUDP
)

func NewTransportProtocol added in v1.2.0

func NewTransportProtocol(protocol string) (TransportProtocol, error)

func (*TransportProtocol) MarshalJSON added in v1.2.0

func (tp *TransportProtocol) MarshalJSON() ([]byte, error)

func (*TransportProtocol) String added in v1.2.0

func (tp *TransportProtocol) String() string

func (*TransportProtocol) UnmarshalJSON added in v1.2.0

func (tp *TransportProtocol) UnmarshalJSON(b []byte) error

UnmarshalJSON for TransportProtocol determines whether to use TCP or UDP, setting TCP as the zero-value but treating other unrecognized values as errors

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