diff --git a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/template/Templates.java b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/template/Templates.java new file mode 100644 index 0000000000..f5ea7f90a9 --- /dev/null +++ b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/template/Templates.java @@ -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; + +/** + * + * @author Jason King + * + */ +@XmlRootElement(name = "Templates") +public class Templates extends BaseResource { + + + @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 { + private Links links = Links.builder().build(); + + /** + * @see Templates#getLinks + */ + public Builder links(Set 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 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 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 getLinks() { + return Collections.unmodifiableSet(links.getLinks()); + } + + @Override + public String string() { + return super.string()+", links="+links; + } +} \ No newline at end of file diff --git a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/features/TemplateAsyncClient.java b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/features/TemplateAsyncClient.java index a8258fe661..b49f4a7587 100644 --- a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/features/TemplateAsyncClient.java +++ b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/features/TemplateAsyncClient.java @@ -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.template.Template; +import org.jclouds.tmrk.enterprisecloud.domain.template.Templates; 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 TemplateAsyncClient { + /** + * @see org.jclouds.tmrk.enterprisecloud.features.TemplateClient#getTemplates + */ + @GET + @Consumes("application/vnd.tmrk.cloud.template; type=collection") + @JAXBResponseParser + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + ListenableFuture getTemplates(@EndpointParam URI uri); + /** * @see org.jclouds.tmrk.enterprisecloud.features.TemplateClient#getTemplate */ diff --git a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/features/TemplateClient.java b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/features/TemplateClient.java index 7c79be6d78..b52350c0b4 100644 --- a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/features/TemplateClient.java +++ b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/features/TemplateClient.java @@ -20,6 +20,7 @@ package org.jclouds.tmrk.enterprisecloud.features; import org.jclouds.concurrent.Timeout; import org.jclouds.tmrk.enterprisecloud.domain.template.Template; +import org.jclouds.tmrk.enterprisecloud.domain.template.Templates; import java.net.URI; import java.util.concurrent.TimeUnit; @@ -37,6 +38,15 @@ import java.util.concurrent.TimeUnit; @Timeout(duration = 180, timeUnit = TimeUnit.SECONDS) 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 * @param uri the uri of the template diff --git a/sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/features/TemplateAsyncClientTest.java b/sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/features/TemplateAsyncClientTest.java index 4cb0e759c2..0c6a2abe2f 100644 --- a/sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/features/TemplateAsyncClientTest.java +++ b/sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/features/TemplateAsyncClientTest.java @@ -38,6 +38,21 @@ import java.net.URISyntaxException; @Test(groups = "unit", testName = "TemplateAsyncClientTest") public class TemplateAsyncClientTest extends BaseTerremarkEnterpriseCloudAsyncClientTest { + 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 { Method method = TemplateAsyncClient.class.getMethod("getTemplate", URI.class); HttpRequest httpRequest = processor.createRequest(method, new URI("/cloudapi/ecloud/templates/6/computepools/89"));