1
1
// Copyright 2018, 2019 Oracle Corporation and/or its affiliates. All rights reserved.
2
2
// Licensed under the Universal Permissive License v 1.0 as shown at
3
3
// http://oss.oracle.com/licenses/upl.
4
-
5
4
package oracle .kubernetes .operator ;
6
5
7
6
import static org .junit .Assert .assertTrue ;
8
7
8
+ import java .io .IOException ;
9
9
import java .nio .charset .StandardCharsets ;
10
10
import java .nio .file .Files ;
11
11
import java .nio .file .Paths ;
30
30
@ FixMethodOrder (MethodSorters .NAME_ASCENDING )
31
31
public class ITMultipleClusters extends BaseTest {
32
32
33
- private static Operator operator1 , operator2 ;
34
-
35
- private static Operator operatorForBackwardCompatibility ;
36
- private static Operator operatorForRESTCertChain ;
37
-
33
+ private static Operator operator1 ;
38
34
private static final String TWO_CONFIGURED_CLUSTER_SCRIPT =
39
35
"create-domain-two-configured-cluster.py" ;
40
36
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" ;
41
39
42
40
/**
43
41
* 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 {
50
48
public static void staticPrepare () throws Exception {
51
49
// initialize test properties and create the directories
52
50
initialize (APP_PROPS_FILE );
51
+ template =
52
+ BaseTest .getProjectRoot () + "/kubernetes/samples/scripts/common/domain-template.yaml" ;
53
53
}
54
54
55
55
/**
@@ -74,11 +74,10 @@ public static void staticUnPrepare() throws Exception {
74
74
*/
75
75
@ Test
76
76
public void testCreateDomainTwoConfiguredCluster () throws Exception {
77
- String DOMAINUID = "twoconfigclustdomain" ;
77
+
78
78
String testMethodName = new Object () {}.getClass ().getEnclosingMethod ().getName ();
79
79
logTestBegin (testMethodName );
80
- String template =
81
- BaseTest .getProjectRoot () + "/kubernetes/samples/scripts/common/domain-template.yaml" ;
80
+
82
81
logger .info ("Creating Operator & waiting for the script to complete execution" );
83
82
// create operator1
84
83
if (operator1 == null ) {
@@ -94,45 +93,20 @@ public void testCreateDomainTwoConfiguredCluster() throws Exception {
94
93
"createDomainPyScript" ,
95
94
"integration-tests/src/test/resources/domain-home-on-pv/"
96
95
+ 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 ();
109
97
domain = TestUtils .createDomain (domainMap );
110
98
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 );
126
100
testBasicUseCases (domain );
127
- if (!SMOKETEST ) domain .testWlsLivenessProbe ();
101
+ if (!SMOKETEST ) {
102
+ domain .testWlsLivenessProbe ();
103
+ }
128
104
testCompletedSuccessfully = true ;
129
105
} finally {
130
106
if (domain != null && !SMOKETEST && (JENKINS || testCompletedSuccessfully )) {
131
107
domain .destroy ();
132
108
}
133
- Files .copy (
134
- Paths .get (template + ".org" ), Paths .get (template ), StandardCopyOption .REPLACE_EXISTING );
135
- Files .delete (Paths .get (template + ".org" ));
109
+ restoreDomainTemplate ();
136
110
}
137
111
logger .info ("SUCCESS - " + testMethodName );
138
112
}
@@ -162,51 +136,85 @@ public void testCreateDomainTwoMixedCluster() throws Exception {
162
136
domainMap .put (
163
137
"createDomainPyScript" ,
164
138
"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 ();
177
140
domain = TestUtils .createDomain (domainMap );
178
141
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 );
194
143
testBasicUseCases (domain );
195
- if (!SMOKETEST ) domain .testWlsLivenessProbe ();
144
+ if (!SMOKETEST ) {
145
+ domain .testWlsLivenessProbe ();
146
+ }
196
147
testCompletedSuccessfully = true ;
197
148
} finally {
198
149
if (domain != null && !SMOKETEST && (JENKINS || testCompletedSuccessfully )) {
199
150
domain .destroy ();
200
151
}
201
- Files .copy (
202
- Paths .get (template + ".org" ), Paths .get (template ), StandardCopyOption .REPLACE_EXISTING );
203
- Files .delete (Paths .get (template + ".org" ));
152
+ restoreDomainTemplate ();
204
153
}
205
154
logger .info ("SUCCESS - " + testMethodName );
206
155
}
207
156
157
+ /**
158
+ * Call the basic usecases tests
159
+ *
160
+ * @param Domain
161
+ * @throws Exception
162
+ */
208
163
private void testBasicUseCases (Domain domain ) throws Exception {
209
164
testAdminT3Channel (domain );
210
165
testAdminServerExternalService (domain );
211
166
}
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
+ }
212
220
}
0 commit comments