service

package
v0.0.0-...-88aa921 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2015 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Copyright 2014 The Serviced Authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright 2014 The Serviced Authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright 2014 The Serviced Authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrHostInvalid = errors.New("invalid host")
	ErrShutdown    = errors.New("listener shut down")
)
View Source
var (
	ErrUnknownState = errors.New("unknown state")
)

Functions

func AddHost

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

func AddResourcePool

func AddResourcePool(conn client.Connection, pool *pool.ResourcePool) error

func EnsureServiceLock

func EnsureServiceLock(cancel, finish <-chan interface{}, conn client.Connection) error

Attempt to acquire a service lock, ensuring that it is held until the finish channel is closed. Function blocks until the lock is held by someone (not necessarily by us).

func GetActiveHosts

func GetActiveHosts(conn client.Connection, poolID string) ([]string, error)

func GetServiceState

func GetServiceState(conn client.Connection, state *servicestate.ServiceState, serviceID string, stateID string) error

GetServiceState gets a service state

func GetServiceStates

func GetServiceStates(conn client.Connection, serviceIDs ...string) (states []servicestate.ServiceState, err error)

GetServiceStates gets all service states for a particular service

func GetServiceStatus

func GetServiceStatus(conn client.Connection, serviceID string) (map[string]dao.ServiceStatus, error)

GetServiceStatus creates a map of service states to their corresponding status

func InitHostRegistry

func InitHostRegistry(conn client.Connection) error

InitHostRegistry initializes the host registry

func IsServiceLocked

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

IsServiceLocked verifies whether services are locked

func LoadRunningService

func LoadRunningService(conn client.Connection, serviceID, ssID string) (*dao.RunningService, error)

LoadRunningService returns a RunningService object given a coordinator connection

func LoadRunningServices

func LoadRunningServices(conn client.Connection) ([]dao.RunningService, error)

LoadRunningServices gets all RunningServices

func LoadRunningServicesByHost

func LoadRunningServicesByHost(conn client.Connection, hostIDs ...string) ([]dao.RunningService, error)

LoadRunningServicesByHost returns a slice of RunningServices given a host(s)

func LoadRunningServicesByService

func LoadRunningServicesByService(conn client.Connection, serviceIDs ...string) ([]dao.RunningService, error)

LoadRunningServicesByService returns a slice of RunningServices per service id(s)

func MonitorResourcePool

func MonitorResourcePool(shutdown <-chan interface{}, conn client.Connection, poolID string) <-chan *pool.ResourcePool

func NewHostSynchronizer

func NewHostSynchronizer(handler HostSyncHandler, poolID string) *zzk.Synchronizer

NewHostSynchronizer instantiates a new Synchronizer for host data

func NewPoolSynchronizer

func NewPoolSynchronizer(handler PoolSyncHandler, getConnection zzk.GetConnection) *zzk.Synchronizer

NewPoolSynchronizer initializes a new Synchronizer

func NewRunningService

func NewRunningService(service *service.Service, state *servicestate.ServiceState) (*dao.RunningService, error)

NewRunningService instantiates a RunningService object from a given service and service state

func NewServiceSynchronizer

func NewServiceSynchronizer(handler ServiceSyncHandler, poolID string) *zzk.Synchronizer

NewServiceSynchronizer initializes a new Synchronizer for Service data

func RemoveHost

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

func RemoveResourcePool

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

func RemoveService

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

RemoveService deletes a service

func RemoveServiceVhost

func RemoveServiceVhost(conn client.Connection, serviceID, vhostname string) error

RemoveServiceVhost deletes a service vhost

func RemoveServiceVhosts

func RemoveServiceVhosts(conn client.Connection, svc *service.Service) error

RemoveServiceVhosts removes vhosts of a service

func ServiceLock

func ServiceLock(conn client.Connection) client.Lock

ServiceLock initializes a new lock for services

func StartService

func StartService(conn client.Connection, serviceID string) error

StartService schedules a service to start

func StopService

func StopService(conn client.Connection, serviceID string) error

StopService schedules a service to stop

func StopServiceInstance

func StopServiceInstance(conn client.Connection, hostID, stateID string) error

func SyncHosts

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

func SyncResourcePools

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

func SyncServices

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

SyncServices synchronizes all services into zookeeper

func UpdateHost

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

func UpdateResourcePool

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

func UpdateService

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

UpdateService updates a service node if it exists, otherwise creates it

func UpdateServiceState

func UpdateServiceState(conn client.Connection, state *servicestate.ServiceState) error

UpdateServiceState updates a particular service state

func UpdateServiceVhost

func UpdateServiceVhost(conn client.Connection, serviceID, vhostname string) error

UpdateServiceVhost updates a service vhost node if it exists, otherwise creates it

func UpdateServiceVhosts

func UpdateServiceVhosts(conn client.Connection, svc *service.Service) error

UpdateServiceVhosts updates vhosts of a service

func WaitService

func WaitService(shutdown <-chan interface{}, conn client.Connection, serviceID string, desiredState service.DesiredState) error

WaitService waits for a particular service's instances to reach a particular state

func WaitServiceLock

func WaitServiceLock(shutdown <-chan interface{}, conn client.Connection, enabled bool) error

WatchServiceLock waits for a service lock to be enabled/disabled

Types

type HostNode

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

HostNode is the zk node for Host

func (*HostNode) Create

func (node *HostNode) Create(conn client.Connection) error

Create implements zzk.Node

func (*HostNode) GetID

func (node *HostNode) GetID() string

ID implements zzk.Node

func (*HostNode) SetVersion

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

SetVersion implements client.Node

func (*HostNode) Update

func (node *HostNode) Update(conn client.Connection) error

Update implements zzk.Node

func (*HostNode) Version

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

Version implements client.Node

type HostRegistryListener

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

HostRegistryListener watches ephemeral nodes on /registry/hosts and provides information about available hosts

func NewHostRegistryListener

func NewHostRegistryListener() *HostRegistryListener

NewHostRegistryListener instantiates a new HostRegistryListener

func (*HostRegistryListener) Done

func (l *HostRegistryListener) Done()

Done shuts down any running processes outside of the main listener, like l.GetHosts()

func (*HostRegistryListener) GetHosts

func (l *HostRegistryListener) GetHosts() (hosts []*host.Host, err error)

GetHosts returns all of the registered hosts

func (*HostRegistryListener) GetPath

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

GetPath implements zzk.Listener

func (*HostRegistryListener) PostProcess

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

PostProcess implments zzk.Listener

func (*HostRegistryListener) Ready

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

Ready implements zzk.Listener

func (*HostRegistryListener) SetConnection

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

SetConnection implements zzk.Listener

func (*HostRegistryListener) Spawn

func (l *HostRegistryListener) Spawn(shutdown <-chan interface{}, eHostID string)

Spawn listens on the host registry and waits til the node is deleted to unregister

type HostState

type HostState struct {
	HostID         string
	ServiceID      string
	ServiceStateID string
	DesiredState   int
	// contains filtered or unexported fields
}

HostState is the zookeeper node for storing service instance information per host

func NewHostState

func NewHostState(state *servicestate.ServiceState) *HostState

NewHostState instantiates a new HostState node for client.Node

func (*HostState) SetVersion

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

SetVersion implements client.Node

func (*HostState) Version

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

Version inplements client.Node

type HostStateHandler

type HostStateHandler interface {
	AttachService(*service.Service, *servicestate.ServiceState, func(string)) error
	StartService(*service.Service, *servicestate.ServiceState, func(string)) error
	PauseService(*service.Service, *servicestate.ServiceState) error
	ResumeService(*service.Service, *servicestate.ServiceState) error
	StopService(*servicestate.ServiceState) error
}

HostHandler 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) *HostStateListener

NewHostListener instantiates a HostListener object

func (*HostStateListener) Done

func (l *HostStateListener) Done()

Done removes the ephemeral node from the host registry

func (*HostStateListener) GetPath

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

GetPath implements zzk.Listener

func (*HostStateListener) PostProcess

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

PostProcess implements zzk.Listener

func (*HostStateListener) Ready

func (l *HostStateListener) Ready() error

Ready adds an ephemeral node to the host registry

func (*HostStateListener) SetConnection

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

GetConnection implements zzk.Listener

func (*HostStateListener) Spawn

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

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

type HostSyncHandler

type HostSyncHandler interface {
	// GetHostsByPool looks up all host given the pool ID
	GetHostsByPool(string) ([]host.Host, error)
	// AddUpdateHost adds or updates a host
	AddUpdateHost(*host.Host) error
	// RemoteHost removes an existing host
	RemoveHost(string) error
}

HostSyncHandler is the handler for synchronizing local host data

type HostSynchronizer

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

HostSynchronizer is the synchronizer for Host data

func (*HostSynchronizer) AddUpdate

func (l *HostSynchronizer) AddUpdate(id string, node zzk.Node) (string, error)

AddUpdate implements zzk.SyncHandler

func (*HostSynchronizer) Allocate

func (l *HostSynchronizer) Allocate() zzk.Node

Allocate implements zzk.SyncHandler

func (*HostSynchronizer) Delete

func (l *HostSynchronizer) Delete(id string) error

Delete implements zzk.SyncHandler

func (*HostSynchronizer) Done

func (l *HostSynchronizer) Done()

Done implements zzk.Done

func (*HostSynchronizer) GetAll

func (l *HostSynchronizer) GetAll() ([]zzk.Node, error)

GetAll implements zzk.SyncHandler

func (*HostSynchronizer) GetConnection

func (l *HostSynchronizer) GetConnection(path string) (client.Connection, error)

GetConnection implements zzk.SyncHandler

func (*HostSynchronizer) GetPath

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

GetPath implements zzk.SyncHandler

func (*HostSynchronizer) Ready

func (l *HostSynchronizer) Ready() error

Ready implements zzk.SyncHandler

type PoolNode

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

func (*PoolNode) Create

func (node *PoolNode) Create(conn client.Connection) error

Create implements zzk.Node

func (*PoolNode) GetID

func (node *PoolNode) GetID() string

ID implements zzk.Node

func (*PoolNode) SetVersion

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

SetVersion implements client.Node

func (*PoolNode) Update

func (node *PoolNode) Update(conn client.Connection) error

Update implements zzk.Node

func (*PoolNode) Version

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

Version implements client.Node

type PoolSyncHandler

type PoolSyncHandler interface {
	// GetResourcePools gets all resource pools
	GetResourcePools() ([]pool.ResourcePool, error)
	// AddUpdateResourcePool adds or updates a resource pool
	AddUpdateResourcePool(*pool.ResourcePool) error
	// RemoveResourcePool deletes a resource pool
	RemoveResourcePool(string) error
}

PoolSyncHandler is the handler for synchronizing ResourcePool data

type PoolSynchronizer

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

PoolSynchronizer is the synchronizer for ResourcePool data

func (*PoolSynchronizer) AddUpdate

func (l *PoolSynchronizer) AddUpdate(id string, node zzk.Node) (string, error)

AddUpdate implements zzk.SyncHandler

func (*PoolSynchronizer) Allocate

func (l *PoolSynchronizer) Allocate() zzk.Node

Allocate implements zzk.SyncHandler

func (*PoolSynchronizer) Delete

func (l *PoolSynchronizer) Delete(id string) error

Delete implements zzk.SyncHandler

func (*PoolSynchronizer) Done

func (l *PoolSynchronizer) Done()

Done implements zzk.SyncHandler

func (*PoolSynchronizer) GetAll

func (l *PoolSynchronizer) GetAll() ([]zzk.Node, error)

GetAll implements zzk.SyncHandler

func (*PoolSynchronizer) GetConnection

func (l *PoolSynchronizer) GetConnection(path string) (client.Connection, error)

GetConnection implements zzk.SyncHandler

func (*PoolSynchronizer) GetPath

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

GetPath implements zzk.SyncHandler

func (*PoolSynchronizer) Ready

func (l *PoolSynchronizer) Ready() error

Ready implements zzk.SyncHandler

type ServiceHandler

type ServiceHandler interface {
	SelectHost(*service.Service) (*host.Host, error)
}

ServiceHandler handles all non-zookeeper interactions required by the service

type ServiceListener

type ServiceListener struct {
	sync.Mutex
	// contains filtered or unexported fields
}

ServiceListener is the listener for /services

func NewServiceListener

func NewServiceListener(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) 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) 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

type ServiceLockListener

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

func NewServiceLockListener

func NewServiceLockListener() *ServiceLockListener

func (*ServiceLockListener) Done

func (l *ServiceLockListener) Done()

func (*ServiceLockListener) GetPath

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

func (*ServiceLockListener) PostProcess

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

func (*ServiceLockListener) Ready

func (l *ServiceLockListener) Ready() error

func (*ServiceLockListener) SetConnection

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

func (*ServiceLockListener) Spawn

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

type ServiceNode

type ServiceNode struct {
	*service.Service
	// contains filtered or unexported fields
}

ServiceNode is the zookeeper client Node for services

func (*ServiceNode) Create

func (node *ServiceNode) Create(conn client.Connection) error

Create implements zzk.Node

func (*ServiceNode) GetID

func (node *ServiceNode) GetID() string

ID implements zzk.Node

func (*ServiceNode) SetVersion

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

SetVersion implements client.Node

func (*ServiceNode) Update

func (node *ServiceNode) Update(conn client.Connection) error

Update implements zzk.Node

func (*ServiceNode) Version

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

Version implements client.Node

type ServiceStateNode

type ServiceStateNode struct {
	*servicestate.ServiceState
	// contains filtered or unexported fields
}

ServiceStateNode is the zookeeper client node for service states

func (*ServiceStateNode) SetVersion

func (node *ServiceStateNode) SetVersion(version interface{})

SetVersion implements client.Node

func (*ServiceStateNode) Version

func (node *ServiceStateNode) Version() interface{}

Version implements client.Node

type ServiceSyncHandler

type ServiceSyncHandler interface {
	// GetServicesByPool gets all the services for a pool ID
	GetServicesByPool(string) ([]service.Service, error)
	// AddUpdateService adds or updates a service
	AddUpdateService(*service.Service) error
	// RemoveService removes an existing service
	RemoveService(string) error
}

ServiceSyncHandler is the handler for local Service data

type ServiceSynchronizer

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

ServiceSynchonizer is the Synchronizer for Service data

func (*ServiceSynchronizer) AddUpdate

func (l *ServiceSynchronizer) AddUpdate(id string, node zzk.Node) (string, error)

AddUpdate implements zzk.SyncHandler

func (*ServiceSynchronizer) Allocate

func (l *ServiceSynchronizer) Allocate() zzk.Node

Allocate implements zzk.SyncHandler

func (*ServiceSynchronizer) Delete

func (l *ServiceSynchronizer) Delete(id string) error

Delete implements zzk.SyncHandler

func (*ServiceSynchronizer) Done

func (l *ServiceSynchronizer) Done()

Done implements zzk.SyncHandler

func (*ServiceSynchronizer) GetAll

func (l *ServiceSynchronizer) GetAll() ([]zzk.Node, error)

GetAll implements zzk.SyncHandler

func (*ServiceSynchronizer) GetConnection

func (l *ServiceSynchronizer) GetConnection(path string) (client.Connection, error)

GetConnection implements zzk.SyncHandler

func (*ServiceSynchronizer) GetPath

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

GetPath implements zzk.SyncHandler

func (*ServiceSynchronizer) Ready

func (l *ServiceSynchronizer) Ready() error

Ready implements zzk.SyncHandler

type ServiceVhostNode

type ServiceVhostNode struct {
	ServiceID string
	Vhost     string
	// contains filtered or unexported fields
}

ServiceVhostNode is the zookeeper client Node for service vhosts

func (*ServiceVhostNode) Create

func (node *ServiceVhostNode) Create(conn client.Connection) error

Create implements zzk.Node

func (*ServiceVhostNode) GetID

func (node *ServiceVhostNode) GetID() string

GetID implements zzk.Node

func (*ServiceVhostNode) SetVersion

func (node *ServiceVhostNode) SetVersion(version interface{})

SetVersion implements client.Node

func (*ServiceVhostNode) Update

func (node *ServiceVhostNode) Update(conn client.Connection) error

Update implements zzk.Node

func (*ServiceVhostNode) Version

func (node *ServiceVhostNode) Version() interface{}

Version implements client.Node

Jump to

Keyboard shortcuts

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