watchers

package
v0.22.0 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2021 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseWatcherState added in v0.19.0

func ParseWatcherState(state []byte) (interface{}, error)

func RegisterWatcherPlugin added in v0.19.0

func RegisterWatcherPlugin(name string, plugin WatcherConstructor) error

RegisterWatcherPlugin registers a new type of watcher

Types

type Machine

type Machine interface {
	Name() string
	State() string
	Directory() string
	Transition(t string, args ...interface{}) error
	NotifyWatcherState(string, interface{})
	Watchers() []*WatcherDef
	Identity() string
	InstanceID() string
	Version() string
	TimeStampSeconds() int64
	TextFileDirectory() string
	OverrideData() ([]byte, error)
	ChoriaStatusFile() (string, int)
	Debugf(name string, format string, args ...interface{})
	Infof(name string, format string, args ...interface{})
	Errorf(name string, format string, args ...interface{})
}

Machine is a Choria Machine

type Manager

type Manager struct {
	sync.Mutex
	// contains filtered or unexported fields
}

Manager manages all the defined watchers in a specific machine implements machine.WatcherManager

func New

func New() *Manager

func (*Manager) AddWatcher

func (m *Manager) AddWatcher(w Watcher) error

AddWatcher adds a watcher to a managed machine

func (*Manager) Delete added in v0.15.0

func (m *Manager) Delete()

Delete gets called before a watcher is being deleted after its files were removed from disk

func (*Manager) NotifyStateChance

func (m *Manager) NotifyStateChance()

NotifyStateChance implements machine.WatcherManager

func (*Manager) Run

func (m *Manager) Run(ctx context.Context, wg *sync.WaitGroup) error

Run starts all the defined watchers and periodically announce their state based on AnnounceInterval

func (*Manager) SetMachine

func (m *Manager) SetMachine(t interface{}) (err error)

SetMachine supplies the machine this manager will manage

func (*Manager) WatcherState added in v0.17.0

func (m *Manager) WatcherState(watcher string) (interface{}, bool)

WatcherState retrieves the current status for a given watcher, boolean result is false for unknown watchers

type State

type State int

type Watcher

type Watcher interface {
	Name() string
	Type() string
	Run(context.Context, *sync.WaitGroup)
	NotifyStateChance()
	CurrentState() interface{}
	AnnounceInterval() time.Duration
	Delete()
}

Watcher is anything that can be used to watch the system for events

type WatcherConstructor added in v0.19.0

type WatcherConstructor interface {
	New(machine watcher.Machine, name string, states []string, failEvent string, successEvent string, interval string, ai time.Duration, properties map[string]interface{}) (interface{}, error)
	Type() string
	EventType() string
	UnmarshalNotification(n []byte) (interface{}, error)
}

WatcherConstructor creates a new watcher plugin

type WatcherDef

type WatcherDef struct {
	Name              string                 `json:"name" yaml:"name"`
	Type              string                 `json:"type" yaml:"type"`
	StateMatch        []string               `json:"state_match" yaml:"state_match"`
	FailTransition    string                 `json:"fail_transition" yaml:"fail_transition"`
	SuccessTransition string                 `json:"success_transition" yaml:"success_transition"`
	Interval          string                 `json:"interval" yaml:"interval"`
	AnnounceInterval  string                 `json:"announce_interval" yaml:"announce_interval"`
	Properties        map[string]interface{} `json:"properties" yaml:"properties"`
	AnnounceDuration  time.Duration          `json:"-" yaml:"-"`
}

WatcherDef is the core definition of a watcher, watcher type specific properties get stored in Properties and parsed by each watcher type

func (*WatcherDef) ParseAnnounceInterval

func (w *WatcherDef) ParseAnnounceInterval() (err error)

ParseAnnounceInterval parses the announce interval and ensures its not too small

func (*WatcherDef) ValidateStates

func (w *WatcherDef) ValidateStates(valid []string) (err error)

ValidateStates makes sure that all the states mentioned are valid

func (*WatcherDef) ValidateTransitions

func (w *WatcherDef) ValidateTransitions(valid []string) (err error)

ValidateTransitions checks that all stated transitions are valid

Directories

Path Synopsis
Package watcher is a generated GoMock package.
Package watcher is a generated GoMock package.

Jump to

Keyboard shortcuts

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