hook

package
v0.0.0-...-6cf1bc9 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2016 License: AGPL-3.0 Imports: 6 Imported by: 0

Documentation

Overview

hook provides types that define the hooks known to the Uniter

Index

Constants

View Source
const (
	LeaderElected         hooks.Kind = "leader-elected"
	LeaderDeposed         hooks.Kind = "leader-deposed"
	LeaderSettingsChanged hooks.Kind = "leader-settings-changed"
)

TODO(fwereade): move these definitions to juju/charm/hooks.

Variables

This section is empty.

Functions

This section is empty.

Types

type Committer

type Committer interface {
	CommitHook(Info) error
}

Committer is an interface that may be used to convey the fact that the specified hook has been successfully executed, and committed.

type Info

type Info struct {
	Kind hooks.Kind `yaml:"kind"`

	// RelationId identifies the relation associated with the hook. It is
	// only set when Kind indicates a relation hook.
	RelationId int `yaml:"relation-id,omitempty"`

	// RemoteUnit is the name of the unit that triggered the hook. It is only
	// set when Kind indicates a relation hook other than relation-broken.
	RemoteUnit string `yaml:"remote-unit,omitempty"`

	// ChangeVersion identifies the most recent unit settings change
	// associated with RemoteUnit. It is only set when RemoteUnit is set.
	ChangeVersion int64 `yaml:"change-version,omitempty"`

	// StorageId is the ID of the storage instance relevant to the hook.
	StorageId string `yaml:"storage-id,omitempty"`
}

Info holds details required to execute a hook. Not all fields are relevant to all Kind values.

func (Info) Validate

func (hi Info) Validate() error

Validate returns an error if the info is not valid.

type NoUpdates

type NoUpdates struct{}

NoUpdates implements a subset of HookSource that delivers no changes, errors on update, and ignores stop requests (because there's nothing running in the first place). It's useful for implementing static HookSources.

func (*NoUpdates) Changes

func (_ *NoUpdates) Changes() <-chan SourceChange

func (*NoUpdates) Stop

func (_ *NoUpdates) Stop() error

type Peek

type Peek interface {
	// HookInfo returns information about the hook at the head of the queue.
	HookInfo() Info
	// Consume pops the hook from the head of the queue and makes new Peeks
	// available.
	Consume()
	// Reject makes new Peeks available.
	Reject()
}

Peek exists to support Peeker and has no independent meaning or existence. Receiving a Peek from a Peeker's Peek channel implies acceptance of the responsibility to either Consume or Reject the Peek.

type Peeker

type Peeker interface {
	// Peeks returns a channel on which Peeks are delivered. The receiver of a
	// Peek must Consume or Reject the Peek before further peeks will be sent.
	Peeks() <-chan Peek
	// Stop stops the Peeker's Source, and prevents any further Peeks from
	// being delivered.
	Stop() error
}

Peeker maintains a Source, and allows an external client to inspect and consume, or reject, the head of the queue.

func NewPeeker

func NewPeeker(source Source) Peeker

NewPeeker returns a new Peeker providing a view of the supplied source (of which it takes ownership).

type Sender

type Sender interface {
	Stop() error
}

Sender maintains a Source and delivers its hooks via a channel.

func NewSender

func NewSender(out chan<- Info, source Source) Sender

NewSender starts sending hooks from source onto the out channel, and will continue to do so until Stop()ped (or the source is exhausted). NewSender takes ownership of the supplied source, and responsibility for cleaning it up; but it will not close the out channel.

type Source

type Source interface {

	// Changes returns a channel sending events which must be processed
	// synchronously, and in order.
	Changes() <-chan SourceChange

	// Stop causes the Source to clean up its resources and stop sending
	// changes.
	Stop() error

	// Empty returns false if any hooks are scheduled.
	Empty() bool

	// Next returns the first scheduled hook. It will panic if no hooks are
	// scheduled.
	Next() Info

	// Pop removes the first scheduled hook, and invalidates the results of
	// previous calls to Next() and Empty(). It will panic if no hooks are
	// scheduled.
	Pop()
}

Source defines a generator of Info events.

A Source's client must be careful to:

  • use it from a single goroutine.
  • collect asynchronous events from Changes(), and synchronously Apply() them whenever possible.
  • only use fresh values returned from Empty() and Next(); i.e. only those which have been generated since the last call to Pop() or Update().
  • Stop() it when finished.

func NewListSource

func NewListSource(list []Info) Source

NewListSource returns a Source that generates only the supplied hooks, in order; and which cannot be updated.

type SourceChange

type SourceChange func() error

SourceChange is the type of functions returned via Source.Changes().

func (SourceChange) Apply

func (s SourceChange) Apply() error

Apply applies the change to its Source's schedule, and invalidates the results of previous calls to Next() and Empty().

type Validator

type Validator interface {
	ValidateHook(Info) error
}

Validator is an interface that may be used to validate a hook execution request prior to executing it.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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