~juju-qa/ubuntu/xenial/juju/xenial-2.0-beta3

« back to all changes in this revision

Viewing changes to src/github.com/juju/juju/status/status.go

  • Committer: Martin Packman
  • Date: 2016-03-30 19:31:08 UTC
  • mfrom: (1.1.41)
  • Revision ID: martin.packman@canonical.com-20160330193108-h9iz3ak334uk0z5r
Merge new upstream source 2.0~beta3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright 2016 Canonical Ltd.
 
2
// Licensed under the AGPLv3, see LICENCE file for details.
 
3
 
 
4
package status
 
5
 
 
6
import "time"
 
7
 
 
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
 
10
// very clear reason.
 
11
//
 
12
// Status values currently apply to machine (agents), unit (agents), unit
 
13
// (workloads), service (workloads), and volumes.
 
14
type Status string
 
15
 
 
16
// StatusInfo holds a Status and associated information.
 
17
type StatusInfo struct {
 
18
        Status  Status
 
19
        Message string
 
20
        Data    map[string]interface{}
 
21
        Since   *time.Time
 
22
}
 
23
 
 
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
 
27
}
 
28
 
 
29
// StatusGetter represents a type whose status can be read.
 
30
type StatusGetter interface {
 
31
        Status() (StatusInfo, error)
 
32
}
 
33
 
 
34
// InstanceStatusGetter represents a type whose instance status can be read.
 
35
type InstanceStatusGetter interface {
 
36
        InstanceStatus() (StatusInfo, error)
 
37
}
 
38
 
 
39
// StatusHistoryGetter instances can fetch their status history.
 
40
type StatusHistoryGetter interface {
 
41
        StatusHistory(size int) ([]StatusInfo, error)
 
42
}
 
43
 
 
44
// InstanceStatusHistoryGetter instances can fetch their instance status history.
 
45
type InstanceStatusHistoryGetter interface {
 
46
        InstanceStatusHistory(size int) ([]StatusInfo, error)
 
47
}
 
48
 
 
49
const (
 
50
        // Status values common to machine and unit agents.
 
51
 
 
52
        // StatusError means the entity requires human intervention
 
53
        // in order to operate correctly.
 
54
        StatusError Status = "error"
 
55
 
 
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"
 
63
)
 
64
 
 
65
const (
 
66
        // Status values specific to machine agents.
 
67
 
 
68
        // StatusPending is set when:
 
69
        // The machine is not yet participating in the model.
 
70
        StatusPending Status = "pending"
 
71
 
 
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"
 
76
 
 
77
        // StatusDown is set when:
 
78
        // The machine ought to be signalling activity, but it cannot be
 
79
        // detected.
 
80
        StatusDown Status = "down"
 
81
)
 
82
 
 
83
const (
 
84
        // Status values specific to unit agents.
 
85
 
 
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"
 
90
 
 
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"
 
95
 
 
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"
 
100
 
 
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"
 
106
 
 
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"
 
112
 
 
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"
 
117
)
 
118
 
 
119
const (
 
120
        // Status values specific to services and units, reflecting the
 
121
        // state of the software itself.
 
122
 
 
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"
 
129
 
 
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"
 
134
 
 
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"
 
139
 
 
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"
 
144
 
 
145
        // StatusBlocked is set when:
 
146
        // The unit needs manual intervention to get back to the Running state.
 
147
        StatusBlocked Status = "blocked"
 
148
 
 
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"
 
153
)
 
154
 
 
155
const (
 
156
        // Status values specific to storage.
 
157
 
 
158
        // StatusAttaching indicates that the storage is being attached
 
159
        // to a machine.
 
160
        StatusAttaching Status = "attaching"
 
161
 
 
162
        // StatusAttached indicates that the storage is attached to a
 
163
        // machine.
 
164
        StatusAttached Status = "attached"
 
165
 
 
166
        // StatusDetaching indicates that the storage is being detached
 
167
        // from a machine.
 
168
        StatusDetaching Status = "detaching"
 
169
 
 
170
        // StatusDetached indicates that the storage is not attached to
 
171
        // any machine.
 
172
        StatusDetached Status = "detached"
 
173
 
 
174
        // StatusDestroying indicates that the storage is being destroyed.
 
175
        StatusDestroying Status = "destroying"
 
176
)
 
177
 
 
178
// InstanceStatus
 
179
const (
 
180
        StatusEmpty             Status = ""
 
181
        StatusProvisioning      Status = "allocating"
 
182
        StatusRunning           Status = "running"
 
183
        StatusProvisioningError Status = "provisioning error"
 
184
)
 
185
 
 
186
const (
 
187
        MessageInstalling = "installing charm software"
 
188
 
 
189
        // StorageReadyMessage is the message set to the agent status when all storage
 
190
        // attachments are properly done.
 
191
        StorageReadyMessage = "storage ready"
 
192
 
 
193
        // PreparingStorageMessage is the message set to the agent status before trying
 
194
        // to attach storages.
 
195
        PreparingStorageMessage = "preparing storage"
 
196
)
 
197
 
 
198
func (status Status) KnownInstanceStatus() bool {
 
199
        switch status {
 
200
        case
 
201
                StatusPending,
 
202
                StatusProvisioningError,
 
203
                StatusAllocating,
 
204
                StatusRunning,
 
205
                StatusUnknown:
 
206
                return true
 
207
        }
 
208
        return false
 
209
}
 
210
 
 
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 {
 
215
        switch status {
 
216
        case
 
217
                StatusAllocating,
 
218
                StatusError,
 
219
                StatusFailed,
 
220
                StatusRebooting,
 
221
                StatusExecuting,
 
222
                StatusIdle:
 
223
                return true
 
224
        }
 
225
        return false
 
226
}
 
227
 
 
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) {
 
233
                return true
 
234
        }
 
235
        switch status {
 
236
        case StatusError: // include error so that we can filter on what the spec says is valid
 
237
                return true
 
238
        default:
 
239
                return false
 
240
        }
 
241
}
 
242
 
 
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 {
 
246
        switch status {
 
247
        case
 
248
                StatusBlocked,
 
249
                StatusMaintenance,
 
250
                StatusWaiting,
 
251
                StatusActive,
 
252
                StatusUnknown,
 
253
                StatusTerminated:
 
254
                return true
 
255
        default:
 
256
                return false
 
257
        }
 
258
}
 
259
 
 
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
 
265
}
 
266
 
 
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
 
272
}