Skip to content

Commit 2b68d11

Browse files
authored
Merge pull request #1079 from oracle/multiclusterwdt
Adding multiple dynamic clusters in a domain
2 parents 0cca90a + 03b7999 commit 2b68d11

File tree

4 files changed

+165
-61
lines changed

4 files changed

+165
-61
lines changed

integration-tests/src/test/java/oracle/kubernetes/operator/ITMultipleClusters.java

Lines changed: 81 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,12 @@
55

66
import static org.junit.Assert.assertTrue;
77

8-
import java.io.IOException;
9-
import java.nio.charset.StandardCharsets;
108
import java.nio.file.Files;
119
import java.nio.file.Paths;
1210
import java.nio.file.StandardCopyOption;
1311
import java.nio.file.StandardOpenOption;
1412
import java.util.Map;
13+
import java.util.logging.Level;
1514
import oracle.kubernetes.operator.utils.Domain;
1615
import oracle.kubernetes.operator.utils.K8sTestUtils;
1716
import oracle.kubernetes.operator.utils.Operator;
@@ -34,7 +33,7 @@ public class ITMultipleClusters extends BaseTest {
3433
private static final String TWO_CONFIGURED_CLUSTER_SCRIPT =
3534
"create-domain-two-configured-cluster.py";
3635
private static final String TWO_MIXED_CLUSTER_SCRIPT = "create-domain-two-mixed-cluster.py";
37-
private static String template;
36+
private static String customDomainTemplate;
3837
private static final String DOMAINUID = "twoconfigclustdomain";
3938

4039
/**
@@ -48,8 +47,16 @@ public class ITMultipleClusters extends BaseTest {
4847
public static void staticPrepare() throws Exception {
4948
// initialize test properties and create the directories
5049
initialize(APP_PROPS_FILE);
51-
template =
50+
String template =
5251
BaseTest.getProjectRoot() + "/kubernetes/samples/scripts/common/domain-template.yaml";
52+
String add =
53+
" - clusterName: %CLUSTER_NAME%-2\n"
54+
+ " serverStartState: \"RUNNING\"\n"
55+
+ " replicas: %INITIAL_MANAGED_SERVER_REPLICAS%\n";
56+
customDomainTemplate = BaseTest.getResultDir() + "/customDomainTemplate.yaml";
57+
Files.copy(
58+
Paths.get(template), Paths.get(customDomainTemplate), StandardCopyOption.REPLACE_EXISTING);
59+
Files.write(Paths.get(customDomainTemplate), add.getBytes(), StandardOpenOption.APPEND);
5360
}
5461

5562
/**
@@ -89,6 +96,7 @@ public void testCreateDomainTwoConfiguredCluster() throws Exception {
8996
Map<String, Object> domainMap = TestUtils.loadYaml(DOMAINONPV_WLST_YAML);
9097
domainMap.put("domainUID", DOMAINUID);
9198
domainMap.put("clusterType", "CONFIGURED");
99+
domainMap.put("customDomainTemplate", customDomainTemplate);
92100
domainMap.put(
93101
"createDomainPyScript",
94102
"integration-tests/src/test/resources/domain-home-on-pv/"
@@ -98,10 +106,17 @@ public void testCreateDomainTwoConfiguredCluster() throws Exception {
98106
&& ((String) domainMap.get("loadBalancer")).equalsIgnoreCase("VOYAGER"))) {
99107
domainMap.put("voyagerWebPort", new Integer("30366"));
100108
}
101-
addCluster2ToDomainTemplate();
102109
domain = TestUtils.createDomain(domainMap);
103110
domain.verifyDomainCreated();
104-
verifyServersStatus(domain);
111+
String pods[] = {
112+
DOMAINUID + "-" + domain.getAdminServerName(),
113+
DOMAINUID + "-managed-server",
114+
DOMAINUID + "-managed-server1",
115+
DOMAINUID + "-managed-server2",
116+
DOMAINUID + "-new-managed-server1",
117+
DOMAINUID + "-new-managed-server2",
118+
};
119+
verifyServersStatus(domain, pods);
105120
testBasicUseCases(domain);
106121
if (!SMOKETEST) {
107122
domain.testWlsLivenessProbe();
@@ -111,7 +126,6 @@ public void testCreateDomainTwoConfiguredCluster() throws Exception {
111126
if (domain != null && !SMOKETEST && (JENKINS || testCompletedSuccessfully)) {
112127
domain.destroy();
113128
}
114-
restoreDomainTemplate();
115129
}
116130
logger.info("SUCCESS - " + testMethodName);
117131
}
@@ -138,6 +152,7 @@ public void testCreateDomainTwoMixedCluster() throws Exception {
138152
try {
139153
Map<String, Object> domainMap = TestUtils.loadYaml(DOMAINONPV_WLST_YAML);
140154
domainMap.put("domainUID", DOMAINUID);
155+
domainMap.put("customDomainTemplate", customDomainTemplate);
141156
domainMap.put(
142157
"createDomainPyScript",
143158
"integration-tests/src/test/resources/domain-home-on-pv/" + TWO_MIXED_CLUSTER_SCRIPT);
@@ -146,10 +161,18 @@ public void testCreateDomainTwoMixedCluster() throws Exception {
146161
&& ((String) domainMap.get("loadBalancer")).equalsIgnoreCase("VOYAGER"))) {
147162
domainMap.put("voyagerWebPort", new Integer("30377"));
148163
}
149-
addCluster2ToDomainTemplate();
150164
domain = TestUtils.createDomain(domainMap);
151165
domain.verifyDomainCreated();
152-
verifyServersStatus(domain);
166+
String pods[] = {
167+
DOMAINUID + "-" + domain.getAdminServerName(),
168+
DOMAINUID + "-managed-server",
169+
DOMAINUID + "-managed-server1",
170+
DOMAINUID + "-managed-server2",
171+
DOMAINUID + "-new-managed-server1",
172+
DOMAINUID + "-new-managed-server2",
173+
};
174+
verifyServersStatus(domain, pods);
175+
153176
testBasicUseCases(domain);
154177
if (!SMOKETEST) {
155178
domain.testWlsLivenessProbe();
@@ -159,58 +182,73 @@ public void testCreateDomainTwoMixedCluster() throws Exception {
159182
if (domain != null && !SMOKETEST && (JENKINS || testCompletedSuccessfully)) {
160183
domain.destroy();
161184
}
162-
restoreDomainTemplate();
163185
}
164186
logger.info("SUCCESS - " + testMethodName);
165187
}
166188

167189
/**
168-
* Append a second cluster to the domain template
190+
* Create 2 dynamic clusters in a domain using WDT in inimage each having 2 managed servers.
191+
* Verify the managed servers are running and verify the basic use cases.
169192
*
170-
* @throws IOException when append fails
193+
* @throws Exception
171194
*/
172-
private void addCluster2ToDomainTemplate() throws IOException {
173-
String add =
174-
" - clusterName: %CLUSTER_NAME%-2\n"
175-
+ " serverStartState: \"RUNNING\"\n"
176-
+ " replicas: %INITIAL_MANAGED_SERVER_REPLICAS%\n";
177-
logger.info("Making a backup of the domain template file:" + template);
178-
if (!Files.exists(Paths.get(template + ".org"))) {
179-
Files.copy(Paths.get(template), Paths.get(template + ".org"));
195+
@Test
196+
public void testCreateDomainTwoClusterWDTInImage() throws Exception {
197+
String DOMAINUID = "twoclusterdomainwdt";
198+
String testMethodName = new Object() {}.getClass().getEnclosingMethod().getName();
199+
logTestBegin(testMethodName);
200+
logger.info("Creating Operator & waiting for the script to complete execution");
201+
if (operator1 == null) {
202+
operator1 = TestUtils.createOperator(OPERATOR1_YAML);
180203
}
181-
Files.write(Paths.get(template), add.getBytes(), StandardOpenOption.APPEND);
182-
byte[] readAllBytes = Files.readAllBytes(Paths.get(template));
183-
logger.info(new String(readAllBytes, StandardCharsets.UTF_8));
184-
}
185-
186-
/**
187-
* Restore the domain template to original state when test is finished
188-
*
189-
* @throws IOException
190-
*/
191-
private void restoreDomainTemplate() throws IOException {
192-
Files.copy(
193-
Paths.get(template + ".org"), Paths.get(template), StandardCopyOption.REPLACE_EXISTING);
194-
Files.delete(Paths.get(template + ".org"));
204+
Domain domain = null;
205+
boolean testCompletedSuccessfully = false;
206+
try {
207+
Map<String, Object> domainMap = TestUtils.loadYaml(DOMAININIMAGE_WDT_YAML);
208+
domainMap.put("domainUID", DOMAINUID);
209+
domainMap.put("customDomainTemplate", customDomainTemplate);
210+
if ((System.getenv("LB_TYPE") != null && System.getenv("LB_TYPE").equalsIgnoreCase("VOYAGER"))
211+
|| (domainMap.containsKey("loadBalancer")
212+
&& ((String) domainMap.get("loadBalancer")).equalsIgnoreCase("VOYAGER"))) {
213+
domainMap.put("voyagerWebPort", new Integer("30377"));
214+
}
215+
domainMap.put(
216+
"customWdtTemplate",
217+
BaseTest.getProjectRoot()
218+
+ "/integration-tests/src/test/resources/multipleclusters/wdtmultipledynclusters.yml");
219+
domain = TestUtils.createDomain(domainMap);
220+
domain.verifyDomainCreated();
221+
String pods[] = {
222+
DOMAINUID + "-" + domain.getAdminServerName(),
223+
DOMAINUID + "-managed-server1",
224+
DOMAINUID + "-managed-server2",
225+
DOMAINUID + "-managed-server-21",
226+
DOMAINUID + "-managed-server-22",
227+
};
228+
verifyServersStatus(domain, pods);
229+
testBasicUseCases(domain);
230+
if (!SMOKETEST) {
231+
domain.testWlsLivenessProbe();
232+
}
233+
testCompletedSuccessfully = true;
234+
} finally {
235+
if (domain != null && !SMOKETEST && (JENKINS || testCompletedSuccessfully)) {
236+
domain.destroy();
237+
}
238+
}
239+
logger.log(Level.INFO, "SUCCESS - {0}", testMethodName);
195240
}
196241

197242
/**
198243
* Verifies all of the servers in the cluster are in Running status
199244
*
200245
* @param Domain
246+
* @param String array pod names to check the status for
201247
*/
202-
private void verifyServersStatus(Domain domain) {
248+
private void verifyServersStatus(Domain domain, String[] pods) {
203249
K8sTestUtils testUtil = new K8sTestUtils();
204250
String domain1LabelSelector = String.format("weblogic.domainUID in (%s)", DOMAINUID);
205251
String namespace = domain.getDomainNS();
206-
String pods[] = {
207-
DOMAINUID + "-" + domain.getAdminServerName(),
208-
DOMAINUID + "-managed-server",
209-
DOMAINUID + "-managed-server1",
210-
DOMAINUID + "-managed-server2",
211-
DOMAINUID + "-new-managed-server1",
212-
DOMAINUID + "-new-managed-server2",
213-
};
214252
for (String pod : pods) {
215253
assertTrue(
216254
pod + " Pod not running", testUtil.isPodRunning(namespace, domain1LabelSelector, pod));

integration-tests/src/test/java/oracle/kubernetes/operator/ITOperator.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,12 @@ public void testDomainInImageUsingWDT() throws Exception {
482482
Domain domain = null;
483483
boolean testCompletedSuccessfully = false;
484484
try {
485-
domain = TestUtils.createDomain(DOMAININIMAGE_WDT_YAML);
485+
Map<String, Object> domainMap = TestUtils.loadYaml(DOMAININIMAGE_WDT_YAML);
486+
domainMap.put(
487+
"customWdtTemplate",
488+
BaseTest.getProjectRoot()
489+
+ "/integration-tests/src/test/resources/wdt/config.cluster.topology.yaml");
490+
domain = TestUtils.createDomain(domainMap);
486491
domain.verifyDomainCreated();
487492

488493
testBasicUseCases(domain);

integration-tests/src/test/java/oracle/kubernetes/operator/utils/Domain.java

Lines changed: 37 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import java.io.FilenameFilter;
1010
import java.io.IOException;
1111
import java.io.InputStream;
12+
import java.nio.charset.StandardCharsets;
1213
import java.nio.file.Files;
1314
import java.nio.file.Path;
1415
import java.nio.file.Paths;
@@ -21,6 +22,7 @@
2122
import java.util.Map;
2223
import java.util.Objects;
2324
import java.util.StringTokenizer;
25+
import java.util.logging.Level;
2426
import java.util.logging.Logger;
2527
import javax.jms.ConnectionFactory;
2628
import javax.jms.QueueConnection;
@@ -1156,6 +1158,8 @@ protected void callCreateDomainScript(String outputDir) throws Exception {
11561158
gitCloneDockerImagesSample();
11571159
}
11581160

1161+
copyDomainTemplate(domainMap);
1162+
11591163
// copy create domain py script if domain map contains createDomainPyScript
11601164
copyCreateDomainPy();
11611165

@@ -1522,6 +1526,20 @@ protected void initialize(Map<String, Object> inputDomainMap) throws Exception {
15221526
createConfigMapAndSecretForSitConfig();
15231527
}
15241528

1529+
private void copyDomainTemplate(Map<String, Object> inputDomainMap) throws IOException {
1530+
if (inputDomainMap.containsKey("customDomainTemplate")) {
1531+
Files.copy(
1532+
Paths.get((String) inputDomainMap.get("customDomainTemplate")),
1533+
Paths.get(BaseTest.getResultDir() + "/samples/scripts/common/domain-template.yaml"),
1534+
StandardCopyOption.REPLACE_EXISTING);
1535+
}
1536+
logger.log(Level.FINEST, "Domain Template");
1537+
byte[] readAllBytes =
1538+
Files.readAllBytes(
1539+
Paths.get(BaseTest.getResultDir() + "/samples/scripts/common/domain-template.yaml"));
1540+
logger.log(Level.FINEST, new String(readAllBytes, StandardCharsets.UTF_8));
1541+
}
1542+
15251543
private String getNodeHost() throws Exception {
15261544
String cmd =
15271545
"kubectl describe pod "
@@ -1740,23 +1758,25 @@ private void changeClusterTypeInCreateDomainJobTemplate() throws Exception {
17401758

17411759
// change CLUSTER_TYPE to CONFIGURED in create-domain-job-template.yaml for configured cluster
17421760
// as samples only support DYNAMIC cluster
1743-
if (clusterType.equalsIgnoreCase("CONFIGURED")) {
1744-
1745-
// domain in image
1746-
if (domainMap.containsKey("domainHomeImageBase")
1747-
&& domainHomeImageBuildPath.contains("wdt")) {
1748-
TestUtils.copyFile(
1749-
BaseTest.getProjectRoot()
1750-
+ "/integration-tests/src/test/resources/wdt/config.cluster.topology.yaml",
1751-
BaseTest.getResultDir()
1752-
+ "/docker-images/OracleWebLogic/samples/12213-domain-home-in-image-wdt/simple-topology.yaml");
1753-
} else {
1754-
// domain on pv
1755-
StringBuffer createDomainJobTemplateFile = new StringBuffer(BaseTest.getResultDir());
1756-
createDomainJobTemplateFile.append(
1757-
"/samples/scripts/create-weblogic-domain/domain-home-on-pv/create-domain-job-template.yaml");
1758-
TestUtils.exec("sed -i -e 's?DYNAMIC?CONFIGURED?g' " + createDomainJobTemplateFile);
1759-
}
1761+
1762+
// domain in image
1763+
if (domainMap.containsKey("customWdtTemplate")) {
1764+
TestUtils.copyFile(
1765+
(String) domainMap.get("customWdtTemplate"),
1766+
BaseTest.getResultDir()
1767+
+ "/docker-images/OracleWebLogic/samples/12213-domain-home-in-image-wdt/simple-topology.yaml");
1768+
ExecResult exec =
1769+
TestUtils.exec(
1770+
"cat "
1771+
+ BaseTest.getResultDir()
1772+
+ "/docker-images/OracleWebLogic/samples/12213-domain-home-in-image-wdt/simple-topology.yaml");
1773+
logger.log(Level.FINEST, exec.stdout());
1774+
} else if (clusterType.equalsIgnoreCase("CONFIGURED")) {
1775+
// domain on pv
1776+
StringBuffer createDomainJobTemplateFile = new StringBuffer(BaseTest.getResultDir());
1777+
createDomainJobTemplateFile.append(
1778+
"/samples/scripts/create-weblogic-domain/domain-home-on-pv/create-domain-job-template.yaml");
1779+
TestUtils.exec("sed -i -e 's?DYNAMIC?CONFIGURED?g' " + createDomainJobTemplateFile);
17601780
}
17611781
}
17621782

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
domainInfo:
2+
AdminUserName: '@@FILE:/u01/oracle/properties/adminuser.properties@@'
3+
AdminPassword: '@@FILE:/u01/oracle/properties/adminpass.properties@@'
4+
topology:
5+
Name: '@@PROP:DOMAIN_NAME@@'
6+
AdminServerName: '@@PROP:ADMIN_NAME@@'
7+
ProductionModeEnabled: '@@PROP:PRODUCTION_MODE_ENABLED@@'
8+
Cluster:
9+
'@@PROP:CLUSTER_NAME@@':
10+
DynamicServers:
11+
CalculatedListenPorts: false
12+
DynamicClusterSize: 2
13+
MaxDynamicClusterSize: '@@PROP:CONFIGURED_MANAGED_SERVER_COUNT@@'
14+
ServerNamePrefix: '@@PROP:MANAGED_SERVER_NAME_BASE@@'
15+
ServerTemplate: '@@PROP:CLUSTER_NAME@@-template'
16+
'@@PROP:CLUSTER_NAME@@-2':
17+
DynamicServers:
18+
CalculatedListenPorts: false
19+
DynamicClusterSize: 2
20+
MaxDynamicClusterSize: '@@PROP:CONFIGURED_MANAGED_SERVER_COUNT@@'
21+
ServerNamePrefix: '@@PROP:MANAGED_SERVER_NAME_BASE@@-2'
22+
ServerTemplate: '@@PROP:CLUSTER_NAME@@-2-template'
23+
Server:
24+
'@@PROP:ADMIN_NAME@@':
25+
ListenPort: '@@PROP:ADMIN_PORT@@'
26+
NetworkAccessPoint:
27+
T3Channel:
28+
ListenPort: '@@PROP:T3_CHANNEL_PORT@@'
29+
PublicAddress: '@@PROP:T3_PUBLIC_ADDRESS@@'
30+
PublicPort: '@@PROP:T3_CHANNEL_PORT@@'
31+
ServerTemplate:
32+
'@@PROP:CLUSTER_NAME@@-template':
33+
Cluster: '@@PROP:CLUSTER_NAME@@'
34+
ListenPort: '@@PROP:MANAGED_SERVER_PORT@@'
35+
JTAMigratableTarget:
36+
Cluster: '@@PROP:CLUSTER_NAME@@'
37+
'@@PROP:CLUSTER_NAME@@-2-template':
38+
Cluster: '@@PROP:CLUSTER_NAME@@-2'
39+
ListenPort: '@@PROP:MANAGED_SERVER_PORT@@'
40+
JTAMigratableTarget:
41+
Cluster: '@@PROP:CLUSTER_NAME@@-2'

0 commit comments

Comments
 (0)