6
6
7
7
import java .io .File ;
8
8
import java .io .FileInputStream ;
9
+ import java .io .FilenameFilter ;
9
10
import java .io .InputStream ;
10
11
import java .nio .file .Files ;
11
12
import java .nio .file .Path ;
12
13
import java .nio .file .Paths ;
13
14
import java .nio .file .StandardCopyOption ;
14
15
import java .nio .file .StandardOpenOption ;
16
+ import java .util .Arrays ;
15
17
import java .util .HashMap ;
16
18
import java .util .Hashtable ;
19
+ import java .util .List ;
17
20
import java .util .Map ;
18
21
import java .util .Objects ;
19
22
import java .util .StringTokenizer ;
@@ -1506,7 +1509,13 @@ public void restartManagedServerUsingServerStartPolicy(String msName) throws Exc
1506
1509
* @throws Exception
1507
1510
*/
1508
1511
private void callShellScriptToBuildWarDeployAppInPod (
1509
- String webappName , String scriptName , String username , String password ) throws Exception {
1512
+ String webappName ,
1513
+ String scriptName ,
1514
+ String archiveExt ,
1515
+ String infoDirNames ,
1516
+ String username ,
1517
+ String password )
1518
+ throws Exception {
1510
1519
1511
1520
String nodeHost = getHostNameForCurl ();
1512
1521
String nodePort = getNodePort ();
@@ -1541,6 +1550,10 @@ private void callShellScriptToBuildWarDeployAppInPod(
1541
1550
.append (webappName )
1542
1551
.append (" " )
1543
1552
.append (clusterName )
1553
+ .append (" " )
1554
+ .append (infoDirNames )
1555
+ .append (" " )
1556
+ .append (archiveExt )
1544
1557
.append ("'" );
1545
1558
1546
1559
logger .info ("Command to exec script file: " + cmdKubectlSh );
@@ -1568,24 +1581,50 @@ private void callShellScriptToBuildWarDeployAppInPod(
1568
1581
* Create dir to save Web App files Copy the shell script file and all App files over to the admin
1569
1582
* pod Run the shell script to build .war file and deploy the App in the admin pod
1570
1583
*
1571
- * @param webappName - Web App Name to be deployed
1584
+ * @param appName - Java App name to be deployed
1572
1585
* @param scriptName - a shell script to build .war file and deploy the App in the admin pod
1573
1586
* @param username - weblogic user name
1574
1587
* @param password - weblogc password
1588
+ * @param args - by default, a WAR file is created for a Web App and a EAR file is created for EJB
1589
+ * App. this varargs gives a client a chance to change EJB's archive extenyion to JAR
1575
1590
* @throws Exception
1576
1591
*/
1577
- public void buildWarDeployAppInPod (
1578
- String webappName , String scriptName , String username , String password ) throws Exception {
1592
+ public void buildDeployJavaAppInPod (
1593
+ String appName , String scriptName , String username , String password , String ... args )
1594
+ throws Exception {
1579
1595
String adminServerPod = domainUid + "-" + adminServerName ;
1580
- // String scriptName = "buildDeployWebAppInPod.sh";
1581
1596
1582
- String appLocationOnHost = BaseTest .getAppLocationOnHost () + "/" + webappName ;
1583
- String appLocationInPod = BaseTest .getAppLocationInPod () + "/" + webappName ;
1597
+ String appLocationOnHost = BaseTest .getAppLocationOnHost () + "/" + appName ;
1598
+ String appLocationInPod = BaseTest .getAppLocationInPod () + "/" + appName ;
1584
1599
String scriptPathOnHost = BaseTest .getAppLocationOnHost () + "/" + scriptName ;
1585
1600
String scriptPathInPod = BaseTest .getAppLocationInPod () + "/" + scriptName ;
1586
1601
1602
+ final String initInfoDirName = "WEB-INF" ;
1603
+ String archiveExt = "war" ;
1604
+ String infoDirName = initInfoDirName ;
1605
+ File appFiles = new File (appLocationOnHost );
1606
+
1607
+ String [] subDirArr =
1608
+ appFiles .list (
1609
+ new FilenameFilter () {
1610
+ @ Override
1611
+ public boolean accept (File dir , String name ) {
1612
+ return name .equals (initInfoDirName );
1613
+ }
1614
+ });
1615
+
1616
+ List <String > subDirList = Arrays .asList (subDirArr );
1617
+
1618
+ if (!subDirList .contains (infoDirName )) {
1619
+ infoDirName = "META-INF" ;
1620
+ // Create .ear file or .jar file for EJB
1621
+ archiveExt = (args .length == 0 ) ? "ear" : args [0 ];
1622
+ }
1623
+
1624
+ logger .info ("Build and deploy: " + appName + "." + archiveExt + " in the admin pod" );
1625
+
1587
1626
StringBuffer mkdirCmd = new StringBuffer (" -- bash -c 'mkdir -p " );
1588
- mkdirCmd .append (appLocationInPod ).append ("/WEB-INF '" );
1627
+ mkdirCmd .append (appLocationInPod ).append ("/" + infoDirName + " '" );
1589
1628
1590
1629
// Create app dir in the pod
1591
1630
TestUtils .kubectlexec (adminServerPod , domainNS , mkdirCmd .toString ());
@@ -1597,6 +1636,7 @@ public void buildWarDeployAppInPod(
1597
1636
TestUtils .copyAppFilesToPod (appLocationOnHost , appLocationInPod , adminServerPod , domainNS );
1598
1637
1599
1638
// Run the script to build .war file and deploy the App in the pod
1600
- callShellScriptToBuildWarDeployAppInPod (webappName , scriptName , username , password );
1639
+ callShellScriptToBuildWarDeployAppInPod (
1640
+ appName , scriptName , archiveExt , infoDirName , username , password );
1601
1641
}
1602
1642
}
0 commit comments