agents

package
v0.29.4 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2024 License: Apache-2.0 Imports: 14 Imported by: 10

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Agent

type Agent interface {
	Metadata() *Metadata
	Name() string
	HandleMessage(context.Context, inter.Message, protocol.Request, inter.ConnectorInfo, chan *AgentReply)
	SetServerInfo(ServerInfoSource)
	ServerInfo() ServerInfoSource
	ShouldActivate() bool
}

Agent is a generic choria agent

type AgentReply

type AgentReply struct {
	Body    []byte
	Request protocol.Request
	Message inter.Message
	Error   error
}

AgentReply is a generic reply from an agent

type Manager

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

Manager manages agents, handles registration, dispatches requests etc

func New

New creates a new Agent Manager

func NewServices added in v0.23.0

func NewServices(requests chan inter.ConnectorMessage, fw inter.Framework, conn inter.ConnectorInfo, srv ServerInfoSource, log *logrus.Entry) *Manager

NewServices creates an agent manager restricted to service agents

func (*Manager) Choria

func (a *Manager) Choria() inter.Framework

Choria provides an instance of the choria framework

func (*Manager) DenyAgent

func (a *Manager) DenyAgent(agent string)

DenyAgent adds an agent to the list of agent names not allowed to start

func (*Manager) Dispatch

func (a *Manager) Dispatch(ctx context.Context, wg *sync.WaitGroup, replies chan *AgentReply, msg inter.Message, request protocol.Request)

Dispatch sends a request to a agent and wait for a reply

func (*Manager) Get

func (a *Manager) Get(name string) (Agent, bool)

Get retrieves an agent by name

func (*Manager) KnownAgents

func (a *Manager) KnownAgents() []string

KnownAgents retrieves a list of known agents

func (*Manager) Logger

func (a *Manager) Logger() *logrus.Entry

Logger is the logger the manager prefers new agents derive from

func (*Manager) RegisterAgent

func (a *Manager) RegisterAgent(ctx context.Context, name string, agent Agent, conn inter.AgentConnector) error

RegisterAgent connects a new agent to the server instance, subscribe to all its targets etc

func (*Manager) ReplaceAgent added in v0.28.0

func (a *Manager) ReplaceAgent(name string, agent Agent) error

ReplaceAgent allows an agent manager to replace an agent that is already known, and subsscribed, with another instance to facilitate in-place upgrades

func (*Manager) UnregisterAgent added in v0.28.0

func (a *Manager) UnregisterAgent(name string, conn inter.AgentConnector) error

UnregisterAgent attempts to remove interest in messages for an agent

Each agent has a number of subscriptions (one per collective) so this can fail for some while working for others, in this case the agent is essentially in an unrecoverable state however the cases where unsubscribe will error are quite few in the nats client as its not being-connected dependant and we handle most errors correctly.

So this function will try to unsubscribe but if it fails, it will continue and finally unload the agent, any stale subscriptions then will be dropped by the handlers so its ok. We will treat unsbuscribe errors as non terminal, only logging errors.

type Metadata

type Metadata struct {
	License     string `json:"license"`
	Author      string `json:"author"`
	Timeout     int    `json:"timeout"`
	Name        string `json:"name"`
	Version     string `json:"version"`
	URL         string `json:"url"`
	Description string `json:"description"`
	Provider    string `json:"provider,omitempty"`
	Service     bool   `json:"service,omitempty"`
}

Metadata describes an agent at a high level and is required for any agent

type ServerInfoSource

type ServerInfoSource interface {
	AgentMetadata(string) (Metadata, bool)
	BuildInfo() *build.Info
	Classes() []string
	ConfigFile() string
	ConnectedServer() string
	DataFuncMap() (ddl.FuncMap, error)
	Facts() json.RawMessage
	Identity() string
	KnownAgents() []string
	LastProcessedMessage() time.Time
	MachineTransition(name string, version string, path string, id string, transition string) error
	MachinesStatus() ([]aagent.MachineState, error)
	NewEvent(t lifecycle.Type, opts ...lifecycle.Option) error
	PrepareForShutdown() error
	Provisioning() bool
	StartTime() time.Time
	Stats() statistics.ServerStats
	UpTime() int64
}

ServerInfoSource provides data about a running server instance

Jump to

Keyboard shortcuts

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