3
3
4
4
package oracle .verrazzano .weblogic .kubernetes ;
5
5
6
+ import java .util .ArrayList ;
6
7
import java .util .Arrays ;
8
+ import java .util .Collections ;
7
9
import java .util .HashMap ;
8
10
import java .util .List ;
9
11
import java .util .Map ;
25
27
import oracle .verrazzano .weblogic .WorkloadSpec ;
26
28
import oracle .verrazzano .weblogic .kubernetes .annotations .VzIntegrationTest ;
27
29
import oracle .weblogic .domain .DomainResource ;
30
+ import oracle .weblogic .kubernetes .actions .impl .primitive .Command ;
31
+ import oracle .weblogic .kubernetes .actions .impl .primitive .CommandParams ;
32
+ import oracle .weblogic .kubernetes .actions .impl .primitive .WitParams ;
28
33
import oracle .weblogic .kubernetes .annotations .Namespaces ;
29
34
import oracle .weblogic .kubernetes .logging .LoggingFacade ;
30
35
import org .junit .jupiter .api .BeforeAll ;
33
38
import org .junit .jupiter .api .Test ;
34
39
35
40
import static oracle .weblogic .kubernetes .TestConstants .ADMIN_PASSWORD_DEFAULT ;
41
+ import static oracle .weblogic .kubernetes .TestConstants .ADMIN_SERVER_NAME_BASE ;
36
42
import static oracle .weblogic .kubernetes .TestConstants .ADMIN_USERNAME_DEFAULT ;
43
+ import static oracle .weblogic .kubernetes .TestConstants .MANAGED_SERVER_NAME_BASE ;
44
+ import static oracle .weblogic .kubernetes .TestConstants .MII_AUXILIARY_IMAGE_NAME ;
45
+ import static oracle .weblogic .kubernetes .TestConstants .MII_BASIC_APP_NAME ;
37
46
import static oracle .weblogic .kubernetes .TestConstants .MII_BASIC_IMAGE_NAME ;
38
47
import static oracle .weblogic .kubernetes .TestConstants .MII_BASIC_IMAGE_TAG ;
48
+ import static oracle .weblogic .kubernetes .TestConstants .MII_BASIC_WDT_MODEL_FILE ;
39
49
import static oracle .weblogic .kubernetes .TestConstants .TEST_IMAGES_REPO_SECRET_NAME ;
50
+ import static oracle .weblogic .kubernetes .TestConstants .WEBLOGIC_IMAGE_TO_USE_IN_SPEC ;
51
+ import static oracle .weblogic .kubernetes .actions .ActionConstants .ARCHIVE_DIR ;
52
+ import static oracle .weblogic .kubernetes .actions .ActionConstants .MODEL_DIR ;
53
+ import static oracle .weblogic .kubernetes .actions .TestActions .buildAppArchive ;
54
+ import static oracle .weblogic .kubernetes .actions .TestActions .defaultAppParams ;
40
55
import static oracle .weblogic .kubernetes .actions .impl .primitive .Kubernetes .createApplication ;
41
56
import static oracle .weblogic .kubernetes .actions .impl .primitive .Kubernetes .createComponent ;
57
+ import static oracle .weblogic .kubernetes .utils .AuxiliaryImageUtils .createAndPushAuxiliaryImage ;
58
+ import static oracle .weblogic .kubernetes .utils .AuxiliaryImageUtils .createPushAuxiliaryImageWithDomainConfig ;
59
+ import static oracle .weblogic .kubernetes .utils .ClusterUtils .createClusterResourceAndAddReferenceToDomain ;
42
60
import static oracle .weblogic .kubernetes .utils .CommonMiiTestUtils .createDomainResource ;
61
+ import static oracle .weblogic .kubernetes .utils .CommonMiiTestUtils .createDomainResourceWithAuxiliaryImage ;
43
62
import static oracle .weblogic .kubernetes .utils .CommonTestUtils .checkPodReadyAndServiceExists ;
63
+ import static oracle .weblogic .kubernetes .utils .CommonTestUtils .testUntil ;
44
64
import static oracle .weblogic .kubernetes .utils .ImageUtils .createTestRepoSecret ;
45
65
import static oracle .weblogic .kubernetes .utils .SecretUtils .createSecretWithUsernamePassword ;
66
+ import static oracle .weblogic .kubernetes .utils .SecretUtils .createSecretsForImageRepos ;
46
67
import static oracle .weblogic .kubernetes .utils .ThreadSafeLogger .getLogger ;
47
68
import static oracle .weblogic .kubernetes .utils .VerrazzanoUtils .getIstioHost ;
48
69
import static oracle .weblogic .kubernetes .utils .VerrazzanoUtils .getLoadbalancerAddress ;
53
74
import static org .junit .jupiter .api .Assertions .assertTrue ;
54
75
55
76
// Test to create model in image domain and verify the domain started successfully
56
-
57
77
@ DisplayName ("Test to a create model in image domain and start the domain in verrazzano" )
58
78
@ VzIntegrationTest
59
79
@ Tag ("v8o" )
60
80
class ItVzMiiDomain {
61
-
81
+
62
82
private static String domainNamespace = null ;
83
+ private static String auxDomainNamespace = null ;
63
84
private final String domainUid = "domain1" ;
64
85
private static LoggingFacade logger = null ;
65
-
66
86
67
87
/**
68
88
* Label domain namespace.
69
- * @param namespaces list of namespaces created by the IntegrationTestWatcher by the
70
- JUnit engine parameter resolution mechanism
89
+ *
90
+ * @param namespaces list of namespaces created by the IntegrationTestWatcher by the JUnit engine parameter resolution
91
+ * mechanism
71
92
*/
72
93
@ BeforeAll
73
- public static void initAll (@ Namespaces (1 ) List <String > namespaces ) throws Exception {
94
+ public static void initAll (@ Namespaces (2 ) List <String > namespaces ) throws Exception {
74
95
logger = getLogger ();
75
96
logger .info ("Getting unique namespace for Domain" );
76
97
assertNotNull (namespaces .get (0 ), "Namespace list is null" );
77
98
domainNamespace = namespaces .get (0 );
78
- setLabelToNamespace (domainNamespace );
99
+ auxDomainNamespace = namespaces .get (1 );
100
+ setLabelToNamespace (Arrays .asList (domainNamespace , auxDomainNamespace ));
79
101
}
80
102
81
103
/**
@@ -98,17 +120,17 @@ void testCreateVzMiiDomain() {
98
120
logger .info ("Create secret for admin credentials" );
99
121
String adminSecretName = "weblogic-credentials" ;
100
122
createSecretWithUsernamePassword (adminSecretName , domainNamespace ,
101
- ADMIN_USERNAME_DEFAULT , ADMIN_PASSWORD_DEFAULT );
123
+ ADMIN_USERNAME_DEFAULT , ADMIN_PASSWORD_DEFAULT );
102
124
103
125
// create encryption secret
104
126
logger .info ("Create encryption secret" );
105
127
String encryptionSecretName = "encryptionsecret" ;
106
128
createSecretWithUsernamePassword (encryptionSecretName , domainNamespace ,
107
- "weblogicenc" , "weblogicenc" );
129
+ "weblogicenc" , "weblogicenc" );
108
130
109
131
// create cluster object
110
132
String clusterName = "cluster-1" ;
111
-
133
+
112
134
DomainResource domain = createDomainResource (domainUid , domainNamespace ,
113
135
MII_BASIC_IMAGE_NAME + ":" + MII_BASIC_IMAGE_TAG ,
114
136
adminSecretName , new String []{TEST_IMAGES_REPO_SECRET_NAME },
@@ -126,11 +148,11 @@ void testCreateVzMiiDomain() {
126
148
.kind ("VerrazzanoWebLogicWorkload" )
127
149
.spec (new WorkloadSpec ()
128
150
.template (domain ))));
129
-
151
+
130
152
Map <String , String > keyValueMap = new HashMap <>();
131
- keyValueMap .put ("version" , "v1.0.0" );
153
+ keyValueMap .put ("version" , "v1.0.0" );
132
154
keyValueMap .put ("description" , "My vz wls application" );
133
-
155
+
134
156
ApplicationConfiguration application = new ApplicationConfiguration ()
135
157
.apiVersion ("core.oam.dev/v1alpha2" )
136
158
.kind ("ApplicationConfiguration" )
@@ -164,12 +186,12 @@ void testCreateVzMiiDomain() {
164
186
.destination (new Destination ()
165
187
.host (domainUid + "-cluster-" + clusterName )
166
188
.port (8001 )))))))))));
167
-
189
+
168
190
logger .info (Yaml .dump (component ));
169
191
logger .info (Yaml .dump (application ));
170
-
192
+
171
193
logger .info ("Deploying components" );
172
- assertDoesNotThrow (() -> createComponent (component ));
194
+ assertDoesNotThrow (() -> createComponent (component ));
173
195
logger .info ("Deploying application" );
174
196
assertDoesNotThrow (() -> createApplication (application ));
175
197
@@ -183,7 +205,7 @@ void testCreateVzMiiDomain() {
183
205
managedServerPrefix + i , domainNamespace );
184
206
checkPodReadyAndServiceExists (managedServerPrefix + i , domainUid , domainNamespace );
185
207
}
186
-
208
+
187
209
// get istio gateway host and loadbalancer address
188
210
String host = getIstioHost (domainNamespace );
189
211
String address = getLoadbalancerAddress ();
@@ -197,7 +219,202 @@ void testCreateVzMiiDomain() {
197
219
message = "Hello World, you have reached server managed-server" ;
198
220
String appUrl = "https://" + host + "/sample-war/index.jsp --resolve " + host + ":443:" + address ;
199
221
assertTrue (verifyVzApplicationAccess (appUrl , message ), "Failed to get access to sample application" );
222
+
223
+ }
224
+
225
+ /**
226
+ * Create a WebLogic domain VerrazzanoWebLogicWorkload component in verrazzano with auxilary images.
227
+ */
228
+ @ Test
229
+ @ DisplayName ("Verrazzano mii domain with auxilary image" )
230
+ void testVzMiiAuxilaryImage () {
231
+ String auxDomainUid = "aux-domain" ;
232
+ String miiAuxiliaryImage1Tag = "image1" + MII_BASIC_IMAGE_TAG ;
233
+ String miiAuxiliaryImage1 = MII_AUXILIARY_IMAGE_NAME + ":" + miiAuxiliaryImage1Tag ;
234
+ String miiAuxiliaryImage2Tag = "image2" + MII_BASIC_IMAGE_TAG ;
235
+ String miiAuxiliaryImage2 = MII_AUXILIARY_IMAGE_NAME + ":" + miiAuxiliaryImage2Tag ;
200
236
237
+ final int replicaCount = 2 ;
238
+ final String adminServerPodName = auxDomainUid + "-" + ADMIN_SERVER_NAME_BASE ;
239
+ final String managedServerPrefix = auxDomainUid + "-" + MANAGED_SERVER_NAME_BASE ;
240
+
241
+ String adminSecretName = "weblogic-credentials" ;
242
+ String encryptionSecretName = "encryptionsecret" ;
243
+
244
+ // create secret for admin credentials
245
+ logger .info ("Create secret for admin credentials" );
246
+ createSecretWithUsernamePassword (adminSecretName , auxDomainNamespace ,
247
+ ADMIN_USERNAME_DEFAULT , ADMIN_PASSWORD_DEFAULT );
248
+
249
+ // create encryption secret
250
+ logger .info ("Create encryption secret" );
251
+ createSecretWithUsernamePassword (encryptionSecretName , auxDomainNamespace ,
252
+ "weblogicenc" , "weblogicenc" );
253
+
254
+ // build app
255
+ assertTrue (buildAppArchive (defaultAppParams ()
256
+ .srcDirList (Collections .singletonList (MII_BASIC_APP_NAME ))
257
+ .appName (MII_BASIC_APP_NAME )),
258
+ String .format ("Failed to create app archive for %s" , MII_BASIC_APP_NAME ));
259
+
260
+ // image1 with model files for domain config, ds, app and wdt install files
261
+ List <String > archiveList = Collections .singletonList (ARCHIVE_DIR + "/" + MII_BASIC_APP_NAME + ".zip" );
262
+
263
+ List <String > modelList = new ArrayList <>();
264
+ modelList .add (MODEL_DIR + "/" + MII_BASIC_WDT_MODEL_FILE );
265
+ modelList .add (MODEL_DIR + "/multi-model-one-ds.20.yaml" );
266
+ createPushAuxiliaryImageWithDomainConfig (MII_AUXILIARY_IMAGE_NAME , miiAuxiliaryImage1Tag , archiveList , modelList );
267
+ // image2 with model files for jms config
268
+ modelList = new ArrayList <>();
269
+ modelList .add (MODEL_DIR + "/model.jms2.yaml" );
270
+ WitParams witParams
271
+ = new WitParams ()
272
+ .modelImageName (MII_AUXILIARY_IMAGE_NAME )
273
+ .modelImageTag (miiAuxiliaryImage2Tag )
274
+ .wdtModelOnly (true )
275
+ .modelFiles (modelList )
276
+ .wdtVersion ("NONE" );
277
+ createAndPushAuxiliaryImage (MII_AUXILIARY_IMAGE_NAME , miiAuxiliaryImage2Tag , witParams );
278
+
279
+ // admin/managed server name here should match with model yaml
280
+ String auxiliaryImagePath = "/auxiliary" ;
281
+ String clusterName = "cluster-1" ;
282
+
283
+ // create domain custom resource using 2 auxiliary images
284
+ logger .info ("Creating domain custom resource with domainUid {0} and auxiliary images {1} {2}" ,
285
+ auxDomainUid , miiAuxiliaryImage1 , miiAuxiliaryImage2 );
286
+ DomainResource domainCR = createDomainResourceWithAuxiliaryImage (
287
+ auxDomainUid , auxDomainNamespace , WEBLOGIC_IMAGE_TO_USE_IN_SPEC , adminSecretName ,
288
+ createSecretsForImageRepos (auxDomainNamespace ), encryptionSecretName , auxiliaryImagePath ,
289
+ miiAuxiliaryImage1 , miiAuxiliaryImage2 );
290
+
291
+ domainCR = createClusterResourceAndAddReferenceToDomain (
292
+ auxDomainUid + "-" + clusterName , clusterName , auxDomainNamespace , domainCR , replicaCount );
293
+
294
+ Component component = new Component ()
295
+ .apiVersion ("core.oam.dev/v1alpha2" )
296
+ .kind ("Component" )
297
+ .metadata (new V1ObjectMeta ()
298
+ .name (auxDomainUid )
299
+ .namespace (auxDomainNamespace ))
300
+ .spec (new ComponentSpec ()
301
+ .workLoad (new Workload ()
302
+ .apiVersion ("oam.verrazzano.io/v1alpha1" )
303
+ .kind ("VerrazzanoWebLogicWorkload" )
304
+ .spec (new WorkloadSpec ()
305
+ .template (domainCR ))));
306
+
307
+ Map <String , String > keyValueMap = new HashMap <>();
308
+ keyValueMap .put ("version" , "v1.0.0" );
309
+ keyValueMap .put ("description" , "My vz wls application" );
310
+
311
+ ApplicationConfiguration application = new ApplicationConfiguration ()
312
+ .apiVersion ("core.oam.dev/v1alpha2" )
313
+ .kind ("ApplicationConfiguration" )
314
+ .metadata (new V1ObjectMeta ()
315
+ .name ("myvzauxdomain" )
316
+ .namespace (auxDomainNamespace )
317
+ .annotations (keyValueMap ))
318
+ .spec (new ApplicationConfigurationSpec ()
319
+ .components (Arrays .asList (new Components ()
320
+ .componentName (auxDomainUid )
321
+ .traits (Arrays .asList (new IngressTraits ()
322
+ .trait (new IngressTrait ()
323
+ .apiVersion ("oam.verrazzano.io/v1alpha1" )
324
+ .kind ("IngressTrait" )
325
+ .metadata (new V1ObjectMeta ()
326
+ .name ("myauxdomain-ingress" )
327
+ .namespace (auxDomainNamespace ))
328
+ .spec (new IngressTraitSpec ()
329
+ .ingressRules (Arrays .asList (
330
+ new IngressRule ()
331
+ .paths (Arrays .asList (new Path ()
332
+ .path ("/console" )
333
+ .pathType ("Prefix" )))
334
+ .destination (new Destination ()
335
+ .host (adminServerPodName )
336
+ .port (7001 )),
337
+ new IngressRule ()
338
+ .paths (Arrays .asList (new Path ()
339
+ .path ("/management" )
340
+ .pathType ("Prefix" )))
341
+ .destination (new Destination ()
342
+ .host (adminServerPodName )
343
+ .port (7001 )),
344
+ new IngressRule ()
345
+ .paths (Arrays .asList (new Path ()
346
+ .path ("/sample-war" )
347
+ .pathType ("Prefix" )))
348
+ .destination (new Destination ()
349
+ .host (auxDomainUid + "-cluster-" + clusterName )
350
+ .port (8001 )))))))))));
351
+
352
+ logger .info (Yaml .dump (component ));
353
+ logger .info (Yaml .dump (application ));
354
+
355
+ logger .info ("Deploying components" );
356
+ assertDoesNotThrow (() -> createComponent (component ));
357
+ logger .info ("Deploying application" );
358
+ assertDoesNotThrow (() -> createApplication (application ));
359
+
360
+ // check admin server pod is ready
361
+ logger .info ("Wait for admin server pod {0} to be ready in namespace {1}" ,
362
+ adminServerPodName , auxDomainNamespace );
363
+ checkPodReadyAndServiceExists (adminServerPodName , auxDomainUid , auxDomainNamespace );
364
+ // check managed server pods are ready
365
+ for (int i = 1 ; i <= replicaCount ; i ++) {
366
+ logger .info ("Wait for managed server pod {0} to be ready in namespace {1}" ,
367
+ managedServerPrefix + i , auxDomainNamespace );
368
+ checkPodReadyAndServiceExists (managedServerPrefix + i , auxDomainUid , auxDomainNamespace );
369
+ }
370
+
371
+ // get istio gateway host and loadbalancer address
372
+ String host = getIstioHost (auxDomainNamespace );
373
+ String address = getLoadbalancerAddress ();
374
+
375
+ // verify WebLogic console page is accessible through istio/loadbalancer
376
+ String message = "Oracle WebLogic Server Administration Console" ;
377
+ String consoleUrl = "https://" + host + "/console/login/LoginForm.jsp --resolve " + host + ":443:" + address ;
378
+ assertTrue (verifyVzApplicationAccess (consoleUrl , message ), "Failed to get WebLogic administration console" );
379
+
380
+ // verify sample running in cluster is accessible through istio/loadbalancer
381
+ message = "Hello World, you have reached server managed-server" ;
382
+ String appUrl = "https://" + host + "/sample-war/index.jsp --resolve " + host + ":443:" + address ;
383
+ assertTrue (verifyVzApplicationAccess (appUrl , message ), "Failed to get access to sample application" );
384
+
385
+ // check configuration for JMS
386
+ testUntil (
387
+ () -> checkSystemResourceConfiguration (auxDomainNamespace , "JMSSystemResources" ,
388
+ "TestClusterJmsModule2" , "200" ),
389
+ logger ,
390
+ "Checking for TestClusterJmsModule2 in JMSSystemResources resourceName exists" );
391
+ logger .info ("Found the TestClusterJmsModule2 configuration" );
392
+
201
393
}
202
394
395
+ private static boolean checkSystemResourceConfiguration (String namespace , String resourcesType ,
396
+ String resourcesName , String expectedStatusCode ) {
397
+ // get istio gateway host and loadbalancer address
398
+ String host = getIstioHost (namespace );
399
+ String address = getLoadbalancerAddress ();
400
+
401
+ StringBuffer curlString = new StringBuffer ("status=$(curl -k --user " );
402
+ curlString .append (ADMIN_USERNAME_DEFAULT + ":" + ADMIN_PASSWORD_DEFAULT )
403
+ .append (" https://" + host )
404
+ .append ("/management/weblogic/latest/domainConfig" )
405
+ .append ("/" )
406
+ .append (resourcesType )
407
+ .append ("/" )
408
+ .append (resourcesName )
409
+ .append ("/ --resolve " + host + ":443:" + address )
410
+ .append (" --silent --show-error " )
411
+ .append (" -o /dev/null " )
412
+ .append (" -w %{http_code});" )
413
+ .append ("echo ${status}" );
414
+ logger .info ("checkSystemResource: curl command {0}" , new String (curlString ));
415
+ return Command
416
+ .withParams (new CommandParams ()
417
+ .command (curlString .toString ()))
418
+ .executeAndVerify (expectedStatusCode );
419
+ }
203
420
}
0 commit comments