BIND 10 master, updated. bf2a2aab27a29e23699f42c393ac31b324c7f096 Merge #2930
BIND 10 source code commits
bind10-changes at lists.isc.org
Fri May 24 08:23:49 UTC 2013
The branch, master has been updated
via bf2a2aab27a29e23699f42c393ac31b324c7f096 (commit)
via 1248e88ace533f61e4f8865fafa5f0c89470c6cd (commit)
via e8a9043a2508edd209a01facb71fe4bac4d9eceb (commit)
via cd146974efff9794c989296158c0e05997da1edf (commit)
via 4b68c9bb855e1cee112ed6a0c3dd398048930824 (commit)
via fafa0dd4a0c97aeef84b7c95ed624c3873ca4cb4 (commit)
via 85dff79c7ec72f5079dea7646baa557de2e98c5b (commit)
via 2ae9ac7bb5a19741eb21b0ccec951588c5672d1d (commit)
via e7591db5df9c7694e1e0e3f7dd3e2d77753999c1 (commit)
via 453f362d6c7bba06582e713b9fa243fa0b8ef5b7 (commit)
via c738282e2dabd4004dd451edc1d5dd36b4e59df7 (commit)
via 88fe64ea760b7c2f4e2f5d4fdcc8c298481b46b7 (commit)
via 143264e9d77c446e9f5d9f2611198bb73de82243 (commit)
via f3cd2b49392a4883751e2dbce2d8677e46d1f167 (commit)
from 26f8bf358b2eceec472e341f1f380bf9474913de (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit bf2a2aab27a29e23699f42c393ac31b324c7f096
Merge: 26f8bf3 1248e88
Author: Michal 'vorner' Vaner <vorner at vorner.cz>
Date: Fri May 24 09:05:22 2013 +0200
Merge #2930
Sending notifications over msgq.
No receiving end yet.
-----------------------------------------------------------------------
Summary of changes:
doc/design/ipc-high.txt | 4 +--
src/lib/cc/proto_defs.cc | 3 ++
src/lib/config/ccsession.cc | 16 +++++++++
src/lib/config/ccsession.h | 18 +++++++---
src/lib/config/tests/ccsession_unittests.cc | 40 +++++++++++++++++++++
src/lib/python/isc/config/ccsession.py | 36 +++++++++++++++++++
src/lib/python/isc/config/tests/ccsession_test.py | 26 ++++++++++++++
7 files changed, 136 insertions(+), 7 deletions(-)
-----------------------------------------------------------------------
diff --git a/doc/design/ipc-high.txt b/doc/design/ipc-high.txt
index 3f46b5c..5addb88 100644
--- a/doc/design/ipc-high.txt
+++ b/doc/design/ipc-high.txt
@@ -210,7 +210,7 @@ about changes to zone data, they'd subscribe to the
`Notifications/ZoneUpdates` group. Then, other client (let's say
`XfrIn`, with session ID `s12345`) would send something like:
- s12345 -> Notifications/ZoneUpdates
+ s12345 -> notifications/ZoneUpdates
{"notification": ["zone-update", {
"class": "IN",
"origin": "example.org.",
@@ -221,7 +221,7 @@ Both receivers would receive the message and know that the
`example.org` zone is now at version 123456. Note that multiple users
may produce the same kind of notification. Also, single group may be
used to send multiple notification names (but they should be related;
-in our example, the `Notifications/ZoneUpdates` could be used for
+in our example, the `notifications/ZoneUpdates` could be used for
`zone-update`, `zone-available` and `zone-unavailable` notifications
for change in zone data, configuration of new zone in the system and
removal of a zone from configuration).
diff --git a/src/lib/cc/proto_defs.cc b/src/lib/cc/proto_defs.cc
index 8f7fb91..2806c2a 100644
--- a/src/lib/cc/proto_defs.cc
+++ b/src/lib/cc/proto_defs.cc
@@ -43,6 +43,8 @@ const char* const CC_COMMAND_STOP = "stop";
// The wildcards of some headers
const char* const CC_TO_WILDCARD = "*";
const char* const CC_INSTANCE_WILDCARD = "*";
+// Prefixes for groups
+const char* const CC_GROUP_NOTIFICATION_PREFIX = "notifications/";
// Reply codes
const int CC_REPLY_NO_RECPT = -1;
const int CC_REPLY_SUCCESS = 0;
@@ -50,6 +52,7 @@ const int CC_REPLY_SUCCESS = 0;
const char *const CC_PAYLOAD_LNAME = "lname";
const char *const CC_PAYLOAD_RESULT = "result";
const char *const CC_PAYLOAD_COMMAND = "command";
+const char *const CC_PAYLOAD_NOTIFICATION = "notification";
}
}
diff --git a/src/lib/config/ccsession.cc b/src/lib/config/ccsession.cc
index d094ab9..0d43b27 100644
--- a/src/lib/config/ccsession.cc
+++ b/src/lib/config/ccsession.cc
@@ -884,5 +884,21 @@ ModuleCCSession::rpcCall(const std::string &command, const std::string &group,
}
}
+void
+ModuleCCSession::notify(const std::string& group, const std::string& name,
+ const ConstElementPtr& params)
+{
+ const ElementPtr message(Element::createMap());
+ const ElementPtr notification(Element::createList());
+ notification->add(Element::create(name));
+ if (params) {
+ notification->add(params);
+ }
+ message->set(isc::cc::CC_PAYLOAD_NOTIFICATION, notification);
+ groupSendMsg(message, isc::cc::CC_GROUP_NOTIFICATION_PREFIX + group,
+ isc::cc::CC_INSTANCE_WILDCARD,
+ isc::cc::CC_TO_WILDCARD, false);
+}
+
}
}
diff --git a/src/lib/config/ccsession.h b/src/lib/config/ccsession.h
index aee6518..04e3046 100644
--- a/src/lib/config/ccsession.h
+++ b/src/lib/config/ccsession.h
@@ -425,18 +425,26 @@ public:
params =
isc::data::ConstElementPtr());
- /// \brief Send a notification to subscribed clients
+ /// \brief Send a notification to subscribed users
///
- /// Send a notification message to all clients subscribed to the given
+ /// Send a notification message to all users subscribed to the given
/// notification group.
///
+ /// This method does not not block.
+ ///
+ /// See docs/design/ipc-high.txt for details about notifications and
+ /// the format of messages sent.
+ ///
+ /// \throw CCSessionError for low-level communication errors.
/// \param notification_group This parameter (indirectly) signifies what
- /// clients should receive the notification. Only the clients that
+ /// users should receive the notification. Only the users that
/// subscribed to notifications on the same group receive it.
/// \param name The name of the event to notify about (for example
- /// `config_changed`).
+ /// `new_group_member`).
/// \param params Other parameters that describe the event. This might
- /// be, for example, the new configuration value.
+ /// be, for example, the ID of the new member and the name of the
+ /// group. This can be any data element, but it is common for it to be
+ /// map.
void notify(const std::string& notification_group,
const std::string& name,
const isc::data::ConstElementPtr& params =
diff --git a/src/lib/config/tests/ccsession_unittests.cc b/src/lib/config/tests/ccsession_unittests.cc
index c11cd24..700ffe4 100644
--- a/src/lib/config/tests/ccsession_unittests.cc
+++ b/src/lib/config/tests/ccsession_unittests.cc
@@ -117,6 +117,46 @@ TEST_F(CCSessionTest, rpcNoRecpt) {
RPCRecipientMissing);
}
+// Test sending a notification
+TEST_F(CCSessionTest, notify) {
+ ModuleCCSession mccs(ccspecfile("spec1.spec"), session, NULL, NULL, false,
+ false);
+ mccs.notify("group", "event", el("{\"param\": true}"));
+ const ConstElementPtr notification(el(
+ "["
+ " \"notifications/group\","
+ " \"*\","
+ " {"
+ " \"notification\": ["
+ " \"event\", {"
+ " \"param\": true"
+ " }"
+ " ]"
+ " },"
+ " -1"
+ "]"));
+ EXPECT_TRUE(notification->equals(*session.getMsgQueue()->get(1))) <<
+ session.getMsgQueue()->get(1)->toWire();
+}
+
+// Test sending a notification
+TEST_F(CCSessionTest, notifyNoParams) {
+ ModuleCCSession mccs(ccspecfile("spec1.spec"), session, NULL, NULL, false,
+ false);
+ mccs.notify("group", "event");
+ const ConstElementPtr notification(el(
+ "["
+ " \"notifications/group\","
+ " \"*\","
+ " {"
+ " \"notification\": [\"event\"]"
+ " },"
+ " -1"
+ "]"));
+ EXPECT_TRUE(notification->equals(*session.getMsgQueue()->get(1))) <<
+ session.getMsgQueue()->get(1)->toWire();
+}
+
TEST_F(CCSessionTest, createAnswer) {
ConstElementPtr answer;
answer = createAnswer();
diff --git a/src/lib/python/isc/config/ccsession.py b/src/lib/python/isc/config/ccsession.py
index e801309..206a0ee 100644
--- a/src/lib/python/isc/config/ccsession.py
+++ b/src/lib/python/isc/config/ccsession.py
@@ -539,6 +539,42 @@ class ModuleCCSession(ConfigData):
raise RPCError(code, value)
return value
+ def notify(self, notification_group, event_name, params=None):
+ """
+ Send a notification to subscribed users.
+
+ Send a notification message to all users subscribed to the given
+ notification group.
+
+ This method does not block.
+
+ See docs/design/ipc-high.txt for details about notifications
+ and the format of messages sent.
+
+ Throws:
+ - CCSessionError: for low-level communication errors.
+ Params:
+ - notification_group (string): This parameter (indirectly) signifies
+ what users should receive the notification. Only users that
+ subscribed to notifications on the same group receive it.
+ - event_name (string): The name of the event to notify about (for
+ example `new_group_member`).
+ - params: Other parameters that describe the event. This might be, for
+ example, the ID of the new member and the name of the group. This can
+ be any data that can be sent over the isc.cc.Session, but it is
+ common for it to be dict.
+ Returns: Nothing
+ """
+ notification = [event_name]
+ if params is not None:
+ notification.append(params)
+ self._session.group_sendmsg({CC_PAYLOAD_NOTIFICATION: notification},
+ CC_GROUP_NOTIFICATION_PREFIX +
+ notification_group,
+ instance=CC_INSTANCE_WILDCARD,
+ to=CC_TO_WILDCARD,
+ want_answer=False)
+
class UIModuleCCSession(MultiConfigData):
"""This class is used in a configuration user interface. It contains
specific functions for getting, displaying, and sending
diff --git a/src/lib/python/isc/config/tests/ccsession_test.py b/src/lib/python/isc/config/tests/ccsession_test.py
index 2a2d790..3585337 100644
--- a/src/lib/python/isc/config/tests/ccsession_test.py
+++ b/src/lib/python/isc/config/tests/ccsession_test.py
@@ -350,6 +350,32 @@ class TestModuleCCSession(unittest.TestCase):
self.assertRaises(RPCRecipientMissing, self.rpc_check,
{"result": [-1, "Error"]})
+ def test_notify(self):
+ """
+ Test the sent notification has the right format.
+ """
+ fake_session = FakeModuleCCSession()
+ mccs = self.create_session("spec1.spec", None, None, fake_session)
+ mccs.notify("group", "event", {"param": True})
+ self.assertEqual([
+ ["notifications/group", "*", {"notification": ["event", {
+ "param": True
+ }]}, False]], fake_session.message_queue)
+
+ def test_notify_no_params(self):
+ """
+ Test the sent notification has the right format, this time
+ without passing parameters.
+ """
+ fake_session = FakeModuleCCSession()
+ mccs = self.create_session("spec1.spec", None, None, fake_session)
+ mccs.notify("group", "event")
+ self.assertEqual([
+ ["notifications/group", "*", {"notification": ["event"]},
+ False]
+ ],
+ fake_session.message_queue)
+
def my_config_handler_ok(self, new_config):
return isc.config.ccsession.create_answer(0)
More information about the bind10-changes
mailing list