juju: github.com/juju/juju/core/cache Index | Files | Directories

package cache

import "github.com/juju/juju/core/cache"

Package cache is responsible for keeping an in memory representation of the controller's models.

The Controller is kept up to date with the database though a changes channel.

Instances in the cache package also provide watchers. These watchers are checking for changes in the in-memory representation and can be used to avoid excess database reads.

Index

Package Files

application.go branch.go changes.go charm.go charmconfigwatcher.go controller.go doc.go hash.go lxdprofilewatcher.go machine.go metrics.go model.go modelwatcher.go resident.go unit.go watcher.go

Variables

var (
    // IdleFunc allows tests to be able to get callbacks when the controller
    // hasn't been given any changes for a specified time.
    IdleFunc func()

    // IdleTime relates to how long the controller needs to wait with no changes
    // to be considered idle.
    IdleTime = 50 * time.Millisecond
)

type Application Uses

type Application struct {
    // Resident identifies the application as a type-agnostic cached entity
    // and tracks resources that it is responsible for cleaning up.
    *Resident
    // contains filtered or unexported fields
}

Application represents an application in a model.

func (*Application) CharmURL Uses

func (a *Application) CharmURL() string

CharmURL returns the charm url string for this application.

func (*Application) Config Uses

func (a *Application) Config() map[string]interface{}

Config returns a copy of the current application config.

func (*Application) WatchConfig Uses

func (a *Application) WatchConfig(keys ...string) *ConfigWatcher

WatchConfig creates a watcher for the application config. Do not use this to watch config on behalf of a unit. It is not aware of branch-based config deltas and only deals with master settings.

type ApplicationChange Uses

type ApplicationChange struct {
    ModelUUID       string
    Name            string
    Exposed         bool
    CharmURL        string
    Life            life.Value
    MinUnits        int
    Constraints     constraints.Value
    Config          map[string]interface{}
    Subordinate     bool
    Status          status.StatusInfo
    WorkloadVersion string
}

ApplicationChange represents either a new application, or a change to an existing application in a model.

type Branch Uses

type Branch struct {
    // Resident identifies the branch as a type-agnostic cached entity
    // and tracks resources that it is responsible for cleaning up.
    *Resident
    // contains filtered or unexported fields
}

Branch represents an active branch in a cached model.

func (*Branch) AppConfig Uses

func (b *Branch) AppConfig(appName string) settings.ItemChanges

AppConfig returns the configuration changes that apply to the branch for a specific application.

func (*Branch) AssignedUnits Uses

func (b *Branch) AssignedUnits() map[string][]string

AssignedUnits returns a map of the names of units tracking this branch, keyed by application names with changes made under the branch.

func (*Branch) Completed Uses

func (b *Branch) Completed() int64

Completed returns a Unix timestamp indicating when this generation was committed.

func (*Branch) CompletedBy Uses

func (b *Branch) CompletedBy() string

CreatedBy returns user who committed the branch.

func (*Branch) Config Uses

func (b *Branch) Config() map[string]settings.ItemChanges

Config returns the configuration changes that apply to the branch.

func (*Branch) Created Uses

func (b *Branch) Created() int64

Created returns a Unix timestamp indicating when this generation was created.

func (*Branch) CreatedBy Uses

func (b *Branch) CreatedBy() string

CreatedBy returns user who created the branch.

func (*Branch) Name Uses

func (b *Branch) Name() string

Name returns the name of the branch. It is guaranteed to uniquely identify an active branch in the cache.

type BranchChange Uses

type BranchChange struct {
    ModelUUID     string
    Id            string
    Name          string
    AssignedUnits map[string][]string
    Config        map[string]settings.ItemChanges
    Created       int64
    CreatedBy     string
    Completed     int64
    CompletedBy   string
    GenerationId  int
}

BranchChange represents a change to an active model branch. Note that this corresponds to a multi-watcher BranchInfo payload, and that the cache behaviour differs from other entities; when a generation is completed (aborted or committed), it is no longer an active branch and will be removed from the cache.

type Charm Uses

type Charm struct {
    // Resident identifies the charm as a type-agnostic cached entity
    // and tracks resources that it is responsible for cleaning up.
    *Resident
    // contains filtered or unexported fields
}

Charm represents an charm in a model.

func (*Charm) DefaultConfig Uses

func (c *Charm) DefaultConfig() map[string]interface{}

DefaultConfig returns the default configuration settings for the charm.

func (*Charm) LXDProfile Uses

func (c *Charm) LXDProfile() lxdprofile.Profile

LXDProfile returns the lxd profile of this charm.

type CharmChange Uses

type CharmChange struct {
    ModelUUID     string
    CharmURL      string
    CharmVersion  string
    LXDProfile    lxdprofile.Profile
    DefaultConfig map[string]interface{}
}

CharmChange represents either a new charm, or a change to an existing charm in a model.

type CharmConfigWatcher Uses

type CharmConfigWatcher struct {
    CharmConfigHashCacheHitInc  func()
    CharmConfigHashCacheMissInc func()
    // contains filtered or unexported fields
}

CharmConfigWatcher watches application charm config on behalf of a unit. The watcher will notify if either of the following events cause a change to the unit's effective configuration: - Changes to the charm config settings for the unit's application. - Changes to a model branch being tracked by the unit.

func (CharmConfigWatcher) Changes Uses

func (w CharmConfigWatcher) Changes() <-chan []string

Changes is part of the core watcher definition. The changes channel is never closed.

func (CharmConfigWatcher) Err Uses

func (w CharmConfigWatcher) Err() error

Err returns the inner tomb's error.

func (CharmConfigWatcher) Kill Uses

func (w CharmConfigWatcher) Kill()

Kill is part of the worker.Worker interface.

func (CharmConfigWatcher) Stop Uses

func (w CharmConfigWatcher) Stop() error

Stop is currently required by the Resources wrapper in the apiserver.

func (CharmConfigWatcher) Wait Uses

func (w CharmConfigWatcher) Wait() error

Wait is part of the worker.Worker interface.

type Clock Uses

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

Clock defines the clockish methods used by the controller.

type Collector Uses

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

Collector is a prometheus.Collector that collects metrics about the Juju global state.

func NewMetricsCollector Uses

func NewMetricsCollector(controller *Controller) *Collector

NewMetricsCollector returns a new Collector.

func (*Collector) Collect Uses

func (c *Collector) Collect(ch chan<- prometheus.Metric)

Collect is part of the prometheus.Collector interface.

func (*Collector) Describe Uses

func (c *Collector) Describe(ch chan<- *prometheus.Desc)

Describe is part of the prometheus.Collector interface.

type ConfigWatcher Uses

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

ConfigWatcher watches a single entity's configuration. If keys are specified the watcher only signals a change when at least one of those keys changes value. If no keys are specified, any change in the config will trigger the watcher to notify.

func (ConfigWatcher) Changes Uses

func (w ConfigWatcher) Changes() <-chan struct{}

Changes is part of the core watcher definition.

func (ConfigWatcher) Kill Uses

func (w ConfigWatcher) Kill()

Kill is part of the worker.Worker interface.

func (ConfigWatcher) Stop Uses

func (w ConfigWatcher) Stop() error

Stop is currently required by the Resources wrapper in the apiserver.

func (ConfigWatcher) Wait Uses

func (w ConfigWatcher) Wait() error

Wait is part of the worker.Worker interface.

type Controller Uses

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

Controller is the primary cached object.

func NewController Uses

func NewController(config ControllerConfig) (*Controller, error)

NewController creates a new cached controller instance. The changes channel is what is used to supply the cache with the changes in order for the cache to be kept up to date.

func (*Controller) Kill Uses

func (c *Controller) Kill()

Kill is part of the worker.Worker interface.

func (*Controller) Mark Uses

func (c *Controller) Mark()

Mark updates all cached entities to indicate they are stale.

func (*Controller) Model Uses

func (c *Controller) Model(uuid string) (*Model, error)

Model returns the model for the specified UUID. If the model isn't found, a NotFoundError is returned.

func (*Controller) ModelUUIDs Uses

func (c *Controller) ModelUUIDs() []string

ModelUUIDs returns the UUIDs of the models in the cache.

func (*Controller) Report Uses

func (c *Controller) Report() map[string]interface{}

Report returns information that is used in the dependency engine report.

func (*Controller) Sweep Uses

func (c *Controller) Sweep()

Sweep evicts any stale entities from the cache, cleaning up resources that they are responsible for.

func (*Controller) Wait Uses

func (c *Controller) Wait() error

Wait is part of the worker.Worker interface.

func (*Controller) WaitForModel Uses

func (c *Controller) WaitForModel(uuid string, clock Clock) (*Model, error)

WaitForModel waits for a time for the specified model to appear in the cache.

type ControllerConfig Uses

type ControllerConfig struct {
    // Changes from the event source come over this channel.
    // The changes channel must be non-nil.
    Changes chan interface{}

    // Notify is a callback function used primarily for testing, and is
    // called by the controller main processing loop after processing a change.
    // The change processed is passed in as the arg to notify.
    Notify func(interface{})
}

ControllerConfig is a simple config value struct for the controller.

func (*ControllerConfig) Validate Uses

func (c *ControllerConfig) Validate() error

Validate ensures the controller has the right values to be created.

type ControllerGauges Uses

type ControllerGauges struct {
    ModelConfigReads   prometheus.Gauge
    ModelHashCacheHit  prometheus.Gauge
    ModelHashCacheMiss prometheus.Gauge

    ApplicationConfigReads   prometheus.Gauge
    ApplicationHashCacheHit  prometheus.Gauge
    ApplicationHashCacheMiss prometheus.Gauge

    CharmConfigHashCacheHit  prometheus.Gauge
    CharmConfigHashCacheMiss prometheus.Gauge

    LXDProfileChangeError        prometheus.Gauge
    LXDProfileChangeNotification prometheus.Gauge
    LXDProfileNoChange           prometheus.Gauge
}

ControllerGauges holds the prometheus gauges for ever increasing values used by the controller.

func (*ControllerGauges) Collect Uses

func (c *ControllerGauges) Collect(ch chan<- prometheus.Metric)

Collect is part of the prometheus.Collector interface.

func (*ControllerGauges) Describe Uses

func (c *ControllerGauges) Describe(ch chan<- *prometheus.Desc)

Describe is part of the prometheus.Collector interface.

type Machine Uses

type Machine struct {
    // Resident identifies the machine as a type-agnostic cached entity
    // and tracks resources that it is responsible for cleaning up.
    *Resident
    // contains filtered or unexported fields
}

Machine represents a machine in a model.

func (*Machine) CharmProfiles Uses

func (m *Machine) CharmProfiles() []string

CharmProfiles returns the cached list of charm profiles for the machine.

func (*Machine) Config Uses

func (m *Machine) Config() map[string]interface{}

Config returns configuration settings for the machine.

func (*Machine) ContainerType Uses

func (m *Machine) ContainerType() instance.ContainerType

ContainerType returns the cached container type hosting this machine.

func (*Machine) Id Uses

func (m *Machine) Id() string

Id returns the id string of this machine.

func (*Machine) InstanceId Uses

func (m *Machine) InstanceId() (instance.Id, error)

InstanceId returns the provider specific instance id for this machine and returns not provisioned if instance ID is empty.

func (*Machine) Units Uses

func (m *Machine) Units() ([]Unit, error)

Units returns all the units that have been assigned to the machine including subordinates.

func (*Machine) WatchContainers Uses

func (m *Machine) WatchContainers() (*PredicateStringsWatcher, error)

WatchContainers creates a PredicateStringsWatcher (strings watcher) to notify about added and removed containers on this machine. The initial event contains a slice of the current container machine ids.

func (*Machine) WatchLXDProfileVerificationNeeded Uses

func (m *Machine) WatchLXDProfileVerificationNeeded() (*MachineLXDProfileWatcher, error)

WatchLXDProfileVerificationNeeded notifies if any of the following happen relative to this machine:

1. A new unit whose charm has an LXD profile is added.
2. A unit being removed has a profile and other units
   exist on the machine.
3. The LXD profile of an application with a unit on this
   machine is added, removed, or exists.
4. The machine's instanceId is changed, indicating it
   has been provisioned.

type MachineAppModeler Uses

type MachineAppModeler interface {
    Application(string) (Application, error)
    Charm(string) (Charm, error)
    Unit(string) (Unit, error)
}

MachineAppModeler is a point of use model for MachineLXDProfileWatcher to get Applications, Charms and Units.

type MachineChange Uses

type MachineChange struct {
    ModelUUID                string
    Id                       string
    InstanceId               string
    AgentStatus              status.StatusInfo
    InstanceStatus           status.StatusInfo
    Life                     life.Value
    Config                   map[string]interface{}
    Series                   string
    ContainerType            string
    SupportedContainers      []instance.ContainerType
    SupportedContainersKnown bool
    HardwareCharacteristics  *instance.HardwareCharacteristics
    CharmProfiles            []string
    Addresses                []network.ProviderAddress
    HasVote                  bool
    WantsVote                bool
}

MachineChange represents either a new machine, or a change to an existing machine in a model.

type MachineLXDProfileWatcher Uses

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

func (MachineLXDProfileWatcher) Changes Uses

func (w MachineLXDProfileWatcher) Changes() <-chan struct{}

Changes is part of the core watcher definition.

func (MachineLXDProfileWatcher) Kill Uses

func (w MachineLXDProfileWatcher) Kill()

Kill is part of the worker.Worker interface.

func (MachineLXDProfileWatcher) Stop Uses

func (w MachineLXDProfileWatcher) Stop() error

Stop is currently required by the Resources wrapper in the apiserver.

func (MachineLXDProfileWatcher) Wait Uses

func (w MachineLXDProfileWatcher) Wait() error

Wait is part of the worker.Worker interface.

type MachineLXDProfileWatcherConfig Uses

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

type Model Uses

type Model struct {
    // Resident identifies the model as a type-agnostic cached entity
    // and tracks resources that it is responsible for cleaning up.
    *Resident
    // contains filtered or unexported fields
}

Model is a cached model in the controller. The model is kept up to date with changes flowing into the cached controller.

func (*Model) Application Uses

func (m *Model) Application(appName string) (Application, error)

Application returns the application for the input name. If the application is not found, a NotFoundError is returned.

func (*Model) Branch Uses

func (m *Model) Branch(name string) (Branch, error)

Branch returns the branch with the input name. If the branch is not found, a NotFoundError is returned. All API-level logic identifies active branches by their name whereas they are managed in the cache by ID - we iterate over the map to locate them. We do not expect many active branches to exist at once, so the performance should be acceptable.

func (*Model) Branches Uses

func (m *Model) Branches() []Branch

Branches returns all active branches in the model.

func (*Model) Charm Uses

func (m *Model) Charm(charmURL string) (Charm, error)

Charm returns the charm for the input charmURL. If the charm is not found, a NotFoundError is returned.

func (*Model) Config Uses

func (m *Model) Config() map[string]interface{}

Config returns the current model config.

func (*Model) Machine Uses

func (m *Model) Machine(machineId string) (Machine, error)

Machine returns the machine with the input id. If the machine is not found, a NotFoundError is returned.

func (*Model) Machines Uses

func (m *Model) Machines() map[string]Machine

Machines makes a copy of the model's machine collection and returns it.

func (*Model) Metrics Uses

func (m *Model) Metrics() *ControllerGauges

Metrics returns the metrics of the model

func (*Model) Name Uses

func (m *Model) Name() string

Name returns the current model's name.

func (*Model) Report Uses

func (m *Model) Report() map[string]interface{}

Report returns information that is used in the dependency engine report.

func (*Model) UUID Uses

func (m *Model) UUID() string

UUID returns the model's model-uuid.

func (*Model) Unit Uses

func (m *Model) Unit(unitName string) (Unit, error)

Unit returns the unit with the input name. If the unit is not found, a NotFoundError is returned.

func (*Model) Units Uses

func (m *Model) Units() map[string]Unit

Units returns all units in the model.

func (*Model) WaitForUnit Uses

func (m *Model) WaitForUnit(name string, predicate func(*Unit) bool, cancel <-chan struct{}) <-chan struct{}

WaitForUnit is the second attempt at providing a genericish way to wait for the cache to be updated. The method subscribes to the hub with the topic "unit-change.<source>". The expected payload is a *Unit. The method effectively runs another goroutine that will close the result channel when the field is updated to the expected value, or the cancel channel is signalled. This method is not responsible for checking the current value, it only deals with changes.

func (*Model) WatchConfig Uses

func (m *Model) WatchConfig(keys ...string) *ConfigWatcher

WatchConfig creates a watcher for the model config.

func (*Model) WatchMachines Uses

func (m *Model) WatchMachines() (*PredicateStringsWatcher, error)

WatchMachines returns a PredicateStringsWatcher to notify about added and removed machines in the model. The initial event contains a slice of the current machine ids. Containers are excluded.

type ModelChange Uses

type ModelChange struct {
    ModelUUID string
    Name      string
    Life      life.Value
    Owner     string // tag maybe?
    Config    map[string]interface{}
    Status    status.StatusInfo
}

ModelChange represents either a new model, or a change to an existing model.

type ModelWatcher Uses

type ModelWatcher interface {
    Watcher
    Changes() <-chan *Model
}

ModelWatcher will pass back models added to the cache.

type NotifyWatcher Uses

type NotifyWatcher interface {
    Watcher
    Changes() <-chan struct{}
}

NotifyWatcher will only say something changed.

type PredicateStringsWatcher Uses

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

PredicateStringsWatcher notifies that something changed, with a slice of strings. The predicateFunc will test the values before notification. An initial event is sent with the input given at creation.

func (PredicateStringsWatcher) Changes Uses

func (w PredicateStringsWatcher) Changes() <-chan []string

Changes is part of the core watcher definition. The changes channel is never closed.

func (PredicateStringsWatcher) Err Uses

func (w PredicateStringsWatcher) Err() error

Err returns the inner tomb's error.

func (PredicateStringsWatcher) Kill Uses

func (w PredicateStringsWatcher) Kill()

Kill is part of the worker.Worker interface.

func (PredicateStringsWatcher) Stop Uses

func (w PredicateStringsWatcher) Stop() error

Stop is currently required by the Resources wrapper in the apiserver.

func (PredicateStringsWatcher) Wait Uses

func (w PredicateStringsWatcher) Wait() error

Wait is part of the worker.Worker interface.

type RemoveApplication Uses

type RemoveApplication struct {
    ModelUUID string
    Name      string
}

RemoveApplication represents the situation when an application is removed from a model in the database.

type RemoveBranch Uses

type RemoveBranch struct {
    ModelUUID string
    Id        string
}

RemoveBranch represents the situation when a branch is to be removed from the cache. This will rarely be a result of deletion from the database. It will usually be the result of the branch no longer being considered "in-flight" due to being committed or aborted.

type RemoveCharm Uses

type RemoveCharm struct {
    ModelUUID string
    CharmURL  string
}

RemoveCharm represents the situation when an charm is removed from a model in the database.

type RemoveMachine Uses

type RemoveMachine struct {
    ModelUUID string
    Id        string
}

RemoveMachine represents the situation when a machine is removed from a model in the database.

type RemoveModel Uses

type RemoveModel struct {
    ModelUUID string
}

RemoveModel represents the situation when a model is removed from the database.

type RemoveUnit Uses

type RemoveUnit struct {
    ModelUUID string
    Name      string
}

RemoveUnit represents the situation when a unit is removed from a model in the database.

type Resident Uses

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

Resident is the base class for entities managed in the cache.

func (*Resident) CacheId Uses

func (r *Resident) CacheId() uint64

CacheId returns the unique ID for this cache resident.

type StringsWatcher Uses

type StringsWatcher interface {
    Watcher
    Changes() <-chan []string
}

StringsWatcher will return what has changed.

type Unit Uses

type Unit struct {
    // Resident identifies the unit as a type-agnostic cached entity
    // and tracks resources that it is responsible for cleaning up.
    *Resident
    // contains filtered or unexported fields
}

Unit represents a unit in a cached model.

func (*Unit) Application Uses

func (u *Unit) Application() string

Application returns the application name of this unit.

func (*Unit) CharmURL Uses

func (u *Unit) CharmURL() string

CharmURL returns the charm URL for this unit's application.

func (*Unit) ConfigSettings Uses

func (u *Unit) ConfigSettings() (charm.Settings, error)

Config settings returns the effective charm configuration for this unit taking into account whether it is tracking a model branch.

func (*Unit) Life Uses

func (u *Unit) Life() life.Value

Life returns the current life of the unit.

func (*Unit) MachineId Uses

func (u *Unit) MachineId() string

MachineId returns the ID of the machine hosting this unit.

func (*Unit) Name Uses

func (u *Unit) Name() string

Name returns the name of this unit.

func (*Unit) Ports Uses

func (u *Unit) Ports() []network.Port

Ports returns the exposed ports for the unit.

func (*Unit) Principal Uses

func (u *Unit) Principal() string

Principal returns the name of the principal unit for the same application.

func (*Unit) Subordinate Uses

func (u *Unit) Subordinate() bool

Subordinate returns a bool indicating whether this unit is a subordinate.

func (*Unit) WatchConfigSettings Uses

func (u *Unit) WatchConfigSettings() (*CharmConfigWatcher, error)

WatchConfigSettings returns a new watcher that will notify when the effective application charm config for this unit changes.

type UnitChange Uses

type UnitChange struct {
    ModelUUID      string
    Name           string
    Application    string
    Series         string
    CharmURL       string
    Life           life.Value
    PublicAddress  string
    PrivateAddress string
    MachineId      string
    Ports          []network.Port
    PortRanges     []network.PortRange
    Principal      string
    Subordinate    bool
    WorkloadStatus status.StatusInfo
    AgentStatus    status.StatusInfo
}

UnitChange represents either a new unit, or a change to an existing unit in a model.

type Watcher Uses

type Watcher interface {
    worker.Worker
    // Stop is currently needed by the apiserver until the resources
    // work on workers instead of things that can be stopped.
    Stop() error
}

Watcher is the common methods

Directories

PathSynopsis
cachetest

Package cache imports 26 packages (graph) and is imported by 34 packages. Updated 2019-12-08. Refresh now. Tools for package owners.