cluster

package
v0.0.0-...-b52e348 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2017 License: Apache-2.0 Imports: 19 Imported by: 2

Documentation

Index

Constants

View Source
const (
	DOCKER_NETWORK = "/docker/networks"
	DOCKER_LOGS    = "/docker/logs"
	HTTP           = "http://"
)
View Source
const (
	DOCKER_REGISTRY  = "registry"
	DOCKER_ZONE      = "region"
	DOCKER_SWARM     = "swarm"
	DOCKER_GULP      = "gulp_port"
	DOCKER_MEMSIZE   = "mem"
	DOCKER_SWAPSIZE  = "swap"
	DOCKER_CPUPERIOD = "cpuperiod"
	DOCKER_CPUQUOTA  = "cpuquota"

	BRIDGE_NAME    = "name"
	BRIDGE_NETWORK = "network"
	BRIDGE_GATEWAY = "gateway"
	BRIDGE_CLUSTER = "cluster_id"
)
View Source
const (
	NodeStatusWaiting  = "waiting"
	NodeStatusReady    = "ready"
	NodeStatusRetry    = "ready for retry"
	NodeStatusDisabled = "disabled"
	NodeStatusHealing  = "healing"

	NodeCreationStatusCreated = "created"
	NodeCreationStatusError   = "error"
	NodeCreationStatusPending = "pending"
)

Variables

View Source
var (
	ErrNoSuchNode            = errors.New("No such node in storage")
	ErrNoSuchContainer       = errors.New("No such container in storage")
	ErrNoSuchImage           = errors.New("No such image in storage")
	ErrDuplicatedNodeAddress = errors.New("Node address shouldn't repeat")
)

Functions

This section is empty.

Types

type Bridge

type Bridge struct {
	ClusterId string
	Name      string
	Network   string
	Gateway   string
}

func (*Bridge) IPRequest

func (b *Bridge) IPRequest(subnet *net.IPNet, pos uint) net.IP

type Bridges

type Bridges []Bridge

type Cluster

type Cluster struct {
	Healer Healer

	VNets map[string]string

	Region string
	// contains filtered or unexported fields
}

Cluster is the basic type of the package. It manages internal nodes, and provide methods for interaction with those nodes, like CreateContainer, which creates a container in one node of the cluster.

func New

func New(storage Storage, nodes ...Node) (*Cluster, error)

New creates a new Cluster, initially composed by the given nodes.

The scheduler parameter defines the scheduling strategy. It defaults to round robin if nil. The storage parameter is the storage the cluster instance will use.

func (*Cluster) AttachToContainer

func (c *Cluster) AttachToContainer(opts docker.AttachToContainerOptions) error

AttachToContainer attaches to a container, using the given options.

func (*Cluster) BuildImage

func (c *Cluster) BuildImage(buildOptions docker.BuildImageOptions) error

BuildImage build an image and pushes it to registry

func (*Cluster) CommitContainer

func (c *Cluster) CommitContainer(opts docker.CommitContainerOptions) (*docker.Image, error)

CommitContainer commits a container and returns the image id.

func (*Cluster) CreateContainer

func (c *Cluster) CreateContainer(opts docker.CreateContainerOptions) (string, *docker.Container, error)

CreateContainer creates a container in the specified node. If no node is specified, it will create the container in a node selected by the scheduler.

It returns the container, or an error, in case of failures.

func (*Cluster) CreateContainerSchedulerOpts

func (c *Cluster) CreateContainerSchedulerOpts(opts docker.CreateContainerOptions) (string, *docker.Container, error)

Similar to CreateContainer but allows arbritary options to be passed to the scheduler.

func (*Cluster) CreateExec

func (c *Cluster) CreateExec(opts docker.CreateExecOptions, region string) (*docker.Exec, error)

func (*Cluster) ExportContainer

func (c *Cluster) ExportContainer(opts docker.ExportContainerOptions) error

ExportContainer exports a container as a tar and writes the result in out.

func (*Cluster) GulpPort

func (c *Cluster) GulpPort() string

func (*Cluster) ImportImage

func (c *Cluster) ImportImage(opts docker.ImportImageOptions) error

ImportImage imports an image from a url or stdin

func (*Cluster) InspectContainer

func (c *Cluster) InspectContainer(id string) (*docker.Container, error)

InspectContainer returns information about a container by its ID, getting the information from the right node.

func (*Cluster) InspectExec

func (c *Cluster) InspectExec(execId, containerId string, region string) (*docker.ExecInspect, error)

func (*Cluster) InspectImage

func (c *Cluster) InspectImage(repo string) (*docker.Image, error)

InspectContainer inspects an image based on its repo name

func (*Cluster) Ips

func (c *Cluster) Ips(ip, CartonId, email string) error

func (*Cluster) KillContainer

func (c *Cluster) KillContainer(opts docker.KillContainerOptions) error

KillContainer kills a container, returning an error in case of failure.

func (*Cluster) ListContainers

func (c *Cluster) ListContainers(opts docker.ListContainersOptions) ([]docker.APIContainers, error)

ListContainers returns a slice of all containers in the cluster matching the given criteria.

func (*Cluster) ListImages

func (c *Cluster) ListImages(opts docker.ListImagesOptions) ([]docker.APIImages, error)

ListImages lists images existing in each cluster node

func (*Cluster) Logs

func (c *Cluster) Logs(opts docker.LogsOptions) error

Logs retrieves the logs of the specified container.

func (*Cluster) Nodes

func (c *Cluster) Nodes() ([]Node, error)

func (*Cluster) NodesForMetadata

func (c *Cluster) NodesForMetadata(metadata map[string]string) ([]Node, error)

func (*Cluster) PauseContainer

func (c *Cluster) PauseContainer(id string) error

PauseContainer changes the container to the paused state.

func (*Cluster) Ports

func (c *Cluster) Ports(ports map[docker.Port][]docker.PortBinding, CartonId, email string) error

func (*Cluster) PreStopAction

func (c *Cluster) PreStopAction(name string) (string, error)

func (*Cluster) PullImage

func (c *Cluster) PullImage(opts docker.PullImageOptions, auth docker.AuthConfiguration, nodes ...string) error

PullImage pulls an image from a remote registry server, returning an error in case of failure.

It will pull all images in parallel, so users need to make sure that the given buffer is safe.

func (*Cluster) PushImage

func (c *Cluster) PushImage(opts docker.PushImageOptions, auth docker.AuthConfiguration) error

PushImage pushes an image to a remote registry server, returning an error in case of failure.

func (*Cluster) Register

func (c *Cluster) Register(node Node) error

Register adds new nodes to the cluster.

func (*Cluster) RemoveContainer

func (c *Cluster) RemoveContainer(opts docker.RemoveContainerOptions) error

RemoveContainer removes a container from the cluster.

func (*Cluster) RemoveFromRegistry

func (c *Cluster) RemoveFromRegistry(imageId string) error

func (*Cluster) RemoveImage

func (c *Cluster) RemoveImage(name string) error

RemoveImage removes an image from the nodes where this images exists, returning an error in case of failure. Will wait for the image to be removed on all nodes.

func (*Cluster) RemoveImageIgnoreLast

func (c *Cluster) RemoveImageIgnoreLast(name string) error

RemoveImageIgnoreLast works similarly to RemoveImage except it won't remove the last built/pulled/commited image.

func (*Cluster) ResizeExecTTY

func (c *Cluster) ResizeExecTTY(execId, containerId string, height, width int, region string) error

func (*Cluster) RestartContainer

func (c *Cluster) RestartContainer(id string, timeout uint) error

RestartContainer restarts a container, killing it after the given timeout, if it fails to stop nicely.

func (*Cluster) SetLogs

func (c *Cluster) SetLogs(cs chan []byte, opts docker.LogsOptions, closechan chan bool) error

func (*Cluster) SetNetworkinNode

func (c *Cluster) SetNetworkinNode(containerId, cartonId, email string) error

func (*Cluster) Showback

func (c *Cluster) Showback(start int64, end int64, point string) ([]interface{}, error)

func (*Cluster) StartContainer

func (c *Cluster) StartContainer(id string, hostConfig *docker.HostConfig) error

func (*Cluster) StartExec

func (c *Cluster) StartExec(execId, containerId string, opts docker.StartExecOptions, region string) error

func (*Cluster) StopContainer

func (c *Cluster) StopContainer(id string, timeout uint) error

StopContainer stops a container, killing it after the given timeout, if it fails to stop nicely.

func (*Cluster) TagImage

func (c *Cluster) TagImage(name string, opts docker.TagImageOptions) error

TagImage adds a tag to the given image, returning an error in case of failure.

func (*Cluster) TopContainer

func (c *Cluster) TopContainer(id string, psArgs string) (docker.TopResult, error)

TopContainer returns information about running processes inside a container by its ID, getting the information from the right node.

func (*Cluster) UnfilteredNodes

func (c *Cluster) UnfilteredNodes() ([]Node, error)

func (*Cluster) UnpauseContainer

func (c *Cluster) UnpauseContainer(id string) error

UnpauseContainer removes the container from the paused state.

func (*Cluster) Unregister

func (c *Cluster) Unregister(address string) error

Unregister removes nodes from the cluster.

func (*Cluster) UpdateNode

func (c *Cluster) UpdateNode(node Node) (Node, error)

func (*Cluster) WaitContainer

func (c *Cluster) WaitContainer(id string) (int, error)

WaitContainer blocks until the given container stops, returning the exit code of the container command.

type Container

type Container struct {
	Id   string
	Host string
}

type ContainerStorage

type ContainerStorage interface {
	StoreContainer(container, host string) error
	RetrieveContainer(container string) (host string, err error)
	RemoveContainer(container string) error
	RetrieveContainers() ([]Container, error)

	StoreContainerByName(container, host string) error
	RetrieveContainerByName(name string) (container string, err error)
}

ContainerStorage provides methods to store and retrieve information about the relation between the node and the container. It can be easily represented as a key-value storage.

The relevant information is: in which host the given container is running?

type DefaultHealer

type DefaultHealer struct{}

func (DefaultHealer) HandleError

func (DefaultHealer) HandleError(node *Node) time.Duration

type DockerClient

type DockerClient struct {
	ContainerName string
	ContainerId   string
	Bridge        string
	IpAddr        string
	Gateway       string
	CartonId      string
	AccountId     string
}

func (*DockerClient) LogsRequest

func (d *DockerClient) LogsRequest(url string, port string) error

func (*DockerClient) NetworkRequest

func (d *DockerClient) NetworkRequest(url, port string) error

type DockerNodeError

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

func (DockerNodeError) BaseError

func (n DockerNodeError) BaseError() error

func (DockerNodeError) Error

func (n DockerNodeError) Error() string

type Gulp

type Gulp struct {
	Port string
}

type Healer

type Healer interface {
	HandleError(node *Node) time.Duration
}

type HealingData

type HealingData struct {
	LockedUntil time.Time
	IsFailure   bool
}

type IPIndex

type IPIndex struct {
	Ip     string
	Subnet string
	Index  uint
}

type Image

type Image struct {
	Repository string
	LastNode   string
	LastId     string
	History    []ImageHistory
}

type ImageHistory

type ImageHistory struct {
	Node    string
	ImageId string
}

type ImageStorage

type ImageStorage interface {
	StoreImage(repo, id, host string) error
	RetrieveImage(repo string) (Image, error)
	RemoveImage(repo, id, host string) error
	RetrieveImages() ([]Image, error)
}

ImageStorage works like ContainerStorage, but stores information about images and hosts.

type MapStorage

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

func (*MapStorage) ExtendNodeLock

func (s *MapStorage) ExtendNodeLock(address string, timeout time.Duration) error

func (*MapStorage) LockNodeForHealing

func (s *MapStorage) LockNodeForHealing(address string, isFailure bool, timeout time.Duration) (bool, error)

func (*MapStorage) RemoveContainer

func (s *MapStorage) RemoveContainer(containerID string) error

func (*MapStorage) RemoveImage

func (s *MapStorage) RemoveImage(repo, id, host string) error

func (*MapStorage) RemoveNode

func (s *MapStorage) RemoveNode(addr string) error

func (*MapStorage) RetrieveContainer

func (s *MapStorage) RetrieveContainer(containerID string) (string, error)

func (*MapStorage) RetrieveContainerByName

func (s *MapStorage) RetrieveContainerByName(Name string) (string, error)

func (*MapStorage) RetrieveContainers

func (s *MapStorage) RetrieveContainers() ([]Container, error)

func (*MapStorage) RetrieveImage

func (s *MapStorage) RetrieveImage(repo string) (Image, error)

func (*MapStorage) RetrieveImages

func (s *MapStorage) RetrieveImages() ([]Image, error)

func (*MapStorage) RetrieveNode

func (s *MapStorage) RetrieveNode(address string) (Node, error)

func (*MapStorage) RetrieveNodes

func (s *MapStorage) RetrieveNodes() ([]Node, error)

func (*MapStorage) RetrieveNodesByMetadata

func (s *MapStorage) RetrieveNodesByMetadata(metadata map[string]string) ([]Node, error)

func (*MapStorage) StoreContainer

func (s *MapStorage) StoreContainer(containerID, hostID string) error

func (*MapStorage) StoreContainerByName

func (s *MapStorage) StoreContainerByName(containerID, Name string) error

func (*MapStorage) StoreImage

func (s *MapStorage) StoreImage(repo, id, host string) error

func (*MapStorage) StoreNode

func (s *MapStorage) StoreNode(node Node) error

func (*MapStorage) UnlockNode

func (s *MapStorage) UnlockNode(address string) error

func (*MapStorage) UpdateNode

func (s *MapStorage) UpdateNode(node Node) error

type Node

type Node struct {
	Address        string
	Healing        HealingData
	Metadata       map[string]string
	Bridges        map[string]map[string]string
	CreationStatus string
}

Node represents a host running Docker. Each node has an Address (in the form <scheme>://<host>:<port>/) and map with arbritary metadata.

func (*Node) CleanMetadata

func (n *Node) CleanMetadata() map[string]string

func (*Node) Client

func (n *Node) Client() (*docker.Client, error)

func (*Node) FailureCount

func (n *Node) FailureCount() int

func (*Node) HasSuccess

func (n *Node) HasSuccess() bool

func (Node) MarshalJSON

func (n Node) MarshalJSON() ([]byte, error)

func (*Node) ResetFailures

func (n *Node) ResetFailures()

func (*Node) Status

func (n *Node) Status() string

type NodeList

type NodeList []Node

func (NodeList) Len

func (a NodeList) Len() int

func (NodeList) Less

func (a NodeList) Less(i, j int) bool

func (NodeList) Swap

func (a NodeList) Swap(i, j int)

type NodeStorage

type NodeStorage interface {
	StoreNode(node Node) error
	RetrieveNodesByMetadata(metadata map[string]string) ([]Node, error)
	RetrieveNodes() ([]Node, error)
	RetrieveNode(address string) (Node, error)
	UpdateNode(node Node) error
	RemoveNode(address string) error
	LockNodeForHealing(address string, isFailure bool, timeout time.Duration) (bool, error)
	ExtendNodeLock(address string, timeout time.Duration) error
	UnlockNode(address string) error
}

type Storage

type Storage interface {
	ContainerStorage
	ImageStorage
	NodeStorage
}

Jump to

Keyboard shortcuts

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