# Path: monasca_api/api/healthcheck_api.py
# LOG = log.getLogger(__name__)
# class HealthCheckApi(object):
#     def __init__(self):
#     def on_get(self, req, res):
#     def on_head(self, req, res):
# 
# Path: monasca_api/healthcheck/alarms_db_check.py
# LOG = log.getLogger(__name__)
# class AlarmsDbHealthCheck(base.BaseHealthCheck,
#                           sql_repository.SQLRepository):
#     def health_check(self):
#     def check_db_status(self):
# 
# Path: monasca_api/healthcheck/metrics_db_check.py
# CONF = cfg.CONF
# LOG = log.getLogger(__name__)
# class MetricsDbCheck(base.BaseHealthCheck):
#     def __init__(self):
#     def health_check(self):
# 
# Path: monasca_api/v2/reference/helpers.py
# LOG = log.getLogger(__name__)
# CONF = conf.CONF
# def from_json(req):
# def to_json(data):
# def validate_json_content_type(req):
# def validate_authorization(http_request, authorized_rules_list):
# def validate_payload_size(content_length):
# def get_x_tenant_or_tenant_id(http_request, delegate_authorized_rules_list):
# def get_query_param(req, param_name, required=False, default_val=None):
# def get_query_name(req, name_required=False):
# def get_query_dimensions(req, param_key='dimensions'):
# def get_query_starttime_timestamp(req, required=True):
# def get_query_endtime_timestamp(req, required=True):
# def validate_start_end_timestamps(start_timestamp, end_timestamp=None):
# def _convert_time_string(date_time_string):
# def get_query_statistics(req):
# def get_query_period(req):
# def get_query_group_by(req):
# def validate_query_name(name):
# def validate_query_dimensions(dimensions):
# def paginate(resource, uri, limit):
# def paginate_with_no_id(dictionary_list, uri, offset, limit):
# def _truncate_with_offset(resource, value_list, offset):
# def paginate_alarming(resource, uri, limit):
# def paginate_dimension_values(dimvals, uri, offset, limit):
# def _truncate_dimension_values(values, limit, offset):
# def paginate_measurements(measurements, uri, limit):
# def _get_old_query_params(parsed_uri):
# def _get_old_query_params_except_offset(new_query_params, parsed_uri):
# def paginate_statistics(statistics, uri, limit):
# def create_alarms_count_next_link(uri, offset, limit):
# def build_base_uri(parsed_uri):
# def get_link(uri, resource_id, rel='self'):
# def add_links_to_resource(resource, uri, rel='self'):
# def add_links_to_resource_list(resourcelist, uri):
# def raise_not_found_exception(resource_name, resource_id, tenant_id):
# def str_2_bool(s):


import falcon
from monasca_api.api import healthcheck_api
from monasca_api.healthcheck import alarms_db_check
from monasca_api.healthcheck import kafka_check
from monasca_api.healthcheck import metrics_db_check
from monasca_api.v2.reference import helpers
    HEALTHY_CODE_GET = falcon.HTTP_OK
    HEALTHY_CODE_HEAD = falcon.HTTP_NO_CONTENT
    NOT_HEALTHY_CODE = falcon.HTTP_SERVICE_UNAVAILABLE

    def __init__(self):
        super(HealthChecks, self).__init__()
        self._kafka_check = kafka_check.KafkaHealthCheck()
        self._alarm_db_check = alarms_db_check.AlarmsDbHealthCheck()
        self._metrics_db_check = metrics_db_check.MetricsDbCheck()

    def on_head(self, req, res):
        res.status = self.HEALTHY_CODE_HEAD
        res.cache_control = self.CACHE_CONTROL

    def on_get(self, req, res):
        helpers.validate_authorization(req, ['api:healthcheck'])
        kafka_result = self._kafka_check.health_check()
        alarms_db_result = self._alarm_db_check.health_check()
        metrics_db_result = self._metrics_db_check.health_check()

        status_data = {
            'kafka': kafka_result.message,
            'alarms_database': alarms_db_result.message,
            'metrics_database': metrics_db_result.message
        }
        health = (kafka_result.healthy and alarms_db_result.healthy and
                  metrics_db_result.healthy)
        res.status = (self.HEALTHY_CODE_GET
                      if health else self.NOT_HEALTHY_CODE)
        res.cache_control = self.CACHE_CONTROL

# Path: monasca_api/api/healthcheck_api.py
# LOG = log.getLogger(__name__)
# class HealthCheckApi(object):
#     def __init__(self):
#     def on_get(self, req, res):
#     def on_head(self, req, res):
# 
# Path: monasca_api/healthcheck/alarms_db_check.py
# LOG = log.getLogger(__name__)
# class AlarmsDbHealthCheck(base.BaseHealthCheck,
#                           sql_repository.SQLRepository):
#     def health_check(self):
#     def check_db_status(self):
# 
# Path: monasca_api/healthcheck/metrics_db_check.py
# CONF = cfg.CONF
# LOG = log.getLogger(__name__)
# class MetricsDbCheck(base.BaseHealthCheck):
#     def __init__(self):
#     def health_check(self):
# 
# Path: monasca_api/v2/reference/helpers.py
# LOG = log.getLogger(__name__)
# CONF = conf.CONF
# def from_json(req):
# def to_json(data):
# def validate_json_content_type(req):
# def validate_authorization(http_request, authorized_rules_list):
# def validate_payload_size(content_length):
# def get_x_tenant_or_tenant_id(http_request, delegate_authorized_rules_list):
# def get_query_param(req, param_name, required=False, default_val=None):
# def get_query_name(req, name_required=False):
# def get_query_dimensions(req, param_key='dimensions'):
# def get_query_starttime_timestamp(req, required=True):
# def get_query_endtime_timestamp(req, required=True):
# def validate_start_end_timestamps(start_timestamp, end_timestamp=None):
# def _convert_time_string(date_time_string):
# def get_query_statistics(req):
# def get_query_period(req):
# def get_query_group_by(req):
# def validate_query_name(name):
# def validate_query_dimensions(dimensions):
# def paginate(resource, uri, limit):
# def paginate_with_no_id(dictionary_list, uri, offset, limit):
# def _truncate_with_offset(resource, value_list, offset):
# def paginate_alarming(resource, uri, limit):
# def paginate_dimension_values(dimvals, uri, offset, limit):
# def _truncate_dimension_values(values, limit, offset):
# def paginate_measurements(measurements, uri, limit):
# def _get_old_query_params(parsed_uri):
# def _get_old_query_params_except_offset(new_query_params, parsed_uri):
# def paginate_statistics(statistics, uri, limit):
# def create_alarms_count_next_link(uri, offset, limit):
# def build_base_uri(parsed_uri):
# def get_link(uri, resource_id, rel='self'):
# def add_links_to_resource(resource, uri, rel='self'):
# def add_links_to_resource_list(resourcelist, uri):
# def raise_not_found_exception(resource_name, resource_id, tenant_id):
# def str_2_bool(s):


# Path: monasca_api/healthchecks.py
import falcon
from monasca_api.api import healthcheck_api
from monasca_api.healthcheck import alarms_db_check
from monasca_api.healthcheck import kafka_check
from monasca_api.healthcheck import metrics_db_check
from monasca_api.v2.reference import helpers

    HEALTHY_CODE_GET = falcon.HTTP_OK
    HEALTHY_CODE_HEAD = falcon.HTTP_NO_CONTENT
    NOT_HEALTHY_CODE = falcon.HTTP_SERVICE_UNAVAILABLE

    def __init__(self):
        super(HealthChecks, self).__init__()
        self._kafka_check = kafka_check.KafkaHealthCheck()
        self._alarm_db_check = alarms_db_check.AlarmsDbHealthCheck()
        self._metrics_db_check = metrics_db_check.MetricsDbCheck()

    def on_head(self, req, res):
        res.status = self.HEALTHY_CODE_HEAD
        res.cache_control = self.CACHE_CONTROL

    def on_get(self, req, res):
        helpers.validate_authorization(req, ['api:healthcheck'])
        kafka_result = self._kafka_check.health_check()
        alarms_db_result = self._alarm_db_check.health_check()
        metrics_db_result = self._metrics_db_check.health_check()

        status_data = {
            'kafka': kafka_result.message,
            'alarms_database': alarms_db_result.message,
            'metrics_database': metrics_db_result.message
        }
        health = (kafka_result.healthy and alarms_db_result.healthy and
                  metrics_db_result.healthy)
        res.status = (self.HEALTHY_CODE_GET
                      if health else self.NOT_HEALTHY_CODE)
        res.cache_control = self.CACHE_CONTROL

        res.body = helpers.to_json(status_data)