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
This commit is contained in:
Fei Long Wang 2014-02-18 12:46:43 +08:00
parent ffb625abb2
commit 50c5f9c812
4 changed files with 77 additions and 4 deletions

View File

@ -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))
]

View File

@ -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 File

@ -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"

View File

@ -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, [])