Issue 695: Added ComputePoolMemoryUsage objects+service call+tests

This commit is contained in:
Jason King 2011-12-06 17:20:37 +00:00
parent 00de94b7b8
commit c1a36994fd
9 changed files with 2698 additions and 3 deletions

View File

@ -0,0 +1,223 @@
/**
* 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.domain.resource.memory;
import org.jclouds.javax.annotation.Nullable;
import org.jclouds.tmrk.enterprisecloud.domain.Action;
import org.jclouds.tmrk.enterprisecloud.domain.Link;
import org.jclouds.tmrk.enterprisecloud.domain.internal.BaseResource;
import org.jclouds.tmrk.enterprisecloud.domain.internal.Resource;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import java.net.URI;
import java.util.Date;
import java.util.Map;
import java.util.Set;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* ComputePoolMemoryUsage is more than a simple wrapper as it extends Resource.
* <xs:complexType name="ComputePoolMemoryUsage">
* @author Jason King
*
*/
@XmlRootElement(name = "ComputePoolMemoryUsage")
public class ComputePoolMemoryUsage extends Resource<ComputePoolMemoryUsage> {
@SuppressWarnings("unchecked")
public static Builder builder() {
return new Builder();
}
/**
* {@inheritDoc}
*/
@Override
public Builder toBuilder() {
return new Builder().fromComputePoolCpuUsage(this);
}
public static class Builder extends Resource.Builder<ComputePoolMemoryUsage> {
private Date startTime;
private Date endTime;
private MemoryUsageDetails details;
/**
* @see ComputePoolMemoryUsage#getStartTime
*/
public Builder startTime(Date startTime) {
this.startTime =(checkNotNull(startTime,"startTime"));
return this;
}
/**
* @see ComputePoolMemoryUsage#getEndTime
*/
public Builder endTime(Date endTime) {
this.endTime =(checkNotNull(endTime,"endTime"));
return this;
}
/**
* @see ComputePoolMemoryUsage#getDetails
*/
public Builder details(MemoryUsageDetails details) {
this.details =(checkNotNull(details,"details"));
return this;
}
@Override
public ComputePoolMemoryUsage build() {
return new ComputePoolMemoryUsage(href, type, name, links, actions, startTime, endTime, details);
}
public Builder fromComputePoolCpuUsage(ComputePoolMemoryUsage in) {
return fromResource(in).startTime(in.getStartTime()).endTime(in.getEndTime()).details(in.getDetails());
}
/**
* {@inheritDoc}
*/
@Override
public Builder fromBaseResource(BaseResource<ComputePoolMemoryUsage> in) {
return Builder.class.cast(super.fromBaseResource(in));
}
/**
* {@inheritDoc}
*/
@Override
public Builder fromResource(Resource<ComputePoolMemoryUsage> in) {
return Builder.class.cast(super.fromResource(in));
}
/**
* {@inheritDoc}
*/
@Override
public Builder type(String type) {
return Builder.class.cast(super.type(type));
}
/**
* {@inheritDoc}
*/
@Override
public Builder href(URI href) {
return Builder.class.cast(super.href(href));
}
/**
* {@inheritDoc}
*/
@Override
public Builder name(String name) {
return Builder.class.cast(super.name(name));
}
/**
* {@inheritDoc}
*/
@Override
public Builder links(Set<Link> links) {
return Builder.class.cast(super.links(links));
}
/**
* {@inheritDoc}
*/
@Override
public Builder actions(Set<Action> actions) {
return Builder.class.cast(super.actions(actions));
}
/**
* {@inheritDoc}
*/
@Override
public Builder fromAttributes(Map<String, String> attributes) {
return Builder.class.cast(super.fromAttributes(attributes));
}
}
@XmlElement(name = "StartTime", required = true)
private Date startTime;
@XmlElement(name = "EndTime", required = true)
private Date endTime;
@XmlElement(name = "MemoryUsageDetailSummary", required = false)
private MemoryUsageDetails details;
private ComputePoolMemoryUsage(URI href, String type, String name, Set<Link> links, Set<Action> actions, Date startTime, Date endTime, @Nullable MemoryUsageDetails details) {
super(href, type, name, links, actions);
this.startTime = checkNotNull(startTime, "startTime");
this.endTime = checkNotNull(endTime, "endTime");
this.details = details;
}
private ComputePoolMemoryUsage() {
//For JAXB
}
public Date getStartTime() {
return startTime;
}
public Date getEndTime() {
return endTime;
}
public MemoryUsageDetails getDetails() {
return details;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
if (!super.equals(o)) return false;
ComputePoolMemoryUsage that = (ComputePoolMemoryUsage) o;
if (details != null ? !details.equals(that.details) : that.details != null)
return false;
if (!endTime.equals(that.endTime)) return false;
if (!startTime.equals(that.startTime)) return false;
return true;
}
@Override
public int hashCode() {
int result = super.hashCode();
result = 31 * result + startTime.hashCode();
result = 31 * result + endTime.hashCode();
result = 31 * result + (details != null ? details.hashCode() : 0);
return result;
}
@Override
public String string() {
return super.string()+", startTime="+startTime+", endTime="+endTime+", details="+details;
}
}

View File

@ -0,0 +1,127 @@
/**
* 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.domain.resource.memory;
import org.jclouds.javax.annotation.Nullable;
import org.jclouds.tmrk.enterprisecloud.domain.internal.ResourceCapacity;
import javax.xml.bind.annotation.XmlElement;
import java.util.Date;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* <xs:complexType name="ComputePoolMemoryUsageDetailSummaryEntry">
* @author Jason King
*
*/
public class ComputePoolMemoryUsageDetailSummaryEntry {
@SuppressWarnings("unchecked")
public static Builder builder() {
return new Builder();
}
/**
* {@inheritDoc}
*/
public Builder toBuilder() {
return new Builder().ComputePoolCpuUsageDetailSummaryEntry(this);
}
public static class Builder {
private Date time;
private ResourceCapacity value;
/**
* @see ComputePoolMemoryUsageDetailSummaryEntry#getTime
*/
public Builder time(Date time) {
this.time = time;
return this;
}
/**
* @see ComputePoolMemoryUsageDetailSummaryEntry#getValue
*/
public Builder value(ResourceCapacity value) {
this.value = value;
return this;
}
public ComputePoolMemoryUsageDetailSummaryEntry build() {
return new ComputePoolMemoryUsageDetailSummaryEntry(time,value);
}
public Builder ComputePoolCpuUsageDetailSummaryEntry(ComputePoolMemoryUsageDetailSummaryEntry in) {
return time(in.getTime()).value(in.getValue());
}
}
@XmlElement(name = "Time", required = true)
private Date time;
@XmlElement(name = "Value", required = false)
private ResourceCapacity value;
private ComputePoolMemoryUsageDetailSummaryEntry(Date time, @Nullable ResourceCapacity value) {
this.time = checkNotNull(time, "time");
this.value = value;
}
private ComputePoolMemoryUsageDetailSummaryEntry() {
//For JAXB
}
public Date getTime() {
return time;
}
public ResourceCapacity getValue() {
return value;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ComputePoolMemoryUsageDetailSummaryEntry that = (ComputePoolMemoryUsageDetailSummaryEntry) o;
if (!time.equals(that.time)) return false;
if (value != null ? !value.equals(that.value) : that.value != null)
return false;
return true;
}
@Override
public int hashCode() {
int result = time.hashCode();
result = 31 * result + (value != null ? value.hashCode() : 0);
return result;
}
@Override
public String toString() {
return "[time="+ time +", value="+value+"]";
}
}

View File

@ -0,0 +1,106 @@
/**
* 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.domain.resource.memory;
import com.google.common.collect.Sets;
import javax.xml.bind.annotation.XmlElement;
import java.util.Collections;
import java.util.Set;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* Wraps individual ComputePoolMemoryUsageDetailSummaryEntry elements.
* <xs:complexType name="MemoryUsageDetails">
* @author Jason King
*/
public class MemoryUsageDetails {
@SuppressWarnings("unchecked")
public static Builder builder() {
return new Builder();
}
public Builder toBuilder() {
return new Builder().fromMemoryUsageDetails(this);
}
public static class Builder {
private Set<ComputePoolMemoryUsageDetailSummaryEntry> entries = Sets.newLinkedHashSet();
/**
* @see MemoryUsageDetails#getEntries
*/
public Builder entries(Set<ComputePoolMemoryUsageDetailSummaryEntry> entries) {
this.entries = Sets.newLinkedHashSet(checkNotNull(entries, "entries"));
return this;
}
public Builder addEntry(ComputePoolMemoryUsageDetailSummaryEntry entry) {
entries.add(checkNotNull(entry,"entry"));
return this;
}
public MemoryUsageDetails build() {
return new MemoryUsageDetails(entries);
}
public Builder fromMemoryUsageDetails(MemoryUsageDetails in) {
return entries(in.getEntries());
}
}
private MemoryUsageDetails() {
//For JAXB and builder use
}
private MemoryUsageDetails(Set<ComputePoolMemoryUsageDetailSummaryEntry> entries) {
this.entries = Sets.newLinkedHashSet(entries);
}
@XmlElement(name = "MemoryUsageDetail", required=false)
private Set<ComputePoolMemoryUsageDetailSummaryEntry> entries = Sets.newLinkedHashSet();
public Set<ComputePoolMemoryUsageDetailSummaryEntry> getEntries() {
return Collections.unmodifiableSet(entries);
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
MemoryUsageDetails tasks1 = (MemoryUsageDetails) o;
if (!entries.equals(tasks1.entries)) return false;
return true;
}
@Override
public int hashCode() {
return entries.hashCode();
}
public String toString() {
return "["+ entries.toString()+"]";
}
}

View File

@ -26,6 +26,7 @@ import org.jclouds.tmrk.enterprisecloud.domain.resource.cpu.ComputePoolCpuUsage;
import org.jclouds.tmrk.enterprisecloud.domain.resource.ComputePoolResourceSummary; import org.jclouds.tmrk.enterprisecloud.domain.resource.ComputePoolResourceSummary;
import org.jclouds.tmrk.enterprisecloud.domain.resource.ComputePoolResourceSummaryList; import org.jclouds.tmrk.enterprisecloud.domain.resource.ComputePoolResourceSummaryList;
import org.jclouds.tmrk.enterprisecloud.domain.resource.cpu.ComputePoolCpuUsageDetail; import org.jclouds.tmrk.enterprisecloud.domain.resource.cpu.ComputePoolCpuUsageDetail;
import org.jclouds.tmrk.enterprisecloud.domain.resource.memory.ComputePoolMemoryUsage;
import javax.ws.rs.Consumes; import javax.ws.rs.Consumes;
import javax.ws.rs.GET; import javax.ws.rs.GET;
@ -80,4 +81,13 @@ public interface ResourceAsyncClient {
@JAXBResponseParser @JAXBResponseParser
@ExceptionParser(ReturnNullOnNotFoundOr404.class) @ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<ComputePoolCpuUsageDetail> getComputePoolCpuUsageDetail(@EndpointParam URI uri); ListenableFuture<ComputePoolCpuUsageDetail> getComputePoolCpuUsageDetail(@EndpointParam URI uri);
/**
* @see ResourceClient#getComputePoolMemoryUsage
*/
@GET
@Consumes("application/vnd.tmrk.cloud.computePoolMemoryUsage")
@JAXBResponseParser
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<ComputePoolMemoryUsage> getComputePoolMemoryUsage(@EndpointParam URI uri);
} }

View File

@ -23,6 +23,7 @@ import org.jclouds.tmrk.enterprisecloud.domain.resource.cpu.ComputePoolCpuUsage;
import org.jclouds.tmrk.enterprisecloud.domain.resource.ComputePoolResourceSummary; import org.jclouds.tmrk.enterprisecloud.domain.resource.ComputePoolResourceSummary;
import org.jclouds.tmrk.enterprisecloud.domain.resource.ComputePoolResourceSummaryList; import org.jclouds.tmrk.enterprisecloud.domain.resource.ComputePoolResourceSummaryList;
import org.jclouds.tmrk.enterprisecloud.domain.resource.cpu.ComputePoolCpuUsageDetail; import org.jclouds.tmrk.enterprisecloud.domain.resource.cpu.ComputePoolCpuUsageDetail;
import org.jclouds.tmrk.enterprisecloud.domain.resource.memory.ComputePoolMemoryUsage;
import java.net.URI; import java.net.URI;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@ -96,4 +97,16 @@ public interface ResourceClient {
*/ */
ComputePoolCpuUsageDetail getComputePoolCpuUsageDetail(URI uri); ComputePoolCpuUsageDetail getComputePoolCpuUsageDetail(URI uri);
/**
* The Get Resources Usage Memory call returns information regarding memory usage
* for a specified compute pool defined in an environment at five minute intervals
* for the 24 hours ending one hour prior to the current time, rounded later.
* For example, if current time is 11:22, the end time 10:25.
*
* @param uri the uri of the call based upon the compute pool
* e.g. /cloudapi/ecloud/computepools/{id}/usage/memory
* @return The memory usage for the compute pool
*/
ComputePoolMemoryUsage getComputePoolMemoryUsage(URI uri);
} }

View File

@ -98,6 +98,21 @@ public class ResourceAsyncClientTest extends BaseTerremarkEnterpriseCloudAsyncCl
checkFilters(httpRequest); checkFilters(httpRequest);
} }
public void testGetComputePoolMemoryUsage() throws SecurityException, NoSuchMethodException, IOException, URISyntaxException {
Method method = ResourceAsyncClient.class.getMethod("getComputePoolMemoryUsage", URI.class);
HttpRequest httpRequest = processor.createRequest(method, URI.create("/cloudapi/ecloud/computepools/89/usage/memory"));
assertRequestLineEquals(httpRequest, "GET https://services-beta.enterprisecloud.terremark.com/cloudapi/ecloud/computepools/89/usage/memory HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest,
"Accept: application/vnd.tmrk.cloud.computePoolMemoryUsage\nx-tmrk-version: 2011-07-01\n");
assertPayloadEquals(httpRequest, null, null, false);
assertResponseParserClassEquals(method, httpRequest, ParseXMLWithJAXB.class);
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
checkFilters(httpRequest);
}
@Override @Override
protected TypeLiteral<RestAnnotationProcessor<ResourceAsyncClient>> createTypeLiteral() { protected TypeLiteral<RestAnnotationProcessor<ResourceAsyncClient>> createTypeLiteral() {
return new TypeLiteral<RestAnnotationProcessor<ResourceAsyncClient>>() { return new TypeLiteral<RestAnnotationProcessor<ResourceAsyncClient>>() {

View File

@ -24,6 +24,7 @@ import org.jclouds.tmrk.enterprisecloud.domain.resource.cpu.ComputePoolCpuUsage;
import org.jclouds.tmrk.enterprisecloud.domain.resource.ComputePoolResourceSummary; import org.jclouds.tmrk.enterprisecloud.domain.resource.ComputePoolResourceSummary;
import org.jclouds.tmrk.enterprisecloud.domain.resource.ComputePoolResourceSummaryList; import org.jclouds.tmrk.enterprisecloud.domain.resource.ComputePoolResourceSummaryList;
import org.jclouds.tmrk.enterprisecloud.domain.resource.cpu.ComputePoolCpuUsageDetail; import org.jclouds.tmrk.enterprisecloud.domain.resource.cpu.ComputePoolCpuUsageDetail;
import org.jclouds.tmrk.enterprisecloud.domain.resource.memory.ComputePoolMemoryUsage;
import org.testng.annotations.BeforeGroups; import org.testng.annotations.BeforeGroups;
import org.testng.annotations.Test; import org.testng.annotations.Test;
@ -67,14 +68,14 @@ public class ResourceClientLiveTest extends BaseTerremarkEnterpriseCloudClientLi
} }
public void testGetComputePoolCpuUsage() throws Exception { public void testGetComputePoolCpuUsage() throws Exception {
ComputePoolCpuUsage cpuUsage = client.getComputePoolCpuUsage(URI.create("/cloudapi/ecloud/computepools/89/usage/cpu")); ComputePoolCpuUsage usage = client.getComputePoolCpuUsage(URI.create("/cloudapi/ecloud/computepools/89/usage/cpu"));
for(Link link: cpuUsage.getLinks()) { assertNotNull(usage);
for(Link link: usage.getLinks()) {
//The compute pool cpu usage has a link to a detail entry //The compute pool cpu usage has a link to a detail entry
if( "application/vnd.tmrk.cloud.computePoolCpuUsageDetail".equals(link.getType())) { if( "application/vnd.tmrk.cloud.computePoolCpuUsageDetail".equals(link.getType())) {
testGetComputePoolCpuUsageDetail(link.getHref()); testGetComputePoolCpuUsageDetail(link.getHref());
} }
} }
assertNotNull(cpuUsage);
} }
public void testMissingComputePoolCpuUsage() { public void testMissingComputePoolCpuUsage() {
@ -96,4 +97,20 @@ public class ResourceClientLiveTest extends BaseTerremarkEnterpriseCloudClientLi
assertEquals(detail.getValue(), ResourceCapacity.builder().value(0).unit("MHz").build()); assertEquals(detail.getValue(), ResourceCapacity.builder().value(0).unit("MHz").build());
assertNull(detail.getVirtualMachinesCpuUsage()); assertNull(detail.getVirtualMachinesCpuUsage());
} }
public void testGetComputePoolMemoryUsage() throws Exception {
ComputePoolMemoryUsage usage = client.getComputePoolMemoryUsage(URI.create("/cloudapi/ecloud/computepools/89/usage/memory"));
assertNotNull(usage);
for(Link link: usage.getLinks()) {
//The compute pool memory usage has a link to a detail entry
if( "application/vnd.tmrk.cloud.computePoolMemoryUsageDetail".equals(link.getType())) {
testGetComputePoolMemoryUsageDetail(link.getHref());
}
}
}
private void testGetComputePoolMemoryUsageDetail(URI uri) {
// ComputePoolMemoryUsageDetail detail = client.getComputePoolMemoryUsageDetail(uri);
// assertNotNull(detail.getTime());
}
} }

View File

@ -0,0 +1,145 @@
/**
* 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.xml;
import com.google.common.base.Function;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
import com.google.inject.AbstractModule;
import com.google.inject.Module;
import com.google.inject.Provides;
import org.jclouds.crypto.Crypto;
import org.jclouds.date.internal.SimpleDateFormatDateService;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpResponse;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.http.functions.ParseXMLWithJAXB;
import org.jclouds.logging.config.NullLoggingModule;
import org.jclouds.rest.AuthorizationException;
import org.jclouds.rest.BaseRestClientTest;
import org.jclouds.rest.RestContextSpec;
import org.jclouds.rest.internal.RestAnnotationProcessor;
import org.jclouds.tmrk.enterprisecloud.domain.Link;
import org.jclouds.tmrk.enterprisecloud.domain.resource.memory.ComputePoolMemoryUsage;
import org.jclouds.tmrk.enterprisecloud.domain.resource.memory.ComputePoolMemoryUsageDetailSummaryEntry;
import org.jclouds.tmrk.enterprisecloud.domain.resource.memory.MemoryUsageDetails;
import org.jclouds.tmrk.enterprisecloud.features.ResourceAsyncClient;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import javax.inject.Named;
import java.io.InputStream;
import java.lang.reflect.Method;
import java.net.URI;
import java.util.Set;
import static org.jclouds.io.Payloads.newInputStreamPayload;
import static org.jclouds.rest.RestContextFactory.contextSpec;
import static org.jclouds.rest.RestContextFactory.createContextBuilder;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
/**
* Tests behavior of JAXB parsing for ComputePoolMemoryUsage
*
* @author Jason King
*/
@Test(groups = "unit", testName = "ComputePoolMemoryUsageJAXBParsingTest")
public class ComputePoolMemoryUsageJAXBParsingTest extends BaseRestClientTest {
private SimpleDateFormatDateService dateService;
@BeforeMethod
public void setUp() {
dateService = new SimpleDateFormatDateService();
}
@BeforeClass
void setupFactory() {
RestContextSpec<String, Integer> contextSpec = contextSpec("test", "http://localhost:9999", "1", "", "userfoo",
"credentialFoo", String.class, Integer.class,
ImmutableSet.<Module>of(new MockModule(), new NullLoggingModule(), new AbstractModule() {
@Override
protected void configure() {
}
@SuppressWarnings("unused")
@Provides
@Named("exception")
Set<String> exception() {
throw new AuthorizationException();
}
}));
injector = createContextBuilder(contextSpec).buildInjector();
parserFactory = injector.getInstance(ParseSax.Factory.class);
crypto = injector.getInstance(Crypto.class);
}
public void testParseWithJAXB() throws Exception {
Method method = ResourceAsyncClient.class.getMethod("getComputePoolMemoryUsage", URI.class);
HttpRequest request = factory(ResourceAsyncClient.class).createRequest(method,new URI("/1"));
assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class);
Function<HttpResponse, ComputePoolMemoryUsage> parser = (Function<HttpResponse, ComputePoolMemoryUsage>) RestAnnotationProcessor
.createResponseParser(parserFactory, injector, method, request);
InputStream is = getClass().getResourceAsStream("/computePoolMemoryUsage.xml");
ComputePoolMemoryUsage memoryUsage = parser.apply(new HttpResponse(200, "ok", newInputStreamPayload(is)));
assertLinks(memoryUsage.getLinks());
assertEquals(memoryUsage.getStartTime(), dateService.iso8601DateParse("2011-12-05T15:55:00.0Z"));
assertEquals(memoryUsage.getEndTime(), dateService.iso8601DateParse("2011-12-06T15:55:00.0Z"));
assertDetails(memoryUsage.getDetails());
Set<ComputePoolMemoryUsageDetailSummaryEntry> entries = memoryUsage.getDetails().getEntries();
ComputePoolMemoryUsageDetailSummaryEntry first = Iterables.getFirst(entries, null);
assertEquals(memoryUsage.getStartTime(),first.getTime());
ComputePoolMemoryUsageDetailSummaryEntry last = Iterables.getLast(entries, null);
assertEquals(memoryUsage.getEndTime(),last.getTime());
}
private void assertLinks(Set<Link> links) {
assertEquals(links.size(),2);
Link link = Iterables.get(links, 0);
assertEquals(link.getName(),"Default Compute Pool");
assertEquals(link.getRelationship(), Link.Relationship.UP);
Link link2 = Iterables.get(links, 1);
assertEquals(link2.getHref(), URI.create("/cloudapi/ecloud/computepools/89/usage/memory/details?time=2011-12-05t15%3a55%3a00z"));
assertEquals(link2.getType(), "application/vnd.tmrk.cloud.computePoolMemoryUsageDetail");
assertEquals(link2.getRelationship(), Link.Relationship.DOWN);
}
private void assertDetails(MemoryUsageDetails details) {
assertEquals(details.getEntries().size(), 289);
for(ComputePoolMemoryUsageDetailSummaryEntry entry: details.getEntries()) {
assertDetail(entry);
}
}
private void assertDetail(ComputePoolMemoryUsageDetailSummaryEntry entry) {
assertNotNull(entry.getTime());
assertNotNull(entry.getValue());
}
}