Merge "storage: factorize not implemented methods"

This commit is contained in:
Jenkins 2013-12-20 14:06:09 +00:00 committed by Gerrit Code Review
commit 58490558ee
5 changed files with 68 additions and 363 deletions

View File

@ -112,20 +112,19 @@ class StorageEngine(object):
"""Return a Connection instance based on the configuration settings."""
@six.add_metaclass(abc.ABCMeta)
class Connection(object):
"""Base class for storage system connections."""
@abc.abstractmethod
def __init__(self, conf):
@staticmethod
def __init__(conf):
"""Constructor."""
@abc.abstractmethod
def upgrade(self):
@staticmethod
def upgrade():
"""Migrate the database to `version` or the most recent version."""
@abc.abstractmethod
def record_metering_data(self, data):
@staticmethod
def record_metering_data(data):
"""Write the data to the backend storage system.
:param data: a dictionary such as returned by
@ -133,32 +132,36 @@ class Connection(object):
All timestamps must be naive utc datetime object.
"""
raise NotImplementedError(_('Projects not implemented'))
@abc.abstractmethod
def clear_expired_metering_data(self, ttl):
@staticmethod
def clear_expired_metering_data(ttl):
"""Clear expired data from the backend storage system according to the
time-to-live.
:param ttl: Number of seconds to keep records for.
"""
raise NotImplementedError(_('Clearing samples not implemented'))
@abc.abstractmethod
def get_users(self, source=None):
@staticmethod
def get_users(source=None):
"""Return an iterable of user id strings.
:param source: Optional source filter.
"""
raise NotImplementedError(_('Users not implemented'))
@abc.abstractmethod
def get_projects(self, source=None):
@staticmethod
def get_projects(source=None):
"""Return an iterable of project id strings.
:param source: Optional source filter.
"""
raise NotImplementedError(_('Projects not implemented'))
@abc.abstractmethod
def get_resources(self, user=None, project=None, source=None,
@staticmethod
def get_resources(user=None, project=None, source=None,
start_timestamp=None, start_timestamp_op=None,
end_timestamp=None, end_timestamp_op=None,
metaquery={}, resource=None, pagination=None):
@ -176,9 +179,10 @@ class Connection(object):
:param resource: Optional resource filter.
:param pagination: Optional pagination query.
"""
raise NotImplementedError(_('Resources not implemented'))
@abc.abstractmethod
def get_meters(self, user=None, project=None, resource=None, source=None,
@staticmethod
def get_meters(user=None, project=None, resource=None, source=None,
metaquery={}, pagination=None):
"""Return an iterable of model.Meter instances containing meter
information.
@ -190,47 +194,51 @@ class Connection(object):
:param metaquery: Optional dict with metadata to match on.
:param pagination: Optional pagination query.
"""
raise NotImplementedError(_('Meters not implemented'))
@abc.abstractmethod
def get_samples(self, sample_filter, limit=None):
@staticmethod
def get_samples(sample_filter, limit=None):
"""Return an iterable of model.Sample instances.
:param sample_filter: Filter.
:param limit: Maximum number of results to return.
"""
raise NotImplementedError(_('Samples not implemented'))
@abc.abstractmethod
def get_meter_statistics(self, sample_filter, period=None, groupby=None):
@staticmethod
def get_meter_statistics(sample_filter, period=None, groupby=None):
"""Return an iterable of model.Statistics instances.
The filter must have a meter value set.
"""
raise NotImplementedError(_('Statistics not implemented'))
@abc.abstractmethod
def get_alarms(self, name=None, user=None,
@staticmethod
def get_alarms(name=None, user=None,
project=None, enabled=None, alarm_id=None, pagination=None):
"""Yields a lists of alarms that match filters
"""
"""Yields a lists of alarms that match filters."""
raise NotImplementedError(_('Alarms not implemented'))
@abc.abstractmethod
def create_alarm(self, alarm):
@staticmethod
def create_alarm(alarm):
"""Create an alarm. Returns the alarm as created.
:param alarm: The alarm to create.
"""
raise NotImplementedError(_('Alarms not implemented'))
@abc.abstractmethod
def update_alarm(self, alarm):
"""update alarm
"""
@staticmethod
def update_alarm(alarm):
"""Update alarm."""
raise NotImplementedError(_('Alarms not implemented'))
@abc.abstractmethod
def delete_alarm(self, alarm_id):
"""Delete a alarm
"""
@staticmethod
def delete_alarm(alarm_id):
"""Delete an alarm."""
raise NotImplementedError(_('Alarms not implemented'))
@abc.abstractmethod
def get_alarm_changes(self, alarm_id, on_behalf_of,
@staticmethod
def get_alarm_changes(alarm_id, on_behalf_of,
user=None, project=None, type=None,
start_timestamp=None, start_timestamp_op=None,
end_timestamp=None, end_timestamp_op=None):
@ -257,47 +265,53 @@ class Connection(object):
:param end_timestamp: Optional modified timestamp end range
:param end_timestamp_op: Optional timestamp end range operation
"""
raise NotImplementedError(_('Alarm history not implemented'))
@abc.abstractmethod
def record_alarm_change(self, alarm_change):
"""Record alarm change event.
"""
@staticmethod
def record_alarm_change(alarm_change):
"""Record alarm change event."""
raise NotImplementedError(_('Alarm history not implemented'))
@abc.abstractmethod
def clear(self):
@staticmethod
def clear():
"""Clear database."""
@abc.abstractmethod
def record_events(self, events):
@staticmethod
def record_events(events):
"""Write the events to the backend storage system.
:param events: a list of model.Event objects.
"""
raise NotImplementedError(_('Events not implemented.'))
@abc.abstractmethod
def get_events(self, event_filter):
@staticmethod
def get_events(event_filter):
"""Return an iterable of model.Event objects.
"""
raise NotImplementedError(_('Events not implemented.'))
@abc.abstractmethod
def get_event_types(self):
@staticmethod
def get_event_types():
"""Return all event types as an iterable of strings.
"""
raise NotImplementedError(_('Events not implemented.'))
@abc.abstractmethod
def get_trait_types(self, event_type):
@staticmethod
def get_trait_types(event_type):
"""Return a dictionary containing the name and data type of
the trait type. Only trait types for the provided event_type are
returned.
:param event_type: the type of the Event
"""
raise NotImplementedError(_('Events not implemented.'))
@abc.abstractmethod
def get_traits(self, event_type, trait_type=None):
@staticmethod
def get_traits(event_type, trait_type=None):
"""Return all trait instances associated with an event_type. If
trait_type is specified, only return instances of that trait type.
:param event_type: the type of the Event to filter by
:param trait_type: the name of the Trait to filter by
"""
raise NotImplementedError(_('Events not implemented.'))

View File

@ -349,15 +349,6 @@ class Connection(base.Connection):
record['_id'] = str(bson.objectid.ObjectId())
self.db.meter.insert(record)
def clear_expired_metering_data(self, ttl):
"""Clear expired data from the backend storage system according to the
time-to-live.
:param ttl: Number of seconds to keep records for.
"""
raise NotImplementedError('TTL not implemented.')
def get_users(self, source=None):
"""Return an iterable of user id strings.
@ -720,81 +711,3 @@ class Connection(base.Connection):
"""Delete an alarm
"""
self.db.alarm.remove({'alarm_id': alarm_id})
def get_alarm_changes(self, alarm_id, on_behalf_of,
user=None, project=None, type=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 occurence, 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
:project type: Optional change type
: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 NotImplementedError(_('Alarm history not implemented'))
def record_alarm_change(self, alarm_change):
"""Record alarm change event.
"""
raise NotImplementedError(_('Alarm history not implemented'))
@staticmethod
def record_events(events):
"""Write the events.
:param events: a list of model.Event objects.
"""
raise NotImplementedError(_('Events not implemented.'))
@staticmethod
def get_events(event_filter):
"""Return an iterable of model.Event objects.
:param event_filter: EventFilter instance
"""
raise NotImplementedError(_('Events not implemented.'))
@staticmethod
def get_event_types():
"""Return all event types as an iterable of strings.
"""
raise NotImplementedError(_('Events not implemented.'))
@staticmethod
def get_trait_types(event_type):
"""Return a dictionary containing the name and data type of
the trait type. Only trait types for the provided event_type are
returned.
:param event_type: the type of the Event
"""
raise NotImplementedError(_('Events not implemented.'))
@staticmethod
def get_traits(event_type, trait_type=None):
"""Return all trait instances associated with an event_type. If
trait_type is specified, only return instances of that trait type.
:param event_type: the type of the Event to filter by
:param trait_type: the name of the Trait to filter by
"""
raise NotImplementedError(_('Events not implemented.'))

View File

@ -255,15 +255,6 @@ class Connection(base.Connection):
record['f:message'] = json.dumps(data)
meter_table.put(row, record)
def clear_expired_metering_data(self, ttl):
"""Clear expired data from the backend storage system according to the
time-to-live.
:param ttl: Number of seconds to keep records for.
"""
raise NotImplementedError
def get_users(self, source=None):
"""Return an iterable of user id strings.
@ -592,101 +583,6 @@ class Connection(base.Connection):
self._update_meter_stats(results[-1], meter)
return results
def get_alarms(self, name=None, user=None,
project=None, enabled=None, alarm_id=None, pagination=None):
"""Yields a lists of alarms that match filters
raise NotImplementedError('metaquery not implemented')
"""
raise NotImplementedError(_('Alarms not implemented'))
def create_alarm(self, alarm):
"""update alarm
"""
raise NotImplementedError(_('Alarms not implemented'))
def update_alarm(self, alarm):
"""update alarm
"""
raise NotImplementedError(_('Alarms not implemented'))
def get_alarm_changes(self, alarm_id, on_behalf_of,
user=None, project=None, type=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 occurence, 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
:project type: Optional change type
: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 NotImplementedError(_('Alarm history not implemented'))
def record_alarm_change(self, alarm_change):
"""Record alarm change event.
"""
raise NotImplementedError(_('Alarm history not implemented'))
def delete_alarm(self, alarm_id):
"""Delete a alarm
"""
raise NotImplementedError(_('Alarms not implemented'))
def record_events(self, events):
"""Write the events.
:param events: a list of model.Event objects.
"""
raise NotImplementedError(_('Events not implemented.'))
def get_events(self, event_filter):
"""Return an iterable of model.Event objects.
:param event_filter: EventFilter instance
"""
raise NotImplementedError(_('Events not implemented.'))
def get_event_types(self):
"""Return all event types as an iterable of strings.
"""
raise NotImplementedError(_('Events not implemented.'))
def get_trait_types(self, event_type):
"""Return a dictionary containing the name and data type of
the trait type. Only trait types for the provided event_type are
returned.
:param event_type: the type of the Event
"""
raise NotImplementedError(_('Events not implemented.'))
def get_traits(self, event_type, trait_type=None):
"""Return all trait instances associated with an event_type. If
trait_type is specified, only return instances of that trait type.
:param event_type: the type of the Event to filter by
:param trait_type: the name of the Trait to filter by
"""
raise NotImplementedError(_('Events not implemented.'))
###############
# This is a very crude version of "in-memory HBase", which implements just

View File

@ -176,78 +176,4 @@ class Connection(base.Connection):
return alarm
def delete_alarm(self, alarm_id):
"""Delete a alarm
"""
def get_alarm_changes(self, alarm_id, on_behalf_of,
user=None, project=None, type=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 occurence, 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
:project type: Optional change type
: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 NotImplementedError(_('Alarm history not implemented'))
def record_alarm_change(self, alarm_change):
"""Record alarm change event.
"""
raise NotImplementedError(_('Alarm history not implemented'))
def record_events(self, events):
"""Write the events.
:param events: a list of model.Event objects.
"""
raise NotImplementedError(_('Events not implemented.'))
def get_events(self, event_filter):
"""Return an iterable of model.Event objects.
:param event_filter: EventFilter instance
"""
raise NotImplementedError(_('Events not implemented.'))
def get_event_types(self):
"""Return all event types as an iterable of strings.
"""
raise NotImplementedError(_('Events not implemented.'))
def get_trait_types(self, event_type):
"""Return a dictionary containing the name and data type of
the trait type. Only trait types for the provided event_type are
returned.
:param event_type: the type of the Event
"""
raise NotImplementedError(_('Events not implemented.'))
def get_traits(self, event_type, trait_type=None):
"""Return all trait instances associated with an event_type. If
trait_type is specified, only return instances of that trait type.
:param event_type: the type of the Event to filter by
:param trait_type: the name of the Trait to filter by
"""
raise NotImplementedError(_('Events not implemented.'))
"""Delete a alarm."""

View File

@ -958,47 +958,3 @@ class Connection(base.Connection):
"""Record alarm change event.
"""
self.db.alarm_history.insert(alarm_change)
@staticmethod
def record_events(events):
"""Write the events.
:param events: a list of model.Event objects.
"""
raise NotImplementedError(_('Events not implemented.'))
@staticmethod
def get_events(event_filter):
"""Return an iterable of model.Event objects.
:param event_filter: EventFilter instance
"""
raise NotImplementedError(_('Events not implemented.'))
@staticmethod
def get_event_types():
"""Return all event types as an iterable of strings.
"""
raise NotImplementedError(_('EventTypes not implemented.'))
@staticmethod
def get_trait_types(event_type):
"""Return a dictionary containing the name and data type of
the trait type. Only trait types for the provided event_type are
returned.
:param event_type: the type of the Event
"""
raise NotImplementedError(_('Events not implemented.'))
@staticmethod
def get_traits(event_type, trait_type=None):
"""Return all trait instances associated with an event_type. If
trait_type is specified, only return instances of that trait type.
:param event_type: the type of the Event to filter by
:param trait_type: the name of the Trait to filter by
"""
raise NotImplementedError(_('Events not implemented.'))