Documentation ¶
Index ¶
- func ValidateDir(dir string) (validationErrors []string, err error)
- type ActivationChecker
- type InfoSource
- type Machine
- func (m *Machine) AvailableTransitions() []string
- func (m *Machine) Can(t string) bool
- func (m *Machine) ChoriaStatusFile() (string, int)
- func (m *Machine) Data() map[string]interface{}
- func (m *Machine) DataDelete(key string) error
- func (m *Machine) DataGet(key string) (interface{}, bool)
- func (m *Machine) DataPut(key string, val interface{}) error
- func (m *Machine) Debugf(watcher string, format string, args ...interface{})
- func (m *Machine) Delete()
- func (m *Machine) Directory() string
- func (m *Machine) Errorf(watcher string, format string, args ...interface{})
- func (m *Machine) Facts() json.RawMessage
- func (m *Machine) Graph() string
- func (m *Machine) Hash() (string, error)
- func (m *Machine) Identity() string
- func (m *Machine) Infof(watcher string, format string, args ...interface{})
- func (m *Machine) InstanceID() string
- func (m *Machine) IsEmbedded() bool
- func (m *Machine) IsStarted() bool
- func (m *Machine) JetStreamConnection() (*jsm.Manager, error)
- func (m *Machine) KnownStates() []string
- func (m *Machine) KnownTransitions() []string
- func (m *Machine) MainCollective() string
- func (m *Machine) Name() string
- func (m *Machine) NotifyWatcherState(watcher string, state interface{})
- func (m *Machine) OverrideData() ([]byte, error)
- func (m *Machine) PublishLifecycleEvent(t lifecycle.Type, opts ...lifecycle.Option)
- func (m *Machine) RegisterNotifier(services ...NotificationService)
- func (m *Machine) SetChoriaStatusFile(f string, freq int)
- func (m *Machine) SetConnection(conn inter.Connector) error
- func (m *Machine) SetDirectory(dir string, manifest string) error
- func (m *Machine) SetFactSource(facts func() json.RawMessage)
- func (m *Machine) SetIdentity(id string)
- func (m *Machine) SetMainCollective(collective string)
- func (m *Machine) SetOverridesFile(f string)
- func (m *Machine) SetTextFileDirectory(d string)
- func (m *Machine) Setup() error
- func (m *Machine) Start(ctx context.Context, wg *sync.WaitGroup) (started chan struct{})
- func (m *Machine) StartTime() time.Time
- func (m *Machine) State() string
- func (m *Machine) Stop()
- func (m *Machine) TextFileDirectory() string
- func (m *Machine) TimeStamp() time.Time
- func (m *Machine) TimeStampSeconds() int64
- func (m *Machine) Transition(t string, args ...interface{}) error
- func (m *Machine) UniqueID() (id string)
- func (m *Machine) Validate() error
- func (m *Machine) Version() string
- func (m *Machine) Warnf(watcher string, format string, args ...interface{})
- func (m *Machine) WatcherState(watcher string) (interface{}, bool)
- func (m *Machine) Watchers() []*watchers.WatcherDef
- type NotificationService
- type Transition
- type TransitionNotification
- type WatcherManager
- type WatcherStateNotification
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ValidateDir ¶
ValidateDir validates a machine.yaml against the v1 schema
Types ¶
type ActivationChecker ¶ added in v0.24.0
ActivationChecker allows embedded machines to determine if they should activate or not
type InfoSource ¶
type InfoSource interface { // Identity retrieves the identity of the node hosting this machine, "unknown" when not set Identity() string // Version returns the version of the machine Version() string // Name is the name of the machine Name() string // State returns the current state of the machine State() string // InstanceID return the unique ID of the machine instance InstanceID() string }
InfoSource provides information about a running machine
type Machine ¶
type Machine struct { // MachineName is the unique name for this machine MachineName string `json:"name" yaml:"name"` // MachineVersion is the semver compliant version for the running machine MachineVersion string `json:"version" yaml:"version"` // InitialState is the state this machine starts in when it first starts InitialState string `json:"initial_state" yaml:"initial_state"` // Transitions contain a list of valid events of transitions this machine can move through Transitions []*Transition `json:"transitions" yaml:"transitions"` // WatcherDefs contains all the watchers that can interact with the system WatcherDefs []*watchers.WatcherDef `json:"watchers" yaml:"watchers"` // SplayStart causes a random sleep of maximum this many seconds before the machine starts SplayStart int `json:"splay_start" yaml:"splay_start"` // ActivationCheck when set this can be called to avoid activating a plugin // typically this would be used when compiling machines into the binary ActivationCheck ActivationChecker `json:"-" yaml:"-"` sync.Mutex // contains filtered or unexported fields }
Machine is a autonomous agent implemented as a Finite State Machine and hosted within Choria Server
func FromPlugin ¶ added in v0.24.0
func FromPlugin(p model.MachineConstructor, manager WatcherManager, log *logrus.Entry) (*Machine, error)
func FromYAML ¶
func FromYAML(file string, manager WatcherManager) (m *Machine, err error)
FromYAML loads a machine from a YAML definition
func (*Machine) AvailableTransitions ¶
AvailableTransitions reports the transitions thats possible in the current state
func (*Machine) ChoriaStatusFile ¶ added in v0.19.0
ChoriaStatusFile is the path to and write frequency of the choria status file, empty when not set
func (*Machine) Data ¶ added in v0.23.0
Data retrieves a copy of the current data stored by the machine, changes will not be reflected in the machine
func (*Machine) DataDelete ¶ added in v0.23.0
DataDelete deletes a value from the store
func (*Machine) DataGet ¶ added in v0.23.0
DataGet gets the value for a key, empty string and false when no value is stored
func (*Machine) Delete ¶ added in v0.15.0
func (m *Machine) Delete()
Delete deletes a running machine by canceling its context and giving its manager a change to do clean up before final termination
func (*Machine) Directory ¶
Directory returns the directory where the machine definition is, "" when unknown
func (*Machine) Facts ¶ added in v0.23.0
func (m *Machine) Facts() json.RawMessage
Facts is the active facts for the node
func (*Machine) InstanceID ¶
InstanceID is a unique id for the instance of a machine
func (*Machine) IsEmbedded ¶ added in v0.24.0
func (*Machine) IsStarted ¶ added in v0.24.0
IsStarted determines if the machine is currently running
func (*Machine) JetStreamConnection ¶ added in v0.23.0
func (*Machine) KnownStates ¶
KnownStates is a list of all the known states in the Machine gathered by looking at initial state and all the states mentioned in transitions
func (*Machine) KnownTransitions ¶
KnownTransitions is a list of known transition names
func (*Machine) MainCollective ¶ added in v0.23.0
MainCollective is the main collective this choria belongs to
func (*Machine) NotifyWatcherState ¶
NotifyWatcherState implements NotificationService
func (*Machine) OverrideData ¶ added in v0.15.0
func (*Machine) PublishLifecycleEvent ¶ added in v0.23.0
func (*Machine) RegisterNotifier ¶
func (m *Machine) RegisterNotifier(services ...NotificationService)
RegisterNotifier adds a new NotificationService to the list of ones to receive notifications
func (*Machine) SetChoriaStatusFile ¶ added in v0.19.0
SetChoriaStatusFile sets the path and write frequency of the choria status file
func (*Machine) SetConnection ¶ added in v0.23.0
func (*Machine) SetDirectory ¶ added in v0.24.0
func (*Machine) SetFactSource ¶ added in v0.23.0
func (m *Machine) SetFactSource(facts func() json.RawMessage)
SetFactSource sets a function that return current machine facts
func (*Machine) SetIdentity ¶
SetIdentity sets the identity of the node hosting this machine
func (*Machine) SetMainCollective ¶ added in v0.23.0
SetMainCollective sets the collective name this machine lives in
func (*Machine) SetOverridesFile ¶ added in v0.15.0
func (*Machine) SetTextFileDirectory ¶ added in v0.15.0
func (*Machine) Stop ¶
func (m *Machine) Stop()
Stop stops a running machine by canceling its context
func (*Machine) TextFileDirectory ¶ added in v0.15.0
func (*Machine) TimeStampSeconds ¶
TimeStampSeconds returns the current time in unix seconds
func (*Machine) Transition ¶
Transition performs the machine transition as defined by event t
func (*Machine) UniqueID ¶
UniqueID creates a new unique ID, usually a v4 uuid, if that fails a random string based ID is made
func (*Machine) WatcherState ¶ added in v0.17.0
WatcherState is the status of a given watcher, boolean result is false for unknown watchers
func (*Machine) Watchers ¶
func (m *Machine) Watchers() []*watchers.WatcherDef
Watchers retrieves the watcher definitions
type NotificationService ¶
type NotificationService interface { // NotifyPostTransition receives an event after a transition completed NotifyPostTransition(t *TransitionNotification) error // NotifyWatcherState receives the current state of a watcher either after running or periodically NotifyWatcherState(watcher string, state WatcherStateNotification) error // Debugf logs a message at debug level Debugf(machine InfoSource, watcher string, format string, args ...interface{}) // Infof logs a message at info level Infof(machine InfoSource, watcher string, format string, args ...interface{}) // Warnf logs a message at warning level Warnf(machine InfoSource, watcher string, format string, args ...interface{}) // Errorf logs a message at error level Errorf(machine InfoSource, watcher string, format string, args ...interface{}) }
NotificationService receives events notifications about the state machine
type Transition ¶
type Transition struct { // Name is the name for the transition shown in logs and graphs Name string `json:"name" yaml:"name"` // From is a list of valid state names from where this transition event is valid From []string `json:"from" yaml:"from"` // Destination is the name of the target state this event will move the machine into Destination string `json:"destination" yaml:"destination"` // Description is a human friendly description of the purpose of this transition Description string `json:"description" yaml:"description"` }
Transition describes a transition event within the Finite State Machine
type TransitionNotification ¶
type TransitionNotification struct { Protocol string `json:"protocol"` Identity string `json:"identity"` ID string `json:"id"` Version string `json:"version"` Timestamp int64 `json:"timestamp"` Machine string `json:"machine"` Transition string `json:"transition"` FromState string `json:"from_state"` ToState string `json:"to_state"` Info InfoSource `json:"-"` }
TransitionNotification is a notification when a transition completes
func (*TransitionNotification) CloudEvent ¶ added in v0.13.0
func (t *TransitionNotification) CloudEvent() cloudevents.Event
CloudEvent creates a cloud event from the transition
func (*TransitionNotification) String ¶
func (t *TransitionNotification) String() string
String returns a string representation of the event
type WatcherManager ¶
type WatcherManager interface { Run(context.Context, *sync.WaitGroup) error NotifyStateChance() SetMachine(interface{}) error WatcherState(watcher string) (interface{}, bool) Delete() }
WatcherManager manages watchers
type WatcherStateNotification ¶
type WatcherStateNotification interface { JSON() ([]byte, error) CloudEvent() cloudevents.Event String() string WatcherType() string SenderID() string }
WatcherStateNotification is a notification about the state of a watcher