Documentation
¶
Index ¶
- Constants
- func RegisterPlugin(name string, plugin Plugin) error
- type API
- type ConsulClient
- func (cp *ConsulClient) DelObj(key string) error
- func (cp *ConsulClient) DeregisterService(serviceInfo ServiceInfo) error
- func (cp *ConsulClient) GetObj(key string, retVal interface{}) error
- func (cp *ConsulClient) GetService(srvName string) ([]ServiceInfo, error)
- func (cp *ConsulClient) ListDir(key string) ([]string, error)
- func (cp *ConsulClient) NewLock(name string, myID string, ttl uint64) (LockInterface, error)
- func (cp *ConsulClient) RegisterService(serviceInfo ServiceInfo) error
- func (cp *ConsulClient) SetObj(key string, value interface{}) error
- func (cp *ConsulClient) WatchService(srvName string, eventCh chan WatchServiceEvent, stopCh chan bool) error
- type EtcdClient
- func (ep *EtcdClient) DelObj(key string) error
- func (ep *EtcdClient) DeregisterService(serviceInfo ServiceInfo) error
- func (ep *EtcdClient) GetObj(key string, retVal interface{}) error
- func (ep *EtcdClient) GetService(name string) ([]ServiceInfo, error)
- func (ep *EtcdClient) ListDir(key string) ([]string, error)
- func (ep *EtcdClient) NewLock(name string, myID string, ttl uint64) (LockInterface, error)
- func (ep *EtcdClient) RegisterService(serviceInfo ServiceInfo) error
- func (ep *EtcdClient) SetObj(key string, value interface{}) error
- func (ep *EtcdClient) WatchService(name string, eventCh chan WatchServiceEvent, stopCh chan bool) error
- type LockEvent
- type LockInterface
- type Plugin
- type ServiceInfo
- type WatchServiceEvent
Constants ¶
const ( LockAcquired = iota // Successfully acquired LockReleased // explicitly released LockAcquireTimeout // Timeout trying to acquire lock LockAcquireError // Error while acquiring LockRefreshError // Error during ttl refresh LockLost // We lost the lock )
Lock event types
const ( WatchServiceEventAdd = iota // New Service endpoint added WatchServiceEventDel // A service endpoint was deleted WatchServiceEventError // Error occurred while watching for service )
Watch events
Variables ¶
This section is empty.
Functions ¶
func RegisterPlugin ¶
RegisterPlugin Register a plugin
Types ¶
type API ¶
type API interface {
// Get a Key from conf store
GetObj(key string, retValue interface{}) error
// Set a key in conf store
SetObj(key string, value interface{}) error
// Remove an object
DelObj(key string) error
// List all objects in a directory
ListDir(key string) ([]string, error)
// Create a new lock
NewLock(name string, holderID string, ttl uint64) (LockInterface, error)
// Register a service
// Service is registered with a ttl for 60sec and a goroutine is created
// to refresh the ttl.
RegisterService(serviceInfo ServiceInfo) error
// List all end points for a service
GetService(name string) ([]ServiceInfo, error)
// Watch for addition/deletion of service end points
WatchService(name string, eventCh chan WatchServiceEvent, stopCh chan bool) error
// Deregister a service
// This removes the service from the registry and stops the refresh groutine
DeregisterService(serviceInfo ServiceInfo) error
}
API Plugin API
type ConsulClient ¶
type ConsulClient struct {
// contains filtered or unexported fields
}
ConsulClient has consul client state
func (*ConsulClient) DelObj ¶
func (cp *ConsulClient) DelObj(key string) error
DelObj deletes an object
func (*ConsulClient) DeregisterService ¶
func (cp *ConsulClient) DeregisterService(serviceInfo ServiceInfo) error
DeregisterService deregisters a service instance
func (*ConsulClient) GetObj ¶
func (cp *ConsulClient) GetObj(key string, retVal interface{}) error
GetObj reads the object
func (*ConsulClient) GetService ¶
func (cp *ConsulClient) GetService(srvName string) ([]ServiceInfo, error)
GetService gets all instances of a service
func (*ConsulClient) ListDir ¶
func (cp *ConsulClient) ListDir(key string) ([]string, error)
ListDir returns a list of keys in a directory
func (*ConsulClient) NewLock ¶
func (cp *ConsulClient) NewLock(name string, myID string, ttl uint64) (LockInterface, error)
NewLock returns a new lock instance
func (*ConsulClient) RegisterService ¶
func (cp *ConsulClient) RegisterService(serviceInfo ServiceInfo) error
RegisterService registers a service
func (*ConsulClient) SetObj ¶
func (cp *ConsulClient) SetObj(key string, value interface{}) error
SetObj writes an object
func (*ConsulClient) WatchService ¶
func (cp *ConsulClient) WatchService(srvName string, eventCh chan WatchServiceEvent, stopCh chan bool) error
WatchService watches for service instance changes
type EtcdClient ¶
type EtcdClient struct {
// contains filtered or unexported fields
}
EtcdClient has etcd client state
func (*EtcdClient) DeregisterService ¶
func (ep *EtcdClient) DeregisterService(serviceInfo ServiceInfo) error
DeregisterService Deregister a service This removes the service from the registry and stops the refresh groutine
func (*EtcdClient) GetObj ¶
func (ep *EtcdClient) GetObj(key string, retVal interface{}) error
GetObj Get an object
func (*EtcdClient) GetService ¶
func (ep *EtcdClient) GetService(name string) ([]ServiceInfo, error)
GetService lists all end points for a service
func (*EtcdClient) ListDir ¶
func (ep *EtcdClient) ListDir(key string) ([]string, error)
ListDir Get a list of objects in a directory
func (*EtcdClient) NewLock ¶
func (ep *EtcdClient) NewLock(name string, myID string, ttl uint64) (LockInterface, error)
NewLock Create a new lock
func (*EtcdClient) RegisterService ¶
func (ep *EtcdClient) RegisterService(serviceInfo ServiceInfo) error
RegisterService Register a service Service is registered with a ttl for 60sec and a goroutine is created to refresh the ttl.
func (*EtcdClient) SetObj ¶
func (ep *EtcdClient) SetObj(key string, value interface{}) error
SetObj Save an object, create if it doesnt exist
func (*EtcdClient) WatchService ¶
func (ep *EtcdClient) WatchService(name string, eventCh chan WatchServiceEvent, stopCh chan bool) error
WatchService Watch for a service
type LockEvent ¶
type LockEvent struct {
EventType uint // Type of event
}
LockEvent Lock Event notifications
type LockInterface ¶
type LockInterface interface {
// Acquire a lock.
// Give up acquiring lock after timeout seconds. if timeout is 0, wait forever
Acquire(timeout uint64) error
// Release the lock. This explicitly releases the lock and cleans up all state
// If we were still waiting to acquire lock, it stops it and cleans up
Release() error
// For debug purposes only.
// Just stops refreshing the lock
Kill() error
// Get the event channel
EventChan() <-chan LockEvent
// Is the lock acquired
IsAcquired() bool
// Get current holder of the lock
GetHolder() string
}
LockInterface Lock interface
type Plugin ¶
type Plugin interface {
// Initialize the plugin, only called once
NewClient(endpoints []string) (API, error)
}
Plugin interface
type ServiceInfo ¶
type ServiceInfo struct {
ServiceName string // Name of the service
Role string // Role of the service. (leader, follower etc)
Version string // Version string for the service
TTL int // TTL for this service
HostAddr string // Host name or IP address where its running
Port int // Port number where its listening
Hostname string // Host name where its running
}
ServiceInfo hash Information about a service Notes:
There could be multiple instances of a service. hostname:port uniquely identify an instance of a service
type WatchServiceEvent ¶
type WatchServiceEvent struct {
EventType uint // event type
ServiceInfo ServiceInfo // Information about the service
}
WatchServiceEvent : watch event on services