mirror of https://github.com/apache/jclouds.git
Issue 695: Added ComputePoolResourceSummaryList class, service call and tests
This commit is contained in:
parent
5e854c8a6b
commit
2849284777
|
@ -0,0 +1,188 @@
|
|||
/**
|
||||
* 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;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
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.Collections;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
* ComputePoolResourceSummaryList is more than a simple wrapper as it extends Resource.
|
||||
* <xs:complexType name="ComputePoolResourceSummaryList">
|
||||
* @author Jason King
|
||||
*
|
||||
*/
|
||||
@XmlRootElement(name = "ComputePoolResourceSummaryList")
|
||||
public class ComputePoolResourceSummaryList extends Resource<ComputePoolResourceSummaryList> {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static Builder builder() {
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Builder toBuilder() {
|
||||
return new Builder().fromSummaryList(this);
|
||||
}
|
||||
|
||||
public static class Builder extends Resource.Builder<ComputePoolResourceSummaryList> {
|
||||
private Set<ComputePoolResourceSummary> summaries = Sets.newLinkedHashSet();
|
||||
|
||||
/**
|
||||
* @see org.jclouds.tmrk.enterprisecloud.domain.resource.ComputePoolResourceSummaryList#getComputePoolResourceSummaries
|
||||
*/
|
||||
public Builder summaries(Set<ComputePoolResourceSummary> summaries) {
|
||||
this.summaries =(checkNotNull(summaries,"summaries"));
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ComputePoolResourceSummaryList build() {
|
||||
return new ComputePoolResourceSummaryList(href, type, name, links, actions, summaries);
|
||||
}
|
||||
|
||||
public Builder fromSummaryList(ComputePoolResourceSummaryList in) {
|
||||
return fromResource(in).summaries(in.getComputePoolResourceSummaries());
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Builder fromBaseResource(BaseResource<ComputePoolResourceSummaryList> in) {
|
||||
return Builder.class.cast(super.fromBaseResource(in));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Builder fromResource(Resource<ComputePoolResourceSummaryList> 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 = "ComputePoolResourceSummary")
|
||||
private Set<ComputePoolResourceSummary> summaries = Sets.newLinkedHashSet();
|
||||
|
||||
private ComputePoolResourceSummaryList(URI href, String type, String name, Set<Link> links, Set<Action> actions, Set<ComputePoolResourceSummary> summaries) {
|
||||
super(href, type, name, links, actions);
|
||||
this.summaries = checkNotNull(summaries,"summaries");
|
||||
}
|
||||
|
||||
private ComputePoolResourceSummaryList() {
|
||||
//For JAXB
|
||||
}
|
||||
|
||||
public Set<Link> getLinks() {
|
||||
return Collections.unmodifiableSet(links.getLinks());
|
||||
}
|
||||
|
||||
public Set<ComputePoolResourceSummary> getComputePoolResourceSummaries() {
|
||||
return summaries;
|
||||
}
|
||||
|
||||
@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;
|
||||
|
||||
ComputePoolResourceSummaryList that = (ComputePoolResourceSummaryList) o;
|
||||
|
||||
if (!summaries.equals(that.summaries)) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = super.hashCode();
|
||||
result = 31 * result + summaries.hashCode();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String string() {
|
||||
return super.string()+", summaries="+summaries;
|
||||
}
|
||||
}
|
|
@ -23,6 +23,7 @@ import org.jclouds.http.filters.BasicAuthentication;
|
|||
import org.jclouds.rest.annotations.*;
|
||||
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
|
||||
import org.jclouds.tmrk.enterprisecloud.domain.resource.ComputePoolResourceSummary;
|
||||
import org.jclouds.tmrk.enterprisecloud.domain.resource.ComputePoolResourceSummaryList;
|
||||
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.GET;
|
||||
|
@ -42,6 +43,15 @@ import java.net.URI;
|
|||
@Headers(keys = "x-tmrk-version", values = "{jclouds.api-version}")
|
||||
public interface ResourceAsyncClient {
|
||||
|
||||
/**
|
||||
* @see ResourceClient#getResourceSummary
|
||||
*/
|
||||
@GET
|
||||
@Consumes("application/vnd.tmrk.cloud.computePoolResourceSummary; type=collection")
|
||||
@JAXBResponseParser
|
||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||
ListenableFuture<ComputePoolResourceSummaryList> getResourceSummaries(@EndpointParam URI uri);
|
||||
|
||||
/**
|
||||
* @see ResourceClient#getResourceSummary
|
||||
*/
|
||||
|
|
|
@ -20,6 +20,7 @@ package org.jclouds.tmrk.enterprisecloud.features;
|
|||
|
||||
import org.jclouds.concurrent.Timeout;
|
||||
import org.jclouds.tmrk.enterprisecloud.domain.resource.ComputePoolResourceSummary;
|
||||
import org.jclouds.tmrk.enterprisecloud.domain.resource.ComputePoolResourceSummaryList;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
@ -38,8 +39,19 @@ import java.util.concurrent.TimeUnit;
|
|||
public interface ResourceClient {
|
||||
|
||||
/**
|
||||
* The Get Resources Summary call returns resource summary information regarding a specified compute pool defined in an environment.
|
||||
* @param uri the uri of the compute pool
|
||||
* The Get Resources Summary List call returns summary information regarding
|
||||
* resource utilization in the compute pools defined in an environment.
|
||||
* @param uri the uri of the call based upon the environment
|
||||
* e.g. /cloudapi/ecloud/computepools/environments/{id}/resourcesummarylist
|
||||
* @return the summary list
|
||||
*/
|
||||
ComputePoolResourceSummaryList getResourceSummaries(URI uri);
|
||||
|
||||
/**
|
||||
* The Get Resources Summary call returns resource summary information regarding
|
||||
* a specified compute pool defined in an environment.
|
||||
* @param uri the uri of the call based upon the compute pool
|
||||
* e.g. /cloudapi/ecloud/computepools/{id}/resourcesummary
|
||||
* @return the summary
|
||||
*/
|
||||
ComputePoolResourceSummary getResourceSummary(URI uri);
|
||||
|
|
|
@ -38,6 +38,21 @@ import java.net.URISyntaxException;
|
|||
@Test(groups = "unit", testName = "ResourceAsyncClient")
|
||||
public class ResourceAsyncClientTest extends BaseTerremarkEnterpriseCloudAsyncClientTest<ResourceAsyncClient> {
|
||||
|
||||
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"));
|
||||
|
||||
assertRequestLineEquals(httpRequest, "GET https://services-beta.enterprisecloud.terremark.com/cloudapi/ecloud/computepools/environments/77/resourcesummarylist HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest,
|
||||
"Accept: application/vnd.tmrk.cloud.computePoolResourceSummary; type=collection\nx-tmrk-version: 2011-07-01\n");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest, ParseXMLWithJAXB.class);
|
||||
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
|
||||
|
||||
checkFilters(httpRequest);
|
||||
}
|
||||
|
||||
public void testGetResourceSummary() throws SecurityException, NoSuchMethodException, IOException, URISyntaxException {
|
||||
Method method = ResourceAsyncClient.class.getMethod("getResourceSummary", URI.class);
|
||||
HttpRequest httpRequest = processor.createRequest(method, new URI("/cloudapi/ecloud/computepools/89/resourcesummary"));
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
package org.jclouds.tmrk.enterprisecloud.features;
|
||||
|
||||
import org.jclouds.tmrk.enterprisecloud.domain.resource.ComputePoolResourceSummary;
|
||||
import org.jclouds.tmrk.enterprisecloud.domain.resource.ComputePoolResourceSummaryList;
|
||||
import org.testng.annotations.BeforeGroups;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
|
@ -42,6 +43,15 @@ public class ResourceClientLiveTest extends BaseTerremarkEnterpriseCloudClientLi
|
|||
|
||||
private ResourceClient client;
|
||||
|
||||
public void testGetResourceSummaries() throws Exception {
|
||||
ComputePoolResourceSummaryList list = client.getResourceSummaries(URI.create("/cloudapi/ecloud/computepools/environments/77/resourcesummarylist"));
|
||||
assertNotNull(list);
|
||||
}
|
||||
|
||||
public void testMissingResourceSummaries() {
|
||||
assertNull(client.getResourceSummaries(URI.create("/cloudapi/ecloud/computepools/environments/-1/resourcesummarylist")));
|
||||
}
|
||||
|
||||
public void testGetResourceSummary() throws Exception {
|
||||
ComputePoolResourceSummary resourceSummary = client.getResourceSummary(URI.create("/cloudapi/ecloud/computepools/89/resourcesummary"));
|
||||
assertNotNull(resourceSummary);
|
||||
|
|
Loading…
Reference in New Issue