From 7df5cbb41f7673012bb6f8d13215facd8df3fe87 Mon Sep 17 00:00:00 2001 From: huiling_zhao Date: Wed, 13 Nov 2024 17:47:05 +0000 Subject: [PATCH] forward port 2 MRs from R42 to Main --- .../kubernetes/ItIstioDBOperator.java | 25 ++++++++++++---- .../kubernetes/utils/ApplicationUtils.java | 29 +++++++++++++++++++ .../kubernetes/utils/CommonLBTestUtils.java | 6 ++++ .../kubernetes/utils/LoadBalancerUtils.java | 7 ++++- 4 files changed, 61 insertions(+), 6 deletions(-) diff --git a/integration-tests/src/test/java/oracle/weblogic/kubernetes/ItIstioDBOperator.java b/integration-tests/src/test/java/oracle/weblogic/kubernetes/ItIstioDBOperator.java index 6b614c28df1..10d0b8bca87 100644 --- a/integration-tests/src/test/java/oracle/weblogic/kubernetes/ItIstioDBOperator.java +++ b/integration-tests/src/test/java/oracle/weblogic/kubernetes/ItIstioDBOperator.java @@ -74,6 +74,7 @@ import static oracle.weblogic.kubernetes.utils.CommonTestUtils.createTestWebAppWarFile; import static oracle.weblogic.kubernetes.utils.CommonTestUtils.formatIPv6Host; import static oracle.weblogic.kubernetes.utils.CommonTestUtils.getHostAndPort; +import static oracle.weblogic.kubernetes.utils.CommonTestUtils.getServiceExtIPAddrtOke; import static oracle.weblogic.kubernetes.utils.CommonTestUtils.getUniqueName; import static oracle.weblogic.kubernetes.utils.CommonTestUtils.runClientInsidePod; import static oracle.weblogic.kubernetes.utils.CommonTestUtils.runJavacInsidePod; @@ -139,6 +140,9 @@ class ItIstioDBOperator { private static String hostHeader; Map httpHeaders; + private static final String istioNamespace = "istio-system"; + private static final String istioIngressServiceName = "istio-ingressgateway"; + /** * Start DB service and create RCU schema. * Assigns unique namespaces for operator and domains. @@ -418,7 +422,11 @@ private void runJmsClientOnAdminPod(String action, String queue) { * @returns true if MBean is found otherwise false **/ private boolean checkJmsServerRuntime(String jmsServer, String managedServer) throws UnknownHostException { - String hostAndPort = getHostAndPort(adminSvcExtRouteHost, wlDomainIstioIngressPort); + // In internal OKE env, use Istio EXTERNAL-IP; in non-OKE env, use K8S_NODEPORT_HOST + ":" + istioIngressPort + String hostAndPort = getServiceExtIPAddrtOke(istioIngressServiceName, istioNamespace) != null + ? getServiceExtIPAddrtOke(istioIngressServiceName, istioNamespace) + : getHostAndPort(adminSvcExtRouteHost, wlDomainIstioIngressPort); + if (!TestConstants.WLSIMG_BUILDER.equals(TestConstants.WLSIMG_BUILDER_DEFAULT)) { hostAndPort = formatIPv6Host(InetAddress.getLocalHost().getHostAddress()) + ":" + ISTIO_HTTP_HOSTPORT; } @@ -437,7 +445,10 @@ private boolean checkJmsServerRuntime(String jmsServer, String managedServer) th * @returns true if MBean is found otherwise false **/ private boolean checkStoreRuntime(String storeName, String managedServer) throws UnknownHostException { - String hostAndPort = getHostAndPort(adminSvcExtRouteHost, wlDomainIstioIngressPort); + String hostAndPort = getServiceExtIPAddrtOke(istioIngressServiceName, istioNamespace) != null + ? getServiceExtIPAddrtOke(istioIngressServiceName, istioNamespace) + : getHostAndPort(adminSvcExtRouteHost, wlDomainIstioIngressPort); + if (!TestConstants.WLSIMG_BUILDER.equals(TestConstants.WLSIMG_BUILDER_DEFAULT)) { hostAndPort = formatIPv6Host(InetAddress.getLocalHost().getHostAddress()) + ":" + ISTIO_HTTP_HOSTPORT; } @@ -458,9 +469,13 @@ private boolean checkStoreRuntime(String storeName, String managedServer) throws * @returns true if MBean is found otherwise false **/ private boolean checkJtaRecoveryServiceRuntime(String managedServer, - String recoveryService, String active) throws UnknownHostException { - - String hostAndPort = getHostAndPort(adminSvcExtRouteHost, wlDomainIstioIngressPort); + String recoveryService, + String active) throws UnknownHostException { + + String hostAndPort = getServiceExtIPAddrtOke(istioIngressServiceName, istioNamespace) != null + ? getServiceExtIPAddrtOke(istioIngressServiceName, istioNamespace) + : getHostAndPort(adminSvcExtRouteHost, wlDomainIstioIngressPort); + if (!TestConstants.WLSIMG_BUILDER.equals(TestConstants.WLSIMG_BUILDER_DEFAULT)) { hostAndPort = formatIPv6Host(InetAddress.getLocalHost().getHostAddress()) + ":" + ISTIO_HTTP_HOSTPORT; } diff --git a/integration-tests/src/test/java/oracle/weblogic/kubernetes/utils/ApplicationUtils.java b/integration-tests/src/test/java/oracle/weblogic/kubernetes/utils/ApplicationUtils.java index 300f365f113..852233e95f9 100644 --- a/integration-tests/src/test/java/oracle/weblogic/kubernetes/utils/ApplicationUtils.java +++ b/integration-tests/src/test/java/oracle/weblogic/kubernetes/utils/ApplicationUtils.java @@ -8,6 +8,7 @@ import java.nio.file.Paths; import java.util.HashMap; import java.util.List; +import java.util.concurrent.Callable; import oracle.weblogic.kubernetes.logging.LoggingFacade; import org.awaitility.core.ConditionFactory; @@ -350,6 +351,34 @@ public static boolean callWebAppAndCheckForServerNameInResponse( return false; } + /** + * Call a web app and wait for the response code 200. + * @param curlCmd curl command to call the web app + * @return true if 200 response code is returned, false otherwise + */ + public static Callable callWebAppAndWaitTillReady(String curlCmd) { + LoggingFacade logger = getLogger(); + String httpStatusCode = "200"; + + return () -> { + final ExecResult result = ExecCommand.exec(curlCmd); + final String responseCode = result.stdout().trim(); + + if (result != null) { + logger.info("result.stdout: \n{0}", result.stdout()); + logger.info("result.stderr: \n{0}", result.stderr()); + logger.info("result.exitValue: \n{0}", result.exitValue()); + } + + if (result.exitValue() != 0 || !responseCode.equals(httpStatusCode)) { + logger.info("callWebApp did not return {0} response code, got {1}", httpStatusCode, responseCode); + return false; + } + + return true; + }; + } + /** * Call a web app and wait for the response code 200. * @param curlCmd curl command to call the web app diff --git a/integration-tests/src/test/java/oracle/weblogic/kubernetes/utils/CommonLBTestUtils.java b/integration-tests/src/test/java/oracle/weblogic/kubernetes/utils/CommonLBTestUtils.java index bc55a364eaa..5e465ac46e2 100644 --- a/integration-tests/src/test/java/oracle/weblogic/kubernetes/utils/CommonLBTestUtils.java +++ b/integration-tests/src/test/java/oracle/weblogic/kubernetes/utils/CommonLBTestUtils.java @@ -913,6 +913,12 @@ public static void verifyAdminServerAccess(boolean isTLS, consoleAccessible = true; break; } + + try { + Thread.sleep(5000); + } catch (InterruptedException ignore) { + // ignore + } } catch (IOException | InterruptedException ex) { getLogger().severe(ex.getMessage()); } diff --git a/integration-tests/src/test/java/oracle/weblogic/kubernetes/utils/LoadBalancerUtils.java b/integration-tests/src/test/java/oracle/weblogic/kubernetes/utils/LoadBalancerUtils.java index ad4a2116085..95072202522 100644 --- a/integration-tests/src/test/java/oracle/weblogic/kubernetes/utils/LoadBalancerUtils.java +++ b/integration-tests/src/test/java/oracle/weblogic/kubernetes/utils/LoadBalancerUtils.java @@ -71,7 +71,7 @@ import static oracle.weblogic.kubernetes.utils.CommonTestUtils.checkServiceExists; import static oracle.weblogic.kubernetes.utils.CommonTestUtils.getHostAndPort; import static oracle.weblogic.kubernetes.utils.CommonTestUtils.testUntil; -//import static oracle.weblogic.kubernetes.utils.CommonTestUtils.verifyCommandResultContainsMsg; +import static oracle.weblogic.kubernetes.utils.CommonTestUtils.withLongRetryPolicy; import static oracle.weblogic.kubernetes.utils.ExecCommand.exec; import static oracle.weblogic.kubernetes.utils.ImageUtils.createTestRepoSecret; import static oracle.weblogic.kubernetes.utils.ThreadSafeLogger.getLogger; @@ -743,6 +743,11 @@ public static void createNginxIngressPathRoutingRules(String domainNamespace, + "/weblogic/ready --write-out %{http_code} -o /dev/null"; logger.info("Executing curl command {0}", curlCmd); + testUntil( + withLongRetryPolicy, + callWebAppAndWaitTillReady(curlCmd), + logger, + "Waiting until Web App available"); assertTrue(callWebAppAndWaitTillReady(curlCmd, 60)); }