Skip to content

Commit 458eba6

Browse files
authored
WebLogic remote console integration test (#2320)
* WebLogic remote console integration test
1 parent ea8c40f commit 458eba6

File tree

7 files changed

+315
-7
lines changed

7 files changed

+315
-7
lines changed
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
// Copyright (c) 2021, Oracle and/or its affiliates.
2+
// Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
3+
4+
package oracle.weblogic.kubernetes;
5+
6+
import java.util.List;
7+
8+
import oracle.weblogic.kubernetes.annotations.IntegrationTest;
9+
import oracle.weblogic.kubernetes.annotations.Namespaces;
10+
import oracle.weblogic.kubernetes.logging.LoggingFacade;
11+
import org.junit.jupiter.api.AfterAll;
12+
import org.junit.jupiter.api.BeforeAll;
13+
import org.junit.jupiter.api.DisplayName;
14+
import org.junit.jupiter.api.Test;
15+
16+
import static oracle.weblogic.kubernetes.TestConstants.ADMIN_SERVER_NAME_BASE;
17+
import static oracle.weblogic.kubernetes.TestConstants.K8S_NODEPORT_HOST;
18+
import static oracle.weblogic.kubernetes.TestConstants.MANAGED_SERVER_NAME_BASE;
19+
import static oracle.weblogic.kubernetes.TestConstants.MII_BASIC_IMAGE_NAME;
20+
import static oracle.weblogic.kubernetes.TestConstants.MII_BASIC_IMAGE_TAG;
21+
import static oracle.weblogic.kubernetes.actions.impl.Service.getServiceNodePort;
22+
import static oracle.weblogic.kubernetes.utils.CommonMiiTestUtils.createMiiDomainAndVerify;
23+
import static oracle.weblogic.kubernetes.utils.CommonTestUtils.getExternalServicePodName;
24+
import static oracle.weblogic.kubernetes.utils.CommonTestUtils.installAndVerifyOperator;
25+
import static oracle.weblogic.kubernetes.utils.CommonTestUtils.installAndVerifyWlsRemoteConsole;
26+
import static oracle.weblogic.kubernetes.utils.CommonTestUtils.shutdownWlsRemoteConsole;
27+
import static oracle.weblogic.kubernetes.utils.TestUtils.callWebAppAndWaitTillReturnedCode;
28+
import static oracle.weblogic.kubernetes.utils.ThreadSafeLogger.getLogger;
29+
import static org.junit.jupiter.api.Assertions.assertNotNull;
30+
import static org.junit.jupiter.api.Assertions.assertTrue;
31+
32+
@DisplayName("Test WebLogic remote console connecting to mii domain")
33+
@IntegrationTest
34+
class ItRemoteConsole {
35+
36+
private static String domainNamespace = null;
37+
38+
// domain constants
39+
private static final String domainUid = "domain1";
40+
private static final String clusterName = "cluster-1";
41+
private static final int replicaCount = 1;
42+
private static final String adminServerPodName = domainUid + "-" + ADMIN_SERVER_NAME_BASE;
43+
private static final String managedServerPrefix = domainUid + "-" + MANAGED_SERVER_NAME_BASE;
44+
private static LoggingFacade logger = null;
45+
46+
/**
47+
* Get namespaces for operator and WebLogic domain.
48+
*
49+
* @param namespaces list of namespaces created by the IntegrationTestWatcher by the
50+
* JUnit engine parameter resolution mechanism
51+
*/
52+
@BeforeAll
53+
public static void initAll(@Namespaces(2) List<String> namespaces) {
54+
logger = getLogger();
55+
// get a unique operator namespace
56+
logger.info("Getting a unique namespace for operator");
57+
assertNotNull(namespaces.get(0), "Namespace list is null");
58+
final String opNamespace = namespaces.get(0);
59+
60+
// get a unique domain namespace
61+
logger.info("Getting a unique namespace for WebLogic domain");
62+
assertNotNull(namespaces.get(1), "Namespace list is null");
63+
domainNamespace = namespaces.get(1);
64+
65+
// install and verify operator
66+
installAndVerifyOperator(opNamespace, domainNamespace);
67+
68+
// create a basic model in image domain
69+
createMiiDomainAndVerify(
70+
domainNamespace,
71+
domainUid,
72+
MII_BASIC_IMAGE_NAME + ":" + MII_BASIC_IMAGE_TAG,
73+
adminServerPodName,
74+
managedServerPrefix,
75+
replicaCount);
76+
77+
}
78+
79+
/**
80+
* Verify WLS Remote Console installation is successful.
81+
* Verify k8s WebLogic domain is accessible through remote console.
82+
*/
83+
@Test
84+
@DisplayName("Verify Connecting to Mii domain through WLS Remote Console is successful")
85+
public void testWlsRemoteConsoleConnection() {
86+
87+
assertTrue(installAndVerifyWlsRemoteConsole(), "Remote Console installation failed");
88+
89+
int nodePort = getServiceNodePort(
90+
domainNamespace, getExternalServicePodName(adminServerPodName), "default");
91+
assertTrue(nodePort != -1,
92+
"Could not get the default external service node port");
93+
logger.info("Found the default service nodePort {0}", nodePort);
94+
logger.info("The K8S_NODEPORT_HOST is {0}", K8S_NODEPORT_HOST);
95+
String curlCmd = "curl -v --user weblogic:welcome1 -H Content-Type:application/json -d "
96+
+ "\"{ \\" + "\"domainUrl\\" + "\"" + ": " + "\\" + "\"" + "http://"
97+
+ K8S_NODEPORT_HOST + ":" + nodePort + "\\" + "\" }" + "\""
98+
+ " http://localhost:8012/api/connection --write-out %{http_code} -o /dev/null";
99+
logger.info("Executing default nodeport curl command {0}", curlCmd);
100+
assertTrue(callWebAppAndWaitTillReturnedCode(curlCmd, "201", 10), "Calling web app failed");
101+
logger.info("WebLogic domain is accessible through remote console");
102+
103+
}
104+
105+
/**
106+
* Shutdown WLS Remote Console.
107+
*/
108+
@AfterAll
109+
public void tearDownAll() {
110+
if (System.getenv("SKIP_CLEANUP") == null
111+
|| (System.getenv("SKIP_CLEANUP") != null
112+
&& System.getenv("SKIP_CLEANUP").equalsIgnoreCase("false"))) {
113+
assertTrue(shutdownWlsRemoteConsole(), "Remote Console shutdown failed");
114+
}
115+
}
116+
117+
}

integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/ActionConstants.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,17 @@ public interface ActionConstants {
5555
public static final String WLE = "WLE";
5656
public static final String SNAKE = "SNAKE";
5757

58+
public static final String REMOTECONSOLE = "REMOTECONSOLE";
59+
//remoteconsole jar file after unzipping
60+
public static final String REMOTECONSOLE_FILE = WORK_DIR + "/console/console.jar";
61+
public static final String REMOTECONSOLE_DOWNLOAD_URL_DEFAULT =
62+
"https://github.com/oracle/weblogic-remote-console/releases/latest";
63+
public static final String REMOTECONSOLE_DOWNLOAD_URL
64+
= System.getProperty("remoteconsole.download.url", REMOTECONSOLE_DOWNLOAD_URL_DEFAULT);
65+
public static final String REMOTECONSOLE_VERSION = System.getProperty("remoteconsole.version", "1.1.0");
66+
public static final String REMOTECONSOLE_DOWNLOAD_FILENAME_DEFAULT = "console.zip";
67+
public static final String REMOTECONSOLE_ZIP_PATH = DOWNLOAD_DIR + "/" + REMOTECONSOLE_DOWNLOAD_FILENAME_DEFAULT;
68+
5869
public static final String WLE_DOWNLOAD_URL_DEFAULT
5970
= "https://github.com/oracle/weblogic-logging-exporter/releases/latest";
6071
public static final String WLE_DOWNLOAD_URL

integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/TestActions.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
import oracle.weblogic.kubernetes.actions.impl.TraefikParams;
6363
import oracle.weblogic.kubernetes.actions.impl.Voyager;
6464
import oracle.weblogic.kubernetes.actions.impl.VoyagerParams;
65+
import oracle.weblogic.kubernetes.actions.impl.WebLogicRemoteConsole;
6566
import oracle.weblogic.kubernetes.actions.impl.primitive.Docker;
6667
import oracle.weblogic.kubernetes.actions.impl.primitive.Helm;
6768
import oracle.weblogic.kubernetes.actions.impl.primitive.HelmParams;
@@ -1436,6 +1437,24 @@ public static boolean installElasticsearch(LoggingExporterParams params) {
14361437
return LoggingExporter.installElasticsearch(params);
14371438
}
14381439

1440+
/**
1441+
* Install WebLogic Remote Console.
1442+
*
1443+
* @return true if WebLogic Remote Console is successfully installed, false otherwise.
1444+
*/
1445+
public static boolean installWlsRemoteConsole() {
1446+
return WebLogicRemoteConsole.installWlsRemoteConsole();
1447+
}
1448+
1449+
/**
1450+
* Shutdown WebLogic Remote Console.
1451+
*
1452+
* @return true if WebLogic Remote Console is successfully shutdown, false otherwise.
1453+
*/
1454+
public static boolean shutdownWlsRemoteConsole() {
1455+
return WebLogicRemoteConsole.shutdownWlsRemoteConsole();
1456+
}
1457+
14391458
/**
14401459
* Install Kibana.
14411460
*
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
// Copyright (c) 2021, Oracle and/or its affiliates.
2+
// Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
3+
4+
package oracle.weblogic.kubernetes.actions.impl;
5+
6+
import oracle.weblogic.kubernetes.actions.impl.primitive.Installer;
7+
import oracle.weblogic.kubernetes.logging.LoggingFacade;
8+
import oracle.weblogic.kubernetes.utils.ExecResult;
9+
10+
import static oracle.weblogic.kubernetes.actions.ActionConstants.REMOTECONSOLE_FILE;
11+
import static oracle.weblogic.kubernetes.actions.ActionConstants.WORK_DIR;
12+
import static oracle.weblogic.kubernetes.actions.impl.primitive.Installer.defaultInstallRemoteconsoleParams;
13+
import static oracle.weblogic.kubernetes.utils.ExecCommand.exec;
14+
import static oracle.weblogic.kubernetes.utils.TestUtils.callWebAppAndWaitTillReady;
15+
import static oracle.weblogic.kubernetes.utils.ThreadSafeLogger.getLogger;
16+
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
17+
18+
/**
19+
* Utility class for WebLogic Remote Console.
20+
*/
21+
public class WebLogicRemoteConsole {
22+
23+
private static LoggingFacade logger = getLogger();
24+
25+
/**
26+
* Install WebLogic Remote Console.
27+
*
28+
* @return true if WebLogic Remote Console is successfully installed, false otherwise.
29+
*/
30+
public static boolean installWlsRemoteConsole() {
31+
if (!downloadRemoteConsole()) {
32+
return false;
33+
}
34+
35+
if (!runRemoteconsole()) {
36+
return false;
37+
}
38+
39+
return true;
40+
}
41+
42+
/**
43+
* Shutdown WebLogic Remote Console.
44+
*
45+
* @return true if WebLogic Remote Console is successfully shutdown, false otherwise.
46+
*/
47+
public static boolean shutdownWlsRemoteConsole() {
48+
49+
String command = "kill -9 `jps | grep console.jar | awk '{print $1}'`";
50+
logger.info("Command to shutdown the remote console: {0}", command);
51+
ExecResult result = assertDoesNotThrow(() -> exec(command, true));
52+
logger.info("Shutdown command returned {0}", result.toString());
53+
logger.info(" Shutdown command returned EXIT value {0}", result.exitValue());
54+
55+
return (result.exitValue() == 0);
56+
57+
}
58+
59+
private static boolean downloadRemoteConsole() {
60+
61+
return Installer.withParams(
62+
defaultInstallRemoteconsoleParams())
63+
.download();
64+
}
65+
66+
private static boolean runRemoteconsole() {
67+
68+
String jarLocation = REMOTECONSOLE_FILE;
69+
StringBuffer javaCmd = new StringBuffer("java -jar ");
70+
javaCmd.append(jarLocation);
71+
javaCmd.append(" > ");
72+
javaCmd.append(WORK_DIR + "/console");
73+
javaCmd.append("/remoteconsole.out 2>&1 ");
74+
javaCmd.append(WORK_DIR + "/console");
75+
javaCmd.append(" &");
76+
logger.info("java command to be run {0}", javaCmd.toString());
77+
78+
ExecResult result = assertDoesNotThrow(() -> exec(new String(javaCmd), true));
79+
logger.info("java returned {0}", result.toString());
80+
logger.info("java returned EXIT value {0}", result.exitValue());
81+
82+
return ((result.exitValue() == 0) && accessRemoteconsole());
83+
84+
}
85+
86+
private static boolean accessRemoteconsole() {
87+
88+
String curlCmd = "curl -s -L --show-error --noproxy '*' "
89+
+ " http://localhost:8012"
90+
+ " --write-out %{http_code} -o /dev/null";
91+
logger.info("Executing curl command {0}", curlCmd);
92+
93+
return callWebAppAndWaitTillReady(curlCmd, 10);
94+
95+
}
96+
97+
}

integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/impl/primitive/Installer.java

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
77

88
import static oracle.weblogic.kubernetes.actions.ActionConstants.DOWNLOAD_DIR;
99
import static oracle.weblogic.kubernetes.actions.ActionConstants.IMAGE_TOOL;
10+
import static oracle.weblogic.kubernetes.actions.ActionConstants.REMOTECONSOLE;
11+
import static oracle.weblogic.kubernetes.actions.ActionConstants.REMOTECONSOLE_DOWNLOAD_FILENAME_DEFAULT;
12+
import static oracle.weblogic.kubernetes.actions.ActionConstants.REMOTECONSOLE_DOWNLOAD_URL;
13+
import static oracle.weblogic.kubernetes.actions.ActionConstants.REMOTECONSOLE_DOWNLOAD_URL_DEFAULT;
14+
import static oracle.weblogic.kubernetes.actions.ActionConstants.REMOTECONSOLE_FILE;
1015
import static oracle.weblogic.kubernetes.actions.ActionConstants.SNAKE;
1116
import static oracle.weblogic.kubernetes.actions.ActionConstants.SNAKE_DOWNLOADED_FILENAME;
1217
import static oracle.weblogic.kubernetes.actions.ActionConstants.SNAKE_DOWNLOAD_URL;
@@ -92,6 +97,20 @@ public static InstallParams defaultInstallSnakeParams() {
9297
.unzip(false);
9398
}
9499

100+
/**
101+
* Create an InstallParams with the default values for Remoteconsole.
102+
* @return an InstallParams instance
103+
*/
104+
public static InstallParams defaultInstallRemoteconsoleParams() {
105+
return new InstallParams()
106+
.defaults()
107+
.type(REMOTECONSOLE)
108+
.location(REMOTECONSOLE_DOWNLOAD_URL)
109+
.verify(true)
110+
.unzip(true);
111+
}
112+
113+
95114
/**
96115
* Set up the installer with given parameters.
97116
*
@@ -138,7 +157,7 @@ && new File(DOWNLOAD_DIR, getInstallerFileName(params.type())).exists()) {
138157
}
139158
if (params.unzip()) {
140159
// only unzip WIT once
141-
if (!(doesFileExist(IMAGE_TOOL))) {
160+
if (!(doesFileExist(IMAGE_TOOL)) || !(doesFileExist(REMOTECONSOLE_FILE))) {
142161
unzipSucceeded = unzip();
143162
}
144163
}
@@ -258,6 +277,8 @@ private boolean needToGetActualLocation(
258277
return WIT_DOWNLOAD_URL_DEFAULT.equals(location);
259278
case WLE:
260279
return WLE_DOWNLOAD_URL_DEFAULT.equals(location);
280+
case REMOTECONSOLE:
281+
return REMOTECONSOLE_DOWNLOAD_URL_DEFAULT.equals(location);
261282
default:
262283
return false;
263284
}
@@ -274,6 +295,8 @@ private String getInstallerFileName(
274295
return WLE_DOWNLOAD_FILENAME_DEFAULT;
275296
case SNAKE:
276297
return SNAKE_DOWNLOADED_FILENAME;
298+
case REMOTECONSOLE:
299+
return REMOTECONSOLE_DOWNLOAD_FILENAME_DEFAULT;
277300
default:
278301
return "";
279302
}

integration-tests/src/test/java/oracle/weblogic/kubernetes/utils/CommonTestUtils.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1197,6 +1197,36 @@ public static boolean installAndVerifyWlsLoggingExporter(String filter,
11971197
return true;
11981198
}
11991199

1200+
/**
1201+
* Install WebLogic Remote Console.
1202+
*
1203+
* @return true if WebLogic Remote Console is successfully installed, false otherwise.
1204+
*/
1205+
public static boolean installAndVerifyWlsRemoteConsole() {
1206+
1207+
assertThat(TestActions.installWlsRemoteConsole())
1208+
.as("WebLogic Remote Console installation succeeds")
1209+
.withFailMessage("WebLogic Remote Console installation failed")
1210+
.isTrue();
1211+
1212+
return true;
1213+
}
1214+
1215+
/**
1216+
* Shutdown WebLogic Remote Console.
1217+
*
1218+
* @return true if WebLogic Remote Console is successfully shutdown, false otherwise.
1219+
*/
1220+
public static boolean shutdownWlsRemoteConsole() {
1221+
1222+
assertThat(TestActions.shutdownWlsRemoteConsole())
1223+
.as("WebLogic Remote Console shutdown succeeds")
1224+
.withFailMessage("WebLogic Remote Console shutdown failed")
1225+
.isTrue();
1226+
1227+
return true;
1228+
}
1229+
12001230
/**
12011231
* Verify that the logging exporter is ready to use in Operator pod or WebLogic server pod.
12021232
*

0 commit comments

Comments
 (0)