agent

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2014 License: MPL-2.0 Imports: 30 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MinIPCVersion = 1
	MaxIPCVersion = 1
)
View Source
const DefaultBindPort int = 7946

This is the default port that we use for Serf communication

Variables

This section is empty.

Functions

func LevelFilter

func LevelFilter() *logutils.LevelFilter

LevelFilter returns a LevelFilter that is configured with the log levels that we use.

func NewLogWriter added in v0.3.0

func NewLogWriter(buf int) *logWriter

NewLogWriter creates a logWriter with the given buffer capacity

func ValidateLevelFilter

func ValidateLevelFilter(minLevel logutils.LogLevel, filter *logutils.LevelFilter) bool

ValidateLevelFilter verifies that the log levels within the filter are valid.

Types

type Agent

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

Agent starts and manages a Serf instance, adding some niceties on top of Serf such as storing logs that you can later retrieve, and invoking EventHandlers when events occur.

func Create added in v0.3.0

func Create(conf *serf.Config, logOutput io.Writer) (*Agent, error)

Start creates a new agent, potentially returning an error

func (*Agent) DeregisterEventHandler added in v0.3.0

func (a *Agent) DeregisterEventHandler(eh EventHandler)

DeregisterEventHandler removes an EventHandler and prevents more invocations

func (*Agent) ForceLeave added in v0.3.0

func (a *Agent) ForceLeave(node string) error

ForceLeave is used to eject a failed node from the cluster

func (*Agent) Join

func (a *Agent) Join(addrs []string, replay bool) (n int, err error)

Join asks the Serf instance to join. See the Serf.Join function.

func (*Agent) Leave added in v0.3.0

func (a *Agent) Leave() error

Leave prepares for a graceful shutdown of the agent and its processes

func (*Agent) Query added in v0.5.0

func (a *Agent) Query(name string, payload []byte, params *serf.QueryParam) (*serf.QueryResponse, error)

Query sends a Query on Serf, see Serf.Query.

func (*Agent) RegisterEventHandler added in v0.3.0

func (a *Agent) RegisterEventHandler(eh EventHandler)

RegisterEventHandler adds an event handler to recieve event notifications

func (*Agent) Serf

func (a *Agent) Serf() *serf.Serf

Returns the Serf agent of the running Agent.

func (*Agent) SerfConfig

func (a *Agent) SerfConfig() *serf.Config

Returns the Serf config of the running Agent.

func (*Agent) Shutdown

func (a *Agent) Shutdown() error

Shutdown closes this agent and all of its processes. Should be preceeded by a Leave for a graceful shutdown.

func (*Agent) ShutdownCh added in v0.3.0

func (a *Agent) ShutdownCh() <-chan struct{}

ShutdownCh returns a channel that can be selected to wait for the agent to perform a shutdown.

func (*Agent) Start

func (a *Agent) Start() error

Start is used to initiate the event listeners. It is seperate from create so that there isn't a race condition between creating the agent and registering handlers

func (*Agent) UserEvent

func (a *Agent) UserEvent(name string, payload []byte, coalesce bool) error

UserEvent sends a UserEvent on Serf, see Serf.UserEvent.

type AgentIPC added in v0.3.0

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

func NewAgentIPC added in v0.3.0

func NewAgentIPC(agent *Agent, authKey string, listener net.Listener,
	logOutput io.Writer, logWriter *logWriter) *AgentIPC

NewAgentIPC is used to create a new Agent IPC handler

func (*AgentIPC) Shutdown added in v0.3.0

func (i *AgentIPC) Shutdown()

Shutdown is used to shutdown the IPC layer

type AgentMDNS added in v0.4.0

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

AgentMDNS is used to advertise ourself using mDNS and to attempt to join peers periodically using mDNS queries.

func NewAgentMDNS added in v0.4.0

func NewAgentMDNS(agent *Agent, logOutput io.Writer, replay bool,
	node, discover string, iface *net.Interface, bind net.IP, port int) (*AgentMDNS, error)

NewAgentMDNS is used to create a new AgentMDNS

type AppendSliceValue

type AppendSliceValue []string

AppendSliceValue implements the flag.Value interface and allows multiple calls to the same variable to append a list.

func (*AppendSliceValue) Set

func (s *AppendSliceValue) Set(value string) error

func (*AppendSliceValue) String

func (s *AppendSliceValue) String() string

type Command

type Command struct {
	Ui         cli.Ui
	ShutdownCh <-chan struct{}
	// contains filtered or unexported fields
}

Command is a Command implementation that runs a Serf agent. The command will not end unless a shutdown message is sent on the ShutdownCh. If two messages are sent on the ShutdownCh it will forcibly exit.

func (*Command) Help

func (c *Command) Help() string

func (*Command) Run

func (c *Command) Run(args []string) int

func (*Command) Synopsis

func (c *Command) Synopsis() string

type Config

type Config struct {
	// All the configurations in this section are identical to their
	// Serf counterparts. See the documentation for Serf.Config for
	// more info.
	NodeName string `mapstructure:"node_name"`
	Role     string `mapstructure:"role"`

	// Tags are used to attach key/value metadata to a node. They have
	// replaced 'Role' as a more flexible meta data mechanism. For compatibility,
	// the 'role' key is special, and is used for backwards compatibility.
	Tags map[string]string `mapstructure:"tags"`

	// BindAddr is the address that the Serf agent's communication ports
	// will bind to. Serf will use this address to bind to for both TCP
	// and UDP connections. If no port is present in the address, the default
	// port will be used.
	BindAddr string `mapstructure:"bind"`

	// AdvertiseAddr is the address that the Serf agent will advertise to
	// other members of the cluster. Can be used for basic NAT traversal
	// where both the internal ip:port and external ip:port are known.
	AdvertiseAddr string `mapstructure:"advertise"`

	// EncryptKey is the secret key to use for encrypting communication
	// traffic for Serf. The secret key must be exactly 16-bytes, base64
	// encoded. The easiest way to do this on Unix machines is this command:
	// "head -c16 /dev/urandom | base64". If this is not specified, the
	// traffic will not be encrypted.
	EncryptKey string `mapstructure:"encrypt_key"`

	// LogLevel is the level of the logs to output.
	// This can be updated during a reload.
	LogLevel string `mapstructure:"log_level"`

	// RPCAddr is the address and port to listen on for the agent's RPC
	// interface.
	RPCAddr string `mapstructure:"rpc_addr"`

	// RPCAuthKey is a key that can be set to optionally require that
	// RPC's provide an authentication key. This is meant to be
	// a very simple authentication control
	RPCAuthKey string `mapstructure:"rpc_auth"`

	// Protocol is the Serf protocol version to use.
	Protocol int `mapstructure:"protocol"`

	// ReplayOnJoin tells Serf to replay past user events
	// when joining based on a `StartJoin`.
	ReplayOnJoin bool `mapstructure:"replay_on_join"`

	// StartJoin is a list of addresses to attempt to join when the
	// agent starts. If Serf is unable to communicate with any of these
	// addresses, then the agent will error and exit.
	StartJoin []string `mapstructure:"start_join"`

	// EventHandlers is a list of event handlers that will be invoked.
	// These can be updated during a reload.
	EventHandlers []string `mapstructure:"event_handlers"`

	// Profile is used to select a timing profile for Serf. The supported choices
	// are "wan", "lan", and "local". The default is "lan"
	Profile string `mapstructure:"profile"`

	// SnapshotPath is used to allow Serf to snapshot important transactional
	// state to make a more graceful recovery possible. This enables auto
	// re-joining a cluster on failure and avoids old message replay.
	SnapshotPath string `mapstructure:"snapshot_path"`

	// LeaveOnTerm controls if Serf does a graceful leave when receiving
	// the TERM signal. Defaults false. This can be changed on reload.
	LeaveOnTerm bool `mapstructure:"leave_on_terminate"`

	// SkipLeaveOnInt controls if Serf skips a graceful leave when receiving
	// the INT signal. Defaults false. This can be changed on reload.
	SkipLeaveOnInt bool `mapstructure:"skip_leave_on_interrupt"`

	// Discover is used to setup an mDNS Discovery name. When this is set, the
	// agent will setup an mDNS responder and periodically run an mDNS query
	// to look for peers. For peers on a network that supports multicast, this
	// allows Serf agents to join each other with zero configuration.
	Discover string `mapstructure:"discover"`

	// Interface is used to provide a binding interface to use. It can be
	// used instead of providing a bind address, as Serf will discover the
	// address of the provided interface. It is also used to set the multicast
	// device used with `-discover`.
	Interface string `mapstructure:"interface"`

	// ReconnectIntervalRaw is the string reconnect interval time. This interval
	// controls how often we attempt to connect to a failed node.
	ReconnectIntervalRaw string        `mapstructure:"reconnect_interval"`
	ReconnectInterval    time.Duration `mapstructure:"-"`

	// ReconnectTimeoutRaw is the string reconnect timeout. This timeout controls
	// for how long we attempt to connect to a failed node before removing
	// it from the cluster.
	ReconnectTimeoutRaw string        `mapstructure:"reconnect_timeout"`
	ReconnectTimeout    time.Duration `mapstructure:"-"`

	// TombstoneTimeoutRaw is the string tombstone timeout. This timeout controls
	// for how long we remember a left node before removing it from the cluster.
	TombstoneTimeoutRaw string        `mapstructure:"tombstone_timeout"`
	TombstoneTimeout    time.Duration `mapstructure:"-"`

	// By default Serf will attempt to resolve name conflicts. This is done by
	// determining which node the majority believe to be the proper node, and
	// by having the minority node shutdown. If you want to disable this behavior,
	// then this flag can be set to true.
	DisableNameResolution bool `mapstructure:"disable_name_resolution"`
}

Config is the configuration that can be set for an Agent. Some of these configurations are exposed as command-line flags to `serf agent`, whereas many of the more advanced configurations can only be set by creating a configuration file.

func DecodeConfig added in v0.2.0

func DecodeConfig(r io.Reader) (*Config, error)

DecodeConfig reads the configuration from the given reader in JSON format and decodes it into a proper Config structure.

func DefaultConfig added in v0.2.0

func DefaultConfig() *Config

DefaultConfig contains the defaults for configurations.

func MergeConfig added in v0.2.0

func MergeConfig(a, b *Config) *Config

MergeConfig merges two configurations together to make a single new configuration.

func ReadConfigPaths added in v0.2.0

func ReadConfigPaths(paths []string) (*Config, error)

ReadConfigPaths reads the paths in the given order to load configurations. The paths can be to files or directories. If the path is a directory, we read one directory deep and read any files ending in ".json" as configuration files.

func (*Config) AddrParts added in v0.4.0

func (c *Config) AddrParts(address string) (string, int, error)

BindAddrParts returns the parts of the BindAddr that should be used to configure Serf.

func (*Config) EncryptBytes added in v0.2.0

func (c *Config) EncryptBytes() ([]byte, error)

EncryptBytes returns the encryption key configured.

func (*Config) EventScripts

func (c *Config) EventScripts() []EventScript

EventScripts returns the list of EventScripts associated with this configuration and specified by the "event_handlers" configuration.

func (*Config) NetworkInterface added in v0.4.5

func (c *Config) NetworkInterface() (*net.Interface, error)

Networkinterface is used to get the associated network interface from the configured value

type EventFilter added in v0.3.0

type EventFilter struct {
	Event string
	Name  string
}

EventFilter is used to filter which events are processed

func ParseEventFilter added in v0.3.0

func ParseEventFilter(v string) []EventFilter

ParseEventFilter a string with the event type filters and parses it into a series of EventFilters if it can.

func (*EventFilter) Invoke added in v0.3.0

func (s *EventFilter) Invoke(e serf.Event) bool

Invoke tests whether or not this event script should be invoked for the given Serf event.

func (*EventFilter) Valid added in v0.3.0

func (s *EventFilter) Valid() bool

Valid checks if this is a valid agent event script.

type EventHandler

type EventHandler interface {
	HandleEvent(serf.Event)
}

EventHandler is a handler that does things when events happen.

type EventScript

type EventScript struct {
	EventFilter
	Script string
}

EventScript is a single event script that will be executed in the case of an event, and is configured from the command-line or from a configuration file.

func ParseEventScript

func ParseEventScript(v string) []EventScript

ParseEventScript takes a string in the format of "type=script" and parses it into an EventScript struct, if it can.

func (*EventScript) String

func (s *EventScript) String() string

type GatedWriter

type GatedWriter struct {
	Writer io.Writer
	// contains filtered or unexported fields
}

GatedWriter is an io.Writer implementation that buffers all of its data into an internal buffer until it is told to let data through.

func (*GatedWriter) Flush

func (w *GatedWriter) Flush()

Flush tells the GatedWriter to flush any buffered data and to stop buffering.

func (*GatedWriter) Write

func (w *GatedWriter) Write(p []byte) (n int, err error)

type IPCClient added in v0.3.0

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

func (*IPCClient) RegisterQuery added in v0.5.0

func (c *IPCClient) RegisterQuery(q *serf.Query) uint64

RegisterQuery is used to register a pending query that may get a response. The ID of the query is returned

func (*IPCClient) Send added in v0.3.0

func (c *IPCClient) Send(header *responseHeader, obj interface{}) error

send is used to send an object using the MsgPack encoding. send is serialized to prevent write overlaps, while properly buffering.

func (*IPCClient) String added in v0.3.0

func (c *IPCClient) String() string

type LogHandler added in v0.3.0

type LogHandler interface {
	HandleLog(string)
}

LogHandler interface is used for clients that want to subscribe to logs, for example to stream them over an IPC mechanism

type Member added in v0.3.0

type Member struct {
	Name        string
	Addr        net.IP
	Port        uint16
	Tags        map[string]string
	Status      string
	ProtocolMin uint8
	ProtocolMax uint8
	ProtocolCur uint8
	DelegateMin uint8
	DelegateMax uint8
	DelegateCur uint8
}

type MockEventHandler

type MockEventHandler struct {
	Events []serf.Event
	sync.Mutex
}

MockEventHandler is an EventHandler implementation that can be used for tests.

func (*MockEventHandler) HandleEvent

func (h *MockEventHandler) HandleEvent(e serf.Event)

type MockQueryHandler added in v0.5.0

type MockQueryHandler struct {
	Response []byte
	Queries  []*serf.Query
	sync.Mutex
}

MockQueryHandler is an EventHandler implementation used for tests, it always responds to a query with a given response

func (*MockQueryHandler) HandleEvent added in v0.5.0

func (h *MockQueryHandler) HandleEvent(e serf.Event)

type ScriptEventHandler

type ScriptEventHandler struct {
	SelfFunc func() serf.Member
	Scripts  []EventScript
	Logger   *log.Logger
	// contains filtered or unexported fields
}

ScriptEventHandler invokes scripts for the events that it receives.

func (*ScriptEventHandler) HandleEvent

func (h *ScriptEventHandler) HandleEvent(e serf.Event)

func (*ScriptEventHandler) UpdateScripts added in v0.3.0

func (h *ScriptEventHandler) UpdateScripts(scripts []EventScript)

UpdateScripts is used to safely update the scripts we invoke in a thread safe manner

Jump to

Keyboard shortcuts

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