Documentation ¶
Index ¶
- func ValidateDir(dir string) (validationErrors []string, err error)
- type InfoSource
- type Machine
- func (m *Machine) AvailableTransitions() []string
- func (m *Machine) Can(t string) bool
- func (m *Machine) Debugf(watcher string, format string, args ...interface{})
- func (m *Machine) Directory() string
- func (m *Machine) Errorf(watcher string, format string, args ...interface{})
- 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) KnownStates() []string
- func (m *Machine) KnownTransitions() []string
- func (m *Machine) Name() string
- func (m *Machine) NotifyWatcherState(watcher string, state interface{})
- func (m *Machine) RegisterNotifier(services ...NotificationService)
- func (m *Machine) SetIdentity(id 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) 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) 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 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"` sync.Mutex // contains filtered or unexported fields }
Machine is a autonomous agent implemented as a Finite State Machine and hosted within Choria Server
func FromYAML ¶
func FromYAML(file string, manager WatcherManager) (m *Machine, err error)
FromYAML loads a macine from a YAML definition
func (*Machine) AvailableTransitions ¶
AvailableTransitions reports the transitions thats possible in the current state
func (*Machine) Directory ¶
Directory returns the directory where the machine definition is, "" when unknown
func (*Machine) InstanceID ¶
InstanceID is a unique id for the instance of a machine
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) NotifyWatcherState ¶
NotifyWatcherState implements NotificationService
func (*Machine) RegisterNotifier ¶
func (m *Machine) RegisterNotifier(services ...NotificationService)
RegisterNotifier adds a new NotificationService to the list of ones to receive notifications
func (*Machine) SetIdentity ¶
SetIdentity sets the identity of the node hosting this machine
func (*Machine) Stop ¶
func (m *Machine) Stop()
Stop stops a running machine by canceling its context
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) 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"` }
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 }
WatcherManager manages watchers
type WatcherStateNotification ¶
type WatcherStateNotification interface { JSON() ([]byte, error) CloudEvent() cloudevents.Event String() string WatcherType() string }
WatcherStateNotification is a notification about the state of a watcher
func ParseWatcherState ¶
func ParseWatcherState(state []byte) (n WatcherStateNotification, err error)
ParseWatcherState parses the watcher state JSON