containersvc

package
v0.8.1 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2017 License: Apache-2.0 Imports: 8 Imported by: 36

Documentation

Index

Constants

View Source
const (
	// The busybox image for unit test.
	TestBusyBoxContainerImage = common.OrgName + "/" + common.SystemName + "-busybox"
)

Variables

View Source
var (
	ErrContainerSvcTooManyTasks   = errors.New("The service has more than one tasks on the same ContainerInstance")
	ErrContainerSvcNoTask         = errors.New("The service has no task on the ContainerInstance")
	ErrInvalidContainerInstanceID = errors.New("InvalidContainerInstanceID")
	ErrInvalidCluster             = errors.New("InvalidCluster")
)

Functions

func GenVolumeSourceForSwarm

func GenVolumeSourceForSwarm(serviceUUID string) string

GenVolumeSourceForSwarm creates the volume mount source for swarm service. https://docs.docker.com/docker-for-aws/persistent-data-volumes/#use-a-unique-volume-per-task-using-ebs. so the volume driver could directly know which volume to mount.

func GenVolumeSourceName

func GenVolumeSourceName(serviceUUID string, index int64) string

GenVolumeSourceName creates the volume source name.

func ParseVolumeSource

func ParseVolumeSource(volName string) (string, int64, error)

ParseVolumeSource parses the volume name. return serviceUUID, task slot, error.

func VolumeSourceHasTaskSlot

func VolumeSourceHasTaskSlot(volName string) bool

VolumeSourceHasTaskSlot checks whether the volume name includes the task slot. Docker swarm could pass the volume name with task slot, such as serviceUUID-1.

Types

type CommonOptions

type CommonOptions struct {
	Cluster        string
	ServiceName    string
	ServiceUUID    string
	ContainerImage string
	Resource       *common.Resources
	LogConfig      *cloudlog.LogConfig
}

type ContainerSvc

type ContainerSvc interface {
	// IsServiceExist checks if service exists. If not exist, return false & nil. If exists, return true & nil.
	// If meets any error, error will be returned.
	IsServiceExist(ctx context.Context, cluster string, service string) (bool, error)
	CreateService(ctx context.Context, opts *CreateServiceOptions) error
	GetServiceStatus(ctx context.Context, cluster string, service string) (*common.ServiceStatus, error)
	// StopService stops the service on the container platform, and waits till all containers are stopped.
	// Expect no error (nil) if service is already stopped or does not exist.
	StopService(ctx context.Context, cluster string, service string) error
	RestartService(ctx context.Context, cluster string, service string, desiredCount int64) error
	// DeleteService deletes the service on the container platform.
	// Expect no error (nil) if service does not exist.
	DeleteService(ctx context.Context, cluster string, service string) error
	// List the active (pending and running) tasks of the service.
	ListActiveServiceTasks(ctx context.Context, cluster string, service string) (serviceTaskIDs map[string]bool, err error)
	GetServiceTask(ctx context.Context, cluster string, service string, containerInstanceID string) (serviceTaskID string, err error)

	// One node (EC2) could crash at any time. So the task needs to be reentrant.
	// The container orchestration framework, such as ECS, usually does not retry the
	// task automatically, when a taks fails. The caller needs to check the task status
	// and decide whether to retry.
	// It may not be easy to know the task failure reason clearly.
	// For example, ECS task will reach the stopped status at many conditions,
	// http://docs.aws.amazon.com/AmazonECS/latest/developerguide/task_life_cycle.html.
	// The Task.StoppedReason records the detail reason,
	// http://docs.aws.amazon.com/AmazonECS/latest/developerguide/troubleshooting.html#stopped-task-errors.
	//
	// The caller could check whether a task succeeds or not by checking
	// both TaskStatus.Status and TaskStatus.StoppedReason. This does not sounds the best
	// option. It would be better that ECS could add the explicit task failure status.
	//
	// The other option is the task updates the status somewhere at the end,
	// and the caller could check that status to decide whether the task needs to be retried.
	// For example, the MongoDB init task will set the service initialized in the control plane.
	RunTask(ctx context.Context, opts *RunTaskOptions) (taskID string, err error)
	GetTaskStatus(ctx context.Context, cluster string, taskID string) (*common.TaskStatus, error)
	DeleteTask(ctx context.Context, cluster string, service string, taskType string) error
}

ContainerSvc defines the cluster, service and task related functions

type CreateServiceOptions

type CreateServiceOptions struct {
	Common        *CommonOptions
	ContainerPath string // The mount path inside container
	PortMappings  []common.PortMapping
	Replicas      int64
	// the placement constraints. If not specified, spread to all zones.
	Place  *Placement
	Envkvs []*common.EnvKeyValuePair
}

type Info

type Info interface {
	GetLocalContainerInstanceID() string
	GetContainerClusterID() string
}

Info defines the operations for the container related info

type MemContainerSvc

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

func NewMemContainerSvc

func NewMemContainerSvc() *MemContainerSvc

func (*MemContainerSvc) AddServiceTask

func (m *MemContainerSvc) AddServiceTask(ctx context.Context, cluster string, service string, taskID string, containerInstanceID string) error

func (*MemContainerSvc) CreateService

func (m *MemContainerSvc) CreateService(ctx context.Context, opts *CreateServiceOptions) error

func (*MemContainerSvc) DeleteService

func (m *MemContainerSvc) DeleteService(ctx context.Context, cluster string, service string) error

func (*MemContainerSvc) DeleteTask

func (m *MemContainerSvc) DeleteTask(ctx context.Context, cluster string, service string, taskType string) error

func (*MemContainerSvc) GetServiceStatus

func (m *MemContainerSvc) GetServiceStatus(ctx context.Context, cluster string, service string) (*common.ServiceStatus, error)

func (*MemContainerSvc) GetServiceTask

func (m *MemContainerSvc) GetServiceTask(ctx context.Context, cluster string, service string, containerInstanceID string) (taskID string, err error)

func (*MemContainerSvc) GetTaskStatus

func (m *MemContainerSvc) GetTaskStatus(ctx context.Context, cluster string, taskID string) (*common.TaskStatus, error)

func (*MemContainerSvc) IsServiceExist

func (m *MemContainerSvc) IsServiceExist(ctx context.Context, cluster string, service string) (bool, error)

func (*MemContainerSvc) ListActiveServiceTasks

func (m *MemContainerSvc) ListActiveServiceTasks(ctx context.Context, cluster string, service string) (taskIDs map[string]bool, err error)

func (*MemContainerSvc) RestartService

func (m *MemContainerSvc) RestartService(ctx context.Context, cluster string, service string, desiredCount int64) error

func (*MemContainerSvc) RunTask

func (m *MemContainerSvc) RunTask(ctx context.Context, opts *RunTaskOptions) (taskID string, err error)

func (*MemContainerSvc) StopService

func (m *MemContainerSvc) StopService(ctx context.Context, cluster string, service string) error

type MockContainerSvcInfo

type MockContainerSvcInfo struct {
}

func NewMockContainerSvcInfo

func NewMockContainerSvcInfo() *MockContainerSvcInfo

func (*MockContainerSvcInfo) GetContainerClusterID

func (m *MockContainerSvcInfo) GetContainerClusterID() string

func (*MockContainerSvcInfo) GetLocalContainerInstanceID

func (m *MockContainerSvcInfo) GetLocalContainerInstanceID() string

type Placement added in v0.8.1

type Placement struct {
	Zones []string
}

type RunTaskOptions

type RunTaskOptions struct {
	Common   *CommonOptions
	TaskType string
	Envkvs   []*common.EnvKeyValuePair
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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