Documentation
¶
Overview ¶
Info: The idea about the ring buffer is that we have a FIFO buffer where we store all incomming messages requested by operators. Each message processed will also be stored in a DB.
Idea: All incomming messages should be handled from the in-memory buffered channel, but when they are put on the buffer they should also be written to the DB with a handled flag set to false. When a message have left the buffer the handled flag should be set to true.
Notes:
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewServer ¶
func NewServer(c *Configuration) (*server, error)
newServer will prepare and return a server type
Types ¶
type CommandOrEvent ¶
type CommandOrEvent string
CommandOrEvent describes on the message level if this is an event or command kind of message in the Subject name. This field is mainly used to be able to spawn up different worker processes based on the Subject name so we can have one process for handling event kind, and another for handling command kind of messages. This type is used in both building the subject name, and also inside the Message type to describe if it is a Command or Event.
const ( // Command, command that will just wait for an // ack, and nothing of the output of the command are // delivered back in the reply ack message. // The message should contain the unique ID of the // command. CommandACK CommandOrEvent = "CommandACK" // Same as above, but No ACK. CommandNACK CommandOrEvent = "CommandNACK" // Same as above, but No ACK // Event, wait for and return the ACK message. This means // that the command should be executed immediately // and that we should get the confirmation if it // was successful or not. EventACK CommandOrEvent = "EventACK" // Same as above, but No ACK. EventNACK CommandOrEvent = "EventNACK" )
func (CommandOrEvent) GetCommandOrEventAvailable ¶
func (c CommandOrEvent) GetCommandOrEventAvailable() CommandOrEventAvailable
type CommandOrEventAvailable ¶
type CommandOrEventAvailable struct {
// contains filtered or unexported fields
}
func (CommandOrEventAvailable) CheckIfExists ¶
func (co CommandOrEventAvailable) CheckIfExists(c CommandOrEvent, subject Subject) bool
type Configuration ¶
type Configuration struct {
// The configuration folder on disk
ConfigFolder string
// The folder where the socket file should live
SocketFolder string
// The folder where the database should live
DatabaseFolder string
// some unique string to identify this Edge unit
NodeName string
// the address of the message broker
BrokerAddress string
// The number of the profiling port
ProfilingPort string
// host and port for prometheus listener, e.g. localhost:2112
PromHostAndPort string
// set to true if this is the node that should receive the error log's from other nodes
DefaultMessageTimeout int
// default amount of retries that will be done before a message is thrown away, and out of the system
DefaultMessageRetries int
// Publisher data folder
SubscribersDataFolder string
// central node to receive messages published from nodes
CentralNodeName string
// Path to the certificate of the root CA
RootCAPath string
// Make the current node send hello messages to central at given interval in seconds
StartPubREQHello int
// Start the central error logger.
// Takes a comma separated string of nodes to receive from or "*" for all nodes.
StartSubREQErrorLog flagNodeSlice
// Subscriber for hello messages
StartSubREQHello flagNodeSlice
// Subscriber for text logging
StartSubREQToFileAppend flagNodeSlice
// Subscriber for writing to file
StartSubREQToFile flagNodeSlice
// Subscriber for Echo Request
StartSubREQPing flagNodeSlice
// Subscriber for Echo Reply
StartSubREQPong flagNodeSlice
// Subscriber for CLICommandRequest
StartSubREQCliCommand flagNodeSlice
// Subscriber for REQnCliCommand
StartSubREQnCliCommand flagNodeSlice
// Subscriber for REQToConsole
StartSubREQToConsole flagNodeSlice
// Subscriber for REQHttpGet
StartSubREQHttpGet flagNodeSlice
// Subscriber for tailing log files
StartSubREQTailFile flagNodeSlice
}
--- Configuration
func NewConfiguration ¶
func NewConfiguration() *Configuration
NewConfiguration will set a default Configuration, and return a *Configuration.
func (*Configuration) CheckFlags ¶
func (c *Configuration) CheckFlags() error
CheckFlags will parse all flags
func (*Configuration) ReadConfigFile ¶
func (c *Configuration) ReadConfigFile() (Configuration, error)
Reads the current config file from disk.
func (*Configuration) WriteConfigFile ¶
func (c *Configuration) WriteConfigFile() error
WriteConfigFile will write the current config to file. If the file or the directory for the config file does not exist it will be created.
type Message ¶
type Message struct {
// The node to send the message to
ToNode node `json:"toNode" yaml:"toNode"`
// The Unique ID of the message
ID int `json:"id" yaml:"id"`
// The actual data in the message
Data []string `json:"data" yaml:"data"`
// Method, what is this message doing, etc. CLI, syslog, etc.
Method Method `json:"method" yaml:"method"`
// ReplyMethod, is the method to use for the reply message.
// By default the reply method will be set to log to file, but
// you can override it setting your own here.
ReplyMethod Method `json:"replyMethod" yaml:"replyMethod"`
// From what node the message originated
FromNode node
// ACKTimeout for waiting for an ack message
ACKTimeout int `json:"ACKTimeout" yaml:"ACKTimeout"`
// Resend retries
Retries int `json:"retries" yaml:"retries"`
// The ACK timeout of the new message created via a request event.
ReplyACKTimeout int `json:"replyACKTimeout" yaml:"replyACKTimeout"`
// The retries of the new message created via a request event.
ReplyRetries int `json:"replyRetries" yaml:"replyRetries"`
// Timeout for long a process should be allowed to operate
MethodTimeout int `json:"methodTimeout" yaml:"methodTimeout"`
// Directory is a string that can be used to create the
//directory structure when saving the result of some method.
// For example "syslog","metrics", or "metrics/mysensor"
// The type is typically used in the handler of a method.
Directory string `json:"directory" yaml:"directory"`
// FileExtension is used to be able to set a wanted extension
// on a file being saved as the result of data being handled
// by a method handler.
FileExtension string `json:"fileExtension" yaml:"fileExtension"`
// operation are used to give an opCmd and opArg's.
Operation Operation `json:"operation"`
// PreviousMessage are used for example if a reply message is
// generated and we also need a copy of thedetails of the the
// initial request message.
PreviousMessage *Message
// contains filtered or unexported fields
}
type Method ¶
type Method string
Method is used to specify the actual function/method that is represented in a typed manner.
const ( // Initial method used to start other processes. REQInitial Method = "REQInitial" // Command for client operation request of the system. The op // command to execute shall be given in the data field of the // message as string value. For example "ps". REQOpCommand Method = "REQOpCommand" // Execute a CLI command in for example bash or cmd. // This is an event type, where a message will be sent to a // node with the command to execute and an ACK will be replied // if it was delivered succesfully. The output of the command // ran will be delivered back to the node where it was initiated // as a new message. // The data field is a slice of strings where the first string // value should be the command, and the following the arguments. REQCliCommand Method = "REQCliCommand" // Execute a CLI command in for example bash or cmd. // This is an event type, where a message will be sent to a // node with the command to execute and an ACK will be replied // if it was delivered succesfully. The output of the command // ran will be delivered back to the node where it was initiated // as a new message. // The NOSEQ method will process messages as they are recived, // and the reply back will be sent as soon as the process is // done. No order are preserved. // The data field is a slice of strings where the first string // value should be the command, and the following the arguments. REQnCliCommand Method = "REQnCliCommand" // Send text to be logged to the console. // The data field is a slice of strings where the first string // value should be the command, and the following the arguments. REQToConsole Method = "REQToConsole" // Send text logging to some host by appending the output to a // file, if the file do not exist we create it. // A file with the full subject+hostName will be created on // the receiving end. // The data field is a slice of strings where the values of the // slice will be written to the log file. REQToFileAppend Method = "REQToFileAppend" // Send text to some host by overwriting the existing content of // the fileoutput to a file. If the file do not exist we create it. // A file with the full subject+hostName will be created on // the receiving end. // The data field is a slice of strings where the values of the // slice will be written to the file. REQToFile Method = "REQToFile" // Send Hello I'm here message. REQHello Method = "REQHello" // Error log methods to centralError node. REQErrorLog Method = "REQErrorLog" // Echo request will ask the subscriber for a // reply generated as a new message, and sent back to where // the initial request was made. REQPing Method = "REQPing" // Will generate a reply for a ECHORequest REQPong Method = "REQPong" // Http Get REQHttpGet Method = "REQHttpGet" // Tail file REQTailFile Method = "REQTailFile" )
------------------------------------------------------------ The constants that will be used throughout the system for when specifying what kind of Method to send or work with.
func (Method) GetMethodsAvailable ¶
func (m Method) GetMethodsAvailable() MethodsAvailable
The mapping of all the method constants specified, what type it references, and the kind if it is an Event or Command, and if it is ACK or NACK.
Allowed values for the commandOrEvent field are: - CommandACK - CommandNACK - EventACK - EventNack
type MethodsAvailable ¶
type MethodsAvailable struct {
// contains filtered or unexported fields
}
----
func (MethodsAvailable) CheckIfExists ¶
func (ma MethodsAvailable) CheckIfExists(m Method) (methodHandler, bool)
Check if exists will check if the Method is defined. If true the bool value will be set to true, and the methodHandler function for that type will be returned.
type OpCmdStartProc ¶
type OpCmdStartProc struct {
Method Method `json:"method"`
AllowedNodes []node `json:"allowedNodes"`
}
type OpCmdStopProc ¶
type OpCmdStopProc struct {
RecevingNode node `json:"receivingNode"`
Method Method `json:"method"`
Kind processKind `json:"kind"`
}
type Operation ¶
type Operation struct {
OpCmd string `json:"opCmd"`
OpArg json.RawMessage `json:"opArg"`
}
type Subject ¶
type Subject struct {
// node, the name of the node
ToNode string `json:"node" yaml:"toNode"`
// messageType, command/event
CommandOrEvent CommandOrEvent `json:"commandOrEvent" yaml:"commandOrEvent"`
// method, what is this message doing, etc. CLICommand, Syslog, etc.
Method Method `json:"method" yaml:"method"`
// contains filtered or unexported fields
}
subject contains the representation of a subject to be used with one specific process