@@ -53,6 +53,24 @@ def connect_the_dots(names):
53
53
resp = requests .put (uri , data = json .dumps (doc ))
54
54
print ('Adding CouchDB cluster node' , name , "to this pod's CouchDB" , flush = True )
55
55
56
+ # Run action:enable_cluster on every CouchDB cluster node
57
+ def enable_cluster (nr_of_peers ):
58
+ creds = (os .getenv ("COUCHDB_USER" ), os .getenv ("COUCHDB_PASSWORD" ))
59
+ if creds [0 ] and creds [1 ]:
60
+ headers = {'Content-type' : 'application/json' }
61
+ print ("== Enabling cluster mode ===" )
62
+ # http://docs.couchdb.org/en/stable/cluster/setup.html
63
+ payload = {}
64
+ payload ['action' ] = 'enable_cluster'
65
+ payload ['bind_address' ] = '0.0.0.0'
66
+ payload ['username' ] = creds [0 ]
67
+ payload ['password' ] = creds [1 ]
68
+ payload ['node_count' ] = nr_of_peers
69
+ setup_resp = requests .post ("http://127.0.0.1:5984/_cluster_setup" , json .dumps (payload ), auth = creds , headers = headers )
70
+ payload ['password' ] = "**masked**"
71
+ print ("\t Request: http://127.0.0.1:5984/_cluster_setup , payload:" ,json .dumps (payload ))
72
+ print ("\t Response:" , setup_resp )
73
+
56
74
# Compare (json) objects - order does not matter. Credits to:
57
75
# https://stackoverflow.com/a/25851972
58
76
def ordered (obj ):
@@ -85,7 +103,7 @@ def finish_cluster(names):
85
103
local_resp = requests .get (local_membership_uri , auth = creds )
86
104
else :
87
105
local_resp = requests .get (local_membership_uri )
88
- # Step through every peer pod and grab the _membership .
106
+ # Step through every peer. Ensure they are "ready" before progressing .
89
107
for name in names :
90
108
print ("Probing {0} for cluster membership" .format (name ))
91
109
remote_membership_uri = "http://{0}:5984/_membership" .format (name )
@@ -103,8 +121,10 @@ def finish_cluster(names):
103
121
time .sleep (5 )
104
122
if creds [0 ] and creds [1 ]:
105
123
remote_resp = requests .get (remote_membership_uri , auth = creds )
124
+ print ("Node {0} has all node members in place!" .format (name ))
106
125
# The node in <name> is primed
107
126
# http://docs.couchdb.org/en/stable/cluster/setup.html
127
+ print ("== Adding nodes to CouchDB cluster via the “setup coordination node” ===" )
108
128
109
129
headers = {'Content-type' : 'application/json' }
110
130
@@ -122,7 +142,8 @@ def finish_cluster(names):
122
142
setup_resp = requests .post ("http://127.0.0.1:5984/_cluster_setup" , json .dumps (payload ), auth = creds , headers = headers )
123
143
payload ['password' ] = "**masked**"
124
144
payload ['remote_current_password' ] = "**masked**"
125
- print ("POST to http://127.0.0.1:5984/_cluster_setup returned" ,setup_resp .status_code ,"payload=" ,json .dumps (payload ))
145
+ print ("\t Request: http://127.0.0.1:5984/_cluster_setup , payload:" ,json .dumps (payload ))
146
+ print ("\t Response:" , setup_resp )
126
147
127
148
# action: add_node
128
149
payload = {}
@@ -133,7 +154,8 @@ def finish_cluster(names):
133
154
payload ['host' ] = name
134
155
setup_resp = requests .post ("http://127.0.0.1:5984/_cluster_setup" , json .dumps (payload ), auth = creds , headers = headers )
135
156
payload ['password' ] = "**masked**"
136
- print ("POST to http://127.0.0.1:5984/_cluster_setup returned" ,setup_resp .status_code ,"payload=" ,json .dumps (payload ))
157
+ print ("\t Request: http://127.0.0.1:5984/_cluster_setup , payload:" ,json .dumps (payload ))
158
+ print ("\t Response:" , setup_resp )
137
159
138
160
print ('CouchDB cluster peer {} added to "setup coordination node"' .format (name ))
139
161
# At this point ALL peers have _nodes populated. Finish the cluster setup!
@@ -146,23 +168,6 @@ def finish_cluster(names):
146
168
else :
147
169
print ("This pod is intentionally skipping the call to http://127.0.0.1:5984/_cluster_setup" )
148
170
149
- # Run action:enable_cluster on every CouchDB cluster node
150
- def enable_cluster (nr_of_peers ):
151
- creds = (os .getenv ("COUCHDB_USER" ), os .getenv ("COUCHDB_PASSWORD" ))
152
- if creds [0 ] and creds [1 ]:
153
- headers = {'Content-type' : 'application/json' }
154
-
155
- # http://docs.couchdb.org/en/stable/cluster/setup.html
156
- payload = {}
157
- payload ['action' ] = 'enable_cluster'
158
- payload ['bind_address' ] = '0.0.0.0'
159
- payload ['username' ] = creds [0 ]
160
- payload ['password' ] = creds [1 ]
161
- payload ['node_count' ] = '{0}' .format (nr_of_peers )
162
- setup_resp = requests .post ("http://127.0.0.1:5984/_cluster_setup" , json .dumps (payload ), auth = creds , headers = headers )
163
- payload ['password' ] = "**masked**"
164
- print ("POST to http://127.0.0.1:5984/_cluster_setup returned" ,setup_resp .status_code ,"payload=" ,json .dumps (payload ))
165
-
166
171
def sleep_forever ():
167
172
while True :
168
173
time .sleep (5 )
0 commit comments