|
| 1 | +// Copyright (c) 2022, Oracle and/or its affiliates. |
| 2 | +// Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. |
| 3 | + |
| 4 | +package oracle.weblogic.kubernetes; |
| 5 | + |
| 6 | +import java.util.ArrayList; |
| 7 | +import java.util.List; |
| 8 | + |
| 9 | +import io.kubernetes.client.custom.V1Patch; |
| 10 | +import oracle.weblogic.kubernetes.annotations.IntegrationTest; |
| 11 | +import oracle.weblogic.kubernetes.annotations.Namespaces; |
| 12 | +import oracle.weblogic.kubernetes.logging.LoggingFacade; |
| 13 | +import org.junit.jupiter.api.BeforeAll; |
| 14 | +import org.junit.jupiter.api.DisplayName; |
| 15 | +import org.junit.jupiter.api.MethodOrderer; |
| 16 | +import org.junit.jupiter.api.Order; |
| 17 | +import org.junit.jupiter.api.Tag; |
| 18 | +import org.junit.jupiter.api.Test; |
| 19 | +import org.junit.jupiter.api.TestMethodOrder; |
| 20 | + |
| 21 | +import static oracle.weblogic.kubernetes.TestConstants.ADMIN_SERVER_NAME_BASE; |
| 22 | +import static oracle.weblogic.kubernetes.TestConstants.MANAGED_SERVER_NAME_BASE; |
| 23 | +import static oracle.weblogic.kubernetes.TestConstants.MII_BASIC_APP_NAME; |
| 24 | +import static oracle.weblogic.kubernetes.actions.TestActions.patchDomainCustomResource; |
| 25 | +import static oracle.weblogic.kubernetes.utils.CommonTestUtils.checkPodReadyAndServiceExists; |
| 26 | +import static oracle.weblogic.kubernetes.utils.CommonTestUtils.getNonEmptySystemProperty; |
| 27 | +import static oracle.weblogic.kubernetes.utils.DomainUtils.createAndVerifyDomainInImageUsingWdt; |
| 28 | +import static oracle.weblogic.kubernetes.utils.DomainUtils.shutdownDomainAndVerify; |
| 29 | +import static oracle.weblogic.kubernetes.utils.OperatorUtils.installAndVerifyOperator; |
| 30 | +import static oracle.weblogic.kubernetes.utils.ThreadSafeLogger.getLogger; |
| 31 | +import static org.junit.jupiter.api.Assertions.assertTrue; |
| 32 | + |
| 33 | +/** |
| 34 | + * Tests related to large capacity DII domain and multiple clusters. |
| 35 | + */ |
| 36 | +@TestMethodOrder(MethodOrderer.OrderAnnotation.class) |
| 37 | +@DisplayName("Verify the Operator can handle multiple DII domains and clusters at the same time.") |
| 38 | +@IntegrationTest |
| 39 | +@Tag("okdenv") |
| 40 | +class ItLargeCapacityDomainsClustersDII { |
| 41 | + |
| 42 | + private static String opNamespace = null; |
| 43 | + private static int numOfDomains = Integer.valueOf(getNonEmptySystemProperty("NUMBER_OF_DOMAINS", "10")); |
| 44 | + private static final String baseDomainUid = "domain"; |
| 45 | + private static List<String> domainNamespaces; |
| 46 | + |
| 47 | + private static final String adminServerName = ADMIN_SERVER_NAME_BASE; |
| 48 | + private static int clusterReplicaCount = 2; |
| 49 | + private static String clusterName = "cluster-1"; |
| 50 | + private static LoggingFacade logger; |
| 51 | + |
| 52 | + static String adminSecretName = "weblogic-credentials"; |
| 53 | + //static String encryptionSecretName = "encryptionsecret"; |
| 54 | + private static final String wdtModelFileForDomainInImage = "wdt-singlecluster-sampleapp-usingprop-wls.yaml"; |
| 55 | + |
| 56 | + /** |
| 57 | + * Assigns unique namespaces for operator and domains. Installs operator. |
| 58 | + * |
| 59 | + * @param namespaces injected by JUnit |
| 60 | + */ |
| 61 | + @BeforeAll |
| 62 | + public static void initAll(@Namespaces(50) List<String> namespaces) { |
| 63 | + logger = getLogger(); |
| 64 | + logger.info("Assign a unique namespace for operator"); |
| 65 | + opNamespace = namespaces.get(0); |
| 66 | + logger.info("Assign a unique namespaces for WebLogic domains"); |
| 67 | + domainNamespaces = namespaces.subList(1, numOfDomains + 1); |
| 68 | + |
| 69 | + // install operator and verify its running in ready state |
| 70 | + installAndVerifyOperator(opNamespace, namespaces.subList(1, 50).toArray(new String[0])); |
| 71 | + } |
| 72 | + |
| 73 | + /** |
| 74 | + * Test brings up new DII domains and verifies it can successfully start by doing the following. |
| 75 | + * |
| 76 | + * a. Creates domain resource and deploys in Kubernetes cluster. |
| 77 | + * b. Verifies the servers in the new WebLogic domain comes up. |
| 78 | + */ |
| 79 | + @Order(1) |
| 80 | + @Test |
| 81 | + @DisplayName("Test DII domains creation") |
| 82 | + void testCreateDomains() { |
| 83 | + String domainUid; |
| 84 | + for (int i = 0; i < numOfDomains; i++) { |
| 85 | + domainUid = baseDomainUid + (i + 1); |
| 86 | + List<String> appSrcDirList = new ArrayList<>(); |
| 87 | + appSrcDirList.add(MII_BASIC_APP_NAME); |
| 88 | + createAndVerifyDomainInImageUsingWdt(domainUid, domainNamespaces.get(i), |
| 89 | + wdtModelFileForDomainInImage, appSrcDirList, adminSecretName, clusterName, clusterReplicaCount); |
| 90 | + } |
| 91 | + } |
| 92 | + |
| 93 | + /** |
| 94 | + * Test restart all existing DII domains. |
| 95 | + * |
| 96 | + * a. Shutdowns all domains using serverStartPolicy NEVER. |
| 97 | + * b. Patch the Domain Resource with cluster serverStartPolicy IF_NEEDED. |
| 98 | + * c. Verifies the servers in the domain cluster comes up. |
| 99 | + */ |
| 100 | + @Order(2) |
| 101 | + @Test |
| 102 | + @DisplayName("Test DII domain shutdown and startup") |
| 103 | + void testRestartDomains() { |
| 104 | + String domainUid; |
| 105 | + for (int i = 0; i < numOfDomains; i++) { |
| 106 | + domainUid = baseDomainUid + (i + 1); |
| 107 | + shutdownDomainAndVerify(domainNamespaces.get(i), domainUid, clusterReplicaCount); |
| 108 | + logger.info("patch the domain resource with serverStartPolicy to IF_NEEDED"); |
| 109 | + String patchStr |
| 110 | + = "[{" |
| 111 | + + "\"op\": \"replace\", \"path\": \"/spec/serverStartPolicy\", \"value\": \"IF_NEEDED\"" |
| 112 | + + "}]"; |
| 113 | + logger.info("Updating domain configuration using patch string: {0}\n", patchStr); |
| 114 | + V1Patch patch = new V1Patch(patchStr); |
| 115 | + assertTrue(patchDomainCustomResource(domainUid, domainNamespaces.get(i), patch, V1Patch.PATCH_FORMAT_JSON_PATCH), |
| 116 | + "Failed to patch domain"); |
| 117 | + // check that admin service/pod exists in the domain namespace |
| 118 | + logger.info("Checking that admin service/pod {0} exists in namespace {1}", |
| 119 | + domainUid + "-" + ADMIN_SERVER_NAME_BASE, domainNamespaces.get(i)); |
| 120 | + checkPodReadyAndServiceExists(domainUid + "-" + ADMIN_SERVER_NAME_BASE, domainUid, domainNamespaces.get(i)); |
| 121 | + |
| 122 | + for (int j = 1; j <= clusterReplicaCount; j++) { |
| 123 | + String managedServerPodName = domainUid + "-" + MANAGED_SERVER_NAME_BASE + j; |
| 124 | + // check that ms service/pod exists in the domain namespace |
| 125 | + logger.info("Checking that clustered ms service/pod {0} exists in namespace {1}", |
| 126 | + managedServerPodName, domainNamespaces.get(i)); |
| 127 | + checkPodReadyAndServiceExists(managedServerPodName, domainUid, domainNamespaces.get(i)); |
| 128 | + } |
| 129 | + } |
| 130 | + |
| 131 | + } |
| 132 | +} |
0 commit comments