Merge pull request #855 from jclouds/path-buckets

Issue 1092: fix hostname when path-based buckets are used in non-default location
This commit is contained in:
Andrew Gaul 2012-09-26 10:39:33 -07:00
commit 68e44df1f6
5 changed files with 57 additions and 15 deletions

View File

@ -187,7 +187,6 @@ public interface S3AsyncClient {
*/ */
@DELETE @DELETE
@Path("/") @Path("/")
@Endpoint(Bucket.class)
@ExceptionParser(ReturnTrueOn404OrNotFoundFalseOnIllegalState.class) @ExceptionParser(ReturnTrueOn404OrNotFoundFalseOnIllegalState.class)
ListenableFuture<Boolean> deleteBucketIfEmpty( ListenableFuture<Boolean> deleteBucketIfEmpty(
@Bucket @EndpointParam(parser = DefaultEndpointThenInvalidateRegion.class) @BinderParam(BindAsHostPrefixIfConfigured.class) @ParamValidators(BucketNameValidator.class) String bucketName); @Bucket @EndpointParam(parser = DefaultEndpointThenInvalidateRegion.class) @BinderParam(BindAsHostPrefixIfConfigured.class) @ParamValidators(BucketNameValidator.class) String bucketName);
@ -197,11 +196,10 @@ public interface S3AsyncClient {
*/ */
@HEAD @HEAD
@Path("/") @Path("/")
@Endpoint(Bucket.class)
@QueryParams(keys = "max-keys", values = "0") @QueryParams(keys = "max-keys", values = "0")
@ExceptionParser(ReturnFalseOnContainerNotFound.class) @ExceptionParser(ReturnFalseOnContainerNotFound.class)
ListenableFuture<Boolean> bucketExists( ListenableFuture<Boolean> bucketExists(
@Bucket @BinderParam(BindAsHostPrefixIfConfigured.class) @ParamValidators(BucketNameValidator.class) String bucketName); @Bucket @EndpointParam(parser = AssignCorrectHostnameForBucket.class) @BinderParam(BindAsHostPrefixIfConfigured.class) @ParamValidators(BucketNameValidator.class) String bucketName);
/** /**

View File

@ -24,7 +24,6 @@ import javax.inject.Inject;
import javax.inject.Singleton; import javax.inject.Singleton;
import org.jclouds.javax.annotation.Nullable; import org.jclouds.javax.annotation.Nullable;
import org.jclouds.location.functions.RegionToEndpointOrProviderIfNull;
import org.jclouds.s3.Bucket; import org.jclouds.s3.Bucket;
import com.google.common.base.Function; import com.google.common.base.Function;
@ -39,10 +38,10 @@ import com.google.common.cache.LoadingCache;
public class DefaultEndpointThenInvalidateRegion implements Function<Object, URI> { public class DefaultEndpointThenInvalidateRegion implements Function<Object, URI> {
private final LoadingCache<String, Optional<String>> bucketToRegionCache; private final LoadingCache<String, Optional<String>> bucketToRegionCache;
private final RegionToEndpointOrProviderIfNull r2; private final AssignCorrectHostnameForBucket r2;
@Inject @Inject
public DefaultEndpointThenInvalidateRegion(RegionToEndpointOrProviderIfNull r2, public DefaultEndpointThenInvalidateRegion(AssignCorrectHostnameForBucket r2,
@Bucket LoadingCache<String, Optional<String>> bucketToRegionCache) { @Bucket LoadingCache<String, Optional<String>> bucketToRegionCache) {
this.r2 = r2; this.r2 = r2;
this.bucketToRegionCache = bucketToRegionCache; this.bucketToRegionCache = bucketToRegionCache;
@ -51,7 +50,7 @@ public class DefaultEndpointThenInvalidateRegion implements Function<Object, URI
@Override @Override
public URI apply(@Nullable Object from) { public URI apply(@Nullable Object from) {
try { try {
return r2.apply(null); return r2.apply(from);
} finally { } finally {
bucketToRegionCache.invalidate(from.toString()); bucketToRegionCache.invalidate(from.toString());
} }

View File

@ -25,7 +25,6 @@ import static org.easymock.EasyMock.verify;
import java.net.URI; import java.net.URI;
import org.jclouds.location.functions.RegionToEndpointOrProviderIfNull;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.common.base.Optional; import com.google.common.base.Optional;
@ -40,10 +39,10 @@ public class DefaultEndpointThenInvalidateRegionTest {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Test @Test
void testInvalidate() throws Exception { void testInvalidate() throws Exception {
RegionToEndpointOrProviderIfNull r2 = createMock(RegionToEndpointOrProviderIfNull.class); AssignCorrectHostnameForBucket r2 = createMock(AssignCorrectHostnameForBucket.class);
LoadingCache<String, Optional<String>> bucketToRegionCache = createMock(LoadingCache.class); LoadingCache<String, Optional<String>> bucketToRegionCache = createMock(LoadingCache.class);
expect(r2.apply(null)).andReturn(URI.create("http://east-url")); expect(r2.apply("mybucket")).andReturn(URI.create("http://east-url"));
bucketToRegionCache.invalidate("mybucket"); bucketToRegionCache.invalidate("mybucket");
replay(r2, bucketToRegionCache); replay(r2, bucketToRegionCache);

View File

@ -19,6 +19,7 @@
package org.jclouds.blobstore.integration.internal; package org.jclouds.blobstore.integration.internal;
import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;
import java.util.Set; import java.util.Set;
@ -64,6 +65,7 @@ public class BaseServiceIntegrationTest extends BaseBlobStoreIntegrationTest {
return containerName.equals(md.getName()) && location.equals(md.getLocation()); return containerName.equals(md.getName()) && location.equals(md.getLocation());
} }
}) : String.format("container %s/%s not found in list %s", location, containerName, list); }) : String.format("container %s/%s not found in list %s", location, containerName, list);
assertTrue(view.getBlobStore().containerExists(containerName), containerName);
} }
}); });

View File

@ -0,0 +1,44 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.aws.s3.blobstore.integration;
import static org.jclouds.s3.reference.S3Constants.PROPERTY_S3_VIRTUAL_HOST_BUCKETS;
import java.util.Properties;
import org.jclouds.s3.blobstore.integration.S3ContainerLiveTest;
import org.testng.annotations.Test;
/**
* @author Adrian Cole
*/
@Test(groups = "live", singleThreaded = true, testName = "PathBasedContainerLiveTest")
public class PathBasedContainerLiveTest extends S3ContainerLiveTest {
public PathBasedContainerLiveTest() {
provider = "aws-s3";
}
@Override
public Properties setupProperties() {
Properties properties = super.setupProperties();
properties.setProperty(PROPERTY_S3_VIRTUAL_HOST_BUCKETS, "false");
return properties;
}
}