66
77import java .io .File ;
88import java .io .FileInputStream ;
9+ import java .io .FilenameFilter ;
910import java .io .InputStream ;
1011import java .nio .file .Files ;
1112import java .nio .file .Path ;
1213import java .nio .file .Paths ;
1314import java .nio .file .StandardCopyOption ;
1415import java .nio .file .StandardOpenOption ;
16+ import java .util .Arrays ;
1517import java .util .HashMap ;
1618import java .util .Hashtable ;
19+ import java .util .List ;
1720import java .util .Map ;
1821import java .util .Objects ;
1922import java .util .StringTokenizer ;
@@ -1506,7 +1509,13 @@ public void restartManagedServerUsingServerStartPolicy(String msName) throws Exc
15061509 * @throws Exception
15071510 */
15081511 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 {
15101519
15111520 String nodeHost = getHostNameForCurl ();
15121521 String nodePort = getNodePort ();
@@ -1541,6 +1550,10 @@ private void callShellScriptToBuildWarDeployAppInPod(
15411550 .append (webappName )
15421551 .append (" " )
15431552 .append (clusterName )
1553+ .append (" " )
1554+ .append (infoDirNames )
1555+ .append (" " )
1556+ .append (archiveExt )
15441557 .append ("'" );
15451558
15461559 logger .info ("Command to exec script file: " + cmdKubectlSh );
@@ -1568,24 +1581,50 @@ private void callShellScriptToBuildWarDeployAppInPod(
15681581 * Create dir to save Web App files Copy the shell script file and all App files over to the admin
15691582 * pod Run the shell script to build .war file and deploy the App in the admin pod
15701583 *
1571- * @param webappName - Web App Name to be deployed
1584+ * @param appName - Java App name to be deployed
15721585 * @param scriptName - a shell script to build .war file and deploy the App in the admin pod
15731586 * @param username - weblogic user name
15741587 * @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
15751590 * @throws Exception
15761591 */
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 {
15791595 String adminServerPod = domainUid + "-" + adminServerName ;
1580- // String scriptName = "buildDeployWebAppInPod.sh";
15811596
1582- String appLocationOnHost = BaseTest .getAppLocationOnHost () + "/" + webappName ;
1583- String appLocationInPod = BaseTest .getAppLocationInPod () + "/" + webappName ;
1597+ String appLocationOnHost = BaseTest .getAppLocationOnHost () + "/" + appName ;
1598+ String appLocationInPod = BaseTest .getAppLocationInPod () + "/" + appName ;
15841599 String scriptPathOnHost = BaseTest .getAppLocationOnHost () + "/" + scriptName ;
15851600 String scriptPathInPod = BaseTest .getAppLocationInPod () + "/" + scriptName ;
15861601
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+
15871626 StringBuffer mkdirCmd = new StringBuffer (" -- bash -c 'mkdir -p " );
1588- mkdirCmd .append (appLocationInPod ).append ("/WEB-INF '" );
1627+ mkdirCmd .append (appLocationInPod ).append ("/" + infoDirName + " '" );
15891628
15901629 // Create app dir in the pod
15911630 TestUtils .kubectlexec (adminServerPod , domainNS , mkdirCmd .toString ());
@@ -1597,6 +1636,7 @@ public void buildWarDeployAppInPod(
15971636 TestUtils .copyAppFilesToPod (appLocationOnHost , appLocationInPod , adminServerPod , domainNS );
15981637
15991638 // 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 );
16011641 }
16021642}
0 commit comments