Skip to content

Commit 0834916

Browse files
author
Robert Gartman
committed
Automate _cluster_setup
1 parent 2c9a42b commit 0834916

File tree

1 file changed

+9
-13
lines changed

1 file changed

+9
-13
lines changed

mem3_helper.py

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def ordered(obj):
6767
else:
6868
return obj
6969

70-
# Run action:finish_cluster on one (and only one) CouchDB cluster node
70+
# Call action:finish_cluster on one (and only one) CouchDB cluster node
7171
def finish_cluster(names):
7272
# The HTTP POST to /_cluster_setup should be done to
7373
# one (and only one) of the CouchDB cluster nodes.
@@ -90,9 +90,10 @@ def finish_cluster(names):
9090
print ("\t\tResponse:", setup_resp.status_code, setup_resp.json())
9191
print("Time to relax!")
9292
else:
93-
print('Ouch! Failed the final step: http://127.0.0.1:5984/_cluster_setup returned {0}'.format(setup_resp.status_code))
93+
print('Ouch! Failed the final step finalizing the cluster.')
9494
else:
95-
print("This pod is intentionally skipping the call to http://127.0.0.1:5984/_cluster_setup")
95+
print('This pod is intentionally skipping the POST to http://127.0.0.1:5984/_cluster_setup {"action": "finish_cluster"}')
96+
9697

9798
@backoff.on_exception(
9899
backoff.expo,
@@ -106,7 +107,6 @@ def are_nodes_in_sync(names):
106107
# have the same _membership data.Use "this" nodes memebership as
107108
# "source"
108109
local_membership_uri = "http://127.0.0.1:5984/_membership"
109-
print ("Fetching CouchDB node mebership from this pod: {0}".format(local_membership_uri),flush=True)
110110
creds = (os.getenv("COUCHDB_USER"), os.getenv("COUCHDB_PASSWORD"))
111111
if creds[0] and creds[1]:
112112
local_resp = requests.get(local_membership_uri, auth=creds)
@@ -139,20 +139,16 @@ def are_nodes_in_sync(names):
139139
is_different = True
140140
if ordered(local_resp.json()) != ordered(remote_resp.json()):
141141
is_different = True
142-
print ("Fetching CouchDB node mebership from this pod: {0}".format(local_membership_uri),flush=True)
142+
143+
# For logging only...
143144
records_in_local_but_not_in_remote = set(local_resp.json()['cluster_nodes']) - set(remote_resp.json()['cluster_nodes'])
144-
records_in_remote_but_not_in_local = set(remote_resp.json()['cluster_nodes']) - set(local_resp.json()['cluster_nodes'])
145145
if records_in_local_but_not_in_remote:
146-
print ("Cluster members in {0} not yet present in {1}: {2}".format(os.getenv("HOSTNAME"), name.split(".",1)[0], records_in_local_but_not_in_remote))
146+
print ("\tCluster members in {0} not yet present in {1}: {2}".format(os.getenv("HOSTNAME"), name.split(".",1)[0], records_in_local_but_not_in_remote))
147+
records_in_remote_but_not_in_local = set(remote_resp.json()['cluster_nodes']) - set(local_resp.json()['cluster_nodes'])
147148
if records_in_remote_but_not_in_local:
148-
print ("Cluster members in {0} not yet present in {1}: {2}".format(name.split(".",1)[0], os.getenv("HOSTNAME"), records_in_remote_but_not_in_local))
149+
print ("\tCluster members in {0} not yet present in {1}: {2}".format(name.split(".",1)[0], os.getenv("HOSTNAME"), records_in_remote_but_not_in_local))
149150
else:
150151
is_different = True
151-
152-
if (remote_resp.status_code == 200) and (local_resp.status_code == 200):
153-
print("local: ",local_resp.json()['cluster_nodes'])
154-
print("remote: ",remote_resp.json()['cluster_nodes'])
155-
print('returnerar', not is_different)
156152
return not is_different
157153

158154
def sleep_forever():

0 commit comments

Comments
 (0)