mirror of https://github.com/apache/jclouds.git
Issue 112: support instantiation
git-svn-id: http://jclouds.googlecode.com/svn/trunk@2245 3d8758e0-26b5-11de-8745-db77d3ebf521
This commit is contained in:
parent
7f73d1761a
commit
37d5d4f071
|
@ -32,6 +32,8 @@ import org.jclouds.vcloud.domain.Task;
|
||||||
import org.jclouds.vcloud.domain.TaskStatus;
|
import org.jclouds.vcloud.domain.TaskStatus;
|
||||||
import org.joda.time.DateTime;
|
import org.joda.time.DateTime;
|
||||||
|
|
||||||
|
import com.google.inject.internal.Nullable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Locations of resources in vCloud
|
* Locations of resources in vCloud
|
||||||
*
|
*
|
||||||
|
@ -43,19 +45,21 @@ public class TaskImpl implements Task {
|
||||||
private final URI location;
|
private final URI location;
|
||||||
private final TaskStatus status;
|
private final TaskStatus status;
|
||||||
private final DateTime startTime;
|
private final DateTime startTime;
|
||||||
|
@Nullable
|
||||||
private final DateTime endTime;
|
private final DateTime endTime;
|
||||||
private final Link owner;
|
private final Link owner;
|
||||||
|
@Nullable
|
||||||
private final Link result;
|
private final Link result;
|
||||||
|
|
||||||
public TaskImpl(String type, URI location, TaskStatus status, DateTime startTime,
|
public TaskImpl(String type, URI location, TaskStatus status, DateTime startTime,
|
||||||
DateTime endTime, Link owner, Link result) {
|
@Nullable DateTime endTime, Link owner, @Nullable Link result) {
|
||||||
this.type = checkNotNull(type, "type");
|
this.type = checkNotNull(type, "type");
|
||||||
this.location = checkNotNull(location, "location");
|
this.location = checkNotNull(location, "location");
|
||||||
this.status = checkNotNull(status, "status");
|
this.status = checkNotNull(status, "status");
|
||||||
this.startTime = checkNotNull(startTime, "startTime");
|
this.startTime = checkNotNull(startTime, "startTime");
|
||||||
this.endTime = checkNotNull(endTime, "endTime");
|
this.endTime = endTime;
|
||||||
this.owner = checkNotNull(owner, "owner");
|
this.owner = checkNotNull(owner, "owner");
|
||||||
this.result = checkNotNull(result, "result");
|
this.result = result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TaskStatus getStatus() {
|
public TaskStatus getStatus() {
|
||||||
|
|
|
@ -25,17 +25,24 @@ package org.jclouds.vcloud.terremark;
|
||||||
|
|
||||||
import static org.jclouds.vcloud.VCloudMediaType.VDC_XML;
|
import static org.jclouds.vcloud.VCloudMediaType.VDC_XML;
|
||||||
|
|
||||||
|
import java.net.URI;
|
||||||
import java.util.concurrent.Future;
|
import java.util.concurrent.Future;
|
||||||
|
|
||||||
import javax.ws.rs.Consumes;
|
import javax.ws.rs.Consumes;
|
||||||
import javax.ws.rs.GET;
|
import javax.ws.rs.GET;
|
||||||
|
import javax.ws.rs.POST;
|
||||||
|
import javax.ws.rs.Path;
|
||||||
|
import javax.ws.rs.Produces;
|
||||||
|
|
||||||
import org.jclouds.rest.annotations.Endpoint;
|
import org.jclouds.rest.annotations.Endpoint;
|
||||||
|
import org.jclouds.rest.annotations.MapBinder;
|
||||||
|
import org.jclouds.rest.annotations.MapEntityParam;
|
||||||
import org.jclouds.rest.annotations.RequestFilters;
|
import org.jclouds.rest.annotations.RequestFilters;
|
||||||
import org.jclouds.rest.annotations.XMLResponseParser;
|
import org.jclouds.rest.annotations.XMLResponseParser;
|
||||||
import org.jclouds.vcloud.VCloudClient;
|
import org.jclouds.vcloud.VCloudClient;
|
||||||
import org.jclouds.vcloud.domain.VDC;
|
import org.jclouds.vcloud.domain.VDC;
|
||||||
import org.jclouds.vcloud.filters.SetVCloudTokenCookie;
|
import org.jclouds.vcloud.filters.SetVCloudTokenCookie;
|
||||||
|
import org.jclouds.vcloud.terremark.binders.BindInstantiateVAppTemplateParamsToXmlEntity;
|
||||||
import org.jclouds.vcloud.terremark.xml.TerremarkVDCHandler;
|
import org.jclouds.vcloud.terremark.xml.TerremarkVDCHandler;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -48,20 +55,19 @@ import org.jclouds.vcloud.terremark.xml.TerremarkVDCHandler;
|
||||||
@RequestFilters(SetVCloudTokenCookie.class)
|
@RequestFilters(SetVCloudTokenCookie.class)
|
||||||
public interface TerremarkVCloudClient extends VCloudClient {
|
public interface TerremarkVCloudClient extends VCloudClient {
|
||||||
|
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Endpoint(org.jclouds.vcloud.endpoints.VDC.class)
|
@Endpoint(org.jclouds.vcloud.endpoints.VDC.class)
|
||||||
@XMLResponseParser(TerremarkVDCHandler.class)
|
@XMLResponseParser(TerremarkVDCHandler.class)
|
||||||
@Consumes(VDC_XML)
|
@Consumes(VDC_XML)
|
||||||
Future<? extends VDC> getDefaultVDC();
|
Future<? extends VDC> getDefaultVDC();
|
||||||
|
|
||||||
//
|
@POST
|
||||||
// @GET
|
@Endpoint(org.jclouds.vcloud.endpoints.VDC.class)
|
||||||
// @Endpoint(vDC.class)
|
@Path("/action/instantiatevAppTemplate")
|
||||||
// public Set<String> getvDCs();
|
@Produces("application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml")
|
||||||
//
|
@MapBinder(BindInstantiateVAppTemplateParamsToXmlEntity.class)
|
||||||
// @GET
|
String instantiateVAppTemplate(@MapEntityParam("name") String appName,
|
||||||
// @Endpoint(TasksList.class)
|
@MapEntityParam("template") URI vAppTemplate, @MapEntityParam("count") int cpuCount,
|
||||||
// public Set<String> getTasksLists();
|
@MapEntityParam("megabytes") int megabytesMemory, @MapEntityParam("network") URI network);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,51 @@
|
||||||
|
package org.jclouds.vcloud.terremark.binders;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
import javax.inject.Named;
|
||||||
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
|
import org.jclouds.http.HttpRequest;
|
||||||
|
import org.jclouds.rest.MapBinder;
|
||||||
|
import org.jclouds.rest.binders.BindToStringEntity;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Adrian Cole
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@Singleton
|
||||||
|
public class BindInstantiateVAppTemplateParamsToXmlEntity implements MapBinder {
|
||||||
|
@Inject
|
||||||
|
@Named("InstantiateVAppTemplateParams")
|
||||||
|
String xmlTemplate;
|
||||||
|
@Inject
|
||||||
|
BindToStringEntity stringBinder;
|
||||||
|
|
||||||
|
public void bindToRequest(HttpRequest request, Map<String, String> postParams) {
|
||||||
|
|
||||||
|
String name = checkNotNull(postParams.get("name"), "name parameter not present");
|
||||||
|
String template = checkNotNull(postParams.get("template"), "template parameter not present");
|
||||||
|
String count = checkNotNull(postParams.get("count"), "count parameter not present");
|
||||||
|
String megabytes = checkNotNull(postParams.get("megabytes"),
|
||||||
|
"megabytes parameter not present");
|
||||||
|
String network = checkNotNull(postParams.get("network"), "network parameter not present");
|
||||||
|
|
||||||
|
String entity = xmlTemplate.replaceAll("\\{name\\}", name);
|
||||||
|
entity = entity.replaceAll("\\{template\\}", template);
|
||||||
|
entity = entity.replaceAll("\\{count\\}", count);
|
||||||
|
entity = entity.replaceAll("\\{megabytes\\}", megabytes);
|
||||||
|
entity = entity.replaceAll("\\{network\\}", network);
|
||||||
|
|
||||||
|
stringBinder.bindToRequest(request, entity);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void bindToRequest(HttpRequest request, Object input) {
|
||||||
|
throw new IllegalStateException("InstantiateVAppTemplateParams is needs parameters");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -23,11 +23,16 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.vcloud.terremark.config;
|
package org.jclouds.vcloud.terremark.config;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
|
||||||
|
import javax.inject.Named;
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
import org.jclouds.http.RequiresHttp;
|
import org.jclouds.http.RequiresHttp;
|
||||||
import org.jclouds.rest.ConfiguresRestClient;
|
import org.jclouds.rest.ConfiguresRestClient;
|
||||||
import org.jclouds.rest.RestClientFactory;
|
import org.jclouds.rest.RestClientFactory;
|
||||||
|
import org.jclouds.util.Utils;
|
||||||
import org.jclouds.vcloud.VCloudClient;
|
import org.jclouds.vcloud.VCloudClient;
|
||||||
import org.jclouds.vcloud.config.VCloudRestClientModule;
|
import org.jclouds.vcloud.config.VCloudRestClientModule;
|
||||||
import org.jclouds.vcloud.terremark.TerremarkVCloudClient;
|
import org.jclouds.vcloud.terremark.TerremarkVCloudClient;
|
||||||
|
@ -54,4 +59,13 @@ public class TerremarkVCloudRestClientModule extends VCloudRestClientModule {
|
||||||
return factory.create(TerremarkVCloudClient.class);
|
return factory.create(TerremarkVCloudClient.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Singleton
|
||||||
|
@Provides
|
||||||
|
@Named("InstantiateVAppTemplateParams")
|
||||||
|
String provideInstantiateVAppTemplateParams() throws IOException {
|
||||||
|
InputStream is = getClass().getResourceAsStream(
|
||||||
|
"/terremark/InstantiateVAppTemplateParams.xml");
|
||||||
|
return Utils.toStringAndClose(is);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -78,8 +78,9 @@ public class TasksListHandler extends ParseSax.HandlerWithResult<TasksList> {
|
||||||
status = TaskStatus.fromValue(attributes.getValue(attributes.getIndex("status")));
|
status = TaskStatus.fromValue(attributes.getValue(attributes.getIndex("status")));
|
||||||
startTime = dateService.iso8601DateParse(attributes.getValue(attributes
|
startTime = dateService.iso8601DateParse(attributes.getValue(attributes
|
||||||
.getIndex("startTime")));
|
.getIndex("startTime")));
|
||||||
endTime = dateService
|
if (attributes.getIndex("endTime") != -1)
|
||||||
.iso8601DateParse(attributes.getValue(attributes.getIndex("endTime")));
|
endTime = dateService.iso8601DateParse(attributes.getValue(attributes
|
||||||
|
.getIndex("endTime")));
|
||||||
} else if (qName.equals("Owner")) {
|
} else if (qName.equals("Owner")) {
|
||||||
owner = Utils.newLink(attributes);
|
owner = Utils.newLink(attributes);
|
||||||
} else if (qName.equals("Result")) {
|
} else if (qName.equals("Result")) {
|
||||||
|
|
|
@ -0,0 +1,38 @@
|
||||||
|
<InstantiateVAppTemplateParams name="{name}"
|
||||||
|
xml:lang="en" xmlns="http://www.vmware.com/vcloud/v1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||||
|
<VAppTemplate href="{template}" />
|
||||||
|
<InstantiationParams>
|
||||||
|
<ProductSection xmlns:q1="http://www.vmware.com/vcloud/v1"
|
||||||
|
xmlns:ovf="http://schemas.dmtf.org/ovf/envelope/1">
|
||||||
|
<Property xmlns="http://schemas.dmtf.org/ovf/envelope/1"
|
||||||
|
ovf:key="password" ovf:value="secretPassword" />
|
||||||
|
<Property xmlns="http://schemas.dmtf.org/ovf/envelope/1"
|
||||||
|
ovf:key="row" ovf:value="Row1" />
|
||||||
|
<Property xmlns="http://schemas.dmtf.org/ovf/envelope/1"
|
||||||
|
ovf:key="group" ovf:value="Group1" />
|
||||||
|
</ProductSection>
|
||||||
|
<VirtualHardwareSection xmlns:q1="http://www.vmware.com/vcloud/v1">
|
||||||
|
<Item xmlns="http://schemas.dmtf.org/ovf/envelope/1">
|
||||||
|
<InstanceID
|
||||||
|
xmlns="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData">1</InstanceID>
|
||||||
|
<ResourceType
|
||||||
|
xmlns="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData">3</ResourceType>
|
||||||
|
<VirtualQuantity
|
||||||
|
xmlns="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData">{count}</VirtualQuantity>
|
||||||
|
</Item>
|
||||||
|
<Item xmlns="http://schemas.dmtf.org/ovf/envelope/1">
|
||||||
|
<InstanceID
|
||||||
|
xmlns="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData">2</InstanceID>
|
||||||
|
<ResourceType
|
||||||
|
xmlns="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData">4</ResourceType>
|
||||||
|
<VirtualQuantity
|
||||||
|
xmlns="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData">{megabytes}</VirtualQuantity>
|
||||||
|
</Item>
|
||||||
|
</VirtualHardwareSection>
|
||||||
|
<NetworkConfigSection>
|
||||||
|
<NetworkConfig>
|
||||||
|
<NetworkAssociation href="{network}" />
|
||||||
|
</NetworkConfig>
|
||||||
|
</NetworkConfigSection>
|
||||||
|
</InstantiationParams>
|
||||||
|
</InstantiateVAppTemplateParams>
|
|
@ -26,7 +26,10 @@ package org.jclouds.vcloud.terremark;
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
import static org.testng.Assert.assertNotNull;
|
import static org.testng.Assert.assertNotNull;
|
||||||
|
|
||||||
|
import java.net.URI;
|
||||||
|
import java.util.concurrent.ExecutionException;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import java.util.concurrent.TimeoutException;
|
||||||
|
|
||||||
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
|
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
|
||||||
import org.jclouds.vcloud.VCloudClientLiveTest;
|
import org.jclouds.vcloud.VCloudClientLiveTest;
|
||||||
|
@ -41,24 +44,43 @@ import org.testng.annotations.Test;
|
||||||
*/
|
*/
|
||||||
@Test(groups = "live", sequential = true, testName = "vcloud.TerremarkVCloudClientLiveTest")
|
@Test(groups = "live", sequential = true, testName = "vcloud.TerremarkVCloudClientLiveTest")
|
||||||
public class TerremarkVCloudClientLiveTest extends VCloudClientLiveTest {
|
public class TerremarkVCloudClientLiveTest extends VCloudClientLiveTest {
|
||||||
|
TerremarkVCloudClient tmClient;
|
||||||
|
|
||||||
|
public static final String PREFIX = System.getProperty("user.name") + "-terremark";
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDefaultVDC() throws Exception {
|
public void testDefaultVDC() throws Exception {
|
||||||
super.testDefaultVDC();
|
super.testDefaultVDC();
|
||||||
TerremarkVDC response = (TerremarkVDC) connection.getDefaultVDC().get(10, TimeUnit.SECONDS);
|
TerremarkVDC response = (TerremarkVDC) tmClient.getDefaultVDC().get(10, TimeUnit.SECONDS);
|
||||||
assertNotNull(response);
|
assertNotNull(response);
|
||||||
assertNotNull(response.getCatalog());
|
assertNotNull(response.getCatalog());
|
||||||
assertNotNull(response.getInternetServices());
|
assertNotNull(response.getInternetServices());
|
||||||
assertNotNull(response.getPublicIps());
|
assertNotNull(response.getPublicIps());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test(enabled = false)
|
||||||
|
// disabled until stop functionality is added
|
||||||
|
public void testInstantiate() throws InterruptedException, ExecutionException, TimeoutException {
|
||||||
|
URI template = tmClient.getCatalog().get(10, TimeUnit.SECONDS).get(
|
||||||
|
"Ubuntu Server 9.04 (32-bit)").getLocation();
|
||||||
|
|
||||||
|
URI network = tmClient.getDefaultVDC().get(10, TimeUnit.SECONDS).getAvailableNetworks()
|
||||||
|
.values().iterator().next().getLocation();
|
||||||
|
|
||||||
|
String response = tmClient.instantiateVAppTemplate("adriantest", template, 1, 512, network);
|
||||||
|
|
||||||
|
|
||||||
|
System.out.println(response);
|
||||||
|
}
|
||||||
|
|
||||||
@BeforeGroups(groups = { "live" })
|
@BeforeGroups(groups = { "live" })
|
||||||
@Override
|
@Override
|
||||||
public void setupClient() {
|
public void setupClient() {
|
||||||
account = checkNotNull(System.getProperty("jclouds.test.user"), "jclouds.test.user");
|
account = checkNotNull(System.getProperty("jclouds.test.user"), "jclouds.test.user");
|
||||||
String key = checkNotNull(System.getProperty("jclouds.test.key"), "jclouds.test.key");
|
String key = checkNotNull(System.getProperty("jclouds.test.key"), "jclouds.test.key");
|
||||||
connection = new TerremarkVCloudContextBuilder(new TerremarkVCloudPropertiesBuilder(account,
|
connection = tmClient = new TerremarkVCloudContextBuilder(
|
||||||
key).build()).withModules(new Log4JLoggingModule()).buildContext().getApi();
|
new TerremarkVCloudPropertiesBuilder(account, key).build()).withModules(
|
||||||
|
new Log4JLoggingModule()).buildContext().getApi();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,17 +26,23 @@ package org.jclouds.vcloud.terremark;
|
||||||
import static org.testng.Assert.assertEquals;
|
import static org.testng.Assert.assertEquals;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
|
|
||||||
|
import javax.inject.Named;
|
||||||
import javax.inject.Provider;
|
import javax.inject.Provider;
|
||||||
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
|
import org.apache.commons.io.IOUtils;
|
||||||
import org.jclouds.http.functions.ParseSax;
|
import org.jclouds.http.functions.ParseSax;
|
||||||
|
import org.jclouds.http.functions.ReturnStringIf200;
|
||||||
import org.jclouds.logging.Logger;
|
import org.jclouds.logging.Logger;
|
||||||
import org.jclouds.logging.Logger.LoggerFactory;
|
import org.jclouds.logging.Logger.LoggerFactory;
|
||||||
import org.jclouds.rest.RestClientTest;
|
import org.jclouds.rest.RestClientTest;
|
||||||
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
||||||
import org.jclouds.rest.internal.RestAnnotationProcessor;
|
import org.jclouds.rest.internal.RestAnnotationProcessor;
|
||||||
|
import org.jclouds.util.Utils;
|
||||||
import org.jclouds.vcloud.endpoints.Catalog;
|
import org.jclouds.vcloud.endpoints.Catalog;
|
||||||
import org.jclouds.vcloud.endpoints.VDC;
|
import org.jclouds.vcloud.endpoints.VDC;
|
||||||
import org.jclouds.vcloud.filters.SetVCloudTokenCookie;
|
import org.jclouds.vcloud.filters.SetVCloudTokenCookie;
|
||||||
|
@ -45,6 +51,7 @@ import org.testng.annotations.Test;
|
||||||
|
|
||||||
import com.google.inject.AbstractModule;
|
import com.google.inject.AbstractModule;
|
||||||
import com.google.inject.Module;
|
import com.google.inject.Module;
|
||||||
|
import com.google.inject.Provides;
|
||||||
import com.google.inject.TypeLiteral;
|
import com.google.inject.TypeLiteral;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -70,6 +77,30 @@ public class TerremarkVCloudClientTest extends RestClientTest<TerremarkVCloudCli
|
||||||
checkFilters(httpMethod);
|
checkFilters(httpMethod);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testInstantiateVAppTemplate() throws SecurityException, NoSuchMethodException,
|
||||||
|
IOException {
|
||||||
|
Method method = TerremarkVCloudClient.class.getMethod("instantiateVAppTemplate",
|
||||||
|
|
||||||
|
String.class, URI.class, int.class, int.class, URI.class
|
||||||
|
|
||||||
|
);
|
||||||
|
GeneratedHttpRequest<TerremarkVCloudClient> httpMethod = processor.createRequest(method,
|
||||||
|
"name", URI.create("http://template"), 1, 512, URI.create("http://network"));
|
||||||
|
|
||||||
|
assertRequestLineEquals(httpMethod, "POST http://vdc/action/instantiatevAppTemplate HTTP/1.1");
|
||||||
|
assertHeadersEqual(
|
||||||
|
httpMethod,
|
||||||
|
"Content-Length: 2242\nContent-Type: application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml\n");
|
||||||
|
assertEntityEquals(httpMethod, IOUtils.toString(getClass().getResourceAsStream(
|
||||||
|
"/terremark/InstantiateVAppTemplateParams-test.xml")));
|
||||||
|
|
||||||
|
assertResponseParserClassEquals(method, httpMethod, ReturnStringIf200.class);
|
||||||
|
assertSaxResponseParserClassEquals(method, null);
|
||||||
|
assertExceptionParserClassEquals(method, null);
|
||||||
|
|
||||||
|
checkFilters(httpMethod);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void checkFilters(GeneratedHttpRequest<TerremarkVCloudClient> httpMethod) {
|
protected void checkFilters(GeneratedHttpRequest<TerremarkVCloudClient> httpMethod) {
|
||||||
assertEquals(httpMethod.getFilters().size(), 1);
|
assertEquals(httpMethod.getFilters().size(), 1);
|
||||||
|
@ -105,6 +136,15 @@ public class TerremarkVCloudClientTest extends RestClientTest<TerremarkVCloudCli
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
@Singleton
|
||||||
|
@Provides
|
||||||
|
@Named("InstantiateVAppTemplateParams")
|
||||||
|
String provideInstantiateVAppTemplateParams() throws IOException {
|
||||||
|
InputStream is = getClass().getResourceAsStream(
|
||||||
|
"/terremark/InstantiateVAppTemplateParams.xml");
|
||||||
|
return Utils.toStringAndClose(is);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,91 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright (C) 2009 Cloud Conscious,"LLC. <info@cloudconscious.com>
|
||||||
|
*
|
||||||
|
* ====================================================================
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF 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.vcloud.terremark.binders;
|
||||||
|
|
||||||
|
import static org.testng.Assert.assertEquals;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.net.URI;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import javax.inject.Named;
|
||||||
|
import javax.inject.Singleton;
|
||||||
|
import javax.ws.rs.core.HttpHeaders;
|
||||||
|
|
||||||
|
import org.apache.commons.io.IOUtils;
|
||||||
|
import org.jclouds.http.HttpRequest;
|
||||||
|
import org.jclouds.util.Utils;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
import com.google.common.collect.Maps;
|
||||||
|
import com.google.inject.AbstractModule;
|
||||||
|
import com.google.inject.Guice;
|
||||||
|
import com.google.inject.Injector;
|
||||||
|
import com.google.inject.Provides;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests behavior of {@code BindInstantiateVAppTemplateParamsToXmlEntity}
|
||||||
|
*
|
||||||
|
* @author Adrian Cole
|
||||||
|
*/
|
||||||
|
@Test(groups = "unit", testName = "vcloud.BindInstantiateVAppTemplateParamsToXmlEntityTest")
|
||||||
|
public class BindInstantiateVAppTemplateParamsToXmlEntityTest {
|
||||||
|
Injector injector = Guice.createInjector(new AbstractModule() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void configure() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
@Singleton
|
||||||
|
@Provides
|
||||||
|
@Named("InstantiateVAppTemplateParams")
|
||||||
|
String provideInstantiateVAppTemplateParams() throws IOException {
|
||||||
|
InputStream is = getClass().getResourceAsStream(
|
||||||
|
"/terremark/InstantiateVAppTemplateParams.xml");
|
||||||
|
return Utils.toStringAndClose(is);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
public void testApplyInputStream() throws IOException {
|
||||||
|
String expected = IOUtils.toString(getClass().getResourceAsStream(
|
||||||
|
"/terremark/InstantiateVAppTemplateParams-test.xml"));
|
||||||
|
HttpRequest request = new HttpRequest("GET", URI.create("http://test"));
|
||||||
|
BindInstantiateVAppTemplateParamsToXmlEntity binder = injector
|
||||||
|
.getInstance(BindInstantiateVAppTemplateParamsToXmlEntity.class);
|
||||||
|
|
||||||
|
Map<String, String> map = Maps.newHashMap();
|
||||||
|
map.put("name", "name");
|
||||||
|
map.put("template", "http://template");
|
||||||
|
map.put("count", "1");
|
||||||
|
map.put("megabytes", "512");
|
||||||
|
map.put("network", "http://network");
|
||||||
|
binder.bindToRequest(request, map);
|
||||||
|
assertEquals(request.getFirstHeaderOrNull(HttpHeaders.CONTENT_TYPE), "application/unknown");
|
||||||
|
assertEquals(request.getFirstHeaderOrNull(HttpHeaders.CONTENT_LENGTH), "2242");
|
||||||
|
assertEquals(request.getEntity(), expected);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,38 @@
|
||||||
|
<InstantiateVAppTemplateParams name="name"
|
||||||
|
xml:lang="en" xmlns="http://www.vmware.com/vcloud/v1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||||
|
<VAppTemplate href="http://template" />
|
||||||
|
<InstantiationParams>
|
||||||
|
<ProductSection xmlns:q1="http://www.vmware.com/vcloud/v1"
|
||||||
|
xmlns:ovf="http://schemas.dmtf.org/ovf/envelope/1">
|
||||||
|
<Property xmlns="http://schemas.dmtf.org/ovf/envelope/1"
|
||||||
|
ovf:key="password" ovf:value="secretPassword" />
|
||||||
|
<Property xmlns="http://schemas.dmtf.org/ovf/envelope/1"
|
||||||
|
ovf:key="row" ovf:value="Row1" />
|
||||||
|
<Property xmlns="http://schemas.dmtf.org/ovf/envelope/1"
|
||||||
|
ovf:key="group" ovf:value="Group1" />
|
||||||
|
</ProductSection>
|
||||||
|
<VirtualHardwareSection xmlns:q1="http://www.vmware.com/vcloud/v1">
|
||||||
|
<Item xmlns="http://schemas.dmtf.org/ovf/envelope/1">
|
||||||
|
<InstanceID
|
||||||
|
xmlns="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData">1</InstanceID>
|
||||||
|
<ResourceType
|
||||||
|
xmlns="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData">3</ResourceType>
|
||||||
|
<VirtualQuantity
|
||||||
|
xmlns="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData">1</VirtualQuantity>
|
||||||
|
</Item>
|
||||||
|
<Item xmlns="http://schemas.dmtf.org/ovf/envelope/1">
|
||||||
|
<InstanceID
|
||||||
|
xmlns="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData">2</InstanceID>
|
||||||
|
<ResourceType
|
||||||
|
xmlns="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData">4</ResourceType>
|
||||||
|
<VirtualQuantity
|
||||||
|
xmlns="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData">512</VirtualQuantity>
|
||||||
|
</Item>
|
||||||
|
</VirtualHardwareSection>
|
||||||
|
<NetworkConfigSection>
|
||||||
|
<NetworkConfig>
|
||||||
|
<NetworkAssociation href="http://network" />
|
||||||
|
</NetworkConfig>
|
||||||
|
</NetworkConfigSection>
|
||||||
|
</InstantiationParams>
|
||||||
|
</InstantiateVAppTemplateParams>
|
|
@ -0,0 +1,8 @@
|
||||||
|
<VApp href="https://services.vcloudexpress.terremark.com/api/v0.8/vapp/13775"
|
||||||
|
type="application/vnd.vmware.vcloud.vApp+xml" name="adriantest"
|
||||||
|
status="0" size="4" xmlns="http://www.vmware.com/vcloud/v1"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
|
||||||
|
<Link rel="up"
|
||||||
|
href="https://services.vcloudexpress.terremark.com/api/v0.8/vdc/32"
|
||||||
|
type="application/vnd.vmware.vcloud.vdc+xml" />
|
||||||
|
</VApp>
|
Loading…
Reference in New Issue