juju: github.com/juju/juju/worker/uniter/runner/context Index | Files | Directories

package context

import "github.com/juju/juju/worker/uniter/runner/context"

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

Index

Package Files

action.go cache.go context.go contextfactory.go env.go errors.go leader.go ports.go relation.go

Variables

var ErrIsNotLeader = errors.Errorf("this unit is not the leader")
var ErrReboot = errors.New("reboot after hook")
var ErrRequeueAndReboot = errors.New("reboot now")

func OSDependentEnvVars Uses

func OSDependentEnvVars(paths Paths) []string

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

func RegisterComponentFunc Uses

func RegisterComponentFunc(name string, f ComponentFunc) error

Add the named component factory func to the registry.

type ActionData Uses

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 Uses

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 Clock Uses

type Clock interface {
    // After waits for the duration to elapse and then sends the
    // current time on the returned channel.
    After(time.Duration) <-chan time.Time
}

Clock defines the methods of the full clock.Clock that are needed here.

type CommandInfo Uses

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
    // TODO(jam): 2019-10-23 Add RemoteApplicationName
    // ForceRemoteUnit skips unit inference and existence validation.
    ForceRemoteUnit bool
}

CommandInfo specifies the information necessary to run a command.

type ComponentConfig Uses

type ComponentConfig struct {
    // UnitName is the name of the unit.
    UnitName string
    // DataDir is the component's data directory.
    DataDir string
    // APICaller is the API caller the component may use.
    APICaller base.APICaller
}

ComponentConfig holds all the information related to a hook context needed by components.

type ComponentFunc Uses

type ComponentFunc func(ComponentConfig) (jujuc.ContextComponent, error)

ComponentFunc is a factory function for Context components.

type ContextFactory Uses

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 Uses

func NewContextFactory(config FactoryConfig) (ContextFactory, error)

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

type ContextRelation Uses

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

ContextRelation is the implementation of hooks.ContextRelation.

func NewContextRelation Uses

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) ApplicationSettings Uses

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

func (*ContextRelation) FakeId Uses

func (ctx *ContextRelation) FakeId() string

func (*ContextRelation) Id Uses

func (ctx *ContextRelation) Id() int

func (*ContextRelation) Name Uses

func (ctx *ContextRelation) Name() string

func (*ContextRelation) ReadApplicationSettings Uses

func (ctx *ContextRelation) ReadApplicationSettings(app string) (settings params.Settings, err error)

func (*ContextRelation) ReadSettings Uses

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

func (*ContextRelation) SetStatus Uses

func (ctx *ContextRelation) SetStatus(status relation.Status) error

SetStatus sets the relation's status.

func (*ContextRelation) Settings Uses

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

func (*ContextRelation) Suspended Uses

func (ctx *ContextRelation) Suspended() bool

Suspended returns true if the relation is suspended.

func (*ContextRelation) UnitNames Uses

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

func (*ContextRelation) WriteSettings Uses

func (ctx *ContextRelation) WriteSettings() error

WriteSettings persists all changes made to the relation settings (unit and application)

type FactoryConfig Uses

type FactoryConfig struct {
    State            *uniter.State
    UnitTag          names.UnitTag
    Tracker          leadership.Tracker
    GetRelationInfos RelationsFunc
    Storage          StorageContextAccessor
    Paths            Paths
    Clock            Clock
}

FactoryConfig contains configuration values for the context factory.

type HookContext Uses

type HookContext struct {

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

HookContext is the implementation of runner.Context.

func (*HookContext) ActionData Uses

func (ctx *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. Implements runner.Context.

func (*HookContext) ActionParams Uses

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

ActionParams simply returns the arguments to the Action. Implements jujuc.ActionHookContext.actionHookContext, part of runner.Context.

func (*HookContext) AddMetric Uses

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

AddMetric adds metrics to the hook context. Implements jujuc.HookContext.ContextMetrics, part of runner.Context.

func (*HookContext) AddMetricLabels Uses

func (ctx *HookContext) AddMetricLabels(key, value string, created time.Time, labels map[string]string) error

AddMetricLabels adds metrics with labels to the hook context. Implements jujuc.HookContext.ContextMetrics, part of runner.Context.

func (*HookContext) AddUnitStorage Uses

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

AddUnitStorage saves storage constraints in the context. Implements jujuc.HookContext.ContextStorage, part of runner.Context.

func (*HookContext) ApplicationStatus Uses

func (ctx *HookContext) ApplicationStatus() (jujuc.ApplicationStatusInfo, error)

ApplicationStatus returns the status for the application and all the units on the application to which this context unit belongs, only if this unit is the leader. Implements jujuc.HookContext.ContextStatus, part of runner.Context.

func (*HookContext) AvailabilityZone Uses

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

AvailabilityZone returns the executing unit's availability zone or an error if it was not found (or is not available). Implements jujuc.HookContext.ContextInstance, part of runner.Context.

func (*HookContext) ClosePorts Uses

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

ClosePorts ensures the supplied port range is closed even when the executing unit's application is exposed (unless it is opened separately by a co- located unit). Implements jujuc.HookContext.ContextNetworking, part of runner.Context.

func (*HookContext) CloudSpec Uses

func (ctx *HookContext) CloudSpec() (*params.CloudSpec, error)

CloudSpec return the cloud specification for the running unit's model. Implements jujuc.HookContext.ContextUnit, part of runner.Context.

func (*HookContext) Component Uses

func (ctx *HookContext) Component(name string) (jujuc.ContextComponent, error)

Component returns the ContextComponent with the supplied name if it was found. Implements jujuc.HookContext.ContextComponents, part of runner.Context.

func (*HookContext) ConfigSettings Uses

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

Config returns the current application configuration of the executing unit. Implements jujuc.HookContext.ContextUnit, part of runner.Context.

func (*HookContext) DeleteCacheValue Uses

func (ctx *HookContext) DeleteCacheValue(key string) error

DeleteCacheValue deletes the key/value pair for the given key from the cache. Implements jujuc.HookContext.unitCacheContext, part of runner.Context.

func (*HookContext) Flush Uses

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

Flush implements the runner.Context interface.

func (*HookContext) GetCache Uses

func (ctx *HookContext) GetCache() (map[string]string, error)

GetCache returns a copy of the cache. Implements jujuc.HookContext.unitCacheContext, part of runner.Context.

func (*HookContext) GetPodSpec Uses

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

GetPodSpec returns the podspec for the unit's application. Implements jujuc.HookContext.ContextUnit, part of runner.Context.

func (*HookContext) GetProcess Uses

func (ctx *HookContext) GetProcess() HookProcess

func (*HookContext) GetRebootPriority Uses

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

func (*HookContext) GetSingleCacheValue Uses

func (ctx *HookContext) GetSingleCacheValue(key string) (string, error)

GetSingleCacheValue returns the value of the given key. Implements jujuc.HookContext.unitCacheContext, part of runner.Context.

func (*HookContext) GoalState Uses

func (ctx *HookContext) GoalState() (*application.GoalState, error)

GoalState returns the goal state for the current unit. Implements jujuc.HookContext.ContextUnit, part of runner.Context.

func (*HookContext) HasExecutionSetUnitStatus Uses

func (ctx *HookContext) HasExecutionSetUnitStatus() bool

Implements runner.Context.

func (*HookContext) HookRelation Uses

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

HookRelation returns the ContextRelation associated with the executing hook if it was found, or an error if it was not found (or is not available). Implements jujuc.RelationHookContext.relationHookContext, part of runner.Context.

func (*HookContext) HookStorage Uses

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

HookStorage returns the storage attachment associated the executing hook if it was found, and an error if it was not found or is not available. Implements jujuc.HookContext.ContextStorage, part of runner.Context.

func (*HookContext) HookVars Uses

func (ctx *HookContext) HookVars(paths Paths, remote bool) ([]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. Implements runner.Context.

func (*HookContext) Id Uses

func (ctx *HookContext) Id() string

Id returns an integer which uniquely identifies the relation. Implements jujuc.HookContext.ContextRelation, part of runner.Context.

func (*HookContext) LogActionMessage Uses

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

LogActionMessage logs a progress message for the Action. Implements jujuc.ActionHookContext.actionHookContext, part of runner.Context.

func (*HookContext) ModelType Uses

func (ctx *HookContext) ModelType() model.ModelType

ModelType of the context we are running in. SetProcess implements runner.Context.

func (*HookContext) NetworkInfo Uses

func (ctx *HookContext) NetworkInfo(bindingNames []string, relationId int) (map[string]params.NetworkInfoResult, error)

NetworkInfo returns the network info for the given bindings on the given relation. Implements jujuc.HookContext.ContextNetworking, part of runner.Context.

func (*HookContext) OpenPorts Uses

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

OpenPorts marks the supplied port range for opening when the executing unit's application is exposed. Implements jujuc.HookContext.ContextNetworking, part of runner.Context.

func (*HookContext) OpenedPorts Uses

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

OpenedPorts returns all port ranges currently opened by this unit on its assigned machine. The result is sorted first by protocol, then by number. Implements jujuc.HookContext.ContextNetworking, part of runner.Context.

func (*HookContext) Prepare Uses

func (ctx *HookContext) Prepare() error

Prepare implements the runner.Context interface.

func (*HookContext) PrivateAddress Uses

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

PrivateAddress returns the executing unit's private address or an error if it is not available. Implements jujuc.HookContext.ContextNetworking, part of runner.Context.

func (*HookContext) PublicAddress Uses

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

PublicAddress returns the executing unit's public address or an error if it is not available. Implements jujuc.HookContext.ContextNetworking, part of runner.Context.

func (*HookContext) Relation Uses

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

Relation returns the relation with the supplied id if it was found, and an error if it was not found or is not available. Implements jujuc.HookContext.ContextRelations, part of runner.Context.

func (*HookContext) RelationIds Uses

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

RelationIds returns the ids of all relations the executing unit is currently participating in or an error if they are not available. Implements jujuc.HookContext.ContextRelations, part of runner.Context.

func (*HookContext) RemoteApplicationName Uses

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

RemoteApplicationName returns the name of the remote application the hook execution is associated with if it was found, and an error if it was not found or is not available. Implements jujuc.RelationHookContext.relationHookContext, part of runner.Context.

func (*HookContext) RemoteUnitName Uses

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

RemoteUnitName returns the name of the remote unit the hook execution is associated with if it was found, and an error if it was not found or is not available. Implements jujuc.RelationHookContext.relationHookContext, part of runner.Context.

func (*HookContext) RequestReboot Uses

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

RequestReboot will set the reboot flag to true on the machine agent Implements jujuc.HookContext.ContextInstance, part of runner.Context.

func (*HookContext) ResetExecutionSetUnitStatus Uses

func (ctx *HookContext) ResetExecutionSetUnitStatus()

Implements runner.Context.

func (*HookContext) SetActionFailed Uses

func (ctx *HookContext) SetActionFailed() error

SetActionFailed sets the fail state of the action. Implements jujuc.ActionHookContext.actionHookContext, part of runner.Context.

func (*HookContext) SetActionMessage Uses

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

SetActionMessage sets a message for the Action, usually an error message. Implements jujuc.ActionHookContext.actionHookContext, part of runner.Context.

func (*HookContext) SetApplicationStatus Uses

func (ctx *HookContext) SetApplicationStatus(applicationStatus jujuc.StatusInfo) error

SetApplicationStatus will set the given status to the application to which this unit's belong, only if this unit is the leader. Implements jujuc.HookContext.ContextStatus, part of runner.Context.

func (*HookContext) SetCacheValue Uses

func (ctx *HookContext) SetCacheValue(key, value string) error

SetCacheValue sets the key/value pair provided in the cache. Implements jujuc.HookContext.unitCacheContext, part of runner.Context.

func (*HookContext) SetPodSpec Uses

func (ctx *HookContext) SetPodSpec(specYaml string) error

SetPodSpec sets the podspec for the unit's application. Implements jujuc.HookContext.ContextUnit, part of runner.Context.

func (*HookContext) SetProcess Uses

func (ctx *HookContext) SetProcess(process HookProcess)

SetProcess implements runner.Context.

func (*HookContext) SetUnitStatus Uses

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

SetUnitStatus will set the given status for this unit. Implements jujuc.HookContext.ContextStatus, part of runner.Context.

func (*HookContext) SetUnitWorkloadVersion Uses

func (ctx *HookContext) SetUnitWorkloadVersion(version string) error

SetUnitWorkloadVersion sets the current unit's workload version to the specified value. Implements jujuc.HookContext.ContextVersion, part of runner.Context.

func (*HookContext) Storage Uses

func (ctx *HookContext) Storage(tag names.StorageTag) (jujuc.ContextStorageAttachment, error)

Storage returns the ContextStorageAttachment with the supplied tag if it was found, and an error if it was not found or is not available to the context. Implements jujuc.HookContext.ContextStorage, part of runner.Context.

func (*HookContext) StorageTags Uses

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

StorageTags returns a list of tags for storage instances attached to the unit or an error if they are not available. Implements jujuc.HookContext.ContextStorage, part of runner.Context.

func (*HookContext) UnitName Uses

func (ctx *HookContext) UnitName() string

UnitName returns the executing unit's name. UnitName implements jujuc.HookContext.ContextUnit, part of runner.Context.

func (*HookContext) UnitStatus Uses

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

UnitStatus will return the status for the current Unit. Implements jujuc.HookContext.ContextStatus, part of runner.Context.

func (*HookContext) UnitWorkloadVersion Uses

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

UnitWorkloadVersion returns the version of the workload reported by the current unit. Implements jujuc.HookContext.ContextVersion, part of runner.Context.

func (*HookContext) UpdateActionResults Uses

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 controller upon completion of the Action. It returns an error if not called on an Action-containing HookContext. Implements jujuc.ActionHookContext.actionHookContext, part of runner.Context.

type HookProcess Uses

type HookProcess interface {
    Pid() int
    Kill() error
}

HookProcess is an interface representing a process running a hook.

type HookUnit Uses

type HookUnit interface {
    AddStorage(constraints map[string][]params.StorageConstraints) error
    Application() (*uniter.Application, error)
    ApplicationName() string
    ClosePorts(protocol string, fromPort, toPort int) error
    ConfigSettings() (charm.Settings, error)
    LogActionMessage(names.ActionTag, string) error
    Name() string
    NetworkInfo(bindings []string, relationId *int) (map[string]params.NetworkInfoResult, error)
    OpenPorts(protocol string, fromPort, toPort int) error
    RequestReboot() error
    SetState(map[string]string) error
    SetUnitStatus(unitStatus status.Status, info string, data map[string]interface{}) error
    State() (map[string]string, error)
    Tag() names.UnitTag
    UnitStatus() (params.StatusResult, error)
    UpdateNetworkInfo() error
}

HookUnit represents the functions needed by a unit in a hook context to call into state.

type LeadershipContext Uses

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

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

func NewLeadershipContext Uses

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

type LeadershipSettingsAccessor Uses

type LeadershipSettingsAccessor interface {
    Read(applicationName string) (map[string]string, error)
    Merge(applicationName, unitName 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 Uses

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.
    GetBaseDir() string

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

    // GetJujucServerSocket 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.
    GetJujucServerSocket(remote bool) sockets.Socket

    // GetJujucClientSocket 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.
    GetJujucClientSocket(remote bool) sockets.Socket

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

    // ComponentDir returns the filesystem path to the directory
    // containing all data files for a component.
    ComponentDir(name string) string
}

Paths exposes the paths needed by Context.

type PortRange Uses

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 Uses

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 Uses

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 Uses

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) ApplicationSettings Uses

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

ApplicationSettings returns the relation settings of the named application.

func (*RelationCache) InvalidateApplication Uses

func (cache *RelationCache) InvalidateApplication(appName string)

InvalidateApplication ensures that contents cached for remote app will be wiped clean and that the next attempt to read its settings will use fresh data.

func (*RelationCache) InvalidateMember Uses

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 Uses

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

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

func (*RelationCache) Prune Uses

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 Uses

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 Uses

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 Uses

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

type RelationsFunc Uses

type RelationsFunc func() map[int]*RelationInfo

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

type SettingsFunc Uses

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

SettingsFunc returns the relation settings for a unit.

type SettingsMap Uses

type SettingsMap map[string]params.Settings

SettingsMap is a map from unit name to relation settings.

type StorageContextAccessor Uses

type StorageContextAccessor interface {

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

    // Storage returns the hooks.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 hooks.Context.

Directories

PathSynopsis
mocksPackage mocks is a generated GoMock package.

Package context imports 33 packages (graph) and is imported by 146 packages. Updated 2020-02-20. Refresh now. Tools for package owners.