relation

package
v0.0.0-...-732aecd Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2014 License: AGPL-3.0 Imports: 14 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 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 AliveHookQueue

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

AliveHookQueue aggregates values obtained from a relation units watcher and sends out details about hooks that must be executed in the unit.

func NewAliveHookQueue

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

NewAliveHookQueue returns a new AliveHookQueue that aggregates the values obtained from the w watcher and sends into out the details about 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 AliveHookQueue's behaviour is undefined.

func (*AliveHookQueue) Stop

func (q *AliveHookQueue) Stop() error

Stop stops the AliveHookQueue and returns any errors encountered during operation or while shutting down.

type DyingHookQueue

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

DyingHookQueue is a hook queue that deals with a relation that is being shut down. It honours the obligations of an AliveHookQueue with respect to relation hook execution order; as soon as those obligations are fulfilled, it sends a "relation-departed" hook for every relation member, and finally a "relation-broken" hook for the relation itself.

func NewDyingHookQueue

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

NewDyingHookQueue returns a new DyingHookQueue that shuts down the state in initial.

func (*DyingHookQueue) Stop

func (q *DyingHookQueue) Stop() error

Stop stops the DyingHookQueue and returns any errors encountered during operation or while shutting down.

type HookQueue

type HookQueue interface {
	Stop() error
	// contains filtered or unexported methods
}

HookQueue is the minimal interface implemented by both AliveHookQueue and DyingHookQueue.

type RelationUnitsWatcher

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

RelationUnitsWatcher is used to enable deterministic testing of AliveHookQueue, by supplying a reliable stream of RelationUnitsChange events; usually, it will be a *state.RelationUnitsWatcher.

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