Skip to content

Commit

Permalink
Catch possible exceptions deleting snapshots
Browse files Browse the repository at this point in the history
  • Loading branch information
Marc Baumbach committed Apr 15, 2016
1 parent a3625ca commit 91c0911
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/main/java/com/marcbaumbach/ec2/snapshotter/Snapshotter.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,14 @@ private CreateSnapshotRequest createSnapshotRequest(Volume volume) {
return new CreateSnapshotRequest(volume.getVolumeId(), description);
}

private DeleteSnapshotRequest deleteSnapshotRequest(Snapshot snapshot) {
private void deleteSnapshot(Snapshot snapshot) {
logger.info("Deleting snapshot {} for volume {}", snapshot.getDescription(), snapshot.getVolumeId());
return new DeleteSnapshotRequest(snapshot.getSnapshotId());
DeleteSnapshotRequest request = new DeleteSnapshotRequest(snapshot.getSnapshotId());
try {
ec2Client.deleteSnapshot(request);
} catch (Exception e) {
logger.error("Error deleting snapshot {}", snapshot.getSnapshotId(), e);
}
}

private CreateTagsRequest createTagsRequest(String snapshotId) {
Expand Down Expand Up @@ -96,8 +101,7 @@ public Snapshotter cleanupSnapshots() {
Date cutoff = calendar.getTime();
snapshotsResult.getSnapshots().stream()
.filter(s -> s.getStartTime().before(cutoff))
.map(this::deleteSnapshotRequest)
.forEach(ec2Client::deleteSnapshot);
.forEach(this::deleteSnapshot);
logger.info("Completed snapshot cleanup in {}s", (TimeUnit.NANOSECONDS.toSeconds(System.nanoTime() - start)));
return this;
}
Expand Down

0 comments on commit 91c0911

Please sign in to comment.