Add /health support to the client
The patch adds /health support of the client. This will allow users to check the status of shard from Marconi. Partially-Implements blueprint: python-marconiclient-v1 Change-Id: I5e6bbb79144a5808ef91b00bb8265936364cec30
This commit is contained in:
parent
2974818961
commit
d49c752e28
|
@ -0,0 +1,25 @@
|
|||
# Copyright 2014 IBM Corp.
|
||||
#
|
||||
# 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.
|
||||
|
||||
from marconiclient.queues import client
|
||||
|
||||
URL = 'http://localhost:8888/v1'
|
||||
|
||||
|
||||
def healthy():
|
||||
cli = client.Client(url=URL, version=1)
|
||||
return True if cli.health() else False
|
||||
|
||||
if __name__ == '__main__':
|
||||
healthy()
|
|
@ -161,4 +161,10 @@ class V1(api.Api):
|
|||
'shard_name': {'type': 'string'},
|
||||
}
|
||||
},
|
||||
|
||||
'health': {
|
||||
'admin': True,
|
||||
'ref': 'health',
|
||||
'method': 'GET',
|
||||
},
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
|
||||
import uuid
|
||||
|
||||
from marconiclient.queues.v1 import core
|
||||
from marconiclient.queues.v1 import queues
|
||||
from marconiclient.queues.v1 import shard
|
||||
from marconiclient import transport
|
||||
|
@ -112,3 +113,8 @@ class Client(object):
|
|||
:rtype: `shard.Shard`
|
||||
"""
|
||||
return shard.Shard(self, ref, **kwargs)
|
||||
|
||||
def health(self):
|
||||
"""Gets the health status of Marconi server."""
|
||||
req, trans = self._request_and_transport()
|
||||
return core.health(trans, req)
|
||||
|
|
|
@ -267,3 +267,21 @@ def shard_delete(transport, request, shard_name):
|
|||
request.operation = 'shard_delete'
|
||||
request.params['shard_name'] = shard_name
|
||||
transport.send(request)
|
||||
|
||||
|
||||
def health(transport, request, callback=None):
|
||||
"""Check the health of web head for load balancing
|
||||
|
||||
:param transport: Transport instance to use
|
||||
:type transport: `transport.base.Transport`
|
||||
:param request: Request instance ready to be sent.
|
||||
:type request: `transport.request.Request`
|
||||
:param callback: Optional callable to use as callback.
|
||||
If specified, this request will be sent asynchronously.
|
||||
(IGNORED UNTIL ASYNC SUPPORT IS COMPLETE)
|
||||
:type callback: Callable object.
|
||||
"""
|
||||
|
||||
request.operation = 'health'
|
||||
resp = transport.send(request)
|
||||
return resp.deserialized_content
|
||||
|
|
|
@ -13,8 +13,12 @@
|
|||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import mock
|
||||
|
||||
from marconiclient.queues import client
|
||||
from marconiclient.queues.v1 import core
|
||||
from marconiclient.tests import base
|
||||
from marconiclient.transport import response
|
||||
|
||||
VERSION = 1
|
||||
|
||||
|
@ -25,3 +29,11 @@ class TestClient(base.TestBase):
|
|||
cli = client.Client('http://example.com',
|
||||
VERSION, {})
|
||||
self.assertIsNotNone(cli.transport())
|
||||
|
||||
def test_health(self):
|
||||
cli = client.Client('http://example.com',
|
||||
VERSION, {})
|
||||
with mock.patch.object(core, 'health', autospec=True) as core_health:
|
||||
resp = response.Response(None, None)
|
||||
core_health.return_value = resp
|
||||
self.assertIsNotNone(cli.health())
|
||||
|
|
|
@ -187,3 +187,12 @@ class TestV1Core(base.TestBase):
|
|||
|
||||
req = request.Request()
|
||||
core.shard_delete(self.transport, req, 'test_shard')
|
||||
|
||||
def test_health(self):
|
||||
with mock.patch.object(self.transport, 'send',
|
||||
autospec=True) as send_method:
|
||||
resp = response.Response(None, None)
|
||||
send_method.return_value = resp
|
||||
|
||||
req = request.Request()
|
||||
core.health(self.transport, req)
|
||||
|
|
Loading…
Reference in New Issue