// WatchUpgradeSeriesNotifications mocks base method
484571
func (m *MockFacade) WatchUpgradeSeriesNotifications() (watcher.NotifyWatcher, error) {
	ret := m.ctrl.Call(m, "WatchUpgradeSeriesNotifications")
	ret0, _ := ret[0].(watcher.NotifyWatcher)
	ret1, _ := ret[1].(error)
	return ret0, ret1
}
349155
func (api *InstanceMutaterAPI) WatchLXDProfileVerificationNeeded(args params.Entities) (params.NotifyWatchResults, error) {
	result := params.NotifyWatchResults{
		Results: make([]params.NotifyWatchResult, len(args.Entities)),
	}
	if len(args.Entities) == 0 {
		return result, nil
	}
	canAccess, err := api.getAuthFunc()
	if err != nil {
		return result, errors.Trace(err)
	}
	for i, entity := range args.Entities {
		tag, err := names.ParseMachineTag(entity.Tag)
		if err != nil {
			result.Results[i].Error = common.ServerError(common.ErrPerm)
			continue
		}
		entityResult, err := api.watchOneEntityApplication(canAccess, tag)
		result.Results[i] = entityResult
		result.Results[i].Error = common.ServerError(err)
	}
	return result, nil
}
1090762
func (api *CrossControllerAPI) WatchControllerInfo() (params.NotifyWatchResults, error) {
	results := params.NotifyWatchResults{
		Results: make([]params.NotifyWatchResult, 1),
	}
	w := api.watchLocalControllerInfo()
	if _, ok := <-w.Changes(); !ok {
		results.Results[0].Error = common.ServerError(watcher.EnsureErr(w))
		return results, nil
	}
	results.Results[0].NotifyWatcherId = api.resources.Register(w)
	return results, nil
}
749061
func (m *Machine) GetUpgradeSeriesMessages() ([]string, bool, error) {
	lock, err := m.getUpgradeSeriesLock()
	if errors.IsNotFound(err) {
		// If the lock is not found here then there are no more messages
		return nil, true, nil
	}
	if err != nil {
		return nil, false, errors.Trace(err)
	}
	// finished means that a subsequent call to this method, while the
	// Machine Lock is of a similar Machine Status, would return no
	// additional messages (notifications). Since the value of this variable
	// is returned, callers may choose to close streams or stop watchers
	// based on this information.
	finished := lock.MachineStatus == model.UpgradeSeriesCompleted ||
		lock.MachineStatus == model.UpgradeSeriesPrepareCompleted
	// Filter seen messages
	unseenMessages := make([]UpgradeSeriesMessage, 0)
	for _, upgradeSeriesMessage := range lock.Messages {
		if !upgradeSeriesMessage.Seen {
			unseenMessages = append(unseenMessages, upgradeSeriesMessage)
		}
	}
	if len(unseenMessages) == 0 {
		return []string{}, finished, nil
	}
	sort.Slice(unseenMessages, func(i, j int) bool {
		return unseenMessages[i].Timestamp.Before(unseenMessages[j].Timestamp)
	})
	messages := make([]string, 0)
	for _, unseenMessage := range unseenMessages {
		messages = append(messages, unseenMessage.Message)
	}
	err = m.SetUpgradeSeriesMessagesAsSeen(lock.Messages)
	if err != nil {
		return nil, false, errors.Trace(err)
	}
	return messages, finished, nil
}
1071859
func (c *Client) WatchActionNotifications(agent names.MachineTag) (watcher.StringsWatcher, error) {
	var results params.StringsWatchResults
	args := params.Entities{
		Entities: []params.Entity{{Tag: agent.String()}},
	}

	err := c.facade.FacadeCall("WatchActionNotifications", args, &results)
	if err != nil {
		return nil, errors.Trace(err)
	}

	if len(results.Results) != 1 {
		return nil, errors.Errorf("expected 1 result, got %d", len(results.Results))
	}

	result := results.Results[0]
	if result.Error != nil {
		return nil, errors.Trace(result.Error)
	}
	w := apiwatcher.NewStringsWatcher(c.facade.RawAPICaller(), result)
	return w, nil
}
1057091
func (u *Unit) WatchLXDProfileUpgradeNotifications() (StringsWatcher, error) {
	app, err := u.Application()
	if err != nil {
		return nil, errors.Trace(err)
	}
	watchDocId := app.doc.DocID
	return watchInstanceCharmProfileCompatibilityData(u.st, watchDocId), nil
}
461947
func (m *MockUpgradeSeriesMachine) UpdateMachineSeries(arg0 string, arg1 bool) error {
	ret := m.ctrl.Call(m, "UpdateMachineSeries", arg0, arg1)
	ret0, _ := ret[0].(error)
	return ret0
}
63023
func (mr *MockLXDProfileUnitMockRecorder) WatchLXDProfileUpgradeNotifications() *gomock.Call {
	return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "WatchLXDProfileUpgradeNotifications", reflect.TypeOf((*MockLXDProfileUnit)(nil).WatchLXDProfileUpgradeNotifications))
}
107918
func (u *UnitUpgraderAPI) WatchAPIVersion(args params.Entities) (params.NotifyWatchResults, error) {
	result := params.NotifyWatchResults{
		Results: make([]params.NotifyWatchResult, len(args.Entities)),
	}
	for i, agent := range args.Entities {
		tag, err := names.ParseTag(agent.Tag)
		if err != nil {
			result.Results[i].Error = common.ServerError(common.ErrPerm)
			continue
		}
		err = common.ErrPerm
		if u.authorizer.AuthOwner(tag) {
			var watcherId string
			watcherId, err = u.watchAssignedMachine(tag)
			if err == nil {
				result.Results[i].NotifyWatcherId = watcherId
			}
		}
		result.Results[i].Error = common.ServerError(err)
	}
	return result, nil
}
384242
func (m *Machine) SetUpgradeSeriesUnitStatus(unitName string, status model.UpgradeSeriesStatus, message string) error {
	buildTxn := func(attempt int) ([]txn.Op, error) {
		if attempt > 0 {
			if err := m.Refresh(); err != nil {
				return nil, errors.Trace(err)
			}
		}
		if err := m.isStillAlive(); err != nil {
			return nil, errors.Trace(err)
		}
		canUpdate, err := m.verifyUnitUpgradeSeriesStatus(unitName, status)
		if err != nil {
			return nil, errors.Trace(err)
		}
		if !canUpdate {
			return nil, jujutxn.ErrNoOperations
		}
		timestamp := bson.Now()
		updateMessage := newUpgradeSeriesMessage(unitName, message, timestamp)
		return setUpgradeSeriesTxnOps(m.doc.Id, unitName, status, timestamp, updateMessage)
	}
	err := m.st.db().Run(buildTxn)
	if err != nil {
		err = onAbort(err, ErrDead)
		return err
	}
	return nil
}
548010
func (f *Facade) WatchActionNotifications(args params.Entities) params.StringsWatchResults {
	tagToActionReceiver := f.backend.TagToActionReceiverFn(f.backend.FindEntity)
	watchOne := common.WatchOneActionReceiverNotifications(tagToActionReceiver, f.resources.Register)
	return common.WatchActionNotifications(args, f.accessMachine, watchOne)
}
212722
func (b *backend) WatchModelCredential() (state.NotifyWatcher, error) {
	m, err := b.Model()
	if err != nil {
		return nil, errors.Trace(err)
	}
	return m.WatchModelCredential(), nil
}
1053261
func (u *UpgradeSeriesAPI) SetUpgradeSeriesUnitStatus(status model.UpgradeSeriesStatus, reason string) error {
	var results params.ErrorResults
	args := params.UpgradeSeriesStatusParams{
		Params: []params.UpgradeSeriesStatusParam{{
			Entity:  params.Entity{Tag: u.tag.String()},
			Status:  status,
			Message: reason,
		}},
	}
	err := u.facade.FacadeCall("SetUpgradeSeriesUnitStatus", args, &results)
	if err != nil {
		return err
	}
	if len(results.Results) != 1 {
		return errors.Errorf("expected 1 result, got %d", len(results.Results))
	}
	result := results.Results[0]
	if result.Error != nil {
		return result.Error
	}
	return nil
}
284566
func (u *LXDProfileAPI) WatchLXDProfileUpgradeNotifications(args params.LXDProfileUpgrade) (params.StringsWatchResults, error) {
	u.logger.Tracef("Starting WatchLXDProfileUpgradeNotifications with %+v", args)
	result := params.StringsWatchResults{
		Results: make([]params.StringsWatchResult, len(args.Entities)),
	}
	canAccess, err := u.accessUnit()
	if err != nil {
		return params.StringsWatchResults{}, err
	}
	for i, entity := range args.Entities {
		tag, err := names.ParseTag(entity.Tag)
		if err != nil {
			result.Results[i].Error = common.ServerError(common.ErrPerm)
			continue
		}

		if !canAccess(tag) {
			result.Results[i].Error = common.ServerError(common.ErrPerm)
			continue
		}
		machine, err := u.getLXDProfileMachine(tag)
		if err != nil {
			result.Results[i].Error = common.ServerError(err)
			continue
		}

		watcherId, initial, err := u.watchOneChangeLXDProfileUpgradeNotifications(machine, args.ApplicationName)
		if err != nil {
			result.Results[i].Error = common.ServerError(err)
			continue
		}

		result.Results[i].StringsWatcherId = watcherId
		result.Results[i].Changes = initial
	}
	return result, nil
}
5343
func (mr *MockFacadeMockRecorder) FinishUpgradeSeries(arg0 interface{}) *gomock.Call {
	return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "FinishUpgradeSeries", reflect.TypeOf((*MockFacade)(nil).FinishUpgradeSeries), arg0)
}
812216
func (m *Manager) NotifyStateChance() {
	m.Lock()
	defer m.Unlock()

	for _, watcher := range m.watchers {
		watcher.NotifyStateChance()
	}
}
602114
func (a *Application) WatchScale() NotifyWatcher {
	currentScale := -1
	filter := func(id interface{}) bool {
		k, err := a.st.strictLocalID(id.(string))
		if err != nil {
			return false
		}
		if k != a.doc.Name {
			return false
		}
		applications, closer := a.st.db().GetCollection(applicationsC)
		defer closer()

		var scaleField = bson.D{{"scale", 1}}
		var doc *applicationDoc
		if err := applications.FindId(k).Select(scaleField).One(&doc); err != nil {
			return false
		}
		match := doc.DesiredScale != currentScale
		currentScale = doc.DesiredScale
		return match
	}
	return newNotifyCollWatcher(a.st, applicationsC, filter)
}