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