Issue 306, Issue 327: more progress unraveling vcloud URI-based operations

This commit is contained in:
Adrian Cole 2010-08-13 20:11:09 -07:00
parent 4b76982261
commit 22e10f84a6
62 changed files with 1418 additions and 1005 deletions

View File

@ -21,6 +21,9 @@ package org.jclouds.rest.internal;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.collect.Collections2.filter;
import static com.google.common.collect.Iterables.concat;
import static com.google.common.collect.Iterables.get;
import static com.google.common.collect.Iterables.transform;
import static com.google.common.collect.Lists.newArrayList;
import static com.google.common.collect.Lists.newLinkedList;
import static com.google.common.collect.Maps.filterValues;
@ -28,6 +31,7 @@ import static com.google.common.collect.Maps.newHashMap;
import static com.google.common.collect.Maps.newLinkedHashMap;
import static com.google.common.collect.Sets.difference;
import static com.google.common.collect.Sets.newHashSet;
import static com.google.common.collect.Sets.newTreeSet;
import static java.util.Arrays.asList;
import static javax.ws.rs.core.HttpHeaders.ACCEPT;
import static javax.ws.rs.core.HttpHeaders.CONTENT_TYPE;
@ -53,6 +57,7 @@ import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.SortedSet;
import java.util.Map.Entry;
import javax.annotation.Nullable;
@ -122,7 +127,6 @@ import org.jclouds.rest.functions.MapHttp4xxCodesToExceptions;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Function;
import com.google.common.base.Predicate;
import com.google.common.collect.Iterables;
import com.google.common.collect.LinkedHashMultimap;
import com.google.common.collect.LinkedListMultimap;
import com.google.common.collect.MapMaker;
@ -460,10 +464,10 @@ public class RestAnnotationProcessor<T> {
if (payload == null)
payload = findPayloadInArgs(args);
List<? extends Part> parts = getParts(method, args, Iterables.concat(tokenValues.entries(), formParams.entries()));
List<? extends Part> parts = getParts(method, args, concat(tokenValues.entries(), formParams.entries()));
if (parts.size() > 0) {
if (formParams.size() > 0) {
parts = newLinkedList(Iterables.concat(Iterables.transform(formParams.entries(), ENTRY_TO_PART), parts));
parts = newLinkedList(concat(transform(formParams.entries(), ENTRY_TO_PART), parts));
}
payload = new MultipartForm(BOUNDARY, parts);
} else if (formParams.size() > 0) {
@ -618,7 +622,7 @@ public class RestAnnotationProcessor<T> {
Map<Integer, Set<Annotation>> map = indexWithAtLeastOneAnnotation(method,
methodToIndexOfParamToEndpointParamAnnotations);
if (map.size() >= 1 && args.length > 0) {
EndpointParam firstAnnotation = (EndpointParam) Iterables.get(Iterables.get(map.values(), 0), 0);
EndpointParam firstAnnotation = (EndpointParam) get(get(map.values(), 0), 0);
Function<Object, URI> parser = injector.getInstance(firstAnnotation.parser());
if (map.size() == 1) {
@ -632,7 +636,8 @@ public class RestAnnotationProcessor<T> {
throw new IllegalArgumentException(String.format("argument at index %d on method %s", index, method), e);
}
} else {
Iterable<Object> argsToParse = Iterables.transform(map.keySet(), new Function<Integer, Object>() {
SortedSet<Integer> keys = newTreeSet(map.keySet());
Iterable<Object> argsToParse = transform(keys, new Function<Integer, Object>() {
@Override
public Object apply(Integer from) {
@ -1145,9 +1150,8 @@ public class RestAnnotationProcessor<T> {
if (extractors != null && extractors.size() > 0) {
ParamParser extractor = (ParamParser) extractors.iterator().next();
paramValue = injector.getInstance(extractor.value()).apply(args[entry.getKey()]);
} else {
paramValue = args[entry.getKey()].toString();
paramValue = args[entry.getKey()] != null ? args[entry.getKey()].toString() : null;
}
postParams.put(paramKey, paramValue);

View File

@ -31,6 +31,7 @@ import org.jclouds.vcloud.VCloudClient;
import org.jclouds.vcloud.compute.BaseVCloudComputeClient;
import org.jclouds.vcloud.domain.VApp;
import org.jclouds.vcloud.domain.VAppStatus;
import org.jclouds.vcloud.domain.VAppTemplate;
import com.google.common.base.Predicate;
@ -42,21 +43,16 @@ public class BlueLockVCloudComputeClient extends BaseVCloudComputeClient {
private final PopulateDefaultLoginCredentialsForImageStrategy credentialsProvider;
@Inject
protected BlueLockVCloudComputeClient(
PopulateDefaultLoginCredentialsForImageStrategy credentialsProvider,
VCloudClient client, Predicate<String> successTester,
Map<VAppStatus, NodeState> vAppStatusToNodeState) {
protected BlueLockVCloudComputeClient(PopulateDefaultLoginCredentialsForImageStrategy credentialsProvider,
VCloudClient client, Predicate<String> successTester, Map<VAppStatus, NodeState> vAppStatusToNodeState) {
super(client, successTester, vAppStatusToNodeState);
this.credentialsProvider = credentialsProvider;
}
@Override
protected Map<String, String> parseAndValidateResponse(String templateId,
VApp vAppResponse) {
Credentials credentials = credentialsProvider.execute(client
.getVAppTemplate(templateId));
Map<String, String> toReturn = super.parseResponse(templateId,
vAppResponse);
protected Map<String, String> parseAndValidateResponse(VAppTemplate template, VApp vAppResponse) {
Credentials credentials = credentialsProvider.execute(template);
Map<String, String> toReturn = super.parseResponse(template, vAppResponse);
toReturn.put("username", credentials.identity);
toReturn.put("password", credentials.credential);
return toReturn;

View File

@ -65,7 +65,8 @@ public class ParseVAppTemplatesInVDCToSizeProvider implements Provider<Set<? ext
private final FindLocationForResource findLocationForResourceInVDC;
// TODO fix to work with multiple orgs. this currently assumes only one per user which is ok for
// TODO fix to work with multiple orgs. this currently assumes only one per
// user which is ok for
// now
@Inject
ParseVAppTemplatesInVDCToSizeProvider(VCloudClient client, FindLocationForResource findLocationForResourceInVDC) {
@ -78,7 +79,7 @@ public class ParseVAppTemplatesInVDCToSizeProvider implements Provider<Set<? ext
final Set<Size> sizes = Sets.newHashSet();
logger.debug(">> providing vAppTemplates");
for (final NamedResource vDC : client.getDefaultOrganization().getVDCs().values()) {
VDC vdc = client.getVDC(vDC.getId());
VDC vdc = client.getVDC(vDC.getLocation());
addSizesFromVAppTemplatesInVDC(vdc, sizes);
}
return sizes;
@ -99,7 +100,7 @@ public class ParseVAppTemplatesInVDCToSizeProvider implements Provider<Set<? ext
String name = resource.getName().split(" ")[1];
String id = vdc.getId() + "/" + resource.getId();
sizes.add(new SizeImpl(resource.getId(), name, id, location, null, ImmutableMap.<String, String> of(),
cores, ram, disk, ImagePredicates.idEquals(id)));
cores, ram, disk, ImagePredicates.idEquals(id)));
} catch (NoSuchElementException e) {
logger.debug("<< didn't match at all(%s)", resource);
}

View File

@ -29,6 +29,8 @@ import static org.jclouds.vcloud.VCloudMediaType.VAPPTEMPLATE_XML;
import static org.jclouds.vcloud.VCloudMediaType.VAPP_XML;
import static org.jclouds.vcloud.VCloudMediaType.VDC_XML;
import java.net.URI;
import javax.annotation.Nullable;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
@ -44,7 +46,6 @@ import org.jclouds.rest.annotations.EndpointParam;
import org.jclouds.rest.annotations.ExceptionParser;
import org.jclouds.rest.annotations.MapBinder;
import org.jclouds.rest.annotations.MapPayloadParam;
import org.jclouds.rest.annotations.ParamParser;
import org.jclouds.rest.annotations.ParamValidators;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.XMLResponseParser;
@ -66,9 +67,9 @@ import org.jclouds.vcloud.filters.SetVCloudTokenCookie;
import org.jclouds.vcloud.functions.OrgNameAndCatalogNameToEndpoint;
import org.jclouds.vcloud.functions.OrgNameAndTasksListNameToEndpoint;
import org.jclouds.vcloud.functions.OrgNameAndVDCNameToEndpoint;
import org.jclouds.vcloud.functions.OrgNameCatalogNameItemNameToEndpoint;
import org.jclouds.vcloud.functions.OrgNameCatalogNameVAppTemplateNameToEndpoint;
import org.jclouds.vcloud.functions.OrgNameToEndpoint;
import org.jclouds.vcloud.functions.VAppIdToUri;
import org.jclouds.vcloud.functions.VAppTemplateIdToUri;
import org.jclouds.vcloud.options.CloneVAppOptions;
import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions;
import org.jclouds.vcloud.xml.CatalogHandler;
@ -106,14 +107,11 @@ public interface VCloudAsyncClient {
/**
* @see VCloudClient#getOrganization
*/
@Deprecated
@GET
@Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class)
@Path("/org/{orgId}")
@XMLResponseParser(OrgHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
@Consumes(ORG_XML)
ListenableFuture<? extends Organization> getOrganization(@PathParam("orgId") String orgId);
ListenableFuture<? extends Organization> getOrganization(@EndpointParam URI orgId);
/**
* @see VCloudClient#getOrganizationNamed
@ -122,7 +120,7 @@ public interface VCloudAsyncClient {
@XMLResponseParser(OrgHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
@Consumes(ORG_XML)
ListenableFuture<? extends Organization> getOrganizationNamed(
ListenableFuture<? extends Organization> findOrganizationNamed(
@Nullable @EndpointParam(parser = OrgNameToEndpoint.class) String orgName);
/**
@ -148,13 +146,13 @@ public interface VCloudAsyncClient {
ListenableFuture<? extends Catalog> getCatalog(@PathParam("catalogId") String catalogId);
/**
* @see VCloudClient#getCatalogInOrg
* @see VCloudClient#findCatalogInOrgNamed
*/
@GET
@XMLResponseParser(CatalogHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
@Consumes(CATALOG_XML)
ListenableFuture<? extends Catalog> getCatalogInOrg(
ListenableFuture<? extends Catalog> findCatalogInOrgNamed(
@Nullable @EndpointParam(parser = OrgNameAndCatalogNameToEndpoint.class) String orgName,
@Nullable @EndpointParam(parser = OrgNameAndCatalogNameToEndpoint.class) String catalogName);
@ -162,23 +160,43 @@ public interface VCloudAsyncClient {
* @see VCloudClient#getVAppTemplate
*/
@GET
@Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class)
@Path("/vAppTemplate/{vAppTemplateId}")
@Consumes(VAPPTEMPLATE_XML)
@XMLResponseParser(VAppTemplateHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<? extends VAppTemplate> getVAppTemplate(@PathParam("vAppTemplateId") String vAppTemplateId);
ListenableFuture<? extends VAppTemplate> getVAppTemplate(@EndpointParam URI vAppTemplate);
/**
* @see VCloudClient#findVAppTemplateInOrgCatalogNameds
*/
@GET
@Consumes(VAPPTEMPLATE_XML)
@XMLResponseParser(VAppTemplateHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<? extends VAppTemplate> findVAppTemplateInOrgCatalogNamed(
@Nullable @EndpointParam(parser = OrgNameCatalogNameVAppTemplateNameToEndpoint.class) String orgName,
@Nullable @EndpointParam(parser = OrgNameCatalogNameVAppTemplateNameToEndpoint.class) String catalogName,
@Nullable @EndpointParam(parser = OrgNameCatalogNameVAppTemplateNameToEndpoint.class) String itemName);
/**
* @see VCloudClient#getCatalogItem
*/
@GET
@Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class)
@Path("/catalogItem/{catalogItemId}")
@Consumes(CATALOGITEM_XML)
@XMLResponseParser(CatalogItemHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<? extends CatalogItem> getCatalogItem(@PathParam("catalogItemId") String catalogItemId);
ListenableFuture<? extends CatalogItem> getCatalogItem(@EndpointParam URI catalogItem);
/**
* @see VCloudClient#getCatalogItemInOrg
*/
@GET
@Consumes(CATALOGITEM_XML)
@XMLResponseParser(CatalogItemHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<? extends CatalogItem> findCatalogItemInOrgCatalogNamed(
@Nullable @EndpointParam(parser = OrgNameCatalogNameItemNameToEndpoint.class) String orgName,
@Nullable @EndpointParam(parser = OrgNameCatalogNameItemNameToEndpoint.class) String catalogName,
@Nullable @EndpointParam(parser = OrgNameCatalogNameItemNameToEndpoint.class) String itemName);
/**
* @see VCloudClient#getNetwork
@ -202,25 +220,22 @@ public interface VCloudAsyncClient {
ListenableFuture<? extends VDC> getDefaultVDC();
/**
* @see VCloudClient#getVDC(String)
* @see VCloudClient#getVDC(URI)
*/
@Deprecated
@GET
@Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class)
@Path("/vdc/{vDCId}")
@XMLResponseParser(VDCHandler.class)
@Consumes(VDC_XML)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<? extends VDC> getVDC(@PathParam("vDCId") String vDCId);
ListenableFuture<? extends VDC> getVDC(@EndpointParam URI vdc);
/**
* @see VCloudClient#getVDCInOrg(String, String)
* @see VCloudClient#findVDCInOrgNamed(String, String)
*/
@GET
@XMLResponseParser(VDCHandler.class)
@Consumes(VDC_XML)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<? extends VDC> getVDCInOrg(
ListenableFuture<? extends VDC> findVDCInOrgNamed(
@Nullable @EndpointParam(parser = OrgNameAndVDCNameToEndpoint.class) String orgName,
@Nullable @EndpointParam(parser = OrgNameAndVDCNameToEndpoint.class) String vdcName);
@ -243,7 +258,7 @@ public interface VCloudAsyncClient {
@Consumes(TASKSLIST_XML)
@XMLResponseParser(TasksListHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<? extends TasksList> getTasksListInOrg(
ListenableFuture<? extends TasksList> findTasksListInOrgNamed(
@Nullable @EndpointParam(parser = OrgNameAndTasksListNameToEndpoint.class) String orgName,
@Nullable @EndpointParam(parser = OrgNameAndTasksListNameToEndpoint.class) String tasksListName);
@ -364,40 +379,22 @@ public interface VCloudAsyncClient {
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<? extends VApp> getVApp(@PathParam("vAppId") String appId);
/**
* @see VCloudClient#instantiateVAppTemplate
*/
@POST
@Path("/action/instantiateVAppTemplate")
@Produces("application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml")
@Consumes(VAPP_XML)
@XMLResponseParser(VAppHandler.class)
@MapBinder(BindInstantiateVAppTemplateParamsToXmlPayload.class)
ListenableFuture<? extends VApp> instantiateVAppTemplateInOrg(
@Nullable @EndpointParam(parser = OrgNameAndVDCNameToEndpoint.class) String orgName,
@Nullable @EndpointParam(parser = OrgNameAndVDCNameToEndpoint.class) String vdcName,
@MapPayloadParam("name") @ParamValidators(DnsNameValidator.class) String appName,
@MapPayloadParam("template") @ParamParser(VAppTemplateIdToUri.class) String templateId,
InstantiateVAppTemplateOptions... options);
/**
* @see VCloudClient#instantiateVAppTemplateInVDC
*/
@Deprecated
@POST
@Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class)
@Path("/vdc/{vDCId}/action/instantiateVAppTemplate")
@Path("action/instantiateVAppTemplate")
@Produces("application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml")
@Consumes(VAPP_XML)
@XMLResponseParser(VAppHandler.class)
@MapBinder(BindInstantiateVAppTemplateParamsToXmlPayload.class)
ListenableFuture<? extends VApp> instantiateVAppTemplateInVDC(@PathParam("vDCId") String vDCId,
ListenableFuture<? extends VApp> instantiateVAppTemplateInVDC(@EndpointParam URI vdc,
@MapPayloadParam("template") URI template,
@MapPayloadParam("name") @ParamValidators(DnsNameValidator.class) String appName,
@MapPayloadParam("template") @ParamParser(VAppTemplateIdToUri.class) String templateId,
InstantiateVAppTemplateOptions... options);
/**
* @see VCloudClient#cloneVApp
* @see VCloudClient#cloneVAppInVDC
*/
@POST
@Path("/action/cloneVApp")
@ -405,26 +402,7 @@ public interface VCloudAsyncClient {
@Consumes(TASK_XML)
@XMLResponseParser(TaskHandler.class)
@MapBinder(BindCloneVAppParamsToXmlPayload.class)
ListenableFuture<? extends Task> cloneVAppInOrg(
@Nullable @EndpointParam(parser = OrgNameAndVDCNameToEndpoint.class) String orgName,
@Nullable @EndpointParam(parser = OrgNameAndVDCNameToEndpoint.class) String vdcName,
@MapPayloadParam("vApp") @ParamParser(VAppIdToUri.class) String vAppIdToClone,
@MapPayloadParam("newName") @ParamValidators(DnsNameValidator.class) String newName,
CloneVAppOptions... options);
/**
* - * @see VCloudClient#cloneVAppInVDC
*/
@Deprecated
@POST
@Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class)
@Path("/vdc/{vDCId}/action/cloneVApp")
@Produces("application/vnd.vmware.vcloud.cloneVAppParams+xml")
@Consumes(TASK_XML)
@XMLResponseParser(TaskHandler.class)
@MapBinder(BindCloneVAppParamsToXmlPayload.class)
ListenableFuture<? extends Task> cloneVAppInVDC(@PathParam("vDCId") String vDCId,
@MapPayloadParam("vApp") @ParamParser(VAppIdToUri.class) String vAppIdToClone,
ListenableFuture<? extends Task> cloneVAppInVDC(@EndpointParam URI vdc, @MapPayloadParam("vApp") URI toClone,
@MapPayloadParam("newName") @ParamValidators(DnsNameValidator.class) String newName,
CloneVAppOptions... options);

View File

@ -19,6 +19,7 @@
package org.jclouds.vcloud;
import java.net.URI;
import java.util.concurrent.TimeUnit;
import org.jclouds.concurrent.Timeout;
@ -44,17 +45,14 @@ import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions;
*/
@Timeout(duration = 300, timeUnit = TimeUnit.SECONDS)
public interface VCloudClient {
/**
* Please use {@link #getOrganizationNamed(String)} passing null
* Please use {@link #findOrganizationNamed(String)} passing null
*/
@Deprecated
Organization getDefaultOrganization();
/**
* Please use #getOrganizationNamed
*/
@Deprecated
Organization getOrganization(String orgId);
Organization getOrganization(URI orgId);
/**
* This call returns a list of all vCloud Data Centers (vdcs), catalogs, and
@ -63,49 +61,49 @@ public interface VCloudClient {
* @param name
* organization name, or null for the default
*/
Organization getOrganizationNamed(String name);
Organization findOrganizationNamed(String name);
/**
* Please use #getCatalogInOrg(null, null)
* Please use #findCatalogInOrgNamed(null, null)
*/
@Deprecated
Catalog getDefaultCatalog();
/**
* Please use #getCatalogInOrg
* Please use #findCatalogInOrgNamed
*/
@Deprecated
Catalog getCatalog(String catalogId);
Catalog getCatalogInOrg(String orgName, String catalogName);
Catalog findCatalogInOrgNamed(String orgName, String catalogName);
CatalogItem getCatalogItem(String catalogItemId);
CatalogItem getCatalogItem(URI catalogItem);
VAppTemplate getVAppTemplate(String vAppTemplateId);
CatalogItem findCatalogItemInOrgCatalogNamed(String orgName, String catalogName, String itemName);
VAppTemplate getVAppTemplate(URI vAppTemplate);
VAppTemplate findVAppTemplateInOrgCatalogNamed(String orgName, String catalogName, String templateName);
Network getNetwork(String networkId);
/**
* please use {@link #getVDCInOrg}
*/
@Deprecated
VDC getVDC(String vDCId);
VDC getVDC(URI vdc);
VDC getVDCInOrg(String orgName, String vdcName);
VDC findVDCInOrgNamed(String orgName, String vdcName);
/**
* Please use #getVDCInOrg(null, null)
* Please use #findVDCInOrgNamed
*/
@Deprecated
VDC getDefaultVDC();
/**
* Please use #getTasksListInOrg
* Please use #findTasksListInOrgNamed
*/
@Deprecated
TasksList getTasksList(String tasksListId);
TasksList getTasksListInOrg(String orgName, String tasksListName);
TasksList findTasksListInOrgNamed(String orgName, String tasksListName);
/**
* Please use #getTasksListInOrg(null, null)
@ -152,16 +150,8 @@ public interface VCloudClient {
VApp getVApp(String appId);
@Deprecated
VApp instantiateVAppTemplateInVDC(String vDCId, String appName, String templateId,
InstantiateVAppTemplateOptions... options);
VApp instantiateVAppTemplateInVDC(URI vDC, URI template, String appName, InstantiateVAppTemplateOptions... options);
VApp instantiateVAppTemplateInOrg(String org, String vdc, String appName, String templateId,
InstantiateVAppTemplateOptions... options);
@Deprecated
Task cloneVAppInVDC(String vDCId, String vAppIdToClone, String newName, CloneVAppOptions... options);
Task cloneVAppInOrg(String org, String vdc, String vAppIdToClone, String newName, CloneVAppOptions... options);
Task cloneVAppInVDC(URI vDC, URI toClone, String newName, CloneVAppOptions... options);
}

View File

@ -22,6 +22,7 @@ package org.jclouds.vcloud.compute;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
import java.net.URI;
import java.util.Map;
import java.util.Set;
@ -37,6 +38,8 @@ import org.jclouds.vcloud.VCloudClient;
import org.jclouds.vcloud.domain.Task;
import org.jclouds.vcloud.domain.VApp;
import org.jclouds.vcloud.domain.VAppStatus;
import org.jclouds.vcloud.domain.VAppTemplate;
import org.jclouds.vcloud.domain.VDC;
import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions;
import com.google.common.base.Predicate;
@ -67,13 +70,15 @@ public class BaseVCloudComputeClient implements VCloudComputeClient {
}
@Override
public Map<String, String> start(@Nullable String orgName, @Nullable String vDCName, String name, String templateId,
public Map<String, String> start(@Nullable URI VDC, URI templateId, String name,
InstantiateVAppTemplateOptions options, int... portsToOpen) {
checkNotNull(options, "options");
logger.debug(">> instantiating vApp org(%s) vDC(%s) name(%s) template(%s) options(%s) ", orgName, vDCName, name,
templateId, options);
logger.debug(">> instantiating vApp vDC(%s) template(%s) name(%s) options(%s) ", VDC, templateId, name, options);
VApp vAppResponse = client.instantiateVAppTemplateInOrg(orgName, vDCName, name, templateId, options);
VDC vdc = client.getVDC(VDC);
VAppTemplate template = client.getVAppTemplate(templateId);
VApp vAppResponse = client.instantiateVAppTemplateInVDC(vdc.getLocation(), template.getLocation(), name, options);
logger.debug("<< instantiated VApp(%s)", vAppResponse.getId());
logger.debug(">> deploying vApp(%s)", vAppResponse.getId());
@ -92,18 +97,18 @@ public class BaseVCloudComputeClient implements VCloudComputeClient {
}
logger.debug("<< on vApp(%s)", vAppResponse.getId());
}
return parseAndValidateResponse(templateId, vAppResponse);
return parseAndValidateResponse(template, vAppResponse);
}
protected Map<String, String> parseAndValidateResponse(String templateId, VApp vAppResponse) {
Map<String, String> response = parseResponse(templateId, vAppResponse);
protected Map<String, String> parseAndValidateResponse(VAppTemplate template, VApp vAppResponse) {
Map<String, String> response = parseResponse(template, vAppResponse);
checkState(response.containsKey("id"), "bad configuration: [id] should be in response");
checkState(response.containsKey("username"), "bad configuration: [username] should be in response");
checkState(response.containsKey("password"), "bad configuration: [password] should be in response");
return response;
}
protected Map<String, String> parseResponse(String templateId, VApp vAppResponse) {
protected Map<String, String> parseResponse(VAppTemplate template, VApp vAppResponse) {
Map<String, String> config = Maps.newLinkedHashMap();// Allows nulls
config.put("id", vAppResponse.getId());
config.put("username", null);

View File

@ -19,6 +19,7 @@
package org.jclouds.vcloud.compute;
import java.net.URI;
import java.util.Map;
import java.util.Set;
@ -66,8 +67,8 @@ public interface VCloudComputeClient {
* password - console login password</li>
* </ol>
*/
Map<String, String> start(@Nullable String orgName, @Nullable String vDCName, String name, String templateId,
InstantiateVAppTemplateOptions options, int... portsToOpen);
Map<String, String> start(@Nullable URI VDC, URI templateId, String name, InstantiateVAppTemplateOptions options,
int... portsToOpen);
/**
* returns a set of addresses that are only visible to the private network.

View File

@ -42,6 +42,7 @@ import org.jclouds.compute.strategy.GetNodeMetadataStrategy;
import org.jclouds.compute.strategy.ListNodesStrategy;
import org.jclouds.compute.strategy.RebootNodeStrategy;
import org.jclouds.compute.strategy.RunNodesAndAddToSetStrategy;
import org.jclouds.compute.strategy.impl.EncodeTagIntoNameRunNodesAndAddToSetStrategy;
import org.jclouds.domain.Location;
import org.jclouds.rest.RestContext;
import org.jclouds.rest.internal.RestContextImpl;
@ -51,13 +52,14 @@ import org.jclouds.vcloud.compute.BaseVCloudComputeClient;
import org.jclouds.vcloud.compute.config.providers.OrgAndVDCToLocationProvider;
import org.jclouds.vcloud.compute.config.providers.StaticSizeProvider;
import org.jclouds.vcloud.compute.config.providers.VAppTemplatesInVDCs;
import org.jclouds.vcloud.compute.strategy.EncodeTemplateIdIntoNameRunNodesAndAddToSetStrategy;
import org.jclouds.vcloud.compute.domain.VCloudLocation;
import org.jclouds.vcloud.compute.strategy.VCloudAddNodeWithTagStrategy;
import org.jclouds.vcloud.compute.strategy.VCloudDestroyNodeStrategy;
import org.jclouds.vcloud.compute.strategy.VCloudGetNodeMetadataStrategy;
import org.jclouds.vcloud.compute.strategy.VCloudListNodesStrategy;
import org.jclouds.vcloud.compute.strategy.VCloudRebootNodeStrategy;
import org.jclouds.vcloud.domain.VAppStatus;
import org.jclouds.vcloud.domain.VDC;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Function;
@ -106,7 +108,7 @@ public class VCloudComputeServiceContextModule extends AbstractModule {
bind(new TypeLiteral<RestContext<VCloudClient, VCloudAsyncClient>>() {
}).to(new TypeLiteral<RestContextImpl<VCloudClient, VCloudAsyncClient>>() {
}).in(Scopes.SINGLETON);
bind(RunNodesAndAddToSetStrategy.class).to(EncodeTemplateIdIntoNameRunNodesAndAddToSetStrategy.class);
bind(RunNodesAndAddToSetStrategy.class).to(EncodeTagIntoNameRunNodesAndAddToSetStrategy.class);
bind(ListNodesStrategy.class).to(VCloudListNodesStrategy.class);
bind(GetNodeMetadataStrategy.class).to(VCloudGetNodeMetadataStrategy.class);
bind(RebootNodeStrategy.class).to(VCloudRebootNodeStrategy.class);
@ -121,7 +123,7 @@ public class VCloudComputeServiceContextModule extends AbstractModule {
@Named("NAMING_CONVENTION")
@Singleton
protected String provideNamingConvention() {
return "%s-%s%s";
return "%s-%s";
}
protected void bindLoadBalancer() {
@ -157,12 +159,12 @@ public class VCloudComputeServiceContextModule extends AbstractModule {
@Provides
@Singleton
Location getVDC(VCloudClient client, Set<? extends Location> locations) {
final String vdc = client.getDefaultVDC().getName();
final VDC vdc = client.findVDCInOrgNamed(null, null);
return Iterables.find(locations, new Predicate<Location>() {
@Override
public boolean apply(Location input) {
return input.getId().equals(vdc);
return VCloudLocation.class.cast(input).getResource().getLocation().equals(vdc.getLocation());
}
});

View File

@ -44,12 +44,12 @@ import com.google.common.collect.Sets;
public class OrgAndVDCToLocationProvider implements Provider<Set<? extends Location>> {
private final String providerName;
private final Supplier<Map<String, NamedResource>> orgNameToResource;
private final Supplier<Map<String, Organization>> orgNameToVDCResource;
private final Supplier<Map<String, ? extends Organization>> orgNameToVDCResource;
@Inject
OrgAndVDCToLocationProvider(@org.jclouds.rest.annotations.Provider String providerName,
@Org Supplier<Map<String, NamedResource>> orgNameToResource,
Supplier<Map<String, Organization>> orgNameToVDCResource) {
Supplier<Map<String, ? extends Organization>> orgNameToVDCResource) {
this.providerName = providerName;
this.orgNameToResource = orgNameToResource;
this.orgNameToVDCResource = orgNameToVDCResource;

View File

@ -32,21 +32,18 @@ import org.jclouds.vcloud.domain.NamedResource;
*/
public class VCloudLocation extends LocationImpl {
private static final long serialVersionUID = -5052812549904524841L;
private final NamedResource resource;
public VCloudLocation(NamedResource resource, Location parent) {
super(checkNotNull(resource, "resource").getType().endsWith("org+xml") ? LocationScope.REGION
: LocationScope.ZONE, resource.getLocation().toASCIIString(), resource.getName(), parent);
this.resource = resource;
}
public NamedResource getResource() {
return resource;
}
public VCloudLocation(NamedResource resource, Location parent) {
super(checkNotNull(resource, "resource").getType().endsWith("org+xml") ? LocationScope.REGION
: LocationScope.ZONE, resource.getName(), resource.getName(), parent);
this.resource = resource;
}
/**
*
*/
private static final long serialVersionUID = -5052812549904524841L;
}

View File

@ -46,7 +46,7 @@ public class ImageForVAppTemplate implements Function<VAppTemplate, Image> {
@Inject
protected ImageForVAppTemplate(FindLocationForResource findLocationForResource,
PopulateDefaultLoginCredentialsForImageStrategy credentialsProvider) {
PopulateDefaultLoginCredentialsForImageStrategy credentialsProvider) {
this.findLocationForResource = findLocationForResource;
this.credentialsProvider = credentialsProvider;
}
@ -63,8 +63,9 @@ public class ImageForVAppTemplate implements Function<VAppTemplate, Image> {
Location location = findLocationForResource.apply(parent);
String name = getName(from.getName());
String desc = from.getDescription() != null ? from.getDescription() : from.getName();
return new ImageImpl(from.getId(), name, parent.getId() + "/" + from.getId(), location, from.getLocation(),
ImmutableMap.<String, String> of(), desc, "", myOs, name, arch, credentialsProvider.execute(from));
return new ImageImpl(from.getLocation().toASCIIString(), name, from.getLocation().toASCIIString(), location, from
.getLocation(), ImmutableMap.<String, String> of(), desc, "", myOs, name, arch, credentialsProvider
.execute(from));
}
protected String getName(String name) {

View File

@ -22,7 +22,6 @@ package org.jclouds.vcloud.compute.functions;
import static com.google.common.base.Preconditions.checkNotNull;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@ -46,13 +45,11 @@ import org.jclouds.vcloud.compute.VCloudComputeClient;
import org.jclouds.vcloud.domain.VApp;
import org.jclouds.vcloud.domain.VAppStatus;
import com.google.common.base.Predicate;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Iterables;
/**
* Configures the {@link VCloudComputeServiceContext}; requires {@link BaseVCloudComputeClient}
* bound.
* Configures the {@link VCloudComputeServiceContext}; requires
* {@link BaseVCloudComputeClient} bound.
*
* @author Adrian Cole
*/
@ -69,16 +66,12 @@ public class VCloudGetNodeMetadata {
protected final GetExtra getExtra;
protected final Map<VAppStatus, NodeState> vAppStatusToNodeState;
// hex [][][] are templateId, last two are instanceId
public static final Pattern TAG_PATTERN_WITH_TEMPLATE = Pattern
.compile("([^-]+)-([0-9a-f][0-9a-f][0-9a-f])[0-9a-f]+");
public static final Pattern TAG_PATTERN_WITHOUT_TEMPLATE = Pattern.compile("([^-]+)-[0-9]+");
@Inject
VCloudGetNodeMetadata(VCloudClient client, VCloudComputeClient computeClient,
Map<VAppStatus, NodeState> vAppStatusToNodeState, GetExtra getExtra,
FindLocationForResource findLocationForResourceInVDC, Provider<Set<? extends Image>> images) {
Map<VAppStatus, NodeState> vAppStatusToNodeState, GetExtra getExtra,
FindLocationForResource findLocationForResourceInVDC, Provider<Set<? extends Image>> images) {
this.client = checkNotNull(client, "client");
this.images = checkNotNull(images, "images");
this.getExtra = checkNotNull(getExtra, "getExtra");
@ -94,37 +87,15 @@ public class VCloudGetNodeMetadata {
String tag = null;
Image image = null;
Matcher matcher = vApp.getName() != null ? TAG_PATTERN_WITH_TEMPLATE.matcher(vApp.getName()) : null;
final Location location = findLocationForResourceInVDC.apply(vApp.getVDC());
if (matcher != null && matcher.find()) {
Matcher matcher = TAG_PATTERN_WITHOUT_TEMPLATE.matcher(vApp.getName());
if (matcher.find()) {
tag = matcher.group(1);
String templateIdInHexWithoutLeadingZeros = matcher.group(2).replaceAll("^[0]+", "");
final String templateId = Integer.parseInt(templateIdInHexWithoutLeadingZeros, 16) + "";
try {
image = Iterables.find(images.get(), new Predicate<Image>() {
@Override
public boolean apply(Image input) {
return input.getProviderId().equals(templateId)
&& (input.getLocation().equals(location) || input.getLocation().equals(location.getParent()));
}
});
} catch (NoSuchElementException e) {
logger.warn("could not find a matching image for vapp %s; vapptemplate %s in location %s", vApp,
templateId, location);
}
} else {
matcher = TAG_PATTERN_WITHOUT_TEMPLATE.matcher(vApp.getName());
if (matcher.find()) {
tag = matcher.group(1);
} else {
tag = "NOTAG-" + vApp.getName();
}
tag = "NOTAG-" + vApp.getName();
}
Location location = findLocationForResourceInVDC.apply(vApp.getVDC());
return new NodeMetadataImpl(vApp.getId(), vApp.getName(), vApp.getId(), location, vApp.getLocation(),
ImmutableMap.<String, String> of(), tag, image, vAppStatusToNodeState.get(vApp.getStatus()),
computeClient.getPublicAddresses(id), computeClient.getPrivateAddresses(id), getExtra.apply(vApp), null);
ImmutableMap.<String, String> of(), tag, image, vAppStatusToNodeState.get(vApp.getStatus()), computeClient
.getPublicAddresses(id), computeClient.getPrivateAddresses(id), getExtra.apply(vApp), null);
}
}

View File

@ -1,73 +0,0 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed 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.compute.strategy;
import java.security.SecureRandom;
import java.util.concurrent.ExecutorService;
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
import org.jclouds.Constants;
import org.jclouds.compute.domain.Template;
import org.jclouds.compute.strategy.AddNodeWithTagStrategy;
import org.jclouds.compute.strategy.ListNodesStrategy;
import org.jclouds.compute.strategy.impl.EncodeTagIntoNameRunNodesAndAddToSetStrategy;
import org.jclouds.compute.util.ComputeUtils;
import com.google.common.base.Strings;
/**
*
* @author Adrian Cole
*/
@Singleton
public class EncodeTemplateIdIntoNameRunNodesAndAddToSetStrategy extends
EncodeTagIntoNameRunNodesAndAddToSetStrategy {
private final SecureRandom random;
@Inject
protected EncodeTemplateIdIntoNameRunNodesAndAddToSetStrategy(
AddNodeWithTagStrategy addNodeWithTagStrategy,
ListNodesStrategy listNodesStrategy,
@Named("NAMING_CONVENTION") String nodeNamingConvention,
ComputeUtils utils,
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor,
SecureRandom random) {
super(addNodeWithTagStrategy, listNodesStrategy, nodeNamingConvention,
utils, executor);
this.random = random;
}
/**
* Get a name corresponding to the tag-hex*5 where the first 3 hex correspond
* to the template id and the last a random number
*
*/
@Override
protected String getNextName(final String tag, final Template template) {
return String.format(nodeNamingConvention, tag, Strings.padStart(
Integer.toHexString(Integer.parseInt(template.getImage()
.getProviderId())), 3, '0'), Strings.padStart(Integer
.toHexString(random.nextInt(255)), 2, '0'));
}
}

View File

@ -21,6 +21,7 @@ package org.jclouds.vcloud.compute.strategy;
import static org.jclouds.vcloud.options.InstantiateVAppTemplateOptions.Builder.processorCount;
import java.net.URI;
import java.util.Map;
import javax.inject.Inject;
@ -63,9 +64,8 @@ public class VCloudAddNodeWithTagStrategy implements AddNodeWithTagStrategy {
.memory(template.getSize().getRam()).disk(template.getSize().getDisk() * 1024 * 1024l);
if (!template.getOptions().shouldBlockUntilRunning())
options.blockOnDeploy(false);
Map<String, String> metaMap = computeClient.start(template.getLocation().getParent().getId(), template
.getLocation().getId(), name, template.getImage().getProviderId(), options, template.getOptions()
.getInboundPorts());
Map<String, String> metaMap = computeClient.start(URI.create(template.getLocation().getDescription()), URI
.create(template.getImage().getId()), name, options, template.getOptions().getInboundPorts());
VApp vApp = client.getVApp(metaMap.get("id"));
return newCreateNodeResponse(tag, template, metaMap, vApp);
}

View File

@ -86,8 +86,8 @@ public class VCloudListNodesStrategy implements ListNodesStrategy {
public Iterable<ComputeMetadata> list() {
Set<ComputeMetadata> nodes = Sets.newHashSet();
for (String org : orgNameToEndpoint.get().keySet()) {
for (NamedResource vdc : client.getOrganizationNamed(org).getVDCs().values()) {
for (NamedResource resource : client.getVDC(vdc.getId()).getResourceEntities().values()) {
for (NamedResource vdc : client.findOrganizationNamed(org).getVDCs().values()) {
for (NamedResource resource : client.getVDC(vdc.getLocation()).getResourceEntities().values()) {
if (validVApp(resource)) {
nodes.add(convertVAppToComputeMetadata(vdc, resource));
}
@ -111,8 +111,8 @@ public class VCloudListNodesStrategy implements ListNodesStrategy {
public Iterable<NodeMetadata> listDetailsOnNodesMatching(Predicate<ComputeMetadata> filter) {
Set<NodeMetadata> nodes = Sets.newHashSet();
for (String org : orgNameToEndpoint.get().keySet()) {
for (NamedResource vdc : client.getOrganizationNamed(org).getVDCs().values()) {
for (NamedResource resource : client.getVDC(vdc.getId()).getResourceEntities().values()) {
for (NamedResource vdc : client.findOrganizationNamed(org).getVDCs().values()) {
for (NamedResource resource : client.getVDC(vdc.getLocation()).getResourceEntities().values()) {
if (validVApp(resource) && filter.apply(convertVAppToComputeMetadata(vdc, resource))) {
addVAppToSetRetryingIfNotYetPresent(nodes, vdc, resource);
}

View File

@ -21,6 +21,12 @@ package org.jclouds.vcloud.config;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
import static com.google.common.base.Throwables.propagate;
import static com.google.common.collect.Iterables.get;
import static com.google.common.collect.Iterables.getLast;
import static com.google.common.collect.Maps.newLinkedHashMap;
import static com.google.common.collect.Maps.transformValues;
import static com.google.common.collect.Maps.uniqueIndex;
import static org.jclouds.Constants.PROPERTY_API_VERSION;
import static org.jclouds.Constants.PROPERTY_IDENTITY;
import static org.jclouds.Constants.PROPERTY_SESSION_INTERVAL;
@ -56,6 +62,7 @@ import org.jclouds.rest.suppliers.RetryOnTimeOutButNotOnAuthorizationExceptionSu
import org.jclouds.vcloud.VCloudAsyncClient;
import org.jclouds.vcloud.VCloudClient;
import org.jclouds.vcloud.VCloudToken;
import org.jclouds.vcloud.domain.CatalogItem;
import org.jclouds.vcloud.domain.NamedResource;
import org.jclouds.vcloud.domain.Organization;
import org.jclouds.vcloud.endpoints.Catalog;
@ -68,17 +75,18 @@ import org.jclouds.vcloud.endpoints.VDC;
import org.jclouds.vcloud.endpoints.internal.CatalogItemRoot;
import org.jclouds.vcloud.endpoints.internal.VAppRoot;
import org.jclouds.vcloud.endpoints.internal.VAppTemplateRoot;
import org.jclouds.vcloud.functions.AllCatalogItemsInCatalog;
import org.jclouds.vcloud.functions.AllCatalogsInOrganization;
import org.jclouds.vcloud.functions.OrganizationsForNames;
import org.jclouds.vcloud.handlers.ParseVCloudErrorFromHttpResponse;
import org.jclouds.vcloud.internal.VCloudLoginAsyncClient;
import org.jclouds.vcloud.internal.VCloudVersionsAsyncClient;
import org.jclouds.vcloud.internal.VCloudLoginAsyncClient.VCloudSession;
import org.jclouds.vcloud.predicates.TaskSuccess;
import com.google.common.base.Function;
import com.google.common.base.Predicate;
import com.google.common.base.Supplier;
import com.google.common.base.Throwables;
import com.google.common.collect.Iterables;
import com.google.common.collect.Maps;
import com.google.inject.Provides;
import com.google.inject.TypeLiteral;
@ -126,27 +134,27 @@ public abstract class BaseVCloudRestClientModule<S extends VCloudClient, A exten
@Org
@Singleton
protected URI provideOrg(@Org Iterable<NamedResource> orgs) {
return Iterables.getLast(orgs).getLocation();
return getLast(orgs).getLocation();
}
@Provides
@Org
@Singleton
protected String provideOrgName(@Org Iterable<NamedResource> orgs) {
return Iterables.getLast(orgs).getName();
return getLast(orgs).getName();
}
@Provides
@Singleton
@VDC
protected Supplier<Map<String, String>> provideVDCtoORG(@Named(PROPERTY_SESSION_INTERVAL) long seconds,
final Supplier<Map<String, Organization>> orgToVDCSupplier) {
final Supplier<Map<String, ? extends Organization>> orgToVDCSupplier) {
return new RetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Map<String, String>>(authException, seconds,
new Supplier<Map<String, String>>() {
@Override
public Map<String, String> get() {
Map<String, String> returnVal = Maps.newLinkedHashMap();
for (Entry<String, Organization> orgr : orgToVDCSupplier.get().entrySet()) {
Map<String, String> returnVal = newLinkedHashMap();
for (Entry<String, ? extends Organization> orgr : orgToVDCSupplier.get().entrySet()) {
for (String vdc : orgr.getValue().getVDCs().keySet()) {
returnVal.put(vdc, orgr.getKey());
}
@ -187,7 +195,7 @@ public abstract class BaseVCloudRestClientModule<S extends VCloudClient, A exten
try {
return login.login().get(10, TimeUnit.SECONDS);
} catch (Exception e) {
Throwables.propagate(e);
propagate(e);
assert false : e;
return null;
}
@ -198,12 +206,83 @@ public abstract class BaseVCloudRestClientModule<S extends VCloudClient, A exten
@Provides
@Singleton
protected Supplier<Map<String, Organization>> provideOrgMapCache(@Named(PROPERTY_SESSION_INTERVAL) long seconds,
final OrganizationMapSupplier supplier) {
return new RetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Map<String, Organization>>(authException,
seconds, new Supplier<Map<String, Organization>>() {
protected Supplier<Map<String, ? extends Organization>> provideOrgMapCache(
@Named(PROPERTY_SESSION_INTERVAL) long seconds, final OrganizationMapSupplier supplier) {
return new RetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Map<String, ? extends Organization>>(
authException, seconds, new Supplier<Map<String, ? extends Organization>>() {
@Override
public Map<String, Organization> get() {
public Map<String, ? extends Organization> get() {
return supplier.get();
}
});
}
private final static Function<NamedResource, String> name = new Function<NamedResource, String>() {
@Override
public String apply(NamedResource from) {
return from.getName();
}
};
@Singleton
public static class OrganizationMapSupplier implements Supplier<Map<String, ? extends Organization>> {
protected final Supplier<VCloudSession> sessionSupplier;
private final OrganizationsForNames organizationsForNames;
@Inject
protected OrganizationMapSupplier(Supplier<VCloudSession> sessionSupplier,
OrganizationsForNames organizationsForNames) {
this.sessionSupplier = sessionSupplier;
this.organizationsForNames = organizationsForNames;
}
@Override
public Map<String, ? extends Organization> get() {
return uniqueIndex(organizationsForNames.apply(sessionSupplier.get().getOrgs().keySet()), name);
}
}
@Singleton
public static class OrganizationCatalogSupplier implements
Supplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.Catalog>>> {
protected final Supplier<Map<String, ? extends Organization>> orgSupplier;
private final AllCatalogsInOrganization allCatalogsInOrganization;
@Inject
protected OrganizationCatalogSupplier(Supplier<Map<String, ? extends Organization>> orgSupplier,
AllCatalogsInOrganization allCatalogsInOrganization) {
this.orgSupplier = orgSupplier;
this.allCatalogsInOrganization = allCatalogsInOrganization;
}
@Override
public Map<String, Map<String, ? extends org.jclouds.vcloud.domain.Catalog>> get() {
return transformValues(
transformValues(orgSupplier.get(), allCatalogsInOrganization),
new Function<Iterable<? extends org.jclouds.vcloud.domain.Catalog>, Map<String, ? extends org.jclouds.vcloud.domain.Catalog>>() {
@Override
public Map<String, ? extends org.jclouds.vcloud.domain.Catalog> apply(
Iterable<? extends org.jclouds.vcloud.domain.Catalog> from) {
return uniqueIndex(from, name);
}
});
}
}
@Provides
@Singleton
protected Supplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.Catalog>>> provideOrganizationCatalogItemMapSupplierCache(
@Named(PROPERTY_SESSION_INTERVAL) long seconds, final OrganizationCatalogSupplier supplier) {
return new RetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.Catalog>>>(
authException, seconds,
new Supplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.Catalog>>>() {
@Override
public Map<String, Map<String, ? extends org.jclouds.vcloud.domain.Catalog>> get() {
return supplier.get();
}
@ -211,25 +290,55 @@ public abstract class BaseVCloudRestClientModule<S extends VCloudClient, A exten
}
@Singleton
public static class OrganizationMapSupplier implements Supplier<Map<String, Organization>> {
protected final Supplier<VCloudSession> sessionSupplier;
private final VCloudClient client;
public static class OrganizationCatalogItemSupplier implements
Supplier<Map<String, Map<String, Map<String, ? extends org.jclouds.vcloud.domain.CatalogItem>>>> {
protected final Supplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.Catalog>>> catalogSupplier;
private final AllCatalogItemsInCatalog allCatalogItemsInCatalog;
@Inject
protected OrganizationMapSupplier(Supplier<VCloudSession> sessionSupplier, VCloudClient client) {
this.sessionSupplier = sessionSupplier;
this.client = client;
protected OrganizationCatalogItemSupplier(
Supplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.Catalog>>> catalogSupplier,
AllCatalogItemsInCatalog allCatalogItemsInCatalog) {
this.catalogSupplier = catalogSupplier;
this.allCatalogItemsInCatalog = allCatalogItemsInCatalog;
}
@Override
public Map<String, Organization> get() {
Map<String, Organization> returnVal = Maps.newLinkedHashMap();
for (String orgName : sessionSupplier.get().getOrgs().keySet()) {
returnVal.put(orgName, client.getOrganizationNamed(orgName));
}
return returnVal;
}
public Map<String, Map<String, Map<String, ? extends org.jclouds.vcloud.domain.CatalogItem>>> get() {
return transformValues(
catalogSupplier.get(),
new Function<Map<String, ? extends org.jclouds.vcloud.domain.Catalog>, Map<String, Map<String, ? extends org.jclouds.vcloud.domain.CatalogItem>>>() {
@Override
public Map<String, Map<String, ? extends CatalogItem>> apply(
Map<String, ? extends org.jclouds.vcloud.domain.Catalog> from) {
return transformValues(
from,
new Function<org.jclouds.vcloud.domain.Catalog, Map<String, ? extends org.jclouds.vcloud.domain.CatalogItem>>() {
@Override
public Map<String, ? extends CatalogItem> apply(org.jclouds.vcloud.domain.Catalog from) {
return uniqueIndex(allCatalogItemsInCatalog.apply(from), name);
}
});
}
});
}
}
@Provides
@Singleton
protected Supplier<Map<String, Map<String, Map<String, ? extends org.jclouds.vcloud.domain.CatalogItem>>>> provideOrganizationCatalogItemSupplierCache(
@Named(PROPERTY_SESSION_INTERVAL) long seconds, final OrganizationCatalogItemSupplier supplier) {
return new RetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Map<String, Map<String, Map<String, ? extends org.jclouds.vcloud.domain.CatalogItem>>>>(
authException, seconds,
new Supplier<Map<String, Map<String, Map<String, ? extends org.jclouds.vcloud.domain.CatalogItem>>>>() {
@Override
public Map<String, Map<String, Map<String, ? extends org.jclouds.vcloud.domain.CatalogItem>>> get() {
return supplier.get();
}
});
}
@Provides
@ -312,7 +421,7 @@ public abstract class BaseVCloudRestClientModule<S extends VCloudClient, A exten
@Singleton
protected URI provideDefaultVDC(Organization org) {
checkState(org.getVDCs().size() > 0, "No vdcs present in org: " + org.getName());
return Iterables.get(org.getVDCs().values(), 0).getLocation();
return get(org.getVDCs().values(), 0).getLocation();
}
@Provides
@ -320,7 +429,15 @@ public abstract class BaseVCloudRestClientModule<S extends VCloudClient, A exten
@Singleton
protected URI provideCatalog(Organization org, @Named(PROPERTY_IDENTITY) String user) {
checkState(org.getCatalogs().size() > 0, "No catalogs present in org: " + org.getName());
return Iterables.get(org.getCatalogs().values(), 0).getLocation();
return get(org.getCatalogs().values(), 0).getLocation();
}
@Provides
@Catalog
@Singleton
protected String provideCatalogName(
Supplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.Catalog>>> catalogs) {
return getLast(getLast(catalogs.get().values()).keySet());
}
@Provides
@ -334,7 +451,7 @@ public abstract class BaseVCloudRestClientModule<S extends VCloudClient, A exten
org.jclouds.vcloud.domain.VDC vDC = client.getDefaultVDC();
Map<String, NamedResource> networks = vDC.getAvailableNetworks();
checkState(networks.size() > 0, "No networks present in vDC: " + vDC.getName());
return Iterables.get(networks.values(), 0).getLocation();
return get(networks.values(), 0).getLocation();
} catch (AuthorizationException e) {
authException.set(e);
throw e;
@ -360,6 +477,6 @@ public abstract class BaseVCloudRestClientModule<S extends VCloudClient, A exten
@Singleton
protected URI provideDefaultTasksList(Organization org) {
checkState(org.getTasksLists().size() > 0, "No tasks lists present in org: " + org.getName());
return Iterables.get(org.getTasksLists().values(), 0).getLocation();
return get(org.getTasksLists().values(), 0).getLocation();
}
}

View File

@ -25,14 +25,14 @@ import org.jclouds.vcloud.VCloudAsyncClient;
import org.jclouds.vcloud.VCloudClient;
/**
* Configures the VCloud authentication service connection, including logging and http transport.
* Configures the VCloud authentication service connection, including logging
* and http transport.
*
* @author Adrian Cole
*/
@RequiresHttp
@ConfiguresRestClient
public class VCloudRestClientModule extends
BaseVCloudRestClientModule<VCloudClient, VCloudAsyncClient> {
public class VCloudRestClientModule extends BaseVCloudRestClientModule<VCloudClient, VCloudAsyncClient> {
public VCloudRestClientModule() {
super(VCloudClient.class, VCloudAsyncClient.class);

View File

@ -19,22 +19,22 @@
package org.jclouds.vcloud.domain;
import java.util.SortedMap;
import java.util.Map;
import org.jclouds.vcloud.domain.internal.CatalogImpl;
import org.jclouds.vcloud.domain.internal.CatalogItemImpl;
import com.google.inject.ImplementedBy;
/**
* @author Adrian Cole
*/
@ImplementedBy(CatalogImpl.class)
@ImplementedBy(CatalogItemImpl.class)
public interface CatalogItem extends NamedResource {
String getDescription();
NamedResource getEntity();
SortedMap<String, String> getProperties();
Map<String, String> getProperties();
}

View File

@ -22,8 +22,8 @@ package org.jclouds.vcloud.domain.internal;
import static com.google.common.base.Preconditions.checkNotNull;
import java.net.URI;
import java.util.SortedMap;
import java.util.TreeMap;
import java.util.LinkedHashMap;
import java.util.Map;
import org.jclouds.vcloud.VCloudMediaType;
import org.jclouds.vcloud.domain.Catalog;
@ -37,7 +37,7 @@ import com.google.inject.internal.Nullable;
* @author Adrian Cole
*
*/
public class CatalogImpl extends TreeMap<String, NamedResource> implements Catalog {
public class CatalogImpl extends LinkedHashMap<String, NamedResource> implements Catalog {
/** The serialVersionUID */
private static final long serialVersionUID = 8464716396538298809L;
@ -47,7 +47,7 @@ public class CatalogImpl extends TreeMap<String, NamedResource> implements Catal
private final URI location;
public CatalogImpl(String id, String name, URI location, @Nullable String description,
SortedMap<String, NamedResource> contents) {
Map<String, NamedResource> contents) {
this.id = checkNotNull(id, "id");
this.name = checkNotNull(name, "name");
this.description = description;

View File

@ -22,7 +22,7 @@ package org.jclouds.vcloud.domain.internal;
import static com.google.common.base.Preconditions.checkNotNull;
import java.net.URI;
import java.util.SortedMap;
import java.util.Map;
import javax.annotation.Nullable;
@ -43,10 +43,10 @@ public class CatalogItemImpl extends NamedResourceImpl implements CatalogItem {
private static final long serialVersionUID = 8464716396538298809L;
private final String description;
private final NamedResource entity;
private final SortedMap<String, String> properties = Maps.newTreeMap();
private final Map<String, String> properties = Maps.newLinkedHashMap();
public CatalogItemImpl(String id, String name, URI location, @Nullable String description,
NamedResource entity, SortedMap<String, String> properties) {
public CatalogItemImpl(String id, String name, URI location, @Nullable String description, NamedResource entity,
Map<String, String> properties) {
super(id, name, VCloudMediaType.CATALOGITEM_XML, location);
this.description = description;
this.entity = checkNotNull(entity, "entity");
@ -67,15 +67,15 @@ public class CatalogItemImpl extends NamedResourceImpl implements CatalogItem {
return description;
}
public SortedMap<String, String> getProperties() {
public Map<String, String> getProperties() {
return properties;
}
@Override
public String toString() {
return "CatalogItemImpl [id=" + getId() + ", name=" + getName() + ", location="
+ getLocation() + ", type=" + getType() + ", description=" + getDescription()
+ ", entity=" + entity + ", properties=" + properties + "]";
return "CatalogItemImpl [id=" + getId() + ", name=" + getName() + ", location=" + getLocation() + ", type="
+ getType() + ", description=" + getDescription() + ", entity=" + entity + ", properties=" + properties
+ "]";
}
@Override

View File

@ -75,10 +75,10 @@ public class AllCatalogItemsInCatalog implements Function<Catalog, Iterable<? ex
@SuppressWarnings("unchecked")
@Override
public Future<CatalogItem> apply(NamedResource from) {
return (Future<CatalogItem>) aclient.getCatalogItem(from.getId());
return (Future<CatalogItem>) aclient.getCatalogItem(from.getLocation());
}
}, executor, null, logger, "catalogItems in " + from.getId());
}, executor, null, logger, "catalogItems in " + from.getLocation());
return catalogItems;
}

View File

@ -58,17 +58,16 @@ public class AllCatalogsInOrganization implements Function<Organization, Iterabl
}
@Override
public Iterable<? extends Catalog> apply(Organization from) {
public Iterable<? extends Catalog> apply(final Organization org) {
Iterable<Catalog> catalogs = transformParallel(org.getCatalogs().values(),
new Function<NamedResource, Future<Catalog>>() {
@SuppressWarnings("unchecked")
@Override
public Future<Catalog> apply(NamedResource from) {
return (Future<Catalog>) aclient.findCatalogInOrgNamed(org.getName(), from.getName());
}
Iterable<Catalog> catalogItems = transformParallel(from.getCatalogs().values(),
new Function<NamedResource, Future<Catalog>>() {
@SuppressWarnings("unchecked")
@Override
public Future<Catalog> apply(NamedResource from) {
return (Future<Catalog>) aclient.getCatalog(from.getId());
}
}, executor, null, logger, "catalogs in " + from.getName());
return catalogItems;
}, executor, null, logger, "catalogs in " + org.getName());
return catalogs;
}
}

View File

@ -65,7 +65,7 @@ public class AllVDCsInOrganization implements Function<Organization, Iterable<?
@SuppressWarnings("unchecked")
@Override
public Future<VDC> apply(NamedResource from) {
return (Future<VDC>) aclient.getVDCInOrg(org.getName(), from.getName());
return (Future<VDC>) aclient.findVDCInOrgNamed(org.getName(), from.getName());
}
}, executor, null, logger, "vdcs in " + org.getName());

View File

@ -43,12 +43,12 @@ import com.google.common.collect.Iterables;
*/
@Singleton
public class OrgNameAndCatalogNameToEndpoint implements Function<Object, URI> {
private final Supplier<Map<String, Organization>> orgMap;
private final Supplier<Map<String, ? extends Organization>> orgMap;
private final String defaultOrg;
private final URI defaultUri;
@Inject
public OrgNameAndCatalogNameToEndpoint(Supplier<Map<String, Organization>> orgMap, @Org String defaultOrg,
public OrgNameAndCatalogNameToEndpoint(Supplier<Map<String, ? extends Organization>> orgMap, @Org String defaultOrg,
@Catalog URI defaultUri) {
this.orgMap = orgMap;
this.defaultOrg = defaultOrg;

View File

@ -43,13 +43,13 @@ import com.google.common.collect.Iterables;
*/
@Singleton
public class OrgNameAndTasksListNameToEndpoint implements Function<Object, URI> {
private final Supplier<Map<String, Organization>> orgMap;
private final Supplier<Map<String, ? extends Organization>> orgMap;
private final String defaultOrg;
private final URI defaultUri;
@Inject
public OrgNameAndTasksListNameToEndpoint(Supplier<Map<String, Organization>> orgMap, @Org String defaultOrg,
@TasksList URI defaultUri) {
public OrgNameAndTasksListNameToEndpoint(Supplier<Map<String, ? extends Organization>> orgMap,
@Org String defaultOrg, @TasksList URI defaultUri) {
this.orgMap = orgMap;
this.defaultOrg = defaultOrg;
this.defaultUri = defaultUri;

View File

@ -43,13 +43,13 @@ import com.google.common.collect.Iterables;
*/
@Singleton
public class OrgNameAndVDCNameToEndpoint implements Function<Object, URI> {
private final Supplier<Map<String, Organization>> orgNameToVDCEndpoint;
private final Supplier<Map<String, ? extends Organization>> orgNameToVDCEndpoint;
private final String defaultOrg;
private final URI defaultUri;
@Inject
public OrgNameAndVDCNameToEndpoint(Supplier<Map<String, Organization>> orgNameToVDCEndpoint, @Org String defaultOrg,
@VDC URI defaultUri) {
public OrgNameAndVDCNameToEndpoint(Supplier<Map<String, ? extends Organization>> orgNameToVDCEndpoint,
@Org String defaultOrg, @VDC URI defaultUri) {
this.orgNameToVDCEndpoint = orgNameToVDCEndpoint;
this.defaultOrg = defaultOrg;
this.defaultUri = defaultUri;

View File

@ -0,0 +1,76 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed 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.functions;
import static com.google.common.base.Preconditions.checkNotNull;
import java.net.URI;
import java.util.Map;
import java.util.NoSuchElementException;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.vcloud.endpoints.Catalog;
import org.jclouds.vcloud.endpoints.Org;
import com.google.common.base.Function;
import com.google.common.base.Supplier;
import com.google.common.collect.Iterables;
/**
*
* @author Adrian Cole
*/
@Singleton
public class OrgNameCatalogNameItemNameToEndpoint implements Function<Object, URI> {
private final Supplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.Catalog>>> orgCatalogMap;
private final String defaultOrg;
private final String defaultCatalog;
@Inject
public OrgNameCatalogNameItemNameToEndpoint(
Supplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.Catalog>>> orgCatalogMap,
@Org String defaultOrg, @Catalog String defaultCatalog) {
this.orgCatalogMap = orgCatalogMap;
this.defaultOrg = defaultOrg;
this.defaultCatalog = defaultCatalog;
}
@SuppressWarnings("unchecked")
public URI apply(Object from) {
Iterable<Object> orgCatalog = (Iterable<Object>) checkNotNull(from, "args");
Object org = Iterables.get(orgCatalog, 0);
Object catalog = Iterables.get(orgCatalog, 1);
Object catalogItem = Iterables.get(orgCatalog, 2);
if (org == null)
org = defaultOrg;
if (catalog == null)
catalog = defaultCatalog;
try {
Map<String, ? extends org.jclouds.vcloud.domain.Catalog> catalogs = checkNotNull(orgCatalogMap.get().get(org));
return catalogs.get(catalog).get(catalogItem).getLocation();
} catch (NullPointerException e) {
throw new NoSuchElementException(org + "/" + catalog + "/" + catalogItem + " not found in "
+ orgCatalogMap.get());
}
}
}

View File

@ -0,0 +1,77 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed 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.functions;
import static com.google.common.base.Preconditions.checkNotNull;
import java.net.URI;
import java.util.Map;
import java.util.NoSuchElementException;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.vcloud.domain.CatalogItem;
import org.jclouds.vcloud.endpoints.Catalog;
import org.jclouds.vcloud.endpoints.Org;
import com.google.common.base.Function;
import com.google.common.base.Supplier;
import com.google.common.collect.Iterables;
/**
*
* @author Adrian Cole
*/
@Singleton
public class OrgNameCatalogNameVAppTemplateNameToEndpoint implements Function<Object, URI> {
private final Supplier<Map<String, Map<String, Map<String, ? extends org.jclouds.vcloud.domain.CatalogItem>>>> orgCatalogItemMap;
private final String defaultOrg;
private final String defaultCatalog;
@Inject
public OrgNameCatalogNameVAppTemplateNameToEndpoint(
Supplier<Map<String, Map<String, Map<String, ? extends org.jclouds.vcloud.domain.CatalogItem>>>> orgCatalogItemMap,
@Org String defaultOrg, @Catalog String defaultCatalog) {
this.orgCatalogItemMap = orgCatalogItemMap;
this.defaultOrg = defaultOrg;
this.defaultCatalog = defaultCatalog;
}
@SuppressWarnings("unchecked")
public URI apply(Object from) {
Iterable<Object> orgCatalog = (Iterable<Object>) checkNotNull(from, "args");
Object org = Iterables.get(orgCatalog, 0);
Object catalog = Iterables.get(orgCatalog, 1);
Object catalogItem = Iterables.get(orgCatalog, 2);
if (org == null)
org = defaultOrg;
if (catalog == null)
catalog = defaultCatalog;
try {
Map<String, Map<String, ? extends CatalogItem>> catalogs = checkNotNull(orgCatalogItemMap.get().get(org));
return catalogs.get(catalog).get(catalogItem).getEntity().getLocation();
} catch (NullPointerException e) {
throw new NoSuchElementException(org + "/" + catalog + "/" + catalogItem + " not found in "
+ orgCatalogItemMap.get());
}
}
}

View File

@ -0,0 +1,70 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed 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.functions;
import static org.jclouds.concurrent.FutureIterables.transformParallel;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import javax.annotation.Resource;
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
import org.jclouds.Constants;
import org.jclouds.compute.reference.ComputeServiceConstants;
import org.jclouds.logging.Logger;
import org.jclouds.vcloud.VCloudAsyncClient;
import org.jclouds.vcloud.domain.Organization;
import com.google.common.base.Function;
/**
* @author Adrian Cole
*/
@Singleton
public class OrganizationsForNames implements Function<Iterable<String>, Iterable<? extends Organization>> {
@Resource
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
public Logger logger = Logger.NULL;
private final VCloudAsyncClient aclient;
private final ExecutorService executor;
@Inject
OrganizationsForNames(VCloudAsyncClient aclient, @Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor) {
this.aclient = aclient;
this.executor = executor;
}
@Override
public Iterable<? extends Organization> apply(Iterable<String> from) {
return transformParallel(from, new Function<String, Future<Organization>>() {
@SuppressWarnings("unchecked")
@Override
public Future<Organization> apply(String from) {
return (Future<Organization>) aclient.findOrganizationNamed(from);
}
}, executor, null, logger, "organizations for names");
}
}

View File

@ -20,8 +20,10 @@
package org.jclouds.vcloud.functions;
import static com.google.common.collect.Iterables.filter;
import static com.google.common.collect.Iterables.transform;
import static org.jclouds.concurrent.FutureIterables.transformParallel;
import java.net.URI;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
@ -36,17 +38,19 @@ import org.jclouds.domain.Location;
import org.jclouds.domain.LocationScope;
import org.jclouds.logging.Logger;
import org.jclouds.vcloud.VCloudAsyncClient;
import org.jclouds.vcloud.compute.domain.VCloudLocation;
import org.jclouds.vcloud.domain.Organization;
import com.google.common.base.Function;
import com.google.common.base.Predicate;
import com.google.common.collect.Sets;
/**
* @author Adrian Cole
*/
@Singleton
public class OrganizatonsForLocations implements
Function<Iterable<? extends Location>, Iterable<? extends Organization>> {
Function<Iterable<? extends Location>, Iterable<? extends Organization>> {
@Resource
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
public Logger logger = Logger.NULL;
@ -60,27 +64,35 @@ public class OrganizatonsForLocations implements
}
/**
* regions are not currently an assignable location, so they don't show up in the list. As such,
* we'll blindly look for all zones, and get their "parents"
* Zones are assignable, but we want regions. so we look for zones, whose
* parent is region. then, we use a set to extract the unique set.
*/
@Override
public Iterable<? extends Organization> apply(Iterable<? extends Location> from) {
return transformParallel(filter(from, new Predicate<Location>() {
return transformParallel(Sets.newLinkedHashSet(transform(filter(from, new Predicate<Location>() {
@Override
public boolean apply(Location input) {
return input.getScope() == LocationScope.ZONE;
}
}), new Function<Location, Future<Organization>>() {
}), new Function<Location, URI>() {
@Override
public URI apply(Location from) {
return VCloudLocation.class.cast(from.getParent()).getResource().getLocation();
}
})), new Function<URI, Future<Organization>>() {
@SuppressWarnings("unchecked")
@Override
public Future<Organization> apply(Location from) {
return (Future<Organization>) aclient.getOrganizationNamed(from.getParent().getId());
public Future<Organization> apply(URI from) {
return (Future<Organization>) aclient.getOrganization(from);
}
}, executor, null, logger, "organizations for locations");
}, executor, null, logger, "organizations for uris");
}
}

View File

@ -40,12 +40,13 @@ import org.jclouds.vcloud.domain.VAppTemplate;
import com.google.common.base.Function;
import com.google.common.base.Predicate;
/**
* @author Adrian Cole
*/
@Singleton
public class VAppTemplatesForCatalogItems implements
Function<Iterable<? extends CatalogItem>, Iterable<? extends VAppTemplate>> {
Function<Iterable<? extends CatalogItem>, Iterable<? extends VAppTemplate>> {
@Resource
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
public Logger logger = Logger.NULL;
@ -54,7 +55,7 @@ public class VAppTemplatesForCatalogItems implements
@Inject
VAppTemplatesForCatalogItems(VCloudAsyncClient aclient,
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor) {
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor) {
this.aclient = aclient;
this.executor = executor;
}
@ -73,7 +74,7 @@ public class VAppTemplatesForCatalogItems implements
@SuppressWarnings("unchecked")
@Override
public Future<VAppTemplate> apply(CatalogItem from) {
return (Future<VAppTemplate>) aclient.getVAppTemplate(from.getEntity().getId());
return (Future<VAppTemplate>) aclient.getVAppTemplate(from.getEntity().getLocation());
}
}, executor, null, logger, "vappTemplates in");

View File

@ -40,12 +40,13 @@ import org.jclouds.vcloud.domain.VAppTemplate;
import com.google.common.base.Function;
import com.google.common.base.Predicate;
/**
* @author Adrian Cole
*/
@Singleton
public class VAppTemplatesForResourceEntities implements
Function<Iterable<? extends NamedResource>, Iterable<? extends VAppTemplate>> {
Function<Iterable<? extends NamedResource>, Iterable<? extends VAppTemplate>> {
@Resource
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
public Logger logger = Logger.NULL;
@ -54,7 +55,7 @@ public class VAppTemplatesForResourceEntities implements
@Inject
VAppTemplatesForResourceEntities(VCloudAsyncClient aclient,
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor) {
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor) {
this.aclient = aclient;
this.executor = executor;
}
@ -73,7 +74,7 @@ public class VAppTemplatesForResourceEntities implements
@SuppressWarnings("unchecked")
@Override
public Future<VAppTemplate> apply(NamedResource from) {
return (Future<VAppTemplate>) aclient.getVAppTemplate(from.getId());
return (Future<VAppTemplate>) aclient.getVAppTemplate(from.getLocation());
}
}, executor, null, logger, "vappTemplates in");

View File

@ -37,15 +37,15 @@ import com.google.common.collect.Maps;
public class CatalogItemHandler extends ParseSax.HandlerWithResult<CatalogItem> {
private StringBuilder currentText = new StringBuilder();
private NamedResource catalog;
private NamedResource entity;
protected NamedResource catalogItem;
protected NamedResource entity;
private String description;
private String key;
private SortedMap<String, String> properties = Maps.newTreeMap();
protected String description;
protected String key;
protected SortedMap<String, String> properties = Maps.newTreeMap();
public CatalogItem getResult() {
return new CatalogItemImpl(catalog.getId(), catalog.getName(), catalog.getLocation(),
return new CatalogItemImpl(catalogItem.getId(), catalogItem.getName(), catalogItem.getLocation(),
description, entity, properties);
}
@ -53,7 +53,7 @@ public class CatalogItemHandler extends ParseSax.HandlerWithResult<CatalogItem>
public void startElement(String uri, String localName, String qName, Attributes attributes)
throws SAXException {
if (qName.equals("CatalogItem")) {
catalog = Utils.newNamedResource(attributes);
catalogItem = Utils.newNamedResource(attributes);
} else if (qName.equals("Entity")) {
entity = Utils.newNamedResource(attributes);
} else if (qName.equals("Property")) {

View File

@ -26,7 +26,6 @@ import static org.jclouds.vcloud.options.InstantiateVAppTemplateOptions.Builder.
import static org.testng.Assert.assertEquals;
import java.io.IOException;
import java.lang.reflect.Array;
import java.lang.reflect.Method;
import java.net.URI;
import java.util.Map;
@ -52,6 +51,8 @@ import org.jclouds.util.Utils;
import org.jclouds.vcloud.config.VCloudRestClientModule;
import org.jclouds.vcloud.domain.NamedResource;
import org.jclouds.vcloud.domain.Organization;
import org.jclouds.vcloud.domain.internal.CatalogImpl;
import org.jclouds.vcloud.domain.internal.CatalogItemImpl;
import org.jclouds.vcloud.domain.internal.NamedResourceImpl;
import org.jclouds.vcloud.domain.internal.OrganizationImpl;
import org.jclouds.vcloud.endpoints.Org;
@ -85,10 +86,13 @@ import com.google.inject.TypeLiteral;
*/
@Test(groups = "unit", testName = "vcloud.VCloudAsyncClientTest")
public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
public void testInstantiateVAppTemplate() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("instantiateVAppTemplateInVDC", String.class, String.class,
String.class, Array.newInstance(InstantiateVAppTemplateOptions.class, 0).getClass());
HttpRequest request = processor.createRequest(method, "1", "my-vapp", 3 + "");
public void testInstantiateVAppTemplateInVDCURI() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("instantiateVAppTemplateInVDC", URI.class, URI.class,
String.class, InstantiateVAppTemplateOptions[].class);
HttpRequest request = processor.createRequest(method, URI
.create("https://vcloud.safesecureweb.com/api/v0.8/vdc/1"), URI
.create("https://vcloud.safesecureweb.com/api/v0.8/vAppTemplate/3"), "my-vapp");
assertRequestLineEquals(request,
"POST https://vcloud.safesecureweb.com/api/v0.8/vdc/1/action/instantiateVAppTemplate HTTP/1.1");
@ -103,100 +107,13 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
checkFilters(request);
}
public void testInstantiateVAppTemplateOptions() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("instantiateVAppTemplateInVDC", String.class, String.class,
String.class, Array.newInstance(InstantiateVAppTemplateOptions.class, 0).getClass());
HttpRequest request = processor.createRequest(method, "1", "my-vapp", 3 + "", processorCount(1).memory(512).disk(
1024).fenceMode("allowInOut").inNetwork(URI.create("https://vcloud.safesecureweb.com/network/1990")));
assertRequestLineEquals(request,
"POST https://vcloud.safesecureweb.com/api/v0.8/vdc/1/action/instantiateVAppTemplate HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.vApp+xml\n");
assertPayloadEquals(request, Utils.toStringAndClose(getClass().getResourceAsStream(
"/newvapp-hostingcpumemdisk.xml")), "application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml",
false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, VAppHandler.class);
assertExceptionParserClassEquals(method, null);
checkFilters(request);
}
@Test(expectedExceptions = IllegalArgumentException.class)
public void testInstantiateVAppTemplateOptionsIllegalName() throws SecurityException, NoSuchMethodException,
public void testInstantiateVAppTemplateInVDCURIOptions() throws SecurityException, NoSuchMethodException,
IOException {
Method method = VCloudAsyncClient.class.getMethod("instantiateVAppTemplateInVDC", String.class, String.class,
String.class, Array.newInstance(InstantiateVAppTemplateOptions.class, 0).getClass());
processor.createRequest(method, "1", "CentOS 01", 3 + "", processorCount(1).memory(512).disk(1024).inNetwork(
URI.create("https://vcloud.safesecureweb.com/network/1990")));
}
public void testCloneVApp() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("cloneVAppInVDC", String.class, String.class, String.class,
Array.newInstance(CloneVAppOptions.class, 0).getClass());
HttpRequest request = processor.createRequest(method, "1", "4181", "my-vapp");
assertRequestLineEquals(request, "POST https://vcloud.safesecureweb.com/api/v0.8/vdc/1/action/cloneVApp HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.task+xml\n");
assertPayloadEquals(request, Utils.toStringAndClose(getClass().getResourceAsStream("/cloneVApp-default.xml")),
"application/vnd.vmware.vcloud.cloneVAppParams+xml", false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, TaskHandler.class);
assertExceptionParserClassEquals(method, null);
checkFilters(request);
}
public void testCloneVAppOptions() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("cloneVAppInVDC", String.class, String.class, String.class,
Array.newInstance(CloneVAppOptions.class, 0).getClass());
HttpRequest request = processor.createRequest(method, "1", "201", "new-linux-server", new CloneVAppOptions()
.deploy().powerOn().withDescription("The description of the new vApp"));
assertRequestLineEquals(request, "POST https://vcloud.safesecureweb.com/api/v0.8/vdc/1/action/cloneVApp HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.task+xml\n");
assertPayloadEquals(request, Utils.toStringAndClose(getClass().getResourceAsStream("/cloneVApp.xml")),
"application/vnd.vmware.vcloud.cloneVAppParams+xml", false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, TaskHandler.class);
assertExceptionParserClassEquals(method, null);
checkFilters(request);
}
@Test(expectedExceptions = IllegalArgumentException.class)
public void testCloneVAppOptionsIllegalName() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("cloneVAppInVDC", String.class, String.class, String.class,
Array.newInstance(CloneVAppOptions.class, 0).getClass());
processor.createRequest(method, "1", "201", "New Linux Server", new CloneVAppOptions().deploy().powerOn()
.withDescription("The description of the new vApp"));
}
public void testInstantiateVAppTemplateInOrg() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("instantiateVAppTemplateInOrg", String.class, String.class,
String.class, String.class, Array.newInstance(InstantiateVAppTemplateOptions.class, 0).getClass());
HttpRequest request = processor.createRequest(method, "org", "vdc", "my-vapp", 3 + "");
assertRequestLineEquals(request,
"POST https://vcloud.safesecureweb.com/api/v0.8/vdc/1/action/instantiateVAppTemplate HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.vApp+xml\n");
assertPayloadEquals(request, Utils.toStringAndClose(getClass().getResourceAsStream("/newvapp-hosting.xml")),
"application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml", false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, VAppHandler.class);
assertExceptionParserClassEquals(method, null);
checkFilters(request);
}
public void testInstantiateVAppTemplateInOrgOptions() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("instantiateVAppTemplateInOrg", String.class, String.class,
String.class, String.class, Array.newInstance(InstantiateVAppTemplateOptions.class, 0).getClass());
HttpRequest request = processor.createRequest(method, "org", "vdc", "my-vapp", 3 + "", processorCount(1).memory(
Method method = VCloudAsyncClient.class.getMethod("instantiateVAppTemplateInVDC", URI.class, URI.class,
String.class, InstantiateVAppTemplateOptions[].class);
HttpRequest request = processor.createRequest(method, URI
.create("https://vcloud.safesecureweb.com/api/v0.8/vdc/1"), URI
.create("https://vcloud.safesecureweb.com/api/v0.8/vAppTemplate/3"), "my-vapp", processorCount(1).memory(
512).disk(1024).fenceMode("allowInOut").inNetwork(
URI.create("https://vcloud.safesecureweb.com/network/1990")));
@ -217,16 +134,19 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
@Test(expectedExceptions = IllegalArgumentException.class)
public void testInstantiateVAppTemplateInOrgOptionsIllegalName() throws SecurityException, NoSuchMethodException,
IOException {
Method method = VCloudAsyncClient.class.getMethod("instantiateVAppTemplateInOrg", String.class, String.class,
String.class, String.class, Array.newInstance(InstantiateVAppTemplateOptions.class, 0).getClass());
processor.createRequest(method, "org", "vdc", "CentOS 01", 3 + "", processorCount(1).memory(512).disk(1024)
.inNetwork(URI.create("https://vcloud.safesecureweb.com/network/1990")));
Method method = VCloudAsyncClient.class.getMethod("instantiateVAppTemplateInVDC", URI.class, URI.class,
String.class, InstantiateVAppTemplateOptions[].class);
processor.createRequest(method, URI.create("https://vcloud.safesecureweb.com/api/v0.8/vdc/1"), URI
.create("https://vcloud.safesecureweb.com/api/v0.8/vdc/1"), "CentOS 01", processorCount(1).memory(512)
.disk(1024).inNetwork(URI.create("https://vcloud.safesecureweb.com/network/1990")));
}
public void testCloneVAppInOrg() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("cloneVAppInOrg", String.class, String.class, String.class,
String.class, Array.newInstance(CloneVAppOptions.class, 0).getClass());
HttpRequest request = processor.createRequest(method, "org", "vdc", "4181", "my-vapp");
public void testCloneVAppInVDC() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("cloneVAppInVDC", URI.class, URI.class, String.class,
CloneVAppOptions[].class);
HttpRequest request = processor.createRequest(method, URI
.create("https://vcloud.safesecureweb.com/api/v0.8/vdc/1"), URI
.create("https://vcloud.safesecureweb.com/api/v0.8/vapp/4181"), "my-vapp");
assertRequestLineEquals(request, "POST https://vcloud.safesecureweb.com/api/v0.8/vdc/1/action/cloneVApp HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.task+xml\n");
@ -240,11 +160,13 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
checkFilters(request);
}
public void testCloneVAppInOrgOptions() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("cloneVAppInOrg", String.class, String.class, String.class,
String.class, Array.newInstance(CloneVAppOptions.class, 0).getClass());
HttpRequest request = processor.createRequest(method, "org", "vdc", "201", "new-linux-server",
new CloneVAppOptions().deploy().powerOn().withDescription("The description of the new vApp"));
public void testCloneVAppInVDCOptions() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("cloneVAppInVDC", URI.class, URI.class, String.class,
CloneVAppOptions[].class);
HttpRequest request = processor.createRequest(method, URI
.create("https://vcloud.safesecureweb.com/api/v0.8/vdc/1"), URI
.create("https://vcloud.safesecureweb.com/api/v0.8/vapp/201"), "new-linux-server", new CloneVAppOptions()
.deploy().powerOn().withDescription("The description of the new vApp"));
assertRequestLineEquals(request, "POST https://vcloud.safesecureweb.com/api/v0.8/vdc/1/action/cloneVApp HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.task+xml\n");
@ -274,8 +196,9 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
}
public void testOrganization() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("getOrganization", String.class);
HttpRequest request = processor.createRequest(method, "1");
Method method = VCloudAsyncClient.class.getMethod("getOrganization", URI.class);
HttpRequest request = processor.createRequest(method, URI
.create("https://vcloud.safesecureweb.com/api/v0.8/org/1"));
assertRequestLineEquals(request, "GET https://vcloud.safesecureweb.com/api/v0.8/org/1 HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.org+xml\n");
@ -288,8 +211,8 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
checkFilters(request);
}
public void testOrganizationNamed() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("getOrganizationNamed", String.class);
public void testFindOrganizationNamed() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("findOrganizationNamed", String.class);
HttpRequest request = processor.createRequest(method, "org");
assertRequestLineEquals(request, "GET https://vcloud.safesecureweb.com/api/v0.8/org/1 HTTP/1.1");
@ -334,7 +257,7 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
}
public void testCatalogInOrg() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("getCatalogInOrg", String.class, String.class);
Method method = VCloudAsyncClient.class.getMethod("findCatalogInOrgNamed", String.class, String.class);
HttpRequest request = processor.createRequest(method, "org", "catalog");
assertRequestLineEquals(request, "GET https://vcloud.safesecureweb.com/api/v0.8/catalog/1 HTTP/1.1");
@ -363,9 +286,10 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
checkFilters(request);
}
public void testCatalogItem() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("getCatalogItem", String.class);
HttpRequest request = processor.createRequest(method, "2");
public void testCatalogItemURI() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("getCatalogItem", URI.class);
HttpRequest request = processor.createRequest(method, URI
.create("https://vcloud.safesecureweb.com/api/v0.8/catalogItem/2"));
assertRequestLineEquals(request, "GET https://vcloud.safesecureweb.com/api/v0.8/catalogItem/2 HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.catalogItem+xml\n");
@ -378,9 +302,42 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
checkFilters(request);
}
public void testVAppTemplate() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("getVAppTemplate", String.class);
HttpRequest request = processor.createRequest(method, "2");
public void testFindCatalogItemInOrgCatalogNamed() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("findCatalogItemInOrgCatalogNamed", String.class, String.class,
String.class);
HttpRequest request = processor.createRequest(method, "org", "catalog", "item");
assertRequestLineEquals(request, "GET https://vcloud.safesecureweb.com/api/v0.8/catalogItem/1 HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.catalogItem+xml\n");
assertPayloadEquals(request, null, null, false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, CatalogItemHandler.class);
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
checkFilters(request);
}
public void testFindVAppTemplate() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("findVAppTemplateInOrgCatalogNamed", String.class,
String.class, String.class);
HttpRequest request = processor.createRequest(method, "org", "catalog", "template");
assertRequestLineEquals(request, "GET https://vcloud.safesecureweb.com/api/v0.8/vAppTemplate/2 HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.vAppTemplate+xml\n");
assertPayloadEquals(request, null, null, false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, VAppTemplateHandler.class);
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
checkFilters(request);
}
public void testVAppTemplateURI() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("getVAppTemplate", URI.class);
HttpRequest request = processor.createRequest(method, URI
.create("https://vcloud.safesecureweb.com/api/v0.8/vAppTemplate/2"));
assertRequestLineEquals(request, "GET https://vcloud.safesecureweb.com/api/v0.8/vAppTemplate/2 HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.vAppTemplate+xml\n");
@ -408,8 +365,8 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
checkFilters(request);
}
public void testGetVDCByOrgAndName() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("getVDCInOrg", String.class, String.class);
public void testFindVDCInOrgNamed() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("findVDCInOrgNamed", String.class, String.class);
HttpRequest request = processor.createRequest(method, "org", "vdc");
assertRequestLineEquals(request, "GET https://vcloud.safesecureweb.com/api/v0.8/vdc/1 HTTP/1.1");
@ -424,19 +381,19 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
}
@Test(expectedExceptions = NoSuchElementException.class)
public void testGetVDCByOrgAndNameBadVDC() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("getVDCInOrg", String.class, String.class);
public void testFindVDCInOrgNamedBadVDC() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("findVDCInOrgNamed", String.class, String.class);
processor.createRequest(method, "org", "vdc1");
}
@Test(expectedExceptions = NoSuchElementException.class)
public void testGetVDCByOrgAndNameBadOrg() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("getVDCInOrg", String.class, String.class);
public void testFindVDCInOrgNamedBadOrg() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("findVDCInOrgNamed", String.class, String.class);
processor.createRequest(method, "org1", "vdc");
}
public void testGetVDCByOrgAndNameNullOrg() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("getVDCInOrg", String.class, String.class);
public void testFindVDCInOrgNamedNullOrg() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("findVDCInOrgNamed", String.class, String.class);
HttpRequest request = processor.createRequest(method, null, "vdc");
assertRequestLineEquals(request, "GET https://vcloud.safesecureweb.com/api/v0.8/vdc/1 HTTP/1.1");
@ -450,8 +407,8 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
checkFilters(request);
}
public void testGetVDCByOrgAndNameNullOrgAndVDC() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("getVDCInOrg", String.class, String.class);
public void testFindVDCInOrgNamedNullOrgAndVDC() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("findVDCInOrgNamed", String.class, String.class);
HttpRequest request = processor.createRequest(method, null, null);
assertRequestLineEquals(request, "GET https://vcloud.safesecureweb.com/api/v0.8/vdc/1 HTTP/1.1");
@ -465,9 +422,10 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
checkFilters(request);
}
public void testGetVDCString() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("getVDC", String.class);
HttpRequest request = processor.createRequest(method, "1");
public void testGetVDC() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("getVDC", URI.class);
HttpRequest request = processor.createRequest(method, URI
.create("https://vcloud.safesecureweb.com/api/v0.8/vdc/1"));
assertRequestLineEquals(request, "GET https://vcloud.safesecureweb.com/api/v0.8/vdc/1 HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.vdc+xml\n");
@ -510,8 +468,8 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
checkFilters(request);
}
public void testGetTasksListInOrg() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("getTasksListInOrg", String.class, String.class);
public void testFindTasksListInOrgNamed() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("findTasksListInOrgNamed", String.class, String.class);
HttpRequest request = processor.createRequest(method, "org", "tasksList");
assertRequestLineEquals(request, "GET https://vcloud.safesecureweb.com/api/v0.8/tasksList/1 HTTP/1.1");
@ -732,6 +690,8 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
protected void configure() {
super.configure();
bind(OrganizationMapSupplier.class).to(TestOrganizationMapSupplier.class);
bind(OrganizationCatalogSupplier.class).to(TestOrganizationCatalogItemMapSupplier.class);
bind(OrganizationCatalogItemSupplier.class).to(TestOrganizationCatalogItemSupplier.class);
}
@Override
@ -817,6 +777,48 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
}
}
@Singleton
public static class TestOrganizationCatalogItemMapSupplier extends OrganizationCatalogSupplier {
@Inject
protected TestOrganizationCatalogItemMapSupplier() {
super(null, null);
}
@Override
public Map<String, Map<String, ? extends org.jclouds.vcloud.domain.Catalog>> get() {
return ImmutableMap.<String, Map<String, ? extends org.jclouds.vcloud.domain.Catalog>> of("org",
ImmutableMap.<String, org.jclouds.vcloud.domain.Catalog> of("catalog", new CatalogImpl("1", "catalog", URI
.create("https://vcloud.safesecureweb.com/api/v0.8/catalog/1"), "description", ImmutableMap
.<String, NamedResource> of("item", new NamedResourceImpl("1", "item",
"application/vnd.vmware.vcloud.catalogItem+xml", URI
.create("https://vcloud.safesecureweb.com/api/v0.8/catalogItem/1")), "template",
new NamedResourceImpl("2", "template", "application/vnd.vmware.vcloud.vAppTemplate+xml", URI
.create("https://vcloud.safesecureweb.com/api/v0.8/catalogItem/2"))))));
}
}
@Singleton
public static class TestOrganizationCatalogItemSupplier extends OrganizationCatalogItemSupplier {
protected TestOrganizationCatalogItemSupplier() {
super(null, null);
}
@Override
public Map<String, Map<String, Map<String, ? extends org.jclouds.vcloud.domain.CatalogItem>>> get() {
return ImmutableMap.<String, Map<String, Map<String, ? extends org.jclouds.vcloud.domain.CatalogItem>>> of(
"org", ImmutableMap.<String, Map<String, ? extends org.jclouds.vcloud.domain.CatalogItem>> of(
"catalog", ImmutableMap.<String, org.jclouds.vcloud.domain.CatalogItem> of("template",
new CatalogItemImpl("2", "template", URI
.create("https://vcloud.safesecureweb.com/api/v0.8/catalogItem/2"), "description",
new NamedResourceImpl("2", "template",
"application/vnd.vmware.vcloud.vAppTemplate+xml", URI
.create("https://vcloud.safesecureweb.com/api/v0.8/vAppTemplate/2")),
ImmutableMap.<String, String> of()))));
}
}
}
}

View File

@ -56,28 +56,28 @@ public class VCloudClientLiveTest {
@Test
public void testOrganization() throws Exception {
Organization response = connection.getOrganizationNamed(null);
Organization response = connection.findOrganizationNamed(null);
assertNotNull(response);
assertNotNull(response.getName());
assert response.getCatalogs().size() >= 1;
assert response.getTasksLists().size() >= 1;
assert response.getVDCs().size() >= 1;
assertEquals(connection.getOrganizationNamed(response.getName()), response);
assertEquals(connection.findOrganizationNamed(response.getName()), response);
}
@Test
public void testCatalog() throws Exception {
Catalog response = connection.getCatalogInOrg(null, null);
Catalog response = connection.findCatalogInOrgNamed(null, null);
assertNotNull(response);
assertNotNull(response.getId());
assertNotNull(response.getName());
assertNotNull(response.getLocation());
assertEquals(connection.getCatalogInOrg(null, response.getName()), response);
assertEquals(connection.findCatalogInOrgNamed(null, response.getName()), response);
}
@Test
public void testGetNetwork() throws Exception {
VDC response = connection.getVDCInOrg(null, null);
VDC response = connection.findVDCInOrgNamed(null, null);
for (NamedResource resource : response.getAvailableNetworks().values()) {
if (resource.getType().equals(VCloudMediaType.NETWORK_XML)) {
Network item = connection.getNetwork(resource.getId());
@ -88,10 +88,10 @@ public class VCloudClientLiveTest {
@Test
public void testGetCatalogItem() throws Exception {
Catalog response = connection.getCatalogInOrg(null, null);
Catalog response = connection.findCatalogInOrgNamed(null, null);
for (NamedResource resource : response.values()) {
if (resource.getType().equals(VCloudMediaType.CATALOGITEM_XML)) {
CatalogItem item = connection.getCatalogItem(resource.getId());
CatalogItem item = connection.findCatalogItemInOrgCatalogNamed(null, null, resource.getName());
assertNotNull(item);
assertNotNull(item.getEntity());
assertNotNull(item.getId());
@ -104,12 +104,12 @@ public class VCloudClientLiveTest {
@Test
public void testGetVAppTemplate() throws Exception {
Catalog response = connection.getCatalogInOrg(null, null);
Catalog response = connection.findCatalogInOrgNamed(null, null);
for (NamedResource resource : response.values()) {
if (resource.getType().equals(VCloudMediaType.CATALOGITEM_XML)) {
CatalogItem item = connection.getCatalogItem(resource.getId());
CatalogItem item = connection.getCatalogItem(resource.getLocation());
if (item.getEntity().getType().equals(VCloudMediaType.VAPPTEMPLATE_XML)) {
assertNotNull(connection.getVAppTemplate(item.getEntity().getId()));
assertNotNull(connection.findVAppTemplateInOrgCatalogNamed(null, null, item.getEntity().getName()));
}
}
}
@ -117,19 +117,19 @@ public class VCloudClientLiveTest {
@Test
public void testDefaultVDC() throws Exception {
VDC response = connection.getVDCInOrg(null, null);
VDC response = connection.findVDCInOrgNamed(null, null);
assertNotNull(response);
assertNotNull(response.getId());
assertNotNull(response.getName());
assertNotNull(response.getLocation());
assertNotNull(response.getResourceEntities());
assertNotNull(response.getAvailableNetworks());
assertEquals(connection.getVDC(response.getId()).getId(), response.getId());
assertEquals(connection.getVDC(response.getLocation()), response);
}
@Test
public void testDefaultTasksList() throws Exception {
org.jclouds.vcloud.domain.TasksList response = connection.getTasksListInOrg(null, null);
org.jclouds.vcloud.domain.TasksList response = connection.findTasksListInOrgNamed(null, null);
assertNotNull(response);
assertNotNull(response.getId());
assertNotNull(response.getLocation());
@ -139,7 +139,7 @@ public class VCloudClientLiveTest {
@Test
public void testGetTask() throws Exception {
org.jclouds.vcloud.domain.TasksList response = connection.getTasksListInOrg(null, null);
org.jclouds.vcloud.domain.TasksList response = connection.findTasksListInOrgNamed(null, null);
assertNotNull(response);
assertNotNull(response.getLocation());
assertNotNull(response.getTasks());
@ -151,7 +151,7 @@ public class VCloudClientLiveTest {
@Test
public void testGetVApp() throws Exception {
VDC response = connection.getVDCInOrg(null, null);
VDC response = connection.findVDCInOrgNamed(null, null);
for (NamedResource item : response.getResourceEntities().values()) {
if (item.getType().equals(VCloudMediaType.VAPP_XML)) {
VApp app = connection.getVApp(item.getId());

View File

@ -36,6 +36,7 @@ import org.jclouds.vcloud.VCloudClient;
import org.jclouds.vcloud.domain.ResourceType;
import org.jclouds.vcloud.domain.VApp;
import org.jclouds.vcloud.domain.VAppStatus;
import org.jclouds.vcloud.domain.VAppTemplate;
import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeGroups;
@ -64,7 +65,7 @@ public class VCloudComputeClientLiveTest {
protected String id;
protected String publicAddress;
protected String templateId;
protected String templateName;
public static class Expectation {
final long hardDisk;
@ -88,10 +89,11 @@ public class VCloudComputeClientLiveTest {
int processorCount = 1;
int memory = 512;
VAppTemplate template = client.findVAppTemplateInOrgCatalogNamed(null, null, templateName);
InstantiateVAppTemplateOptions options = processorCount(1).memory(512).disk(10 * 1025 * 1024).productProperties(
ImmutableMap.of("foo", "bar"));
id = computeClient.start(null, null, serverName, templateId, options).get("id");
id = computeClient.start(null, template.getLocation(), templateName, options).get("id");
Expectation expectation = expectationMap.get(toTest);
VApp vApp = client.getVApp(id);
@ -149,7 +151,7 @@ public class VCloudComputeClientLiveTest {
expectationMap = ImmutableMap.<OsFamily, Expectation> builder().put(OsFamily.CENTOS,
new Expectation(4194304 / 2 * 10, "Red Hat Enterprise Linux 5 (64-bit)")).build();
provider = "vcloudtest";
templateId = "3";
templateName = "Ubuntu JeOS 9.10 (32-bit)";
}
}

View File

@ -1,88 +0,0 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed 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.compute.strategy;
import static org.easymock.EasyMock.expect;
import static org.easymock.classextension.EasyMock.createMock;
import static org.easymock.classextension.EasyMock.createNiceMock;
import static org.easymock.classextension.EasyMock.replay;
import static org.easymock.classextension.EasyMock.verify;
import static org.testng.Assert.assertEquals;
import java.security.SecureRandom;
import java.util.concurrent.ExecutorService;
import org.jclouds.compute.domain.Image;
import org.jclouds.compute.domain.Template;
import org.jclouds.compute.strategy.AddNodeWithTagStrategy;
import org.jclouds.compute.strategy.ListNodesStrategy;
import org.jclouds.compute.util.ComputeUtils;
import org.testng.annotations.Test;
/**
* @author Adrian Cole
*/
@Test(groups = "unit", testName = "vcloud.EncodeTemplateIdIntoNameRunNodesAndAddToSetStrategyTest")
public class EncodeTemplateIdIntoNameRunNodesAndAddToSetStrategyTest {
@Test
public void testGetNextName() {
SecureRandom random = createMock(SecureRandom.class);
expect(random.nextInt(255)).andReturn(12).atLeastOnce();
replay(random);
EncodeTemplateIdIntoNameRunNodesAndAddToSetStrategy strategy = new EncodeTemplateIdIntoNameRunNodesAndAddToSetStrategy(
createNiceMock(AddNodeWithTagStrategy.class),
createNiceMock(ListNodesStrategy.class), "%s-%s%s",
createNiceMock(ComputeUtils.class),
createNiceMock(ExecutorService.class), random);
String oldName = null;
for (int i = 0; i < 5; i++) {
Template template = createMock(Template.class);
Image image = createMock(Image.class);
expect(template.getImage()).andReturn(image);
expect(image.getProviderId()).andReturn("233");
replay(template);
replay(image);
String name = strategy.getNextName("test", template);
if (oldName != null) {
assert !oldName.equals(name);
oldName = name;
}
assertEquals(name.length(), 10);
assertEquals(name.substring(0, 4), "test");
System.out.println(name);
assertEquals(name.substring(5, 8), "0e9");
assert name.substring(8, 9).matches("[0-9a-f]+");
verify(template);
verify(image);
}
verify(random);
}
}

View File

@ -22,7 +22,8 @@ package org.jclouds.vcloud.hostingdotcom;
import static org.jclouds.vcloud.VCloudMediaType.CATALOG_XML;
import static org.jclouds.vcloud.VCloudMediaType.VAPP_XML;
import javax.annotation.Nullable;
import java.net.URI;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
@ -30,12 +31,13 @@ import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import org.jclouds.predicates.validators.DnsNameValidator;
import org.jclouds.rest.annotations.Endpoint;
import org.jclouds.rest.annotations.EndpointParam;
import org.jclouds.rest.annotations.ExceptionParser;
import org.jclouds.rest.annotations.MapBinder;
import org.jclouds.rest.annotations.MapPayloadParam;
import org.jclouds.rest.annotations.ParamParser;
import org.jclouds.rest.annotations.ParamValidators;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.XMLResponseParser;
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
@ -43,8 +45,6 @@ import org.jclouds.vcloud.VCloudAsyncClient;
import org.jclouds.vcloud.binders.BindInstantiateVAppTemplateParamsToXmlPayload;
import org.jclouds.vcloud.domain.Catalog;
import org.jclouds.vcloud.filters.SetVCloudTokenCookie;
import org.jclouds.vcloud.functions.OrgNameAndVDCNameToEndpoint;
import org.jclouds.vcloud.functions.VAppTemplateIdToUri;
import org.jclouds.vcloud.hostingdotcom.domain.HostingDotComVApp;
import org.jclouds.vcloud.hostingdotcom.xml.HostingDotComVAppHandler;
import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions;
@ -89,26 +89,9 @@ public interface HostingDotComVCloudAsyncClient extends VCloudAsyncClient {
@XMLResponseParser(HostingDotComVAppHandler.class)
@MapBinder(BindInstantiateVAppTemplateParamsToXmlPayload.class)
@Override
ListenableFuture<? extends HostingDotComVApp> instantiateVAppTemplateInOrg(
@Nullable @EndpointParam(parser = OrgNameAndVDCNameToEndpoint.class) String orgName,
@Nullable @EndpointParam(parser = OrgNameAndVDCNameToEndpoint.class) String vdcName,
@MapPayloadParam("name") String appName,
@MapPayloadParam("template") @ParamParser(VAppTemplateIdToUri.class) String templateId,
InstantiateVAppTemplateOptions... options);
@Deprecated
@POST
@Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class)
@Path("/vdc/{vDCId}/action/instantiateVAppTemplate")
@Produces("application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml")
@Consumes(VAPP_XML)
// required for hosting.com to operate
@XMLResponseParser(HostingDotComVAppHandler.class)
@MapBinder(BindInstantiateVAppTemplateParamsToXmlPayload.class)
@Override
ListenableFuture<? extends HostingDotComVApp> instantiateVAppTemplateInVDC(@PathParam("vDCId") String vDCId,
@MapPayloadParam("name") String appName,
@MapPayloadParam("template") @ParamParser(VAppTemplateIdToUri.class) String templateId,
ListenableFuture<? extends HostingDotComVApp> instantiateVAppTemplateInVDC(@EndpointParam URI vdc,
@MapPayloadParam("template") URI template,
@MapPayloadParam("name") @ParamValidators(DnsNameValidator.class) String appName,
InstantiateVAppTemplateOptions... options);
}

View File

@ -19,6 +19,7 @@
package org.jclouds.vcloud.hostingdotcom;
import java.net.URI;
import java.util.concurrent.TimeUnit;
import org.jclouds.concurrent.Timeout;
@ -39,12 +40,7 @@ public interface HostingDotComVCloudClient extends VCloudClient {
@Override
@Timeout(duration = 600, timeUnit = TimeUnit.SECONDS)
HostingDotComVApp instantiateVAppTemplateInOrg(String org, String vDC, String appName, String templateId,
InstantiateVAppTemplateOptions... options);
@Override
@Timeout(duration = 600, timeUnit = TimeUnit.SECONDS)
HostingDotComVApp instantiateVAppTemplateInVDC(String vDC, String appName, String templateId,
HostingDotComVApp instantiateVAppTemplateInVDC(URI vDC, URI template, String appName,
InstantiateVAppTemplateOptions... options);
@Override

View File

@ -29,6 +29,7 @@ import org.jclouds.vcloud.VCloudClient;
import org.jclouds.vcloud.compute.BaseVCloudComputeClient;
import org.jclouds.vcloud.domain.VApp;
import org.jclouds.vcloud.domain.VAppStatus;
import org.jclouds.vcloud.domain.VAppTemplate;
import org.jclouds.vcloud.hostingdotcom.domain.HostingDotComVApp;
import com.google.common.base.Predicate;
@ -41,18 +42,16 @@ import com.google.common.collect.ImmutableMap;
public class HostingDotComVCloudComputeClient extends BaseVCloudComputeClient {
@Inject
protected HostingDotComVCloudComputeClient(VCloudClient client,
Predicate<String> successTester,
protected HostingDotComVCloudComputeClient(VCloudClient client, Predicate<String> successTester,
Map<VAppStatus, NodeState> vAppStatusToNodeState) {
super(client, successTester, vAppStatusToNodeState);
}
@Override
protected Map<String, String> parseResponse(String templateId,
VApp vAppResponse) {
protected Map<String, String> parseResponse(VAppTemplate template, VApp vAppResponse) {
HostingDotComVApp hVApp = HostingDotComVApp.class.cast(vAppResponse);
return ImmutableMap.<String, String> of("id", vAppResponse.getId(),
"username", hVApp.getUsername(), "password", hVApp.getPassword());
return ImmutableMap.<String, String> of("id", vAppResponse.getId(), "username", hVApp.getUsername(), "password",
hVApp.getPassword());
}
}

View File

@ -63,7 +63,7 @@ public class HostingDotComVCloudComputeClientLiveTest extends VCloudComputeClien
expectationMap = ImmutableMap.<OsFamily, Expectation> builder().put(OsFamily.CENTOS,
new Expectation(4194304 / 2 * 10, "Red Hat Enterprise Linux 5 (64-bit)")).build();
provider = "vcloudtest";
templateId = "3";
templateName = "3";
}
}

View File

@ -19,6 +19,7 @@
package org.jclouds.vcloud.terremark;
import static org.jclouds.vcloud.VCloudMediaType.CATALOGITEM_XML;
import static org.jclouds.vcloud.VCloudMediaType.CATALOG_XML;
import static org.jclouds.vcloud.VCloudMediaType.ORG_XML;
import static org.jclouds.vcloud.VCloudMediaType.VAPP_XML;
@ -30,6 +31,7 @@ import static org.jclouds.vcloud.terremark.TerremarkVCloudMediaType.NODESERVICE_
import static org.jclouds.vcloud.terremark.TerremarkVCloudMediaType.PUBLICIPSLIST_XML;
import static org.jclouds.vcloud.terremark.TerremarkVCloudMediaType.PUBLICIP_XML;
import java.net.URI;
import java.util.Set;
import javax.annotation.Nullable;
@ -43,7 +45,6 @@ import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import org.jclouds.predicates.validators.DnsNameValidator;
import org.jclouds.rest.annotations.BinderParam;
import org.jclouds.rest.annotations.Endpoint;
import org.jclouds.rest.annotations.EndpointParam;
import org.jclouds.rest.annotations.ExceptionParser;
@ -66,9 +67,9 @@ import org.jclouds.vcloud.domain.VDC;
import org.jclouds.vcloud.endpoints.Org;
import org.jclouds.vcloud.filters.SetVCloudTokenCookie;
import org.jclouds.vcloud.functions.OrgNameAndVDCNameToEndpoint;
import org.jclouds.vcloud.functions.OrgNameCatalogNameItemNameToEndpoint;
import org.jclouds.vcloud.functions.OrgNameToEndpoint;
import org.jclouds.vcloud.functions.VAppId;
import org.jclouds.vcloud.functions.VAppTemplateIdToUri;
import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions;
import org.jclouds.vcloud.terremark.binders.BindNodeConfigurationToXmlPayload;
import org.jclouds.vcloud.terremark.binders.BindVAppConfigurationToXmlPayload;
@ -76,10 +77,11 @@ import org.jclouds.vcloud.terremark.binders.TerremarkBindInstantiateVAppTemplate
import org.jclouds.vcloud.terremark.domain.CustomizationParameters;
import org.jclouds.vcloud.terremark.domain.InternetService;
import org.jclouds.vcloud.terremark.domain.Node;
import org.jclouds.vcloud.terremark.domain.NodeConfiguration;
import org.jclouds.vcloud.terremark.domain.Protocol;
import org.jclouds.vcloud.terremark.domain.PublicIpAddress;
import org.jclouds.vcloud.terremark.domain.TerremarkCatalogItem;
import org.jclouds.vcloud.terremark.domain.TerremarkOrganization;
import org.jclouds.vcloud.terremark.domain.TerremarkVDC;
import org.jclouds.vcloud.terremark.domain.VAppConfiguration;
import org.jclouds.vcloud.terremark.functions.ParseTaskFromLocationHeader;
import org.jclouds.vcloud.terremark.functions.ReturnVoidOnDeleteDefaultIp;
@ -91,6 +93,7 @@ import org.jclouds.vcloud.terremark.xml.InternetServicesHandler;
import org.jclouds.vcloud.terremark.xml.NodeHandler;
import org.jclouds.vcloud.terremark.xml.NodesHandler;
import org.jclouds.vcloud.terremark.xml.PublicIpAddressesHandler;
import org.jclouds.vcloud.terremark.xml.TerremarkCatalogItemHandler;
import org.jclouds.vcloud.terremark.xml.TerremarkOrgHandler;
import org.jclouds.vcloud.terremark.xml.TerremarkVDCHandler;
import org.jclouds.vcloud.xml.CatalogHandler;
@ -108,6 +111,27 @@ import com.google.common.util.concurrent.ListenableFuture;
*/
@RequestFilters(SetVCloudTokenCookie.class)
public interface TerremarkVCloudAsyncClient extends VCloudAsyncClient {
/**
* @see VCloudClient#getCatalogItemInOrg
*/
@GET
@Consumes(CATALOGITEM_XML)
@XMLResponseParser(TerremarkCatalogItemHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<? extends TerremarkCatalogItem> findCatalogItemInOrgCatalogNamed(
@Nullable @EndpointParam(parser = OrgNameCatalogNameItemNameToEndpoint.class) String orgName,
@Nullable @EndpointParam(parser = OrgNameCatalogNameItemNameToEndpoint.class) String catalogName,
@Nullable @EndpointParam(parser = OrgNameCatalogNameItemNameToEndpoint.class) String itemName);
/**
* @see VCloudClient#getCatalogItem
*/
@Override
@GET
@Consumes(CATALOGITEM_XML)
@XMLResponseParser(TerremarkCatalogItemHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<? extends TerremarkCatalogItem> getCatalogItem(@EndpointParam URI catalogItem);
@GET
@Deprecated
@ -117,22 +141,20 @@ public interface TerremarkVCloudAsyncClient extends VCloudAsyncClient {
ListenableFuture<? extends TerremarkOrganization> getDefaultOrganization();
@GET
@Deprecated
@Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class)
@Path("/org/{orgId}")
@XMLResponseParser(TerremarkOrgHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
@Consumes(ORG_XML)
ListenableFuture<? extends TerremarkOrganization> getOrganization(@PathParam("orgId") String orgId);
ListenableFuture<? extends TerremarkOrganization> getOrganization(@EndpointParam URI orgId);
/**
* @see VCloudClient#getOrganizationNamed
* @see VCloudClient#findOrganizationNamed
*/
@Override
@GET
@XMLResponseParser(TerremarkOrgHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
@Consumes(ORG_XML)
ListenableFuture<? extends TerremarkOrganization> getOrganizationNamed(
ListenableFuture<? extends TerremarkOrganization> findOrganizationNamed(
@Nullable @EndpointParam(parser = OrgNameToEndpoint.class) String orgName);
/**
@ -147,7 +169,9 @@ public interface TerremarkVCloudAsyncClient extends VCloudAsyncClient {
/**
* Terremark does not have multiple catalogs, so we ignore this parameter.
*/
@Deprecated
@GET
@Override
@Endpoint(org.jclouds.vcloud.endpoints.Catalog.class)
@XMLResponseParser(CatalogHandler.class)
@Consumes(CATALOG_XML)
@ -157,46 +181,37 @@ public interface TerremarkVCloudAsyncClient extends VCloudAsyncClient {
/**
* @see TerremarkVCloudExpressClient#getVDC
*/
@Override
@GET
@Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class)
@Path("/vdc/{vDCId}")
@XMLResponseParser(TerremarkVDCHandler.class)
@Consumes(VDC_XML)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<? extends VDC> getVDC(@PathParam("vDCId") String vDCId);
ListenableFuture<? extends TerremarkVDC> getVDC(@EndpointParam URI vdc);
/**
* @see VCloudClient#instantiateVAppTemplate
* @see VCloudClient#findVDCInOrgNamed
*/
@GET
@Override
@POST
@Path("/action/instantiateVAppTemplate")
@Produces("application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml")
@Consumes(VAPP_XML)
@XMLResponseParser(VAppHandler.class)
@MapBinder(TerremarkBindInstantiateVAppTemplateParamsToXmlPayload.class)
ListenableFuture<? extends VApp> instantiateVAppTemplateInOrg(
@XMLResponseParser(TerremarkVDCHandler.class)
@Consumes(VDC_XML)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<? extends VDC> findVDCInOrgNamed(
@Nullable @EndpointParam(parser = OrgNameAndVDCNameToEndpoint.class) String orgName,
@Nullable @EndpointParam(parser = OrgNameAndVDCNameToEndpoint.class) String vdcName,
@MapPayloadParam("name") @ParamValidators(DnsNameValidator.class) String appName,
@MapPayloadParam("template") @ParamParser(VAppTemplateIdToUri.class) String templateId,
InstantiateVAppTemplateOptions... options);
@Nullable @EndpointParam(parser = OrgNameAndVDCNameToEndpoint.class) String vdcName);
/**
* @see VCloudClient#instantiateVAppTemplateInVDC
*/
@Deprecated
@Override
@POST
@Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class)
@Path("/vdc/{vDCId}/action/instantiateVAppTemplate")
@Path("action/instantiateVAppTemplate")
@Produces("application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml")
@Consumes(VAPP_XML)
@XMLResponseParser(VAppHandler.class)
@MapBinder(TerremarkBindInstantiateVAppTemplateParamsToXmlPayload.class)
ListenableFuture<? extends VApp> instantiateVAppTemplateInVDC(@PathParam("vDCId") String vDCId,
ListenableFuture<? extends VApp> instantiateVAppTemplateInVDC(@EndpointParam URI vdc,
@MapPayloadParam("template") URI template,
@MapPayloadParam("name") @ParamValidators(DnsNameValidator.class) String appName,
@MapPayloadParam("template") @ParamParser(VAppTemplateIdToUri.class) String templateId,
InstantiateVAppTemplateOptions... options);
/**
@ -331,8 +346,10 @@ public interface TerremarkVCloudAsyncClient extends VCloudAsyncClient {
@Produces(NODESERVICE_XML)
@Consumes(NODESERVICE_XML)
@XMLResponseParser(NodeHandler.class)
@MapBinder(BindNodeConfigurationToXmlPayload.class)
ListenableFuture<? extends Node> configureNode(@PathParam("nodeId") int nodeId,
@BinderParam(BindNodeConfigurationToXmlPayload.class) NodeConfiguration nodeConfiguration);
@MapPayloadParam("name") String name, @MapPayloadParam("enabled") boolean enabled,
@Nullable @MapPayloadParam("description") String description);
/**
* @see TerremarkVCloudExpressClient#deleteNode
@ -357,8 +374,9 @@ public interface TerremarkVCloudAsyncClient extends VCloudAsyncClient {
VAppConfiguration configuration);
/**
* @see TerremarkVCloudExpressClient#getCustomizationOptionsOfCatalogItem
* @see TerremarkVCloudClient#getCustomizationOptionsOfCatalogItem
*/
@Deprecated
@GET
@Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class)
@Path("/extensions/template/{catalogItemId}/options/customization")
@ -367,4 +385,12 @@ public interface TerremarkVCloudAsyncClient extends VCloudAsyncClient {
ListenableFuture<? extends CustomizationParameters> getCustomizationOptionsOfCatalogItem(
@PathParam("catalogItemId") String catalogItemId);
/**
* @see TerremarkVCloudClient#getCustomizationOptions
*/
@GET
@XMLResponseParser(CustomizationParametersHandler.class)
@Consumes(CATALOGITEMCUSTOMIZATIONPARAMETERS_XML)
ListenableFuture<? extends CustomizationParameters> getCustomizationOptions(@EndpointParam URI customization);
}

View File

@ -19,9 +19,12 @@
package org.jclouds.vcloud.terremark;
import java.net.URI;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import javax.annotation.Nullable;
import org.jclouds.concurrent.Timeout;
import org.jclouds.vcloud.VCloudClient;
import org.jclouds.vcloud.domain.Task;
@ -29,10 +32,11 @@ import org.jclouds.vcloud.domain.VApp;
import org.jclouds.vcloud.terremark.domain.CustomizationParameters;
import org.jclouds.vcloud.terremark.domain.InternetService;
import org.jclouds.vcloud.terremark.domain.Node;
import org.jclouds.vcloud.terremark.domain.NodeConfiguration;
import org.jclouds.vcloud.terremark.domain.Protocol;
import org.jclouds.vcloud.terremark.domain.PublicIpAddress;
import org.jclouds.vcloud.terremark.domain.TerremarkCatalogItem;
import org.jclouds.vcloud.terremark.domain.TerremarkOrganization;
import org.jclouds.vcloud.terremark.domain.TerremarkVDC;
import org.jclouds.vcloud.terremark.domain.VAppConfiguration;
import org.jclouds.vcloud.terremark.options.AddInternetServiceOptions;
import org.jclouds.vcloud.terremark.options.AddNodeOptions;
@ -47,19 +51,31 @@ import org.jclouds.vcloud.terremark.options.AddNodeOptions;
*/
@Timeout(duration = 300, timeUnit = TimeUnit.SECONDS)
public interface TerremarkVCloudClient extends VCloudClient {
@Override
TerremarkCatalogItem getCatalogItem(URI catalogItem);
@Override
TerremarkVDC getVDC(URI catalogItem);
@Override
TerremarkCatalogItem findCatalogItemInOrgCatalogNamed(String orgName, String catalogName, String itemName);
@Deprecated
@Override
TerremarkOrganization getDefaultOrganization();
@Override
TerremarkOrganization getOrganization(URI orgId);
@Override
TerremarkOrganization findOrganizationNamed(String orgName);
@Deprecated
@Override
TerremarkOrganization getOrganization(String orgId);
@Override
TerremarkOrganization getOrganizationNamed(String orgName);
CustomizationParameters getCustomizationOptionsOfCatalogItem(String catalogItemId);
CustomizationParameters getCustomizationOptions(URI customizationOptions);
/**
* This call returns a list of public IP addresses.
*/
@ -67,7 +83,6 @@ public interface TerremarkVCloudClient extends VCloudClient {
void deletePublicIp(int ipId);
/**
* This call adds an internet service to a known, existing public IP. This
* call is identical to Add Internet Service except you specify the public IP
@ -109,7 +124,7 @@ public interface TerremarkVCloudClient extends VCloudClient {
Node getNode(int nodeId);
Node configureNode(int nodeId, NodeConfiguration nodeConfiguration);
Node configureNode(int nodeId, String name, boolean enabled, @Nullable String description);
void deleteNode(int nodeId);

View File

@ -19,10 +19,10 @@
package org.jclouds.vcloud.terremark.binders;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.jclouds.vcloud.terremark.reference.TerremarkConstants.PROPERTY_TERREMARK_EXTENSION_NS;
import java.util.Map;
import java.util.Properties;
import javax.inject.Inject;
@ -33,9 +33,10 @@ import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.TransformerException;
import org.jclouds.http.HttpRequest;
import org.jclouds.rest.MapBinder;
import org.jclouds.rest.binders.BindToStringPayload;
import org.jclouds.vcloud.terremark.domain.NodeConfiguration;
import com.google.common.base.Throwables;
import com.jamesmurty.utils.XMLBuilder;
/**
@ -44,51 +45,41 @@ import com.jamesmurty.utils.XMLBuilder;
*
*/
@Singleton
public class BindNodeConfigurationToXmlPayload extends BindToStringPayload {
public class BindNodeConfigurationToXmlPayload implements MapBinder {
private final String ns;
private final BindToStringPayload stringBinder;
@Inject
BindNodeConfigurationToXmlPayload(@Named(PROPERTY_TERREMARK_EXTENSION_NS) String ns) {
BindNodeConfigurationToXmlPayload(@Named(PROPERTY_TERREMARK_EXTENSION_NS) String ns, BindToStringPayload stringBinder) {
this.ns = ns;
this.stringBinder = stringBinder;
}
@Override
public void bindToRequest(HttpRequest request, Object input) {
NodeConfiguration nodeConfiguration = (NodeConfiguration) checkNotNull(input,
"nodeConfiguration");
checkArgument(nodeConfiguration.getDescription() != null
|| nodeConfiguration.getEnabled() != null || nodeConfiguration.getName() != null,
"no configuration set");
try {
super.bindToRequest(request, generateXml(nodeConfiguration));
} catch (ParserConfigurationException e) {
throw new RuntimeException(e);
} catch (FactoryConfigurationError e) {
throw new RuntimeException(e);
} catch (TransformerException e) {
throw new RuntimeException(e);
}
}
protected String generateXml(NodeConfiguration nodeConfiguration)
throws ParserConfigurationException, FactoryConfigurationError, TransformerException {
protected String generateXml(Map<String, String> postParams) throws ParserConfigurationException,
FactoryConfigurationError, TransformerException {
XMLBuilder rootBuilder = XMLBuilder.create("NodeService").a("xmlns", ns).a("xmlns:xsi",
"http://www.w3.org/2001/XMLSchema-instance").a("xmlns:xsd",
"http://www.w3.org/2001/XMLSchema");
if (nodeConfiguration.getDescription() != null)
rootBuilder.e("Description").t(nodeConfiguration.getDescription());
if (nodeConfiguration.getName() != null)
rootBuilder.e("Name").t(nodeConfiguration.getName());
if (nodeConfiguration.getEnabled() != null)
rootBuilder.e("Enabled").t(nodeConfiguration.getEnabled());
"http://www.w3.org/2001/XMLSchema-instance").a("xmlns:xsd", "http://www.w3.org/2001/XMLSchema");
rootBuilder.e("Name").t(checkNotNull(postParams.get("name"), "name"));
rootBuilder.e("Enabled").t(checkNotNull(postParams.get("enabled"), "enabled"));
if (postParams.containsKey("description") && postParams.get("description") != null)
rootBuilder.e("Description").t(postParams.get("description"));
Properties outputProperties = new Properties();
outputProperties.put(javax.xml.transform.OutputKeys.OMIT_XML_DECLARATION, "yes");
return rootBuilder.asString(outputProperties);
}
protected String ifNullDefaultTo(String value, String defaultValue) {
return value != null ? value : checkNotNull(defaultValue, "defaultValue");
@Override
public void bindToRequest(HttpRequest request, Map<String, String> postParams) {
try {
stringBinder.bindToRequest(request, generateXml(postParams));
} catch (Exception e) {
Throwables.propagate(e);
}
}
@Override
public void bindToRequest(HttpRequest request, Object input) {
throw new IllegalArgumentException("this is a map binder");
}
}

View File

@ -23,11 +23,13 @@ import static com.google.common.collect.Iterables.filter;
import static com.google.common.collect.Iterables.getLast;
import static org.jclouds.vcloud.terremark.options.AddInternetServiceOptions.Builder.withDescription;
import java.net.URI;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Set;
import javax.annotation.Nullable;
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Provider;
@ -42,6 +44,7 @@ import org.jclouds.vcloud.domain.TaskStatus;
import org.jclouds.vcloud.domain.TasksList;
import org.jclouds.vcloud.domain.VApp;
import org.jclouds.vcloud.domain.VAppStatus;
import org.jclouds.vcloud.domain.VAppTemplate;
import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions;
import org.jclouds.vcloud.terremark.TerremarkECloudClient;
import org.jclouds.vcloud.terremark.TerremarkVCloudExpressClient;
@ -76,16 +79,16 @@ public class TerremarkVCloudComputeClient extends BaseVCloudComputeClient {
}
@Override
protected Map<String, String> parseAndValidateResponse(String templateId, VApp vAppResponse) {
Credentials credentials = credentialsProvider.execute(client.getVAppTemplate(templateId));
Map<String, String> toReturn = super.parseResponse(templateId, vAppResponse);
protected Map<String, String> parseAndValidateResponse(VAppTemplate template, VApp vAppResponse) {
Credentials credentials = credentialsProvider.execute(template);
Map<String, String> toReturn = super.parseResponse(template, vAppResponse);
toReturn.put("username", credentials.identity);
toReturn.put("password", credentials.credential);
return toReturn;
}
@Override
public Map<String, String> start(String org, String vDC, String name, String templateId,
public Map<String, String> start(@Nullable URI VDC, URI templateId, String name,
InstantiateVAppTemplateOptions options, int... portsToOpen) {
if (options.getDiskSizeKilobytes() != null) {
logger.warn("trmk does not support resizing the primary disk; unsetting disk size");
@ -94,11 +97,12 @@ public class TerremarkVCloudComputeClient extends BaseVCloudComputeClient {
if (portsToOpen.length > 0 && !options.shouldBlockOnDeploy())
throw new IllegalArgumentException("We cannot open ports on terremark unless we can deploy the vapp");
String password = null;
if (client.getVAppTemplate(templateId).getDescription().indexOf("Windows") != -1) {
VAppTemplate template = client.getVAppTemplate(templateId);
if (template.getDescription().indexOf("Windows") != -1) {
password = passwordGenerator.get();
options.getProperties().put("password", password);
}
Map<String, String> response = super.start(org, vDC, name, templateId, options, portsToOpen);
Map<String, String> response = super.start(VDC, templateId, name, options, portsToOpen);
if (password != null) {
response = new LinkedHashMap<String, String>(response);
response.put("password", password);

View File

@ -22,6 +22,7 @@ package org.jclouds.vcloud.terremark.compute.config;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.jclouds.vcloud.terremark.options.TerremarkInstantiateVAppTemplateOptions.Builder.processorCount;
import java.net.URI;
import java.security.SecureRandom;
import java.util.Map;
import java.util.Set;
@ -49,6 +50,7 @@ import org.jclouds.compute.strategy.ListNodesStrategy;
import org.jclouds.compute.strategy.PopulateDefaultLoginCredentialsForImageStrategy;
import org.jclouds.compute.strategy.RebootNodeStrategy;
import org.jclouds.compute.strategy.RunNodesAndAddToSetStrategy;
import org.jclouds.compute.strategy.impl.EncodeTagIntoNameRunNodesAndAddToSetStrategy;
import org.jclouds.vcloud.VCloudAsyncClient;
import org.jclouds.vcloud.VCloudClient;
import org.jclouds.vcloud.compute.VCloudComputeClient;
@ -64,7 +66,6 @@ import org.jclouds.vcloud.terremark.compute.domain.OrgAndName;
import org.jclouds.vcloud.terremark.compute.functions.NodeMetadataToOrgAndName;
import org.jclouds.vcloud.terremark.compute.options.TerremarkVCloudTemplateOptions;
import org.jclouds.vcloud.terremark.compute.strategy.ParseVAppTemplateDescriptionToGetDefaultLoginCredentials;
import org.jclouds.vcloud.terremark.compute.strategy.TerremarkEncodeTemplateIdIntoNameRunNodesAndAddToSetStrategy;
import org.jclouds.vcloud.terremark.compute.strategy.TerremarkVCloudGetNodeMetadataStrategy;
import org.jclouds.vcloud.terremark.domain.KeyPair;
import org.jclouds.vcloud.terremark.options.TerremarkInstantiateVAppTemplateOptions;
@ -115,9 +116,8 @@ public class TerremarkVCloudComputeServiceContextModule extends VCloudComputeSer
@Override
public NodeMetadata execute(String tag, String name, Template template) {
TerremarkInstantiateVAppTemplateOptions options = getOptions.apply(template);
Map<String, String> metaMap = computeClient.start(template.getLocation().getParent().getId(), template
.getLocation().getId(), name, template.getImage().getProviderId(), options, template.getOptions()
.getInboundPorts());
Map<String, String> metaMap = computeClient.start(URI.create(template.getLocation().getId()), URI
.create(template.getImage().getId()), name, options, template.getOptions().getInboundPorts());
return getNode.execute(metaMap.get("id"));
}
@ -150,7 +150,7 @@ public class TerremarkVCloudComputeServiceContextModule extends VCloudComputeSer
}).to(new TypeLiteral<ComputeServiceContextImpl<VCloudClient, VCloudAsyncClient>>() {
}).in(Scopes.SINGLETON);
// NOTE
bind(RunNodesAndAddToSetStrategy.class).to(TerremarkEncodeTemplateIdIntoNameRunNodesAndAddToSetStrategy.class);
bind(RunNodesAndAddToSetStrategy.class).to(EncodeTagIntoNameRunNodesAndAddToSetStrategy.class);
bind(ListNodesStrategy.class).to(VCloudListNodesStrategy.class);
// NOTE
bind(GetNodeMetadataStrategy.class).to(TerremarkVCloudGetNodeMetadataStrategy.class);

View File

@ -1,73 +0,0 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed 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.compute.strategy;
import java.security.SecureRandom;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ExecutorService;
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
import org.jclouds.Constants;
import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.domain.Template;
import org.jclouds.compute.strategy.AddNodeWithTagStrategy;
import org.jclouds.compute.strategy.ListNodesStrategy;
import org.jclouds.compute.util.ComputeUtils;
import org.jclouds.domain.LocationScope;
import org.jclouds.vcloud.compute.strategy.EncodeTemplateIdIntoNameRunNodesAndAddToSetStrategy;
import org.jclouds.vcloud.terremark.compute.options.TerremarkVCloudTemplateOptions;
import java.util.concurrent.Future;
/**
* creates futures that correlate to
*
* @author Adrian Cole
*/
@Singleton
public class TerremarkEncodeTemplateIdIntoNameRunNodesAndAddToSetStrategy extends
EncodeTemplateIdIntoNameRunNodesAndAddToSetStrategy {
private final CreateNewKeyPairUnlessUserSpecifiedOtherwise createNewKeyPairUnlessUserSpecifiedOtherwise;
@Inject
protected TerremarkEncodeTemplateIdIntoNameRunNodesAndAddToSetStrategy(
AddNodeWithTagStrategy addNodeWithTagStrategy, ListNodesStrategy listNodesStrategy,
@Named("NAMING_CONVENTION") String nodeNamingConvention, ComputeUtils utils,
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor, SecureRandom random,
CreateNewKeyPairUnlessUserSpecifiedOtherwise createNewKeyPairUnlessUserSpecifiedOtherwise) {
super(addNodeWithTagStrategy, listNodesStrategy, nodeNamingConvention, utils, executor, random);
this.createNewKeyPairUnlessUserSpecifiedOtherwise = createNewKeyPairUnlessUserSpecifiedOtherwise;
}
@Override
public Map<?, Future<Void>> execute(String tag, int count, Template template, Set<NodeMetadata> nodes,
Map<NodeMetadata, Exception> badNodes) {
assert template.getLocation().getParent().getScope() == LocationScope.REGION : "template location should have a parent of org, which should be mapped to region: "
+ template.getLocation();
createNewKeyPairUnlessUserSpecifiedOtherwise.execute(template.getLocation().getParent().getId(), tag, template
.getOptions().as(TerremarkVCloudTemplateOptions.class));
return super.execute(tag, count, template, nodes, badNodes);
}
}

View File

@ -102,7 +102,7 @@ public class TerremarkVCloudExpressRestClientModule extends
@Override
public NamedResource apply(NamedResource from) {
return client.getOrganizationNamed(from.getName()).getKeysList();
return client.findOrganizationNamed(from.getName()).getKeysList();
}
});

View File

@ -1,98 +0,0 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed 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.domain;
/**
*
* @author Adrian Cole
*
*/
public class NodeConfiguration {
private String name = null;
private String description = null;
private String enabled = null;
public NodeConfiguration enableTraffic() {
this.enabled = "true";
return this;
}
public NodeConfiguration disableTraffic() {
this.enabled = "false";
return this;
}
public NodeConfiguration changeNameTo(String name) {
this.name = name;
return this;
}
public NodeConfiguration changeDescriptionTo(String description) {
this.description = description;
return this;
}
public static class Builder {
/**
* @see NodeConfiguration#changeNameTo(String)
*/
public static NodeConfiguration changeNameTo(String name) {
NodeConfiguration options = new NodeConfiguration();
return options.changeNameTo(name);
}
/**
* @see NodeConfiguration#changeDescriptionTo(String)
*/
public static NodeConfiguration changeDescriptionTo(String description) {
NodeConfiguration options = new NodeConfiguration();
return options.changeDescriptionTo(description);
}
/**
* @see NodeConfiguration#enableTraffic()
*/
public static NodeConfiguration enableTraffic() {
NodeConfiguration options = new NodeConfiguration();
return options.enableTraffic();
}
/**
* @see NodeConfiguration#disableTraffic()
*/
public static NodeConfiguration disableTraffic() {
NodeConfiguration options = new NodeConfiguration();
return options.disableTraffic();
}
}
public String getName() {
return name;
}
public String getDescription() {
return description;
}
public String getEnabled() {
return enabled;
}
}

View File

@ -0,0 +1,38 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed 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.domain;
import org.jclouds.vcloud.domain.CatalogItem;
import org.jclouds.vcloud.domain.NamedResource;
import org.jclouds.vcloud.terremark.domain.internal.TerremarkCatalogItemImpl;
import com.google.inject.ImplementedBy;
/**
* @author Adrian Cole
*/
@ImplementedBy(TerremarkCatalogItemImpl.class)
public interface TerremarkCatalogItem extends CatalogItem {
NamedResource getComputeOptions();
NamedResource getCustomizationOptions();
}

View File

@ -0,0 +1,88 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed 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.domain.internal;
import java.net.URI;
import java.util.Map;
import org.jclouds.vcloud.domain.NamedResource;
import org.jclouds.vcloud.domain.internal.CatalogItemImpl;
import org.jclouds.vcloud.terremark.domain.TerremarkCatalogItem;
/**
*
* @author Adrian Cole
*
*/
public class TerremarkCatalogItemImpl extends CatalogItemImpl implements TerremarkCatalogItem {
private final NamedResource computeOptions;
private final NamedResource customizationOptions;
public TerremarkCatalogItemImpl(String id, String name, URI location, String description,
NamedResource computeOptions, NamedResource customizationOptions, NamedResource entity,
Map<String, String> properties) {
super(id, name, location, description, entity, properties);
this.computeOptions = computeOptions;
this.customizationOptions = customizationOptions;
}
@Override
public NamedResource getComputeOptions() {
return computeOptions;
}
@Override
public NamedResource getCustomizationOptions() {
return customizationOptions;
}
@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result + ((computeOptions == null) ? 0 : computeOptions.hashCode());
result = prime * result + ((customizationOptions == null) ? 0 : customizationOptions.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (!super.equals(obj))
return false;
if (getClass() != obj.getClass())
return false;
TerremarkCatalogItemImpl other = (TerremarkCatalogItemImpl) obj;
if (computeOptions == null) {
if (other.computeOptions != null)
return false;
} else if (!computeOptions.equals(other.computeOptions))
return false;
if (customizationOptions == null) {
if (other.customizationOptions != null)
return false;
} else if (!customizationOptions.equals(other.customizationOptions))
return false;
return true;
}
}

View File

@ -55,6 +55,9 @@ public class ParseTerremarkVCloudErrorFromHttpResponse implements HttpErrorHandl
try {
String content = parseErrorFromContentOrNull(command, response);
switch (response.getStatusCode()) {
case 400:
exception = new IllegalArgumentException(response.getMessage(), exception);
break;
case 401:
exception = new AuthorizationException(command.getRequest(), content);
break;

View File

@ -0,0 +1,59 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed 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.xml;
import static org.jclouds.vcloud.util.Utils.newNamedResource;
import org.jclouds.vcloud.domain.NamedResource;
import org.jclouds.vcloud.terremark.domain.TerremarkCatalogItem;
import org.jclouds.vcloud.terremark.domain.internal.TerremarkCatalogItemImpl;
import org.jclouds.vcloud.xml.CatalogItemHandler;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
/**
* @author Adrian Cole
*/
public class TerremarkCatalogItemHandler extends CatalogItemHandler {
private NamedResource customizationOptions;
private NamedResource computeOptions;
public TerremarkCatalogItem getResult() {
return new TerremarkCatalogItemImpl(catalogItem.getId(), catalogItem.getName(), catalogItem.getLocation(),
description, computeOptions, customizationOptions, entity, properties);
}
@Override
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
super.startElement(uri, localName, qName, attributes);
if (qName.equals("Link")) {
int nameIndex = attributes.getIndex("name");
if (nameIndex != -1) {
if (attributes.getValue(nameIndex).equals("Customization Options")) {
customizationOptions = newNamedResource(attributes);
} else if (attributes.getValue(nameIndex).equals("Compute Options")) {
computeOptions = newNamedResource(attributes);
}
}
}
}
}

View File

@ -47,21 +47,22 @@ import org.jclouds.ssh.jsch.config.JschSshClientModule;
import org.jclouds.vcloud.VCloudClientLiveTest;
import org.jclouds.vcloud.VCloudMediaType;
import org.jclouds.vcloud.domain.Catalog;
import org.jclouds.vcloud.domain.CatalogItem;
import org.jclouds.vcloud.domain.NamedResource;
import org.jclouds.vcloud.domain.ResourceAllocation;
import org.jclouds.vcloud.domain.ResourceType;
import org.jclouds.vcloud.domain.Task;
import org.jclouds.vcloud.domain.VApp;
import org.jclouds.vcloud.domain.VAppStatus;
import org.jclouds.vcloud.domain.VAppTemplate;
import org.jclouds.vcloud.domain.VDC;
import org.jclouds.vcloud.options.CloneVAppOptions;
import org.jclouds.vcloud.predicates.TaskSuccess;
import org.jclouds.vcloud.terremark.domain.CustomizationParameters;
import org.jclouds.vcloud.terremark.domain.InternetService;
import org.jclouds.vcloud.terremark.domain.Node;
import org.jclouds.vcloud.terremark.domain.NodeConfiguration;
import org.jclouds.vcloud.terremark.domain.Protocol;
import org.jclouds.vcloud.terremark.domain.PublicIpAddress;
import org.jclouds.vcloud.terremark.domain.TerremarkCatalogItem;
import org.jclouds.vcloud.terremark.domain.TerremarkVDC;
import org.jclouds.vcloud.terremark.options.TerremarkInstantiateVAppTemplateOptions;
import org.testng.annotations.AfterTest;
@ -96,6 +97,7 @@ public abstract class TerremarkClientLiveTest extends VCloudClientLiveTest {
private RetryablePredicate<IPSocket> socketTester;
private RetryablePredicate<String> successTester;
private VApp clone;
private VDC vdc;
public static final String PREFIX = System.getProperty("user.name") + "-terremark";
@Test(expectedExceptions = NullPointerException.class)
@ -106,14 +108,15 @@ public abstract class TerremarkClientLiveTest extends VCloudClientLiveTest {
@Test
public void testGetAllInternetServices() throws Exception {
for (InternetService service : tmClient.getAllInternetServicesInVDC(tmClient.getDefaultVDC().getId())) {
for (InternetService service : tmClient.getAllInternetServicesInVDC(tmClient.findVDCInOrgNamed(null, null)
.getId())) {
assertNotNull(tmClient.getNodes(service.getId()));
}
}
@Test
public void testGetPublicIpsAssociatedWithVDC() throws Exception {
for (PublicIpAddress ip : tmClient.getPublicIpsAssociatedWithVDC(tmClient.getDefaultVDC().getId())) {
for (PublicIpAddress ip : tmClient.getPublicIpsAssociatedWithVDC(tmClient.findVDCInOrgNamed(null, null).getId())) {
assertNotNull(tmClient.getInternetServicesOnPublicIp(ip.getId()));
assertNotNull(tmClient.getPublicIp(ip.getId()));
}
@ -121,11 +124,11 @@ public abstract class TerremarkClientLiveTest extends VCloudClientLiveTest {
@Test
public void testGetConfigCustomizationOptions() throws Exception {
Catalog response = connection.getDefaultCatalog();
Catalog response = connection.findCatalogInOrgNamed(null, null);
for (NamedResource resource : response.values()) {
if (resource.getType().equals(VCloudMediaType.CATALOGITEM_XML)) {
CatalogItem item = connection.getCatalogItem(resource.getId());
assert tmClient.getCustomizationOptionsOfCatalogItem(item.getId()) != null;
TerremarkCatalogItem item = tmClient.findCatalogItemInOrgCatalogNamed(null, null, resource.getName());
assert tmClient.getCustomizationOptions(item.getCustomizationOptions().getLocation()) != null;
}
}
}
@ -133,7 +136,7 @@ public abstract class TerremarkClientLiveTest extends VCloudClientLiveTest {
@Test
public void testDefaultVDC() throws Exception {
super.testDefaultVDC();
TerremarkVDC response = (TerremarkVDC) tmClient.getDefaultVDC();
TerremarkVDC response = (TerremarkVDC) tmClient.findVDCInOrgNamed(null, null);
assertNotNull(response);
assertNotNull(response.getCatalog());
assertNotNull(response.getInternetServices());
@ -155,27 +158,26 @@ public abstract class TerremarkClientLiveTest extends VCloudClientLiveTest {
// String catalogOs = "CentOS 5.3 (32-bit)";
// String expectedOs = "Red Hat Enterprise Linux 5 (32-bit)";
// lookup the name of the datacenter you are deploying into
String vdc = tmClient.getDefaultVDC().getName();
// lookup the datacenter you are deploying into
vdc = tmClient.findVDCInOrgNamed(null, null);
// lookup the id of the item in the catalog you wish to deploy by name
Catalog catalog = tmClient.getDefaultCatalog();
String itemId = catalog.get(itemName).getId();
// create an options object to collect the configuration we want.
TerremarkInstantiateVAppTemplateOptions instantiateOptions = createInstantiateOptions();
TerremarkCatalogItem item = tmClient.findCatalogItemInOrgCatalogNamed(null, null, itemName);
// if this template supports setting the root password, let's add it to
// our options
CustomizationParameters customizationOptions = tmClient.getCustomizationOptionsOfCatalogItem(itemId);
CustomizationParameters customizationOptions = tmClient.getCustomizationOptions(item.getCustomizationOptions()
.getLocation());
if (customizationOptions.canCustomizePassword())
instantiateOptions.withPassword("robotsarefun");
// the vAppTemplateId tends to be the same as the itemId, but just in
// case, convert
String vAppTemplateId = tmClient.getCatalogItem(itemId).getEntity().getId();
VAppTemplate vAppTemplate = tmClient.getVAppTemplate(item.getEntity().getLocation());
// instantiate, noting vApp returned has minimal details
vApp = tmClient.instantiateVAppTemplateInOrg(null, vdc, serverName, vAppTemplateId, instantiateOptions);
vApp = tmClient.instantiateVAppTemplateInVDC(vdc.getLocation(), vAppTemplate.getLocation(), serverName,
instantiateOptions);
assertEquals(vApp.getStatus(), VAppStatus.RESOLVED);
@ -203,7 +205,7 @@ public abstract class TerremarkClientLiveTest extends VCloudClientLiveTest {
vApp = tmClient.getVApp(vApp.getId());
NamedResource vAppResource = tmClient.getDefaultVDC().getResourceEntities().get(serverName);
NamedResource vAppResource = tmClient.findVDCInOrgNamed(null, null).getResourceEntities().get(serverName);
assertEquals(vAppResource.getId(), vApp.getId());
int processorCount = 1;
@ -229,11 +231,11 @@ public abstract class TerremarkClientLiveTest extends VCloudClientLiveTest {
PublicIpAddress ip;
if (tmClient instanceof TerremarkVCloudExpressClient) {
is = TerremarkVCloudExpressClient.class.cast(tmClient).addInternetServiceToVDC(
tmClient.getVDCInOrg(null, null).getId(), "SSH", Protocol.TCP, 22);
tmClient.findVDCInOrgNamed(null, null).getId(), "SSH", Protocol.TCP, 22);
ip = is.getPublicIpAddress();
} else {
ip = TerremarkECloudClient.class.cast(tmClient)
.activatePublicIpInVDC(tmClient.getVDCInOrg(null, null).getId());
ip = TerremarkECloudClient.class.cast(tmClient).activatePublicIpInVDC(
tmClient.findVDCInOrgNamed(null, null).getId());
is = tmClient.addInternetServiceToExistingIp(ip.getId(), "SSH", Protocol.TCP, 22);
}
publicIp = ip.getAddress();
@ -244,11 +246,6 @@ public abstract class TerremarkClientLiveTest extends VCloudClientLiveTest {
assert successTester.apply(tmClient.powerOffVApp(vApp.getId()).getId());
System.out.printf("%d: done powering off vApp%n", System.currentTimeMillis());
// lookup the id of the datacenter you are deploying into
String vdc = tmClient.getDefaultVDC().getName();
String vAppIdToClone = vApp.getId();
StringBuffer name = new StringBuffer();
for (int i = 0; i < 15; i++)
name.append("b");
@ -257,7 +254,7 @@ public abstract class TerremarkClientLiveTest extends VCloudClientLiveTest {
CloneVAppOptions options = deploy().powerOn().withDescription("The description of " + newName);
System.out.printf("%d: cloning vApp%n", System.currentTimeMillis());
Task task = tmClient.cloneVAppInOrg(null, vdc, vAppIdToClone, newName, options);
Task task = tmClient.cloneVAppInVDC(vdc.getLocation(), vApp.getLocation(), newName, options);
// wait for the task to complete
assert successTester.apply(task.getId());
@ -300,8 +297,7 @@ public abstract class TerremarkClientLiveTest extends VCloudClientLiveTest {
@Test(enabled = true, dependsOnMethods = "testPublicIp")
public void testConfigureNode() throws InterruptedException, ExecutionException, TimeoutException, IOException {
node = tmClient.configureNode(node.getId(), new NodeConfiguration().changeDescriptionTo("holy cow"));
assertEquals(node.getDescription(), "holy cow");
tmClient.configureNode(node.getId(), node.getName(), node.isEnabled(), "holy cow");
}
@Test(enabled = true, dependsOnMethods = "testPublicIp")

View File

@ -62,7 +62,6 @@ import org.jclouds.vcloud.internal.VCloudVersionsAsyncClient;
import org.jclouds.vcloud.internal.VCloudLoginAsyncClient.VCloudSession;
import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions;
import org.jclouds.vcloud.terremark.config.TerremarkVCloudExpressRestClientModule;
import org.jclouds.vcloud.terremark.domain.NodeConfiguration;
import org.jclouds.vcloud.terremark.domain.Protocol;
import org.jclouds.vcloud.terremark.options.AddInternetServiceOptions;
import org.jclouds.vcloud.terremark.options.AddNodeOptions;
@ -127,8 +126,8 @@ public class TerremarkECloudAsyncClientTest extends RestClientTest<TerremarkEClo
}
public void testGetVDC() throws SecurityException, NoSuchMethodException, IOException {
Method method = TerremarkECloudAsyncClient.class.getMethod("getVDC", String.class);
HttpRequest request = processor.createRequest(method, "1");
Method method = TerremarkECloudAsyncClient.class.getMethod("getVDC", URI.class);
HttpRequest request = processor.createRequest(method, URI.create("https://vcloud/vdc/1"));
assertRequestLineEquals(request, "GET https://vcloud/vdc/1 HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.vdc+xml\n");
@ -141,11 +140,12 @@ public class TerremarkECloudAsyncClientTest extends RestClientTest<TerremarkEClo
checkFilters(request);
}
public void testInstantiateVAppTemplate() throws SecurityException, NoSuchMethodException, IOException {
Method method = TerremarkECloudAsyncClient.class.getMethod("instantiateVAppTemplateInOrg", String.class,
String.class, String.class, String.class, Array.newInstance(InstantiateVAppTemplateOptions.class, 0)
.getClass());
HttpRequest request = processor.createRequest(method, "org", "vdc", "name", 3 + "");
public void testInstantiateVAppTemplateInVDCURI() throws SecurityException, NoSuchMethodException, IOException {
Method method = TerremarkECloudAsyncClient.class.getMethod("instantiateVAppTemplateInVDC", URI.class, URI.class,
String.class, InstantiateVAppTemplateOptions[].class);
HttpRequest request = processor.createRequest(method, URI
.create("https://vcloud.safesecureweb.com/api/v0.8/vdc/1"), URI.create("https://vcloud/vAppTemplate/3"),
"name");
assertRequestLineEquals(request,
"POST https://vcloud.safesecureweb.com/api/v0.8/vdc/1/action/instantiateVAppTemplate HTTP/1.1");
@ -161,13 +161,14 @@ public class TerremarkECloudAsyncClientTest extends RestClientTest<TerremarkEClo
checkFilters(request);
}
public void testInstantiateVAppTemplateOptions() throws SecurityException, NoSuchMethodException, IOException {
Method method = TerremarkECloudAsyncClient.class.getMethod("instantiateVAppTemplateInOrg", String.class,
String.class, String.class, String.class, Array.newInstance(InstantiateVAppTemplateOptions.class, 0)
.getClass());
HttpRequest request = processor.createRequest(method, "org", "vdc", "name", 3 + "",
TerremarkInstantiateVAppTemplateOptions.Builder.processorCount(2).memory(512).inRow("row").inGroup("group")
.withPassword("password").inNetwork(URI.create("http://network")));
public void testInstantiateVAppTemplateInVDCURIOptions() throws SecurityException, NoSuchMethodException,
IOException {
Method method = TerremarkECloudAsyncClient.class.getMethod("instantiateVAppTemplateInVDC", URI.class, URI.class,
String.class, InstantiateVAppTemplateOptions[].class);
HttpRequest request = processor.createRequest(method, URI
.create("https://vcloud.safesecureweb.com/api/v0.8/vdc/1"), URI.create("https://vcloud/vAppTemplate/3"),
"name", TerremarkInstantiateVAppTemplateOptions.Builder.processorCount(2).memory(512).inRow("row").inGroup(
"group").withPassword("password").inNetwork(URI.create("http://network")));
assertRequestLineEquals(request,
"POST https://vcloud.safesecureweb.com/api/v0.8/vdc/1/action/instantiateVAppTemplate HTTP/1.1");
@ -313,15 +314,34 @@ public class TerremarkECloudAsyncClientTest extends RestClientTest<TerremarkEClo
checkFilters(request);
}
public void testConfigureNode() throws SecurityException, NoSuchMethodException, IOException {
Method method = TerremarkECloudAsyncClient.class.getMethod("configureNode", int.class, NodeConfiguration.class);
HttpRequest request = processor.createRequest(method, 12, new NodeConfiguration().changeDescriptionTo("eggs"));
public void testConfigureNodeWithDescription() throws SecurityException, NoSuchMethodException, IOException {
Method method = TerremarkECloudAsyncClient.class.getMethod("configureNode", int.class, String.class,
boolean.class, String.class);
HttpRequest request = processor.createRequest(method, 12, "name", true, "eggs");
assertRequestLineEquals(request, "PUT https://vcloud/extensions/nodeService/12 HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.tmrk.vCloud.nodeService+xml\n");
assertPayloadEquals(
request,
"<NodeService xmlns=\"urn:tmrk:vCloudExpressExtensions-1.6\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"><Description>eggs</Description></NodeService>",
"<NodeService xmlns=\"urn:tmrk:vCloudExpressExtensions-1.6\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"><Name>name</Name><Enabled>true</Enabled><Description>eggs</Description></NodeService>",
"application/vnd.tmrk.vCloud.nodeService+xml", false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, NodeHandler.class);
assertExceptionParserClassEquals(method, null);
checkFilters(request);
}
public void testConfigureNodeNoDescription() throws SecurityException, NoSuchMethodException, IOException {
Method method = TerremarkECloudAsyncClient.class.getMethod("configureNode", int.class, String.class,
boolean.class, String.class);
HttpRequest request = processor.createRequest(method, 12, "name", true, null);
assertRequestLineEquals(request, "PUT https://vcloud/extensions/nodeService/12 HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.tmrk.vCloud.nodeService+xml\n");
assertPayloadEquals(
request,
"<NodeService xmlns=\"urn:tmrk:vCloudExpressExtensions-1.6\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"><Name>name</Name><Enabled>true</Enabled></NodeService>",
"application/vnd.tmrk.vCloud.nodeService+xml", false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, NodeHandler.class);

View File

@ -48,7 +48,7 @@ public class TerremarkVCloudClientLiveTest extends TerremarkClientLiveTest {
@Test
public void testKeysList() throws Exception {
TerremarkVCloudExpressClient vCloudExpressClient = TerremarkVCloudExpressClient.class.cast(tmClient);
TerremarkOrganization org = vCloudExpressClient.getOrganizationNamed(null);
TerremarkOrganization org = vCloudExpressClient.findOrganizationNamed(null);
Set<KeyPair> response = vCloudExpressClient.listKeyPairsInOrg(null);
assertNotNull(response);
System.err.println(response);
@ -59,7 +59,7 @@ public class TerremarkVCloudClientLiveTest extends TerremarkClientLiveTest {
protected void prepare() {
TerremarkVCloudExpressClient vCloudExpressClient = TerremarkVCloudExpressClient.class.cast(tmClient);
TerremarkOrganization org = vCloudExpressClient.getOrganizationNamed(null);
TerremarkOrganization org = vCloudExpressClient.findOrganizationNamed(null);
try {
key = vCloudExpressClient.generateKeyPairInOrg(org.getName(), "livetest", false);
} catch (IllegalStateException e) {

View File

@ -52,8 +52,11 @@ import org.jclouds.rest.internal.RestAnnotationProcessor;
import org.jclouds.util.Utils;
import org.jclouds.vcloud.VCloudClient;
import org.jclouds.vcloud.VCloudMediaType;
import org.jclouds.vcloud.domain.Catalog;
import org.jclouds.vcloud.domain.NamedResource;
import org.jclouds.vcloud.domain.Organization;
import org.jclouds.vcloud.domain.internal.CatalogImpl;
import org.jclouds.vcloud.domain.internal.CatalogItemImpl;
import org.jclouds.vcloud.domain.internal.NamedResourceImpl;
import org.jclouds.vcloud.domain.internal.OrganizationImpl;
import org.jclouds.vcloud.endpoints.Org;
@ -63,7 +66,6 @@ import org.jclouds.vcloud.internal.VCloudVersionsAsyncClient;
import org.jclouds.vcloud.internal.VCloudLoginAsyncClient.VCloudSession;
import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions;
import org.jclouds.vcloud.terremark.config.TerremarkVCloudExpressRestClientModule;
import org.jclouds.vcloud.terremark.domain.NodeConfiguration;
import org.jclouds.vcloud.terremark.domain.Protocol;
import org.jclouds.vcloud.terremark.options.AddInternetServiceOptions;
import org.jclouds.vcloud.terremark.options.AddNodeOptions;
@ -76,6 +78,7 @@ import org.jclouds.vcloud.terremark.xml.KeyPairHandler;
import org.jclouds.vcloud.terremark.xml.KeyPairsHandler;
import org.jclouds.vcloud.terremark.xml.NodeHandler;
import org.jclouds.vcloud.terremark.xml.NodesHandler;
import org.jclouds.vcloud.terremark.xml.TerremarkCatalogItemHandler;
import org.jclouds.vcloud.terremark.xml.TerremarkVDCHandler;
import org.jclouds.vcloud.xml.CatalogHandler;
import org.jclouds.vcloud.xml.VAppHandler;
@ -96,6 +99,39 @@ import com.google.inject.TypeLiteral;
*/
@Test(groups = "unit", sequential = true, testName = "TerremarkVCloudExpressAsyncClientTest")
public class TerremarkVCloudExpressAsyncClientTest extends RestClientTest<TerremarkVCloudExpressAsyncClient> {
public void testCatalogItemURI() throws SecurityException, NoSuchMethodException, IOException {
Method method = TerremarkVCloudExpressAsyncClient.class.getMethod("getCatalogItem", URI.class);
HttpRequest request = processor.createRequest(method, URI
.create("https://vcloud.safesecureweb.com/api/v0.8/catalogItem/2"));
assertRequestLineEquals(request, "GET https://vcloud.safesecureweb.com/api/v0.8/catalogItem/2 HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.catalogItem+xml\n");
assertPayloadEquals(request, null, null, false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, TerremarkCatalogItemHandler.class);
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
checkFilters(request);
}
public void testFindCatalogItemInOrgCatalogNamed() throws SecurityException, NoSuchMethodException, IOException {
Method method = TerremarkVCloudExpressAsyncClient.class.getMethod("findCatalogItemInOrgCatalogNamed",
String.class, String.class, String.class);
HttpRequest request = processor.createRequest(method, "org", "catalog", "item");
assertRequestLineEquals(request, "GET https://vcloud.safesecureweb.com/api/v0.8/catalogItem/1 HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.catalogItem+xml\n");
assertPayloadEquals(request, null, null, false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, TerremarkCatalogItemHandler.class);
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
checkFilters(request);
}
/**
* ignore parameter of catalog id since this doesn't work
*/
@ -130,8 +166,8 @@ public class TerremarkVCloudExpressAsyncClientTest extends RestClientTest<Terrem
}
public void testGetVDC() throws SecurityException, NoSuchMethodException, IOException {
Method method = TerremarkVCloudExpressAsyncClient.class.getMethod("getVDC", String.class);
HttpRequest request = processor.createRequest(method, "1");
Method method = TerremarkVCloudExpressAsyncClient.class.getMethod("getVDC", URI.class);
HttpRequest request = processor.createRequest(method, URI.create("https://vcloud/vdc/1"));
assertRequestLineEquals(request, "GET https://vcloud/vdc/1 HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.vdc+xml\n");
@ -144,11 +180,12 @@ public class TerremarkVCloudExpressAsyncClientTest extends RestClientTest<Terrem
checkFilters(request);
}
public void testInstantiateVAppTemplate() throws SecurityException, NoSuchMethodException, IOException {
Method method = TerremarkVCloudExpressAsyncClient.class.getMethod("instantiateVAppTemplateInOrg", String.class,
String.class, String.class, String.class, Array.newInstance(InstantiateVAppTemplateOptions.class, 0)
.getClass());
HttpRequest request = processor.createRequest(method, "org", "vdc", "name", 3 + "");
public void testInstantiateVAppTemplateInVDCURI() throws SecurityException, NoSuchMethodException, IOException {
Method method = TerremarkVCloudExpressAsyncClient.class.getMethod("instantiateVAppTemplateInVDC", URI.class,
URI.class, String.class, InstantiateVAppTemplateOptions[].class);
HttpRequest request = processor.createRequest(method, URI
.create("https://vcloud.safesecureweb.com/api/v0.8/vdc/1"), URI.create("https://vcloud/vAppTemplate/3"),
"name");
assertRequestLineEquals(request,
"POST https://vcloud.safesecureweb.com/api/v0.8/vdc/1/action/instantiateVAppTemplate HTTP/1.1");
@ -164,13 +201,14 @@ public class TerremarkVCloudExpressAsyncClientTest extends RestClientTest<Terrem
checkFilters(request);
}
public void testInstantiateVAppTemplateOptions() throws SecurityException, NoSuchMethodException, IOException {
Method method = TerremarkVCloudExpressAsyncClient.class.getMethod("instantiateVAppTemplateInOrg", String.class,
String.class, String.class, String.class, Array.newInstance(InstantiateVAppTemplateOptions.class, 0)
.getClass());
HttpRequest request = processor.createRequest(method, "org", "vdc", "name", 3 + "",
TerremarkInstantiateVAppTemplateOptions.Builder.processorCount(2).memory(512).inRow("row").inGroup("group")
.withPassword("password").inNetwork(URI.create("http://network")));
public void testInstantiateVAppTemplateInVDCURIOptions() throws SecurityException, NoSuchMethodException,
IOException {
Method method = TerremarkVCloudExpressAsyncClient.class.getMethod("instantiateVAppTemplateInVDC", URI.class,
URI.class, String.class, InstantiateVAppTemplateOptions[].class);
HttpRequest request = processor.createRequest(method, URI
.create("https://vcloud.safesecureweb.com/api/v0.8/vdc/1"), URI.create("https://vcloud/vAppTemplate/3"),
"name", TerremarkInstantiateVAppTemplateOptions.Builder.processorCount(2).memory(512).inRow("row").inGroup(
"group").withPassword("password").inNetwork(URI.create("http://network")));
assertRequestLineEquals(request,
"POST https://vcloud.safesecureweb.com/api/v0.8/vdc/1/action/instantiateVAppTemplate HTTP/1.1");
@ -351,16 +389,34 @@ public class TerremarkVCloudExpressAsyncClientTest extends RestClientTest<Terrem
checkFilters(request);
}
public void testConfigureNode() throws SecurityException, NoSuchMethodException, IOException {
Method method = TerremarkVCloudExpressAsyncClient.class.getMethod("configureNode", int.class,
NodeConfiguration.class);
HttpRequest request = processor.createRequest(method, 12, new NodeConfiguration().changeDescriptionTo("eggs"));
public void testConfigureNodeWithDescription() throws SecurityException, NoSuchMethodException, IOException {
Method method = TerremarkVCloudExpressAsyncClient.class.getMethod("configureNode", int.class, String.class,
boolean.class, String.class);
HttpRequest request = processor.createRequest(method, 12, "name", true, "eggs");
assertRequestLineEquals(request, "PUT https://vcloud/extensions/nodeService/12 HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.tmrk.vCloud.nodeService+xml\n");
assertPayloadEquals(
request,
"<NodeService xmlns=\"urn:tmrk:vCloudExpressExtensions-1.6\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"><Description>eggs</Description></NodeService>",
"<NodeService xmlns=\"urn:tmrk:vCloudExpressExtensions-1.6\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"><Name>name</Name><Enabled>true</Enabled><Description>eggs</Description></NodeService>",
"application/vnd.tmrk.vCloud.nodeService+xml", false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, NodeHandler.class);
assertExceptionParserClassEquals(method, null);
checkFilters(request);
}
public void testConfigureNodeNoDescription() throws SecurityException, NoSuchMethodException, IOException {
Method method = TerremarkVCloudExpressAsyncClient.class.getMethod("configureNode", int.class, String.class,
boolean.class, String.class);
HttpRequest request = processor.createRequest(method, 12, "name", true, null);
assertRequestLineEquals(request, "PUT https://vcloud/extensions/nodeService/12 HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.tmrk.vCloud.nodeService+xml\n");
assertPayloadEquals(
request,
"<NodeService xmlns=\"urn:tmrk:vCloudExpressExtensions-1.6\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"><Name>name</Name><Enabled>true</Enabled></NodeService>",
"application/vnd.tmrk.vCloud.nodeService+xml", false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, NodeHandler.class);
@ -558,6 +614,8 @@ public class TerremarkVCloudExpressAsyncClientTest extends RestClientTest<Terrem
super.configure();
bind(OrgNameToKeysListSupplier.class).to(TestOrgNameToKeysListSupplier.class);
bind(OrganizationMapSupplier.class).to(TestOrganizationMapSupplier.class);
bind(OrganizationCatalogSupplier.class).to(TestOrganizationCatalogItemMapSupplier.class);
bind(OrganizationCatalogItemSupplier.class).to(TestOrganizationCatalogItemSupplier.class);
}
@Override
@ -650,6 +708,49 @@ public class TerremarkVCloudExpressAsyncClientTest extends RestClientTest<Terrem
VCloudMediaType.TASKSLIST_XML, URI
.create("https://vcloud.safesecureweb.com/api/v0.8/tasksList/1")))));
}
}
@Singleton
public static class TestOrganizationCatalogItemMapSupplier extends OrganizationCatalogSupplier {
@Inject
protected TestOrganizationCatalogItemMapSupplier() {
super(null, null);
}
@Override
public Map<String, Map<String, ? extends org.jclouds.vcloud.domain.Catalog>> get() {
return ImmutableMap.<String, Map<String, ? extends org.jclouds.vcloud.domain.Catalog>> of("org",
ImmutableMap.<String, org.jclouds.vcloud.domain.Catalog> of("catalog", new CatalogImpl("1", "catalog", URI
.create("https://vcloud.safesecureweb.com/api/v0.8/catalog/1"), "description", ImmutableMap
.<String, NamedResource> of("item", new NamedResourceImpl("1", "item",
"application/vnd.vmware.vcloud.catalogItem+xml", URI
.create("https://vcloud.safesecureweb.com/api/v0.8/catalogItem/1")), "template",
new NamedResourceImpl("2", "template", "application/vnd.vmware.vcloud.vAppTemplate+xml", URI
.create("https://vcloud.safesecureweb.com/api/v0.8/catalogItem/2"))))));
}
}
@Singleton
public static class TestOrganizationCatalogItemSupplier extends OrganizationCatalogItemSupplier {
protected TestOrganizationCatalogItemSupplier() {
super(null, null);
}
@Override
public Map<String, Map<String, Map<String, ? extends org.jclouds.vcloud.domain.CatalogItem>>> get() {
return ImmutableMap.<String, Map<String, Map<String, ? extends org.jclouds.vcloud.domain.CatalogItem>>> of(
"org", ImmutableMap.<String, Map<String, ? extends org.jclouds.vcloud.domain.CatalogItem>> of(
"catalog", ImmutableMap.<String, org.jclouds.vcloud.domain.CatalogItem> of("template",
new CatalogItemImpl("2", "template", URI
.create("https://vcloud.safesecureweb.com/api/v0.8/catalogItem/2"), "description",
new NamedResourceImpl("2", "template",
"application/vnd.vmware.vcloud.vAppTemplate+xml", URI
.create("https://vcloud.safesecureweb.com/api/v0.8/vAppTemplate/2")),
ImmutableMap.<String, String> of()))));
}
}
@Override
@ -662,6 +763,11 @@ public class TerremarkVCloudExpressAsyncClientTest extends RestClientTest<Terrem
return URI.create("https://vdc/1");
}
@Override
protected String provideCatalogName(Supplier<Map<String, Map<String, ? extends Catalog>>> catalogs) {
return "catalog";
}
@Override
protected URI provideDefaultNetwork(VCloudClient client) {
return URI.create("https://vcloud.safesecureweb.com/network/1990");

View File

@ -27,13 +27,14 @@ import static org.easymock.classextension.EasyMock.verify;
import java.io.IOException;
import java.net.URI;
import java.util.Map;
import java.util.Properties;
import org.jclouds.http.HttpRequest;
import org.jclouds.vcloud.terremark.TerremarkVCloudExpressPropertiesBuilder;
import org.jclouds.vcloud.terremark.domain.NodeConfiguration;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableMap;
import com.google.inject.AbstractModule;
import com.google.inject.Guice;
import com.google.inject.Injector;
@ -51,51 +52,35 @@ public class BindNodeConfigurationToXmlPayloadTest {
@Override
protected void configure() {
Properties props = new Properties();
Names.bindProperties(binder(), checkNotNull(new TerremarkVCloudExpressPropertiesBuilder(
props).build(), "properties"));
Names.bindProperties(binder(), checkNotNull(new TerremarkVCloudExpressPropertiesBuilder(props).build(),
"properties"));
}
});
public void testChangeName() throws IOException {
NodeConfiguration config = new NodeConfiguration().changeNameTo("willie");
String expectedPayload = "<NodeService xmlns=\"urn:tmrk:vCloudExpressExtensions-1.6\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"><Name>willie</Name></NodeService>";
assertConfigMakesPayload(config, expectedPayload);
}
public void testChangeDescription() throws IOException {
NodeConfiguration config = new NodeConfiguration().changeDescriptionTo("description");
String expectedPayload = "<NodeService xmlns=\"urn:tmrk:vCloudExpressExtensions-1.6\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"><Description>description</Description></NodeService>";
assertConfigMakesPayload(config, expectedPayload);
}
public void testEnableTraffic() throws IOException {
NodeConfiguration config = new NodeConfiguration().enableTraffic();
String expectedPayload = "<NodeService xmlns=\"urn:tmrk:vCloudExpressExtensions-1.6\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"><Enabled>true</Enabled></NodeService>";
assertConfigMakesPayload(config, expectedPayload);
String expectedPayload = "<NodeService xmlns=\"urn:tmrk:vCloudExpressExtensions-1.6\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"><Name>willie</Name><Enabled>true</Enabled><Description>description</Description></NodeService>";
assertConfigMakesPayload(ImmutableMap.<String, String> of("name", "willie", "enabled", "true", "description",
"description"), expectedPayload);
}
public void testDisableTraffic() throws IOException {
NodeConfiguration config = new NodeConfiguration().disableTraffic();
String expectedPayload = "<NodeService xmlns=\"urn:tmrk:vCloudExpressExtensions-1.6\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"><Enabled>false</Enabled></NodeService>";
assertConfigMakesPayload(config, expectedPayload);
String expectedPayload = "<NodeService xmlns=\"urn:tmrk:vCloudExpressExtensions-1.6\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"><Name>willie</Name><Enabled>false</Enabled></NodeService>";
assertConfigMakesPayload(ImmutableMap.<String, String> of("name", "willie", "enabled", "false"), expectedPayload);
}
public void testTwoOptions() throws IOException {
NodeConfiguration config = new NodeConfiguration().disableTraffic().changeNameTo("willie");
String expectedPayload = "<NodeService xmlns=\"urn:tmrk:vCloudExpressExtensions-1.6\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"><Name>willie</Name><Enabled>false</Enabled></NodeService>";
assertConfigMakesPayload(config, expectedPayload);
String expectedPayload = "<NodeService xmlns=\"urn:tmrk:vCloudExpressExtensions-1.6\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"><Name>willie</Name><Enabled>true</Enabled></NodeService>";
assertConfigMakesPayload(ImmutableMap.<String, String> of("name", "willie", "enabled", "true"), expectedPayload);
}
@Test(expectedExceptions = IllegalArgumentException.class)
@Test(expectedExceptions = NullPointerException.class)
public void testNoOptions() throws IOException {
NodeConfiguration config = new NodeConfiguration();
String expectedPayload = "<NodeService xmlns=\"urn:tmrk:vCloudExpressExtensions-1.6\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"><Name>willie</Name><Enabled>false</Enabled></NodeService>";
assertConfigMakesPayload(config, expectedPayload);
assertConfigMakesPayload(ImmutableMap.<String, String> of(), expectedPayload);
}
private void assertConfigMakesPayload(NodeConfiguration config, String expectedPayload) {
BindNodeConfigurationToXmlPayload binder = injector
.getInstance(BindNodeConfigurationToXmlPayload.class);
private void assertConfigMakesPayload(Map<String, String> config, String expectedPayload) {
BindNodeConfigurationToXmlPayload binder = injector.getInstance(BindNodeConfigurationToXmlPayload.class);
HttpRequest request = createMock(HttpRequest.class);
expect(request.getEndpoint()).andReturn(URI.create("http://localhost/key")).anyTimes();
request.setPayload(expectedPayload);

View File

@ -27,6 +27,7 @@ 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.Provider;
@ -38,6 +39,7 @@ import org.jclouds.vcloud.domain.VAppStatus;
import org.jclouds.vcloud.domain.VAppTemplate;
import org.jclouds.vcloud.terremark.TerremarkVCloudExpressClient;
import org.jclouds.vcloud.terremark.compute.strategy.ParseVAppTemplateDescriptionToGetDefaultLoginCredentials;
import org.jclouds.vcloud.terremark.domain.TerremarkVDC;
import org.jclouds.vcloud.terremark.options.TerremarkInstantiateVAppTemplateOptions;
import org.testng.annotations.Test;
@ -55,19 +57,28 @@ public class TerremarkVCloudComputeClientTest {
InputStream is = getClass().getResourceAsStream("/terremark/windows_description.txt");
String description = new String(ByteStreams.toByteArray(is));
VAppTemplate template = createMock(VAppTemplate.class);
TerremarkVDC vdc = createMock(TerremarkVDC.class);
URI templateURI = URI.create("template");
URI vdcURI = URI.create("vdc");
expect(template.getDescription()).andReturn(description).atLeastOnce();
TerremarkVCloudExpressClient client = createMock(TerremarkVCloudExpressClient.class);
expect(client.getVAppTemplate("templateId")).andReturn(template);
VApp vApp = createMock(VApp.class);
expect(client.getVDC(vdcURI)).andReturn(vdc);
expect(client.getVAppTemplate(templateURI)).andReturn(template);
// TODO make this call only once
expect(client.getVAppTemplate(templateURI)).andReturn(template);
expect(vdc.getLocation()).andReturn(vdcURI);
expect(template.getLocation()).andReturn(templateURI);
expect(
client.instantiateVAppTemplateInOrg("org", "vDC", "name", "templateId",
client.instantiateVAppTemplateInVDC(vdcURI, templateURI, "name",
new TerremarkInstantiateVAppTemplateOptions().productProperty("password", "password"))).andReturn(
vApp);
Task task = createMock(Task.class);
expect(vApp.getId()).andReturn("1").atLeastOnce();
expect(client.getVAppTemplate("templateId")).andReturn(template);
expect(client.deployVApp("1")).andReturn(task);
expect(task.getId()).andReturn("1").atLeastOnce();
Predicate<String> successTester = createMock(Predicate.class);
@ -87,6 +98,7 @@ public class TerremarkVCloudComputeClientTest {
}, successTester, vAppStatusToNodeState);
replay(vdc);
replay(template);
replay(vApp);
replay(task);
@ -95,13 +107,14 @@ public class TerremarkVCloudComputeClientTest {
replay(notFoundTester);
replay(vAppStatusToNodeState);
Map<String, String> response = computeClient.start("org", "vDC", "name", "templateId",
Map<String, String> response = computeClient.start(vdcURI, templateURI, "name",
new TerremarkInstantiateVAppTemplateOptions());
assertEquals(response.get("id"), "1");
assertEquals(response.get("username"), "Administrator");
assertEquals(response.get("password"), "password");
verify(vdc);
verify(template);
verify(vApp);
verify(task);

View File

@ -34,7 +34,15 @@ import org.testng.annotations.Test;
*/
@Test(groups = { "unit" })
public class ParseTerremarkVCloudErrorFromHttpResponseTest extends BaseHttpErrorHandlerTest {
@Test
public void testGet400SetsIllegalArgumentException() {
assertCodeMakes(
"GET",
URI.create("https://services.vcloudexpress.terremark.com/api/v0.8a-ext1.6/vdc/32"),
400,
"HTTP/1.1 400 Service name is required.",
"", IllegalArgumentException.class);
}
@Test
public void testGet403SetsResourceNotFoundException() {
assertCodeMakes(

View File

@ -0,0 +1,95 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed 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.xml;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.testng.Assert.assertEquals;
import java.io.InputStream;
import java.net.URI;
import java.util.Properties;
import org.jclouds.http.functions.BaseHandlerTest;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.http.functions.config.SaxParserModule;
import org.jclouds.vcloud.domain.internal.NamedResourceImpl;
import org.jclouds.vcloud.terremark.TerremarkVCloudPropertiesBuilder;
import org.jclouds.vcloud.terremark.domain.TerremarkCatalogItem;
import org.jclouds.vcloud.terremark.domain.internal.TerremarkCatalogItemImpl;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableMap;
import com.google.inject.Guice;
import com.google.inject.name.Names;
/**
* Tests behavior of {@code TerremarkCatalogItemHandler}
*
* @author Adrian Cole
*/
@Test(groups = "unit", testName = "vcloud.TerremarkCatalogItemHandlerTest")
public class TerremarkCatalogItemHandlerTest extends BaseHandlerTest {
@Override
@BeforeTest
protected void setUpInjector() {
injector = Guice.createInjector(new SaxParserModule() {
@Override
public void configure() {
super.configure();
Properties props = new Properties();
Names.bindProperties(binder(), checkNotNull(new TerremarkVCloudPropertiesBuilder(props).build(),
"properties"));
}
});
factory = injector.getInstance(ParseSax.Factory.class);
assert factory != null;
}
public void testApplyInputStream() {
InputStream is = getClass().getResourceAsStream("/terremark/catalogItem.xml");
TerremarkCatalogItem result = (TerremarkCatalogItem) factory.create(
injector.getInstance(TerremarkCatalogItemHandler.class)).parse(is);
assertEquals(
result,
new TerremarkCatalogItemImpl(
"37-159",
"CentOS 5.3 (32-bit)",
URI.create("https://services.vCloudexpress.terremark.com/api/v0.8a-13ext1.6/catalogItem/37-159"),
null,
new NamedResourceImpl(
"compute",
"Compute Options",
"application/vnd.tmrk.vcloudExpress.vappComputeOptionParameters+xml",
URI
.create("https://services.vCloudexpress.terremark.com/api/v0.8a-ext1.6/extensions/template/37-159/options/compute")),
new NamedResourceImpl(
"customization",
"Customization Options",
"application/vnd.tmrk.vcloudExpress.vappCustomizationParameters+xml",
URI
.create("https://services.vCloudexpress.terremark.com/api/v0.8a-ext1.6/extensions/template/37-159/options/customization")),
new NamedResourceImpl("37", "CentOS 5.3 (32-bit)", "application/vnd.vmware.vCloud.vAppTemplate+xml",
URI.create("https://services.vCloudexpress.terremark.com/api/v0.8a-ext1.6/vappTemplate/37")),
ImmutableMap.<String, String> of("LicensingCost", "0")));
}
}

View File

@ -0,0 +1,17 @@
<CatalogItem
href="https://services.vCloudexpress.terremark.com/api/v0.8a-13ext1.6/catalogItem/37-159"
type="application/vnd.vmware.vCloud.catalogItem+xml" name="CentOS 5.3 (32-bit)"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Link rel="down"
href="https://services.vCloudexpress.terremark.com/api/v0.8a-ext1.6/extensions/template/37-159/options/compute"
type="application/vnd.tmrk.vcloudExpress.vappComputeOptionParameters+xml"
name="Compute Options" />
<Link rel="down"
href="https://services.vCloudexpress.terremark.com/api/v0.8a-ext1.6/extensions/template/37-159/options/customization"
type="application/vnd.tmrk.vcloudExpress.vappCustomizationParameters+xml"
name="Customization Options" />
<Entity
href="https://services.vCloudexpress.terremark.com/api/v0.8a-ext1.6/vappTemplate/37"
type="application/vnd.vmware.vCloud.vAppTemplate+xml" name="CentOS 5.3 (32-bit)" />
<Property key="LicensingCost">0</Property>
</CatalogItem>