Skip to content

Commit 90d5cef

Browse files
authored
backport : Split Test class ItMultiDomainModelsWithLoadBalancer to main (#3578)
* Split Test class ItMultiDomainModelsWithLoadBalancer
1 parent 302958c commit 90d5cef

File tree

6 files changed

+660
-568
lines changed

6 files changed

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

0 commit comments

Comments
 (0)