OLD | NEW |
1 // hook provides types and constants that define the hooks known to Juju, | 1 // hook provides types and constants that define the hooks known to Juju, |
2 // and implements persistence of hook execution state. | 2 // and implements persistence of hook execution state. |
3 package hook | 3 package hook |
4 | 4 |
5 import ( | 5 import ( |
6 "errors" | 6 "errors" |
7 "fmt" | 7 "fmt" |
8 "launchpad.net/juju-core/trivial" | 8 "launchpad.net/juju-core/trivial" |
9 "os" | 9 "os" |
10 ) | 10 ) |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 // for the member units, but these are communicated only when already | 81 // for the member units, but these are communicated only when already |
82 // known to the producer: their presence should never be assumed. The | 82 // known to the producer: their presence should never be assumed. The |
83 // field is only set when Kind identifies a relation hook. | 83 // field is only set when Kind identifies a relation hook. |
84 Members map[string]map[string]interface{} | 84 Members map[string]map[string]interface{} |
85 } | 85 } |
86 | 86 |
87 // Status defines the stages of execution through which a hook passes. | 87 // Status defines the stages of execution through which a hook passes. |
88 type Status string | 88 type Status string |
89 | 89 |
90 const ( | 90 const ( |
91 » // StatusStarted indicates that the unit agent intended to run the hook. | 91 » // Queued indicates that the hook should be executed at the earliest |
92 » // This status implies that a hook *may* have been interrupted and have | 92 » // opportunity. |
93 » // failed to complete all required operations, and that therefore the | 93 » Queued Status = "queued" |
94 » // proper response is to treat it as a hook execution failure and punt | |
95 » // to the user for manual resolution. | |
96 » StatusStarted Status = "started" | |
97 | 94 |
98 » // StatusSucceeded indicates that the hook itself completed successfully
, | 95 » // Pending indicates that execution of the hook is pending. A hook |
99 » // but that local state (ie relation membership) may not have been | 96 » // that fails should keep this status until it is successfully re- |
100 » // synchronized, and that recovery should therefore be performed. | 97 » // executed or skipped. |
101 » StatusSucceeded Status = "succeeded" | 98 » Pending Status = "pending" |
102 | 99 |
103 » // StatusCommitted indicates that the last hook ran successfully and tha
t | 100 » // Committing indicates that execution of the hook has successfully |
104 » // local state has been synchronized. | 101 » // completed, or that the hook has been skipped, but that persistent |
105 » StatusCommitted Status = "committed" | 102 » // local state has not been synchronized with the change embodied by |
| 103 » // the hook. |
| 104 » Committing Status = "committing" |
| 105 |
| 106 » // Complete indicates that all operations associated with the hook have |
| 107 » // succeeded. |
| 108 » Complete Status = "complete" |
106 ) | 109 ) |
107 | 110 |
108 // valid will return true if the Status is known. | 111 // valid will return true if the Status is known. |
109 func (status Status) valid() bool { | 112 func (status Status) valid() bool { |
110 switch status { | 113 switch status { |
111 » case StatusStarted, StatusSucceeded, StatusCommitted: | 114 » case Queued, Pending, Committing, Complete: |
112 return true | 115 return true |
113 } | 116 } |
114 return false | 117 return false |
115 } | 118 } |
116 | 119 |
117 // State holds details necessary for executing a hook, and the | 120 // State holds details necessary for executing a hook, and the |
118 // status of the execution. | 121 // status of the execution. |
119 type State struct { | 122 type State struct { |
120 Info Info | 123 Info Info |
121 Status Status | 124 Status Status |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 | 190 |
188 // state defines the hook state serialization. | 191 // state defines the hook state serialization. |
189 type state struct { | 192 type state struct { |
190 Kind Kind | 193 Kind Kind |
191 RelationId int `yaml:"relation-id,omitempty"` | 194 RelationId int `yaml:"relation-id,omitempty"` |
192 RemoteUnit string `yaml:"remote-unit,omitempty"` | 195 RemoteUnit string `yaml:"remote-unit,omitempty"` |
193 ChangeVersion int `yaml:"change-version,omitempty"` | 196 ChangeVersion int `yaml:"change-version,omitempty"` |
194 Members []string `yaml:"members,omitempty"` | 197 Members []string `yaml:"members,omitempty"` |
195 Status Status | 198 Status Status |
196 } | 199 } |
OLD | NEW |