Move aodh.alarm.storage to aodh.storage

Change-Id: I1179addc15624800e4113a6b7ea21999dd45d66f
This commit is contained in:
Julien Danjou 2015-06-29 17:33:37 +02:00
parent b8a678929d
commit a16fa7ae8a
29 changed files with 198 additions and 213 deletions

View File

@ -20,9 +20,9 @@ from oslo_context import context
from oslo_log import log
import six
from aodh.alarm.storage import models
from aodh.i18n import _
from aodh import messaging
from aodh.storage import models
OPTS = [
cfg.StrOpt('notifier_rpc_topic',

View File

@ -1,166 +0,0 @@
#
# Copyright 2012 New Dream Network, LLC (DreamHost)
#
# 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.
"""Base classes for storage engines
"""
import aodh
class Connection(object):
"""Base class for alarm storage system connections."""
# A dictionary representing the capabilities of this driver.
CAPABILITIES = {
'alarms': {'query': {'simple': False,
'complex': False},
'history': {'query': {'simple': False,
'complex': False}}},
}
STORAGE_CAPABILITIES = {
'storage': {'production_ready': False},
}
def __init__(self, url):
pass
@staticmethod
def upgrade():
"""Migrate the database to `version` or the most recent version."""
@staticmethod
def get_alarms(name=None, user=None, state=None, meter=None,
project=None, enabled=None, alarm_id=None,
alarm_type=None, severity=None):
"""Yields a lists of alarms that match filters.
:param name: Optional name for alarm.
:param user: Optional ID for user that owns the resource.
:param state: Optional string for alarm state.
:param meter: Optional string for alarms associated with meter.
:param project: Optional ID for project that owns the resource.
:param enabled: Optional boolean to list disable alarm.
:param alarm_id: Optional alarm_id to return one alarm.
:param alarm_type: Optional alarm type.
:parmr severity: Optional alarm severity
"""
raise aodh.NotImplementedError('Alarms not implemented')
@staticmethod
def create_alarm(alarm):
"""Create an alarm. Returns the alarm as created.
:param alarm: The alarm to create.
"""
raise aodh.NotImplementedError('Alarms not implemented')
@staticmethod
def update_alarm(alarm):
"""Update alarm."""
raise aodh.NotImplementedError('Alarms not implemented')
@staticmethod
def delete_alarm(alarm_id):
"""Delete an alarm."""
raise aodh.NotImplementedError('Alarms not implemented')
@staticmethod
def get_alarm_changes(alarm_id, on_behalf_of,
user=None, project=None, alarm_type=None,
severity=None, start_timestamp=None,
start_timestamp_op=None, end_timestamp=None,
end_timestamp_op=None):
"""Yields list of AlarmChanges describing alarm history
Changes are always sorted in reverse order of occurrence, given
the importance of currency.
Segregation for non-administrative users is done on the basis
of the on_behalf_of parameter. This allows such users to have
visibility on both the changes initiated by themselves directly
(generally creation, rule changes, or deletion) and also on those
changes initiated on their behalf by the alarming service (state
transitions after alarm thresholds are crossed).
:param alarm_id: ID of alarm to return changes for
:param on_behalf_of: ID of tenant to scope changes query (None for
administrative user, indicating all projects)
:param user: Optional ID of user to return changes for
:param project: Optional ID of project to return changes for
:param alarm_type: Optional change type
:param severity: Optional change severity
:param start_timestamp: Optional modified timestamp start range
:param start_timestamp_op: Optional timestamp start range operation
:param end_timestamp: Optional modified timestamp end range
:param end_timestamp_op: Optional timestamp end range operation
"""
raise aodh.NotImplementedError('Alarm history not implemented')
@staticmethod
def record_alarm_change(alarm_change):
"""Record alarm change event."""
raise aodh.NotImplementedError('Alarm history not implemented')
@staticmethod
def clear():
"""Clear database."""
@staticmethod
def query_alarms(filter_expr=None, orderby=None, limit=None):
"""Return an iterable of model.Alarm objects.
:param filter_expr: Filter expression for query.
:param orderby: List of field name and direction pairs for order by.
:param limit: Maximum number of results to return.
"""
raise aodh.NotImplementedError('Complex query for alarms '
'is not implemented.')
@staticmethod
def query_alarm_history(filter_expr=None, orderby=None, limit=None):
"""Return an iterable of model.AlarmChange objects.
:param filter_expr: Filter expression for query.
:param orderby: List of field name and direction pairs for order by.
:param limit: Maximum number of results to return.
"""
raise aodh.NotImplementedError('Complex query for alarms '
'history is not implemented.')
@classmethod
def get_capabilities(cls):
"""Return an dictionary with the capabilities of each driver."""
return cls.CAPABILITIES
@classmethod
def get_storage_capabilities(cls):
"""Return a dictionary representing the performance capabilities.
This is needed to evaluate the performance of each driver.
"""
return cls.STORAGE_CAPABILITIES
@staticmethod
def clear_expired_alarm_history_data(alarm_history_ttl):
"""Clear expired alarm history data from the backend storage system.
Clearing occurs according to the time-to-live.
:param alarm_history_ttl: Number of seconds to keep alarm history
records for.
"""
raise aodh.NotImplementedError('Clearing alarm history '
'not implemented')

View File

@ -39,13 +39,13 @@ import wsmeext.pecan as wsme_pecan
import aodh
from aodh import alarm as aodh_alarm
from aodh.alarm.storage import models as alarm_models
from aodh.api.controllers.v2.alarm_rules import combination
from aodh.api.controllers.v2 import base
from aodh.api.controllers.v2 import utils as v2_utils
from aodh.api import rbac
from aodh.i18n import _
from aodh import messaging
from aodh.storage import models
from aodh import utils
LOG = log.getLogger(__name__)
@ -459,7 +459,7 @@ class AlarmController(rest.RestController):
def _record_change(self, data, now, on_behalf_of=None, type=None):
if not cfg.CONF.alarm.record_history:
return
type = type or alarm_models.AlarmChange.RULE_CHANGE
type = type or models.AlarmChange.RULE_CHANGE
scrubbed_data = utils.stringify_timestamps(data)
detail = json.dumps(scrubbed_data)
user_id = pecan.request.headers.get('X-User-Id')
@ -533,10 +533,10 @@ class AlarmController(rest.RestController):
ALARMS_RULES[data.type].plugin.update_hook(data)
old_alarm = Alarm.from_db_model(alarm_in).as_dict(alarm_models.Alarm)
updated_alarm = data.as_dict(alarm_models.Alarm)
old_alarm = Alarm.from_db_model(alarm_in).as_dict(models.Alarm)
updated_alarm = data.as_dict(models.Alarm)
try:
alarm_in = alarm_models.Alarm(**updated_alarm)
alarm_in = models.Alarm(**updated_alarm)
except Exception:
LOG.exception(_("Error while putting alarm: %s") % updated_alarm)
raise base.ClientSideError(_("Alarm incorrect"))
@ -558,10 +558,10 @@ class AlarmController(rest.RestController):
# ensure alarm exists before deleting
alarm = self._alarm()
self.conn.delete_alarm(alarm.alarm_id)
change = Alarm.from_db_model(alarm).as_dict(alarm_models.Alarm)
change = Alarm.from_db_model(alarm).as_dict(models.Alarm)
self._record_change(change,
timeutils.utcnow(),
type=alarm_models.AlarmChange.DELETION)
type=models.AlarmChange.DELETION)
@wsme_pecan.wsexpose([AlarmChange], [base.Query])
def history(self, q=None):
@ -605,7 +605,7 @@ class AlarmController(rest.RestController):
alarm = self.conn.update_alarm(alarm)
change = {'state': alarm.state}
self._record_change(change, now, on_behalf_of=alarm.project_id,
type=alarm_models.AlarmChange.STATE_TRANSITION)
type=models.AlarmChange.STATE_TRANSITION)
return alarm.state
@wsme_pecan.wsexpose(state_kind_enum)
@ -629,7 +629,7 @@ class AlarmsController(rest.RestController):
def _record_creation(conn, data, alarm_id, now):
if not cfg.CONF.alarm.record_history:
return
type = alarm_models.AlarmChange.CREATION
type = models.AlarmChange.CREATION
scrubbed_data = utils.stringify_timestamps(data)
detail = json.dumps(scrubbed_data)
user_id = pecan.request.headers.get('X-User-Id')
@ -691,7 +691,7 @@ class AlarmsController(rest.RestController):
ALARMS_RULES[data.type].plugin.create_hook(data)
change = data.as_dict(alarm_models.Alarm)
change = data.as_dict(models.Alarm)
# make sure alarms are unique by name per project.
alarms = list(conn.get_alarms(name=data.name,
@ -702,7 +702,7 @@ class AlarmsController(rest.RestController):
status_code=409)
try:
alarm_in = alarm_models.Alarm(**change)
alarm_in = models.Alarm(**change)
except Exception:
LOG.exception(_("Error while posting alarm: %s") % change)
raise base.ClientSideError(_("Alarm incorrect"))

View File

@ -28,11 +28,11 @@ from pecan import rest
from wsme import types as wtypes
import wsmeext.pecan as wsme_pecan
from aodh.alarm.storage import models as alarm_models
from aodh.api.controllers.v2 import alarms
from aodh.api.controllers.v2 import base
from aodh.api import rbac
from aodh.i18n import _
from aodh.storage import models
from aodh import utils
LOG = log.getLogger(__name__)
@ -339,7 +339,7 @@ class QueryAlarmHistoryController(rest.RestController):
rbac.enforce('query_alarm_history', pecan.request)
query = ValidatedComplexQuery(body,
alarm_models.AlarmChange)
models.AlarmChange)
query.validate(visibility_field="on_behalf_of")
conn = pecan.request.alarm_storage_conn
return [alarms.AlarmChange.from_db_model(s)
@ -362,7 +362,7 @@ class QueryAlarmsController(rest.RestController):
rbac.enforce('query_alarm', pecan.request)
query = ValidatedComplexQuery(body,
alarm_models.Alarm)
models.Alarm)
query.validate(visibility_field="project_id")
conn = pecan.request.alarm_storage_conn
return [alarms.Alarm.from_db_model(s)

View File

@ -19,6 +19,8 @@ import inspect
import six
import aodh
class Model(object):
"""Base class for storage API models."""
@ -46,3 +48,152 @@ class Model(object):
def get_field_names(cls):
fields = inspect.getargspec(cls.__init__)[0]
return set(fields) - set(["self"])
class Connection(object):
"""Base class for alarm storage system connections."""
# A dictionary representing the capabilities of this driver.
CAPABILITIES = {
'alarms': {'query': {'simple': False,
'complex': False},
'history': {'query': {'simple': False,
'complex': False}}},
}
STORAGE_CAPABILITIES = {
'storage': {'production_ready': False},
}
def __init__(self, url):
pass
@staticmethod
def upgrade():
"""Migrate the database to `version` or the most recent version."""
@staticmethod
def get_alarms(name=None, user=None, state=None, meter=None,
project=None, enabled=None, alarm_id=None,
alarm_type=None, severity=None):
"""Yields a lists of alarms that match filters.
:param name: Optional name for alarm.
:param user: Optional ID for user that owns the resource.
:param state: Optional string for alarm state.
:param meter: Optional string for alarms associated with meter.
:param project: Optional ID for project that owns the resource.
:param enabled: Optional boolean to list disable alarm.
:param alarm_id: Optional alarm_id to return one alarm.
:param alarm_type: Optional alarm type.
:parmr severity: Optional alarm severity
"""
raise aodh.NotImplementedError('Alarms not implemented')
@staticmethod
def create_alarm(alarm):
"""Create an alarm. Returns the alarm as created.
:param alarm: The alarm to create.
"""
raise aodh.NotImplementedError('Alarms not implemented')
@staticmethod
def update_alarm(alarm):
"""Update alarm."""
raise aodh.NotImplementedError('Alarms not implemented')
@staticmethod
def delete_alarm(alarm_id):
"""Delete an alarm."""
raise aodh.NotImplementedError('Alarms not implemented')
@staticmethod
def get_alarm_changes(alarm_id, on_behalf_of,
user=None, project=None, alarm_type=None,
severity=None, start_timestamp=None,
start_timestamp_op=None, end_timestamp=None,
end_timestamp_op=None):
"""Yields list of AlarmChanges describing alarm history
Changes are always sorted in reverse order of occurrence, given
the importance of currency.
Segregation for non-administrative users is done on the basis
of the on_behalf_of parameter. This allows such users to have
visibility on both the changes initiated by themselves directly
(generally creation, rule changes, or deletion) and also on those
changes initiated on their behalf by the alarming service (state
transitions after alarm thresholds are crossed).
:param alarm_id: ID of alarm to return changes for
:param on_behalf_of: ID of tenant to scope changes query (None for
administrative user, indicating all projects)
:param user: Optional ID of user to return changes for
:param project: Optional ID of project to return changes for
:param alarm_type: Optional change type
:param severity: Optional change severity
:param start_timestamp: Optional modified timestamp start range
:param start_timestamp_op: Optional timestamp start range operation
:param end_timestamp: Optional modified timestamp end range
:param end_timestamp_op: Optional timestamp end range operation
"""
raise aodh.NotImplementedError('Alarm history not implemented')
@staticmethod
def record_alarm_change(alarm_change):
"""Record alarm change event."""
raise aodh.NotImplementedError('Alarm history not implemented')
@staticmethod
def clear():
"""Clear database."""
@staticmethod
def query_alarms(filter_expr=None, orderby=None, limit=None):
"""Return an iterable of model.Alarm objects.
:param filter_expr: Filter expression for query.
:param orderby: List of field name and direction pairs for order by.
:param limit: Maximum number of results to return.
"""
raise aodh.NotImplementedError('Complex query for alarms '
'is not implemented.')
@staticmethod
def query_alarm_history(filter_expr=None, orderby=None, limit=None):
"""Return an iterable of model.AlarmChange objects.
:param filter_expr: Filter expression for query.
:param orderby: List of field name and direction pairs for order by.
:param limit: Maximum number of results to return.
"""
raise aodh.NotImplementedError('Complex query for alarms '
'history is not implemented.')
@classmethod
def get_capabilities(cls):
"""Return an dictionary with the capabilities of each driver."""
return cls.CAPABILITIES
@classmethod
def get_storage_capabilities(cls):
"""Return a dictionary representing the performance capabilities.
This is needed to evaluate the performance of each driver.
"""
return cls.STORAGE_CAPABILITIES
@staticmethod
def clear_expired_alarm_history_data(alarm_history_ttl):
"""Clear expired alarm history data from the backend storage system.
Clearing occurs according to the time-to-live.
:param alarm_history_ttl: Number of seconds to keep alarm history
records for.
"""
raise aodh.NotImplementedError('Clearing alarm history '
'not implemented')

View File

@ -21,9 +21,9 @@ from __future__ import division
from oslo_log import log
import pymongo
from aodh.alarm.storage import pymongo_base
from aodh import storage
from aodh.storage.mongo import utils as pymongo_utils
from aodh.storage import pymongo_base
LOG = log.getLogger(__name__)

View File

@ -17,12 +17,12 @@ import operator
from oslo_log import log
import aodh
from aodh.alarm.storage import base
from aodh.alarm.storage import models
from aodh.i18n import _
from aodh.storage import base
from aodh.storage.hbase import base as hbase_base
from aodh.storage.hbase import migration as hbase_migration
from aodh.storage.hbase import utils as hbase_utils
from aodh.storage import models
from aodh import utils
LOG = log.getLogger(__name__)

View File

@ -17,8 +17,8 @@
from oslo_log import log
from aodh.alarm.storage import base
from aodh.i18n import _LI
from aodh.storage import base
LOG = log.getLogger(__name__)

View File

@ -24,11 +24,11 @@ from oslo_config import cfg
from oslo_log import log
import pymongo
from aodh.alarm.storage import pymongo_base
from aodh import storage
from aodh.storage.mongo import utils as pymongo_utils
from aodh.storage import pymongo_base
cfg.CONF.import_opt('alarm_history_time_to_live', 'aodh.alarm.storage',
cfg.CONF.import_opt('alarm_history_time_to_live', 'aodh.storage',
group="database")
LOG = log.getLogger(__name__)

View File

@ -21,9 +21,9 @@ from oslo_log import log
from oslo_utils import timeutils
from sqlalchemy import desc
from aodh.alarm.storage import base
from aodh.alarm.storage import models as alarm_api_models
from aodh.i18n import _LI
from aodh.storage import base
from aodh.storage import models as alarm_api_models
from aodh.storage.sqlalchemy import models
from aodh.storage.sqlalchemy import utils as sql_utils
from aodh import utils

View File

@ -21,8 +21,8 @@
from oslo_log import log
import pymongo
from aodh.alarm.storage import base
from aodh.alarm.storage import models
from aodh.storage import base
from aodh.storage import models
from aodh.storage.mongo import utils as pymongo_utils
from aodh import utils

View File

@ -28,7 +28,7 @@ from oslo_utils import timeutils
import pytz
from aodh.alarm.evaluator import combination
from aodh.alarm.storage import models
from aodh.storage import models
from aodh.tests.alarm.evaluator import base
from aodh.tests import constants

View File

@ -26,7 +26,7 @@ import six
from six import moves
from aodh.alarm.evaluator import gnocchi
from aodh.alarm.storage import models
from aodh.storage import models
from aodh.tests.alarm.evaluator import base
from aodh.tests import constants

View File

@ -26,7 +26,7 @@ import pytz
from six import moves
from aodh.alarm.evaluator import threshold
from aodh.alarm.storage import models
from aodh.storage import models
from aodh.tests.alarm.evaluator import base
from aodh.tests import constants

View File

@ -22,8 +22,8 @@ from oslo_config import fixture as fixture_config
import six
from aodh.alarm import rpc as rpc_alarm
from aodh.alarm.storage import models
from aodh import messaging
from aodh.storage import models
from aodh.tests import base as tests_base

View File

@ -25,8 +25,8 @@ import six
from six import moves
import six.moves.urllib.parse as urlparse
from aodh.alarm.storage import models
from aodh import messaging
from aodh.storage import models
from aodh.tests.api import v2
from aodh.tests import constants
from aodh.tests import db as tests_db

View File

@ -24,8 +24,8 @@ import mock
from oslotest import base
import wsme
from aodh.alarm.storage import models as alarm_models
from aodh.api.controllers.v2 import query
from aodh.storage import models as alarm_models
class FakeComplexQuery(query.ValidatedComplexQuery):

View File

@ -22,7 +22,7 @@ import datetime
from oslo_utils import timeutils
from aodh.alarm.storage import models
from aodh.storage import models
from aodh.tests.api import v2 as tests_api
from aodh.tests import db as tests_db

View File

@ -23,10 +23,10 @@ from oslotest import base
from oslotest import mockpatch
import wsme
from aodh.alarm.storage import base as alarm_storage_base
from aodh.api.controllers.v2 import base as v2_base
from aodh.api.controllers.v2 import utils
from aodh import storage
from aodh.storage import base as alarm_storage_base
from aodh.tests import base as tests_base

View File

@ -19,8 +19,8 @@ from oslo_config import fixture as fixture_config
from oslotest import base
import retrying
from aodh.alarm.storage import impl_log
from aodh import storage
from aodh.storage import impl_log
import six

View File

@ -23,7 +23,7 @@
"""
from aodh.alarm.storage import impl_db2
from aodh.storage import impl_db2
from aodh.tests import base as test_base

View File

@ -28,7 +28,7 @@ except ImportError:
import testtools.testcase
raise testtools.testcase.TestSkipped("happybase is needed")
from aodh.alarm.storage import impl_hbase
from aodh.storage import impl_hbase
from aodh.tests import base as test_base
from aodh.tests import db as tests_db

View File

@ -16,7 +16,7 @@
"""
from oslotest import base
from aodh.alarm.storage import impl_log
from aodh.storage import impl_log
class ConnectionTest(base.BaseTestCase):

View File

@ -21,7 +21,7 @@
"""
from aodh.alarm.storage import impl_mongodb as impl_mongodb
from aodh.storage import impl_mongodb
from aodh.tests import base as test_base
from aodh.tests import db as tests_db

View File

@ -18,7 +18,7 @@
"""
from aodh.alarm.storage import impl_sqlalchemy as impl_sqla_alarm
from aodh.storage import impl_sqlalchemy as impl_sqla_alarm
from aodh.tests import base as test_base

View File

@ -20,7 +20,7 @@ import datetime
import mock
from oslo_utils import timeutils
from aodh.alarm.storage import models as alarm_models
from aodh.storage import models as alarm_models
from aodh.tests import constants
from aodh.tests import db as tests_db

View File

@ -27,13 +27,13 @@ packages =
[entry_points]
aodh.alarm.storage =
log = aodh.alarm.storage.impl_log:Connection
mongodb = aodh.alarm.storage.impl_mongodb:Connection
mysql = aodh.alarm.storage.impl_sqlalchemy:Connection
postgresql = aodh.alarm.storage.impl_sqlalchemy:Connection
sqlite = aodh.alarm.storage.impl_sqlalchemy:Connection
hbase = aodh.alarm.storage.impl_hbase:Connection
db2 = aodh.alarm.storage.impl_db2:Connection
log = aodh.storage.impl_log:Connection
mongodb = aodh.storage.impl_mongodb:Connection
mysql = aodh.storage.impl_sqlalchemy:Connection
postgresql = aodh.storage.impl_sqlalchemy:Connection
sqlite = aodh.storage.impl_sqlalchemy:Connection
hbase = aodh.storage.impl_hbase:Connection
db2 = aodh.storage.impl_db2:Connection
aodh.alarm.rule =
threshold = aodh.api.controllers.v2.alarm_rules.threshold:AlarmThresholdRule