Example #1
0
File: uniter.go Project: bac/juju
// 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
}
Example #2
0
func (s *actionsSuite) TestWatchOneActionReceiverNotifications(c *gc.C) {
	expectErr := errors.New("zwoosh")
	registerFunc := func(common.Resource) string { return "bambalam" }
	tagToActionReceiver := common.TagToActionReceiverFn(makeFindEntity(map[string]state.Entity{
		"machine-1": &fakeActionReceiver{watcher: &fakeWatcher{}},
		"machine-2": &fakeActionReceiver{watcher: &fakeWatcher{err: expectErr}},
	}))

	watchOneFn := common.WatchOneActionReceiverNotifications(tagToActionReceiver, registerFunc)

	for i, test := range []struct {
		tag       names.Tag
		err       string
		watcherId string
	}{{
		tag: names.NewMachineTag("0"),
		err: "id not found",
	}, {
		tag:       names.NewMachineTag("1"),
		watcherId: "bambalam",
	}, {
		tag: names.NewMachineTag("2"),
		err: "zwoosh",
	}} {
		c.Logf("test %d", i)
		c.Logf(test.tag.String())
		result, err := watchOneFn(test.tag)
		if test.err != "" {
			c.Check(err, gc.ErrorMatches, test.err)
			c.Check(result, jc.DeepEquals, params.StringsWatchResult{})
		} else {
			c.Check(err, jc.ErrorIsNil)
			c.Check(result.StringsWatcherId, gc.Equals, test.watcherId)
		}
	}
}
Example #3
0
// 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)
}