@@ -32,23 +32,14 @@ def discover_peers(service_record):
32
32
# name to form the hostname used for the Erlang node. This feels hacky
33
33
# but not sure of a more official answer
34
34
result = [rdata .target .to_text ()[:- 1 ] for rdata in answers ]
35
- print ("\t Got the following peers' fqdm from DNS lookup:" ,result ,flush = True )
35
+ print ("\t | Got the following peers' fqdm from DNS lookup:" ,result ,flush = True )
36
36
return result
37
37
38
38
def backoff_hdlr (details ):
39
39
print ("Backing off {wait:0.1f} seconds afters {tries} tries "
40
40
"calling function {target} with args {args} and kwargs "
41
41
"{kwargs}" .format (** details ))
42
42
43
- def pod_not_ready_yet (details ):
44
- print ('\t Connection failure. CouchDB is not responding. Will retry.' )
45
-
46
- @backoff .on_exception (
47
- backoff .expo ,
48
- requests .exceptions .ConnectionError ,
49
- max_tries = 3 ,
50
- on_giveup = pod_not_ready_yet
51
- )
52
43
def connect_the_dots (names ):
53
44
54
45
# Ordinal Index: For a StatefulSet with N replicas, each Pod in the StatefulSet
@@ -84,12 +75,15 @@ def connect_the_dots(names):
84
75
uri = "http://127.0.0.1:5986/_nodes/couchdb@{0}" .format (name )
85
76
doc = {}
86
77
print ('Adding CouchDB cluster node' , name , "to this pod's CouchDB." )
87
- print ('\t Request: PUT' ,uri )
88
- if creds [0 ] and creds [1 ]:
89
- resp = requests .put (uri , data = json .dumps (doc ), auth = creds )
90
- else :
91
- resp = requests .put (uri , data = json .dumps (doc ))
92
- print ("\t Response:" , setup_resp .status_code , setup_resp .json (),flush = True )
78
+ print ('\t | Request: PUT' ,uri )
79
+ try :
80
+ if creds [0 ] and creds [1 ]:
81
+ resp = requests .put (uri , data = json .dumps (doc ), auth = creds )
82
+ else :
83
+ resp = requests .put (uri , data = json .dumps (doc ))
84
+ print ("\t | Response:" , setup_resp .status_code , setup_resp .json (),flush = True )
85
+ except requests .exceptions .ConnectionError :
86
+ print ('\t | Connection failure. CouchDB not responding. Will retry.' )
93
87
94
88
# Compare (json) objects - order does not matter. Credits to:
95
89
# https://stackoverflow.com/a/25851972
@@ -115,13 +109,13 @@ def finish_cluster(names):
115
109
creds = (os .getenv ("COUCHDB_USER" ), os .getenv ("COUCHDB_PASSWORD" ))
116
110
print ("== Get the cluster up and running ===" )
117
111
setup_resp = requests .post ("http://127.0.0.1:5984/_cluster_setup" , json = {"action" : "finish_cluster" }, auth = creds )
118
- print ('\t Request : POST http://127.0.0.1:5984/_cluster_setup , payload {"action": "finish_cluster"}' )
119
- print ("\t \t Response:" , setup_resp .status_code , setup_resp .json ())
112
+ print ('\t | Request : POST http://127.0.0.1:5984/_cluster_setup , payload {"action": "finish_cluster"}' )
113
+ print ("\t | \t Response:" , setup_resp .status_code , setup_resp .json ())
120
114
if (setup_resp .status_code == 201 ):
121
- print ("\t Sweet ! Just a final check for the logs..." )
115
+ print ("\t | Sweet ! Just a final check for the logs..." )
122
116
setup_resp = requests .get ("http://127.0.0.1:5984/_cluster_setup" , auth = creds )
123
- print ('\t Request : GET http://127.0.0.1:5984/_cluster_setup' )
124
- print ("\t \t Response:" , setup_resp .status_code , setup_resp .json ())
117
+ print ('\t | Request : GET http://127.0.0.1:5984/_cluster_setup' )
118
+ print ("\t | \t Response:" , setup_resp .status_code , setup_resp .json ())
125
119
print ("Time to relax!" )
126
120
else :
127
121
print ('Ouch! Failed the final step finalizing the cluster.' )
@@ -162,30 +156,30 @@ def are_nodes_in_sync(names):
162
156
if len (names ) < 2 :
163
157
# Minimum 2 nodes to form cluster!
164
158
not_ready = True
165
- print ("\t Need at least 2 DNS records to start with. Got " ,len (names ))
159
+ print ("\t | Need at least 2 DNS records to start with. Got " ,len (names ))
166
160
167
161
# Compare local and remote _mebership data. Make sure the set
168
162
# of nodes match. This will ensure that the remote nodes
169
163
# are fully primed with nodes data before progressing with
170
164
# _cluster_setup
171
165
if (remote_resp .status_code == 200 ) and (local_resp .status_code == 200 ):
172
166
if ordered (local_resp .json ()) == ordered (remote_resp .json ()):
173
- print ("\t In sync!" )
167
+ print ("\t | In sync!" )
174
168
else :
175
169
not_ready = True
176
170
# Rest is for logging only...
177
171
records_in_local_but_not_in_remote = set (local_resp .json ()['cluster_nodes' ]) - set (remote_resp .json ()['cluster_nodes' ])
178
172
if records_in_local_but_not_in_remote :
179
- print ("\t 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 ))
173
+ print ("\t | 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 ))
180
174
records_in_remote_but_not_in_local = set (remote_resp .json ()['cluster_nodes' ]) - set (local_resp .json ()['cluster_nodes' ])
181
175
if records_in_remote_but_not_in_local :
182
- print ("\t 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 ))
176
+ print ("\t | 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 ))
183
177
184
178
# Cover the case where local pod has 1 record only
185
179
if len (local_resp .json ()['cluster_nodes' ]) < 2 :
186
180
# Minimum 2 nodes to form cluster!
187
181
not_ready = True
188
- print ("\t Need at least 2 cluster nodes in the _membership of pod" ,os .getenv ("HOSTNAME" ))
182
+ print ("\t | Need at least 2 cluster nodes in the _membership of pod" ,os .getenv ("HOSTNAME" ))
189
183
else :
190
184
not_ready = True
191
185
return not not_ready
0 commit comments