Documentation ¶
Index ¶
- Constants
- type Agent
- type Cli
- type CommandCallback
- type CommandCtx
- type Config
- type Ctx
- type EventCallback
- type EventCtx
- type EventFilter
- type Identity
- type Logger
- type Manifest
- type MessageName
- type Messaging
- type Schema
- type SchemaRegistry
- type State
- type StateCallback
- type Sync
- type Type
- type TypeRegistry
Constants ¶
const ( // name of the configuration file ConfigName = "config.properties" // path to look for the config file in a local (user) place // %s stands for agent name ConfigPathLocal = "$HOME/.%s" )
Paths to look for the config file
const ( // ConfigDefaultEndpoint is the default endpoint for an agent. ConfigDefaultEndpoint = "amqp://guest:guest@localhost:5672/" // StateConnected represent an agent state when connected. StateConnected State = iota + 1 // StateDisconnected represent an agent state when disconnected. StateDisconnected // ExchangeCommand is the name of the AMQP exchange used by the agent to send commands. ExchangeCommand = "crucibuild.command" // ExchangeEvent is the name of the AMQP exchange used by the agent to send events. ExchangeEvent = "crucibuild.event" // MimeTypeAvro is the mime type used when sending AVRO schemas. MimeTypeAvro = "application/vnd.apache.avro+binary" // AmqpHeaderSendTo is the AMQP header SendTo used to force destination of a message. AmqpHeaderSendTo = "SendTo" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Agent ¶
type Agent interface { Sync io.Closer Identity Logger Messaging Cli Config SchemaRegistry TypeRegistry Manifest() Manifest }
Agent is the interface of the base behaviour that all Crucibuild agents should implement: - config file parsing - logging - command line args parsing - command registration - etc...
type Cli ¶
type Cli interface { ParseCommandLine() error RegisterCommand(cmd *cobra.Command) RootCommand() *cobra.Command }
Cli is an interface which encapsulates command line argument parsing.
type CommandCallback ¶
type CommandCallback func(ctx CommandCtx) error
CommandCallback is a type of callback occurring on command reception.
type CommandCtx ¶
type CommandCtx interface { Ctx // SendEvent sends an event as a consequence of this message (correlationId is set) SendEvent(command interface{}) error // SendCommand sends a new command as a consequence of this command (correlationId is set) SendCommand(to string, command interface{}) error }
CommandCtx is a specialized Ctx which can trigger a command or an event after receiving a command.
type Config ¶
type Config interface { LoadConfig() error LoadConfigFrom(path string) error CreateDefaultConfig() error CreateDefaultConfigOverwrite() error PrintConfig(w io.Writer) error SetDefaultConfigOption(key string, value interface{}) BindConfigPFlag(key string, flag *pflag.Flag) error GetConfigString(key string) string }
Config is an wrapping basic operations to create and load a configuration file.
type Ctx ¶
type Ctx interface { // Messaging returns the instance of Messaging. Messaging() Messaging // Command returns the concrete instance of the deserialized message. Message() interface{} // The (Avro) schema of the message serialized. Schema() Schema // Properties returns the properties attached to the message. Properties() map[string]string }
Ctx denotes a context when receiving a command or an event. From this instance can be retrieved: - the message (command or event) - the schema - the properties attached to the message
type EventCallback ¶
EventCallback is a type of callback occurring on event reception.
type EventCtx ¶
type EventCtx interface { Ctx // SendCommand sends a command as a consequence of this event (correlationId is set) SendCommand(to string, command interface{}) error }
EventCtx is a specialized Ctx which can trigger a command after receiving an event.
type EventFilter ¶
type EventFilter map[string]interface{}
EventFilter is a type representing a filter on event messages.
type Identity ¶
type Identity interface {
ID() string
}
Identity is a struct representing an unique identifier representing an agent.
type Logger ¶
type Logger interface { // Emergency logs a message indicating the system is unusable. Emergency(format string, a ...interface{}) // Alert logs a message indicating action must be taken immediately. Alert(format string, a ...interface{}) // Critical logs a message indicating critical conditions. Critical(format string, a ...interface{}) // Error logs a message indicating an error condition. // This method takes one or multiple parameters. If a single parameter // is provided, it will be treated as the log message. If multiple parameters // are provided, they will be passed to fmt.Sprintf() to generate the log message. Error(format string, a ...interface{}) // Warning logs a message indicating a warning condition. Warning(format string, a ...interface{}) // Info logs a message for informational purpose. Info(format string, a ...interface{}) // Debug logs a message for debugging purpose. Debug(format string, a ...interface{}) }
Logger is an abstraction wrapping basic operations in order to log messages.
type Manifest ¶
type Manifest interface { Name() string Description() string Version() string Spec() map[string]interface{} }
Manifest is the mandatory core properties of an Agent.
type Messaging ¶
type Messaging interface { Connect() error Disconnect() error State() State RegisterStateCallback(stateCallback StateCallback) string RegisterCommandCallback(commandName MessageName, commandCallback CommandCallback) (string, error) RegisterEventCallback(filter EventFilter, eventCallback EventCallback) (string, error) SendCommand(to string, command interface{}) error }
Messaging interface denotes the capability to send and receive messages and manage connection.
type Schema ¶
type Schema interface { // Id returns the Unique identifier used to reference the schema. ID() string // Title returns the schema title. Title() string // MimeType returns the mimetype of the schema. MimeType() string // Raw returns the schema in raw format. Raw() string // Decode unserializes a message with its schema. Decode(o []byte, t Type) (interface{}, error) // Code serializes a message with its schema. Code(o interface{}) ([]byte, error) }
Schema represent a type of message for a schema based utility like AVRO.
type SchemaRegistry ¶
type SchemaRegistry interface { // SchemaRegister registers a new Schema in the registry. SchemaRegister(schema Schema) (string, error) // SchemaGetByID retrieve the Schema in the registry given its id. SchemaGetByID(id string) (Schema, error) // SchemaListNames list all the Schemas contained in the registry. SchemaListIds() []string // SchemaUnregister removes the schema from the registry. SchemaUnregister(id string) error // SchemaExist check if the given schema exists in the registry. SchemaExist(id string) bool }
SchemaRegistry permits to register multiple schemas and manage them.
type StateCallback ¶
StateCallback is a type of callback occurring on state changes.
type Sync ¶
type Sync interface { // Go Go(f func(quit <-chan struct{}) error) // Quit Quit() // Wait Wait() error }
Sync is an abstraction representing the final stage of a GoRoutine pipeline.
type Type ¶
type Type interface { // Name returns the name of the type. Name() string // Type returns the a reflection type (reflection). Type() reflect.Type }
Type represents a message type.
type TypeRegistry ¶
type TypeRegistry interface { // TypeRegister registers a new Type in the registry. TypeRegister(t Type) (string, error) // TypeGetByName retrieve the Type in the registry given its key. TypeGetByName(key string) (Type, error) // TypeGetByType retrieve the type in the registry given its type. TypeGetByType(t reflect.Type) (Type, error) // TypeListNames list all the item names (Types) contained in the registry. TypeListNames() []string // TypeUnregister removes the item from the registry. TypeUnregister(key string) error // TypeExist check if the given key exists in the registry. TypeExist(key string) bool }
TypeRegistry is a registry for types. It enables us to register multiple Types and manage them with it.