mirror of https://github.com/apache/jclouds.git
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:
parent
d113b0ba63
commit
86147cd961
|
@ -30,7 +30,7 @@ import javax.inject.Named;
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
import org.jclouds.Constants;
|
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.PageSet;
|
||||||
import org.jclouds.blobstore.domain.StorageMetadata;
|
import org.jclouds.blobstore.domain.StorageMetadata;
|
||||||
import org.jclouds.blobstore.internal.BlobRuntimeException;
|
import org.jclouds.blobstore.internal.BlobRuntimeException;
|
||||||
|
@ -58,9 +58,9 @@ public class DeleteAllKeysInList implements ClearListStrategy, ClearContainerStr
|
||||||
protected Logger logger = Logger.NULL;
|
protected Logger logger = Logger.NULL;
|
||||||
|
|
||||||
protected final BackoffLimitedRetryHandler retryHandler;
|
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. */
|
/** Maximum duration in milliseconds of a request. */
|
||||||
protected long maxTime = Long.MAX_VALUE;
|
protected long maxTime = Long.MAX_VALUE;
|
||||||
|
@ -69,10 +69,10 @@ public class DeleteAllKeysInList implements ClearListStrategy, ClearContainerStr
|
||||||
protected int maxErrors = 3;
|
protected int maxErrors = 3;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
DeleteAllKeysInList(@Named(Constants.PROPERTY_USER_THREADS) ListeningExecutorService userExecutor,
|
DeleteAllKeysInList(@Named(Constants.PROPERTY_USER_THREADS) ListeningExecutorService executorService,
|
||||||
AsyncBlobStore connection, BackoffLimitedRetryHandler retryHandler) {
|
BlobStore blobStore, BackoffLimitedRetryHandler retryHandler) {
|
||||||
this.userExecutor = userExecutor;
|
this.executorService = executorService;
|
||||||
this.connection = connection;
|
this.blobStore = blobStore;
|
||||||
this.retryHandler = retryHandler;
|
this.retryHandler = retryHandler;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -101,31 +101,8 @@ public class DeleteAllKeysInList implements ClearListStrategy, ClearContainerStr
|
||||||
Map<StorageMetadata, Exception> exceptions = Maps.newHashMap();
|
Map<StorageMetadata, Exception> exceptions = Maps.newHashMap();
|
||||||
for (int numErrors = 0; numErrors < maxErrors; ) {
|
for (int numErrors = 0; numErrors < maxErrors; ) {
|
||||||
// fetch partial directory listing
|
// fetch partial directory listing
|
||||||
PageSet<? extends StorageMetadata> listing;
|
PageSet<? extends StorageMetadata> listing =
|
||||||
ListenableFuture<PageSet<? extends StorageMetadata>> listFuture =
|
blobStore.list(containerName, options);
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
// recurse on subdirectories
|
// recurse on subdirectories
|
||||||
if (options.isRecursive()) {
|
if (options.isRecursive()) {
|
||||||
|
@ -149,21 +126,36 @@ public class DeleteAllKeysInList implements ClearListStrategy, ClearContainerStr
|
||||||
|
|
||||||
// remove blobs and now-empty subdirectories
|
// remove blobs and now-empty subdirectories
|
||||||
Map<StorageMetadata, ListenableFuture<?>> responses = Maps.newHashMap();
|
Map<StorageMetadata, ListenableFuture<?>> responses = Maps.newHashMap();
|
||||||
for (StorageMetadata md : listing) {
|
for (final StorageMetadata md : listing) {
|
||||||
String fullPath = parentIsFolder(options, md) ? options.getDir() + "/"
|
final String fullPath = parentIsFolder(options, md) ? options.getDir() + "/"
|
||||||
+ md.getName() : md.getName();
|
+ md.getName() : md.getName();
|
||||||
switch (md.getType()) {
|
switch (md.getType()) {
|
||||||
case BLOB:
|
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;
|
break;
|
||||||
case FOLDER:
|
case FOLDER:
|
||||||
if (options.isRecursive()) {
|
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;
|
break;
|
||||||
case RELATIVE_PATH:
|
case RELATIVE_PATH:
|
||||||
if (options.isRecursive()) {
|
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;
|
break;
|
||||||
case CONTAINER:
|
case CONTAINER:
|
||||||
|
@ -172,7 +164,7 @@ public class DeleteAllKeysInList implements ClearListStrategy, ClearContainerStr
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
exceptions = awaitCompletion(responses, userExecutor, maxTime, logger, message);
|
exceptions = awaitCompletion(responses, executorService, maxTime, logger, message);
|
||||||
} catch (TimeoutException te) {
|
} catch (TimeoutException te) {
|
||||||
++numErrors;
|
++numErrors;
|
||||||
if (numErrors == maxErrors) {
|
if (numErrors == maxErrors) {
|
||||||
|
|
|
@ -28,7 +28,6 @@ import java.util.concurrent.TimeoutException;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import org.jclouds.ContextBuilder;
|
import org.jclouds.ContextBuilder;
|
||||||
import org.jclouds.blobstore.AsyncBlobStore;
|
|
||||||
import org.jclouds.blobstore.BlobStore;
|
import org.jclouds.blobstore.BlobStore;
|
||||||
import org.jclouds.blobstore.options.ListContainerOptions;
|
import org.jclouds.blobstore.options.ListContainerOptions;
|
||||||
import org.jclouds.blobstore.domain.PageSet;
|
import org.jclouds.blobstore.domain.PageSet;
|
||||||
|
@ -86,27 +85,6 @@ public class DeleteAllKeysInListTest {
|
||||||
assertEquals(blobstore.countBlobs(containerName), 1111);
|
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
|
* Create a container "container" with 1111 blobs named "blob-%d". Create a
|
||||||
* subdirectory "directory" which contains 2222 more blobs named
|
* subdirectory "directory" which contains 2222 more blobs named
|
||||||
|
|
Loading…
Reference in New Issue