state

package
v0.0.0-...-65247a5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 21, 2014 License: AGPL-3.0 Imports: 34 Imported by: 0

Documentation

Overview

The state package enables reading, observing, and changing the state stored in MongoDB of a whole environment managed by juju.

Index

Constants

View Source
const (
	ItemAdded = iota
	ItemModified
	ItemDeleted
)
View Source
const BootstrapNonce = "user-admin:bootstrap"

BootstrapNonce is used as a nonce for the state server machine.

Variables

View Source
var ErrCannotEnterScope = stderrors.New("cannot enter scope: unit or relation is not alive")

ErrCannotEnterScope indicates that a relation unit failed to enter its scope due to either the unit or the relation not being Alive.

View Source
var ErrCannotEnterScopeYet = stderrors.New("cannot enter scope yet: non-alive subordinate unit has not been removed")

ErrCannotEnterScopeYet indicates that a relation unit failed to enter its scope due to a required and pre-existing subordinate unit that is not Alive. Once that subordinate has been removed, a new one can be created.

View Source
var ErrCharmRevisionAlreadyModified = fmt.Errorf("charm revision already modified")

ErrCharmRevisionAlreadyModified is returned when a pending or placeholder charm is no longer pending or a placeholder, signaling the charm is available in state with its full information.

View Source
var ErrExcessiveContention = stderrors.New("state changing too quickly; try again soon")
View Source
var ErrStateClosed = fmt.Errorf("state has been closed")

ErrStateClosed is returned from watchers if their underlying state connection has been closed.

View Source
var ErrSubordinateConstraints = stderrors.New("constraints do not apply to subordinate services")
View Source
var ErrUnitHasSubordinates = stderrors.New("unit has subordinates")

Functions

func ContainerTypeFromId

func ContainerTypeFromId(machineId string) instance.ContainerType

ContainerTypeFromId returns the container type if machineId is a container id, or "" if machineId is not for a container.

func IsCharmAlreadyUploadedError

func IsCharmAlreadyUploadedError(err interface{}) bool

IsCharmAlreadyUploadedError returns if the given error is ErrCharmAlreadyUploaded.

func IsHasAssignedUnitsError

func IsHasAssignedUnitsError(err error) bool

func IsHasContainersError

func IsHasContainersError(err error) bool

func IsNotAssigned

func IsNotAssigned(err error) bool

func IsNotProvisionedError

func IsNotProvisionedError(err error) bool

IsNotProvisionedError returns true if err is a notProvisionedError.

func IsVersionInconsistentError

func IsVersionInconsistentError(e interface{}) bool

IsVersionInconsistentError returns if the given error is versionInconsistentError.

func NestingLevel

func NestingLevel(machineId string) int

NestingLevel returns how many levels of nesting exist for a machine id.

func NotProvisionedError

func NotProvisionedError(machineId string) error

func ParentId

func ParentId(machineId string) string

ParentId returns the id of the host machine if machineId a container id, or "" if machineId is not for a container.

func TopParentId

func TopParentId(machineId string) string

TopParentId returns the id of the top level host machine for a container id.

Types

type AgentEntity

AgentEntity represents an entity that can have an agent responsible for it.

type AgentLiving

type AgentLiving interface {
	Living
	EnsureDead() error
	Remove() error
}

AgentLiving describes state entities with a lifecycle and an agent that manages it.

type AgentTooler

type AgentTooler interface {
	AgentTools() (*tools.Tools, error)
	SetAgentVersion(version.Binary) error
}

AgentTooler is implemented by entities that have associated agent tools.

type Annotator

type Annotator interface {
	Annotation(key string) (string, error)
	Annotations() (map[string]string, error)
	SetAnnotations(pairs map[string]string) error
}

Annotator represents entities capable of handling annotations.

type AssignmentPolicy

type AssignmentPolicy string

AssignmentPolicy controls what machine a unit will be assigned to.

const (
	// AssignLocal indicates that all service units should be assigned
	// to machine 0.
	AssignLocal AssignmentPolicy = "local"

	// AssignClean indicates that every service unit should be assigned
	// to a machine which never previously has hosted any units, and that
	// new machines should be launched if required.
	AssignClean AssignmentPolicy = "clean"

	// AssignCleanEmpty indicates that every service unit should be assigned
	// to a machine which never previously has hosted any units, and which is not
	// currently hosting any containers, and that new machines should be launched if required.
	AssignCleanEmpty AssignmentPolicy = "clean-empty"

	// AssignNew indicates that every service unit should be assigned to a new
	// dedicated machine.  A new machine will be launched for each new unit.
	AssignNew AssignmentPolicy = "new"
)

type Authenticator

type Authenticator interface {
	Refresh() error
	SetPassword(pass string) error
	PasswordValid(pass string) bool
}

Authenticator represents entites capable of handling password authentication.

type Charm

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

Charm represents the state of a charm in the environment.

func (*Charm) BundleSha256

func (c *Charm) BundleSha256() string

BundleSha256 returns the SHA256 digest of the charm bundle bytes.

func (*Charm) BundleURL

func (c *Charm) BundleURL() *url.URL

BundleURL returns the url to the charm bundle in the provider storage.

func (*Charm) Config

func (c *Charm) Config() *charm.Config

Config returns the configuration of the charm.

func (*Charm) IsPlaceholder

func (c *Charm) IsPlaceholder() bool

IsPlaceholder returns whether the charm record is just a placeholder rather than representing a deployed charm.

func (*Charm) IsUploaded

func (c *Charm) IsUploaded() bool

IsUploaded returns whether the charm has been uploaded to the provider storage.

func (*Charm) Meta

func (c *Charm) Meta() *charm.Meta

Meta returns the metadata of the charm.

func (*Charm) Revision

func (c *Charm) Revision() int

Revision returns the monotonically increasing charm revision number.

func (*Charm) String

func (c *Charm) String() string

func (*Charm) URL

func (c *Charm) URL() *charm.URL

URL returns the URL that identifies the charm.

type D

type D []bson.DocElem

TODO(niemeyer): This must not be exported.

type DeployerConnectionValues

type DeployerConnectionValues struct {
	StateAddresses []string
	APIAddresses   []string
}

type DialOpts

type DialOpts struct {
	// Timeout is the amount of time to wait contacting
	// a state server.
	Timeout time.Duration
}

DialOpts holds configuration parameters that control the Dialing behavior when connecting to a state server.

func DefaultDialOpts

func DefaultDialOpts() DialOpts

DefaultDialOpts returns a DialOpts representing the default parameters for contacting a state server.

type Endpoint

type Endpoint struct {
	ServiceName string
	charm.Relation
}

Endpoint represents one endpoint of a relation.

func (Endpoint) CanRelateTo

func (ep Endpoint) CanRelateTo(other Endpoint) bool

CanRelateTo returns whether a relation may be established between e and other.

func (Endpoint) String

func (ep Endpoint) String() string

String returns the unique identifier of the relation endpoint.

type EnsureDeader

type EnsureDeader interface {
	EnsureDead() error
}

EnsureDeader with an EnsureDead method.

type Entity

type Entity interface {
	Tag() string
}

Entity represents any entity that can be returned by State.FindEntity. All entities have a tag.

type EntityFinder

type EntityFinder interface {
	FindEntity(tag string) (Entity, error)
}

EntityFinder is implemented by *State. See State.FindEntity for documentation on the method.

type EnvironAccessor

type EnvironAccessor interface {
	WatchForEnvironConfigChanges() NotifyWatcher
	EnvironConfig() (*config.Config, error)
}

EnvironAccessor defines the methods needed to watch for environment config changes, and read the environment config.

type EnvironConfigWatcher

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

EnvironConfigWatcher observes changes to the environment configuration.

func (*EnvironConfigWatcher) Changes

func (w *EnvironConfigWatcher) Changes() <-chan *config.Config

Changes returns a channel that will receive the new environment configuration when a change is detected. Note that multiple changes may be observed as a single event in the channel.

func (*EnvironConfigWatcher) Err

func (w *EnvironConfigWatcher) Err() error

Err returns any error encountered while running or shutting down, or tomb.ErrStillAlive if the watcher is still running.

func (*EnvironConfigWatcher) Kill

func (w *EnvironConfigWatcher) Kill()

Kill kills the watcher without waiting for it to shut down.

func (*EnvironConfigWatcher) Stop

func (w *EnvironConfigWatcher) Stop() error

Stop stops the watcher, and returns any error encountered while running or shutting down.

func (*EnvironConfigWatcher) Wait

func (w *EnvironConfigWatcher) Wait() error

Wait waits for the watcher to die and returns any error encountered when it was running.

type EnvironMachinesWatcher

type EnvironMachinesWatcher interface {
	WatchEnvironMachines() StringsWatcher
}

EnvironMachinesWatcher defines a single method - WatchEnvironMachines.

type Environment

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

Environment represents the state of an environment.

func (*Environment) Annotation

func (a *Environment) Annotation(key string) (string, error)

Annotation returns the annotation value corresponding to the given key. If the requested annotation is not found, an empty string is returned.

func (*Environment) Annotations

func (a *Environment) Annotations() (map[string]string, error)

Annotations returns all the annotations corresponding to an entity.

func (*Environment) Destroy

func (e *Environment) Destroy() error

Destroy sets the environment's lifecycle to Dying, preventing addition of services or machines to state.

func (*Environment) Life

func (e *Environment) Life() Life

Life returns whether the environment is Alive, Dying or Dead.

func (*Environment) Name

func (e *Environment) Name() string

Name returns the human friendly name of the environment.

func (*Environment) Refresh

func (e *Environment) Refresh() error

func (*Environment) SetAnnotations

func (a *Environment) SetAnnotations(pairs map[string]string) (err error)

SetAnnotations adds key/value pairs to annotations in MongoDB.

func (*Environment) Tag

func (e *Environment) Tag() string

Tag returns a name identifying the environment. The returned name will be different from other Tag values returned by any other entities from the same state.

func (*Environment) UUID

func (e *Environment) UUID() string

UUID returns the universally unique identifier of the environment.

func (*Environment) Watch

func (e *Environment) Watch() NotifyWatcher

Watch returns a watcher for observing changes to an environment.

type ErrCharmAlreadyUploaded

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

ErrCharmAlreadyUploaded is returned by UpdateUploadedCharm() when the given charm is already uploaded and marked as not pending in state.

func (*ErrCharmAlreadyUploaded) Error

func (e *ErrCharmAlreadyUploaded) Error() string

type HasAssignedUnitsError

type HasAssignedUnitsError struct {
	MachineId string
	UnitNames []string
}

func (*HasAssignedUnitsError) Error

func (e *HasAssignedUnitsError) Error() string

type HasContainersError

type HasContainersError struct {
	MachineId    string
	ContainerIds []string
}

func (*HasContainersError) Error

func (e *HasContainersError) Error() string

type Info

type Info struct {
	// Addrs gives the addresses of the MongoDB servers for the state.
	// Each address should be in the form address:port.
	Addrs []string

	// CACert holds the CA certificate that will be used
	// to validate the state server's certificate, in PEM format.
	CACert []byte

	// Tag holds the name of the entity that is connecting.
	// It should be empty when connecting as an administrator.
	Tag string

	// Password holds the password for the connecting entity.
	Password string
}

Info encapsulates information about cluster of servers holding juju state and can be used to make a connection to that cluster.

type InstanceIdGetter

type InstanceIdGetter interface {
	InstanceId() (instance.Id, error)
}

InstanceIdGetter defines a single method - InstanceId.

type ItemChange

type ItemChange struct {
	Type     int
	Key      string
	OldValue interface{}
	NewValue interface{}
}

ItemChange represents the change of an item in a settings.

func (*ItemChange) String

func (ic *ItemChange) String() string

String returns the item change in a readable format.

type Life

type Life int8

Life represents the lifecycle state of the entities Relation, Unit, Service and Machine.

const (
	Alive Life = iota
	Dying
	Dead
)

func (Life) String

func (l Life) String() string

type Lifer

type Lifer interface {
	Life() Life
}

Lifer represents an entity with a life.

type Living

type Living interface {
	Life() Life
	Destroy() error
	Refresh() error
}

Living describes state entities with a lifecycle.

type Machine

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

Machine represents the state of a machine.

func (*Machine) Addresses

func (m *Machine) Addresses() (addresses []instance.Address)

Addresses returns any hostnames and ips associated with a machine, determined both by the machine itself, and by asking the provider.

The addresses returned by the provider shadow any of the addresses that the machine reported with the same address value.

func (*Machine) AgentAlive

func (m *Machine) AgentAlive() (bool, error)

AgentAlive returns whether the respective remote agent is alive.

func (*Machine) AgentTools

func (m *Machine) AgentTools() (*tools.Tools, error)

AgentTools returns the tools that the agent is currently running. It returns an error that satisfies IsNotFound if the tools have not yet been set.

func (*Machine) Annotation

func (a *Machine) Annotation(key string) (string, error)

Annotation returns the annotation value corresponding to the given key. If the requested annotation is not found, an empty string is returned.

func (*Machine) Annotations

func (a *Machine) Annotations() (map[string]string, error)

Annotations returns all the annotations corresponding to an entity.

func (*Machine) CheckProvisioned

func (m *Machine) CheckProvisioned(nonce string) bool

CheckProvisioned returns true if the machine was provisioned with the given nonce.

func (*Machine) Clean

func (m *Machine) Clean() bool

Clean returns true if the machine does not have any deployed units or containers.

func (*Machine) Constraints

func (m *Machine) Constraints() (constraints.Value, error)

Constraints returns the exact constraints that should apply when provisioning an instance for the machine.

func (*Machine) ContainerType

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

ContainerType returns the type of container hosting this machine.

func (*Machine) Containers

func (m *Machine) Containers() ([]string, error)

Containers returns the container ids belonging to a parent machine. TODO(wallyworld): move this method to a service

func (*Machine) Destroy

func (m *Machine) Destroy() error

Destroy sets the machine lifecycle to Dying if it is Alive. It does nothing otherwise. Destroy will fail if the machine has principal units assigned, or if the machine has JobManageEnviron. If the machine has assigned units, Destroy will return a HasAssignedUnitsError.

func (*Machine) EnsureDead

func (m *Machine) EnsureDead() error

EnsureDead sets the machine lifecycle to Dead if it is Alive or Dying. It does nothing otherwise. EnsureDead will fail if the machine has principal units assigned, or if the machine has JobManageEnviron. If the machine has assigned units, EnsureDead will return a HasAssignedUnitsError.

func (*Machine) ForceDestroy

func (m *Machine) ForceDestroy() error

ForceDestroy queues the machine for complete removal, including the destruction of all units and containers on the machine.

func (*Machine) HardwareCharacteristics

func (m *Machine) HardwareCharacteristics() (*instance.HardwareCharacteristics, error)

TODO(wallyworld): move this method to a service.

func (*Machine) HasVote

func (m *Machine) HasVote() bool

HasVote reports whether that machine is currently a voting member of the replica set.

func (*Machine) Id

func (m *Machine) Id() string

Id returns the machine id.

func (*Machine) InstanceId

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

InstanceId returns the provider specific instance id for this machine, or a NotProvisionedError, if not set.

func (*Machine) InstanceStatus

func (m *Machine) InstanceStatus() (string, error)

InstanceStatus returns the provider specific instance status for this machine, or a NotProvisionedError if instance is not yet provisioned.

func (*Machine) IsManager

func (m *Machine) IsManager() bool

IsManager returns true if the machine has JobManageEnviron.

func (*Machine) IsManual

func (m *Machine) IsManual() (bool, error)

IsManual returns true if the machine was manually provisioned.

func (*Machine) Jobs

func (m *Machine) Jobs() []MachineJob

Jobs returns the responsibilities that must be fulfilled by m's agent.

func (*Machine) Life

func (m *Machine) Life() Life

Life returns whether the machine is Alive, Dying or Dead.

func (*Machine) MachineAddresses

func (m *Machine) MachineAddresses() (addresses []instance.Address)

MachineAddresses returns any hostnames and ips associated with a machine, determined by asking the machine itself.

func (*Machine) ParentId

func (m *Machine) ParentId() (string, bool)

ParentId returns the Id of the host machine if this machine is a container.

func (*Machine) PasswordValid

func (m *Machine) PasswordValid(password string) bool

PasswordValid returns whether the given password is valid for the given machine.

func (*Machine) Refresh

func (m *Machine) Refresh() error

Refresh refreshes the contents of the machine from the underlying state. It returns an error that satisfies IsNotFound if the machine has been removed.

func (*Machine) Remove

func (m *Machine) Remove() (err error)

Remove removes the machine from state. It will fail if the machine is not Dead.

func (*Machine) Series

func (m *Machine) Series() string

Series returns the operating system series running on the machine.

func (*Machine) SetAddresses

func (m *Machine) SetAddresses(addresses []instance.Address) (err error)

SetAddresses records any addresses related to the machine, sourced by asking the provider.

func (*Machine) SetAgentAlive

func (m *Machine) SetAgentAlive() (*presence.Pinger, error)

SetAgentAlive signals that the agent for machine m is alive. It returns the started pinger.

func (*Machine) SetAgentVersion

func (m *Machine) SetAgentVersion(v version.Binary) (err error)

SetAgentVersion sets the version of juju that the agent is currently running.

func (*Machine) SetAnnotations

func (a *Machine) SetAnnotations(pairs map[string]string) (err error)

SetAnnotations adds key/value pairs to annotations in MongoDB.

func (*Machine) SetConstraints

func (m *Machine) SetConstraints(cons constraints.Value) (err error)

SetConstraints sets the exact constraints to apply when provisioning an instance for the machine. It will fail if the machine is Dead, or if it is already provisioned.

func (*Machine) SetHasVote

func (m *Machine) SetHasVote(hasVote bool) error

SetHasVote sets whether the machine is currently a voting member of the replica set. It should only be called from the worker that maintains the replica set.

func (*Machine) SetInstanceStatus

func (m *Machine) SetInstanceStatus(status string) (err error)

SetInstanceStatus sets the provider specific instance status for a machine.

func (*Machine) SetMachineAddresses

func (m *Machine) SetMachineAddresses(addresses []instance.Address) (err error)

SetMachineAddresses records any addresses related to the machine, sourced by asking the machine.

func (*Machine) SetMongoPassword

func (m *Machine) SetMongoPassword(password string) error

SetMongoPassword sets the password the agent responsible for the machine should use to communicate with the state servers. Previous passwords are invalidated.

func (*Machine) SetPassword

func (m *Machine) SetPassword(password string) error

SetPassword sets the password for the machine's agent.

func (*Machine) SetProvisioned

func (m *Machine) SetProvisioned(id instance.Id, nonce string, characteristics *instance.HardwareCharacteristics) (err error)

SetProvisioned sets the provider specific machine id, nonce and also metadata for this machine. Once set, the instance id cannot be changed.

When provisioning an instance, a nonce should be created and passed when starting it, before adding the machine to the state. This means that if the provisioner crashes (or its connection to the state is lost) after starting the instance, we can be sure that only a single instance will be able to act for that machine.

func (*Machine) SetStatus

func (m *Machine) SetStatus(status params.Status, info string, data params.StatusData) error

SetStatus sets the status of the machine.

func (*Machine) SetSupportedContainers

func (m *Machine) SetSupportedContainers(containers []instance.ContainerType) (err error)

SetSupportedContainers sets the list of containers supported by this machine.

func (*Machine) Status

func (m *Machine) Status() (status params.Status, info string, data params.StatusData, err error)

Status returns the status of the machine.

func (*Machine) String

func (m *Machine) String() string

String returns a unique description of this machine.

func (*Machine) SupportedContainers

func (m *Machine) SupportedContainers() ([]instance.ContainerType, bool)

SupportedContainers returns any containers this machine is capable of hosting, and a bool indicating if the supported containers have been determined or not.

func (*Machine) SupportsNoContainers

func (m *Machine) SupportsNoContainers() (err error)

SupportsNoContainers records the fact that this machine doesn't support any containers.

func (*Machine) Tag

func (m *Machine) Tag() string

Tag returns a name identifying the machine that is safe to use as a file name. The returned name will be different from other Tag values returned by any other entities from the same state.

func (*Machine) Units

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

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

func (*Machine) WaitAgentAlive

func (m *Machine) WaitAgentAlive(timeout time.Duration) (err error)

WaitAgentAlive blocks until the respective agent is alive.

func (*Machine) WantsVote

func (m *Machine) WantsVote() bool

WantsVote reports whether the machine is a state server that wants to take part in peer voting.

func (*Machine) Watch

func (m *Machine) Watch() NotifyWatcher

Watch returns a watcher for observing changes to a machine.

func (*Machine) WatchAllContainers

func (m *Machine) WatchAllContainers() StringsWatcher

WatchAllContainers returns a StringsWatcher that notifies of changes to the lifecycles of all containers on a machine.

func (*Machine) WatchContainers

func (m *Machine) WatchContainers(ctype instance.ContainerType) StringsWatcher

WatchContainers returns a StringsWatcher that notifies of changes to the lifecycles of containers of the specified type on a machine.

func (*Machine) WatchHardwareCharacteristics

func (m *Machine) WatchHardwareCharacteristics() NotifyWatcher

WatchHardwareCharacteristics returns a watcher for observing changes to a machine's hardware characteristics.

func (*Machine) WatchPrincipalUnits

func (m *Machine) WatchPrincipalUnits() StringsWatcher

WatchPrincipalUnits returns a StringsWatcher tracking the machine's principal units.

func (*Machine) WatchUnits

func (m *Machine) WatchUnits() StringsWatcher

WatchUnits returns a new StringsWatcher watching m's units.

type MachineJob

type MachineJob int

MachineJob values define responsibilities that machines may be expected to fulfil.

const (
	JobHostUnits MachineJob
	JobManageEnviron

	// Deprecated in 1.18.
	JobManageStateDeprecated
)

func AllJobs

func AllJobs() []MachineJob

AllJobs returns all supported machine jobs.

func MachineJobFromParams

func MachineJobFromParams(job params.MachineJob) (MachineJob, error)

MachineJobFromParams returns the job corresponding to params.MachineJob.

func (MachineJob) String

func (job MachineJob) String() string

func (MachineJob) ToParams

func (job MachineJob) ToParams() params.MachineJob

ToParams returns the job as params.MachineJob.

type MachineTemplate

type MachineTemplate struct {
	// Series is the series to be associated with the new machine.
	Series string

	// Constraints are the constraints to be used when finding
	// an instance for the machine.
	Constraints constraints.Value

	// Jobs holds the jobs to run on the machine's instance.
	// A machine must have at least one job to do.
	// JobManageEnviron can only be part of the jobs
	// when the first (bootstrap) machine is added.
	Jobs []MachineJob

	// NoVote holds whether a machine running
	// a state server should abstain from peer voting.
	// It is ignored if Jobs does not contain JobManageEnviron.
	NoVote bool

	// Addresses holds the addresses to be associated with the
	// new machine.
	Addresses []instance.Address

	// InstanceId holds the instance id to associate with the machine.
	// If this is empty, the provisioner will try to provision the machine.
	// If this is non-empty, the HardwareCharacteristics and Nonce
	// fields must be set appropriately.
	InstanceId instance.Id

	// HardwareCharacteristics holds the h/w characteristics to
	// be associated with the machine.
	HardwareCharacteristics instance.HardwareCharacteristics

	// Nonce holds a unique value that can be used to check
	// if a new instance was really started for this machine.
	// See Machine.SetProvisioned. This must be set if InstanceId is set.
	Nonce string

	// Dirty signifies whether the new machine will be treated
	// as unclean for unit-assignment purposes.
	Dirty bool
	// contains filtered or unexported fields
}

MachineTemplate holds attributes that are to be associated with a newly created machine.

type MongoPassworder

type MongoPassworder interface {
	SetMongoPassword(password string) error
}

MongoPassworder represents an entity that can have a mongo password set for it.

type NotAssignedError

type NotAssignedError struct{ Unit *Unit }

NotAssignedError indicates that a unit is not assigned to a machine (and, in the case of subordinate units, that the unit's principal is not assigned).

func (*NotAssignedError) Error

func (e *NotAssignedError) Error() string

type NotifyWatcher

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

NotifyWatcher generates signals when something changes, but it does not return any content for those changes

type NotifyWatcherFactory

type NotifyWatcherFactory interface {
	Watch() NotifyWatcher
}

NotifyWatcherFactory represents an entity that can be watched.

type Policy

type Policy interface {
	// Prechecker takes a *config.Config and returns
	// a (possibly nil) Prechecker or an error.
	Prechecker(*config.Config) (Prechecker, error)
}

Policy is an interface provided to State that may be consulted by State to validate or modify the behaviour of certain operations.

If a Policy implementation does not implement one of the methods, it must return an error that satisfies errors.IsNotImplemented, and will thus be ignored. Any other error will cause an error in the use of the policy.

type Prechecker

type Prechecker interface {
	// PrecheckInstance performs a preflight check on the specified
	// series and constraints, ensuring that they are possibly valid for
	// creating an instance in this environment.
	//
	// PrecheckInstance is best effort, and not guaranteed to eliminate
	// all invalid parameters. If PrecheckInstance returns nil, it is not
	// guaranteed that the constraints are valid; if a non-nil error is
	// returned, then the constraints are definitely invalid.
	PrecheckInstance(series string, cons constraints.Value) error
}

Prechecker is a policy interface that is provided to State to perform pre-flight checking of instance creation.

type Relation

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

Relation represents a relation between one or two service endpoints.

func (*Relation) Destroy

func (r *Relation) Destroy() (err error)

Destroy ensures that the relation will be removed at some point; if no units are currently in scope, it will be removed immediately.

func (*Relation) Endpoint

func (r *Relation) Endpoint(serviceName string) (Endpoint, error)

Endpoint returns the endpoint of the relation for the named service. If the service is not part of the relation, an error will be returned.

func (*Relation) Id

func (r *Relation) Id() int

Id returns the integer internal relation key. This is exposed because the unit agent needs to expose a value derived from this (as JUJU_RELATION_ID) to allow relation hooks to differentiate between relations with different services.

func (*Relation) Life

func (r *Relation) Life() Life

Life returns the relation's current life state.

func (*Relation) Refresh

func (r *Relation) Refresh() error

Refresh refreshes the contents of the relation from the underlying state. It returns an error that satisfies IsNotFound if the relation has been removed.

func (*Relation) RelatedEndpoints

func (r *Relation) RelatedEndpoints(serviceName string) ([]Endpoint, error)

RelatedEndpoints returns the endpoints of the relation r with which units of the named service will establish relations. If the service is not part of the relation r, an error will be returned.

func (*Relation) String

func (r *Relation) String() string

func (*Relation) Tag

func (r *Relation) Tag() string

Tag returns a name identifying the relation that is safe to use as a file name.

func (*Relation) Unit

func (r *Relation) Unit(u *Unit) (*RelationUnit, error)

Unit returns a RelationUnit for the supplied unit.

type RelationScopeChange

type RelationScopeChange struct {
	Entered []string
	Left    []string
}

RelationScopeChange contains information about units that have entered or left a particular scope.

type RelationScopeWatcher

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

RelationScopeWatcher observes changes to the set of units in a particular relation scope.

func (*RelationScopeWatcher) Changes

func (w *RelationScopeWatcher) Changes() <-chan *RelationScopeChange

Changes returns a channel that will receive changes when units enter and leave a relation scope. The Entered field in the first event on the channel holds the initial state.

func (*RelationScopeWatcher) Err

func (w *RelationScopeWatcher) Err() error

Err returns any error encountered while running or shutting down, or tomb.ErrStillAlive if the watcher is still running.

func (*RelationScopeWatcher) Kill

func (w *RelationScopeWatcher) Kill()

Kill kills the watcher without waiting for it to shut down.

func (*RelationScopeWatcher) Stop

func (w *RelationScopeWatcher) Stop() error

Stop stops the watcher, and returns any error encountered while running or shutting down.

func (*RelationScopeWatcher) Wait

func (w *RelationScopeWatcher) Wait() error

Wait waits for the watcher to die and returns any error encountered when it was running.

type RelationUnit

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

RelationUnit holds information about a single unit in a relation, and allows clients to conveniently access unit-specific functionality.

func (*RelationUnit) Endpoint

func (ru *RelationUnit) Endpoint() Endpoint

Endpoint returns the relation endpoint that defines the unit's participation in the relation.

func (*RelationUnit) EnterScope

func (ru *RelationUnit) EnterScope(settings map[string]interface{}) error

EnterScope ensures that the unit has entered its scope in the relation. When the unit has already entered its relation scope, EnterScope will report success but make no changes to state.

Otherwise, assuming both the relation and the unit are alive, it will enter scope and create or overwrite the unit's settings in the relation according to the supplied map.

If the unit is a principal and the relation has container scope, EnterScope will also create the required subordinate unit, if it does not already exist; this is because there's no point having a principal in scope if there is no corresponding subordinate to join it.

Once a unit has entered a scope, it stays in scope without further intervention; the relation will not be able to become Dead until all units have departed its scopes.

func (*RelationUnit) InScope

func (ru *RelationUnit) InScope() (bool, error)

InScope returns whether the relation unit has entered scope or not.

func (*RelationUnit) LeaveScope

func (ru *RelationUnit) LeaveScope() error

LeaveScope signals that the unit has left its scope in the relation. After the unit has left its relation scope, it is no longer a member of the relation; if the relation is dying when its last member unit leaves, it is removed immediately. It is not an error to leave a scope that the unit is not, or never was, a member of.

func (*RelationUnit) PrivateAddress

func (ru *RelationUnit) PrivateAddress() (string, bool)

PrivateAddress returns the private address of the unit and whether it is valid.

func (*RelationUnit) ReadSettings

func (ru *RelationUnit) ReadSettings(uname string) (m map[string]interface{}, err error)

ReadSettings returns a map holding the settings of the unit with the supplied name within this relation. An error will be returned if the relation no longer exists, or if the unit's service is not part of the relation, or the settings are invalid; but mere non-existence of the unit is not grounds for an error, because the unit settings are guaranteed to persist for the lifetime of the relation, regardless of the lifetime of the unit.

func (*RelationUnit) Relation

func (ru *RelationUnit) Relation() *Relation

Relation returns the relation associated with the unit.

func (*RelationUnit) Settings

func (ru *RelationUnit) Settings() (*Settings, error)

Settings returns a Settings which allows access to the unit's settings within the relation.

func (*RelationUnit) Watch

func (ru *RelationUnit) Watch() RelationUnitsWatcher

Watch returns a watcher that notifies of changes to conterpart units in the relation.

func (*RelationUnit) WatchScope

func (ru *RelationUnit) WatchScope() *RelationScopeWatcher

WatchScope returns a watcher which notifies of counterpart units entering and leaving the unit's scope.

type RelationUnitsWatcher

type RelationUnitsWatcher interface {
	Watcher
	Changes() <-chan params.RelationUnitsChange
}

RelationUnitsWatcher generates signals when units enter or leave the scope of a RelationUnit, and changes to the settings of those units known to have entered.

type Remover

type Remover interface {
	Remove() error
}

Remover represents entities with a Remove method.

type ResolvedMode

type ResolvedMode string

ResolvedMode describes the way state transition errors are resolved.

const (
	ResolvedNone       ResolvedMode = ""
	ResolvedRetryHooks ResolvedMode = "retry-hooks"
	ResolvedNoHooks    ResolvedMode = "no-hooks"
)

type Service

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

Service represents the state of a service.

func (*Service) AddUnit

func (s *Service) AddUnit() (unit *Unit, err error)

AddUnit adds a new principal unit to the service.

func (*Service) AllUnits

func (s *Service) AllUnits() (units []*Unit, err error)

AllUnits returns all units of the service.

func (*Service) Annotation

func (a *Service) Annotation(key string) (string, error)

Annotation returns the annotation value corresponding to the given key. If the requested annotation is not found, an empty string is returned.

func (*Service) Annotations

func (a *Service) Annotations() (map[string]string, error)

Annotations returns all the annotations corresponding to an entity.

func (*Service) Charm

func (s *Service) Charm() (ch *Charm, force bool, err error)

Charm returns the service's charm and whether units should upgrade to that charm even if they are in an error state.

func (*Service) CharmURL

func (s *Service) CharmURL() (curl *charm.URL, force bool)

CharmURL returns the service's charm URL, and whether units should upgrade to the charm with that URL even if they are in an error state.

func (*Service) ClearExposed

func (s *Service) ClearExposed() error

ClearExposed removes the exposed flag from the service. See SetExposed and IsExposed.

func (*Service) ConfigSettings

func (s *Service) ConfigSettings() (charm.Settings, error)

ConfigSettings returns the raw user configuration for the service's charm. Unset values are omitted.

func (*Service) Constraints

func (s *Service) Constraints() (constraints.Value, error)

Constraints returns the current service constraints.

func (*Service) Destroy

func (s *Service) Destroy() (err error)

Destroy ensures that the service and all its relations will be removed at some point; if the service has no units, and no relation involving the service has any units in scope, they are all removed immediately.

func (*Service) Endpoint

func (s *Service) Endpoint(relationName string) (Endpoint, error)

Endpoint returns the relation endpoint with the supplied name, if it exists.

func (*Service) Endpoints

func (s *Service) Endpoints() (eps []Endpoint, err error)

Endpoints returns the service's currently available relation endpoints.

func (*Service) EnsureMinUnits

func (s *Service) EnsureMinUnits() (err error)

EnsureMinUnits adds new units if the service's MinUnits value is greater than the number of alive units.

func (*Service) GetOwnerTag

func (s *Service) GetOwnerTag() string

SCHEMACHANGE TODO(mattyw) remove when schema upgrades are possible

func (*Service) IsExposed

func (s *Service) IsExposed() bool

IsExposed returns whether this service is exposed. The explicitly open ports (with open-port) for exposed services may be accessed from machines outside of the local deployment network. See SetExposed and ClearExposed.

func (*Service) IsPrincipal

func (s *Service) IsPrincipal() bool

IsPrincipal returns whether units of the service can have subordinate units.

func (*Service) Life

func (s *Service) Life() Life

Life returns whether the service is Alive, Dying or Dead.

func (*Service) MinUnits

func (s *Service) MinUnits() int

MinUnits returns the minimum units count for the service.

func (*Service) Name

func (s *Service) Name() string

Name returns the service name.

func (*Service) Refresh

func (s *Service) Refresh() error

Refresh refreshes the contents of the Service from the underlying state. It returns an error that satisfies IsNotFound if the service has been removed.

func (*Service) Relations

func (s *Service) Relations() (relations []*Relation, err error)

Relations returns a Relation for every relation the service is in.

func (*Service) SetAnnotations

func (a *Service) SetAnnotations(pairs map[string]string) (err error)

SetAnnotations adds key/value pairs to annotations in MongoDB.

func (*Service) SetCharm

func (s *Service) SetCharm(ch *Charm, force bool) (err error)

SetCharm changes the charm for the service. New units will be started with this charm, and existing units will be upgraded to use it. If force is true, units will be upgraded even if they are in an error state.

func (*Service) SetConstraints

func (s *Service) SetConstraints(cons constraints.Value) (err error)

SetConstraints replaces the current service constraints.

func (*Service) SetExposed

func (s *Service) SetExposed() error

SetExposed marks the service as exposed. See ClearExposed and IsExposed.

func (*Service) SetMinUnits

func (s *Service) SetMinUnits(minUnits int) (err error)

SetMinUnits changes the number of minimum units required by the service.

func (*Service) String

func (s *Service) String() string

String returns the service name.

func (*Service) Tag

func (s *Service) Tag() string

Tag returns a name identifying the service that is safe to use as a file name. The returned name will be different from other Tag values returned by any other entities from the same state.

func (*Service) Unit

func (s *Service) Unit(name string) (*Unit, error)

Unit returns the service's unit with name.

func (*Service) UpdateConfigSettings

func (s *Service) UpdateConfigSettings(changes charm.Settings) error

UpdateConfigSettings changes a service's charm config settings. Values set to nil will be deleted; unknown and invalid values will return an error.

func (*Service) Watch

func (s *Service) Watch() NotifyWatcher

Watch returns a watcher for observing changes to a service.

func (*Service) WatchRelations

func (s *Service) WatchRelations() StringsWatcher

WatchRelations returns a StringsWatcher that notifies of changes to the lifecycles of relations involving s.

func (*Service) WatchUnits

func (s *Service) WatchUnits() StringsWatcher

WatchUnits returns a StringsWatcher that notifies of changes to the lifecycles of units of s.

type Settings

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

A Settings manages changes to settings as a delta in memory and merges them back in the database when explicitly requested.

func (*Settings) Delete

func (c *Settings) Delete(key string)

Delete removes key.

func (*Settings) Get

func (c *Settings) Get(key string) (value interface{}, found bool)

Get returns the value of key and whether it was found.

func (*Settings) Keys

func (c *Settings) Keys() []string

Keys returns the current keys in alphabetical order.

func (*Settings) Map

func (c *Settings) Map() map[string]interface{}

Map returns all keys and values of the node.

func (*Settings) Read

func (c *Settings) Read() error

Read (re)reads the node data into c.

func (*Settings) Set

func (c *Settings) Set(key string, value interface{})

Set sets key to value

func (*Settings) Update

func (c *Settings) Update(kv map[string]interface{})

Update sets multiple key/value pairs.

func (*Settings) Write

func (c *Settings) Write() ([]ItemChange, error)

Write writes changes made to c back onto its node. Changes are written as a delta applied on top of the latest version of the node, to prevent overwriting unrelated changes made to the node since it was last read.

type State

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

State represents the state of an environment managed by juju.

func Initialize

func Initialize(info *Info, cfg *config.Config, opts DialOpts, policy Policy) (rst *State, err error)

Initialize sets up an initial empty state and returns it. This needs to be performed only once for a given environment. It returns unauthorizedError if access is unauthorized.

func Open

func Open(info *Info, opts DialOpts, policy Policy) (*State, error)

Open connects to the server described by the given info, waits for it to be initialized, and returns a new State representing the environment connected to.

A policy may be provided, which will be used to validate and modify behaviour of certain operations in state. A nil policy may be provided.

Open returns unauthorizedError if access is unauthorized.

func (*State) APIAddresses

func (st *State) APIAddresses() ([]string, error)

APIAddresses returns the list of cloud-internal addresses that can be used to connect to the state API server.

func (*State) AddCharm

func (st *State) AddCharm(ch charm.Charm, curl *charm.URL, bundleURL *url.URL, bundleSha256 string) (stch *Charm, err error)

AddCharm adds the ch charm with curl to the state. bundleURL must be set to a URL where the bundle for ch may be downloaded from. On success the newly added charm state is returned.

func (*State) AddMachine

func (st *State) AddMachine(series string, jobs ...MachineJob) (*Machine, error)

AddMachine adds a machine with the given series and jobs. It is deprecated and around for testing purposes only.

func (*State) AddMachineInsideMachine

func (st *State) AddMachineInsideMachine(template MachineTemplate, parentId string, containerType instance.ContainerType) (*Machine, error)

AddMachineInsideMachine adds a machine inside a container of the given type on the existing machine with id=parentId.

func (*State) AddMachineInsideNewMachine

func (st *State) AddMachineInsideNewMachine(template, parentTemplate MachineTemplate, containerType instance.ContainerType) (*Machine, error)

AddMachineInsideNewMachine creates a new machine within a container of the given type inside another new machine. The two given templates specify the form of the child and parent respectively.

func (*State) AddMachines

func (st *State) AddMachines(templates ...MachineTemplate) (_ []*Machine, err error)

AddMachines adds new machines configured according to the given templates.

func (*State) AddOneMachine

func (st *State) AddOneMachine(template MachineTemplate) (*Machine, error)

AddOne machine adds a new machine configured according to the given template.

func (*State) AddRelation

func (st *State) AddRelation(eps ...Endpoint) (r *Relation, err error)

AddRelation creates a new relation with the given endpoints.

func (*State) AddService

func (st *State) AddService(name, ownerTag string, ch *Charm) (service *Service, err error)

AddService creates a new service, running the supplied charm, with the supplied name (which must be unique). If the charm defines peer relations, they will be created automatically.

func (*State) AddStoreCharmPlaceholder

func (st *State) AddStoreCharmPlaceholder(curl *charm.URL) (err error)

AddStoreCharmPlaceholder creates a charm document in state for the given charm URL which must reference a charm from the store. The charm document is marked as a placeholder which means that if the charm is to be deployed, it will need to first be uploaded to env storage.

func (*State) AddUser

func (st *State) AddUser(name, password string) (*User, error)

AddUser adds a user to the state.

func (*State) Addresses

func (st *State) Addresses() ([]string, error)

Addresses returns the list of cloud-internal addresses that can be used to connect to the state.

func (*State) AllMachines

func (st *State) AllMachines() (machines []*Machine, err error)

AllMachines returns all machines in the environment ordered by id.

func (*State) AllServices

func (st *State) AllServices() (services []*Service, err error)

AllServices returns all deployed services in the environment.

func (*State) AssignUnit

func (st *State) AssignUnit(u *Unit, policy AssignmentPolicy) (err error)

AssignUnit places the unit on a machine. Depending on the policy, and the state of the environment, this may lead to new instances being launched within the environment.

func (*State) CACert

func (st *State) CACert() (cert []byte)

CACert returns the certificate used to validate the state connection.

func (*State) Charm

func (st *State) Charm(curl *charm.URL) (*Charm, error)

Charm returns the charm with the given URL. Charms pending upload to storage and placeholders are never returned.

func (*State) Cleanup

func (st *State) Cleanup() error

Cleanup removes all documents that were previously marked for removal, if any such exist. It should be called periodically by at least one element of the system.

func (*State) Close

func (st *State) Close() error

func (*State) DeployerConnectionInfo

func (st *State) DeployerConnectionInfo() (*DeployerConnectionValues, error)

DeployerConnectionInfo returns the address information necessary for the deployer. The function does the expensive operations (getting stuff from mongo) just once.

func (*State) EndpointsRelation

func (st *State) EndpointsRelation(endpoints ...Endpoint) (*Relation, error)

EndpointsRelation returns the existing relation with the given endpoints.

func (*State) EnsureAvailability

func (st *State) EnsureAvailability(numStateServers int, cons constraints.Value, series string) error

EnsureAvailability adds state server machines as necessary to make the number of live state servers equal to numStateServers. The given constraints and series will be attached to any new machines.

TODO(rog): If any current state servers are down, they will be removed from the current set of voting replica set peers (although the machines themselves will remain and they will still remain part of the replica set). Once a machine's voting status has been removed, the machine itself may be removed.

func (*State) EnvironConfig

func (st *State) EnvironConfig() (*config.Config, error)

func (*State) EnvironConstraints

func (st *State) EnvironConstraints() (constraints.Value, error)

EnvironConstraints returns the current environment constraints.

func (*State) Environment

func (st *State) Environment() (*Environment, error)

Environment returns the environment entity.

func (*State) FindEntity

func (st *State) FindEntity(tag string) (Entity, error)

FindEntity returns the entity with the given tag.

The returned value can be of type *Machine, *Unit, *User, *Service or *Environment, depending on the tag.

func (*State) InferEndpoints

func (st *State) InferEndpoints(names []string) ([]Endpoint, error)

InferEndpoints returns the endpoints corresponding to the supplied names. There must be 1 or 2 supplied names, of the form <service>[:<relation>]. If the supplied names uniquely specify a possible relation, or if they uniquely specify a possible relation once all implicit relations have been filtered, the endpoints corresponding to that relation will be returned.

func (*State) KeyRelation

func (st *State) KeyRelation(key string) (*Relation, error)

KeyRelation returns the existing relation with the given key (which can be derived unambiguously from the relation's endpoints).

func (*State) LatestPlaceholderCharm

func (st *State) LatestPlaceholderCharm(curl *charm.URL) (*Charm, error)

LatestPlaceholderCharm returns the latest charm described by the given URL but which is not yet deployed.

func (*State) Machine

func (st *State) Machine(id string) (*Machine, error)

Machine returns the machine with the given id.

func (*State) MongoSession

func (st *State) MongoSession() *mgo.Session

MongoSession returns the underlying mongodb session used by the state. It is exposed so that external code can maintain the mongo replica set and should not otherwise be used.

func (*State) NeedsCleanup

func (st *State) NeedsCleanup() (bool, error)

NeedsCleanup returns true if documents previously marked for removal exist.

func (*State) Ping

func (st *State) Ping() error

Ping probes the state's database connection to ensure that it is still alive.

func (*State) PrepareLocalCharmUpload

func (st *State) PrepareLocalCharmUpload(curl *charm.URL) (chosenUrl *charm.URL, err error)

PrepareLocalCharmUpload must be called before a local charm is uploaded to the provider storage in order to create a charm document in state. It returns the chosen unique charm URL reserved in state for the charm.

The url's schema must be "local" and it must include a revision.

func (*State) PrepareStoreCharmUpload

func (st *State) PrepareStoreCharmUpload(curl *charm.URL) (*Charm, error)

PrepareStoreCharmUpload must be called before a charm store charm is uploaded to the provider storage in order to create a charm document in state. If a charm with the same URL is already in state, it will be returned as a *state.Charm (is can be still pending or already uploaded). Otherwise, a new charm document is added in state with just the given charm URL and PendingUpload=true, which is then returned as a *state.Charm.

The url's schema must be "cs" and it must include a revision.

func (*State) Relation

func (st *State) Relation(id int) (*Relation, error)

Relation returns the existing relation with the given id.

func (*State) ResumeTransactions

func (st *State) ResumeTransactions() error

ResumeTransactions resumes all pending transactions.

func (*State) Service

func (st *State) Service(name string) (service *Service, err error)

Service returns a service state by name.

func (*State) SetAdminMongoPassword

func (st *State) SetAdminMongoPassword(password string) error

SetAdminMongoPassword sets the administrative password to access the state. If the password is non-empty, all subsequent attempts to access the state must be authorized; otherwise no authorization is required.

func (*State) SetEnvironAgentVersion

func (st *State) SetEnvironAgentVersion(newVersion version.Number) error

SetEnvironAgentVersion changes the agent version for the environment to the given version, only if the environment is in a stable state (all agents are running the current version).

func (*State) SetEnvironConfig

func (st *State) SetEnvironConfig(cfg, old *config.Config) error

SetEnvironConfig replaces the current configuration of the environment with the provided configuration.

func (*State) SetEnvironConstraints

func (st *State) SetEnvironConstraints(cons constraints.Value) error

SetEnvironConstraints replaces the current environment constraints.

func (*State) StartSync

func (st *State) StartSync()

StartSync forces watchers to resynchronize their state with the database immediately. This will happen periodically automatically.

func (*State) StateServerInfo

func (st *State) StateServerInfo() (*StateServerInfo, error)

StateServerInfo returns returns information about the currently configured state server machines.

func (*State) Unit

func (st *State) Unit(name string) (*Unit, error)

Unit returns a unit by name.

func (*State) UpdateUploadedCharm

func (st *State) UpdateUploadedCharm(ch charm.Charm, curl *charm.URL, bundleURL *url.URL, bundleSha256 string) (*Charm, error)

UpdateUploadedCharm marks the given charm URL as uploaded and updates the rest of its data, returning it as *state.Charm.

func (*State) User

func (st *State) User(name string) (*User, error)

User returns the state user for the given name,

func (*State) Watch

func (st *State) Watch() *multiwatcher.Watcher

func (*State) WatchCleanups

func (st *State) WatchCleanups() NotifyWatcher

WatchCleanups starts and returns a CleanupWatcher.

func (*State) WatchEnvironConfig

func (s *State) WatchEnvironConfig() *EnvironConfigWatcher

WatchEnvironConfig returns a watcher for observing changes to the environment configuration.

func (*State) WatchEnvironMachines

func (st *State) WatchEnvironMachines() StringsWatcher

WatchEnvironMachines returns a StringsWatcher that notifies of changes to the lifecycles of the machines (but not containers) in the environment.

func (*State) WatchForEnvironConfigChanges

func (st *State) WatchForEnvironConfigChanges() NotifyWatcher

WatchForEnvironConfigChanges return a NotifyWatcher waiting for the Environ Config to change. This differs from WatchEnvironConfig in that the watcher is a NotifyWatcher that does not give content during Changes()

func (*State) WatchMinUnits

func (st *State) WatchMinUnits() StringsWatcher

func (*State) WatchServices

func (st *State) WatchServices() StringsWatcher

WatchServices returns a StringsWatcher that notifies of changes to the lifecycles of the services in the environment.

func (*State) WatchStateServerInfo

func (st *State) WatchStateServerInfo() NotifyWatcher

type StateServerInfo

type StateServerInfo struct {
	// MachineIds holds the ids of all machines configured
	// to run a state server. It includes all the machine
	// ids in VotingMachineIds.
	MachineIds []string

	// VotingMachineIds holds the ids of all machines
	// configured to run a state server and to have a vote
	// in peer election.
	VotingMachineIds []string
}

StateServerInfo holds information about currently configured state server machines.

type StatusSetter

type StatusSetter interface {
	SetStatus(status params.Status, info string, data params.StatusData) error
}

type StringsWatcher

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

StringsWatcher generates signals when something changes, returning the changes as a list of strings.

type Unit

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

Unit represents the state of a service unit.

func (*Unit) AgentAlive

func (u *Unit) AgentAlive() (bool, error)

AgentAlive returns whether the respective remote agent is alive.

func (*Unit) AgentTools

func (u *Unit) AgentTools() (*tools.Tools, error)

AgentTools returns the tools that the agent is currently running. It an error that satisfies IsNotFound if the tools have not yet been set.

func (*Unit) Annotation

func (a *Unit) Annotation(key string) (string, error)

Annotation returns the annotation value corresponding to the given key. If the requested annotation is not found, an empty string is returned.

func (*Unit) Annotations

func (a *Unit) Annotations() (map[string]string, error)

Annotations returns all the annotations corresponding to an entity.

func (*Unit) AssignToCleanEmptyMachine

func (u *Unit) AssignToCleanEmptyMachine() (m *Machine, err error)

AssignToCleanMachine assigns u to a machine which is marked as clean and is also not hosting any containers. A machine is clean if it has never had any principal units assigned to it. If there are no clean machines besides any machine(s) running JobHostEnviron, an error is returned. This method does not take constraints into consideration when choosing a machine (lp:1161919).

func (*Unit) AssignToCleanMachine

func (u *Unit) AssignToCleanMachine() (m *Machine, err error)

AssignToCleanMachine assigns u to a machine which is marked as clean. A machine is clean if it has never had any principal units assigned to it. If there are no clean machines besides any machine(s) running JobHostEnviron, an error is returned. This method does not take constraints into consideration when choosing a machine (lp:1161919).

func (*Unit) AssignToMachine

func (u *Unit) AssignToMachine(m *Machine) (err error)

AssignToMachine assigns this unit to a given machine.

func (*Unit) AssignToNewMachine

func (u *Unit) AssignToNewMachine() (err error)

AssignToNewMachine assigns the unit to a new machine, with constraints determined according to the service and environment constraints at the time of unit creation.

func (*Unit) AssignToNewMachineOrContainer

func (u *Unit) AssignToNewMachineOrContainer() (err error)

AssignToNewMachineOrContainer assigns the unit to a new machine, with constraints determined according to the service and environment constraints at the time of unit creation. If a container is required, a clean, empty machine instance is required on which to create the container. An existing clean, empty instance is first searched for, and if not found, a new one is created.

func (*Unit) AssignedMachineId

func (u *Unit) AssignedMachineId() (id string, err error)

AssignedMachineId returns the id of the assigned machine.

func (*Unit) CharmURL

func (u *Unit) CharmURL() (*charm.URL, bool)

CharmURL returns the charm URL this unit is currently using.

func (*Unit) ClearResolved

func (u *Unit) ClearResolved() error

ClearResolved removes any resolved setting on the unit.

func (*Unit) ClosePort

func (u *Unit) ClosePort(protocol string, number int) (err error)

ClosePort sets the policy of the port with protocol and number to be closed.

func (*Unit) ConfigSettings

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

ConfigSettings returns the complete set of service charm config settings available to the unit. Unset values will be replaced with the default value for the associated option, and may thus be nil when no default is specified.

func (*Unit) DeployerTag

func (u *Unit) DeployerTag() (string, bool)

DeployerTag returns the tag of the agent responsible for deploying the unit. If no such entity can be determined, false is returned.

func (*Unit) Destroy

func (u *Unit) Destroy() (err error)

Destroy, when called on a Alive unit, advances its lifecycle as far as possible; it otherwise has no effect. In most situations, the unit's life is just set to Dying; but if a principal unit that is not assigned to a provisioned machine is Destroyed, it will be removed from state directly.

func (*Unit) EnsureDead

func (u *Unit) EnsureDead() (err error)

EnsureDead sets the unit lifecycle to Dead if it is Alive or Dying. It does nothing otherwise. If the unit has subordinates, it will return ErrUnitHasSubordinates.

func (*Unit) IsPrincipal

func (u *Unit) IsPrincipal() bool

IsPrincipal returns whether the unit is deployed in its own container, and can therefore have subordinate services deployed alongside it.

func (*Unit) Life

func (u *Unit) Life() Life

Life returns whether the unit is Alive, Dying or Dead.

func (*Unit) Name

func (u *Unit) Name() string

Name returns the unit name.

func (*Unit) OpenPort

func (u *Unit) OpenPort(protocol string, number int) (err error)

OpenPort sets the policy of the port with protocol and number to be opened.

func (*Unit) OpenedPorts

func (u *Unit) OpenedPorts() []instance.Port

OpenedPorts returns a slice containing the open ports of the unit.

func (*Unit) PasswordValid

func (u *Unit) PasswordValid(password string) bool

PasswordValid returns whether the given password is valid for the given unit.

func (*Unit) PrincipalName

func (u *Unit) PrincipalName() (string, bool)

PrincipalName returns the name of the unit's principal. If the unit is not a subordinate, false is returned.

func (*Unit) PrivateAddress

func (u *Unit) PrivateAddress() (string, bool)

PrivateAddress returns the private address of the unit and whether it is valid.

func (*Unit) PublicAddress

func (u *Unit) PublicAddress() (string, bool)

PublicAddress returns the public address of the unit and whether it is valid.

func (*Unit) Refresh

func (u *Unit) Refresh() error

Refresh refreshes the contents of the Unit from the underlying state. It an error that satisfies IsNotFound if the unit has been removed.

func (*Unit) Remove

func (u *Unit) Remove() (err error)

Remove removes the unit from state, and may remove its service as well, if the service is Dying and no other references to it exist. It will fail if the unit is not Dead.

func (*Unit) Resolve

func (u *Unit) Resolve(retryHooks bool) error

Resolve marks the unit as having had any previous state transition problems resolved, and informs the unit that it may attempt to reestablish normal workflow. The retryHooks parameter informs whether to attempt to reexecute previous failed hooks or to continue as if they had succeeded before.

func (*Unit) Resolved

func (u *Unit) Resolved() ResolvedMode

Resolved returns the resolved mode for the unit.

func (*Unit) Series

func (u *Unit) Series() string

Series returns the deployed charm's series.

func (*Unit) Service

func (u *Unit) Service() (*Service, error)

Service returns the service.

func (*Unit) ServiceName

func (u *Unit) ServiceName() string

ServiceName returns the service name.

func (*Unit) SetAgentAlive

func (u *Unit) SetAgentAlive() (*presence.Pinger, error)

SetAgentAlive signals that the agent for unit u is alive. It returns the started pinger.

func (*Unit) SetAgentVersion

func (u *Unit) SetAgentVersion(v version.Binary) (err error)

SetAgentVersion sets the version of juju that the agent is currently running.

func (*Unit) SetAnnotations

func (a *Unit) SetAnnotations(pairs map[string]string) (err error)

SetAnnotations adds key/value pairs to annotations in MongoDB.

func (*Unit) SetCharmURL

func (u *Unit) SetCharmURL(curl *charm.URL) (err error)

SetCharmURL marks the unit as currently using the supplied charm URL. An error will be returned if the unit is dead, or the charm URL not known.

func (*Unit) SetMongoPassword

func (u *Unit) SetMongoPassword(password string) error

SetMongoPassword sets the password the agent responsible for the unit should use to communicate with the state servers. Previous passwords are invalidated.

func (*Unit) SetPassword

func (u *Unit) SetPassword(password string) error

SetPassword sets the password for the machine's agent.

func (*Unit) SetPrivateAddress

func (u *Unit) SetPrivateAddress(address string) error

SetPrivateAddress sets the private address of the unit.

func (*Unit) SetPublicAddress

func (u *Unit) SetPublicAddress(address string) (err error)

SetPublicAddress sets the public address of the unit.

func (*Unit) SetResolved

func (u *Unit) SetResolved(mode ResolvedMode) (err error)

SetResolved marks the unit as having had any previous state transition problems resolved, and informs the unit that it may attempt to reestablish normal workflow. The resolved mode parameter informs whether to attempt to reexecute previous failed hooks or to continue as if they had succeeded before.

func (*Unit) SetStatus

func (u *Unit) SetStatus(status params.Status, info string, data params.StatusData) error

SetStatus sets the status of the unit. The optional values allow to pass additional helpful status data.

func (*Unit) Status

func (u *Unit) Status() (status params.Status, info string, data params.StatusData, err error)

Status returns the status of the unit.

func (*Unit) String

func (u *Unit) String() string

String returns the unit as string.

func (*Unit) SubordinateNames

func (u *Unit) SubordinateNames() []string

SubordinateNames returns the names of any subordinate units.

func (*Unit) Tag

func (u *Unit) Tag() string

Tag returns a name identifying the unit that is safe to use as a file name. The returned name will be different from other Tag values returned by any other entities from the same state.

func (*Unit) UnassignFromMachine

func (u *Unit) UnassignFromMachine() (err error)

UnassignFromMachine removes the assignment between this unit and the machine it's assigned to.

func (*Unit) WaitAgentAlive

func (u *Unit) WaitAgentAlive(timeout time.Duration) (err error)

WaitAgentAlive blocks until the respective agent is alive.

func (*Unit) Watch

func (u *Unit) Watch() NotifyWatcher

Watch returns a watcher for observing changes to a unit.

func (*Unit) WatchConfigSettings

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

WatchConfigSettings returns a watcher for observing changes to the unit's service configuration settings. The unit must have a charm URL set before this method is called, and the returned watcher will be valid only while the unit's charm URL is not changed. TODO(fwereade): this could be much smarter; if it were, uniter.Filter could be somewhat simpler.

func (*Unit) WatchSubordinateUnits

func (u *Unit) WatchSubordinateUnits() StringsWatcher

WatchSubordinateUnits returns a StringsWatcher tracking the unit's subordinate units.

type UnitsWatcher

type UnitsWatcher interface {
	Entity
	WatchUnits() StringsWatcher
}

UnitsWatcher defines the methods needed to retrieve an entity (a machine or a service) and watch its units.

type User

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

User represents a juju client user.

func (*User) Name

func (u *User) Name() string

Name returns the user name,

func (*User) PasswordValid

func (u *User) PasswordValid(password string) bool

PasswordValid returns whether the given password is valid for the user.

func (*User) Refresh

func (u *User) Refresh() error

Refresh refreshes information about the user from the state.

func (*User) SetPassword

func (u *User) SetPassword(password string) error

SetPassword sets the password associated with the user.

func (*User) SetPasswordHash

func (u *User) SetPasswordHash(pwHash string, pwSalt string) error

SetPasswordHash sets the password to the inverse of pwHash = utils.UserPasswordHash(pw, pwSalt). It can be used when we know only the hash of the password, but not the clear text.

func (*User) Tag

func (u *User) Tag() string

Tag returns the Tag for the user ("user-$username")

type Watcher

type Watcher interface {
	// Kill asks the watcher to stop without waiting for it do so.
	Kill()
	// Wait waits for the watcher to die and returns any
	// error encountered when it was running.
	Wait() error
	// Stop kills the watcher, then waits for it to die.
	Stop() error
	// Err returns any error encountered while the watcher
	// has been running.
	Err() error
}

Watcher is implemented by all watchers; the actual changes channel is returned by a watcher-specific Changes method.

Directories

Path Synopsis
api
agent
The machine package implements the API interfaces used by the machine agent.
The machine package implements the API interfaces used by the machine agent.
machine
The machiner package implements the API interface used by the machiner worker.
The machiner package implements the API interface used by the machiner worker.
uniter
The uniter package implements the API interface used by the uniter worker.
The uniter package implements the API interface used by the uniter worker.
The presence package implements an interface for observing liveness of arbitrary keys (agents, processes, etc) on top of MongoDB.
The presence package implements an interface for observing liveness of arbitrary keys (agents, processes, etc) on top of MongoDB.
The watcher package provides an interface for observing changes to arbitrary MongoDB documents that are maintained via the mgo/txn transaction package.
The watcher package provides an interface for observing changes to arbitrary MongoDB documents that are maintained via the mgo/txn transaction package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL