overlord

package
v0.0.0-...-921daf7 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2016 License: GPL-3.0 Imports: 2 Imported by: 0

Documentation

Overview

Package overlord implements the policies for state transitions for the operation of a snappy system.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WriteState

func WriteState(s *State, w io.Writer) error

WriteState serializes the provided state into w.

Types

type AssertManager

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

AssertManager is responsible for the enforcement of assertions in system states. It manipulates observed states to ensure nothing in them violates existing assertions, or misses required ones.

func NewAssertManager

func NewAssertManager(o *Overlord) (*AssertManager, error)

NewAssertManager returns a new assertion manager.

func (*AssertManager) Apply

func (m *AssertManager) Apply(s *State) error

Apply implements StateManager.Apply.

func (*AssertManager) Delta

func (m *AssertManager) Delta(a, b *State) (Delta, error)

Delta implements StateManager.Delta.

func (*AssertManager) Learn

func (m *AssertManager) Learn(s *State) error

Learn implements StateManager.Learn.

func (*AssertManager) Sanitize

func (m *AssertManager) Sanitize(s *State) error

Sanitize implements StateManager.Sanitize.

type Delta

type Delta []DeltaItem

Delta represents a list of state changes.

func (Delta) MarshalText

func (d Delta) MarshalText() ([]byte, error)

MarshalText returns a human-oriented textual representation of the delta.

This function turns Delta into an encoding.TextMarshaler.

type DeltaItem

type DeltaItem struct {
	Header  string // Header for grouping
	Summary string // Summary with textual description
	Reason  string // Optional reason for the change, available with sanitization
}

DeltaItem represent a single state change, possibly with a reason for it.

type Overlord

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

Overlord is the central manager of a snappy system, keeping track of all available state managers and related helpers.

func New

func New() (*Overlord, error)

New creates a new Overlord with all its state managers.

func (*Overlord) AssertManager

func (o *Overlord) AssertManager() *AssertManager

AssertManager returns the assertion manager enforcing assertions under the overlord.

func (*Overlord) SkillManager

func (o *Overlord) SkillManager() *SkillManager

SkillManager returns the skill manager mantaining skill assignments under the overlord.

func (*Overlord) SnapManager

func (o *Overlord) SnapManager() *SnapManager

SnapManager returns the snap manager responsible for snaps under the overlord.

func (*Overlord) StateJournal

func (o *Overlord) StateJournal() *StateJournal

StateJournal returns the StateJournal used by the overlord.

type SkillManager

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

SkillManager is responsible for the maintenance of skills in system states. It maintains skills assignments, and also observes installed snaps to track the current set of available skills and skill slots.

func NewSkillManager

func NewSkillManager(o *Overlord) (*SkillManager, error)

NewSkillManager returns a new SkillManager.

func (*SkillManager) Apply

func (m *SkillManager) Apply(s *State) error

Apply implements StateManager.Apply.

func (*SkillManager) Delta

func (m *SkillManager) Delta(a, b *State) (Delta, error)

Delta implements StateManager.Delta.

func (*SkillManager) Grant

func (m *SkillManager) Grant(s *State, skillSnap, skillName, slotSnap, slotName string) error

Grant records the intent of granting the skill in state s.

func (*SkillManager) Learn

func (m *SkillManager) Learn(s *State) error

Learn implements StateManager.Learn.

func (*SkillManager) Revoke

func (m *SkillManager) Revoke(s *State, skillSnap, skillName, slotSnap, slotName string) error

Revoke records the intent of revoking the skill in state s.

func (*SkillManager) Sanitize

func (m *SkillManager) Sanitize(s *State) error

Sanitize implements StateManager.Sanitize.

type SnapManager

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

SnapManager is responsible for the installation and removal of snaps.

func NewSnapManager

func NewSnapManager(o *Overlord) (*SnapManager, error)

NewSnapManager returns a new snap manager.

func (*SnapManager) Apply

func (m *SnapManager) Apply(s *State) error

Apply implements StateManager.Apply.

func (*SnapManager) Delta

func (m *SnapManager) Delta(a, b *State) (Delta, error)

Delta implements StateManager.Delta.

func (*SnapManager) Install

func (m *SnapManager) Install(s *State, snap string) error

Install records the intent of installing snap in state s.

func (*SnapManager) Learn

func (m *SnapManager) Learn(s *State) error

Learn implements StateManager.Learn.

func (*SnapManager) Remove

func (m *SnapManager) Remove(s *State, snap string) error

Remove records the intent of removing snap in state s.

func (*SnapManager) Sanitize

func (m *SnapManager) Sanitize(s *State) error

Sanitize implements StateManager.Sanitize.

type State

type State struct{}

State represents a snapshot of the system state.

func ReadState

func ReadState(r io.Reader) (*State, error)

ReadState returns the state deserialized from r.

func (*State) Copy

func (s *State) Copy() *State

Copy returns an indepent copy of the state.

func (*State) Get

func (s *State) Get(key string, value interface{})

Get unmarshals the stored value associated with the provided key into the value parameter.

func (*State) Set

func (s *State) Set(key string, value interface{})

Set associates value with key for future consulting by managers. The provided value must properly marshal and unmarshal with encoding/json.

type StateEngine

type StateEngine struct{}

StateEngine controls the dispatching of state changes to state managers.

The operations performed by StateEngine resemble in some ways a transaction system, but it needs to deal with the fact that many of the system changes involved in a snappy system are not atomic, and may actually become invalid without notice (e.g. USB device physically removed).

func NewStateEngine

func NewStateEngine() *StateEngine

NewStateEngine returns a new state engine.

func (*StateEngine) AddManager

func (se *StateEngine) AddManager(m StateManager)

AddManager adds the provided manager to take part in state operations.

func (*StateEngine) Apply

func (se *StateEngine) Apply(s *State) error

Apply attempts to perform the necessary changes in the system to make s the current state.

func (*StateEngine) Delta

func (se *StateEngine) Delta(a, b *State) (Delta, error)

Delta returns the differences between state a and b, or nil if there are no relevant differences.

func (*StateEngine) Learn

func (se *StateEngine) Learn(s *State) error

Learn records the current state into s.

func (*StateEngine) Sanitize

func (se *StateEngine) Sanitize(s *State) (Delta, error)

Sanitize attempts to make the necessary changes in the provided state to make it ready for applying. It returns a Delta with the changes performed and the reasoning for them.

func (*StateEngine) Validate

func (se *StateEngine) Validate(s *State) error

Validate checks whether the s state might be applied as-is if desired. It's implemented in terms of Sanitize and Delta.

type StateJournal

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

StateJournal is responsible for keeping track of multiple states persistently and recording intended state changes so that the system may be properly recovered from an interruption by moving into the intended state completely, or retroceding to a prior good state.

func NewStateJournal

func NewStateJournal(engine *StateEngine, dir string) (*StateJournal, error)

NewStateJournal returns a new state journal using dir as its configuration directory.

func (*StateJournal) Commit

func (j *StateJournal) Commit(s *State) error

Commit attempts to apply the s state, recording it in the journal first to ensure the operation may be continued later if necessary.

func (*StateJournal) Current

func (j *StateJournal) Current() (*State, error)

Current returns the current system state.

func (*StateJournal) Pending

func (j *StateJournal) Pending() (*State, error)

Pending returns the last attempted but unfinished commit, if any. It returns ErrNotPending if there are no pending states.

func (*StateJournal) Recover

func (j *StateJournal) Recover() error

Recover attempts to apply the currently pending state, if any. If applying the pending state fails for any reason and there's a previous good state, applying that will be attempted instead.

func (*StateJournal) Revert

func (j *StateJournal) Revert() error

Revert attempts to revert the system to the previous known good state, whether the current state is valid or not. This is unlike Recover in that it ignores whether a pending state exists.

type StateManager

type StateManager interface {
	Apply(s *State) error
	Learn(s *State) error
	Sanitize(s *State) error
	Delta(a, b *State) (Delta, error)
}

StateManager is implemented by types responsible for observing the system state and directly manipulating it.

See the interface of StateEngine for details on those methods.

Jump to

Keyboard shortcuts

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