Skip to content

Commit 31dcb0f

Browse files
authored
Merge pull request #997 from oracle/wsapp
Added WebService app to test load balancing, and utility to build WebServices and its Servlet client
2 parents 9b075da + 3476689 commit 31dcb0f

File tree

12 files changed

+531
-78
lines changed

12 files changed

+531
-78
lines changed

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

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
public class BaseTest {
2727
public static final Logger logger = Logger.getLogger("OperatorIT", "OperatorIT");
2828
public static final String TESTWEBAPP = "testwebapp";
29+
public static final String TESTWSAPP = "testwsapp";
30+
public static final String TESTWSSERVICE = "TestWSApp";
2931

3032
// property file used to customize operator properties for operator inputs yaml
3133

@@ -320,6 +322,23 @@ public void testAdminT3ChannelWithJMS(Domain domain) throws Exception {
320322
logger.info("Done - testAdminT3ChannelWithJMS");
321323
}
322324

325+
/**
326+
* Verify Load Balancing by deploying and invoking webservicebapp.
327+
*
328+
* @param domain - domain where the app will be tested
329+
* @throws Exception exception reported as a failure to build, deploy or verify load balancing for
330+
* Web Service app
331+
*/
332+
public void testWSLoadBalancing(Domain domain) throws Exception {
333+
logger.info("Inside testWSLoadBalancing");
334+
TestUtils.renewK8sClusterLease(getProjectRoot(), getLeaseId());
335+
buildDeployWebServiceApp(domain, TESTWSAPP, TESTWSSERVICE);
336+
337+
// invoke webservice via servlet client
338+
domain.verifyWebAppLoadBalancing(TESTWSSERVICE + "Servlet");
339+
logger.info("Done - testWSLoadBalancing");
340+
}
341+
323342
/**
324343
* Restarting the domain should not have any impact on Operator managing the domain, web app load
325344
* balancing and node port service
@@ -339,6 +358,9 @@ public void testDomainLifecyle(Operator operator, Domain domain) throws Exceptio
339358
} else {
340359
domain.verifyWebAppLoadBalancing(TESTWEBAPP);
341360
}
361+
362+
// intermittent failure, see OWLS-73416
363+
// testWSLoadBalancing(domain);
342364
domain.verifyAdminServerExternalService(getUsername(), getPassword());
343365
domain.verifyHasClusterServiceChannelPort("TCP", 8011, TESTWEBAPP + "/");
344366
logger.info("Done - testDomainLifecyle");
@@ -570,6 +592,15 @@ private void copyScalingScriptToPod(
570592
domainNS);
571593
}
572594

595+
private void buildDeployWebServiceApp(Domain domain, String testAppName, String wsName)
596+
throws Exception {
597+
String scriptName = "buildDeployWSAndWSClientAppInPod.sh";
598+
// Build WS and WS client WARs in the admin pod and deploy it from the admin pod to a weblogic
599+
// target
600+
TestUtils.buildDeployWebServiceAppInPod(
601+
domain, testAppName, scriptName, BaseTest.getUsername(), BaseTest.getPassword(), wsName);
602+
}
603+
573604
private void callWebAppAndVerifyScaling(Domain domain, int replicas) throws Exception {
574605
Map<String, Object> domainMap = domain.getDomainMap();
575606
String domainNS = domainMap.get("namespace").toString();

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

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,6 @@ public void callWebAppAndVerifyLoadBalancing(String webappName, boolean verifyLo
468468
.append(domainUid)
469469
.append(".org' ")
470470
.append(testAppUrl.toString());
471-
472471
// curl cmd to get response code
473472
StringBuffer curlCmdResCode = new StringBuffer(curlCmd.toString());
474473
curlCmdResCode.append(" --write-out %{http_code} -o /dev/null");
@@ -705,6 +704,15 @@ public String getAdminServerName() {
705704
return adminServerName;
706705
}
707706

707+
/**
708+
* Get the name of the cluster in the domain
709+
*
710+
* @return the name of the cluster
711+
*/
712+
public String getClusterName() {
713+
return clusterName;
714+
}
715+
708716
/**
709717
* Get the namespace in which the domain is running
710718
*
@@ -1198,43 +1206,47 @@ private void callWebAppAndWaitTillReady(String curlCmd) throws Exception {
11981206
String responseCode = result.stdout().trim();
11991207
if (!responseCode.equals("200")) {
12001208
logger.info(
1201-
"testwebapp did not return 200 status code, got "
1209+
"callWebApp did not return 200 status code, got "
12021210
+ responseCode
12031211
+ ", iteration "
12041212
+ i
12051213
+ " of "
12061214
+ maxIterations);
12071215
if (i == (maxIterations - 1)) {
12081216
throw new RuntimeException(
1209-
"FAILURE: testwebapp did not return 200 status code, got " + responseCode);
1217+
"FAILURE: callWebApp did not return 200 status code, got " + responseCode);
12101218
}
12111219
try {
12121220
Thread.sleep(waitTime * 1000);
12131221
} catch (InterruptedException ignore) {
12141222
}
12151223
} else {
1216-
logger.info("testwebapp returned 200 response code, iteration " + i);
1224+
logger.info("callWebApp returned 200 response code, iteration " + i);
12171225
break;
12181226
}
12191227
}
12201228
}
12211229

12221230
private void callWebAppAndCheckForServerNameInResponse(
12231231
String curlCmd, boolean verifyLoadBalancing) throws Exception {
1232+
callWebAppAndCheckForServerNameInResponse(curlCmd, verifyLoadBalancing, 50);
1233+
}
1234+
1235+
private void callWebAppAndCheckForServerNameInResponse(
1236+
String curlCmd, boolean verifyLoadBalancing, int maxIterations) throws Exception {
12241237
// map with server names and boolean values
12251238
HashMap<String, Boolean> managedServers = new HashMap<String, Boolean>();
12261239
for (int i = 1; i <= TestUtils.getClusterReplicas(domainUid, clusterName, domainNS); i++) {
12271240
managedServers.put(domainUid + "-" + managedServerNameBase + i, new Boolean(false));
12281241
}
1229-
logger.info("Calling webapp 20 times " + curlCmd);
1242+
logger.info("Calling webapp " + maxIterations + " times " + curlCmd);
12301243
// number of times to call webapp
1231-
for (int i = 0; i < 20; i++) {
1232-
ExecResult result = TestUtils.exec(curlCmd);
12331244

1245+
for (int i = 0; i < maxIterations; i++) {
1246+
ExecResult result = ExecCommand.exec(curlCmd.toString());
12341247
logger.info("webapp invoked successfully for curlCmd:" + curlCmd);
12351248
if (verifyLoadBalancing) {
12361249
String response = result.stdout().trim();
1237-
// logger.info("response: " + response);
12381250
for (String key : managedServers.keySet()) {
12391251
if (response.contains(key)) {
12401252
managedServers.put(key, new Boolean(true));
@@ -1243,6 +1255,7 @@ private void callWebAppAndCheckForServerNameInResponse(
12431255
}
12441256
}
12451257
}
1258+
12461259
logger.info("ManagedServers " + managedServers);
12471260

12481261
// error if any managedserver value is false
@@ -1643,19 +1656,13 @@ public void restartManagedServerUsingServerStartPolicy(String msName) throws Exc
16431656
* @param webappName - Web App Name to be deployed
16441657
* @param scriptName - a shell script to build WAR, EAR or JAR file and deploy the App in the
16451658
* admin pod
1646-
* @param archiveExt - archive extention
1647-
* @param infoDirNames - archive information dir location
16481659
* @param username - weblogic user name
16491660
* @param password - weblogc password
1661+
* @param args - optional args to add for script if needed
16501662
* @throws Exception
16511663
*/
1652-
private void callShellScriptToBuildDeployAppInPod(
1653-
String webappName,
1654-
String scriptName,
1655-
String archiveExt,
1656-
String infoDirNames,
1657-
String username,
1658-
String password)
1664+
public void callShellScriptToBuildDeployAppInPod(
1665+
String webappName, String scriptName, String username, String password, String... args)
16591666
throws Exception {
16601667

16611668
String nodeHost = getHostNameForCurl();
@@ -1692,9 +1699,7 @@ private void callShellScriptToBuildDeployAppInPod(
16921699
.append(" ")
16931700
.append(clusterName)
16941701
.append(" ")
1695-
.append(infoDirNames)
1696-
.append(" ")
1697-
.append(archiveExt)
1702+
.append(String.join(" ", args).toString())
16981703
.append("'");
16991704

17001705
logger.info("Command to exec script file: " + cmdKubectlSh);
@@ -1795,7 +1800,7 @@ public void buildDeployJavaAppInPod(
17951800
String scriptPathOnHost = BaseTest.getAppLocationOnHost() + "/" + scriptName;
17961801
String scriptPathInPod = BaseTest.getAppLocationInPod() + "/" + scriptName;
17971802

1798-
// Default velues to build archive file
1803+
// Default values to build archive file
17991804
final String initInfoDirName = "WEB-INF";
18001805
String archiveExt = "war";
18011806
String infoDirName = initInfoDirName;
@@ -1817,6 +1822,7 @@ public boolean accept(File dir, String name) {
18171822
// Check archive file type
18181823
if (!subDirList.contains(infoDirName)) {
18191824
infoDirName = "META-INF";
1825+
18201826
// Create .ear file or .jar file for EJB
18211827
archiveExt = (args.length == 0) ? "ear" : args[0];
18221828
}
@@ -1833,9 +1839,8 @@ public boolean accept(File dir, String name) {
18331839

18341840
// Copy all App files to the admin pod
18351841
TestUtils.copyAppFilesToPod(appLocationOnHost, appLocationInPod, adminServerPod, domainNS);
1836-
18371842
// Run the script to build WAR, EAR or JAR file and deploy the App in the admin pod
18381843
callShellScriptToBuildDeployAppInPod(
1839-
appName, scriptName, archiveExt, infoDirName, username, password);
1844+
appName, scriptName, username, password, infoDirName, archiveExt);
18401845
}
18411846
}

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

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1199,4 +1199,113 @@ public static void copyFile(String fromFile, String toFile) throws Exception {
11991199
logger.info("Copying file from " + fromFile + " to " + toFile);
12001200
Files.copy(new File(fromFile).toPath(), Paths.get(toFile), StandardCopyOption.REPLACE_EXISTING);
12011201
}
1202+
1203+
/**
1204+
* retrieve IP address info for cluster service.
1205+
*
1206+
* @param domainUID - name of domain.
1207+
* @param clusterName - name Web Logic cluster
1208+
* @param domainNS - domain namespace
1209+
* @throws Exception - exception will be thrown if kubectl command will fail
1210+
*/
1211+
public static String retrieveClusterIP(String domainUID, String clusterName, String domainNS)
1212+
throws Exception {
1213+
// kubectl get service domainonpvwlst-cluster-cluster-1 | grep ClusterIP | awk '{print $3}'
1214+
StringBuffer cmd = new StringBuffer("kubectl get service ");
1215+
cmd.append(domainUID);
1216+
cmd.append("-cluster-");
1217+
cmd.append(clusterName);
1218+
cmd.append(" -n ").append(domainNS);
1219+
cmd.append(" | grep ClusterIP | awk '{print $3}' ");
1220+
logger.info(
1221+
" Get ClusterIP for "
1222+
+ clusterName
1223+
+ " in namespace "
1224+
+ domainNS
1225+
+ " with command: '"
1226+
+ cmd
1227+
+ "'");
1228+
1229+
ExecResult result = ExecCommand.exec(cmd.toString());
1230+
String stdout = result.stdout();
1231+
logger.info(" ClusterIP for cluster: " + clusterName + " found: ");
1232+
logger.info(stdout);
1233+
return stdout;
1234+
}
1235+
1236+
/**
1237+
* Create dir to save Web Service App files. Copy the shell script file and all App files over to
1238+
* the admin pod Run the shell script to build WARs files and deploy the Web Service App and it's
1239+
* client Servlet App in the admin pod
1240+
*
1241+
* @param domain - Domain where to build and deploy app
1242+
* @param appName - WebService App name to be deployed
1243+
* @param scriptName - a shell script to build and deploy the App in the admin pod
1244+
* @param username - weblogic user name
1245+
* @param password - weblogc password
1246+
* @param args - by default it use TestWSApp name for webservices impl files, or add arg for
1247+
* different name
1248+
* @throws Exception - exception reported as a failure to build or deploy ws
1249+
*/
1250+
public static void buildDeployWebServiceAppInPod(
1251+
Domain domain,
1252+
String appName,
1253+
String scriptName,
1254+
String username,
1255+
String password,
1256+
String... args)
1257+
throws Exception {
1258+
String adminServerPod = domain.getDomainUid() + "-" + domain.getAdminServerName();
1259+
String appLocationOnHost = BaseTest.getAppLocationOnHost() + "/" + appName;
1260+
String appLocationInPod = BaseTest.getAppLocationInPod() + "/" + appName;
1261+
String scriptPathOnHost = BaseTest.getAppLocationOnHost() + "/" + scriptName;
1262+
String scriptPathInPod = BaseTest.getAppLocationInPod() + "/" + scriptName;
1263+
1264+
// Default values to build archive file
1265+
final String initInfoDirName = "WEB-INF";
1266+
String archiveExt = "war";
1267+
String infoDirName = initInfoDirName;
1268+
String domainNS = domain.getDomainNS();
1269+
int managedServerPort = ((Integer) (domain.getDomainMap()).get("managedServerPort")).intValue();
1270+
String wsServiceName = (args.length == 0) ? BaseTest.TESTWSSERVICE : args[0];
1271+
String clusterURL =
1272+
retrieveClusterIP(domain.getDomainUid(), domain.getClusterName(), domainNS)
1273+
+ ":"
1274+
+ managedServerPort;
1275+
logger.info(
1276+
"Build and deploy WebService App: "
1277+
+ appName
1278+
+ "."
1279+
+ archiveExt
1280+
+ " in the admin pod with web service name "
1281+
+ wsServiceName);
1282+
1283+
// Create app dir in the admin pod
1284+
StringBuffer mkdirCmd = new StringBuffer(" -- bash -c 'mkdir -p ");
1285+
mkdirCmd.append(appLocationInPod + "'");
1286+
1287+
// Create app dir in the admin pod
1288+
kubectlexec(adminServerPod, domainNS, mkdirCmd.toString());
1289+
1290+
// Create WEB-INF in the app dir
1291+
mkdirCmd = new StringBuffer(" -- bash -c 'mkdir -p ");
1292+
mkdirCmd.append(appLocationInPod + "/WEB-INF'");
1293+
kubectlexec(adminServerPod, domainNS, mkdirCmd.toString());
1294+
1295+
// Copy shell script to the admin pod
1296+
copyFileViaCat(scriptPathOnHost, scriptPathInPod, adminServerPod, domainNS);
1297+
1298+
// Copy all App files to the admin pod
1299+
copyAppFilesToPod(appLocationOnHost, appLocationInPod, adminServerPod, domainNS);
1300+
1301+
// Copy all App files to the admin pod
1302+
copyAppFilesToPod(
1303+
appLocationOnHost + "/WEB-INF", appLocationInPod + "/WEB-INF", adminServerPod, domainNS);
1304+
1305+
logger.info("Creating WebService and WebService Servlet Client Applications");
1306+
1307+
// Run the script to build WAR, EAR or JAR file and deploy the App in the admin pod
1308+
domain.callShellScriptToBuildDeployAppInPod(
1309+
appName, scriptName, username, password, clusterURL, wsServiceName);
1310+
}
12021311
}

integration-tests/src/test/resources/OperatorIT.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ baseDir=/scratch
66
username=weblogic
77
password=welcome1
88
maxIterationsPod=25
9-
waitTimePod=10
9+
waitTimePod=10

0 commit comments

Comments
 (0)