Issue 695: Added Templates class, and client call to retrieve them

This commit is contained in:
Jason King 2011-11-24 18:03:10 +00:00
parent 2595aa5b7b
commit 81605f1258
4 changed files with 165 additions and 0 deletions

View File

@ -0,0 +1,130 @@
/**
* 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.template;
import org.jclouds.tmrk.enterprisecloud.domain.Link;
import org.jclouds.tmrk.enterprisecloud.domain.Links;
import org.jclouds.tmrk.enterprisecloud.domain.internal.BaseResource;
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;
/**
* <xs:complexType name="Templates">
* @author Jason King
*
*/
@XmlRootElement(name = "Templates")
public class Templates extends BaseResource<Templates> {
@SuppressWarnings("unchecked")
public static Builder builder() {
return new Builder();
}
/**
* {@inheritDoc}
*/
@Override
public Builder toBuilder() {
return new Builder().fromTemplates(this);
}
public static class Builder extends BaseResource.Builder<Templates> {
private Links links = Links.builder().build();
/**
* @see Templates#getLinks
*/
public Builder links(Set<Link> links) {
this.links = Links.builder().links(checkNotNull(links,"links")).build();
return this;
}
@Override
public Templates build() {
return new Templates(href, type, links);
}
public Builder fromTemplates(Templates in) {
return fromResource(in).links(in.getLinks());
}
/**
* {@inheritDoc}
*/
@Override
public Builder fromResource(BaseResource<Templates> 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 fromAttributes(Map<String, String> attributes) {
return Builder.class.cast(super.fromAttributes(attributes));
}
}
@XmlElement(name = "Links", required = true)
private Links links = Links.builder().build();
public Templates(URI href, String type, Links links ) {
super(href, type);
this.links = checkNotNull(links, "links");
}
protected Templates() {
//For JAXB
}
public Set<Link> getLinks() {
return Collections.unmodifiableSet(links.getLinks());
}
@Override
public String string() {
return super.string()+", links="+links;
}
}

View File

@ -23,6 +23,7 @@ import org.jclouds.http.filters.BasicAuthentication;
import org.jclouds.rest.annotations.*; import org.jclouds.rest.annotations.*;
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
import org.jclouds.tmrk.enterprisecloud.domain.template.Template; import org.jclouds.tmrk.enterprisecloud.domain.template.Template;
import org.jclouds.tmrk.enterprisecloud.domain.template.Templates;
import javax.ws.rs.Consumes; import javax.ws.rs.Consumes;
import javax.ws.rs.GET; import javax.ws.rs.GET;
@ -42,6 +43,15 @@ import java.net.URI;
@Headers(keys = "x-tmrk-version", values = "{jclouds.api-version}") @Headers(keys = "x-tmrk-version", values = "{jclouds.api-version}")
public interface TemplateAsyncClient { public interface TemplateAsyncClient {
/**
* @see org.jclouds.tmrk.enterprisecloud.features.TemplateClient#getTemplates
*/
@GET
@Consumes("application/vnd.tmrk.cloud.template; type=collection")
@JAXBResponseParser
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<Templates> getTemplates(@EndpointParam URI uri);
/** /**
* @see org.jclouds.tmrk.enterprisecloud.features.TemplateClient#getTemplate * @see org.jclouds.tmrk.enterprisecloud.features.TemplateClient#getTemplate
*/ */

View File

@ -20,6 +20,7 @@ package org.jclouds.tmrk.enterprisecloud.features;
import org.jclouds.concurrent.Timeout; import org.jclouds.concurrent.Timeout;
import org.jclouds.tmrk.enterprisecloud.domain.template.Template; import org.jclouds.tmrk.enterprisecloud.domain.template.Template;
import org.jclouds.tmrk.enterprisecloud.domain.template.Templates;
import java.net.URI; import java.net.URI;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@ -37,6 +38,15 @@ import java.util.concurrent.TimeUnit;
@Timeout(duration = 180, timeUnit = TimeUnit.SECONDS) @Timeout(duration = 180, timeUnit = TimeUnit.SECONDS)
public interface TemplateClient { public interface TemplateClient {
/**
* The Get Templates call returns information regarding templates defined in a compute pool.
* Note that Templates are not a simple wrapper around template objects.
* Once the desired template is located getTemplate must be called to retrieve all the attached information
* @param uri compute pool identifier
* @return the templates
*/
Templates getTemplates(URI uri);
/** /**
* The Get Templates by ID call returns information regarding a specified template defined in a compute pool * The Get Templates by ID call returns information regarding a specified template defined in a compute pool
* @param uri the uri of the template * @param uri the uri of the template

View File

@ -38,6 +38,21 @@ import java.net.URISyntaxException;
@Test(groups = "unit", testName = "TemplateAsyncClientTest") @Test(groups = "unit", testName = "TemplateAsyncClientTest")
public class TemplateAsyncClientTest extends BaseTerremarkEnterpriseCloudAsyncClientTest<TemplateAsyncClient> { public class TemplateAsyncClientTest extends BaseTerremarkEnterpriseCloudAsyncClientTest<TemplateAsyncClient> {
public void testGetTemplates() throws SecurityException, NoSuchMethodException, IOException, URISyntaxException {
Method method = TemplateAsyncClient.class.getMethod("getTemplates", URI.class);
HttpRequest httpRequest = processor.createRequest(method, new URI("/cloudapi/ecloud/templates/computepools/89"));
assertRequestLineEquals(httpRequest, "GET https://services-beta.enterprisecloud.terremark.com/cloudapi/ecloud/templates/computepools/89 HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest,
"Accept: application/vnd.tmrk.cloud.template; 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 testGetTemplate() throws SecurityException, NoSuchMethodException, IOException, URISyntaxException { public void testGetTemplate() throws SecurityException, NoSuchMethodException, IOException, URISyntaxException {
Method method = TemplateAsyncClient.class.getMethod("getTemplate", URI.class); Method method = TemplateAsyncClient.class.getMethod("getTemplate", URI.class);
HttpRequest httpRequest = processor.createRequest(method, new URI("/cloudapi/ecloud/templates/6/computepools/89")); HttpRequest httpRequest = processor.createRequest(method, new URI("/cloudapi/ecloud/templates/6/computepools/89"));