Skip to content

Commit 6d5666b

Browse files
committed
moved method from domain to testutils
1 parent f75f4be commit 6d5666b

File tree

3 files changed

+91
-85
lines changed

3 files changed

+91
-85
lines changed

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

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -323,31 +323,16 @@ public void testAdminT3ChannelWithJMS(Domain domain) throws Exception {
323323
}
324324

325325
/**
326-
* Verify Load Balancing by deploying and invoking webservicebapp
326+
* Verify Load Balancing by deploying and invoking webservicebapp.
327327
*
328-
* @throws Exception
328+
* @throws Exception exception reported as a failure to build, deploy or verify load balancing for
329+
* Web Service app
329330
*/
330331
public void testWSLoadBalancing(Domain domain) throws Exception {
331332
logger.info("Inside testWSLoadBalancing");
332333
TestUtils.renewK8sClusterLease(getProjectRoot(), getLeaseId());
333-
Map<String, Object> domainMap = domain.getDomainMap();
334-
335-
ExecResult result =
336-
TestUtils.kubectlexecNoCheck(
337-
domain.getDomainUid() + ("-") + domainMap.get("adminServerName"),
338-
"" + domainMap.get("namespace"),
339-
" -- mkdir -p " + appLocationInPod);
340-
if (result.exitValue() != 0) {
341-
throw new RuntimeException(
342-
"FAILURE: command to create directory "
343-
+ appLocationInPod
344-
+ " in the pod failed, returned "
345-
+ result.stderr()
346-
+ " "
347-
+ result.stdout());
348-
}
349-
350334
buildDeployWebServiceApp(domain, TESTWSAPP, TESTWSSERVICE);
335+
351336
// invoke webservice via servlet client
352337
domain.verifyWebAppLoadBalancing(TESTWSSERVICE + "Servlet");
353338
logger.info("Done - testWSLoadBalancing");
@@ -609,8 +594,8 @@ private void buildDeployWebServiceApp(Domain domain, String testAppName, String
609594
String scriptName = "buildDeployWSAndWSClientAppInPod.sh";
610595
// Build WS and WS client WARs in the admin pod and deploy it from the admin pod to a weblogic
611596
// target
612-
domain.buildDeployWebServiceAppInPod(
613-
testAppName, scriptName, BaseTest.getUsername(), BaseTest.getPassword(), wsName);
597+
TestUtils.buildDeployWebServiceAppInPod(
598+
domain, testAppName, scriptName, BaseTest.getUsername(), BaseTest.getPassword(), wsName);
614599
}
615600

616601
private void callWebAppAndVerifyScaling(Domain domain, int replicas) throws Exception {

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

Lines changed: 11 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -759,6 +759,15 @@ public String getAdminServerName() {
759759
return adminServerName;
760760
}
761761

762+
/**
763+
* Get the name of the cluster in the domain
764+
*
765+
* @return the name of the cluster
766+
*/
767+
public String getClusterName() {
768+
return clusterName;
769+
}
770+
762771
/**
763772
* Get the namespace in which the domain is running
764773
*
@@ -1630,7 +1639,7 @@ public void restartManagedServerUsingServerStartPolicy(String msName) throws Exc
16301639
* @param args - optional args to add for script if needed
16311640
* @throws Exception
16321641
*/
1633-
private void callShellScriptToBuildDeployAppInPod(
1642+
public void callShellScriptToBuildDeployAppInPod(
16341643
String webappName, String scriptName, String username, String password, String... args)
16351644
throws Exception {
16361645

@@ -1737,6 +1746,7 @@ public boolean accept(File dir, String name) {
17371746
// Check archive file type
17381747
if (!subDirList.contains(infoDirName)) {
17391748
infoDirName = "META-INF";
1749+
17401750
// Create .ear file or .jar file for EJB
17411751
archiveExt = (args.length == 0) ? "ear" : args[0];
17421752
}
@@ -1757,67 +1767,4 @@ public boolean accept(File dir, String name) {
17571767
callShellScriptToBuildDeployAppInPod(
17581768
appName, scriptName, username, password, infoDirName, archiveExt);
17591769
}
1760-
/**
1761-
* Create dir to save Web App files Copy the shell script file and all App files over to the admin
1762-
* pod Run the shell script to build WAR, EAR or JAR file and deploy the App in the admin pod
1763-
*
1764-
* @param appName - WebService App name to be deployed
1765-
* @param scriptName - a shell script to build and deploy the App in the admin pod
1766-
* @param username - weblogic user name
1767-
* @param password - weblogc password
1768-
* @param args - by default it use TestWSApp name for webservices impl files, or add arg for
1769-
* different name
1770-
* @throws Exception
1771-
*/
1772-
public void buildDeployWebServiceAppInPod(
1773-
String appName, String scriptName, String username, String password, String... args)
1774-
throws Exception {
1775-
String adminServerPod = domainUid + "-" + adminServerName;
1776-
String appLocationOnHost = BaseTest.getAppLocationOnHost() + "/" + appName;
1777-
String appLocationInPod = BaseTest.getAppLocationInPod() + "/" + appName;
1778-
String scriptPathOnHost = BaseTest.getAppLocationOnHost() + "/" + scriptName;
1779-
String scriptPathInPod = BaseTest.getAppLocationInPod() + "/" + scriptName;
1780-
1781-
// Default values to build archive file
1782-
final String initInfoDirName = "WEB-INF";
1783-
String archiveExt = "war";
1784-
String infoDirName = initInfoDirName;
1785-
String wsServiceName = (args.length == 0) ? BaseTest.TESTWSSERVICE : args[0];
1786-
String clusterDNS =
1787-
getDomainUid()
1788-
+ "-cluster-"
1789-
+ this.clusterName
1790-
+ "."
1791-
+ getDomainNS()
1792-
+ ".svc.cluster.local:8001";
1793-
1794-
logger.info(
1795-
"Build and deploy WebService App: "
1796-
+ appName
1797-
+ "."
1798-
+ archiveExt
1799-
+ " in the admin pod with web service name "
1800-
+ wsServiceName);
1801-
1802-
// Create app dir in the admin pod
1803-
StringBuffer mkdirCmd = new StringBuffer(" -- bash -c 'mkdir -p ");
1804-
mkdirCmd.append(appLocationInPod).append("/WEB-INF'");
1805-
TestUtils.kubectlexec(adminServerPod, domainNS, mkdirCmd.toString());
1806-
1807-
// Copy shell script to the admin pod
1808-
TestUtils.copyFileViaCat(scriptPathOnHost, scriptPathInPod, adminServerPod, domainNS);
1809-
1810-
// Copy all App files to the admin pod
1811-
TestUtils.copyAppFilesToPod(appLocationOnHost, appLocationInPod, adminServerPod, domainNS);
1812-
1813-
// Copy all App files to the admin pod
1814-
TestUtils.copyAppFilesToPod(
1815-
appLocationOnHost + "/WEB-INF", appLocationInPod + "/WEB-INF", adminServerPod, domainNS);
1816-
1817-
logger.info("Creating WebService and WebService Servlet Client Applications");
1818-
1819-
// Run the script to build WAR, EAR or JAR file and deploy the App in the admin pod
1820-
callShellScriptToBuildDeployAppInPod(
1821-
appName, scriptName, username, password, clusterDNS, wsServiceName);
1822-
}
18231770
}

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

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1188,4 +1188,78 @@ public static void copyFile(String fromFile, String toFile) throws Exception {
11881188
logger.info("Copying file from " + fromFile + " to " + toFile);
11891189
Files.copy(new File(fromFile).toPath(), Paths.get(toFile), StandardCopyOption.REPLACE_EXISTING);
11901190
}
1191+
1192+
/**
1193+
* Create dir to save Web Service App files. Copy the shell script file and all App files over to
1194+
* the admin pod Run the shell script to build WARs files and deploy the Web Service App and it's
1195+
* client Servlet App in the admin pod
1196+
*
1197+
* @param domain - Domain where to build and deploy app
1198+
* @param appName - WebService App name to be deployed
1199+
* @param scriptName - a shell script to build and deploy the App in the admin pod
1200+
* @param username - weblogic user name
1201+
* @param password - weblogc password
1202+
* @param args - by default it use TestWSApp name for webservices impl files, or add arg for
1203+
* different name
1204+
* @throws Exception - exception reported as a failure to build or deploy ws
1205+
*/
1206+
public static void buildDeployWebServiceAppInPod(
1207+
Domain domain,
1208+
String appName,
1209+
String scriptName,
1210+
String username,
1211+
String password,
1212+
String... args)
1213+
throws Exception {
1214+
String adminServerPod = domain.getDomainUid() + "-" + domain.getAdminServerName();
1215+
String appLocationOnHost = BaseTest.getAppLocationOnHost() + "/" + appName;
1216+
String appLocationInPod = BaseTest.getAppLocationInPod() + "/" + appName;
1217+
String scriptPathOnHost = BaseTest.getAppLocationOnHost() + "/" + scriptName;
1218+
String scriptPathInPod = BaseTest.getAppLocationInPod() + "/" + scriptName;
1219+
1220+
// Default values to build archive file
1221+
final String initInfoDirName = "WEB-INF";
1222+
String archiveExt = "war";
1223+
String infoDirName = initInfoDirName;
1224+
String domainNS = domain.getDomainNS();
1225+
String wsServiceName = (args.length == 0) ? BaseTest.TESTWSSERVICE : args[0];
1226+
String clusterDNS =
1227+
domain.getDomainUid()
1228+
+ "-cluster-"
1229+
+ domain.getClusterName()
1230+
+ "."
1231+
+ domainNS
1232+
+ ".svc.cluster.local:8001";
1233+
1234+
logger.info(
1235+
"Build and deploy WebService App: "
1236+
+ appName
1237+
+ "."
1238+
+ archiveExt
1239+
+ " in the admin pod with web service name "
1240+
+ wsServiceName);
1241+
1242+
// Create app dir in the admin pod
1243+
StringBuffer mkdirCmd = new StringBuffer(" -- bash -c 'mkdir -p ");
1244+
kubectlexec(adminServerPod, domainNS, mkdirCmd.toString());
1245+
// Create WEB-INF in the app dir
1246+
mkdirCmd.append(appLocationInPod).append("/WEB-INF'");
1247+
kubectlexec(adminServerPod, domainNS, mkdirCmd.toString());
1248+
1249+
// Copy shell script to the admin pod
1250+
copyFileViaCat(scriptPathOnHost, scriptPathInPod, adminServerPod, domainNS);
1251+
1252+
// Copy all App files to the admin pod
1253+
copyAppFilesToPod(appLocationOnHost, appLocationInPod, adminServerPod, domainNS);
1254+
1255+
// Copy all App files to the admin pod
1256+
copyAppFilesToPod(
1257+
appLocationOnHost + "/WEB-INF", appLocationInPod + "/WEB-INF", adminServerPod, domainNS);
1258+
1259+
logger.info("Creating WebService and WebService Servlet Client Applications");
1260+
1261+
// Run the script to build WAR, EAR or JAR file and deploy the App in the admin pod
1262+
domain.callShellScriptToBuildDeployAppInPod(
1263+
appName, scriptName, username, password, clusterDNS, wsServiceName);
1264+
}
11911265
}

0 commit comments

Comments
 (0)