From f6c606e631d325bd39297140d1c535b46041ec79 Mon Sep 17 00:00:00 2001 From: Jason King Date: Thu, 8 Dec 2011 12:01:09 +0000 Subject: [PATCH 1/3] 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); From 98e2702e0455aa621887efbfef9dc0e23ec617fb Mon Sep 17 00:00:00 2001 From: Jason King Date: Thu, 8 Dec 2011 17:05:15 +0000 Subject: [PATCH 2/3] Issue 695: Implemented getPerformanceStatistics for a date range --- .../binders/BindDateToQueryParam.java | 55 ++++++++++++++ .../binders/BindEndTimeQueryParam.java | 36 +++++++++ .../binders/BindStartTimeQueryParam.java | 36 +++++++++ .../features/ResourceAsyncClient.java | 6 +- .../features/ResourceClient.java | 37 ++++++++- .../binders/BindDateToQueryParamTest.java | 76 +++++++++++++++++++ .../features/ResourceAsyncClientTest.java | 35 ++++++++- .../features/ResourceClientLiveTest.java | 35 +++++++-- .../PerformanceStatisticsJAXBParsingTest.java | 5 +- 9 files changed, 306 insertions(+), 15 deletions(-) create mode 100644 sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/binders/BindDateToQueryParam.java create mode 100644 sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/binders/BindEndTimeQueryParam.java create mode 100644 sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/binders/BindStartTimeQueryParam.java create mode 100644 sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/binders/BindDateToQueryParamTest.java diff --git a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/binders/BindDateToQueryParam.java b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/binders/BindDateToQueryParam.java new file mode 100644 index 0000000000..7278fe4183 --- /dev/null +++ b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/binders/BindDateToQueryParam.java @@ -0,0 +1,55 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.tmrk.enterprisecloud.binders; + +import org.jclouds.date.DateService; +import org.jclouds.date.internal.SimpleDateFormatDateService; +import org.jclouds.http.HttpRequest; +import org.jclouds.http.utils.ModifyRequest; +import org.jclouds.rest.Binder; + +import javax.inject.Provider; +import javax.ws.rs.core.UriBuilder; +import java.util.Date; + +import static com.google.common.base.Preconditions.checkNotNull; + +/** + * @author Jason King + */ +abstract class BindDateToQueryParam implements Binder { + + private final Provider uriBuilderProvider; + private final DateService dateService; + private final String key; + + public BindDateToQueryParam(Provider uriBuilderProvider, String key) { + this.uriBuilderProvider = checkNotNull(uriBuilderProvider, "uriBuilderProvider"); + this.dateService = new SimpleDateFormatDateService(); + this.key = key; + } + + @Override + public R bindToRequest(R request, Object input) { + if(input==null) return request; + Date date = Date.class.cast(input); + String dateString = dateService.iso8601SecondsDateFormat(date); + return ModifyRequest.addQueryParam(request, key, dateString, uriBuilderProvider.get()); + } +} diff --git a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/binders/BindEndTimeQueryParam.java b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/binders/BindEndTimeQueryParam.java new file mode 100644 index 0000000000..069a599dd1 --- /dev/null +++ b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/binders/BindEndTimeQueryParam.java @@ -0,0 +1,36 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.tmrk.enterprisecloud.binders; + +import javax.inject.Inject; +import javax.inject.Provider; +import javax.inject.Singleton; +import javax.ws.rs.core.UriBuilder; + +/** + * @author Jason King + */ +@Singleton +public class BindEndTimeQueryParam extends BindDateToQueryParam { + + @Inject + public BindEndTimeQueryParam(Provider uriBuilderProvider) { + super(uriBuilderProvider,"endtime"); + } +} diff --git a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/binders/BindStartTimeQueryParam.java b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/binders/BindStartTimeQueryParam.java new file mode 100644 index 0000000000..55e06f4c06 --- /dev/null +++ b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/binders/BindStartTimeQueryParam.java @@ -0,0 +1,36 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.tmrk.enterprisecloud.binders; + +import javax.inject.Inject; +import javax.inject.Provider; +import javax.inject.Singleton; +import javax.ws.rs.core.UriBuilder; + +/** + * @author Jason King + */ +@Singleton +public class BindStartTimeQueryParam extends BindDateToQueryParam { + + @Inject + public BindStartTimeQueryParam(Provider uriBuilderProvider) { + super(uriBuilderProvider,"starttime"); + } +} 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 7d14e5aec2..659ca2c2cc 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 @@ -20,8 +20,11 @@ package org.jclouds.tmrk.enterprisecloud.features; import com.google.common.util.concurrent.ListenableFuture; import org.jclouds.http.filters.BasicAuthentication; +import org.jclouds.javax.annotation.Nullable; import org.jclouds.rest.annotations.*; import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; +import org.jclouds.tmrk.enterprisecloud.binders.BindEndTimeQueryParam; +import org.jclouds.tmrk.enterprisecloud.binders.BindStartTimeQueryParam; 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; @@ -35,6 +38,7 @@ import org.jclouds.tmrk.enterprisecloud.domain.resource.storage.ComputePoolStora import javax.ws.rs.Consumes; import javax.ws.rs.GET; import java.net.URI; +import java.util.Date; /** * Provides asynchronous access to various Resources via their REST API. @@ -129,5 +133,5 @@ public interface ResourceAsyncClient { @Consumes("application/vnd.tmrk.cloud.performanceStatistics") @JAXBResponseParser @ExceptionParser(ReturnNullOnNotFoundOr404.class) - ListenableFuture getPerformanceStatistics(@EndpointParam URI uri); + ListenableFuture getPerformanceStatistics(@EndpointParam URI uri, @Nullable @BinderParam(BindStartTimeQueryParam.class) Date startTime, @Nullable @BinderParam(BindEndTimeQueryParam.class) Date endTime); } 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 70001108e9..397268568d 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 @@ -30,6 +30,7 @@ import org.jclouds.tmrk.enterprisecloud.domain.resource.memory.ComputePoolMemory import org.jclouds.tmrk.enterprisecloud.domain.resource.storage.ComputePoolStorageUsageDetail; import java.net.URI; +import java.util.Date; import java.util.concurrent.TimeUnit; /** @@ -155,12 +156,17 @@ public interface ResourceClient { ComputePoolPerformanceStatistics getComputePoolPerformanceStatistics(URI uri); /** + *

Introduction

+ * * 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) * + *

Default Mode

+ * + *

Daily Statistics

* Daily statistics return results for the previous seven days. * * The default endTime is midnight the beginning of the current day @@ -168,6 +174,7 @@ public interface ResourceClient { * 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

* Hourly statistics return results for the previous 24 hours * * The default endTime is the end of the hour prior to the current time @@ -175,8 +182,36 @@ public interface ResourceClient { * 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. * + *

Query Mode

+ * + *

Daily Statistics with startTime and endTime

+ * + * If startTime and endTime are present returns statistics for the complete days + * between the requested dates. + * + * If either parameter is missing, the default value is used. + * Only complete days are returned. + * For example, 2011-06-20T00:00:00Z to 2011-06-22T00:00:00Z returns information for 2 days: + * June 20 and June 21. + * Conversely, 2011-06-20T22:00:00Z to 2011-06-21T22:30:00Z returns no information + * as no complete days are in the requested interval. + * + *

Hourly Statistics with startTime and endTime

+ * + * If startTime and endTime are present returns statistics for the complete hours + * between the requested dates. + * + * If either parameter is missing, the default value is used. + * Only complete hours are returned. + * For example, 2011-06-22T06:00:00Z to 2011-06-22T08:00:00Z returns information for 2 hours: + * the 06:00 hour and the 07:00 hour. + * Conversely, 2011-06-21T14:10:00Z to 2011-06-21T15:50:00Z returns no information + * as no complete hours are in the requested interval. + * * @param uri uri the uri of the call. + * @param startTime the desired start time for the statistics (optional). + * @param endTime the desired end time for the statistics (optional). * @return the performance statistics for the desired period and metric */ - PerformanceStatistics getPerformanceStatistics(URI uri); + PerformanceStatistics getPerformanceStatistics(URI uri, Date startTime, Date endTime); } diff --git a/sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/binders/BindDateToQueryParamTest.java b/sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/binders/BindDateToQueryParamTest.java new file mode 100644 index 0000000000..7087f78059 --- /dev/null +++ b/sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/binders/BindDateToQueryParamTest.java @@ -0,0 +1,76 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.tmrk.enterprisecloud.binders; + +import com.sun.jersey.api.uri.UriBuilderImpl; +import org.jclouds.date.DateService; +import org.jclouds.date.internal.SimpleDateFormatDateService; +import org.jclouds.http.HttpRequest; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +import javax.inject.Provider; +import javax.ws.rs.core.UriBuilder; +import java.net.URI; +import java.util.Date; + +import static org.testng.Assert.assertEquals; + +/** + * Tests {@code BindDateToQueryParam} + * @author Jason King + */ +@Test(groups = "unit", testName = "BindDateToQueryParamTest") +public class BindDateToQueryParamTest { + + private DateService dateService; + private BindDateToQueryParam binder; + + @BeforeMethod + public void setUp() { + dateService = new SimpleDateFormatDateService(); + Provider uriBuilderProvider = new Provider() { + @Override + public UriBuilder get() { + return new UriBuilderImpl(); + } + }; + binder = new BindMyDateToQueryParam(uriBuilderProvider); + } + + public void testNullDate() { + HttpRequest request = new HttpRequest("GET", URI.create("https://localhost:9999")); + HttpRequest result = binder.bindToRequest(request, null); + assertEquals(result.getRequestLine(),"GET https://localhost:9999 HTTP/1.1"); + } + + public void testDatePresent() { + HttpRequest request = new HttpRequest("GET", URI.create("https://localhost:9999")); + Date date = dateService.iso8601SecondsDateParse("2011-12-08T15:09:33Z"); + HttpRequest result = binder.bindToRequest(request, date); + assertEquals(result.getRequestLine(),"GET https://localhost:9999?mydate=2011-12-08T15%3A09%3A33Z HTTP/1.1"); + } + + + private static class BindMyDateToQueryParam extends BindDateToQueryParam { + public BindMyDateToQueryParam(Provider uriBuilderProvider) { + super(uriBuilderProvider, "mydate"); + } + } +} 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 bcc8c5e4f4..7e7da57129 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 @@ -19,16 +19,20 @@ package org.jclouds.tmrk.enterprisecloud.features; import com.google.inject.TypeLiteral; +import org.jclouds.date.DateService; +import org.jclouds.date.internal.SimpleDateFormatDateService; import org.jclouds.http.HttpRequest; import org.jclouds.http.functions.ParseXMLWithJAXB; import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; import org.jclouds.rest.internal.RestAnnotationProcessor; +import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; import java.io.IOException; import java.lang.reflect.Method; import java.net.URI; import java.net.URISyntaxException; +import java.util.Date; /** * Tests annotation parsing of {@code ResourceAsyncClient} @@ -38,6 +42,13 @@ import java.net.URISyntaxException; @Test(groups = "unit", testName = "ResourceAsyncClient") public class ResourceAsyncClientTest extends BaseTerremarkEnterpriseCloudAsyncClientTest { + private DateService dateService; + + @BeforeMethod + public void setUp() { + dateService = new SimpleDateFormatDateService(); + } + public void testGetResourceSummaries() throws SecurityException, NoSuchMethodException, IOException, URISyntaxException { Method method = ResourceAsyncClient.class.getMethod("getResourceSummaries", URI.class); HttpRequest httpRequest = processor.createRequest(method, new URI("/cloudapi/ecloud/computepools/environments/77/resourcesummarylist")); @@ -158,9 +169,9 @@ public class ResourceAsyncClientTest extends BaseTerremarkEnterpriseCloudAsyncCl checkFilters(httpRequest); } - 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")); + public void testGetPerformanceStatisticsNoDates() throws SecurityException, NoSuchMethodException, IOException, URISyntaxException { + Method method = ResourceAsyncClient.class.getMethod("getPerformanceStatistics", URI.class,Date.class,Date.class); + HttpRequest httpRequest = processor.createRequest(method, URI.create("/cloudapi/ecloud/computepools/89/usage/cpu/performancestatistics/daily"),null,null); assertRequestLineEquals(httpRequest, "GET https://services-beta.enterprisecloud.terremark.com/cloudapi/ecloud/computepools/89/usage/cpu/performancestatistics/daily HTTP/1.1"); assertNonPayloadHeadersEqual(httpRequest, @@ -173,6 +184,24 @@ public class ResourceAsyncClientTest extends BaseTerremarkEnterpriseCloudAsyncCl checkFilters(httpRequest); } + public void testGetPerformanceStatisticsWithDates() throws SecurityException, NoSuchMethodException, IOException, URISyntaxException { + Method method = ResourceAsyncClient.class.getMethod("getPerformanceStatistics", URI.class,Date.class,Date.class); + + Date startTime = dateService.iso8601SecondsDateParse("2011-12-08T15:00:00Z"); + Date endTime = dateService.iso8601SecondsDateParse("2011-12-08T16:30:00Z");; + HttpRequest httpRequest = processor.createRequest(method, URI.create("/cloudapi/ecloud/computepools/89/usage/cpu/performancestatistics/daily"),startTime,endTime); + + assertRequestLineEquals(httpRequest, "GET https://services-beta.enterprisecloud.terremark.com/cloudapi/ecloud/computepools/89/usage/cpu/performancestatistics/daily?endtime=2011-12-08T16%3A30%3A00Z&starttime=2011-12-08T15%3A00%3A00Z HTTP/1.1"); + assertNonPayloadHeadersEqual(httpRequest, + "Accept: application/vnd.tmrk.cloud.performanceStatistics\nx-tmrk-version: 2011-07-01\n"); + assertPayloadEquals(httpRequest, null, null, false); + + assertResponseParserClassEquals(method, httpRequest, ParseXMLWithJAXB.class); + assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); + + checkFilters(httpRequest); + } + @Override protected TypeLiteral> createTypeLiteral() { return new TypeLiteral>() { 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 7fce663e71..a69700c25a 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 @@ -18,13 +18,11 @@ */ package org.jclouds.tmrk.enterprisecloud.features; +import com.google.common.collect.Iterables; 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.*; import org.jclouds.tmrk.enterprisecloud.domain.resource.cpu.ComputePoolCpuUsage; -import org.jclouds.tmrk.enterprisecloud.domain.resource.ComputePoolResourceSummary; -import org.jclouds.tmrk.enterprisecloud.domain.resource.ComputePoolResourceSummaryList; import org.jclouds.tmrk.enterprisecloud.domain.resource.cpu.ComputePoolCpuUsageDetail; import org.jclouds.tmrk.enterprisecloud.domain.resource.memory.ComputePoolMemoryUsage; import org.jclouds.tmrk.enterprisecloud.domain.resource.memory.ComputePoolMemoryUsageDetail; @@ -33,10 +31,10 @@ import org.testng.annotations.BeforeGroups; import org.testng.annotations.Test; import java.net.URI; +import java.util.Date; +import java.util.Set; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertNotNull; -import static org.testng.Assert.assertNull; +import static org.testng.Assert.*; /** * Tests behavior of {@code ResourceClient} @@ -133,7 +131,28 @@ public class ResourceClientLiveTest extends BaseTerremarkEnterpriseCloudClientLi } private void testPerformanceStatistic(URI uri) { - PerformanceStatistics stats = client.getPerformanceStatistics(uri); + PerformanceStatistics stats = client.getPerformanceStatistics(uri,null,null); assertNotNull(stats); } + + public void testGetPerformanceStatisticsWithDateRange() { + ComputePoolPerformanceStatistics statistics = client.getComputePoolPerformanceStatistics(URI.create("/cloudapi/ecloud/computepools/89/performancestatistics")); + URI uri = statistics.getDaily().getCpu().getHref(); + + Set set = getStatsForFirstVM(uri,null,null); + assertEquals(set.size(), 7); + + // A subset of the entire results + Date start = Iterables.get(set, 1).getTime(); + Date end = Iterables.get(set, set.size()-1).getTime(); + + Set result = getStatsForFirstVM(uri, start, end); + assertEquals(result.size(), 5); + } + + private Set getStatsForFirstVM(URI uri, Date start, Date end) { + PerformanceStatistics stats = client.getPerformanceStatistics(uri, start, end); + Set virtualMachines = stats.getStatistics().getVirtualMachinesPerformanceStatistics(); + return Iterables.getFirst(virtualMachines,null).getStatistics(); + } } \ 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 ec097fc601..4a9ff884ce 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 @@ -47,6 +47,7 @@ import javax.inject.Named; import java.io.InputStream; import java.lang.reflect.Method; import java.net.URI; +import java.util.Date; import java.util.Set; import static org.jclouds.io.Payloads.newInputStreamPayload; @@ -95,8 +96,8 @@ public class PerformanceStatisticsJAXBParsingTest extends BaseRestClientTest { public void testParseWithJAXB() throws Exception { - Method method = ResourceAsyncClient.class.getMethod("getPerformanceStatistics", URI.class); - HttpRequest request = factory(ResourceAsyncClient.class).createRequest(method,new URI("/1")); + Method method = ResourceAsyncClient.class.getMethod("getPerformanceStatistics", URI.class, Date.class, Date.class); + HttpRequest request = factory(ResourceAsyncClient.class).createRequest(method,new URI("/1"),null,null); assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); Function parser = (Function) RestAnnotationProcessor From 037755ad94319f8593653895221a34864c8b9334 Mon Sep 17 00:00:00 2001 From: Jason King Date: Thu, 8 Dec 2011 17:09:54 +0000 Subject: [PATCH 3/3] Issue 695: Fix @Test annotation test names --- .../tmrk/enterprisecloud/domain/vm/VirtualMachinesTest.java | 2 +- .../features/BaseTerremarkEnterpriseCloudClientLiveTest.java | 2 +- .../tmrk/enterprisecloud/features/ResourceAsyncClientTest.java | 2 +- .../xml/ComputePoolCpuUsageDetailJAXBParsingTest.java | 2 +- .../xml/ComputePoolMemoryUsageDetailJAXBParsingTest.java | 2 +- .../xml/HardwareConfigurationJAXBParsingTest.java | 1 + .../jclouds/tmrk/enterprisecloud/xml/TaskJAXBParsingTest.java | 2 +- 7 files changed, 7 insertions(+), 6 deletions(-) diff --git a/sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/domain/vm/VirtualMachinesTest.java b/sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/domain/vm/VirtualMachinesTest.java index 8556f50602..25c2e41c5e 100644 --- a/sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/domain/vm/VirtualMachinesTest.java +++ b/sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/domain/vm/VirtualMachinesTest.java @@ -34,7 +34,7 @@ import static org.testng.Assert.assertTrue; /** * @author Jason King */ -@Test(groups = "unit", testName = "ActionsTest") +@Test(groups = "unit", testName = "VirtualMachinesTest") public class VirtualMachinesTest { private VirtualMachine virtualMachine; diff --git a/sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/features/BaseTerremarkEnterpriseCloudClientLiveTest.java b/sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/features/BaseTerremarkEnterpriseCloudClientLiveTest.java index 44e4910668..abf95a4221 100644 --- a/sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/features/BaseTerremarkEnterpriseCloudClientLiveTest.java +++ b/sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/features/BaseTerremarkEnterpriseCloudClientLiveTest.java @@ -39,7 +39,7 @@ import com.google.inject.Module; * * @author Adrian Cole */ -@Test(groups = "live") +@Test(groups = "live", testName = "BaseTerremarkEnterpriseCloudClientLiveTest") public class BaseTerremarkEnterpriseCloudClientLiveTest extends BaseVersionedServiceLiveTest { protected RestContext context; 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 7e7da57129..5d1952b4bf 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 @@ -39,7 +39,7 @@ import java.util.Date; * * @author Jason King */ -@Test(groups = "unit", testName = "ResourceAsyncClient") +@Test(groups = "unit", testName = "ResourceAsyncClientTest") public class ResourceAsyncClientTest extends BaseTerremarkEnterpriseCloudAsyncClientTest { private DateService dateService; diff --git a/sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/xml/ComputePoolCpuUsageDetailJAXBParsingTest.java b/sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/xml/ComputePoolCpuUsageDetailJAXBParsingTest.java index 814cd5d515..fd16bf2dfe 100644 --- a/sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/xml/ComputePoolCpuUsageDetailJAXBParsingTest.java +++ b/sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/xml/ComputePoolCpuUsageDetailJAXBParsingTest.java @@ -60,7 +60,7 @@ import static org.testng.Assert.assertNull; * * @author Jason King */ -@Test(groups = "unit", testName = "ComputePoolResourceSummaryListJAXBParsingTest") +@Test(groups = "unit", testName = "ComputePoolCpuUsageDetailJAXBParsingTest") public class ComputePoolCpuUsageDetailJAXBParsingTest extends BaseRestClientTest { private SimpleDateFormatDateService dateService; diff --git a/sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/xml/ComputePoolMemoryUsageDetailJAXBParsingTest.java b/sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/xml/ComputePoolMemoryUsageDetailJAXBParsingTest.java index 465e43b3c6..817b41a263 100644 --- a/sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/xml/ComputePoolMemoryUsageDetailJAXBParsingTest.java +++ b/sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/xml/ComputePoolMemoryUsageDetailJAXBParsingTest.java @@ -60,7 +60,7 @@ import static org.testng.Assert.assertNull; * * @author Jason King */ -@Test(groups = "unit", testName = "ComputePoolResourceSummaryListJAXBParsingTest") +@Test(groups = "unit", testName = "ComputePoolMemoryUsageDetailJAXBParsingTest") public class ComputePoolMemoryUsageDetailJAXBParsingTest extends BaseRestClientTest { private SimpleDateFormatDateService dateService; diff --git a/sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/xml/HardwareConfigurationJAXBParsingTest.java b/sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/xml/HardwareConfigurationJAXBParsingTest.java index 63bf121c5a..2ca4afc1f9 100644 --- a/sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/xml/HardwareConfigurationJAXBParsingTest.java +++ b/sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/xml/HardwareConfigurationJAXBParsingTest.java @@ -61,6 +61,7 @@ import static org.testng.AssertJUnit.assertNotNull; * @author Jason King * */ +@Test(groups = "unit", testName = "HardwareConfigurationJAXBParsingTest") public class HardwareConfigurationJAXBParsingTest extends BaseRestClientTest { @BeforeClass diff --git a/sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/xml/TaskJAXBParsingTest.java b/sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/xml/TaskJAXBParsingTest.java index 2b08857a29..0387e66d6c 100644 --- a/sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/xml/TaskJAXBParsingTest.java +++ b/sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/xml/TaskJAXBParsingTest.java @@ -59,7 +59,7 @@ import static org.testng.Assert.assertTrue; * * @author Adrian Cole */ -@Test(groups = "unit", testName = "TaskHandlerTest") +@Test(groups = "unit", testName = "TaskJAXBParsingTest") public class TaskJAXBParsingTest extends BaseRestClientTest { private SimpleDateFormatDateService dateService; private Task expected1;