@@ -166,6 +166,65 @@ public VersionInfo readVersionCode() throws ApiException {
166
166
requestParams , ((client , params ) -> new VersionApi (client ).getCode ()));
167
167
}
168
168
169
+ /**
170
+ * Class extended by callers to {@link
171
+ * #executeSynchronousCallWithConflictRetry(RequestParamsBuilder, SynchronousCallFactory,
172
+ * ConflictRetry)} for building the RequestParams to be passed to {@link
173
+ * #executeSynchronousCall(RequestParams, SynchronousCallFactory)}.
174
+ *
175
+ * @param <T> Type of kubernetes object to be passed to the API
176
+ */
177
+ abstract static class RequestParamsBuilder <T > {
178
+ T body ;
179
+
180
+ public RequestParamsBuilder (T body ) {
181
+ this .body = body ;
182
+ }
183
+
184
+ abstract RequestParams buildRequestParams ();
185
+
186
+ void setBody (T body ) {
187
+ this .body = body ;
188
+ }
189
+ }
190
+
191
+ private <T > T executeSynchronousCallWithConflictRetry (
192
+ RequestParamsBuilder requestParamsBuilder ,
193
+ SynchronousCallFactory <T > factory ,
194
+ ConflictRetry <T > conflictRetry )
195
+ throws ApiException {
196
+ int retryCount = 0 ;
197
+ while (retryCount == 0 || retryCount < maxRetryCount ) {
198
+ retryCount ++;
199
+ RequestParams requestParams = requestParamsBuilder .buildRequestParams ();
200
+ try {
201
+ return executeSynchronousCall (requestParams , factory );
202
+ } catch (ApiException apiException ) {
203
+ boolean retry = false ;
204
+ if (apiException .getCode () == HTTP_CONFLICT
205
+ && conflictRetry != null
206
+ && retryCount < maxRetryCount ) {
207
+ T body = conflictRetry .getUpdatedObject ();
208
+ if (body != null ) {
209
+ requestParamsBuilder .setBody (body );
210
+ retry = true ;
211
+ LOGGER .fine (
212
+ MessageKeys .SYNC_RETRY ,
213
+ requestParams .call ,
214
+ apiException .getCode (),
215
+ apiException .getMessage (),
216
+ retryCount ,
217
+ maxRetryCount );
218
+ }
219
+ }
220
+ if (!retry ) {
221
+ throw apiException ;
222
+ }
223
+ }
224
+ }
225
+ return null ;
226
+ }
227
+
169
228
private <T > T executeSynchronousCall (
170
229
RequestParams requestParams , SynchronousCallFactory <T > factory ) throws ApiException {
171
230
return DISPATCHER .execute (factory , requestParams , helper );
@@ -317,34 +376,16 @@ public Step readDomainAsync(String name, String namespace, ResponseStep<Domain>
317
376
public Domain replaceDomainWithConflictRetry (
318
377
String uid , String namespace , Domain body , ConflictRetry <Domain > conflictRetry )
319
378
throws ApiException {
320
- int retryCount = 0 ;
321
- while (retryCount == 0 || retryCount < maxRetryCount ) {
322
- retryCount ++;
323
- try {
324
- return replaceDomain (uid , namespace , body );
325
- } catch (ApiException apiException ) {
326
- boolean retry = false ;
327
- if (apiException .getCode () == HTTP_CONFLICT
328
- && conflictRetry != null
329
- && retryCount < maxRetryCount ) {
330
- body = conflictRetry .getUpdatedObject ();
331
- if (body != null ) {
332
- retry = true ;
333
- LOGGER .fine (
334
- MessageKeys .SYNC_RETRY ,
335
- "replaceDomain" ,
336
- apiException .getCode (),
337
- apiException .getMessage (),
338
- retryCount ,
339
- maxRetryCount );
379
+ return executeSynchronousCallWithConflictRetry (
380
+ new RequestParamsBuilder <Domain >(body ) {
381
+
382
+ @ Override
383
+ RequestParams buildRequestParams () {
384
+ return new RequestParams ("replaceDomain" , namespace , uid , body );
340
385
}
341
- }
342
- if (!retry ) {
343
- throw apiException ;
344
- }
345
- }
346
- }
347
- return null ;
386
+ },
387
+ REPLACE_DOMAIN_CALL ,
388
+ conflictRetry );
348
389
}
349
390
350
391
/**
0 commit comments