From 29d44444e5b3f9c5dc7e2ddc63e6348c3ce6cd6c Mon Sep 17 00:00:00 2001 From: Joshua Boniface Date: Sat, 27 Oct 2018 15:24:42 -0400 Subject: [PATCH] Add function to get primary node --- client-common/common.py | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/client-common/common.py b/client-common/common.py index 52a39e1c..e8064069 100644 --- a/client-common/common.py +++ b/client-common/common.py @@ -41,7 +41,6 @@ def validateUUID(dom_uuid): except: return False - # # Connect and disconnect from Zookeeper # @@ -176,16 +175,30 @@ def verifyNode(zk_conn, node): return True except: return False -# -# Verify router is valid in cluster -# -def verifyRouter(zk_conn, router): - try: - zk_conn.get('/routers/{}'.format(router)) - return True - except: - return False +# +# Get the primary coordinator node +# +def getPrimaryNode(zk_conn): + failcount = 0 + while True: + try: + primary_node = zkhandler.readdata(zk_conn, '/primary_node') + except: + primary_node == 'none' + + if primary_node == 'none': + raise + time.sleep(1) + failcount += 1 + continue + else: + break + + if failcount > 2: + return None + + return primary_node # # Get the list of valid target nodes