uniter

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: 37 Imported by: 0

Documentation

Index

Constants

View Source
const JujuRunEndpoint = "JujuRunServer.RunCommands"
View Source
const (
	// These work fine for linux, but should we need to work with windows
	// workloads in the future, we'll need to move these into a file that is
	// compiled conditionally for different targets and use tcp (most likely).
	RunListenerFile = "run.socket"
)

Variables

View Source
var ErrNoStateFile = errors.New("uniter state file does not exist")

Functions

func EnsureJujucSymlinks(dir string) (err error)

EnsureJujucSymlinks creates a symbolic link to jujuc within dir for each hook command. If the commands already exist, this operation does nothing.

func IsMissingHookError

func IsMissingHookError(err error) bool

Types

type CommandRunner

type CommandRunner interface {
	RunCommands(commands string) (results *exec.ExecResponse, err error)
}

A CommandRunner is something that will actually execute the commands and return the results of that execution in the exec.ExecResponse (which contains stdout, stderr, and return code).

type ContextRelation

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

ContextRelation is the implementation of jujuc.ContextRelation.

func NewContextRelation

func NewContextRelation(ru *uniter.RelationUnit, members map[string]int64) *ContextRelation

NewContextRelation creates a new context for the given relation unit. The unit-name keys of members supplies the initial membership.

func (*ContextRelation) ClearCache

func (ctx *ContextRelation) ClearCache()

ClearCache discards all cached settings for units that are not members of the relation, and all unwritten changes to the unit's relation settings. including any changes to Settings that have not been written.

func (*ContextRelation) DeleteMember

func (ctx *ContextRelation) DeleteMember(unitName string)

DeleteMember drops the membership and cache of a single remote unit, without perturbing settings for the remaining members.

func (*ContextRelation) FakeId

func (ctx *ContextRelation) FakeId() string

func (*ContextRelation) Id

func (ctx *ContextRelation) Id() int

func (*ContextRelation) Name

func (ctx *ContextRelation) Name() string

func (*ContextRelation) ReadSettings

func (ctx *ContextRelation) ReadSettings(unit string) (settings params.RelationSettings, err error)

func (*ContextRelation) Settings

func (ctx *ContextRelation) Settings() (jujuc.Settings, error)

func (*ContextRelation) UnitNames

func (ctx *ContextRelation) UnitNames() (units []string)

func (*ContextRelation) UpdateMembers

func (ctx *ContextRelation) UpdateMembers(members SettingsMap)

UpdateMembers ensures that the context is aware of every supplied member unit. For each supplied member, the cached settings will be overwritten.

func (*ContextRelation) WriteSettings

func (ctx *ContextRelation) WriteSettings() (err error)

WriteSettings persists all changes made to the unit's relation settings.

type HookContext

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

HookContext is the implementation of jujuc.Context.

func NewHookContext

func NewHookContext(unit *uniter.Unit, id, uuid, envName string,
	relationId int, remoteUnitName string, relations map[int]*ContextRelation,
	apiAddrs []string, serviceOwner string, proxySettings proxy.Settings) (*HookContext, error)

func (*HookContext) ClosePort

func (ctx *HookContext) ClosePort(protocol string, port int) error

func (*HookContext) ConfigSettings

func (ctx *HookContext) ConfigSettings() (charm.Settings, error)

func (*HookContext) GetLogger

func (ctx *HookContext) GetLogger(hookName string) loggo.Logger

func (*HookContext) HookRelation

func (ctx *HookContext) HookRelation() (jujuc.ContextRelation, bool)

func (*HookContext) OpenPort

func (ctx *HookContext) OpenPort(protocol string, port int) error

func (*HookContext) OwnerTag

func (ctx *HookContext) OwnerTag() string

func (*HookContext) PrivateAddress

func (ctx *HookContext) PrivateAddress() (string, bool)

func (*HookContext) PublicAddress

func (ctx *HookContext) PublicAddress() (string, bool)

func (*HookContext) Relation

func (ctx *HookContext) Relation(id int) (jujuc.ContextRelation, bool)

func (*HookContext) RelationIds

func (ctx *HookContext) RelationIds() []int

func (*HookContext) RemoteUnitName

func (ctx *HookContext) RemoteUnitName() (string, bool)

func (*HookContext) RunCommands

func (ctx *HookContext) RunCommands(commands, charmDir, toolsDir, socketPath string) (*utilexec.ExecResponse, error)

RunCommands executes the commands in an environment which allows it to to call back into the hook context to execute jujuc tools.

func (*HookContext) RunHook

func (ctx *HookContext) RunHook(hookName, charmDir, toolsDir, socketPath string) error

RunHook executes a hook in an environment which allows it to to call back into the hook context to execute jujuc tools.

func (*HookContext) UnitName

func (ctx *HookContext) UnitName() string

type JujuRunServer

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

The JujuRunServer is the entity that has the methods that are called over the rpc connection.

func (*JujuRunServer) RunCommands

func (r *JujuRunServer) RunCommands(commands string, result *exec.ExecResponse) error

RunCommands delegates the actual running to the runner and populates the response structure.

type Mode

type Mode func(u *Uniter) (Mode, error)

Mode defines the signature of the functions that implement the possible states of a running Uniter.

func ModeAbide

func ModeAbide(u *Uniter) (next Mode, err error)

ModeAbide is the Uniter's usual steady state. It watches for and responds to: * service configuration changes * charm upgrade requests * relation changes * unit death

func ModeConfigChanged

func ModeConfigChanged(u *Uniter) (next Mode, err error)

ModeConfigChanged runs the "config-changed" hook.

func ModeConflicted

func ModeConflicted(curl *charm.URL) Mode

ModeConflicted is responsible for watching and responding to: * user resolution of charm upgrade conflicts * forced charm upgrade requests

func ModeContinue

func ModeContinue(u *Uniter) (next Mode, err error)

ModeContinue determines what action to take based on persistent uniter state.

func ModeHookError

func ModeHookError(u *Uniter) (next Mode, err error)

ModeHookError is responsible for watching and responding to: * user resolution of hook errors * forced charm upgrade requests

func ModeInstalling

func ModeInstalling(curl *charm.URL) Mode

ModeInstalling is responsible for the initial charm deployment.

func ModeStarting

func ModeStarting(u *Uniter) (next Mode, err error)

ModeStarting runs the "start" hook.

func ModeStopping

func ModeStopping(u *Uniter) (next Mode, err error)

ModeStopping runs the "stop" hook.

func ModeTerminating

func ModeTerminating(u *Uniter) (next Mode, err error)

ModeTerminating marks the unit dead and returns ErrTerminateAgent.

func ModeUpgrading

func ModeUpgrading(curl *charm.URL) Mode

ModeUpgrading is responsible for upgrading the charm.

type Op

type Op string

Op enumerates the operations the uniter can perform.

const (
	// Install indicates that the uniter is installing the charm.
	Install Op = "install"

	// RunHook indicates that the uniter is running a hook.
	RunHook Op = "run-hook"

	// Upgrade indicates that the uniter is upgrading the charm.
	Upgrade Op = "upgrade"

	// Continue indicates that the uniter should run ModeContinue
	// to determine the next operation.
	Continue Op = "continue"
)

type OpStep

type OpStep string

OpStep describes the recorded progression of an operation.

const (
	// Queued indicates that the uniter should undertake the operation
	// as soon as possible.
	Queued OpStep = "queued"

	// Pending indicates that the uniter has started, but not completed,
	// the operation.
	Pending OpStep = "pending"

	// Done indicates that the uniter has completed the operation,
	// but may not yet have synchronized all necessary secondary state.
	Done OpStep = "done"
)

type Relationer

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

Relationer manages a unit's presence in a relation.

func NewRelationer

func NewRelationer(ru *apiuniter.RelationUnit, dir *relation.StateDir, hooks chan<- hook.Info) *Relationer

NewRelationer creates a new Relationer. The unit will not join the relation until explicitly requested.

func (*Relationer) CommitHook

func (r *Relationer) CommitHook(hi hook.Info) error

CommitHook persists the fact of the supplied hook's completion.

func (*Relationer) Context

func (r *Relationer) Context() *ContextRelation

Context returns the ContextRelation associated with r.

func (*Relationer) IsImplicit

func (r *Relationer) IsImplicit() bool

IsImplicit returns whether the local relation endpoint is implicit. Implicit relations do not run hooks.

func (*Relationer) Join

func (r *Relationer) Join() error

Join initializes local state and causes the unit to enter its relation scope, allowing its counterpart units to detect its presence and settings changes. Local state directory is not created until needed.

func (*Relationer) PrepareHook

func (r *Relationer) PrepareHook(hi hook.Info) (hookName string, err error)

PrepareHook checks that the relation is in a state such that it makes sense to execute the supplied hook, and ensures that the relation context contains the latest relation state as communicated in the hook.Info. It returns the name of the hook that must be run.

func (*Relationer) SetDying

func (r *Relationer) SetDying() error

SetDying informs the relationer that the unit is departing the relation, and that the only hooks it should send henceforth are -departed hooks, until the relation is empty, followed by a -broken hook.

func (*Relationer) StartHooks

func (r *Relationer) StartHooks() error

StartHooks starts watching the relation, and sending hook.Info events on the hooks channel. It will panic if called when already responding to relation changes.

func (*Relationer) StopHooks

func (r *Relationer) StopHooks() error

StopHooks ensures that the relationer is not watching the relation, or sending hook.Info events on the hooks channel.

type RunListener

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

RunListener is responsible for listening on the network connection and seting up the rpc server on that net connection. Also starts the go routine that listens and hands off the work.

func NewRunListener

func NewRunListener(runner CommandRunner, socketPath string) (*RunListener, error)

NewRunListener returns a new RunListener that is listening on given unix socket path passed in. If a valid RunListener is returned, is has the go routine running, and should be closed by the creator when they are done with it.

func (*RunListener) Close

func (s *RunListener) Close()

Close immediately stops accepting connections, and blocks until all existing connections have been closed.

func (*RunListener) Run

func (s *RunListener) Run() (err error)

Run accepts new connections until it encounters an error, or until Close is called, and then blocks until all existing connections have been closed.

type SettingsMap

type SettingsMap map[string]params.RelationSettings

SettingsMap is a map from unit name to relation settings.

type State

type State struct {
	// Started indicates whether the start hook has run.
	Started bool

	// Op indicates the current operation.
	Op Op

	// OpStep indicates the current operation's progression.
	OpStep OpStep

	// Hook holds hook information relevant to the current operation. If Op
	// is Continue, it holds the last hook that was executed; if Op is RunHook,
	// it holds the running hook; if Op is Upgrade, a non-nil hook indicates
	// that the uniter should return to that hook's Pending state after the
	// upgrade is complete (instead of running an upgrade-charm hook).
	Hook *uhook.Info `yaml:"hook,omitempty"`

	// Charm describes the charm being deployed by an Install or Upgrade
	// operation, and is otherwise blank.
	CharmURL *charm.URL `yaml:"charm,omitempty"`
}

State defines the local persistent state of the uniter, excluding relation state.

type StateFile

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

StateFile holds the disk state for a uniter.

func NewStateFile

func NewStateFile(path string) *StateFile

NewStateFile returns a new StateFile using path.

func (*StateFile) Read

func (f *StateFile) Read() (*State, error)

Read reads a State from the file. If the file does not exist it returns ErrNoStateFile.

func (*StateFile) Write

func (f *StateFile) Write(started bool, op Op, step OpStep, hi *uhook.Info, url *charm.URL) error

Write stores the supplied state to the file.

type Uniter

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

Uniter implements the capabilities of the unit agent. It is not intended to implement the actual *behaviour* of the unit agent; that responsibility is delegated to Mode values, which are expected to react to events and direct the uniter's responses to them.

func NewUniter

func NewUniter(st *uniter.State, unitTag string, dataDir string, hookLock *fslock.Lock) *Uniter

NewUniter creates a new Uniter which will install, run, and upgrade a charm on behalf of the unit with the given unitTag, by executing hooks and operations provoked by changes in st.

func (*Uniter) Dead

func (u *Uniter) Dead() <-chan struct{}

func (*Uniter) Kill

func (u *Uniter) Kill()

func (*Uniter) RunCommands

func (u *Uniter) RunCommands(commands string) (results *exec.ExecResponse, err error)

RunCommands executes the supplied commands in a hook context.

func (*Uniter) Stop

func (u *Uniter) Stop() error

func (*Uniter) Wait

func (u *Uniter) Wait() error

type UniterExecutionObserver

type UniterExecutionObserver interface {
	HookCompleted(hookName string)
	HookFailed(hookName string)
}

A UniterExecutionObserver gets the appropriate methods called when a hook is executed and either succeeds or fails. Missing hooks don't get reported in this way.

Directories

Path Synopsis
hook provides types that define the hooks known to the Uniter
hook provides types that define the hooks known to the Uniter
The worker/uniter/jujuc package implements the server side of the jujuc proxy tool, which forwards command invocations to the unit agent process so that they can be executed against specific state.
The worker/uniter/jujuc package implements the server side of the jujuc proxy tool, which forwards command invocations to the unit agent process so that they can be executed against specific state.
relation implements persistent local storage of a unit's relation state, and translation of relation changes into hooks that need to be run.
relation implements persistent local storage of a unit's relation state, and translation of relation changes into hooks that need to be run.

Jump to

Keyboard shortcuts

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