16
16
import com .fasterxml .jackson .annotation .JsonIgnore ;
17
17
import com .fasterxml .jackson .annotation .JsonProperty ;
18
18
import com .spotify .reaper .core .RepairRun ;
19
- import com .spotify .reaper .core .RepairSegment ;
20
19
import com .spotify .reaper .core .RepairUnit ;
21
20
import com .spotify .reaper .resources .CommonTools ;
22
21
22
+ import org .apache .cassandra .repair .RepairParallelism ;
23
+ import org .apache .commons .lang .time .DurationFormatUtils ;
23
24
import org .joda .time .DateTime ;
25
+ import org .joda .time .Duration ;
24
26
import org .joda .time .format .ISODateTimeFormat ;
25
27
26
28
import java .util .Collection ;
@@ -48,8 +50,8 @@ public class RepairRunStatus {
48
50
@ JsonProperty ("keyspace_name" )
49
51
private String keyspaceName ;
50
52
51
- @ JsonProperty ( "run_state" )
52
- private String runState ;
53
+ @ JsonProperty
54
+ private RepairRun . RunState state ;
53
55
54
56
@ JsonIgnore
55
57
private DateTime creationTime ;
@@ -66,18 +68,24 @@ public class RepairRunStatus {
66
68
@ JsonProperty
67
69
private double intensity ;
68
70
69
- @ JsonProperty ("segment_count " )
70
- private int segmentCount ;
71
+ @ JsonProperty ("total_segments " )
72
+ private int totalSegments ;
71
73
72
74
@ JsonProperty ("repair_parallelism" )
73
- private String repairParallelism ;
75
+ private RepairParallelism repairParallelism ;
74
76
75
77
@ JsonProperty ("segments_repaired" )
76
78
private int segmentsRepaired ;
77
79
78
80
@ JsonProperty ("last_event" )
79
81
private String lastEvent ;
80
82
83
+ @ JsonProperty
84
+ private String duration ;
85
+
86
+ @ JsonIgnore
87
+ private DateTime estimatedTimeOfArrival ;
88
+
81
89
/**
82
90
* Default public constructor Required for Jackson JSON parsing.
83
91
*/
@@ -91,23 +99,45 @@ public RepairRunStatus(RepairRun repairRun, RepairUnit repairUnit, int segmentsR
91
99
this .clusterName = repairRun .getClusterName ();
92
100
this .columnFamilies = repairUnit .getColumnFamilies ();
93
101
this .keyspaceName = repairUnit .getKeyspaceName ();
94
- this .runState = repairRun .getRunState (). name ();
102
+ this .state = repairRun .getRunState ();
95
103
this .creationTime = repairRun .getCreationTime ();
96
104
this .startTime = repairRun .getStartTime ();
97
105
this .endTime = repairRun .getEndTime ();
98
106
this .pauseTime = repairRun .getPauseTime ();
99
107
this .intensity = CommonTools .roundDoubleNicely (repairRun .getIntensity ());
100
- this .segmentCount = repairRun .getSegmentCount ();
101
- this .repairParallelism = repairRun .getRepairParallelism (). name (). toLowerCase () ;
108
+ this .totalSegments = repairRun .getSegmentCount ();
109
+ this .repairParallelism = repairRun .getRepairParallelism ();
102
110
this .segmentsRepaired = segmentsRepaired ;
103
111
this .lastEvent = repairRun .getLastEvent ();
112
+
113
+ if (startTime == null || endTime == null ) {
114
+ duration = null ;
115
+ } else {
116
+ duration = DurationFormatUtils .formatDurationWords (
117
+ new Duration (startTime .toInstant (), endTime .toInstant ()).getMillis (),
118
+ true , false );
119
+ }
120
+
121
+ if (startTime == null || endTime != null ) {
122
+ estimatedTimeOfArrival = null ;
123
+ } else {
124
+ if (state == RepairRun .RunState .ERROR || state == RepairRun .RunState .DELETED ) {
125
+ estimatedTimeOfArrival = null ;
126
+ } else if (segmentsRepaired == 0 ) {
127
+ estimatedTimeOfArrival = null ;
128
+ }
129
+ else {
130
+ long now = DateTime .now ().getMillis ();
131
+ long currentDuration = now - startTime .getMillis ();
132
+ long millisecondsPerSegment = currentDuration / segmentsRepaired ;
133
+ int segmentsLeft = totalSegments - segmentsRepaired ;
134
+ estimatedTimeOfArrival = new DateTime (now + millisecondsPerSegment * segmentsLeft );
135
+ }
136
+ }
104
137
}
105
138
106
139
@ JsonProperty ("creation_time" )
107
140
public String getCreationTimeISO8601 () {
108
- if (creationTime == null ) {
109
- return null ;
110
- }
111
141
return CommonTools .dateTimeToISO8601 (creationTime );
112
142
}
113
143
@@ -120,9 +150,6 @@ public void setCreationTimeISO8601(String dateStr) {
120
150
121
151
@ JsonProperty ("start_time" )
122
152
public String getStartTimeISO8601 () {
123
- if (startTime == null ) {
124
- return null ;
125
- }
126
153
return CommonTools .dateTimeToISO8601 (startTime );
127
154
}
128
155
@@ -135,9 +162,6 @@ public void setStartTimeISO8601(String dateStr) {
135
162
136
163
@ JsonProperty ("end_time" )
137
164
public String getEndTimeISO8601 () {
138
- if (endTime == null ) {
139
- return null ;
140
- }
141
165
return CommonTools .dateTimeToISO8601 (endTime );
142
166
}
143
167
@@ -150,9 +174,6 @@ public void setEndTimeISO8601(String dateStr) {
150
174
151
175
@ JsonProperty ("pause_time" )
152
176
public String getPauseTimeISO8601 () {
153
- if (pauseTime == null ) {
154
- return null ;
155
- }
156
177
return CommonTools .dateTimeToISO8601 (pauseTime );
157
178
}
158
179
@@ -211,12 +232,12 @@ public void setKeyspaceName(String keyspaceName) {
211
232
this .keyspaceName = keyspaceName ;
212
233
}
213
234
214
- public String getRunState () {
215
- return runState ;
235
+ public RepairRun . RunState getState () {
236
+ return state ;
216
237
}
217
238
218
- public void setRunState ( String runState ) {
219
- this .runState = runState ;
239
+ public void setState ( RepairRun . RunState runState ) {
240
+ this .state = runState ;
220
241
}
221
242
222
243
public DateTime getCreationTime () {
@@ -259,19 +280,19 @@ public void setIntensity(double intensity) {
259
280
this .intensity = intensity ;
260
281
}
261
282
262
- public int getSegmentCount () {
263
- return segmentCount ;
283
+ public int getTotalSegments () {
284
+ return totalSegments ;
264
285
}
265
286
266
- public void setSegmentCount (int segmentCount ) {
267
- this .segmentCount = segmentCount ;
287
+ public void setTotalSegments (int segmentCount ) {
288
+ this .totalSegments = segmentCount ;
268
289
}
269
290
270
- public String getRepairParallelism () {
291
+ public RepairParallelism getRepairParallelism () {
271
292
return repairParallelism ;
272
293
}
273
294
274
- public void setRepairParallelism (String repairParallelism ) {
295
+ public void setRepairParallelism (RepairParallelism repairParallelism ) {
275
296
this .repairParallelism = repairParallelism ;
276
297
}
277
298
@@ -290,4 +311,24 @@ public String getLastEvent() {
290
311
public void setLastEvent (String lastEvent ) {
291
312
this .lastEvent = lastEvent ;
292
313
}
314
+
315
+ public String getDuration () {
316
+ return duration ;
317
+ }
318
+
319
+ public void setDuration (String duration ) {
320
+ this .duration = duration ;
321
+ }
322
+
323
+ @ JsonProperty ("estimate_time_of_arrival" )
324
+ public String getEstimatedTimeOfArrivalISO8601 () {
325
+ return CommonTools .dateTimeToISO8601 (estimatedTimeOfArrival );
326
+ }
327
+
328
+ @ JsonProperty ("estimate_time_of_arrival" )
329
+ public void setEstimatedTimeOfArrivalISO8601 (String dateStr ) {
330
+ if (null != dateStr ) {
331
+ estimatedTimeOfArrival = ISODateTimeFormat .dateTimeNoMillis ().parseDateTime (dateStr );
332
+ }
333
+ }
293
334
}
0 commit comments