OLD | NEW |
1 package uniter | 1 package uniter |
2 | 2 |
3 import ( | 3 import ( |
4 "fmt" | 4 "fmt" |
5 "launchpad.net/juju-core/charm" | 5 "launchpad.net/juju-core/charm" |
6 "launchpad.net/juju-core/log" | 6 "launchpad.net/juju-core/log" |
7 "launchpad.net/juju-core/state" | 7 "launchpad.net/juju-core/state" |
8 "launchpad.net/juju-core/state/watcher" | 8 "launchpad.net/juju-core/state/watcher" |
9 "launchpad.net/juju-core/worker" | 9 "launchpad.net/juju-core/worker" |
10 "launchpad.net/tomb" | 10 "launchpad.net/tomb" |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 // once we receive the initial change, we unblock discard requests by | 185 // once we receive the initial change, we unblock discard requests by |
186 // setting this channel to its namesake on f. | 186 // setting this channel to its namesake on f. |
187 var discardConfig chan struct{} | 187 var discardConfig chan struct{} |
188 for { | 188 for { |
189 var ok bool | 189 var ok bool |
190 select { | 190 select { |
191 case <-f.tomb.Dying(): | 191 case <-f.tomb.Dying(): |
192 return tomb.ErrDying | 192 return tomb.ErrDying |
193 | 193 |
194 // Handle watcher changes. | 194 // Handle watcher changes. |
195 » » case f.unit, ok = <-unitw.Changes(): | 195 » » case _, ok = <-unitw.Changes(): |
196 log.Debugf("worker/uniter/filter: got unit change") | 196 log.Debugf("worker/uniter/filter: got unit change") |
197 if !ok { | 197 if !ok { |
198 return watcher.MustErr(unitw) | 198 return watcher.MustErr(unitw) |
199 } | 199 } |
200 if err = f.unitChanged(); err != nil { | 200 if err = f.unitChanged(); err != nil { |
201 return err | 201 return err |
202 } | 202 } |
203 » » case f.service, ok = <-servicew.Changes(): | 203 » » case _, ok = <-servicew.Changes(): |
204 log.Debugf("worker/uniter/filter: got service change") | 204 log.Debugf("worker/uniter/filter: got service change") |
205 if !ok { | 205 if !ok { |
206 return watcher.MustErr(servicew) | 206 return watcher.MustErr(servicew) |
207 } | 207 } |
208 if err = f.serviceChanged(); err != nil { | 208 if err = f.serviceChanged(); err != nil { |
209 return err | 209 return err |
210 } | 210 } |
211 case _, ok := <-configw.Changes(): | 211 case _, ok := <-configw.Changes(): |
212 log.Debugf("worker/uniter/filter: got config change") | 212 log.Debugf("worker/uniter/filter: got config change") |
213 if !ok { | 213 if !ok { |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
254 case <-discardConfig: | 254 case <-discardConfig: |
255 log.Debugf("filter: discarded config event") | 255 log.Debugf("filter: discarded config event") |
256 f.outConfig = nil | 256 f.outConfig = nil |
257 } | 257 } |
258 } | 258 } |
259 panic("unreachable") | 259 panic("unreachable") |
260 } | 260 } |
261 | 261 |
262 // unitChanged responds to changes in the unit. | 262 // unitChanged responds to changes in the unit. |
263 func (f *filter) unitChanged() error { | 263 func (f *filter) unitChanged() error { |
| 264 if err := f.unit.Refresh(); err != nil { |
| 265 if state.IsNotFound(err) { |
| 266 return worker.ErrDead |
| 267 } |
| 268 return err |
| 269 } |
264 if f.life != f.unit.Life() { | 270 if f.life != f.unit.Life() { |
265 switch f.life = f.unit.Life(); f.life { | 271 switch f.life = f.unit.Life(); f.life { |
266 case state.Dying: | 272 case state.Dying: |
267 log.Printf("worker/uniter: unit is dying") | 273 log.Printf("worker/uniter: unit is dying") |
268 close(f.outUnitDying) | 274 close(f.outUnitDying) |
269 f.outUpgrade = nil | 275 f.outUpgrade = nil |
270 case state.Dead: | 276 case state.Dead: |
271 log.Printf("worker/uniter: unit is dead") | 277 log.Printf("worker/uniter: unit is dead") |
272 return worker.ErrDead | 278 return worker.ErrDead |
273 } | 279 } |
274 } | 280 } |
275 if resolved := f.unit.Resolved(); resolved != f.resolved { | 281 if resolved := f.unit.Resolved(); resolved != f.resolved { |
276 f.resolved = resolved | 282 f.resolved = resolved |
277 if f.resolved != state.ResolvedNone { | 283 if f.resolved != state.ResolvedNone { |
278 f.outResolved = f.outResolvedOn | 284 f.outResolved = f.outResolvedOn |
279 } | 285 } |
280 } | 286 } |
281 return nil | 287 return nil |
282 } | 288 } |
283 | 289 |
284 // serviceChanged responds to changes in the service. | 290 // serviceChanged responds to changes in the service. |
285 func (f *filter) serviceChanged() error { | 291 func (f *filter) serviceChanged() error { |
| 292 if err := f.service.Refresh(); err != nil { |
| 293 if state.IsNotFound(err) { |
| 294 return fmt.Errorf("service unexpectedly removed") |
| 295 } |
| 296 return err |
| 297 } |
286 url, force := f.service.CharmURL() | 298 url, force := f.service.CharmURL() |
287 f.upgradeAvailable = serviceCharm{url, force} | 299 f.upgradeAvailable = serviceCharm{url, force} |
288 switch f.service.Life() { | 300 switch f.service.Life() { |
289 case state.Dying: | 301 case state.Dying: |
290 if err := f.unit.EnsureDying(); err != nil { | 302 if err := f.unit.EnsureDying(); err != nil { |
291 return err | 303 return err |
292 } | 304 } |
293 case state.Dead: | 305 case state.Dead: |
294 return fmt.Errorf("service unexpectedly dead") | 306 return fmt.Errorf("service unexpectedly dead") |
295 } | 307 } |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
339 } | 351 } |
340 | 352 |
341 // serviceCharm holds information about a charm. | 353 // serviceCharm holds information about a charm. |
342 type serviceCharm struct { | 354 type serviceCharm struct { |
343 url *charm.URL | 355 url *charm.URL |
344 force bool | 356 force bool |
345 } | 357 } |
346 | 358 |
347 // nothing is marginally more pleasant to read than "struct{}{}". | 359 // nothing is marginally more pleasant to read than "struct{}{}". |
348 var nothing = struct{}{} | 360 var nothing = struct{}{} |
OLD | NEW |