mirror of https://github.com/apache/jclouds.git
Merge pull request #261 from andreisavu/cloudwatch-update
Updated CloudWatchClient code to latest version
This commit is contained in:
commit
a7359a25e7
|
@ -53,7 +53,7 @@ import com.google.common.util.concurrent.ListenableFuture;
|
||||||
@FormParams(keys = "Version", values = CloudWatchAsyncClient.VERSION)
|
@FormParams(keys = "Version", values = CloudWatchAsyncClient.VERSION)
|
||||||
@VirtualHost
|
@VirtualHost
|
||||||
public interface CloudWatchAsyncClient {
|
public interface CloudWatchAsyncClient {
|
||||||
public static final String VERSION = "2009-05-15";
|
public static final String VERSION = "2010-08-01";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see CloudWatchClient#getMetricStatisticsInRegion
|
* @see CloudWatchClient#getMetricStatisticsInRegion
|
||||||
|
@ -64,7 +64,8 @@ public interface CloudWatchAsyncClient {
|
||||||
@FormParams(keys = "Action", values = "GetMetricStatistics")
|
@FormParams(keys = "Action", values = "GetMetricStatistics")
|
||||||
ListenableFuture<? extends Set<Datapoint>> getMetricStatisticsInRegion(
|
ListenableFuture<? extends Set<Datapoint>> getMetricStatisticsInRegion(
|
||||||
@EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region,
|
@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("StartTime") @ParamParser(ISO8601Format.class) Date startTime,
|
||||||
@FormParam("EndTime") @ParamParser(ISO8601Format.class) Date endTime, @FormParam("Period") int period,
|
@FormParam("EndTime") @ParamParser(ISO8601Format.class) Date endTime, @FormParam("Period") int period,
|
||||||
@FormParam("Statistics.member.1") String statistics);
|
@FormParam("Statistics.member.1") String statistics);
|
||||||
|
|
|
@ -51,13 +51,15 @@ public interface CloudWatchClient {
|
||||||
*
|
*
|
||||||
* @param region
|
* @param region
|
||||||
* region to gather metrics in
|
* region to gather metrics in
|
||||||
* @param measureName
|
* @param metricName
|
||||||
* The measure name that corresponds to the measure for the gathered metric.
|
* The measure name that corresponds to the measure for the gathered metric.
|
||||||
* <p/>
|
* <p/>
|
||||||
* note
|
* note
|
||||||
* <p/>
|
* <p/>
|
||||||
* Must be a valid collected metric with the corresponding measure name, please see
|
* Must be a valid collected metric with the corresponding measure name, please see
|
||||||
* Available Amazon CloudWatch Metrics
|
* Available Amazon CloudWatch Metrics
|
||||||
|
* @param namespace
|
||||||
|
* The namespace of the metric (e.g. AWS/EC2)
|
||||||
* @param startTime
|
* @param startTime
|
||||||
* The timestamp of the first datapoint to return, inclusive. We round your value down
|
* 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
|
* 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
|
* @param statistics
|
||||||
* The statistics to be returned for the given metric. ex. Average
|
* The statistics to be returned for the given metric. ex. Average
|
||||||
*/
|
*/
|
||||||
Set<Datapoint> getMetricStatisticsInRegion(@Nullable String region, String measureName, Date startTime,
|
Set<Datapoint> getMetricStatisticsInRegion(@Nullable String region, String metricName, String namespace,
|
||||||
Date endTime, int period, String statistics);
|
Date startTime, Date endTime, int period, String statistics);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,21 +62,21 @@ public class CloudWatchAsyncClientTest extends RestClientTest<CloudWatchAsyncCli
|
||||||
public void testRegisterInstancesWithMeasure() throws SecurityException, NoSuchMethodException, IOException {
|
public void testRegisterInstancesWithMeasure() throws SecurityException, NoSuchMethodException, IOException {
|
||||||
Date date = new Date(10000000l);
|
Date date = new Date(10000000l);
|
||||||
Method method = CloudWatchAsyncClient.class.getMethod("getMetricStatisticsInRegion", String.class, String.class,
|
Method method = CloudWatchAsyncClient.class.getMethod("getMetricStatisticsInRegion", String.class, String.class,
|
||||||
Date.class, Date.class, int.class, String.class);
|
String.class, Date.class, Date.class, int.class, String.class);
|
||||||
HttpRequest request = processor.createRequest(method, (String) null, "CPUUtilization", date, date, 60, "Average");
|
HttpRequest request = processor.createRequest(method, (String) null, "CPUUtilization", "AWS/EC2", date, date, 60, "Average");
|
||||||
|
|
||||||
assertRequestLineEquals(request, "POST https://monitoring.us-east-1.amazonaws.com/ HTTP/1.1");
|
assertRequestLineEquals(request, "POST https://monitoring.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||||
assertNonPayloadHeadersEqual(request, "Host: monitoring.us-east-1.amazonaws.com\n");
|
assertNonPayloadHeadersEqual(request, "Host: monitoring.us-east-1.amazonaws.com\n");
|
||||||
try {
|
try {
|
||||||
assertPayloadEquals(
|
assertPayloadEquals(
|
||||||
request,
|
request,
|
||||||
"Version=2009-05-15&Action=GetMetricStatistics&Statistics.member.1=Average&StartTime=1970-01-01T02%3A46%3A40Z&MeasureName=CPUUtilization&EndTime=1970-01-01T02%3A46%3A40Z&Period=60",
|
"Version=2010-08-01&Action=GetMetricStatistics&Statistics.member.1=Average&StartTime=1970-01-01T02%3A46%3A40Z&Namespace=AWS%2FEC2&&MetricName=CPUUtilization&EndTime=1970-01-01T02%3A46%3A40Z&Period=60",
|
||||||
"application/x-www-form-urlencoded", false);
|
"application/x-www-form-urlencoded", false);
|
||||||
} catch (AssertionError e) {
|
} catch (AssertionError e) {
|
||||||
// mvn 3.0 osx 10.6.5 somehow sorts differently
|
// mvn 3.0 osx 10.6.5 somehow sorts differently
|
||||||
assertPayloadEquals(
|
assertPayloadEquals(
|
||||||
request,
|
request,
|
||||||
"Version=2009-05-15&Action=GetMetricStatistics&Statistics.member.1=Average&StartTime=1970-01-01T02%3A46%3A40Z&MeasureName=CPUUtilization&Period=60&EndTime=1970-01-01T02%3A46%3A40Z",
|
"Version=2010-08-01&Action=GetMetricStatistics&Statistics.member.1=Average&Period=60&Namespace=AWS%2FEC2&MetricName=CPUUtilization&StartTime=1970-01-01T02%3A46%3A40Z&EndTime=1970-01-01T02%3A46%3A40Z",
|
||||||
"application/x-www-form-urlencoded", false);
|
"application/x-www-form-urlencoded", false);
|
||||||
}
|
}
|
||||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||||
|
|
|
@ -27,7 +27,6 @@ import java.util.Set;
|
||||||
|
|
||||||
import org.jclouds.Constants;
|
import org.jclouds.Constants;
|
||||||
import org.jclouds.cloudwatch.domain.Datapoint;
|
import org.jclouds.cloudwatch.domain.Datapoint;
|
||||||
import org.jclouds.logging.Logger;
|
|
||||||
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
|
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
|
||||||
import org.jclouds.rest.RestContext;
|
import org.jclouds.rest.RestContext;
|
||||||
import org.jclouds.rest.RestContextFactory;
|
import org.jclouds.rest.RestContextFactory;
|
||||||
|
@ -86,16 +85,17 @@ public class CloudWatchClientLiveTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
protected void testGetMetricStatisticsInRegion() {
|
protected void testGetMetricStatisticsInRegion() {
|
||||||
getMetricStatisticsInRegion(null);
|
getEC2MetricStatisticsInRegion(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void getMetricStatisticsInRegion(String region) {
|
protected Set<Datapoint> getEC2MetricStatisticsInRegion(String region) {
|
||||||
Calendar cal = Calendar.getInstance();
|
Calendar cal = Calendar.getInstance();
|
||||||
cal.add(Calendar.MINUTE, -1);
|
cal.add(Calendar.MINUTE, -60 * 24 * 3); // 3 days
|
||||||
|
|
||||||
Set<Datapoint> datapoints = client.getMetricStatisticsInRegion(
|
Set<Datapoint> datapoints = client.getMetricStatisticsInRegion(
|
||||||
region, "CPUUtilization", cal.getTime(), new Date(), 60, "Average");
|
region, "CPUUtilization", "AWS/EC2", cal.getTime(), new Date(), 180, "Average");
|
||||||
assert datapoints != null;
|
|
||||||
|
return checkNotNull(datapoints, "Got null response for EC2 datapoints in region ");
|
||||||
}
|
}
|
||||||
|
|
||||||
@AfterTest
|
@AfterTest
|
||||||
|
|
|
@ -36,7 +36,7 @@ public class AWSCloudWatchClientLiveTest extends CloudWatchClientLiveTest {
|
||||||
@Test
|
@Test
|
||||||
public void testGetMetricStatisticsInRegion() {
|
public void testGetMetricStatisticsInRegion() {
|
||||||
for (String region : Region.DEFAULT_REGIONS) {
|
for (String region : Region.DEFAULT_REGIONS) {
|
||||||
getMetricStatisticsInRegion(region);
|
getEC2MetricStatisticsInRegion(region);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -155,8 +155,9 @@ public class AWSEC2ComputeServiceLiveTest extends EC2ComputeServiceLiveTest {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Set<Datapoint> datapoints = monitoringContext.getApi().getMetricStatisticsInRegion(instance.getRegion(),
|
Set<Datapoint> datapoints = monitoringContext.getApi().getMetricStatisticsInRegion(instance.getRegion(),
|
||||||
"CPUUtilization", before, new Date(), 60, "Average");
|
"CPUUtilization", "AWS/EC2", before, new Date(), 60, "Average");
|
||||||
assert datapoints != null;
|
assert datapoints != null && datapoints.size() > 0;
|
||||||
|
|
||||||
} finally {
|
} finally {
|
||||||
monitoringContext.close();
|
monitoringContext.close();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue