|
1 |
| -// Copyright (c) 2021, 2022, Oracle and/or its affiliates. |
| 1 | +// Copyright (c) 2021, 2023, Oracle and/or its affiliates. |
2 | 2 | // Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
|
3 | 3 |
|
4 | 4 | package oracle.weblogic.kubernetes.utils;
|
|
90 | 90 | import static oracle.weblogic.kubernetes.assertions.TestAssertions.domainDoesNotExist;
|
91 | 91 | import static oracle.weblogic.kubernetes.assertions.TestAssertions.domainExists;
|
92 | 92 | import static oracle.weblogic.kubernetes.assertions.TestAssertions.domainStatusReasonMatches;
|
| 93 | +import static oracle.weblogic.kubernetes.assertions.TestAssertions.pvExists; |
| 94 | +import static oracle.weblogic.kubernetes.assertions.TestAssertions.pvcExists; |
93 | 95 | import static oracle.weblogic.kubernetes.utils.CommonTestUtils.checkPodReadyAndServiceExists;
|
94 | 96 | import static oracle.weblogic.kubernetes.utils.CommonTestUtils.getNextFreePort;
|
95 | 97 | import static oracle.weblogic.kubernetes.utils.CommonTestUtils.getUniqueName;
|
| 98 | +import static oracle.weblogic.kubernetes.utils.CommonTestUtils.testUntil; |
96 | 99 | import static oracle.weblogic.kubernetes.utils.CommonTestUtils.withStandardRetryPolicy;
|
97 | 100 | import static oracle.weblogic.kubernetes.utils.ImageUtils.createBaseRepoSecret;
|
98 | 101 | import static oracle.weblogic.kubernetes.utils.ImageUtils.createImageAndVerify;
|
99 | 102 | import static oracle.weblogic.kubernetes.utils.ImageUtils.createTestRepoSecret;
|
100 | 103 | import static oracle.weblogic.kubernetes.utils.ImageUtils.dockerLoginAndPushImageToRegistry;
|
101 | 104 | import static oracle.weblogic.kubernetes.utils.JobUtils.createJobAndWaitUntilComplete;
|
| 105 | +import static oracle.weblogic.kubernetes.utils.PersistentVolumeUtils.createPV; |
| 106 | +import static oracle.weblogic.kubernetes.utils.PersistentVolumeUtils.createPVC; |
102 | 107 | import static oracle.weblogic.kubernetes.utils.PersistentVolumeUtils.createPVPVCAndVerify;
|
103 | 108 | import static oracle.weblogic.kubernetes.utils.PersistentVolumeUtils.createfixPVCOwnerContainer;
|
104 | 109 | import static oracle.weblogic.kubernetes.utils.PodUtils.checkPodDoesNotExist;
|
@@ -166,25 +171,46 @@ public static void createDomainAndVerify(Domain domain,
|
166 | 171 | public static void createDomainAndVerify(String domainUid, Domain domain,
|
167 | 172 | String domainNamespace, String adminServerPodName,
|
168 | 173 | String managedServerPodNamePrefix, int replicaCount) {
|
| 174 | + createDomainAndVerify(domainUid, domain, domainNamespace, adminServerPodName, managedServerPodNamePrefix, |
| 175 | + replicaCount, true); |
| 176 | + } |
| 177 | + |
| 178 | + /** |
| 179 | + * Create a domain in the specified namespace, wait up to five minutes until the domain exists and |
| 180 | + * verify the servers are running. |
| 181 | + * |
| 182 | + * @param domainUid domain |
| 183 | + * @param domain the oracle.weblogic.domain.Domain object to create domain custom resource |
| 184 | + * @param domainNamespace namespace in which the domain will be created |
| 185 | + * @param adminServerPodName admin server pod name |
| 186 | + * @param managedServerPodNamePrefix managed server pod prefix |
| 187 | + * @param replicaCount replica count |
| 188 | + * @param verifyServerPods whether to verify server pods of the domain |
| 189 | + */ |
| 190 | + public static void createDomainAndVerify(String domainUid, Domain domain, |
| 191 | + String domainNamespace, String adminServerPodName, |
| 192 | + String managedServerPodNamePrefix, int replicaCount, |
| 193 | + boolean verifyServerPods) { |
169 | 194 | LoggingFacade logger = getLogger();
|
170 | 195 |
|
171 | 196 | // create domain and verify
|
172 | 197 | createDomainAndVerify(domain, domainNamespace);
|
173 | 198 |
|
174 |
| - // check that admin service/pod exists in the domain namespace |
175 |
| - logger.info("Checking that admin service/pod {0} exists in namespace {1}", |
176 |
| - adminServerPodName, domainNamespace); |
177 |
| - checkPodReadyAndServiceExists(adminServerPodName, domainUid, domainNamespace); |
| 199 | + if (verifyServerPods) { |
| 200 | + // check that admin service/pod exists in the domain namespace |
| 201 | + logger.info("Checking that admin service/pod {0} exists in namespace {1}", |
| 202 | + adminServerPodName, domainNamespace); |
| 203 | + checkPodReadyAndServiceExists(adminServerPodName, domainUid, domainNamespace); |
178 | 204 |
|
179 |
| - for (int i = 1; i <= replicaCount; i++) { |
180 |
| - String managedServerPodName = managedServerPodNamePrefix + i; |
| 205 | + for (int i = 1; i <= replicaCount; i++) { |
| 206 | + String managedServerPodName = managedServerPodNamePrefix + i; |
181 | 207 |
|
182 |
| - // check that ms service/pod exists in the domain namespace |
183 |
| - logger.info("Checking that clustered ms service/pod {0} exists in namespace {1}", |
184 |
| - managedServerPodName, domainNamespace); |
185 |
| - checkPodReadyAndServiceExists(managedServerPodName, domainUid, domainNamespace); |
| 208 | + // check that ms service/pod exists in the domain namespace |
| 209 | + logger.info("Checking that clustered ms service/pod {0} exists in namespace {1}", |
| 210 | + managedServerPodName, domainNamespace); |
| 211 | + checkPodReadyAndServiceExists(managedServerPodName, domainUid, domainNamespace); |
| 212 | + } |
186 | 213 | }
|
187 |
| - |
188 | 214 | }
|
189 | 215 |
|
190 | 216 | /**
|
@@ -328,6 +354,109 @@ public static Domain createDomainOnPvUsingWdt(String domainUid,
|
328 | 354 | return domain;
|
329 | 355 | }
|
330 | 356 |
|
| 357 | + /** |
| 358 | + * Create a domain in PV using WDT. |
| 359 | + * |
| 360 | + * @param domainUid uid of the domain |
| 361 | + * @param domainNamespace namespace in which the domain will be created |
| 362 | + * @param wlSecretName WLS secret name |
| 363 | + * @param clusterName WLS domain cluster name |
| 364 | + * @param replicaCount domain replica count |
| 365 | + * @param testClassName the test class name calling this method |
| 366 | + * @param wdtModelFile WDT model file to create the domain |
| 367 | + * @param verifyServerPods whether to verify the server pods |
| 368 | + * @return oracle.weblogic.domain.Domain objects |
| 369 | + */ |
| 370 | + public static Domain createDomainOnPvUsingWdt(String domainUid, |
| 371 | + String domainNamespace, |
| 372 | + String wlSecretName, |
| 373 | + String clusterName, |
| 374 | + int replicaCount, |
| 375 | + String testClassName, |
| 376 | + String wdtModelFile, |
| 377 | + boolean verifyServerPods) { |
| 378 | + |
| 379 | + int t3ChannelPort = getNextFreePort(); |
| 380 | + |
| 381 | + final String pvName = getUniqueName(domainUid + "-pv-"); // name of the persistent volume |
| 382 | + final String pvcName = getUniqueName(domainUid + "-pvc-"); // name of the persistent volume claim |
| 383 | + |
| 384 | + // create pull secrets for WebLogic image when running in non Kind Kubernetes cluster |
| 385 | + // this secret is used only for non-kind cluster |
| 386 | + createBaseRepoSecret(domainNamespace); |
| 387 | + |
| 388 | + // create WebLogic domain credential secret |
| 389 | + createSecretWithUsernamePassword(wlSecretName, domainNamespace, ADMIN_USERNAME_DEFAULT, ADMIN_PASSWORD_DEFAULT); |
| 390 | + |
| 391 | + // create persistent volume and persistent volume claim for domain |
| 392 | + // these resources should be labeled with domainUid for cleanup after testing |
| 393 | + |
| 394 | + createPV(pvName, domainUid, testClassName); |
| 395 | + createPVC(pvName, pvcName, domainUid, domainNamespace); |
| 396 | + |
| 397 | + String labelSelector = String.format("weblogic.domainUid in (%s)", domainUid); |
| 398 | + LoggingFacade logger = getLogger(); |
| 399 | + // check the persistent volume and persistent volume claim exist |
| 400 | + testUntil( |
| 401 | + assertDoesNotThrow(() -> pvExists(pvName, labelSelector), |
| 402 | + String.format("pvExists failed with ApiException when checking pv %s", pvName)), |
| 403 | + logger, |
| 404 | + "persistent volume {0} exists", |
| 405 | + pvName); |
| 406 | + |
| 407 | + testUntil( |
| 408 | + assertDoesNotThrow(() -> pvcExists(pvcName, domainNamespace), |
| 409 | + String.format("pvcExists failed with ApiException when checking pvc %s in namespace %s", |
| 410 | + pvcName, domainNamespace)), |
| 411 | + logger, |
| 412 | + "persistent volume claim {0} exists in namespace {1}", |
| 413 | + pvcName, |
| 414 | + domainNamespace); |
| 415 | + |
| 416 | + |
| 417 | + // create a temporary WebLogic domain property file as a input for WDT model file |
| 418 | + File domainPropertiesFile = assertDoesNotThrow(() -> createTempFile("domainonpv" + domainUid, "properties"), |
| 419 | + "Failed to create domain properties file"); |
| 420 | + |
| 421 | + Properties p = new Properties(); |
| 422 | + p.setProperty("adminUsername", ADMIN_USERNAME_DEFAULT); |
| 423 | + p.setProperty("adminPassword", ADMIN_PASSWORD_DEFAULT); |
| 424 | + p.setProperty("domainName", domainUid); |
| 425 | + p.setProperty("adminServerName", ADMIN_SERVER_NAME_BASE); |
| 426 | + p.setProperty("productionModeEnabled", "true"); |
| 427 | + p.setProperty("clusterName", clusterName); |
| 428 | + p.setProperty("configuredManagedServerCount", "4"); |
| 429 | + p.setProperty("managedServerNameBase", MANAGED_SERVER_NAME_BASE); |
| 430 | + p.setProperty("t3ChannelPort", Integer.toString(t3ChannelPort)); |
| 431 | + p.setProperty("t3PublicAddress", K8S_NODEPORT_HOST); |
| 432 | + p.setProperty("managedServerPort", "8001"); |
| 433 | + p.setProperty("adminServerSslPort", "7002"); |
| 434 | + assertDoesNotThrow(() -> |
| 435 | + p.store(new FileOutputStream(domainPropertiesFile), "WDT properties file"), |
| 436 | + "Failed to write domain properties file"); |
| 437 | + |
| 438 | + // shell script to download WDT and run the WDT createDomain script |
| 439 | + Path wdtScript = get(RESOURCE_DIR, "bash-scripts", "setup_wdt.sh"); |
| 440 | + |
| 441 | + // create configmap and domain in persistent volume using WDT |
| 442 | + runCreateDomainOnPVJobUsingWdt(wdtScript, get(RESOURCE_DIR, "wdt-models", wdtModelFile), |
| 443 | + domainPropertiesFile.toPath(), |
| 444 | + domainUid, pvName, pvcName, domainNamespace, testClassName); |
| 445 | + |
| 446 | + Domain domain = createDomainResourceForDomainOnPV(domainUid, domainNamespace, wlSecretName, pvName, pvcName, |
| 447 | + clusterName, replicaCount); |
| 448 | + |
| 449 | + // Verify the domain custom resource is created. |
| 450 | + // Also verify the admin server pod and managed server pods are up and running. |
| 451 | + if (verifyServerPods) { |
| 452 | + createDomainAndVerify(domainUid, domain, domainNamespace, domainUid + "-" + ADMIN_SERVER_NAME_BASE, |
| 453 | + domainUid + "-" + MANAGED_SERVER_NAME_BASE, replicaCount); |
| 454 | + } else { |
| 455 | + createDomainAndVerify(domain, domainNamespace); |
| 456 | + } |
| 457 | + return domain; |
| 458 | + } |
| 459 | + |
331 | 460 | /**
|
332 | 461 | * Create domain with domain-on-pv type and verify the domain is created.
|
333 | 462 | * Also verify the admin server pod and managed server pods are up and running.
|
@@ -642,6 +771,57 @@ public static Domain createAndVerifyDomainInImageUsingWdt(String domainUid,
|
642 | 771 | clusterName, replicaCount);
|
643 | 772 | }
|
644 | 773 |
|
| 774 | + /** |
| 775 | + * Create a WebLogic domain in image using WDT. |
| 776 | + * |
| 777 | + * @param domainUid domain uid |
| 778 | + * @param domainNamespace namespace in which the domain to be created |
| 779 | + * @param wdtModelFileForDomainInImage WDT model file used to create domain image |
| 780 | + * @param appSrcDirList list of the app src in WDT model file |
| 781 | + * @param propertyFiles list of property files |
| 782 | + * @param wlSecretName wls admin secret name |
| 783 | + * @param clusterName cluster name |
| 784 | + * @param replicaCount replica count of the cluster |
| 785 | + * @return oracle.weblogic.domain.Domain object |
| 786 | + */ |
| 787 | + public static Domain createDomainInImageUsingWdt(String domainUid, |
| 788 | + String domainNamespace, |
| 789 | + String wdtModelFileForDomainInImage, |
| 790 | + List<String> appSrcDirList, |
| 791 | + List<String> propertyFiles, |
| 792 | + String wlSecretName, |
| 793 | + String clusterName, |
| 794 | + int replicaCount) { |
| 795 | + |
| 796 | + // create secret for admin credentials |
| 797 | + getLogger().info("Create secret for admin credentials"); |
| 798 | + createSecretWithUsernamePassword(wlSecretName, domainNamespace, ADMIN_USERNAME_DEFAULT, ADMIN_PASSWORD_DEFAULT); |
| 799 | + |
| 800 | + // create image with model files |
| 801 | + getLogger().info("Creating image with model file and verify"); |
| 802 | + String domainInImageWithWDTImage = createImageAndVerify("domaininimage-wdtimage", |
| 803 | + Collections.singletonList(MODEL_DIR + "/" + wdtModelFileForDomainInImage), appSrcDirList, |
| 804 | + propertyFiles, |
| 805 | + WEBLOGIC_IMAGE_NAME, WEBLOGIC_IMAGE_TAG, WLS_DOMAIN_TYPE, false, |
| 806 | + domainUid, false); |
| 807 | + |
| 808 | + // repo login and push image to registry if necessary |
| 809 | + dockerLoginAndPushImageToRegistry(domainInImageWithWDTImage); |
| 810 | + |
| 811 | + // Create the repo secret to pull the image |
| 812 | + // this secret is used only for non-kind cluster |
| 813 | + createTestRepoSecret(domainNamespace); |
| 814 | + |
| 815 | + // create the domain custom resource |
| 816 | + Domain domain = createDomainResourceForDomainInImage(domainUid, domainNamespace, domainInImageWithWDTImage, |
| 817 | + wlSecretName, clusterName, replicaCount); |
| 818 | + |
| 819 | + // create domain and verify |
| 820 | + createDomainAndVerify(domain, domainNamespace); |
| 821 | + |
| 822 | + return domain; |
| 823 | + } |
| 824 | + |
645 | 825 | /**
|
646 | 826 | * Create domain resource with domain-in-image type.
|
647 | 827 | *
|
|
0 commit comments