From deb8c5c593bf7c9b6f4aad744bc7129141e8a840 Mon Sep 17 00:00:00 2001 From: dbernstein Date: Fri, 1 Mar 2024 15:43:49 -0800 Subject: [PATCH] =?UTF-8?q?Ensure=20restored=20spaces=20that=20have=20been?= =?UTF-8?q?=20deleted=20by=20the=20duracloud=20user=20c=E2=80=A6=20(#34)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Ensure restored spaces that have been deleted by the duracloud user can be transition to expired state. --- .../service/impl/RestoreManagerImpl.java | 35 ++++++++++++------- .../service/impl/RestoreManagerImplTest.java | 1 + 2 files changed, 24 insertions(+), 12 deletions(-) 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..bf1b101 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,27 +488,38 @@ 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); + + if (spaceExists) { + 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); + spaceExists = false; + } + } + if (!spaceExists) { // 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 " + diff --git a/snapshot-service-impl/src/test/java/org/duracloud/snapshot/service/impl/RestoreManagerImplTest.java b/snapshot-service-impl/src/test/java/org/duracloud/snapshot/service/impl/RestoreManagerImplTest.java index 58fe74e..1cabd39 100644 --- a/snapshot-service-impl/src/test/java/org/duracloud/snapshot/service/impl/RestoreManagerImplTest.java +++ b/snapshot-service-impl/src/test/java/org/duracloud/snapshot/service/impl/RestoreManagerImplTest.java @@ -308,6 +308,7 @@ public void testFinalizeRestores() throws Exception { expect(destination.getSpaceId()).andReturn(spaceId); expect(destination.getHost()).andReturn(host); + expect(contentStore.spaceExists(spaceId)).andReturn(true); expect(contentStore.getSpaceContents(spaceId)) .andReturn(Collections.emptyList().iterator());