1
// Copyright 2016 Canonical Ltd.
2
// Licensed under the AGPLv3, see LICENCE file for details.
8
// Status used to represent the status of an entity, but has recently become
9
// and applies to "workloads" as well, which we don't currently model, for no
12
// Status values currently apply to machine (agents), unit (agents), unit
13
// (workloads), service (workloads), and volumes.
16
// StatusInfo holds a Status and associated information.
17
type StatusInfo struct {
20
Data map[string]interface{}
24
// StatusSetter represents a type whose status can be set.
25
type StatusSetter interface {
26
SetStatus(status Status, info string, data map[string]interface{}) error
29
// StatusGetter represents a type whose status can be read.
30
type StatusGetter interface {
31
Status() (StatusInfo, error)
34
// InstanceStatusGetter represents a type whose instance status can be read.
35
type InstanceStatusGetter interface {
36
InstanceStatus() (StatusInfo, error)
39
// StatusHistoryGetter instances can fetch their status history.
40
type StatusHistoryGetter interface {
41
StatusHistory(size int) ([]StatusInfo, error)
44
// InstanceStatusHistoryGetter instances can fetch their instance status history.
45
type InstanceStatusHistoryGetter interface {
46
InstanceStatusHistory(size int) ([]StatusInfo, error)
50
// Status values common to machine and unit agents.
52
// StatusError means the entity requires human intervention
53
// in order to operate correctly.
54
StatusError Status = "error"
56
// StatusStarted is set when:
57
// The entity is actively participating in the model.
58
// For unit agents, this is a state we preserve for backwards
59
// compatibility with scripts during the life of Juju 1.x.
60
// In Juju 2.x, the agent-state will remain “active” and scripts
61
// will watch the unit-state instead for signals of service readiness.
62
StatusStarted Status = "started"
66
// Status values specific to machine agents.
68
// StatusPending is set when:
69
// The machine is not yet participating in the model.
70
StatusPending Status = "pending"
72
// StatusStopped is set when:
73
// The machine's agent will perform no further action, other than
74
// to set the unit to Dead at a suitable moment.
75
StatusStopped Status = "stopped"
77
// StatusDown is set when:
78
// The machine ought to be signalling activity, but it cannot be
80
StatusDown Status = "down"
84
// Status values specific to unit agents.
86
// StatusAllocating is set when:
87
// The machine on which a unit is to be hosted is still being
88
// spun up in the cloud.
89
StatusAllocating Status = "allocating"
91
// StatusRebooting is set when:
92
// The machine on which this agent is running is being rebooted.
93
// The juju-agent should move from rebooting to idle when the reboot is complete.
94
StatusRebooting Status = "rebooting"
96
// StatusExecuting is set when:
97
// The agent is running a hook or action. The human-readable message should reflect
98
// which hook or action is being run.
99
StatusExecuting Status = "executing"
101
// StatusIdle is set when:
102
// Once the agent is installed and running it will notify the Juju server and its state
103
// becomes "idle". It will stay "idle" until some action (e.g. it needs to run a hook) or
104
// error (e.g it loses contact with the Juju server) moves it to a different state.
105
StatusIdle Status = "idle"
107
// StatusFailed is set when:
108
// The unit agent has failed in some way,eg the agent ought to be signalling
109
// activity, but it cannot be detected. It might also be that the unit agent
110
// detected an unrecoverable condition and managed to tell the Juju server about it.
111
StatusFailed Status = "failed"
113
// StatusLost is set when:
114
// The juju agent has has not communicated with the juju server for an unexpectedly long time;
115
// the unit agent ought to be signalling activity, but none has been detected.
116
StatusLost Status = "lost"
120
// Status values specific to services and units, reflecting the
121
// state of the software itself.
123
// StatusMaintenance is set when:
124
// The unit is not yet providing services, but is actively doing stuff
125
// in preparation for providing those services.
126
// This is a "spinning" state, not an error state.
127
// It reflects activity on the unit itself, not on peers or related units.
128
StatusMaintenance Status = "maintenance"
130
// StatusTerminated is set when:
131
// This unit used to exist, we have a record of it (perhaps because of storage
132
// allocated for it that was flagged to survive it). Nonetheless, it is now gone.
133
StatusTerminated Status = "terminated"
135
// StatusUnknown is set when:
136
// A unit-agent has finished calling install, config-changed, and start,
137
// but the charm has not called status-set yet.
138
StatusUnknown Status = "unknown"
140
// StatusWaiting is set when:
141
// The unit is unable to progress to an active state because a service to
142
// which it is related is not running.
143
StatusWaiting Status = "waiting"
145
// StatusBlocked is set when:
146
// The unit needs manual intervention to get back to the Running state.
147
StatusBlocked Status = "blocked"
149
// StatusActive is set when:
150
// The unit believes it is correctly offering all the services it has
151
// been asked to offer.
152
StatusActive Status = "active"
156
// Status values specific to storage.
158
// StatusAttaching indicates that the storage is being attached
160
StatusAttaching Status = "attaching"
162
// StatusAttached indicates that the storage is attached to a
164
StatusAttached Status = "attached"
166
// StatusDetaching indicates that the storage is being detached
168
StatusDetaching Status = "detaching"
170
// StatusDetached indicates that the storage is not attached to
172
StatusDetached Status = "detached"
174
// StatusDestroying indicates that the storage is being destroyed.
175
StatusDestroying Status = "destroying"
180
StatusEmpty Status = ""
181
StatusProvisioning Status = "allocating"
182
StatusRunning Status = "running"
183
StatusProvisioningError Status = "provisioning error"
187
MessageInstalling = "installing charm software"
189
// StorageReadyMessage is the message set to the agent status when all storage
190
// attachments are properly done.
191
StorageReadyMessage = "storage ready"
193
// PreparingStorageMessage is the message set to the agent status before trying
194
// to attach storages.
195
PreparingStorageMessage = "preparing storage"
198
func (status Status) KnownInstanceStatus() bool {
202
StatusProvisioningError,
211
// KnownAgentStatus returns true if status has a known value for an agent.
212
// It includes every status that has ever been valid for a unit or machine agent.
213
// This is used by the apiserver client facade to filter out unknown values.
214
func (status Status) KnownAgentStatus() bool {
228
// KnownWorkloadStatus returns true if status has a known value for a workload.
229
// It includes every status that has ever been valid for a unit agent.
230
// This is used by the apiserver client facade to filter out unknown values.
231
func (status Status) KnownWorkloadStatus() bool {
232
if ValidWorkloadStatus(status) {
236
case StatusError: // include error so that we can filter on what the spec says is valid
243
// ValidWorkloadStatus returns true if status has a valid value (that is to say,
244
// a value that it's OK to set) for units or services.
245
func ValidWorkloadStatus(status Status) bool {
260
// WorkloadMatches returns true if the candidate matches status,
261
// taking into account that the candidate may be a legacy
262
// status value which has been deprecated.
263
func (status Status) WorkloadMatches(candidate Status) bool {
264
return status == candidate
267
// Matches returns true if the candidate matches status,
268
// taking into account that the candidate may be a legacy
269
// status value which has been deprecated.
270
func (status Status) Matches(candidate Status) bool {
271
return status == candidate