diff --git a/apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/CloudWatch.java b/apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/CloudWatch.java index 8fdae90e02..424e243e2e 100644 --- a/apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/CloudWatch.java +++ b/apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/CloudWatch.java @@ -18,16 +18,16 @@ */ package org.jclouds.cloudwatch; -import java.util.Iterator; import java.util.List; -import org.jclouds.cloudwatch.domain.ListMetricsResponse; import org.jclouds.cloudwatch.domain.Metric; import org.jclouds.cloudwatch.domain.MetricDatum; import org.jclouds.cloudwatch.features.MetricClient; import org.jclouds.cloudwatch.options.ListMetricsOptions; +import org.jclouds.collect.PaginatedSet; +import org.jclouds.collect.PaginatedSets; -import com.google.common.collect.AbstractIterator; +import com.google.common.base.Function; import com.google.common.collect.Iterables; /** @@ -46,43 +46,18 @@ public class CloudWatch { * @return iterable of metrics fitting the criteria */ public static Iterable listMetrics(final MetricClient metricClient, final ListMetricsOptions options) { - return new Iterable() { - public Iterator iterator() { - return new AbstractIterator() { + return PaginatedSets.lazyContinue(metricClient.list(options), new Function>() { - private ListMetricsOptions lastOptions = options; - private ListMetricsResponse response = metricClient.listMetrics(lastOptions); - private Iterator iterator = response.iterator(); - - /** - * {@inheritDoc} - */ - @Override - protected Metric computeNext() { - while (true) { - if (iterator == null) { - lastOptions = ListMetricsOptions.builder() - .namespace(lastOptions.getNamespace()) - .metricName(lastOptions.getMetricName()) - .dimensions(lastOptions.getDimensions()) - .nextToken(lastOptions.getNextToken()) - .build(); - response = metricClient.listMetrics(lastOptions); - iterator = response.iterator(); - } - if (iterator.hasNext()) { - return iterator.next(); - } - if (response.getNextToken() == null) { - return endOfData(); - } - iterator = null; - } - } - - }; + @Override + public PaginatedSet apply(String input) { + return metricClient.list(options.clone().nextMarker(input)); } - }; + + @Override + public String toString() { + return "listMetrics(" + options + ")"; + } + }); } /** @@ -112,7 +87,7 @@ public class CloudWatch { MetricClient metricClient = cloudWatchClient.getMetricClientForRegion(region); for (List slice : Iterables.partition(metrics, 10)) { - metricClient.putMetricData(slice, namespace); + metricClient.putMetricsInNamespace(slice, namespace); } } diff --git a/apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/CloudWatchAsyncClient.java b/apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/CloudWatchAsyncClient.java index a609bc6e7c..a2f5ef5f1b 100644 --- a/apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/CloudWatchAsyncClient.java +++ b/apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/CloudWatchAsyncClient.java @@ -87,6 +87,9 @@ public interface CloudWatchAsyncClient { /** * Provides asynchronous access to Metric features. */ + @Delegate + MetricAsyncClient getMetricClient(); + @Delegate MetricAsyncClient getMetricClientForRegion(@EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region); diff --git a/apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/CloudWatchClient.java b/apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/CloudWatchClient.java index 8234a035c3..a9fc991d9c 100644 --- a/apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/CloudWatchClient.java +++ b/apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/CloudWatchClient.java @@ -95,6 +95,12 @@ public interface CloudWatchClient { Set getMetricStatisticsInRegion(@Nullable String region, String metricName, String namespace, Date startTime, Date endTime, int period, Statistics statistics, GetMetricStatisticsOptions... options); + /** + * Provides synchronous access to Metric features. + */ + @Delegate + MetricClient getMetricClient(); + /** * Provides synchronous access to Metric features. */ diff --git a/apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/features/MetricAsyncClient.java b/apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/features/MetricAsyncClient.java index 951d731c1b..6ff1df5663 100644 --- a/apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/features/MetricAsyncClient.java +++ b/apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/features/MetricAsyncClient.java @@ -18,27 +18,29 @@ */ package org.jclouds.cloudwatch.features; -import com.google.common.util.concurrent.ListenableFuture; +import javax.ws.rs.FormParam; +import javax.ws.rs.POST; +import javax.ws.rs.Path; + import org.jclouds.aws.filters.FormSigner; import org.jclouds.cloudwatch.binders.GetMetricStatisticsBinder; import org.jclouds.cloudwatch.binders.MetricDataBinder; import org.jclouds.cloudwatch.domain.GetMetricStatistics; import org.jclouds.cloudwatch.domain.GetMetricStatisticsResponse; -import org.jclouds.cloudwatch.domain.ListMetricsResponse; +import org.jclouds.cloudwatch.domain.Metric; import org.jclouds.cloudwatch.domain.MetricDatum; import org.jclouds.cloudwatch.options.GetMetricStatisticsOptions; import org.jclouds.cloudwatch.options.ListMetricsOptions; import org.jclouds.cloudwatch.xml.GetMetricStatisticsResponseHandlerV2; import org.jclouds.cloudwatch.xml.ListMetricsResponseHandler; +import org.jclouds.collect.PaginatedSet; import org.jclouds.rest.annotations.BinderParam; import org.jclouds.rest.annotations.FormParams; import org.jclouds.rest.annotations.RequestFilters; import org.jclouds.rest.annotations.VirtualHost; import org.jclouds.rest.annotations.XMLResponseParser; -import javax.ws.rs.FormParam; -import javax.ws.rs.POST; -import javax.ws.rs.Path; +import com.google.common.util.concurrent.ListenableFuture; /** * Provides access to Amazon CloudWatch via the Query API @@ -52,22 +54,22 @@ import javax.ws.rs.Path; public interface MetricAsyncClient { /** - * @see MetricClient#listMetrics() + * @see MetricClient#list() */ @POST @Path("/") @XMLResponseParser(ListMetricsResponseHandler.class) @FormParams(keys = "Action", values = "ListMetrics") - ListenableFuture listMetrics(); + ListenableFuture> list(); /** - * @see MetricClient#listMetrics(ListMetricsOptions) + * @see MetricClient#list(ListMetricsOptions) */ @POST @Path("/") @XMLResponseParser(ListMetricsResponseHandler.class) @FormParams(keys = "Action", values = "ListMetrics") - ListenableFuture listMetrics(ListMetricsOptions options); + ListenableFuture> list(ListMetricsOptions options); /** * @see MetricClient#getMetricStatistics(GetMetricStatistics) @@ -91,12 +93,12 @@ public interface MetricAsyncClient { GetMetricStatisticsOptions options); /** - * @see MetricClient#putMetricData(Iterable, String) + * @see MetricClient#putMetricsInNamespace(Iterable, String) */ @POST @Path("/") @FormParams(keys = "Action", values = "PutMetricData") - ListenableFuture putMetricData(@BinderParam(MetricDataBinder.class) Iterable metrics, + ListenableFuture putMetricsInNamespace(@BinderParam(MetricDataBinder.class) Iterable metrics, @FormParam("Namespace") String namespace); } diff --git a/apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/features/MetricClient.java b/apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/features/MetricClient.java index fe3477deec..02bb77ca69 100644 --- a/apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/features/MetricClient.java +++ b/apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/features/MetricClient.java @@ -18,16 +18,17 @@ */ package org.jclouds.cloudwatch.features; +import java.util.concurrent.TimeUnit; + import org.jclouds.cloudwatch.domain.GetMetricStatistics; import org.jclouds.cloudwatch.domain.GetMetricStatisticsResponse; -import org.jclouds.cloudwatch.domain.ListMetricsResponse; +import org.jclouds.cloudwatch.domain.Metric; import org.jclouds.cloudwatch.domain.MetricDatum; import org.jclouds.cloudwatch.options.GetMetricStatisticsOptions; import org.jclouds.cloudwatch.options.ListMetricsOptions; +import org.jclouds.collect.PaginatedSet; import org.jclouds.concurrent.Timeout; -import java.util.concurrent.TimeUnit; - /** * Provides access to Amazon CloudWatch via the Query API *

@@ -53,9 +54,9 @@ public interface MetricClient { * * @return the response object */ - ListMetricsResponse listMetrics(ListMetricsOptions options); + PaginatedSet list(ListMetricsOptions options); - ListMetricsResponse listMetrics(); + PaginatedSet list(); /** * Gets statistics for the specified metric. @@ -75,6 +76,6 @@ public interface MetricClient { * @param metrics the metrics to publish * @param namespace the namespace to publish the metrics to */ - void putMetricData(Iterable metrics, String namespace); + void putMetricsInNamespace(Iterable metrics, String namespace); } diff --git a/apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/options/ListMetricsOptions.java b/apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/options/ListMetricsOptions.java index a86f64dc88..ff844546bc 100644 --- a/apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/options/ListMetricsOptions.java +++ b/apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/options/ListMetricsOptions.java @@ -18,12 +18,15 @@ */ package org.jclouds.cloudwatch.options; -import com.google.common.collect.Sets; +import java.util.Set; + import org.jclouds.cloudwatch.domain.Dimension; import org.jclouds.http.options.BaseHttpRequestOptions; -import org.jclouds.javax.annotation.Nullable; -import java.util.Set; +import com.google.common.collect.ImmutableMultimap; +import com.google.common.collect.Iterables; +import com.google.common.collect.Multimap; +import com.google.common.collect.Sets; /** * Options used to list available metrics. @@ -32,169 +35,148 @@ import java.util.Set; * * @author Jeremy Whitlock */ -public class ListMetricsOptions extends BaseHttpRequestOptions { +public class ListMetricsOptions extends BaseHttpRequestOptions implements Cloneable { - private final Set dimensions; - private final String metricName; - private final String namespace; - private final String nextToken; + private Set dimensions = Sets.newLinkedHashSet(); + private String metricName; + private String namespace; + private String nextToken; /** - * Private constructor to enforce using {@link Builder}. + * The namespace to filter against. + * + * @param namespace the namespace to filter against + * + * @return this {@code Builder} object */ - private ListMetricsOptions(@Nullable String namespace, @Nullable String metricName, - @Nullable Set dimensions, @Nullable String nextToken) { - this.dimensions = dimensions; - this.metricName = metricName; + public ListMetricsOptions namespace(String namespace) { this.namespace = namespace; + return this; + } + + /** + * The name of the metric to filter against. + * + * @param metricName the metric name to filter against + * + * @return this {@code Builder} object + */ + public ListMetricsOptions metricName(String metricName) { + this.metricName = metricName; + return this; + } + + /** + * A list of dimensions to filter against. + * + * @param dimensions the dimensions to filter against + * + * @return this {@code Builder} object + */ + public ListMetricsOptions dimensions(Iterable dimensions) { + Iterables.addAll(this.dimensions, dimensions); + return this; + } + + /** + * A dimension to filter the available metrics by. + * + * @param dimension a dimension to filter the returned metrics by + * + * @return this {@code Builder} object + */ + public ListMetricsOptions dimension(Dimension dimension) { + this.dimensions.add(dimension); + return this; + } + + /** + * The token returned by a previous call to indicate that there is more data available. + * + * @param nextToken the next token indicating that there is more data available + * + * @return this {@code Builder} object + */ + public ListMetricsOptions nextMarker(String nextToken) { this.nextToken = nextToken; + return this; } /** - * return the set of dimensions for this request + * Returns a newly-created {@code ListMetricsOptions} based on the contents of + * the {@code Builder}. */ - @Nullable - public Set getDimensions() { - return dimensions; - } + @Override + public Multimap buildFormParameters() { + ImmutableMultimap.Builder formParameters = ImmutableMultimap.builder(); + int dimensionIndex = 1; - /** - * return the metric name for this request - */ - @Nullable - public String getMetricName() { - return metricName; - } + // If namespace isn't specified, don't include it + if (namespace != null) { + formParameters.put("Namespace", namespace); + } + // If metricName isn't specified, don't include it + if (metricName != null) { + formParameters.put("MetricName", metricName); + } - /** - * return the namespace for this request - */ - @Nullable - public String getNamespace() { - return namespace; - } + // If dimensions isn't specified, don't include it + if (dimensions != null) { + for (Dimension dimension : dimensions) { + formParameters.put("Dimensions.member." + dimensionIndex + ".Name", dimension.getName()); + formParameters.put("Dimensions.member." + dimensionIndex + ".Value", dimension.getValue()); + dimensionIndex++; + } + } - /** - * return the next token for this request - */ - @Nullable - public String getNextToken() { - return nextToken; - } + // If nextToken isn't specified, don't include it + if (nextToken != null) { + formParameters.put("NextToken", nextToken); + } - /** - * Returns a new builder. The generated builder is equivalent to the builder - * created by the {@link Builder} constructor. - */ - public static Builder builder() { - return new Builder(); + return formParameters.build(); } - + + @Override + public ListMetricsOptions clone() { + return Builder.namespace(namespace).metricName(metricName).dimensions(dimensions).nextMarker(nextToken); + } + public static class Builder { - private Set dimensions = Sets.newLinkedHashSet(); - private String metricName; - private String namespace; - private String nextToken; - /** - * Creates a new builder. The returned builder is equivalent to the builder - * generated by {@link ListMetricsOptions#builder}. + * @see ListMetricsOptions#namespace(String) */ - public Builder() {} - - /** - * The namespace to filter against. - * - * @param namespace the namespace to filter against - * - * @return this {@code Builder} object - */ - public Builder namespace(String namespace) { - this.namespace = namespace; - return this; + public static ListMetricsOptions namespace(String namespace) { + return new ListMetricsOptions().namespace(namespace); } /** - * The name of the metric to filter against. - * - * @param metricName the metric name to filter against - * - * @return this {@code Builder} object + * @see ListMetricsOptions#metricName(String) */ - public Builder metricName(String metricName) { - this.metricName = metricName; - return this; + public static ListMetricsOptions metricName(String metricName) { + return new ListMetricsOptions().metricName(metricName); } /** - * A list of dimensions to filter against. - * - * @param dimensions the dimensions to filter against - * - * @return this {@code Builder} object + * @see ListMetricsOptions#dimensions(Iterable) */ - public Builder dimensions(Set dimensions) { - this.dimensions = dimensions; - return this; + public static ListMetricsOptions dimensions(Iterable dimensions) { + return new ListMetricsOptions().dimensions(dimensions); } /** - * A dimension to filter the available metrics by. - * - * @param dimension a dimension to filter the returned metrics by - * - * @return this {@code Builder} object + * @see ListMetricsOptions#dimension(String) */ - public Builder dimension(Dimension dimension) { - this.dimensions.add(dimension); - return this; + public static ListMetricsOptions dimension(Dimension dimension) { + return new ListMetricsOptions().dimension(dimension); } /** - * The token returned by a previous call to indicate that there is more data available. - * - * @param nextToken the next token indicating that there is more data available - * - * @return this {@code Builder} object + * @see ListMetricsOptions#nextMarker(String) */ - public Builder nextToken(String nextToken) { - this.nextToken = nextToken; - return this; - } - - /** - * Returns a newly-created {@code ListMetricsOptions} based on the contents of - * the {@code Builder}. - */ - public ListMetricsOptions build() { - ListMetricsOptions lmo = new ListMetricsOptions(namespace, metricName, dimensions, nextToken); - int dimensionIndex = 1; - - // If namespace isn't specified, don't include it - if (namespace != null) { - lmo.formParameters.put("Namespace", namespace); - } - // If metricName isn't specified, don't include it - if (metricName != null) { - lmo.formParameters.put("MetricName", metricName); - } - - // If dimensions isn't specified, don't include it - if (dimensions != null) { - for (Dimension dimension : dimensions) { - lmo.formParameters.put("Dimensions.member." + dimensionIndex + ".Name", dimension.getName()); - lmo.formParameters.put("Dimensions.member." + dimensionIndex + ".Value", dimension.getValue()); - dimensionIndex++; - } - } - - // If nextToken isn't specified, don't include it - if (nextToken != null) { - lmo.formParameters.put("NextToken", nextToken); - } - - return lmo; + public static ListMetricsOptions nextMarker(String nextToken) { + return new ListMetricsOptions().nextMarker(nextToken); } } diff --git a/apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/xml/ListMetricsResponseHandler.java b/apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/xml/ListMetricsResponseHandler.java index 7c55490efc..bd4df34ee0 100644 --- a/apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/xml/ListMetricsResponseHandler.java +++ b/apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/xml/ListMetricsResponseHandler.java @@ -18,23 +18,24 @@ */ package org.jclouds.cloudwatch.xml; -import com.google.common.collect.Sets; -import com.google.inject.Inject; -import org.jclouds.cloudwatch.domain.ListMetricsResponse; +import java.util.Set; + import org.jclouds.cloudwatch.domain.Metric; +import org.jclouds.collect.PaginatedSet; import org.jclouds.http.functions.ParseSax; import org.jclouds.util.SaxUtils; import org.xml.sax.Attributes; import org.xml.sax.SAXException; -import java.util.Set; +import com.google.common.collect.Sets; +import com.google.inject.Inject; /** * @see * * @author Jeremy Whitlock */ -public class ListMetricsResponseHandler extends ParseSax.HandlerForGeneratedRequestWithResult { +public class ListMetricsResponseHandler extends ParseSax.HandlerForGeneratedRequestWithResult> { private final MetricHandler metricHandler; @@ -52,8 +53,8 @@ public class ListMetricsResponseHandler extends ParseSax.HandlerForGeneratedRequ * {@inheritDoc} */ @Override - public ListMetricsResponse getResult() { - return new ListMetricsResponse(metrics, nextToken); + public PaginatedSet getResult() { + return PaginatedSet.copyOfWithMarker(metrics, nextToken); } /** diff --git a/apis/cloudwatch/src/test/java/org/jclouds/cloudwatch/CloudWatchLiveTest.java b/apis/cloudwatch/src/test/java/org/jclouds/cloudwatch/CloudWatchLiveTest.java index 4bd451e4ee..c306147913 100644 --- a/apis/cloudwatch/src/test/java/org/jclouds/cloudwatch/CloudWatchLiveTest.java +++ b/apis/cloudwatch/src/test/java/org/jclouds/cloudwatch/CloudWatchLiveTest.java @@ -67,7 +67,7 @@ public class CloudWatchLiveTest extends BaseContextLiveTest(new Predicate() { @Override public boolean apply(ListMetricsOptions options) { diff --git a/apis/cloudwatch/src/test/java/org/jclouds/cloudwatch/CloudWatchTest.java b/apis/cloudwatch/src/test/java/org/jclouds/cloudwatch/CloudWatchTest.java index d3bffb1d11..03ea4d1693 100644 --- a/apis/cloudwatch/src/test/java/org/jclouds/cloudwatch/CloudWatchTest.java +++ b/apis/cloudwatch/src/test/java/org/jclouds/cloudwatch/CloudWatchTest.java @@ -26,11 +26,11 @@ import java.util.List; import java.util.Set; import org.easymock.EasyMock; -import org.jclouds.cloudwatch.domain.ListMetricsResponse; import org.jclouds.cloudwatch.domain.Metric; import org.jclouds.cloudwatch.domain.MetricDatum; import org.jclouds.cloudwatch.features.MetricClient; import org.jclouds.cloudwatch.options.ListMetricsOptions; +import org.jclouds.collect.PaginatedSet; import org.testng.Assert; import org.testng.annotations.Test; @@ -56,14 +56,14 @@ public class CloudWatchTest { public void testSinglePageResult() throws Exception { CloudWatchClient client = createMock(CloudWatchClient.class); MetricClient metricClient = createMock(MetricClient.class); - ListMetricsOptions options = ListMetricsOptions.builder().build(); - ListMetricsResponse response = new ListMetricsResponse(ImmutableSet.of(createMock(Metric.class)), null); + ListMetricsOptions options = new ListMetricsOptions(); + PaginatedSet response = PaginatedSet.copyOfWithMarker(ImmutableSet.of(createMock(Metric.class)), null); expect(client.getMetricClientForRegion(null)) .andReturn(metricClient) .atLeastOnce(); - expect(metricClient.listMetrics(options)) + expect(metricClient.list(options)) .andReturn(response) .once(); @@ -82,19 +82,19 @@ public class CloudWatchTest { public void testMultiPageResult() throws Exception { CloudWatchClient client = createMock(CloudWatchClient.class); MetricClient metricClient = createMock(MetricClient.class); - ListMetricsOptions options = ListMetricsOptions.builder().build(); - ListMetricsResponse response1 = new ListMetricsResponse(ImmutableSet.of(createMock(Metric.class)), "NEXTTOKEN"); - ListMetricsResponse response2 = new ListMetricsResponse(ImmutableSet.of(createMock(Metric.class)), null); + ListMetricsOptions options = new ListMetricsOptions(); + PaginatedSet response1 = PaginatedSet.copyOfWithMarker(ImmutableSet.of(createMock(Metric.class)), "NEXTTOKEN"); + PaginatedSet response2 = PaginatedSet.copyOfWithMarker(ImmutableSet.of(createMock(Metric.class)), null); // Using EasyMock.eq("") because EasyMock makes it impossible to pass null as a String value here expect(client.getMetricClientForRegion(EasyMock.eq(""))) .andReturn(metricClient) .atLeastOnce(); - expect(metricClient.listMetrics(anyObject(ListMetricsOptions.class))) + expect(metricClient.list(anyObject(ListMetricsOptions.class))) .andReturn(response1) .once(); - expect(metricClient.listMetrics(anyObject(ListMetricsOptions.class))) + expect(metricClient.list(anyObject(ListMetricsOptions.class))) .andReturn(response2) .once(); @@ -126,7 +126,7 @@ public class CloudWatchTest { .atLeastOnce(); for (List slice : Iterables.partition(metrics, 10)) { - metricClient.putMetricData(slice, namespace); + metricClient.putMetricsInNamespace(slice, namespace); } EasyMock.replay(client, metricClient); diff --git a/apis/cloudwatch/src/test/java/org/jclouds/cloudwatch/features/MetricClientExpectTest.java b/apis/cloudwatch/src/test/java/org/jclouds/cloudwatch/features/MetricClientExpectTest.java index a25271c58f..76ebd79484 100644 --- a/apis/cloudwatch/src/test/java/org/jclouds/cloudwatch/features/MetricClientExpectTest.java +++ b/apis/cloudwatch/src/test/java/org/jclouds/cloudwatch/features/MetricClientExpectTest.java @@ -18,7 +18,12 @@ */ package org.jclouds.cloudwatch.features; -import com.google.common.collect.ImmutableMultimap; +import static org.testng.Assert.assertEquals; + +import java.net.URI; +import java.util.Date; +import java.util.TimeZone; + import org.jclouds.cloudwatch.CloudWatchClient; import org.jclouds.cloudwatch.domain.Dimension; import org.jclouds.cloudwatch.domain.EC2Constants; @@ -34,11 +39,7 @@ import org.jclouds.http.HttpResponse; import org.jclouds.rest.ResourceNotFoundException; import org.testng.annotations.Test; -import java.net.URI; -import java.util.Date; -import java.util.TimeZone; - -import static org.testng.Assert.assertEquals; +import com.google.common.collect.ImmutableMultimap; /** * @author Jeremy Whitlock, Adrian Cole @@ -76,9 +77,8 @@ public class MetricClientExpectTest extends BaseCloudWatchClientExpectTest { CloudWatchClient clientWhenMetricsExist = requestSendsResponse( listMetrics, listMetricsResponse); - assertEquals(clientWhenMetricsExist.getMetricClientForRegion(null).listMetrics().toString(), - "ListMetricsResponse{metrics=[Metric{namespace=AWS/EC2, metricName=CPUUtilization, " + - "dimension=[Dimension{name=InstanceId, value=i-689fcf0f}]}], nextToken=null}"); + assertEquals(clientWhenMetricsExist.getMetricClientForRegion(null).list().toString(), + "PaginatedSet{contents=[Metric{namespace=AWS/EC2, metricName=CPUUtilization, dimension=[Dimension{name=InstanceId, value=i-689fcf0f}]}], marker=null}"); } // TODO: this should really be an empty set @@ -90,7 +90,7 @@ public class MetricClientExpectTest extends BaseCloudWatchClientExpectTest { CloudWatchClient clientWhenMetricsDontExist = requestSendsResponse( listMetrics, listMetricsResponse); - clientWhenMetricsDontExist.getMetricClientForRegion(null).listMetrics(); + clientWhenMetricsDontExist.getMetricClientForRegion(null).list(); } public void testListMetricsWithOptionsWhenResponseIs2xx() throws Exception { @@ -124,16 +124,14 @@ public class MetricClientExpectTest extends BaseCloudWatchClientExpectTest { listMetricsWithOptionsResponse); assertEquals( - clientWhenMetricsWithOptionsExist.getMetricClientForRegion(null).listMetrics( - ListMetricsOptions.builder() + clientWhenMetricsWithOptionsExist.getMetricClientForRegion(null).list( + ListMetricsOptions.Builder .dimension(new Dimension(EC2Constants.Dimension.INSTANCE_ID, "SOMEINSTANCEID")) .metricName(EC2Constants.MetricName.CPU_UTILIZATION) .namespace("SOMENEXTTOKEN") - .nextToken( Namespaces.EC2) - .build()).toString(), - "ListMetricsResponse{metrics=[Metric{namespace=AWS/EC2, metricName=CPUUtilization, " + - "dimension=[Dimension{name=InstanceId, value=i-689fcf0f}]}], nextToken=null}"); + .nextMarker(Namespaces.EC2)).toString(), + "PaginatedSet{contents=[Metric{namespace=AWS/EC2, metricName=CPUUtilization, dimension=[Dimension{name=InstanceId, value=i-689fcf0f}]}], marker=null}"); } GetMetricStatistics stats = GetMetricStatistics.builder() diff --git a/apis/cloudwatch/src/test/java/org/jclouds/cloudwatch/features/MetricClientLiveTest.java b/apis/cloudwatch/src/test/java/org/jclouds/cloudwatch/features/MetricClientLiveTest.java index 9f91fbf94d..5dc2dcb90d 100644 --- a/apis/cloudwatch/src/test/java/org/jclouds/cloudwatch/features/MetricClientLiveTest.java +++ b/apis/cloudwatch/src/test/java/org/jclouds/cloudwatch/features/MetricClientLiveTest.java @@ -31,7 +31,6 @@ import org.jclouds.cloudwatch.domain.Dimension; import org.jclouds.cloudwatch.domain.EC2Constants; import org.jclouds.cloudwatch.domain.GetMetricStatistics; import org.jclouds.cloudwatch.domain.GetMetricStatisticsResponse; -import org.jclouds.cloudwatch.domain.ListMetricsResponse; import org.jclouds.cloudwatch.domain.Metric; import org.jclouds.cloudwatch.domain.MetricDatum; import org.jclouds.cloudwatch.domain.Namespaces; @@ -40,6 +39,7 @@ import org.jclouds.cloudwatch.domain.Statistics; import org.jclouds.cloudwatch.domain.Unit; import org.jclouds.cloudwatch.internal.BaseCloudWatchClientLiveTest; import org.jclouds.cloudwatch.options.ListMetricsOptions; +import org.jclouds.collect.PaginatedSet; import org.jclouds.predicates.RetryablePredicate; import org.testng.Assert; import org.testng.annotations.Test; @@ -84,15 +84,14 @@ public class MetricClientLiveTest extends BaseCloudWatchClientLiveTest { .value(10.0) .build(); - client().putMetricData(ImmutableSet.of(metricDatum, metricDatum2), namespace); + client().putMetricsInNamespace(ImmutableSet.of(metricDatum, metricDatum2), namespace); - ListMetricsOptions lmo = ListMetricsOptions.builder().namespace(namespace) - .dimension(new Dimension("BaseMetricName", metricName)) - .build(); + ListMetricsOptions lmo = ListMetricsOptions.Builder.namespace(namespace) + .dimension(new Dimension("BaseMetricName", metricName)); boolean success = new RetryablePredicate(new Predicate() { @Override public boolean apply(ListMetricsOptions options) { - return Iterables.size(client().listMetrics(options)) == 2; + return Iterables.size(client().list(options)) == 2; } }, 20, 1, TimeUnit.MINUTES).apply(lmo); @@ -100,7 +99,7 @@ public class MetricClientLiveTest extends BaseCloudWatchClientLiveTest { Assert.fail("Unable to gather the created CloudWatch data within the time (20m) allotted."); } - ListMetricsResponse lmr = client().listMetrics(lmo); + PaginatedSet lmr = client().list(lmo); Date endTime = new Date(metricTimestampInCloudWatch.getTime() + (60 * 1000)); // Pad a minute just in case Date startTime = new Date(metricTimestampInCloudWatch.getTime() - (60 * 1000)); // Pad a minute just in case @@ -146,7 +145,7 @@ public class MetricClientLiveTest extends BaseCloudWatchClientLiveTest { // TODO: change this test to retrieve pre-seeded custom metrics @Test protected void testGetMetricStatistics() { - ListMetricsResponse metricsResponse = client().listMetrics(); + PaginatedSet metricsResponse = client().list(); // Walk through all datapoints in all metrics until we find a metric datapoint that returns statistics if (metricsResponse.size() > 0) { @@ -196,14 +195,14 @@ public class MetricClientLiveTest extends BaseCloudWatchClientLiveTest { @Test protected void testListMetrics() { - ListMetricsResponse response; + PaginatedSet response; String testNamespace = Namespaces.EC2; String testMetricName = EC2Constants.MetricName.CPU_UTILIZATION; String testDimensionName = EC2Constants.Dimension.INSTANCE_TYPE; String testDimensionValue = "t1.micro"; // Test an empty request (pulls all stored metric options across all products) - response = client().listMetrics(); + response = client().list(); performDefaultMetricsTests(response); @@ -237,12 +236,12 @@ public class MetricClientLiveTest extends BaseCloudWatchClientLiveTest { } // Test with a NextToken, even if it's null - response = client().listMetrics(ListMetricsOptions.builder().nextToken(response.getNextToken()).build()); + response = client().list(ListMetricsOptions.Builder.nextMarker(response.getNextMarker())); performDefaultMetricsTests(response); // Test with a Namespace - response = client().listMetrics(ListMetricsOptions.builder().namespace(testNamespace).build()); + response = client().list(ListMetricsOptions.Builder.namespace(testNamespace)); performDefaultMetricsTests(response); @@ -252,7 +251,7 @@ public class MetricClientLiveTest extends BaseCloudWatchClientLiveTest { } // Test with a MetricName - response = client().listMetrics(ListMetricsOptions.builder().metricName(testMetricName).build()); + response = client().list(ListMetricsOptions.Builder.metricName(testMetricName)); performDefaultMetricsTests(response); @@ -265,7 +264,7 @@ public class MetricClientLiveTest extends BaseCloudWatchClientLiveTest { if (testDimensionName != null) { Dimension testDimension = new Dimension(testDimensionName, testDimensionValue); - response = client().listMetrics(ListMetricsOptions.builder().dimension(testDimension).build()); + response = client().list(ListMetricsOptions.Builder.dimension(testDimension)); performDefaultMetricsTests(response); @@ -282,10 +281,10 @@ public class MetricClientLiveTest extends BaseCloudWatchClientLiveTest { } } - private void performDefaultMetricsTests(ListMetricsResponse response) { + private void performDefaultMetricsTests(PaginatedSet response) { // If there are less than 500 metrics, NextToken should be null if (response.size() < 500) { - checkArgument(response.getNextToken() == null, + checkArgument(response.getNextMarker() == null, "NextToken should be null for response with fewer than 500 metrics."); }