Queue Stats in WSGI.
Change-Id: Ic3652dd1c7e7a97323c9c7d86b281c4f1691532d Implements: blueprint transport-wsgi
This commit is contained in:
parent
628737108e
commit
2157af264c
@ -150,6 +150,17 @@ class TestMessages(util.TestBase):
|
||||
self.assertEquals(cnt, 4)
|
||||
self.assertEquals(self.srmock.status, falcon.HTTP_204)
|
||||
|
||||
# Stats
|
||||
env = testing.create_environ('/v1/480924/queues/fizbit/stats')
|
||||
|
||||
body = self.app(env, self.srmock)
|
||||
countof = json.loads(body[0])
|
||||
|
||||
self.assertEquals(self.srmock.status, falcon.HTTP_200)
|
||||
self.assertEquals(self.srmock.headers_dict['Content-Location'],
|
||||
env['PATH_INFO'])
|
||||
self.assertEquals(countof['messages'], 10)
|
||||
|
||||
env = testing.create_environ('/v1/480924/queues/nonexistent/messages',
|
||||
headers=self.headers)
|
||||
|
||||
|
@ -4,3 +4,4 @@ from marconi.transport.wsgi import claims # NOQA
|
||||
from marconi.transport.wsgi.driver import Driver # NOQA
|
||||
from marconi.transport.wsgi import messages # NOQA
|
||||
from marconi.transport.wsgi import queues # NOQA
|
||||
from marconi.transport.wsgi import stats # NOQA
|
||||
|
@ -31,6 +31,8 @@ class Driver(transport.DriverBase):
|
||||
queue_controller)
|
||||
queue_item = transport.wsgi.queues.ItemResource(queue_controller)
|
||||
|
||||
stats_endpoint = transport.wsgi.stats.Resource(queue_controller)
|
||||
|
||||
msg_collection = transport.wsgi.messages.CollectionResource(
|
||||
message_controller)
|
||||
msg_item = transport.wsgi.messages.ItemResource(message_controller)
|
||||
@ -42,6 +44,8 @@ class Driver(transport.DriverBase):
|
||||
self.app = api = falcon.API()
|
||||
api.add_route('/v1/{tenant_id}/queues', queue_collection)
|
||||
api.add_route('/v1/{tenant_id}/queues/{queue_name}', queue_item)
|
||||
api.add_route('/v1/{tenant_id}/queues/{queue_name}'
|
||||
'/stats', stats_endpoint)
|
||||
api.add_route('/v1/{tenant_id}/queues/{queue_name}'
|
||||
'/messages', msg_collection)
|
||||
api.add_route('/v1/{tenant_id}/queues/{queue_name}'
|
||||
|
34
marconi/transport/wsgi/stats.py
Normal file
34
marconi/transport/wsgi/stats.py
Normal file
@ -0,0 +1,34 @@
|
||||
# Copyright (c) 2013 Rackspace, Inc.
|
||||
#
|
||||
# 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 falcon
|
||||
|
||||
from marconi.transport import helpers
|
||||
|
||||
|
||||
class Resource(object):
|
||||
|
||||
__slots__ = ('queue_ctrl')
|
||||
|
||||
def __init__(self, queue_controller):
|
||||
self.queue_ctrl = queue_controller
|
||||
|
||||
def on_get(self, req, resp, tenant_id, queue_name):
|
||||
resp_dict = self.queue_ctrl.stats(queue_name,
|
||||
tenant=tenant_id)
|
||||
|
||||
resp.content_location = req.path
|
||||
resp.body = helpers.to_json(resp_dict)
|
||||
resp.status = falcon.HTTP_200
|
Loading…
x
Reference in New Issue
Block a user