[ADMIN_API] Fixes to passive health monitoring
Mostly typo fixes to Marc's code Change-Id: Ic14f96d49c8948a4494e1ec53b976f5bd0552372
This commit is contained in:
@@ -209,6 +209,7 @@ class Stats(object):
|
|||||||
return lb
|
return lb
|
||||||
|
|
||||||
def _update_nodes(self, node_status, session):
|
def _update_nodes(self, node_status, session):
|
||||||
|
lbids = []
|
||||||
for lb, nodes in node_status.iteritems():
|
for lb, nodes in node_status.iteritems():
|
||||||
data = self._get_lb(lb, session)
|
data = self._get_lb(lb, session)
|
||||||
if not data:
|
if not data:
|
||||||
@@ -216,11 +217,10 @@ class Stats(object):
|
|||||||
'Device {0} has no Loadbalancer attached'.
|
'Device {0} has no Loadbalancer attached'.
|
||||||
format(lb)
|
format(lb)
|
||||||
)
|
)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# Iterate the list of nodes returned from the worker
|
# Iterate the list of nodes returned from the worker
|
||||||
# and track any status changes
|
# and track any status changes
|
||||||
lbids = []
|
|
||||||
degraded = []
|
degraded = []
|
||||||
failed_nodes = dict()
|
failed_nodes = dict()
|
||||||
repaired_nodes = dict()
|
repaired_nodes = dict()
|
||||||
@@ -231,26 +231,33 @@ class Stats(object):
|
|||||||
|
|
||||||
# Note all degraded LBs
|
# Note all degraded LBs
|
||||||
if (node['status'] == 'DOWN' and
|
if (node['status'] == 'DOWN' and
|
||||||
node.data.lbid not in degraded):
|
node_data.lbid not in degraded):
|
||||||
degraded.append(node_data.lbid)
|
degraded.append(node_data.lbid)
|
||||||
|
|
||||||
|
new_status = None
|
||||||
# Compare node status to the workers status
|
# Compare node status to the workers status
|
||||||
if (node['status'] == 'DOWN' and node_data.status == 'ONLINE'):
|
if (node['status'] == 'DOWN' and node_data.status == 'ONLINE'):
|
||||||
|
new_status = 'ERROR'
|
||||||
|
if node_data.lbid not in failed_nodes:
|
||||||
|
failed_nodes[node_data.lbid] = []
|
||||||
failed_nodes[node_data.lbid].append(node['id'])
|
failed_nodes[node_data.lbid].append(node['id'])
|
||||||
elif (node['status'] == 'UP' and node_data.status == 'ERROR'):
|
elif (node['status'] == 'UP' and node_data.status == 'ERROR'):
|
||||||
|
new_status = 'ONLINE'
|
||||||
|
if node_data.lbid not in repaired_nodes:
|
||||||
|
repaired_nodes[node_data.lbid] = []
|
||||||
repaired_nodes[node_data.lbid].append(node['id'])
|
repaired_nodes[node_data.lbid].append(node['id'])
|
||||||
else:
|
else:
|
||||||
# No change
|
# No change
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# Note all LBs with node status changes
|
# Note all LBs with node status changes
|
||||||
if node.data.lbid not in lbids:
|
if node_data.lbid not in lbids:
|
||||||
lbids.append(node_data.lbid)
|
lbids.append(node_data.lbid)
|
||||||
|
|
||||||
# Change the node status in the node table
|
# Change the node status in the node table
|
||||||
session.query(Node).\
|
session.query(Node).\
|
||||||
filter(Node.id == node['id']).\
|
filter(Node.id == node['id']).\
|
||||||
update({"status": node['status']},
|
update({"status": new_status},
|
||||||
synchronize_session='fetch')
|
synchronize_session='fetch')
|
||||||
session.flush()
|
session.flush()
|
||||||
|
|
||||||
@@ -259,9 +266,9 @@ class Stats(object):
|
|||||||
# Generate a status message per LB for the alert.
|
# Generate a status message per LB for the alert.
|
||||||
for lbid in lbids:
|
for lbid in lbids:
|
||||||
message = 'Node status change\n\
|
message = 'Node status change\n\
|
||||||
ID: {1}\n\
|
ID: {0}\n\
|
||||||
IP: {2}\n\
|
IP: {1}\n\
|
||||||
tenant: {3}:\n'.format(
|
tenant: {2}:\n'.format(
|
||||||
lbid, data.floatingIpAddr, data.tenantid)
|
lbid, data.floatingIpAddr, data.tenantid)
|
||||||
|
|
||||||
if lbid in failed_nodes:
|
if lbid in failed_nodes:
|
||||||
@@ -274,22 +281,25 @@ class Stats(object):
|
|||||||
message += ','.join(str(x) for x in repaired_nodes[lbid])
|
message += ','.join(str(x) for x in repaired_nodes[lbid])
|
||||||
|
|
||||||
# Send the LB node change alert
|
# Send the LB node change alert
|
||||||
|
if lbid in degraded:
|
||||||
|
is_degraded = True
|
||||||
|
else:
|
||||||
|
is_degraded = False
|
||||||
for driver in self.drivers:
|
for driver in self.drivers:
|
||||||
instance = driver(self.logger, self.args)
|
instance = driver(self.logger, self.args)
|
||||||
self.logger.info(
|
self.logger.info(
|
||||||
'Sending failure of nodes on LB {0} to {1}'.format(
|
'Sending change of node status on LB {0} to {1}'.format(
|
||||||
node, instance.__class__.__name__)
|
lbid, instance.__class__.__name__)
|
||||||
)
|
)
|
||||||
|
|
||||||
degraded = lbid in degraded
|
|
||||||
try:
|
try:
|
||||||
instance.send_node_change(message, lbid, degraded)
|
instance.send_node_change(message, lbid, is_degraded)
|
||||||
except NotImplementedError:
|
except NotImplementedError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def start_ping_sched(self):
|
def start_ping_sched(self):
|
||||||
# Always try to hit the expected second mark for pings
|
# Always try to hit the expected second mark for pings
|
||||||
seconds = datetime.now().seconds
|
seconds = datetime.now().second
|
||||||
if seconds < self.PING_SECONDS:
|
if seconds < self.PING_SECONDS:
|
||||||
sleeptime = self.PING_SECONDS - seconds
|
sleeptime = self.PING_SECONDS - seconds
|
||||||
else:
|
else:
|
||||||
@@ -302,7 +312,7 @@ class Stats(object):
|
|||||||
|
|
||||||
def start_repair_sched(self):
|
def start_repair_sched(self):
|
||||||
# Always try to hit the expected second mark for repairs
|
# Always try to hit the expected second mark for repairs
|
||||||
seconds = datetime.now().seconds
|
seconds = datetime.now().second
|
||||||
if seconds < self.REPAIR_SECONDS:
|
if seconds < self.REPAIR_SECONDS:
|
||||||
sleeptime = self.REPAIR_SECONDS - seconds
|
sleeptime = self.REPAIR_SECONDS - seconds
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -306,9 +306,10 @@ class LoadBalancersController(RestController):
|
|||||||
for node in body.nodes:
|
for node in body.nodes:
|
||||||
if node.condition == 'DISABLED':
|
if node.condition == 'DISABLED':
|
||||||
enabled = 0
|
enabled = 0
|
||||||
|
node_status = 'OFFLINE'
|
||||||
else:
|
else:
|
||||||
enabled = 1
|
enabled = 1
|
||||||
node_status = 'ONLINE' if enabled else 'OFFLINE'
|
node_status = 'ONLINE'
|
||||||
out_node = Node(
|
out_node = Node(
|
||||||
lbid=lb.id, port=node.port, address=node.address,
|
lbid=lb.id, port=node.port, address=node.address,
|
||||||
enabled=enabled, status=node_status, weight=1
|
enabled=enabled, status=node_status, weight=1
|
||||||
|
|||||||
@@ -168,9 +168,10 @@ class NodesController(RestController):
|
|||||||
for node in body.nodes:
|
for node in body.nodes:
|
||||||
if node.condition == 'DISABLED':
|
if node.condition == 'DISABLED':
|
||||||
enabled = 0
|
enabled = 0
|
||||||
|
node_status = 'OFFLINE'
|
||||||
else:
|
else:
|
||||||
enabled = 1
|
enabled = 1
|
||||||
node_status = 'ONLINE' if enabled else 'OFFLINE'
|
node_status = 'ONLINE'
|
||||||
new_node = Node(
|
new_node = Node(
|
||||||
lbid=self.lbid, port=node.port, address=node.address,
|
lbid=self.lbid, port=node.port, address=node.address,
|
||||||
enabled=enabled, status=node_status, weight=1
|
enabled=enabled, status=node_status, weight=1
|
||||||
|
|||||||
Reference in New Issue
Block a user