36
36
import oracle .kubernetes .operator .work .FiberTestSupport ;
37
37
import oracle .kubernetes .operator .work .Step ;
38
38
import oracle .kubernetes .operator .work .TerminalStep ;
39
+ import oracle .kubernetes .utils .SystemClock ;
39
40
import oracle .kubernetes .utils .TestUtils ;
40
41
import oracle .kubernetes .weblogic .domain .DomainConfigurator ;
41
42
import oracle .kubernetes .weblogic .domain .DomainConfiguratorFactory ;
62
63
import static oracle .kubernetes .operator .DomainUpPlanTest .StepChainMatcher .hasChainWithStepsInOrder ;
63
64
import static oracle .kubernetes .operator .ProcessingConstants .DOMAIN_INTROSPECTOR_JOB ;
64
65
import static oracle .kubernetes .operator .ProcessingConstants .DOMAIN_TOPOLOGY ;
66
+ import static oracle .kubernetes .operator .ProcessingConstants .EXCEEDED_INTROSPECTOR_MAX_RETRY_COUNT_ERROR_MSG ;
67
+ import static oracle .kubernetes .operator .ProcessingConstants .FATAL_ERROR_DOMAIN_STATUS_MESSAGE ;
68
+ import static oracle .kubernetes .operator .ProcessingConstants .INTROSPECTION_ERROR ;
65
69
import static oracle .kubernetes .operator .ProcessingConstants .JOBWATCHER_COMPONENT_NAME ;
66
70
import static oracle .kubernetes .operator .ProcessingConstants .JOB_POD_NAME ;
67
71
import static oracle .kubernetes .operator .helpers .DomainStatusMatcher .hasStatus ;
@@ -110,8 +114,11 @@ class DomainIntrospectorJobTest {
110
114
IntStream .rangeClosed (1 , MAX_SERVERS ).mapToObj (n -> MS_PREFIX + n ).toArray (String []::new );
111
115
private static final String SEVERE_PROBLEM_1 = "really bad" ;
112
116
private static final String SEVERE_MESSAGE_1 = "@[SEVERE] " + SEVERE_PROBLEM_1 ;
117
+ private static final String FATAL_PROBLEM_1 = "FatalIntrospectorError: really bad" ;
118
+ private static final String FATAL_MESSAGE_1 = "@[SEVERE] " + FATAL_PROBLEM_1 ;
113
119
public static final String TEST_VOLUME_NAME = "test" ;
114
- public static final String LAST_JOB_PROCESSED_ID = "some-unique-id" ;
120
+ public static final String JOB_UID = "some-unique-id" ;
121
+ public static final String INFO_MESSAGE_1 = "informational message" ;
115
122
116
123
private final TerminalStep terminalStep = new TerminalStep ();
117
124
private final Domain domain = createDomain ();
@@ -122,6 +129,7 @@ class DomainIntrospectorJobTest {
122
129
private final DomainConfigurator configurator = DomainConfiguratorFactory .forDomain (domain );
123
130
private final EventRetryStrategyStub retryStrategy = createStrictStub (EventRetryStrategyStub .class );
124
131
private final String jobPodName = LegalNames .toJobIntrospectorName (UID );
132
+ private TestUtils .ConsoleHandlerMemento consoleHandlerMemento ;
125
133
126
134
public DomainIntrospectorJobTest () {
127
135
}
@@ -133,7 +141,7 @@ private static String getJobName() {
133
141
@ BeforeEach
134
142
public void setUp () throws Exception {
135
143
mementos .add (
136
- TestUtils .silenceOperatorLogger ()
144
+ consoleHandlerMemento = TestUtils .silenceOperatorLogger ()
137
145
.collectLogMessages (logRecords , getMessageKeys ())
138
146
.withLogLevel (Level .FINE )
139
147
.ignoringLoggedExceptions (ApiException .class ));
@@ -532,10 +540,7 @@ void whenIntrospectorJobNotNeeded_doesNotValidatesDomainTopology() throws JsonPr
532
540
533
541
@ Test
534
542
void whenJobLogContainsSevereError_logJobInfosOnDelete () {
535
- testSupport .defineResources (
536
- new V1Job ().metadata (new V1ObjectMeta ().name (getJobName ()).namespace (NS )).status (new V1JobStatus ()));
537
- IntrospectionTestUtils .defineResources (testSupport , SEVERE_MESSAGE_1 );
538
- testSupport .addToPacket (DOMAIN_INTROSPECTOR_JOB , testSupport .getResourceWithName (JOB , getJobName ()));
543
+ createIntrospectionLog (SEVERE_MESSAGE_1 , false );
539
544
540
545
testSupport .runSteps (JobHelper .deleteDomainIntrospectorJobStep (terminalStep ));
541
546
@@ -546,10 +551,7 @@ void whenJobLogContainsSevereError_logJobInfosOnDelete() {
546
551
547
552
@ Test
548
553
void whenJobLogContainsSevereError_logJobInfosOnReadPogLog () {
549
- testSupport .defineResources (
550
- new V1Job ().metadata (new V1ObjectMeta ().name (getJobName ()).namespace (NS )).status (new V1JobStatus ()));
551
- IntrospectionTestUtils .defineResources (testSupport , SEVERE_MESSAGE_1 );
552
- testSupport .addToPacket (DOMAIN_INTROSPECTOR_JOB , testSupport .getResourceWithName (JOB , getJobName ()));
554
+ createIntrospectionLog (SEVERE_MESSAGE_1 , false );
553
555
554
556
testSupport .runSteps (JobHelper .readDomainIntrospectorPodLog (terminalStep ));
555
557
@@ -559,57 +561,39 @@ void whenJobLogContainsSevereError_logJobInfosOnReadPogLog() {
559
561
560
562
@ Test
561
563
void whenJobLogContainsSevereError_incrementFailureCount () {
562
- testSupport .defineResources (
563
- new V1Job ().metadata (new V1ObjectMeta ().name (getJobName ()).namespace (NS )).status (new V1JobStatus ()));
564
- IntrospectionTestUtils .defineResources (testSupport , SEVERE_MESSAGE_1 );
565
- testSupport .addToPacket (DOMAIN_INTROSPECTOR_JOB , testSupport .getResourceWithName (JOB , getJobName ()));
564
+ createIntrospectionLog (SEVERE_MESSAGE_1 );
566
565
567
566
testSupport .runSteps (JobHelper .readDomainIntrospectorPodLog (terminalStep ));
568
567
569
- final Domain updatedDomain = testSupport .<Domain >getResources (DOMAIN ).get (0 );
570
-
571
- assertThat (updatedDomain .getStatus ().getIntrospectJobFailureCount (), equalTo (1 ));
572
- logRecords .clear ();
568
+ assertThat (getUpdatedDomain ().getStatus ().getIntrospectJobFailureCount (), equalTo (1 ));
573
569
}
574
570
575
571
@ Test
576
572
void whenReadJobLogCompletesWithSevereError_domainStatusContainsLastProcessedJobId () {
577
- testSupport .defineResources (
578
- new V1Job ().metadata (new V1ObjectMeta ().name (getJobName ()).namespace (NS ).uid (LAST_JOB_PROCESSED_ID ))
579
- .status (new V1JobStatus ()));
580
- IntrospectionTestUtils .defineResources (testSupport , SEVERE_MESSAGE_1 );
581
- testSupport .addToPacket (DOMAIN_INTROSPECTOR_JOB , testSupport .getResourceWithName (JOB , getJobName ()));
573
+ createIntrospectionLog (SEVERE_MESSAGE_1 );
582
574
583
575
testSupport .runSteps (JobHelper .readDomainIntrospectorPodLog (terminalStep ));
584
576
585
- final Domain updatedDomain = testSupport .<Domain >getResources (DOMAIN ).get (0 );
586
-
587
- assertThat (updatedDomain .getStatus ().getLastIntrospectJobProcessedUid (), equalTo (LAST_JOB_PROCESSED_ID ));
588
- logRecords .clear ();
577
+ assertThat (getUpdatedDomain ().getStatus ().getLastIntrospectJobProcessedUid (), equalTo (JOB_UID ));
589
578
}
590
579
591
580
@ Test
592
581
void whenReadJobLogCompletesWithoutSevereError_domainStatusContainsLastProcessedJobId () {
593
- testSupport .defineResources (
594
- new V1Job ().metadata (new V1ObjectMeta ().name (getJobName ()).namespace (NS ).uid (LAST_JOB_PROCESSED_ID ))
595
- .status (new V1JobStatus ()));
596
- IntrospectionTestUtils .defineResources (testSupport , "passed" );
597
- testSupport .addToPacket (DOMAIN_INTROSPECTOR_JOB , testSupport .getResourceWithName (JOB , getJobName ()));
582
+ createIntrospectionLog (INFO_MESSAGE_1 );
598
583
599
584
testSupport .runSteps (JobHelper .readDomainIntrospectorPodLog (terminalStep ));
600
585
601
586
final Domain updatedDomain = testSupport .<Domain >getResources (DOMAIN ).get (0 );
602
587
603
- assertThat (updatedDomain .getStatus ().getLastIntrospectJobProcessedUid (), equalTo (LAST_JOB_PROCESSED_ID ));
604
- logRecords .clear ();
588
+ assertThat (updatedDomain .getStatus ().getLastIntrospectJobProcessedUid (), equalTo (JOB_UID ));
605
589
}
606
590
607
591
@ Test
608
592
void whenDomainStatusContainsNullLastIntrospectProcessedJobUid_correctStepsExecuted () {
609
593
List <Step > nextSteps = new ArrayList <>();
610
594
domainPresenceInfo .getDomain ()
611
595
.setStatus (new DomainStatus ().withLastIntrospectJobProcessedUid (null ));
612
- V1Job job = new V1Job ().metadata (new V1ObjectMeta ().name (getJobName ()).namespace (NS ).uid (LAST_JOB_PROCESSED_ID ))
596
+ V1Job job = new V1Job ().metadata (new V1ObjectMeta ().name (getJobName ()).namespace (NS ).uid (JOB_UID ))
613
597
.status (new V1JobStatus ());
614
598
testSupport .defineResources (job );
615
599
IntrospectionTestUtils .defineResources (testSupport , "passed" );
@@ -626,8 +610,8 @@ void whenDomainStatusContainsNullLastIntrospectProcessedJobUid_correctStepsExecu
626
610
void whenDomainStatusContainsProcessedJobIdSameAsCurrentJob_correctStepsExecuted () {
627
611
List <Step > nextSteps = new ArrayList <>();
628
612
domainPresenceInfo .getDomain ()
629
- .setStatus (new DomainStatus ().withLastIntrospectJobProcessedUid (LAST_JOB_PROCESSED_ID ));
630
- V1Job job = new V1Job ().metadata (new V1ObjectMeta ().name (getJobName ()).namespace (NS ).uid (LAST_JOB_PROCESSED_ID ))
613
+ .setStatus (new DomainStatus ().withLastIntrospectJobProcessedUid (JOB_UID ));
614
+ V1Job job = new V1Job ().metadata (new V1ObjectMeta ().name (getJobName ()).namespace (NS ).uid (JOB_UID ))
631
615
.status (new V1JobStatus ());
632
616
testSupport .defineResources (job );
633
617
IntrospectionTestUtils .defineResources (testSupport , "passed" );
@@ -667,6 +651,75 @@ void whenJobCreateFailsWith409Error_JobIsCreated() {
667
651
logRecords .clear ();
668
652
}
669
653
654
+ @ Test
655
+ void whenJobLogContainsSevereErrorAndRetriesLeft_domainStatusHasExpectedMessage () {
656
+ createIntrospectionLog (SEVERE_MESSAGE_1 );
657
+
658
+ testSupport .runSteps (JobHelper .readDomainIntrospectorPodLog (terminalStep ));
659
+
660
+ assertThat (getUpdatedDomain ().getStatus ().getMessage (), equalTo (String .join (System .lineSeparator (),
661
+ "Introspection failed on try 1 of 2." , INTROSPECTION_ERROR ,
662
+ SEVERE_PROBLEM_1 )));
663
+ }
664
+
665
+ @ Test
666
+ void whenJobLogContainsFatalError_domainStatusHasExpectedMessage () {
667
+ createIntrospectionLog (FATAL_MESSAGE_1 );
668
+
669
+ testSupport .runSteps (JobHelper .readDomainIntrospectorPodLog (terminalStep ));
670
+
671
+ final Domain updatedDomain = testSupport .<Domain >getResources (DOMAIN ).get (0 );
672
+
673
+ assertThat (updatedDomain .getStatus ().getMessage (), equalTo (String .join (System .lineSeparator (),
674
+ FATAL_ERROR_DOMAIN_STATUS_MESSAGE , INTROSPECTION_ERROR ,
675
+ FATAL_PROBLEM_1 )));
676
+ }
677
+
678
+ @ Test
679
+ void whenJobLogContainsSevereErrorAndNumberOfRetriesExceedsMaxLimit_domainStatusHasExpectedMessage () {
680
+ createIntrospectionLog (SEVERE_MESSAGE_1 );
681
+
682
+ getUpdatedDomain ().setStatus (createDomainStatusWithIntrospectJobFailureCount (2 ));
683
+
684
+ testSupport .runSteps (JobHelper .readDomainIntrospectorPodLog (terminalStep ));
685
+
686
+ assertThat (getUpdatedDomain ().getStatus ().getMessage (), equalTo (String .join (System .lineSeparator (),
687
+ EXCEEDED_INTROSPECTOR_MAX_RETRY_COUNT_ERROR_MSG , INTROSPECTION_ERROR ,
688
+ SEVERE_PROBLEM_1 )));
689
+ }
690
+
691
+ private void createIntrospectionLog (String logMessage ) {
692
+ createIntrospectionLog (logMessage , true );
693
+ }
694
+
695
+ private void createIntrospectionLog (String logMessage , boolean ignoreLogMessages ) {
696
+ if (ignoreLogMessages ) {
697
+ consoleHandlerMemento .ignoreMessage (getJobFailedMessageKey ());
698
+ consoleHandlerMemento .ignoreMessage (getJobFailedDetailMessageKey ());
699
+ }
700
+ testSupport .defineResources (createIntrospectorJob ());
701
+ IntrospectionTestUtils .defineResources (testSupport , logMessage );
702
+ testSupport .addToPacket (DOMAIN_INTROSPECTOR_JOB , testSupport .getResourceWithName (JOB , getJobName ()));
703
+ }
704
+
705
+ private V1Job createIntrospectorJob () {
706
+ return new V1Job ().metadata (createJobMetadata ()).status (new V1JobStatus ());
707
+ }
708
+
709
+ private V1ObjectMeta createJobMetadata () {
710
+ return new V1ObjectMeta ().name (getJobName ()).namespace (NS ).creationTimestamp (SystemClock .now ()).uid (JOB_UID );
711
+ }
712
+
713
+ private DomainStatus createDomainStatusWithIntrospectJobFailureCount (int failureCount ) {
714
+ final DomainStatus status = new DomainStatus ();
715
+ status .withIntrospectJobFailureCount (failureCount );
716
+ return status ;
717
+ }
718
+
719
+ private Domain getUpdatedDomain () {
720
+ return testSupport .<Domain >getResources (DOMAIN ).get (0 );
721
+ }
722
+
670
723
private Cluster getCluster (String clusterName ) {
671
724
return domain .getSpec ().getClusters ().stream ()
672
725
.filter (c -> clusterName .equals (c .getClusterName ()))
0 commit comments