mirror of https://github.com/apache/jclouds.git
allow 409 on putBucket so it is compatible w/googlestorage
This commit is contained in:
parent
a6145cfae9
commit
0263a15278
|
@ -52,7 +52,7 @@ import org.jclouds.s3.functions.BindRegionToXmlPayload;
|
|||
import org.jclouds.s3.functions.ObjectKey;
|
||||
import org.jclouds.s3.functions.ParseObjectFromHeadersAndHttpContent;
|
||||
import org.jclouds.s3.functions.ParseObjectMetadataFromHeaders;
|
||||
import org.jclouds.s3.functions.ReturnFalseIfBucketAlreadyOwnedByYou;
|
||||
import org.jclouds.s3.functions.ReturnFalseIfBucketAlreadyOwnedByYouOrIllegalState;
|
||||
import org.jclouds.s3.functions.ReturnTrueOn404OrNotFoundFalseIfNotEmpty;
|
||||
import org.jclouds.s3.options.CopyObjectOptions;
|
||||
import org.jclouds.s3.options.ListBucketOptions;
|
||||
|
@ -170,7 +170,7 @@ public interface S3AsyncClient {
|
|||
*/
|
||||
@PUT
|
||||
@Path("/")
|
||||
@ExceptionParser(ReturnFalseIfBucketAlreadyOwnedByYou.class)
|
||||
@ExceptionParser(ReturnFalseIfBucketAlreadyOwnedByYouOrIllegalState.class)
|
||||
ListenableFuture<Boolean> putBucketInRegion(
|
||||
// TODO endpoint based on region
|
||||
@BinderParam(BindRegionToXmlPayload.class) @Nullable String region,
|
||||
|
|
|
@ -19,17 +19,12 @@
|
|||
|
||||
package org.jclouds.s3.functions;
|
||||
|
||||
import static com.google.common.base.Throwables.getCausalChain;
|
||||
import static com.google.common.collect.Iterables.filter;
|
||||
import static com.google.common.collect.Iterables.get;
|
||||
import static com.google.common.collect.Iterables.size;
|
||||
import static org.jclouds.util.Throwables2.propagateOrNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.aws.AWSResponseException;
|
||||
import org.jclouds.util.Throwables2;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
|
||||
|
@ -38,14 +33,14 @@ import com.google.common.base.Function;
|
|||
* @author Adrian Cole
|
||||
*/
|
||||
@Singleton
|
||||
public class ReturnFalseIfBucketAlreadyOwnedByYou implements Function<Exception, Boolean> {
|
||||
public class ReturnFalseIfBucketAlreadyOwnedByYouOrIllegalState implements Function<Exception, Boolean> {
|
||||
|
||||
public Boolean apply(Exception from) {
|
||||
List<Throwable> throwables = getCausalChain(from);
|
||||
|
||||
Iterable<AWSResponseException> matchingAWSResponseException = filter(throwables, AWSResponseException.class);
|
||||
if (size(matchingAWSResponseException) >= 1 && get(matchingAWSResponseException, 0).getError() != null) {
|
||||
if (get(matchingAWSResponseException, 0).getError().getCode().equals("BucketAlreadyOwnedByYou"))
|
||||
AWSResponseException exception = Throwables2.getFirstThrowableOfType(from, AWSResponseException.class);
|
||||
if (exception != null && exception.getError() != null
|
||||
&& exception.getError().getCode().equals("BucketAlreadyOwnedByYou")) {
|
||||
return false;
|
||||
} else if (Throwables2.getFirstThrowableOfType(from, IllegalStateException.class) != null) {
|
||||
return false;
|
||||
}
|
||||
return Boolean.class.cast(propagateOrNull(from));
|
|
@ -37,7 +37,7 @@ import org.jclouds.s3.domain.AccessControlList.Grant;
|
|||
import org.jclouds.s3.domain.AccessControlList.Permission;
|
||||
import org.jclouds.s3.functions.ParseObjectFromHeadersAndHttpContent;
|
||||
import org.jclouds.s3.functions.ParseObjectMetadataFromHeaders;
|
||||
import org.jclouds.s3.functions.ReturnFalseIfBucketAlreadyOwnedByYou;
|
||||
import org.jclouds.s3.functions.ReturnFalseIfBucketAlreadyOwnedByYouOrIllegalState;
|
||||
import org.jclouds.s3.functions.ReturnTrueOn404OrNotFoundFalseIfNotEmpty;
|
||||
import org.jclouds.s3.options.CopyObjectOptions;
|
||||
import org.jclouds.s3.options.ListBucketOptions;
|
||||
|
@ -384,7 +384,7 @@ public class S3AsyncClientTest extends BaseS3AsyncClientTest {
|
|||
|
||||
assertResponseParserClassEquals(method, request, ReturnTrueIf2xx.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, ReturnFalseIfBucketAlreadyOwnedByYou.class);
|
||||
assertExceptionParserClassEquals(method, ReturnFalseIfBucketAlreadyOwnedByYouOrIllegalState.class);
|
||||
|
||||
checkFilters(request);
|
||||
}
|
||||
|
@ -403,7 +403,7 @@ public class S3AsyncClientTest extends BaseS3AsyncClientTest {
|
|||
|
||||
assertResponseParserClassEquals(method, request, ReturnTrueIf2xx.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, ReturnFalseIfBucketAlreadyOwnedByYou.class);
|
||||
assertExceptionParserClassEquals(method, ReturnFalseIfBucketAlreadyOwnedByYouOrIllegalState.class);
|
||||
|
||||
checkFilters(request);
|
||||
}
|
||||
|
|
|
@ -26,19 +26,25 @@ import org.testng.annotations.Test;
|
|||
/**
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Test(testName = "s3.ReturnTrueIfBucketAlreadyOwnedByYouTest")
|
||||
public class ReturnTrueIfBucketAlreadyOwnedByYouTest {
|
||||
@Test(testName = "ReturnFalseIfBucketAlreadyOwnedByYouOrIllegalStateTest")
|
||||
public class ReturnFalseIfBucketAlreadyOwnedByYouOrIllegalStateTest {
|
||||
|
||||
@Test
|
||||
void testBucketAlreadyOwnedByYouIsOk() throws Exception {
|
||||
Exception e = getErrorWithCode("BucketAlreadyOwnedByYou");
|
||||
assert !new ReturnFalseIfBucketAlreadyOwnedByYou().apply(e);
|
||||
assert !new ReturnFalseIfBucketAlreadyOwnedByYouOrIllegalState().apply(e);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testIllegalStateIsOk() throws Exception {
|
||||
Exception e = new IllegalStateException();
|
||||
assert !new ReturnFalseIfBucketAlreadyOwnedByYouOrIllegalState().apply(e);
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = AWSResponseException.class)
|
||||
void testBlahIsNotOk() throws Exception {
|
||||
Exception e = getErrorWithCode("blah");
|
||||
new ReturnFalseIfBucketAlreadyOwnedByYou().apply(e);
|
||||
new ReturnFalseIfBucketAlreadyOwnedByYouOrIllegalState().apply(e);
|
||||
}
|
||||
|
||||
private Exception getErrorWithCode(String code) {
|
Loading…
Reference in New Issue