agent

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2015 License: MPL-2.0 Imports: 37 Imported by: 107

Documentation

Index

Constants

View Source
const (
	// ErrInvalidMethod is used if the HTTP method is not supported
	ErrInvalidMethod = "Invalid method"
)

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

func NewLogWriter(buf int) *logWriter

NewLogWriter creates a logWriter with the given buffer capacity

func NewProvider

func NewProvider(c *Config, logOutput io.Writer) (*client.Provider, net.Listener, error)

NewProvider creates a new SCADA provider using the given configuration. Requests for the HTTP capability are passed off to the listener that is returned.

func ProviderConfig

func ProviderConfig(c *Config) *client.ProviderConfig

ProviderConfig returns the configuration for the SCADA provider

func ProviderService

func ProviderService(c *Config) *client.ProviderService

ProviderService returns the service information for the provider

func ValidateLevelFilter

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

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

Types

type Addresses

type Addresses struct {
	HTTP string `hcl:"http"`
	RPC  string `hcl:"rpc"`
	Serf string `hcl:"serf"`
}

Addresses encapsulates all of the addresses we bind to for various network services. Everything is optional and defaults to BindAddr.

func (*Addresses) Merge

func (a *Addresses) Merge(b *Addresses) *Addresses

Merge is used to merge two address configs together.

type AdvertiseAddrs

type AdvertiseAddrs struct {
	RPC  string `hcl:"rpc"`
	Serf string `hcl:"serf"`
}

AdvertiseAddrs is used to control the addresses we advertise out for different network services. Not all network services support an advertise address. All are optional and default to BindAddr.

func (*AdvertiseAddrs) Merge

Merge merges two advertise addrs configs together.

type Agent

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

Agent is a long running daemon that is used to run both clients and servers. Servers are responsible for managing state and making scheduling decisions. Clients can be scheduled to, and are responsible for interfacing with servers to run allocations.

func NewAgent

func NewAgent(config *Config, logOutput io.Writer) (*Agent, error)

NewAgent is used to create a new agent with the given configuration

func (*Agent) Client

func (a *Agent) Client() *client.Client

Client returns the configured client or nil

func (*Agent) Leave

func (a *Agent) Leave() error

Leave is used gracefully exit. Clients will inform servers of their departure so that allocations can be rescheduled.

func (*Agent) RPC

func (a *Agent) RPC(method string, args interface{}, reply interface{}) error

RPC is used to make an RPC call to the Nomad servers

func (*Agent) Server

func (a *Agent) Server() *nomad.Server

Server returns the configured server or nil

func (*Agent) Shutdown

func (a *Agent) Shutdown() error

Shutdown is used to terminate the agent.

func (*Agent) Stats

func (a *Agent) Stats() map[string]map[string]string

Stats is used to return statistics for debugging and insight for various sub-systems

type AtlasConfig

type AtlasConfig struct {
	// Infrastructure is the name of the infrastructure
	// we belong to. e.g. hashicorp/stage
	Infrastructure string `hcl:"infrastructure"`

	// Token is our authentication token from Atlas
	Token string `hcl:"token" json:"-"`

	// Join controls if Atlas will attempt to auto-join the node
	// to it's cluster. Requires Atlas integration.
	Join bool `hcl:"join"`

	// Endpoint is the SCADA endpoint used for Atlas integration. If
	// empty, the defaults from the provider are used.
	Endpoint string `hcl:"endpoint"`
}

AtlasConfig is used to enable an parameterize the Atlas integration

type ClientConfig

type ClientConfig struct {
	// Enabled controls if we are a client
	Enabled bool `hcl:"enabled"`

	// StateDir is the state directory
	StateDir string `hcl:"state_dir"`

	// AllocDir is the directory for storing allocation data
	AllocDir string `hcl:"alloc_dir"`

	// Servers is a list of known server addresses. These are as "host:port"
	Servers []string `hcl:"servers"`

	// NodeID is the unique node identifier to use. A UUID is used
	// if not provided, and stored in the data directory
	NodeID string `hcl:"node_id"`

	// NodeClass is used to group the node by class
	NodeClass string `hcl:"node_class"`

	// Options is used for configuration of nomad internals,
	// like fingerprinters and drivers. The format is:
	//
	//  namespace.option = value
	Options map[string]string `hcl:"options"`

	// Metadata associated with the node
	Meta map[string]string `hcl:"meta"`

	// Interface to use for network fingerprinting
	NetworkInterface string `hcl:"network_interface"`

	// The network link speed to use if it can not be determined dynamically.
	NetworkSpeed int `hcl:"network_speed"`
}

ClientConfig is configuration specific to the client mode

func (*ClientConfig) Merge

func (a *ClientConfig) Merge(b *ClientConfig) *ClientConfig

Merge is used to merge two client configs together

type Command

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

Command is a Command implementation that runs a Nomad 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 {
	// Region is the region this agent is in. Defaults to global.
	Region string `hcl:"region"`

	// Datacenter is the datacenter this agent is in. Defaults to dc1
	Datacenter string `hcl:"datacenter"`

	// NodeName is the name we register as. Defaults to hostname.
	NodeName string `hcl:"name"`

	// DataDir is the directory to store our state in
	DataDir string `hcl:"data_dir"`

	// LogLevel is the level of the logs to putout
	LogLevel string `hcl:"log_level"`

	// BindAddr is the address on which all of nomad's services will
	// be bound. If not specified, this defaults to 127.0.0.1.
	BindAddr string `hcl:"bind_addr"`

	// EnableDebug is used to enable debugging HTTP endpoints
	EnableDebug bool `hcl:"enable_debug"`

	// Ports is used to control the network ports we bind to.
	Ports *Ports `hcl:"ports"`

	// Addresses is used to override the network addresses we bind to.
	Addresses *Addresses `hcl:"addresses"`

	// AdvertiseAddrs is used to control the addresses we advertise.
	AdvertiseAddrs *AdvertiseAddrs `hcl:"advertise"`

	// Client has our client related settings
	Client *ClientConfig `hcl:"client"`

	// Server has our server related settings
	Server *ServerConfig `hcl:"server"`

	// Telemetry is used to configure sending telemetry
	Telemetry *Telemetry `hcl:"telemetry"`

	// LeaveOnInt is used to gracefully leave on the interrupt signal
	LeaveOnInt bool `hcl:"leave_on_interrupt"`

	// LeaveOnTerm is used to gracefully leave on the terminate signal
	LeaveOnTerm bool `hcl:"leave_on_terminate"`

	// EnableSyslog is used to enable sending logs to syslog
	EnableSyslog bool `hcl:"enable_syslog"`

	// SyslogFacility is used to control the syslog facility used.
	SyslogFacility string `hcl:"syslog_facility"`

	// DisableUpdateCheck is used to disable the periodic update
	// and security bulletin checking.
	DisableUpdateCheck bool `hcl:"disable_update_check"`

	// DisableAnonymousSignature is used to disable setting the
	// anonymous signature when doing the update check and looking
	// for security bulletins
	DisableAnonymousSignature bool `hcl:"disable_anonymous_signature"`

	// AtlasConfig is used to configure Atlas
	Atlas *AtlasConfig `hcl:"atlas"`

	// NomadConfig is used to override the default config.
	// This is largly used for testing purposes.
	NomadConfig *nomad.Config `hcl:"-" json:"-"`

	// ClientConfig is used to override the default config.
	// This is largly used for testing purposes.
	ClientConfig *client.Config `hcl:"-" json:"-"`

	// DevMode is set by the -dev CLI flag.
	DevMode bool `hcl:"-"`

	// Version information is set at compilation time
	Revision          string
	Version           string
	VersionPrerelease string
}

Config is the configuration for the Nomad agent.

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig is a the baseline configuration for Nomad

func DevConfig

func DevConfig() *Config

DevConfig is a Config that is used for dev mode of Nomad.

func LoadConfig

func LoadConfig(path string) (*Config, error)

LoadConfig loads the configuration at the given path, regardless if its a file or directory.

func LoadConfigDir

func LoadConfigDir(dir string) (*Config, error)

LoadConfigDir loads all the configurations in the given directory in alphabetical order.

func LoadConfigFile

func LoadConfigFile(path string) (*Config, error)

LoadConfigFile loads the configuration from the given file.

func LoadConfigString

func LoadConfigString(s string) (*Config, error)

LoadConfigString is used to parse a config string

func (*Config) Listener

func (c *Config) Listener(proto, addr string, port int) (net.Listener, error)

GetListener can be used to get a new listener using a custom bind address. If the bind provided address is empty, the BindAddr is used instead.

func (*Config) Merge

func (a *Config) Merge(b *Config) *Config

Merge merges two configurations.

type HTTPCodedError

type HTTPCodedError interface {
	error
	Code() int
}

HTTPCodedError is used to provide the HTTP error code

func CodedError

func CodedError(c int, s string) HTTPCodedError

type HTTPServer

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

HTTPServer is used to wrap an Agent and expose it over an HTTP interface

func NewHTTPServer

func NewHTTPServer(agent *Agent, config *Config, logOutput io.Writer) (*HTTPServer, error)

NewHTTPServer starts new HTTP server over the agent

func (*HTTPServer) AgentForceLeaveRequest

func (s *HTTPServer) AgentForceLeaveRequest(resp http.ResponseWriter, req *http.Request) (interface{}, error)

func (*HTTPServer) AgentJoinRequest

func (s *HTTPServer) AgentJoinRequest(resp http.ResponseWriter, req *http.Request) (interface{}, error)

func (*HTTPServer) AgentMembersRequest

func (s *HTTPServer) AgentMembersRequest(resp http.ResponseWriter, req *http.Request) (interface{}, error)

func (*HTTPServer) AgentSelfRequest

func (s *HTTPServer) AgentSelfRequest(resp http.ResponseWriter, req *http.Request) (interface{}, error)

func (*HTTPServer) AgentServersRequest

func (s *HTTPServer) AgentServersRequest(resp http.ResponseWriter, req *http.Request) (interface{}, error)

func (*HTTPServer) AllocSpecificRequest

func (s *HTTPServer) AllocSpecificRequest(resp http.ResponseWriter, req *http.Request) (interface{}, error)

func (*HTTPServer) AllocsRequest

func (s *HTTPServer) AllocsRequest(resp http.ResponseWriter, req *http.Request) (interface{}, error)

func (*HTTPServer) EvalSpecificRequest

func (s *HTTPServer) EvalSpecificRequest(resp http.ResponseWriter, req *http.Request) (interface{}, error)

func (*HTTPServer) EvalsRequest

func (s *HTTPServer) EvalsRequest(resp http.ResponseWriter, req *http.Request) (interface{}, error)

func (*HTTPServer) JobSpecificRequest

func (s *HTTPServer) JobSpecificRequest(resp http.ResponseWriter, req *http.Request) (interface{}, error)

func (*HTTPServer) JobsRequest

func (s *HTTPServer) JobsRequest(resp http.ResponseWriter, req *http.Request) (interface{}, error)

func (*HTTPServer) NodeSpecificRequest

func (s *HTTPServer) NodeSpecificRequest(resp http.ResponseWriter, req *http.Request) (interface{}, error)

func (*HTTPServer) NodesRequest

func (s *HTTPServer) NodesRequest(resp http.ResponseWriter, req *http.Request) (interface{}, error)

func (*HTTPServer) Shutdown

func (s *HTTPServer) Shutdown()

Shutdown is used to shutdown the HTTP server

func (*HTTPServer) StatusLeaderRequest

func (s *HTTPServer) StatusLeaderRequest(resp http.ResponseWriter, req *http.Request) (interface{}, error)

func (*HTTPServer) StatusPeersRequest

func (s *HTTPServer) StatusPeersRequest(resp http.ResponseWriter, req *http.Request) (interface{}, error)

type LogHandler

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

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 Ports

type Ports struct {
	HTTP int `hcl:"http"`
	RPC  int `hcl:"rpc"`
	Serf int `hcl:"serf"`
}

Ports is used to encapsulate the various ports we bind to for network services. If any are not specified then the defaults are used instead.

func (*Ports) Merge

func (a *Ports) Merge(b *Ports) *Ports

Merge is used to merge two port configurations.

type ServerConfig

type ServerConfig struct {
	// Enabled controls if we are a server
	Enabled bool `hcl:"enabled"`

	// BootstrapExpect tries to automatically bootstrap the Consul cluster,
	// by witholding peers until enough servers join.
	BootstrapExpect int `hcl:"bootstrap_expect"`

	// DataDir is the directory to store our state in
	DataDir string `hcl:"data_dir"`

	// ProtocolVersion is the protocol version to speak. This must be between
	// ProtocolVersionMin and ProtocolVersionMax.
	ProtocolVersion int `hcl:"protocol_version"`

	// NumSchedulers is the number of scheduler thread that are run.
	// This can be as many as one per core, or zero to disable this server
	// from doing any scheduling work.
	NumSchedulers int `hcl:"num_schedulers"`

	// EnabledSchedulers controls the set of sub-schedulers that are
	// enabled for this server to handle. This will restrict the evaluations
	// that the workers dequeue for processing.
	EnabledSchedulers []string `hcl:"enabled_schedulers"`

	// NodeGCThreshold contros how "old" a node must be to be collected by GC.
	NodeGCThreshold string `hcl:"node_gc_threshold"`
}

ServerConfig is configuration specific to the server mode

func (*ServerConfig) Merge

func (a *ServerConfig) Merge(b *ServerConfig) *ServerConfig

Merge is used to merge two server configs together

type SyslogWrapper

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

SyslogWrapper is used to cleaup log messages before writing them to a Syslogger. Implements the io.Writer interface.

func (*SyslogWrapper) Write

func (s *SyslogWrapper) Write(p []byte) (int, error)

Write is used to implement io.Writer

type Telemetry

type Telemetry struct {
	StatsiteAddr    string `hcl:"statsite_address"`
	StatsdAddr      string `hcl:"statsd_address"`
	DisableHostname bool   `hcl:"disable_hostname"`
}

Telemetry is the telemetry configuration for the server

func (*Telemetry) Merge

func (a *Telemetry) Merge(b *Telemetry) *Telemetry

Merge is used to merge two telemetry configs together

Jump to

Keyboard shortcuts

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