service

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2015 License: BSD-2-Clause Imports: 13 Imported by: 0

Documentation

Overview

A Go package that provides a layer of abstraction above ECS to introduce the concept of Apps, which have are a collection of services.

Index

Constants

This section is empty.

Variables

View Source
var DefaultDelimiter = "-"
View Source
var ErrUnsuitableLoadBalancer = errors.New("currently assigned load balancer is not suitable for the given exposure")

Functions

This section is empty.

Types

type App

type App struct {
	// The id of the app.
	ID string

	// The name of the app.
	Name string

	// Process that belong to this app.
	Processes []*Process
}

type ECSConfig

type ECSConfig struct {
	// The ECS cluster to create services and task definitions in.
	Cluster string

	// The IAM role to use for ECS services with ELB's attached.
	ServiceRole string

	// VPC controls what subnets to attach to ELB's that are created.
	VPC string

	// The hosted zone id to create internal DNS records in
	ZoneID string

	// The ID of the security group to assign to internal load balancers.
	InternalSecurityGroupID string

	// The ID of the security group to assign to external load balancers.
	ExternalSecurityGroupID string

	// The Subnet IDs to assign when creating internal load balancers.
	InternalSubnetIDs []string

	// The Subnet IDs to assign when creating external load balancers.
	ExternalSubnetIDs []string

	// AWS configuration.
	AWS *aws.Config
}

ECSConfig holds configuration for generating a new ECS backed Manager implementation.

type ECSManager

type ECSManager struct {
	ProcessManager
	// contains filtered or unexported fields
}

ECSManager is an implementation of the ServiceManager interface that is backed by Amazon ECS.

func NewECSManager

func NewECSManager(config ECSConfig) (*ECSManager, error)

NewECSManager returns a new Manager implementation that:

* Creates services with ECS.

func NewLoadBalancedECSManager

func NewLoadBalancedECSManager(config ECSConfig) (*ECSManager, error)

NewLoadBalancedECSManager returns a new Manager implementation that:

* Creates services with ECS. * Creates internal or external ELB's for ECS services. * Creates a CNAME record in route53 under the internal TLD.

func (*ECSManager) Instances

func (m *ECSManager) Instances(ctx context.Context, appID string) ([]*Instance, error)

Instances returns all instances that are currently running, pending or draining.

func (*ECSManager) Remove

func (m *ECSManager) Remove(ctx context.Context, appID string) error

Remove removes any ECS services that belong to this app.

func (*ECSManager) Stop

func (m *ECSManager) Stop(ctx context.Context, instanceID string) error

func (*ECSManager) Submit

func (m *ECSManager) Submit(ctx context.Context, app *App) error

Submit will create an ECS service for each individual process in the App. New task definitions will be created based on the information with each process.

If the app was previously submitted with different process than what are provided, any process types that don't exist in the new release will be removed from ECS. For example, if you previously submitted an app with a `web` and `worker` process, then submit an app with the `web` process, the ECS service for the old `worker` process will be removed.

type Exposure

type Exposure int
const (
	ExposeNone Exposure = iota
	ExposePrivate
	ExposePublic
)

func (Exposure) String

func (e Exposure) String() string

type FakeManager

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

func NewFakeManager

func NewFakeManager() *FakeManager

func (*FakeManager) Instances

func (m *FakeManager) Instances(ctx context.Context, appID string) ([]*Instance, error)

func (*FakeManager) Remove

func (m *FakeManager) Remove(ctx context.Context, appID string) error

func (*FakeManager) Scale

func (m *FakeManager) Scale(ctx context.Context, app string, ptype string, instances uint) error

func (*FakeManager) Stop

func (m *FakeManager) Stop(ctx context.Context, instanceID string) error

func (*FakeManager) Submit

func (m *FakeManager) Submit(ctx context.Context, app *App) error

type Instance

type Instance struct {
	Process *Process

	// The instance ID.
	ID string

	// The State that this Instance is in.
	State string

	// The time that this instance was last updated.
	UpdatedAt time.Time
}

Instance represents an Instance of a Process.

type LBProcessManager

type LBProcessManager struct {
	ProcessManager
	// contains filtered or unexported fields
}

LBProcessManager is an implementation of the ProcessManager interface that creates LoadBalancers when a Process is created.

func (*LBProcessManager) CreateProcess

func (m *LBProcessManager) CreateProcess(ctx context.Context, app *App, p *Process) error

CreateProcess ensures that there is a load balancer for the process, then creates it. It uses the following algorithm:

* Attempt to find existing load balancer. * If the load balancer exists, check that the exposure is appropriate for the process. * If the load balancer's External attribute doesn't match what we want. Delete the process, also deleting the load balancer. * Create the load balancer * Attach it to the process.

func (*LBProcessManager) RemoveProcess

func (m *LBProcessManager) RemoveProcess(ctx context.Context, app string, p string) error

RemoveProcess removes the process then removes the associated LoadBalancer.

type Manager

type Manager interface {
	Scaler

	// Submit submits an app, creating it or updating it as necessary.
	Submit(context.Context, *App) error

	// Remove removes the App.
	Remove(ctx context.Context, app string) error

	// Instance lists the instances of a Process for an app.
	Instances(ctx context.Context, app string) ([]*Instance, error)

	// Stop stops an instance. The scheduler will automatically start a new
	// instance.
	Stop(ctx context.Context, instanceID string) error
}

Manager is an interface for interfacing with Services.

type PortMap

type PortMap struct {
	// The Host port.
	Host *int64

	// The container port.
	Container *int64
}

type Process

type Process struct {
	// The type of process.
	Type string

	// The Image to run.
	Image string

	// The Command to run.
	Command string

	// Environment variables to set.
	Env map[string]string

	// Mapping of host -> container port mappings.
	Ports []PortMap

	// Exposure is the level of exposure for this process.
	Exposure Exposure

	// Instances is the desired instances of this service to run.
	Instances uint

	// The amount of RAM to allocate to this process in bytes.
	MemoryLimit uint

	// The amount of CPU to allocate to this process, out of 1024. Maps to
	// the --cpu-shares flag for docker.
	CPUShares uint

	// A load balancer to attach to the process.
	LoadBalancer string

	// An SSL Cert associated with this process.
	SSLCert string
}

type ProcessManager

type ProcessManager interface {
	Scaler

	// CreateProcess creates a process for the app.
	CreateProcess(ctx context.Context, app *App, process *Process) error

	// RemoveProcess removes a process for the app.
	RemoveProcess(ctx context.Context, app string, process string) error

	// Processes returns all processes for the app.
	Processes(ctx context.Context, app string) ([]*Process, error)
}

ProcessManager is a layer level interface than Manager, that provides direct control over individual processes.

type Scaler

type Scaler interface {
	// Scale scales an app process.
	Scale(ctx context.Context, app string, process string, instances uint) error
}

Jump to

Keyboard shortcuts

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