agent

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2013 License: MPL-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

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 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) (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) 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{}
	// 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, rawUi cli.Ui) 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"`

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

	// 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 (*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) 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) Join

func (c *RPCClient) Join(addrs []string) (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) error

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
}

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