1
- // Copyright (c) 2020, 2022, 2023 , Oracle and/or its affiliates.
1
+ // Copyright (c) 2020, 2024 , Oracle and/or its affiliates.
2
2
// Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
3
3
4
4
package oracle .weblogic .kubernetes ;
10
10
import java .nio .file .Path ;
11
11
import java .nio .file .Paths ;
12
12
import java .nio .file .StandardCopyOption ;
13
+ import java .util .ArrayList ;
13
14
import java .util .Arrays ;
14
15
import java .util .Collections ;
15
16
import java .util .List ;
16
17
import java .util .Properties ;
17
18
18
19
import io .kubernetes .client .openapi .models .V1EnvVar ;
20
+ import io .kubernetes .client .openapi .models .V1HTTPIngressPath ;
21
+ import io .kubernetes .client .openapi .models .V1HTTPIngressRuleValue ;
22
+ import io .kubernetes .client .openapi .models .V1IngressBackend ;
23
+ import io .kubernetes .client .openapi .models .V1IngressRule ;
24
+ import io .kubernetes .client .openapi .models .V1IngressServiceBackend ;
19
25
import io .kubernetes .client .openapi .models .V1LocalObjectReference ;
20
26
import io .kubernetes .client .openapi .models .V1ObjectMeta ;
27
+ import io .kubernetes .client .openapi .models .V1ServiceBackendPort ;
21
28
import oracle .weblogic .domain .AdminServer ;
22
29
import oracle .weblogic .domain .AdminService ;
23
30
import oracle .weblogic .domain .Channel ;
26
33
import oracle .weblogic .domain .DomainSpec ;
27
34
import oracle .weblogic .domain .Model ;
28
35
import oracle .weblogic .domain .ServerPod ;
36
+ import oracle .weblogic .kubernetes .actions .impl .NginxParams ;
37
+ import oracle .weblogic .kubernetes .actions .impl .Service ;
29
38
import oracle .weblogic .kubernetes .annotations .IntegrationTest ;
30
39
import oracle .weblogic .kubernetes .annotations .Namespaces ;
40
+ //import oracle.weblogic.kubernetes.assertions.TestAssertions;
31
41
import oracle .weblogic .kubernetes .logging .LoggingFacade ;
32
42
import oracle .weblogic .kubernetes .utils .ExecResult ;
33
43
import org .junit .jupiter .api .BeforeAll ;
34
44
import org .junit .jupiter .api .BeforeEach ;
35
45
import org .junit .jupiter .api .DisplayName ;
36
46
import org .junit .jupiter .api .Tag ;
37
47
import org .junit .jupiter .api .Test ;
48
+ import org .junit .jupiter .api .condition .DisabledIfEnvironmentVariable ;
38
49
39
50
import static oracle .weblogic .kubernetes .TestConstants .ADMIN_PASSWORD_DEFAULT ;
40
51
import static oracle .weblogic .kubernetes .TestConstants .ADMIN_USERNAME_DEFAULT ;
41
52
import static oracle .weblogic .kubernetes .TestConstants .DB_IMAGE_TO_USE_IN_SPEC ;
42
53
import static oracle .weblogic .kubernetes .TestConstants .DOMAIN_API_VERSION ;
43
54
import static oracle .weblogic .kubernetes .TestConstants .DOMAIN_VERSION ;
44
55
import static oracle .weblogic .kubernetes .TestConstants .IMAGE_PULL_POLICY ;
56
+ import static oracle .weblogic .kubernetes .TestConstants .K8S_NODEPORT_HOST ;
57
+ import static oracle .weblogic .kubernetes .TestConstants .OKE_CLUSTER ;
45
58
import static oracle .weblogic .kubernetes .TestConstants .RESULTS_ROOT ;
46
59
import static oracle .weblogic .kubernetes .TestConstants .TEST_IMAGES_REPO_SECRET_NAME ;
60
+ import static oracle .weblogic .kubernetes .TestConstants .WEBLOGIC_SLIM ;
47
61
import static oracle .weblogic .kubernetes .actions .ActionConstants .APP_DIR ;
48
62
import static oracle .weblogic .kubernetes .actions .ActionConstants .MODEL_DIR ;
49
63
import static oracle .weblogic .kubernetes .actions .ActionConstants .WORK_DIR ;
50
64
import static oracle .weblogic .kubernetes .actions .TestActions .createDomainCustomResource ;
51
65
import static oracle .weblogic .kubernetes .actions .TestActions .getPodIP ;
52
66
import static oracle .weblogic .kubernetes .actions .TestActions .getServiceNodePort ;
67
+ import static oracle .weblogic .kubernetes .actions .TestActions .listIngresses ;
53
68
import static oracle .weblogic .kubernetes .assertions .TestAssertions .domainExists ;
69
+ import static oracle .weblogic .kubernetes .utils .ApplicationUtils .callWebAppAndWaitTillReady ;
54
70
import static oracle .weblogic .kubernetes .utils .ApplicationUtils .checkAppIsActive ;
55
71
import static oracle .weblogic .kubernetes .utils .BuildApplication .buildApplication ;
56
72
import static oracle .weblogic .kubernetes .utils .CommonTestUtils .checkPodReadyAndServiceExists ;
73
+ import static oracle .weblogic .kubernetes .utils .CommonTestUtils .exeAppInServerPod ;
57
74
import static oracle .weblogic .kubernetes .utils .CommonTestUtils .getHostAndPort ;
58
75
import static oracle .weblogic .kubernetes .utils .CommonTestUtils .getNextFreePort ;
76
+ import static oracle .weblogic .kubernetes .utils .CommonTestUtils .getServiceExtIPAddrtOke ;
59
77
import static oracle .weblogic .kubernetes .utils .CommonTestUtils .testUntil ;
60
78
import static oracle .weblogic .kubernetes .utils .DbUtils .getDBNodePort ;
61
79
import static oracle .weblogic .kubernetes .utils .DbUtils .startOracleDB ;
66
84
import static oracle .weblogic .kubernetes .utils .ImageUtils .createImageAndVerify ;
67
85
import static oracle .weblogic .kubernetes .utils .ImageUtils .createTestRepoSecret ;
68
86
import static oracle .weblogic .kubernetes .utils .ImageUtils .imageRepoLoginAndPushImageToRegistry ;
87
+ import static oracle .weblogic .kubernetes .utils .LoadBalancerUtils .createIngressAndRetryIfFail ;
88
+ import static oracle .weblogic .kubernetes .utils .LoadBalancerUtils .installAndVerifyNginx ;
69
89
import static oracle .weblogic .kubernetes .utils .OKDUtils .createRouteForOKD ;
70
90
import static oracle .weblogic .kubernetes .utils .OperatorUtils .installAndVerifyOperator ;
71
91
import static oracle .weblogic .kubernetes .utils .PodUtils .getExternalServicePodName ;
72
92
import static oracle .weblogic .kubernetes .utils .PodUtils .setPodAntiAffinity ;
73
93
import static oracle .weblogic .kubernetes .utils .SecretUtils .createSecretWithUsernamePassword ;
74
94
import static oracle .weblogic .kubernetes .utils .ThreadSafeLogger .getLogger ;
95
+ import static org .assertj .core .api .Assertions .assertThat ;
75
96
import static org .junit .jupiter .api .Assertions .assertDoesNotThrow ;
97
+ import static org .junit .jupiter .api .Assertions .assertEquals ;
76
98
import static org .junit .jupiter .api .Assertions .assertNotEquals ;
77
99
import static org .junit .jupiter .api .Assertions .assertNotNull ;
78
100
import static org .junit .jupiter .api .Assertions .assertTrue ;
82
104
*/
83
105
@ DisplayName ("Verify cross domain transaction is successful" )
84
106
@ IntegrationTest
85
- @ Tag ("oke-parallel " )
107
+ @ Tag ("oke-gate " )
86
108
@ Tag ("kind-parallel" )
87
109
@ Tag ("okd-wls-srg" )
88
110
class ItCrossDomainTransaction {
@@ -122,13 +144,17 @@ class ItCrossDomainTransaction {
122
144
private static String dbPodIP = null ;
123
145
private static int dbPort = 1521 ;
124
146
147
+ private static String nginxNamespace = null ;
148
+ private static NginxParams nginxHelmParams = null ;
149
+ private static int nginxNodePort ;
150
+
125
151
/**
126
152
* Install Operator.
127
153
* @param namespaces list of namespaces created by the IntegrationTestWatcher by the
128
154
* JUnit engine parameter resolution mechanism
129
155
*/
130
156
@ BeforeAll
131
- public static void initAll (@ Namespaces (3 ) List <String > namespaces ) {
157
+ public static void initAll (@ Namespaces (4 ) List <String > namespaces ) {
132
158
logger = getLogger ();
133
159
134
160
// get a new unique opNamespace
@@ -144,6 +170,11 @@ public static void initAll(@Namespaces(3) List<String> namespaces) {
144
170
assertNotNull (namespaces .get (2 ), "Namespace list is null" );
145
171
domain2Namespace = namespaces .get (2 );
146
172
173
+ // get a unique Nginx namespace
174
+ logger .info ("Assign a unique namespace for Nginx" );
175
+ assertNotNull (namespaces .get (3 ), "Namespace list is null" );
176
+ nginxNamespace = namespaces .get (3 );
177
+
147
178
final int dbListenerPort = getNextFreePort ();
148
179
ORACLEDBSUFFIX = ".svc.cluster.local:" + dbListenerPort + "/devpdb.k8s" ;
149
180
dbUrl = ORACLEDBURLPREFIX + domain2Namespace + ORACLEDBSUFFIX ;
@@ -172,6 +203,13 @@ public static void initAll(@Namespaces(3) List<String> namespaces) {
172
203
173
204
// install and verify operator
174
205
installAndVerifyOperator (opNamespace , domain1Namespace , domain2Namespace );
206
+
207
+ if (OKE_CLUSTER ) {
208
+ logger .info ("Installing Nginx controller using helm" );
209
+ // install and verify Nginx
210
+ nginxHelmParams = installAndVerifyNginx (nginxNamespace , 0 , 0 );
211
+ }
212
+
175
213
buildApplicationsAndDomains ();
176
214
}
177
215
@@ -359,7 +397,13 @@ private static void buildApplicationsAndDomains() {
359
397
"Getting admin server node port failed" );
360
398
assertNotEquals (-1 , admin2ServiceNodePort , "admin server default node port is not valid" );
361
399
362
- hostAndPort = getHostAndPort (domain1AdminExtSvcRouteHost , domain1AdminServiceNodePort );
400
+ if (OKE_CLUSTER ) {
401
+ createNginxIngressPathRoutingRules ();
402
+ String nginxServiceName = nginxHelmParams .getHelmParams ().getReleaseName () + "-ingress-nginx-controller" ;
403
+ hostAndPort = getServiceExtIPAddrtOke (nginxServiceName , nginxNamespace );
404
+ } else {
405
+ hostAndPort = getHostAndPort (domain1AdminExtSvcRouteHost , domain1AdminServiceNodePort );
406
+ }
363
407
}
364
408
365
409
/*
@@ -414,6 +458,7 @@ void testCrossDomainTransaction() {
414
458
*/
415
459
@ Test
416
460
@ DisplayName ("Check cross domain transaction with TMAfterTLogBeforeCommitExit property commits" )
461
+ @ DisabledIfEnvironmentVariable (named = "OKE_CLUSTER" , matches = "true" )
417
462
void testCrossDomainTransactionWithFailInjection () {
418
463
419
464
String curlRequest = String .format ("curl -g -v --show-error --noproxy '*' "
@@ -499,8 +544,10 @@ private boolean checkLocalQueue() {
499
544
return true ;
500
545
}
501
546
502
- private static void createDomain (String domainUid , String domainNamespace , String adminSecretName ,
503
- String domainImage ) {
547
+ private static void createDomain (String domainUid ,
548
+ String domainNamespace ,
549
+ String adminSecretName ,
550
+ String domainImage ) {
504
551
// admin/managed server name here should match with model yaml in WDT_MODEL_FILE
505
552
final String adminServerPodName = domainUid + "-admin-server" ;
506
553
final String managedServerPrefix = domainUid + "-managed-server" ;
@@ -541,12 +588,41 @@ private static void createDomain(String domainUid, String domainNamespace, Strin
541
588
// The fail inject test case, the response to the curl command takes longer than the default timeout of 30s
542
589
// So, have to increase the proxy timeout for the route
543
590
String command = "oc -n " + domainNamespace + " annotate route "
544
- + getExternalServicePodName (adminServerPodName )
545
- + " --overwrite haproxy.router.openshift.io/timeout=600s" ;
591
+ + getExternalServicePodName (adminServerPodName )
592
+ + " --overwrite haproxy.router.openshift.io/timeout=600s" ;
546
593
logger .info ("command to set timeout = {0}" , command );
547
- assertDoesNotThrow (
548
- () -> exec (command , true ));
594
+ assertDoesNotThrow (() -> exec (command , true ));
595
+
596
+ logger .info ("Getting node port" );
597
+ int serviceNodePort = assertDoesNotThrow (() -> getServiceNodePort (domainNamespace ,
598
+ getExternalServicePodName (adminServerPodName ), "default" ),
599
+ "Getting admin server node port failed" );
549
600
601
+ if (!WEBLOGIC_SLIM ) {
602
+ logger .info ("Validating WebLogic admin console" );
603
+ String resourcePath = "/console/login/LoginForm.jsp" ;
604
+ ExecResult result = exeAppInServerPod (domainNamespace , adminServerPodName ,7001 , resourcePath );
605
+ logger .info ("result in OKE_CLUSTER is {0}" , result .toString ());
606
+ assertEquals (0 , result .exitValue (), "Failed to access WebLogic console" );
607
+
608
+ /*
609
+ if (OKE_CLUSTER) {
610
+ String resourcePath = "/console/login/LoginForm.jsp";
611
+ ExecResult result = exeAppInServerPod(domainNamespace, adminServerPodName,7001, resourcePath);
612
+ logger.info("result in OKE_CLUSTER is {0}", result.toString());
613
+ assertEquals(0, result.exitValue(), "Failed to access WebLogic console");
614
+ } else {
615
+ testUntil(
616
+ assertDoesNotThrow(() -> {
617
+ return TestAssertions.adminNodePortAccessible(serviceNodePort,
618
+ ADMIN_USERNAME_DEFAULT, ADMIN_PASSWORD_DEFAULT, adminExtSvcRouteHost);
619
+ }, "Access to admin server node port failed"),
620
+ logger,
621
+ "Console login validation");
622
+ }*/
623
+ } else {
624
+ logger .info ("Skipping WebLogic Console check for Weblogic slim images" );
625
+ }
550
626
}
551
627
552
628
private static void createDomainResource (String domainUid , String domNamespace , String adminSecretName ,
@@ -599,4 +675,57 @@ private static void createDomainResource(String domainUid, String domNamespace,
599
675
assertTrue (domCreated , String .format ("Create domain custom resource failed with ApiException "
600
676
+ "for %s in namespace %s" , domainUid , domNamespace ));
601
677
}
678
+
679
+ private static void createNginxIngressPathRoutingRules () {
680
+ // create an ingress in domain namespace
681
+ final int ADMIN_SERVER_PORT = 7001 ;
682
+ String ingressName = domain1Namespace + "-nginx-path-routing" ;
683
+ String ingressClassName = nginxHelmParams .getIngressClassName ();
684
+
685
+ // create ingress rules for two domains
686
+ List <V1IngressRule > ingressRules = new ArrayList <>();
687
+ List <V1HTTPIngressPath > httpIngressPaths = new ArrayList <>();
688
+
689
+ V1HTTPIngressPath httpIngressPath = new V1HTTPIngressPath ()
690
+ .path ("/" )
691
+ .pathType ("Prefix" )
692
+ .backend (new V1IngressBackend ()
693
+ .service (new V1IngressServiceBackend ()
694
+ .name (domainUid1 + "-admin-server" )
695
+ .port (new V1ServiceBackendPort ()
696
+ .number (ADMIN_SERVER_PORT )))
697
+ );
698
+ httpIngressPaths .add (httpIngressPath );
699
+
700
+ V1IngressRule ingressRule = new V1IngressRule ()
701
+ .host ("" )
702
+ .http (new V1HTTPIngressRuleValue ()
703
+ .paths (httpIngressPaths ));
704
+
705
+ ingressRules .add (ingressRule );
706
+
707
+ createIngressAndRetryIfFail (60 , false , ingressName , domain1Namespace , null , ingressClassName , ingressRules , null );
708
+
709
+ // check the ingress was found in the domain namespace
710
+ assertThat (assertDoesNotThrow (() -> listIngresses (domain1Namespace )))
711
+ .as (String .format ("Test ingress %s was found in namespace %s" , ingressName , domain1Namespace ))
712
+ .withFailMessage (String .format ("Ingress %s was not found in namespace %s" , ingressName , domain1Namespace ))
713
+ .contains (ingressName );
714
+
715
+ logger .info ("ingress {0} was created in namespace {1}" , ingressName , domain1Namespace );
716
+
717
+ // check the ingress is ready to route the app to the server pod
718
+ String nginxServiceName = nginxHelmParams .getHelmParams ().getReleaseName () + "-ingress-nginx-controller" ;
719
+ nginxNodePort = assertDoesNotThrow (() -> Service .getServiceNodePort (nginxNamespace , nginxServiceName , "http" ),
720
+ "Getting Nginx loadbalancer service node port failed" );
721
+
722
+ String hostAndPort = getServiceExtIPAddrtOke (nginxServiceName , nginxNamespace ) != null
723
+ ? getServiceExtIPAddrtOke (nginxServiceName , nginxNamespace ) : K8S_NODEPORT_HOST + ":" + nginxNodePort ;
724
+
725
+ String curlCmd = "curl -g --silent --show-error --noproxy '*' http://" + hostAndPort
726
+ + "/weblogic/ready --write-out %{http_code} -o /dev/null" ;
727
+
728
+ logger .info ("Executing curl command {0}" , curlCmd );
729
+ assertTrue (callWebAppAndWaitTillReady (curlCmd , 60 ));
730
+ }
602
731
}
0 commit comments