Skip to content

Commit 02a2c1f

Browse files
committed
Add duration and ETA to RepairRunStatus
1 parent e23de9f commit 02a2c1f

File tree

3 files changed

+77
-33
lines changed

3 files changed

+77
-33
lines changed

src/main/java/com/spotify/reaper/resources/CommonTools.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
import java.util.List;
3030
import java.util.Set;
3131

32+
import javax.annotation.Nullable;
33+
3234
import static com.google.common.base.Preconditions.checkNotNull;
3335

3436
public class CommonTools {
@@ -245,7 +247,8 @@ public static RepairUnit getNewOrExistingRepairUnit(AppContext context, Cluster
245247
return theRepairUnit;
246248
}
247249

248-
public static String dateTimeToISO8601(DateTime dateTime) {
250+
@Nullable
251+
public static String dateTimeToISO8601(@Nullable DateTime dateTime) {
249252
if (null == dateTime) {
250253
return null;
251254
}

src/main/java/com/spotify/reaper/resources/view/RepairRunStatus.java

+72-31
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,13 @@
1616
import com.fasterxml.jackson.annotation.JsonIgnore;
1717
import com.fasterxml.jackson.annotation.JsonProperty;
1818
import com.spotify.reaper.core.RepairRun;
19-
import com.spotify.reaper.core.RepairSegment;
2019
import com.spotify.reaper.core.RepairUnit;
2120
import com.spotify.reaper.resources.CommonTools;
2221

22+
import org.apache.cassandra.repair.RepairParallelism;
23+
import org.apache.commons.lang.time.DurationFormatUtils;
2324
import org.joda.time.DateTime;
25+
import org.joda.time.Duration;
2426
import org.joda.time.format.ISODateTimeFormat;
2527

2628
import java.util.Collection;
@@ -48,8 +50,8 @@ public class RepairRunStatus {
4850
@JsonProperty("keyspace_name")
4951
private String keyspaceName;
5052

51-
@JsonProperty("run_state")
52-
private String runState;
53+
@JsonProperty
54+
private RepairRun.RunState state;
5355

5456
@JsonIgnore
5557
private DateTime creationTime;
@@ -66,18 +68,24 @@ public class RepairRunStatus {
6668
@JsonProperty
6769
private double intensity;
6870

69-
@JsonProperty("segment_count")
70-
private int segmentCount;
71+
@JsonProperty("total_segments")
72+
private int totalSegments;
7173

7274
@JsonProperty("repair_parallelism")
73-
private String repairParallelism;
75+
private RepairParallelism repairParallelism;
7476

7577
@JsonProperty("segments_repaired")
7678
private int segmentsRepaired;
7779

7880
@JsonProperty("last_event")
7981
private String lastEvent;
8082

83+
@JsonProperty
84+
private String duration;
85+
86+
@JsonIgnore
87+
private DateTime estimatedTimeOfArrival;
88+
8189
/**
8290
* Default public constructor Required for Jackson JSON parsing.
8391
*/
@@ -91,23 +99,45 @@ public RepairRunStatus(RepairRun repairRun, RepairUnit repairUnit, int segmentsR
9199
this.clusterName = repairRun.getClusterName();
92100
this.columnFamilies = repairUnit.getColumnFamilies();
93101
this.keyspaceName = repairUnit.getKeyspaceName();
94-
this.runState = repairRun.getRunState().name();
102+
this.state = repairRun.getRunState();
95103
this.creationTime = repairRun.getCreationTime();
96104
this.startTime = repairRun.getStartTime();
97105
this.endTime = repairRun.getEndTime();
98106
this.pauseTime = repairRun.getPauseTime();
99107
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();
102110
this.segmentsRepaired = segmentsRepaired;
103111
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+
}
104137
}
105138

106139
@JsonProperty("creation_time")
107140
public String getCreationTimeISO8601() {
108-
if (creationTime == null) {
109-
return null;
110-
}
111141
return CommonTools.dateTimeToISO8601(creationTime);
112142
}
113143

@@ -120,9 +150,6 @@ public void setCreationTimeISO8601(String dateStr) {
120150

121151
@JsonProperty("start_time")
122152
public String getStartTimeISO8601() {
123-
if (startTime == null) {
124-
return null;
125-
}
126153
return CommonTools.dateTimeToISO8601(startTime);
127154
}
128155

@@ -135,9 +162,6 @@ public void setStartTimeISO8601(String dateStr) {
135162

136163
@JsonProperty("end_time")
137164
public String getEndTimeISO8601() {
138-
if (endTime == null) {
139-
return null;
140-
}
141165
return CommonTools.dateTimeToISO8601(endTime);
142166
}
143167

@@ -150,9 +174,6 @@ public void setEndTimeISO8601(String dateStr) {
150174

151175
@JsonProperty("pause_time")
152176
public String getPauseTimeISO8601() {
153-
if (pauseTime == null) {
154-
return null;
155-
}
156177
return CommonTools.dateTimeToISO8601(pauseTime);
157178
}
158179

@@ -211,12 +232,12 @@ public void setKeyspaceName(String keyspaceName) {
211232
this.keyspaceName = keyspaceName;
212233
}
213234

214-
public String getRunState() {
215-
return runState;
235+
public RepairRun.RunState getState() {
236+
return state;
216237
}
217238

218-
public void setRunState(String runState) {
219-
this.runState = runState;
239+
public void setState(RepairRun.RunState runState) {
240+
this.state = runState;
220241
}
221242

222243
public DateTime getCreationTime() {
@@ -259,19 +280,19 @@ public void setIntensity(double intensity) {
259280
this.intensity = intensity;
260281
}
261282

262-
public int getSegmentCount() {
263-
return segmentCount;
283+
public int getTotalSegments() {
284+
return totalSegments;
264285
}
265286

266-
public void setSegmentCount(int segmentCount) {
267-
this.segmentCount = segmentCount;
287+
public void setTotalSegments(int segmentCount) {
288+
this.totalSegments = segmentCount;
268289
}
269290

270-
public String getRepairParallelism() {
291+
public RepairParallelism getRepairParallelism() {
271292
return repairParallelism;
272293
}
273294

274-
public void setRepairParallelism(String repairParallelism) {
295+
public void setRepairParallelism(RepairParallelism repairParallelism) {
275296
this.repairParallelism = repairParallelism;
276297
}
277298

@@ -290,4 +311,24 @@ public String getLastEvent() {
290311
public void setLastEvent(String lastEvent) {
291312
this.lastEvent = lastEvent;
292313
}
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+
}
293334
}

src/test/java/com/spotify/reaper/unit/resources/RepairRunResourceTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ public void testTriggerRepairRun() throws Exception {
190190
assertTrue(response.getEntity() instanceof RepairRunStatus);
191191
// the thing we get as a reply from the endpoint is a not started run. This is because the
192192
// executor didn't have time to start the run
193-
assertEquals(RepairRun.RunState.NOT_STARTED.name(), repairRunStatus.getRunState());
193+
assertEquals(RepairRun.RunState.NOT_STARTED, repairRunStatus.getState());
194194

195195
// give the executor some time to actually start the run
196196
Thread.sleep(50);

0 commit comments

Comments
 (0)