Add support for version discovery to worker.
The worker now supports a DISCOVER message that can be sent to it to discover which version of the JSON message format that it supports. The Gearman function name that it registers is now simply the hostname and no longer includes 'lbaas-<VERSION>-' as a prefix. Change-Id: Ib34ae424e5461b3b1f8df601a6e7a1fd99c48c05
This commit is contained in:
parent
27b1393bec
commit
ae8952dea7
@ -4,10 +4,10 @@ Description
|
||||
Purpose
|
||||
-------
|
||||
|
||||
A Python-based Gearman worker that handles work for the job queue named
|
||||
'lbaas-HOSTNAME'. It receives JSON data describing a load balancer, and
|
||||
returns this same JSON object, but with status fields added to describe
|
||||
the state of the LB.
|
||||
A Python-based Gearman worker that handles messages for the Gearman job queue
|
||||
sharing the same name as the local hostname. The messages that it receives are
|
||||
JSON objects describing a load balancer, and returns this same JSON object, but
|
||||
with status fields added to describe the state of the LB.
|
||||
|
||||
Installation
|
||||
------------
|
||||
|
@ -55,6 +55,8 @@ class LBaaSController(object):
|
||||
return self._action_enable()
|
||||
elif action == 'DELETE':
|
||||
return self._action_delete()
|
||||
elif action == 'DISCOVER':
|
||||
return self._action_discover()
|
||||
else:
|
||||
self.logger.error("Invalid `%s` value: %s" %
|
||||
(self.ACTION_FIELD, action))
|
||||
@ -66,6 +68,19 @@ class LBaaSController(object):
|
||||
self.msg[self.RESPONSE_FIELD] = self.RESPONSE_FAILURE
|
||||
return self.msg
|
||||
|
||||
def _action_discover(self):
|
||||
"""
|
||||
Return service discovery information.
|
||||
|
||||
This message type is currently used to report which message
|
||||
version this worker supports.
|
||||
"""
|
||||
# Version of the JSON message format that this worker understands.
|
||||
msg_fmt_version = "1.0"
|
||||
self.msg['version'] = msg_fmt_version
|
||||
self.msg[self.RESPONSE_FIELD] = self.RESPONSE_SUCCESS
|
||||
return self.msg
|
||||
|
||||
def _action_update(self):
|
||||
"""
|
||||
Create/Update a Load Balancer.
|
||||
|
@ -49,14 +49,9 @@ def handler(worker, job):
|
||||
|
||||
def config_thread(logger, driver, servers, reconnect_sleep):
|
||||
""" Worker thread function. """
|
||||
# Version of the JSON message format that this worker understands.
|
||||
msg_fmt_version = "1.0"
|
||||
|
||||
# Hostname should be a unique value, like UUID
|
||||
hostname = socket.gethostname()
|
||||
|
||||
task_name = "lbaas-%s-%s" % (msg_fmt_version, hostname)
|
||||
logger.info("[worker] Registering task %s" % task_name)
|
||||
logger.info("[worker] Registering task %s" % hostname)
|
||||
|
||||
worker = CustomJSONGearmanWorker(servers)
|
||||
worker.set_client_id(hostname)
|
||||
|
@ -127,3 +127,10 @@ class TestWorkerController(unittest.TestCase):
|
||||
response = controller.run()
|
||||
self.assertIn(c.RESPONSE_FIELD, response)
|
||||
self.assertEquals(response[c.RESPONSE_FIELD], c.RESPONSE_FAILURE)
|
||||
|
||||
def testDiscover(self):
|
||||
msg = { c.ACTION_FIELD: 'DISCOVER' }
|
||||
controller = c(self.logger, self.driver, msg)
|
||||
response = controller.run()
|
||||
self.assertIn('version', response)
|
||||
self.assertEquals(response[c.RESPONSE_FIELD], c.RESPONSE_SUCCESS)
|
||||
|
Loading…
x
Reference in New Issue
Block a user