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

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,
    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.

type Clock Uses

type Clock interface {
    Now() time.Time
    After(time.Duration) <-chan time.Time
}

Clock defines the time methods used by this package.

type ConnectedConfig Uses

type ConnectedConfig struct {
    Runner          HookRunner
    Status          meterstatus.MeterStatusClient
    StateReadWriter StateReadWriter
    Logger          Logger
}

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

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

ControllerBackedState is a StateReadWriter that uses the controller as its backing store.

func NewControllerBackedState Uses

func NewControllerBackedState(api UnitStateAPI) *ControllerBackedState

NewControllerBackedState returns a new ControllerBackedState that uses the provided UnitStateAPI to communicate with the controller.

func (*ControllerBackedState) Read Uses

func (cbs *ControllerBackedState) Read() (*State, error)

Read the current meter status information from the controller.

func (*ControllerBackedState) Write Uses

func (cbs *ControllerBackedState) Write(st *State) error

Write the supplied status information to the controller.

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

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

DiskBackedState stores the meter status on disk.

func NewDiskBackedState Uses

func NewDiskBackedState(path string) *DiskBackedState

NewDiskBackedState creates a DiskBackedState instance that uses path for reading/writing the meter status state.

func (*DiskBackedState) Read Uses

func (dbs *DiskBackedState) Read() (*State, error)

Read the current meter status information from disk.

func (*DiskBackedState) Write Uses

func (dbs *DiskBackedState) Write(st *State) error

Write the supplied status information to disk.

type HookRunner Uses

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

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

func NewHookRunner Uses

func NewHookRunner(config HookRunnerConfig) HookRunner

type HookRunnerConfig Uses

type HookRunnerConfig struct {
    MachineLock machinelock.Lock
    AgentConfig agent.Config
    Tag         names.UnitTag
    Clock       Clock
    Logger      Logger
}

HookRunnerConfig is just an argument struct for NewHookRunner.

type IsolatedConfig Uses

type IsolatedConfig struct {
    Runner           HookRunner
    StateReadWriter  StateReadWriter
    Clock            Clock
    Logger           Logger
    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 Logger Uses

type Logger interface {
    Errorf(string, ...interface{})
    Warningf(string, ...interface{})
    Infof(string, ...interface{})
    Debugf(string, ...interface{})
    Tracef(string, ...interface{})

    Root() loggo.Logger
}

Logger represents the logging methods used in this package.

type ManifoldConfig Uses

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

    NewHookRunner           func(HookRunnerConfig) HookRunner
    NewMeterStatusAPIClient func(base.APICaller, names.UnitTag) meterstatus.MeterStatusClient
    NewUniterStateAPIClient func(base.FacadeCaller, names.UnitTag) *common.UnitStateAPI

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

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

type State Uses

type State struct {
    Code         string        `yaml:"status-code"`
    Info         string        `yaml:"status-info"`
    Disconnected *Disconnected `yaml:"disconnected,omitempty"`
}

State represents the worker's internal state.

type StateReadWriter Uses

type StateReadWriter interface {
    Read() (*State, error)
    Write(*State) error
}

StateReadWriter is implemented by types that can read and write the meter worker's internal state.

type TriggerCreator Uses

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

type UnitStateAPI Uses

type UnitStateAPI interface {
    State() (params.UnitStateResult, error)
    SetState(params.SetUnitStateArg) error
}

UnitStateAPI describes the API for reading/writing unit state data from/to the controller.

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.
)

Directories

PathSynopsis
mocksPackage mocks is a generated GoMock package.

Package meterstatus imports 28 packages (graph) and is imported by 28 packages. Updated 2020-08-04. Refresh now. Tools for package owners.