juju: github.com/juju/juju/worker/meterstatus Index | Files

package meterstatus

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

Package meterstatus provides a worker that executes the meter-status-changed hook periodically.

Index

Package Files

connected.go context.go isolated.go manifold.go runner.go state.go triggers.go

func GetTriggers Uses

func GetTriggers(
    wst WorkerState,
    status string,
    disconnectedAt time.Time,
    clk clock.Clock,
    amberGracePeriod time.Duration,
    redGracePeriod time.Duration) (<-chan time.Time, <-chan time.Time)

GetTriggers returns the signal channels for state transitions based on the current state. It controls the transitions of the inactive meter status worker.

In a simple case, the transitions are trivial:

D------------------A----------------------R--------------------->

D - disconnect time A - amber status triggered R - red status triggered

The problem arises from the fact that the lifetime of the worker can be interrupted, possibly with significant portions of the duration missing.

func Manifold Uses

func Manifold(config ManifoldConfig) dependency.Manifold

Manifold returns a status manifold.

func NewConnectedStatusHandler Uses

func NewConnectedStatusHandler(cfg ConnectedConfig) (watcher.NotifyHandler, error)

NewConnectedStatusHandler creates a new meter status handler for handling meter status changes as provided by the API.

func NewConnectedStatusWorker Uses

func NewConnectedStatusWorker(cfg ConnectedConfig) (worker.Worker, error)

NewConnectedStatusWorker creates a new worker that monitors the meter status of the unit and runs the meter-status-changed hook appropriately.

func NewIsolatedStatusWorker Uses

func NewIsolatedStatusWorker(cfg IsolatedConfig) (worker.Worker, error)

NewIsolatedStatusWorker creates a new status worker that runs without an API connection.

func NewLimitedContext Uses

func NewLimitedContext(unitName string) *limitedContext

NewLimitedContext creates a new context that implements just the bare minimum of the hooks.Context interface.

type ConnectedConfig Uses

type ConnectedConfig struct {
    Runner    HookRunner
    StateFile *StateFile
    Status    meterstatus.MeterStatusClient
}

ConnectedConfig contains all the dependencies required to create a new connected status worker.

func (ConnectedConfig) Validate Uses

func (c ConnectedConfig) Validate() error

Validate validates the config structure and returns an error on failure.

type Disconnected Uses

type Disconnected struct {
    Disconnected int64       `yaml:"disconnected-at,omitempty"`
    State        WorkerState `yaml:"disconnected-state,omitempty"`
}

Disconnected stores the information relevant to the inactive meter status worker.

func (Disconnected) When Uses

func (d Disconnected) When() time.Time

When returns the time when the unit was disconnected.

type HookRunner Uses

type HookRunner interface {
    RunHook(string, string, <-chan struct{}) error
}

HookRunner implements the functionality necessary to run a meter-status-changed hook.

func NewHookRunner Uses

func NewHookRunner(tag names.UnitTag, machineLock machinelock.Lock, config agent.Config, clock clock.Clock) HookRunner

type IsolatedConfig Uses

type IsolatedConfig struct {
    Runner           HookRunner
    StateFile        *StateFile
    Clock            clock.Clock
    AmberGracePeriod time.Duration
    RedGracePeriod   time.Duration
    TriggerFactory   TriggerCreator
}

IsolatedConfig stores all the dependencies required to create an isolated meter status worker.

func (IsolatedConfig) Validate Uses

func (c IsolatedConfig) Validate() error

Validate validates the config structure and returns an error on failure.

type ManifoldConfig Uses

type ManifoldConfig struct {
    AgentName     string
    APICallerName string
    MachineLock   machinelock.Lock
    Clock         clock.Clock

    NewHookRunner           func(names.UnitTag, machinelock.Lock, agent.Config, clock.Clock) HookRunner
    NewMeterStatusAPIClient func(base.APICaller, names.UnitTag) meterstatus.MeterStatusClient

    NewConnectedStatusWorker func(ConnectedConfig) (worker.Worker, error)
    NewIsolatedStatusWorker  func(IsolatedConfig) (worker.Worker, error)
}

ManifoldConfig identifies the resource names upon which the status manifold depends.

type StateFile Uses

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

StateFile holds the meter status on disk.

func NewStateFile Uses

func NewStateFile(path string) *StateFile

NewStateFile creates a new file for persistent storage of the meter status.

func (*StateFile) Read Uses

func (f *StateFile) Read() (string, string, *Disconnected, error)

Read reads the current meter status information from disk.

func (*StateFile) Write Uses

func (f *StateFile) Write(code, info string, disconnected *Disconnected) error

Write stores the supplied status information to disk.

type TriggerCreator Uses

type TriggerCreator func(WorkerState, string, time.Time, clock.Clock, time.Duration, time.Duration) (<-chan time.Time, <-chan time.Time)

type WorkerState Uses

type WorkerState int

workerState defines all the possible states the isolatedStatusWorker can be in.

const (
    Uninitialized WorkerState = iota
    WaitingAmber              // Waiting for a signal to switch to AMBER status.
    WaitingRed                // Waiting for a signal to switch to RED status.
    Done                      // No more transitions to perform.
)

Package meterstatus imports 26 packages (graph) and is imported by 23 packages. Updated 2019-09-18. Refresh now. Tools for package owners.