Skip to content

Commit c991dc6

Browse files
committed
Code cleanup, including moving logic from DomainStatusUpdater into DomainStatus and DomainConditionCode
1 parent 9187e95 commit c991dc6

File tree

22 files changed

+854
-776
lines changed

22 files changed

+854
-776
lines changed

docs/domains/Domain.json

Lines changed: 14 additions & 3 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.",
@@ -297,6 +302,9 @@
297302
"type": "number",
298303
"minimum": 0
299304
},
305+
"modified": {
306+
"type": "boolean"
307+
},
300308
"startTime": {
301309
"description": "RFC 3339 date and time at which the operator started the domain. This will be when the operator begins processing and will precede when the various servers or clusters are available.",
302310
"$ref": "#/definitions/DateTime"
@@ -312,7 +320,10 @@
312320
"description": "A human readable message indicating details about why the domain is in this condition.",
313321
"type": "string"
314322
}
315-
}
323+
},
324+
"required": [
325+
"modified"
326+
]
316327
},
317328
"KubernetesResource": {
318329
"type": "object",

docs/domains/Domain.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ DomainStatus represents information about the status of a domain. Status may tra
4646
| --- | --- | --- |
4747
| conditions | array of [Domain Condition](#domain-condition) | Current service state of domain. |
4848
| message | string | A human readable message indicating details about why the domain is in this condition. |
49+
| modified | boolean | |
4950
| reason | string | A brief CamelCase message indicating details about why the domain is in this state. |
5051
| replicas | number | The number of running managed servers in the WebLogic cluster if there is only one cluster in the domain and where the cluster does not explicitly configure its replicas in a cluster specification. |
5152
| servers | array of [Server Status](#server-status) | Status of WebLogic servers in this domain. |
@@ -127,7 +128,7 @@ ServerPod describes the configuration for a Kubernetes pod for a server.
127128
| message | string | Human-readable message indicating details about last transition. |
128129
| reason | string | Unique, one-word, CamelCase reason for the condition's last transition. |
129130
| 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 |
131+
| type | string | The type of the condition. Valid types are Progressing, Available, and Failed. Required |
131132

132133
### Server Status
133134

docs/domains/index.html

Lines changed: 14 additions & 3 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.",
@@ -1217,6 +1222,9 @@
12171222
"type": "number",
12181223
"minimum": 0.0
12191224
},
1225+
"modified": {
1226+
"type": "boolean"
1227+
},
12201228
"startTime": {
12211229
"description": "RFC 3339 date and time at which the operator started the domain. This will be when the operator begins processing and will precede when the various servers or clusters are available.",
12221230
"$ref": "#/definitions/DateTime"
@@ -1232,7 +1240,10 @@
12321240
"description": "A human readable message indicating details about why the domain is in this condition.",
12331241
"type": "string"
12341242
}
1235-
}
1243+
},
1244+
"required": [
1245+
"modified"
1246+
]
12361247
},
12371248
"KubernetesResource": {
12381249
"type": "object",

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)