Use messaging notifications transport instead of default

The usage of oslo_messaging.get_transport is not meant for
notifications; And oslo_messaging.get_notification_transport is
favored for those means. So this change introduces the usage of that
function.

If the settings for the notifications are not set with the
configuration that's under the oslo_messaging_notifications group,
this will fall back to the old settings which are under the DEFAULT
group; just like this used to work.

Change-Id: I52d7a72dadd10ade1f5335f14c58391271e209c2
This commit is contained in:
Juan Antonio Osorio Robles 2016-04-14 12:19:07 +03:00
parent ee9ce1d871
commit afbbe071b1

View File

@ -23,6 +23,7 @@ from heat.common import context
TRANSPORT = None
NOTIFICATIONS_TRANSPORT = None
NOTIFIER = None
_ALIASES = {
@ -73,39 +74,56 @@ class JsonPayloadSerializer(oslo_messaging.NoOpSerializer):
return jsonutils.to_primitive(entity, convert_instances=True)
def get_specific_transport(url, optional, exmods, is_for_notifications=False):
try:
if is_for_notifications:
return oslo_messaging.get_notification_transport(
cfg.CONF, url, allowed_remote_exmods=exmods, aliases=_ALIASES)
else:
return oslo_messaging.get_transport(
cfg.CONF, url, allowed_remote_exmods=exmods, aliases=_ALIASES)
except oslo_messaging.InvalidTransportURL as e:
if not optional or e.url:
# NOTE(sileht): oslo_messaging is configured but unloadable
# so reraise the exception
raise
else:
return None
def setup_transports(url, optional):
global TRANSPORT, NOTIFICATIONS_TRANSPORT
oslo_messaging.set_transport_defaults('heat')
exmods = ['heat.common.exception']
TRANSPORT = get_specific_transport(url, optional, exmods)
NOTIFICATIONS_TRANSPORT = get_specific_transport(url, optional, exmods,
is_for_notifications=True)
def setup(url=None, optional=False):
"""Initialise the oslo_messaging layer."""
global TRANSPORT, NOTIFIER
global NOTIFIER
if url and url.startswith("fake://"):
# NOTE(sileht): oslo_messaging fake driver uses time.sleep
# for task switch, so we need to monkey_patch it
eventlet.monkey_patch(time=True)
if not TRANSPORT or not NOTIFICATIONS_TRANSPORT:
setup_transports(url, optional)
if not TRANSPORT:
oslo_messaging.set_transport_defaults('heat')
exmods = ['heat.common.exception']
try:
TRANSPORT = oslo_messaging.get_transport(
cfg.CONF, url, allowed_remote_exmods=exmods, aliases=_ALIASES)
except oslo_messaging.InvalidTransportURL as e:
TRANSPORT = None
if not optional or e.url:
# NOTE(sileht): oslo_messaging is configured but unloadable
# so reraise the exception
raise
if not NOTIFIER and TRANSPORT:
if not NOTIFIER and NOTIFICATIONS_TRANSPORT:
serializer = RequestContextSerializer(JsonPayloadSerializer())
NOTIFIER = oslo_messaging.Notifier(TRANSPORT, serializer=serializer)
NOTIFIER = oslo_messaging.Notifier(NOTIFICATIONS_TRANSPORT,
serializer=serializer)
def cleanup():
"""Cleanup the oslo_messaging layer."""
global TRANSPORT, NOTIFIER
global TRANSPORT, NOTIFICATIONS_TRANSPORT, NOTIFIER
if TRANSPORT:
TRANSPORT.cleanup()
TRANSPORT = NOTIFIER = None
NOTIFICATIONS_TRANSPORT.cleanup()
TRANSPORT = NOTIFICATIONS_TRANSPORT = NOTIFIER = None
def get_rpc_server(target, endpoint):