File tree Expand file tree Collapse file tree 2 files changed +46
-17
lines changed Expand file tree Collapse file tree 2 files changed +46
-17
lines changed Original file line number Diff line number Diff line change 2727 ParcelResourceApi ,
2828 ParcelsResourceApi ,
2929)
30+ from cm_client .rest import ApiException
3031
3132from ansible_collections .cloudera .cluster .plugins .module_utils .cm_utils import (
3233 normalize_output ,
@@ -89,11 +90,26 @@ def _wait(self, stage: STAGE) -> None:
8990 return Exception (f"Failed to reach { stage .name } : timeout ({ self .timeout } secs)" )
9091
9192 def _exec (self , stage : STAGE , func ) -> None :
92- func (
93- cluster_name = self .cluster ,
94- product = self .product ,
95- version = self .version ,
96- )
93+ retries = 0
94+
95+ # Retry the function, i.e. start_distribution, if receiving a 400 error due to
96+ # potential "eventual consistency" issues with parcel torrents.
97+ while True :
98+ try :
99+ func (
100+ cluster_name = self .cluster ,
101+ product = self .product ,
102+ version = self .version ,
103+ )
104+ break
105+ except ApiException as e :
106+ if retries < 4 and e .status == 400 :
107+ retries += 1
108+ time .sleep (15 )
109+ continue
110+ else :
111+ raise e
112+
97113 self ._wait (stage )
98114
99115 def remove (self ):
Original file line number Diff line number Diff line change 339339 returned: when supported
340340"""
341341
342+ from time import sleep
342343
343344from cm_client import (
344345 ApiHost ,
@@ -626,18 +627,30 @@ def process(self):
626627 self .diff ["after" ].update (cluster = cluster .name )
627628
628629 if not self .module .check_mode :
629- # Add the host to the cluster
630- cluster_api .add_hosts (
631- cluster_name = cluster .name ,
632- body = ApiHostRefList (
633- items = [
634- ApiHostRef (
635- host_id = current .host_id ,
636- hostname = current .hostname ,
637- )
638- ]
639- ),
640- )
630+ # Add the host to the cluster (with simple retry)
631+ add_retry = 0
632+
633+ while True :
634+ try :
635+ cluster_api .add_hosts (
636+ cluster_name = cluster .name ,
637+ body = ApiHostRefList (
638+ items = [
639+ ApiHostRef (
640+ host_id = current .host_id ,
641+ hostname = current .hostname ,
642+ )
643+ ]
644+ ),
645+ )
646+ break
647+ except ApiException as ae :
648+ if add_retry < 4 and ae .status == 400 :
649+ add_retry += 1
650+ sleep (10 )
651+ continue
652+ else :
653+ raise ae
641654
642655 # parcel_api = ParcelResourceApi(self.api_client)
643656 # try:
You can’t perform that action at this time.
0 commit comments