2020import java .util .Map ;
2121import java .util .Optional ;
2222import java .util .concurrent .Callable ;
23+ import java .util .concurrent .atomic .AtomicBoolean ;
24+ import java .util .concurrent .atomic .AtomicInteger ;
2325
2426import com .google .gson .Gson ;
2527import com .google .gson .JsonElement ;
9193import static java .util .concurrent .TimeUnit .MINUTES ;
9294import static java .util .concurrent .TimeUnit .SECONDS ;
9395import static oracle .weblogic .kubernetes .TestConstants .DOMAIN_VERSION ;
96+ import static oracle .weblogic .kubernetes .utils .CommonTestUtils .testUntil ;
9497import static oracle .weblogic .kubernetes .utils .ThreadSafeLogger .getLogger ;
9598import static org .awaitility .Awaitility .with ;
9699import static org .junit .jupiter .api .Assertions .assertDoesNotThrow ;
@@ -290,7 +293,6 @@ private static void initializeGenericKubernetesApiClients() {
290293 );
291294 deleteOptions = new DeleteOptions ();
292295 deleteOptions .setGracePeriodSeconds (0L );
293- deleteOptions .setPropagationPolicy (FOREGROUND );
294296 }
295297
296298 // ------------------------ deployments -----------------------------------
@@ -1358,23 +1360,37 @@ public static boolean patchCustomResourceDomainJsonMergePatch(String domainUid,
13581360 */
13591361 public static boolean patchDomainCustomResource (String domainUid , String namespace ,
13601362 V1Patch patch , String patchFormat ) {
1363+ return patchDomainCustomResource (domainUid , namespace , patch , patchFormat , 0 );
1364+ }
13611365
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." );
13761392
1377- return true ;
1393+ return result . get () ;
13781394 }
13791395
13801396 /**
@@ -2954,4 +2970,4 @@ public InputStream getInputStream() {
29542970 return new ByteArrayInputStream (copy .toByteArray ());
29552971 }
29562972 }
2957- }
2973+ }
0 commit comments