|
| 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.Collections; |
| 8 | +import java.util.List; |
| 9 | +import java.util.concurrent.Callable; |
| 10 | + |
| 11 | +import oracle.weblogic.kubernetes.annotations.IntegrationTest; |
| 12 | +import oracle.weblogic.kubernetes.annotations.Namespaces; |
| 13 | +import oracle.weblogic.kubernetes.logging.LoggingFacade; |
| 14 | +import org.junit.jupiter.api.BeforeAll; |
| 15 | +import org.junit.jupiter.api.DisplayName; |
| 16 | +import org.junit.jupiter.api.Test; |
| 17 | + |
| 18 | +import static oracle.weblogic.kubernetes.TestConstants.ADMIN_SERVER_NAME_BASE; |
| 19 | +import static oracle.weblogic.kubernetes.TestConstants.MANAGED_SERVER_NAME_BASE; |
| 20 | +import static oracle.weblogic.kubernetes.TestConstants.MII_BASIC_APP_NAME; |
| 21 | +import static oracle.weblogic.kubernetes.TestConstants.WDT_BASIC_MODEL_PROPERTIES_FILE; |
| 22 | +import static oracle.weblogic.kubernetes.TestConstants.WEBLOGIC_IMAGE_NAME; |
| 23 | +import static oracle.weblogic.kubernetes.TestConstants.WEBLOGIC_IMAGE_TAG; |
| 24 | +import static oracle.weblogic.kubernetes.TestConstants.WLS_DOMAIN_TYPE; |
| 25 | +import static oracle.weblogic.kubernetes.actions.ActionConstants.MODEL_DIR; |
| 26 | +import static oracle.weblogic.kubernetes.utils.CommonMiiTestUtils.createMiiDomainAndVerify; |
| 27 | +import static oracle.weblogic.kubernetes.utils.CommonTestUtils.testUntil; |
| 28 | +import static oracle.weblogic.kubernetes.utils.DomainUtils.shutdownDomainAndVerify; |
| 29 | +import static oracle.weblogic.kubernetes.utils.FileUtils.doesFileExistInPod; |
| 30 | +import static oracle.weblogic.kubernetes.utils.ImageUtils.createImageAndVerify; |
| 31 | +import static oracle.weblogic.kubernetes.utils.ImageUtils.dockerLoginAndPushImageToRegistry; |
| 32 | +import static oracle.weblogic.kubernetes.utils.OperatorUtils.installAndVerifyOperator; |
| 33 | +import static oracle.weblogic.kubernetes.utils.ThreadSafeLogger.getLogger; |
| 34 | +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; |
| 35 | +import static org.junit.jupiter.api.Assertions.assertFalse; |
| 36 | +import static org.junit.jupiter.api.Assertions.assertNotNull; |
| 37 | + |
| 38 | +/** |
| 39 | + * Verify dataHome override with different dataHome setting in the domain spec. |
| 40 | + */ |
| 41 | +@DisplayName("Verify dataHome override with different dataHome setting in the domain spec") |
| 42 | +@IntegrationTest |
| 43 | +class ItDataHomeOverride { |
| 44 | + |
| 45 | + // domain constants |
| 46 | + private static final int replicaCount = 2; |
| 47 | + private static final String WLDF_OPENSESSION_APP = "opensessionapp"; |
| 48 | + private static final String DATA_HOME_OVERRIDE = "/u01/mydata"; |
| 49 | + private static final String miiImageName = "datahome-mii-image"; |
| 50 | + private static final String wdtModelFileForMiiDomain = "wdt-singlecluster-multiapps-usingprop-wls.yaml"; |
| 51 | + |
| 52 | + private static LoggingFacade logger = null; |
| 53 | + private static String miiDomainNamespace = null; |
| 54 | + private static String miiImage = null; |
| 55 | + |
| 56 | + /** |
| 57 | + * Install operator. |
| 58 | + * |
| 59 | + * @param namespaces list of namespaces created by the IntegrationTestWatcher by the |
| 60 | + * JUnit engine parameter resolution mechanism |
| 61 | + */ |
| 62 | + @BeforeAll |
| 63 | + public static void initAll(@Namespaces(2) List<String> namespaces) { |
| 64 | + logger = getLogger(); |
| 65 | + |
| 66 | + // get a unique operator namespace |
| 67 | + logger.info("Get a unique namespace for operator"); |
| 68 | + assertNotNull(namespaces.get(0), "Namespace list is null"); |
| 69 | + String opNamespace = namespaces.get(0); |
| 70 | + |
| 71 | + // get unique namespaces for three different type of domains |
| 72 | + logger.info("Getting unique namespaces for three different type of domains"); |
| 73 | + assertNotNull(namespaces.get(1)); |
| 74 | + miiDomainNamespace = namespaces.get(1); |
| 75 | + |
| 76 | + // create mii image |
| 77 | + miiImage = createAndPushMiiImage(); |
| 78 | + |
| 79 | + // set the service account name for the operator |
| 80 | + String opServiceAccount = opNamespace + "-sa"; |
| 81 | + |
| 82 | + // install and verify operator with REST API |
| 83 | + installAndVerifyOperator(opNamespace, opServiceAccount, false, 0, miiDomainNamespace); |
| 84 | + } |
| 85 | + |
| 86 | + /** |
| 87 | + * Verify dataHome override in a domain when dataHome set in the domain spec. |
| 88 | + * In this domain, set dataHome to /u01/mydata in domain custom resource |
| 89 | + * The domain contains JMS and File Store configuration |
| 90 | + * File store directory is set to /u01/oracle/customFileStore in the model file which should be overridden by dataHome |
| 91 | + * File store and JMS server are targeted to the WebLogic cluster cluster-1 |
| 92 | + * see resource/wdt-models/wdt-singlecluster-multiapps-usingprop-wls.yaml |
| 93 | + */ |
| 94 | + @Test |
| 95 | + @DisplayName("Test dataHome override in a domain with dataHome is set in the domain spec") |
| 96 | + void testDataHomeOverrideWithDataHomeInSpec() { |
| 97 | + |
| 98 | + // create domain in image domain |
| 99 | + String domainUid = "overridedatahome-domain"; |
| 100 | + String adminServerPodName = domainUid + "-" + ADMIN_SERVER_NAME_BASE; |
| 101 | + String managedServerPrefix = domainUid + "-" + MANAGED_SERVER_NAME_BASE; |
| 102 | + createMiiDomainAndVerify(miiDomainNamespace, domainUid, miiImage, adminServerPodName, managedServerPrefix, |
| 103 | + replicaCount, true, DATA_HOME_OVERRIDE); |
| 104 | + |
| 105 | + // check in admin server pod, there is no data file for JMS server created |
| 106 | + String dataFileToCheck = DATA_HOME_OVERRIDE + "/" + domainUid + "/FILESTORE-0000000.DAT"; |
| 107 | + assertFalse(assertDoesNotThrow( |
| 108 | + () -> doesFileExistInPod(miiDomainNamespace, adminServerPodName, dataFileToCheck), |
| 109 | + String.format("exception thrown when checking file %s exists in pod %s in namespace %s", |
| 110 | + dataFileToCheck, adminServerPodName, miiDomainNamespace)), |
| 111 | + String.format("%s exists in pod %s in namespace %s, expects not exist", |
| 112 | + dataFileToCheck, adminServerPodName, miiDomainNamespace)); |
| 113 | + |
| 114 | + // check in admin server pod, the default admin server data file moved to DATA_HOME_OVERRIDE |
| 115 | + String defaultAdminDataFile = DATA_HOME_OVERRIDE + "/" + domainUid + "/_WLS_ADMIN-SERVER000000.DAT"; |
| 116 | + waitForFileExistsInPod(miiDomainNamespace, adminServerPodName, defaultAdminDataFile); |
| 117 | + |
| 118 | + // check in managed server pod, the custom data file for JMS and default managed server datafile are created |
| 119 | + // in DATA_HOME_OVERRIDE |
| 120 | + for (int i = 1; i <= replicaCount; i++) { |
| 121 | + String managedServerPodName = domainUid + "-" + MANAGED_SERVER_NAME_BASE + i; |
| 122 | + String customDataFile = |
| 123 | + DATA_HOME_OVERRIDE + "/" + domainUid + "/FILESTORE-0@MANAGED-SERVER" + i + "000000.DAT"; |
| 124 | + waitForFileExistsInPod(miiDomainNamespace, managedServerPodName, customDataFile); |
| 125 | + |
| 126 | + String defaultMSDataFile = DATA_HOME_OVERRIDE + "/" + domainUid + "/_WLS_MANAGED-SERVER" + i + "000000.DAT"; |
| 127 | + waitForFileExistsInPod(miiDomainNamespace, managedServerPodName, defaultMSDataFile); |
| 128 | + } |
| 129 | + |
| 130 | + // shutdown domain and verify the domain is shutdown |
| 131 | + shutdownDomainAndVerify(miiDomainNamespace, domainUid, replicaCount); |
| 132 | + } |
| 133 | + |
| 134 | + /** |
| 135 | + * Verify dataHome override in a domain with model in image type. |
| 136 | + * In this domain, dataHome is not specified in the domain custom resource |
| 137 | + * The domain contains JMS and File Store configuration |
| 138 | + * File store directory is set to /u01/oracle/customFileStore in the model file which should not be overridden |
| 139 | + * by dataHome |
| 140 | + * File store and JMS server are targeted to the WebLogic cluster cluster-1 |
| 141 | + * see resource/wdt-models/wdt-singlecluster-multiapps-usingprop-wls.yaml |
| 142 | + */ |
| 143 | + @Test |
| 144 | + @DisplayName("Test dataHome override in a domain with model in image type") |
| 145 | + void testDataHomeOverrideNoDataHomeInSpec() { |
| 146 | + |
| 147 | + String domainUid = "nodatahome-domain"; |
| 148 | + String adminServerPodName = domainUid + "-" + ADMIN_SERVER_NAME_BASE; |
| 149 | + String managedServerPrefix = domainUid + "-" + MANAGED_SERVER_NAME_BASE; |
| 150 | + createMiiDomainAndVerify(miiDomainNamespace, domainUid, miiImage, adminServerPodName, managedServerPrefix, |
| 151 | + replicaCount, false, null); |
| 152 | + |
| 153 | + // check in admin server pod, there is no data file for JMS server created in /u01/oracle/customFileStore |
| 154 | + String dataFileToCheck = "/u01/oracle/customFileStore/FILESTORE-0000000.DAT"; |
| 155 | + assertFalse(assertDoesNotThrow( |
| 156 | + () -> doesFileExistInPod(miiDomainNamespace, adminServerPodName, dataFileToCheck), |
| 157 | + String.format("exception thrown when checking file %s exists in pod %s in namespace %s", |
| 158 | + dataFileToCheck, adminServerPodName, miiDomainNamespace)), |
| 159 | + String.format("%s exists in pod %s in namespace %s, expects not exist", |
| 160 | + dataFileToCheck, adminServerPodName, miiDomainNamespace)); |
| 161 | + |
| 162 | + // check in admin server pod, the default admin server data file is in default data store |
| 163 | + String defaultAdminDataFile = |
| 164 | + "/u01/domains/" + domainUid + "/servers/admin-server/data/store/default/_WLS_ADMIN-SERVER000000.DAT"; |
| 165 | + waitForFileExistsInPod(miiDomainNamespace, adminServerPodName, defaultAdminDataFile); |
| 166 | + |
| 167 | + // check in managed server pod, there is custom data file for JMS is created |
| 168 | + for (int i = 1; i <= replicaCount; i++) { |
| 169 | + String managedServerPodName = managedServerPrefix + i; |
| 170 | + String customDataFile = "/u01/oracle/customFileStore/FILESTORE-0@MANAGED-SERVER" + i + "000000.DAT"; |
| 171 | + waitForFileExistsInPod(miiDomainNamespace, managedServerPodName, customDataFile); |
| 172 | + |
| 173 | + String defaultMSDataFile = "/u01/domains/" + domainUid + "/servers/managed-server" + i |
| 174 | + + "/data/store/default/_WLS_MANAGED-SERVER" + i + "000000.DAT"; |
| 175 | + waitForFileExistsInPod(miiDomainNamespace, managedServerPodName, defaultMSDataFile); |
| 176 | + } |
| 177 | + |
| 178 | + // shutdown domain and verify the domain is shutdown |
| 179 | + shutdownDomainAndVerify(miiDomainNamespace, domainUid, replicaCount); |
| 180 | + } |
| 181 | + |
| 182 | + /** |
| 183 | + * Verify dataHome override in a domain with dataHome is set to empty string. |
| 184 | + * In this domain, dataHome is set to empty string in the domain custom resource |
| 185 | + * The domain contains JMS and File Store configuration |
| 186 | + * File store directory is set to /u01/oracle/customFileStore in the model file which should not be overridden |
| 187 | + * by dataHome |
| 188 | + * File store and JMS server are targeted to the WebLogic cluster cluster-1 |
| 189 | + */ |
| 190 | + @Test |
| 191 | + @DisplayName("Test dataHome override in a domain with dataHome is a empty string in the domain spec") |
| 192 | + void testDataHomeOverrideDataHomeEmpty() { |
| 193 | + |
| 194 | + String domainUid = "emptydatahome-domain"; |
| 195 | + String adminServerPodName = domainUid + "-" + ADMIN_SERVER_NAME_BASE; |
| 196 | + String managedServerPrefix = domainUid + "-" + MANAGED_SERVER_NAME_BASE; |
| 197 | + createMiiDomainAndVerify(miiDomainNamespace, domainUid, miiImage, adminServerPodName, managedServerPrefix, |
| 198 | + replicaCount, true, ""); |
| 199 | + |
| 200 | + // check in admin server pod, there is no data file for JMS server created in /u01/oracle/customFileStore |
| 201 | + String dataFileToCheck = "/u01/oracle/customFileStore/FILESTORE-0000000.DAT"; |
| 202 | + assertFalse(assertDoesNotThrow( |
| 203 | + () -> doesFileExistInPod(miiDomainNamespace, adminServerPodName, dataFileToCheck), |
| 204 | + String.format("exception thrown when checking file %s exists in pod %s in namespace %s", |
| 205 | + dataFileToCheck, adminServerPodName, miiDomainNamespace)), |
| 206 | + String.format("%s exists in pod %s in namespace %s, expects not exist", |
| 207 | + dataFileToCheck, adminServerPodName, miiDomainNamespace)); |
| 208 | + |
| 209 | + // check in admin server pod, the default admin server data file is in default data store |
| 210 | + String defaultAdminDataFile = |
| 211 | + "/u01/domains/" + domainUid + "/servers/admin-server/data/store/default/_WLS_ADMIN-SERVER000000.DAT"; |
| 212 | + waitForFileExistsInPod(miiDomainNamespace, adminServerPodName, defaultAdminDataFile); |
| 213 | + |
| 214 | + // check in managed server pod, there is custom data file for JMS is created |
| 215 | + for (int i = 1; i <= replicaCount; i++) { |
| 216 | + String managedServerPodName = domainUid + "-" + MANAGED_SERVER_NAME_BASE + i; |
| 217 | + String customDataFile = "/u01/oracle/customFileStore/FILESTORE-0@MANAGED-SERVER" + i + "000000.DAT"; |
| 218 | + waitForFileExistsInPod(miiDomainNamespace, managedServerPodName, customDataFile); |
| 219 | + |
| 220 | + String defaultMSDataFile = "/u01/domains/" + domainUid + "/servers/managed-server" + i |
| 221 | + + "/data/store/default/_WLS_MANAGED-SERVER" + i + "000000.DAT"; |
| 222 | + waitForFileExistsInPod(miiDomainNamespace, managedServerPodName, defaultMSDataFile); |
| 223 | + } |
| 224 | + |
| 225 | + // shutdown domain and verify the domain is shutdown |
| 226 | + shutdownDomainAndVerify(miiDomainNamespace, domainUid, replicaCount); |
| 227 | + } |
| 228 | + |
| 229 | + /** |
| 230 | + * Check whether a file exists in a pod in the given namespace. |
| 231 | + * |
| 232 | + * @param namespace the Kubernetes namespace that the pod is in |
| 233 | + * @param podName the name of the Kubernetes pod in which the command is expected to run |
| 234 | + * @param fileName the filename to check |
| 235 | + * @return true if the file exists, otherwise return false |
| 236 | + */ |
| 237 | + private Callable<Boolean> fileExistsInPod(String namespace, String podName, String fileName) { |
| 238 | + return () -> doesFileExistInPod(namespace, podName, fileName); |
| 239 | + } |
| 240 | + |
| 241 | + /** |
| 242 | + * Wait for file existing in the pod in the given namespace up to 1 minute. |
| 243 | + * @param namespace the Kubernetes namespace that the pod is in |
| 244 | + * @param podName the name of the Kubernetes pod in which the command is expected to run |
| 245 | + * @param fileName the filename to check |
| 246 | + */ |
| 247 | + private void waitForFileExistsInPod(String namespace, String podName, String fileName) { |
| 248 | + |
| 249 | + logger.info("Wait for file {0} existing in pod {1} in namespace {2}", fileName, podName, namespace); |
| 250 | + testUntil( |
| 251 | + assertDoesNotThrow(() -> fileExistsInPod(namespace, podName, fileName)), |
| 252 | + logger, |
| 253 | + "file {0} exists in pod {1} in namespace {2}", |
| 254 | + fileName, |
| 255 | + podName, |
| 256 | + namespace); |
| 257 | + } |
| 258 | + |
| 259 | + /** |
| 260 | + * Create mii image and push it to the registry. |
| 261 | + * |
| 262 | + * @return mii image created |
| 263 | + */ |
| 264 | + private static String createAndPushMiiImage() { |
| 265 | + // create image with model files |
| 266 | + logger.info("Creating image with model file {0} and verify", wdtModelFileForMiiDomain); |
| 267 | + List<String> appSrcDirList = new ArrayList<>(); |
| 268 | + appSrcDirList.add(MII_BASIC_APP_NAME); |
| 269 | + appSrcDirList.add(WLDF_OPENSESSION_APP); |
| 270 | + |
| 271 | + miiImage = createImageAndVerify( |
| 272 | + miiImageName, Collections.singletonList(MODEL_DIR + "/" + wdtModelFileForMiiDomain), appSrcDirList, |
| 273 | + Collections.singletonList(MODEL_DIR + "/" + WDT_BASIC_MODEL_PROPERTIES_FILE), WEBLOGIC_IMAGE_NAME, |
| 274 | + WEBLOGIC_IMAGE_TAG, WLS_DOMAIN_TYPE, true, null, false); |
| 275 | + |
| 276 | + // docker login and push image to docker registry if necessary |
| 277 | + dockerLoginAndPushImageToRegistry(miiImage); |
| 278 | + |
| 279 | + return miiImage; |
| 280 | + } |
| 281 | + |
| 282 | +} |
0 commit comments