github.com/wallyworld/juju@v0.0.0-20161013125918-6cf1bc9d917a/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), service (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 service 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 services 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 a service 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 179 const ( 180 // Status values that are common to several entities. 181 182 // Destroying indicates that the entity is being destroyed. 183 // 184 // This is valid for volumes, filesystems, and models. 185 Destroying Status = "destroying" 186 ) 187 188 // InstanceStatus 189 const ( 190 Empty Status = "" 191 Provisioning Status = "allocating" 192 Running Status = "running" 193 ProvisioningError Status = "provisioning error" 194 ) 195 196 const ( 197 MessageWaitForMachine = "waiting for machine" 198 MessageInstallingAgent = "installing agent" 199 MessageInitializingAgent = "agent initializing" 200 MessageInstallingCharm = "installing charm software" 201 ) 202 203 func (status Status) KnownInstanceStatus() bool { 204 switch status { 205 case 206 Pending, 207 ProvisioningError, 208 Allocating, 209 Running, 210 Unknown: 211 return true 212 } 213 return false 214 } 215 216 // KnownAgentStatus returns true if status has a known value for an agent. 217 // It includes every status that has ever been valid for a unit or machine agent. 218 // This is used by the apiserver client facade to filter out unknown values. 219 func (status Status) KnownAgentStatus() bool { 220 switch status { 221 case 222 Allocating, 223 Error, 224 Failed, 225 Rebooting, 226 Executing, 227 Idle: 228 return true 229 } 230 return false 231 } 232 233 // KnownWorkloadStatus returns true if status has a known value for a workload. 234 // It includes every status that has ever been valid for a unit agent. 235 // This is used by the apiserver client facade to filter out unknown values. 236 func (status Status) KnownWorkloadStatus() bool { 237 if ValidWorkloadStatus(status) { 238 return true 239 } 240 switch status { 241 case Error: // include error so that we can filter on what the spec says is valid 242 return true 243 default: 244 return false 245 } 246 } 247 248 // ValidWorkloadStatus returns true if status has a valid value (that is to say, 249 // a value that it's OK to set) for units or services. 250 func ValidWorkloadStatus(status Status) bool { 251 switch status { 252 case 253 Blocked, 254 Maintenance, 255 Waiting, 256 Active, 257 Unknown, 258 Terminated: 259 return true 260 default: 261 return false 262 } 263 } 264 265 // WorkloadMatches returns true if the candidate matches status, 266 // taking into account that the candidate may be a legacy 267 // status value which has been deprecated. 268 func (status Status) WorkloadMatches(candidate Status) bool { 269 return status == candidate 270 } 271 272 // ValidModelStatus returns true if status has a valid value (that is to say, 273 // a value that it's OK to set) for models. 274 func ValidModelStatus(status Status) bool { 275 switch status { 276 case 277 Available, 278 Destroying: 279 return true 280 default: 281 return false 282 } 283 } 284 285 // Matches returns true if the candidate matches status, 286 // taking into account that the candidate may be a legacy 287 // status value which has been deprecated. 288 func (status Status) Matches(candidate Status) bool { 289 return status == candidate 290 }