github.com/niedbalski/juju@v0.0.0-20190215020005-8ff100488e47/core/status/status.go (about) 1 // Copyright 2016 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package status 5 6 import ( 7 "time" 8 ) 9 10 // Status used to represent the status of an entity, but has recently become 11 // and applies to "workloads" as well, which we don't currently model, for no 12 // very clear reason. 13 // 14 // Status values currently apply to machine (agents), unit (agents), unit 15 // (workloads), application (workloads), volumes, filesystems, and models. 16 type Status string 17 18 // String returns a string representation of the Status. 19 func (s Status) String() string { 20 return string(s) 21 } 22 23 // StatusInfo holds a Status and associated information. 24 type StatusInfo struct { 25 Status Status 26 Message string 27 Data map[string]interface{} 28 Since *time.Time 29 } 30 31 // StatusSetter represents a type whose status can be set. 32 type StatusSetter interface { 33 SetStatus(StatusInfo) error 34 } 35 36 // StatusGetter represents a type whose status can be read. 37 type StatusGetter interface { 38 Status() (StatusInfo, error) 39 } 40 41 // InstanceStatusGetter represents a type whose instance status can be read. 42 type InstanceStatusGetter interface { 43 InstanceStatus() (StatusInfo, error) 44 } 45 46 const ( 47 // Status values common to machine and unit agents. 48 49 // Error means the entity requires human intervention 50 // in order to operate correctly. 51 Error Status = "error" 52 53 // Started is set when: 54 // The entity is actively participating in the model. 55 // For unit agents, this is a state we preserve for backwards 56 // compatibility with scripts during the life of Juju 1.x. 57 // In Juju 2.x, the agent-state will remain “active” and scripts 58 // will watch the unit-state instead for signals of application readiness. 59 Started Status = "started" 60 ) 61 62 const ( 63 // Status values specific to machine agents. 64 65 // Pending is set when: 66 // The machine is not yet participating in the model. 67 Pending Status = "pending" 68 69 // Stopped is set when: 70 // The machine's agent will perform no further action, other than 71 // to set the unit to Dead at a suitable moment. 72 Stopped Status = "stopped" 73 74 // Down is set when: 75 // The machine ought to be signalling activity, but it cannot be 76 // detected. 77 Down Status = "down" 78 ) 79 80 const ( 81 // Status values specific to unit agents. 82 83 // Allocating is set when: 84 // The machine on which a unit is to be hosted is still being 85 // spun up in the cloud. 86 Allocating Status = "allocating" 87 88 // Rebooting is set when: 89 // The machine on which this agent is running is being rebooted. 90 // The juju-agent should move from rebooting to idle when the reboot is complete. 91 Rebooting Status = "rebooting" 92 93 // Executing is set when: 94 // The agent is running a hook or action. The human-readable message should reflect 95 // which hook or action is being run. 96 Executing Status = "executing" 97 98 // Idle is set when: 99 // Once the agent is installed and running it will notify the Juju server and its state 100 // becomes "idle". It will stay "idle" until some action (e.g. it needs to run a hook) or 101 // error (e.g it loses contact with the Juju server) moves it to a different state. 102 Idle Status = "idle" 103 104 // Failed is set when: 105 // The unit agent has failed in some way,eg the agent ought to be signalling 106 // activity, but it cannot be detected. It might also be that the unit agent 107 // detected an unrecoverable condition and managed to tell the Juju server about it. 108 Failed Status = "failed" 109 110 // Lost is set when: 111 // The juju agent has has not communicated with the juju server for an unexpectedly long time; 112 // the unit agent ought to be signalling activity, but none has been detected. 113 Lost Status = "lost" 114 ) 115 116 const ( 117 // Status values specific to applications and units, reflecting the 118 // state of the software itself. 119 120 // Maintenance is set when: 121 // The unit is not yet providing services, but is actively doing stuff 122 // in preparation for providing those services. 123 // This is a "spinning" state, not an error state. 124 // It reflects activity on the unit itself, not on peers or related units. 125 Maintenance Status = "maintenance" 126 127 // Terminated is set when: 128 // This unit used to exist, we have a record of it (perhaps because of storage 129 // allocated for it that was flagged to survive it). Nonetheless, it is now gone. 130 Terminated Status = "terminated" 131 132 // Unknown is set when: 133 // A unit-agent has finished calling install, config-changed, and start, 134 // but the charm has not called status-set yet. 135 Unknown Status = "unknown" 136 137 // Waiting is set when: 138 // The unit is unable to progress to an active state because an application to 139 // which it is related is not running. 140 Waiting Status = "waiting" 141 142 // Blocked is set when: 143 // The unit needs manual intervention to get back to the Running state. 144 Blocked Status = "blocked" 145 146 // Active is set when: 147 // The unit believes it is correctly offering all the services it has 148 // been asked to offer. 149 Active Status = "active" 150 ) 151 152 const ( 153 // Status values specific to storage. 154 155 // Attaching indicates that the storage is being attached 156 // to a machine. 157 Attaching Status = "attaching" 158 159 // Attached indicates that the storage is attached to a 160 // machine. 161 Attached Status = "attached" 162 163 // Detaching indicates that the storage is being detached 164 // from a machine. 165 Detaching Status = "detaching" 166 167 // Detached indicates that the storage is not attached to 168 // any machine. 169 Detached Status = "detached" 170 ) 171 172 const ( 173 // Status values specific to models. 174 175 // Available indicates that the model is available for use. 176 Available Status = "available" 177 178 // Busy indicates that the model is not available for use because it is 179 // running a process that must take the model offline, such as a migration, 180 // upgrade, or backup. This is a spinning state, it is not an error state, 181 // and it should be expected that the model will eventually go back to 182 // available. 183 Busy Status = "busy" 184 ) 185 186 const ( 187 // Status values specific to relations. 188 189 // Joining is used to signify that a relation should become joined soon. 190 Joining Status = "joining" 191 192 // Joined is the normal status for a healthy, alive relation. 193 Joined Status = "joined" 194 195 // Broken is the status for when a relation life goes to Dead. 196 Broken Status = "broken" 197 198 // Suspended is used to signify that a relation will be temporarily broken 199 // pending action to resume it. 200 Suspending Status = "suspending" 201 202 // Suspended is used to signify that a relation is temporarily broken pending 203 // action to resume it. 204 Suspended Status = "suspended" 205 ) 206 207 const ( 208 // Status values that are common to several entities. 209 210 // Destroying indicates that the entity is being destroyed. 211 // 212 // This is valid for volumes, filesystems, and models. 213 Destroying Status = "destroying" 214 ) 215 216 // InstanceStatus 217 const ( 218 Empty Status = "" 219 Provisioning Status = "allocating" 220 Running Status = "running" 221 ProvisioningError Status = "provisioning error" 222 ) 223 224 const ( 225 MessageWaitForMachine = "waiting for machine" 226 MessageWaitForContainer = "waiting for container" 227 MessageInstallingAgent = "installing agent" 228 MessageInitializingAgent = "agent initializing" 229 MessageInstallingCharm = "installing charm software" 230 ) 231 232 func (status Status) KnownInstanceStatus() bool { 233 switch status { 234 case 235 Pending, 236 ProvisioningError, 237 Allocating, 238 Running, 239 Error, 240 Unknown: 241 return true 242 } 243 return false 244 } 245 246 // KnownAgentStatus returns true if status has a known value for an agent. 247 // It includes every status that has ever been valid for a unit or machine agent. 248 // This is used by the apiserver client facade to filter out unknown values. 249 func (status Status) KnownAgentStatus() bool { 250 switch status { 251 case 252 Allocating, 253 Error, 254 Failed, 255 Rebooting, 256 Executing, 257 Idle: 258 return true 259 } 260 return false 261 } 262 263 // KnownWorkloadStatus returns true if status has a known value for a workload. 264 // It includes every status that has ever been valid for a unit agent. 265 // This is used by the apiserver client facade to filter out unknown values. 266 func (status Status) KnownWorkloadStatus() bool { 267 if ValidWorkloadStatus(status) { 268 return true 269 } 270 switch status { 271 case Error: // include error so that we can filter on what the spec says is valid 272 return true 273 default: 274 return false 275 } 276 } 277 278 // ValidWorkloadStatus returns true if status has a valid value (that is to say, 279 // a value that it's OK to set) for units or applications. 280 func ValidWorkloadStatus(status Status) bool { 281 switch status { 282 case 283 Blocked, 284 Maintenance, 285 Waiting, 286 Active, 287 Unknown, 288 Terminated: 289 return true 290 default: 291 return false 292 } 293 } 294 295 // WorkloadMatches returns true if the candidate matches status, 296 // taking into account that the candidate may be a legacy 297 // status value which has been deprecated. 298 func (status Status) WorkloadMatches(candidate Status) bool { 299 return status == candidate 300 } 301 302 // ValidModelStatus returns true if status has a valid value (that is to say, 303 // a value that it's OK to set) for models. 304 func ValidModelStatus(status Status) bool { 305 switch status { 306 case 307 Available, 308 Busy, 309 Destroying, 310 Error: 311 return true 312 default: 313 return false 314 } 315 } 316 317 // Matches returns true if the candidate matches status, 318 // taking into account that the candidate may be a legacy 319 // status value which has been deprecated. 320 func (status Status) Matches(candidate Status) bool { 321 return status == candidate 322 }