agent

package
v0.0.0-...-56e5da9 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2018 License: MPL-2.0 Imports: 46 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	DefaultAddr       = "0.0.0.0"
	DefaultMaxPayload = 100 * 1024 * 1024 // 100M
)

This is the default addr to all interfaces.

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

Variables

This section is empty.

Functions

func ApiJobToStructJob

func ApiJobToStructJob(job *api.Job, trafficLimit int) *models.Job

func ApiOrderToStructOrder

func ApiOrderToStructOrder(order *api.Order) *models.Order

func ApiTaskToStructsTask

func ApiTaskToStructsTask(apiTask *api.Task, structsTask *models.Task)

func Asset

func Asset(name string) ([]byte, error)

Asset loads and returns the asset for the given name. It returns an error if the asset could not be found or could not be loaded.

func AssetDir

func AssetDir(name string) ([]string, error)

AssetDir returns the file names below a certain directory embedded in the file by go-bindata. For example if you run go-bindata on data/... and data contains the following hierarchy:

data/
  foo.txt
  img/
    a.png
    b.png

then AssetDir("data") would return []string{"foo.txt", "img"} AssetDir("data/img") would return []string{"a.png", "b.png"} AssetDir("foo.txt") and AssetDir("notexist") would return an error AssetDir("") will return []string{"data"}.

func AssetInfo

func AssetInfo(name string) (os.FileInfo, error)

AssetInfo loads and returns the asset info for the given name. It returns an error if the asset could not be found or could not be loaded.

func AssetNames

func AssetNames() []string

AssetNames returns the names of the assets.

func GetMd5Hash

func GetMd5Hash(text string) string

获取字符串的MD5值

func MustAsset

func MustAsset(name string) []byte

MustAsset is like Asset but panics when Asset would return an error. It simplifies safe initialization of global variables.

func RestoreAsset

func RestoreAsset(dir, name string) error

RestoreAsset restores an asset under the given directory

func RestoreAssets

func RestoreAssets(dir, name string) error

RestoreAssets restores an asset under the given directory recursively

Types

type Addresses

type Addresses struct {
	HTTP string `mapstructure:"http"`
	RPC  string `mapstructure:"rpc"`
	Serf string `mapstructure:"serf"`
	Nats string `mapstructure:"nats"`
}

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 {
	HTTP string `mapstructure:"http"`
	RPC  string `mapstructure:"rpc"`
	Serf string `mapstructure:"serf"`
	Nats string `mapstructure:"nats"`
}

AdvertiseAddrs is used to control the addresses we advertise out for different network services. All are optional and default to BindAddr and their default Port.

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, log *ulog.Logger) (*Agent, error)

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

func (*Agent) Client

func (a *Agent) Client() *ucli.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 Udup servers

func (*Agent) Server

func (a *Agent) Server() *usrv.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 AppInfo

type AppInfo struct {
	FrontEndUrl string
	AdminUrl    string
	Username    string
	Password    string
	AuthUrl     string
	AuthCode    string
}

type ClientConfig

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

	// StateDir is the store directory
	StateDir string `mapstructure:"state_dir"`

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

	// NoHostUUID disables using the host's UUID and will force generation of a
	// random UUID.
	NoHostUUID bool `mapstructure:"no_host_uuid"`
}

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 CloudOrderResponse

type CloudOrderResponse struct {
	InstanceId string
	AppInfo    AppInfo
}

type Command

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

Command is a Command implementation that runs a Udup 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 `mapstructure:"region"`

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

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

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

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

	LogToStdout bool `mapstructure:"log_to_stdout"`

	// file to write our pid to
	PidFile string `mapstructure:"pid_file"`

	// Specify the log file name. The empty string means to log to stdout.
	LogFile string `mapstructure:"log_file"`

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

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

	// Addresses is used to override the network addresses we bind to.
	// Use normalizedAddrs if you need the host+port to bind to.
	Addresses *Addresses `mapstructure:"addresses"`

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

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

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

	Metric *Metric `mapstructure:"metric"`

	Network *Network `mapstructure:"network"`

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

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

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

	// Consul contains the configuration for the Consul Agent and
	// parameters necessary to register services, their checks, and
	// discover the current Udup servers.
	Consul *uconf.ConsulConfig `mapstructure:"consul"`

	// UdupConfig is used to override the default config.
	// This is largly used for testing purposes.
	UdupConfig *uconf.ServerConfig `mapstructure:"-" json:"-"`

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

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

	// List of config files that have been loaded (in order)
	Files []string `mapstructure:"-"`

	// HTTPAPIResponseHeaders allows users to configure the Udup http agent to
	// set arbritrary headers on API responses
	HTTPAPIResponseHeaders map[string]string `mapstructure:"http_api_response_headers"`

	// EnableUi enables the statically-compiled assets for the Udup web UI and
	// serves them at the default /ui/ endpoint automatically.
	EnableUi bool `mapstructure:"ui"`

	// UiDir is the directory containing the Web UI resources.
	// If provided, the UI endpoints will be enabled.
	UiDir string `mapstructure:"ui_dir"`

	// Schema name for dtle meta info (e.g. gtid_executed).
	// Do not use special characters (which need to be quoted) in schema name.
	DtleSchemaName string `mapstructure:"dtle_schema_name"`
	// contains filtered or unexported fields
}

Config is the configuration for the Udup agent.

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig is a the baseline configuration for Udup

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 ParseConfig

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

ParseConfig parses the config from the given io.Reader.

Due to current internal limitations, the entire contents of the io.Reader will be copied into memory first before parsing.

func ParseConfigFile

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

ParseConfigFile parses the given path as a config file.

func (*Config) Listener

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

Listener 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 (c *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)

AgentServersRequest is used to query the list of servers used by the Udup Client for RPCs. This endpoint can also be used to update the list of servers for a given agent.

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

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

func (*HTTPServer) DcsRequest

func (s *HTTPServer) DcsRequest(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) JobsInfoRequest

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

func (*HTTPServer) JobsRenewalRequest

func (s *HTTPServer) JobsRenewalRequest(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) LoginRequest

func (s *HTTPServer) LoginRequest(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) OperatorRaftConfiguration

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

OperatorRaftConfiguration is used to inspect the current Raft configuration. This supports the stale query mode in case the cluster doesn't have a leader.

func (*HTTPServer) OperatorRaftPeer

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

OperatorRaftPeer supports actions on Raft peers. Currently we only support removing peers by address.

func (*HTTPServer) OperatorRequest

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

func (*HTTPServer) OrderCloudRequest

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

func (*HTTPServer) OrderSpecificRequest

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

func (*HTTPServer) OrdersRequest

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

func (*HTTPServer) PendingOrdersRequest

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

func (*HTTPServer) RegionListRequest

func (s *HTTPServer) RegionListRequest(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)

func (*HTTPServer) ValidateJobRequest

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

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 Metric

type Metric struct {
	DisableHostname    bool   `mapstructure:"disable_hostname"`
	UseNodeName        bool   `mapstructure:"use_node_name"`
	CollectionInterval string `mapstructure:"collection_interval"`

	PublishAllocationMetrics bool `mapstructure:"publish_allocation_metrics"`
	PublishNodeMetrics       bool `mapstructure:"publish_node_metrics"`
	// contains filtered or unexported fields
}

func (*Metric) Merge

func (a *Metric) Merge(b *Metric) *Metric

Merge is used to merge two metric configs together

type Network

type Network struct {
	// MAX_PAYLOAD is the maximum allowed payload size. Should be using
	// something different if > 1MB payloads are needed.
	MaxPayload int `mapstructure:"max_payload"`
}

func (*Network) Merge

func (a *Network) Merge(b *Network) *Network

type Node

type Node struct {
	Code string
	Name string
}

type Ports

type Ports struct {
	HTTP int `mapstructure:"http"`
	RPC  int `mapstructure:"rpc"`
	Serf int `mapstructure:"serf"`
	Nats int `mapstructure:"nats"`
}

Ports encapsulates 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 `mapstructure:"enabled"`

	// BootstrapExpect tries to automatically bootstrap the udup cluster,
	// by withholding peers until enough servers join.
	BootstrapExpect int `mapstructure:"bootstrap_expect"`

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

	// 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 `mapstructure:"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 `mapstructure:"enabled_schedulers"`

	// HeartbeatGrace is the grace period beyond the TTL to account for network,
	// processing delays and clock skew before marking a node as "down".
	HeartbeatGrace string `mapstructure:"heartbeat_grace"`

	// 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:"join"`

	// RetryMaxAttempts specifies the maximum number of times to retry joining a
	// host on startup. This is useful for cases where we know the node will be
	// online eventually.
	RetryMaxAttempts int `mapstructure:"retry_max"`

	// RetryInterval specifies the amount of time to wait in between join
	// attempts on agent start. The minimum allowed value is 1 second and
	// the default is 30s.
	RetryInterval string `mapstructure:"retry_interval"`
	// contains filtered or unexported fields
}

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 StringFlag

type StringFlag []string

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

func (*StringFlag) Set

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

func (*StringFlag) String

func (s *StringFlag) String() string

type ZTreeData

type ZTreeData struct {
	Code  string
	Name  string
	Nodes []*Node
}

Jump to

Keyboard shortcuts

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