Skip to content

Commit 59e39c6

Browse files
authored
Added tests to verify the Cluster Status (#3529)
* Added tests to verify the Cluster Status
1 parent 9aad69b commit 59e39c6

File tree

8 files changed

+585
-6
lines changed

8 files changed

+585
-6
lines changed
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
// Copyright (c) 2022, Oracle and/or its affiliates.
2+
// Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
3+
4+
package oracle.weblogic.domain;
5+
6+
import java.time.OffsetDateTime;
7+
8+
import io.swagger.annotations.ApiModel;
9+
import io.swagger.annotations.ApiModelProperty;
10+
import org.apache.commons.lang3.builder.EqualsBuilder;
11+
import org.apache.commons.lang3.builder.HashCodeBuilder;
12+
import org.apache.commons.lang3.builder.ToStringBuilder;
13+
14+
@ApiModel(
15+
description = "ClusterCondition contains details for the current condition of this cluster.")
16+
public class ClusterCondition {
17+
18+
@ApiModelProperty(
19+
"The type of the condition. Valid types are "
20+
+ "Available, Failed, and Rolling.")
21+
private String type;
22+
23+
@ApiModelProperty("Last time the condition transitioned from one status to another.")
24+
private OffsetDateTime lastTransitionTime;
25+
26+
@ApiModelProperty("Human-readable message indicating details about last transition.")
27+
private String message;
28+
29+
@ApiModelProperty("Status is the status of the condition. Can be True, False, Unknown. Required.")
30+
private String status;
31+
32+
public ClusterCondition type(String type) {
33+
this.type = type;
34+
return this;
35+
}
36+
37+
public String type() {
38+
return type;
39+
}
40+
41+
public String getType() {
42+
return type;
43+
}
44+
45+
public void setType(String type) {
46+
this.type = type;
47+
}
48+
49+
public ClusterCondition lastTransitionTime(OffsetDateTime lastTransitionTime) {
50+
this.lastTransitionTime = lastTransitionTime;
51+
return this;
52+
}
53+
54+
public OffsetDateTime lastTransitionTime() {
55+
return lastTransitionTime;
56+
}
57+
58+
public OffsetDateTime getLastTransitionTime() {
59+
return lastTransitionTime;
60+
}
61+
62+
public void setLastTransitionTime(OffsetDateTime lastTransitionTime) {
63+
this.lastTransitionTime = lastTransitionTime;
64+
}
65+
66+
public ClusterCondition message(String message) {
67+
this.message = message;
68+
return this;
69+
}
70+
71+
public String message() {
72+
return message;
73+
}
74+
75+
public String getMessage() {
76+
return message;
77+
}
78+
79+
public void setMessage(String message) {
80+
this.message = message;
81+
}
82+
83+
public ClusterCondition status(String status) {
84+
this.status = status;
85+
return this;
86+
}
87+
88+
public String status() {
89+
return status;
90+
}
91+
92+
public String getStatus() {
93+
return status;
94+
}
95+
96+
public void setStatus(String status) {
97+
this.status = status;
98+
}
99+
100+
@Override
101+
public String toString() {
102+
return new ToStringBuilder(this)
103+
.append("type", type)
104+
.append("lastTransitionTime", lastTransitionTime)
105+
.append("message", message)
106+
.append("status", status)
107+
.toString();
108+
}
109+
110+
@Override
111+
public int hashCode() {
112+
return new HashCodeBuilder()
113+
.append(type)
114+
.append(lastTransitionTime)
115+
.append(message)
116+
.append(status)
117+
.toHashCode();
118+
}
119+
120+
@Override
121+
public boolean equals(Object other) {
122+
if (this == other) {
123+
return true;
124+
}
125+
126+
if (other == null || getClass() != other.getClass()) {
127+
return false;
128+
}
129+
ClusterCondition rhs = (ClusterCondition) other;
130+
return new EqualsBuilder()
131+
.append(type, rhs.type)
132+
.append(lastTransitionTime, rhs.lastTransitionTime)
133+
.append(message, rhs.message)
134+
.append(status, rhs.status)
135+
.isEquals();
136+
}
137+
}

integration-tests/src/test/java/oracle/weblogic/domain/ClusterStatus.java

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33

44
package oracle.weblogic.domain;
55

6+
import java.util.ArrayList;
7+
import java.util.List;
8+
69
import io.swagger.annotations.ApiModel;
710
import io.swagger.annotations.ApiModelProperty;
811
import org.apache.commons.lang3.builder.EqualsBuilder;
@@ -43,6 +46,15 @@ public class ClusterStatus {
4346
allowableValues = "range[0,infinity]")
4447
private Integer replicasGoal;
4548

49+
@ApiModelProperty(
50+
value = "The generation observed by the WebLogic operator.",
51+
allowableValues = "range[0,infinity]")
52+
private Integer observedGeneration;
53+
54+
@ApiModelProperty(
55+
value = "Current service state of the cluster.")
56+
private List<ClusterCondition> conditions = new ArrayList<>();
57+
4658
public ClusterStatus clusterName(String clusterName) {
4759
this.clusterName = clusterName;
4860
return this;
@@ -145,6 +157,49 @@ public void setReplicasGoal(Integer replicasGoal) {
145157
this.replicasGoal = replicasGoal;
146158
}
147159

160+
public ClusterStatus conditions(List<ClusterCondition> conditions) {
161+
this.conditions = conditions;
162+
return this;
163+
}
164+
165+
public List<ClusterCondition> conditions() {
166+
return conditions;
167+
}
168+
169+
/**
170+
* Adds condition item.
171+
* @param conditionsItem Condition
172+
* @return this
173+
*/
174+
public ClusterStatus addConditionsItem(ClusterCondition conditionsItem) {
175+
if (conditions == null) {
176+
conditions = new ArrayList<>();
177+
}
178+
conditions.add(conditionsItem);
179+
return this;
180+
}
181+
182+
public List<ClusterCondition> getConditions() {
183+
return conditions;
184+
}
185+
186+
public void setConditions(List<ClusterCondition> conditions) {
187+
this.conditions = conditions;
188+
}
189+
190+
public Integer getObservedGeneration() {
191+
return observedGeneration;
192+
}
193+
194+
public ClusterStatus observedGeneration(int observedGeneration) {
195+
this.observedGeneration = observedGeneration;
196+
return this;
197+
}
198+
199+
public void setObservedGeneration(int observedGeneration) {
200+
this.observedGeneration = observedGeneration;
201+
}
202+
148203
@Override
149204
public String toString() {
150205
return new ToStringBuilder(this)
@@ -154,6 +209,8 @@ public String toString() {
154209
.append("maximumReplicas", maximumReplicas)
155210
.append("mimimumReplicas", minimumReplicas)
156211
.append("replicasGoal", replicasGoal)
212+
.append("observedGeneration", observedGeneration)
213+
.append("conditions", conditions)
157214
.toString();
158215
}
159216

@@ -166,6 +223,8 @@ public int hashCode() {
166223
.append(maximumReplicas)
167224
.append(minimumReplicas)
168225
.append(replicasGoal)
226+
.append(observedGeneration)
227+
.append(conditions)
169228
.toHashCode();
170229
}
171230

@@ -186,6 +245,8 @@ public boolean equals(Object other) {
186245
.append(maximumReplicas, rhs.maximumReplicas)
187246
.append(minimumReplicas, rhs.minimumReplicas)
188247
.append(replicasGoal, rhs.replicasGoal)
248+
.append(observedGeneration, rhs.observedGeneration)
249+
.append(DomainResource.sortList(conditions), DomainResource.sortList(rhs.conditions))
189250
.isEquals();
190251
}
191252
}

integration-tests/src/test/java/oracle/weblogic/domain/DomainResource.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33

44
package oracle.weblogic.domain;
55

6+
import java.util.Arrays;
7+
import java.util.Comparator;
8+
import java.util.List;
9+
610
import io.kubernetes.client.common.KubernetesObject;
711
import io.kubernetes.client.openapi.models.V1ObjectMeta;
812
import io.swagger.annotations.ApiModel;
@@ -116,6 +120,21 @@ public void setStatus(DomainStatus status) {
116120
this.status = status;
117121
}
118122

123+
@SuppressWarnings({"rawtypes"})
124+
static List sortList(List list) {
125+
return sortList(list, null);
126+
}
127+
128+
@SuppressWarnings({"rawtypes", "unchecked"})
129+
static List sortList(List list, Comparator c) {
130+
if (list != null) {
131+
Object[] a = list.toArray(new Object[0]);
132+
Arrays.sort(a, c);
133+
return Arrays.asList(a);
134+
}
135+
return List.of();
136+
}
137+
119138
@Override
120139
public String toString() {
121140
return new ToStringBuilder(this)

integration-tests/src/test/java/oracle/weblogic/domain/DomainStatus.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ public boolean equals(Object other) {
245245
}
246246
DomainStatus rhs = (DomainStatus) other;
247247
return new EqualsBuilder()
248-
.append(conditions, rhs.conditions)
248+
.append(DomainResource.sortList(conditions), DomainResource.sortList(rhs.conditions))
249249
.append(message, rhs.message)
250250
.append(reason, rhs.reason)
251251
.append(servers, rhs.servers)

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,10 @@
8383
import static oracle.weblogic.kubernetes.utils.JobUtils.createDomainJob;
8484
import static oracle.weblogic.kubernetes.utils.JobUtils.getIntrospectJobName;
8585
import static oracle.weblogic.kubernetes.utils.K8sEvents.ABORTED_ERROR;
86+
import static oracle.weblogic.kubernetes.utils.K8sEvents.CLUSTER_AVAILABLE;
87+
import static oracle.weblogic.kubernetes.utils.K8sEvents.CLUSTER_CHANGED;
88+
import static oracle.weblogic.kubernetes.utils.K8sEvents.CLUSTER_COMPLETED;
89+
import static oracle.weblogic.kubernetes.utils.K8sEvents.CLUSTER_DELETED;
8690
import static oracle.weblogic.kubernetes.utils.K8sEvents.DOMAIN_AVAILABLE;
8791
import static oracle.weblogic.kubernetes.utils.K8sEvents.DOMAIN_CHANGED;
8892
import static oracle.weblogic.kubernetes.utils.K8sEvents.DOMAIN_COMPLETED;
@@ -242,6 +246,8 @@ void testK8SEventsSuccess() {
242246
checkEvent(opNamespace, domainNamespace1, domainUid, DOMAIN_CREATED, "Normal", timestamp);
243247
logger.info("verify the Completed event is generated");
244248
checkEvent(opNamespace, domainNamespace1, domainUid, DOMAIN_COMPLETED, "Normal", timestamp);
249+
logger.info("verify the ClusterCompleted event is generated");
250+
checkEvent(opNamespace, domainNamespace1, domainUid, CLUSTER_COMPLETED, "Normal", timestamp);
245251
shutdownDomain(domainUid, domainNamespace1);
246252
}
247253

@@ -389,12 +395,21 @@ void testK8SEventsMultiClusterEvents() {
389395
logger.info("verify the Domain_Available event is generated");
390396
checkEvent(opNamespace, domainNamespace3, domainUid,
391397
DOMAIN_AVAILABLE, "Normal", timestamp);
398+
logger.info("verify the Cluster_Available event is generated");
399+
checkEvent(opNamespace, domainNamespace3, domainUid,
400+
CLUSTER_AVAILABLE, "Normal", timestamp);
392401
logger.info("verify the Completed event is generated");
393402
checkEvent(opNamespace, domainNamespace3,
394403
domainUid, DOMAIN_COMPLETED, "Normal", timestamp);
404+
logger.info("verify the ClusterCompleted event is generated");
405+
checkEvent(opNamespace, domainNamespace3,
406+
domainUid, CLUSTER_COMPLETED, "Normal", timestamp);
395407
logger.info("verify the only 1 Completed event for domain is generated");
396408
assertEquals(1, getOpGeneratedEventCount(domainNamespace3, domainUid,
397409
DOMAIN_COMPLETED, timestamp));
410+
logger.info("verify the only 1 ClusterCompleted event for domain is generated");
411+
assertEquals(1, getOpGeneratedEventCount(domainNamespace3, domainUid,
412+
CLUSTER_COMPLETED, timestamp));
398413
}
399414

400415
/**
@@ -438,6 +453,8 @@ void testDomainK8sEventsScalePastMaxAndChangeIntrospectVersion() {
438453
logger.info("Updating domain resource to set correct replicas size");
439454

440455
assertTrue(scaleCluster(clusterRes1Name, domainNamespace3, 2), "failed to scale cluster via patching");
456+
logger.info("verify the ClusterChanged event is generated");
457+
checkEvent(opNamespace, domainNamespace3, domainUid, CLUSTER_CHANGED, "Normal", timestamp);
441458
checkPodReadyAndServiceExists(adminServerPodName, domainUid, domainNamespace3);
442459

443460
for (int i = 1; i <= replicaCount; i++) {
@@ -660,6 +677,8 @@ void testK8SEventsDelete() {
660677

661678
//verify domain deleted event
662679
checkEvent(opNamespace, domainNamespace2, domainUid, DOMAIN_DELETED, "Normal", timestamp);
680+
//verify cluster deleted event
681+
checkEvent(opNamespace, domainNamespace2, domainUid, CLUSTER_DELETED, "Normal", timestamp);
663682
}
664683

665684
/**

0 commit comments

Comments
 (0)