Skip to content

Commit def5404

Browse files
authored
Merge pull request #844 from oracle/owls_69951
OWLS-69951 Add unit tests for Domain status processing and cleanup
2 parents 7c31b28 + 72e3938 commit def5404

34 files changed

+1991
-1975
lines changed

docs/domains/Domain.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,13 @@
146146
"type": "string"
147147
},
148148
"type": {
149-
"description": "Type is the type of the condition. Currently, valid types are Progressing, Available, and Failure. Required",
150-
"type": "string"
149+
"description": "The type of the condition. Valid types are Progressing, Available, and Failed. Required",
150+
"type": "string",
151+
"enum": [
152+
"Progressing",
153+
"Available",
154+
"Failed"
155+
]
151156
},
152157
"lastProbeTime": {
153158
"description": "Last time we probed the condition.",

docs/domains/Domain.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ ServerPod describes the configuration for a Kubernetes pod for a server.
127127
| message | string | Human-readable message indicating details about last transition. |
128128
| reason | string | Unique, one-word, CamelCase reason for the condition's last transition. |
129129
| status | string | Status is the status of the condition. Can be True, False, Unknown. Required |
130-
| type | string | Type is the type of the condition. Currently, valid types are Progressing, Available, and Failure. Required |
130+
| type | string | The type of the condition. Valid types are Progressing, Available, and Failed. Required |
131131

132132
### Server Status
133133

docs/domains/index.html

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1066,8 +1066,13 @@
10661066
"type": "string"
10671067
},
10681068
"type": {
1069-
"description": "Type is the type of the condition. Currently, valid types are Progressing, Available, and Failure. Required",
1070-
"type": "string"
1069+
"description": "The type of the condition. Valid types are Progressing, Available, and Failed. Required",
1070+
"type": "string",
1071+
"enum": [
1072+
"Progressing",
1073+
"Available",
1074+
"Failed"
1075+
]
10711076
},
10721077
"lastProbeTime": {
10731078
"description": "Last time we probed the condition.",

json-schema/src/main/java/oracle/kubernetes/json/SchemaGenerator.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,13 +186,17 @@ void generateFieldIn(Map<String, Object> map, Field field) {
186186
}
187187

188188
private boolean includeInSchema(Field field) {
189-
return !isStatic(field) && !ignoreAsDeprecated(field);
189+
return !isStatic(field) && !isVolatile(field) && !ignoreAsDeprecated(field);
190190
}
191191

192192
private boolean isStatic(Field field) {
193193
return Modifier.isStatic(field.getModifiers());
194194
}
195195

196+
private boolean isVolatile(Field field) {
197+
return Modifier.isVolatile(field.getModifiers());
198+
}
199+
196200
private boolean ignoreAsDeprecated(Field field) {
197201
return !includeDeprecated && field.getAnnotation(Deprecated.class) != null;
198202
}

json-schema/src/test/java/oracle/kubernetes/json/SchemaGeneratorTest.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,16 @@ public void generateSchemaForIntArray() throws NoSuchFieldException {
9090
@SuppressWarnings("unused")
9191
private int[] intArray;
9292

93+
@Test
94+
public void doNotGenerateSchemaForVolatileFields() throws NoSuchFieldException {
95+
Object schema = generateForField(getClass().getDeclaredField("ignoreMe"));
96+
97+
assertThat(schema, hasNoJsonPath("$.ignoreMe"));
98+
}
99+
100+
@SuppressWarnings("unused")
101+
private volatile boolean ignoreMe;
102+
93103
@Test
94104
public void generateSchemaForEnum() throws NoSuchFieldException {
95105
Object schema = generateForField(getClass().getDeclaredField("colors"));

model/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,11 @@
151151
<artifactId>junit</artifactId>
152152
<scope>test</scope>
153153
</dependency>
154+
<dependency>
155+
<groupId>com.meterware.simplestub</groupId>
156+
<artifactId>simplestub</artifactId>
157+
<scope>test</scope>
158+
</dependency>
154159
<dependency>
155160
<groupId>com.fasterxml.jackson.core</groupId>
156161
<artifactId>jackson-databind</artifactId>
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Copyright 2019 Oracle Corporation and/or its affiliates. All rights reserved.
2+
// Licensed under the Universal Permissive License v 1.0 as shown at
3+
// http://oss.oracle.com/licenses/upl.
4+
5+
package oracle.kubernetes.utils;
6+
7+
import org.joda.time.DateTime;
8+
9+
/** A wrapper for the system clock that facilitates unit testing of time. */
10+
public abstract class SystemClock {
11+
12+
private static SystemClock DELEGATE =
13+
new SystemClock() {
14+
@Override
15+
public DateTime getCurrentTime() {
16+
return DateTime.now();
17+
}
18+
};
19+
20+
/**
21+
* Returns the current time.
22+
*
23+
* @return a time instance
24+
*/
25+
public static DateTime now() {
26+
return DELEGATE.getCurrentTime();
27+
}
28+
29+
/**
30+
* Returns the delegate's current time.
31+
*
32+
* @return a time instance
33+
*/
34+
public abstract DateTime getCurrentTime();
35+
}

model/src/main/java/oracle/kubernetes/weblogic/domain/v2/Domain.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,17 @@ public DomainStatus getStatus() {
287287
return status;
288288
}
289289

290+
/**
291+
* DomainStatus represents information about the status of a domain. Status may trail the actual
292+
* state of a system.
293+
*
294+
* @return Status
295+
*/
296+
public DomainStatus getOrCreateStatus() {
297+
if (status == null) status = new DomainStatus();
298+
return status;
299+
}
300+
290301
/**
291302
* DomainStatus represents information about the status of a domain. Status may trail the actual
292303
* state of a system.

model/src/main/java/oracle/kubernetes/weblogic/domain/v2/DomainCondition.java

Lines changed: 16 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import com.google.gson.annotations.SerializedName;
99
import javax.validation.constraints.NotNull;
1010
import oracle.kubernetes.json.Description;
11+
import oracle.kubernetes.utils.SystemClock;
1112
import org.apache.commons.lang3.builder.EqualsBuilder;
1213
import org.apache.commons.lang3.builder.HashCodeBuilder;
1314
import org.apache.commons.lang3.builder.ToStringBuilder;
@@ -43,12 +44,15 @@ public class DomainCondition implements Comparable<DomainCondition> {
4344
private String status;
4445

4546
@Description(
46-
"Type is the type of the condition. Currently, valid types are Progressing, "
47-
+ "Available, and Failure. Required")
48-
@SerializedName("type")
49-
@Expose
47+
"The type of the condition. Valid types are Progressing, "
48+
+ "Available, and Failed. Required")
5049
@NotNull
51-
private String type;
50+
private final DomainConditionType type;
51+
52+
public DomainCondition(DomainConditionType conditionType) {
53+
lastTransitionTime = SystemClock.now();
54+
type = conditionType;
55+
}
5256

5357
/**
5458
* Last time we probed the condition.
@@ -88,26 +92,6 @@ public DateTime getLastTransitionTime() {
8892
return lastTransitionTime;
8993
}
9094

91-
/**
92-
* Last time the condition transitioned from one status to another.
93-
*
94-
* @param lastTransitionTime time
95-
*/
96-
public void setLastTransitionTime(DateTime lastTransitionTime) {
97-
this.lastTransitionTime = lastTransitionTime;
98-
}
99-
100-
/**
101-
* Last time the condition transitioned from one status to another.
102-
*
103-
* @param lastTransitionTime time
104-
* @return this
105-
*/
106-
public DomainCondition withLastTransitionTime(DateTime lastTransitionTime) {
107-
this.lastTransitionTime = lastTransitionTime;
108-
return this;
109-
}
110-
11195
/**
11296
* Human-readable message indicating details about last transition.
11397
*
@@ -117,22 +101,14 @@ public String getMessage() {
117101
return message;
118102
}
119103

120-
/**
121-
* Human-readable message indicating details about last transition.
122-
*
123-
* @param message message
124-
*/
125-
public void setMessage(String message) {
126-
this.message = message;
127-
}
128-
129104
/**
130105
* Human-readable message indicating details about last transition.
131106
*
132107
* @param message message
133108
* @return this
134109
*/
135110
public DomainCondition withMessage(String message) {
111+
lastTransitionTime = SystemClock.now();
136112
this.message = message;
137113
return this;
138114
}
@@ -146,22 +122,14 @@ public String getReason() {
146122
return reason;
147123
}
148124

149-
/**
150-
* Unique, one-word, CamelCase reason for the condition's last transition.
151-
*
152-
* @param reason reason
153-
*/
154-
public void setReason(String reason) {
155-
this.reason = reason;
156-
}
157-
158125
/**
159126
* Unique, one-word, CamelCase reason for the condition's last transition.
160127
*
161128
* @param reason reason
162129
* @return this
163130
*/
164131
public DomainCondition withReason(String reason) {
132+
lastTransitionTime = SystemClock.now();
165133
this.reason = reason;
166134
return this;
167135
}
@@ -175,22 +143,14 @@ public String getStatus() {
175143
return status;
176144
}
177145

178-
/**
179-
* Status is the status of the condition. Can be True, False, Unknown. (Required)
180-
*
181-
* @param status status
182-
*/
183-
public void setStatus(String status) {
184-
this.status = status;
185-
}
186-
187146
/**
188147
* Status is the status of the condition. Can be True, False, Unknown. (Required)
189148
*
190149
* @param status status
191150
* @return this
192151
*/
193152
public DomainCondition withStatus(String status) {
153+
lastTransitionTime = SystemClock.now();
194154
this.status = status;
195155
return this;
196156
}
@@ -201,30 +161,12 @@ public DomainCondition withStatus(String status) {
201161
*
202162
* @return type
203163
*/
204-
public String getType() {
164+
public DomainConditionType getType() {
205165
return type;
206166
}
207167

208-
/**
209-
* Type is the type of the condition. Currently, valid types are Progressing, Available, and
210-
* Failure. (Required)
211-
*
212-
* @param type type
213-
*/
214-
public void setType(String type) {
215-
this.type = type;
216-
}
217-
218-
/**
219-
* Type is the type of the condition. Currently, valid types are Progressing, Available, and
220-
* Failure. (Required)
221-
*
222-
* @param type type
223-
* @return this
224-
*/
225-
public DomainCondition withType(String type) {
226-
this.type = type;
227-
return this;
168+
public boolean hasType(DomainConditionType type) {
169+
return type == this.type;
228170
}
229171

230172
@Override
@@ -243,10 +185,8 @@ public String toString() {
243185
public int hashCode() {
244186
return new HashCodeBuilder()
245187
.append(reason)
246-
.append(lastTransitionTime)
247188
.append(message)
248189
.append(type)
249-
.append(lastProbeTime)
250190
.append(status)
251191
.toHashCode();
252192
}
@@ -256,16 +196,14 @@ public boolean equals(Object other) {
256196
if (other == this) {
257197
return true;
258198
}
259-
if ((other instanceof DomainCondition) == false) {
199+
if (!(other instanceof DomainCondition)) {
260200
return false;
261201
}
262202
DomainCondition rhs = ((DomainCondition) other);
263203
return new EqualsBuilder()
264204
.append(reason, rhs.reason)
265-
.append(lastTransitionTime, rhs.lastTransitionTime)
266205
.append(message, rhs.message)
267206
.append(type, rhs.type)
268-
.append(lastProbeTime, rhs.lastProbeTime)
269207
.append(status, rhs.status)
270208
.isEquals();
271209
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Copyright 2019 Oracle Corporation and/or its affiliates. All rights reserved.
2+
// Licensed under the Universal Permissive License v 1.0 as shown at
3+
// http://oss.oracle.com/licenses/upl.
4+
5+
package oracle.kubernetes.weblogic.domain.v2;
6+
7+
public enum DomainConditionType {
8+
Progressing,
9+
Available,
10+
Failed
11+
}

0 commit comments

Comments
 (0)