Documentation ¶
Overview ¶
Package beekeeper is a batteries-included cluster computing library
Index ¶
- Constants
- Variables
- func WrapJob(job func(*Task))
- type Config
- type Conn
- type LoadBalancer
- type Message
- type Monitor
- type Node
- type NodeInfo
- type Nodes
- type Operation
- type Request
- type Result
- type Server
- func (s *Server) Connect(ip string, timeout ...time.Duration) (Node, error)
- func (s *Server) DistributeJob(pkgName string, function string, nodes ...Node) error
- func (s *Server) Execute(n Node, t Task, timeout ...time.Duration) (res Result, err error)
- func (s *Server) ExecuteMany(n Nodes, t Task, timeout ...time.Duration) ([]Result, error)
- func (s *Server) Scan(waitTime time.Duration) (Nodes, error)
- func (s *Server) Start() error
- func (s *Server) Stop()
- type Status
- type Task
Constants ¶
const ( // DefaultPort is the default port for Beekeeper servers DefaultPort = 2020 // DefaultScanTime is the scan time to be used by scan functions DefaultScanTime = time.Second * 2 )
const ( // Version is the version of the package in semantic notation. Version = "v0.3.2" // License is the copyright license used in this package. License = "MIT" // Author is the first and last name of the package's author. Author = "Camilo Hernández" )
const ( // OperationNone nil value for operations OperationNone = iota // OperationStatus ask a node for a status report OperationStatus // OperationJobTransfer transfer a job via the Data field OperationJobTransfer // OperationTransferFailed transfer failed, Data contains the details OperationTransferFailed // OperationTransferAcknowledge transfer was successful OperationTransferAcknowledge // OperationJobExecute run the local job OperationJobExecute // OperationJobResult job ran and the details come in the Data OperationJobResult )
const ( // StatusNone nil value for Status StatusNone = iota // StatusIDLE node is IDLE StatusIDLE // StatusWorking node is working on a job StatusWorking )
Variables ¶
var ErrMessageTooLarge = errors.New("message too large")
ErrMessageTooLarge is triggered when a message exceeds the size limit set by MaxMessageSize
var ErrNodeDisconnected = errors.New("node disconnected")
ErrNodeDisconnected is produced when a node is gets disconnected while executing an operation
var ErrTimeout = errors.New("time exceeded")
ErrTimeout is produced by functions called with a timeout when the allocated time is exceeded
var WatchdogSleep = time.Second * 15
WatchdogSleep is the time between node pings for the watchdog
Functions ¶
Types ¶
type Config ¶
type Config struct { // Name of the node. It defaults to the system's hostname. Name string `mapstructure:"name,omitempty"` // Debug toggles between verbosity for debugging. Debug bool `mapstructure:"debug,omitempty"` // Token is a passphrase used to restrict usage of the node. Must match on the receiving node. Token string `mapstructure:"token,omitempty"` // InboundPort is the port to be used for receiving connections. Defaults to 2020. InboundPort int `mapstructure:"inbound_port,omitempty"` // OutboundPort is the port assumed to be used by a remote node. It's only used to establish a connection, and // afterwards a port is negotiated with the remote node. Defaults to 2020. OutboundPort int `mapstructure:"outbound_port,omitempty"` // TLSCertificate is used for TLS connections between nodes. If none is given a certificate is created on the first // run and reused as needed. TLSCertificate []byte // TLSPrivateKey is used for TLS connections between nodes. If none is given a key is created on the first // run and reused as needed. TLSPrivateKey []byte // AllowExternal sets whether non-local connections should be accepted. It's heavily encouraged that a whitelist // and token is set with this featured turn on. Defaults to false. AllowExternal bool `mapstructure:"allow_external,omitempty"` // Whitelist contains a list of allowed hosts. If none is provided it's understood that the whitelist is disabled. // A wildcard sign (*) can be used. Whitelist []string `mapstructure:"whitelist,omitempty"` // MaxMessageSize is the size limit in bytes for incoming messages. It defaults to 1.024 MB MaxMessageSize uint64 `mapstructure:"max_message_size,omitempty"` // DisableCleanup turns off the post-build cleanup DisableCleanup bool `mapstructure:"disable_cleanup,omitempty"` // DisableConnectionWatchdog disables the connection watchdog, and stops disconnection notifications. DisableConnectionWatchdog bool `mapstructure:"disable_connection_watchdog,omitempty"` }
Config holds the configurations for a node or a primary node.
func NewConfigFromFile ¶
NewConfigFromFile parses a file on the provided path as a Config object. If a field is not set, the default value is assigned.
func NewDefaultConfig ¶
func NewDefaultConfig() (c Config)
NewDefaultConfig returns a new Config with sensible defaults. It's recommended that NewDefaultConfig be used. for the creation of Config structs.
type LoadBalancer ¶
type LoadBalancer struct {
// contains filtered or unexported fields
}
LoadBalancer contains the data needed to try to select the best node for a task. Should be created using NewLoadBalancer.
func NewLoadBalancer ¶
func NewLoadBalancer(s *Server, ns Nodes) *LoadBalancer
NewLoadBalancer creates and sets up a LoadBalancer from the given Nodes.
type Message ¶
type Message struct { // SentAt timestamp for the Message. SentAt time.Time // Name the sender's name. Name string // Operation operation the remote node wishes to execute. It may be nilled with OperationNone. Operation Operation // Data the body of the message. Contains the payload needed for the execution if the Operation. Data []byte // Token is used as a passphrase to operate in a multi-node environment. Token string // Addr is the address of the sender Addr *net.TCPAddr // RespondOnPort is the port that the sender wishes to be used for the response. RespondOnPort int // Status represents the current action the node is doing. Status Status // NodeInfo contains metadata about the sender, like OS and current usage. NodeInfo NodeInfo }
Message is used for node communication. It holds the transferable data as well as some metadata about the node.
type Monitor ¶
type Monitor struct { App *tview.Application Pages *tview.Pages CurrentPage int // contains filtered or unexported fields }
Monitor represents a Beekeeper Monitor.
func (*Monitor) PreviousPage ¶
func (m *Monitor) PreviousPage()
PreviousPage changes the page to the n-1 page.
type NodeInfo ¶
type NodeInfo struct { // CPUTemp is the temperature as measured in the CPU dice when possible. Certain OS can return 0. CPUTemp float32 // Usage is the percentage of usage of the host system in a range from 1 (max) to 0 (min). Usage float32 // OS is the GOOS of the host system. OS string }
NodeInfo holds additional info abut a node.
type Nodes ¶
type Nodes []Node
Nodes is a Node slice
func (Nodes) PrettyPrint ¶
PrettyPrint prints a formatted table of workers.
type Operation ¶
type Operation int
Operation is used to specify a Message's intent to the remote node
type Server ¶
type Server struct { // Config hold the configuration data of the server. Config Config // Status represents the action the server is currently doing. Status Status // contains filtered or unexported fields }
Server is a node server, that holds the configuration to be used.
func NewServer ¶
NewServer creates a Server struct using the given config or the default if none is provided.
func (*Server) Connect ¶
Connect established a TCP over TLS connection with the given address. If no node is reachable an error will be returned. An optional timeout argument can be provided.
func (*Server) DistributeJob ¶
DistributeJob builds a job and sends a copy to the workers. Will fail if an empty workers list is given.
func (*Server) Execute ¶
Execute runs a task on the given node and blocks until the task results are retrieved. It will fail if no job is present on the node's systems. An optional timeout parameter can be provided.
func (*Server) ExecuteMany ¶
ExecuteMany runs a task on the provided Nodes and blocks until a Result is sent back. Optionally a timeout argument can be passed.