service

package
v0.0.0-...-1c5d739 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2023 License: Apache-2.0 Imports: 22 Imported by: 18

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNoAssignedHost is returned when the call expects the virtual IP to
	// already be assigned to a host
	ErrNoAssignedHost = errors.New("unable to find assigned host")

	// ErrAlreadyAssigned is returned when the call expects the virtual IP is not
	// already assigned to a host
	ErrAlreadyAssigned = errors.New("virtual IP has already been assigned")
)
View Source
var ErrInstanceNotFound = errors.New("instance is not scheduled to a host")
View Source
var ErrInvalidIPID = errors.New("invalid ip id")

ErrInvalidIPID is an error that is returned when the ip id value is not parseable.

View Source
var ErrInvalidStateID = errors.New("invalid state id")

ErrInvalidStateID is an error that is returned when a state id value is not parseable.

View Source
var ErrNoHosts = errors.New("there are no hosts to select")

ErrNoHosts is returned when a strategy is given no hosts to select.

Functions

func AddHost

func AddHost(conn client.Connection, h host.Host) error

AddHost creates the host if it doesn't already exist. (uses a pool-based connection)

func CleanHostStates

func CleanHostStates(conn client.Connection, poolID, hostID string) error

CleanHostStates deletes host states with invalid state ids or incongruent data.

func CleanServiceStates

func CleanServiceStates(conn client.Connection, poolID, serviceID string) error

CleanServiceStates deletes service states with invalid state ids or incongruent data.

func CreateIP

func CreateIP(conn client.Connection, req IPRequest, netmask, iface string) error

CreateIP adds a new ip for pool and the host

func CreateState

func CreateState(conn client.Connection, req StateRequest) error

CreateState creates a new service state and host state

func DeleteHostStates

func DeleteHostStates(conn client.Connection, poolID, hostID string) (count int)

DeleteHostStates returns the number of states deleted from a host

func DeleteHostStatesWhen

func DeleteHostStatesWhen(conn client.Connection, poolID, hostID string, when func(*State) bool) (count int)

DeleteHostStatesWhen returns the number of states deleted from a host when the state satisfies a particular condition.

func DeleteIP

func DeleteIP(conn client.Connection, req IPRequest) error

DeleteIP removes the ip from the pool and the host

func DeleteServiceStates

func DeleteServiceStates(conn client.Connection, poolID, serviceID string) (count int)

DeleteServiceStates returns the number of states deleted from a service

func DeleteState

func DeleteState(conn client.Connection, req StateRequest) error

DeleteState removes the service state and host state

func GetCurrentHosts

func GetCurrentHosts(conn client.Connection, poolid string) ([]string, error)

GetCurrentHosts returns the list of hosts that are currently active in a resource pool.

func GetHostID

func GetHostID(conn client.Connection, poolID string, address string) (string, error)

GetHostID returns the signed host ID for a virtual IP or and err if it is not assigned.

func GetRegisteredHostsForPool

func GetRegisteredHostsForPool(conn client.Connection, poolID string) ([]host.Host, error)

func GetServiceStateHostID

func GetServiceStateHostID(conn client.Connection, poolID, serviceID string, instanceID int) (string, error)

GetServiceStateHostID returns the hostid of the matching service state

func IsHostOnline

func IsHostOnline(conn client.Connection, poolid, hostid string) (bool, error)

IsHostOnline returns true if a provided host is currently active.

func IsServiceLocked

func IsServiceLocked(conn client.Connection) (bool, error)

IsServiceLocked verifies whether services are locked

func IsValidState

func IsValidState(conn client.Connection, req StateRequest) (bool, error)

IsValidState returns true if both the service state and host state exists.

func LockServices

func LockServices(conn client.Connection, svcs []ServiceLockNode) error

LockServices locks a group of services

func ParseIPID

func ParseIPID(ipid string) (hostid string, ipaddress string, err error)

ParseIPID returns the host and ip address from a given IP id

func ParseStateID

func ParseStateID(stateID string) (string, string, int, error)

ParseStateID returns the host, service, and instance id from the given state id

func RegisterHost

func RegisterHost(cancel <-chan interface{}, conn client.Connection, hostid string) error

RegisterHost persists a registered host to the coordinator. This is managed by the worker node, so it is expected that the connection will be pre-loaded with the path to the resource pool.

func RemoveHost

func RemoveHost(cancel <-chan struct{}, conn client.Connection, poolID, hostID string) error

RemoveHost removes an existing host, after waiting for existing states to shutdown.

func RemoveResourcePool

func RemoveResourcePool(conn client.Connection, poolid string) error

RemoveResourcePool removes the resource pool

func RemoveService

func RemoveService(conn client.Connection, poolID, serviceID string) error

RemoveService deletes a service if the service has no running states

func ServiceLock

func ServiceLock(conn client.Connection) (client.Lock, error)

ServiceLock initializes a new lock for services

func SortStateRequests

func SortStateRequests(reqs []StateRequest)

SortStateRequest sorts a list of state requests by instance id

func StartPoolListener

func StartPoolListener(shutdown <-chan interface{}, connection client.Connection)

func SyncHosts

func SyncHosts(conn client.Connection, hosts []host.Host) error

SyncHosts synchronizes the hosts to the provided list (uses a pool-based connection)

func SyncResourcePools

func SyncResourcePools(conn client.Connection, pools []pool.ResourcePool) error

SyncResourcePools synchronizes the resource pools to the provided list

func SyncServices

func SyncServices(conn client.Connection, svcs []service.Service) error

SyncServices synchronizes the services to the provided list (uses a pool- based connection)

func UnlockServices

func UnlockServices(conn client.Connection, svcs []ServiceLockNode) error

UnlockServices unlocks a group of services

func UpdateHost

func UpdateHost(conn client.Connection, h host.Host) error

UpdateHost updates an existing host. (uses a pool-based connection)

func UpdateIP

func UpdateIP(conn client.Connection, req IPRequest, mutate func(*IP) bool) error

UpdateIP updates the ip for the pool and the host

func UpdateResourcePool

func UpdateResourcePool(conn client.Connection, p pool.ResourcePool) error

UpdateResourcePool creates the resource pool if it doesn't exist or updates it if it does exist.

func UpdateService

func UpdateService(conn client.Connection, svc *service.Service, setLockOnCreate, setLockOnUpdate bool) error

UpdateService creates the service if it doesn't exist or updates it if it does exist. (uses a pool-based connection)

func UpdateServices

func UpdateServices(conn client.Connection, svcs []*service.Service, setLockOnCreate, setLockOnUpdate bool) error

UpdateServices creates the services if they doesn't exist or updates it if it does exist. (uses a pool-based connection). All svcs MUST be in the same pool

func UpdateState

func UpdateState(conn client.Connection, req StateRequest, mutate func(*State) bool) error

UpdateState updates the service state and host state

func WaitInstance

func WaitInstance(cancel <-chan struct{}, conn client.Connection, poolID, serviceID string, instanceID int, checkState func(s *State, exists bool) bool) error

WaitInstance waits for an instance of a service to satisfy a particular state

func WaitService

func WaitService(cancel <-chan struct{}, conn client.Connection, poolID, serviceID string, checkCount func(count int) bool, checkState func(s *State, exists bool) bool) error

WaitService waits for all of a service's instances to satisfy a particular state.

Types

type AssignmentHandler

type AssignmentHandler interface {
	Assign(poolID, ipAddress, netmask, binding string) error
	Unassign(poolID, ipAddress string) error
}

AssignmentHandler is used to assign, unassign, and watch virtual IP assignments to hosts

type CurrentStateContainer

type CurrentStateContainer struct {
	Status service.InstanceCurrentState
	// contains filtered or unexported fields
}

func (*CurrentStateContainer) SetVersion

func (s *CurrentStateContainer) SetVersion(version interface{})

func (*CurrentStateContainer) Version

func (s *CurrentStateContainer) Version() interface{}

type DefaultRegisteredHostHandler

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

func (*DefaultRegisteredHostHandler) GetRegisteredHosts

func (h *DefaultRegisteredHostHandler) GetRegisteredHosts(pool string) ([]host.Host, error)

type ErrLockServiceFailure

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

func NewLockServiceFailure

func NewLockServiceFailure(serviceid, pool string, err error) ErrLockServiceFailure

func NewUnlockServiceFailure

func NewUnlockServiceFailure(serviceid, pool string, err error) ErrLockServiceFailure

func (ErrLockServiceFailure) Error

func (e ErrLockServiceFailure) Error() string

type ExportBinding

type ExportBinding struct {
	Application        string
	Protocol           string
	PortNumber         uint16
	AssignedPortNumber uint16
}

ExportBinding describes an export endpoint

type HostIP

type HostIP struct {
	Netmask       string
	BindInterface string
	// contains filtered or unexported fields
}

HostIP describes to the delegate how to set up the virtual ip

func (*HostIP) SetVersion

func (ip *HostIP) SetVersion(version interface{})

SetVersion implements client.Node

func (*HostIP) Version

func (ip *HostIP) Version() interface{}

Version implements client.Node

type HostIPHandler

type HostIPHandler interface {
	// Bind adds a virtual ip to an interface. If the interface is already
	// bound then this command returns nil.
	BindIP(ip, netmask, iface string) error

	// Release removes a virtual ip from an interface.  If the interface doesn't
	// exist, then this command returns nil.
	ReleaseIP(ip string) error
}

HostIPHandler is the handler for running the HostIPListener.

type HostIPListener

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

HostIPListener is the listener for monitoring virtual ips.

func NewHostIPListener

func NewHostIPListener(hostid string, handler HostIPHandler, binds []string) *HostIPListener

NewHostIPListener instantiates a new host ip listener.

func (*HostIPListener) Exited

func (l *HostIPListener) Exited()

Exited implements zzk.Listener2. It manages cleanup for the host ip

func (*HostIPListener) Listen

func (l *HostIPListener) Listen(cancel <-chan interface{}, conn client.Connection)

Listen implements zzk.Listener2. It starts the listener for the host ip nodes.

func (*HostIPListener) Path

func (l *HostIPListener) Path() string

Path implements zzk.Spawner. It returns the path to the parent.

func (*HostIPListener) Post

func (l *HostIPListener) Post(p map[string]struct{})

Post synchronizes the passive thread list by unbinding all inactive and orphaned ips.

func (*HostIPListener) Pre

func (l *HostIPListener) Pre()

Pre implements zzk.Spawner. It is the synchronous action that gets called before Spawn.

func (*HostIPListener) SetConn

func (l *HostIPListener) SetConn(conn client.Connection)

SetConn implements zzk.Spawner. It sets the zookeeper connection for the listener.

func (*HostIPListener) Spawn

func (l *HostIPListener) Spawn(cancel <-chan struct{}, ipid string)

Spawn implements zzk.Spawner. It starts a new watcher for the given child node.

type HostNode

type HostNode struct {
	*host.Host
	// contains filtered or unexported fields
}

HostNode is the storage object for host data

func (*HostNode) SetVersion

func (h *HostNode) SetVersion(version interface{})

SetVersion implements client.Node

func (*HostNode) Version

func (h *HostNode) Version() interface{}

Version implements client.Node

type HostRegistryListener

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

HostRegistryListener monitors the availability of hosts within a pool by watching for children within the path /pools/POOLID/hosts/HOSTID/online

func NewHostRegistryListener

func NewHostRegistryListener(poolid string, handler VirtualIPUnassignmentHandler) *HostRegistryListener

NewHostRegistryListener instantiates a new host registry listener

func (*HostRegistryListener) Done

func (h *HostRegistryListener) Done()

func (*HostRegistryListener) GetPath

func (h *HostRegistryListener) GetPath(nodes ...string) string

func (*HostRegistryListener) GetRegisteredHosts

func (h *HostRegistryListener) GetRegisteredHosts(cancel <-chan interface{}) ([]host.Host, error)

GetRegisteredHosts returns a list of hosts that are active. If there are zero active hosts, then it will wait until at least one host is available.

func (*HostRegistryListener) PostProcess

func (h *HostRegistryListener) PostProcess(p map[string]struct{})

func (*HostRegistryListener) Ready

func (h *HostRegistryListener) Ready() error

func (*HostRegistryListener) SetConnection

func (h *HostRegistryListener) SetConnection(conn client.Connection)

func (*HostRegistryListener) Spawn

func (h *HostRegistryListener) Spawn(cancel <-chan interface{}, hostid string)

type HostSelectionStrategy

type HostSelectionStrategy interface {
	Select(hosts []h.Host) (h.Host, error)
}

HostSelectionStrategy represents a selection strategy to choose from a list of hosts

type HostState

type HostState struct {
	DesiredState service.DesiredState
	Scheduled    time.Time
	// contains filtered or unexported fields
}

HostState provides information for a particular instance on host for a service.

func (*HostState) SetVersion

func (s *HostState) SetVersion(version interface{})

SetVersion implements client.Node

func (*HostState) Version

func (s *HostState) Version() interface{}

Version implements client.Node

type HostStateHandler

type HostStateHandler interface {

	// StopsContainer stops the container if the container exists and isn't
	// already stopped.
	StopContainer(serviceID string, instanceID int) error

	// AttachContainer attaches to an existing container for the service
	// instance. Returns nil channel if the container id doesn't match or if
	// the container has stopped. Channel reports the time that the container
	// has stopped.
	AttachContainer(state *ServiceState, serviceID string, instanceID int) (<-chan time.Time, error)

	// StartContainer creates and starts a new container for the given service
	// instance.  It returns relevant information about the container and a
	// channel that triggers when the container has stopped.
	StartContainer(cancel <-chan interface{}, serviceID string, instanceID int) (*ServiceState, <-chan time.Time, error)

	// RestartContainer asynchronously prepulls the latest image before
	// stopping the container.  It only returns an error if there is a problem
	// with docker and not if the container is not running or doesn't exist.
	RestartContainer(cancel <-chan interface{}, serviceID string, instanceID int) error

	// ResumeContainer resumes a paused container.  Returns nil if the
	// container has stopped or if it doesn't exist.
	ResumeContainer(serviceID string, instanceID int) error

	// PauseContainer pauses a running container.  Returns nil if the container
	// has stopped or if it doesn't exist.
	PauseContainer(serviceID string, instanceID int) error
}

HostStateHandler is the handler for running the HostListener

type HostStateListener

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

HostStateListener is the listener for monitoring service instances

func NewHostStateListener

func NewHostStateListener(handler HostStateHandler, hostID string, shutdown <-chan interface{}) *HostStateListener

NewHostStateListener instantiates a HostStateListener object

func (*HostStateListener) Done

func (l *HostStateListener) Done()

Done implements zzk.Listener

func (*HostStateListener) GetPath

func (l *HostStateListener) GetPath(nodes ...string) string

GetPath implements zzk.Listener

func (*HostStateListener) GetShutdownComplete

func (l *HostStateListener) GetShutdownComplete() <-chan interface{}

Used by tests, returns a channel that will be closed when shutdown is complete

func (*HostStateListener) PostProcess

func (l *HostStateListener) PostProcess(p map[string]struct{})

PostProcess implements zzk.Listener This is always called after all threads have been spawned

func (*HostStateListener) Ready

func (l *HostStateListener) Ready() error

Ready implements zzk.Listener

func (*HostStateListener) SetConnection

func (l *HostStateListener) SetConnection(conn client.Connection)

GetConnection implements zzk.Listener

func (*HostStateListener) Spawn

func (l *HostStateListener) Spawn(cancel <-chan interface{}, stateID string)

Spawn listens for changes in the host state and manages running instances

type HostUnassignmentHandler

type HostUnassignmentHandler interface {
	UnassignAll(poolID, hostID string) error
}

HostUnassignmentHandler will handle unassigning the virtual ips that are assigned to a host

type IP

type IP struct {
	PoolIP
	HostIP
	HostID    string
	IPAddress string
}

IP is the concatenation of the PoolIP and HostIP objects

func GetIP

func GetIP(conn client.Connection, req IPRequest) (*IP, error)

GetIP returns the ip data for a given virtual ip

type IPRequest

type IPRequest struct {
	PoolID    string
	HostID    string
	IPAddress string
}

IPRequest provides information for ip CRUD

func (IPRequest) IPID

func (req IPRequest) IPID() string

IPID is the string identifier of the node in zookeeper

type ImportBinding

type ImportBinding struct {
	Application    string
	Purpose        string // import or import_all
	PortNumber     uint16
	PortTemplate   string
	VirtualAddress string
}

ImportBinding describes an import endpoint

func (ImportBinding) GetPortNumber

func (i ImportBinding) GetPortNumber(instanceID int) (uint16, error)

GetPortNumber retrieves a port number for a given instance ID

func (ImportBinding) GetVirtualAddress

func (i ImportBinding) GetVirtualAddress(instanceID int) (string, error)

GetVirtualAddress retrieves the virtual address for a given instance ID

type PoolIP

type PoolIP struct {
	OK bool
	// contains filtered or unexported fields
}

PoolIP provides information about the virtual ip with respect to its state on the host.

func (*PoolIP) SetVersion

func (ip *PoolIP) SetVersion(version interface{})

SetVersion implements client.Node

func (*PoolIP) Version

func (ip *PoolIP) Version() interface{}

Version implements client.Node

type PoolListener

type PoolListener struct {
	Timeout time.Duration
	// contains filtered or unexported fields
}

PoolListener implements zzk.Listener. The PoolListener will watch pool nodes (/pools/poolid) for changes and then sync virtual IP assignments.

func NewPoolListener

func NewPoolListener(synchronizer VirtualIPSynchronizer) *PoolListener

NewPoolListener instantiates a new PoolListener

func (*PoolListener) Done

func (l *PoolListener) Done()

Done is part of the zzk.Listener interface.

func (*PoolListener) GetPath

func (l *PoolListener) GetPath(nodes ...string) string

GetPath returns the path for the pool being watched, /pools/poolid. It is part of the zzk.Listener interface.

func (*PoolListener) PostProcess

func (l *PoolListener) PostProcess(p map[string]struct{})

PostProcess is part of the zzk.Listener interface.

func (*PoolListener) Ready

func (l *PoolListener) Ready() (err error)

Ready is part of the zzk.Listener interface.

func (*PoolListener) SetConnection

func (l *PoolListener) SetConnection(connection client.Connection)

SetConnection sets the ZooKeeper connection. It is part of the zzk.Listener interface.

func (*PoolListener) Spawn

func (l *PoolListener) Spawn(shutdown <-chan interface{}, poolID string)

Spawn watches a pool and syncs its virtual IPs.

type PoolNode

type PoolNode struct {
	*pool.ResourcePool
	// contains filtered or unexported fields
}

PoolNode is the storage object for resource pool data

func (*PoolNode) SetVersion

func (p *PoolNode) SetVersion(version interface{})

SetVersion implements client.Node

func (*PoolNode) Version

func (p *PoolNode) Version() interface{}

Version implements client.Node

type RandomHostSelectionStrategy

type RandomHostSelectionStrategy struct{}

RandomHostSelectionStrategy will randomly pick from one of the provided hosts

func (*RandomHostSelectionStrategy) Select

func (s *RandomHostSelectionStrategy) Select(hosts []h.Host) (h.Host, error)

Select will randomly pick of the provided hosts. If no hosts are given, ErrNoHosts will be returned.

type RegisteredHostHandler

type RegisteredHostHandler interface {
	GetRegisteredHosts(pool string) ([]host.Host, error)
}

RegisteredHostHandler can be used to get hosts that are registered. Calls to get the registered hosts should block until a host comes online. The cancel parameter can be used to stop the call.

func NewRegisteredHostHandler

func NewRegisteredHostHandler(conn client.Connection) RegisteredHostHandler

type ServiceError

type ServiceError struct {
	Action    string
	ServiceID string
	Message   string
}

ServiceError manages service errors

func (ServiceError) Error

func (err ServiceError) Error() string

type ServiceHandler

type ServiceHandler interface {
	SelectHost(*ServiceNode) (string, error)
}

ServiceHandler handles all non-zookeeper interactions required by the service

type ServiceListener

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

ServiceListener is the listener for /services

func NewServiceListener

func NewServiceListener(poolid string, handler ServiceHandler) *ServiceListener

NewServiceListener instantiates a new ServiceListener

func (*ServiceListener) Done

func (l *ServiceListener) Done()

Done implements zzk.Listener

func (*ServiceListener) GetPath

func (l *ServiceListener) GetPath(nodes ...string) string

GetPath implements zzk.Listener

func (*ServiceListener) Pause

func (l *ServiceListener) Pause(reqs []StateRequest) (int, bool)

Pause schedules the service instance as paused and returns the number of affected instances.

func (*ServiceListener) PostProcess

func (l *ServiceListener) PostProcess(p map[string]struct{})

PostProcess implements zzk.Listener

func (*ServiceListener) Ready

func (l *ServiceListener) Ready() (err error)

Ready implements zzk.Listener

func (*ServiceListener) Resume

func (l *ServiceListener) Resume(reqs []StateRequest) (int, bool)

Resume schedules the service instance as run and returns the number of affected instances.

func (*ServiceListener) SetConnection

func (l *ServiceListener) SetConnection(conn client.Connection)

SetConnection implements zzk.Listener

func (*ServiceListener) Spawn

func (l *ServiceListener) Spawn(shutdown <-chan interface{}, serviceID string)

Spawn watches a service and syncs the number of running instances

func (*ServiceListener) Start

func (l *ServiceListener) Start(sn *ServiceNode, instanceID int) bool

Start schedules a service instance

func (*ServiceListener) Stop

func (l *ServiceListener) Stop(reqs []StateRequest) (int, bool)

Stop unschedules the list of service instances and returns the number of instances successfully stopped.

func (*ServiceListener) Sync

func (l *ServiceListener) Sync(isLocked bool, sn *ServiceNode, reqs []StateRequest) (int, bool)

Sync synchronizes the number of running service states and returns the delta of added (>0) or deleted (<0) instances.

type ServiceLockNode

type ServiceLockNode struct {
	PoolID    string
	ServiceID string
}

ServiceLock sets a lock on a group of services

func (ServiceLockNode) Path

func (l ServiceLockNode) Path() string

Path returns the path to the service

type ServiceNode

type ServiceNode struct {
	ID                          string
	Name                        string
	DesiredState                int
	HostPolicy                  servicedefinition.HostPolicy
	Instances                   int
	RAMCommitment               utils.EngNotation
	CPUCommitment               int
	ChangeOptions               []servicedefinition.ChangeOption
	AddressAssignment           addressassignment.AddressAssignment
	ShouldHaveAddressAssignment bool
	//non-service fields
	Locked bool
	// contains filtered or unexported fields
}

ServiceNode is the storage object for service data

func GetServiceNodes

func GetServiceNodes(conn client.Connection) ([]ServiceNode, error)

func NewServiceNodeFromService

func NewServiceNodeFromService(s *service.Service) (*ServiceNode, error)

func (*ServiceNode) SetVersion

func (s *ServiceNode) SetVersion(version interface{})

SetVersion implements client.Node

func (*ServiceNode) Version

func (s *ServiceNode) Version() interface{}

Version implements client.Node

type ServiceState

type ServiceState struct {
	ContainerID string
	ImageUUID   string
	Paused      bool
	PrivateIP   string
	HostIP      string
	AssignedIP  string
	Static      bool
	Imports     []ImportBinding
	Exports     []ExportBinding
	Started     time.Time
	Restarted   time.Time
	Terminated  time.Time
	// contains filtered or unexported fields
}

ServiceState provides information of a service state

func (*ServiceState) SetVersion

func (s *ServiceState) SetVersion(version interface{})

SetVersion implements client.Node

func (*ServiceState) Version

func (s *ServiceState) Version() interface{}

Version implements client.Node

type State

type State struct {
	HostState
	ServiceState
	CurrentStateContainer
	HostID     string
	ServiceID  string
	InstanceID int
}

State is a concatenation of the HostState and ServiceState objects

func GetHostStates

func GetHostStates(conn client.Connection, poolID, hostID string) ([]State, error)

GetHostStates returns the states running on a host

func GetServiceStates

func GetServiceStates(conn client.Connection, poolID, serviceID string) ([]State, error)

GetServiceStates returns the states of a running service

func GetState

func GetState(conn client.Connection, req StateRequest) (*State, error)

GetState returns the service state and host state for a particular instance.

func MonitorState

func MonitorState(cancel <-chan struct{}, conn client.Connection, req StateRequest, check func(s *State, exists bool) bool) (*State, error)

MonitorState returns the state object once it satisfies certain conditions.

type StateError

type StateError struct {
	Request   StateRequest
	Operation string
	Message   string
}

StateError describes an error from a state CRUD operation

func (StateError) Error

func (err StateError) Error() string

type StateRequest

type StateRequest struct {
	PoolID     string
	HostID     string
	ServiceID  string
	InstanceID int
}

StateRequest provides information for service instance CRUD

func GetHostStateIDs

func GetHostStateIDs(conn client.Connection, poolID, hostID string) ([]StateRequest, error)

GetHostStateIDs returns the state ids running on a host

func GetServiceStateIDs

func GetServiceStateIDs(conn client.Connection, poolID, serviceID string) ([]StateRequest, error)

GetServiceStateIDs returns the parsed state ids of a running service

func (StateRequest) StateID

func (req StateRequest) StateID() string

type StateRequests

type StateRequests []StateRequest

StateRequests is a list of StateRequests for purposes of sorting

func (StateRequests) Len

func (reqs StateRequests) Len() int

func (StateRequests) Less

func (reqs StateRequests) Less(i, j int) bool

func (StateRequests) Swap

func (reqs StateRequests) Swap(i, j int)

type SyncError

type SyncError []error

func (SyncError) Error

func (e SyncError) Error() string

type TemplateError

type TemplateError struct {
	Application string
	Field       string
	Message     string
}

func (TemplateError) Error

func (err TemplateError) Error() string

type VirtualIPSynchronizer

type VirtualIPSynchronizer interface {
	Sync(pool p.ResourcePool, assignments map[string]string) error
}

VirtualIPSynchronizer will sync virtual IP assignments for a pool.

type VirtualIPUnassignmentHandler

type VirtualIPUnassignmentHandler interface {
	UnassignAll(poolID, hostID string) error
}

VirtualIPUnassignmentHandler will handle unassigning virtual IPs for a host. UnassignAll should be called when a host is about to go offline.

type ZKAssignmentHandler

type ZKAssignmentHandler struct {
	Timeout time.Duration
	// contains filtered or unexported fields
}

ZKAssignmentHandler implements the AssignmentHandler interface. Assignments are created using ZooKeeper by creating and deleting the appropriate nodes. The following paths are used:

/pools/poolid/ips/hostid-ipaddress
/pools/poolid/hosts/hostid/ips/hostid-ipaddress

func NewZKAssignmentHandler

func NewZKAssignmentHandler(strategy HostSelectionStrategy,
	handler RegisteredHostHandler,
	connection client.Connection) *ZKAssignmentHandler

NewZKAssignmentHandler returns a new ZKAssignmentHandler with the provided dependencies.

func (*ZKAssignmentHandler) Assign

func (h *ZKAssignmentHandler) Assign(poolID, ipAddress, netmask, binding string) error

Assign will assign the provided virtual IP to a host. If an IP is assigned to host there is a 10s timeout until that IP can be assigned to the host again. This prevents spamming of errors. If a IP address is already assigned to a host, ErrAlreadyAssigned will be returned. If no hosts are availd, ErrNoHosts will be returned.

func (*ZKAssignmentHandler) Unassign

func (h *ZKAssignmentHandler) Unassign(poolID, ipAddress string) error

Unassign will unassign a virtual IP if it is currently assigned to a host. ErrNoHostAssigned will be returned if there is no host for the virtual IP when Unassign is called.

type ZKHostUnassignmentHandler

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

ZKHostUnassignmentHandler implements HostUnassignmentHandler. It will remove the nodes in ZooKeeper for a host. The paths affected are the following:

/pools/poolid/hosts/hostid/ips/hostid-ipaddress
/pools/poolid/ips/hostid-ipaddress

func NewZKHostUnassignmentHandler

func NewZKHostUnassignmentHandler(connection client.Connection) *ZKHostUnassignmentHandler

NewZKHostUnassignmentHandler returns a new ZKHostUnassignmentHandler instance.

func (*ZKHostUnassignmentHandler) UnassignAll

func (h *ZKHostUnassignmentHandler) UnassignAll(poolID, hostID string) error

UnassignAll will remove all virtual IP nodes for a host in ZooKeeper.

type ZKPath

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

ZKPath can be used to build slash seperated paths to zookeeper nodes.

func Base

func Base() *ZKPath

Base returns the starting point for a zookeeper path which is a single forward slash.

func (*ZKPath) Hosts

func (p *ZKPath) Hosts() *ZKPath

Hosts appends the node name for hosts to the zookeeper path.

func (*ZKPath) ID

func (p *ZKPath) ID(id string) *ZKPath

ID appends the given id to the zookeeper path. If the string is empty, the method will add nothing to the path. If this behavior is not desired, then checks for a empty string should be done before this method is called.

func (*ZKPath) IPs

func (p *ZKPath) IPs() *ZKPath

IPs appends the node name for IPs to the zookeeper path.

func (*ZKPath) Locked

func (p *ZKPath) Locked() *ZKPath

Locked appends the node name for locked to the zookeeper path.

func (*ZKPath) Online

func (p *ZKPath) Online() *ZKPath

Online appends the node name for online to the zookeeper path.

func (*ZKPath) Path

func (p *ZKPath) Path() string

Path returns the slash seperated string representation for a zookeeper path.

func (*ZKPath) Pools

func (p *ZKPath) Pools() *ZKPath

Pools appends the node name for pools to the zookeeper path.

func (*ZKPath) VirtualIPs

func (p *ZKPath) VirtualIPs() *ZKPath

VirtualIPs appends the node name for virtual IPs to the zookeeper path.

type ZKVirtualIPSynchronizer

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

ZKVirtualIPSynchronizer implements the VirtualIPSynchronizer interface for ZooKeeper.

func NewZKVirtualIPSynchronizer

func NewZKVirtualIPSynchronizer(handler AssignmentHandler) *ZKVirtualIPSynchronizer

NewZKVirtualIPSynchronizer returns a new ZKVirtualIPSynchronizer

func (*ZKVirtualIPSynchronizer) Sync

func (s *ZKVirtualIPSynchronizer) Sync(pool p.ResourcePool, assignments map[string]string) error

Sync will synchronize virtual IP assignments for a pool. It will assign virtual IPs that are not assigned to a host. It will unassign any active assignments if the virtual IP as been removed from the pool.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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