55
66import static org .junit .Assert .assertTrue ;
77
8- import java .io .IOException ;
9- import java .nio .charset .StandardCharsets ;
108import java .nio .file .Files ;
119import java .nio .file .Paths ;
1210import java .nio .file .StandardCopyOption ;
1311import java .nio .file .StandardOpenOption ;
1412import java .util .Map ;
13+ import java .util .logging .Level ;
1514import oracle .kubernetes .operator .utils .Domain ;
1615import oracle .kubernetes .operator .utils .K8sTestUtils ;
1716import 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 ));
0 commit comments