agent

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2013 License: MPL-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultBindPort int = 7946

This is the default port that we use for Serf communication

Variables

View Source
var DefaultConfig = &Config{
	BindAddr: "0.0.0.0",
	LogLevel: "INFO",
	RPCAddr:  "127.0.0.1:7373",
	Protocol: serf.ProtocolVersionMax,
}

DefaultConfig contains the defaults for configurations.

Functions

func LevelFilter

func LevelFilter() *logutils.LevelFilter

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

func ValidateLevelFilter

func ValidateLevelFilter(filter *logutils.LevelFilter) bool

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

Types

type Agent

type Agent struct {
	// EventHandler is what is invoked when an event occurs. If this
	// isn't set, then events aren't handled in any special way.
	EventHandler EventHandler

	// LogOutput is where log messages are written to for the Agent,
	// Serf, and the underlying Memberlist.
	LogOutput io.Writer

	// RPCAddr is the address to bind the RPC listener to.
	RPCAddr string

	// SerfConfig is the configuration of Serf to use. Some settings
	// in here may be overriden by the agent.
	SerfConfig *serf.Config
	// 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, invoking and EventHandler when events occur, and putting an RPC layer in front so that you can query and control the Serf instance remotely.

func (*Agent) Join

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

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

func (*Agent) NotifyLogs

func (a *Agent) NotifyLogs(ch chan<- string) []string

NotifyLogs causes the agent to begin sending log events to the given channel. The return value is a buffer of past events up to a point.

All NotifyLogs calls should be paired with a StopLogs call.

func (*Agent) Serf

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

Returns the Serf agent of the running Agent.

func (*Agent) Shutdown

func (a *Agent) Shutdown() error

Shutdown does a graceful shutdown of this agent and all of its processes.

func (*Agent) Start

func (a *Agent) Start() error

Start starts the agent, kicking off any goroutines to handle various aspects of the agent.

func (*Agent) StopLogs

func (a *Agent) StopLogs(ch chan<- string)

StopLogs causes the agent to stop sending logs to the given channel.

func (*Agent) UserEvent

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

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

type AgentState

type AgentState int
const (
	AgentIdle AgentState = iota
	AgentRunning
)

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 {
	ShutdownCh <-chan struct{}
	Ui         cli.Ui
	// 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"`

	// 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_addr"`

	// 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.
	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"`

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

	// 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.
	EventHandlers []string `mapstructure:"event_handlers"`
}

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

func (c *Config) BindAddrParts() (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, error)

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

type EventHandler

type EventHandler interface {
	HandleEvent(*log.Logger, serf.Event) error
}

EventHandler is a handler that does things when events happen.

type EventScript

type EventScript struct {
	Event     string
	UserEvent string
	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, error)

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

func (*EventScript) Invoke

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

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

func (*EventScript) String

func (s *EventScript) String() string

func (*EventScript) Valid

func (s *EventScript) Valid() bool

Valid checks if this is a valid agent event script.

type EventWriter

type EventWriter struct {
	Agent *Agent
}

EventWriter is an io.Writer that writes all of its output to the event log of an agent.

func (*EventWriter) Write

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

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 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(l *log.Logger, e serf.Event) error

type RPCClient

type RPCClient struct {
	Client *rpc.Client
}

RPCClient is the RPC client to make requests to the agent RPC.

func (*RPCClient) Close

func (c *RPCClient) Close() error

Close just closes the underlying RPC client.

func (*RPCClient) ForceLeave added in v0.2.0

func (c *RPCClient) ForceLeave(node string) error

func (*RPCClient) Join

func (c *RPCClient) Join(addrs []string, ignoreOld bool) (n int, err error)

func (*RPCClient) Members

func (c *RPCClient) Members() ([]serf.Member, error)

func (*RPCClient) Monitor

func (c *RPCClient) Monitor(level logutils.LogLevel, ch chan<- string, done <-chan struct{}) error

func (*RPCClient) UserEvent

func (c *RPCClient) UserEvent(name string, payload []byte, coalesce bool) error

type RPCJoinArgs added in v0.2.0

type RPCJoinArgs struct {
	Addrs     []string
	IgnoreOld bool
}

RPCJoinArgs are the args for the Join RPC call.

type RPCMonitorArgs

type RPCMonitorArgs struct {
	CallbackAddr string
	LogLevel     string
}

RPCMonitorArgs are the args for the Monitor RPC call.

type RPCUserEventArgs

type RPCUserEventArgs struct {
	Name     string
	Payload  []byte
	Coalesce bool
}

RPCUserEventArgs are the args for the user event RPC call.

type ScriptEventHandler

type ScriptEventHandler struct {
	Self    serf.Member
	Scripts []EventScript
}

ScriptEventHandler invokes scripts for the events that it receives.

func (*ScriptEventHandler) HandleEvent

func (h *ScriptEventHandler) HandleEvent(logger *log.Logger, e serf.Event) error

Jump to

Keyboard shortcuts

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