Skip to content

Commit

Permalink
Merge pull request #775 from arunagrawal84/3.11
Browse files Browse the repository at this point in the history
Do not throw NPE when no backup is found for the requested date.
  • Loading branch information
arunagrawal-84 authored Feb 7, 2019
2 parents 34eb9e6 + 281e1c0 commit e836056
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions priam/src/main/java/com/netflix/priam/resources/BackupServlet.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
import com.netflix.priam.config.IConfiguration;
import com.netflix.priam.scheduler.PriamScheduler;
import com.netflix.priam.utils.DateUtil;
import com.netflix.priam.utils.DateUtil.DateRange;
import java.time.Instant;
import java.time.temporal.ChronoUnit;
import java.util.*;
import java.util.stream.Collectors;
import javax.ws.rs.*;
Expand Down Expand Up @@ -131,25 +134,26 @@ public Response status() throws Exception {
@Path("/status/{date}")
@Produces(MediaType.APPLICATION_JSON)
public Response statusByDate(@PathParam("date") String date) throws Exception {
JSONObject object = new JSONObject();
Instant startTime = DateUtil.parseInstant(date);
Optional<BackupMetadata> backupMetadataOptional =
this.completedBkups
.locate(date)
.getLatestBackupMetadata(
BackupVersion.SNAPSHOT_BACKUP,
new DateRange(
startTime.truncatedTo(ChronoUnit.DAYS),
startTime
.plus(1, ChronoUnit.DAYS)
.truncatedTo(ChronoUnit.DAYS)))
.stream()
.filter(Objects::nonNull)
.filter(backupMetadata -> backupMetadata.getStatus() == Status.FINISHED)
.filter(
backupMetadata ->
backupMetadata
.getBackupVersion()
.equals(BackupVersion.SNAPSHOT_BACKUP))
.findFirst();

JSONObject object = new JSONObject();
if (!backupMetadataOptional.isPresent()) {
object.put("Snapshotstatus", false);
} else {

object.put("Snapshotstatus", true);
object.put("Details", backupMetadataOptional.get().toString());
object.put("Details", backupMetadataOptional.get());
}
return Response.ok(object.toString(), MediaType.APPLICATION_JSON).build();
}
Expand Down

0 comments on commit e836056

Please sign in to comment.