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: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DOCKER_NETWORK = "/docker/networks"
	DOCKER_LOGS    = "/docker/logs"
	HTTP           = "http://"
)
View Source
const (
	RANCHER_REGISTRY = "registry"
	RANCHER_ZONE     = "region"
	RANCHER_SERVER   = "rancher"

	RANCHER_MEMSIZE   = "mem"
	RANCHER_SWAPSIZE  = "swap"
	RANCHER_CPUPERIOD = "cpuperiod"
	RANCHER_CPUQUOTA  = "cpuquota"

	ADMIN_ID  = "admin_id"
	ACCESSKEY = "access_key"
	SECRETKEY = "secret_key"

	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)

func (*Cluster) CreateContainerSchedulerOpts

func (c *Cluster) CreateContainerSchedulerOpts(opts client.Container) (string, *client.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 (c *Cluster) CreateContainer(opts docker.CreateContainerOptions) (string, *docker.Container, error) {
	return c.CreateContainerSchedulerOpts(opts)
}

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

func (*Cluster) GetContainerById

func (c *Cluster) GetContainerById(id string) (*client.Container, error)

func (*Cluster) IpNode

func (c *Cluster) IpNode(contIp, nodeIp, CartonId, email string) error

func (*Cluster) Nodes

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

func (*Cluster) NodesForMetadata

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

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 *client.Container) error

RemoveContainer removes a container from the cluster.

func (*Cluster) SetNetworkinNode

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

func (*Cluster) StartContainer

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

func (*Cluster) StopContainer

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

func (*Cluster) UnfilteredNodes

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

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)

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)
}

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 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
}
func (s *MapStorage) StoreImage(repo, id, host string) error {
	s.iMut.Lock()
	defer s.iMut.Unlock()
	if s.iMap == nil {
		s.iMap = make(map[string]*Image)
	}
	img, _ := s.iMap[repo]
	if img == nil {
		img = &Image{Repository: repo, History: []ImageHistory{}}
		s.iMap[repo] = img
	}
	hasId := false
	for _, entry := range img.History {
		if entry.ImageId == id && entry.Node == host {
			hasId = true
			break
		}
	}
	if !hasId {
		img.History = append(img.History, ImageHistory{Node: host, ImageId: id})
	}
	img.LastNode = host
	img.LastId = id
	return nil
}
func (s *MapStorage) RetrieveImage(repo string) (Image, error) {
	s.iMut.Lock()
	defer s.iMut.Unlock()
	image, ok := s.iMap[repo]
	if !ok {
		return Image{}, ErrNoSuchImage
	}
	if len(image.History) == 0 {
		return Image{}, ErrNoSuchImage
	}
	return *image, nil
}
func (s *MapStorage) RemoveImage(repo, id, host string) error {
	s.iMut.Lock()
	defer s.iMut.Unlock()
	image, ok := s.iMap[repo]
	if !ok {
		return ErrNoSuchImage
	}
	newHistory := []ImageHistory{}
	for _, entry := range image.History {
		if entry.ImageId != id || entry.Node != host {
			newHistory = append(newHistory, entry)
		}
	}
	image.History = newHistory
	return nil
}
func (s *MapStorage) RetrieveImages() ([]Image, error) {
	s.iMut.Lock()
	defer s.iMut.Unlock()
	images := make([]Image, 0, len(s.iMap))
	for _, img := range s.iMap {
		images = append(images, *img)
	}
	return images, nil
}

type ImageStorage

type ImageStorage interface {
}

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) 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) 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) 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) 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 RancherNodeError

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

func (RancherNodeError) BaseError

func (n RancherNodeError) BaseError() error

func (RancherNodeError) Error

func (n RancherNodeError) Error() string

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