Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2021, Oracle and/or its affiliates.
// Copyright (c) 2021, 2022, Oracle and/or its affiliates.
// Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.

package oracle.weblogic.kubernetes;
Expand Down Expand Up @@ -31,25 +31,23 @@

import static java.util.concurrent.TimeUnit.MINUTES;
import static java.util.concurrent.TimeUnit.SECONDS;
import static oracle.weblogic.kubernetes.TestConstants.ADMIN_PASSWORD_DEFAULT;
import static oracle.weblogic.kubernetes.TestConstants.ADMIN_SERVER_NAME_BASE;
import static oracle.weblogic.kubernetes.TestConstants.ADMIN_USERNAME_DEFAULT;
import static oracle.weblogic.kubernetes.TestConstants.K8S_NODEPORT_HOST;
import static oracle.weblogic.kubernetes.TestConstants.MANAGED_SERVER_NAME_BASE;
import static oracle.weblogic.kubernetes.TestConstants.MII_BASIC_IMAGE_NAME;
import static oracle.weblogic.kubernetes.TestConstants.MII_BASIC_IMAGE_TAG;
import static oracle.weblogic.kubernetes.TestConstants.RESULTS_ROOT;
import static oracle.weblogic.kubernetes.TestConstants.VOYAGER_CHART_NAME;
import static oracle.weblogic.kubernetes.actions.ActionConstants.RESOURCE_DIR;
import static oracle.weblogic.kubernetes.actions.TestActions.createIngress;
import static oracle.weblogic.kubernetes.actions.TestActions.listIngresses;
import static oracle.weblogic.kubernetes.actions.impl.Service.getServiceNodePort;
import static oracle.weblogic.kubernetes.assertions.TestAssertions.isVoyagerReady;
import static oracle.weblogic.kubernetes.utils.ApplicationUtils.callWebAppAndWaitTillReady;
import static oracle.weblogic.kubernetes.utils.ApplicationUtils.callWebAppAndWaitTillReturnedCode;
import static oracle.weblogic.kubernetes.utils.CommonMiiTestUtils.createMiiDomainAndVerify;
import static oracle.weblogic.kubernetes.utils.LoadBalancerUtils.createIngressAndRetryIfFail;
import static oracle.weblogic.kubernetes.utils.LoadBalancerUtils.installAndVerifyNginx;
import static oracle.weblogic.kubernetes.utils.LoadBalancerUtils.installAndVerifyTraefik;
import static oracle.weblogic.kubernetes.utils.LoadBalancerUtils.installAndVerifyVoyager;
import static oracle.weblogic.kubernetes.utils.OperatorUtils.installAndVerifyOperator;
import static oracle.weblogic.kubernetes.utils.PodUtils.getExternalServicePodName;
import static oracle.weblogic.kubernetes.utils.ThreadSafeLogger.getLogger;
Expand All @@ -68,12 +66,9 @@ class ItRemoteConsole {

private static String domainNamespace = null;
private static String traefikNamespace = null;
private static String voyagerNamespace = null;
private static String nginxNamespace = null;
private static HelmParams traefikHelmParams = null;
private static HelmParams voyagerHelmParams = null;
private static HelmParams nginxHelmParams = null;
private static int voyagerNodePort;
private static int nginxNodePort;

// domain constants
Expand All @@ -83,8 +78,7 @@ class ItRemoteConsole {
private static final String managedServerPrefix = domainUid + "-" + MANAGED_SERVER_NAME_BASE;
private static LoggingFacade logger = null;
private static final int ADMIN_SERVER_PORT = 7001;
private static final String voyagerIngressName = "voyager-path-routing";


private static ConditionFactory withStandardRetryPolicy =
with().pollDelay(2, SECONDS)
.and().with().pollInterval(10, SECONDS)
Expand All @@ -97,7 +91,7 @@ class ItRemoteConsole {
* JUnit engine parameter resolution mechanism
*/
@BeforeAll
public static void initAll(@Namespaces(5) List<String> namespaces) {
public static void initAll(@Namespaces(4) List<String> namespaces) {
logger = getLogger();
// get a unique operator namespace
logger.info("Getting a unique namespace for operator");
Expand All @@ -113,15 +107,10 @@ public static void initAll(@Namespaces(5) List<String> namespaces) {
assertNotNull(namespaces.get(2), "Namespace list is null");
traefikNamespace = namespaces.get(2);

// get a unique Voyager namespace
logger.info("Assign a unique namespace for Voyager");
assertNotNull(namespaces.get(3), "Namespace list is null");
voyagerNamespace = namespaces.get(3);

// get a unique Nginx namespace
logger.info("Assign a unique namespace for Nginx");
assertNotNull(namespaces.get(4), "Namespace list is null");
nginxNamespace = namespaces.get(4);
assertNotNull(namespaces.get(3), "Namespace list is null");
nginxNamespace = namespaces.get(3);

// install and verify operator
installAndVerifyOperator(opNamespace, domainNamespace);
Expand All @@ -130,12 +119,6 @@ public static void initAll(@Namespaces(5) List<String> namespaces) {
logger.info("Installing Traefik controller using helm");
traefikHelmParams = installAndVerifyTraefik(traefikNamespace, 0, 0);

// install and verify Voyager
final String cloudProvider = "baremetal";
final boolean enableValidatingWebhook = false;
voyagerHelmParams =
installAndVerifyVoyager(voyagerNamespace, cloudProvider, enableValidatingWebhook);

// install and verify Nginx
nginxHelmParams = installAndVerifyNginx(nginxNamespace, 0, 0);

Expand All @@ -148,9 +131,8 @@ public static void initAll(@Namespaces(5) List<String> namespaces) {
managedServerPrefix,
replicaCount);

// create ingress rules with path routing for Traefik, Voyager and NGINX
// create ingress rules with path routing for Traefik, and NGINX
createTraefikIngressRoutingRules(domainNamespace);
createVoyagerIngressPathRoutingRules();
createNginxIngressPathRoutingRules();

// install WebLogic remote console
Expand All @@ -161,7 +143,7 @@ public static void initAll(@Namespaces(5) List<String> namespaces) {
}

/**
* Verify k8s WebLogic domain is accessible through remote console using Traefik.
* Access WebLogic domain through remote console using Traefik.
*/
@Test
@DisplayName("Verify Connecting to Mii domain WLS Remote Console through Traefik is successful")
Expand All @@ -172,37 +154,12 @@ void testWlsRemoteConsoleConnectionThroughTraefik() {
"Could not get the default external service node port");
logger.info("Found the Traefik service nodePort {0}", traefikNodePort);
logger.info("The K8S_NODEPORT_HOST is {0}", K8S_NODEPORT_HOST);
String curlCmd = "curl -v --user weblogic:welcome1 -H Content-Type:application/json -d "
+ "\"{ \\" + "\"domainUrl\\" + "\"" + ": " + "\\" + "\"" + "http://"
+ K8S_NODEPORT_HOST + ":" + traefikNodePort + "\\" + "\" }" + "\""
+ " http://localhost:8012/api/connection --write-out %{http_code} -o /dev/null";
logger.info("Executing Traefik nodeport curl command {0}", curlCmd);
assertTrue(callWebAppAndWaitTillReturnedCode(curlCmd, "201", 10), "Calling web app failed");
verifyRemoteConsoleConnectionThroughLB(traefikNodePort);
logger.info("WebLogic domain is accessible through remote console using Traefik");
}

/**
* Verify k8s WebLogic domain is accessible through remote console using Voyager.
*/
@Test
@DisplayName("Verify Connecting to Mii domain WLS Remote Console through Voyager is successful")
void testWlsRemoteConsoleConnectionThroughVoyager() {

assertTrue(voyagerNodePort != -1, "Could not get the default external service node port");
logger.info("Found the Voyager service nodePort {0}", voyagerNodePort);
logger.info("The K8S_NODEPORT_HOST is {0}", K8S_NODEPORT_HOST);

String curlCmd = "curl -v --user weblogic:welcome1 -H Content-Type:application/json -d "
+ "\"{ \\" + "\"domainUrl\\" + "\"" + ": " + "\\" + "\"" + "http://"
+ K8S_NODEPORT_HOST + ":" + voyagerNodePort + "\\" + "\" }" + "\""
+ " http://localhost:8012/api/connection --write-out %{http_code} -o /dev/null";
logger.info("Executing Voyager nodeport curl command {0}", curlCmd);
assertTrue(callWebAppAndWaitTillReturnedCode(curlCmd, "201", 10), "Calling web app failed");
logger.info("WebLogic domain is accessible through remote console using Voyager");
}

/**
* Verify k8s WebLogic domain is accessible through remote console using NGINX.
* Access WebLogic domain through remote console using NGINX.
*/
@Test
@DisplayName("Verify Connecting to Mii domain WLS Remote Console through NGINX is successful")
Expand All @@ -212,12 +169,7 @@ void testWlsRemoteConsoleConnectionThroughNginx() {
logger.info("Found the NGINX service nodePort {0}", nginxNodePort);
logger.info("The K8S_NODEPORT_HOST is {0}", K8S_NODEPORT_HOST);

String curlCmd = "curl -v --user weblogic:welcome1 -H Content-Type:application/json -d "
+ "\"{ \\" + "\"domainUrl\\" + "\"" + ": " + "\\" + "\"" + "http://"
+ K8S_NODEPORT_HOST + ":" + nginxNodePort + "\\" + "\" }" + "\""
+ " http://localhost:8012/api/connection --write-out %{http_code} -o /dev/null";
logger.info("Executing NGINX nodeport curl command {0}", curlCmd);
assertTrue(callWebAppAndWaitTillReturnedCode(curlCmd, "201", 10), "Calling web app failed");
verifyRemoteConsoleConnectionThroughLB(nginxNodePort);
logger.info("WebLogic domain is accessible through remote console using NGINX");
}

Expand Down Expand Up @@ -258,64 +210,6 @@ private static void createTraefikIngressRoutingRules(String domainNamespace) {
}
}

private static void createVoyagerIngressPathRoutingRules() {

// set the annotations for Voyager
HashMap<String, String> annotations = new HashMap<>();
annotations.put("ingress.appscode.com/type", "NodePort");
annotations.put("kubernetes.io/ingress.class", "voyager");
annotations.put("ingress.appscode.com/rewrite-target", "/");

List<NetworkingV1beta1IngressRule> ingressRules = new ArrayList<>();
List<NetworkingV1beta1HTTPIngressPath> httpIngressPaths = new ArrayList<>();

NetworkingV1beta1HTTPIngressPath httpIngressPath = new NetworkingV1beta1HTTPIngressPath()
.path("/")
.backend(new NetworkingV1beta1IngressBackend()
.serviceName(domainUid + "-admin-server")
.servicePort(new IntOrString(ADMIN_SERVER_PORT))
);
httpIngressPaths.add(httpIngressPath);

NetworkingV1beta1IngressRule ingressRule = new NetworkingV1beta1IngressRule()
.host("")
.http(new NetworkingV1beta1HTTPIngressRuleValue()
.paths(httpIngressPaths));

ingressRules.add(ingressRule);

assertDoesNotThrow(() -> createIngress(voyagerIngressName, domainNamespace, annotations, ingressRules, null));

// wait until voyager ingress pod is ready
withStandardRetryPolicy
.conditionEvaluationListener(
condition -> logger.info(
"Waiting for Voyager ingress to be ready in namespace {0} (elapsed time {1}ms, remaining time {2}ms)",
domainNamespace,
condition.getElapsedTimeInMS(),
condition.getRemainingTimeInMS()))
.until(assertDoesNotThrow(() -> isVoyagerReady(domainNamespace, voyagerIngressName),
"isVoyagerReady failed with ApiException"));

// check the ingress was found in the domain namespace
assertThat(assertDoesNotThrow(() -> listIngresses(domainNamespace)))
.as(String.format("Test ingress %s was found in namespace %s", voyagerIngressName, domainNamespace))
.withFailMessage(String.format("Ingress %s was not found in namespace %s", voyagerIngressName, domainNamespace))
.contains(voyagerIngressName);

logger.info("ingress {0} was created in namespace {1}", voyagerIngressName, domainNamespace);

// check the ingress is ready to route the app to the server pod
voyagerNodePort = assertDoesNotThrow(() ->
getServiceNodePort(domainNamespace, VOYAGER_CHART_NAME + "-" + voyagerIngressName, "tcp-80"),
"Getting voyager loadbalancer service node port failed");
String curlCmd = "curl --silent --show-error --noproxy '*' http://" + K8S_NODEPORT_HOST + ":" + voyagerNodePort
+ "/weblogic/ready --write-out %{http_code} -o /dev/null";

logger.info("Executing curl command {0}", curlCmd);
assertTrue(callWebAppAndWaitTillReady(curlCmd, 60));
}

private static void createNginxIngressPathRoutingRules() {

// create an ingress in domain namespace
Expand Down Expand Up @@ -372,12 +266,45 @@ private static void verifyWlsRemoteConsoleConnection() {
"Could not get the default external service node port");
logger.info("Found the default service nodePort {0}", nodePort);
logger.info("The K8S_NODEPORT_HOST is {0}", K8S_NODEPORT_HOST);
String curlCmd = "curl -v --user weblogic:welcome1 -H Content-Type:application/json -d "
+ "\"{ \\" + "\"domainUrl\\" + "\"" + ": " + "\\" + "\"" + "http://"
+ K8S_NODEPORT_HOST + ":" + nodePort + "\\" + "\" }" + "\""
+ " http://localhost:8012/api/connection --write-out %{http_code} -o /dev/null";


//The final complete curl command to run is like:
//curl -v --show-error --user username:password http://localhost:8012/api/providers/AdminServerConnection -H
//"Content-Type:application/json" --data "{ \"name\": \"asconn\", \"domainUrl\": \"http://myhost://nodeport\"}"
//--write-out %{http_code} -o /dev/null
String curlCmd = "curl -v --show-error --noproxy '*' --user "
+ ADMIN_USERNAME_DEFAULT + ":" + ADMIN_PASSWORD_DEFAULT
+ " http://localhost:8012/api/providers/AdminServerConnection -H "
+ "\"" + "Content-Type:application/json" + "\""
+ " --data "
+ "\"{\\" + "\"name\\" + "\"" + ": " + "\\" + "\"" + "asconn\\" + "\"" + ", "
+ "\\" + "\"domainUrl\\" + "\"" + ": " + "\\" + "\"" + "http://"
+ K8S_NODEPORT_HOST + ":" + nodePort + "\\" + "\"}" + "\""
+ " --write-out %{http_code} -o /dev/null";
logger.info("Executing default nodeport curl command {0}", curlCmd);
assertTrue(callWebAppAndWaitTillReturnedCode(curlCmd, "201", 10), "Calling web app failed");
logger.info("WebLogic domain is accessible through remote console");
}

private static void verifyRemoteConsoleConnectionThroughLB(int nodePortOfLB) {
logger.info("LB nodePort is {0}", nodePortOfLB);
logger.info("The K8S_NODEPORT_HOST is {0}", K8S_NODEPORT_HOST);

//The final complete curl command to run is like:
//curl -v --user username:password http://localhost:8012/api/providers/AdminServerConnection -H
//"Content-Type:application/json" --data "{ \"name\": \"asconn\", \"domainUrl\": \"http://myhost://nodeport\"}"
//--write-out %{http_code} -o /dev/null
String curlCmd = "curl -v --user " + ADMIN_USERNAME_DEFAULT + ":" + ADMIN_PASSWORD_DEFAULT
+ " http://localhost:8012/api/providers/AdminServerConnection -H "
+ "\"" + "Content-Type:application/json" + "\""
+ " --data "
+ "\"{ \\" + "\"name\\" + "\"" + ": " + "\\" + "\"" + "asconn\\" + "\"" + ", "
+ "\\" + "\"" + "domainUrl\\" + "\"" + ": " + "\\" + "\"" + "http://"
+ K8S_NODEPORT_HOST + ":" + nodePortOfLB + "\\" + "\" }" + "\""
+ " --write-out %{http_code} -o /dev/null";
logger.info("Executing LB nodeport curl command {0}", curlCmd);
assertTrue(callWebAppAndWaitTillReturnedCode(curlCmd, "201", 10),
"Calling web app failed");
}

}