diff --git a/snapshot-service-impl/src/main/java/org/duracloud/snapshot/service/impl/RestoreManagerImpl.java b/snapshot-service-impl/src/main/java/org/duracloud/snapshot/service/impl/RestoreManagerImpl.java index 65e9caa..74bed5d 100644 --- a/snapshot-service-impl/src/main/java/org/duracloud/snapshot/service/impl/RestoreManagerImpl.java +++ b/snapshot-service-impl/src/main/java/org/duracloud/snapshot/service/impl/RestoreManagerImpl.java @@ -488,28 +488,42 @@ public void finalizeRestores() { bridgeConfig.getDuracloudPassword()); try { String spaceId = destination.getSpaceId(); - Iterator it = store.getSpaceContents(spaceId); - if (!it.hasNext()) { // if space is empty - // Call DuraCloud to remove space - log.info("Deleting expired restoration space: " + spaceId + - " at host: " + destination.getHost()); - store.deleteSpace(spaceId); + boolean spaceExists = store.spaceExists(spaceId); + boolean spaceEmpty = false; + + if(spaceExists) { + Iterator it = store.getSpaceContents(spaceId); + spaceEmpty = !it.hasNext(); + if (spaceEmpty) { // if space is empty + // Call DuraCloud to remove space + log.info("Deleting expired restoration space: " + spaceId + + " at host: " + destination.getHost()); + store.deleteSpace(spaceId); + } + } + if (!spaceExists || spaceEmpty){ // Update restore status validateAndSet(restoration, - RestoreStatus.RESTORATION_EXPIRED, - "Restoration expired"); + RestoreStatus.RESTORATION_EXPIRED, + "Restoration expired"); restoration = save(restoration); log.info("Transition of restore " + - restoration.getRestorationId() + - " to expired state completed successfully"); + restoration.getRestorationId() + + " to expired state completed successfully"); // Add history event String history = - "[{'" + RESTORE_ACTION_TITLE + "':'" + RESTORE_ACTION_EXPIRED + "'}," + - "{'" + RESTORE_ID_TITLE + "':'" + restoration.getRestorationId() + "'}]"; + "[{'" + RESTORE_ACTION_TITLE + "':'" + RESTORE_ACTION_EXPIRED + "'}," + + "{'" + RESTORE_ID_TITLE + "':'" + restoration.getRestorationId() + "'}]"; snapshotManager.updateHistory(restoration.getSnapshot(), history); + + } else { + log.info("Space {} is not empty. Space will be removed and restoration {} transition to " + + "expired state when space is empty.", spaceId, restoration); } + + } catch (Exception e) { log.error("Failed to transition restore " + restoration.getRestorationId() +