12
12
import java .util .Map ;
13
13
import java .util .Optional ;
14
14
15
+ import io .kubernetes .client .openapi .models .V1Pod ;
15
16
import oracle .weblogic .kubernetes .annotations .IntegrationTest ;
16
17
import oracle .weblogic .kubernetes .annotations .Namespaces ;
17
18
import oracle .weblogic .kubernetes .logging .LoggingFacade ;
26
27
import static oracle .weblogic .kubernetes .TestConstants .ADMIN_USERNAME_DEFAULT ;
27
28
import static oracle .weblogic .kubernetes .TestConstants .K8S_NODEPORT_HOST ;
28
29
import static oracle .weblogic .kubernetes .TestConstants .MANAGED_SERVER_NAME_BASE ;
30
+ import static oracle .weblogic .kubernetes .TestConstants .OKE_CLUSTER ;
29
31
import static oracle .weblogic .kubernetes .TestConstants .WEBLOGIC_SLIM ;
30
32
import static oracle .weblogic .kubernetes .actions .ActionConstants .RESOURCE_DIR ;
31
33
import static oracle .weblogic .kubernetes .actions .TestActions .addLabelsToNamespace ;
34
+ import static oracle .weblogic .kubernetes .actions .TestActions .getPod ;
32
35
import static oracle .weblogic .kubernetes .utils .ApplicationUtils .checkAppUsingHostHeader ;
33
36
import static oracle .weblogic .kubernetes .utils .CommonMiiTestUtils .configIstioModelInImageDomain ;
34
37
import static oracle .weblogic .kubernetes .utils .CommonTestUtils .createTestWebAppWarFile ;
35
38
import static oracle .weblogic .kubernetes .utils .CommonTestUtils .generateNewModelFileWithUpdatedDomainUid ;
39
+ import static oracle .weblogic .kubernetes .utils .CommonTestUtils .getServiceExtIPAddrtOke ;
36
40
import static oracle .weblogic .kubernetes .utils .DeployUtil .deployToClusterUsingRest ;
41
+ import static oracle .weblogic .kubernetes .utils .DeployUtil .deployUsingRest ;
42
+ import static oracle .weblogic .kubernetes .utils .FileUtils .copyFileToPod ;
37
43
import static oracle .weblogic .kubernetes .utils .FileUtils .generateFileFromTemplate ;
38
44
import static oracle .weblogic .kubernetes .utils .ImageUtils .createMiiImageAndVerify ;
39
45
import static oracle .weblogic .kubernetes .utils .ImageUtils .imageRepoLoginAndPushImageToRegistry ;
40
46
import static oracle .weblogic .kubernetes .utils .IstioUtils .deployHttpIstioGatewayAndVirtualservice ;
41
47
import static oracle .weblogic .kubernetes .utils .IstioUtils .deployIstioDestinationRule ;
42
48
import static oracle .weblogic .kubernetes .utils .IstioUtils .getIstioHttpIngressPort ;
43
49
import static oracle .weblogic .kubernetes .utils .OperatorUtils .installAndVerifyOperator ;
50
+ import static oracle .weblogic .kubernetes .utils .PodUtils .execInPod ;
44
51
import static oracle .weblogic .kubernetes .utils .SessionMigrationUtil .getOrigModelFile ;
45
52
import static oracle .weblogic .kubernetes .utils .SessionMigrationUtil .getServerAndSessionInfoAndVerify ;
46
53
import static oracle .weblogic .kubernetes .utils .SessionMigrationUtil .shutdownServerAndVerify ;
54
61
55
62
@ DisplayName ("Test WLS Session Migration via istio enabled using Istio gateway" )
56
63
@ IntegrationTest
57
- @ Tag ("oke-parallel" )
58
64
@ Tag ("kind-parallel" )
59
65
@ Tag ("olcne" )
66
+ @ Tag ("oke-gate" )
60
67
class ItIstioGatewaySessionMigration {
61
68
62
69
private static String opNamespace = null ;
@@ -83,6 +90,9 @@ class ItIstioGatewaySessionMigration {
83
90
private static int istioIngressPort = 0 ;
84
91
private static String testWebAppWarLoc = null ;
85
92
93
+ private static final String istioNamespace = "istio-system" ;
94
+ private static final String istioIngressServiceName = "istio-ingressgateway" ;
95
+
86
96
private static LoggingFacade logger = null ;
87
97
88
98
/**
@@ -168,10 +178,18 @@ void testSessionMigrationIstioGateway() {
168
178
final String webServiceGetUrl = SESSMIGR_APP_WAR_NAME + "/?getCounter" ;
169
179
String serverName = managedServerPrefix + "1" ;
170
180
181
+ // In internal OKE env, use Istio EXTERNAL-IP; in non-OKE env, use K8S_NODEPORT_HOST + ":" + istioIngressPort
182
+ String istioIngressIP = getServiceExtIPAddrtOke (istioIngressServiceName , istioNamespace ) != null
183
+ ? getServiceExtIPAddrtOke (istioIngressServiceName , istioNamespace ) : K8S_NODEPORT_HOST ;
184
+
171
185
// send a HTTP request to set http session state(count number) and save HTTP session info
172
186
// before shutting down the primary server
173
- Map <String , String > httpDataInfo = getServerAndSessionInfoAndVerify (domainNamespace ,
174
- adminServerPodName , serverName , K8S_NODEPORT_HOST , istioIngressPort , webServiceSetUrl , " -c " );
187
+ // the NodePort services created by the operator are not usable, because they would expose ports
188
+ // on the worker node’s private IP addresses only, which are not reachable from outside the cluster
189
+ Map <String , String > httpDataInfo = OKE_CLUSTER ? getServerAndSessionInfoAndVerify (domainNamespace ,
190
+ adminServerPodName , serverName , istioIngressIP , 0 , webServiceSetUrl , " -c " )
191
+ : getServerAndSessionInfoAndVerify (domainNamespace ,
192
+ adminServerPodName , serverName , istioIngressIP , istioIngressPort , webServiceSetUrl , " -c " );
175
193
// get server and session info from web service deployed on the cluster
176
194
String origPrimaryServerName = httpDataInfo .get (primaryServerAttr );
177
195
String origSecondaryServerName = httpDataInfo .get (secondaryServerAttr );
@@ -186,8 +204,10 @@ void testSessionMigrationIstioGateway() {
186
204
187
205
// send a HTTP request to get server and session info after shutting down the primary server
188
206
serverName = domainUid + "-" + origSecondaryServerName ;
189
- httpDataInfo = getServerAndSessionInfoAndVerify (domainNamespace ,
190
- adminServerPodName , serverName , K8S_NODEPORT_HOST , istioIngressPort , webServiceGetUrl , " -b " );
207
+ httpDataInfo = OKE_CLUSTER ? getServerAndSessionInfoAndVerify (domainNamespace ,
208
+ adminServerPodName , serverName , istioIngressIP , 0 , webServiceGetUrl , " -b " )
209
+ : getServerAndSessionInfoAndVerify (domainNamespace ,
210
+ adminServerPodName , serverName , istioIngressIP , istioIngressPort , webServiceGetUrl , " -b " );
191
211
// get server and session info from web service deployed on the cluster
192
212
String primaryServerName = httpDataInfo .get (primaryServerAttr );
193
213
String sessionCreateTime = httpDataInfo .get (sessionCreateTimeAttr );
@@ -254,10 +274,15 @@ private static int configIstioGatewayModelInImageDomain(String miiImage,
254
274
int istioIngressPort = getIstioHttpIngressPort ();
255
275
logger .info ("Istio Ingress Port is {0}" , istioIngressPort );
256
276
277
+ // In internal OKE env, use Istio EXTERNAL-IP; in non-OKE env, use K8S_NODEPORT_HOST + ":" + istioIngressPort
278
+ String hostAndPort = getServiceExtIPAddrtOke (istioIngressServiceName , istioNamespace ) != null
279
+ ? getServiceExtIPAddrtOke (istioIngressServiceName , istioNamespace )
280
+ : K8S_NODEPORT_HOST + ":" + istioIngressPort ;
281
+
257
282
// We can not verify Rest Management console thru Adminstration NodePort
258
283
// in istio, as we can not enable Adminstration NodePort
259
284
if (!WEBLOGIC_SLIM ) {
260
- String consoleUrl = "http://" + K8S_NODEPORT_HOST + ":" + istioIngressPort + "/console/login/LoginForm.jsp" ;
285
+ String consoleUrl = "http://" + hostAndPort + "/console/login/LoginForm.jsp" ;
261
286
boolean checkConsole =
262
287
checkAppUsingHostHeader (consoleUrl , domainNamespace + ".org" );
263
288
assertTrue (checkConsole , "Failed to access WebLogic console" );
@@ -266,17 +291,51 @@ private static int configIstioGatewayModelInImageDomain(String miiImage,
266
291
logger .info ("Skipping WebLogic console in WebLogic slim image" );
267
292
}
268
293
269
- Path archivePath = Paths .get (testWebAppWarLoc );
270
294
ExecResult result = null ;
271
- result = deployToClusterUsingRest (K8S_NODEPORT_HOST ,
295
+ Path archivePath = Paths .get (testWebAppWarLoc );
296
+ // Use WebLogic restful management services to deploy Web App
297
+ if (OKE_CLUSTER ) {
298
+ // In internal OKE env, deploy App in domain pods using WLST
299
+ String destLocation = "/u01/testwebapp.war" ;
300
+
301
+ // Copy App archive to admin pod
302
+ assertDoesNotThrow (() -> copyFileToPod (domainNamespace ,
303
+ adminServerPodName , "" ,
304
+ archivePath ,
305
+ Paths .get (destLocation )));
306
+
307
+ // chown of App archive in admin pod
308
+ V1Pod adminPod = assertDoesNotThrow (() -> getPod (domainNamespace , null , adminServerPodName ));
309
+ execInPod (adminPod , null , true , "chown 1000:root " + destLocation );
310
+
311
+ for (int i = 1 ; i <= replicaCount ; i ++) {
312
+ // Copy App archive to managed server pod
313
+ String managedServerPodName = managedServerPrefix + i ;
314
+ assertDoesNotThrow (() -> copyFileToPod (domainNamespace ,
315
+ managedServerPodName , "" ,
316
+ archivePath ,
317
+ Paths .get (destLocation )));
318
+
319
+ // chown of App archive in managed server pod
320
+ V1Pod msPod = assertDoesNotThrow (() -> getPod (domainNamespace , null , managedServerPodName ));
321
+ execInPod (msPod , null , true , "chown 1000:root " + destLocation );
322
+ }
323
+
324
+ String target = "{identity: [clusters,'" + clusterName + "']}" ;
325
+ result = deployUsingRest (hostAndPort , ADMIN_USERNAME_DEFAULT , ADMIN_PASSWORD_DEFAULT ,
326
+ target , Paths .get (destLocation ), domainNamespace + ".org" , "testwebapp" );
327
+ assertNotNull (result , "Application deployment failed" );
328
+ } else {
329
+ result = deployToClusterUsingRest (K8S_NODEPORT_HOST ,
272
330
String .valueOf (istioIngressPort ),
273
331
ADMIN_USERNAME_DEFAULT , ADMIN_PASSWORD_DEFAULT ,
274
332
clusterName , archivePath , domainNamespace + ".org" , "testwebapp" );
275
- assertNotNull (result , "Application deployment failed" );
276
- logger .info ("Application deployment returned {0}" , result .toString ());
277
- assertEquals ("202" , result .stdout (), "Deployment didn't return HTTP status code 202" );
333
+ assertNotNull (result , "Application deployment failed" );
334
+ logger .info ("Application deployment returned {0}" , result .toString ());
335
+ assertEquals ("202" , result .stdout (), "Deployment didn't return HTTP status code 202" );
336
+ }
278
337
279
- String url = "http://" + K8S_NODEPORT_HOST + ":" + istioIngressPort + "/testwebapp/index.jsp" ;
338
+ String url = "http://" + hostAndPort + "/testwebapp/index.jsp" ;
280
339
logger .info ("Application Access URL {0}" , url );
281
340
282
341
return istioIngressPort ;
0 commit comments