Add Alarms resources files

Change-Id: If2305a636b0b5eedc09a8f49ab9466c7bcc476ed
This commit is contained in:
Deklan Dieterly 2014-11-07 14:34:34 -07:00
parent cbedd43002
commit 9a31307470
10 changed files with 261 additions and 55 deletions

View File

@ -42,6 +42,9 @@ transforms_driver = mysql_transforms_repo
# The driver to use for the alarm definitions repository
alarm_definitions_driver = mysql_alarm_definitions_repo
# The driver to use for the alarms repository
alarms_driver = mysql_alarms_repo
# The driver to use for the notifications repository
notifications_driver = mysql_notifications_repo

View File

@ -0,0 +1,44 @@
# Copyright 2014 Hewlett-Packard
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from monasca.common import resource_api
from monasca.openstack.common import log
LOG = log.getLogger(__name__)
class AlarmsV2API(object):
def __init__(self, global_conf):
LOG.debug('initializing AlarmsV2API!')
self.global_conf = global_conf
@resource_api.Restify('/v2.0/alarms/{id}', method='put')
def do_put_alarms(self, req, res, id):
res.status = '501 Not Implemented'
@resource_api.Restify('/v2.0/alarms/{id}', method='patch')
def do_patch_alarms(self, req, res, id):
res.status = '501 Not Implemented'
@resource_api.Restify('/v2.0/alarms/{id}', method='delete')
def do_delete_alarms(self, req, res, id):
res.status = '501 Not Implemented'
@resource_api.Restify('/v2.0/alarms/', method='get')
def do_get_alarms(self, req, res, id):
res.status = '501 Not Implemented'
@resource_api.Restify('/v2.0/alarms/{id}', method='get')
def do_get_alarm_by_id(self, req, res, id):
res.status = '501 Not Implemented'

View File

@ -46,25 +46,7 @@ class V2API(object):
def do_get_statistics(self, req, res):
res.status = '501 Not Implemented'
@resource_api.Restify('/v2.0/alarms/{id}', method='put')
def do_put_alarms(self, req, res, id):
res.status = '501 Not Implemented'
@resource_api.Restify('/v2.0/alarms/{id}', method='patch')
def do_patch_alarms(self, req, res, id):
res.status = '501 Not Implemented'
@resource_api.Restify('/v2.0/alarms/{id}', method='delete')
def do_delete_alarms(self, req, res, id):
res.status = '501 Not Implemented'
@resource_api.Restify('/v2.0/alarms/', method='get')
def do_get_alarms(self, req, res, id):
res.status = '501 Not Implemented'
@resource_api.Restify('/v2.0/alarms/{id}', method='get')
def do_get_alarm_by_id(self, req, res, id):
res.status = '501 Not Implemented'
@resource_api.Restify('/v2.0/alarms/state-history', method='get')
def do_get_alarms_state_history(self, req, res, id):

View File

@ -25,6 +25,7 @@ from wsgiref import simple_server
METRICS_DISPATCHER_NAMESPACE = 'monasca.metrics_dispatcher'
ALARM_DEFINITIONS_DISPATCHER_NAMESPACE = 'monasca.alarm_definitions_dispatcher'
ALARMS_DISPATCHER_NAMESPACE = 'monasca.alarms_dispatcher'
EVENTS_DISPATCHER_NAMESPACE = 'monasca.events_dispatcher'
TRANSFORMS_DISPATCHER_NAMESPACE = 'monasca.transforms_dispatcher'
NOTIFICATIONS_DISPATCHER_NAMESPACE = 'monasca.notifications_dispatcher'
@ -68,6 +69,8 @@ repositories_opts = [
cfg.StrOpt('alarm_definitions_driver',
default='mysql_alarm_definitions_repo',
help='The repository driver to use for alarm definitions'),
cfg.StrOpt('alarms_driver', default='mysql_alarms_repo',
help='The repository driver to use for alarms'),
cfg.StrOpt('events_driver', default='fake_events_repo',
help='The repository driver to use for events'),
cfg.StrOpt('transforms_driver', default='mysql_transforms_repo',
@ -97,9 +100,9 @@ kafka_opts = [cfg.StrOpt('uri', help='Address to kafka server. For example: '
help='The group name that this service belongs to.'),
cfg.IntOpt('wait_time', default=1,
help='The wait time when no messages on kafka '
'queue.'),
cfg.IntOpt('ack_time', default=20,
help='The ack time back to kafka.'),
'queue.'), cfg.IntOpt('ack_time', default=20,
help='The ack time back '
'to kafka.'),
cfg.IntOpt('max_retry', default=3,
help='The number of retry when there is a '
'connection error.'),
@ -108,16 +111,16 @@ kafka_opts = [cfg.StrOpt('uri', help='Address to kafka server. For example: '
'messages.'),
cfg.BoolOpt('async', default=True, help='The type of posting.'),
cfg.BoolOpt('compact', default=True, help=(
'Specify if the message received should be parsed.'
'If True, message will not be parsed, otherwise '
'messages will be parsed.')),
'Specify if the message received should be parsed.'
'If True, message will not be parsed, otherwise '
'messages will be parsed.')),
cfg.MultiOpt('partitions', item_type=types.Integer(),
default=[0],
help='The sleep time when no messages on kafka '
'queue.'),
cfg.BoolOpt('drop_data', default=False, help=(
'Specify if received data should be simply dropped. '
'This parameter is only for testing purposes.')), ]
'Specify if received data should be simply dropped. '
'This parameter is only for testing purposes.')), ]
kafka_group = cfg.OptGroup(name='kafka', title='title')
cfg.CONF.register_group(kafka_group)
@ -171,6 +174,11 @@ def api_app(conf):
ALARM_DEFINITIONS_DISPATCHER_NAMESPACE,
cfg.CONF.dispatcher.driver, [conf])
# load the alarm definitions resource
app.add_resource('alarms',
ALARM_DEFINITIONS_DISPATCHER_NAMESPACE,
cfg.CONF.dispatcher.driver, [conf])
return app

View File

@ -0,0 +1,20 @@
# Copyright 2014 Hewlett-Packard
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import abc
import six
@six.add_metaclass(abc.ABCMeta)
class AlarmsRepository(object):
pass

View File

@ -17,6 +17,7 @@ import pyodbc
from oslo.config import cfg
from monasca.common.repositories import alarm_definitions_repository
from monasca.common.repositories.mysql.mysql_repository import MySQLRepository
from monasca.openstack.common import log
from monasca.openstack.common import uuidutils
from monasca.common.repositories import exceptions
@ -25,40 +26,14 @@ from monasca.common.repositories import exceptions
LOG = log.getLogger(__name__)
class AlarmDefinitionsRepository(
class AlarmDefinitionsRepository(MySQLRepository,
alarm_definitions_repository.AlarmDefinitionsRepository):
database_driver = 'MySQL ODBC 5.3 ANSI Driver'
database_cnxn_template = 'DRIVER={' \
'%s};Server=%s;CHARSET=UTF8;Database=%s;Uid=%s' \
';Pwd=%s'
def __init__(self):
try:
self.conf = cfg.CONF
database_name = self.conf.mysql.database_name
database_server = self.conf.mysql.hostname
database_uid = self.conf.mysql.username
database_pwd = self.conf.mysql.password
self._cnxn_string = (
AlarmDefinitionsRepository.database_cnxn_template % (
AlarmDefinitionsRepository.database_driver,
database_server, database_name, database_uid,
database_pwd))
super(AlarmDefinitionsRepository, self).__init__()
except Exception as ex:
LOG.exception(ex)
raise exceptions.RepositoryException(ex)
def _get_cnxn_cursor_tuple(self):
cnxn = pyodbc.connect(self._cnxn_string)
cursor = cnxn.cursor()
return cnxn, cursor
def _commit_close_cnxn(self, cnxn):
cnxn.commit()
cnxn.close()
def get_alarm_definition_list(self, tenant_id, name, dimensions):

View File

@ -0,0 +1,33 @@
# Copyright 2014 Hewlett-Packard
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import datetime
import pyodbc
from oslo.config import cfg
from monasca.common.repositories import alarms_repository
from monasca.common.repositories.mysql.mysql_repository import MySQLRepository
from monasca.openstack.common import log
LOG = log.getLogger(__name__)
class AlarmsRepository(MySQLRepository, alarms_repository.AlarmsRepository):
def __init__(self):
super(AlarmsRepository, self).__init__()

View File

@ -0,0 +1,62 @@
# Copyright 2014 Hewlett-Packard
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import datetime
import pyodbc
from oslo.config import cfg
from monasca.common.repositories import alarms_repository
from monasca.openstack.common import log
from monasca.openstack.common import uuidutils
from monasca.common.repositories import exceptions
LOG = log.getLogger(__name__)
class MySQLRepository(object):
database_driver = 'MySQL ODBC 5.3 ANSI Driver'
database_cnxn_template = 'DRIVER={' \
'%s};Server=%s;CHARSET=UTF8;Database=%s;Uid=%s' \
';Pwd=%s'
def __init__(self):
try:
self.conf = cfg.CONF
database_name = self.conf.mysql.database_name
database_server = self.conf.mysql.hostname
database_uid = self.conf.mysql.username
database_pwd = self.conf.mysql.password
self._cnxn_string = (
MySQLRepository.database_cnxn_template % (
MySQLRepository.database_driver,
database_server, database_name, database_uid,
database_pwd))
except Exception as ex:
LOG.exception(ex)
raise exceptions.RepositoryException(ex)
def _get_cnxn_cursor_tuple(self):
cnxn = pyodbc.connect(self._cnxn_string)
cursor = cnxn.cursor()
return cnxn, cursor
def _commit_close_cnxn(self, cnxn):
cnxn.commit()
cnxn.close()

View File

@ -0,0 +1,78 @@
# Copyright 2014 Hewlett-Packard
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import json
from pyparsing import ParseException
import falcon
from oslo.config import cfg
from monasca.api.alarms_api_v2 import AlarmsV2API
from monasca.common.repositories import exceptions
from monasca.common import resource_api
from monasca.api.alarm_definitions_api_v2 import AlarmDefinitionsV2API
from monasca.expression_parser.alarm_expr_parser import AlarmExprParser
from monasca.openstack.common import log
from monasca.v2.reference import helpers
from monasca.v2.common.schemas import alarm_definition_request_body_schema as schema_alarms
from monasca.v2.common.schemas import exceptions as schemas_exceptions
from monasca.v2.reference.helpers import read_json_msg_body
from monasca.common.messaging import exceptions as message_queue_exceptions
LOG = log.getLogger(__name__)
class Alarms(AlarmsV2API):
def __init__(self, global_conf):
try:
super(Alarms, self).__init__(global_conf)
self._region = cfg.CONF.region
self._default_authorized_roles = cfg.CONF.security.default_authorized_roles
self._delegate_authorized_roles = cfg.CONF.security.delegate_authorized_roles
self._post_metrics_authorized_roles = cfg.CONF.security.default_authorized_roles + cfg.CONF.security.agent_authorized_roles
self._message_queue = resource_api.init_driver('monasca.messaging',
cfg.CONF.messaging.driver,
(['events']))
self._alarms_repo = resource_api.init_driver(
'monasca.repositories',
cfg.CONF.repositories.alarms_driver)
except Exception as ex:
LOG.exception(ex)
raise exceptions.RepositoryException(ex)
@resource_api.Restify('/v2.0/alarms/{id}', method='put')
def do_put_alarms(self, req, res, id):
res.status = '501 Not Implemented'
@resource_api.Restify('/v2.0/alarms/{id}', method='patch')
def do_patch_alarms(self, req, res, id):
res.status = '501 Not Implemented'
@resource_api.Restify('/v2.0/alarms/{id}', method='delete')
def do_delete_alarms(self, req, res, id):
res.status = '501 Not Implemented'
@resource_api.Restify('/v2.0/alarms/', method='get')
def do_get_alarms(self, req, res, id):
res.status = '501 Not Implemented'
@resource_api.Restify('/v2.0/alarms/{id}', method='get')
def do_get_alarm_by_id(self, req, res, id):
res.status = '501 Not Implemented'

View File

@ -66,6 +66,7 @@ monasca.repositories =
fake_events_repo = monasca.common.repositories.fake.events_repository:EventsRepository
mysql_transforms_repo = monasca.common.repositories.mysql.transforms_repository:TransformsRepository
mysql_alarm_definitions_repo = monasca.common.repositories.mysql.alarm_definitions_repository:AlarmDefinitionsRepository
mysql_alarms_repo = monasca.common.repositories.mysql.alarms_repository:AlarmsRepository
mysql_notifications_repo = monasca.common.repositories.mysql.notifications_repository:NotificationsRepository
[pbr]