Enable notification messaging pools

Use notification pools by default and use the same notification
topic as ceilometer, separate notification topic is no need to add.

Change-Id: Ieef1ece78e6e8d20abfeea9546e1a9170b7eeb70
This commit is contained in:
lvdongbing 2016-06-08 05:33:15 -04:00
parent e5385d4e9b
commit 5025328bc1
6 changed files with 83 additions and 21 deletions

View File

@ -20,13 +20,11 @@ MAX_RESOURCE_NUM = 1000
RPC_ATTRS = (
ENGINE_TOPIC,
SCHEDULER_TOPIC,
NOTIFICATION_TOPICS,
ENGINE_DISPATCHER_TOPIC,
RPC_API_VERSION,
) = (
'bilean-engine',
'bilean-scheduler',
'billing_notifications',
'bilean_engine_dispatcher',
'1.0',
)

View File

@ -24,7 +24,7 @@ from bilean.common import exception
from bilean.common.i18n import _LE
from bilean.engine import policy as policy_mod
from bilean.engine import user as user_mod
from bilean.plugin import base as plugin_base
from bilean.plugins import base as plugin_base
from bilean import scheduler as bilean_scheduler
LOG = logging.getLogger(__name__)

View File

@ -11,37 +11,75 @@
# License for the specific language governing permissions and limitations
# under the License.
from oslo_config import cfg
from oslo_log import log as logging
import oslo_messaging
from oslo_service import service
from bilean.common import consts
from bilean.common.i18n import _
from bilean.common.i18n import _LE
from bilean.common import messaging as bilean_messaging
from bilean.engine import environment
from bilean.notification import endpoint
LOG = logging.getLogger(__name__)
listener_opts = [
cfg.IntOpt('workers',
default=1,
min=1,
help='Number of workers for notification service. A single '
'notification agent is enabled by default.'),
cfg.StrOpt('notifications_pool',
default='bilean-listener',
help='Use an oslo.messaging pool, which can be an alternative '
'to multiple topics. ')
]
CONF = cfg.CONF
CONF.register_opts(listener_opts, group="listener")
class NotificationService(service.Service):
def __init__(self, *args, **kwargs):
super(NotificationService, self).__init__(*args, **kwargs)
self.targets, self.listeners = [], []
self.transport = None
self.group_id = None
self.endpoints = [endpoint.EventsNotificationEndpoint()]
self.listeners = []
self.topics_exchanges_set = self.topics_and_exchanges()
def topics_and_exchanges(self):
topics_exchanges = set()
plugins = environment.global_env().get_plugins()
for plugin in plugins:
try:
topic_exchanges = plugin.get_notification_topics_exchanges()
for plugin_topic in topic_exchanges:
if isinstance(plugin_topic, basestring):
raise Exception(
_LE("Plugin %s should return a list of topic "
"exchange pairs") % plugin.__class__.__name__)
topics_exchanges.add(plugin_topic)
except Exception as e:
LOG.error(_LE("Failed to retrieve notification topic(s) "
"and exchanges from bilean plugin "
"%(ext)s: %(e)s") %
{'ext': plugin.__name__, 'e': e})
return topics_exchanges
def start(self):
super(NotificationService, self).start()
self.transport = bilean_messaging.get_transport()
self.targets.append(
oslo_messaging.Target(topic=consts.NOTIFICATION_TOPICS))
listener = bilean_messaging.get_notification_listener(
self.transport, self.targets, self.endpoints)
transport = bilean_messaging.get_transport()
targets = [
oslo_messaging.Target(topic=tp, exchange=eg)
for tp, eg in self.topics_exchanges_set
]
endpoints = [endpoint.EventsNotificationEndpoint()]
listener = oslo_messaging.get_notification_listener(
transport,
targets,
endpoints,
pool=CONF.listener.notifications_pool)
LOG.info(_("Starting listener on topic: %s"),
consts.NOTIFICATION_TOPICS)
listener.start()
self.listeners.append(listener)

View File

@ -128,4 +128,4 @@ class ServerPlugin(base.Plugin):
RuleClass = ServerRule
ResourceClass = ServerResource
notification_exchanges = ['nova', 'neutron']
notification_exchanges = ['nova']

View File

@ -22,8 +22,21 @@ Enabling Bilean in DevStack
Bilean service is driven using a plugin mechanism for integrating to other
services. Each integrated service may require additional configuration
settings. For example, typically, you will need to add the
``billing_notifications`` notification topic to each service's configuration.
settings. Typically, you will need to set the notifications driver in each
service's configuration.
For example, to enable nova service, edit `/etc/nova/nvoa.conf` and add
following configuration::
[oslo_messaging_notifications]
driver = messaging
Or add following configurations to post config section in `local.conf` to
make devstack automaticlly configure the settings above::
[[post-config|$NOVA_CONF]]
[oslo_messaging_notifications]
driver = messaging
4. Then run devstack normally.

View File

@ -46,8 +46,21 @@ following detailed instructions.
Bilean service is driven using a plugin mechanism for integrating to other
services. Each integrated service may require additional configuration
settings. For example, typically, you will need to add the
``billing_notifications`` notification topic to each service's configuration.
settings. Typically, you will need to set the notifications driver in each
service's configuration.
For example, to enable nova service, edit `/etc/nova/nvoa.conf` and add
following configuration::
[oslo_messaging_notifications]
driver = messaging
Or add following configurations to post config section in `local.conf` to
make devstack automaticlly configure the settings above::
[[post-config|$NOVA_CONF]]
[oslo_messaging_notifications]
driver = messaging
4. Then run devstack normally.