Issue 695: Converted api method calls to URI instead of primitives

This commit is contained in:
Jason King 2011-11-18 18:49:21 +00:00
parent 9852a579e9
commit 820bdf6f47
11 changed files with 47 additions and 63 deletions

View File

@ -28,8 +28,6 @@ import org.jclouds.tmrk.enterprisecloud.domain.Tasks;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import java.net.URI;
/**
@ -44,18 +42,16 @@ import java.net.URI;
*/
@RequestFilters(BasicAuthentication.class)
@Headers(keys = "x-tmrk-version", values = "{jclouds.api-version}")
//@VirtualHost
public interface TaskAsyncClient {
/**
* @see TaskClient#getTasksInEnvironment
*/
@GET
@Path("/tasks/environments/{environmentId}")
@Consumes("application/vnd.tmrk.cloud.task; type=collection")
@JAXBResponseParser
@ExceptionParser(ReturnEmptySetOnNotFoundOr404.class)
ListenableFuture<Tasks> getTasksInEnvironment(@PathParam("environmentId") long environmentId);
ListenableFuture<Tasks> getTasksInEnvironment(@EndpointParam URI environmentId);
/**
* @see TaskClient#getTask

View File

@ -44,7 +44,7 @@ public interface TaskClient {
*
* @return a history of changes to the environment.
*/
Tasks getTasksInEnvironment(long environmentId);
Tasks getTasksInEnvironment(URI environmentUri);
/**
* The Get Tasks by ID call returns information regarding a specified task in

View File

@ -20,10 +20,7 @@ package org.jclouds.tmrk.enterprisecloud.features;
import com.google.common.util.concurrent.ListenableFuture;
import org.jclouds.http.filters.BasicAuthentication;
import org.jclouds.rest.annotations.ExceptionParser;
import org.jclouds.rest.annotations.Headers;
import org.jclouds.rest.annotations.JAXBResponseParser;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.*;
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
import org.jclouds.tmrk.enterprisecloud.domain.AssignedIpAddresses;
import org.jclouds.tmrk.enterprisecloud.domain.VirtualMachine;
@ -31,8 +28,7 @@ import org.jclouds.tmrk.enterprisecloud.domain.VirtualMachines;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import java.net.URI;
/**
* Provides asynchronous access to VirtualMachine via their REST API.
@ -52,30 +48,27 @@ public interface VirtualMachineAsyncClient {
* @see VirtualMachineClient#getVirtualMachines
*/
@GET
@Path("/virtualMachines/computePools/{id}")
@Consumes("application/vnd.tmrk.cloud.virtualMachine; type=collection")
@JAXBResponseParser
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<VirtualMachines> getVirtualMachines(@PathParam("id") long id);
ListenableFuture<VirtualMachines> getVirtualMachines(@EndpointParam URI uri);
/**
* @see VirtualMachineClient#getVirtualMachine
*/
@GET
@Path("/virtualMachines/{id}")
@Consumes("application/vnd.tmrk.cloud.virtualMachine")
@JAXBResponseParser
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<VirtualMachine> getVirtualMachine(@PathParam("id") long id);
ListenableFuture<VirtualMachine> getVirtualMachine(@EndpointParam URI uri);
/**
* @see VirtualMachineClient#getVirtualMachine
*/
@GET
@Path("/virtualMachines/{id}/assignedIps")
@Consumes("application/vnd.tmrk.cloud.virtualMachineAssignedIps")
@JAXBResponseParser
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<AssignedIpAddresses> getAssignedIpAddresses(@PathParam("id") long id);
ListenableFuture<AssignedIpAddresses> getAssignedIpAddresses(@EndpointParam URI uri);
}

View File

@ -23,6 +23,7 @@ import org.jclouds.tmrk.enterprisecloud.domain.AssignedIpAddresses;
import org.jclouds.tmrk.enterprisecloud.domain.VirtualMachine;
import org.jclouds.tmrk.enterprisecloud.domain.VirtualMachines;
import java.net.URI;
import java.util.concurrent.TimeUnit;
/**
@ -40,25 +41,25 @@ public interface VirtualMachineClient {
/**
* returns information regarding virtual machines defined in a compute pool
* @param id the i of the compute pool
* @param uri the uri of the compute pool
* @return the virtual machines
*/
VirtualMachines getVirtualMachines(long id);
VirtualMachines getVirtualMachines(URI uri);
/**
* The Get Virtual Machines by ID call returns information regarding a
* specified virtual machine defined in an environment.
* @param id the id of the virtual machine
* @param uri the id of the virtual machine
* @return the virtual Machine or null if not found
*/
VirtualMachine getVirtualMachine(long id);
VirtualMachine getVirtualMachine(URI uri);
/**
* The Get Virtual Machines Assigned IP Addresses call returns information
* regarding the IP addresses assigned to a specified virtual machine in a compute pool.
* @param id the id of the virtual machine
* @param uri the assignedIpAddresses call
* @return the assigned ip addresses
*/
AssignedIpAddresses getAssignedIpAddresses(long id);
AssignedIpAddresses getAssignedIpAddresses(URI uri);
}

View File

@ -29,6 +29,7 @@ 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 TaskAsyncClient}
@ -38,9 +39,9 @@ import java.net.URI;
@Test(groups = "unit", testName = "TaskAsyncClientTest")
public class TaskAsyncClientTest extends BaseTerremarkEnterpriseCloudAsyncClientTest<TaskAsyncClient> {
public void testGetTasksInEnvironment() throws SecurityException, NoSuchMethodException, IOException {
Method method = TaskAsyncClient.class.getMethod("getTasksInEnvironment", long.class);
HttpRequest httpRequest = processor.createRequest(method, 1l);
public void testGetTasksInEnvironment() throws SecurityException, NoSuchMethodException, IOException, URISyntaxException {
Method method = TaskAsyncClient.class.getMethod("getTasksInEnvironment", URI.class);
HttpRequest httpRequest = processor.createRequest(method, new URI("/cloudapi/ecloud/tasks/environments/1"));
assertRequestLineEquals(httpRequest, "GET https://services-beta.enterprisecloud.terremark.com/cloudapi/ecloud/tasks/environments/1 HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest,

View File

@ -23,6 +23,8 @@ import org.jclouds.tmrk.enterprisecloud.domain.Tasks;
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.assertTrue;
@ -42,11 +44,11 @@ public class TaskClientLiveTest extends BaseTerremarkEnterpriseCloudClientLiveTe
private TaskClient client;
@Test
public void testGetTasks() {
public void testGetTasks() throws Exception {
// TODO: don't hard-code id
// TODO: docs say don't parse the href, yet no xml includes "identifier",
// I suspect we may need to change to URI args as opposed to long
Tasks response = client.getTasksInEnvironment(77);
Tasks response = client.getTasksInEnvironment(new URI("/cloudapi/ecloud/tasks/environments/77"));
assert null != response;
assertTrue(response.getTasks().size() >= 0);

View File

@ -27,6 +27,8 @@ 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 TaskAsyncClient}
@ -36,9 +38,9 @@ import java.lang.reflect.Method;
@Test(groups = "unit", testName = "VirtualMachineAsyncClientTest")
public class VirtualMachineAsyncClientTest extends BaseTerremarkEnterpriseCloudAsyncClientTest<VirtualMachineAsyncClient> {
public void testGetVirtualMachine() throws SecurityException, NoSuchMethodException, IOException {
Method method = VirtualMachineAsyncClient.class.getMethod("getVirtualMachine", long.class);
HttpRequest httpRequest = processor.createRequest(method,1);
public void testGetVirtualMachine() throws SecurityException, NoSuchMethodException, IOException, URISyntaxException {
Method method = VirtualMachineAsyncClient.class.getMethod("getVirtualMachine", URI.class);
HttpRequest httpRequest = processor.createRequest(method,new URI("/cloudapi/ecloud/virtualMachines/1"));
assertRequestLineEquals(httpRequest, "GET https://services-beta.enterprisecloud.terremark.com/cloudapi/ecloud/virtualMachines/1 HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/vnd.tmrk.cloud.virtualMachine\nx-tmrk-version: 2011-07-01\n");
@ -50,9 +52,9 @@ public class VirtualMachineAsyncClientTest extends BaseTerremarkEnterpriseCloudA
checkFilters(httpRequest);
}
public void testGetVirtualMachines() throws SecurityException, NoSuchMethodException, IOException {
Method method = VirtualMachineAsyncClient.class.getMethod("getVirtualMachines", long.class);
HttpRequest httpRequest = processor.createRequest(method,567);
public void testGetVirtualMachines() throws SecurityException, NoSuchMethodException, IOException, URISyntaxException {
Method method = VirtualMachineAsyncClient.class.getMethod("getVirtualMachines", URI.class);
HttpRequest httpRequest = processor.createRequest(method,new URI("/cloudapi/ecloud/virtualMachines/computePools/567"));
assertRequestLineEquals(httpRequest, "GET https://services-beta.enterprisecloud.terremark.com/cloudapi/ecloud/virtualMachines/computePools/567 HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/vnd.tmrk.cloud.virtualMachine; type=collection\nx-tmrk-version: 2011-07-01\n");
@ -64,11 +66,11 @@ public class VirtualMachineAsyncClientTest extends BaseTerremarkEnterpriseCloudA
checkFilters(httpRequest);
}
public void testGetAssignedIpAddresses() throws SecurityException, NoSuchMethodException, IOException {
Method method = VirtualMachineAsyncClient.class.getMethod("getAssignedIpAddresses", long.class);
HttpRequest httpRequest = processor.createRequest(method,1);
public void testGetAssignedIpAddresses() throws SecurityException, NoSuchMethodException, IOException, URISyntaxException {
Method method = VirtualMachineAsyncClient.class.getMethod("getAssignedIpAddresses", URI.class);
HttpRequest httpRequest = processor.createRequest(method,new URI("/cloudapi/ecloud/virtualMachines/1/assignedips"));
assertRequestLineEquals(httpRequest, "GET https://services-beta.enterprisecloud.terremark.com/cloudapi/ecloud/virtualMachines/1/assignedIps HTTP/1.1");
assertRequestLineEquals(httpRequest, "GET https://services-beta.enterprisecloud.terremark.com/cloudapi/ecloud/virtualMachines/1/assignedips HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/vnd.tmrk.cloud.virtualMachineAssignedIps\nx-tmrk-version: 2011-07-01\n");
assertPayloadEquals(httpRequest, null, null, false);

View File

@ -49,10 +49,10 @@ public class VirtualMachineClientLiveTest extends BaseTerremarkEnterpriseCloudCl
@Test
public void testGetVirtualMachines() throws Exception {
// TODO: don't hard-code id
VirtualMachines virtualMachines = client.getVirtualMachines(89);
// TODO: don't hard-code uri
VirtualMachines virtualMachines = client.getVirtualMachines(new URI("/cloudapi/ecloud/virtualMachines/computePools/89"));
for( VirtualMachine vm : virtualMachines.getVirtualMachines()) {
VirtualMachine virtualMachine = client.getVirtualMachine(parse(vm.getHref()));
VirtualMachine virtualMachine = client.getVirtualMachine(vm.getHref());
assert null != virtualMachine;
assertEquals(virtualMachine.getStatus(),VirtualMachine.VirtualMachineStatus.DEPLOYED);
}
@ -60,29 +60,18 @@ public class VirtualMachineClientLiveTest extends BaseTerremarkEnterpriseCloudCl
@Test
public void testGetVirtualMachine() throws Exception {
// TODO: don't hard-code id
VirtualMachine virtualMachine = client.getVirtualMachine(5504);
// TODO: don't hard-code uri
VirtualMachine virtualMachine = client.getVirtualMachine(new URI("/cloudapi/ecloud/virtualMachines/5504"));
assert null != virtualMachine;
assertEquals(virtualMachine.getStatus(),VirtualMachine.VirtualMachineStatus.DEPLOYED);
}
@Test
public void testGetAssignedIpAddresses() throws Exception {
AssignedIpAddresses assignedIpAddresses = client.getAssignedIpAddresses(5504);
AssignedIpAddresses assignedIpAddresses = client.getAssignedIpAddresses(new URI("/cloudapi/ecloud/virtualMachines/5504/assignedips"));
assert null != assignedIpAddresses;
DeviceNetwork network = Iterables.getOnlyElement(assignedIpAddresses.getNetworks().getDeviceNetworks());
Set<String> ipAddresses = network.getIpAddresses().getIpAddresses();
assertTrue(ipAddresses.size()>0, "vm has no assigned ip addresses");
}
// TODO: We are not supposed to parse the href's
// The alternative is to use URI's on the method calls.
// But this has the risk of exposing strings like "/virtualmachines/5504" and "/computepools/89" to users
// Also - would need to figure out how to configure the tests
// to add on the endpoint so that the @EndpointParam is converted into a proper request.
private long parse(URI uri) {
String path = uri.getPath();
path = path.substring(path.lastIndexOf("/")+1);
return Long.parseLong(path);
}
}

View File

@ -97,8 +97,8 @@ public class AssignedIpAddressesJAXBParsingTest extends BaseRestClientTest {
@Test
public void testParseAssignedIpAddressesWithJAXB() throws Exception {
Method method = VirtualMachineAsyncClient.class.getMethod("getAssignedIpAddresses", long.class);
HttpRequest request = factory(VirtualMachineAsyncClient.class).createRequest(method,1);
Method method = VirtualMachineAsyncClient.class.getMethod("getAssignedIpAddresses", URI.class);
HttpRequest request = factory(VirtualMachineAsyncClient.class).createRequest(method,new URI("/1"));
assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class);
Function<HttpResponse, AssignedIpAddresses> parser = (Function<HttpResponse, AssignedIpAddresses>) RestAnnotationProcessor

View File

@ -130,7 +130,7 @@ public class TaskJAXBParsingTest extends BaseRestClientTest {
public void testParseTaskWithJAXB() throws Exception {
Method method = TaskAsyncClient.class.getMethod("getTask",URI.class);
HttpRequest request = factory(TaskAsyncClient.class).createRequest(method);
HttpRequest request = factory(TaskAsyncClient.class).createRequest(method, new URI("/1"));
assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class);
Function<HttpResponse, Task> parser = (Function<HttpResponse, Task>) RestAnnotationProcessor
@ -144,8 +144,8 @@ public class TaskJAXBParsingTest extends BaseRestClientTest {
@Test
public void testParseTasksWithJAXB() throws Exception {
Method method = TaskAsyncClient.class.getMethod("getTasksInEnvironment",long.class);
HttpRequest request = factory(TaskAsyncClient.class).createRequest(method,1);
Method method = TaskAsyncClient.class.getMethod("getTasksInEnvironment",URI.class);
HttpRequest request = factory(TaskAsyncClient.class).createRequest(method,new URI("/1"));
assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class);
Function<HttpResponse, Tasks> parser = (Function<HttpResponse, Tasks>) RestAnnotationProcessor

View File

@ -97,8 +97,8 @@ public class VirtualMachineJAXBParsingTest extends BaseRestClientTest {
@Test
public void testParseVirtualMachineWithJAXB() throws Exception {
Method method = VirtualMachineAsyncClient.class.getMethod("getVirtualMachine", long.class);
HttpRequest request = factory(VirtualMachineAsyncClient.class).createRequest(method,1);
Method method = VirtualMachineAsyncClient.class.getMethod("getVirtualMachine", URI.class);
HttpRequest request = factory(VirtualMachineAsyncClient.class).createRequest(method,new URI("/1"));
assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class);
Function<HttpResponse, VirtualMachine> parser = (Function<HttpResponse, VirtualMachine>) RestAnnotationProcessor