Issue 695: Added ComputePoolStorageUsageDetail+service call+tests

This commit is contained in:
Jason King 2011-12-07 11:50:06 +00:00
parent be93927f45
commit c5d859ce26
9 changed files with 681 additions and 0 deletions

View File

@ -0,0 +1,183 @@
/**
* 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.storage;
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 org.jclouds.tmrk.enterprisecloud.domain.internal.ResourceCapacity;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import java.net.URI;
import java.util.Map;
import java.util.Set;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* ComputePoolStorageUsageDetail is more than a simple wrapper as it extends Resource.
* <xs:complexType name="ComputePoolStorageUsageDetail">
* @author Jason King
*
*/
@XmlRootElement(name = "ComputePoolStorageUsageDetail")
public class ComputePoolStorageUsageDetail extends Resource<ComputePoolStorageUsageDetail> {
@SuppressWarnings("unchecked")
public static Builder builder() {
return new Builder();
}
/**
* {@inheritDoc}
*/
@Override
public Builder toBuilder() {
return new Builder().fromComputePoolStorageUsageDetail(this);
}
public static class Builder extends Resource.Builder<ComputePoolStorageUsageDetail> {
private ResourceCapacity allocated;
private VirtualMachinesStorageDetails virtualMachinesStorageDetails;
/**
* @see org.jclouds.tmrk.enterprisecloud.domain.resource.storage.ComputePoolStorageUsageDetail#getAllocated
*/
public Builder allocated(ResourceCapacity allocated) {
this.allocated =(checkNotNull(allocated,"allocated"));
return this;
}
/**
* @see org.jclouds.tmrk.enterprisecloud.domain.resource.storage.ComputePoolStorageUsageDetail#getVirtualMachinesStorageDetails
*/
public Builder virtualMachines(VirtualMachinesStorageDetails virtualMachinesStorageDetails) {
this.virtualMachinesStorageDetails =(checkNotNull(virtualMachinesStorageDetails,"virtualMachinesStorageDetails"));
return this;
}
@Override
public ComputePoolStorageUsageDetail build() {
return new ComputePoolStorageUsageDetail(href, type, name, links, actions, allocated, virtualMachinesStorageDetails);
}
public Builder fromComputePoolStorageUsageDetail(ComputePoolStorageUsageDetail in) {
return fromResource(in).allocated(in.getAllocated()).virtualMachines(in.getVirtualMachinesStorageDetails());
}
/**
* {@inheritDoc}
*/
@Override
public Builder fromBaseResource(BaseResource<ComputePoolStorageUsageDetail> in) {
return Builder.class.cast(super.fromBaseResource(in));
}
/**
* {@inheritDoc}
*/
@Override
public Builder fromResource(Resource<ComputePoolStorageUsageDetail> 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 = "Allocated", required = false)
private ResourceCapacity allocated;
@XmlElement(name = "VirtualMachines", required = false)
private VirtualMachinesStorageDetails virtualMachinesStorageDetails;
private ComputePoolStorageUsageDetail(URI href, String type, String name, Set<Link> links, Set<Action> actions, @Nullable ResourceCapacity allocated, @Nullable VirtualMachinesStorageDetails virtualMachinesStorageDetails) {
super(href, type, name, links, actions);
this.allocated = allocated;
this.virtualMachinesStorageDetails = virtualMachinesStorageDetails;
}
private ComputePoolStorageUsageDetail() {
//For JAXB
}
public ResourceCapacity getAllocated() {
return allocated;
}
public VirtualMachinesStorageDetails getVirtualMachinesStorageDetails() {
return virtualMachinesStorageDetails;
}
@Override
public String string() {
return super.string()+", allocated="+ allocated +", virtualMachinesStorageDetails="+ virtualMachinesStorageDetails;
}
}

View File

@ -0,0 +1,204 @@
/**
* 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.storage;
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 org.jclouds.tmrk.enterprisecloud.domain.internal.ResourceCapacity;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import java.net.URI;
import java.util.Map;
import java.util.Set;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* VirtualMachineStorageUsageDetail is more than a simple wrapper as it extends Resource.
* <xs:complexType name="VirtualMachineStorageUsageDetail">
* @author Jason King
*
*/
@XmlRootElement(name = "VirtualMachineStorageUsageDetail")
public class VirtualMachineStorageUsageDetail extends Resource<VirtualMachineStorageUsageDetail> {
@SuppressWarnings("unchecked")
public static Builder builder() {
return new Builder();
}
/**
* {@inheritDoc}
*/
@Override
public Builder toBuilder() {
return new Builder().fromVirtualMachineStorageUsageDetail(this);
}
public static class Builder extends Resource.Builder<VirtualMachineStorageUsageDetail> {
private int diskCount;
private ResourceCapacity allocated;
/**
* @see VirtualMachineStorageUsageDetail#getDiskCount
*/
public Builder diskCount(int diskCount) {
this.diskCount =(checkNotNull(diskCount,"diskCount"));
return this;
}
/**
* @see VirtualMachineStorageUsageDetail#getAllocated
*/
public Builder allocated(ResourceCapacity allocated) {
this.allocated =(checkNotNull(allocated,"allocated"));
return this;
}
@Override
public VirtualMachineStorageUsageDetail build() {
return new VirtualMachineStorageUsageDetail(href, type, name, links, actions, diskCount, allocated);
}
public Builder fromVirtualMachineStorageUsageDetail(VirtualMachineStorageUsageDetail in) {
return fromResource(in).diskCount(in.getDiskCount()).allocated(in.getAllocated());
}
/**
* {@inheritDoc}
*/
@Override
public Builder fromBaseResource(BaseResource<VirtualMachineStorageUsageDetail> in) {
return Builder.class.cast(super.fromBaseResource(in));
}
/**
* {@inheritDoc}
*/
@Override
public Builder fromResource(Resource<VirtualMachineStorageUsageDetail> 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 = "DiskCount", required = true)
private int diskCount;
@XmlElement(name = "Allocated", required = false)
private ResourceCapacity allocated;
private VirtualMachineStorageUsageDetail(URI href, String type, String name, Set<Link> links, Set<Action> actions, int diskCount, @Nullable ResourceCapacity allocated) {
super(href, type, name, links, actions);
this.diskCount = diskCount;
this.allocated = allocated;
}
private VirtualMachineStorageUsageDetail() {
//For JAXB
}
public int getDiskCount() {
return diskCount;
}
public ResourceCapacity getAllocated() {
return allocated;
}
@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;
VirtualMachineStorageUsageDetail that = (VirtualMachineStorageUsageDetail) o;
if (diskCount != that.diskCount) return false;
if (allocated != null ? !allocated.equals(that.allocated) : that.allocated != null)
return false;
return true;
}
@Override
public int hashCode() {
int result = super.hashCode();
result = 31 * result + diskCount;
result = 31 * result + (allocated != null ? allocated.hashCode() : 0);
return result;
}
@Override
public String string() {
return super.string()+", diskCount="+ diskCount +", allocated="+ allocated;
}
}

View File

@ -0,0 +1,107 @@
/**
* 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.storage;
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 VirtualMachineStorageUsageDetail elements.
* <xs:complexType name="StorageDetails_VirtualMachines">
* @author Jason King
*/
public class VirtualMachinesStorageDetails {
@SuppressWarnings("unchecked")
public static Builder builder() {
return new Builder();
}
public Builder toBuilder() {
return new Builder().fromStorageUsageDetails(this);
}
public static class Builder {
private Set<VirtualMachineStorageUsageDetail> virtualMachinesStorageUsageDetail = Sets.newLinkedHashSet();
/**
* @see org.jclouds.tmrk.enterprisecloud.domain.resource.storage.VirtualMachinesStorageDetails#getVirtualMachinesStorageUsageDetail
*/
public Builder vmStorageUsageDetails(Set<VirtualMachineStorageUsageDetail> vmStorageUsageDetails) {
this.virtualMachinesStorageUsageDetail = Sets.newLinkedHashSet(checkNotNull(vmStorageUsageDetails, "vmStorageUsageDetails"));
return this;
}
public Builder addVmStorageUsageDetail(VirtualMachineStorageUsageDetail vmStorageUsageDetails) {
virtualMachinesStorageUsageDetail.add(checkNotNull(vmStorageUsageDetails,"vmStorageUsageDetails"));
return this;
}
public VirtualMachinesStorageDetails build() {
return new VirtualMachinesStorageDetails(virtualMachinesStorageUsageDetail);
}
public Builder fromStorageUsageDetails(VirtualMachinesStorageDetails in) {
return vmStorageUsageDetails(in.getVirtualMachinesStorageUsageDetail());
}
}
private VirtualMachinesStorageDetails() {
//For JAXB and builder use
}
private VirtualMachinesStorageDetails(Set<VirtualMachineStorageUsageDetail> virtualMachinesStorageUsageDetail) {
this.virtualMachinesStorageUsageDetail = Sets.newLinkedHashSet(virtualMachinesStorageUsageDetail);
}
@XmlElement(name = "VirtualMachine", required=false)
private Set<VirtualMachineStorageUsageDetail> virtualMachinesStorageUsageDetail = Sets.newLinkedHashSet();
public Set<VirtualMachineStorageUsageDetail> getVirtualMachinesStorageUsageDetail() {
return Collections.unmodifiableSet(virtualMachinesStorageUsageDetail);
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
VirtualMachinesStorageDetails that = (VirtualMachinesStorageDetails) o;
if (virtualMachinesStorageUsageDetail != null ? !virtualMachinesStorageUsageDetail.equals(that.virtualMachinesStorageUsageDetail) : that.virtualMachinesStorageUsageDetail != null)
return false;
return true;
}
@Override
public int hashCode() {
return virtualMachinesStorageUsageDetail != null ? virtualMachinesStorageUsageDetail.hashCode() : 0;
}
public String toString() {
return "["+ virtualMachinesStorageUsageDetail.toString()+"]";
}
}

View File

@ -28,6 +28,7 @@ import org.jclouds.tmrk.enterprisecloud.domain.resource.ComputePoolResourceSumma
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.jclouds.tmrk.enterprisecloud.domain.resource.memory.ComputePoolMemoryUsage;
import org.jclouds.tmrk.enterprisecloud.domain.resource.memory.ComputePoolMemoryUsageDetail; import org.jclouds.tmrk.enterprisecloud.domain.resource.memory.ComputePoolMemoryUsageDetail;
import org.jclouds.tmrk.enterprisecloud.domain.resource.storage.ComputePoolStorageUsageDetail;
import javax.ws.rs.Consumes; import javax.ws.rs.Consumes;
import javax.ws.rs.GET; import javax.ws.rs.GET;
@ -100,4 +101,13 @@ public interface ResourceAsyncClient {
@JAXBResponseParser @JAXBResponseParser
@ExceptionParser(ReturnNullOnNotFoundOr404.class) @ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<ComputePoolMemoryUsageDetail> getComputePoolMemoryUsageDetail(@EndpointParam URI uri); ListenableFuture<ComputePoolMemoryUsageDetail> getComputePoolMemoryUsageDetail(@EndpointParam URI uri);
/**
* @see ResourceClient#getComputePoolStorageUsage
*/
@GET
@Consumes("application/vnd.tmrk.cloud.computePoolStorageUsageDetail")
@JAXBResponseParser
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<ComputePoolStorageUsageDetail> getComputePoolStorageUsage(@EndpointParam URI uri);
} }

View File

@ -25,6 +25,7 @@ import org.jclouds.tmrk.enterprisecloud.domain.resource.ComputePoolResourceSumma
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.jclouds.tmrk.enterprisecloud.domain.resource.memory.ComputePoolMemoryUsage;
import org.jclouds.tmrk.enterprisecloud.domain.resource.memory.ComputePoolMemoryUsageDetail; import org.jclouds.tmrk.enterprisecloud.domain.resource.memory.ComputePoolMemoryUsageDetail;
import org.jclouds.tmrk.enterprisecloud.domain.resource.storage.ComputePoolStorageUsageDetail;
import java.net.URI; import java.net.URI;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@ -131,4 +132,14 @@ public interface ResourceClient {
* @return the compute pool memory usage detail * @return the compute pool memory usage detail
*/ */
ComputePoolMemoryUsageDetail getComputePoolMemoryUsageDetail(URI uri); ComputePoolMemoryUsageDetail getComputePoolMemoryUsageDetail(URI uri);
/**
* The Get Resources Usage Storage call returns information regarding current storage usage
* for a specified compute pool defined in an environment for active virtual machines.
* The response includes usage of every active virtual machine.
* @param uri the uri of the call based upon the compute pool
* e.g. /cloudapi/ecloud/computepools/{id}/usage/storage
* @return the compute pool storage usage detail
*/
ComputePoolStorageUsageDetail getComputePoolStorageUsage(URI uri);
} }

View File

@ -128,6 +128,21 @@ public class ResourceAsyncClientTest extends BaseTerremarkEnterpriseCloudAsyncCl
checkFilters(httpRequest); checkFilters(httpRequest);
} }
public void testGetComputePoolStorageUsage() throws SecurityException, NoSuchMethodException, IOException, URISyntaxException {
Method method = ResourceAsyncClient.class.getMethod("getComputePoolStorageUsage", URI.class);
HttpRequest httpRequest = processor.createRequest(method, URI.create("/cloudapi/ecloud/computepools/89/usage/storage"));
assertRequestLineEquals(httpRequest, "GET https://services-beta.enterprisecloud.terremark.com/cloudapi/ecloud/computepools/89/usage/storage HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest,
"Accept: application/vnd.tmrk.cloud.computePoolStorageUsageDetail\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

@ -26,6 +26,7 @@ import org.jclouds.tmrk.enterprisecloud.domain.resource.ComputePoolResourceSumma
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.jclouds.tmrk.enterprisecloud.domain.resource.memory.ComputePoolMemoryUsage;
import org.jclouds.tmrk.enterprisecloud.domain.resource.memory.ComputePoolMemoryUsageDetail; import org.jclouds.tmrk.enterprisecloud.domain.resource.memory.ComputePoolMemoryUsageDetail;
import org.jclouds.tmrk.enterprisecloud.domain.resource.storage.ComputePoolStorageUsageDetail;
import org.testng.annotations.BeforeGroups; import org.testng.annotations.BeforeGroups;
import org.testng.annotations.Test; import org.testng.annotations.Test;
@ -114,4 +115,9 @@ public class ResourceClientLiveTest extends BaseTerremarkEnterpriseCloudClientLi
ComputePoolMemoryUsageDetail detail = client.getComputePoolMemoryUsageDetail(uri); ComputePoolMemoryUsageDetail detail = client.getComputePoolMemoryUsageDetail(uri);
assertNotNull(detail.getTime()); assertNotNull(detail.getTime());
} }
public void testGetComputePoolStorageUsage() throws Exception {
ComputePoolStorageUsageDetail usage = client.getComputePoolStorageUsage(URI.create("/cloudapi/ecloud/computepools/89/usage/storage"));
assertNotNull(usage);
}
} }

View File

@ -0,0 +1,120 @@
/**
* 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.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.internal.ResourceCapacity;
import org.jclouds.tmrk.enterprisecloud.domain.resource.storage.ComputePoolStorageUsageDetail;
import org.jclouds.tmrk.enterprisecloud.domain.resource.storage.VirtualMachineStorageUsageDetail;
import org.jclouds.tmrk.enterprisecloud.features.ResourceAsyncClient;
import org.testng.annotations.BeforeClass;
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;
/**
* Tests behavior of JAXB parsing for ComputePoolStorageUsageDetail
*
* @author Jason King
*/
@Test(groups = "unit", testName = "ComputePoolStorageUsageDetailJAXBParsingTest")
public class ComputePoolStorageUsageDetailJAXBParsingTest extends BaseRestClientTest {
@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("getComputePoolStorageUsage", URI.class);
HttpRequest request = factory(ResourceAsyncClient.class).createRequest(method,new URI("/1"));
assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class);
Function<HttpResponse, ComputePoolStorageUsageDetail> parser = (Function<HttpResponse, ComputePoolStorageUsageDetail>) RestAnnotationProcessor
.createResponseParser(parserFactory, injector, method, request);
InputStream is = getClass().getResourceAsStream("/computePoolStorageUsage.xml");
ComputePoolStorageUsageDetail storageUsageDetail = parser.apply(new HttpResponse(200, "ok", newInputStreamPayload(is)));
assertLinks(storageUsageDetail.getLinks());
assertEquals(storageUsageDetail.getAllocated(), ResourceCapacity.builder().value(10).unit("GB").build());
assertStorageDetails(storageUsageDetail.getVirtualMachinesStorageDetails().getVirtualMachinesStorageUsageDetail());
}
private void assertStorageDetails(Set<VirtualMachineStorageUsageDetail> virtualMachinesStorageUsageDetail) {
assertEquals(1, virtualMachinesStorageUsageDetail.size());
VirtualMachineStorageUsageDetail detail = Iterables.getOnlyElement(virtualMachinesStorageUsageDetail);
assertEquals(detail.getDiskCount(),1);
assertEquals(detail.getAllocated(), ResourceCapacity.builder().value(10).unit("GB").build());
}
private void assertLinks(Set<Link> links) {
assertEquals(links.size(),1);
Link link = Iterables.get(links, 0);
assertEquals(link.getName(),"Default Compute Pool");
assertEquals(link.getRelationship(), Link.Relationship.UP);
}
}

View File

@ -0,0 +1,25 @@
<ComputePoolStorageUsageDetail
href="/cloudapi/ecloud/computepools/89/usage/storage"
type="application/vnd.tmrk.cloud.computePoolStorageUsageDetail"
xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<Links>
<Link href="/cloudapi/ecloud/computepools/89"
name="Default Compute Pool"
type="application/vnd.tmrk.cloud.computePool" rel="up"/>
</Links>
<Allocated>
<Unit>GB</Unit>
<Value>10</Value>
</Allocated>
<VirtualMachines>
<VirtualMachine href="/cloudapi/ecloud/virtualmachines/5504"
name="helloworld"
type="application/vnd.tmrk.cloud.virtualMachine">
<DiskCount>1</DiskCount>
<Allocated>
<Unit>GB</Unit>
<Value>10</Value>
</Allocated>
</VirtualMachine>
</VirtualMachines>
</ComputePoolStorageUsageDetail>