|
26 | 26 | import static oracle.weblogic.kubernetes.actions.TestActions.getPodLog; |
27 | 27 | import static oracle.weblogic.kubernetes.utils.CommonTestUtils.withStandardRetryPolicy; |
28 | 28 | import static oracle.weblogic.kubernetes.utils.ThreadSafeLogger.getLogger; |
| 29 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
29 | 30 | import static org.junit.jupiter.api.Assertions.assertTrue; |
30 | 31 | import static org.junit.jupiter.api.Assertions.fail; |
31 | 32 |
|
|
35 | 36 | public class K8sEvents { |
36 | 37 |
|
37 | 38 | private static final LoggingFacade logger = getLogger(); |
| 39 | + public static final String ABORTED_ERROR = "Domain processing is aborted"; |
| 40 | + public static final String DOMAIN_CREATED = "DomainCreated"; |
| 41 | + public static final String DOMAIN_DELETED = "DomainDeleted"; |
| 42 | + public static final String DOMAIN_CHANGED = "DomainChanged"; |
| 43 | + public static final String DOMAIN_FAILED = "DomainFailed"; |
| 44 | + public static final String DOMAIN_PROCESSING_STARTING = "DomainProcessingStarting"; |
| 45 | + public static final String DOMAIN_PROCESSING_COMPLETED = "DomainProcessingCompleted"; |
| 46 | + public static final String DOMAIN_PROCESSING_FAILED = "DomainProcessingFailed"; |
| 47 | + public static final String DOMAIN_PROCESSING_RETRYING = "DomainProcessingRetrying"; |
| 48 | + public static final String DOMAIN_PROCESSING_ABORTED = "DomainProcessingAborted"; |
| 49 | + public static final String DOMAIN_ROLL_STARTING = "DomainRollStarting"; |
| 50 | + public static final String DOMAIN_ROLL_COMPLETED = "DomainRollCompleted"; |
| 51 | + public static final String DOMAIN_VALIDATION_ERROR = "DomainValidationError"; |
| 52 | + public static final String NAMESPACE_WATCHING_STARTED = "NamespaceWatchingStarted"; |
| 53 | + public static final String NAMESPACE_WATCHING_STOPPED = "NamespaceWatchingStopped"; |
| 54 | + public static final String STOP_MANAGING_NAMESPACE = "StopManagingNamespace"; |
| 55 | + public static final String POD_TERMINATED = "Killing"; |
| 56 | + public static final String POD_STARTED = "Started"; |
| 57 | + public static final String POD_CYCLE_STARTING = "PodCycleStarting"; |
38 | 58 |
|
39 | 59 | /** |
40 | 60 | * Utility method to check event. |
@@ -492,23 +512,54 @@ private static void verifyOperatorDetails( |
492 | 512 | } |
493 | 513 | } |
494 | 514 |
|
| 515 | + /** |
| 516 | + * Check if a given DomainFailed event is logged by the operator. |
| 517 | + * |
| 518 | + * @param opNamespace namespace in which the operator is running |
| 519 | + * @param domainNamespace namespace in which the domain exists |
| 520 | + * @param domainUid UID of the domain |
| 521 | + * @param failureReason DomainFailureReason to check |
| 522 | + * @param type type of event, Normal of Warning |
| 523 | + * @param timestamp the timestamp after which to see events |
| 524 | + */ |
| 525 | + public static Callable<Boolean> checkDomainFailedEventWithReason( |
| 526 | + String opNamespace, String domainNamespace, String domainUid, String failureReason, |
| 527 | + String type, OffsetDateTime timestamp) { |
| 528 | + return () -> { |
| 529 | + return domainFailedEventExists(opNamespace, domainNamespace, domainUid, failureReason, type, timestamp); |
| 530 | + }; |
| 531 | + } |
495 | 532 |
|
496 | | - public static final String DOMAIN_CREATED = "DomainCreated"; |
497 | | - public static final String DOMAIN_DELETED = "DomainDeleted"; |
498 | | - public static final String DOMAIN_CHANGED = "DomainChanged"; |
499 | | - public static final String DOMAIN_PROCESSING_STARTING = "DomainProcessingStarting"; |
500 | | - public static final String DOMAIN_PROCESSING_COMPLETED = "DomainProcessingCompleted"; |
501 | | - public static final String DOMAIN_PROCESSING_FAILED = "DomainProcessingFailed"; |
502 | | - public static final String DOMAIN_PROCESSING_RETRYING = "DomainProcessingRetrying"; |
503 | | - public static final String DOMAIN_PROCESSING_ABORTED = "DomainProcessingAborted"; |
504 | | - public static final String DOMAIN_ROLL_STARTING = "DomainRollStarting"; |
505 | | - public static final String DOMAIN_ROLL_COMPLETED = "DomainRollCompleted"; |
506 | | - public static final String DOMAIN_VALIDATION_ERROR = "DomainValidationError"; |
507 | | - public static final String NAMESPACE_WATCHING_STARTED = "NamespaceWatchingStarted"; |
508 | | - public static final String NAMESPACE_WATCHING_STOPPED = "NamespaceWatchingStopped"; |
509 | | - public static final String STOP_MANAGING_NAMESPACE = "StopManagingNamespace"; |
510 | | - public static final String POD_TERMINATED = "Killing"; |
511 | | - public static final String POD_STARTED = "Started"; |
512 | | - public static final String POD_CYCLE_STARTING = "PodCycleStarting"; |
| 533 | + /** |
| 534 | + * Check if a given event is logged by the operator in the given namespace. |
| 535 | + * |
| 536 | + * @param opNamespace namespace in which the operator is running |
| 537 | + * @param domainNamespace namespace in which the event is logged |
| 538 | + * @param domainUid UID of the domain |
| 539 | + * @param failureReason failure reason to check |
| 540 | + * @param type type of event, Normal or Warning |
| 541 | + * @param timestamp the timestamp after which to see events |
| 542 | + */ |
| 543 | + public static boolean domainFailedEventExists( |
| 544 | + String opNamespace, String domainNamespace, String domainUid, String failureReason, |
| 545 | + String type, OffsetDateTime timestamp) { |
513 | 546 |
|
| 547 | + try { |
| 548 | + List<CoreV1Event> events = Kubernetes.listOpGeneratedNamespacedEvents(domainNamespace); |
| 549 | + for (CoreV1Event event : events) { |
| 550 | + if (DOMAIN_FAILED.equals(event.getReason()) && (isEqualOrAfter(timestamp, event)) |
| 551 | + && event.getMessage().contains(failureReason)) { |
| 552 | + logger.info(Yaml.dump(event)); |
| 553 | + verifyOperatorDetails(event, opNamespace, domainUid); |
| 554 | + //verify type |
| 555 | + logger.info("Verifying domain event type {0}", type); |
| 556 | + assertEquals(event.getType(), type); |
| 557 | + return true; |
| 558 | + } |
| 559 | + } |
| 560 | + } catch (ApiException ex) { |
| 561 | + logger.log(Level.SEVERE, null, ex); |
| 562 | + } |
| 563 | + return false; |
| 564 | + } |
514 | 565 | } |
0 commit comments