aodh/ceilometer/messaging.py
Eoghan Glynn 36269031a7 Revert "oslo.messaging context must be a dict"
This reverts commit 5df4cb53ae.

The commit in question appears to have broken the notification agent
as an unintended side-effect. Reverting pending further investigation
as the notification agent is the more crucial component.

Related-to: #1317290
Change-Id: If9b1d638b60b7029c67f45e2e9feda62b9fd042a
2014-05-07 23:28:45 +01:00

97 lines
3.2 KiB
Python
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# -*- encoding: utf-8 -*-
# Copyright © 2013 eNovance <licensing@enovance.com>
#
# Author: Mehdi Abaakouk <mehdi.abaakouk@enovance.com>
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from oslo.config import cfg
import oslo.messaging
TRANSPORT = None
NOTIFIER = None
_ALIASES = {
'ceilometer.openstack.common.rpc.impl_kombu': 'rabbit',
'ceilometer.openstack.common.rpc.impl_qpid': 'qpid',
'ceilometer.openstack.common.rpc.impl_zmq': 'zmq',
}
def setup(url=None):
"""Initialise the oslo.messaging layer."""
global TRANSPORT, NOTIFIER
if not TRANSPORT:
oslo.messaging.set_transport_defaults('ceilometer')
TRANSPORT = oslo.messaging.get_transport(cfg.CONF, url,
aliases=_ALIASES)
if not NOTIFIER:
NOTIFIER = oslo.messaging.Notifier(TRANSPORT)
def cleanup():
"""Cleanup the oslo.messaging layer."""
global TRANSPORT, NOTIFIER
assert TRANSPORT is not None
assert NOTIFIER is not None
TRANSPORT.cleanup()
TRANSPORT = NOTIFIER = None
def get_rpc_server(topic, endpoint):
"""Return a configured oslo.messaging rpc server."""
global TRANSPORT
target = oslo.messaging.Target(server=cfg.CONF.host, topic=topic)
return oslo.messaging.get_rpc_server(TRANSPORT, target, [endpoint],
executor='eventlet')
def get_rpc_client(**kwargs):
"""Return a configured oslo.messaging RPCClient."""
global TRANSPORT
target = oslo.messaging.Target(**kwargs)
return oslo.messaging.RPCClient(TRANSPORT, target)
def get_notification_listener(targets, endpoints, url=None):
"""Return a configured oslo.messaging notification listener."""
global TRANSPORT
if url:
transport = oslo.messaging.get_transport(cfg.CONF, url,
_ALIASES)
else:
transport = TRANSPORT
return oslo.messaging.get_notification_listener(
transport, targets, endpoints, executor='eventlet')
def get_notifier(publisher_id):
"""Return a configured oslo.messaging notifier."""
global NOTIFIER
return NOTIFIER.prepare(publisher_id=publisher_id)
def convert_to_old_notification_format(priority, ctxt, publisher_id,
event_type, payload, metadata):
#FIXME(sileht): temporary convert notification to old format
#to focus on oslo.messaging migration before refactoring the code to
#use the new oslo.messaging facilities
notification = {'priority': priority,
'payload': payload,
'event_type': event_type,
'publisher_id': publisher_id}
notification.update(metadata)
for k in ctxt:
notification['_context_' + k] = ctxt[k]
return notification