OLD | NEW |
1 package state | 1 package state |
2 | 2 |
3 import ( | 3 import ( |
4 "fmt" | 4 "fmt" |
5 "labix.org/v2/mgo" | 5 "labix.org/v2/mgo" |
6 "launchpad.net/juju-core/log" | |
7 "launchpad.net/juju-core/state/api/params" | 6 "launchpad.net/juju-core/state/api/params" |
8 "launchpad.net/juju-core/state/multiwatcher" | 7 "launchpad.net/juju-core/state/multiwatcher" |
9 "launchpad.net/juju-core/state/watcher" | 8 "launchpad.net/juju-core/state/watcher" |
10 "reflect" | 9 "reflect" |
11 "strings" | 10 "strings" |
12 ) | 11 ) |
13 | 12 |
14 // allWatcherStateBacking implements allWatcherBacking by | 13 // allWatcherStateBacking implements allWatcherBacking by |
15 // fetching entities from the State. | 14 // fetching entities from the State. |
16 type allWatcherStateBacking struct { | 15 type allWatcherStateBacking struct { |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
218 | 217 |
219 func (a *backingAnnotation) mongoId() interface{} { | 218 func (a *backingAnnotation) mongoId() interface{} { |
220 return a.GlobalKey | 219 return a.GlobalKey |
221 } | 220 } |
222 | 221 |
223 type backingStatus statusDoc | 222 type backingStatus statusDoc |
224 | 223 |
225 func (s *backingStatus) updated(st *State, store *multiwatcher.Store, id interfa
ce{}) error { | 224 func (s *backingStatus) updated(st *State, store *multiwatcher.Store, id interfa
ce{}) error { |
226 parentId, ok := backingEntityIdForGlobalKey(id.(string)) | 225 parentId, ok := backingEntityIdForGlobalKey(id.(string)) |
227 if !ok { | 226 if !ok { |
228 log.Errorf("status for entity with unrecognised global key %q",
id) | |
229 return nil | 227 return nil |
230 } | 228 } |
231 info0 := store.Get(parentId) | 229 info0 := store.Get(parentId) |
232 switch info := info0.(type) { | 230 switch info := info0.(type) { |
233 case nil: | 231 case nil: |
234 // The parent info doesn't exist. Ignore the status until it doe
s. | 232 // The parent info doesn't exist. Ignore the status until it doe
s. |
235 return nil | 233 return nil |
236 case *params.UnitInfo: | 234 case *params.UnitInfo: |
237 newInfo := *info | 235 newInfo := *info |
238 newInfo.Status = s.Status | 236 newInfo.Status = s.Status |
(...skipping 19 matching lines...) Expand all Loading... |
258 | 256 |
259 func (a *backingStatus) mongoId() interface{} { | 257 func (a *backingStatus) mongoId() interface{} { |
260 panic("cannot find mongo id from status document") | 258 panic("cannot find mongo id from status document") |
261 } | 259 } |
262 | 260 |
263 type backingConstraints constraintsDoc | 261 type backingConstraints constraintsDoc |
264 | 262 |
265 func (s *backingConstraints) updated(st *State, store *multiwatcher.Store, id in
terface{}) error { | 263 func (s *backingConstraints) updated(st *State, store *multiwatcher.Store, id in
terface{}) error { |
266 parentId, ok := backingEntityIdForGlobalKey(id.(string)) | 264 parentId, ok := backingEntityIdForGlobalKey(id.(string)) |
267 if !ok { | 265 if !ok { |
268 log.Errorf("constraints for entity with unrecognised global key
%q", id) | |
269 return nil | 266 return nil |
270 } | 267 } |
271 info0 := store.Get(parentId) | 268 info0 := store.Get(parentId) |
272 switch info := info0.(type) { | 269 switch info := info0.(type) { |
273 case nil: | 270 case nil: |
274 // The parent info doesn't exist. Ignore the status until it doe
s. | 271 // The parent info doesn't exist. Ignore the status until it doe
s. |
275 return nil | 272 return nil |
276 case *params.UnitInfo, *params.MachineInfo: | 273 case *params.UnitInfo, *params.MachineInfo: |
277 // We don't (yet) publish unit or machine constraints. | 274 // We don't (yet) publish unit or machine constraints. |
278 return nil | 275 return nil |
(...skipping 14 matching lines...) Expand all Loading... |
293 | 290 |
294 func (a *backingConstraints) mongoId() interface{} { | 291 func (a *backingConstraints) mongoId() interface{} { |
295 panic("cannot find mongo id from constraints document") | 292 panic("cannot find mongo id from constraints document") |
296 } | 293 } |
297 | 294 |
298 type backingSettings map[string]interface{} | 295 type backingSettings map[string]interface{} |
299 | 296 |
300 func (s *backingSettings) updated(st *State, store *multiwatcher.Store, id inter
face{}) error { | 297 func (s *backingSettings) updated(st *State, store *multiwatcher.Store, id inter
face{}) error { |
301 parentId, url, ok := backingEntityIdForSettingsKey(id.(string)) | 298 parentId, url, ok := backingEntityIdForSettingsKey(id.(string)) |
302 if !ok { | 299 if !ok { |
303 log.Errorf("settings for entity with unrecognized key %q", id) | |
304 return nil | 300 return nil |
305 } | 301 } |
306 info0 := store.Get(parentId) | 302 info0 := store.Get(parentId) |
307 switch info := info0.(type) { | 303 switch info := info0.(type) { |
308 case nil: | 304 case nil: |
309 // The parent info doesn't exist. Ignore the status until it doe
s. | 305 // The parent info doesn't exist. Ignore the status until it doe
s. |
310 return nil | 306 return nil |
311 case *params.ServiceInfo: | 307 case *params.ServiceInfo: |
312 // If we're seeing settings for the service with a different | 308 // If we're seeing settings for the service with a different |
313 // charm URL, we ignore them - we will fetch | 309 // charm URL, we ignore them - we will fetch |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
514 // in, such as settings changes to entities we don't care about. | 510 // in, such as settings changes to entities we don't care about. |
515 err := c.FindId(change.Id).One(doc) | 511 err := c.FindId(change.Id).One(doc) |
516 if err == mgo.ErrNotFound { | 512 if err == mgo.ErrNotFound { |
517 return doc.removed(b.st, all, change.Id) | 513 return doc.removed(b.st, all, change.Id) |
518 } | 514 } |
519 if err != nil { | 515 if err != nil { |
520 return err | 516 return err |
521 } | 517 } |
522 return doc.updated(b.st, all, change.Id) | 518 return doc.updated(b.st, all, change.Id) |
523 } | 519 } |
OLD | NEW |