|
| 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 oracle.weblogic.domain.Domain; |
| 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.params.ParameterizedTest; |
| 16 | +import org.junit.jupiter.params.provider.ValueSource; |
| 17 | + |
| 18 | +import static oracle.weblogic.kubernetes.TestConstants.ADMIN_PASSWORD_DEFAULT; |
| 19 | +import static oracle.weblogic.kubernetes.TestConstants.ADMIN_SERVER_NAME_BASE; |
| 20 | +import static oracle.weblogic.kubernetes.TestConstants.ADMIN_USERNAME_DEFAULT; |
| 21 | +import static oracle.weblogic.kubernetes.TestConstants.MANAGED_SERVER_NAME_BASE; |
| 22 | +import static oracle.weblogic.kubernetes.TestConstants.MII_BASIC_APP_NAME; |
| 23 | +import static oracle.weblogic.kubernetes.TestConstants.MII_BASIC_IMAGE_NAME; |
| 24 | +import static oracle.weblogic.kubernetes.TestConstants.MII_BASIC_IMAGE_TAG; |
| 25 | +import static oracle.weblogic.kubernetes.TestConstants.WEBLOGIC_SLIM; |
| 26 | +import static oracle.weblogic.kubernetes.actions.TestActions.getServiceNodePort; |
| 27 | +import static oracle.weblogic.kubernetes.assertions.TestAssertions.adminNodePortAccessible; |
| 28 | +import static oracle.weblogic.kubernetes.utils.CommonMiiTestUtils.createMiiDomainAndVerify; |
| 29 | +import static oracle.weblogic.kubernetes.utils.CommonTestUtils.scaleAndVerifyCluster; |
| 30 | +import static oracle.weblogic.kubernetes.utils.DomainUtils.createAndVerifyDomainInImageUsingWdt; |
| 31 | +import static oracle.weblogic.kubernetes.utils.DomainUtils.createDomainOnPvUsingWdt; |
| 32 | +import static oracle.weblogic.kubernetes.utils.DomainUtils.shutdownDomainAndVerify; |
| 33 | +import static oracle.weblogic.kubernetes.utils.OperatorUtils.installAndVerifyOperator; |
| 34 | +import static oracle.weblogic.kubernetes.utils.PodUtils.getExternalServicePodName; |
| 35 | +import static oracle.weblogic.kubernetes.utils.ThreadSafeLogger.getLogger; |
| 36 | +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; |
| 37 | +import static org.junit.jupiter.api.Assertions.assertNotNull; |
| 38 | +import static org.junit.jupiter.api.Assertions.assertTrue; |
| 39 | +import static org.junit.jupiter.api.Assumptions.assumeFalse; |
| 40 | + |
| 41 | +/** |
| 42 | + * The test class creates WebLogic domains with three models. |
| 43 | + * domain-on-pv ( using WDT ) |
| 44 | + * domain-in-image ( using WDT ) |
| 45 | + * model-in-image |
| 46 | + * Verify the basic lifecycle operations of the WebLogic server pods by scaling the domain. |
| 47 | + * Also verify admin console login using admin node port. |
| 48 | + */ |
| 49 | +@DisplayName("Verify the basic lifecycle operations of the WebLogic server pods by scaling the clusters in the domain" |
| 50 | + + " with different domain types and verify admin console login using admin node port.") |
| 51 | +@IntegrationTest |
| 52 | +class ItMultiDomainModels { |
| 53 | + |
| 54 | + // domain constants |
| 55 | + private static final String clusterName = "cluster-1"; |
| 56 | + private static final int replicaCount = 2; |
| 57 | + private static final String wlSecretName = "weblogic-credentials"; |
| 58 | + private static final String miiDomainUid = "miidomain"; |
| 59 | + private static final String dimDomainUid = "domaininimage"; |
| 60 | + private static final String dpvDomainUid = "domainonpv"; |
| 61 | + private static final String wdtModelFileForDomainInImage = "wdt-singlecluster-sampleapp-usingprop-wls.yaml"; |
| 62 | + |
| 63 | + private static LoggingFacade logger = null; |
| 64 | + private static String miiDomainNamespace = null; |
| 65 | + private static String domainOnPVNamespace = null; |
| 66 | + private static String domainInImageNamespace = null; |
| 67 | + |
| 68 | + /** |
| 69 | + * Install operator. |
| 70 | + * Create three different type of domains: model in image, domain on PV and domain in image. |
| 71 | + * |
| 72 | + * @param namespaces list of namespaces created by the IntegrationTestWatcher by the |
| 73 | + * JUnit engine parameter resolution mechanism |
| 74 | + */ |
| 75 | + @BeforeAll |
| 76 | + public static void initAll(@Namespaces(4) List<String> namespaces) { |
| 77 | + logger = getLogger(); |
| 78 | + |
| 79 | + // get a unique operator namespace |
| 80 | + logger.info("Getting a unique namespace for operator"); |
| 81 | + assertNotNull(namespaces.get(0), "Namespace list is null"); |
| 82 | + String opNamespace = namespaces.get(0); |
| 83 | + |
| 84 | + // get unique namespaces for three different type of domains |
| 85 | + logger.info("Getting unique namespaces for three different type of domains"); |
| 86 | + assertNotNull(namespaces.get(1)); |
| 87 | + miiDomainNamespace = namespaces.get(1); |
| 88 | + assertNotNull(namespaces.get(2)); |
| 89 | + domainOnPVNamespace = namespaces.get(2); |
| 90 | + assertNotNull(namespaces.get(3)); |
| 91 | + domainInImageNamespace = namespaces.get(3); |
| 92 | + |
| 93 | + // set the service account name for the operator |
| 94 | + String opServiceAccount = opNamespace + "-sa"; |
| 95 | + |
| 96 | + // install and verify operator |
| 97 | + installAndVerifyOperator(opNamespace, opServiceAccount, false, 0, |
| 98 | + miiDomainNamespace, domainOnPVNamespace, domainInImageNamespace); |
| 99 | + } |
| 100 | + |
| 101 | + /** |
| 102 | + * Scale the cluster by patching domain resource for three different |
| 103 | + * type of domains i.e. domain-on-pv, domain-in-image and model-in-image |
| 104 | + * Also verify admin console login using admin node port. |
| 105 | + * @param domainType domain type, possible value: modelInImage, domainInImage, domainOnPV |
| 106 | + */ |
| 107 | + @ParameterizedTest |
| 108 | + @DisplayName("scale cluster by patching domain resource with three different type of domains and " |
| 109 | + + "verify admin console login using admin node port.") |
| 110 | + @ValueSource(strings = {"modelInImage", "domainInImage", "domainOnPV"}) |
| 111 | + void testScaleClustersAndAdminConsoleLogin(String domainType) { |
| 112 | + |
| 113 | + assumeFalse(WEBLOGIC_SLIM, "Skipping the Console Test for slim image"); |
| 114 | + Domain domain = createDomainBasedOnDomainType(domainType); |
| 115 | + |
| 116 | + // get the domain properties |
| 117 | + String domainUid = domain.getSpec().getDomainUid(); |
| 118 | + String domainNamespace = domain.getMetadata().getNamespace(); |
| 119 | + |
| 120 | + String managedServerPodNamePrefix = domainUid + "-" + MANAGED_SERVER_NAME_BASE; |
| 121 | + |
| 122 | + int numberOfServers = 3; |
| 123 | + logger.info("Scaling cluster {0} of domain {1} in namespace {2} to {3} servers.", |
| 124 | + clusterName, domainUid, domainNamespace, numberOfServers); |
| 125 | + List<String> managedServersBeforeScale = listManagedServersBeforeScale(replicaCount); |
| 126 | + scaleAndVerifyCluster(clusterName, domainUid, domainNamespace, managedServerPodNamePrefix, |
| 127 | + replicaCount, numberOfServers, null, managedServersBeforeScale); |
| 128 | + |
| 129 | + // then scale cluster back to 2 servers |
| 130 | + logger.info("Scaling cluster {0} of domain {1} in namespace {2} from {3} servers to {4} servers.", |
| 131 | + clusterName, domainUid, domainNamespace, numberOfServers, replicaCount); |
| 132 | + managedServersBeforeScale = listManagedServersBeforeScale(numberOfServers); |
| 133 | + scaleAndVerifyCluster(clusterName, domainUid, domainNamespace, managedServerPodNamePrefix, |
| 134 | + numberOfServers, replicaCount, null, managedServersBeforeScale); |
| 135 | + |
| 136 | + String adminServerPodName = domainUid + "-" + ADMIN_SERVER_NAME_BASE; |
| 137 | + logger.info("Getting node port for default channel"); |
| 138 | + int serviceNodePort = assertDoesNotThrow(() -> getServiceNodePort( |
| 139 | + domainNamespace, getExternalServicePodName(adminServerPodName), "default"), |
| 140 | + "Getting admin server node port failed"); |
| 141 | + |
| 142 | + logger.info("Validating WebLogic admin server access by login to console"); |
| 143 | + boolean loginSuccessful = assertDoesNotThrow(() -> |
| 144 | + adminNodePortAccessible(serviceNodePort, ADMIN_USERNAME_DEFAULT, ADMIN_PASSWORD_DEFAULT), |
| 145 | + "Access to admin server node port failed"); |
| 146 | + assertTrue(loginSuccessful, "Console login validation failed"); |
| 147 | + |
| 148 | + // shutdown domain and verify the domain is shutdown |
| 149 | + shutdownDomainAndVerify(domainNamespace, domainUid, replicaCount); |
| 150 | + } |
| 151 | + |
| 152 | + /** |
| 153 | + * Generate a server list which contains all managed servers in the cluster before scale. |
| 154 | + * |
| 155 | + * @param replicasBeforeScale the replicas of WebLogic cluster before scale |
| 156 | + * @return list of managed servers in the cluster before scale |
| 157 | + */ |
| 158 | + private static List<String> listManagedServersBeforeScale(int replicasBeforeScale) { |
| 159 | + |
| 160 | + List<String> managedServerNames = new ArrayList<>(); |
| 161 | + for (int i = 1; i <= replicasBeforeScale; i++) { |
| 162 | + managedServerNames.add(MANAGED_SERVER_NAME_BASE + i); |
| 163 | + } |
| 164 | + |
| 165 | + return managedServerNames; |
| 166 | + } |
| 167 | + |
| 168 | + /** |
| 169 | + * Assert the specified domain and domain spec, metadata and clusters not null. |
| 170 | + * @param domain oracle.weblogic.domain.Domain object |
| 171 | + */ |
| 172 | + private static void assertDomainNotNull(Domain domain) { |
| 173 | + assertNotNull(domain, "domain is null"); |
| 174 | + assertNotNull(domain.getSpec(), domain + " spec is null"); |
| 175 | + assertNotNull(domain.getMetadata(), domain + " metadata is null"); |
| 176 | + assertNotNull(domain.getSpec().getClusters(), domain.getSpec() + " getClusters() is null"); |
| 177 | + } |
| 178 | + |
| 179 | + private static Domain createDomainBasedOnDomainType(String domainType) { |
| 180 | + Domain domain = null; |
| 181 | + |
| 182 | + if (domainType.equalsIgnoreCase("modelInImage")) { |
| 183 | + domain = createMiiDomainAndVerify(miiDomainNamespace, miiDomainUid, |
| 184 | + MII_BASIC_IMAGE_NAME + ":" + MII_BASIC_IMAGE_TAG, |
| 185 | + miiDomainUid + "-" + ADMIN_SERVER_NAME_BASE, |
| 186 | + miiDomainUid + "-" + MANAGED_SERVER_NAME_BASE, replicaCount); |
| 187 | + } else if (domainType.equalsIgnoreCase("domainInImage")) { |
| 188 | + List<String> appSrcDirList = new ArrayList<>(); |
| 189 | + appSrcDirList.add(MII_BASIC_APP_NAME); |
| 190 | + domain = createAndVerifyDomainInImageUsingWdt(dimDomainUid, domainInImageNamespace, |
| 191 | + wdtModelFileForDomainInImage, appSrcDirList, wlSecretName, clusterName, replicaCount); |
| 192 | + } else { |
| 193 | + domain = createDomainOnPvUsingWdt(dpvDomainUid, domainOnPVNamespace, wlSecretName, |
| 194 | + clusterName, replicaCount, ItMultiDomainModels.class.getSimpleName()); |
| 195 | + } |
| 196 | + |
| 197 | + assertDomainNotNull(domain); |
| 198 | + return domain; |
| 199 | + } |
| 200 | +} |
0 commit comments