cleaned up aws apis

This commit is contained in:
Adrian Cole 2012-09-15 23:47:44 -07:00
parent 3a3439c9a0
commit b951276ec3
20 changed files with 72 additions and 63 deletions

View File

@ -18,12 +18,12 @@
*/ */
package org.jclouds.cloudwatch.domain; package org.jclouds.cloudwatch.domain;
import java.util.Set; import java.util.Iterator;
import org.jclouds.javax.annotation.Nullable; import org.jclouds.javax.annotation.Nullable;
import com.google.common.base.Objects; import com.google.common.base.Objects;
import com.google.common.collect.ForwardingSet; import com.google.common.collect.FluentIterable;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
/** /**
@ -33,12 +33,12 @@ import com.google.common.collect.ImmutableSet;
* *
* @author Jeremy Whitlock * @author Jeremy Whitlock
*/ */
public class GetMetricStatisticsResponse extends ForwardingSet<Datapoint> { public class GetMetricStatisticsResponse extends FluentIterable<Datapoint> {
private final Set<Datapoint> datapoints; private final Iterable<Datapoint> datapoints;
private final String label; private final String label;
public GetMetricStatisticsResponse(@Nullable Set<Datapoint> datapoints, String label) { public GetMetricStatisticsResponse(@Nullable Iterable<Datapoint> datapoints, String label) {
// Default to an empty set // Default to an empty set
if (datapoints == null) { if (datapoints == null) {
this.datapoints = ImmutableSet.<Datapoint>of(); this.datapoints = ImmutableSet.<Datapoint>of();
@ -90,8 +90,8 @@ public class GetMetricStatisticsResponse extends ForwardingSet<Datapoint> {
} }
@Override @Override
protected Set<Datapoint> delegate() { public Iterator<Datapoint> iterator() {
return datapoints; return datapoints.iterator();
} }
} }

View File

@ -34,6 +34,7 @@ import org.jclouds.concurrent.Timeout;
* Provides access to Amazon CloudWatch via the Query API * Provides access to Amazon CloudWatch via the Query API
* <p/> * <p/>
* *
* @see MetricAsyncApi
* @see <a href="http://docs.amazonwebservices.com/AmazonCloudWatch/latest/APIReference" /> * @see <a href="http://docs.amazonwebservices.com/AmazonCloudWatch/latest/APIReference" />
* @author Jeremy Whitlock * @author Jeremy Whitlock
*/ */

View File

@ -37,11 +37,14 @@ import org.jclouds.cloudwatch.xml.ListMetricsResponseHandler;
import org.jclouds.collect.IterableWithMarker; import org.jclouds.collect.IterableWithMarker;
import org.jclouds.collect.PagedIterable; import org.jclouds.collect.PagedIterable;
import org.jclouds.rest.annotations.BinderParam; import org.jclouds.rest.annotations.BinderParam;
import org.jclouds.rest.annotations.ExceptionParser;
import org.jclouds.rest.annotations.FormParams; import org.jclouds.rest.annotations.FormParams;
import org.jclouds.rest.annotations.RequestFilters; import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.Transform; import org.jclouds.rest.annotations.Transform;
import org.jclouds.rest.annotations.VirtualHost; import org.jclouds.rest.annotations.VirtualHost;
import org.jclouds.rest.annotations.XMLResponseParser; import org.jclouds.rest.annotations.XMLResponseParser;
import org.jclouds.rest.functions.ReturnEmptyIterableWithMarkerOnNotFoundOr404;
import org.jclouds.rest.functions.ReturnEmptyPagedIterableOnNotFoundOr404;
import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.ListenableFuture;
@ -64,6 +67,7 @@ public interface MetricAsyncApi {
@XMLResponseParser(ListMetricsResponseHandler.class) @XMLResponseParser(ListMetricsResponseHandler.class)
@Transform(MetricsToPagedIterable.class) @Transform(MetricsToPagedIterable.class)
@FormParams(keys = "Action", values = "ListMetrics") @FormParams(keys = "Action", values = "ListMetrics")
@ExceptionParser(ReturnEmptyPagedIterableOnNotFoundOr404.class)
ListenableFuture<? extends PagedIterable<Metric>> list(); ListenableFuture<? extends PagedIterable<Metric>> list();
/** /**
@ -73,6 +77,7 @@ public interface MetricAsyncApi {
@Path("/") @Path("/")
@XMLResponseParser(ListMetricsResponseHandler.class) @XMLResponseParser(ListMetricsResponseHandler.class)
@FormParams(keys = "Action", values = "ListMetrics") @FormParams(keys = "Action", values = "ListMetrics")
@ExceptionParser(ReturnEmptyIterableWithMarkerOnNotFoundOr404.class)
ListenableFuture<? extends IterableWithMarker<Metric>> list(ListMetricsOptions options); ListenableFuture<? extends IterableWithMarker<Metric>> list(ListMetricsOptions options);
/** /**

View File

@ -33,6 +33,7 @@ import org.jclouds.cloudwatch.domain.Unit;
import org.jclouds.cloudwatch.internal.BaseCloudWatchApiExpectTest; import org.jclouds.cloudwatch.internal.BaseCloudWatchApiExpectTest;
import org.jclouds.cloudwatch.options.GetMetricStatisticsOptions; import org.jclouds.cloudwatch.options.GetMetricStatisticsOptions;
import org.jclouds.cloudwatch.options.ListMetricsOptions; import org.jclouds.cloudwatch.options.ListMetricsOptions;
import org.jclouds.collect.IterableWithMarkers;
import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpResponse; import org.jclouds.http.HttpResponse;
import org.jclouds.rest.ResourceNotFoundException; import org.jclouds.rest.ResourceNotFoundException;
@ -76,8 +77,6 @@ public class MetricApiExpectTest extends BaseCloudWatchApiExpectTest {
"[Metric{namespace=AWS/EC2, metricName=CPUUtilization, dimension=[Dimension{name=InstanceId, value=i-689fcf0f}]}]"); "[Metric{namespace=AWS/EC2, metricName=CPUUtilization, dimension=[Dimension{name=InstanceId, value=i-689fcf0f}]}]");
} }
// TODO: this should really be an empty set
@Test(expectedExceptions = ResourceNotFoundException.class)
public void testListMetricsWhenResponseIs404() throws Exception { public void testListMetricsWhenResponseIs404() throws Exception {
HttpResponse listMetricsResponse = HttpResponse.builder().statusCode(404).build(); HttpResponse listMetricsResponse = HttpResponse.builder().statusCode(404).build();
@ -85,7 +84,7 @@ public class MetricApiExpectTest extends BaseCloudWatchApiExpectTest {
CloudWatchApi apiWhenMetricsDontExist = requestSendsResponse( CloudWatchApi apiWhenMetricsDontExist = requestSendsResponse(
listMetrics, listMetricsResponse); listMetrics, listMetricsResponse);
apiWhenMetricsDontExist.getMetricApiForRegion(null).list().get(0); assertEquals(apiWhenMetricsDontExist.getMetricApiForRegion(null).list().get(0), IterableWithMarkers.EMPTY);
} }
public void testListMetrics2PagesWhenResponseIs2xx() throws Exception { public void testListMetrics2PagesWhenResponseIs2xx() throws Exception {

View File

@ -19,7 +19,6 @@
package org.jclouds.sqs.features; package org.jclouds.sqs.features;
import java.net.URI; import java.net.URI;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@ -30,6 +29,7 @@ import org.jclouds.sqs.domain.MessageIdAndMD5;
import org.jclouds.sqs.options.ReceiveMessageOptions; import org.jclouds.sqs.options.ReceiveMessageOptions;
import org.jclouds.sqs.options.SendMessageOptions; import org.jclouds.sqs.options.SendMessageOptions;
import com.google.common.collect.FluentIterable;
import com.google.common.collect.Table; import com.google.common.collect.Table;
/** /**
@ -402,7 +402,7 @@ public interface MessageApi {
* maximum messages to receive, current limit is 10 * maximum messages to receive, current limit is 10
* @see #receive(URI) * @see #receive(URI)
*/ */
List<Message> receive(int max); FluentIterable<Message> receive(int max);
/** /**
* same as {@link #receive(URI, int)} except you can provide options like * same as {@link #receive(URI, int)} except you can provide options like
@ -415,5 +415,5 @@ public interface MessageApi {
* options such as VisibilityTimeout * options such as VisibilityTimeout
* @see #receive(URI, int) * @see #receive(URI, int)
*/ */
List<Message> receive(int max, ReceiveMessageOptions options); FluentIterable<Message> receive(int max, ReceiveMessageOptions options);
} }

View File

@ -21,7 +21,6 @@ package org.jclouds.sqs.features;
import static org.jclouds.sqs.reference.SQSParameters.ACTION; import static org.jclouds.sqs.reference.SQSParameters.ACTION;
import static org.jclouds.sqs.reference.SQSParameters.VERSION; import static org.jclouds.sqs.reference.SQSParameters.VERSION;
import java.util.List;
import java.util.Map; import java.util.Map;
import javax.ws.rs.FormParam; import javax.ws.rs.FormParam;
@ -56,6 +55,7 @@ import org.jclouds.sqs.xml.ReceiveMessageResponseHandler;
import org.jclouds.sqs.xml.RegexMessageIdAndMD5Handler; import org.jclouds.sqs.xml.RegexMessageIdAndMD5Handler;
import org.jclouds.sqs.xml.SendMessageBatchResponseHandler; import org.jclouds.sqs.xml.SendMessageBatchResponseHandler;
import com.google.common.collect.FluentIterable;
import com.google.common.collect.Table; import com.google.common.collect.Table;
import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.ListenableFuture;
@ -260,7 +260,7 @@ public interface MessageAsyncApi {
@Path("/") @Path("/")
@FormParams(keys = ACTION, values = "ReceiveMessage") @FormParams(keys = ACTION, values = "ReceiveMessage")
@XMLResponseParser(ReceiveMessageResponseHandler.class) @XMLResponseParser(ReceiveMessageResponseHandler.class)
ListenableFuture<? extends List<? extends Message>> receive(@FormParam("MaxNumberOfMessages") int max); ListenableFuture<? extends FluentIterable<? extends Message>> receive(@FormParam("MaxNumberOfMessages") int max);
/** /**
* @see MessageApi#receive(int, ReceiveMessageOptions) * @see MessageApi#receive(int, ReceiveMessageOptions)
@ -269,7 +269,7 @@ public interface MessageAsyncApi {
@Path("/") @Path("/")
@FormParams(keys = ACTION, values = "ReceiveMessage") @FormParams(keys = ACTION, values = "ReceiveMessage")
@XMLResponseParser(ReceiveMessageResponseHandler.class) @XMLResponseParser(ReceiveMessageResponseHandler.class)
ListenableFuture<? extends List<? extends Message>> receive(@FormParam("MaxNumberOfMessages") int max, ListenableFuture<? extends FluentIterable<? extends Message>> receive(@FormParam("MaxNumberOfMessages") int max,
ReceiveMessageOptions options); ReceiveMessageOptions options);
} }

View File

@ -20,7 +20,6 @@ package org.jclouds.sqs.features;
import java.net.URI; import java.net.URI;
import java.util.Map; import java.util.Map;
import java.util.Set;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import org.jclouds.concurrent.Timeout; import org.jclouds.concurrent.Timeout;
@ -28,6 +27,8 @@ import org.jclouds.sqs.domain.QueueAttributes;
import org.jclouds.sqs.options.CreateQueueOptions; import org.jclouds.sqs.options.CreateQueueOptions;
import org.jclouds.sqs.options.ListQueuesOptions; import org.jclouds.sqs.options.ListQueuesOptions;
import com.google.common.collect.FluentIterable;
/** /**
* Provides access to SQS via their REST API. * Provides access to SQS via their REST API.
* <p/> * <p/>
@ -53,9 +54,9 @@ public interface QueueApi {
* "http://docs.amazonwebservices.com/AWSSimpleQueueService/2011-10-01/APIReference/Query_QueryListQueues.html" * "http://docs.amazonwebservices.com/AWSSimpleQueueService/2011-10-01/APIReference/Query_QueryListQueues.html"
* /> * />
*/ */
Set<URI> list(); FluentIterable<URI> list();
Set<URI> list(ListQueuesOptions options); FluentIterable<URI> list(ListQueuesOptions options);
/** /**
* The CreateQueue action creates a new queue. * The CreateQueue action creates a new queue.

View File

@ -23,7 +23,6 @@ import static org.jclouds.sqs.reference.SQSParameters.VERSION;
import java.net.URI; import java.net.URI;
import java.util.Map; import java.util.Map;
import java.util.Set;
import javax.ws.rs.FormParam; import javax.ws.rs.FormParam;
import javax.ws.rs.POST; import javax.ws.rs.POST;
@ -52,6 +51,7 @@ import org.jclouds.sqs.xml.RegexListQueuesResponseHandler;
import org.jclouds.sqs.xml.RegexQueueHandler; import org.jclouds.sqs.xml.RegexQueueHandler;
import org.jclouds.sqs.xml.ValueHandler; import org.jclouds.sqs.xml.ValueHandler;
import com.google.common.collect.FluentIterable;
import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.ListenableFuture;
/** /**
@ -72,7 +72,7 @@ public interface QueueAsyncApi {
@Path("/") @Path("/")
@FormParams(keys = ACTION, values = "ListQueues") @FormParams(keys = ACTION, values = "ListQueues")
@ResponseParser(RegexListQueuesResponseHandler.class) @ResponseParser(RegexListQueuesResponseHandler.class)
ListenableFuture<Set<URI>> list(); ListenableFuture<FluentIterable<URI>> list();
/** /**
* @see QueueApi#list(ListQueuesOptions) * @see QueueApi#list(ListQueuesOptions)
@ -81,7 +81,7 @@ public interface QueueAsyncApi {
@Path("/") @Path("/")
@FormParams(keys = ACTION, values = "ListQueues") @FormParams(keys = ACTION, values = "ListQueues")
@ResponseParser(RegexListQueuesResponseHandler.class) @ResponseParser(RegexListQueuesResponseHandler.class)
ListenableFuture<Set<URI>> list(ListQueuesOptions options); ListenableFuture<FluentIterable<URI>> list(ListQueuesOptions options);
/** /**
* @see QueueApi#create * @see QueueApi#create

View File

@ -20,13 +20,12 @@ package org.jclouds.sqs.xml;
import static org.jclouds.util.SaxUtils.equalsOrSuffix; import static org.jclouds.util.SaxUtils.equalsOrSuffix;
import java.util.List;
import org.jclouds.http.functions.ParseSax; import org.jclouds.http.functions.ParseSax;
import org.jclouds.sqs.domain.Message; import org.jclouds.sqs.domain.Message;
import org.xml.sax.Attributes; import org.xml.sax.Attributes;
import org.xml.sax.SAXException; import org.xml.sax.SAXException;
import com.google.common.collect.FluentIterable;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableList.Builder; import com.google.common.collect.ImmutableList.Builder;
import com.google.inject.Inject; import com.google.inject.Inject;
@ -38,7 +37,7 @@ import com.google.inject.Inject;
* *
* @author Adrian Cole * @author Adrian Cole
*/ */
public class ReceiveMessageResponseHandler extends ParseSax.HandlerForGeneratedRequestWithResult<List<Message>> { public class ReceiveMessageResponseHandler extends ParseSax.HandlerForGeneratedRequestWithResult<FluentIterable<Message>> {
private final MessageHandler messageHandler; private final MessageHandler messageHandler;
@ -52,8 +51,8 @@ public class ReceiveMessageResponseHandler extends ParseSax.HandlerForGeneratedR
} }
@Override @Override
public List<Message> getResult() { public FluentIterable<Message> getResult() {
return messages.build(); return FluentIterable.from(messages.build());
} }
@Override @Override

View File

@ -19,7 +19,6 @@
package org.jclouds.sqs.xml; package org.jclouds.sqs.xml;
import java.net.URI; import java.net.URI;
import java.util.Set;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Singleton; import javax.inject.Singleton;
@ -29,6 +28,7 @@ import org.jclouds.http.functions.ReturnStringIf2xx;
import org.jclouds.sqs.xml.internal.BaseRegexQueueHandler; import org.jclouds.sqs.xml.internal.BaseRegexQueueHandler;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.collect.FluentIterable;
/** /**
* *
@ -38,7 +38,7 @@ import com.google.common.base.Function;
* @author Adrian Cole * @author Adrian Cole
*/ */
@Singleton @Singleton
public class RegexListQueuesResponseHandler extends BaseRegexQueueHandler implements Function<HttpResponse, Set<URI>> { public class RegexListQueuesResponseHandler extends BaseRegexQueueHandler implements Function<HttpResponse, FluentIterable<URI>> {
private final ReturnStringIf2xx returnStringIf200; private final ReturnStringIf2xx returnStringIf200;
@Inject @Inject
@ -47,7 +47,7 @@ public class RegexListQueuesResponseHandler extends BaseRegexQueueHandler implem
} }
@Override @Override
public Set<URI> apply(HttpResponse response) { public FluentIterable<URI> apply(HttpResponse response) {
return parse(returnStringIf200.apply(response)); return parse(returnStringIf200.apply(response));
} }

View File

@ -19,13 +19,13 @@
package org.jclouds.sqs.xml.internal; package org.jclouds.sqs.xml.internal;
import java.net.URI; import java.net.URI;
import java.util.Set;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import javax.inject.Singleton; import javax.inject.Singleton;
import com.google.common.base.Strings; import com.google.common.base.Strings;
import com.google.common.collect.FluentIterable;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableSet.Builder; import com.google.common.collect.ImmutableSet.Builder;
@ -40,7 +40,7 @@ import com.google.common.collect.ImmutableSet.Builder;
public class BaseRegexQueueHandler { public class BaseRegexQueueHandler {
protected final Pattern pattern = Pattern.compile("<QueueUrl>(https://[\\S&&[^<]]+)</QueueUrl>"); protected final Pattern pattern = Pattern.compile("<QueueUrl>(https://[\\S&&[^<]]+)</QueueUrl>");
public Set<URI> parse(String in) { public FluentIterable<URI> parse(String in) {
Builder<URI> queues = ImmutableSet.<URI> builder(); Builder<URI> queues = ImmutableSet.<URI> builder();
Matcher matcher = pattern.matcher(in); Matcher matcher = pattern.matcher(in);
while (matcher.find()) { while (matcher.find()) {
@ -48,7 +48,7 @@ public class BaseRegexQueueHandler {
if (!Strings.isNullOrEmpty(uriText)) if (!Strings.isNullOrEmpty(uriText))
queues.add(URI.create(uriText)); queues.add(URI.create(uriText));
} }
return queues.build(); return FluentIterable.from(queues.build());
} }
} }

View File

@ -114,7 +114,7 @@ public class BulkMessageApiLiveTest extends BaseSQSApiLiveTest {
// you are not guaranteed to get all messages in the same request // you are not guaranteed to get all messages in the same request
Set<Message> messages = Sets.newLinkedHashSet(); Set<Message> messages = Sets.newLinkedHashSet();
while (messages.size() != idPayload.size()) while (messages.size() != idPayload.size())
messages.addAll(api.receive(idPayload.size(), attribute("None").visibilityTimeout(5))); messages.addAll(api.receive(idPayload.size(), attribute("None").visibilityTimeout(5)).toImmutableSet());
return messages; return messages;
} }

View File

@ -24,11 +24,11 @@ import static org.testng.Assert.assertNotNull;
import java.net.URI; import java.net.URI;
import java.util.Map; import java.util.Map;
import java.util.Set;
import org.jclouds.sqs.internal.BaseSQSApiLiveTest; import org.jclouds.sqs.internal.BaseSQSApiLiveTest;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.common.collect.FluentIterable;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
/** /**
@ -48,7 +48,7 @@ public class QueueApiLiveTest extends BaseSQSApiLiveTest {
} }
protected void listQueuesInRegion(String region) throws InterruptedException { protected void listQueuesInRegion(String region) throws InterruptedException {
Set<URI> allResults = api().getQueueApiForRegion(region).list(); FluentIterable<URI> allResults = api().getQueueApiForRegion(region).list();
assertNotNull(allResults); assertNotNull(allResults);
if (allResults.size() >= 1) { if (allResults.size() >= 1) {
URI queue = getLast(allResults); URI queue = getLast(allResults);

View File

@ -39,6 +39,7 @@ import org.jclouds.sqs.features.QueueApi;
import org.testng.annotations.AfterClass; import org.testng.annotations.AfterClass;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.common.collect.FluentIterable;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import com.google.common.reflect.TypeToken; import com.google.common.reflect.TypeToken;
import com.google.common.util.concurrent.Uninterruptibles; import com.google.common.util.concurrent.Uninterruptibles;
@ -60,7 +61,7 @@ public class BaseSQSApiLiveTest extends BaseContextLiveTest<RestContext<SQSApi,
protected String recreateQueueInRegion(String queueName, String region) { protected String recreateQueueInRegion(String queueName, String region) {
QueueApi api = api().getQueueApiForRegion(region); QueueApi api = api().getQueueApiForRegion(region);
Set<URI> result = api.list(queuePrefix(queueName)); FluentIterable<URI> result = api.list(queuePrefix(queueName));
if (result.size() >= 1) { if (result.size() >= 1) {
api.delete(getLast(result)); api.delete(getLast(result));
} }
@ -110,7 +111,7 @@ public class BaseSQSApiLiveTest extends BaseContextLiveTest<RestContext<SQSApi,
final URI finalQ = queue; final URI finalQ = queue;
assertEventually(new Runnable() { assertEventually(new Runnable() {
public void run() { public void run() {
Set<URI> result = api().getQueueApiForRegion(region).list(); FluentIterable<URI> result = api().getQueueApiForRegion(region).list();
assertNotNull(result); assertNotNull(result);
assert result.size() >= 1 : result; assert result.size() >= 1 : result;
assertTrue(result.contains(finalQ), finalQ + " not in " + result); assertTrue(result.contains(finalQ), finalQ + " not in " + result);

View File

@ -21,7 +21,6 @@ package org.jclouds.sqs.parse;
import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertEquals;
import java.io.InputStream; import java.io.InputStream;
import java.util.List;
import org.jclouds.crypto.CryptoStreams; import org.jclouds.crypto.CryptoStreams;
import org.jclouds.http.functions.BaseHandlerTest; import org.jclouds.http.functions.BaseHandlerTest;
@ -29,6 +28,7 @@ import org.jclouds.sqs.domain.Message;
import org.jclouds.sqs.xml.ReceiveMessageResponseHandler; import org.jclouds.sqs.xml.ReceiveMessageResponseHandler;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.common.collect.FluentIterable;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.hash.HashCodes; import com.google.common.hash.HashCodes;
@ -43,17 +43,17 @@ public class ReceiveMessageResponseTest extends BaseHandlerTest {
public void test() { public void test() {
InputStream is = getClass().getResourceAsStream("/messages.xml"); InputStream is = getClass().getResourceAsStream("/messages.xml");
List<Message> expected = expected(); FluentIterable<Message> expected = expected();
ReceiveMessageResponseHandler handler = injector.getInstance(ReceiveMessageResponseHandler.class); ReceiveMessageResponseHandler handler = injector.getInstance(ReceiveMessageResponseHandler.class);
List<Message> result = factory.create(handler).parse(is); FluentIterable<Message> result = factory.create(handler).parse(is);
assertEquals(result.toString(), expected.toString()); assertEquals(result.toString(), expected.toString());
} }
public List<Message> expected() { public FluentIterable<Message> expected() {
return ImmutableList.of(Message return FluentIterable.from(ImmutableList.of(Message
.builder() .builder()
.id("5fea7756-0ea4-451a-a703-a558b933e274") .id("5fea7756-0ea4-451a-a703-a558b933e274")
.receiptHandle( .receiptHandle(
@ -63,6 +63,6 @@ public class ReceiveMessageResponseTest extends BaseHandlerTest {
.addAttribute("SenderId", "195004372649") .addAttribute("SenderId", "195004372649")
.addAttribute("SentTimestamp", "1238099229000") .addAttribute("SentTimestamp", "1238099229000")
.addAttribute("ApproximateReceiveCount", "5") .addAttribute("ApproximateReceiveCount", "5")
.addAttribute("ApproximateFirstReceiveTimestamp", "1250700979248").build()); .addAttribute("ApproximateFirstReceiveTimestamp", "1250700979248").build()));
} }
} }

View File

@ -39,16 +39,16 @@ import org.jclouds.javax.annotation.Nullable;
@Timeout(duration = 30, timeUnit = TimeUnit.SECONDS) @Timeout(duration = 30, timeUnit = TimeUnit.SECONDS)
public interface LoadBalancerApi { public interface LoadBalancerApi {
String createLoadBalancerListeningInAvailabilityZones(String name, Iterable<Listener> listeners, String createListeningInAvailabilityZones(String name, Iterable<Listener> listeners,
Iterable<String> availabilityZones); Iterable<String> availabilityZones);
String createLoadBalancerListeningInAvailabilityZones(String name, Listener listeners, String createListeningInAvailabilityZones(String name, Listener listeners,
Iterable<String> availabilityZones); Iterable<String> availabilityZones);
String createLoadBalancerListeningInSubnetAssignedToSecurityGroups(String name, String subnetId, String createListeningInSubnetAssignedToSecurityGroups(String name, String subnetId,
Iterable<String> securityGroupIds); Iterable<String> securityGroupIds);
String createLoadBalancerListeningInSubnetsAssignedToSecurityGroups(String name, Iterable<String> subnetIds, String createListeningInSubnetsAssignedToSecurityGroups(String name, Iterable<String> subnetIds,
Iterable<String> securityGroupIds); Iterable<String> securityGroupIds);

View File

@ -45,6 +45,8 @@ import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.Transform; import org.jclouds.rest.annotations.Transform;
import org.jclouds.rest.annotations.VirtualHost; import org.jclouds.rest.annotations.VirtualHost;
import org.jclouds.rest.annotations.XMLResponseParser; import org.jclouds.rest.annotations.XMLResponseParser;
import org.jclouds.rest.functions.ReturnEmptyIterableWithMarkerOnNotFoundOr404;
import org.jclouds.rest.functions.ReturnEmptyPagedIterableOnNotFoundOr404;
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404; import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404;
@ -63,47 +65,47 @@ import com.google.common.util.concurrent.ListenableFuture;
@VirtualHost @VirtualHost
public interface LoadBalancerAsyncApi { public interface LoadBalancerAsyncApi {
/** /**
* @see LoadBalancerApi#createLoadBalancerListeningInAvailabilityZones() * @see LoadBalancerApi#createListeningInAvailabilityZones()
*/ */
@POST @POST
@Path("/") @Path("/")
@XMLResponseParser(CreateLoadBalancerResponseHandler.class) @XMLResponseParser(CreateLoadBalancerResponseHandler.class)
@FormParams(keys = ACTION, values = "CreateLoadBalancer") @FormParams(keys = ACTION, values = "CreateLoadBalancer")
ListenableFuture<String> createLoadBalancerListeningInAvailabilityZones(@FormParam("LoadBalancerName") String name, ListenableFuture<String> createListeningInAvailabilityZones(@FormParam("LoadBalancerName") String name,
@BinderParam(BindListenersToFormParams.class) Listener listeners, @BinderParam(BindListenersToFormParams.class) Listener listeners,
@BinderParam(BindAvailabilityZonesToIndexedFormParams.class) Iterable<String> availabilityZones); @BinderParam(BindAvailabilityZonesToIndexedFormParams.class) Iterable<String> availabilityZones);
/** /**
* @see LoadBalancerApi#createLoadBalancerListeningInAvailabilityZones() * @see LoadBalancerApi#createListeningInAvailabilityZones()
*/ */
@POST @POST
@Path("/") @Path("/")
@XMLResponseParser(CreateLoadBalancerResponseHandler.class) @XMLResponseParser(CreateLoadBalancerResponseHandler.class)
@FormParams(keys = ACTION, values = "CreateLoadBalancer") @FormParams(keys = ACTION, values = "CreateLoadBalancer")
ListenableFuture<String> createLoadBalancerListeningInAvailabilityZones(@FormParam("LoadBalancerName") String name, ListenableFuture<String> createListeningInAvailabilityZones(@FormParam("LoadBalancerName") String name,
@BinderParam(BindListenersToFormParams.class) Iterable<Listener> listeners, @BinderParam(BindListenersToFormParams.class) Iterable<Listener> listeners,
@BinderParam(BindAvailabilityZonesToIndexedFormParams.class) Iterable<String> availabilityZones); @BinderParam(BindAvailabilityZonesToIndexedFormParams.class) Iterable<String> availabilityZones);
/** /**
* @see LoadBalancerApi#createLoadBalancerListeningInSubnetAssignedToSecurityGroups() * @see LoadBalancerApi#createListeningInSubnetAssignedToSecurityGroups()
*/ */
@POST @POST
@Path("/") @Path("/")
@XMLResponseParser(CreateLoadBalancerResponseHandler.class) @XMLResponseParser(CreateLoadBalancerResponseHandler.class)
@FormParams(keys = ACTION, values = "CreateLoadBalancer") @FormParams(keys = ACTION, values = "CreateLoadBalancer")
ListenableFuture<String> createLoadBalancerListeningInSubnetAssignedToSecurityGroups( ListenableFuture<String> createListeningInSubnetAssignedToSecurityGroups(
@FormParam("LoadBalancerName") String name, @FormParam("LoadBalancerName") String name,
@FormParam("Subnets.member.1") String subnetId, @FormParam("Subnets.member.1") String subnetId,
@BinderParam(BindSecurityGroupsToIndexedFormParams.class) Iterable<String> securityGroupIds); @BinderParam(BindSecurityGroupsToIndexedFormParams.class) Iterable<String> securityGroupIds);
/** /**
* @see LoadBalancerApi#createLoadBalancerListeningInSubnetsAssignedToSecurityGroups() * @see LoadBalancerApi#createListeningInSubnetsAssignedToSecurityGroups()
*/ */
@POST @POST
@Path("/") @Path("/")
@XMLResponseParser(CreateLoadBalancerResponseHandler.class) @XMLResponseParser(CreateLoadBalancerResponseHandler.class)
@FormParams(keys = ACTION, values = "CreateLoadBalancer") @FormParams(keys = ACTION, values = "CreateLoadBalancer")
ListenableFuture<String> createLoadBalancerListeningInSubnetsAssignedToSecurityGroups( ListenableFuture<String> createListeningInSubnetsAssignedToSecurityGroups(
@FormParam("LoadBalancerName") String name, @FormParam("LoadBalancerName") String name,
@BinderParam(BindSubnetsToIndexedFormParams.class) Iterable<String> subnetIds, @BinderParam(BindSubnetsToIndexedFormParams.class) Iterable<String> subnetIds,
@BinderParam(BindSecurityGroupsToIndexedFormParams.class) Iterable<String> securityGroupIds); @BinderParam(BindSecurityGroupsToIndexedFormParams.class) Iterable<String> securityGroupIds);
@ -125,6 +127,7 @@ public interface LoadBalancerAsyncApi {
@Path("/") @Path("/")
@XMLResponseParser(DescribeLoadBalancersResultHandler.class) @XMLResponseParser(DescribeLoadBalancersResultHandler.class)
@Transform(LoadBalancersToPagedIterable.class) @Transform(LoadBalancersToPagedIterable.class)
@ExceptionParser(ReturnEmptyPagedIterableOnNotFoundOr404.class)
@FormParams(keys = "Action", values = "DescribeLoadBalancers") @FormParams(keys = "Action", values = "DescribeLoadBalancers")
ListenableFuture<PagedIterable<LoadBalancer>> list(); ListenableFuture<PagedIterable<LoadBalancer>> list();
@ -134,6 +137,7 @@ public interface LoadBalancerAsyncApi {
@POST @POST
@Path("/") @Path("/")
@XMLResponseParser(DescribeLoadBalancersResultHandler.class) @XMLResponseParser(DescribeLoadBalancersResultHandler.class)
@ExceptionParser(ReturnEmptyIterableWithMarkerOnNotFoundOr404.class)
@FormParams(keys = "Action", values = "DescribeLoadBalancers") @FormParams(keys = "Action", values = "DescribeLoadBalancers")
ListenableFuture<IterableWithMarker<LoadBalancer>> list(ListLoadBalancersOptions options); ListenableFuture<IterableWithMarker<LoadBalancer>> list(ListLoadBalancersOptions options);

View File

@ -82,7 +82,7 @@ public class ELBLoadBalanceNodesStrategy implements LoadBalanceNodesStrategy {
logger.debug(">> creating loadBalancer(%s) in zones(%s)", name, zonesDesired); logger.debug(">> creating loadBalancer(%s) in zones(%s)", name, zonesDesired);
try { try {
String dnsName = api.getLoadBalancerApiForRegion(region).createLoadBalancerListeningInAvailabilityZones( String dnsName = api.getLoadBalancerApiForRegion(region).createListeningInAvailabilityZones(
name, name,
ImmutableSet.of(Listener.builder().port(loadBalancerPort).instancePort(instancePort) ImmutableSet.of(Listener.builder().port(loadBalancerPort).instancePort(instancePort)
.protocol(Protocol.valueOf(protocol)).build()), zonesDesired); .protocol(Protocol.valueOf(protocol)).build()), zonesDesired);

View File

@ -24,6 +24,7 @@ import static org.testng.Assert.assertNull;
import java.util.TimeZone; import java.util.TimeZone;
import org.jclouds.collect.IterableWithMarkers;
import org.jclouds.elb.ELBApi; import org.jclouds.elb.ELBApi;
import org.jclouds.elb.domain.LoadBalancer; import org.jclouds.elb.domain.LoadBalancer;
import org.jclouds.elb.internal.BaseELBApiExpectTest; import org.jclouds.elb.internal.BaseELBApiExpectTest;
@ -31,7 +32,6 @@ import org.jclouds.elb.parse.DescribeLoadBalancersResponseTest;
import org.jclouds.elb.parse.GetLoadBalancerResponseTest; import org.jclouds.elb.parse.GetLoadBalancerResponseTest;
import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpResponse; import org.jclouds.http.HttpResponse;
import org.jclouds.rest.ResourceNotFoundException;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
@ -197,8 +197,6 @@ public class LoadBalancerApiExpectTest extends BaseELBApiExpectTest {
assertEquals(ImmutableSet.copyOf(Iterables.concat(apiWhenExist.getLoadBalancerApiForRegion("eu-west-1").list())), ImmutableSet.of(lb1, lb2)); assertEquals(ImmutableSet.copyOf(Iterables.concat(apiWhenExist.getLoadBalancerApiForRegion("eu-west-1").list())), ImmutableSet.of(lb1, lb2));
} }
// TODO: this should really be an empty set
@Test(expectedExceptions = ResourceNotFoundException.class)
public void testListWhenResponseIs404() throws Exception { public void testListWhenResponseIs404() throws Exception {
HttpResponse listResponse = HttpResponse.builder().statusCode(404).build(); HttpResponse listResponse = HttpResponse.builder().statusCode(404).build();
@ -206,7 +204,8 @@ public class LoadBalancerApiExpectTest extends BaseELBApiExpectTest {
ELBApi apiWhenDontExist = requestSendsResponse( ELBApi apiWhenDontExist = requestSendsResponse(
list, listResponse); list, listResponse);
apiWhenDontExist.getLoadBalancerApi().list(); assertEquals(apiWhenDontExist.getLoadBalancerApi().list().get(0), IterableWithMarkers.EMPTY);
} }
public void testListWithOptionsWhenResponseIs2xx() throws Exception { public void testListWithOptionsWhenResponseIs2xx() throws Exception {

View File

@ -38,10 +38,10 @@ import org.jclouds.aws.ec2.domain.MonitoringState;
import org.jclouds.aws.ec2.services.AWSSecurityGroupClient; import org.jclouds.aws.ec2.services.AWSSecurityGroupClient;
import org.jclouds.cloudwatch.CloudWatchApi; import org.jclouds.cloudwatch.CloudWatchApi;
import org.jclouds.cloudwatch.CloudWatchAsyncApi; import org.jclouds.cloudwatch.CloudWatchAsyncApi;
import org.jclouds.cloudwatch.domain.Datapoint;
import org.jclouds.cloudwatch.domain.Dimension; import org.jclouds.cloudwatch.domain.Dimension;
import org.jclouds.cloudwatch.domain.EC2Constants; import org.jclouds.cloudwatch.domain.EC2Constants;
import org.jclouds.cloudwatch.domain.GetMetricStatistics; import org.jclouds.cloudwatch.domain.GetMetricStatistics;
import org.jclouds.cloudwatch.domain.GetMetricStatisticsResponse;
import org.jclouds.cloudwatch.domain.Statistics; import org.jclouds.cloudwatch.domain.Statistics;
import org.jclouds.cloudwatch.domain.Unit; import org.jclouds.cloudwatch.domain.Unit;
import org.jclouds.compute.domain.ExecResponse; import org.jclouds.compute.domain.ExecResponse;
@ -170,7 +170,7 @@ public class AWSEC2ComputeServiceLiveTest extends EC2ComputeServiceLiveTest {
.modules(setupModules()).build(); .modules(setupModules()).build();
try { try {
Set<Datapoint> datapoints = monitoringContext.getApi().getMetricApiForRegion(instance.getRegion()) GetMetricStatisticsResponse datapoints = monitoringContext.getApi().getMetricApiForRegion(instance.getRegion())
.getMetricStatistics(GetMetricStatistics.builder() .getMetricStatistics(GetMetricStatistics.builder()
.dimension(new Dimension(EC2Constants.Dimension.INSTANCE_ID, instance.getId())) .dimension(new Dimension(EC2Constants.Dimension.INSTANCE_ID, instance.getId()))
.unit(Unit.PERCENT) .unit(Unit.PERCENT)