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

package uniter

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


Package Files

agent.go manifold.go op_callbacks.go paths.go resolver.go runlistener.go timer.go uniter.go


const JujuRunEndpoint = "JujuRunServer.RunCommands"


var (

    // ErrCAASUnitDead is the error returned from terminate or init
    // if the unit is Dead.
    ErrCAASUnitDead = errors.New("unit dead")

func Manifold Uses

func Manifold(config ManifoldConfig) dependency.Manifold

Manifold returns a dependency manifold that runs a uniter worker, using the resource names defined in the supplied config.

func NewRunListenerWrapper Uses

func NewRunListenerWrapper(rl *RunListener) worker.Worker

NewRunListenerWrapper returns a worker that will Close the supplied run listener when the worker is killed. The Wait() method will never return an error -- NewRunListener just drops the Run error on the floor and that's not what I'm fixing here.

func NewUniterResolver Uses

func NewUniterResolver(cfg ResolverConfig) resolver.Resolver

NewUniterResolver returns a new resolver.Resolver for the uniter.

func NewUpdateStatusTimer Uses

func NewUpdateStatusTimer() remotestate.UpdateStatusTimerFunc

NewUpdateStatusTimer returns a func returning timed signal suitable for update-status hook.

func StartUniter Uses

func StartUniter(runner *worker.Runner, params *UniterParams) error

StartUniter creates a new Uniter and starts it using the specified runner.

func TranslateFortressErrors Uses

func TranslateFortressErrors(err error) error

TranslateFortressErrors turns errors returned by dependent manifolds due to fortress lockdown (i.e. model migration) into an error which causes the resolver loop to be restarted. When this happens the uniter is about to be shut down anyway.

type ChannelCommandRunner Uses

type ChannelCommandRunner struct {
    // contains filtered or unexported fields

ChannelCommandRunner is a CommandRunner that registers command arguments in a runcommands.Commands, sends the returned IDs to a channel and waits for response callbacks.

func NewChannelCommandRunner Uses

func NewChannelCommandRunner(cfg ChannelCommandRunnerConfig) (*ChannelCommandRunner, error)

NewChannelCommandRunner returns a new ChannelCommandRunner with the given configuration.

func (*ChannelCommandRunner) RunCommands Uses

func (c *ChannelCommandRunner) RunCommands(args RunCommandsArgs) (results *exec.ExecResponse, err error)

RunCommands executes the supplied run commands by registering the arguments in a runcommands.Commands, and then sending the returned ID to a channel and waiting for a response callback.

type ChannelCommandRunnerConfig Uses

type ChannelCommandRunnerConfig struct {
    // Abort is a channel that will be closed when the runner should abort
    // the execution of run commands.
    Abort <-chan struct{}

    // Commands is used to add commands received from the listener.
    Commands runcommands.Commands

    // CommandChannel will be sent the IDs of commands added to Commands.
    CommandChannel chan<- string

ChannelCommandRunnerConfig contains the configuration for a ChannelCommandRunner.

func (ChannelCommandRunnerConfig) Validate Uses

func (cfg ChannelCommandRunnerConfig) Validate() error

type CommandRunner Uses

type CommandRunner interface {
    RunCommands(RunCommandsArgs RunCommandsArgs) (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 JujuRunServer Uses

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 Uses

func (r *JujuRunServer) RunCommands(args RunCommandsArgs, result *exec.ExecResponse) error

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

type ManifoldConfig Uses

type ManifoldConfig struct {
    AgentName             string
    APICallerName         string
    MachineLock           machinelock.Lock
    Clock                 clock.Clock
    LeadershipTrackerName string
    CharmDirName          string
    HookRetryStrategyName string
    TranslateResolverErr  func(error) error

ManifoldConfig defines the names of the manifolds on which a Manifold will depend.

type NewOperationExecutorFunc Uses

type NewOperationExecutorFunc func(string, operation.State, func(string) (func(), error)) (operation.Executor, error)

type NewRunnerExecutorFunc Uses

type NewRunnerExecutorFunc func(ProviderIDGetter, Paths) runner.ExecFunc

NewRunnerExecutorFunc defines the type of the NewRunnerExecutor.

type NopResolver Uses

type NopResolver struct{}

NopResolver is a resolver that does nothing.

func (NopResolver) NextOp Uses

func (NopResolver) NextOp(resolver.LocalState, remotestate.Snapshot, operation.Factory) (operation.Operation, error)

The NopResolver's NextOp operation should always return the no operation error.

type Paths Uses

type Paths struct {

    // ToolsDir is the directory containing the jujud executable running this
    // process; and also containing jujuc tool symlinks to that executable. It's
    // the only path in this struct that is not typically pointing inside the
    // directory reserved for the exclusive use of this worker (typically
    // /var/lib/juju/agents/$UNIT_TAG/ )
    ToolsDir string

    // Runtime represents the set of paths that are relevant at runtime.
    Runtime RuntimePaths

    // State represents the set of paths that hold persistent local state for
    // the uniter.
    State StatePaths

Paths represents the set of filesystem paths a uniter worker has reason to care about.

func NewPaths Uses

func NewPaths(dataDir string, unitTag names.UnitTag, socketConfig *SocketConfig) Paths

NewPaths returns the set of filesystem paths that the supplied unit should use, given the supplied root juju data directory path. If socketConfig is specified, all sockets will be TLS over TCP.

func NewWorkerPaths Uses

func NewWorkerPaths(dataDir string, unitTag names.UnitTag, worker string, socketConfig *SocketConfig) Paths

NewWorkerPaths returns the set of filesystem paths that the supplied unit worker should use, given the supplied root juju data directory path and worker identifier. Distinct worker identifiers ensure that runtime paths of different worker do not interfere. If socketConfig is specified, all sockets will be TLS over TCP.

func (Paths) ComponentDir Uses

func (paths Paths) ComponentDir(name string) string

ComponentDir returns the filesystem path to the directory containing all data files for a component.

func (Paths) GetBaseDir Uses

func (paths Paths) GetBaseDir() string

GetBaseDir exists to satisfy the context.Paths interface.

func (Paths) GetCharmDir Uses

func (paths Paths) GetCharmDir() string

GetCharmDir exists to satisfy the context.Paths interface.

func (Paths) GetJujucClientSocket Uses

func (paths Paths) GetJujucClientSocket(remote bool) sockets.Socket

GetJujucClientSocket exists to satisfy the context.Paths interface.

func (Paths) GetJujucServerSocket Uses

func (paths Paths) GetJujucServerSocket(remote bool) sockets.Socket

GetJujucServerSocket exists to satisfy the context.Paths interface.

func (Paths) GetMetricsSpoolDir Uses

func (paths Paths) GetMetricsSpoolDir() string

GetMetricsSpoolDir exists to satisfy the runner.Paths interface.

func (Paths) GetToolsDir Uses

func (paths Paths) GetToolsDir() string

GetToolsDir exists to satisfy the context.Paths interface.

type ProviderIDGetter Uses

type ProviderIDGetter interface {
    ProviderID() string
    Refresh() error
    Name() string

ProviderIDGetter defines the API to get provider ID.

type ResolverConfig Uses

type ResolverConfig struct {
    ModelType           model.ModelType
    ClearResolved       func() error
    ReportHookError     func(hook.Info) error
    ShouldRetryHooks    bool
    StartRetryHookTimer func()
    StopRetryHookTimer  func()
    UpgradeSeries       resolver.Resolver
    Leadership          resolver.Resolver
    Actions             resolver.Resolver
    Relations           resolver.Resolver
    Storage             resolver.Resolver
    Commands            resolver.Resolver

ResolverConfig defines configuration for the uniter resolver.

type RunCommandsArgs Uses

type RunCommandsArgs struct {
    // Commands is the arbitrary commands to execute on the unit
    Commands string
    // 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 relation membership and existence validation.
    ForceRemoteUnit bool
    // UnitName is the unit for which the command is being run.
    UnitName string
    // Token is the unit token when run under CAAS environments for auth.
    Token string

RunCommandsArgs stores the arguments for a RunCommands call.

type RunListener Uses

type RunListener struct {
    // contains filtered or unexported fields

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

func NewRunListener Uses

func NewRunListener(socket sockets.Socket) (*RunListener, error)

NewRunListener returns a new RunListener that is listening on given socket or named pipe 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 Uses

func (r *RunListener) Close() error

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

func (*RunListener) RegisterRunner Uses

func (r *RunListener) RegisterRunner(unitName string, runner CommandRunner)

RegisterRunner registers a command runner for a given unit.

func (*RunListener) Run Uses

func (r *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.

func (*RunListener) RunCommands Uses

func (r *RunListener) RunCommands(args RunCommandsArgs) (results *exec.ExecResponse, err error)

RunCommands executes the supplied commands in a hook context.

func (*RunListener) UnregisterRunner Uses

func (r *RunListener) UnregisterRunner(unitName string)

UnregisterRunner unregisters a command runner for a given unit.

type RuntimePaths Uses

type RuntimePaths struct {
    // JujuRunSocket listens for juju-run invocations, and is always
    // active.
    LocalJujuRunSocket SocketPair

    // RemoteJujuRunSocket listens for remote juju-run invocations.
    RemoteJujuRunSocket SocketPair

    // JujucServerSocket listens for jujuc invocations, and is only
    // active when supporting a jujuc execution context.
    LocalJujucServerSocket SocketPair

    // RemoteJujucServerSocket listens for remote jujuc invocations, and is only
    // active when supporting a jujuc execution context.
    RemoteJujucServerSocket SocketPair

RuntimePaths represents the set of paths that are relevant at runtime.

type SocketConfig Uses

type SocketConfig struct {
    ServiceAddress  string
    OperatorAddress string
    TLSConfig       *tls.Config

SocketConfig specifies information for remote sockets.

type SocketPair Uses

type SocketPair struct {
    Server sockets.Socket
    Client sockets.Socket

SocketPair is a server+client pair of socket descriptors.

type StatePaths Uses

type StatePaths struct {
    // BaseDir is the unit agent's base directory.
    BaseDir string

    // CharmDir is the directory to which the charm the uniter runs is deployed.
    CharmDir string

    // OperationsFile holds information about what the uniter is doing
    // and/or has done.
    OperationsFile string

    // RelationsDir holds relation-specific information about what the
    // uniter is doing and/or has done.
    RelationsDir string

    // BundlesDir holds downloaded charms.
    BundlesDir string

    // DeployerDir holds metadata about charms that are installing or have
    // been installed.
    DeployerDir string

    // StorageDir holds storage-specific information about what the
    // uniter is doing and/or has done.
    StorageDir string

    // MetricsSpoolDir acts as temporary storage for metrics being sent from
    // the uniter to state.
    MetricsSpoolDir string

StatePaths represents the set of paths that hold persistent local state for the uniter.

type Uniter Uses

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 Uses

func NewUniter(uniterParams *UniterParams) (*Uniter, error)

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

func (u *Uniter) Kill()

func (*Uniter) RunCommands Uses

func (u *Uniter) RunCommands(args RunCommandsArgs) (results *exec.ExecResponse, err error)

RunCommands executes the supplied commands in a hook context.

func (*Uniter) Wait Uses

func (u *Uniter) Wait() error

type UniterExecutionObserver Uses

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.

type UniterParams Uses

type UniterParams struct {
    UniterFacade            *uniter.State
    UnitTag                 names.UnitTag
    ModelType               model.ModelType
    LeadershipTracker       leadership.TrackerWorker
    DataDir                 string
    Downloader              charm.Downloader
    MachineLock             machinelock.Lock
    CharmDirGuard           fortress.Guard
    UpdateStatusSignal      remotestate.UpdateStatusTimerFunc
    HookRetryStrategy       params.RetryStrategy
    NewOperationExecutor    NewOperationExecutorFunc
    NewRemoteRunnerExecutor NewRunnerExecutorFunc
    RunListener             *RunListener
    TranslateResolverErr    func(error) error
    Clock                   clock.Clock
    ApplicationChannel      watcher.NotifyChannel
    SocketConfig            *SocketConfig
    // TODO (mattyw, wallyworld, fwereade) Having the observer here make this approach a bit more legitimate, but it isn't.
    // the observer is only a stop gap to be used in tests. A better approach would be to have the uniter tests start hooks
    // that write to files, and have the tests watch the output to know that hooks have finished.
    Observer UniterExecutionObserver

UniterParams hold all the necessary parameters for a new Uniter.


hookPackage hook provides types that define the hooks known to the Uniter
operation/mocksPackage mocks is a generated GoMock package.
relationrelation implements persistent local storage of a unit's relation state, and translation of relation changes into hooks that need to be run.
runner/contextPackage context contains the ContextFactory and Context definitions.
runner/jujucThe worker/uniter/runner/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.
storagePackage storage contains the storage subsystem for the uniter, responding to changes in storage attachments (lifecycle, volume/filesystem details) by queuing hooks and managing the storage attachments' lifecycle.

Package uniter imports 54 packages (graph) and is imported by 127 packages. Updated 2019-10-21. Refresh now. Tools for package owners.