[WORKER] Support LB timeout options
Parse the new loadBalancers.options section of the UPDATE JSON message to set various timeouts and retry values. These options can be set per-protocol. Timeout values are assumed to be in milliseconds, with the default being 30000 ms for the timeouts and 3 for the retry value. Example JSON message: { "hpcs_action": "UPDATE", "loadBalancers": [ "protocol": "http", "options": { "client_timeout": "30000", "server_timeout": "30000", "connect_timeout": "30000", "connect_retries": "3" }, ... ] } Change-Id: I45a6b9c85e8fc282ac80fa3f0eae0193e08e9756
This commit is contained in:
parent
833b775321
commit
0eb56f8c62
|
@ -133,6 +133,45 @@ class LBaaSController(object):
|
|||
)
|
||||
raise
|
||||
|
||||
def _set_lb_options(self, protocol, options):
|
||||
"""
|
||||
Parse load balancer options.
|
||||
|
||||
options
|
||||
Dictionary of load balancer options.
|
||||
|
||||
Returns: True on success, False otherwise
|
||||
"""
|
||||
|
||||
# Default timeout values in milliseconds
|
||||
client_val = 30000
|
||||
server_val = 30000
|
||||
connect_val = 30000
|
||||
retries_val = 3
|
||||
|
||||
if 'client_timeout' in options:
|
||||
client_val = options['client_timeout']
|
||||
if 'server_timeout' in options:
|
||||
server_val = options['server_timeout']
|
||||
if 'connect_timeout' in options:
|
||||
connect_val = options['connect_timeout']
|
||||
if 'connect_retries' in options:
|
||||
retries_val = options['connect_retries']
|
||||
|
||||
try:
|
||||
self.driver.set_timeouts(protocol, client_val, server_val,
|
||||
connect_val, retries_val)
|
||||
except NotImplementedError:
|
||||
pass
|
||||
except Exception as e:
|
||||
error = "Failed to set timeout values: %s" % e
|
||||
LOG.error(error)
|
||||
self.msg[self.ERROR_FIELD] = error
|
||||
self.msg[self.RESPONSE_FIELD] = self.RESPONSE_FAILURE
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
def _action_discover(self):
|
||||
"""
|
||||
Return service discovery information.
|
||||
|
@ -257,6 +296,15 @@ class LBaaSController(object):
|
|||
self.msg[self.RESPONSE_FIELD] = self.RESPONSE_FAILURE
|
||||
return self.msg
|
||||
|
||||
if 'options' in current_lb:
|
||||
lb_options = current_lb['options']
|
||||
else:
|
||||
lb_options = {}
|
||||
|
||||
# Always call _set_lb_options() since it sets sensible defaults
|
||||
if not self._set_lb_options(current_lb['protocol'], lb_options):
|
||||
return self.msg
|
||||
|
||||
for lb_node in current_lb['nodes']:
|
||||
port = None
|
||||
address = None
|
||||
|
|
|
@ -122,3 +122,10 @@ class LoadBalancerDriver(object):
|
|||
def archive(self, method, params):
|
||||
""" Archive the load balancer logs using the specified method. """
|
||||
raise NotImplementedError()
|
||||
|
||||
def set_timeouts(self, protocol, client_timeout, server_timeout,
|
||||
connect_timeout, connect_retries):
|
||||
"""
|
||||
Set the various timeout values for the specified protocol.
|
||||
"""
|
||||
raise NotImplementedError()
|
||||
|
|
|
@ -75,10 +75,6 @@ class HAProxyDriver(LoadBalancerDriver):
|
|||
output.append(' option dontlognull')
|
||||
output.append(' option redispatch')
|
||||
output.append(' maxconn 50000')
|
||||
output.append(' retries 3')
|
||||
output.append(' timeout connect 30000ms')
|
||||
output.append(' timeout client 30000ms')
|
||||
output.append(' timeout server 30000ms')
|
||||
|
||||
for proto in self._config:
|
||||
protocfg = self._config[proto]
|
||||
|
@ -93,6 +89,8 @@ class HAProxyDriver(LoadBalancerDriver):
|
|||
output.append(' mode %s' % real_proto)
|
||||
output.append(' bind %s:%s' % (protocfg['bind_address'],
|
||||
protocfg['bind_port']))
|
||||
output.append(' timeout client %sms' %
|
||||
protocfg['timeouts']['timeout_client'])
|
||||
output.append(' default_backend %s-servers' % real_proto)
|
||||
|
||||
# HTTP specific options for the frontend
|
||||
|
@ -109,6 +107,11 @@ class HAProxyDriver(LoadBalancerDriver):
|
|||
output.append('backend %s-servers' % real_proto)
|
||||
output.append(' mode %s' % real_proto)
|
||||
output.append(' balance %s' % protocfg['algorithm'])
|
||||
output.append(' timeout connect %sms' %
|
||||
protocfg['timeouts']['timeout_connect'])
|
||||
output.append(' timeout server %sms' %
|
||||
protocfg['timeouts']['timeout_server'])
|
||||
output.append(' retries %s' % protocfg['timeouts']['retries'])
|
||||
|
||||
# default healthcheck if none specified
|
||||
monitor = 'check inter 30s'
|
||||
|
@ -420,3 +423,13 @@ class HAProxyDriver(LoadBalancerDriver):
|
|||
else:
|
||||
raise Exception("Driver does not support archive method '%s'" %
|
||||
method)
|
||||
|
||||
def set_timeouts(self, protocol, client_timeout, server_timeout,
|
||||
connect_timeout, connect_retries):
|
||||
protocol = protocol.lower()
|
||||
self._config[protocol]['timeouts'] = {
|
||||
'timeout_client': client_timeout,
|
||||
'timeout_server': server_timeout,
|
||||
'timeout_connect': connect_timeout,
|
||||
'retries': connect_retries
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue