Skip to content
Permalink
Browse files
JCLOUDS-457: Add Clear vault strategy
Added a proper implementation to the Clear vault strategy
  • Loading branch information
rcoedo authored and gaul committed Jul 27, 2014
1 parent 5c63245 commit 377c58fbaa5758b1bd4e17f9096b0cbe21e0b5f0
Showing 1 changed file with 28 additions and 2 deletions.
@@ -16,15 +16,41 @@
*/
package org.jclouds.glacier.blobstore.strategy;

import static com.google.common.base.Preconditions.checkNotNull;

import org.jclouds.blobstore.options.ListContainerOptions;
import org.jclouds.blobstore.strategy.ClearListStrategy;
import org.jclouds.glacier.GlacierClient;
import org.jclouds.glacier.domain.ArchiveMetadata;
import org.jclouds.glacier.domain.ArchiveMetadataCollection;
import org.jclouds.glacier.domain.InventoryRetrievalJobRequest;

import com.google.inject.Inject;
import com.google.inject.Singleton;

@Singleton
public class ClearVaultStrategy implements ClearListStrategy {
private final GlacierClient sync;
private final PollingStrategy pollingStrategy;

@Inject
public ClearVaultStrategy(GlacierClient sync, PollingStrategy pollingStrategy) {
this.pollingStrategy = checkNotNull(pollingStrategy, "pollingStrategy");
this.sync = checkNotNull(sync, "sync");
}

@Override
public void execute(String s, ListContainerOptions listContainerOptions) {
return;
public void execute(String container, ListContainerOptions listContainerOptions) {
String jobId = sync.initiateJob(container, InventoryRetrievalJobRequest.builder().build());
try {
if (pollingStrategy.waitForSuccess(container, jobId)) {
ArchiveMetadataCollection archives = sync.getInventoryRetrievalOutput(container, jobId);
for(ArchiveMetadata archive : archives) {
sync.deleteArchive(container, archive.getArchiveId());
}
}
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
}

0 comments on commit 377c58f

Please sign in to comment.