Skip to content

Commit

Permalink
normalized all list operations to Set<Thing> and on 404 they return a…
Browse files Browse the repository at this point in the history
…n empty list
  • Loading branch information
Adrian Cole committed Jul 18, 2010
1 parent 7d27e70 commit cd5fddf
Show file tree
Hide file tree
Showing 59 changed files with 994 additions and 1,119 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ public AWSFormSigningRestClientModule(Class<S> syncClientType, Class<A> asyncCli
@TimeStamp
protected String provideTimeStamp(final DateService dateService,
@Named(Constants.PROPERTY_SESSION_INTERVAL) final int expiration) {
return dateService.iso8601DateFormat(new Date(System.currentTimeMillis()
+ (expiration * 1000)));
return dateService.iso8601DateFormat(new Date(System.currentTimeMillis() + (expiration * 1000)));
}

@Provides
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,32 +67,32 @@ public void handleError(HttpCommand command, HttpResponse response) {
AWSError error = utils.parseAWSErrorFromContent(request, response);
exception = error != null ? new AWSResponseException(command, response, error) : exception;
String notFoundMessage = error != null ? error.getMessage() : String.format("%s -> %s", request
.getRequestLine(), response.getStatusLine());
.getRequestLine(), response.getStatusLine());
switch (response.getStatusCode()) {
case 400:
if (error.getCode().endsWith(".NotFound"))
exception = new ResourceNotFoundException(notFoundMessage, exception);
else if (error.getCode().equals("IncorrectState"))
exception = new IllegalStateException(error.getMessage(), exception);
else if (error.getCode().equals("AuthFailure"))
case 400:
if (error.getCode().endsWith(".NotFound") || error.getCode().endsWith(".Unknown"))
exception = new ResourceNotFoundException(notFoundMessage, exception);
else if (error.getCode().equals("IncorrectState"))
exception = new IllegalStateException(error.getMessage(), exception);
else if (error.getCode().equals("AuthFailure"))
exception = new AuthorizationException(command.getRequest(), error != null ? error.getMessage()
: response.getStatusLine());
break;
case 401:
case 403:
exception = new AuthorizationException(command.getRequest(), error != null ? error.getMessage()
: response.getStatusLine());
break;
case 401:
case 403:
exception = new AuthorizationException(command.getRequest(), error != null ? error.getMessage() : response
.getStatusLine());
break;
case 404:
if (!command.getRequest().getMethod().equals("DELETE")) {
String container = request.getEndpoint().getHost();
String key = request.getEndpoint().getPath();
if (key == null || key.equals("/"))
exception = new ContainerNotFoundException(container, notFoundMessage);
else
exception = new KeyNotFoundException(container, key, notFoundMessage);
}
break;
: response.getStatusLine());
break;
case 404:
if (!command.getRequest().getMethod().equals("DELETE")) {
String container = request.getEndpoint().getHost();
String key = request.getEndpoint().getPath();
if (key == null || key.equals("/"))
exception = new ContainerNotFoundException(container, notFoundMessage);
else
exception = new KeyNotFoundException(container, key, notFoundMessage);
}
break;
}
} finally {
releasePayload(response);
Expand Down
4 changes: 2 additions & 2 deletions aws/core/src/main/java/org/jclouds/aws/s3/S3AsyncClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

import static org.jclouds.blobstore.attr.BlobScopes.CONTAINER;

import java.util.SortedSet;
import java.util.Set;
import java.util.concurrent.ExecutionException;

import javax.annotation.Nullable;
Expand Down Expand Up @@ -242,7 +242,7 @@ ListenableFuture<ListBucketResponse> listBucket(
@XMLResponseParser(ListAllMyBucketsHandler.class)
@Path("/")
@VirtualHost
ListenableFuture<? extends SortedSet<BucketMetadata>> listOwnedBuckets();
ListenableFuture<? extends Set<BucketMetadata>> listOwnedBuckets();

/**
* @see S3Client#copyObject
Expand Down
4 changes: 2 additions & 2 deletions aws/core/src/main/java/org/jclouds/aws/s3/S3Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/
package org.jclouds.aws.s3;

import java.util.SortedSet;
import java.util.Set;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;

Expand Down Expand Up @@ -250,7 +250,7 @@ public interface S3Client {
* />
*
*/
SortedSet<BucketMetadata> listOwnedBuckets();
Set<BucketMetadata> listOwnedBuckets();

/**
* Copies one object to another bucket, retaining UserMetadata from the source. The destination
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import static com.google.common.util.concurrent.Futures.compose;

import java.util.Set;
import java.util.SortedSet;
import java.util.concurrent.ExecutorService;

import javax.inject.Inject;
Expand Down Expand Up @@ -113,9 +112,9 @@ public class S3AsyncBlobStore extends BaseAsyncBlobStore {
public ListenableFuture<? extends PageSet<? extends StorageMetadata>> list() {
return compose(
async.listOwnedBuckets(),
new Function<SortedSet<BucketMetadata>, org.jclouds.blobstore.domain.PageSet<? extends StorageMetadata>>() {
new Function<Set<BucketMetadata>, org.jclouds.blobstore.domain.PageSet<? extends StorageMetadata>>() {
public org.jclouds.blobstore.domain.PageSet<? extends StorageMetadata> apply(
SortedSet<BucketMetadata> from) {
Set<BucketMetadata> from) {
return new PageSetImpl<StorageMetadata>(Iterables.transform(from,
bucket2ResourceMd), null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import static com.google.common.base.Preconditions.checkNotNull;

import java.util.Set;
import java.util.SortedSet;

import javax.inject.Inject;
import javax.inject.Provider;
Expand Down Expand Up @@ -101,9 +100,9 @@ public class S3BlobStore extends BaseBlobStore {
*/
@Override
public PageSet<? extends StorageMetadata> list() {
return new Function<SortedSet<BucketMetadata>, org.jclouds.blobstore.domain.PageSet<? extends StorageMetadata>>() {
return new Function<Set<BucketMetadata>, org.jclouds.blobstore.domain.PageSet<? extends StorageMetadata>>() {
public org.jclouds.blobstore.domain.PageSet<? extends StorageMetadata> apply(
SortedSet<BucketMetadata> from) {
Set<BucketMetadata> from) {
return new PageSetImpl<StorageMetadata>(Iterables.transform(from, bucket2ResourceMd),
null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,18 +61,18 @@ protected void configure() {
super.configure();
}

@Provides
@TimeStamp
protected String provideTimeStamp(@TimeStamp Supplier<String> cache) {
return cache.get();
}

@Provides
@Singleton
protected RequestSigner provideRequestSigner(RequestAuthorizeSignature in) {
return in;
}

@Provides
@TimeStamp
protected String provideTimeStamp(@TimeStamp Supplier<String> cache) {
return cache.get();
}

/**
* borrowing concurrency code to ensure that caching takes place properly
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;

import com.google.common.annotations.VisibleForTesting;
Expand Down Expand Up @@ -67,7 +66,7 @@ public List<Grant> getGrants() {
* @return an unmodifiable set of grantees who have been assigned permissions in this ACL.
*/
public Set<Grantee> getGrantees() {
SortedSet<Grantee> grantees = new TreeSet<Grantee>();
Set<Grantee> grantees = new TreeSet<Grantee>();
for (Grant grant : getGrants()) {
grantees.add(grant.getGrantee());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
package org.jclouds.aws.s3.xml;

import java.util.Date;
import java.util.SortedSet;
import java.util.Set;

import javax.inject.Inject;

Expand All @@ -33,16 +33,16 @@
/**
* Parses the following XML document:
* <p/>
* SortedSetAllMyBucketsResult xmlns="http://doc.s3.amazonaws.com/2006-03-01"
* SetAllMyBucketsResult xmlns="http://doc.s3.amazonaws.com/2006-03-01"
*
* @see <a
* href="http://docs.amazonwebservices.com/AmazonS3/2006-03-01/index.html?RESTServiceGET.html"
* />
* @author Adrian Cole
*/
public class ListAllMyBucketsHandler extends ParseSax.HandlerWithResult<SortedSet<BucketMetadata>> {
public class ListAllMyBucketsHandler extends ParseSax.HandlerWithResult<Set<BucketMetadata>> {

private SortedSet<BucketMetadata> buckets = Sets.newTreeSet();
private Set<BucketMetadata> buckets = Sets.newLinkedHashSet();
private CanonicalUser currentOwner;
private StringBuilder currentText = new StringBuilder();

Expand All @@ -55,7 +55,7 @@ public ListAllMyBucketsHandler(DateService dateParser) {
this.dateParser = dateParser;
}

public SortedSet<BucketMetadata> getResult() {
public Set<BucketMetadata> getResult() {
return buckets;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
package org.jclouds.aws.s3.xml;

import java.util.Date;
import java.util.SortedSet;
import java.util.Set;

import javax.inject.Inject;

Expand Down Expand Up @@ -48,8 +48,8 @@
* />
*/
public class ListBucketHandler extends ParseSax.HandlerWithResult<ListBucketResponse> {
private SortedSet<ObjectMetadata> contents;
private SortedSet<String> commonPrefixes;
private Set<ObjectMetadata> contents;
private Set<String> commonPrefixes;
private CanonicalUser currentOwner;
private StringBuilder currentText = new StringBuilder();

Expand All @@ -67,8 +67,8 @@ public class ListBucketHandler extends ParseSax.HandlerWithResult<ListBucketResp
public ListBucketHandler(DateService dateParser, EncryptionService encryptionService) {
this.dateParser = dateParser;
this.encryptionService = encryptionService;
this.contents = Sets.newTreeSet();
this.commonPrefixes = Sets.newTreeSet();
this.contents = Sets.newLinkedHashSet();
this.commonPrefixes = Sets.newLinkedHashSet();
}

public ListBucketResponse getResult() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ public void test400WithNotFoundSetsResourceNotFoundException() {
"<Error><Code>Monster.NotFound</Code></Error>", ResourceNotFoundException.class);
}

@Test
public void test400WithUnknownSetsResourceNotFoundException() {
assertCodeMakes("GET", URI.create("https://amazonaws.com/foo"), 400, "",
"<Error><Code>InvalidPlacementGroup.Unknown</Code></Error>", ResourceNotFoundException.class);
}

@Test
public void test400WithIncorrectStateSetsIllegalStateException() {
assertCodeMakes("GET", URI.create("https://amazonaws.com/foo"), 400, "",
Expand All @@ -50,24 +56,23 @@ public void test400WithAuthFailureSetsAuthorizationException() {
"<Error><Code>AuthFailure</Code></Error>", AuthorizationException.class);
}

private void assertCodeMakes(String method, URI uri, int statusCode, String message,
String content, Class<? extends Exception> expected) {
private void assertCodeMakes(String method, URI uri, int statusCode, String message, String content,
Class<? extends Exception> expected) {

ParseAWSErrorFromXmlContent function = Guice.createInjector(new ParserModule(),
new AbstractModule() {
ParseAWSErrorFromXmlContent function = Guice.createInjector(new ParserModule(), new AbstractModule() {

@Override
protected void configure() {
bind(RequestSigner.class).toInstance(createMock(RequestSigner.class));
bindConstant().annotatedWith(Names.named(PROPERTY_HEADER_TAG)).to("amz");
}
@Override
protected void configure() {
bind(RequestSigner.class).toInstance(createMock(RequestSigner.class));
bindConstant().annotatedWith(Names.named(PROPERTY_HEADER_TAG)).to("amz");
}

}).getInstance(ParseAWSErrorFromXmlContent.class);
}).getInstance(ParseAWSErrorFromXmlContent.class);

HttpCommand command = createMock(HttpCommand.class);
HttpRequest request = new HttpRequest(method, uri);
HttpResponse response = new HttpResponse(statusCode, message, Payloads
.newInputStreamPayload(Utils.toInputStream(content)));
HttpResponse response = new HttpResponse(statusCode, message, Payloads.newInputStreamPayload(Utils
.toInputStream(content)));

expect(command.getRequest()).andReturn(request).atLeastOnce();
command.setException(classEq(expected));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/
package org.jclouds.aws.s3.blobstore.functions;

import java.util.SortedSet;
import java.util.Set;

import javax.inject.Inject;
import javax.inject.Singleton;
Expand Down Expand Up @@ -67,7 +67,7 @@ public MutableObjectMetadata apply(StorageMetadata from) {

});

SortedSet<String> commonPrefixes = Sets.newTreeSet(Iterables.transform(Iterables.filter(list,
Set<String> commonPrefixes = Sets.newLinkedHashSet(Iterables.transform(Iterables.filter(list,
new Predicate<StorageMetadata>() {

public boolean apply(StorageMetadata input) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

import java.util.Date;
import java.util.Map;
import java.util.SortedSet;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.ExecutorService;
Expand Down Expand Up @@ -302,8 +302,8 @@ public ObjectMetadata apply(BlobMetadata from) {
});
}

public ListenableFuture<? extends SortedSet<BucketMetadata>> listOwnedBuckets() {
return immediateFuture(Sets.newTreeSet(Iterables.transform(containerToBlobs.keySet(),
public ListenableFuture<? extends Set<BucketMetadata>> listOwnedBuckets() {
return immediateFuture(Sets.newLinkedHashSet(Iterables.transform(containerToBlobs.keySet(),
new Function<String, BucketMetadata>() {
public BucketMetadata apply(String name) {
return new BucketMetadata(name, null, null);
Expand Down
Loading

0 comments on commit cd5fddf

Please sign in to comment.