4
4
5
5
package oracle .kubernetes .operator ;
6
6
7
+ import java .nio .charset .Charset ;
8
+ import java .nio .charset .StandardCharsets ;
7
9
import java .nio .file .Files ;
10
+ import java .nio .file .Path ;
8
11
import java .nio .file .Paths ;
12
+ import java .util .HashMap ;
9
13
import java .util .Map ;
14
+ import java .util .logging .Level ;
10
15
import oracle .kubernetes .operator .utils .Domain ;
16
+ import oracle .kubernetes .operator .utils .DomainCRD ;
17
+ import oracle .kubernetes .operator .utils .ExecResult ;
18
+ import oracle .kubernetes .operator .utils .K8sTestUtils ;
11
19
import oracle .kubernetes .operator .utils .Operator ;
12
20
import oracle .kubernetes .operator .utils .TestUtils ;
13
21
import org .junit .AfterClass ;
@@ -29,6 +37,8 @@ public class ITPodsRestart extends BaseTest {
29
37
private static Domain domain = null ;
30
38
private static Operator operator1 ;
31
39
private static String domainUid = "" ;
40
+ private static String restartTmpDir = "" ;
41
+ private static String originalYaml ;
32
42
33
43
/**
34
44
* This method gets called only once before any of the test methods are executed. It does the
@@ -48,8 +58,15 @@ public static void staticPrepare() throws Exception {
48
58
if (operator1 == null ) {
49
59
operator1 = TestUtils .createOperator (OPERATOR1_YAML );
50
60
}
61
+ restartTmpDir = BaseTest .getResultDir () + "/restarttemp" ;
62
+ Files .createDirectories (Paths .get (restartTmpDir ));
51
63
52
64
domain = createPodsRestartdomain ();
65
+ originalYaml =
66
+ BaseTest .getUserProjectsDir ()
67
+ + "/weblogic-domains/"
68
+ + domain .getDomainUid ()
69
+ + "/domain.yaml" ;
53
70
Assert .assertNotNull (domain );
54
71
}
55
72
}
@@ -305,6 +322,209 @@ public void testServerPodsRestartByChangingResource() throws Exception {
305
322
logger .info ("SUCCESS - " + testMethodName );
306
323
}
307
324
325
+ /**
326
+ * Add restartVersion:v1.1 at adminServer level and verify the admin pod is Terminated and
327
+ * recreated
328
+ *
329
+ * @throws Exception when domain.yaml cannot be read or modified to include the
330
+ * restartVersion:v1.1
331
+ */
332
+ @ Test
333
+ public void testAdminServerRestartVersion () throws Exception {
334
+ Assume .assumeFalse (QUICKTEST );
335
+ String testMethodName = new Object () {}.getClass ().getEnclosingMethod ().getName ();
336
+ logTestBegin (testMethodName );
337
+ String podName = domainUid + "-" + domain .getAdminServerName ();
338
+
339
+ try {
340
+ // Modify the original domain yaml to include restartVersion in admin server node
341
+ DomainCRD crd = new DomainCRD (originalYaml );
342
+ Map <String , String > admin = new HashMap ();
343
+ admin .put ("restartVersion" , "v1.1" );
344
+ crd .addObjectNodeToAdminServer (admin );
345
+ String modYaml = crd .getYamlTree ();
346
+ logger .info (modYaml );
347
+
348
+ // Write the modified yaml to a new file
349
+ Path path = Paths .get (restartTmpDir , "restart.admin.yaml" );
350
+ logger .log (Level .INFO , "Path of the modified domain.yaml :{0}" , path .toString ());
351
+ Charset charset = StandardCharsets .UTF_8 ;
352
+ Files .write (path , modYaml .getBytes (charset ));
353
+
354
+ // Apply the new yaml to update the domain
355
+ logger .log (Level .INFO , "kubectl apply -f {0}" , path .toString ());
356
+ ExecResult exec = TestUtils .exec ("kubectl apply -f " + path .toString ());
357
+ logger .info (exec .stdout ());
358
+
359
+ logger .info ("Verifying if the admin server is terminating" );
360
+ verifyPodStatus (podName , "Terminating" );
361
+ verifyPodStatus (podName , "Running" );
362
+
363
+ } finally {
364
+ logger .log (
365
+ Level .INFO , "Reverting back the domain to old crd\n kubectl apply -f {0}" , originalYaml );
366
+ TestUtils .exec ("kubectl apply -f " + originalYaml );
367
+ logger .info ("Verifying if the admin server is terminating" );
368
+ verifyPodStatus (podName , "Terminating" );
369
+ verifyPodStatus (podName , "Running" );
370
+ }
371
+ logger .log (Level .INFO , "SUCCESS - {0}" , testMethodName );
372
+ }
373
+
374
+ /**
375
+ * Add restartVersion:v1.1 at cluster level and verify the managed servers pods are Terminated and
376
+ * recreated
377
+ *
378
+ * @throws Exception when domain.yaml cannot be read or modified to include the
379
+ * restartVersion:v1.1
380
+ */
381
+ @ Test
382
+ public void testClusterRestartVersion () throws Exception {
383
+ Assume .assumeFalse (QUICKTEST );
384
+ String testMethodName = new Object () {}.getClass ().getEnclosingMethod ().getName ();
385
+ logTestBegin (testMethodName );
386
+ String podName = domainUid + "-managed-server1" ;
387
+
388
+ try {
389
+ // Modify the original domain yaml to include restartVersion in admin server node
390
+ DomainCRD crd = new DomainCRD (originalYaml );
391
+ Map <String , String > cluster = new HashMap ();
392
+ cluster .put ("restartVersion" , "v1.1" );
393
+ crd .addObjectNodeToCluster ("cluster-1" , cluster );
394
+ String modYaml = crd .getYamlTree ();
395
+ logger .info (modYaml );
396
+
397
+ // Write the modified yaml to a new file
398
+ Path path = Paths .get (restartTmpDir , "restart.cluster.yaml" );
399
+ logger .log (Level .INFO , "Path of the modified domain.yaml :{0}" , path .toString ());
400
+ Charset charset = StandardCharsets .UTF_8 ;
401
+ Files .write (path , modYaml .getBytes (charset ));
402
+
403
+ // Apply the new yaml to update the domain crd
404
+ logger .log (Level .INFO , "kubectl apply -f {0}" , path .toString ());
405
+ ExecResult exec = TestUtils .exec ("kubectl apply -f " + path .toString ());
406
+ logger .info (exec .stdout ());
407
+ logger .info ("Verifying if the cluster is restarted" );
408
+ verifyPodStatus (podName , "Terminating" );
409
+ verifyPodStatus (podName , "Running" );
410
+ } finally {
411
+ logger .log (
412
+ Level .INFO , "Reverting back the domain to old crd\n kubectl apply -f {0}" , originalYaml );
413
+ TestUtils .exec ("kubectl apply -f " + originalYaml );
414
+ logger .info ("Verifying if the cluster is restarted" );
415
+ verifyPodStatus (podName , "Terminating" );
416
+ verifyPodStatus (podName , "Running" );
417
+ }
418
+ logger .log (Level .INFO , "SUCCESS - {0}" , testMethodName );
419
+ }
420
+
421
+ /**
422
+ * Add restartVersion:v1.1 at managed server level and verify the managed server pod are
423
+ * Terminated and recreated
424
+ *
425
+ * <p>Currently failing and tracked by bug in BugDB - 29489387
426
+ *
427
+ * @throws Exception when domain.yaml cannot be read or modified to include the
428
+ * restartVersion:v1.1
429
+ */
430
+ // @Test
431
+ public void testMSRestartVersion () throws Exception {
432
+ Assume .assumeFalse (QUICKTEST );
433
+ String testMethodName = new Object () {}.getClass ().getEnclosingMethod ().getName ();
434
+ logTestBegin (testMethodName );
435
+ String podName = domainUid + "-managed-server1" ;
436
+
437
+ try {
438
+ // Modify the original domain yaml to include restartVersion in admin server node
439
+ DomainCRD crd = new DomainCRD (originalYaml );
440
+ Map <String , String > ms = new HashMap ();
441
+ ms .put ("restartVersion" , "v1.1" );
442
+ ms .put ("serverStartPolicy" , "IF_NEEDED" );
443
+ ms .put ("serverStartState" , "RUNNING" );
444
+ crd .addObjectNodeToMS ("managed-server1" , ms );
445
+ String modYaml = crd .getYamlTree ();
446
+ logger .info (modYaml );
447
+
448
+ // Write the modified yaml to a new file
449
+ Path path = Paths .get (restartTmpDir , "restart.managed.yaml" );
450
+ logger .log (Level .INFO , "Path of the modified domain.yaml :{0}" , path .toString ());
451
+ Charset charset = StandardCharsets .UTF_8 ;
452
+ Files .write (path , modYaml .getBytes (charset ));
453
+
454
+ // Apply the new yaml to update the domain crd
455
+ logger .log (Level .INFO , "kubectl apply -f {0}" , path .toString ());
456
+ ExecResult exec = TestUtils .exec ("kubectl apply -f " + path .toString ());
457
+ logger .info (exec .stdout ());
458
+ logger .info ("Verifying if the managed server is restarted" );
459
+ verifyPodStatus (podName , "Terminating" );
460
+ verifyPodStatus (podName , "Running" );
461
+ } finally {
462
+ logger .log (
463
+ Level .INFO , "Reverting back the domain to old crd\n kubectl apply -f {0}" , originalYaml );
464
+ TestUtils .exec ("kubectl apply -f " + originalYaml );
465
+ logger .info ("Verifying if the managed server is restarted" );
466
+ verifyPodStatus (podName , "Terminating" );
467
+ verifyPodStatus (podName , "Running" );
468
+ }
469
+ logger .log (Level .INFO , "SUCCESS - {0}" , testMethodName );
470
+ }
471
+
472
+ /**
473
+ * Add restartVersion:v1.1 at doamin level and verify all of the server pods are Terminated and
474
+ * recreated
475
+ *
476
+ * @throws Exception when domain.yaml cannot be read or modified to include the
477
+ * restartVersion:v1.1
478
+ */
479
+ @ Test
480
+ public void testDomainRestartVersion () throws Exception {
481
+ Assume .assumeFalse (QUICKTEST );
482
+ String testMethodName = new Object () {}.getClass ().getEnclosingMethod ().getName ();
483
+ logTestBegin (testMethodName );
484
+ String adminPod = domainUid + "-" + domain .getAdminServerName ();
485
+ String msPod = domainUid + "-managed-server1" ;
486
+
487
+ try {
488
+ // Modify the original domain yaml to include restartVersion in admin server node
489
+ DomainCRD crd = new DomainCRD (originalYaml );
490
+ Map <String , String > domain = new HashMap ();
491
+ domain .put ("restartVersion" , "v1.1" );
492
+ crd .addObjectNodeToDomain (domain );
493
+ String modYaml = crd .getYamlTree ();
494
+ logger .info (modYaml );
495
+
496
+ // Write the modified yaml to a new file
497
+ Path path = Paths .get (restartTmpDir , "restart.domain.yaml" );
498
+ logger .log (Level .INFO , "Path of the modified domain.yaml :{0}" , path .toString ());
499
+ Charset charset = StandardCharsets .UTF_8 ;
500
+ Files .write (path , modYaml .getBytes (charset ));
501
+
502
+ // Apply the new yaml to update the domain crd
503
+ logger .log (Level .INFO , "kubectl apply -f {0}" , path .toString ());
504
+ ExecResult exec = TestUtils .exec ("kubectl apply -f " + path .toString ());
505
+ logger .info (exec .stdout ());
506
+ logger .info ("Verifying if the domain is restarted" );
507
+ logger .info ("Verifying if the admin server is restarted" );
508
+ verifyPodStatus (adminPod , "Terminating" );
509
+ verifyPodStatus (adminPod , "Running" );
510
+ logger .info ("Verifying if the managed server is restarted" );
511
+ verifyPodStatus (msPod , "Terminating" );
512
+ verifyPodStatus (msPod , "Running" );
513
+ } finally {
514
+ logger .log (
515
+ Level .INFO , "Reverting back the domain to old crd\n kubectl apply -f {0}" , originalYaml );
516
+ TestUtils .exec ("kubectl apply -f " + originalYaml );
517
+ logger .info ("Verifying if the domain is restarted" );
518
+ logger .info ("Verifying if the admin server is restarted" );
519
+ verifyPodStatus (adminPod , "Terminating" );
520
+ verifyPodStatus (adminPod , "Running" );
521
+ logger .info ("Verifying if the managed server is restarted" );
522
+ verifyPodStatus (msPod , "Terminating" );
523
+ verifyPodStatus (msPod , "Running" );
524
+ }
525
+ logger .log (Level .INFO , "SUCCESS - {0}" , testMethodName );
526
+ }
527
+
308
528
private static Domain createPodsRestartdomain () throws Exception {
309
529
310
530
Map <String , Object > domainMap = TestUtils .loadYaml (DOMAINONPV_WLST_YAML );
@@ -325,4 +545,35 @@ private static void destroyPodsRestartdomain() throws Exception {
325
545
domain .destroy ();
326
546
}
327
547
}
548
+
549
+ /**
550
+ * Utility method to check if a pod is in Terminating or Running status
551
+ *
552
+ * @param podName - String name of the pod to check the status for
553
+ * @param podStatusExpected - String the expected status of Terminating || RUnning
554
+ * @throws InterruptedException when thread is interrupted
555
+ */
556
+ private void verifyPodStatus (String podName , String podStatusExpected )
557
+ throws InterruptedException {
558
+ K8sTestUtils testUtil = new K8sTestUtils ();
559
+ String domain1LabelSelector = String .format ("weblogic.domainUID in (%s)" , domainUid );
560
+ String namespace = domain .getDomainNS ();
561
+ boolean gotExpected = false ;
562
+ for (int i = 0 ; i < BaseTest .getMaxIterationsPod (); i ++) {
563
+ if (podStatusExpected .equals ("Terminating" )) {
564
+ if (testUtil .isPodTerminating (namespace , domain1LabelSelector , podName )) {
565
+ gotExpected = true ;
566
+ break ;
567
+ }
568
+ } else if (podStatusExpected .equals ("Running" )) {
569
+ if (testUtil .isPodRunning (namespace , domain1LabelSelector , podName )) {
570
+ gotExpected = true ;
571
+ break ;
572
+ }
573
+ }
574
+
575
+ Thread .sleep (BaseTest .getWaitTimePod () * 1000 );
576
+ }
577
+ Assert .assertTrue ("Didn't get the expected pod status" , gotExpected );
578
+ }
328
579
}
0 commit comments