diff options
author | Balazs Gibizer <balazs.gibizer@ericsson.com> | 2015-11-19 15:54:48 +0100 |
---|---|---|
committer | Balazs Gibizer <balazs.gibizer@ericsson.com> | 2016-01-19 19:20:24 +0100 |
commit | bd401d4cc8993e5f76ff9b87cb478c4fcaad1f4b (patch) | |
tree | 7a82e0f4a33d76161954722e8e3fe8f9170d0d1c /nova/rpc.py | |
parent | 1d6451e619799486a6517bab3c34c1c622e529af (diff) | |
download | nova-bd401d4cc8993e5f76ff9b87cb478c4fcaad1f4b.tar.gz |
Make emitting versioned notifications configurable
A new config option is introduced called 'notification_format'
which specifies the format of the notifications emitted, possible
values are 'versioned', 'unversioned', 'both'. The default value is 'both'.
Also to help consumers the versioned notifications will be emited to
a separate topic called 'versioned_notifications'.
DocImpact: new config option notification_format
Partially-Implements: bp versioned-notification-api
Change-Id: Ie45c03175800bb14269f3976b03a53488e084339
Diffstat (limited to 'nova/rpc.py')
-rw-r--r-- | nova/rpc.py | 40 |
1 files changed, 35 insertions, 5 deletions
diff --git a/nova/rpc.py b/nova/rpc.py index 14a6962bb5..b50077efdd 100644 --- a/nova/rpc.py +++ b/nova/rpc.py @@ -33,8 +33,20 @@ from oslo_serialization import jsonutils import nova.context import nova.exception + CONF = cfg.CONF +notification_opts = [ + cfg.StrOpt('notification_format', + choices=['unversioned', 'versioned', 'both'], + default='both', + help='Specifies which notification format shall be used by ' + 'nova.'), +] + +CONF.register_opts(notification_opts) + TRANSPORT = None +LEGACY_NOTIFIER = None NOTIFIER = None ALLOWED_EXMODS = [ @@ -56,21 +68,34 @@ TRANSPORT_ALIASES = { def init(conf): - global TRANSPORT, NOTIFIER + global TRANSPORT, LEGACY_NOTIFIER, NOTIFIER exmods = get_allowed_exmods() TRANSPORT = messaging.get_transport(conf, allowed_remote_exmods=exmods, aliases=TRANSPORT_ALIASES) serializer = RequestContextSerializer(JsonPayloadSerializer()) - NOTIFIER = messaging.Notifier(TRANSPORT, serializer=serializer) + if conf.notification_format == 'unversioned': + LEGACY_NOTIFIER = messaging.Notifier(TRANSPORT, serializer=serializer) + NOTIFIER = messaging.Notifier(TRANSPORT, serializer=serializer, + driver='noop') + elif conf.notification_format == 'both': + LEGACY_NOTIFIER = messaging.Notifier(TRANSPORT, serializer=serializer) + NOTIFIER = messaging.Notifier(TRANSPORT, serializer=serializer, + topic='versioned_notifications') + else: + LEGACY_NOTIFIER = messaging.Notifier(TRANSPORT, serializer=serializer, + driver='noop') + NOTIFIER = messaging.Notifier(TRANSPORT, serializer=serializer, + topic='versioned_notifications') def cleanup(): - global TRANSPORT, NOTIFIER + global TRANSPORT, LEGACY_NOTIFIER, NOTIFIER assert TRANSPORT is not None + assert LEGACY_NOTIFIER is not None assert NOTIFIER is not None TRANSPORT.cleanup() - TRANSPORT = NOTIFIER = None + TRANSPORT = LEGACY_NOTIFIER = NOTIFIER = None def set_defaults(control_exchange): @@ -141,7 +166,12 @@ def get_server(target, endpoints, serializer=None): def get_notifier(service, host=None, publisher_id=None): - assert NOTIFIER is not None + assert LEGACY_NOTIFIER is not None if not publisher_id: publisher_id = "%s.%s" % (service, host or CONF.host) + return LEGACY_NOTIFIER.prepare(publisher_id=publisher_id) + + +def get_versioned_notifier(publisher_id): + assert NOTIFIER is not None return NOTIFIER.prepare(publisher_id=publisher_id) |