overlord

package
v0.0.0-...-55a61f8 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2021 License: GPL-3.0 Imports: 30 Imported by: 0

Documentation

Overview

Package overlord implements the overall control of a snappy system.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

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 Mock

func Mock() *Overlord

Mock creates an Overlord without any managers and with a backend not using disk. Managers can be added with AddManager. For testing.

func MockWithStateAndRestartHandler

func MockWithStateAndRestartHandler(s *state.State, handleRestart func(state.RestartType)) *Overlord

MockWithStateAndRestartHandler creates an Overlord with the given state unless it is nil in which case it uses a state backend not using disk. It will use the given handler on restart requests. Managers can be added with AddManager. For testing.

func New

func New(restartBehavior RestartBehavior) (*Overlord, error)

New creates a new Overlord with all its state managers. It can be provided with an optional RestartBehavior.

func (*Overlord) AddManager

func (o *Overlord) AddManager(mgr StateManager)

AddManager adds a manager to the overlord created with Mock. For testing.

func (*Overlord) AssertManager

func (o *Overlord) AssertManager() *assertstate.AssertManager

AssertManager returns the assertion manager enforcing assertions under the overlord.

func (*Overlord) CanStandby

func (o *Overlord) CanStandby() bool

func (*Overlord) CommandManager

func (o *Overlord) CommandManager() *cmdstate.CommandManager

CommandManager returns the manager responsible for running odd jobs.

func (*Overlord) DeviceManager

func (o *Overlord) DeviceManager() *devicestate.DeviceManager

DeviceManager returns the device manager responsible for the device identity and policies.

func (*Overlord) HookManager

func (o *Overlord) HookManager() *hookstate.HookManager

HookManager returns the hook manager responsible for running hooks under the overlord.

func (*Overlord) InterfaceManager

func (o *Overlord) InterfaceManager() *ifacestate.InterfaceManager

InterfaceManager returns the interface manager maintaining interface connections under the overlord.

func (*Overlord) Loop

func (o *Overlord) Loop()

Loop runs a loop in a goroutine to ensure the current state regularly through StateEngine Ensure.

func (*Overlord) ServiceManager

func (o *Overlord) ServiceManager() *servicestate.ServiceManager

ServiceManager returns the manager responsible for services under the overlord.

func (*Overlord) Settle

func (o *Overlord) Settle(timeout time.Duration) error

Settle runs first a state engine Ensure and then wait for activities to settle. That's done by waiting for all managers' activities to settle while making sure no immediate further Ensure is scheduled. It then waits similarly for all ready changes to reach the clean state. Chiefly for tests. Cannot be used in conjunction with Loop. If timeout is non-zero and settling takes longer than timeout, returns an error. Calls StartUp as well.

func (*Overlord) SettleObserveBeforeCleanups

func (o *Overlord) SettleObserveBeforeCleanups(timeout time.Duration, beforeCleanups func()) error

SettleObserveBeforeCleanups runs first a state engine Ensure and then wait for activities to settle. That's done by waiting for all managers' activities to settle while making sure no immediate further Ensure is scheduled. It then waits similarly for all ready changes to reach the clean state, but calls once the provided callback before doing that. Chiefly for tests. Cannot be used in conjunction with Loop. If timeout is non-zero and settling takes longer than timeout, returns an error. Calls StartUp as well.

func (*Overlord) SnapManager

func (o *Overlord) SnapManager() *snapstate.SnapManager

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

func (*Overlord) SnapshotManager

func (o *Overlord) SnapshotManager() *snapshotstate.SnapshotManager

SnapshotManager returns the manager responsible for snapshots.

func (*Overlord) StartUp

func (o *Overlord) StartUp() error

StartUp proceeds to run any expensive Overlord or managers initialization. After this is done once it is a noop.

func (*Overlord) StartupTimeout

func (o *Overlord) StartupTimeout() (timeout time.Duration, reasoning string, err error)

StartupTimeout computes a usable timeout for the startup initializations by using a pessimistic estimate.

func (*Overlord) State

func (o *Overlord) State() *state.State

State returns the system state managed by the overlord.

func (*Overlord) StateEngine

func (o *Overlord) StateEngine() *StateEngine

StateEngine returns the stage engine used by overlord.

func (*Overlord) Stop

func (o *Overlord) Stop() error

Stop stops the ensure loop and the managers under the StateEngine.

func (*Overlord) TaskRunner

func (o *Overlord) TaskRunner() *state.TaskRunner

TaskRunner returns the shared task runner responsible for running tasks for all managers under the overlord.

type RestartBehavior

type RestartBehavior interface {
	HandleRestart(t state.RestartType)
	// RebootAsExpected is called early when either a reboot was
	// requested by snapd and happened or no reboot was expected at all.
	RebootAsExpected(st *state.State) error
	// RebootDidNotHappen is called early instead when a reboot was
	// requested by snad but did not happen.
	RebootDidNotHappen(st *state.State) error
}

RestartBehavior controls how to hanndle and carry forward restart requests via the state.

type StateEngine

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

StateEngine controls the dispatching of state changes to state managers.

Most of the actual work performed by the state engine is in fact done by the individual managers registered. These managers must be able to cope with Ensure calls in any order, coordinating among themselves solely via the state.

func NewStateEngine

func NewStateEngine(s *state.State) *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) Ensure

func (se *StateEngine) Ensure() error

Ensure asks every manager to ensure that they are doing the necessary work to put the current desired system state in place by calling their respective Ensure methods.

Managers must evaluate the desired state completely when they receive that request, and report whether they found any critical issues. They must not perform long running activities during that operation, though. These should be performed in properly tracked changes and tasks.

func (*StateEngine) StartUp

func (se *StateEngine) StartUp() error

StartUp asks all managers to perform any expensive initialization. It is a noop after the first invocation.

func (*StateEngine) State

func (se *StateEngine) State() *state.State

State returns the current system state.

func (*StateEngine) Stop

func (se *StateEngine) Stop()

Stop asks all managers to terminate activities running concurrently.

func (*StateEngine) Wait

func (se *StateEngine) Wait()

Wait waits for all managers current activities.

type StateManager

type StateManager interface {
	// Ensure forces a complete evaluation of the current state.
	// See StateEngine.Ensure for more details.
	Ensure() error
}

StateManager is implemented by types responsible for observing the system and manipulating it to reflect the desired state.

type StateStarterUp

type StateStarterUp interface {
	// StartUp asks manager to perform any expensive initialization.
	StartUp() error
}

StateStarterUp is optionally implemented by StateManager that have expensive initialization to perform before the main Overlord loop.

type StateStopper

type StateStopper interface {
	// Stop asks the manager to terminate all activities running
	// concurrently.  It must not return before these activities
	// are finished.
	Stop()
}

StateStopper is optionally implemented by StateManagers that have running activities that can be terminated.

type StateWaiter

type StateWaiter interface {
	// Wait asks manager to wait for all running activities to
	// finish.
	Wait()
}

StateWaiter is optionally implemented by StateManagers that have running activities that can be waited.

Directories

Path Synopsis
Package assertstate implements the manager and state aspects responsible for the enforcement of assertions in the system and manages the system-wide assertion database.
Package assertstate implements the manager and state aspects responsible for the enforcement of assertions in the system and manages the system-wide assertion database.
Package cmdstate implements a overlord.StateManager that excutes arbitrary commands as tasks.
Package cmdstate implements a overlord.StateManager that excutes arbitrary commands as tasks.
Package configstate implements the manager and state aspects responsible for the configuration of snaps.
Package configstate implements the manager and state aspects responsible for the configuration of snaps.
Package devicestate implements the manager and state aspects responsible for the device identity and policies.
Package devicestate implements the manager and state aspects responsible for the device identity and policies.
internal
Package internal (of devicestate) provides functions to access and set the device state for use only by devicestate, for convenience they are also exposed via devicestatetest for use in tests.
Package internal (of devicestate) provides functions to access and set the device state for use only by devicestate, for convenience they are also exposed via devicestatetest for use in tests.
Package hookstate implements the manager and state aspects responsible for the running of hooks.
Package hookstate implements the manager and state aspects responsible for the running of hooks.
ctlcmd
Package ctlcmd contains the various snapctl subcommands.
Package ctlcmd contains the various snapctl subcommands.
Package ifacestate implements the manager and state aspects responsible for the maintenance of interfaces the system.
Package ifacestate implements the manager and state aspects responsible for the maintenance of interfaces the system.
Package snapstate implements the manager and state aspects responsible for the installation and removal of snaps.
Package snapstate implements the manager and state aspects responsible for the installation and removal of snaps.
backend
Package backend implements the low-level primitives to manage the snaps and their installation on disk.
Package backend implements the low-level primitives to manage the snaps and their installation on disk.
policy
Package policy implements fine grained decision-making for snapstate
Package policy implements fine grained decision-making for snapstate
Package state implements the representation of system state.
Package state implements the representation of system state.
Package storecontext supplies a pluggable implementation of store.DeviceAndAuthContext.
Package storecontext supplies a pluggable implementation of store.DeviceAndAuthContext.

Jump to

Keyboard shortcuts

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