diff --git a/bilean/common/consts.py b/bilean/common/consts.py index 5df9071..d377551 100644 --- a/bilean/common/consts.py +++ b/bilean/common/consts.py @@ -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', ) diff --git a/bilean/engine/flows/flow.py b/bilean/engine/flows/flow.py index ebecc8f..e0b5d6b 100644 --- a/bilean/engine/flows/flow.py +++ b/bilean/engine/flows/flow.py @@ -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__) diff --git a/bilean/notification/notification.py b/bilean/notification/notification.py index c68d9fb..fcbac78 100644 --- a/bilean/notification/notification.py +++ b/bilean/notification/notification.py @@ -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) diff --git a/bilean/plugins/os/nova/server.py b/bilean/plugins/os/nova/server.py index 3dfb92e..b37df80 100644 --- a/bilean/plugins/os/nova/server.py +++ b/bilean/plugins/os/nova/server.py @@ -128,4 +128,4 @@ class ServerPlugin(base.Plugin): RuleClass = ServerRule ResourceClass = ServerResource - notification_exchanges = ['nova', 'neutron'] + notification_exchanges = ['nova'] diff --git a/devstack/README.rst b/devstack/README.rst index 7c99755..79737f4 100644 --- a/devstack/README.rst +++ b/devstack/README.rst @@ -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. diff --git a/doc/source/install.rst b/doc/source/install.rst index 6439155..4571345 100644 --- a/doc/source/install.rst +++ b/doc/source/install.rst @@ -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.