Skip to content

Commit c873391

Browse files
hzhao-githubhuizhao
andauthored
Added FMW Integration test with Dynamic Cluster using MII (#2218)
* Added FMW Integration test with Dynamic Cluster using MII * Changes based on comments * Changes based on comments Co-authored-by: huizhao <huizhao@huizhao-1.subnet2ad1phx.devweblogicphx.oraclevcn.com>
1 parent 41c91db commit c873391

File tree

2 files changed

+357
-0
lines changed

2 files changed

+357
-0
lines changed
Lines changed: 311 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,311 @@
1+
// Copyright (c) 2021, 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.Collections;
7+
import java.util.List;
8+
9+
import io.kubernetes.client.openapi.models.V1EnvVar;
10+
import io.kubernetes.client.openapi.models.V1LocalObjectReference;
11+
import io.kubernetes.client.openapi.models.V1ObjectMeta;
12+
import io.kubernetes.client.openapi.models.V1SecretReference;
13+
import oracle.weblogic.domain.AdminServer;
14+
import oracle.weblogic.domain.AdminService;
15+
import oracle.weblogic.domain.Channel;
16+
import oracle.weblogic.domain.Cluster;
17+
import oracle.weblogic.domain.Configuration;
18+
import oracle.weblogic.domain.Domain;
19+
import oracle.weblogic.domain.DomainSpec;
20+
import oracle.weblogic.domain.Model;
21+
import oracle.weblogic.domain.Opss;
22+
import oracle.weblogic.domain.ServerPod;
23+
import oracle.weblogic.kubernetes.annotations.IntegrationTest;
24+
import oracle.weblogic.kubernetes.annotations.Namespaces;
25+
import oracle.weblogic.kubernetes.logging.LoggingFacade;
26+
import org.awaitility.core.ConditionFactory;
27+
import org.junit.jupiter.api.BeforeAll;
28+
import org.junit.jupiter.api.DisplayName;
29+
import org.junit.jupiter.api.Test;
30+
31+
import static java.util.concurrent.TimeUnit.MINUTES;
32+
import static java.util.concurrent.TimeUnit.SECONDS;
33+
import static oracle.weblogic.kubernetes.TestConstants.ADMIN_PASSWORD_DEFAULT;
34+
import static oracle.weblogic.kubernetes.TestConstants.ADMIN_USERNAME_DEFAULT;
35+
import static oracle.weblogic.kubernetes.TestConstants.DB_IMAGE_TO_USE_IN_SPEC;
36+
import static oracle.weblogic.kubernetes.TestConstants.DOMAIN_API_VERSION;
37+
import static oracle.weblogic.kubernetes.TestConstants.FMWINFRA_IMAGE_NAME;
38+
import static oracle.weblogic.kubernetes.TestConstants.FMWINFRA_IMAGE_TAG;
39+
import static oracle.weblogic.kubernetes.TestConstants.FMWINFRA_IMAGE_TO_USE_IN_SPEC;
40+
import static oracle.weblogic.kubernetes.TestConstants.K8S_NODEPORT_HOST;
41+
import static oracle.weblogic.kubernetes.TestConstants.MII_BASIC_APP_NAME;
42+
import static oracle.weblogic.kubernetes.TestConstants.OCIR_SECRET_NAME;
43+
import static oracle.weblogic.kubernetes.actions.ActionConstants.MODEL_DIR;
44+
import static oracle.weblogic.kubernetes.actions.TestActions.getServiceNodePort;
45+
import static oracle.weblogic.kubernetes.utils.CommonTestUtils.checkPodReadyAndServiceExists;
46+
import static oracle.weblogic.kubernetes.utils.CommonTestUtils.createDomainAndVerify;
47+
import static oracle.weblogic.kubernetes.utils.CommonTestUtils.createMiiImageAndVerify;
48+
import static oracle.weblogic.kubernetes.utils.CommonTestUtils.createOcirRepoSecret;
49+
import static oracle.weblogic.kubernetes.utils.CommonTestUtils.createOpsswalletpasswordSecret;
50+
import static oracle.weblogic.kubernetes.utils.CommonTestUtils.createRcuAccessSecret;
51+
import static oracle.weblogic.kubernetes.utils.CommonTestUtils.createSecretWithUsernamePassword;
52+
import static oracle.weblogic.kubernetes.utils.CommonTestUtils.dockerLoginAndPushImageToRegistry;
53+
import static oracle.weblogic.kubernetes.utils.CommonTestUtils.getExternalServicePodName;
54+
import static oracle.weblogic.kubernetes.utils.CommonTestUtils.installAndVerifyOperator;
55+
import static oracle.weblogic.kubernetes.utils.DbUtils.setupDBandRCUschema;
56+
import static oracle.weblogic.kubernetes.utils.TestUtils.callWebAppAndWaitTillReady;
57+
import static oracle.weblogic.kubernetes.utils.ThreadSafeLogger.getLogger;
58+
import static org.awaitility.Awaitility.with;
59+
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
60+
import static org.junit.jupiter.api.Assertions.assertNotNull;
61+
import static org.junit.jupiter.api.Assertions.assertTrue;
62+
63+
/**
64+
* Test to creat a FMW dynamic domain in model in image.
65+
*/
66+
@DisplayName("Test to Create a FMW Dynamic Domain with Dynamic Cluster using model in image")
67+
@IntegrationTest
68+
public class ItFmwDynamicClusterMiiDomain {
69+
70+
private static String dbNamespace = null;
71+
private static String opNamespace = null;
72+
private static String domainNamespace = null;
73+
private static String jrfMiiImage = null;
74+
75+
private static final String RCUSCHEMAPREFIX = "jrfdomainmii";
76+
private static final String ORACLEDBURLPREFIX = "oracledb.";
77+
private static final String ORACLEDBSUFFIX = ".svc.cluster.local:1521/devpdb.k8s";
78+
private static final String RCUSCHEMAPASSWORD = "Oradoc_db1";
79+
private static final String modelFile = "model-fmw-dynamicdomain.yaml";
80+
81+
private static String dbUrl = null;
82+
private static LoggingFacade logger = null;
83+
84+
private String domainUid = "jrf-dynamicdomain-mii";
85+
private String adminServerPodName = domainUid + "-admin-server";
86+
private String managedServerPrefix = domainUid + "-managed-server";
87+
private String adminSecretName = domainUid + "-weblogic-credentials";
88+
private String encryptionSecretName = domainUid + "-encryptionsecret";
89+
private String rcuaccessSecretName = domainUid + "-rcu-access";
90+
private String opsswalletpassSecretName = domainUid + "-opss-wallet-password-secret";
91+
private int replicaCount = 2;
92+
93+
// create standard, reusable retry/backoff policy
94+
private static final ConditionFactory withStandardRetryPolicy
95+
= with().pollDelay(2, SECONDS)
96+
.and().with().pollInterval(10, SECONDS)
97+
.atMost(5, MINUTES).await();
98+
99+
/**
100+
* Start DB service and create RCU schema.
101+
* Assigns unique namespaces for operator and domains.
102+
* Pull FMW image and Oracle DB image if running tests in Kind cluster.
103+
* Installs operator.
104+
*
105+
* @param namespaces injected by JUnit
106+
*/
107+
@BeforeAll
108+
public static void initAll(@Namespaces(3) List<String> namespaces) {
109+
110+
logger = getLogger();
111+
logger.info("Assign a unique namespace for DB and RCU");
112+
assertNotNull(namespaces.get(0), "Namespace is null");
113+
dbNamespace = namespaces.get(0);
114+
dbUrl = ORACLEDBURLPREFIX + dbNamespace + ORACLEDBSUFFIX;
115+
116+
logger.info("Assign a unique namespace for operator");
117+
assertNotNull(namespaces.get(1), "Namespace is null");
118+
opNamespace = namespaces.get(1);
119+
120+
logger.info("Assign a unique namespace for JRF domain");
121+
assertNotNull(namespaces.get(2), "Namespace is null");
122+
domainNamespace = namespaces.get(2);
123+
124+
logger.info("Start DB and create RCU schema for namespace: {0}, RCU prefix: {1}, "
125+
+ "dbUrl: {2}, dbImage: {3}, fmwImage: {4} ", dbNamespace, RCUSCHEMAPREFIX, dbUrl,
126+
DB_IMAGE_TO_USE_IN_SPEC, FMWINFRA_IMAGE_TO_USE_IN_SPEC);
127+
assertDoesNotThrow(() -> setupDBandRCUschema(DB_IMAGE_TO_USE_IN_SPEC, FMWINFRA_IMAGE_TO_USE_IN_SPEC,
128+
RCUSCHEMAPREFIX, dbNamespace, 0, dbUrl),
129+
String.format("Failed to create RCU schema for prefix %s in the namespace %s with "
130+
+ "dbUrl %s", RCUSCHEMAPREFIX, dbNamespace, dbUrl));
131+
132+
logger.info("DB image: {0}, FMW image {1} used in the test",
133+
DB_IMAGE_TO_USE_IN_SPEC, FMWINFRA_IMAGE_TO_USE_IN_SPEC);
134+
135+
// install operator and verify its running in ready state
136+
installAndVerifyOperator(opNamespace, domainNamespace);
137+
}
138+
139+
/**
140+
* Create FMW Dynamic Domain with Dynamic Cluster using model in image.
141+
* Verify Pod is ready and service exists for both admin server and managed servers.
142+
* Verify EM console is accessible.
143+
*/
144+
@Test
145+
@DisplayName("Create FMW Dynamic Domain with Dynamic Cluster using model in image")
146+
public void testFmwDynamicClusterDomainInModelInImage() {
147+
// create FMW dynamic domain and verify
148+
createFmwDomainAndVerify();
149+
verifyDomainReady();
150+
}
151+
152+
private void createFmwDomainAndVerify() {
153+
// Create the repo secret to pull the image
154+
// this secret is used only for non-kind cluster
155+
createOcirRepoSecret(domainNamespace);
156+
157+
// create secret for admin credentials
158+
logger.info("Create secret for admin credentials");
159+
assertDoesNotThrow(() -> createSecretWithUsernamePassword(
160+
adminSecretName,
161+
domainNamespace,
162+
ADMIN_USERNAME_DEFAULT,
163+
ADMIN_PASSWORD_DEFAULT),
164+
String.format("createSecret failed for %s", adminSecretName));
165+
166+
// create encryption secret
167+
logger.info("Create encryption secret");
168+
assertDoesNotThrow(() -> createSecretWithUsernamePassword(
169+
encryptionSecretName,
170+
domainNamespace,
171+
"weblogicenc",
172+
"weblogicenc"),
173+
String.format("createSecret failed for %s", encryptionSecretName));
174+
175+
// create RCU access secret
176+
logger.info("Creating RCU access secret: {0}, with prefix: {1}, dbUrl: {2}, schemapassword: {3})",
177+
rcuaccessSecretName, RCUSCHEMAPREFIX, RCUSCHEMAPASSWORD, dbUrl);
178+
assertDoesNotThrow(() -> createRcuAccessSecret(
179+
rcuaccessSecretName,
180+
domainNamespace,
181+
RCUSCHEMAPREFIX,
182+
RCUSCHEMAPASSWORD,
183+
dbUrl),
184+
String.format("createSecret failed for %s", rcuaccessSecretName));
185+
186+
logger.info("Create OPSS wallet password secret");
187+
assertDoesNotThrow(() -> createOpsswalletpasswordSecret(
188+
opsswalletpassSecretName,
189+
domainNamespace,
190+
"welcome1"),
191+
String.format("createSecret failed for %s", opsswalletpassSecretName));
192+
193+
logger.info("Create an image with jrf model file");
194+
final List<String> modelList = Collections.singletonList(MODEL_DIR + "/" + modelFile);
195+
jrfMiiImage = createMiiImageAndVerify(
196+
"jrf-mii-image",
197+
modelList,
198+
Collections.singletonList(MII_BASIC_APP_NAME),
199+
FMWINFRA_IMAGE_NAME,
200+
FMWINFRA_IMAGE_TAG,
201+
"JRF",
202+
false);
203+
204+
// push the image to a registry to make it accessible in multi-node cluster
205+
dockerLoginAndPushImageToRegistry(jrfMiiImage);
206+
207+
// create the domain object
208+
createDomainCrAndVerify(domainUid,
209+
domainNamespace,
210+
adminSecretName,
211+
OCIR_SECRET_NAME,
212+
encryptionSecretName,
213+
rcuaccessSecretName,
214+
opsswalletpassSecretName,
215+
replicaCount,
216+
jrfMiiImage);
217+
}
218+
219+
/**
220+
* Construct a domain object with the given parameters that can be used to create a domain resource.
221+
* @param domainUid unique Uid of the domain
222+
* @param domNamespace namespace where the domain exists
223+
* @param adminSecretName name of admin secret
224+
* @param repoSecretName name of repository secret
225+
* @param encryptionSecretName name of encryption secret
226+
* @param rcuAccessSecretName name of RCU access secret
227+
* @param opssWalletPasswordSecretName name of opss wallet password secret
228+
* @param replicaCount count of replicas
229+
* @param miiImage name of model in image
230+
*/
231+
private void createDomainCrAndVerify(
232+
String domainUid, String domNamespace, String adminSecretName,
233+
String repoSecretName, String encryptionSecretName, String rcuAccessSecretName,
234+
String opssWalletPasswordSecretName, int replicaCount, String miiImage) {
235+
// create the domain CR
236+
Domain domain = new Domain()
237+
.apiVersion(DOMAIN_API_VERSION)
238+
.kind("Domain")
239+
.metadata(new V1ObjectMeta()
240+
.name(domainUid)
241+
.namespace(domNamespace))
242+
.spec(new DomainSpec()
243+
.domainUid(domainUid)
244+
.domainHomeSourceType("FromModel")
245+
.image(miiImage)
246+
.imagePullPolicy("IfNotPresent")
247+
.addImagePullSecretsItem(new V1LocalObjectReference()
248+
.name(repoSecretName))
249+
.webLogicCredentialsSecret(new V1SecretReference()
250+
.name(adminSecretName)
251+
.namespace(domNamespace))
252+
.includeServerOutInPodLog(true)
253+
.serverStartPolicy("IF_NEEDED")
254+
.serverPod(new ServerPod()
255+
.addEnvItem(new V1EnvVar()
256+
.name("ALLOW_DYNAMIC_CLUSTER_IN_FMW")
257+
.value("true"))
258+
.addEnvItem(new V1EnvVar()
259+
.name("JAVA_OPTIONS")
260+
.value("-Dweblogic.StdoutDebugEnabled=false"))
261+
.addEnvItem(new V1EnvVar()
262+
.name("USER_MEM_ARGS")
263+
.value("-Djava.security.egd=file:/dev/./urandom ")))
264+
.adminServer(new AdminServer()
265+
.serverStartState("RUNNING")
266+
.adminService(new AdminService()
267+
.addChannelsItem(new Channel()
268+
.channelName("default")
269+
.nodePort(0))))
270+
.addClustersItem(new Cluster()
271+
.clusterName("cluster-1")
272+
.replicas(replicaCount)
273+
.serverStartState("RUNNING"))
274+
.configuration(new Configuration()
275+
.opss(new Opss()
276+
.walletPasswordSecret(opssWalletPasswordSecretName))
277+
.model(new Model()
278+
.domainType("JRF")
279+
.runtimeEncryptionSecret(encryptionSecretName))
280+
.addSecretsItem(rcuAccessSecretName)
281+
.introspectorJobActiveDeadlineSeconds(600L)));
282+
283+
createDomainAndVerify(domain, domainNamespace);
284+
}
285+
286+
/**
287+
* Verify Pod is ready and service exists for both admin server and managed servers.
288+
* Verify EM console is accessible.
289+
*/
290+
private void verifyDomainReady() {
291+
checkPodReadyAndServiceExists(adminServerPodName, domainUid, domainNamespace);
292+
for (int i = 1; i <= replicaCount; i++) {
293+
logger.info("Checking managed server service {0} is created in namespace {1}",
294+
managedServerPrefix + i, domainNamespace);
295+
checkPodReadyAndServiceExists(managedServerPrefix + i, domainUid, domainNamespace);
296+
}
297+
298+
//check access to the em console: http://hostname:port/em
299+
int nodePort = getServiceNodePort(
300+
domainNamespace, getExternalServicePodName(adminServerPodName), "default");
301+
assertTrue(nodePort != -1,
302+
"Could not get the default external service node port");
303+
logger.info("Found the default service nodePort {0}", nodePort);
304+
String curlCmd1 = "curl -s -L --show-error --noproxy '*' "
305+
+ " http://" + K8S_NODEPORT_HOST + ":" + nodePort
306+
+ "/em --write-out %{http_code} -o /dev/null";
307+
logger.info("Executing default nodeport curl command {0}", curlCmd1);
308+
assertTrue(callWebAppAndWaitTillReady(curlCmd1, 5), "Calling web app failed");
309+
logger.info("EM console is accessible thru default service");
310+
}
311+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Copyright (c) 2021, 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+
domainInfo:
5+
AdminUserName: '@@SECRET:__weblogic-credentials__:username@@'
6+
AdminPassword: '@@SECRET:__weblogic-credentials__:password@@'
7+
ServerStartMode: 'prod'
8+
RCUDbInfo:
9+
rcu_prefix: '@@SECRET:@@ENV:DOMAIN_UID@@-rcu-access:rcu_prefix@@'
10+
rcu_schema_password: '@@SECRET:@@ENV:DOMAIN_UID@@-rcu-access:rcu_schema_password@@'
11+
rcu_db_conn_string: '@@SECRET:@@ENV:DOMAIN_UID@@-rcu-access:rcu_db_conn_string@@'
12+
13+
topology:
14+
AdminServerName: "admin-server"
15+
Name: "domain1"
16+
Log:
17+
FileName: domain1.log
18+
NMProperties:
19+
JavaHome: /usr/java/jdk1.8.0_211
20+
LogFile: "/u01/oracle/user_projects/domains/jrf-dynamicdomain-mii/nodemanager/nodemanager.log"
21+
DomainsFile: "/u01/oracle/user_projects/domains/jrf-dynamicdomain-mii/nodemanager/nodemanager.domains"
22+
NodeManagerHome: "/u01/oracle/user_projects/domains/jrf-dynamicdomain-mii/nodemanager"
23+
weblogic.StartScriptName: startWebLogic.sh
24+
Cluster:
25+
"cluster-1":
26+
FrontendHost: "jrf-dynamicdomain-mii-cluster-cluster-1"
27+
DynamicServers:
28+
ServerTemplate: "cluster-1-template"
29+
ServerNamePrefix: "managed-server"
30+
DynamicClusterSize: 5
31+
MaxDynamicClusterSize: 5
32+
CalculatedListenPorts: false
33+
Server:
34+
"admin-server":
35+
ListenPort: 7001
36+
ServerTemplate:
37+
"cluster-1-template":
38+
Cluster: "cluster-1"
39+
ListenPort : 8001
40+
41+
appDeployments:
42+
Application:
43+
myear:
44+
SourcePath: "wlsdeploy/applications/sample-app.ear"
45+
ModuleType: ear
46+
Target: "cluster-1"

0 commit comments

Comments
 (0)