# Path: monasca_notification/common/utils.py
# def construct_notification_object(db_repo, notification_json):
#     try:
#         notification = Notification(notification_json['id'],
#                                     notification_json['type'],
#                                     notification_json['name'],
#                                     notification_json['address'],
#                                     notification_json['period'],
#                                     notification_json['retry_count'],
#                                     notification_json['raw_alarm'])
#         # Grab notification method from database to see if it was changed
#         stored_notification = grab_stored_notification_method(db_repo, notification.id)
#         # Notification method was deleted
#         if stored_notification is None:
#             LOG.debug("Notification method {0} was deleted from database. "
#                       "Will stop sending.".format(notification.id))
#             return None
#         # Update notification method with most up to date values
#         else:
#             notification.name = stored_notification[0]
#             notification.type = stored_notification[1]
#             notification.address = stored_notification[2]
#             notification.period = stored_notification[3]
#             return notification
#     except exceptions.DatabaseException:
#         LOG.warn("Error querying mysql for notification method. "
#                  "Using currently cached method.")
#         return notification
#     except Exception as e:
#         LOG.warn("Error when attempting to construct notification {0}".format(e))
#         return None
# 
# Path: monasca_notification/common/utils.py
# def get_db_repo():
#     repo_driver = CONF.database.repo_driver
#     LOG.debug('Enabling the %s RDB repository', repo_driver)
#     return repo_driver(CONF)
# 
# Path: monasca_notification/common/utils.py
# def get_statsd_client(dimensions=None):
#     local_dims = dimensions.copy() if dimensions else {}
#     local_dims.update(NOTIFICATION_DIMENSIONS)
#     if CONF.statsd.enable:
#         LOG.debug("Establishing connection with statsd on {0}:{1}"
#                   .format(CONF.statsd.host, CONF.statsd.port))
#         client = monascastatsd.Client(name='monasca',
#                                       host=CONF.statsd.host,
#                                       port=CONF.statsd.port,
#                                       dimensions=local_dims)
#     else:
#         LOG.warn("StatsD monitoring disabled. Overriding monascastatsd.Client to use it offline")
#         client = OfflineClient(name='monasca',
#                                host=CONF.statsd.host,
#                                port=CONF.statsd.port,
#                                dimensions=local_dims)
#     return client
# 
# Path: monasca_notification/processors/notification_processor.py
# class NotificationProcessor(object):
#     def __init__(self):
#     def _remaining_plugin_types(self):
#     def insert_configured_plugins(self):
#     def send(self, notifications):


import time
from oslo_config import cfg
from oslo_log import log as logging
from oslo_serialization import jsonutils
from monasca_common.kafka import client_factory
from monasca_notification.common.utils import construct_notification_object
from monasca_notification.common.utils import get_db_repo
from monasca_notification.common.utils import get_statsd_client
from monasca_notification.processors import notification_processor
            notification = construct_notification_object(self._db_repo, notification_data)

            if notification is None:
                self._consumer.commit()
                continue

            wait_duration = CONF.retry_engine.interval - (
                time.time() - notification_data['notification_timestamp'])

            if wait_duration > 0:
                time.sleep(wait_duration)

            sent, failed = self._notifier.send([notification])

            if sent:
                self._producer.publish(CONF.kafka.notification_topic,
                                       [notification.to_json()])

            if failed:
                notification.retry_count += 1
                notification.notification_timestamp = time.time()
                if notification.retry_count < CONF.retry_engine.max_attempts:
                    log.error(u"retry failed for {} with name {} "
                              u"at {}.  "
                              u"Saving for later retry.".format(notification.type,
                                                                notification.name,
                                                                notification.address))
                    self._producer.publish(CONF.kafka.notification_retry_topic,
                                           [notification.to_json()])
                else:

# Path: monasca_notification/common/utils.py
# def construct_notification_object(db_repo, notification_json):
#     try:
#         notification = Notification(notification_json['id'],
#                                     notification_json['type'],
#                                     notification_json['name'],
#                                     notification_json['address'],
#                                     notification_json['period'],
#                                     notification_json['retry_count'],
#                                     notification_json['raw_alarm'])
#         # Grab notification method from database to see if it was changed
#         stored_notification = grab_stored_notification_method(db_repo, notification.id)
#         # Notification method was deleted
#         if stored_notification is None:
#             LOG.debug("Notification method {0} was deleted from database. "
#                       "Will stop sending.".format(notification.id))
#             return None
#         # Update notification method with most up to date values
#         else:
#             notification.name = stored_notification[0]
#             notification.type = stored_notification[1]
#             notification.address = stored_notification[2]
#             notification.period = stored_notification[3]
#             return notification
#     except exceptions.DatabaseException:
#         LOG.warn("Error querying mysql for notification method. "
#                  "Using currently cached method.")
#         return notification
#     except Exception as e:
#         LOG.warn("Error when attempting to construct notification {0}".format(e))
#         return None
# 
# Path: monasca_notification/common/utils.py
# def get_db_repo():
#     repo_driver = CONF.database.repo_driver
#     LOG.debug('Enabling the %s RDB repository', repo_driver)
#     return repo_driver(CONF)
# 
# Path: monasca_notification/common/utils.py
# def get_statsd_client(dimensions=None):
#     local_dims = dimensions.copy() if dimensions else {}
#     local_dims.update(NOTIFICATION_DIMENSIONS)
#     if CONF.statsd.enable:
#         LOG.debug("Establishing connection with statsd on {0}:{1}"
#                   .format(CONF.statsd.host, CONF.statsd.port))
#         client = monascastatsd.Client(name='monasca',
#                                       host=CONF.statsd.host,
#                                       port=CONF.statsd.port,
#                                       dimensions=local_dims)
#     else:
#         LOG.warn("StatsD monitoring disabled. Overriding monascastatsd.Client to use it offline")
#         client = OfflineClient(name='monasca',
#                                host=CONF.statsd.host,
#                                port=CONF.statsd.port,
#                                dimensions=local_dims)
#     return client
# 
# Path: monasca_notification/processors/notification_processor.py
# class NotificationProcessor(object):
#     def __init__(self):
#     def _remaining_plugin_types(self):
#     def insert_configured_plugins(self):
#     def send(self, notifications):


# Path: monasca_notification/retry_engine.py
import time
from oslo_config import cfg
from oslo_log import log as logging
from oslo_serialization import jsonutils
from monasca_common.kafka import client_factory
from monasca_notification.common.utils import construct_notification_object
from monasca_notification.common.utils import get_db_repo
from monasca_notification.common.utils import get_statsd_client
from monasca_notification.processors import notification_processor

            notification = construct_notification_object(self._db_repo, notification_data)

            if notification is None:
                self._consumer.commit()
                continue

            wait_duration = CONF.retry_engine.interval - (
                time.time() - notification_data['notification_timestamp'])

            if wait_duration > 0:
                time.sleep(wait_duration)

            sent, failed = self._notifier.send([notification])

            if sent:
                self._producer.publish(CONF.kafka.notification_topic,
                                       [notification.to_json()])

            if failed:
                notification.retry_count += 1
                notification.notification_timestamp = time.time()
                if notification.retry_count < CONF.retry_engine.max_attempts:
                    log.error(u"retry failed for {} with name {} "
                              u"at {}.  "
                              u"Saving for later retry.".format(notification.type,
                                                                notification.name,
                                                                notification.address))
                    self._producer.publish(CONF.kafka.notification_retry_topic,
                                           [notification.to_json()])
                else:

                    log.error(u"retry failed for {} with name {} "