Ejemplo n.º 1
0
    def _record_change(self, alarm):
        if not self.conf.record_history:
            return
        type = models.AlarmChange.STATE_TRANSITION
        detail = json.dumps({'state': alarm.state})
        user_id, project_id = self.ks_client.user_id, self.ks_client.project_id
        on_behalf_of = alarm.project_id
        now = timeutils.utcnow()
        payload = dict(event_id=str(uuid.uuid4()),
                       alarm_id=alarm.alarm_id,
                       type=type,
                       detail=detail,
                       user_id=user_id,
                       project_id=project_id,
                       on_behalf_of=on_behalf_of,
                       timestamp=now)

        try:
            self._storage_conn.record_alarm_change(payload)
        except aodh.NotImplementedError:
            pass
        if not self._alarm_change_notifier:
            transport = messaging.get_transport(self.conf)
            self._alarm_change_notifier = messaging.get_notifier(
                transport, publisher_id="aodh.evaluator")
        notification = "alarm.state_transition"
        self._alarm_change_notifier.info({},
                                         notification, payload)
Ejemplo n.º 2
0
    def _record_change(self, alarm):
        if not self.conf.record_history:
            return
        type = models.AlarmChange.STATE_TRANSITION
        detail = json.dumps({'state': alarm.state})
        user_id, project_id = self.ks_client.user_id, self.ks_client.project_id
        on_behalf_of = alarm.project_id
        now = timeutils.utcnow()
        payload = dict(event_id=str(uuid.uuid4()),
                       alarm_id=alarm.alarm_id,
                       type=type,
                       detail=detail,
                       user_id=user_id,
                       project_id=project_id,
                       on_behalf_of=on_behalf_of,
                       timestamp=now)

        try:
            self._storage_conn.record_alarm_change(payload)
        except aodh.NotImplementedError:
            pass
        if not self._alarm_change_notifier:
            transport = messaging.get_transport(self.conf)
            self._alarm_change_notifier = messaging.get_notifier(
                transport, publisher_id="aodh.evaluator")
        notification = "alarm.state_transition"
        self._alarm_change_notifier.info({}, notification, payload)
Ejemplo n.º 3
0
def _send_notification(event, payload):
    notification = event.replace(" ", "_")
    notification = "alarm.%s" % notification
    transport = messaging.get_transport(pecan.request.cfg)
    notifier = messaging.get_notifier(transport, publisher_id="aodh.api")
    # FIXME(sileht): perhaps we need to copy some infos from the
    # pecan request headers like nova does
    notifier.info({}, notification, payload)
Ejemplo n.º 4
0
def _send_notification(event, payload):
    notification = event.replace(" ", "_")
    notification = "alarm.%s" % notification
    transport = messaging.get_transport(pecan.request.cfg)
    notifier = messaging.get_notifier(transport, publisher_id="aodh.api")
    # FIXME(sileht): perhaps we need to copy some infos from the
    # pecan request headers like nova does
    notifier.info({}, notification, payload)
Ejemplo n.º 5
0
 def start(self):
     super(EventAlarmEvaluationService, self).start()
     self.listener = messaging.get_notification_listener(
         messaging.get_transport(self.conf),
         [oslo_messaging.Target(topic=self.conf.event_alarm_topic)],
         [EventAlarmEndpoint(self.evaluator)])
     self.listener.start()
     # Add a dummy thread to have wait() working
     self.tg.add_timer(604800, lambda: None)
Ejemplo n.º 6
0
    def __init__(self, conf):
        super(AlarmNotifierService, self).__init__()
        transport = messaging.get_transport(conf)
        self.rpc_server = messaging.get_rpc_server(
            conf, transport, conf.notifier_rpc_topic, self)

        self.notifiers = extension.ExtensionManager(
            self.NOTIFIER_EXTENSIONS_NAMESPACE,
            invoke_on_load=True,
            invoke_args=(conf,))
Ejemplo n.º 7
0
    def __init__(self, conf):
        super(AlarmNotifierService, self).__init__()
        transport = messaging.get_transport(conf)
        self.rpc_server = messaging.get_rpc_server(conf, transport,
                                                   conf.notifier_rpc_topic,
                                                   self)

        self.notifiers = extension.ExtensionManager(
            self.NOTIFIER_EXTENSIONS_NAMESPACE,
            invoke_on_load=True,
            invoke_args=(conf, ))
Ejemplo n.º 8
0
    def __init__(self, conf):
        super(AlarmNotifierService, self).__init__()
        transport = messaging.get_transport(conf)
        self.notifiers = extension.ExtensionManager(
            self.NOTIFIER_EXTENSIONS_NAMESPACE,
            invoke_on_load=True,
            invoke_args=(conf,))

        target = oslo_messaging.Target(topic=conf.notifier_topic)
        self.listener = messaging.get_notification_listener(
            transport, [target],
            [AlarmEndpoint(self.notifiers)])
Ejemplo n.º 9
0
    def __init__(self, worker_id, conf):
        self.conf = conf
        transport = messaging.get_transport(self.conf)
        self.notifiers = extension.ExtensionManager(
            self.NOTIFIER_EXTENSIONS_NAMESPACE,
            invoke_on_load=True,
            invoke_args=(self.conf,))

        target = oslo_messaging.Target(topic=self.conf.notifier_topic)
        self.listener = messaging.get_batch_notification_listener(
            transport, [target], [AlarmEndpoint(self.notifiers)], False,
            self.conf.notifier.batch_size, self.conf.notifier.batch_timeout)
        self.listener.start()
Ejemplo n.º 10
0
    def setup_messaging(self, conf, exchange=None):
        self.useFixture(oslo_messaging.conffixture.ConfFixture(conf))
        conf.set_override("notification_driver", "messaging")
        if not exchange:
            exchange = 'aodh'
        conf.set_override("control_exchange", exchange)

        # NOTE(sileht): Ensure a new oslo.messaging driver is loaded
        # between each tests
        self.transport = messaging.get_transport(conf, "fake://", cache=False)
        self.useFixture(mockpatch.Patch(
            'aodh.messaging.get_transport',
            return_value=self.transport))
Ejemplo n.º 11
0
 def __init__(self, worker_id, conf):
     super(EventAlarmEvaluationService, self).__init__(worker_id)
     self.conf = conf
     self.storage_conn = storage.get_connection_from_config(self.conf)
     self.evaluator = event.EventAlarmEvaluator(self.conf)
     self.listener = messaging.get_batch_notification_listener(
         messaging.get_transport(self.conf),
         [oslo_messaging.Target(
             topic=self.conf.listener.event_alarm_topic)],
         [EventAlarmEndpoint(self.evaluator)], False,
         self.conf.listener.batch_size,
         self.conf.listener.batch_timeout)
     self.listener.start()
Ejemplo n.º 12
0
    def setup_messaging(self, conf, exchange=None):
        self.useFixture(oslo_messaging.conffixture.ConfFixture(conf))
        conf.set_override("notification_driver", ["messaging"])
        if not exchange:
            exchange = 'aodh'
        conf.set_override("control_exchange", exchange)

        # NOTE(sileht): Ensure a new oslo.messaging driver is loaded
        # between each tests
        self.transport = messaging.get_transport(conf, "fake://", cache=False)
        self.useFixture(
            fixtures.MockPatch('aodh.messaging.get_transport',
                               return_value=self.transport))
Ejemplo n.º 13
0
    def __init__(self, worker_id, conf):
        super(AlarmNotifierService, self).__init__(worker_id)
        self.conf = conf
        transport = messaging.get_transport(self.conf)
        self.notifiers = extension.ExtensionManager(
            self.NOTIFIER_EXTENSIONS_NAMESPACE,
            invoke_on_load=True,
            invoke_args=(self.conf,))

        target = oslo_messaging.Target(topic=self.conf.notifier_topic)
        self.listener = messaging.get_batch_notification_listener(
            transport, [target], [AlarmEndpoint(self.notifiers)], False,
            self.conf.notifier.batch_size, self.conf.notifier.batch_timeout)
        self.listener.start()
Ejemplo n.º 14
0
 def start(self):
     super(EventAlarmEvaluationService, self).start()
     self.storage_conn = storage.get_connection_from_config(self.conf)
     self.evaluator = event.EventAlarmEvaluator(self.conf)
     self.listener = messaging.get_batch_notification_listener(
         messaging.get_transport(self.conf),
         [oslo_messaging.Target(
             topic=self.conf.listener.event_alarm_topic)],
         [EventAlarmEndpoint(self.evaluator)], False,
         self.conf.listener.batch_size,
         self.conf.listener.batch_timeout)
     self.listener.start()
     # Add a dummy thread to have wait() working
     self.tg.add_timer(604800, lambda: None)
Ejemplo n.º 15
0
    def start(self):
        super(AlarmNotifierService, self).start()
        transport = messaging.get_transport(self.conf)
        self.notifiers = extension.ExtensionManager(
            self.NOTIFIER_EXTENSIONS_NAMESPACE,
            invoke_on_load=True,
            invoke_args=(self.conf,))

        target = oslo_messaging.Target(topic=self.conf.notifier_topic)
        self.listener = messaging.get_batch_notification_listener(
            transport, [target], [AlarmEndpoint(self.notifiers)], False,
            self.conf.notifier.batch_size, self.conf.notifier.batch_timeout)
        self.listener.start()
        # Add a dummy thread to have wait() working
        self.tg.add_timer(604800, lambda: None)
Ejemplo n.º 16
0
    def setup_messaging(self, conf, exchange=None):
        self.useFixture(oslo_messaging.conffixture.ConfFixture(conf))
        conf.set_override("notification_driver", "messaging")
        if not exchange:
            exchange = 'aodh'
        conf.set_override("control_exchange", exchange)

        # NOTE(sileht): oslo.messaging fake driver uses time.sleep
        # for task switch, so we need to monkey_patch it
        # and also ensure the correct exchange have been set
        eventlet.monkey_patch(time=True)

        # NOTE(sileht): Ensure a new oslo.messaging driver is loaded
        # between each tests
        self.transport = messaging.get_transport(conf, "fake://", cache=False)
        self.useFixture(mockpatch.Patch(
            'aodh.messaging.get_transport',
            return_value=self.transport))
Ejemplo n.º 17
0
    def setup_messaging(self, conf, exchange=None):
        self.useFixture(oslo_messaging.conffixture.ConfFixture(conf))
        conf.set_override("notification_driver", "messaging")
        if not exchange:
            exchange = 'aodh'
        conf.set_override("control_exchange", exchange)

        # NOTE(sileht): oslo.messaging fake driver uses time.sleep
        # for task switch, so we need to monkey_patch it
        # and also ensure the correct exchange have been set
        eventlet.monkey_patch(time=True)

        # NOTE(sileht): Ensure a new oslo.messaging driver is loaded
        # between each tests
        self.transport = messaging.get_transport(conf, "fake://", cache=False)
        self.useFixture(
            mockpatch.Patch('aodh.messaging.get_transport',
                            return_value=self.transport))
    def __init__(self, conf):
        super(AlarmNotifierService, self).__init__()
        transport = messaging.get_transport(conf)

        self.notifiers = extension.ExtensionManager(
            self.NOTIFIER_EXTENSIONS_NAMESPACE,
            invoke_on_load=True,
            invoke_args=(conf,))

        if conf.ipc_protocol == 'rpc':
            self.ipc = 'rpc'
            self.rpc_server = messaging.get_rpc_server(
                conf, transport, conf.notifier_rpc_topic, self)
        else:
            self.ipc = 'queue'
            target = oslo_messaging.Target(topic=conf.notifier_topic)
            self.listener = messaging.get_notification_listener(
                transport, [target],
                [AlarmEndpoint(self.notifiers)])
Ejemplo n.º 19
0
    def __init__(self, conf):
        super(AlarmNotifierService, self).__init__()
        transport = messaging.get_transport(conf)

        self.notifiers = extension.ExtensionManager(
            self.NOTIFIER_EXTENSIONS_NAMESPACE,
            invoke_on_load=True,
            invoke_args=(conf, ))

        if conf.ipc_protocol == 'rpc':
            self.ipc = 'rpc'
            self.rpc_server = messaging.get_rpc_server(conf, transport,
                                                       conf.notifier_rpc_topic,
                                                       self)
        else:
            self.ipc = 'queue'
            target = oslo_messaging.Target(topic=conf.notifier_topic)
            self.listener = messaging.get_notification_listener(
                transport, [target], [AlarmEndpoint(self.notifiers)])
Ejemplo n.º 20
0
 def alarm_change_notifier(self):
     if not self._alarm_change_notifier:
         transport = messaging.get_transport(self.conf)
         self._alarm_change_notifier = messaging.get_notifier(
             transport, publisher_id="aodh.evaluator")
     return self._alarm_change_notifier
Ejemplo n.º 21
0
 def test_get_transport_optional(self):
     self.CONF.set_override('transport_url', 'non-url')
     self.assertIsNone(messaging.get_transport(self.CONF, optional=True,
                                               cache=False))
Ejemplo n.º 22
0
 def test_get_transport_url_caching(self):
     t1 = messaging.get_transport(self.CONF, 'fake://')
     t2 = messaging.get_transport(self.CONF, 'fake://')
     self.assertEqual(t1, t2)
Ejemplo n.º 23
0
 def __init__(self, conf):
     self.notifier = oslo_messaging.Notifier(
         messaging.get_transport(conf),
         driver='messagingv2',
         publisher_id="alarming.evaluator",
         topic=conf.notifier_topic)
Ejemplo n.º 24
0
 def __init__(self):
     super(AlarmNotifierService, self).__init__()
     transport = messaging.get_transport()
     self.rpc_server = messaging.get_rpc_server(
         transport, cfg.CONF.alarm.notifier_rpc_topic, self)
Ejemplo n.º 25
0
 def test_get_transport_url_caching_mix(self):
     t1 = messaging.get_transport(self.CONF, 'fake://')
     t2 = messaging.get_transport(self.CONF, 'fake://', cache=False)
     self.assertNotEqual(t1, t2)
Ejemplo n.º 26
0
 def test_get_transport_default_url_caching(self):
     t1 = messaging.get_transport(self.CONF, )
     t2 = messaging.get_transport(self.CONF, )
     self.assertEqual(t1, t2)
Ejemplo n.º 27
0
 def test_get_transport_url_caching_mix(self):
     t1 = messaging.get_transport(self.CONF, 'fake://')
     t2 = messaging.get_transport(self.CONF, 'fake://', cache=False)
     self.assertNotEqual(t1, t2)
Ejemplo n.º 28
0
 def __init__(self, conf):
     self.notifier = oslo_messaging.Notifier(
         messaging.get_transport(conf),
         driver='messagingv2',
         publisher_id="alarming.evaluator",
         topics=[conf.notifier_topic])
Ejemplo n.º 29
0
Archivo: rpc.py Proyecto: sileht/aodh
 def __init__(self, conf):
     transport = messaging.get_transport(conf)
     self.client = messaging.get_rpc_client(transport,
                                            topic=conf.notifier_rpc_topic,
                                            version="1.0")
Ejemplo n.º 30
0
 def test_get_transport_optional(self):
     self.CONF.set_override('rpc_backend', '')
     self.assertIsNone(
         messaging.get_transport(self.CONF, optional=True, cache=False))
Ejemplo n.º 31
0
 def test_get_transport_default_url_no_caching(self):
     t1 = messaging.get_transport(self.CONF, cache=False)
     t2 = messaging.get_transport(self.CONF, cache=False)
     self.assertNotEqual(t1, t2)
Ejemplo n.º 32
0
 def test_get_transport_url_caching(self):
     t1 = messaging.get_transport(self.CONF, 'fake://')
     t2 = messaging.get_transport(self.CONF, 'fake://')
     self.assertEqual(t1, t2)
Ejemplo n.º 33
0
 def test_get_transport_default_url_caching(self):
     t1 = messaging.get_transport(self.CONF, )
     t2 = messaging.get_transport(self.CONF, )
     self.assertEqual(t1, t2)
Ejemplo n.º 34
0
 def test_get_transport_default_url_no_caching(self):
     t1 = messaging.get_transport(self.CONF, cache=False)
     t2 = messaging.get_transport(self.CONF, cache=False)
     self.assertNotEqual(t1, t2)
Ejemplo n.º 35
0
 def test_get_transport_url_no_caching(self):
     t1 = messaging.get_transport('fake://', cache=False)
     t2 = messaging.get_transport('fake://', cache=False)
     self.assertNotEqual(t1, t2)
Ejemplo n.º 36
0
 def test_get_transport_optional(self):
     self.CONF.set_override('rpc_backend', '')
     self.assertIsNone(messaging.get_transport(self.CONF, optional=True,
                                               cache=False))
Ejemplo n.º 37
0
 def test_get_transport_default_url_caching_mix(self):
     t1 = messaging.get_transport()
     t2 = messaging.get_transport(cache=False)
     self.assertNotEqual(t1, t2)
Ejemplo n.º 38
0
Archivo: rpc.py Proyecto: pczerkas/aodh
 def __init__(self, conf):
     transport = messaging.get_transport(conf)
     self.client = messaging.get_rpc_client(
         transport, topic=conf.notifier_rpc_topic,
         version="1.0")
Ejemplo n.º 39
0
 def test_get_transport_optional(self):
     self.CONF.set_override('transport_url', 'non-url')
     self.assertIsNone(
         messaging.get_transport(self.CONF, optional=True, cache=False))