Skip to content

Commit 149e0ae

Browse files
committed
fix for Vanaja's review comments
1 parent 7fa8a23 commit 149e0ae

File tree

1 file changed

+79
-71
lines changed

1 file changed

+79
-71
lines changed
Lines changed: 79 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
// Copyright 2018, 2019 Oracle Corporation and/or its affiliates. All rights reserved.
22
// Licensed under the Universal Permissive License v 1.0 as shown at
33
// http://oss.oracle.com/licenses/upl.
4-
54
package oracle.kubernetes.operator;
65

76
import static org.junit.Assert.assertTrue;
87

8+
import java.io.IOException;
99
import java.nio.charset.StandardCharsets;
1010
import java.nio.file.Files;
1111
import java.nio.file.Paths;
@@ -30,14 +30,12 @@
3030
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
3131
public class ITMultipleClusters extends BaseTest {
3232

33-
private static Operator operator1, operator2;
34-
35-
private static Operator operatorForBackwardCompatibility;
36-
private static Operator operatorForRESTCertChain;
37-
33+
private static Operator operator1;
3834
private static final String TWO_CONFIGURED_CLUSTER_SCRIPT =
3935
"create-domain-two-configured-cluster.py";
4036
private static final String TWO_MIXED_CLUSTER_SCRIPT = "create-domain-two-mixed-cluster.py";
37+
private static String template;
38+
private static final String DOMAINUID = "twoconfigclustdomain";
4139

4240
/**
4341
* This method gets called only once before any of the test methods are executed. It does the
@@ -50,6 +48,8 @@ public class ITMultipleClusters extends BaseTest {
5048
public static void staticPrepare() throws Exception {
5149
// initialize test properties and create the directories
5250
initialize(APP_PROPS_FILE);
51+
template =
52+
BaseTest.getProjectRoot() + "/kubernetes/samples/scripts/common/domain-template.yaml";
5353
}
5454

5555
/**
@@ -74,11 +74,10 @@ public static void staticUnPrepare() throws Exception {
7474
*/
7575
@Test
7676
public void testCreateDomainTwoConfiguredCluster() throws Exception {
77-
String DOMAINUID = "twoconfigclustdomain";
77+
7878
String testMethodName = new Object() {}.getClass().getEnclosingMethod().getName();
7979
logTestBegin(testMethodName);
80-
String template =
81-
BaseTest.getProjectRoot() + "/kubernetes/samples/scripts/common/domain-template.yaml";
80+
8281
logger.info("Creating Operator & waiting for the script to complete execution");
8382
// create operator1
8483
if (operator1 == null) {
@@ -94,45 +93,20 @@ public void testCreateDomainTwoConfiguredCluster() throws Exception {
9493
"createDomainPyScript",
9594
"integration-tests/src/test/resources/domain-home-on-pv/"
9695
+ TWO_CONFIGURED_CLUSTER_SCRIPT);
97-
98-
String add =
99-
" - clusterName: %CLUSTER_NAME%-2\n"
100-
+ " serverStartState: \"RUNNING\"\n"
101-
+ " replicas: %INITIAL_MANAGED_SERVER_REPLICAS%\n";
102-
logger.info("Making a backup of the domain template file:" + template);
103-
if (!Files.exists(Paths.get(template + ".org"))) {
104-
Files.copy(Paths.get(template), Paths.get(template + ".org"));
105-
}
106-
Files.write(Paths.get(template), add.getBytes(), StandardOpenOption.APPEND);
107-
byte[] readAllBytes = Files.readAllBytes(Paths.get(template));
108-
logger.info(new String(readAllBytes, StandardCharsets.UTF_8));
96+
addCluster2ToDomainTemplate();
10997
domain = TestUtils.createDomain(domainMap);
11098
domain.verifyDomainCreated();
111-
K8sTestUtils testUtil = new K8sTestUtils();
112-
String domain1LabelSelector = String.format("weblogic.domainUID in (%s)", DOMAINUID);
113-
String namespace = domain.getDomainNS();
114-
String pods[] = {
115-
DOMAINUID + "-" + domain.getAdminServerName(),
116-
DOMAINUID + "-managed-server",
117-
DOMAINUID + "-managed-server1",
118-
DOMAINUID + "-managed-server2",
119-
DOMAINUID + "-new-managed-server1",
120-
DOMAINUID + "-new-managed-server2",
121-
};
122-
for (String pod : pods) {
123-
assertTrue(
124-
pod + " Pod not running", testUtil.isPodRunning(namespace, domain1LabelSelector, pod));
125-
}
99+
verifyServersStatus(domain);
126100
testBasicUseCases(domain);
127-
if (!SMOKETEST) domain.testWlsLivenessProbe();
101+
if (!SMOKETEST) {
102+
domain.testWlsLivenessProbe();
103+
}
128104
testCompletedSuccessfully = true;
129105
} finally {
130106
if (domain != null && !SMOKETEST && (JENKINS || testCompletedSuccessfully)) {
131107
domain.destroy();
132108
}
133-
Files.copy(
134-
Paths.get(template + ".org"), Paths.get(template), StandardCopyOption.REPLACE_EXISTING);
135-
Files.delete(Paths.get(template + ".org"));
109+
restoreDomainTemplate();
136110
}
137111
logger.info("SUCCESS - " + testMethodName);
138112
}
@@ -162,51 +136,85 @@ public void testCreateDomainTwoMixedCluster() throws Exception {
162136
domainMap.put(
163137
"createDomainPyScript",
164138
"integration-tests/src/test/resources/domain-home-on-pv/" + TWO_MIXED_CLUSTER_SCRIPT);
165-
166-
String add =
167-
" - clusterName: %CLUSTER_NAME%-2\n"
168-
+ " serverStartState: \"RUNNING\"\n"
169-
+ " replicas: %INITIAL_MANAGED_SERVER_REPLICAS%\n";
170-
logger.info("Making a backup of the domain template file:" + template);
171-
if (!Files.exists(Paths.get(template + ".org"))) {
172-
Files.copy(Paths.get(template), Paths.get(template + ".org"));
173-
}
174-
Files.write(Paths.get(template), add.getBytes(), StandardOpenOption.APPEND);
175-
byte[] readAllBytes = Files.readAllBytes(Paths.get(template));
176-
logger.info(new String(readAllBytes, StandardCharsets.UTF_8));
139+
addCluster2ToDomainTemplate();
177140
domain = TestUtils.createDomain(domainMap);
178141
domain.verifyDomainCreated();
179-
K8sTestUtils testUtil = new K8sTestUtils();
180-
String domain1LabelSelector = String.format("weblogic.domainUID in (%s)", DOMAINUID);
181-
String namespace = domain.getDomainNS();
182-
String pods[] = {
183-
DOMAINUID + "-" + domain.getAdminServerName(),
184-
DOMAINUID + "-managed-server",
185-
DOMAINUID + "-managed-server1",
186-
DOMAINUID + "-managed-server2",
187-
DOMAINUID + "-new-managed-server1",
188-
DOMAINUID + "-new-managed-server2",
189-
};
190-
for (String pod : pods) {
191-
assertTrue(
192-
pod + " Pod not running", testUtil.isPodRunning(namespace, domain1LabelSelector, pod));
193-
}
142+
verifyServersStatus(domain);
194143
testBasicUseCases(domain);
195-
if (!SMOKETEST) domain.testWlsLivenessProbe();
144+
if (!SMOKETEST) {
145+
domain.testWlsLivenessProbe();
146+
}
196147
testCompletedSuccessfully = true;
197148
} finally {
198149
if (domain != null && !SMOKETEST && (JENKINS || testCompletedSuccessfully)) {
199150
domain.destroy();
200151
}
201-
Files.copy(
202-
Paths.get(template + ".org"), Paths.get(template), StandardCopyOption.REPLACE_EXISTING);
203-
Files.delete(Paths.get(template + ".org"));
152+
restoreDomainTemplate();
204153
}
205154
logger.info("SUCCESS - " + testMethodName);
206155
}
207156

157+
/**
158+
* Call the basic usecases tests
159+
*
160+
* @param Domain
161+
* @throws Exception
162+
*/
208163
private void testBasicUseCases(Domain domain) throws Exception {
209164
testAdminT3Channel(domain);
210165
testAdminServerExternalService(domain);
211166
}
167+
168+
/**
169+
* Append a second cluster to the domain template
170+
*
171+
* @throws IOException when append fails
172+
*/
173+
private void addCluster2ToDomainTemplate() throws IOException {
174+
String add =
175+
" - clusterName: %CLUSTER_NAME%-2\n"
176+
+ " serverStartState: \"RUNNING\"\n"
177+
+ " replicas: %INITIAL_MANAGED_SERVER_REPLICAS%\n";
178+
logger.info("Making a backup of the domain template file:" + template);
179+
if (!Files.exists(Paths.get(template + ".org"))) {
180+
Files.copy(Paths.get(template), Paths.get(template + ".org"));
181+
}
182+
Files.write(Paths.get(template), add.getBytes(), StandardOpenOption.APPEND);
183+
byte[] readAllBytes = Files.readAllBytes(Paths.get(template));
184+
logger.info(new String(readAllBytes, StandardCharsets.UTF_8));
185+
}
186+
187+
/**
188+
* Restore the domain template to original state when test is finished
189+
*
190+
* @throws IOException
191+
*/
192+
private void restoreDomainTemplate() throws IOException {
193+
Files.copy(
194+
Paths.get(template + ".org"), Paths.get(template), StandardCopyOption.REPLACE_EXISTING);
195+
Files.delete(Paths.get(template + ".org"));
196+
}
197+
198+
/**
199+
* Verifies all of the servers in the cluster are in Running status
200+
*
201+
* @param Domain
202+
*/
203+
private void verifyServersStatus(Domain domain) {
204+
K8sTestUtils testUtil = new K8sTestUtils();
205+
String domain1LabelSelector = String.format("weblogic.domainUID in (%s)", DOMAINUID);
206+
String namespace = domain.getDomainNS();
207+
String pods[] = {
208+
DOMAINUID + "-" + domain.getAdminServerName(),
209+
DOMAINUID + "-managed-server",
210+
DOMAINUID + "-managed-server1",
211+
DOMAINUID + "-managed-server2",
212+
DOMAINUID + "-new-managed-server1",
213+
DOMAINUID + "-new-managed-server2",
214+
};
215+
for (String pod : pods) {
216+
assertTrue(
217+
pod + " Pod not running", testUtil.isPodRunning(namespace, domain1LabelSelector, pod));
218+
}
219+
}
212220
}

0 commit comments

Comments
 (0)