relation

package
v0.0.0-...-be26699 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2015 License: AGPL-3.0 Imports: 13 Imported by: 0

Documentation

Overview

relation implements persistent local storage of a unit's relation state, and translation of relation changes into hooks that need to be run.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewDyingHookSource

func NewDyingHookSource(initial *State) hook.Source

NewDyingHookSource returns a new hook.Source that generates all hooks necessary to clean up the supplied initial relation hook state, while preserving the guarantees Juju makes about hook execution order.

func NewLiveHookSource

func NewLiveHookSource(initial *State, w RelationUnitsWatcher) hook.Source

NewLiveHookSource returns a new HookSource that aggregates the values obtained from the w watcher and generates the hooks that must be executed in the unit. It guarantees that the stream of hooks will respect the guarantees Juju makes about hook execution order. If any values have previously been received from w's Changes channel, the Source's behaviour is undefined.

func ReadAllStateDirs

func ReadAllStateDirs(dirPath string) (dirs map[int]*StateDir, err error)

ReadAllStateDirs loads and returns every StateDir persisted directly inside the supplied dirPath. If dirPath does not exist, no error is returned.

Types

type HookQueue

type HookQueue interface {
	hook.Sender
}

HookQueue exists to keep the package interface stable.

func NewAliveHookQueue

func NewAliveHookQueue(initial *State, out chan<- hook.Info, w RelationUnitsWatcher) HookQueue

NewAliveHookQueue exists to keep the package interface stable; it wraps the result of NewLiveHookSource in a HookSender.

func NewDyingHookQueue

func NewDyingHookQueue(initial *State, out chan<- hook.Info) HookQueue

NewDyingHookQueue exists to keep the package interface stable; it wraps the result of NewDyingHookSource in a HookSender.

type RelationUnitsWatcher

type RelationUnitsWatcher interface {
	Err() error
	Stop() error
	Changes() <-chan multiwatcher.RelationUnitsChange
}

RelationUnitsWatcher produces RelationUnitsChange events until stopped, or until it encounters an error. It must not close its Changes channel without signalling an error via Stop and Err.

type State

type State struct {
	// RelationId identifies the relation.
	RelationId int

	// Members is a map from unit name to the last change version
	// for which a hook.Info was delivered on the output channel.
	Members map[string]int64

	// ChangedPending indicates that a "relation-changed" hook for the given
	// unit name must be the first hook.Info to be sent to the output channel.
	ChangedPending string
}

State describes the state of a relation.

func (*State) Validate

func (s *State) Validate(hi hook.Info) (err error)

Validate returns an error if the supplied hook.Info does not represent a valid change to the relation state. Hooks must always be validated against the current state before they are run, to ensure that the system meets its guarantees about hook execution order.

type StateDir

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

StateDir is a filesystem-backed representation of the state of a relation. Concurrent modifications to the underlying state directory will have undefined consequences.

func ReadStateDir

func ReadStateDir(dirPath string, relationId int) (d *StateDir, err error)

ReadStateDir loads a StateDir from the subdirectory of dirPath named for the supplied RelationId. If the directory does not exist, no error is returned,

func (*StateDir) Ensure

func (d *StateDir) Ensure() error

Ensure creates the directory if it does not already exist.

func (*StateDir) Remove

func (d *StateDir) Remove() error

Remove removes the directory if it exists and is empty.

func (*StateDir) State

func (d *StateDir) State() *State

State returns the current state of the relation.

func (*StateDir) Write

func (d *StateDir) Write(hi hook.Info) (err error)

Write atomically writes to disk the relation state change in hi. It must be called after the respective hook was executed successfully. Write doesn't validate hi but guarantees that successive writes of the same hi are idempotent.

Jump to

Keyboard shortcuts

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