Remove pagination code

This code is actually dead code we carry over for a long time now, as
the pagination support never landed completely. Let's clean that old cruft.

Change-Id: Idbb2c93ed00dc2359f555d245c2283844d5a1da4
This commit is contained in:
Julien Danjou 2015-05-25 17:08:58 +02:00
parent 3c95aaa652
commit 1dfb2cb44b
21 changed files with 44 additions and 415 deletions

View File

@ -41,7 +41,7 @@ class Connection(object):
@staticmethod @staticmethod
def get_alarms(name=None, user=None, state=None, meter=None, def get_alarms(name=None, user=None, state=None, meter=None,
project=None, enabled=None, alarm_id=None, pagination=None, project=None, enabled=None, alarm_id=None,
alarm_type=None, severity=None): alarm_type=None, severity=None):
"""Yields a lists of alarms that match filters. """Yields a lists of alarms that match filters.
@ -52,7 +52,6 @@ class Connection(object):
:param project: Optional ID for project that owns the resource. :param project: Optional ID for project that owns the resource.
:param enabled: Optional boolean to list disable alarm. :param enabled: Optional boolean to list disable alarm.
:param alarm_id: Optional alarm_id to return one alarm. :param alarm_id: Optional alarm_id to return one alarm.
:param pagination: Optional pagination query.
:param alarm_type: Optional alarm type. :param alarm_type: Optional alarm type.
:parmr severity: Optional alarm severity :parmr severity: Optional alarm severity
""" """

View File

@ -119,11 +119,9 @@ class Connection(hbase_base.Connection, base.Connection):
alarm_table.delete(alarm_id) alarm_table.delete(alarm_id)
def get_alarms(self, name=None, user=None, state=None, meter=None, def get_alarms(self, name=None, user=None, state=None, meter=None,
project=None, enabled=None, alarm_id=None, pagination=None, project=None, enabled=None, alarm_id=None,
alarm_type=None, severity=None): alarm_type=None, severity=None):
if pagination:
raise ceilometer.NotImplementedError('Pagination not implemented')
if meter: if meter:
raise ceilometer.NotImplementedError( raise ceilometer.NotImplementedError(
'Filter by meter not implemented') 'Filter by meter not implemented')

View File

@ -32,7 +32,7 @@ class Connection(base.Connection):
pass pass
def get_alarms(self, name=None, user=None, state=None, meter=None, def get_alarms(self, name=None, user=None, state=None, meter=None,
project=None, enabled=None, alarm_id=None, pagination=None, project=None, enabled=None, alarm_id=None,
alarm_type=None, severity=None): alarm_type=None, severity=None):
"""Yields a lists of alarms that match filters.""" """Yields a lists of alarms that match filters."""
return [] return []

View File

@ -21,7 +21,6 @@ from oslo_db.sqlalchemy import session as db_session
from oslo_utils import timeutils from oslo_utils import timeutils
from sqlalchemy import desc from sqlalchemy import desc
import ceilometer
from ceilometer.alarm.storage import base from ceilometer.alarm.storage import base
from ceilometer.alarm.storage import models as alarm_api_models from ceilometer.alarm.storage import models as alarm_api_models
from ceilometer.i18n import _LI from ceilometer.i18n import _LI
@ -147,7 +146,7 @@ class Connection(base.Connection):
return (self._row_to_alarm_model(x) for x in query.all()) return (self._row_to_alarm_model(x) for x in query.all())
def get_alarms(self, name=None, user=None, state=None, meter=None, def get_alarms(self, name=None, user=None, state=None, meter=None,
project=None, enabled=None, alarm_id=None, pagination=None, project=None, enabled=None, alarm_id=None,
alarm_type=None, severity=None): alarm_type=None, severity=None):
"""Yields a lists of alarms that match filters. """Yields a lists of alarms that match filters.
@ -158,14 +157,10 @@ class Connection(base.Connection):
:param project: Optional ID for project that owns the resource. :param project: Optional ID for project that owns the resource.
:param enabled: Optional boolean to list disable alarm. :param enabled: Optional boolean to list disable alarm.
:param alarm_id: Optional alarm_id to return one alarm. :param alarm_id: Optional alarm_id to return one alarm.
:param pagination: Optional pagination query.
:param alarm_type: Optional alarm type. :param alarm_type: Optional alarm type.
:param severity: Optional alarm severity :param severity: Optional alarm severity
""" """
if pagination:
raise ceilometer.NotImplementedError('Pagination not implemented')
session = self._engine_facade.get_session() session = self._engine_facade.get_session()
query = session.query(models.Alarm) query = session.query(models.Alarm)
if name is not None: if name is not None:

View File

@ -21,7 +21,6 @@
import pymongo import pymongo
import ceilometer
from ceilometer.alarm.storage import base from ceilometer.alarm.storage import base
from ceilometer.alarm.storage import models from ceilometer.alarm.storage import models
from ceilometer.openstack.common import log from ceilometer.openstack.common import log
@ -80,7 +79,7 @@ class Connection(base.Connection):
self.db.alarm_history.insert(alarm_change.copy()) self.db.alarm_history.insert(alarm_change.copy())
def get_alarms(self, name=None, user=None, state=None, meter=None, def get_alarms(self, name=None, user=None, state=None, meter=None,
project=None, enabled=None, alarm_id=None, pagination=None, project=None, enabled=None, alarm_id=None,
alarm_type=None, severity=None): alarm_type=None, severity=None):
"""Yields a lists of alarms that match filters. """Yields a lists of alarms that match filters.
@ -91,13 +90,9 @@ class Connection(base.Connection):
:param project: Optional ID for project that owns the resource. :param project: Optional ID for project that owns the resource.
:param enabled: Optional boolean to list disable alarm. :param enabled: Optional boolean to list disable alarm.
:param alarm_id: Optional alarm_id to return one alarm. :param alarm_id: Optional alarm_id to return one alarm.
:param pagination: Optional pagination query.
:param alarm_type: Optional alarm type. :param alarm_type: Optional alarm type.
:param severity: Optional alarm severity. :param severity: Optional alarm severity.
""" """
if pagination:
raise ceilometer.NotImplementedError('Pagination not implemented')
q = {} q = {}
if user is not None: if user is not None:
q['user_id'] = user q['user_id'] = user

View File

@ -563,8 +563,6 @@ class AlarmController(rest.RestController):
timeutils.utcnow(), timeutils.utcnow(),
type=alarm_models.AlarmChange.DELETION) type=alarm_models.AlarmChange.DELETION)
# TODO(eglynn): add pagination marker to signature once overall
# API support for pagination is finalized
@wsme_pecan.wsexpose([AlarmChange], [base.Query]) @wsme_pecan.wsexpose([AlarmChange], [base.Query])
def history(self, q=None): def history(self, q=None):
"""Assembles the alarm history requested. """Assembles the alarm history requested.

View File

@ -50,20 +50,16 @@ class Capabilities(base.Base):
def sample(cls): def sample(cls):
return cls( return cls(
api=_flatten_capabilities({ api=_flatten_capabilities({
'meters': {'pagination': True, 'meters': {'query': {'simple': True,
'query': {'simple': True,
'metadata': True, 'metadata': True,
'complex': False}}, 'complex': False}},
'resources': {'pagination': False, 'resources': {'query': {'simple': True,
'query': {'simple': True,
'metadata': True, 'metadata': True,
'complex': False}}, 'complex': False}},
'samples': {'pagination': True, 'samples': {'query': {'simple': True,
'query': {'simple': True,
'metadata': True, 'metadata': True,
'complex': True}}, 'complex': True}},
'statistics': {'pagination': True, 'statistics': {'groupby': True,
'groupby': True,
'query': {'simple': True, 'query': {'simple': True,
'metadata': True, 'metadata': True,
'complex': False}, 'complex': False},

View File

@ -80,29 +80,6 @@ class NoResultFound(Exception):
pass pass
class Pagination(object):
"""Class for pagination query."""
def __init__(self, limit=None, primary_sort_dir='desc', sort_keys=None,
sort_dirs=None, marker_value=None):
"""This puts all parameters used for paginate query together.
:param limit: Maximum number of items to return;
:param primary_sort_dir: Sort direction of primary key.
:param marker_value: Value of primary key to identify the last item of
the previous page.
:param sort_keys: Array of attributes passed in by users to sort the
results besides the primary key.
:param sort_dirs: Per-column array of sort_dirs, corresponding to
sort_keys.
"""
self.limit = limit
self.primary_sort_dir = primary_sort_dir
self.marker_value = marker_value
self.sort_keys = sort_keys or []
self.sort_dirs = sort_dirs or []
class Model(object): class Model(object):
"""Base class for storage API models.""" """Base class for storage API models."""
@ -136,20 +113,16 @@ class Connection(object):
# A dictionary representing the capabilities of this driver. # A dictionary representing the capabilities of this driver.
CAPABILITIES = { CAPABILITIES = {
'meters': {'pagination': False, 'meters': {'query': {'simple': False,
'query': {'simple': False,
'metadata': False, 'metadata': False,
'complex': False}}, 'complex': False}},
'resources': {'pagination': False, 'resources': {'query': {'simple': False,
'query': {'simple': False,
'metadata': False, 'metadata': False,
'complex': False}}, 'complex': False}},
'samples': {'pagination': False, 'samples': {'query': {'simple': False,
'query': {'simple': False,
'metadata': False, 'metadata': False,
'complex': False}}, 'complex': False}},
'statistics': {'pagination': False, 'statistics': {'groupby': False,
'groupby': False,
'query': {'simple': False, 'query': {'simple': False,
'metadata': False, 'metadata': False,
'complex': False}, 'complex': False},
@ -203,7 +176,7 @@ class Connection(object):
def get_resources(user=None, project=None, source=None, def get_resources(user=None, project=None, source=None,
start_timestamp=None, start_timestamp_op=None, start_timestamp=None, start_timestamp_op=None,
end_timestamp=None, end_timestamp_op=None, end_timestamp=None, end_timestamp_op=None,
metaquery=None, resource=None, pagination=None): metaquery=None, resource=None):
"""Return an iterable of models.Resource instances. """Return an iterable of models.Resource instances.
Iterable items containing resource information. Iterable items containing resource information.
@ -216,13 +189,12 @@ class Connection(object):
:param end_timestamp_op: Optional timestamp end range operation. :param end_timestamp_op: Optional timestamp end range operation.
:param metaquery: Optional dict with metadata to match on. :param metaquery: Optional dict with metadata to match on.
:param resource: Optional resource filter. :param resource: Optional resource filter.
:param pagination: Optional pagination query.
""" """
raise ceilometer.NotImplementedError('Resources not implemented') raise ceilometer.NotImplementedError('Resources not implemented')
@staticmethod @staticmethod
def get_meters(user=None, project=None, resource=None, source=None, def get_meters(user=None, project=None, resource=None, source=None,
metaquery=None, pagination=None): metaquery=None):
"""Return an iterable of model.Meter instances. """Return an iterable of model.Meter instances.
Iterable items containing meter information. Iterable items containing meter information.
@ -231,7 +203,6 @@ class Connection(object):
:param resource: Optional resource filter. :param resource: Optional resource filter.
:param source: Optional source filter. :param source: Optional source filter.
:param metaquery: Optional dict with metadata to match on. :param metaquery: Optional dict with metadata to match on.
:param pagination: Optional pagination query.
""" """
raise ceilometer.NotImplementedError('Meters not implemented') raise ceilometer.NotImplementedError('Meters not implemented')

View File

@ -256,7 +256,7 @@ class Connection(pymongo_base.Connection):
def get_resources(self, user=None, project=None, source=None, def get_resources(self, user=None, project=None, source=None,
start_timestamp=None, start_timestamp_op=None, start_timestamp=None, start_timestamp_op=None,
end_timestamp=None, end_timestamp_op=None, end_timestamp=None, end_timestamp_op=None,
metaquery=None, resource=None, pagination=None): metaquery=None, resource=None):
"""Return an iterable of models.Resource instances """Return an iterable of models.Resource instances
:param user: Optional ID for user that owns the resource. :param user: Optional ID for user that owns the resource.
@ -268,11 +268,7 @@ class Connection(pymongo_base.Connection):
:param end_timestamp_op: Optional end time operator, like lt, le. :param end_timestamp_op: Optional end time operator, like lt, le.
:param metaquery: Optional dict with metadata to match on. :param metaquery: Optional dict with metadata to match on.
:param resource: Optional resource filter. :param resource: Optional resource filter.
:param pagination: Optional pagination query.
""" """
if pagination:
raise ceilometer.NotImplementedError('Pagination not implemented')
metaquery = pymongo_utils.improve_keys(metaquery, metaquery=True) or {} metaquery = pymongo_utils.improve_keys(metaquery, metaquery=True) or {}
q = {} q = {}

View File

@ -186,7 +186,7 @@ class Connection(hbase_base.Connection, base.Connection):
def get_resources(self, user=None, project=None, source=None, def get_resources(self, user=None, project=None, source=None,
start_timestamp=None, start_timestamp_op=None, start_timestamp=None, start_timestamp_op=None,
end_timestamp=None, end_timestamp_op=None, end_timestamp=None, end_timestamp_op=None,
metaquery=None, resource=None, pagination=None): metaquery=None, resource=None):
"""Return an iterable of models.Resource instances """Return an iterable of models.Resource instances
:param user: Optional ID for user that owns the resource. :param user: Optional ID for user that owns the resource.
@ -198,11 +198,7 @@ class Connection(hbase_base.Connection, base.Connection):
:param end_timestamp_op: Optional end time operator, like lt, le. :param end_timestamp_op: Optional end time operator, like lt, le.
:param metaquery: Optional dict with metadata to match on. :param metaquery: Optional dict with metadata to match on.
:param resource: Optional resource filter. :param resource: Optional resource filter.
:param pagination: Optional pagination query.
""" """
if pagination:
raise ceilometer.NotImplementedError('Pagination not implemented')
q = hbase_utils.make_query(metaquery=metaquery, user_id=user, q = hbase_utils.make_query(metaquery=metaquery, user_id=user,
project_id=project, project_id=project,
resource_id=resource, source=source) resource_id=resource, source=source)
@ -242,7 +238,7 @@ class Connection(hbase_base.Connection, base.Connection):
metadata=md) metadata=md)
def get_meters(self, user=None, project=None, resource=None, source=None, def get_meters(self, user=None, project=None, resource=None, source=None,
metaquery=None, pagination=None): metaquery=None):
"""Return an iterable of models.Meter instances """Return an iterable of models.Meter instances
:param user: Optional ID for user that owns the resource. :param user: Optional ID for user that owns the resource.
@ -250,14 +246,10 @@ class Connection(hbase_base.Connection, base.Connection):
:param resource: Optional resource filter. :param resource: Optional resource filter.
:param source: Optional source filter. :param source: Optional source filter.
:param metaquery: Optional dict with metadata to match on. :param metaquery: Optional dict with metadata to match on.
:param pagination: Optional pagination query.
""" """
metaquery = metaquery or {} metaquery = metaquery or {}
if pagination:
raise ceilometer.NotImplementedError(
_('Pagination not implemented'))
with self.conn_pool.connection() as conn: with self.conn_pool.connection() as conn:
resource_table = conn.table(self.RESOURCE_TABLE) resource_table = conn.table(self.RESOURCE_TABLE)
q = hbase_utils.make_query(metaquery=metaquery, user_id=user, q = hbase_utils.make_query(metaquery=metaquery, user_id=user,

View File

@ -54,7 +54,7 @@ class Connection(base.Connection):
def get_resources(self, user=None, project=None, source=None, def get_resources(self, user=None, project=None, source=None,
start_timestamp=None, start_timestamp_op=None, start_timestamp=None, start_timestamp_op=None,
end_timestamp=None, end_timestamp_op=None, end_timestamp=None, end_timestamp_op=None,
metaquery=None, resource=None, pagination=None): metaquery=None, resource=None):
"""Return an iterable of dictionaries containing resource information. """Return an iterable of dictionaries containing resource information.
{ 'resource_id': UUID of the resource, { 'resource_id': UUID of the resource,
@ -74,12 +74,11 @@ class Connection(base.Connection):
:param end_timestamp_op: Optional end time operator, like lt, le. :param end_timestamp_op: Optional end time operator, like lt, le.
:param metaquery: Optional dict with metadata to match on. :param metaquery: Optional dict with metadata to match on.
:param resource: Optional resource filter. :param resource: Optional resource filter.
:param pagination: Optional pagination query.
""" """
return [] return []
def get_meters(self, user=None, project=None, resource=None, source=None, def get_meters(self, user=None, project=None, resource=None, source=None,
limit=None, metaquery=None, pagination=None): limit=None, metaquery=None):
"""Return an iterable of dictionaries containing meter information. """Return an iterable of dictionaries containing meter information.
{ 'name': name of the meter, { 'name': name of the meter,
@ -95,7 +94,6 @@ class Connection(base.Connection):
:param source: Optional source filter. :param source: Optional source filter.
:param limit: Maximum number of results to return. :param limit: Maximum number of results to return.
:param metaquery: Optional dict with metadata to match on. :param metaquery: Optional dict with metadata to match on.
:param pagination: Optional pagination query.
""" """
return [] return []

View File

@ -592,47 +592,6 @@ class Connection(pymongo_base.Connection):
criteria_cmp = cls._recurse_sort_keys(sort_keys[1:], marker, flag) criteria_cmp = cls._recurse_sort_keys(sort_keys[1:], marker, flag)
return dict(criteria_equ, ** criteria_cmp) return dict(criteria_equ, ** criteria_cmp)
@classmethod
def _build_paginate_query(cls, marker, sort_keys=None, sort_dir='desc'):
"""Returns a query with sorting / pagination.
Pagination works by requiring sort_key and sort_dir.
We use the last item in previous page as the 'marker' for pagination.
So we return values that follow the passed marker in the order.
:param q: The query dict passed in.
:param marker: the last item of the previous page; we return the next
results after this item.
:param sort_keys: array of attributes by which results be sorted.
:param sort_dir: direction in which results be sorted (asc, desc).
:return: sort parameters, query to use
"""
all_sort = []
sort_keys = sort_keys or []
all_sort, _op = cls._build_sort_instructions(sort_keys, sort_dir)
if marker is not None:
sort_criteria_list = []
for i in range(len(sort_keys)):
# NOTE(fengqian): Generate the query criteria recursively.
# sort_keys=[k1, k2, k3], maker_value=[v1, v2, v3]
# sort_flags = ['$lt', '$gt', 'lt'].
# The query criteria should be
# {'k3': {'$lt': 'v3'}, 'k2': {'eq': 'v2'}, 'k1':
# {'eq': 'v1'}},
# {'k2': {'$gt': 'v2'}, 'k1': {'eq': 'v1'}},
# {'k1': {'$lt': 'v1'}} with 'OR' operation.
# Each recurse will generate one items of three.
sort_criteria_list.append(cls._recurse_sort_keys(
sort_keys[:(len(sort_keys) - i)],
marker, _op))
metaquery = {"$or": sort_criteria_list}
else:
metaquery = {}
return all_sort, metaquery
@classmethod @classmethod
def _build_sort_instructions(cls, sort_keys=None, sort_dir='desc'): def _build_sort_instructions(cls, sort_keys=None, sort_dir='desc'):
"""Returns a sort_instruction and paging operator. """Returns a sort_instruction and paging operator.
@ -655,39 +614,6 @@ class Connection(pymongo_base.Connection):
return sort_instructions, operation return sort_instructions, operation
@classmethod
def paginate_query(cls, q, db_collection, limit=None, marker=None,
sort_keys=None, sort_dir='desc'):
"""Returns a query result with sorting / pagination.
Pagination works by requiring sort_key and sort_dir.
We use the last item in previous page as the 'marker' for pagination.
So we return values that follow the passed marker in the order.
:param q: the query dict passed in.
:param db_collection: Database collection that be query.
:param limit: maximum number of items to return.
:param marker: the last item of the previous page; we return the next
results after this item.
:param sort_keys: array of attributes by which results be sorted.
:param sort_dir: direction in which results be sorted (asc, desc).
:return: The query with sorting/pagination added.
"""
sort_keys = sort_keys or []
all_sort, query = cls._build_paginate_query(marker,
sort_keys,
sort_dir)
q.update(query)
# NOTE(Fengqian): MongoDB collection.find can not handle limit
# when it equals None, it will raise TypeError, so we treat
# None as 0 for the value of limit.
if limit is None:
limit = 0
return db_collection.find(q, limit=limit, sort=all_sort)
def _get_time_constrained_resources(self, query, def _get_time_constrained_resources(self, query,
start_timestamp, start_timestamp_op, start_timestamp, start_timestamp_op,
end_timestamp, end_timestamp_op, end_timestamp, end_timestamp_op,
@ -785,7 +711,7 @@ class Connection(pymongo_base.Connection):
def get_resources(self, user=None, project=None, source=None, def get_resources(self, user=None, project=None, source=None,
start_timestamp=None, start_timestamp_op=None, start_timestamp=None, start_timestamp_op=None,
end_timestamp=None, end_timestamp_op=None, end_timestamp=None, end_timestamp_op=None,
metaquery=None, resource=None, pagination=None): metaquery=None, resource=None):
"""Return an iterable of models.Resource instances """Return an iterable of models.Resource instances
:param user: Optional ID for user that owns the resource. :param user: Optional ID for user that owns the resource.
@ -797,11 +723,7 @@ class Connection(pymongo_base.Connection):
:param end_timestamp_op: Optional end time operator, like lt, le. :param end_timestamp_op: Optional end time operator, like lt, le.
:param metaquery: Optional dict with metadata to match on. :param metaquery: Optional dict with metadata to match on.
:param resource: Optional resource filter. :param resource: Optional resource filter.
:param pagination: Optional pagination query.
""" """
if pagination:
raise ceilometer.NotImplementedError('Pagination not implemented')
metaquery = pymongo_utils.improve_keys(metaquery, metaquery=True) or {} metaquery = pymongo_utils.improve_keys(metaquery, metaquery=True) or {}
query = {} query = {}

View File

@ -72,8 +72,7 @@ AVAILABLE_CAPABILITIES = {
'metadata': True}}, 'metadata': True}},
'resources': {'query': {'simple': True, 'resources': {'query': {'simple': True,
'metadata': True}}, 'metadata': True}},
'samples': {'pagination': True, 'samples': {'query': {'simple': True,
'query': {'simple': True,
'metadata': True, 'metadata': True,
'complex': True}}, 'complex': True}},
'statistics': {'groupby': True, 'statistics': {'groupby': True,
@ -386,7 +385,7 @@ class Connection(base.Connection):
def get_resources(self, user=None, project=None, source=None, def get_resources(self, user=None, project=None, source=None,
start_timestamp=None, start_timestamp_op=None, start_timestamp=None, start_timestamp_op=None,
end_timestamp=None, end_timestamp_op=None, end_timestamp=None, end_timestamp_op=None,
metaquery=None, resource=None, pagination=None): metaquery=None, resource=None):
"""Return an iterable of api_models.Resource instances """Return an iterable of api_models.Resource instances
:param user: Optional ID for user that owns the resource. :param user: Optional ID for user that owns the resource.
@ -398,11 +397,7 @@ class Connection(base.Connection):
:param end_timestamp_op: Optional end time operator, like lt, le. :param end_timestamp_op: Optional end time operator, like lt, le.
:param metaquery: Optional dict with metadata to match on. :param metaquery: Optional dict with metadata to match on.
:param resource: Optional resource filter. :param resource: Optional resource filter.
:param pagination: Optional pagination query.
""" """
if pagination:
raise ceilometer.NotImplementedError('Pagination not implemented')
s_filter = storage.SampleFilter(user=user, s_filter = storage.SampleFilter(user=user,
project=project, project=project,
source=source, source=source,
@ -467,7 +462,7 @@ class Connection(base.Connection):
) )
def get_meters(self, user=None, project=None, resource=None, source=None, def get_meters(self, user=None, project=None, resource=None, source=None,
metaquery=None, pagination=None): metaquery=None):
"""Return an iterable of api_models.Meter instances """Return an iterable of api_models.Meter instances
:param user: Optional ID for user that owns the resource. :param user: Optional ID for user that owns the resource.
@ -475,12 +470,7 @@ class Connection(base.Connection):
:param resource: Optional ID of the resource. :param resource: Optional ID of the resource.
:param source: Optional source filter. :param source: Optional source filter.
:param metaquery: Optional dict with metadata to match on. :param metaquery: Optional dict with metadata to match on.
:param pagination: Optional pagination query.
""" """
if pagination:
raise ceilometer.NotImplementedError('Pagination not implemented')
s_filter = storage.SampleFilter(user=user, s_filter = storage.SampleFilter(user=user,
project=project, project=project,
source=source, source=source,

View File

@ -19,7 +19,6 @@
""" """
import pymongo import pymongo
import ceilometer
from ceilometer.storage import base from ceilometer.storage import base
from ceilometer.storage import models from ceilometer.storage import models
from ceilometer.storage.mongo import utils as pymongo_utils from ceilometer.storage.mongo import utils as pymongo_utils
@ -51,7 +50,7 @@ class Connection(base.Connection):
) )
def get_meters(self, user=None, project=None, resource=None, source=None, def get_meters(self, user=None, project=None, resource=None, source=None,
metaquery=None, pagination=None): metaquery=None):
"""Return an iterable of models.Meter instances """Return an iterable of models.Meter instances
:param user: Optional ID for user that owns the resource. :param user: Optional ID for user that owns the resource.
@ -59,12 +58,8 @@ class Connection(base.Connection):
:param resource: Optional resource filter. :param resource: Optional resource filter.
:param source: Optional source filter. :param source: Optional source filter.
:param metaquery: Optional dict with metadata to match on. :param metaquery: Optional dict with metadata to match on.
:param pagination: Optional pagination query.
""" """
if pagination:
raise ceilometer.NotImplementedError('Pagination not implemented')
metaquery = pymongo_utils.improve_keys(metaquery, metaquery=True) or {} metaquery = pymongo_utils.improve_keys(metaquery, metaquery=True) or {}
q = {} q = {}

View File

@ -381,7 +381,7 @@ class TestQueryToKwArgs(tests_base.BaseTestCase):
exc = self.assertRaises( exc = self.assertRaises(
wsme.exc.UnknownArgument, wsme.exc.UnknownArgument,
utils.query_to_kwargs, q, storage_base.Connection.get_meters) utils.query_to_kwargs, q, storage_base.Connection.get_meters)
valid_keys = ['pagination', 'project', 'resource', 'source', 'user'] valid_keys = ['project', 'resource', 'source', 'user']
msg = ("unrecognized field in query: %s, " msg = ("unrecognized field in query: %s, "
"valid keys: %s") % (q, valid_keys) "valid keys: %s") % (q, valid_keys)
expected_exc = wsme.exc.UnknownArgument('abc', msg) expected_exc = wsme.exc.UnknownArgument('abc', msg)
@ -394,7 +394,7 @@ class TestQueryToKwArgs(tests_base.BaseTestCase):
exc = self.assertRaises( exc = self.assertRaises(
wsme.exc.UnknownArgument, wsme.exc.UnknownArgument,
utils.query_to_kwargs, q, storage_base.Connection.get_resources) utils.query_to_kwargs, q, storage_base.Connection.get_resources)
valid_keys = ['pagination', 'project', 'resource', valid_keys = ['project', 'resource',
'search_offset', 'source', 'timestamp', 'user'] 'search_offset', 'source', 'timestamp', 'user']
msg = ("unrecognized field in query: %s, " msg = ("unrecognized field in query: %s, "
"valid keys: %s") % (q, valid_keys) "valid keys: %s") % (q, valid_keys)
@ -409,7 +409,7 @@ class TestQueryToKwArgs(tests_base.BaseTestCase):
wsme.exc.UnknownArgument, wsme.exc.UnknownArgument,
utils.query_to_kwargs, q, utils.query_to_kwargs, q,
alarm_storage_base.Connection.get_alarms) alarm_storage_base.Connection.get_alarms)
valid_keys = ['alarm_id', 'enabled', 'meter', 'name', 'pagination', valid_keys = ['alarm_id', 'enabled', 'meter', 'name',
'project', 'severity', 'state', 'type', 'user'] 'project', 'severity', 'state', 'type', 'user']
msg = ("unrecognized field in query: %s, " msg = ("unrecognized field in query: %s, "
"valid keys: %s") % (q, valid_keys) "valid keys: %s") % (q, valid_keys)

View File

@ -13,4 +13,3 @@ tests:
$.alarm_storage.['storage:production_ready']: true $.alarm_storage.['storage:production_ready']: true
$.event_storage.['storage:production_ready']: true $.event_storage.['storage:production_ready']: true
$.storage.['storage:production_ready']: true $.storage.['storage:production_ready']: true
$.api.['meters:pagination']: false

View File

@ -41,20 +41,16 @@ class CapabilitiesTest(test_base.BaseTestCase):
def test_capabilities(self): def test_capabilities(self):
expected_capabilities = { expected_capabilities = {
'meters': {'pagination': False, 'meters': {'query': {'simple': True,
'query': {'simple': True,
'metadata': True, 'metadata': True,
'complex': False}}, 'complex': False}},
'resources': {'pagination': False, 'resources': {'query': {'simple': True,
'query': {'simple': True,
'metadata': True, 'metadata': True,
'complex': False}}, 'complex': False}},
'samples': {'pagination': False, 'samples': {'query': {'simple': True,
'query': {'simple': True,
'metadata': True, 'metadata': True,
'complex': True}}, 'complex': True}},
'statistics': {'pagination': False, 'statistics': {'groupby': True,
'groupby': True,
'query': {'simple': True, 'query': {'simple': True,
'metadata': True, 'metadata': True,
'complex': False}, 'complex': False},

View File

@ -57,20 +57,16 @@ class CapabilitiesTest(test_base.BaseTestCase):
def test_capabilities(self): def test_capabilities(self):
expected_capabilities = { expected_capabilities = {
'meters': {'pagination': False, 'meters': {'query': {'simple': True,
'query': {'simple': True,
'metadata': True, 'metadata': True,
'complex': False}}, 'complex': False}},
'resources': {'pagination': False, 'resources': {'query': {'simple': True,
'query': {'simple': True,
'metadata': True, 'metadata': True,
'complex': False}}, 'complex': False}},
'samples': {'pagination': False, 'samples': {'query': {'simple': True,
'query': {'simple': True,
'metadata': True, 'metadata': True,
'complex': False}}, 'complex': False}},
'statistics': {'pagination': False, 'statistics': {'groupby': False,
'groupby': False,
'query': {'simple': True, 'query': {'simple': True,
'metadata': True, 'metadata': True,
'complex': False}, 'complex': False},

View File

@ -23,11 +23,9 @@
from ceilometer.alarm.storage import impl_mongodb as impl_mongodb_alarm from ceilometer.alarm.storage import impl_mongodb as impl_mongodb_alarm
from ceilometer.event.storage import impl_mongodb as impl_mongodb_event from ceilometer.event.storage import impl_mongodb as impl_mongodb_event
from ceilometer.storage import base
from ceilometer.storage import impl_mongodb from ceilometer.storage import impl_mongodb
from ceilometer.tests import base as test_base from ceilometer.tests import base as test_base
from ceilometer.tests import db as tests_db from ceilometer.tests import db as tests_db
from ceilometer.tests.storage import test_storage_scenarios
@tests_db.run_with('mongodb') @tests_db.run_with('mongodb')
@ -53,36 +51,6 @@ class MongoDBConnection(tests_db.TestBase,
self.assertEqual(expect, ret) self.assertEqual(expect, ret)
@tests_db.run_with('mongodb')
class MongoDBTestMarkerBase(test_storage_scenarios.DBTestBase,
tests_db.MixinTestsWithBackendScenarios):
# NOTE(Fengqian): All these three test case are the same for resource
# and meter collection. As to alarm, we will set up in AlarmTestPagination.
def test_get_marker(self):
marker_pairs = {'user_id': 'user-id-4'}
ret = impl_mongodb.Connection._get_marker(self.conn.db.resource,
marker_pairs)
self.assertEqual('project-id-4', ret['project_id'])
def test_get_marker_None(self):
marker_pairs = {'user_id': 'user-id-foo'}
try:
ret = impl_mongodb.Connection._get_marker(self.conn.db.resource,
marker_pairs)
self.assertEqual('project-id-foo', ret['project_id'])
except base.NoResultFound:
self.assertTrue(True)
def test_get_marker_multiple(self):
try:
marker_pairs = {'project_id': 'project-id'}
ret = impl_mongodb.Connection._get_marker(self.conn.db.resource,
marker_pairs)
self.assertEqual('project-id-foo', ret['project_id'])
except base.MultipleResultsFound:
self.assertTrue(True)
@tests_db.run_with('mongodb') @tests_db.run_with('mongodb')
class IndexTest(tests_db.TestBase, class IndexTest(tests_db.TestBase,
tests_db.MixinTestsWithBackendScenarios): tests_db.MixinTestsWithBackendScenarios):
@ -139,57 +107,22 @@ class IndexTest(tests_db.TestBase,
'alarm_history_time_to_live') 'alarm_history_time_to_live')
@tests_db.run_with('mongodb')
class AlarmTestPagination(test_storage_scenarios.AlarmTestBase,
tests_db.MixinTestsWithBackendScenarios):
def test_alarm_get_marker(self):
self.add_some_alarms()
marker_pairs = {'name': 'red-alert'}
ret = impl_mongodb.Connection._get_marker(self.alarm_conn.db.alarm,
marker_pairs=marker_pairs)
self.assertEqual('test.one', ret['rule']['meter_name'])
def test_alarm_get_marker_None(self):
self.add_some_alarms()
try:
marker_pairs = {'name': 'user-id-foo'}
ret = impl_mongodb.Connection._get_marker(self.alarm_conn.db.alarm,
marker_pairs)
self.assertEqual('meter_name-foo', ret['rule']['meter_name'])
except base.NoResultFound:
self.assertTrue(True)
def test_alarm_get_marker_multiple(self):
self.add_some_alarms()
try:
marker_pairs = {'user_id': 'me'}
ret = impl_mongodb.Connection._get_marker(self.alarm_conn.db.alarm,
marker_pairs)
self.assertEqual('counter-name-foo', ret['rule']['meter_name'])
except base.MultipleResultsFound:
self.assertTrue(True)
class CapabilitiesTest(test_base.BaseTestCase): class CapabilitiesTest(test_base.BaseTestCase):
# Check the returned capabilities list, which is specific to each DB # Check the returned capabilities list, which is specific to each DB
# driver # driver
def test_capabilities(self): def test_capabilities(self):
expected_capabilities = { expected_capabilities = {
'meters': {'pagination': False, 'meters': {'query': {'simple': True,
'query': {'simple': True,
'metadata': True, 'metadata': True,
'complex': False}}, 'complex': False}},
'resources': {'pagination': False, 'resources': {'query': {'simple': True,
'query': {'simple': True,
'metadata': True, 'metadata': True,
'complex': False}}, 'complex': False}},
'samples': {'pagination': False, 'samples': {'query': {'simple': True,
'query': {'simple': True,
'metadata': True, 'metadata': True,
'complex': True}}, 'complex': True}},
'statistics': {'pagination': False, 'statistics': {'groupby': True,
'groupby': True,
'query': {'simple': True, 'query': {'simple': True,
'metadata': True, 'metadata': True,
'complex': False}, 'complex': False},

View File

@ -135,20 +135,16 @@ class CapabilitiesTest(test_base.BaseTestCase):
def test_capabilities(self): def test_capabilities(self):
expected_capabilities = { expected_capabilities = {
'meters': {'pagination': False, 'meters': {'query': {'simple': True,
'query': {'simple': True,
'metadata': True, 'metadata': True,
'complex': False}}, 'complex': False}},
'resources': {'pagination': False, 'resources': {'query': {'simple': True,
'query': {'simple': True,
'metadata': True, 'metadata': True,
'complex': False}}, 'complex': False}},
'samples': {'pagination': True, 'samples': {'query': {'simple': True,
'query': {'simple': True,
'metadata': True, 'metadata': True,
'complex': True}}, 'complex': True}},
'statistics': {'pagination': False, 'statistics': {'groupby': True,
'groupby': True,
'query': {'simple': True, 'query': {'simple': True,
'metadata': True, 'metadata': True,
'complex': False}, 'complex': False},

View File

@ -31,7 +31,6 @@ from ceilometer.event.storage import models as event_models
from ceilometer.publisher import utils from ceilometer.publisher import utils
from ceilometer import sample from ceilometer import sample
from ceilometer import storage from ceilometer import storage
from ceilometer.storage import base
from ceilometer.tests import constants from ceilometer.tests import constants
from ceilometer.tests import db as tests_db from ceilometer.tests import db as tests_db
@ -310,49 +309,6 @@ class ResourceTest(DBTestBase,
self.assertEqual(expected_tag, resource.metadata['tag']) self.assertEqual(expected_tag, resource.metadata['tag'])
class ResourceTestPagination(DBTestBase,
tests_db.MixinTestsWithBackendScenarios):
def test_get_resource_all_limit(self):
pagination = base.Pagination(limit=8)
results = list(self.conn.get_resources(pagination=pagination))
self.assertEqual(8, len(results))
pagination = base.Pagination(limit=5)
results = list(self.conn.get_resources(pagination=pagination))
self.assertEqual(5, len(results))
def test_get_resources_all_marker(self):
pagination = base.Pagination(primary_sort_dir='asc',
sort_keys=['user_id'],
sort_dirs=['asc'],
marker_value='resource-id-4')
results = list(self.conn.get_resources(pagination=pagination))
self.assertEqual(5, len(results))
def test_get_resources_paginate(self):
pagination = base.Pagination(limit=3, primary_sort_dir='asc',
sort_keys=['user_id'], sort_dirs=['asc'],
marker_value='resource-id-4')
results = self.conn.get_resources(pagination=pagination)
self.assertEqual(['user-id-5', 'user-id-6', 'user-id-7'],
[i.user_id for i in results])
pagination = base.Pagination(limit=2, primary_sort_dir='desc',
sort_keys=['user_id'], sort_dirs=['asc'],
marker_value='resource-id-4')
results = list(self.conn.get_resources(pagination=pagination))
self.assertEqual(['user-id-3', 'user-id-2'],
[i.user_id for i in results])
pagination = base.Pagination(limit=3, primary_sort_dir='asc',
sort_keys=['user_id'], sort_dirs=['asc'],
marker_value='resource-id-5')
results = list(self.conn.get_resources(pagination=pagination))
self.assertEqual(['resource-id-6', 'resource-id-7', 'resource-id-8'],
[i.resource_id for i in results])
class ResourceTestOrdering(DBTestBase, class ResourceTestOrdering(DBTestBase,
tests_db.MixinTestsWithBackendScenarios): tests_db.MixinTestsWithBackendScenarios):
def prepare_data(self): def prepare_data(self):
@ -433,56 +389,6 @@ class MeterTest(DBTestBase,
self.assertEqual(9, len(results)) self.assertEqual(9, len(results))
class MeterTestPagination(DBTestBase,
tests_db.MixinTestsWithBackendScenarios):
def tet_get_meters_all_limit(self):
pagination = base.Pagination(limit=8)
results = list(self.conn.get_meters(pagination=pagination))
self.assertEqual(8, len(results))
pagination = base.Pagination(limit=5)
results = list(self.conn.get_meters(pagination=pagination))
self.assertEqual(5, len(results))
def test_get_meters_all_marker(self):
pagination = base.Pagination(limit=3, primary_sort_dir='desc',
sort_keys=['user_id'],
sort_dirs=['desc'],
marker_value='resource-id-5')
results = list(self.conn.get_meters(pagination=pagination))
self.assertEqual(8, len(results))
def test_get_meters_paginate(self):
pagination = base.Pagination(limit=3, primary_sort_dir='desc',
sort_keys=['user_id'], sort_dirs=['desc'],
marker_value='resource-id-5')
results = self.conn.get_meters(pagination=pagination)
self.assertEqual(['user-id-8', 'user-id-7', 'user-id-6'],
[i.user_id for i in results])
pagination = base.Pagination(limit=3, primary_sort_dir='asc',
sort_keys=['user_id'], sort_dirs=['desc'],
marker_value='resource-id-5')
results = self.conn.get_meters(pagination=pagination)
self.assertEqual(['user-id-5', 'user-id-6', 'user-id-7'],
[i.user_id for i in results])
pagination = base.Pagination(limit=2, primary_sort_dir='desc',
sort_keys=['user_id'], sort_dirs=['desc'],
marker_value='resource-id-5')
results = list(self.conn.get_meters(pagination=pagination))
self.assertEqual(['user-id-3', 'user-id-2'],
[i.user_id for i in results])
pagination = base.Pagination(limit=3, primary_sort_dir='desc',
sort_keys=['user_id'], sort_dirs=['desc'],
marker_value='resource-id-5')
results = self.conn.get_meters(pagination=pagination)
self.assertEqual([], [i.user_id for i in results])
class RawSampleTest(DBTestBase, class RawSampleTest(DBTestBase,
tests_db.MixinTestsWithBackendScenarios): tests_db.MixinTestsWithBackendScenarios):
@ -2976,48 +2882,6 @@ class AlarmTest(AlarmTestBase,
self.assertNotEqual(victim.name, s.name) self.assertNotEqual(victim.name, s.name)
class AlarmTestPagination(AlarmTestBase,
tests_db.MixinTestsWithBackendScenarios):
def test_get_alarm_all_limit(self):
self.add_some_alarms()
pagination = base.Pagination(limit=2)
alarms = list(self.alarm_conn.get_alarms(pagination=pagination))
self.assertEqual(2, len(alarms))
pagination = base.Pagination(limit=1)
alarms = list(self.alarm_conn.get_alarms(pagination=pagination))
self.assertEqual(1, len(alarms))
def test_get_alarm_all_marker(self):
self.add_some_alarms()
pagination = base.Pagination(marker_value='orange-alert')
alarms = list(self.alarm_conn.get_alarms(pagination=pagination))
self.assertEqual(0, len(alarms))
pagination = base.Pagination(marker_value='red-alert')
alarms = list(self.alarm_conn.get_alarms(pagination=pagination))
self.assertEqual(1, len(alarms))
pagination = base.Pagination(marker_value='yellow-alert')
alarms = list(self.alarm_conn.get_alarms(pagination=pagination))
self.assertEqual(2, len(alarms))
def test_get_alarm_paginate(self):
self.add_some_alarms()
pagination = base.Pagination(limit=4, marker_value='yellow-alert')
page = list(self.alarm_conn.get_alarms(pagination=pagination))
self.assertEqual(['red-alert', 'orange-alert'], [i.name for i in page])
pagination = base.Pagination(limit=2, marker_value='orange-alert',
primary_sort_dir='asc')
page1 = list(self.alarm_conn.get_alarms(pagination=pagination))
self.assertEqual(['red-alert', 'yellow-alert'],
[i.name for i in page1])
@tests_db.run_with('sqlite', 'mysql', 'pgsql', 'hbase', 'db2') @tests_db.run_with('sqlite', 'mysql', 'pgsql', 'hbase', 'db2')
class AlarmHistoryTest(AlarmTestBase, class AlarmHistoryTest(AlarmTestBase,
tests_db.MixinTestsWithBackendScenarios): tests_db.MixinTestsWithBackendScenarios):