context

package
v0.0.0-...-a002913 Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2015 License: AGPL-3.0 Imports: 21 Imported by: 0

Documentation

Overview

Package context contains the ContextFactory and Context definitions. Context implements jujuc.Context and is used together with uniter.Runner to run hooks, commands and actions.

Index

Constants

This section is empty.

Variables

View Source
var ErrIsNotLeader = errors.Errorf("this unit is not the leader")
View Source
var ErrNoProcess = errors.New("no process to kill")
View Source
var ErrReboot = errors.New("reboot after hook")
View Source
var ErrRequeueAndReboot = errors.New("reboot now")

Functions

func IsMissingHookError

func IsMissingHookError(err error) bool

func NewMissingHookError

func NewMissingHookError(hookName string) error

func OSDependentEnvVars

func OSDependentEnvVars(paths Paths) []string

OSDependentEnvVars returns the OS-dependent environment variables that should be set for a hook context.

Types

type ActionData

type ActionData struct {
	Name           string
	Tag            names.ActionTag
	Params         map[string]interface{}
	Failed         bool
	ResultsMessage string
	ResultsMap     map[string]interface{}
}

ActionData contains the tag, parameters, and results of an Action.

func NewActionData

func NewActionData(name string, tag *names.ActionTag, params map[string]interface{}) *ActionData

NewActionData builds a suitable ActionData struct with no nil members. this should only be called in the event that an Action hook is being requested.

type CommandInfo

type CommandInfo struct {
	// RelationId is the relation context to execute the commands in.
	RelationId int
	// RemoteUnitName is the remote unit for the relation context.
	RemoteUnitName string
	// ForceRemoteUnit skips unit inference and existence validation.
	ForceRemoteUnit bool
}

CommandInfo specifies the information necessary to run a command.

type ContextFactory

type ContextFactory interface {
	// CommandContext creates a new context for running a juju command.
	CommandContext(commandInfo CommandInfo) (*HookContext, error)

	// HookContext creates a new context for running a juju hook.
	HookContext(hookInfo hook.Info) (*HookContext, error)

	// ActionContext creates a new context for running a juju action.
	ActionContext(actionData *ActionData) (*HookContext, error)
}

ContextFactory represents a long-lived object that can create execution contexts relevant to a specific unit.

func NewContextFactory

func NewContextFactory(
	state *uniter.State,
	unitTag names.UnitTag,
	tracker leadership.Tracker,
	getRelationInfos RelationsFunc,
	storage StorageContextAccessor,
	paths Paths,
) (
	ContextFactory, error,
)

NewContextFactory returns a ContextFactory capable of creating execution contexts backed by the supplied unit's supplied API connection.

type ContextRelation

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

ContextRelation is the implementation of jujuc.ContextRelation.

func NewContextRelation

func NewContextRelation(ru *uniter.RelationUnit, cache *RelationCache) *ContextRelation

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

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.Settings, err error)

func (*ContextRelation) Settings

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

func (*ContextRelation) UnitNames

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

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 {

	// LeadershipContext supplies several jujuc.Context methods.
	LeadershipContext
	// contains filtered or unexported fields
}

HookContext is the implementation of jujuc.Context.

func (*HookContext) ActionData

func (c *HookContext) ActionData() (*ActionData, error)

ActionData returns the context's internal action data. It's meant to be transitory; it exists to allow uniter and runner code to keep working as it did; it should be considered deprecated, and not used by new clients.

func (*HookContext) ActionName

func (ctx *HookContext) ActionName() (string, error)

ActionName returns the name of the action.

func (*HookContext) ActionParams

func (ctx *HookContext) ActionParams() (map[string]interface{}, error)

ActionParams simply returns the arguments to the Action.

func (*HookContext) AddMetric

func (ctx *HookContext) AddMetric(key, value string, created time.Time) error

AddMetric adds metrics to the hook context.

func (*HookContext) AddUnitStorage

func (ctx *HookContext) AddUnitStorage(cons map[string]params.StorageConstraints) error

func (*HookContext) AvailabilityZone

func (ctx *HookContext) AvailabilityZone() (string, error)

func (*HookContext) ClosePorts

func (ctx *HookContext) ClosePorts(protocol string, fromPort, toPort int) error

func (*HookContext) ConfigSettings

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

func (*HookContext) Flush

func (ctx *HookContext) Flush(process string, ctxErr error) (err error)

Flush implements the Context interface.

func (*HookContext) GetProcess

func (ctx *HookContext) GetProcess() *os.Process

func (*HookContext) GetRebootPriority

func (ctx *HookContext) GetRebootPriority() jujuc.RebootPriority

func (*HookContext) HasExecutionSetUnitStatus

func (ctx *HookContext) HasExecutionSetUnitStatus() bool

func (*HookContext) HookRelation

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

func (*HookContext) HookStorage

func (ctx *HookContext) HookStorage() (jujuc.ContextStorageAttachment, error)

func (*HookContext) HookVars

func (context *HookContext) HookVars(paths Paths) ([]string, error)

HookVars returns an os.Environ-style list of strings necessary to run a hook such that it can know what environment it's operating in, and can call back into context.

func (*HookContext) Id

func (ctx *HookContext) Id() string

func (*HookContext) OpenPorts

func (ctx *HookContext) OpenPorts(protocol string, fromPort, toPort int) error

func (*HookContext) OpenedPorts

func (ctx *HookContext) OpenedPorts() []network.PortRange

func (*HookContext) Prepare

func (ctx *HookContext) Prepare() error

Prepare implements the Context interface.

func (*HookContext) PrivateAddress

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

func (*HookContext) PublicAddress

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

func (*HookContext) Relation

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

func (*HookContext) RelationIds

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

func (*HookContext) RemoteUnitName

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

func (*HookContext) RequestReboot

func (ctx *HookContext) RequestReboot(priority jujuc.RebootPriority) error

func (*HookContext) ResetExecutionSetUnitStatus

func (ctx *HookContext) ResetExecutionSetUnitStatus()

func (*HookContext) ServiceStatus

func (ctx *HookContext) ServiceStatus() (jujuc.ServiceStatusInfo, error)

ServiceStatus returns the status for the service and all the units on the service to which this context unit belongs, only if this unit is the leader.

func (*HookContext) SetActionFailed

func (ctx *HookContext) SetActionFailed() error

SetActionFailed sets the fail state of the action.

func (*HookContext) SetActionMessage

func (ctx *HookContext) SetActionMessage(message string) error

SetActionMessage sets a message for the Action, usually an error message.

func (*HookContext) SetProcess

func (ctx *HookContext) SetProcess(process *os.Process)

func (*HookContext) SetRebootPriority

func (ctx *HookContext) SetRebootPriority(priority jujuc.RebootPriority)

func (*HookContext) SetServiceStatus

func (ctx *HookContext) SetServiceStatus(status jujuc.StatusInfo) error

SetServiceStatus will set the given status to the service to which this unit's belong, only if this unit is the leader.

func (*HookContext) SetUnitStatus

func (ctx *HookContext) SetUnitStatus(status jujuc.StatusInfo) error

SetUnitStatus will set the given status for this unit.

func (*HookContext) Storage

func (*HookContext) StorageTags

func (ctx *HookContext) StorageTags() ([]names.StorageTag, error)

func (*HookContext) UnitName

func (ctx *HookContext) UnitName() string

func (*HookContext) UnitStatus

func (ctx *HookContext) UnitStatus() (*jujuc.StatusInfo, error)

UnitStatus will return the status for the current Unit.

func (*HookContext) UpdateActionResults

func (ctx *HookContext) UpdateActionResults(keys []string, value string) error

UpdateActionResults inserts new values for use with action-set and action-fail. The results struct will be delivered to the state server upon completion of the Action. It returns an error if not called on an Action-containing HookContext.

type LeadershipContext

type LeadershipContext interface {
	IsLeader() (bool, error)
	LeaderSettings() (map[string]string, error)
	WriteLeaderSettings(map[string]string) error
}

LeadershipContext provides several jujuc.Context methods. It exists separately of HookContext for clarity, and ease of testing.

func NewLeadershipContext

func NewLeadershipContext(accessor LeadershipSettingsAccessor, tracker leadership.Tracker) LeadershipContext

type LeadershipSettingsAccessor

type LeadershipSettingsAccessor interface {
	Read(serviceName string) (map[string]string, error)
	Merge(serviceName string, settings map[string]string) error
}

LeadershipSettingsAccessor is an interface that allows us not to have to use the concrete `api/uniter/LeadershipSettingsAccessor` type, thus simplifying testing.

type Paths

type Paths interface {

	// GetToolsDir returns the filesystem path to the dirctory containing
	// the hook tool symlinks.
	GetToolsDir() string

	// GetCharmDir returns the filesystem path to the directory in which
	// the charm is installed.
	GetCharmDir() string

	// GetJujucSocket returns the path to the socket used by the hook tools
	// to communicate back to the executing uniter process. It might be a
	// filesystem path, or it might be abstract.
	GetJujucSocket() string

	// GetMetricsSpoolDir returns the path to a metrics spool dir, used
	// to store metrics recorded during a single hook run.
	GetMetricsSpoolDir() string
}

Paths exposes the paths needed by Context.

type PortRange

type PortRange struct {
	Ports      network.PortRange
	RelationId int
}

PortRange contains a port range and a relation id. Used as key to pendingRelations and is only exported for testing.

type PortRangeInfo

type PortRangeInfo struct {
	ShouldOpen  bool
	RelationTag names.RelationTag
}

PortRangeInfo contains information about a pending open- or close-port operation for a port range. This is only exported for testing.

type RelationCache

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

RelationCache stores a relation's remote unit membership and settings. Member settings are stored until invalidated or removed by name; settings of non-member units are stored only until the cache is pruned.

func NewRelationCache

func NewRelationCache(readSettings SettingsFunc, memberNames []string) *RelationCache

NewRelationCache creates a new RelationCache that will use the supplied SettingsFunc to populate itself on demand. Initial membership is determined by memberNames.

func (*RelationCache) InvalidateMember

func (cache *RelationCache) InvalidateMember(memberName string)

InvalidateMember ensures that the named remote unit will be considered a member of the relation, and that the next attempt to read its settings will use fresh data.

func (*RelationCache) MemberNames

func (cache *RelationCache) MemberNames() (memberNames []string)

MemberNames returns the names of the remote units present in the relation.

func (*RelationCache) Prune

func (cache *RelationCache) Prune(memberNames []string)

Prune resets the membership to the supplied list, and discards the settings of all non-member units.

func (*RelationCache) RemoveMember

func (cache *RelationCache) RemoveMember(memberName string)

RemoveMember ensures that the named remote unit will not be considered a member of the relation,

func (*RelationCache) Settings

func (cache *RelationCache) Settings(unitName string) (params.Settings, error)

Settings returns the settings of the named remote unit. It's valid to get the settings of any unit that has ever been in the relation.

type RelationInfo

type RelationInfo struct {
	RelationUnit *uniter.RelationUnit
	MemberNames  []string
}

type RelationsFunc

type RelationsFunc func() map[int]*RelationInfo

RelationsFunc is used to get snapshots of relation membership at context creation time.

type SettingsFunc

type SettingsFunc func(unitName string) (params.Settings, error)

SettingsFunc returns the relation settings for a unit.

type SettingsMap

type SettingsMap map[string]params.Settings

SettingsMap is a map from unit name to relation settings.

type StorageContextAccessor

type StorageContextAccessor interface {

	// StorageTags returns the tags of storage instances attached to
	// the unit.
	StorageTags() ([]names.StorageTag, error)

	// Storage returns the jujuc.ContextStorageAttachment with the
	// supplied tag if it was found, and whether it was found.
	Storage(names.StorageTag) (jujuc.ContextStorageAttachment, error)
}

StorageContextAccessor is an interface providing access to StorageContexts for a jujuc.Context.

Jump to

Keyboard shortcuts

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