Exemple #1
0
// WatchActionNotifications returns a StringsWatcher for observing
// incoming action calls to a unit. See also state/watcher.go
// Unit.WatchActionNotifications(). This method is called from
// api/uniter/uniter.go WatchActionNotifications().
func (u *UniterAPIV3) WatchActionNotifications(args params.Entities) (params.StringsWatchResults, error) {
	tagToActionReceiver := common.TagToActionReceiverFn(u.st.FindEntity)
	watchOne := common.WatchOneActionReceiverNotifications(tagToActionReceiver, u.resources.Register)
	canAccess, err := u.accessUnit()
	if err != nil {
		return params.StringsWatchResults{}, err
	}
	return common.WatchActionNotifications(args, canAccess, watchOne), nil
}
Exemple #2
0
func (s *actionsSuite) TestWatchActionNotifications(c *gc.C) {
	args := entities("invalid-actionreceiver", "machine-1", "machine-2", "machine-3")
	canAccess := makeCanAccess(map[names.Tag]bool{
		names.NewMachineTag("2"): true,
		names.NewMachineTag("3"): true,
	})
	expectedStringsWatchResult := params.StringsWatchResult{
		StringsWatcherId: "orosu",
	}
	watchOne := makeWatchOne(map[names.Tag]params.StringsWatchResult{
		names.NewMachineTag("3"): expectedStringsWatchResult,
	})

	results := common.WatchActionNotifications(args, canAccess, watchOne)

	c.Assert(results, jc.DeepEquals, params.StringsWatchResults{
		[]params.StringsWatchResult{
			{Error: common.ServerError(errors.New(`invalid actionreceiver tag "invalid-actionreceiver"`))},
			{Error: common.ServerError(common.ErrPerm)},
			{Error: common.ServerError(errors.New("pax"))},
			{StringsWatcherId: "orosu"},
		},
	})
}
// WatchActionNotifications returns a StringsWatcher for observing
// incoming action calls to a machine.
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)
}