Skip to content

Commit fc2d771

Browse files
authored
Backported to 3.4 ItKubernetesEvents changes to remove test dependencies (#3008)
* Backported to 3.4 ItKubernetesEvents changes to remove test dependencies
1 parent a1482ea commit fc2d771

File tree

8 files changed

+811
-507
lines changed

8 files changed

+811
-507
lines changed

integration-tests/pom.xml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,8 @@
430430
<skipITs>false</skipITs>
431431
<includes-failsafe>
432432
**/ItCrossDomainTransaction,
433-
**/ItKubernetesEvents,
433+
**/ItKubernetesDomainEvents,
434+
**/ItKubernetesNameSpaceWatchingEvents,
434435
**/ItMiiAuxiliaryImage,
435436
**/ItMiiAuxiliaryImageCluster,
436437
**/ItMiiDomain,
@@ -500,7 +501,8 @@
500501
<skipITs>false</skipITs>
501502
<includes-failsafe>
502503
**/ItCrossDomainTransaction,
503-
**/ItKubernetesEvents,
504+
**/ItKubernetesDomainEvents,
505+
**/ItKubernetesNameSpaceWatchingEvents,
504506
**/ItMiiAuxiliaryImage,
505507
**/ItMiiAuxiliaryImageCluster,
506508
**/ItMiiDomain,

integration-tests/src/test/java/oracle/weblogic/kubernetes/ItKubernetesEvents.java renamed to integration-tests/src/test/java/oracle/weblogic/kubernetes/ItKubernetesDomainEvents.java

Lines changed: 253 additions & 488 deletions
Large diffs are not rendered by default.

integration-tests/src/test/java/oracle/weblogic/kubernetes/ItKubernetesNameSpaceWatchingEvents.java

Lines changed: 357 additions & 0 deletions
Large diffs are not rendered by default.

integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/TestActions.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,21 @@ public static oracle.weblogic.domain.Domain getDomainCustomResource(String domai
203203
return Domain.getDomainCustomResource(domainUid, namespace);
204204
}
205205

206+
/**
207+
* Get the Domain Custom Resource.
208+
*
209+
* @param domainUid unique domain identifier
210+
* @param namespace name of namespace
211+
* @param domainVersion version of domain
212+
* @return Domain Custom Resource or null if Domain does not exist
213+
* @throws ApiException if Kubernetes client API call fails
214+
*/
215+
public static oracle.weblogic.domain.Domain getDomainCustomResource(String domainUid,
216+
String namespace,
217+
String domainVersion) throws ApiException {
218+
return Domain.getDomainCustomResource(domainUid, namespace, domainVersion);
219+
}
220+
206221
/**
207222
* Shutdown the domain.
208223
*

integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/impl/Domain.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,21 @@ public static oracle.weblogic.domain.Domain getDomainCustomResource(String domai
165165
return Kubernetes.getDomainCustomResource(domainUid, namespace);
166166
}
167167

168+
/**
169+
* Get a Domain Custom Resource.
170+
*
171+
* @param domainUid unique domain identifier
172+
* @param namespace name of namespace
173+
* @param domainVersion domain version
174+
* @return domain custom resource or null if Domain does not exist
175+
* @throws ApiException if Kubernetes request fails
176+
*/
177+
public static oracle.weblogic.domain.Domain getDomainCustomResource(String domainUid,
178+
String namespace,
179+
String domainVersion) throws ApiException {
180+
return Kubernetes.getDomainCustomResource(domainUid, namespace, domainVersion);
181+
}
182+
168183
/**
169184
* Patch the Domain Custom Resource.
170185
*

integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/impl/primitive/Kubernetes.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1265,6 +1265,39 @@ public static Domain getDomainCustomResource(String domainUid, String namespace)
12651265
return null;
12661266
}
12671267

1268+
/**
1269+
* Get the Domain Custom Resource.
1270+
*
1271+
* @param domainUid unique domain identifier
1272+
* @param namespace name of namespace
1273+
* @param domainVersion version of domain
1274+
* @return domain custom resource or null if Domain does not exist
1275+
* @throws ApiException if Kubernetes request fails
1276+
*/
1277+
public static Domain getDomainCustomResource(String domainUid, String namespace, String domainVersion)
1278+
throws ApiException {
1279+
Object domain;
1280+
try {
1281+
domain = customObjectsApi.getNamespacedCustomObject(
1282+
DOMAIN_GROUP, // custom resource's group name
1283+
domainVersion, // //custom resource's version
1284+
namespace, // custom resource's namespace
1285+
DOMAIN_PLURAL, // custom resource's plural name
1286+
domainUid // custom object's name
1287+
);
1288+
} catch (ApiException apex) {
1289+
getLogger().severe(apex.getResponseBody());
1290+
throw apex;
1291+
}
1292+
1293+
if (domain != null) {
1294+
return handleResponse(domain, Domain.class);
1295+
}
1296+
1297+
getLogger().warning("Domain Custom Resource '" + domainUid + "' not found in namespace " + namespace);
1298+
return null;
1299+
}
1300+
12681301
/**
12691302
* Patch the Domain Custom Resource using JSON Patch.JSON Patch is a format for describing changes to a JSON document
12701303
* using a series of operations. JSON Patch is specified in RFC 6902 from the IETF. For example, the following

integration-tests/src/test/java/oracle/weblogic/kubernetes/utils/DomainUtils.java

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
import oracle.weblogic.domain.Cluster;
4646
import oracle.weblogic.domain.Configuration;
4747
import oracle.weblogic.domain.Domain;
48+
import oracle.weblogic.domain.DomainCondition;
4849
import oracle.weblogic.domain.DomainSpec;
4950
import oracle.weblogic.domain.Model;
5051
import oracle.weblogic.domain.ServerPod;
@@ -80,6 +81,7 @@
8081
import static oracle.weblogic.kubernetes.actions.TestActions.createConfigMap;
8182
import static oracle.weblogic.kubernetes.actions.TestActions.createDomainCustomResource;
8283
import static oracle.weblogic.kubernetes.actions.TestActions.deleteDomainCustomResource;
84+
import static oracle.weblogic.kubernetes.actions.TestActions.getDomainCustomResource;
8385
import static oracle.weblogic.kubernetes.actions.TestActions.getJob;
8486
import static oracle.weblogic.kubernetes.actions.TestActions.getPodLog;
8587
import static oracle.weblogic.kubernetes.actions.TestActions.listPods;
@@ -749,4 +751,68 @@ public static void shutdownDomainAndVerify(String domainNamespace, String domain
749751
}
750752
}
751753

754+
/**
755+
* Check the domain status condition type does not exist.
756+
* @param domainUid uid of the domain
757+
* @param domainNamespace namespace of the domain
758+
* @param conditionType the type name of condition, accepted value: Completed, Available, Failed and
759+
* ConfigChangesPendingRestart
760+
* @return true if the condition type does not exist, false otherwise
761+
*/
762+
public static boolean verifyDomainStatusConditionTypeDoesNotExist(String domainUid,
763+
String domainNamespace,
764+
String conditionType) {
765+
return verifyDomainStatusConditionTypeDoesNotExist(domainUid, domainNamespace,
766+
conditionType, DOMAIN_VERSION);
767+
}
768+
769+
/**
770+
* Check the domain status condition type does not exist.
771+
* @param domainUid uid of the domain
772+
* @param domainNamespace namespace of the domain
773+
* @param conditionType the type name of condition, accepted value: Completed, Available, Failed and
774+
* ConfigChangesPendingRestart
775+
* @param domainVersion version of domain
776+
* @return true if the condition type does not exist, false otherwise
777+
*/
778+
public static boolean verifyDomainStatusConditionTypeDoesNotExist(String domainUid,
779+
String domainNamespace,
780+
String conditionType,
781+
String domainVersion) {
782+
Domain domain = assertDoesNotThrow(() -> getDomainCustomResource(domainUid, domainNamespace,
783+
domainVersion));
784+
785+
if (domain != null && domain.getStatus() != null) {
786+
List<DomainCondition> domainConditionList = domain.getStatus().getConditions();
787+
for (DomainCondition domainCondition : domainConditionList) {
788+
if (domainCondition.getType().equalsIgnoreCase(conditionType)) {
789+
return false;
790+
}
791+
}
792+
} else {
793+
if (domain == null) {
794+
getLogger().info("domain is null");
795+
} else {
796+
getLogger().info("domain status is null");
797+
}
798+
}
799+
return true;
800+
}
801+
802+
/**
803+
* Obtains the specified domain, validates that it has a spec and no rolling condition.
804+
* @param domainNamespace the namespace
805+
* @param domainUid the UID
806+
*/
807+
@org.jetbrains.annotations.NotNull
808+
public static Domain getAndValidateInitialDomain(String domainNamespace, String domainUid) {
809+
Domain domain = assertDoesNotThrow(() -> getDomainCustomResource(domainUid, domainNamespace),
810+
String.format("getDomainCustomResource failed "
811+
+ "with ApiException when tried to get domain %s in namespace %s",
812+
domainUid, domainNamespace));
813+
814+
assertNotNull(domain, "Got null domain resource");
815+
assertNotNull(domain.getSpec(), domain + "/spec is null");
816+
return domain;
817+
}
752818
}

integration-tests/src/test/java/oracle/weblogic/kubernetes/utils/K8sEvents.java

Lines changed: 68 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import static oracle.weblogic.kubernetes.actions.TestActions.getPodLog;
2727
import static oracle.weblogic.kubernetes.utils.CommonTestUtils.withStandardRetryPolicy;
2828
import static oracle.weblogic.kubernetes.utils.ThreadSafeLogger.getLogger;
29+
import static org.junit.jupiter.api.Assertions.assertEquals;
2930
import static org.junit.jupiter.api.Assertions.assertTrue;
3031
import static org.junit.jupiter.api.Assertions.fail;
3132

@@ -35,6 +36,25 @@
3536
public class K8sEvents {
3637

3738
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";
3858

3959
/**
4060
* Utility method to check event.
@@ -492,23 +512,54 @@ private static void verifyOperatorDetails(
492512
}
493513
}
494514

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+
}
495532

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) {
513546

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+
}
514565
}

0 commit comments

Comments
 (0)