Skip to content
Permalink
Browse files
JCLOUDS-457: Fix deleteContainer
The ClearVaultStrategy now ignores ResourceNotFound exceptions.

deleteContainer now tries to delete the vault first to avoid long waits.
If the delete request fails, retries it every 24 hours.
  • Loading branch information
rcoedo authored and gaul committed Jul 28, 2014
1 parent 377c58f commit fd324fbfad3fd9a8c0a24280f38b8b4e13e587ca
Showing 2 changed files with 35 additions and 2 deletions.
@@ -18,8 +18,11 @@

import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
import static org.jclouds.util.Predicates2.retry;

import java.util.Set;
import java.util.concurrent.TimeUnit;

import org.jclouds.blobstore.BlobStoreContext;
import org.jclouds.blobstore.domain.Blob;
@@ -48,11 +51,19 @@
import org.jclouds.glacier.util.ContentRange;
import org.jclouds.javax.annotation.Nullable;

import com.google.common.base.Predicate;
import com.google.common.base.Supplier;
import com.google.inject.Inject;
import com.google.inject.Provider;
import com.google.inject.name.Named;

public class GlacierBlobStore extends BaseBlobStore {
public static final long DEFAULT_INVENTORY_UPDATE_TIME = TimeUnit.HOURS.toMillis(24);

@Inject(optional = true)
@Named("jclouds.inventory.update.time")
private final long inventoryUpdateTime = DEFAULT_INVENTORY_UPDATE_TIME;

private final GlacierClient sync;
private final Crypto crypto;
private final Provider<MultipartUploadStrategy> multipartUploadStrategy;
@@ -79,6 +90,24 @@ public class GlacierBlobStore extends BaseBlobStore {
this.crypto = checkNotNull(crypto, "crypto");
}

@Override
public void deleteContainer(String container) {
// attempt to delete possibly-empty vault to avoid inventory retrieval
if (!sync.deleteVault(container)) {
deletePathAndEnsureGone(container);
}
}

@Override
protected void deletePathAndEnsureGone(String container) {
checkState(retry(new Predicate<String>() {
public boolean apply(String container) {
clearContainer(container);
return sync.deleteVault(container);
}
}, inventoryUpdateTime).apply(container), "%s still exists after deleting!", container);
}

@Override
protected boolean deleteAndVerifyContainerGone(String container) {
return sync.deleteVault(container);
@@ -24,6 +24,7 @@
import org.jclouds.glacier.domain.ArchiveMetadata;
import org.jclouds.glacier.domain.ArchiveMetadataCollection;
import org.jclouds.glacier.domain.InventoryRetrievalJobRequest;
import org.jclouds.rest.ResourceNotFoundException;

import com.google.inject.Inject;
import com.google.inject.Singleton;
@@ -45,8 +46,11 @@ public void execute(String container, ListContainerOptions listContainerOptions)
try {
if (pollingStrategy.waitForSuccess(container, jobId)) {
ArchiveMetadataCollection archives = sync.getInventoryRetrievalOutput(container, jobId);
for(ArchiveMetadata archive : archives) {
sync.deleteArchive(container, archive.getArchiveId());
for (ArchiveMetadata archive : archives) {
try {
sync.deleteArchive(container, archive.getArchiveId());
} catch (ResourceNotFoundException ignored) {
}
}
}
} catch (InterruptedException e) {

0 comments on commit fd324fb

Please sign in to comment.