diff --git a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/TerremarkEnterpriseCloudAsyncClient.java b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/TerremarkEnterpriseCloudAsyncClient.java index dbcb6469b6..d027306aac 100644 --- a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/TerremarkEnterpriseCloudAsyncClient.java +++ b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/TerremarkEnterpriseCloudAsyncClient.java @@ -19,9 +19,7 @@ package org.jclouds.tmrk.enterprisecloud; import org.jclouds.rest.annotations.Delegate; -import org.jclouds.tmrk.enterprisecloud.features.TaskAsyncClient; -import org.jclouds.tmrk.enterprisecloud.features.TemplateAsyncClient; -import org.jclouds.tmrk.enterprisecloud.features.VirtualMachineAsyncClient; +import org.jclouds.tmrk.enterprisecloud.features.*; /** * Provides asynchronous access to TerremarkEnterpriseCloud via their REST API. @@ -35,6 +33,12 @@ import org.jclouds.tmrk.enterprisecloud.features.VirtualMachineAsyncClient; */ public interface TerremarkEnterpriseCloudAsyncClient { + /** + * Provides asynchronous access to Location features. + */ + @Delegate + LocationAsyncClient getLocationClient(); + /** * Provides asynchronous access to Task features. */ diff --git a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/TerremarkEnterpriseCloudClient.java b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/TerremarkEnterpriseCloudClient.java index a787096bf7..fe56af6939 100644 --- a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/TerremarkEnterpriseCloudClient.java +++ b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/TerremarkEnterpriseCloudClient.java @@ -22,6 +22,7 @@ import java.util.concurrent.TimeUnit; import org.jclouds.concurrent.Timeout; import org.jclouds.rest.annotations.Delegate; +import org.jclouds.tmrk.enterprisecloud.features.LocationClient; import org.jclouds.tmrk.enterprisecloud.features.TaskClient; import org.jclouds.tmrk.enterprisecloud.features.TemplateClient; import org.jclouds.tmrk.enterprisecloud.features.VirtualMachineClient; @@ -39,6 +40,12 @@ import org.jclouds.tmrk.enterprisecloud.features.VirtualMachineClient; @Timeout(duration = 180, timeUnit = TimeUnit.SECONDS) public interface TerremarkEnterpriseCloudClient { + /** + * Provides synchronous access to Location features. + */ + @Delegate + LocationClient getLocationClient(); + /** * Provides synchronous access to Task features. */ diff --git a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/config/TerremarkEnterpriseCloudRestClientModule.java b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/config/TerremarkEnterpriseCloudRestClientModule.java index 4d3befe166..54edcb2040 100644 --- a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/config/TerremarkEnterpriseCloudRestClientModule.java +++ b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/config/TerremarkEnterpriseCloudRestClientModule.java @@ -47,6 +47,7 @@ public class TerremarkEnterpriseCloudRestClientModule extends RestClientModule { public static final Map, Class> DELEGATE_MAP = ImmutableMap., Class> builder() + .put(LocationClient.class, LocationAsyncClient.class) .put(TaskClient.class, TaskAsyncClient.class) .put(VirtualMachineClient.class, VirtualMachineAsyncClient.class) .put(TemplateClient.class, TemplateAsyncClient.class) diff --git a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/Location.java b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/Location.java new file mode 100644 index 0000000000..343c658933 --- /dev/null +++ b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/Location.java @@ -0,0 +1,221 @@ +/** + * 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; + +import org.jclouds.javax.annotation.Nullable; +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.Map; +import java.util.Set; + +/** + * + * @author Jason King + * + */ +@XmlRootElement(name = "Location") +public class Location extends Resource { + + + @SuppressWarnings("unchecked") + public static Builder builder() { + return new Builder(); + } + + /** + * {@inheritDoc} + */ + @Override + public Builder toBuilder() { + return new Builder().fromTask(this); + } + + public static class Builder extends Resource.Builder { + private String friendlyName; + private String locode; + private String iso3166; + + /** + * @see org.jclouds.tmrk.enterprisecloud.domain.Location#getFriendlyName + */ + public Builder friendlyName(String friendlyName) { + this.friendlyName = friendlyName; + return this; + } + + /** + * @see org.jclouds.tmrk.enterprisecloud.domain.Location#getLocode + */ + public Builder locode(String locode) { + this.locode = locode; + return this; + } + + /** + * @see org.jclouds.tmrk.enterprisecloud.domain.Location#getIso3166 + */ + public Builder iso3166(String iso3166) { + this.iso3166 = iso3166; + return this; + } + + @Override + public Location build() { + return new Location(href, type, name, links, + actions, friendlyName, locode, iso3166); + } + + public Builder fromTask(Location in) { + return fromResource(in).friendlyName(in.getFriendlyName()).locode(in.getLocode()).iso3166(in.getIso3166()); + } + + /** + * {@inheritDoc} + */ + @Override + public Builder fromBaseResource(BaseResource in) { + return Builder.class.cast(super.fromBaseResource(in)); + } + + /** + * {@inheritDoc} + */ + @Override + public Builder fromResource(Resource 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 links) { + return Builder.class.cast(super.links(links)); + } + + /** + * {@inheritDoc} + */ + @Override + public Builder actions(Set actions) { + return Builder.class.cast(super.actions(actions)); + } + + /** + * {@inheritDoc} + */ + @Override + public Builder fromAttributes(Map attributes) { + return Builder.class.cast(super.fromAttributes(attributes)); + } + + } + + @XmlElement(name = "FriendlyName", required = true) + private String friendlyName; + + @XmlElement(name = "Locode", required = false) + private String locode; + + @XmlElement(name = "ISO3166", required = false) + private String iso3166; + + private Location(URI href, String type, String name, Set links, Set actions, @Nullable String friendlyName, @Nullable String locode, @Nullable String iso3166) { + super(href, type, name, links, actions); + this.friendlyName = friendlyName; + this.locode = locode; + this.iso3166 = iso3166; + } + + private Location() { + //For JAXB + } + + public String getFriendlyName() { + return friendlyName; + } + + public String getLocode() { + return locode; + } + + public String getIso3166() { + return iso3166; + } + + @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; + + Location location = (Location) o; + + if (friendlyName != null ? !friendlyName.equals(location.friendlyName) : location.friendlyName != null) + return false; + if (iso3166 != null ? !iso3166.equals(location.iso3166) : location.iso3166 != null) + return false; + if (locode != null ? !locode.equals(location.locode) : location.locode != null) + return false; + + return true; + } + + @Override + public int hashCode() { + int result = super.hashCode(); + result = 31 * result + (friendlyName != null ? friendlyName.hashCode() : 0); + result = 31 * result + (locode != null ? locode.hashCode() : 0); + result = 31 * result + (iso3166 != null ? iso3166.hashCode() : 0); + return result; + } + + @Override + public String string() { + return super.string()+", friendlyName="+friendlyName+", locode="+locode+", iso3166="+iso3166; + } +} \ No newline at end of file diff --git a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/features/LocationAsyncClient.java b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/features/LocationAsyncClient.java new file mode 100644 index 0000000000..aa53ea0da9 --- /dev/null +++ b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/features/LocationAsyncClient.java @@ -0,0 +1,54 @@ +/** + * 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.features; + +import com.google.common.util.concurrent.ListenableFuture; +import org.jclouds.http.filters.BasicAuthentication; +import org.jclouds.rest.annotations.*; +import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; +import org.jclouds.tmrk.enterprisecloud.domain.Location; + +import javax.ws.rs.Consumes; +import javax.ws.rs.GET; +import java.net.URI; + +/** + * Provides asynchronous access to Locations via their REST API. + *

+ * + * @see org.jclouds.tmrk.enterprisecloud.features.LocationClient + * @see + * @author Jason King + */ +@RequestFilters(BasicAuthentication.class) +@Headers(keys = "x-tmrk-version", values = "{jclouds.api-version}") +public interface LocationAsyncClient { + + /** + * @see org.jclouds.tmrk.enterprisecloud.features.LocationClient#getLocationById + */ + @GET + @Consumes("application/vnd.tmrk.cloud.location") + @JAXBResponseParser + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + ListenableFuture getLocationById(@EndpointParam URI uri); + +} diff --git a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/features/LocationClient.java b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/features/LocationClient.java new file mode 100644 index 0000000000..21e8e78747 --- /dev/null +++ b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/features/LocationClient.java @@ -0,0 +1,47 @@ +/** + * 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.features; + +import org.jclouds.concurrent.Timeout; +import org.jclouds.tmrk.enterprisecloud.domain.Location; + +import java.net.URI; +import java.util.concurrent.TimeUnit; + +/** + * Provides synchronous access to Location. + *

+ * + * @see org.jclouds.tmrk.enterprisecloud.features.LocationAsyncClient + * @see + * @author Jason King + */ +@Timeout(duration = 180, timeUnit = TimeUnit.SECONDS) +public interface LocationClient { + + /** + * The Get Locations by ID call returns information regarding a single data center location. + * @param uri the uri of the location + * @return the location + */ + Location getLocationById(URI uri); + +} diff --git a/sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/features/LocationAsyncClientTest.java b/sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/features/LocationAsyncClientTest.java new file mode 100644 index 0000000000..66878f5d3b --- /dev/null +++ b/sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/features/LocationAsyncClientTest.java @@ -0,0 +1,62 @@ +/** + * 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.features; + +import com.google.inject.TypeLiteral; +import org.jclouds.http.HttpRequest; +import org.jclouds.http.functions.ParseXMLWithJAXB; +import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; +import org.jclouds.rest.internal.RestAnnotationProcessor; +import org.testng.annotations.Test; + +import java.io.IOException; +import java.lang.reflect.Method; +import java.net.URI; +import java.net.URISyntaxException; + +/** + * Tests annotation parsing of {@code LocationAsyncClient} + * + * @author Jason King + */ +@Test(groups = "unit", testName = "LocationAsyncClientTest") +public class LocationAsyncClientTest extends BaseTerremarkEnterpriseCloudAsyncClientTest { + + public void testGetLocationById() throws SecurityException, NoSuchMethodException, IOException, URISyntaxException { + Method method = LocationAsyncClient.class.getMethod("getLocationById", URI.class); + HttpRequest httpRequest = processor.createRequest(method, new URI("/cloudapi/ecloud/locations/1")); + + assertRequestLineEquals(httpRequest, "GET https://services-beta.enterprisecloud.terremark.com/cloudapi/ecloud/locations/1 HTTP/1.1"); + assertNonPayloadHeadersEqual(httpRequest, + "Accept: application/vnd.tmrk.cloud.location\nx-tmrk-version: 2011-07-01\n"); + assertPayloadEquals(httpRequest, null, null, false); + + assertResponseParserClassEquals(method, httpRequest, ParseXMLWithJAXB.class); + assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); + + checkFilters(httpRequest); + } + + + @Override + protected TypeLiteral> createTypeLiteral() { + return new TypeLiteral>() { + }; + } +} diff --git a/sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/features/LocationClientLiveTest.java b/sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/features/LocationClientLiveTest.java new file mode 100644 index 0000000000..ffd76a0d40 --- /dev/null +++ b/sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/features/LocationClientLiveTest.java @@ -0,0 +1,55 @@ +/** + * 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.features; + +import org.jclouds.tmrk.enterprisecloud.domain.Location; +import org.testng.annotations.BeforeGroups; +import org.testng.annotations.Test; + +import java.net.URI; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNull; + +/** + * Tests behavior of {@code LocationClient} + * + * @author Jason King + */ +@Test(groups = "live", testName = "LocationClientLiveTest") +public class LocationClientLiveTest extends BaseTerremarkEnterpriseCloudClientLiveTest { + @BeforeGroups(groups = { "live" }) + public void setupClient() { + super.setupClient(); + client = context.getApi().getLocationClient(); + } + + private LocationClient client; + + public void testGetLocationById() throws Exception { + Location location = client.getLocationById(URI.create("/cloudapi/ecloud/locations/1")); + Location expected = Location.builder().href(URI.create("/cloudapi/ecloud/locations/1")).name("Terremark - Richardson").type("application/vnd.tmrk.cloud.location") + .friendlyName("Terremark - Richardson").locode("DAC").iso3166("US-TX").build(); + assertEquals(location,expected); + } + + public void testMissingLocation() { + assertNull(client.getLocationById(URI.create("/cloudapi/ecloud/locations/-1"))); + } +}