예제 #1
0
// Update modifies the queue such that the hook.Info values it sends will
// reflect the supplied change.
func (q *liveSource) Update(change multiwatcher.RelationUnitsChange) error {
	if !q.started {
		q.started = true
		// The first event represents the ideal final state of the system.
		// If it contains any Departed notifications, it cannot be one of
		// those -- most likely the watcher was not a fresh one -- and we're
		// completely hosed.
		if len(change.Departed) != 0 {
			return errors.Errorf("hook source watcher sent bad event: %#v", change)
		}
		// Anyway, before we can generate actual hooks, we have to generate
		// departed hooks for any previously-known members not reflected in
		// the ideal state, and insert those at the head of the queue. The
		// easiest way to do this is to inject a departure update for those
		// missing members before processing the ideal state.
		departs := multiwatcher.RelationUnitsChange{}
		for unit := range q.info {
			if _, found := change.Changed[unit]; !found {
				departs.Departed = append(departs.Departed, unit)
			}
		}
		q.update(departs)
	}
	q.update(change)
	return nil
}
예제 #2
0
func (d send) event() multiwatcher.RelationUnitsChange {
	ruc := multiwatcher.RelationUnitsChange{Changed: map[string]multiwatcher.UnitSettings{}}
	for name, version := range d.changed {
		ruc.Changed[name] = multiwatcher.UnitSettings{Version: version}
	}
	for _, name := range d.departed {
		ruc.Departed = append(ruc.Departed, name)
	}
	return ruc
}