From f6c606e631d325bd39297140d1c535b46041ec79 Mon Sep 17 00:00:00 2001 From: Jason King Date: Thu, 8 Dec 2011 12:01:09 +0000 Subject: [PATCH] Issue 695: Refactored getDailyCpuPerformanceStatistics into getPerformanceStatistics as it works for daily/hourly+memory/cpu --- .../features/ResourceAsyncClient.java | 4 +-- .../features/ResourceClient.java | 32 ++++++++++++------- .../features/ResourceAsyncClientTest.java | 4 +-- .../features/ResourceClientLiveTest.java | 14 ++++++-- .../PerformanceStatisticsJAXBParsingTest.java | 2 +- 5 files changed, 38 insertions(+), 18 deletions(-) diff --git a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/features/ResourceAsyncClient.java b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/features/ResourceAsyncClient.java index 7b81ae0f20..7d14e5aec2 100644 --- a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/features/ResourceAsyncClient.java +++ b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/features/ResourceAsyncClient.java @@ -123,11 +123,11 @@ public interface ResourceAsyncClient { ListenableFuture getComputePoolPerformanceStatistics(@EndpointParam URI uri); /** - * @see ResourceClient#getDailyCpuPerformanceStatistics + * @see ResourceClient#getPerformanceStatistics */ @GET @Consumes("application/vnd.tmrk.cloud.performanceStatistics") @JAXBResponseParser @ExceptionParser(ReturnNullOnNotFoundOr404.class) - ListenableFuture getDailyCpuPerformanceStatistics(@EndpointParam URI uri); + ListenableFuture getPerformanceStatistics(@EndpointParam URI uri); } diff --git a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/features/ResourceClient.java b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/features/ResourceClient.java index 339673e34d..70001108e9 100644 --- a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/features/ResourceClient.java +++ b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/features/ResourceClient.java @@ -155,18 +155,28 @@ public interface ResourceClient { ComputePoolPerformanceStatistics getComputePoolPerformanceStatistics(URI uri); /** - * The Get Resources Performance Statistics Processor Daily call returns daily - * information regarding processor performance for a specified compute pool + * The getPerformanceStatistics call returns information regarding performance for a specified compute pool. + * There are 2 time periods available: daily and hourly + * There is information for cpu (processor) and memory. + * To determine the correct URI to use, first call {@code getComputePoolPerformanceStatistics} + * then select the desired statistic from the result (e.g. hourly or daily then cpu or memory) * - * returns statistics for the previous seven days. + * Daily statistics return results for the previous seven days. * - * The default endTime is midnight the beginning of the current day and the default - * startTime is midnight seven days prior to the endTime. - * For example, if the call is made at 2011-07-12T14:48:00Z, then startTime is 2011-07-05T00:00:00Z - * and endTime is 2011-07-12T00:00:00Z. - * @param uri uri the uri of the call based upon the compute pool - * e.g. /cloudapi/ecloud/computepools/{id}/usage/cpu/performanceStatistics/daily - * @return + * The default endTime is midnight the beginning of the current day + * and the default startTime is midnight seven days prior to the endTime. + * For example, if the call is made at 2011-07-12T14:48:00Z, + * then startTime is 2011-07-05T00:00:00Z and endTime is 2011-07-12T00:00:00Z. + * + * Hourly statistics return results for the previous 24 hours + * + * The default endTime is the end of the hour prior to the current time + * and the default startTime is the beginning of the hour 24 hours prior to the endTime. + * For example, if the call is made at 2011-07- 12T14:48:00Z, + * then startTime is 2011-07-11T13:00:00Z and endTime is 2011-07-12T14:00:00Z. + * + * @param uri uri the uri of the call. + * @return the performance statistics for the desired period and metric */ - PerformanceStatistics getDailyCpuPerformanceStatistics(URI uri); + PerformanceStatistics getPerformanceStatistics(URI uri); } diff --git a/sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/features/ResourceAsyncClientTest.java b/sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/features/ResourceAsyncClientTest.java index 60cc292aaf..bcc8c5e4f4 100644 --- a/sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/features/ResourceAsyncClientTest.java +++ b/sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/features/ResourceAsyncClientTest.java @@ -158,8 +158,8 @@ public class ResourceAsyncClientTest extends BaseTerremarkEnterpriseCloudAsyncCl checkFilters(httpRequest); } - public void testGetDailyCpuPerformanceStatistics() throws SecurityException, NoSuchMethodException, IOException, URISyntaxException { - Method method = ResourceAsyncClient.class.getMethod("getDailyCpuPerformanceStatistics", URI.class); + public void testGetPerformanceStatistics() throws SecurityException, NoSuchMethodException, IOException, URISyntaxException { + Method method = ResourceAsyncClient.class.getMethod("getPerformanceStatistics", URI.class); HttpRequest httpRequest = processor.createRequest(method, URI.create("/cloudapi/ecloud/computepools/89/usage/cpu/performancestatistics/daily")); assertRequestLineEquals(httpRequest, "GET https://services-beta.enterprisecloud.terremark.com/cloudapi/ecloud/computepools/89/usage/cpu/performancestatistics/daily HTTP/1.1"); diff --git a/sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/features/ResourceClientLiveTest.java b/sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/features/ResourceClientLiveTest.java index b2dc7fb8f1..7fce663e71 100644 --- a/sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/features/ResourceClientLiveTest.java +++ b/sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/features/ResourceClientLiveTest.java @@ -20,6 +20,7 @@ package org.jclouds.tmrk.enterprisecloud.features; import org.jclouds.tmrk.enterprisecloud.domain.Link; import org.jclouds.tmrk.enterprisecloud.domain.internal.ResourceCapacity; +import org.jclouds.tmrk.enterprisecloud.domain.resource.ComputePoolPerformanceStatistics; import org.jclouds.tmrk.enterprisecloud.domain.resource.PerformanceStatistics; import org.jclouds.tmrk.enterprisecloud.domain.resource.cpu.ComputePoolCpuUsage; import org.jclouds.tmrk.enterprisecloud.domain.resource.ComputePoolResourceSummary; @@ -122,8 +123,17 @@ public class ResourceClientLiveTest extends BaseTerremarkEnterpriseCloudClientLi assertNotNull(usage); } - public void testGetDailyCpuPerformanceStatistics() throws Exception { - PerformanceStatistics stats = client.getDailyCpuPerformanceStatistics(URI.create("/cloudapi/ecloud/computepools/89/usage/cpu/performancestatistics/daily")); + public void testGetPerformanceStatistics() throws Exception { + ComputePoolPerformanceStatistics statistics = client.getComputePoolPerformanceStatistics(URI.create("/cloudapi/ecloud/computepools/89/performancestatistics")); + assertNotNull(statistics); + testPerformanceStatistic(statistics.getDaily().getCpu().getHref()); + testPerformanceStatistic(statistics.getDaily().getMemory().getHref()); + testPerformanceStatistic(statistics.getHourly().getCpu().getHref()); + testPerformanceStatistic(statistics.getHourly().getMemory().getHref()); + } + + private void testPerformanceStatistic(URI uri) { + PerformanceStatistics stats = client.getPerformanceStatistics(uri); assertNotNull(stats); } } \ No newline at end of file diff --git a/sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/xml/PerformanceStatisticsJAXBParsingTest.java b/sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/xml/PerformanceStatisticsJAXBParsingTest.java index 0893aaaf61..ec097fc601 100644 --- a/sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/xml/PerformanceStatisticsJAXBParsingTest.java +++ b/sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/xml/PerformanceStatisticsJAXBParsingTest.java @@ -95,7 +95,7 @@ public class PerformanceStatisticsJAXBParsingTest extends BaseRestClientTest { public void testParseWithJAXB() throws Exception { - Method method = ResourceAsyncClient.class.getMethod("getDailyCpuPerformanceStatistics", URI.class); + Method method = ResourceAsyncClient.class.getMethod("getPerformanceStatistics", URI.class); HttpRequest request = factory(ResourceAsyncClient.class).createRequest(method,new URI("/1")); assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class);