From 50c5f9c812cf84042b5f4c58b8bb7bb838ebd622 Mon Sep 17 00:00:00 2001 From: Fei Long Wang Date: Tue, 18 Feb 2014 12:46:43 +0800 Subject: [PATCH] feat(v1.1): Implement /ping endpoint for v1.1 This patch creates a new endpoint /ping in v1.1 API, which is a clone of the /health endpoint in v1.0. Because a new /health endpoint will be added in v1.1 to return more detailed KPI of Marconi server. Implement blueprint: api-v1.1-ping-endpoint Change-Id: I486c8a3583fc557c0b0578b0f73a6c6a2a3748b3 --- .../queues/transport/wsgi/v1_1/__init__.py | 7 +++- marconi/queues/transport/wsgi/v1_1/ping.py | 33 +++++++++++++++++ .../unit/queues/storage/test_shard_queues.py | 6 ++-- tests/unit/queues/transport/wsgi/test_ping.py | 35 +++++++++++++++++++ 4 files changed, 77 insertions(+), 4 deletions(-) create mode 100644 marconi/queues/transport/wsgi/v1_1/ping.py create mode 100644 tests/unit/queues/transport/wsgi/test_ping.py diff --git a/marconi/queues/transport/wsgi/v1_1/__init__.py b/marconi/queues/transport/wsgi/v1_1/__init__.py index 0302376e1..8d6ab6ff7 100644 --- a/marconi/queues/transport/wsgi/v1_1/__init__.py +++ b/marconi/queues/transport/wsgi/v1_1/__init__.py @@ -3,6 +3,7 @@ from marconi.queues.transport.wsgi.v1_1 import health from marconi.queues.transport.wsgi.v1_1 import homedoc from marconi.queues.transport.wsgi.v1_1 import messages from marconi.queues.transport.wsgi.v1_1 import metadata +from marconi.queues.transport.wsgi.v1_1 import ping from marconi.queues.transport.wsgi.v1_1 import queues from marconi.queues.transport.wsgi.v1_1 import shards from marconi.queues.transport.wsgi.v1_1 import stats @@ -51,7 +52,11 @@ def public_endpoints(driver): # Health ('/health', - health.Resource(driver._storage)) + health.Resource(driver._storage)), + + # Ping + ('/ping', + ping.Resource(driver._storage)) ] diff --git a/marconi/queues/transport/wsgi/v1_1/ping.py b/marconi/queues/transport/wsgi/v1_1/ping.py new file mode 100644 index 000000000..d0e358b08 --- /dev/null +++ b/marconi/queues/transport/wsgi/v1_1/ping.py @@ -0,0 +1,33 @@ +# Copyright 2014 IBM Corp. +# All Rights Reserved. +# +# 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 + + +class Resource(object): + + __slots__ = ('driver',) + + def __init__(self, driver): + self.driver = driver + + def on_get(self, req, resp, **kwargs): + resp.status = (falcon.HTTP_204 if self.driver.is_alive() + else falcon.HTTP_503) + + def on_head(self, req, resp, **kwargs): + resp.status = falcon.HTTP_204 diff --git a/tests/unit/queues/storage/test_shard_queues.py b/tests/unit/queues/storage/test_shard_queues.py index f84df2aba..7eb5141eb 100644 --- a/tests/unit/queues/storage/test_shard_queues.py +++ b/tests/unit/queues/storage/test_shard_queues.py @@ -49,9 +49,9 @@ class ShardQueuesTest(testing.TestBase): self.shards_ctrl.drop_all() super(ShardQueuesTest, self).tearDown() - def test_health(self): - health = self.driver.is_alive() - self.assertTrue(health) + def test_ping(self): + ping = self.driver.is_alive() + self.assertTrue(ping) def test_listing(self): project = "I.G" diff --git a/tests/unit/queues/transport/wsgi/test_ping.py b/tests/unit/queues/transport/wsgi/test_ping.py new file mode 100644 index 000000000..71ea473e2 --- /dev/null +++ b/tests/unit/queues/transport/wsgi/test_ping.py @@ -0,0 +1,35 @@ +# Copyright 2014 IBM Corp. +# All Rights Reserved. +# +# 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 . import base # noqa + + +class TestPing(base.TestBase): + + config_file = 'wsgi_sqlite.conf' + + def test_get(self): + response = self.simulate_get('/v1.1/ping') + self.assertEqual(self.srmock.status, falcon.HTTP_204) + self.assertEqual(response, []) + + def test_head(self): + response = self.simulate_head('/v1.1/ping') + self.assertEqual(self.srmock.status, falcon.HTTP_204) + self.assertEqual(response, [])