Skip to content

Commit 9c2a173

Browse files
committed
Completed JIRA OWLS-73106 - Create a generic utility to build the jar file for EJB App in a server pod and deploy it from the pod
1 parent 3b78025 commit 9c2a173

File tree

4 files changed

+100
-27
lines changed

4 files changed

+100
-27
lines changed

integration-tests/src/test/java/oracle/kubernetes/operator/ITSessionMigration.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
3030
public class ITSessionMigration extends BaseTest {
3131
private static final String testAppName = "httpsessionreptestapp";
32-
private static final String scriptName = "buildDeployWebAppInPod.sh";
32+
private static final String scriptName = "buildDeployAppInPod.sh";
3333

3434
private static Map<String, String> httpAttrMap;
3535

@@ -77,7 +77,7 @@ public static void staticPrepare() throws Exception {
7777
httpAttrMap.put("count", "(.*)countattribute>(.*)</countattribute(.*)");
7878

7979
// Build WAR in the admin pod and deploy it from the admin pod to a weblogic target
80-
domain.buildWarDeployAppInPod(
80+
domain.buildDeployJavaAppInPod(
8181
testAppName, scriptName, BaseTest.getUsername(), BaseTest.getPassword());
8282

8383
// Wait some time for deployment gets ready

integration-tests/src/test/java/oracle/kubernetes/operator/utils/Domain.java

Lines changed: 49 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,17 @@
66

77
import java.io.File;
88
import java.io.FileInputStream;
9+
import java.io.FilenameFilter;
910
import java.io.InputStream;
1011
import java.nio.file.Files;
1112
import java.nio.file.Path;
1213
import java.nio.file.Paths;
1314
import java.nio.file.StandardCopyOption;
1415
import java.nio.file.StandardOpenOption;
16+
import java.util.Arrays;
1517
import java.util.HashMap;
1618
import java.util.Hashtable;
19+
import java.util.List;
1720
import java.util.Map;
1821
import java.util.Objects;
1922
import 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
}

integration-tests/src/test/resources/apps/README.txt

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,43 @@ How to use the shell script in this dir to build the archive file in the admin p
1212

1313
2) In the standalone client java file, call:
1414

15-
String scriptName = "buildDeployWebAppInPod.sh";
16-
domain.buildWarDeployAppInPod(testAppName, scriptName, BaseTest.getUsername(), BaseTest.getPassword());
15+
String scriptName = "buildDeployAppInPod.sh";
16+
domain.buildDeployJavaAppInPod(testAppName, scriptName, BaseTest.getUsername(), BaseTest.getPassword());
1717
Create dir in the admon pod to save Web App files
1818
Copy the shell script file and all App files over to the admin pod
1919
Run the shell script to build WAR and deploy the App from the admin pod to the given webligic target
2020

2121
3) testAppName.war file is created at "/u01/oracle/apps/testAppName" in the admin pod
22+
23+
EJB App
24+
1) Create a directory structure for packaging JAR
25+
26+
integration-tests/src/test/resources/apps/
27+
testAppName/
28+
foo.java
29+
fooHome.java
30+
fooBean.java
31+
META-INF/
32+
ejb-jar.xml
33+
weblogic-ejb-jar.xml
34+
weblogic-cmp-jar.xml
2235

23-
sh buildDeployWebAppInPod.sh node-hostname node-port username password dir-in-pod-to-save-app-files appname deploy-target
36+
2) In the standalone client java file, call:
37+
38+
String scriptName = "buildDeployAppInPod.sh";
39+
domain.buildDeployJavaAppInPod(testAppName, scriptName, BaseTest.getUsername(), BaseTest.getPassword());
40+
Create dir in the admon pod to save Web App files
41+
Copy the shell script file and all App files over to the admin pod
42+
Run the shell script to build WAR and deploy the App from the admin pod to the given webligic target
43+
44+
or to build a JAR file:
45+
46+
domain.buildDeployJavaAppInPod(testAppName, scriptName, BaseTest.getUsername(), BaseTest.getPassword(), "jar");
47+
48+
3) testAppName.jar file is created at "/u01/oracle/apps/testAppName" in the admin pod
49+
50+
sh buildDeployAppInPod.sh node-hostname node-port username password dir-in-pod-to-save-app-files appname deploy-target
2451
Create directories to save the binaries
2552
Complie java files
26-
Create WAR
53+
Create WAR/EAR/JAR
2754
Deploy the App from the admin pod to the given webligic target

integration-tests/src/test/resources/apps/buildDeployWebAppInPod.sh renamed to integration-tests/src/test/resources/apps/buildDeployAppInPod.sh

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@
77
usage()
88
{
99
printf "\n"
10-
echo 1>&2 "Usage: sh $0 node-hostname node-port username password dir-in-pod-to-save-app-files appname deploy-target"
10+
echo 1>&2 "Usage: sh $0 node-hostname node-port username password dir-in-pod-to-save-app-files appname deploy-target app-info-dir archive-file-name"
11+
printf "\n"
12+
echo 1>&2 "e.g., to build WAR file: sh $0 hostname123 30305 myuser mypwd /u01/oracle/apps/webtestapp webtestapp cluster-1 WEB-INF war"
13+
printf "\n"
14+
echo 1>&2 "e.g., to build EAR file: sh $0 hostname123 30305 myuser mypwd /u01/oracle/apps/ejbtestapp ejbtestapp cluster-1 META-INF ear"
1115
printf "\n"
1216
}
1317

@@ -26,7 +30,9 @@ PASSWORD=${4:-welcome1}
2630
APP_DIR_INPOD=$5
2731
APP_NAME=$6
2832
DEPLOY_TARGET=$7
29-
WAR_FILE_NAME=${APP_NAME}.war
33+
APP_INFO_DIR=$8
34+
ARCHIVE_FILE_EXT=$9
35+
ARCHIVE_FILE_NAME=${APP_NAME}.${ARCHIVE_FILE_EXT}
3036

3137
echo "App location in the pod: ${APP_NAME}"
3238
echo "App name: ${APP_NAME}"
@@ -36,21 +42,21 @@ source $ORACLE_HOME/wlserver/server/bin/setWLSEnv.sh
3642

3743
cd ${APP_DIR_INPOD}
3844

39-
echo -e "mkdir -p stagedir/WEB-INF/classes\n"
40-
mkdir -p stagedir/WEB-INF/classes
45+
echo -e "mkdir -p stagedir/${APP_INFO_DIR}/classes\n"
46+
mkdir -p stagedir/${APP_INFO_DIR}/classes
4147

42-
echo -e "cp -r WEB-INF/* stagedir/WEB-INF/\n"
43-
cp -r WEB-INF/* stagedir/WEB-INF/
48+
echo -e "cp -r ${APP_INFO_DIR}/* stagedir/${APP_INFO_DIR}/\n"
49+
cp -r ${APP_INFO_DIR}/* stagedir/${APP_INFO_DIR}/
4450

45-
echo -e "javac -d stagedir/WEB-INF/classes *.java\n"
46-
javac -d stagedir/WEB-INF/classes *.java
51+
echo -e "javac -d stagedir/${APP_INFO_DIR}/classes *.java\n"
52+
javac -d stagedir/${APP_INFO_DIR}/classes *.java
4753

48-
echo -e "jar -cvf ${WAR_FILE_NAME} -C stagedir .\n"
49-
jar -cvf ${WAR_FILE_NAME} -C stagedir .
54+
echo -e "jar -cvf ${ARCHIVE_FILE_NAME} -C stagedir .\n"
55+
jar -cvf ${ARCHIVE_FILE_NAME} -C stagedir .
5056

5157
echo "Deploy ${APP_NAME} using cmd:"
52-
echo -e "curl --noproxy '*' --silent --user ${USER}:${PASSWORD} -H X-Requested-By:MyClient -H Accept:application/json -H Content-Type:multipart/form-data -F "model={ name: '${APP_NAME}', targets: [ { identity: [ clusters, '${DEPLOY_TARGET}' ] } ] }" -F "sourcePath=@${APP_DIR_INPOD}/${WAR_FILE_NAME}" -H "Prefer:respond-async" -X POST http://${HOST}:${PORT}/management/weblogic/latest/edit/appDeployments\n"
53-
curl --noproxy '*' --silent --user ${USER}:${PASSWORD} -H X-Requested-By:MyClient -H Accept:application/json -H Content-Type:multipart/form-data -F "model={ name: '${APP_NAME}', targets: [ { identity: [ clusters, '${DEPLOY_TARGET}' ] } ] }" -F "sourcePath=@${APP_DIR_INPOD}/${WAR_FILE_NAME}" -H "Prefer:respond-async" -X POST http://${HOST}:${PORT}/management/weblogic/latest/edit/appDeployments
58+
echo -e "curl --noproxy '*' --silent --user ${USER}:${PASSWORD} -H X-Requested-By:MyClient -H Accept:application/json -H Content-Type:multipart/form-data -F "model={ name: '${APP_NAME}', targets: [ { identity: [ clusters, '${DEPLOY_TARGET}' ] } ] }" -F "sourcePath=@${APP_DIR_INPOD}/${ARCHIVE_FILE_NAME}" -H "Prefer:respond-async" -X POST http://${HOST}:${PORT}/management/weblogic/latest/edit/appDeployments\n"
59+
curl --noproxy '*' --silent --user ${USER}:${PASSWORD} -H X-Requested-By:MyClient -H Accept:application/json -H Content-Type:multipart/form-data -F "model={ name: '${APP_NAME}', targets: [ { identity: [ clusters, '${DEPLOY_TARGET}' ] } ] }" -F "sourcePath=@${APP_DIR_INPOD}/${ARCHIVE_FILE_NAME}" -H "Prefer:respond-async" -X POST http://${HOST}:${PORT}/management/weblogic/latest/edit/appDeployments
5460

5561
rm -rf stagedir
5662

0 commit comments

Comments
 (0)