20
20
import java .util .Map ;
21
21
import java .util .Optional ;
22
22
import java .util .concurrent .Callable ;
23
+ import java .util .concurrent .atomic .AtomicBoolean ;
24
+ import java .util .concurrent .atomic .AtomicInteger ;
23
25
24
26
import com .google .gson .Gson ;
25
27
import com .google .gson .JsonElement ;
91
93
import static java .util .concurrent .TimeUnit .MINUTES ;
92
94
import static java .util .concurrent .TimeUnit .SECONDS ;
93
95
import static oracle .weblogic .kubernetes .TestConstants .DOMAIN_VERSION ;
96
+ import static oracle .weblogic .kubernetes .utils .CommonTestUtils .testUntil ;
94
97
import static oracle .weblogic .kubernetes .utils .ThreadSafeLogger .getLogger ;
95
98
import static org .awaitility .Awaitility .with ;
96
99
import static org .junit .jupiter .api .Assertions .assertDoesNotThrow ;
@@ -290,7 +293,6 @@ private static void initializeGenericKubernetesApiClients() {
290
293
);
291
294
deleteOptions = new DeleteOptions ();
292
295
deleteOptions .setGracePeriodSeconds (0L );
293
- deleteOptions .setPropagationPolicy (FOREGROUND );
294
296
}
295
297
296
298
// ------------------------ deployments -----------------------------------
@@ -1358,23 +1360,37 @@ public static boolean patchCustomResourceDomainJsonMergePatch(String domainUid,
1358
1360
*/
1359
1361
public static boolean patchDomainCustomResource (String domainUid , String namespace ,
1360
1362
V1Patch patch , String patchFormat ) {
1363
+ return patchDomainCustomResource (domainUid , namespace , patch , patchFormat , 0 );
1364
+ }
1361
1365
1362
- // GenericKubernetesApi uses CustomObjectsApi calls
1363
- KubernetesApiResponse <Domain > response = crdClient .patch (
1364
- namespace , // name of namespace
1365
- domainUid , // name of custom resource domain
1366
- patchFormat , // "application/json-patch+json" or "application/merge-patch+json"
1367
- patch // patch data
1368
- );
1369
-
1370
- if (!response .isSuccess ()) {
1371
- getLogger ().warning (
1372
- "Failed to patch " + domainUid + " in namespace " + namespace + " using patch format: "
1373
- + patchFormat );
1374
- return false ;
1375
- }
1366
+ /**
1367
+ * Patch the Domain Custom Resource.
1368
+ *
1369
+ * @param domainUid unique domain identifier
1370
+ * @param namespace name of namespace
1371
+ * @param patch patch data in format matching the specified media type
1372
+ * @param patchFormat one of the following types used to identify patch document:
1373
+ * "application/json-patch+json", "application/merge-patch+json",
1374
+ * @param maxRetryCount Max retry count.
1375
+ * @return true if successful, false otherwise
1376
+ */
1377
+ public static boolean patchDomainCustomResource (String domainUid , String namespace ,
1378
+ V1Patch patch , String patchFormat , int maxRetryCount ) {
1379
+
1380
+ final AtomicBoolean result = new AtomicBoolean (false );
1381
+ final AtomicInteger retryCount = new AtomicInteger (0 );
1382
+ testUntil (() -> {
1383
+ KubernetesApiResponse <Domain > response = crdClient .patch (
1384
+ namespace , // name of namespace
1385
+ domainUid , // name of custom resource domain
1386
+ patchFormat , // "application/json-patch+json" or "application/merge-patch+json"
1387
+ patch // patch data
1388
+ );
1389
+ result .set (response .isSuccess ());
1390
+ return response .isSuccess () || retryCount .incrementAndGet () > maxRetryCount ;
1391
+ }, getLogger (), "Retrying the domain resource patch operation until successful." );
1376
1392
1377
- return true ;
1393
+ return result . get () ;
1378
1394
}
1379
1395
1380
1396
/**
@@ -2954,4 +2970,4 @@ public InputStream getInputStream() {
2954
2970
return new ByteArrayInputStream (copy .toByteArray ());
2955
2971
}
2956
2972
}
2957
- }
2973
+ }
0 commit comments