watcher

package
v0.0.0-...-b0bff92 Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2021 License: AGPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CoreWatcher

type CoreWatcher interface {
	worker.Worker
}

CoreWatcher encodes some features of a watcher. The most obvious one:

Changes() <-chan <T>

...can't be expressed cleanly; and this is annoying because every such chan needs to share common behaviours for the abstraction to be generally helpful. The critical features of a Changes chan are as follows:

  • The channel should never be closed.

  • The channel should send a single baseline value, representing the change from a nil state; and subsequently send values representing deltas from whatever had previously been sent.

  • The channel should really never be closed. Many existing watchers *do* close their channels when the watcher stops; this is harmful because it mixes lifetime-handling into change-handling at the cost of clarity (and in some cases correctness). So long as a watcher implements Worker, it can be safely managed with the worker/catacomb package; of course, all sensible clients will still check for closed channels (never trust a contract...) but can treat that scenario as a simple error.

    (This rule only applies to watchers outside the API; watchers inside the API boundary need to close their changes channel so that the .Next() method implementations inside the API server (see apiserver/watcher.go) finish correctly.)

To convert a state/watcher.Watcher to a CoreWatcher, ensure that the watcher no longer closes its Changes() channel; and replace Stop() and Err() with the usual worker boilerplate. Namely:

// Kill is part of the worker.Worker interface.
func (w *watcher) Kill() {
    w.tomb.Kill(nil)
}

// Wait is part of the worker.Worker interface.
func (w *watcher) Wait() error {
    return w.tomb.Wait()
}

Tests using state/testing/{$Kind}WatcherC should be converted to use the equivalents in watcher/watchertest.

type EntitiesWatcher

type EntitiesWatcher interface {
	CoreWatcher
	Changes() StringsChannel
}

EntitiesWatcher conveniently ties an StringsChannel to the worker.Worker that represents its validity.

It purports to deliver strings that can be parsed as tags, but since it doesn't actually produce tags today we may as well make it compatible with StringsWatcher so we can use it with a StringsHandler. In an ideal world we'd have something like `type EntitiesChannel <-chan []names.Tag` instead.

type MachineStorageId

type MachineStorageId struct {
	MachineTag    string
	AttachmentTag string
}

MachineStorageId associates a machine entity with a storage entity. They're expressed as tags because they arrived here as a move, not a change; ideally a MachineStorageIdsWatcher would return them in a more model-appropriate format (i.e. not as strings-that-probably-parse-to-tags).

type MachineStorageIdsChannel

type MachineStorageIdsChannel <-chan []MachineStorageId

MachineStorageIdsChannel is a change channel as described in the CoreWatcher docs.

It reports additions and removals to a set of attachments; and lifecycle changes within the active set.

type MachineStorageIdsWatcher

type MachineStorageIdsWatcher interface {
	CoreWatcher
	Changes() MachineStorageIdsChannel
}

MachineStorageIdsWatcher conveniently ties a MachineStorageIdsChannel to the worker.Worker that represents its validity.

type MigrationStatus

type MigrationStatus struct {
	MigrationId    string
	Attempt        int
	Phase          migration.Phase
	SourceAPIAddrs []string
	SourceCACert   string
	TargetAPIAddrs []string
	TargetCACert   string
}

MigrationStatus is the client side version of params.MigrationStatus.

type MigrationStatusWatcher

type MigrationStatusWatcher interface {
	CoreWatcher
	Changes() <-chan MigrationStatus
}

MigrationStatusWatcher describes a watcher that reports the latest status of a migration for a model.

type MultiNotifyWatcher

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

MultiNotifyWatcher implements NotifyWatcher, combining multiple NotifyWatchers.

func NewMultiNotifyWatcher

func NewMultiNotifyWatcher(w ...NotifyWatcher) *MultiNotifyWatcher

NewMultiNotifyWatcher creates a NotifyWatcher that combines each of the NotifyWatchers passed in. Each watcher's initial event is consumed, and a single initial event is sent. Subsequent events are not coalesced.

func (*MultiNotifyWatcher) Changes

func (w *MultiNotifyWatcher) Changes() NotifyChannel

func (*MultiNotifyWatcher) Err

func (w *MultiNotifyWatcher) Err() error

func (*MultiNotifyWatcher) Kill

func (w *MultiNotifyWatcher) Kill()

func (*MultiNotifyWatcher) Stop

func (w *MultiNotifyWatcher) Stop() error

func (*MultiNotifyWatcher) Wait

func (w *MultiNotifyWatcher) Wait() error

type NotifyChannel

type NotifyChannel <-chan struct{}

NotifyChannel is a change channel as described in the CoreWatcher docs.

It sends a single value to indicate that the watch is active, and subsequent values whenever the value(s) under observation change(s).

type NotifyConfig

type NotifyConfig struct {
	Handler NotifyHandler
}

NotifyConfig holds the direct dependencies of a NotifyWorker.

func (NotifyConfig) Validate

func (config NotifyConfig) Validate() error

Validate returns an error if the config cannot start a NotifyWorker.

type NotifyHandler

type NotifyHandler interface {

	// SetUp is called once when creating a NotifyWorker. It must return a
	// NotifyWatcher or an error. The NotifyHandler takes responsibility for
	// stopping any returned watcher and handling any errors.
	SetUp() (NotifyWatcher, error)

	// Handle is called whenever a value is received from the NotifyWatcher
	// returned by SetUp. If it returns an error, the NotifyWorker will be
	// stopped.
	//
	// If Handle runs any blocking operations it must pass through, or select
	// on, the supplied abort channel; this channel will be closed when the
	// NotifyWorker is killed. An aborted Handle should not return an error.
	Handle(abort <-chan struct{}) error

	// TearDown is called once when stopping a NotifyWorker, whether or not
	// SetUp succeeded. It need not concern itself with the NotifyWatcher, but
	// must clean up any other resources created in SetUp or Handle.
	TearDown() error
}

NotifyHandler defines the operation of a NotifyWorker.

type NotifyWatcher

type NotifyWatcher interface {
	CoreWatcher
	Changes() NotifyChannel
}

NotifyWatcher conveniently ties a NotifyChannel to the worker.Worker that represents its validity.

type NotifyWorker

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

NotifyWorker is a worker that wraps a NotifyWatcher.

func NewNotifyWorker

func NewNotifyWorker(config NotifyConfig) (*NotifyWorker, error)

NewNotifyWorker starts a new worker that runs a NotifyHandler.

func (*NotifyWorker) Kill

func (nw *NotifyWorker) Kill()

Kill is part of the worker.Worker interface.

func (*NotifyWorker) Report

func (nw *NotifyWorker) Report() map[string]interface{}

Report implements dependency.Reporter.

func (*NotifyWorker) Wait

func (nw *NotifyWorker) Wait() error

Wait is part of the worker.Worker interface.

type OfferStatusChange

type OfferStatusChange struct {
	// Name is the name of the offer.
	Name string

	// Status is the status of the offer.
	Status status.StatusInfo
}

OfferStatusChange describes changes to some offer.

type OfferStatusChannel

type OfferStatusChannel <-chan []OfferStatusChange

OfferStatusChannel is a channel used to notify of changes to an offer's status.

type OfferStatusWatcher

type OfferStatusWatcher interface {
	CoreWatcher
	Changes() OfferStatusChannel
}

OfferStatusWatcher conveniently ties an OfferStatusChannel to the worker.Worker that represents its validity.

type RelationStatusChange

type RelationStatusChange struct {
	// Key is the relation key of the changed relation.
	Key string

	// Suspended is the suspended status of the relation.
	Suspended bool

	// SuspendedReason is an optional message to explain why suspend is true.
	SuspendedReason string

	// Life is the relation life value, eg Alive.
	Life life.Value
}

RelationStatusChange describes changes to some relation.

type RelationStatusChannel

type RelationStatusChannel <-chan []RelationStatusChange

RelationStatusChannel is a channel used to notify of changes to a relation's life or suspended status.

type RelationStatusWatcher

type RelationStatusWatcher interface {
	CoreWatcher
	Changes() RelationStatusChannel
}

RelationStatusWatcher conveniently ties a RelationStatusChannel to the worker.Worker that represents its validity.

type RelationUnitsChange

type RelationUnitsChange struct {

	// Changed holds a set of units that are known to be in scope, and the
	// latest known settings version for each.
	Changed map[string]UnitSettings

	// AppChanged holds the latest known settings version for associated
	// applications.
	AppChanged map[string]int64

	// Departed holds a set of units that have previously been reported to
	// be in scope, but which no longer are.
	Departed []string
}

RelationUnitsChange describes the membership and settings of; or changes to; some relation scope.

type RelationUnitsChannel

type RelationUnitsChannel <-chan RelationUnitsChange

RelationUnitsChannel is a change channel as described in the CoreWatcher docs.

It sends a single value representing the current membership of a relation scope; and the versions of the settings documents for each; and subsequent values representing entry, settings-change, and departure for units in that scope.

It feeds the joined-changed-departed logic in worker/uniter, but these events do not map 1:1 with hooks.

type RelationUnitsWatcher

type RelationUnitsWatcher interface {
	CoreWatcher
	Changes() RelationUnitsChannel
}

RelationUnitsWatcher conveniently ties a RelationUnitsChannel to the worker.Worker that represents its validity.

type SecretRotationChange

type SecretRotationChange struct {
	ID             int
	URL            *secrets.URL
	RotateInterval time.Duration
	LastRotateTime time.Time
}

SecretRotationChange describes changes to secret rotation config.

type SecretRotationChannel

type SecretRotationChannel <-chan []SecretRotationChange

SecretRotationChannel is a change channel as described in the CoreWatcher docs.

type SecretRotationWatcher

type SecretRotationWatcher interface {
	CoreWatcher
	Changes() SecretRotationChannel
}

SecretRotationWatcher conveniently ties a SecretRotationChannel to the worker.Worker that represents its validity.

type StringsChannel

type StringsChannel <-chan []string

StringsChannel is a change channel as described in the CoreWatcher docs.

It sends a single value indicating a baseline set of values, and subsequent values representing additions, changes, and/or removals of those values. The precise semantics may depend upon the individual watcher.

type StringsConfig

type StringsConfig struct {
	Handler StringsHandler
}

StringsConfig holds the direct dependencies of a StringsWorker.

func (StringsConfig) Validate

func (config StringsConfig) Validate() error

Validate returns ann error if the config cannot start a StringsWorker.

type StringsHandler

type StringsHandler interface {

	// SetUp is called once when creating a StringsWorker. It must return a
	// StringsWatcher or an error. The StringsHandler takes responsibility for
	// stopping any returned watcher and handling any errors.
	SetUp() (StringsWatcher, error)

	// Handle is called with every value received from the StringsWatcher
	// returned by SetUp. If it returns an error, the StringsWorker will be
	// stopped.
	//
	// If Handle runs any blocking operations it must pass through, or select
	// on, the supplied abort channel; this channel will be closed when the
	// StringsWorker is killed. An aborted Handle should not return an error.
	Handle(abort <-chan struct{}, changes []string) error

	// TearDown is called once when stopping a StringsWorker, whether or not
	// SetUp succeeded. It need not concern itself with the StringsWatcher, but
	// must clean up any other resources created in SetUp or Handle.
	TearDown() error
}

StringsHandler defines the operation of a StringsWorker.

type StringsWatcher

type StringsWatcher interface {
	CoreWatcher
	Changes() StringsChannel
}

StringsWatcher conveniently ties a StringsChannel to the worker.Worker that represents its validity.

type StringsWorker

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

StringsWorker is a worker that wraps a StringsWatcher.

func NewStringsWorker

func NewStringsWorker(config StringsConfig) (*StringsWorker, error)

NewStringsWorker starts a new worker that runs a StringsHandler.

func (*StringsWorker) Kill

func (sw *StringsWorker) Kill()

Kill is part of the worker.Worker interface.

func (*StringsWorker) Report

func (sw *StringsWorker) Report() map[string]interface{}

Report implements dependency.Reporter.

func (*StringsWorker) Wait

func (sw *StringsWorker) Wait() error

Wait is part of the worker.Worker interface.

type UnitSettings

type UnitSettings struct {
	Version int64
}

UnitSettings specifies the version of some unit's settings in some relation.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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