From b15db1357405d8bff9c8b470071058fa39ea4118 Mon Sep 17 00:00:00 2001 From: andreisavu Date: Mon, 19 Dec 2011 13:25:06 +0200 Subject: [PATCH] Updated CloudWatchClient code to latest version See http://docs.amazonwebservices.com/AmazonCloudWatch/latest/APIReference/i ndex.html?API_GetMetricStatistics.html --- .../jclouds/cloudwatch/CloudWatchAsyncClient.java | 5 +++-- .../org/jclouds/cloudwatch/CloudWatchClient.java | 8 +++++--- .../jclouds/cloudwatch/CloudWatchClientLiveTest.java | 12 ++++++------ .../aws/cloudwatch/AWSCloudWatchClientLiveTest.java | 2 +- .../ec2/compute/AWSEC2ComputeServiceLiveTest.java | 5 +++-- 5 files changed, 18 insertions(+), 14 deletions(-) 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 7d9e54c01c..915809f1e5 100644 --- a/apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/CloudWatchAsyncClient.java +++ b/apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/CloudWatchAsyncClient.java @@ -53,7 +53,7 @@ import com.google.common.util.concurrent.ListenableFuture; @FormParams(keys = "Version", values = CloudWatchAsyncClient.VERSION) @VirtualHost public interface CloudWatchAsyncClient { - public static final String VERSION = "2009-05-15"; + public static final String VERSION = "2010-08-01"; /** * @see CloudWatchClient#getMetricStatisticsInRegion @@ -64,7 +64,8 @@ public interface CloudWatchAsyncClient { @FormParams(keys = "Action", values = "GetMetricStatistics") ListenableFuture> getMetricStatisticsInRegion( @EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region, - @FormParam("MeasureName") String measureName, + @FormParam("MetricName") String metricName, + @FormParam("Namespace") String namespace, @FormParam("StartTime") @ParamParser(ISO8601Format.class) Date startTime, @FormParam("EndTime") @ParamParser(ISO8601Format.class) Date endTime, @FormParam("Period") int period, @FormParam("Statistics.member.1") String statistics); 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 276bcef2d7..e39b54af39 100644 --- a/apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/CloudWatchClient.java +++ b/apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/CloudWatchClient.java @@ -51,13 +51,15 @@ public interface CloudWatchClient { * * @param region * region to gather metrics in - * @param measureName + * @param metricName * The measure name that corresponds to the measure for the gathered metric. *

* note *

* Must be a valid collected metric with the corresponding measure name, please see * Available Amazon CloudWatch Metrics + * @param namespace + * The namespace of the metric (e.g. AWS/EC2) * @param startTime * The timestamp of the first datapoint to return, inclusive. We round your value down * to the nearest minute. You can set your start time for more than two weeks in the @@ -70,7 +72,7 @@ public interface CloudWatchClient { * @param statistics * The statistics to be returned for the given metric. ex. Average */ - Set getMetricStatisticsInRegion(@Nullable String region, String measureName, Date startTime, - Date endTime, int period, String statistics); + Set getMetricStatisticsInRegion(@Nullable String region, String metricName, String namespace, + Date startTime, Date endTime, int period, String statistics); } diff --git a/apis/cloudwatch/src/test/java/org/jclouds/cloudwatch/CloudWatchClientLiveTest.java b/apis/cloudwatch/src/test/java/org/jclouds/cloudwatch/CloudWatchClientLiveTest.java index 1876f31920..cf6ead4030 100644 --- a/apis/cloudwatch/src/test/java/org/jclouds/cloudwatch/CloudWatchClientLiveTest.java +++ b/apis/cloudwatch/src/test/java/org/jclouds/cloudwatch/CloudWatchClientLiveTest.java @@ -27,7 +27,6 @@ import java.util.Set; import org.jclouds.Constants; import org.jclouds.cloudwatch.domain.Datapoint; -import org.jclouds.logging.Logger; import org.jclouds.logging.log4j.config.Log4JLoggingModule; import org.jclouds.rest.RestContext; import org.jclouds.rest.RestContextFactory; @@ -86,16 +85,17 @@ public class CloudWatchClientLiveTest { @Test protected void testGetMetricStatisticsInRegion() { - getMetricStatisticsInRegion(null); + getEC2MetricStatisticsInRegion(null); } - protected void getMetricStatisticsInRegion(String region) { + protected Set getEC2MetricStatisticsInRegion(String region) { Calendar cal = Calendar.getInstance(); - cal.add(Calendar.MINUTE, -1); + cal.add(Calendar.MINUTE, -60 * 24 * 3); // 3 days Set datapoints = client.getMetricStatisticsInRegion( - region, "CPUUtilization", cal.getTime(), new Date(), 60, "Average"); - assert datapoints != null; + region, "CPUUtilization", "AWS/EC2", cal.getTime(), new Date(), 180, "Average"); + + return checkNotNull(datapoints, "Got null response for EC2 datapoints in region "); } @AfterTest diff --git a/providers/aws-cloudwatch/src/test/java/org/jclouds/aws/cloudwatch/AWSCloudWatchClientLiveTest.java b/providers/aws-cloudwatch/src/test/java/org/jclouds/aws/cloudwatch/AWSCloudWatchClientLiveTest.java index e494ad5403..5c98f38833 100644 --- a/providers/aws-cloudwatch/src/test/java/org/jclouds/aws/cloudwatch/AWSCloudWatchClientLiveTest.java +++ b/providers/aws-cloudwatch/src/test/java/org/jclouds/aws/cloudwatch/AWSCloudWatchClientLiveTest.java @@ -36,7 +36,7 @@ public class AWSCloudWatchClientLiveTest extends CloudWatchClientLiveTest { @Test public void testGetMetricStatisticsInRegion() { for (String region : Region.DEFAULT_REGIONS) { - getMetricStatisticsInRegion(region); + getEC2MetricStatisticsInRegion(region); } } } diff --git a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/compute/AWSEC2ComputeServiceLiveTest.java b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/compute/AWSEC2ComputeServiceLiveTest.java index 9b10835a50..8558c8d2c6 100644 --- a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/compute/AWSEC2ComputeServiceLiveTest.java +++ b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/compute/AWSEC2ComputeServiceLiveTest.java @@ -155,8 +155,9 @@ public class AWSEC2ComputeServiceLiveTest extends EC2ComputeServiceLiveTest { try { Set datapoints = monitoringContext.getApi().getMetricStatisticsInRegion(instance.getRegion(), - "CPUUtilization", before, new Date(), 60, "Average"); - assert datapoints != null; + "CPUUtilization", "AWS/EC2", before, new Date(), 60, "Average"); + assert datapoints != null && datapoints.size() > 0; + } finally { monitoringContext.close(); }