Issue 280: refactoring to support vcloud 0.9

This commit is contained in:
Adrian Cole 2010-06-22 15:21:49 -07:00
parent 0fca2cba0c
commit 250f6140ee
30 changed files with 845 additions and 730 deletions

View File

@ -19,14 +19,14 @@
package org.jclouds.vcloud;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULT_DHCP_ENABLED;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULT_FENCEMODE;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_ENDPOINT;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_KEY;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_SESSIONINTERVAL;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_TIMEOUT_TASK_COMPLETED;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_USER;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_VERSION;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_VERSION_API;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_VERSION_SCHEMA;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_XML_NAMESPACE;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_XML_SCHEMA;
@ -45,13 +45,11 @@ public class VCloudPropertiesBuilder extends PropertiesBuilder {
@Override
protected Properties defaultProperties() {
Properties properties = super.defaultProperties();
properties.setProperty(PROPERTY_VCLOUD_VERSION, "0.8");
properties.setProperty(PROPERTY_VCLOUD_VERSION_API, "0.8");
properties.setProperty(PROPERTY_VCLOUD_VERSION_SCHEMA, "0.8");
properties.setProperty(PROPERTY_VCLOUD_SESSIONINTERVAL, 8 * 60 + "");
properties.setProperty(PROPERTY_VCLOUD_XML_SCHEMA,
"http://vcloud.safesecureweb.com/ns/vcloud.xsd");
properties.setProperty(PROPERTY_VCLOUD_DEFAULT_DHCP_ENABLED, "false");
properties.setProperty(PROPERTY_VCLOUD_DEFAULT_FENCEMODE,
FenceMode.ALLOW_IN_OUT.toString());
properties.setProperty("jclouds.dns_name_length_min", "1");
properties.setProperty("jclouds.dns_name_length_max", "80");
properties.setProperty(PROPERTY_VCLOUD_TIMEOUT_TASK_COMPLETED,
@ -62,18 +60,32 @@ public class VCloudPropertiesBuilder extends PropertiesBuilder {
public VCloudPropertiesBuilder(Properties properties) {
super(properties);
setNs();
setFenceMode();
}
private void setNs() {
protected void setNs() {
if (properties.getProperty(PROPERTY_VCLOUD_XML_NAMESPACE) == null)
properties.setProperty(PROPERTY_VCLOUD_XML_NAMESPACE,
"http://www.vmware.com/vcloud/v"
+ properties.getProperty(PROPERTY_VCLOUD_VERSION));
+ properties.getProperty(PROPERTY_VCLOUD_VERSION_SCHEMA));
}
protected void setFenceMode() {
if (properties.getProperty(PROPERTY_VCLOUD_DEFAULT_FENCEMODE) == null) {
if (properties.getProperty(PROPERTY_VCLOUD_VERSION_SCHEMA).startsWith(
"0.8"))
properties.setProperty(PROPERTY_VCLOUD_DEFAULT_FENCEMODE,
"allowInOut");
else
properties.setProperty(PROPERTY_VCLOUD_DEFAULT_FENCEMODE,
FenceMode.BRIDGED);
}
}
public VCloudPropertiesBuilder(URI endpoint, String id, String secret) {
super();
setNs();
setFenceMode();
withCredentials(id, secret);
withEndpoint(endpoint);
}

View File

@ -21,11 +21,7 @@ package org.jclouds.vcloud.binders;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULT_CPUCOUNT;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULT_DHCP_ENABLED;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULT_DISK;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULT_FENCEMODE;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULT_MEMORY;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULT_NETWORK;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_XML_NAMESPACE;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_XML_SCHEMA;
@ -36,6 +32,7 @@ import java.util.Properties;
import java.util.SortedMap;
import java.util.Map.Entry;
import javax.annotation.Nullable;
import javax.inject.Named;
import javax.inject.Singleton;
import javax.xml.parsers.FactoryConfigurationError;
@ -46,7 +43,6 @@ import org.jclouds.http.HttpRequest;
import org.jclouds.rest.MapBinder;
import org.jclouds.rest.binders.BindToStringPayload;
import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.jclouds.vcloud.domain.FenceMode;
import org.jclouds.vcloud.domain.ResourceType;
import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions;
@ -66,84 +62,57 @@ public class BindInstantiateVAppTemplateParamsToXmlPayload implements MapBinder
protected final String ns;
protected final String schema;
private final BindToStringPayload stringBinder;
protected final Map<ResourceType, String> defaultVirtualHardwareQuantity;
protected final Map<ResourceType, String> virtualHardwareToInstanceId = ImmutableMap.of(
ResourceType.PROCESSOR, "1", ResourceType.MEMORY, "2", ResourceType.DISK_DRIVE, "9");
protected final Map<ResourceType, String> virtualHardwareToInstanceId = ImmutableMap
.of(ResourceType.PROCESSOR, "1", ResourceType.MEMORY, "2",
ResourceType.DISK_DRIVE, "9");
private final URI defaultNetwork;
private final FenceMode defaultFenceMode;
private final boolean defaultDhcpEnabled;
/**
* To allow for optional injection, since guice doesn't allow unresolved constants in
* constructors
*/
protected static class OptionalConstantsHolder {
@Inject(optional = true)
@Named(PROPERTY_VCLOUD_DEFAULT_CPUCOUNT)
String cpuCount;
@Inject(optional = true)
@Named(PROPERTY_VCLOUD_DEFAULT_MEMORY)
String memorySizeMegabytes;
@Inject(optional = true)
@Named(PROPERTY_VCLOUD_DEFAULT_DISK)
String diskSizeKilobytes;
}
private final String defaultFenceMode;
@Inject
public BindInstantiateVAppTemplateParamsToXmlPayload(BindToStringPayload stringBinder,
@Named(PROPERTY_VCLOUD_XML_NAMESPACE) String ns,
@Named(PROPERTY_VCLOUD_XML_SCHEMA) String schema,
@Named(PROPERTY_VCLOUD_DEFAULT_DHCP_ENABLED) String defaultDhcpEnabled,
@Named(PROPERTY_VCLOUD_DEFAULT_FENCEMODE) String defaultFenceMode,
@Named(PROPERTY_VCLOUD_DEFAULT_NETWORK) String network,
OptionalConstantsHolder defaultsHolder) {
public BindInstantiateVAppTemplateParamsToXmlPayload(
BindToStringPayload stringBinder,
@Named(PROPERTY_VCLOUD_XML_NAMESPACE) String ns,
@Named(PROPERTY_VCLOUD_XML_SCHEMA) String schema,
@Named(PROPERTY_VCLOUD_DEFAULT_NETWORK) String network,
@Named(PROPERTY_VCLOUD_DEFAULT_FENCEMODE) String fenceMode
) {
this.ns = ns;
this.schema = schema;
this.stringBinder = stringBinder;
this.defaultVirtualHardwareQuantity = Maps.newHashMap();
this.defaultNetwork = URI.create(network);
this.defaultFenceMode = FenceMode.fromValue(defaultFenceMode);
this.defaultDhcpEnabled = Boolean.parseBoolean(defaultDhcpEnabled);
if (defaultsHolder.cpuCount != null)
this.defaultVirtualHardwareQuantity.put(ResourceType.PROCESSOR, defaultsHolder.cpuCount);
if (defaultsHolder.memorySizeMegabytes != null)
this.defaultVirtualHardwareQuantity.put(ResourceType.MEMORY,
defaultsHolder.memorySizeMegabytes);
if (defaultsHolder.diskSizeKilobytes != null)
this.defaultVirtualHardwareQuantity.put(ResourceType.DISK_DRIVE,
defaultsHolder.diskSizeKilobytes);
this.defaultFenceMode = fenceMode;
}
@SuppressWarnings("unchecked")
public void bindToRequest(HttpRequest request, Map<String, String> postParams) {
checkArgument(checkNotNull(request, "request") instanceof GeneratedHttpRequest,
"this binder is only valid for GeneratedHttpRequests!");
checkArgument(
checkNotNull(request, "request") instanceof GeneratedHttpRequest,
"this binder is only valid for GeneratedHttpRequests!");
GeneratedHttpRequest gRequest = (GeneratedHttpRequest) request;
checkState(gRequest.getArgs() != null, "args should be initialized at this point");
checkState(gRequest.getArgs() != null,
"args should be initialized at this point");
String name = checkNotNull(postParams.remove("name"), "name");
String template = checkNotNull(postParams.remove("template"), "template");
String network = postParams.remove("network");
String fenceMode = postParams.remove("fenceMode");
String dhcpEnabled = postParams.remove("dhcpEnabled");
String networkName = postParams.remove("networkName");
SortedMap<ResourceType, String> virtualHardwareQuantity = extractVirtualQuantityFromPostParams(postParams);
SortedMap<ResourceType, String> virtualHardwareQuantity = Maps
.newTreeMap();
InstantiateVAppTemplateOptions options = findOptionsInArgsOrNull(gRequest);
Map<String, String> properties = Maps.newTreeMap();
String network = defaultNetwork.toASCIIString();
String fenceMode = defaultFenceMode;
String networkName = name;
if (options != null) {
String networkFromOptions = addQuantityOrReturnNetwork(options, virtualHardwareQuantity,
network);
network = networkFromOptions != null ? networkFromOptions : network;
network = ifNullDefaultTo(options.getNetwork(), network);
fenceMode = ifNullDefaultTo(options.getFenceMode(), defaultFenceMode);
networkName = ifNullDefaultTo(options.getNetworkName(), networkName);
addQuantity(options, virtualHardwareQuantity);
properties.putAll(options.getProperties());
}
try {
stringBinder.bindToRequest(request, generateXml(name, template, properties,
virtualHardwareQuantity, networkName == null ? name : networkName,
fenceMode == null ? defaultFenceMode : FenceMode.fromValue(fenceMode),
dhcpEnabled == null ? defaultDhcpEnabled : Boolean.parseBoolean(dhcpEnabled),
network == null ? defaultNetwork : URI.create(network)));
stringBinder.bindToRequest(request, generateXml(name, template,
properties, virtualHardwareQuantity, networkName, fenceMode, URI
.create(network)));
} catch (ParserConfigurationException e) {
throw new RuntimeException(e);
} catch (FactoryConfigurationError e) {
@ -154,92 +123,99 @@ public class BindInstantiateVAppTemplateParamsToXmlPayload implements MapBinder
}
protected SortedMap<ResourceType, String> extractVirtualQuantityFromPostParams(
Map<String, String> postParams) {
SortedMap<ResourceType, String> virtualHardwareQuantity = Maps.newTreeMap();
virtualHardwareQuantity.putAll(defaultVirtualHardwareQuantity);
for (Entry<String, String> entry : postParams.entrySet()) {
virtualHardwareQuantity.put(ResourceType.fromValue(entry.getKey()), entry.getValue());
}
return virtualHardwareQuantity;
}
protected String generateXml(String name, String template, Map<String, String> properties,
SortedMap<ResourceType, String> virtualHardwareQuantity, String networkName,
FenceMode fenceMode, boolean dhcp, URI network) throws ParserConfigurationException,
FactoryConfigurationError, TransformerException {
protected String generateXml(String name, String template,
Map<String, String> properties,
SortedMap<ResourceType, String> virtualHardwareQuantity,
String networkName, @Nullable String fenceMode, URI network)
throws ParserConfigurationException, FactoryConfigurationError,
TransformerException {
XMLBuilder rootBuilder = buildRoot(name);
rootBuilder.e("VAppTemplate").a("href", template);
XMLBuilder instantiationParamsBuilder = rootBuilder.e("InstantiationParams");
XMLBuilder instantiationParamsBuilder = rootBuilder
.e("InstantiationParams");
addPropertiesifPresent(instantiationParamsBuilder, properties);
addVirtualQuantityIfPresent(instantiationParamsBuilder, virtualHardwareQuantity);
addNetworkConfig(instantiationParamsBuilder, networkName, fenceMode, dhcp, network);
addVirtualQuantityIfPresent(instantiationParamsBuilder,
virtualHardwareQuantity);
addNetworkConfig(instantiationParamsBuilder, networkName, fenceMode,
network);
Properties outputProperties = new Properties();
outputProperties.put(javax.xml.transform.OutputKeys.OMIT_XML_DECLARATION, "yes");
outputProperties.put(javax.xml.transform.OutputKeys.OMIT_XML_DECLARATION,
"yes");
return rootBuilder.asString(outputProperties);
}
protected void addPropertiesifPresent(XMLBuilder instantiationParamsBuilder,
Map<String, String> properties) {
Map<String, String> properties) {
if (properties.size() > 0) {
XMLBuilder productSectionBuilder = instantiationParamsBuilder.e("ProductSection").a(
"xmlns:q1", ns).a("xmlns:ovf", "http://schemas.dmtf.org/ovf/envelope/1");
XMLBuilder productSectionBuilder = instantiationParamsBuilder.e(
"ProductSection").a("xmlns:q1", ns).a("xmlns:ovf",
"http://schemas.dmtf.org/ovf/envelope/1");
for (Entry<String, String> entry : properties.entrySet()) {
productSectionBuilder.e("Property")
.a("xmlns", "http://schemas.dmtf.org/ovf/envelope/1").a("ovf:key",
entry.getKey()).a("ovf:value", entry.getValue());
productSectionBuilder.e("Property").a("xmlns",
"http://schemas.dmtf.org/ovf/envelope/1").a("ovf:key",
entry.getKey()).a("ovf:value", entry.getValue());
}
}
}
protected void addNetworkConfig(XMLBuilder instantiationParamsBuilder, String name,
FenceMode fenceMode, boolean dhcp, URI network) {
XMLBuilder networkConfigBuilder = instantiationParamsBuilder.e("NetworkConfigSection").e(
"NetworkConfig").a("name", name);
XMLBuilder featuresBuilder = networkConfigBuilder.e("Features");
featuresBuilder.e("FenceMode").t(fenceMode.value());
featuresBuilder.e("Dhcp").t(dhcp + "");
networkConfigBuilder.e("NetworkAssociation").a("href", network.toASCIIString());
protected void addNetworkConfig(XMLBuilder instantiationParamsBuilder,
String name, @Nullable String fenceMode, URI network) {
XMLBuilder networkConfigBuilder = instantiationParamsBuilder.e(
"NetworkConfigSection").e("NetworkConfig").a("name", name);
if (fenceMode != null) {
XMLBuilder featuresBuilder = networkConfigBuilder.e("Features");
featuresBuilder.e("FenceMode").t(fenceMode);
}
networkConfigBuilder.e("NetworkAssociation").a("href",
network.toASCIIString());
}
protected void addVirtualQuantityIfPresent(XMLBuilder instantiationParamsBuilder,
SortedMap<ResourceType, String> virtualHardwareQuantity) {
protected void addVirtualQuantityIfPresent(
XMLBuilder instantiationParamsBuilder,
SortedMap<ResourceType, String> virtualHardwareQuantity) {
if (virtualHardwareQuantity.size() > 0) {
XMLBuilder virtualHardwareSectionBuilder = instantiationParamsBuilder.e(
"VirtualHardwareSection").a("xmlns:q1", ns);
for (Entry<ResourceType, String> entry : virtualHardwareQuantity.entrySet()) {
XMLBuilder itemBuilder = virtualHardwareSectionBuilder.e("Item").a("xmlns",
"http://schemas.dmtf.org/ovf/envelope/1");
XMLBuilder virtualHardwareSectionBuilder = instantiationParamsBuilder
.e("VirtualHardwareSection").a("xmlns:q1", ns);
for (Entry<ResourceType, String> entry : virtualHardwareQuantity
.entrySet()) {
XMLBuilder itemBuilder = virtualHardwareSectionBuilder.e("Item").a(
"xmlns", "http://schemas.dmtf.org/ovf/envelope/1");
itemBuilder
.e("InstanceID")
.a("xmlns",
"http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData")
.t(virtualHardwareToInstanceId.get(entry.getKey()));
.e("InstanceID")
.a(
"xmlns",
"http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData")
.t(virtualHardwareToInstanceId.get(entry.getKey()));
itemBuilder
.e("ResourceType")
.a("xmlns",
"http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData")
.t(entry.getKey().value());
.e("ResourceType")
.a(
"xmlns",
"http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData")
.t(entry.getKey().value());
itemBuilder
.e("VirtualQuantity")
.a("xmlns",
"http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData")
.t(entry.getValue());
.e("VirtualQuantity")
.a(
"xmlns",
"http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData")
.t(entry.getValue());
}
}
}
protected XMLBuilder buildRoot(String name) throws ParserConfigurationException,
FactoryConfigurationError {
XMLBuilder rootBuilder = XMLBuilder.create("InstantiateVAppTemplateParams").a("name", name)
.a("xmlns", ns).a("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance").a(
"xsi:schemaLocation", ns + " " + schema);
protected XMLBuilder buildRoot(String name)
throws ParserConfigurationException, FactoryConfigurationError {
XMLBuilder rootBuilder = XMLBuilder.create(
"InstantiateVAppTemplateParams").a("name", name).a("xmlns", ns).a(
"xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance").a(
"xsi:schemaLocation", ns + " " + schema).a("xmlns:ovf",
"http://schemas.dmtf.org/ovf/envelope/1");
return rootBuilder;
}
protected InstantiateVAppTemplateOptions findOptionsInArgsOrNull(GeneratedHttpRequest<?> gRequest) {
protected InstantiateVAppTemplateOptions findOptionsInArgsOrNull(
GeneratedHttpRequest<?> gRequest) {
for (Object arg : gRequest.getArgs()) {
if (arg instanceof InstantiateVAppTemplateOptions) {
return (InstantiateVAppTemplateOptions) arg;
@ -251,25 +227,25 @@ public class BindInstantiateVAppTemplateParamsToXmlPayload implements MapBinder
return null;
}
private String addQuantityOrReturnNetwork(InstantiateVAppTemplateOptions options,
Map<ResourceType, String> virtualHardwareQuantity, String network) {
private void addQuantity(InstantiateVAppTemplateOptions options,
Map<ResourceType, String> virtualHardwareQuantity) {
if (options.getCpuCount() != null) {
virtualHardwareQuantity.put(ResourceType.PROCESSOR, options.getCpuCount());
virtualHardwareQuantity.put(ResourceType.PROCESSOR, options
.getCpuCount());
}
if (options.getMemorySizeMegabytes() != null) {
virtualHardwareQuantity.put(ResourceType.MEMORY, options.getMemorySizeMegabytes());
virtualHardwareQuantity.put(ResourceType.MEMORY, options
.getMemorySizeMegabytes());
}
if (options.getDiskSizeKilobytes() != null) {
virtualHardwareQuantity.put(ResourceType.DISK_DRIVE, options.getDiskSizeKilobytes());
virtualHardwareQuantity.put(ResourceType.DISK_DRIVE, options
.getDiskSizeKilobytes());
}
if (options.getNetwork() != null) {
return options.getNetwork();
}
return network;
}
public void bindToRequest(HttpRequest request, Object input) {
throw new IllegalStateException("InstantiateVAppTemplateParams is needs parameters");
throw new IllegalStateException(
"InstantiateVAppTemplateParams is needs parameters");
}
protected String ifNullDefaultTo(String value, String defaultValue) {

View File

@ -70,7 +70,6 @@ public class BaseVCloudComputeClient implements VCloudComputeClient {
String templateId, InstantiateVAppTemplateOptions options,
int... portsToOpen) {
checkNotNull(options, "options");
logger.debug(
">> instantiating vApp vDC(%s) name(%s) template(%s) options(%s) ",
vDCId, name, templateId, options);

View File

@ -75,7 +75,7 @@ import com.google.inject.util.Providers;
*/
public class VCloudComputeServiceContextModule extends VCloudContextModule {
private final String providerName;
protected final String providerName;
public VCloudComputeServiceContextModule(String providerName) {
this.providerName = providerName;

View File

@ -39,11 +39,13 @@ public class StaticSizeProvider implements Provider<Set<? extends Size>> {
@Override
public Set<? extends Size> get() {
Set<Size> sizes = Sets.newHashSet();
for (int cpus : new int[] { 1, 2, 4 })
for (int cpus : new int[] { 1, 2, 4, 8 })
for (int ram : new int[] { 512, 1024, 2048, 4096, 8192, 16384 }) {
String id = String.format("cpu=%d,ram=%s,disk=%d", cpus, ram, 10);
sizes.add(new SizeImpl(id, null, id, null, null, ImmutableMap.<String, String> of(),
cpus, ram, 10, ImagePredicates.any()));
sizes
.add(new SizeImpl(id, null, id, null, null, ImmutableMap
.<String, String> of(), cpus, ram, 10, ImagePredicates
.any()));
}
return sizes;
}

View File

@ -50,8 +50,8 @@ 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
*/
@ -70,50 +70,59 @@ public class VCloudGetNodeMetadata {
// 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]+");
.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]+");
public static final Pattern TAG_PATTERN_WITHOUT_TEMPLATE = Pattern
.compile("([^-]+)-[0-9]+");
@Inject
protected VCloudGetNodeMetadata(VCloudClient client, VCloudComputeClient computeClient,
Map<VAppStatus, NodeState> vAppStatusToNodeState, GetExtra getExtra,
FindLocationForResourceInVDC findLocationForResourceInVDC,
Provider<Set<? extends Image>> images) {
VCloudGetNodeMetadata(VCloudClient client,
VCloudComputeClient computeClient,
Map<VAppStatus, NodeState> vAppStatusToNodeState, GetExtra getExtra,
FindLocationForResourceInVDC findLocationForResourceInVDC,
Provider<Set<? extends Image>> images) {
this.client = checkNotNull(client, "client");
this.images = checkNotNull(images, "images");
this.getExtra = checkNotNull(getExtra, "getExtra");
this.findLocationForResourceInVDC = checkNotNull(findLocationForResourceInVDC,
"findLocationForResourceInVDC");
this.findLocationForResourceInVDC = checkNotNull(
findLocationForResourceInVDC, "findLocationForResourceInVDC");
this.computeClient = checkNotNull(computeClient, "computeClient");
this.vAppStatusToNodeState = checkNotNull(vAppStatusToNodeState, "vAppStatusToNodeState");
this.vAppStatusToNodeState = checkNotNull(vAppStatusToNodeState,
"vAppStatusToNodeState");
}
protected NodeMetadata getNodeMetadataByIdInVDC(String id) {
public NodeMetadata execute(String id) {
VApp vApp = client.getVApp(id);
String tag = null;
Image image = null;
Matcher matcher = TAG_PATTERN_WITH_TEMPLATE.matcher(vApp.getName());
Matcher matcher = vApp.getName() != null ? TAG_PATTERN_WITH_TEMPLATE
.matcher(vApp.getName()) : null;
final Location location = findLocationForResourceInVDC.apply(vApp, vApp.getVDC().getId());
if (matcher.find()) {
final Location location = findLocationForResourceInVDC.apply(vApp, vApp
.getVDC().getId());
if (matcher != null && matcher.find()) {
tag = matcher.group(1);
String templateIdInHexWithoutLeadingZeros = matcher.group(2).replaceAll("^[0]+", "");
final String templateId = Integer.parseInt(templateIdInHexWithoutLeadingZeros, 16) + "";
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);
}
});
} catch (NoSuchElementException e) {
logger.warn(
"could not find a matching image for vapp %s; vapptemplate %s in location %s",
vApp, templateId, location);
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());
@ -123,9 +132,10 @@ public class VCloudGetNodeMetadata {
tag = "NOTAG-" + vApp.getName();
}
}
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);
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);
}
}

View File

@ -50,10 +50,11 @@ public class EncodeTemplateIdIntoNameRunNodesAndAddToSetStrategy extends
ListNodesStrategy listNodesStrategy,
@Named("NAMING_CONVENTION") String nodeNamingConvention,
ComputeUtils utils,
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor) {
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor,
SecureRandom random) {
super(addNodeWithTagStrategy, listNodesStrategy, nodeNamingConvention,
utils, executor);
this.random = new SecureRandom();
this.random = random;
}
/**

View File

@ -20,43 +20,30 @@ package org.jclouds.vcloud.compute.strategy;
import static com.google.common.base.Preconditions.checkNotNull;
import java.util.Map;
import java.util.Set;
import javax.inject.Inject;
import javax.inject.Provider;
import javax.inject.Singleton;
import org.jclouds.compute.domain.Image;
import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.domain.NodeState;
import org.jclouds.compute.strategy.GetNodeMetadataStrategy;
import org.jclouds.vcloud.VCloudClient;
import org.jclouds.vcloud.compute.VCloudComputeClient;
import org.jclouds.vcloud.compute.functions.FindLocationForResourceInVDC;
import org.jclouds.vcloud.compute.functions.GetExtra;
import org.jclouds.vcloud.compute.functions.VCloudGetNodeMetadata;
import org.jclouds.vcloud.domain.VAppStatus;
/**
* @author Adrian Cole
*/
@Singleton
public class VCloudGetNodeMetadataStrategy extends VCloudGetNodeMetadata implements
public class VCloudGetNodeMetadataStrategy implements
GetNodeMetadataStrategy {
protected final VCloudGetNodeMetadata getNodeMetadata;
@Inject
protected VCloudGetNodeMetadataStrategy(VCloudClient client, VCloudComputeClient computeClient,
Map<VAppStatus, NodeState> vAppStatusToNodeState, GetExtra getExtra,
FindLocationForResourceInVDC findLocationForResourceInVDC,
Provider<Set<? extends Image>> images) {
super(client, computeClient, vAppStatusToNodeState, getExtra, findLocationForResourceInVDC,
images);
protected VCloudGetNodeMetadataStrategy(VCloudGetNodeMetadata getNodeMetadata) {
this.getNodeMetadata=getNodeMetadata;
}
@Override
public NodeMetadata execute(String id) {
return getNodeMetadataByIdInVDC(checkNotNull(id, "node.id"));
return getNodeMetadata.execute(checkNotNull(id, "node.id"));
}
}

View File

@ -18,20 +18,16 @@
*/
package org.jclouds.vcloud.compute.strategy;
import java.util.Map;
import java.util.Set;
import javax.annotation.Resource;
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Provider;
import javax.inject.Singleton;
import org.jclouds.compute.domain.ComputeMetadata;
import org.jclouds.compute.domain.ComputeType;
import org.jclouds.compute.domain.Image;
import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.domain.NodeState;
import org.jclouds.compute.domain.internal.ComputeMetadataImpl;
import org.jclouds.compute.reference.ComputeServiceConstants;
import org.jclouds.compute.strategy.ListNodesStrategy;
@ -39,12 +35,9 @@ import org.jclouds.domain.Location;
import org.jclouds.logging.Logger;
import org.jclouds.vcloud.VCloudClient;
import org.jclouds.vcloud.VCloudMediaType;
import org.jclouds.vcloud.compute.VCloudComputeClient;
import org.jclouds.vcloud.compute.functions.FindLocationForResourceInVDC;
import org.jclouds.vcloud.compute.functions.GetExtra;
import org.jclouds.vcloud.compute.functions.VCloudGetNodeMetadata;
import org.jclouds.vcloud.domain.NamedResource;
import org.jclouds.vcloud.domain.VAppStatus;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Predicate;
@ -55,25 +48,30 @@ import com.google.common.collect.Sets;
* @author Adrian Cole
*/
@Singleton
public class VCloudListNodesStrategy extends VCloudGetNodeMetadata implements ListNodesStrategy {
public class VCloudListNodesStrategy implements ListNodesStrategy {
@Resource
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
public Logger logger = Logger.NULL;
protected final VCloudGetNodeMetadata getNodeMetadata;
protected final VCloudClient client;
protected final FindLocationForResourceInVDC findLocationForResourceInVDC;
@Inject
protected VCloudListNodesStrategy(VCloudClient client, VCloudComputeClient computeClient,
Map<VAppStatus, NodeState> vAppStatusToNodeState, GetExtra getExtra,
FindLocationForResourceInVDC findLocationForResourceInVDC,
Provider<Set<? extends Image>> images) {
super(client, computeClient, vAppStatusToNodeState, getExtra, findLocationForResourceInVDC,
images);
protected VCloudListNodesStrategy(VCloudClient client,
VCloudGetNodeMetadata getNodeMetadata,
FindLocationForResourceInVDC findLocationForResourceInVDC) {
this.client = client;
this.getNodeMetadata = getNodeMetadata;
this.findLocationForResourceInVDC = findLocationForResourceInVDC;
}
@Override
public Iterable<ComputeMetadata> list() {
Set<ComputeMetadata> nodes = Sets.newHashSet();
for (NamedResource vdc : client.getDefaultOrganization().getVDCs().values()) {
for (NamedResource resource : client.getVDC(vdc.getId()).getResourceEntities().values()) {
for (NamedResource vdc : client.getDefaultOrganization().getVDCs()
.values()) {
for (NamedResource resource : client.getVDC(vdc.getId())
.getResourceEntities().values()) {
if (resource.getType().equals(VCloudMediaType.VAPP_XML)) {
nodes.add(convertVAppToComputeMetadata(vdc, resource));
}
@ -82,19 +80,25 @@ public class VCloudListNodesStrategy extends VCloudGetNodeMetadata implements Li
return nodes;
}
private ComputeMetadata convertVAppToComputeMetadata(NamedResource vdc, NamedResource resource) {
Location location = findLocationForResourceInVDC.apply(resource, vdc.getId());
return new ComputeMetadataImpl(ComputeType.NODE, resource.getId(), resource.getName(),
resource.getId(), location, null, ImmutableMap.<String, String> of());
private ComputeMetadata convertVAppToComputeMetadata(NamedResource vdc,
NamedResource resource) {
Location location = findLocationForResourceInVDC.apply(resource, vdc
.getId());
return new ComputeMetadataImpl(ComputeType.NODE, resource.getId(),
resource.getName(), resource.getId(), location, null, ImmutableMap
.<String, String> of());
}
@Override
public Iterable<NodeMetadata> listDetailsOnNodesMatching(Predicate<ComputeMetadata> filter) {
public Iterable<NodeMetadata> listDetailsOnNodesMatching(
Predicate<ComputeMetadata> filter) {
Set<NodeMetadata> nodes = Sets.newHashSet();
for (NamedResource vdc : client.getDefaultOrganization().getVDCs().values()) {
for (NamedResource resource : client.getVDC(vdc.getId()).getResourceEntities().values()) {
for (NamedResource vdc : client.getDefaultOrganization().getVDCs()
.values()) {
for (NamedResource resource : client.getVDC(vdc.getId())
.getResourceEntities().values()) {
if (resource.getType().equals(VCloudMediaType.VAPP_XML)
&& filter.apply(convertVAppToComputeMetadata(vdc, resource))) {
&& filter.apply(convertVAppToComputeMetadata(vdc, resource))) {
addVAppToSetRetryingIfNotYetPresent(nodes, vdc, resource);
}
}
@ -103,16 +107,17 @@ public class VCloudListNodesStrategy extends VCloudGetNodeMetadata implements Li
}
@VisibleForTesting
void addVAppToSetRetryingIfNotYetPresent(Set<NodeMetadata> nodes, NamedResource vdc,
NamedResource resource) {
void addVAppToSetRetryingIfNotYetPresent(Set<NodeMetadata> nodes,
NamedResource vdc, NamedResource resource) {
NodeMetadata node = null;
int i = 0;
while (node == null && i++ < 3) {
try {
node = getNodeMetadataByIdInVDC(resource.getId());
node = getNodeMetadata.execute(resource.getId());
nodes.add(node);
} catch (NullPointerException e) {
logger.warn("vApp %s not yet present in vdc %s", resource.getId(), vdc.getId());
logger.warn("vApp %s not yet present in vdc %s", resource.getId(),
vdc.getId());
}
}
}

View File

@ -26,7 +26,7 @@ import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_KEY;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_SESSIONINTERVAL;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_TIMEOUT_TASK_COMPLETED;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_USER;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_VERSION;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_VERSION_API;
import java.io.UnsupportedEncodingException;
import java.net.URI;
@ -82,6 +82,7 @@ import com.google.common.base.Supplier;
import com.google.common.base.Throwables;
import com.google.common.collect.Iterables;
import com.google.inject.Provides;
import com.google.inject.internal.Maps;
/**
* Configures the VCloud authentication service connection, including logging
@ -125,12 +126,34 @@ public abstract class BaseVCloudRestClientModule<S extends VCloudClient, A exten
@Provides
@Org
@Singleton
protected URI provideOrg(Supplier<VCloudSession> cache,
protected URI provideOrg(@Org Iterable<NamedResource> orgs) {
return Iterables.getLast(orgs).getLocation();
}
@Provides
@Named("VDC_TO_ORG")
@Singleton
protected Map<String, String> provideVDCtoORG(@Org Iterable<NamedResource> orgs,
VCloudClient client) {
Map<String, String> returnVal = Maps.newLinkedHashMap();
for (NamedResource orgr : orgs) {
for (NamedResource vdc : client.getOrganization(orgr.getId())
.getVDCs().values()) {
returnVal.put(vdc.getId(), orgr.getId());
}
}
return returnVal;
}
@Provides
@Org
@Singleton
protected Iterable<NamedResource> provideOrgs(Supplier<VCloudSession> cache,
@Named(PROPERTY_VCLOUD_USER) String user) {
VCloudSession discovery = cache.get();
checkState(discovery.getOrgs().size() > 0, "No orgs present for user: "
+ user);
return Iterables.getLast(discovery.getOrgs().values()).getLocation();
return discovery.getOrgs().values();
}
@Provides
@ -192,7 +215,7 @@ public abstract class BaseVCloudRestClientModule<S extends VCloudClient, A exten
@org.jclouds.vcloud.endpoints.VCloudLogin
protected URI provideAuthenticationURI(
VCloudVersionsAsyncClient versionService,
@Named(PROPERTY_VCLOUD_VERSION) String version)
@Named(PROPERTY_VCLOUD_VERSION_API) String version)
throws InterruptedException, ExecutionException, TimeoutException {
SortedMap<String, URI> versions = versionService.getSupportedVersions()
.get(180, TimeUnit.SECONDS);

View File

@ -18,32 +18,24 @@
*/
package org.jclouds.vcloud.domain;
import static com.google.common.base.Preconditions.checkNotNull;
import com.google.common.base.CaseFormat;
/**
*
* The FenceMode specifies network constraints.
* The FenceMode element contains one of the following strings that specify how
* a network is connected to its parent network.
*
* @author Adrian Cole
*/
public enum FenceMode {
BRIDGED, ISOLATED, BLOCK_IN_OUT, ALLOW_IN, ALLOW_IN_OUT, ALLOW_OUT;
public String value() {
return CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, name());
}
@Override
public String toString() {
return value();
}
public static FenceMode fromValue(String fenceMode) {
return valueOf(CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, checkNotNull(fenceMode,
"fenceMode")));
}
public interface FenceMode {
/**
* The two networks are bridged.
*/
public static final String BRIDGED = "bridged";
/**
* The two networks are not connected.
*/
public static final String ISOLATED = "isolated";
/**
* The two networks are connected as specified in their NatService elements.
*/
public static final String NAT_ROUTED = "natRouted";
}

View File

@ -57,7 +57,7 @@ public interface Network extends NamedResource {
/**
* return the networks fence modes.
*/
Set<FenceMode> getFenceModes();
Set<String> getFenceModes();
/**
* return True if the network provides DHCP services

View File

@ -22,7 +22,6 @@ import java.net.URI;
import java.util.Set;
import org.jclouds.vcloud.VCloudMediaType;
import org.jclouds.vcloud.domain.FenceMode;
import org.jclouds.vcloud.domain.FirewallRule;
import org.jclouds.vcloud.domain.NamedResource;
import org.jclouds.vcloud.domain.NatRule;
@ -45,15 +44,16 @@ public class NetworkImpl extends NamedResourceImpl implements Network {
private final Set<String> dnsServers = Sets.newHashSet();
private final String gateway;
private final String netmask;
private final Set<FenceMode> fenceModes = Sets.newHashSet();
private final Set<String> fenceModes = Sets.newHashSet();
@Nullable
private final Boolean dhcp;
private final Set<NatRule> natRules = Sets.newHashSet();
private final Set<FirewallRule> firewallRules = Sets.newHashSet();
public NetworkImpl(String id, String name, URI location, String description,
Set<String> dnsServers, String gateway, String netmask, Set<FenceMode> fenceModes,
Boolean dhcp, Set<NatRule> natRules, Set<FirewallRule> firewallRules) {
Set<String> dnsServers, String gateway, String netmask,
Set<String> fenceModes, Boolean dhcp, Set<NatRule> natRules,
Set<FirewallRule> firewallRules) {
super(id, name, VCloudMediaType.NETWORK_XML, location);
this.description = description;
this.dnsServers.addAll(dnsServers);
@ -96,7 +96,7 @@ public class NetworkImpl extends NamedResourceImpl implements Network {
/**
* {@inheritDoc}
*/
public Set<FenceMode> getFenceModes() {
public Set<String> getFenceModes() {
return fenceModes;
}
@ -130,11 +130,15 @@ public class NetworkImpl extends NamedResourceImpl implements Network {
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result + ((description == null) ? 0 : description.hashCode());
result = prime * result
+ ((description == null) ? 0 : description.hashCode());
result = prime * result + ((dhcp == null) ? 0 : dhcp.hashCode());
result = prime * result + ((dnsServers == null) ? 0 : dnsServers.hashCode());
result = prime * result + ((fenceModes == null) ? 0 : fenceModes.hashCode());
result = prime * result + ((firewallRules == null) ? 0 : firewallRules.hashCode());
result = prime * result
+ ((dnsServers == null) ? 0 : dnsServers.hashCode());
result = prime * result
+ ((fenceModes == null) ? 0 : fenceModes.hashCode());
result = prime * result
+ ((firewallRules == null) ? 0 : firewallRules.hashCode());
result = prime * result + ((gateway == null) ? 0 : gateway.hashCode());
result = prime * result + ((natRules == null) ? 0 : natRules.hashCode());
result = prime * result + ((netmask == null) ? 0 : netmask.hashCode());
@ -195,11 +199,12 @@ public class NetworkImpl extends NamedResourceImpl implements Network {
@Override
public String toString() {
return "NetworkImpl [id=" + getId() + ", location=" + getLocation() + ", name=" + getName()
+ ", type=" + getType() + ", description=" + description + ", dhcp=" + dhcp
+ ", dnsServers=" + dnsServers + ", fenceModes=" + fenceModes + ", firewallRules="
+ firewallRules + ", gateway=" + gateway + ", natRules=" + natRules + ", netmask="
+ netmask + "]";
return "NetworkImpl [id=" + getId() + ", location=" + getLocation()
+ ", name=" + getName() + ", type=" + getType() + ", description="
+ description + ", dhcp=" + dhcp + ", dnsServers=" + dnsServers
+ ", fenceModes=" + fenceModes + ", firewallRules=" + firewallRules
+ ", gateway=" + gateway + ", natRules=" + natRules + ", netmask="
+ netmask + "]";
}
}

View File

@ -18,6 +18,8 @@
*/
package org.jclouds.vcloud.domain.internal;
import static com.google.common.base.Preconditions.checkNotNull;
import java.net.URI;
import java.util.Set;
@ -55,27 +57,30 @@ public class VAppImpl implements VApp {
/** The serialVersionUID */
private static final long serialVersionUID = 8464716396538298809L;
public VAppImpl(String id, String name, URI location, VAppStatus status, Long size,
NamedResource vDC, ListMultimap<String, String> networkToAddresses,
String operatingSystemDescription, VirtualSystem system,
Set<ResourceAllocation> resourceAllocations) {
this.id = id;
this.name = name;
this.location = location;
this.status = status;
this.size = size;
public VAppImpl(String id, String name, URI location, VAppStatus status,
Long size, NamedResource vDC,
ListMultimap<String, String> networkToAddresses,
String operatingSystemDescription, VirtualSystem system,
Set<ResourceAllocation> resourceAllocations) {
this.id = checkNotNull(id, "id");
this.name = checkNotNull(name, "name");
this.location = checkNotNull(location, "location");
this.status = checkNotNull(status, "status");
this.size = size;// hostingdotcom
this.vDC = vDC;
this.networkToAddresses = networkToAddresses;
this.networkToAddresses = checkNotNull(networkToAddresses,
"networkToAddresses");
this.operatingSystemDescription = operatingSystemDescription;
this.system = system;
this.resourceAllocations = resourceAllocations;
this.resourceAllocations = checkNotNull(resourceAllocations,
"resourceAllocations");
resourceAllocationByType = Multimaps.index(resourceAllocations,
new Function<ResourceAllocation, ResourceType>() {
@Override
public ResourceType apply(ResourceAllocation from) {
return from.getType();
}
});
new Function<ResourceAllocation, ResourceType>() {
@Override
public ResourceType apply(ResourceAllocation from) {
return from.getType();
}
});
}
public VAppStatus getStatus() {
@ -113,13 +118,21 @@ public class VAppImpl implements VApp {
result = prime * result + ((id == null) ? 0 : id.hashCode());
result = prime * result + ((location == null) ? 0 : location.hashCode());
result = prime * result + ((name == null) ? 0 : name.hashCode());
result = prime * result + ((networkToAddresses == null) ? 0 : networkToAddresses.hashCode());
result = prime * result
+ ((operatingSystemDescription == null) ? 0 : operatingSystemDescription.hashCode());
result = prime * result
+ ((resourceAllocationByType == null) ? 0 : resourceAllocationByType.hashCode());
result = prime * result
+ ((resourceAllocations == null) ? 0 : resourceAllocations.hashCode());
result = prime
* result
+ ((networkToAddresses == null) ? 0 : networkToAddresses.hashCode());
result = prime
* result
+ ((operatingSystemDescription == null) ? 0
: operatingSystemDescription.hashCode());
result = prime
* result
+ ((resourceAllocationByType == null) ? 0
: resourceAllocationByType.hashCode());
result = prime
* result
+ ((resourceAllocations == null) ? 0 : resourceAllocations
.hashCode());
result = prime * result + ((size == null) ? 0 : size.hashCode());
result = prime * result + ((status == null) ? 0 : status.hashCode());
result = prime * result + ((system == null) ? 0 : system.hashCode());
@ -159,12 +172,14 @@ public class VAppImpl implements VApp {
if (operatingSystemDescription == null) {
if (other.operatingSystemDescription != null)
return false;
} else if (!operatingSystemDescription.equals(other.operatingSystemDescription))
} else if (!operatingSystemDescription
.equals(other.operatingSystemDescription))
return false;
if (resourceAllocationByType == null) {
if (other.resourceAllocationByType != null)
return false;
} else if (!resourceAllocationByType.equals(other.resourceAllocationByType))
} else if (!resourceAllocationByType
.equals(other.resourceAllocationByType))
return false;
if (resourceAllocations == null) {
if (other.resourceAllocations != null)
@ -212,11 +227,13 @@ public class VAppImpl implements VApp {
@Override
public String toString() {
return "[id=" + id + ", location=" + location + ", name=" + name + ", networkToAddresses="
+ networkToAddresses + ", operatingSystemDescription=" + operatingSystemDescription
+ ", resourceAllocationByType=" + resourceAllocationByType
+ ", resourceAllocations=" + resourceAllocations + ", size=" + size + ", status="
+ status + ", system=" + system + ", vDC=" + vDC + "]";
return "[id=" + id + ", location=" + location + ", name=" + name
+ ", networkToAddresses=" + networkToAddresses
+ ", operatingSystemDescription=" + operatingSystemDescription
+ ", resourceAllocationByType=" + resourceAllocationByType
+ ", resourceAllocations=" + resourceAllocations + ", size=" + size
+ ", status=" + status + ", system=" + system + ", vDC=" + vDC
+ "]";
}
@Override

View File

@ -56,6 +56,7 @@ public class ParseVCloudErrorFromHttpResponse implements HttpErrorHandler {
case 401:
exception = new AuthorizationException(command.getRequest(), content);
break;
case 403: // TODO temporary as terremark mistakenly uses this for vApp not found.
case 404:
if (!command.getRequest().getMethod().equals("DELETE")) {
String path = command.getRequest().getEndpoint().getPath();

View File

@ -21,13 +21,11 @@ package org.jclouds.vcloud.internal;
import java.net.URI;
import java.util.SortedMap;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import org.jclouds.rest.annotations.Endpoint;
import org.jclouds.rest.annotations.XMLResponseParser;
import org.jclouds.vcloud.VCloudMediaType;
import org.jclouds.vcloud.endpoints.VCloud;
import org.jclouds.vcloud.xml.SupportedVersionsHandler;
@ -37,18 +35,18 @@ import com.google.common.util.concurrent.ListenableFuture;
* Establishes a context with a VCloud endpoint.
* <p/>
*
* @see <a href="https://community.vcloudexpress.terremark.com/en-us/discussion_forums/f/60.aspx" />
* @see <a href="https://community.vcloudexpress.terremark.com/en-us/discussion_forums/f/60.aspx"
* />
* @author Adrian Cole
*/
@Endpoint(VCloud.class)
public interface VCloudVersionsAsyncClient {
/**
* Retrieve information for supported versions
* Retrieve information for supported versions
*/
@GET
@XMLResponseParser(SupportedVersionsHandler.class)
@Path("/versions")
@Consumes(VCloudMediaType.VCLOUD_XML)
ListenableFuture<SortedMap<String, URI>> getSupportedVersions();
}

View File

@ -40,7 +40,6 @@ public class InstantiateVAppTemplateOptions {
private String diskSizeKilobytes;
private String network;
private String fenceMode;
private String dhcpEnabled;
private String networkName;
private boolean blockOnDeploy = true;
private Map<String, String> properties = Maps.newTreeMap();
@ -77,16 +76,11 @@ public class InstantiateVAppTemplateOptions {
return this;
}
public InstantiateVAppTemplateOptions fenceMode(FenceMode fenceMode) {
public InstantiateVAppTemplateOptions fenceMode(String fenceMode) {
this.fenceMode = checkNotNull(fenceMode, "fenceMode").toString();
return this;
}
public InstantiateVAppTemplateOptions dhcpEnabled(boolean dhcpEnabled) {
this.dhcpEnabled = dhcpEnabled + "";
return this;
}
public InstantiateVAppTemplateOptions memory(long megabytes) {
checkArgument(megabytes >= 1, "megabytes must be positive");
this.memorySizeMegabytes = megabytes + "";
@ -129,10 +123,6 @@ public class InstantiateVAppTemplateOptions {
return fenceMode;
}
public String getDhcpEnabled() {
return dhcpEnabled;
}
public Map<String, String> getProperties() {
return properties;
}
@ -183,20 +173,11 @@ public class InstantiateVAppTemplateOptions {
/**
* @see InstantiateVAppTemplateOptions#fenceMode(FenceMode)
*/
public static InstantiateVAppTemplateOptions fenceMode(FenceMode fenceMode) {
public static InstantiateVAppTemplateOptions fenceMode(String fenceMode) {
InstantiateVAppTemplateOptions options = new InstantiateVAppTemplateOptions();
return options.fenceMode(fenceMode);
}
/**
* @see InstantiateVAppTemplateOptions#dhcpEnabled(boolean)
*/
public static InstantiateVAppTemplateOptions dhcpEnabled(
boolean dhcpEnabled) {
InstantiateVAppTemplateOptions options = new InstantiateVAppTemplateOptions();
return options.dhcpEnabled(dhcpEnabled);
}
/**
* @see InstantiateVAppTemplateOptions#networkName(String)
*/
@ -231,8 +212,7 @@ public class InstantiateVAppTemplateOptions {
+ ", memorySizeMegabytes=" + memorySizeMegabytes
+ ", diskSizeKilobytes=" + diskSizeKilobytes + ", network="
+ network + ", networkName=" + networkName + ", fenceMode="
+ fenceMode + ", dhcpEnabled=" + dhcpEnabled + ", properties="
+ properties + "]";
+ fenceMode + ", properties=" + properties + "]";
}
@Override
@ -240,8 +220,6 @@ public class InstantiateVAppTemplateOptions {
final int prime = 31;
int result = 1;
result = prime * result + ((cpuCount == null) ? 0 : cpuCount.hashCode());
result = prime * result
+ ((dhcpEnabled == null) ? 0 : dhcpEnabled.hashCode());
result = prime * result
+ ((diskSizeKilobytes == null) ? 0 : diskSizeKilobytes.hashCode());
result = prime * result
@ -272,11 +250,6 @@ public class InstantiateVAppTemplateOptions {
return false;
} else if (!cpuCount.equals(other.cpuCount))
return false;
if (dhcpEnabled == null) {
if (other.dhcpEnabled != null)
return false;
} else if (!dhcpEnabled.equals(other.dhcpEnabled))
return false;
if (diskSizeKilobytes == null) {
if (other.diskSizeKilobytes != null)
return false;

View File

@ -18,14 +18,14 @@
*/
package org.jclouds.vcloud.reference;
/**
* Configuration properties and constants used in VCloud connections.
*
* @author Adrian Cole
*/
public interface VCloudConstants {
public static final String PROPERTY_VCLOUD_VERSION = "jclouds.vcloud.version";
public static final String PROPERTY_VCLOUD_VERSION_API = "jclouds.vcloud.version.api";
public static final String PROPERTY_VCLOUD_VERSION_SCHEMA = "jclouds.vcloud.version.schema";
public static final String PROPERTY_VCLOUD_ENDPOINT = "jclouds.vcloud.endpoint";
public static final String PROPERTY_VCLOUD_USER = "jclouds.vcloud.user";
public static final String PROPERTY_VCLOUD_KEY = "jclouds.vcloud.key";
@ -33,22 +33,9 @@ public interface VCloudConstants {
* automatically renew vcloud token before this interval expires.
*/
public static final String PROPERTY_VCLOUD_SESSIONINTERVAL = "jclouds.vcloud.sessioninterval";
/**
* cpus
*/
public static final String PROPERTY_VCLOUD_DEFAULT_CPUCOUNT = "jclouds.vcloud.defaults.cpucount";
/**
* megabytes
*/
public static final String PROPERTY_VCLOUD_DEFAULT_DHCP_ENABLED = "jclouds.vcloud.defaults.dhcpenabled";
public static final String PROPERTY_VCLOUD_DEFAULT_NETWORK = "jclouds.vcloud.defaults.network";
public static final String PROPERTY_VCLOUD_DEFAULT_FENCEMODE = "jclouds.vcloud.defaults.fencemode";
public static final String PROPERTY_VCLOUD_DEFAULT_MEMORY = "jclouds.vcloud.defaults.memorysizemegabytes";
public static final String PROPERTY_VCLOUD_DEFAULT_NETWORK = "jclouds.vcloud.defaults.network";
/**
* kilobytes
*/
public static final String PROPERTY_VCLOUD_DEFAULT_DISK = "jclouds.vcloud.defaults.getdisksizekilobytes";
public static final String PROPERTY_VCLOUD_XML_NAMESPACE = "jclouds.vcloud.xml.ns";
public static final String PROPERTY_VCLOUD_XML_SCHEMA = "jclouds.vcloud.xml.schema";

View File

@ -24,7 +24,6 @@ import javax.annotation.Resource;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.logging.Logger;
import org.jclouds.vcloud.domain.FenceMode;
import org.jclouds.vcloud.domain.FirewallRule;
import org.jclouds.vcloud.domain.NamedResource;
import org.jclouds.vcloud.domain.NatRule;
@ -52,13 +51,13 @@ public class NetworkHandler extends ParseSax.HandlerWithResult<Network> {
private String description;
private Set<String> dnsServers = Sets.newHashSet();
private Set<String> dnsServers = Sets.newLinkedHashSet();
private String gateway;
private String netmask;
private Set<FenceMode> fenceModes = Sets.newHashSet();
private Set<String> fenceModes = Sets.newLinkedHashSet();
private Boolean dhcp;
private Set<NatRule> natRules = Sets.newHashSet();
private Set<FirewallRule> firewallRules = Sets.newHashSet();
private Set<NatRule> natRules = Sets.newLinkedHashSet();
private Set<FirewallRule> firewallRules = Sets.newLinkedHashSet();
private String externalIP;
private Integer externalPort;
@ -71,13 +70,14 @@ public class NetworkHandler extends ParseSax.HandlerWithResult<Network> {
private String sourcePort;
public Network getResult() {
return new NetworkImpl(network.getId(), network.getName(), network.getLocation(),
description, dnsServers, gateway, netmask, fenceModes, dhcp, natRules, firewallRules);
return new NetworkImpl(network.getId(), network.getName(), network
.getLocation(), description, dnsServers, gateway, netmask,
fenceModes, dhcp, natRules, firewallRules);
}
@Override
public void startElement(String uri, String localName, String qName, Attributes attributes)
throws SAXException {
public void startElement(String uri, String localName, String qName,
Attributes attributes) throws SAXException {
if (qName.equals("Network")) {
network = Utils.newNamedResource(attributes);
}
@ -93,11 +93,12 @@ public class NetworkHandler extends ParseSax.HandlerWithResult<Network> {
} else if (qName.equals("Netmask")) {
netmask = currentOrNull();
} else if (qName.equals("FenceMode")) {
fenceModes.add(FenceMode.fromValue(currentOrNull()));
fenceModes.add(currentOrNull());
} else if (qName.equals("Dhcp")) {
dhcp = new Boolean(currentOrNull());
} else if (qName.equals("NatRule")) {
natRules.add(new NatRule(externalIP, externalPort, internalIP, internalPort));
natRules.add(new NatRule(externalIP, externalPort, internalIP,
internalPort));
externalIP = null;
externalPort = null;
internalIP = null;
@ -111,7 +112,8 @@ public class NetworkHandler extends ParseSax.HandlerWithResult<Network> {
} else if (qName.equals("InternalPort")) {
internalPort = Integer.parseInt(currentOrNull());
} else if (qName.equals("FirewallRule")) {
firewallRules.add(new FirewallRule(policy, protocol, sourceIP, sourcePort));
firewallRules.add(new FirewallRule(policy, protocol, sourceIP,
sourcePort));
policy = null;
protocol = null;
sourceIP = null;

View File

@ -39,10 +39,10 @@ import com.google.common.collect.Maps;
* @author Adrian Cole
*/
public class OrgHandler extends ParseSax.HandlerWithResult<Organization> {
private NamedResource org;
private Map<String, NamedResource> vdcs = Maps.newLinkedHashMap();
private Map<String, NamedResource> tasksLists = Maps.newLinkedHashMap();
private Map<String, NamedResource> catalogs = Maps.newLinkedHashMap();
protected NamedResource org;
protected Map<String, NamedResource> vdcs = Maps.newLinkedHashMap();
protected Map<String, NamedResource> tasksLists = Maps.newLinkedHashMap();
protected Map<String, NamedResource> catalogs = Maps.newLinkedHashMap();
public Organization getResult() {
return new OrganizationImpl(org.getId(), org.getName(), org.getLocation(), catalogs, vdcs,

View File

@ -39,7 +39,6 @@ import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404;
import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.jclouds.rest.internal.RestAnnotationProcessor;
import com.google.inject.name.Names;
import org.jclouds.util.Utils;
import org.jclouds.vcloud.endpoints.Catalog;
import org.jclouds.vcloud.endpoints.Org;
@ -67,6 +66,7 @@ import org.testng.annotations.Test;
import com.google.inject.AbstractModule;
import com.google.inject.Module;
import com.google.inject.TypeLiteral;
import com.google.inject.name.Names;
/**
* Tests behavior of {@code VCloudAsyncClient}
@ -76,21 +76,22 @@ 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());
GeneratedHttpRequest<VCloudAsyncClient> httpMethod = processor.createRequest(method, "1",
"my-vapp", 3 + "");
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());
GeneratedHttpRequest<VCloudAsyncClient> httpMethod = processor
.createRequest(method, "1", "my-vapp", 3 + "");
assertRequestLineEquals(httpMethod,
"POST http://vcloud/vdc/1/action/instantiateVAppTemplate HTTP/1.1");
"POST http://vcloud/vdc/1/action/instantiateVAppTemplate HTTP/1.1");
assertHeadersEqual(
httpMethod,
"Accept: application/vnd.vmware.vcloud.vApp+xml\nContent-Length: 634\nContent-Type: application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml\n");
assertPayloadEquals(httpMethod, Utils.toStringAndClose(getClass().getResourceAsStream(
"/newvapp-hosting.xml")));
httpMethod,
"Accept: application/vnd.vmware.vcloud.vApp+xml\nContent-Length: 667\nContent-Type: application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml\n");
assertPayloadEquals(httpMethod, Utils.toStringAndClose(getClass()
.getResourceAsStream("/newvapp-hosting.xml")));
assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
assertSaxResponseParserClassEquals(method, VAppHandler.class);
@ -100,21 +101,32 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
}
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());
GeneratedHttpRequest<VCloudAsyncClient> httpMethod = processor.createRequest(method, "1",
"my-vapp", 3 + "", processorCount(1).memory(512).disk(1024).inNetwork(
URI.create("https://vcloud.safesecureweb.com/network/1990")));
NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod(
"instantiateVAppTemplateInVDC", String.class, String.class,
String.class, Array.newInstance(
InstantiateVAppTemplateOptions.class, 0).getClass());
GeneratedHttpRequest<VCloudAsyncClient> httpMethod = 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(httpMethod,
"POST http://vcloud/vdc/1/action/instantiateVAppTemplate HTTP/1.1");
"POST http://vcloud/vdc/1/action/instantiateVAppTemplate HTTP/1.1");
assertHeadersEqual(
httpMethod,
"Accept: application/vnd.vmware.vcloud.vApp+xml\nContent-Length: 2018\nContent-Type: application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml\n");
assertPayloadEquals(httpMethod, Utils.toStringAndClose(getClass().getResourceAsStream(
"/newvapp-hostingcpumemdisk.xml")));
httpMethod,
"Accept: application/vnd.vmware.vcloud.vApp+xml\nContent-Length: 2051\nContent-Type: application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml\n");
assertPayloadEquals(httpMethod, Utils.toStringAndClose(getClass()
.getResourceAsStream("/newvapp-hostingcpumemdisk.xml")));
assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
assertSaxResponseParserClassEquals(method, VAppHandler.class);
@ -124,27 +136,32 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
}
@Test(expectedExceptions = IllegalArgumentException.class)
public void testInstantiateVAppTemplateOptionsIllegalName() 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 testInstantiateVAppTemplateOptionsIllegalName()
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());
GeneratedHttpRequest<VCloudAsyncClient> httpMethod = processor.createRequest(method, "1",
"4181", "my-vapp");
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());
GeneratedHttpRequest<VCloudAsyncClient> httpMethod = processor
.createRequest(method, "1", "4181", "my-vapp");
assertRequestLineEquals(httpMethod, "POST http://vcloud/vdc/1/action/cloneVApp HTTP/1.1");
assertRequestLineEquals(httpMethod,
"POST http://vcloud/vdc/1/action/cloneVApp HTTP/1.1");
assertHeadersEqual(
httpMethod,
"Accept: application/vnd.vmware.vcloud.task+xml\nContent-Length: 397\nContent-Type: application/vnd.vmware.vcloud.cloneVAppParams+xml\n");
assertPayloadEquals(httpMethod, Utils.toStringAndClose(getClass().getResourceAsStream(
"/cloneVApp-default.xml")));
httpMethod,
"Accept: application/vnd.vmware.vcloud.task+xml\nContent-Length: 397\nContent-Type: application/vnd.vmware.vcloud.cloneVAppParams+xml\n");
assertPayloadEquals(httpMethod, Utils.toStringAndClose(getClass()
.getResourceAsStream("/cloneVApp-default.xml")));
assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
assertSaxResponseParserClassEquals(method, TaskHandler.class);
@ -153,19 +170,23 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
checkFilters(httpMethod);
}
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());
GeneratedHttpRequest<VCloudAsyncClient> httpMethod = processor.createRequest(method, "1",
"201", "new-linux-server", new CloneVAppOptions().deploy().powerOn()
.withDescription("The description of the new vApp"));
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());
GeneratedHttpRequest<VCloudAsyncClient> httpMethod = processor
.createRequest(method, "1", "201", "new-linux-server",
new CloneVAppOptions().deploy().powerOn().withDescription(
"The description of the new vApp"));
assertRequestLineEquals(httpMethod, "POST http://vcloud/vdc/1/action/cloneVApp HTTP/1.1");
assertRequestLineEquals(httpMethod,
"POST http://vcloud/vdc/1/action/cloneVApp HTTP/1.1");
assertHeadersEqual(
httpMethod,
"Accept: application/vnd.vmware.vcloud.task+xml\nContent-Length: 461\nContent-Type: application/vnd.vmware.vcloud.cloneVAppParams+xml\n");
assertPayloadEquals(httpMethod, Utils.toStringAndClose(getClass().getResourceAsStream(
"/cloneVApp.xml")));
httpMethod,
"Accept: application/vnd.vmware.vcloud.task+xml\nContent-Length: 461\nContent-Type: application/vnd.vmware.vcloud.cloneVAppParams+xml\n");
assertPayloadEquals(httpMethod, Utils.toStringAndClose(getClass()
.getResourceAsStream("/cloneVApp.xml")));
assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
assertSaxResponseParserClassEquals(method, TaskHandler.class);
@ -175,21 +196,26 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
}
@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 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 testDefaultOrganization() throws SecurityException, NoSuchMethodException,
IOException {
Method method = VCloudAsyncClient.class.getMethod("getDefaultOrganization");
GeneratedHttpRequest<VCloudAsyncClient> httpMethod = processor.createRequest(method);
public void testDefaultOrganization() throws SecurityException,
NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class
.getMethod("getDefaultOrganization");
GeneratedHttpRequest<VCloudAsyncClient> httpMethod = processor
.createRequest(method);
assertRequestLineEquals(httpMethod, "GET http://org HTTP/1.1");
assertHeadersEqual(httpMethod, "Accept: application/vnd.vmware.vcloud.org+xml\n");
assertHeadersEqual(httpMethod,
"Accept: application/vnd.vmware.vcloud.org+xml\n");
assertPayloadEquals(httpMethod, null);
assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
@ -199,12 +225,16 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
checkFilters(httpMethod);
}
public void testOrganization() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("getOrganization", String.class);
GeneratedHttpRequest<VCloudAsyncClient> httpMethod = processor.createRequest(method, "1");
public void testOrganization() throws SecurityException,
NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("getOrganization",
String.class);
GeneratedHttpRequest<VCloudAsyncClient> httpMethod = processor
.createRequest(method, "1");
assertRequestLineEquals(httpMethod, "GET http://vcloud/org/1 HTTP/1.1");
assertHeadersEqual(httpMethod, "Accept: application/vnd.vmware.vcloud.org+xml\n");
assertHeadersEqual(httpMethod,
"Accept: application/vnd.vmware.vcloud.org+xml\n");
assertPayloadEquals(httpMethod, null);
assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
@ -214,12 +244,15 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
checkFilters(httpMethod);
}
public void testDefaultCatalog() throws SecurityException, NoSuchMethodException, IOException {
public void testDefaultCatalog() throws SecurityException,
NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("getDefaultCatalog");
GeneratedHttpRequest<VCloudAsyncClient> httpMethod = processor.createRequest(method);
GeneratedHttpRequest<VCloudAsyncClient> httpMethod = processor
.createRequest(method);
assertRequestLineEquals(httpMethod, "GET http://catalog HTTP/1.1");
assertHeadersEqual(httpMethod, "Accept: application/vnd.vmware.vcloud.catalog+xml\n");
assertHeadersEqual(httpMethod,
"Accept: application/vnd.vmware.vcloud.catalog+xml\n");
assertPayloadEquals(httpMethod, null);
assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
@ -229,12 +262,17 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
checkFilters(httpMethod);
}
public void testCatalog() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("getCatalog", String.class);
GeneratedHttpRequest<VCloudAsyncClient> httpMethod = processor.createRequest(method, "1");
public void testCatalog() throws SecurityException, NoSuchMethodException,
IOException {
Method method = VCloudAsyncClient.class.getMethod("getCatalog",
String.class);
GeneratedHttpRequest<VCloudAsyncClient> httpMethod = processor
.createRequest(method, "1");
assertRequestLineEquals(httpMethod, "GET http://vcloud/catalog/1 HTTP/1.1");
assertHeadersEqual(httpMethod, "Accept: application/vnd.vmware.vcloud.catalog+xml\n");
assertRequestLineEquals(httpMethod,
"GET http://vcloud/catalog/1 HTTP/1.1");
assertHeadersEqual(httpMethod,
"Accept: application/vnd.vmware.vcloud.catalog+xml\n");
assertPayloadEquals(httpMethod, null);
assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
@ -244,12 +282,17 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
checkFilters(httpMethod);
}
public void testNetwork() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("getNetwork", String.class);
GeneratedHttpRequest<VCloudAsyncClient> httpMethod = processor.createRequest(method, "2");
public void testNetwork() throws SecurityException, NoSuchMethodException,
IOException {
Method method = VCloudAsyncClient.class.getMethod("getNetwork",
String.class);
GeneratedHttpRequest<VCloudAsyncClient> httpMethod = processor
.createRequest(method, "2");
assertRequestLineEquals(httpMethod, "GET http://vcloud/network/2 HTTP/1.1");
assertHeadersEqual(httpMethod, "Accept: application/vnd.vmware.vcloud.network+xml\n");
assertRequestLineEquals(httpMethod,
"GET http://vcloud/network/2 HTTP/1.1");
assertHeadersEqual(httpMethod,
"Accept: application/vnd.vmware.vcloud.network+xml\n");
assertPayloadEquals(httpMethod, null);
assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
@ -259,12 +302,17 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
checkFilters(httpMethod);
}
public void testCatalogItem() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("getCatalogItem", String.class);
GeneratedHttpRequest<VCloudAsyncClient> httpMethod = processor.createRequest(method, "2");
public void testCatalogItem() throws SecurityException,
NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("getCatalogItem",
String.class);
GeneratedHttpRequest<VCloudAsyncClient> httpMethod = processor
.createRequest(method, "2");
assertRequestLineEquals(httpMethod, "GET http://vcloud/catalogItem/2 HTTP/1.1");
assertHeadersEqual(httpMethod, "Accept: application/vnd.vmware.vcloud.catalogItem+xml\n");
assertRequestLineEquals(httpMethod,
"GET http://vcloud/catalogItem/2 HTTP/1.1");
assertHeadersEqual(httpMethod,
"Accept: application/vnd.vmware.vcloud.catalogItem+xml\n");
assertPayloadEquals(httpMethod, null);
assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
@ -274,12 +322,17 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
checkFilters(httpMethod);
}
public void testVAppTemplate() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("getVAppTemplate", String.class);
GeneratedHttpRequest<VCloudAsyncClient> httpMethod = processor.createRequest(method, "2");
public void testVAppTemplate() throws SecurityException,
NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("getVAppTemplate",
String.class);
GeneratedHttpRequest<VCloudAsyncClient> httpMethod = processor
.createRequest(method, "2");
assertRequestLineEquals(httpMethod, "GET http://vcloud/vAppTemplate/2 HTTP/1.1");
assertHeadersEqual(httpMethod, "Accept: application/vnd.vmware.vcloud.vAppTemplate+xml\n");
assertRequestLineEquals(httpMethod,
"GET http://vcloud/vAppTemplate/2 HTTP/1.1");
assertHeadersEqual(httpMethod,
"Accept: application/vnd.vmware.vcloud.vAppTemplate+xml\n");
assertPayloadEquals(httpMethod, null);
assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
@ -289,12 +342,15 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
checkFilters(httpMethod);
}
public void testGetDefaultVDC() throws SecurityException, NoSuchMethodException, IOException {
public void testGetDefaultVDC() throws SecurityException,
NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("getDefaultVDC");
GeneratedHttpRequest<VCloudAsyncClient> httpMethod = processor.createRequest(method);
GeneratedHttpRequest<VCloudAsyncClient> httpMethod = processor
.createRequest(method);
assertRequestLineEquals(httpMethod, "GET http://vdc HTTP/1.1");
assertHeadersEqual(httpMethod, "Accept: application/vnd.vmware.vcloud.vdc+xml\n");
assertHeadersEqual(httpMethod,
"Accept: application/vnd.vmware.vcloud.vdc+xml\n");
assertPayloadEquals(httpMethod, null);
assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
@ -304,12 +360,15 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
checkFilters(httpMethod);
}
public void testGetVDC() throws SecurityException, NoSuchMethodException, IOException {
public void testGetVDC() throws SecurityException, NoSuchMethodException,
IOException {
Method method = VCloudAsyncClient.class.getMethod("getVDC", String.class);
GeneratedHttpRequest<VCloudAsyncClient> httpMethod = processor.createRequest(method, "1");
GeneratedHttpRequest<VCloudAsyncClient> httpMethod = processor
.createRequest(method, "1");
assertRequestLineEquals(httpMethod, "GET http://vcloud/vdc/1 HTTP/1.1");
assertHeadersEqual(httpMethod, "Accept: application/vnd.vmware.vcloud.vdc+xml\n");
assertHeadersEqual(httpMethod,
"Accept: application/vnd.vmware.vcloud.vdc+xml\n");
assertPayloadEquals(httpMethod, null);
assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
@ -319,13 +378,15 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
checkFilters(httpMethod);
}
public void testGetDefaultTasksList() throws SecurityException, NoSuchMethodException,
IOException {
public void testGetDefaultTasksList() throws SecurityException,
NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("getDefaultTasksList");
GeneratedHttpRequest<VCloudAsyncClient> httpMethod = processor.createRequest(method);
GeneratedHttpRequest<VCloudAsyncClient> httpMethod = processor
.createRequest(method);
assertRequestLineEquals(httpMethod, "GET http://tasksList HTTP/1.1");
assertHeadersEqual(httpMethod, "Accept: application/vnd.vmware.vcloud.tasksList+xml\n");
assertHeadersEqual(httpMethod,
"Accept: application/vnd.vmware.vcloud.tasksList+xml\n");
assertPayloadEquals(httpMethod, null);
assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
@ -335,12 +396,17 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
checkFilters(httpMethod);
}
public void testGetTasksList() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("getTasksList", String.class);
GeneratedHttpRequest<VCloudAsyncClient> httpMethod = processor.createRequest(method, "1");
public void testGetTasksList() throws SecurityException,
NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("getTasksList",
String.class);
GeneratedHttpRequest<VCloudAsyncClient> httpMethod = processor
.createRequest(method, "1");
assertRequestLineEquals(httpMethod, "GET http://vcloud/tasksList/1 HTTP/1.1");
assertHeadersEqual(httpMethod, "Accept: application/vnd.vmware.vcloud.tasksList+xml\n");
assertRequestLineEquals(httpMethod,
"GET http://vcloud/tasksList/1 HTTP/1.1");
assertHeadersEqual(httpMethod,
"Accept: application/vnd.vmware.vcloud.tasksList+xml\n");
assertPayloadEquals(httpMethod, null);
assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
@ -350,12 +416,17 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
checkFilters(httpMethod);
}
public void testDeployVApp() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("deployVApp", String.class);
GeneratedHttpRequest<VCloudAsyncClient> httpMethod = processor.createRequest(method, 1);
public void testDeployVApp() throws SecurityException,
NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("deployVApp",
String.class);
GeneratedHttpRequest<VCloudAsyncClient> httpMethod = processor
.createRequest(method, 1);
assertRequestLineEquals(httpMethod, "POST http://vcloud/vApp/1/action/deploy HTTP/1.1");
assertHeadersEqual(httpMethod, "Accept: application/vnd.vmware.vcloud.task+xml\n");
assertRequestLineEquals(httpMethod,
"POST http://vcloud/vApp/1/action/deploy HTTP/1.1");
assertHeadersEqual(httpMethod,
"Accept: application/vnd.vmware.vcloud.task+xml\n");
assertPayloadEquals(httpMethod, null);
assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
@ -365,12 +436,16 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
checkFilters(httpMethod);
}
public void testGetVApp() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("getVApp", String.class);
GeneratedHttpRequest<VCloudAsyncClient> httpMethod = processor.createRequest(method, 1);
public void testGetVApp() throws SecurityException, NoSuchMethodException,
IOException {
Method method = VCloudAsyncClient.class
.getMethod("getVApp", String.class);
GeneratedHttpRequest<VCloudAsyncClient> httpMethod = processor
.createRequest(method, 1);
assertRequestLineEquals(httpMethod, "GET http://vcloud/vApp/1 HTTP/1.1");
assertHeadersEqual(httpMethod, "Accept: application/vnd.vmware.vcloud.vApp+xml\n");
assertHeadersEqual(httpMethod,
"Accept: application/vnd.vmware.vcloud.vApp+xml\n");
assertPayloadEquals(httpMethod, null);
assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
@ -380,12 +455,17 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
checkFilters(httpMethod);
}
public void testUndeployVApp() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("undeployVApp", String.class);
GeneratedHttpRequest<VCloudAsyncClient> httpMethod = processor.createRequest(method, 1);
public void testUndeployVApp() throws SecurityException,
NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("undeployVApp",
String.class);
GeneratedHttpRequest<VCloudAsyncClient> httpMethod = processor
.createRequest(method, 1);
assertRequestLineEquals(httpMethod, "POST http://vcloud/vApp/1/action/undeploy HTTP/1.1");
assertHeadersEqual(httpMethod, "Accept: application/vnd.vmware.vcloud.task+xml\n");
assertRequestLineEquals(httpMethod,
"POST http://vcloud/vApp/1/action/undeploy HTTP/1.1");
assertHeadersEqual(httpMethod,
"Accept: application/vnd.vmware.vcloud.task+xml\n");
assertPayloadEquals(httpMethod, null);
assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
@ -395,43 +475,37 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
checkFilters(httpMethod);
}
public void testDeleteVApp() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("deleteVApp", String.class);
GeneratedHttpRequest<VCloudAsyncClient> httpMethod = processor.createRequest(method, 1);
public void testDeleteVApp() throws SecurityException,
NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("deleteVApp",
String.class);
GeneratedHttpRequest<VCloudAsyncClient> httpMethod = processor
.createRequest(method, 1);
assertRequestLineEquals(httpMethod, "DELETE http://vcloud/vApp/1 HTTP/1.1");
assertRequestLineEquals(httpMethod,
"DELETE http://vcloud/vApp/1 HTTP/1.1");
assertHeadersEqual(httpMethod, "");
assertPayloadEquals(httpMethod, null);
assertResponseParserClassEquals(method, httpMethod, CloseContentAndReturn.class);
assertResponseParserClassEquals(method, httpMethod,
CloseContentAndReturn.class);
assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, ReturnVoidOnNotFoundOr404.class);
checkFilters(httpMethod);
}
public void testPowerOn() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("powerOnVApp", String.class);
GeneratedHttpRequest<VCloudAsyncClient> httpMethod = processor.createRequest(method, 1);
assertRequestLineEquals(httpMethod, "POST http://vcloud/vApp/1/power/action/powerOn HTTP/1.1");
assertHeadersEqual(httpMethod, "Accept: application/vnd.vmware.vcloud.task+xml\n");
assertPayloadEquals(httpMethod, null);
assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
assertSaxResponseParserClassEquals(method, TaskHandler.class);
assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod);
}
public void testPowerOff() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("powerOffVApp", String.class);
GeneratedHttpRequest<VCloudAsyncClient> httpMethod = processor.createRequest(method, 1);
public void testPowerOn() throws SecurityException, NoSuchMethodException,
IOException {
Method method = VCloudAsyncClient.class.getMethod("powerOnVApp",
String.class);
GeneratedHttpRequest<VCloudAsyncClient> httpMethod = processor
.createRequest(method, 1);
assertRequestLineEquals(httpMethod,
"POST http://vcloud/vApp/1/power/action/powerOff HTTP/1.1");
assertHeadersEqual(httpMethod, "Accept: application/vnd.vmware.vcloud.task+xml\n");
"POST http://vcloud/vApp/1/power/action/powerOn HTTP/1.1");
assertHeadersEqual(httpMethod,
"Accept: application/vnd.vmware.vcloud.task+xml\n");
assertPayloadEquals(httpMethod, null);
assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
@ -441,58 +515,96 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
checkFilters(httpMethod);
}
public void testReset() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("resetVApp", String.class);
GeneratedHttpRequest<VCloudAsyncClient> httpMethod = processor.createRequest(method, 1);
assertRequestLineEquals(httpMethod, "POST http://vcloud/vApp/1/power/action/reset HTTP/1.1");
assertHeadersEqual(httpMethod, "Accept: application/vnd.vmware.vcloud.task+xml\n");
assertPayloadEquals(httpMethod, null);
assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
assertSaxResponseParserClassEquals(method, TaskHandler.class);
assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod);
}
public void testSuspend() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("suspendVApp", String.class);
GeneratedHttpRequest<VCloudAsyncClient> httpMethod = processor.createRequest(method, 1);
assertRequestLineEquals(httpMethod, "POST http://vcloud/vApp/1/power/action/suspend HTTP/1.1");
assertHeadersEqual(httpMethod, "Accept: application/vnd.vmware.vcloud.task+xml\n");
assertPayloadEquals(httpMethod, null);
assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
assertSaxResponseParserClassEquals(method, TaskHandler.class);
assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod);
}
public void testShutdown() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("shutdownVApp", String.class);
GeneratedHttpRequest<VCloudAsyncClient> httpMethod = processor.createRequest(method, 1);
public void testPowerOff() throws SecurityException, NoSuchMethodException,
IOException {
Method method = VCloudAsyncClient.class.getMethod("powerOffVApp",
String.class);
GeneratedHttpRequest<VCloudAsyncClient> httpMethod = processor
.createRequest(method, 1);
assertRequestLineEquals(httpMethod,
"POST http://vcloud/vApp/1/power/action/shutdown HTTP/1.1");
"POST http://vcloud/vApp/1/power/action/powerOff HTTP/1.1");
assertHeadersEqual(httpMethod,
"Accept: application/vnd.vmware.vcloud.task+xml\n");
assertPayloadEquals(httpMethod, null);
assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
assertSaxResponseParserClassEquals(method, TaskHandler.class);
assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod);
}
public void testReset() throws SecurityException, NoSuchMethodException,
IOException {
Method method = VCloudAsyncClient.class.getMethod("resetVApp",
String.class);
GeneratedHttpRequest<VCloudAsyncClient> httpMethod = processor
.createRequest(method, 1);
assertRequestLineEquals(httpMethod,
"POST http://vcloud/vApp/1/power/action/reset HTTP/1.1");
assertHeadersEqual(httpMethod,
"Accept: application/vnd.vmware.vcloud.task+xml\n");
assertPayloadEquals(httpMethod, null);
assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
assertSaxResponseParserClassEquals(method, TaskHandler.class);
assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod);
}
public void testSuspend() throws SecurityException, NoSuchMethodException,
IOException {
Method method = VCloudAsyncClient.class.getMethod("suspendVApp",
String.class);
GeneratedHttpRequest<VCloudAsyncClient> httpMethod = processor
.createRequest(method, 1);
assertRequestLineEquals(httpMethod,
"POST http://vcloud/vApp/1/power/action/suspend HTTP/1.1");
assertHeadersEqual(httpMethod,
"Accept: application/vnd.vmware.vcloud.task+xml\n");
assertPayloadEquals(httpMethod, null);
assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
assertSaxResponseParserClassEquals(method, TaskHandler.class);
assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod);
}
public void testShutdown() throws SecurityException, NoSuchMethodException,
IOException {
Method method = VCloudAsyncClient.class.getMethod("shutdownVApp",
String.class);
GeneratedHttpRequest<VCloudAsyncClient> httpMethod = processor
.createRequest(method, 1);
assertRequestLineEquals(httpMethod,
"POST http://vcloud/vApp/1/power/action/shutdown HTTP/1.1");
assertHeadersEqual(httpMethod, "");
assertPayloadEquals(httpMethod, null);
assertResponseParserClassEquals(method, httpMethod, CloseContentAndReturn.class);
assertResponseParserClassEquals(method, httpMethod,
CloseContentAndReturn.class);
assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod);
}
public void testGetTask() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("getTask", String.class);
GeneratedHttpRequest<VCloudAsyncClient> httpMethod = processor.createRequest(method, "1");
public void testGetTask() throws SecurityException, NoSuchMethodException,
IOException {
Method method = VCloudAsyncClient.class
.getMethod("getTask", String.class);
GeneratedHttpRequest<VCloudAsyncClient> httpMethod = processor
.createRequest(method, "1");
assertRequestLineEquals(httpMethod, "GET http://vcloud/task/1 HTTP/1.1");
assertHeadersEqual(httpMethod, "Accept: application/vnd.vmware.vcloud.task+xml\n");
assertHeadersEqual(httpMethod,
"Accept: application/vnd.vmware.vcloud.task+xml\n");
assertPayloadEquals(httpMethod, null);
assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
@ -502,15 +614,20 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
checkFilters(httpMethod);
}
public void testCancelTask() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("cancelTask", String.class);
GeneratedHttpRequest<VCloudAsyncClient> httpMethod = processor.createRequest(method, "1");
public void testCancelTask() throws SecurityException,
NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("cancelTask",
String.class);
GeneratedHttpRequest<VCloudAsyncClient> httpMethod = processor
.createRequest(method, "1");
assertRequestLineEquals(httpMethod, "POST http://vcloud/task/1/action/cancel HTTP/1.1");
assertRequestLineEquals(httpMethod,
"POST http://vcloud/task/1/action/cancel HTTP/1.1");
assertHeadersEqual(httpMethod, "");
assertPayloadEquals(httpMethod, null);
assertResponseParserClassEquals(method, httpMethod, CloseContentAndReturn.class);
assertResponseParserClassEquals(method, httpMethod,
CloseContentAndReturn.class);
assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null);
@ -518,9 +635,11 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
}
@Override
protected void checkFilters(GeneratedHttpRequest<VCloudAsyncClient> httpMethod) {
protected void checkFilters(
GeneratedHttpRequest<VCloudAsyncClient> httpMethod) {
assertEquals(httpMethod.getFilters().size(), 1);
assertEquals(httpMethod.getFilters().get(0).getClass(), SetVCloudTokenCookie.class);
assertEquals(httpMethod.getFilters().get(0).getClass(),
SetVCloudTokenCookie.class);
}
@Override
@ -536,29 +655,35 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
protected void configure() {
Properties props = new Properties();
props.put(VCloudConstants.PROPERTY_VCLOUD_DEFAULT_NETWORK,
"https://vcloud.safesecureweb.com/network/1990");
"https://vcloud.safesecureweb.com/network/1990");
Names.bindProperties(binder(), checkNotNull(
new VCloudPropertiesBuilder(props).build(), "properties"));
bind(URI.class).annotatedWith(Org.class).toInstance(URI.create("http://org"));
bind(URI.class).annotatedWith(Catalog.class).toInstance(URI.create("http://catalog"));
bind(String.class).annotatedWith(CatalogItemRoot.class)
.toInstance("http://catalogItem");
bind(String.class).annotatedWith(VAppTemplateRoot.class).toInstance(
"https://vcloud.safesecureweb.com/api/v0.8/vAppTemplate");
new VCloudPropertiesBuilder(props).build(), "properties"));
bind(URI.class).annotatedWith(Org.class).toInstance(
URI.create("http://org"));
bind(URI.class).annotatedWith(Catalog.class).toInstance(
URI.create("http://catalog"));
bind(String.class).annotatedWith(CatalogItemRoot.class).toInstance(
"http://catalogItem");
bind(String.class)
.annotatedWith(VAppTemplateRoot.class)
.toInstance(
"https://vcloud.safesecureweb.com/api/v0.8/vAppTemplate");
bind(String.class).annotatedWith(VAppRoot.class).toInstance(
"https://services.vcloudexpress.terremark.com/api/vapp");
bind(URI.class).annotatedWith(VDC.class).toInstance(URI.create("http://vdc"));
"https://services.vcloudexpress.terremark.com/api/vapp");
bind(URI.class).annotatedWith(VDC.class).toInstance(
URI.create("http://vdc"));
bind(URI.class).annotatedWith(TasksList.class).toInstance(
URI.create("http://tasksList"));
bind(URI.class).annotatedWith(VCloudApi.class).toInstance(URI.create("http://vcloud"));
URI.create("http://tasksList"));
bind(URI.class).annotatedWith(VCloudApi.class).toInstance(
URI.create("http://vcloud"));
bind(SetVCloudTokenCookie.class).toInstance(
new SetVCloudTokenCookie(new Provider<String>() {
new SetVCloudTokenCookie(new Provider<String>() {
public String get() {
return "token";
}
public String get() {
return "token";
}
}));
}));
bind(Logger.LoggerFactory.class).toInstance(new LoggerFactory() {
public Logger getLogger(String category) {

View File

@ -26,15 +26,12 @@ import java.lang.reflect.Method;
import java.net.URI;
import java.util.Properties;
import javax.ws.rs.core.HttpHeaders;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.logging.Logger;
import org.jclouds.logging.Logger.LoggerFactory;
import org.jclouds.rest.RestClientTest;
import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.jclouds.rest.internal.RestAnnotationProcessor;
import com.google.inject.name.Names;
import org.jclouds.vcloud.endpoints.VCloud;
import org.jclouds.vcloud.internal.VCloudVersionsAsyncClient;
import org.jclouds.vcloud.xml.SupportedVersionsHandler;
@ -43,6 +40,7 @@ import org.testng.annotations.Test;
import com.google.inject.AbstractModule;
import com.google.inject.Module;
import com.google.inject.TypeLiteral;
import com.google.inject.name.Names;
/**
* Tests behavior of {@code VCloudVersions}
@ -50,15 +48,19 @@ import com.google.inject.TypeLiteral;
* @author Adrian Cole
*/
@Test(groups = "unit", testName = "vcloud.VCloudVersionsTest")
public class VCloudVersionsTest extends RestClientTest<VCloudVersionsAsyncClient> {
public class VCloudVersionsTest extends
RestClientTest<VCloudVersionsAsyncClient> {
public void testLogin() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudVersionsAsyncClient.class.getMethod("getSupportedVersions");
GeneratedHttpRequest<VCloudVersionsAsyncClient> httpMethod = processor.createRequest(method);
public void testLogin() throws SecurityException, NoSuchMethodException,
IOException {
Method method = VCloudVersionsAsyncClient.class
.getMethod("getSupportedVersions");
GeneratedHttpRequest<VCloudVersionsAsyncClient> httpMethod = processor
.createRequest(method);
assertEquals(httpMethod.getRequestLine(), "GET http://localhost:8080/versions HTTP/1.1");
assertHeadersEqual(httpMethod, HttpHeaders.ACCEPT
+ ": application/vnd.vmware.vcloud.vcloud+xml\n");
assertEquals(httpMethod.getRequestLine(),
"GET http://localhost:8080/versions HTTP/1.1");
assertHeadersEqual(httpMethod, "");
assertPayloadEquals(httpMethod, null);
assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
@ -69,7 +71,8 @@ public class VCloudVersionsTest extends RestClientTest<VCloudVersionsAsyncClient
}
@Override
protected void checkFilters(GeneratedHttpRequest<VCloudVersionsAsyncClient> httpMethod) {
protected void checkFilters(
GeneratedHttpRequest<VCloudVersionsAsyncClient> httpMethod) {
assertEquals(httpMethod.getFilters().size(), 0);
}
@ -85,9 +88,10 @@ public class VCloudVersionsTest extends RestClientTest<VCloudVersionsAsyncClient
@Override
protected void configure() {
Names.bindProperties(binder(), checkNotNull(
new VCloudPropertiesBuilder(new Properties()).build(), "properties"));
new VCloudPropertiesBuilder(new Properties()).build(),
"properties"));
bind(URI.class).annotatedWith(VCloud.class).toInstance(
URI.create("http://localhost:8080"));
URI.create("http://localhost:8080"));
bind(Logger.LoggerFactory.class).toInstance(new LoggerFactory() {
public Logger getLogger(String category) {
return Logger.NULL;

View File

@ -31,11 +31,10 @@ import java.util.Map;
import java.util.Properties;
import org.jclouds.rest.internal.GeneratedHttpRequest;
import com.google.inject.name.Names;
import org.jclouds.util.Utils;
import org.jclouds.vcloud.VCloudPropertiesBuilder;
import org.jclouds.vcloud.domain.FenceMode;
import org.jclouds.vcloud.domain.ResourceType;
import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions;
import org.testng.annotations.Test;
import com.google.common.collect.HashMultimap;
@ -45,6 +44,7 @@ import com.google.common.collect.Multimaps;
import com.google.inject.AbstractModule;
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.name.Names;
/**
* Tests behavior of {@code BindInstantiateVAppTemplateParamsToXmlPayload}
@ -58,63 +58,68 @@ public class BindInstantiateVAppTemplateParamsToXmlPayloadTest {
@Override
protected void configure() {
Properties props = new Properties();
props
.put(PROPERTY_VCLOUD_DEFAULT_NETWORK,
"https://vcloud.safesecureweb.com/network/1990");
Names.bindProperties(binder(), checkNotNull(new VCloudPropertiesBuilder(props).build(),
"properties"));
props.put(PROPERTY_VCLOUD_DEFAULT_NETWORK,
"https://vcloud.safesecureweb.com/network/1990");
Names.bindProperties(binder(), checkNotNull(
new VCloudPropertiesBuilder(props).build(), "properties"));
}
});
public void testDefault() throws IOException {
String expected = Utils.toStringAndClose(getClass().getResourceAsStream(
"/newvapp-hosting.xml"));
Multimap<String, String> headers = Multimaps.synchronizedMultimap(HashMultimap
.<String, String> create());
"/newvapp-hosting.xml"));
Multimap<String, String> headers = Multimaps
.synchronizedMultimap(HashMultimap.<String, String> create());
GeneratedHttpRequest<?> request = createMock(GeneratedHttpRequest.class);
expect(request.getEndpoint()).andReturn(URI.create("http://localhost/key")).anyTimes();
expect(request.getEndpoint()).andReturn(
URI.create("http://localhost/key")).anyTimes();
expect(request.getArgs()).andReturn(new Object[] {}).atLeastOnce();
expect(request.getFirstHeaderOrNull("Content-Type")).andReturn(null).atLeastOnce();
expect(request.getFirstHeaderOrNull("Content-Type")).andReturn(null)
.atLeastOnce();
expect(request.getHeaders()).andReturn(headers).atLeastOnce();
request.setPayload(expected);
replay(request);
BindInstantiateVAppTemplateParamsToXmlPayload binder = injector
.getInstance(BindInstantiateVAppTemplateParamsToXmlPayload.class);
.getInstance(BindInstantiateVAppTemplateParamsToXmlPayload.class);
Map<String, String> map = Maps.newHashMap();
map.put("name", "my-vapp");
map.put("template", "https://vcloud.safesecureweb.com/api/v0.8/vAppTemplate/3");
map.put("template",
"https://vcloud.safesecureweb.com/api/v0.8/vAppTemplate/3");
binder.bindToRequest(request, map);
verify(request);
}
public void testWithProcessorMemoryDisk() throws IOException {
InstantiateVAppTemplateOptions options = new InstantiateVAppTemplateOptions();
options.processorCount(1).memory(512).disk(1024);
String expected = Utils.toStringAndClose(getClass().getResourceAsStream(
"/newvapp-hostingcpumemdisk.xml"));
Multimap<String, String> headers = Multimaps.synchronizedMultimap(HashMultimap
.<String, String> create());
"/newvapp-hostingcpumemdisk.xml"));
Multimap<String, String> headers = Multimaps
.synchronizedMultimap(HashMultimap.<String, String> create());
GeneratedHttpRequest<?> request = createMock(GeneratedHttpRequest.class);
expect(request.getEndpoint()).andReturn(URI.create("http://localhost/key")).anyTimes();
expect(request.getArgs()).andReturn(new Object[] {}).atLeastOnce();
expect(request.getFirstHeaderOrNull("Content-Type")).andReturn(null).atLeastOnce();
expect(request.getEndpoint()).andReturn(
URI.create("http://localhost/key")).anyTimes();
expect(request.getArgs()).andReturn(new Object[] { options })
.atLeastOnce();
expect(request.getFirstHeaderOrNull("Content-Type")).andReturn(null)
.atLeastOnce();
expect(request.getHeaders()).andReturn(headers).atLeastOnce();
request.setPayload(expected);
replay(request);
BindInstantiateVAppTemplateParamsToXmlPayload binder = injector
.getInstance(BindInstantiateVAppTemplateParamsToXmlPayload.class);
.getInstance(BindInstantiateVAppTemplateParamsToXmlPayload.class);
Map<String, String> map = Maps.newHashMap();
map.put("name", "my-vapp");
map.put("template", "https://vcloud.safesecureweb.com/api/v0.8/vAppTemplate/3");
map.put("template",
"https://vcloud.safesecureweb.com/api/v0.8/vAppTemplate/3");
map.put("network", "https://vcloud.safesecureweb.com/network/1990");
map.put(ResourceType.PROCESSOR.value(), "1");
map.put(ResourceType.MEMORY.value(), "512");
map.put(ResourceType.DISK_DRIVE.value(), "1024");
binder.bindToRequest(request, map);
verify(request);
@ -122,27 +127,29 @@ public class BindInstantiateVAppTemplateParamsToXmlPayloadTest {
public void testWithNetworkNameDhcpFenceMode() throws IOException {
String expected = Utils.toStringAndClose(getClass().getResourceAsStream(
"/newvapp-hostingnetworknamedhcpfencemode.xml"));
Multimap<String, String> headers = Multimaps.synchronizedMultimap(HashMultimap
.<String, String> create());
"/newvapp-hostingnetworknamedhcpfencemode.xml"));
Multimap<String, String> headers = Multimaps
.synchronizedMultimap(HashMultimap.<String, String> create());
GeneratedHttpRequest<?> request = createMock(GeneratedHttpRequest.class);
expect(request.getEndpoint()).andReturn(URI.create("http://localhost/key")).anyTimes();
expect(request.getEndpoint()).andReturn(
URI.create("http://localhost/key")).anyTimes();
expect(request.getArgs()).andReturn(new Object[] {}).atLeastOnce();
expect(request.getFirstHeaderOrNull("Content-Type")).andReturn(null).atLeastOnce();
expect(request.getFirstHeaderOrNull("Content-Type")).andReturn(null)
.atLeastOnce();
expect(request.getHeaders()).andReturn(headers).atLeastOnce();
request.setPayload(expected);
replay(request);
BindInstantiateVAppTemplateParamsToXmlPayload binder = injector
.getInstance(BindInstantiateVAppTemplateParamsToXmlPayload.class);
.getInstance(BindInstantiateVAppTemplateParamsToXmlPayload.class);
Map<String, String> map = Maps.newHashMap();
map.put("name", "my-vapp");
map.put("template", "https://vcloud.safesecureweb.com/api/v0.8/vAppTemplate/3");
map.put("template",
"https://vcloud.safesecureweb.com/api/v0.8/vAppTemplate/3");
map.put("network", "https://vcloud.safesecureweb.com/network/1990");
map.put("networkName", "aloha");
map.put("fenceMode", FenceMode.BRIDGED.toString());
map.put("dhcpEnabled", "true");
map.put("fenceMode", FenceMode.BRIDGED);
binder.bindToRequest(request, map);
verify(request);

View File

@ -25,6 +25,7 @@ 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;
@ -42,17 +43,25 @@ 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));
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);
@ -67,9 +76,12 @@ public class EncodeTemplateIdIntoNameRunNodesAndAddToSetStrategyTest {
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

@ -18,118 +18,100 @@
*/
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.replay;
import static org.easymock.classextension.EasyMock.verify;
import java.io.IOException;
import java.net.URI;
import java.net.UnknownHostException;
import java.util.Map;
import java.util.Set;
import java.util.SortedSet;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeoutException;
import javax.inject.Provider;
import org.jclouds.compute.domain.Image;
import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.domain.NodeState;
import org.jclouds.domain.Location;
import org.jclouds.domain.LocationScope;
import org.jclouds.domain.internal.LocationImpl;
import org.jclouds.vcloud.VCloudClient;
import org.jclouds.vcloud.compute.VCloudComputeClient;
import org.jclouds.vcloud.compute.functions.FindLocationForResourceInVDC;
import org.jclouds.vcloud.compute.functions.GetExtra;
import org.jclouds.vcloud.domain.NamedResource;
import org.jclouds.vcloud.domain.ResourceAllocation;
import org.jclouds.vcloud.domain.ResourceType;
import org.jclouds.vcloud.domain.VApp;
import org.jclouds.vcloud.domain.VAppStatus;
import org.jclouds.vcloud.domain.VirtualSystem;
import org.jclouds.vcloud.domain.internal.NamedResourceImpl;
import org.jclouds.vcloud.domain.internal.VAppImpl;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableListMultimap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableSortedSet;
import com.google.common.collect.ListMultimap;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import com.google.inject.util.Providers;
/**
* @author Adrian Cole
*/
@Test(groups = "unit", testName = "vcloud.VCloudListNodesStrategyTest")
public class VCloudListNodesStrategyTest {
@SuppressWarnings("unused")
private VApp newVApp() throws UnknownHostException {
ListMultimap<String, String> networkToAddresses = ImmutableListMultimap.<String, String> of(
"Network 1", "127.0.0.1");
ListMultimap<String, String> networkToAddresses = ImmutableListMultimap
.<String, String> of("Network 1", "127.0.0.1");
VirtualSystem system = new VirtualSystem(0, "Virtual Hardware Family", "SimpleVM", "vmx-07");
VirtualSystem system = new VirtualSystem(0, "Virtual Hardware Family",
"SimpleVM", "vmx-07");
SortedSet<ResourceAllocation> resourceAllocations = ImmutableSortedSet
.<ResourceAllocation> naturalOrder().add(
new ResourceAllocation(1, "1 virtual CPU(s)", "Number of Virtual CPUs",
ResourceType.PROCESSOR, null, null, null, null, null, null, 1,
"hertz * 10^6"),
new ResourceAllocation(2, "512MB of memory", "Memory Size",
ResourceType.MEMORY, null, null, null, null, null, null, 512,
"byte * 2^20")).add(
.<ResourceAllocation> naturalOrder().add(
new ResourceAllocation(1, "1 virtual CPU(s)",
"Number of Virtual CPUs", ResourceType.PROCESSOR, null,
null, null, null, null, null, 1, "hertz * 10^6"),
new ResourceAllocation(2, "512MB of memory", "Memory Size",
ResourceType.MEMORY, null, null, null, null, null,
null, 512, "byte * 2^20")).add(
new ResourceAllocation(3, "SCSI Controller 0", "SCSI Controller",
ResourceType.SCSI_CONTROLLER, "lsilogic", null, 0, null, null,
null, 1, null)).add(
new ResourceAllocation(3, "SCSI Controller 0",
"SCSI Controller", ResourceType.SCSI_CONTROLLER,
"lsilogic", null, 0, null, null, null, 1, null)).add(
new ResourceAllocation(9, "Hard Disk 1", null, ResourceType.DISK_DRIVE,
null, "20971520", null, 0, 3, null, 20971520, "byte * 2^20"))
.build();
new ResourceAllocation(9, "Hard Disk 1", null,
ResourceType.DISK_DRIVE, null, "20971520", null, 0, 3,
null, 20971520, "byte * 2^20")).build();
return new VAppImpl("10", "10", URI
.create("https://vcloud.safesecureweb.com/api/v0.8/vapp/10"), VAppStatus.OFF,
new Long(20971520), null, networkToAddresses, null, system, resourceAllocations);
.create("https://vcloud.safesecureweb.com/api/v0.8/vapp/10"),
VAppStatus.OFF, new Long(20971520), null, networkToAddresses, null,
system, resourceAllocations);
}
// consistency delay specifically in terremark beta where a vapp is present for listing, but not
// TODO rewrite this test
//
// consistency delay specifically in terremark beta where a vapp is present
// for listing, but not
// yet available for get vapp command.
@Test
public void testRetryOnVAppNotFoundForGetVAppEvenWhenPresentInAvailableResources()
throws ExecutionException, InterruptedException, TimeoutException, IOException {
VCloudClient client = createMock(VCloudClient.class);
GetExtra getExtra = new GetExtra();
VCloudComputeClient computeClient = createMock(VCloudComputeClient.class);
Map<VAppStatus, NodeState> vAppStatusToNodeState = Maps.newHashMap();
VApp vApp = newVApp();
expect(client.getVApp("10")).andThrow(new NullPointerException());
expect(client.getVApp("10")).andThrow(new NullPointerException());
expect(client.getVApp("10")).andReturn(vApp);
replay(client);
replay(computeClient);
Location vdcL = new LocationImpl(LocationScope.ZONE, "1", "1", null);
Provider<Set<? extends Location>> locations = Providers
.<Set<? extends Location>> of(ImmutableSet.of(vdcL));
Provider<Set<? extends Image>> images = Providers.<Set<? extends Image>> of(ImmutableSet
.<Image> of());
FindLocationForResourceInVDC findLocationForResourceInVDC = new FindLocationForResourceInVDC(
locations, null);
VCloudListNodesStrategy strategy = new VCloudListNodesStrategy(client, computeClient,
vAppStatusToNodeState, getExtra, findLocationForResourceInVDC, images);
Set<NodeMetadata> nodes = Sets.newHashSet();
NamedResource vdc = new NamedResourceImpl("1", null, null, null);
NamedResource resource = new NamedResourceImpl("10", null, null, null);
strategy.addVAppToSetRetryingIfNotYetPresent(nodes, vdc, resource);
verify(client);
verify(computeClient);
}
// @Test
// public void
// testRetryOnVAppNotFoundForGetVAppEvenWhenPresentInAvailableResources()
// throws ExecutionException, InterruptedException, TimeoutException,
// IOException {
// VCloudClient client = createMock(VCloudClient.class);
// GetExtra getExtra = new GetExtra();
//
// VCloudComputeClient computeClient = createMock(VCloudComputeClient.class);
// Map<VAppStatus, NodeState> vAppStatusToNodeState = Maps.newHashMap();
// VApp vApp = newVApp();
// expect(client.getVApp("10")).andThrow(new NullPointerException());
// expect(client.getVApp("10")).andThrow(new NullPointerException());
// expect(client.getVApp("10")).andReturn(vApp);
//
// replay(client);
// replay(computeClient);
//
// Location vdcL = new LocationImpl(LocationScope.ZONE, "1", "1", null);
// Provider<Set<? extends Location>> locations = Providers
// .<Set<? extends Location>> of(ImmutableSet.of(vdcL));
// Provider<Set<? extends Image>> images = Providers
// .<Set<? extends Image>> of(ImmutableSet.<Image> of());
// FindLocationForResourceInVDC findLocationForResourceInVDC = new
// FindLocationForResourceInVDC(
// locations, null);
// VCloudListNodesStrategy strategy = new VCloudListNodesStrategy(client,
// computeClient, vAppStatusToNodeState, getExtra,
// findLocationForResourceInVDC, images);
//
// Set<NodeMetadata> nodes = Sets.newHashSet();
// NamedResource vdc = new NamedResourceImpl("1", null, null, null);
// NamedResource resource = new NamedResourceImpl("10", null, null, null);
//
// strategy.addVAppToSetRetryingIfNotYetPresent(nodes, vdc, resource);
//
// verify(client);
// verify(computeClient);
// }
}

View File

@ -18,7 +18,6 @@
*/
package org.jclouds.vcloud.options;
import static org.jclouds.vcloud.options.InstantiateVAppTemplateOptions.Builder.dhcpEnabled;
import static org.jclouds.vcloud.options.InstantiateVAppTemplateOptions.Builder.disk;
import static org.jclouds.vcloud.options.InstantiateVAppTemplateOptions.Builder.fenceMode;
import static org.jclouds.vcloud.options.InstantiateVAppTemplateOptions.Builder.inNetwork;
@ -55,7 +54,8 @@ public class InstantiateVAppTemplateOptionsTest {
@Test
public void testInNetworkStatic() {
InstantiateVAppTemplateOptions options = inNetwork(URI.create("http://localhost"));
InstantiateVAppTemplateOptions options = inNetwork(URI
.create("http://localhost"));
assertEquals(options.getNetwork(), "http://localhost");
}
@ -119,27 +119,14 @@ public class InstantiateVAppTemplateOptionsTest {
@Test
public void testFenceMode() {
InstantiateVAppTemplateOptions options = new InstantiateVAppTemplateOptions();
options.fenceMode(FenceMode.BLOCK_IN_OUT);
assertEquals(options.getFenceMode(), "blockInOut");
options.fenceMode(FenceMode.BRIDGED);
assertEquals(options.getFenceMode(), "bridged");
}
@Test
public void testFenceModeStatic() {
InstantiateVAppTemplateOptions options = fenceMode(FenceMode.BLOCK_IN_OUT);
assertEquals(options.getFenceMode(), "blockInOut");
}
@Test
public void testDhcpEnabled() {
InstantiateVAppTemplateOptions options = new InstantiateVAppTemplateOptions();
options.dhcpEnabled(true);
assertEquals(options.getDhcpEnabled(), "true");
}
@Test
public void testDhcpEnabledStatic() {
InstantiateVAppTemplateOptions options = dhcpEnabled(true);
assertEquals(options.getDhcpEnabled(), "true");
InstantiateVAppTemplateOptions options = fenceMode(FenceMode.BRIDGED);
assertEquals(options.getFenceMode(), "bridged");
}
}

View File

@ -54,25 +54,33 @@ public class NetworkHandlerTest {
InputStream is = getClass().getResourceAsStream("/network-terremark.xml");
injector = Guice.createInjector(new ParserModule());
factory = injector.getInstance(ParseSax.Factory.class);
Network result = factory.create(injector.getInstance(NetworkHandler.class)).parse(is);
assertEquals(result, new NetworkImpl("1708", "10.114.34.128/26", URI
.create("https://services.vcloudexpress.terremark.com/api/v0.8/network/1708"), null,
ImmutableSet.<String> of(), "10.114.34.129", "255.255.255.192", ImmutableSet
.<FenceMode> of(FenceMode.ISOLATED), null, ImmutableSet.<NatRule> of(),
ImmutableSet.<FirewallRule> of()));
Network result = factory.create(
injector.getInstance(NetworkHandler.class)).parse(is);
assertEquals(
result,
new NetworkImpl(
"1708",
"10.114.34.128/26",
URI
.create("https://services.vcloudexpress.terremark.com/api/v0.8/network/1708"),
null, ImmutableSet.<String> of(), "10.114.34.129",
"255.255.255.192", ImmutableSet
.<String> of(FenceMode.ISOLATED), null, ImmutableSet
.<NatRule> of(), ImmutableSet.<FirewallRule> of()));
}
public void testHosting() throws UnknownHostException {
InputStream is = getClass().getResourceAsStream("/network-hosting.xml");
injector = Guice.createInjector(new ParserModule());
factory = injector.getInstance(ParseSax.Factory.class);
Network result = (Network) factory.create(injector.getInstance(NetworkHandler.class)).parse(
is);
Network result = (Network) factory.create(
injector.getInstance(NetworkHandler.class)).parse(is);
assertEquals(result, new NetworkImpl("1183", "188849 trust", URI
.create("https://vcloud.safesecureweb.com/api/v0.8/network/1183"), "188849 trust",
ImmutableSet.<String> of("76.12.32.110", "208.112.89.187"), "204.12.53.89",
"255.255.255.248", ImmutableSet.<FenceMode> of(), null, ImmutableSet.<NatRule> of(),
ImmutableSet.<FirewallRule> of()));
.create("https://vcloud.safesecureweb.com/api/v0.8/network/1183"),
"188849 trust", ImmutableSet.<String> of("76.12.32.110",
"208.112.89.187"), "204.12.53.89", "255.255.255.248",
ImmutableSet.<String> of(), null, ImmutableSet.<NatRule> of(),
ImmutableSet.<FirewallRule> of()));
}
}

View File

@ -1 +1 @@
<InstantiateVAppTemplateParams xmlns="http://www.vmware.com/vcloud/v0.8" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="my-vapp" xsi:schemaLocation="http://www.vmware.com/vcloud/v0.8 http://vcloud.safesecureweb.com/ns/vcloud.xsd"><VAppTemplate href="https://vcloud.safesecureweb.com/api/v0.8/vAppTemplate/3"/><InstantiationParams><NetworkConfigSection><NetworkConfig name="my-vapp"><Features><FenceMode>allowInOut</FenceMode><Dhcp>false</Dhcp></Features><NetworkAssociation href="https://vcloud.safesecureweb.com/network/1990"/></NetworkConfig></NetworkConfigSection></InstantiationParams></InstantiateVAppTemplateParams>
<InstantiateVAppTemplateParams xmlns="http://www.vmware.com/vcloud/v0.8" xmlns:ovf="http://schemas.dmtf.org/ovf/envelope/1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="my-vapp" xsi:schemaLocation="http://www.vmware.com/vcloud/v0.8 http://vcloud.safesecureweb.com/ns/vcloud.xsd"><VAppTemplate href="https://vcloud.safesecureweb.com/api/v0.8/vAppTemplate/3"/><InstantiationParams><NetworkConfigSection><NetworkConfig name="my-vapp"><Features><FenceMode>allowInOut</FenceMode></Features><NetworkAssociation href="https://vcloud.safesecureweb.com/network/1990"/></NetworkConfig></NetworkConfigSection></InstantiationParams></InstantiateVAppTemplateParams>

View File

@ -1 +1 @@
<InstantiateVAppTemplateParams xmlns="http://www.vmware.com/vcloud/v0.8" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="my-vapp" xsi:schemaLocation="http://www.vmware.com/vcloud/v0.8 http://vcloud.safesecureweb.com/ns/vcloud.xsd"><VAppTemplate href="https://vcloud.safesecureweb.com/api/v0.8/vAppTemplate/3"/><InstantiationParams><VirtualHardwareSection xmlns:q1="http://www.vmware.com/vcloud/v0.8"><Item xmlns="http://schemas.dmtf.org/ovf/envelope/1"><InstanceID xmlns="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData">1</InstanceID><ResourceType xmlns="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData">3</ResourceType><VirtualQuantity xmlns="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData">1</VirtualQuantity></Item><Item xmlns="http://schemas.dmtf.org/ovf/envelope/1"><InstanceID xmlns="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData">2</InstanceID><ResourceType xmlns="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData">4</ResourceType><VirtualQuantity xmlns="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData">512</VirtualQuantity></Item><Item xmlns="http://schemas.dmtf.org/ovf/envelope/1"><InstanceID xmlns="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData">9</InstanceID><ResourceType xmlns="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData">17</ResourceType><VirtualQuantity xmlns="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData">1024</VirtualQuantity></Item></VirtualHardwareSection><NetworkConfigSection><NetworkConfig name="my-vapp"><Features><FenceMode>allowInOut</FenceMode><Dhcp>false</Dhcp></Features><NetworkAssociation href="https://vcloud.safesecureweb.com/network/1990"/></NetworkConfig></NetworkConfigSection></InstantiationParams></InstantiateVAppTemplateParams>
<InstantiateVAppTemplateParams xmlns="http://www.vmware.com/vcloud/v0.8" xmlns:ovf="http://schemas.dmtf.org/ovf/envelope/1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="my-vapp" xsi:schemaLocation="http://www.vmware.com/vcloud/v0.8 http://vcloud.safesecureweb.com/ns/vcloud.xsd"><VAppTemplate href="https://vcloud.safesecureweb.com/api/v0.8/vAppTemplate/3"/><InstantiationParams><VirtualHardwareSection xmlns:q1="http://www.vmware.com/vcloud/v0.8"><Item xmlns="http://schemas.dmtf.org/ovf/envelope/1"><InstanceID xmlns="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData">1</InstanceID><ResourceType xmlns="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData">3</ResourceType><VirtualQuantity xmlns="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData">1</VirtualQuantity></Item><Item xmlns="http://schemas.dmtf.org/ovf/envelope/1"><InstanceID xmlns="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData">2</InstanceID><ResourceType xmlns="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData">4</ResourceType><VirtualQuantity xmlns="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData">512</VirtualQuantity></Item><Item xmlns="http://schemas.dmtf.org/ovf/envelope/1"><InstanceID xmlns="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData">9</InstanceID><ResourceType xmlns="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData">17</ResourceType><VirtualQuantity xmlns="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData">1024</VirtualQuantity></Item></VirtualHardwareSection><NetworkConfigSection><NetworkConfig name="my-vapp"><Features><FenceMode>allowInOut</FenceMode></Features><NetworkAssociation href="https://vcloud.safesecureweb.com/network/1990"/></NetworkConfig></NetworkConfigSection></InstantiationParams></InstantiateVAppTemplateParams>

View File

@ -1 +1 @@
<InstantiateVAppTemplateParams xmlns="http://www.vmware.com/vcloud/v0.8" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="my-vapp" xsi:schemaLocation="http://www.vmware.com/vcloud/v0.8 http://vcloud.safesecureweb.com/ns/vcloud.xsd"><VAppTemplate href="https://vcloud.safesecureweb.com/api/v0.8/vAppTemplate/3"/><InstantiationParams><NetworkConfigSection><NetworkConfig name="aloha"><Features><FenceMode>bridged</FenceMode><Dhcp>true</Dhcp></Features><NetworkAssociation href="https://vcloud.safesecureweb.com/network/1990"/></NetworkConfig></NetworkConfigSection></InstantiationParams></InstantiateVAppTemplateParams>
<InstantiateVAppTemplateParams xmlns="http://www.vmware.com/vcloud/v0.8" xmlns:ovf="http://schemas.dmtf.org/ovf/envelope/1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="my-vapp" xsi:schemaLocation="http://www.vmware.com/vcloud/v0.8 http://vcloud.safesecureweb.com/ns/vcloud.xsd"><VAppTemplate href="https://vcloud.safesecureweb.com/api/v0.8/vAppTemplate/3"/><InstantiationParams><NetworkConfigSection><NetworkConfig name="my-vapp"><Features><FenceMode>allowInOut</FenceMode></Features><NetworkAssociation href="https://vcloud.safesecureweb.com/network/1990"/></NetworkConfig></NetworkConfigSection></InstantiationParams></InstantiateVAppTemplateParams>