Skip to content

Commit

Permalink
fix(core): Fixing NPE when sorting by non-existent startTime (#1575)
Browse files Browse the repository at this point in the history
  • Loading branch information
robzienert committed Aug 24, 2017
1 parent b3687ed commit d6dfeaf
Showing 1 changed file with 19 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -84,10 +83,10 @@ public Boolean call(Execution execution) {
);

private Comparator<PipelineExecutionDetails> sorter = (o1, o2) -> {
if (o1.startTime > o2.startTime) {
if (o1.getRealStartTime() > o2.getRealStartTime()) {
return 1;
}
if (o1.startTime < o2.startTime) {
if (o1.getRealStartTime() < o2.getRealStartTime()) {
return -1;
}
return 0;
Expand Down Expand Up @@ -187,7 +186,7 @@ private void cleanup(List<PipelineExecutionDetails> executions) {
long startTime = p.startTime == null ? p.buildTime : p.startTime;
long days = ChronoUnit.DAYS.between(Instant.ofEpochMilli(startTime), Instant.ofEpochMilli(clock.millis()));
if (days > thresholdDays && !hasEntityTags(p.id)) {
log.info("Deleting pipeline execution " + p.id + " (startTime: " + new Date(startTime) + ", application: " + p.application + ", pipelineConfigId: " + p.pipelineConfigId + ", status: " + p.status + ")");
log.info("Deleting pipeline execution " + p.id + ": " + p.toString());
executionRepository.deletePipeline(p.id);
}
});
Expand Down Expand Up @@ -220,5 +219,21 @@ private static class PipelineExecutionDetails {
this.startTime = startTime;
this.buildTime = buildTime;
}

Long getRealStartTime() {
return startTime == null ? buildTime : startTime;
}

@Override
public String toString() {
return "PipelineExecutionDetails{" +
"id='" + id + '\'' +
", application='" + application + '\'' +
", pipelineConfigId='" + pipelineConfigId + '\'' +
", status=" + status +
", startTime=" + startTime +
", buildTime=" + buildTime +
'}';
}
}
}

0 comments on commit d6dfeaf

Please sign in to comment.