Remove AsyncBlobStore from DeleteAllKeysInList

We deprecated AsyncBlobStore in 1.6.0.  Subsequent commits will
require the caller to provide an ExecutorService.
This commit is contained in:
Andrew Gaul 2013-05-31 20:26:11 -07:00
parent d113b0ba63
commit 86147cd961
2 changed files with 30 additions and 60 deletions

View File

@ -30,7 +30,7 @@ import javax.inject.Named;
import javax.inject.Singleton;
import org.jclouds.Constants;
import org.jclouds.blobstore.AsyncBlobStore;
import org.jclouds.blobstore.BlobStore;
import org.jclouds.blobstore.domain.PageSet;
import org.jclouds.blobstore.domain.StorageMetadata;
import org.jclouds.blobstore.internal.BlobRuntimeException;
@ -58,9 +58,9 @@ public class DeleteAllKeysInList implements ClearListStrategy, ClearContainerStr
protected Logger logger = Logger.NULL;
protected final BackoffLimitedRetryHandler retryHandler;
private final ListeningExecutorService userExecutor;
private final ListeningExecutorService executorService;
protected final AsyncBlobStore connection;
protected final BlobStore blobStore;
/** Maximum duration in milliseconds of a request. */
protected long maxTime = Long.MAX_VALUE;
@ -69,10 +69,10 @@ public class DeleteAllKeysInList implements ClearListStrategy, ClearContainerStr
protected int maxErrors = 3;
@Inject
DeleteAllKeysInList(@Named(Constants.PROPERTY_USER_THREADS) ListeningExecutorService userExecutor,
AsyncBlobStore connection, BackoffLimitedRetryHandler retryHandler) {
this.userExecutor = userExecutor;
this.connection = connection;
DeleteAllKeysInList(@Named(Constants.PROPERTY_USER_THREADS) ListeningExecutorService executorService,
BlobStore blobStore, BackoffLimitedRetryHandler retryHandler) {
this.executorService = executorService;
this.blobStore = blobStore;
this.retryHandler = retryHandler;
}
@ -101,31 +101,8 @@ public class DeleteAllKeysInList implements ClearListStrategy, ClearContainerStr
Map<StorageMetadata, Exception> exceptions = Maps.newHashMap();
for (int numErrors = 0; numErrors < maxErrors; ) {
// fetch partial directory listing
PageSet<? extends StorageMetadata> listing;
ListenableFuture<PageSet<? extends StorageMetadata>> listFuture =
connection.list(containerName, options);
try {
listing = listFuture.get(maxTime, TimeUnit.MILLISECONDS);
} catch (InterruptedException ie) {
Thread.currentThread().interrupt();
break;
} catch (ExecutionException ee) {
++numErrors;
if (numErrors == maxErrors) {
throw propagate(ee.getCause());
}
retryHandler.imposeBackoffExponentialDelay(numErrors, message);
continue;
} catch (TimeoutException te) {
++numErrors;
if (numErrors == maxErrors) {
throw propagate(te);
}
retryHandler.imposeBackoffExponentialDelay(numErrors, message);
continue;
} finally {
listFuture.cancel(true);
}
PageSet<? extends StorageMetadata> listing =
blobStore.list(containerName, options);
// recurse on subdirectories
if (options.isRecursive()) {
@ -149,21 +126,36 @@ public class DeleteAllKeysInList implements ClearListStrategy, ClearContainerStr
// remove blobs and now-empty subdirectories
Map<StorageMetadata, ListenableFuture<?>> responses = Maps.newHashMap();
for (StorageMetadata md : listing) {
String fullPath = parentIsFolder(options, md) ? options.getDir() + "/"
for (final StorageMetadata md : listing) {
final String fullPath = parentIsFolder(options, md) ? options.getDir() + "/"
+ md.getName() : md.getName();
switch (md.getType()) {
case BLOB:
responses.put(md, connection.removeBlob(containerName, fullPath));
responses.put(md, executorService.submit(new Runnable() {
@Override
public void run() {
blobStore.removeBlob(containerName, fullPath);
}
}));
break;
case FOLDER:
if (options.isRecursive()) {
responses.put(md, connection.deleteDirectory(containerName, fullPath));
responses.put(md, executorService.submit(new Runnable() {
@Override
public void run() {
blobStore.deleteDirectory(containerName, fullPath);
}
}));
}
break;
case RELATIVE_PATH:
if (options.isRecursive()) {
responses.put(md, connection.deleteDirectory(containerName, md.getName()));
responses.put(md, executorService.submit(new Runnable() {
@Override
public void run() {
blobStore.deleteDirectory(containerName, md.getName());
}
}));
}
break;
case CONTAINER:
@ -172,7 +164,7 @@ public class DeleteAllKeysInList implements ClearListStrategy, ClearContainerStr
}
try {
exceptions = awaitCompletion(responses, userExecutor, maxTime, logger, message);
exceptions = awaitCompletion(responses, executorService, maxTime, logger, message);
} catch (TimeoutException te) {
++numErrors;
if (numErrors == maxErrors) {

View File

@ -28,7 +28,6 @@ import java.util.concurrent.TimeoutException;
import java.util.concurrent.TimeUnit;
import org.jclouds.ContextBuilder;
import org.jclouds.blobstore.AsyncBlobStore;
import org.jclouds.blobstore.BlobStore;
import org.jclouds.blobstore.options.ListContainerOptions;
import org.jclouds.blobstore.domain.PageSet;
@ -86,27 +85,6 @@ public class DeleteAllKeysInListTest {
assertEquals(blobstore.countBlobs(containerName), 1111);
}
public void testListTimeoutException() throws Exception {
ListenableFuture<PageSet<? extends StorageMetadata>> future = createMock(ListenableFuture.class);
expect(future.get(anyLong(), anyObject(TimeUnit.class))).andThrow(new RuntimeException(new TimeoutException()));
expect(future.cancel(true)).andReturn(true);
replay(future);
AsyncBlobStore asyncBlobStore = createMock(AsyncBlobStore.class);
expect(asyncBlobStore.list(anyObject(String.class), anyObject(ListContainerOptions.class))).andReturn(future);
replay(asyncBlobStore);
deleter = new DeleteAllKeysInList(null, asyncBlobStore, null);
try {
deleter.execute(containerName, ListContainerOptions.NONE);
fail();
} catch (Exception e) {
if (Throwables2.getFirstThrowableOfType(e, TimeoutException.class) == null) {
throw e;
}
}
}
/**
* Create a container "container" with 1111 blobs named "blob-%d". Create a
* subdirectory "directory" which contains 2222 more blobs named