Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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
  • Loading branch information...
commit 50c5f9c812cf84042b5f4c58b8bb7bb838ebd622 1 parent ffb625a
@openstacker openstacker authored
View
7 marconi/queues/transport/wsgi/v1_1/__init__.py
@@ -3,6 +3,7 @@
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))
]
View
33 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
View
6 tests/unit/queues/storage/test_shard_queues.py
@@ -49,9 +49,9 @@ def tearDown(self):
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"
View
35 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, [])
Please sign in to comment.
Something went wrong with that request. Please try again.