agentimpl

package
v0.0.0-...-4c6df9b Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2018 License: Apache-2.0 Imports: 23 Imported by: 3

Documentation

Index

Constants

View Source
const MimeTypeAvroSchema = "application/js+avro"

MimeTypeAvroSchema represents the mime type we use for AVRO schemas.

View Source
const MimeTypeJSONSchema = "application/schema+json"

MimeTypeJSONSchema represents the mime type we use for JSON schemas.

Variables

This section is empty.

Functions

func LoadAvroSchema

func LoadAvroSchema(rawSchema string, registry agentiface.SchemaRegistry) (agentiface.Schema, error)

LoadAvroSchema loads the given raw Avro definition and returns a schema instance the registry is given as argument in order to resolve schemas that depends on other schema.

func LoadJSONSchema

func LoadJSONSchema(rawSchema string) (agentiface.Schema, error)

LoadJSONSchema loads the given Json Schema and returns a schema instance

func NewTypeFromInterface

func NewTypeFromInterface(name string, i interface{}) (agentiface.Type, error)

NewTypeFromInterface returns a new instance of Type from a name and an interface.

func NewTypeFromType

func NewTypeFromType(name string, t reflect.Type) agentiface.Type

NewTypeFromType returns a Type from a name and a Type reflection.

Types

type AMQP

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

AMQP is a low level handler of the AMQP connectionns, events and callbacks.

func NewAMQP

func NewAMQP(a *Agent) *AMQP

NewAMQP creates a new instance of AMQP

func (*AMQP) Connect

func (a *AMQP) Connect() (err error)

Connect actually connects to the AMQP broker and initializes all the exchanges and queues.

func (*AMQP) Disconnect

func (a *AMQP) Disconnect() error

Disconnect disconnect from the broker.

func (*AMQP) RegisterCommandCallback

func (a *AMQP) RegisterCommandCallback(commandName agentiface.MessageName, commandCallback agentiface.CommandCallback) (string, error)

RegisterCommandCallback registers a callback triggered by a command reception.

func (*AMQP) RegisterEventCallback

func (a *AMQP) RegisterEventCallback(filter agentiface.EventFilter, eventCallback agentiface.EventCallback) (string, error)

RegisterEventCallback registers a callback triggered by an event reception.

func (*AMQP) RegisterStateCallback

func (a *AMQP) RegisterStateCallback(stateCallback agentiface.StateCallback) string

RegisterStateCallback registers a callback triggered by state changes.

func (*AMQP) SendCommand

func (a *AMQP) SendCommand(to string, command interface{}) error

SendCommand sends a command to a specific agent.

func (*AMQP) State

func (a *AMQP) State() agentiface.State

State returns the state of the connection.

type Agent

type Agent struct {
	wait.Group

	*Cli
	*Config
	*SchemaRegistry
	*TypeRegistry
	*AMQP
	*Logger
	// contains filtered or unexported fields
}

Agent is the implementation of the base behaviour that all Crucibuild agents should implement: - config file parsing - logging - command line args parsing - command registration - etc...

func NewAgent

func NewAgent(manifest agentiface.Manifest) (agent *Agent, err error)

NewAgent creates a new Agent instance from a spec.

func (*Agent) ID

func (a *Agent) ID() string

ID returns the agent id.

func (*Agent) Manifest

func (a *Agent) Manifest() agentiface.Manifest

Manifest returns the manifest of the agent.

type AvroSchema

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

AvroSchema represents an AVRO schema with all its metadata.

func (*AvroSchema) Code

func (s *AvroSchema) Code(o interface{}) ([]byte, error)

Code serializes data using the AvroSchema registered.

func (*AvroSchema) Decode

func (s *AvroSchema) Decode(o []byte, t agentiface.Type) (interface{}, error)

Decode unserializes data using the AvroSchema registered.

func (*AvroSchema) ID

func (s *AvroSchema) ID() string

ID returns the AvroSchema ID.

func (*AvroSchema) MimeType

func (*AvroSchema) MimeType() string

MimeType returns the AvroSchema mime type.

func (*AvroSchema) Raw

func (s *AvroSchema) Raw() string

Raw returns the raw AvroSchema.

func (*AvroSchema) Title

func (s *AvroSchema) Title() string

Title returns the AvroSchema title.

type Cli

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

Cli implements command line argument parsing.

func NewCli

func NewCli(a agentiface.Agent) *Cli

NewCli creates an new Command Line Interface for the agent.

func (*Cli) ParseCommandLine

func (cli *Cli) ParseCommandLine() error

ParseCommandLine parse the arguments

func (*Cli) RegisterCommand

func (cli *Cli) RegisterCommand(cmd *cobra.Command)

RegisterCommand register additional commands available via the command line.

func (*Cli) RootCommand

func (cli *Cli) RootCommand() *cobra.Command

RootCommand return the rootCommand of the agent.

type Config

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

Config represents an agent configuration data.

func NewConfig

func NewConfig(a agentiface.Agent) *Config

NewConfig creates a new instance of Config for an agent.

func (*Config) BindConfigPFlag

func (config *Config) BindConfigPFlag(key string, flag *pflag.Flag) error

BindConfigPFlag binds a command line flag with a configuration key.

func (*Config) CreateDefaultConfig

func (config *Config) CreateDefaultConfig() error

CreateDefaultConfig initialize a new configuration file with default values. returns an error if configuration file already exists.

func (*Config) CreateDefaultConfigOverwrite

func (config *Config) CreateDefaultConfigOverwrite() error

CreateDefaultConfigOverwrite initialize a new configuration file with default values. Overwrite the file if it exists.

func (*Config) GetConfigString

func (config *Config) GetConfigString(key string) string

GetConfigString returns the value matching the key in parameter from the configuration file.

func (*Config) LoadConfig

func (config *Config) LoadConfig() error

LoadConfig reads the configuration from the config file.

func (*Config) LoadConfigFrom

func (config *Config) LoadConfigFrom(path string) error

LoadConfigFrom reads the configuration from the config file located at path.

func (*Config) PrintConfig

func (config *Config) PrintConfig(w io.Writer) error

PrintConfig prints the configuration values with w.

func (*Config) SetDefaultConfigOption

func (config *Config) SetDefaultConfigOption(key string, value interface{})

SetDefaultConfigOption sets default value for an option of the config.

type Ctx

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

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

func (*Ctx) Message

func (ctx *Ctx) Message() interface{}

Message returns the concrete instance of the deserialized message.

func (*Ctx) Messaging

func (ctx *Ctx) Messaging() agentiface.Messaging

Messaging returns the instance of Messaging.

func (*Ctx) Properties

func (ctx *Ctx) Properties() map[string]string

Properties returns the properties attached to the message.

func (*Ctx) Schema

func (ctx *Ctx) Schema() agentiface.Schema

Schema The (Avro) schema of the message serialized.

func (*Ctx) SendCommand

func (ctx *Ctx) SendCommand(to string, command interface{}) error

SendCommand sends a command as a consequence of this event (correlationId is set)

func (*Ctx) SendEvent

func (ctx *Ctx) SendEvent(event interface{}) error

SendEvent sends an event as a consequence of this message (correlationId is set)

type JSONSchema

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

JSONSchema represents a JSON Schema with all its metadata.

func (*JSONSchema) Code

func (s *JSONSchema) Code(o interface{}) ([]byte, error)

Code serializes data using the JSONSchema registered.

func (*JSONSchema) Decode

func (s *JSONSchema) Decode(o []byte, t agentiface.Type) (interface{}, error)

Decode unserializes data using the JSONSchema registered.

func (*JSONSchema) ID

func (s *JSONSchema) ID() string

ID returns the JSONSchema ID.

func (*JSONSchema) MimeType

func (*JSONSchema) MimeType() string

MimeType returns the JSONSchema mime type.

func (*JSONSchema) Raw

func (s *JSONSchema) Raw() string

Raw returns the raw JSONSchema.

func (*JSONSchema) Title

func (s *JSONSchema) Title() string

Title returns the JSONSchema title.

type Logger

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

Logger is an abstraction wrapping basic operations in order to log messages.

func NewLogger

func NewLogger(a agentiface.Agent) (*Logger, error)

NewLogger creates a new instance of Logger associated with an agent.

func (*Logger) Alert

func (l *Logger) Alert(format string, a ...interface{})

Alert prints a log with criticity Alert.

func (*Logger) Close

func (l *Logger) Close() error

Close actually closes the log stream.

func (*Logger) Critical

func (l *Logger) Critical(format string, a ...interface{})

Critical prints a log with criticity Critical.

func (*Logger) Debug

func (l *Logger) Debug(format string, a ...interface{})

Debug prints a log with criticity Debug.

func (*Logger) Emergency

func (l *Logger) Emergency(format string, a ...interface{})

Emergency prints a log with criticity Emergency.

func (*Logger) Error

func (l *Logger) Error(format string, a ...interface{})

Error prints a log with criticity Error.

func (*Logger) Info

func (l *Logger) Info(format string, a ...interface{})

Info prints a log with criticity Info.

func (*Logger) Warning

func (l *Logger) Warning(format string, a ...interface{})

Warning prints a log with criticity Warning.

type Manifest

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

Manifest represents the core properties defining an Agent.

func NewManifest

func NewManifest(agentSpec map[string]interface{}) *Manifest

NewManifest creates a new instance of Manifest from a map.

func (*Manifest) Description

func (agentSpec *Manifest) Description() string

Description returns the agent description.

func (*Manifest) Name

func (agentSpec *Manifest) Name() string

Name returns the agent name.

func (*Manifest) Spec

func (agentSpec *Manifest) Spec() map[string]interface{}

Spec return the complete agent specification.

func (*Manifest) Version

func (agentSpec *Manifest) Version() string

Version returns the agent version.

type SchemaRegistry

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

SchemaRegistry represents a registry for schemas.

func NewSchemaRegistry

func NewSchemaRegistry(a agentiface.Agent) *SchemaRegistry

NewSchemaRegistry creates a new instance of SchemaRegistry. nolint: unparam, parameter a is reserved for a future usage

func (*SchemaRegistry) SchemaExist

func (s *SchemaRegistry) SchemaExist(key string) bool

SchemaExist returns true if the key match a schema known by the registry.

func (*SchemaRegistry) SchemaGetByID

func (s *SchemaRegistry) SchemaGetByID(id string) (agentiface.Schema, error)

SchemaGetByID returns a schema which id matches the one in parameter.

func (*SchemaRegistry) SchemaListIds

func (s *SchemaRegistry) SchemaListIds() []string

SchemaListIds returns a map of <id, schema> known by the registry.

func (*SchemaRegistry) SchemaRegister

func (s *SchemaRegistry) SchemaRegister(schema agentiface.Schema) (string, error)

SchemaRegister registers a schema in the registry.

func (*SchemaRegistry) SchemaUnregister

func (s *SchemaRegistry) SchemaUnregister(id string) error

SchemaUnregister remove a schema from the registry.

type TypeRegistry

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

TypeRegistry is a registry referencing types.

func NewTypeRegistry

func NewTypeRegistry(a agentiface.Agent) *TypeRegistry

NewTypeRegistry returns a new instance of TypeRegistry from an agent. nolint: unparam, parameter a is reserved for a future usage

func (*TypeRegistry) TypeExist

func (s *TypeRegistry) TypeExist(key string) bool

TypeExist returns true if a type matching key is known to the registry.

func (*TypeRegistry) TypeGetByName

func (s *TypeRegistry) TypeGetByName(key string) (agentiface.Type, error)

TypeGetByName returns a Type which name's match key.

func (*TypeRegistry) TypeGetByType

func (s *TypeRegistry) TypeGetByType(v reflect.Type) (agentiface.Type, error)

TypeGetByType returns a Type from a reflect.Type.

func (*TypeRegistry) TypeListNames

func (s *TypeRegistry) TypeListNames() []string

TypeListNames returns a map(<id, name>) of all the registered types.

func (*TypeRegistry) TypeRegister

func (s *TypeRegistry) TypeRegister(t agentiface.Type) (string, error)

TypeRegister registers a Type into the registry.

func (*TypeRegistry) TypeUnregister

func (s *TypeRegistry) TypeUnregister(key string) error

TypeUnregister unregister the Type key from the registry.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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