diff --git a/apis/vcloud/src/main/java/org/jclouds/vcloud/VCloudAsyncClient.java b/apis/vcloud/src/main/java/org/jclouds/vcloud/VCloudAsyncClient.java index bc2e1e802f..c1954ec3cb 100644 --- a/apis/vcloud/src/main/java/org/jclouds/vcloud/VCloudAsyncClient.java +++ b/apis/vcloud/src/main/java/org/jclouds/vcloud/VCloudAsyncClient.java @@ -21,6 +21,7 @@ package org.jclouds.vcloud; import static org.jclouds.vcloud.VCloudMediaType.DEPLOYVAPPPARAMS_XML; import static org.jclouds.vcloud.VCloudMediaType.GUESTCUSTOMIZATIONSECTION_XML; import static org.jclouds.vcloud.VCloudMediaType.NETWORKCONNECTIONSECTION_XML; +import static org.jclouds.vcloud.VCloudMediaType.RASDITEM_XML; import static org.jclouds.vcloud.VCloudMediaType.TASK_XML; import static org.jclouds.vcloud.VCloudMediaType.UNDEPLOYVAPPPARAMS_XML; import static org.jclouds.vcloud.VCloudMediaType.VAPPTEMPLATE_XML; @@ -56,11 +57,13 @@ import org.jclouds.rest.annotations.RequestFilters; import org.jclouds.rest.annotations.XMLResponseParser; import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404; +import org.jclouds.vcloud.binders.BindCPUCountToXmlPayload; import org.jclouds.vcloud.binders.BindCaptureVAppParamsToXmlPayload; import org.jclouds.vcloud.binders.BindCloneVAppParamsToXmlPayload; import org.jclouds.vcloud.binders.BindDeployVAppParamsToXmlPayload; import org.jclouds.vcloud.binders.BindGuestCustomizationSectionToXmlPayload; import org.jclouds.vcloud.binders.BindInstantiateVAppTemplateParamsToXmlPayload; +import org.jclouds.vcloud.binders.BindMemoryToXmlPayload; import org.jclouds.vcloud.binders.BindNetworkConnectionSectionToXmlPayload; import org.jclouds.vcloud.binders.BindUndeployVAppParamsToXmlPayload; import org.jclouds.vcloud.domain.GuestCustomizationSection; @@ -89,7 +92,9 @@ import com.google.common.util.concurrent.ListenableFuture; * Provides access to VCloud resources via their REST API. *

* - * @see + * @see * @author Adrian Cole */ @RequestFilters(SetVCloudTokenCookie.class) @@ -216,6 +221,28 @@ public interface VCloudAsyncClient extends CommonVCloudAsyncClient { @ExceptionParser(ReturnNullOnNotFoundOr404.class) ListenableFuture getVm(@EndpointParam URI vm); + /** + * @see VCloudClient#updateCPUCountOfVm + */ + @PUT + @Consumes(TASK_XML) + @Produces(RASDITEM_XML) + @Path("/virtualHardwareSection/cpu") + @XMLResponseParser(TaskHandler.class) + ListenableFuture updateCPUCountOfVm(@EndpointParam URI vm, + @BinderParam(BindCPUCountToXmlPayload.class) int cpuCount); + + /** + * @see VCloudClient#updateMemoryMBOfVm + */ + @PUT + @Consumes(TASK_XML) + @Produces(RASDITEM_XML) + @Path("/virtualHardwareSection/memory") + @XMLResponseParser(TaskHandler.class) + ListenableFuture updateMemoryMBOfVm(@EndpointParam URI vm, + @BinderParam(BindMemoryToXmlPayload.class) int memoryInMB); + /** * @see VCloudClient#updateGuestCustomizationOfVm */ diff --git a/apis/vcloud/src/main/java/org/jclouds/vcloud/VCloudClient.java b/apis/vcloud/src/main/java/org/jclouds/vcloud/VCloudClient.java index e00bc0e3f2..bc5041ed7d 100644 --- a/apis/vcloud/src/main/java/org/jclouds/vcloud/VCloudClient.java +++ b/apis/vcloud/src/main/java/org/jclouds/vcloud/VCloudClient.java @@ -43,7 +43,9 @@ import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions; * Provides access to VCloud resources via their REST API. *

* - * @see + * @see * @author Adrian Cole */ @Timeout(duration = 300, timeUnit = TimeUnit.SECONDS) @@ -58,8 +60,8 @@ public interface VCloudClient extends CommonVCloudClient { InputStream getThumbnailOfVm(URI vm); /** - * The response to a login request includes a list of the organizations to which the - * authenticated user has access. + * The response to a login request includes a list of the organizations to + * which the authenticated user has access. * * @return organizations indexed by name */ @@ -70,8 +72,8 @@ public interface VCloudClient extends CommonVCloudClient { Task cloneVAppInVDC(URI vDC, URI toClone, String newName, CloneVAppOptions... options); /** - * The captureVApp request creates a vApp template from an instantiated vApp.

Note

- * Before it can be captured, a vApp must be undeployed + * The captureVApp request creates a vApp template from an instantiated vApp. + *

Note

Before it can be captured, a vApp must be undeployed * * @param vDC * @param toClone @@ -108,8 +110,9 @@ public interface VCloudClient extends CommonVCloudClient { Task updateNetworkConnectionOfVm(URI vm, NetworkConnectionSection guestCustomizationSection); /** - * returns the vapp template corresponding to a catalog item in the catalog associated with the - * specified name. Note that the org and catalog parameters can be null to choose default. + * returns the vapp template corresponding to a catalog item in the catalog + * associated with the specified name. Note that the org and catalog + * parameters can be null to choose default. * * @param orgName * organization name, or null for the default @@ -119,7 +122,8 @@ public interface VCloudClient extends CommonVCloudClient { * item you wish to lookup * * @throws NoSuchElementException - * if you specified an org, catalog, or catalog item name that isn't present + * if you specified an org, catalog, or catalog item name that + * isn't present */ VAppTemplate findVAppTemplateInOrgCatalogNamed(@Nullable String orgName, @Nullable String catalogName, String itemName); @@ -131,97 +135,129 @@ public interface VCloudClient extends CommonVCloudClient { Vm getVm(URI vm); /** - * To deploy a vApp, the client makes a request to its action/deploy URL. Deploying a vApp - * automatically deploys all of the virtual machines it contains. To deploy a virtual machine, - * the client makes a request to its action/deploy URL. + * update the cpuCount of an existing VM + * + * @param vm + * to update + * @param cpuCount + * count to change the primary cpu to + */ + Task updateCPUCountOfVm(URI vm, int cpuCount); + + /** + * update the memoryInMB of an existing VM + * + * @param vm + * to update + * @param memoryInMB + * memory in MB to assign to the VM + */ + Task updateMemoryMBOfVm(URI vm, int memoryInMB); + + /** + * To deploy a vApp, the client makes a request to its action/deploy URL. + * Deploying a vApp automatically deploys all of the virtual machines it + * contains. To deploy a virtual machine, the client makes a request to its + * action/deploy URL. *

- * Deploying a Vm implicitly deploys the parent vApp if that vApp is not already deployed. + * Deploying a Vm implicitly deploys the parent vApp if that vApp is not + * already deployed. */ Task deployVAppOrVm(URI vAppOrVmId); /** - * like {@link #deployVAppOrVm(URI)}, except deploy transistions to power on state + * like {@link #deployVAppOrVm(URI)}, except deploy transistions to power on + * state * */ Task deployAndPowerOnVAppOrVm(URI vAppOrVmId); /** - * Undeploying a vApp powers off or suspends any running virtual machines it contains, then frees - * the resources reserved for the vApp and sets the vApp’s deploy attribute to a value of false - * to indicate that it is not deployed. + * Undeploying a vApp powers off or suspends any running virtual machines it + * contains, then frees the resources reserved for the vApp and sets the + * vApp’s deploy attribute to a value of false to indicate that it is not + * deployed. *

- * Undeploying a virtual machine powers off or suspends the virtual machine, then frees the - * resources reserved for it and sets the its deploy attribute to a value of false to indicate - * that it is not deployed. This operation has no effect on the containing vApp. + * Undeploying a virtual machine powers off or suspends the virtual machine, + * then frees the resources reserved for it and sets the its deploy attribute + * to a value of false to indicate that it is not deployed. This operation + * has no effect on the containing vApp. *

NOTE

- * Using this method will simply power off the vms. In order to save their state, use - * {@link #undeployAndSaveStateOfVAppOrVm} + * Using this method will simply power off the vms. In order to save their + * state, use {@link #undeployAndSaveStateOfVAppOrVm} * */ Task undeployVAppOrVm(URI vAppOrVmId); /** - * like {@link #undeployVAppOrVm(URI)}, where the undeployed virtual machines are suspended and - * their suspend state saved + * like {@link #undeployVAppOrVm(URI)}, where the undeployed virtual machines + * are suspended and their suspend state saved * */ Task undeployAndSaveStateOfVAppOrVm(URI vAppOrVmId); /** - * A powerOn request to a vApp URL powers on all of the virtual machines in the vApp, as - * specified in the vApp’s StartupSection field. + * A powerOn request to a vApp URL powers on all of the virtual machines in + * the vApp, as specified in the vApp’s StartupSection field. *

- * A powerOn request to a virtual machine URL powers on the specified virtual machine and forces - * deployment of the parent vApp. + * A powerOn request to a virtual machine URL powers on the specified virtual + * machine and forces deployment of the parent vApp. *

- *

NOTE

A powerOn request to a vApp or virtual machine that is undeployed forces - * deployment. + *

NOTE

A powerOn request to a vApp or virtual machine that is + * undeployed forces deployment. */ Task powerOnVAppOrVm(URI vAppOrVmId); /** - * A powerOff request to a vApp URL powers off all of the virtual machines in the vApp, as - * specified in its StartupSection field. + * A powerOff request to a vApp URL powers off all of the virtual machines in + * the vApp, as specified in its StartupSection field. *

- * A powerOff request to a virtual machine URL powers off the specified virtual machine. + * A powerOff request to a virtual machine URL powers off the specified + * virtual machine. */ Task powerOffVAppOrVm(URI vAppOrVmId); /** - * A shutdown request to a vApp URL shuts down all of the virtual machines in the vApp, as - * specified in its StartupSection field. + * A shutdown request to a vApp URL shuts down all of the virtual machines in + * the vApp, as specified in its StartupSection field. *

- * A shutdown request to a virtual machine URL shuts down the specified virtual machine. + * A shutdown request to a virtual machine URL shuts down the specified + * virtual machine. *

- *

NOTENOTE - * A reset request to a virtual machine URL resets the specified virtual machine. + * A reset request to a virtual machine URL resets the specified virtual + * machine. */ Task resetVAppOrVm(URI vAppOrVmId); /** - * A reboot request to a vApp URL reboots all of the virtual machines in the vApp, as specified - * in its StartupSection field. + * A reboot request to a vApp URL reboots all of the virtual machines in the + * vApp, as specified in its StartupSection field. *

- * A reboot request to a virtual machine URL reboots the specified virtual machine. + * A reboot request to a virtual machine URL reboots the specified virtual + * machine. *

- *

NOTE

Because this request sends a signal to the guest OS, the vCloud API cannot track - * the progress or verify the result of the requested operation. Hence, void is returned + *

NOTE

Because this request sends a signal to the guest OS, the + * vCloud API cannot track the progress or verify the result of the requested + * operation. Hence, void is returned */ void rebootVAppOrVm(URI vAppOrVmId); /** - * A suspend request to a vApp URL suspends all of the virtual machines in the vApp, as specified - * in its StartupSection field. + * A suspend request to a vApp URL suspends all of the virtual machines in + * the vApp, as specified in its StartupSection field. *

- * A suspend request to a virtual machine URL suspends the specified virtual machine. + * A suspend request to a virtual machine URL suspends the specified virtual + * machine. */ Task suspendVAppOrVm(URI vAppOrVmId); diff --git a/apis/vcloud/src/main/java/org/jclouds/vcloud/binders/BindCPUCountToXmlPayload.java b/apis/vcloud/src/main/java/org/jclouds/vcloud/binders/BindCPUCountToXmlPayload.java new file mode 100644 index 0000000000..846c03a59e --- /dev/null +++ b/apis/vcloud/src/main/java/org/jclouds/vcloud/binders/BindCPUCountToXmlPayload.java @@ -0,0 +1,81 @@ +/** + * + * Copyright (C) 2011 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ +package org.jclouds.vcloud.binders; + +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; +import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_XML_NAMESPACE; +import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_XML_SCHEMA; + +import java.util.Properties; + +import javax.inject.Named; +import javax.inject.Singleton; + +import org.jclouds.cim.ResourceAllocationSettingData.ResourceType; +import org.jclouds.http.HttpRequest; +import org.jclouds.rest.binders.BindToStringPayload; + +import com.google.common.base.Throwables; +import com.google.inject.Inject; +import com.jamesmurty.utils.XMLBuilder; + +/** + * + * @author Adrian Cole + * + */ +@Singleton +public class BindCPUCountToXmlPayload extends BindToStringPayload { + protected final String ns; + protected final String schema; + + @Inject + public BindCPUCountToXmlPayload(BindToStringPayload stringBinder, @Named(PROPERTY_VCLOUD_XML_NAMESPACE) String ns, + @Named(PROPERTY_VCLOUD_XML_SCHEMA) String schema) { + this.ns = ns; + this.schema = schema; + } + + private static final String RESOURCE_ALLOCATION_NS = "http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData"; + + @Override + public R bindToRequest(R request, Object payload) { + checkArgument(checkNotNull(payload, "cpuCount") instanceof Integer, "this binder is only valid for Integers!"); + Integer cpuCount = Integer.class.cast(payload); + XMLBuilder cpuItem; + try { + cpuItem = XMLBuilder.create("Item").a("xmlns", ns).a("xmlns:rasd", RESOURCE_ALLOCATION_NS); + cpuItem.e("rasd:AllocationUnits").t("hertz * 10^6"); + cpuItem.e("rasd:Description").t("Number of Virtual CPUs"); + cpuItem.e("rasd:ElementName").t(cpuCount.toString() + " virtual CPU(s)"); + cpuItem.e("rasd:InstanceID").t("4"); + cpuItem.e("rasd:ResourceType").t(ResourceType.PROCESSOR.value()); + cpuItem.e("rasd:VirtualQuantity").t(cpuCount.toString()); + cpuItem.e("rasd:Weight").t("0"); + Properties outputProperties = new Properties(); + outputProperties.put(javax.xml.transform.OutputKeys.OMIT_XML_DECLARATION, "yes"); + request = super.bindToRequest(request, cpuItem.asString(outputProperties)); + } catch (Exception e) { + Throwables.propagate(e); + } + return request; + } + +} diff --git a/apis/vcloud/src/main/java/org/jclouds/vcloud/binders/BindMemoryToXmlPayload.java b/apis/vcloud/src/main/java/org/jclouds/vcloud/binders/BindMemoryToXmlPayload.java new file mode 100644 index 0000000000..6300c2bcd4 --- /dev/null +++ b/apis/vcloud/src/main/java/org/jclouds/vcloud/binders/BindMemoryToXmlPayload.java @@ -0,0 +1,82 @@ +/** + * + * Copyright (C) 2011 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ +package org.jclouds.vcloud.binders; + +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; +import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_XML_NAMESPACE; +import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_XML_SCHEMA; + +import java.util.Properties; + +import javax.inject.Named; +import javax.inject.Singleton; + +import org.jclouds.cim.ResourceAllocationSettingData.ResourceType; +import org.jclouds.http.HttpRequest; +import org.jclouds.rest.binders.BindToStringPayload; + +import com.google.common.base.Throwables; +import com.google.inject.Inject; +import com.jamesmurty.utils.XMLBuilder; + +/** + * + * @author Adrian Cole + * + */ +@Singleton +public class BindMemoryToXmlPayload extends BindToStringPayload { + protected final String ns; + protected final String schema; + + @Inject + public BindMemoryToXmlPayload(BindToStringPayload stringBinder, @Named(PROPERTY_VCLOUD_XML_NAMESPACE) String ns, + @Named(PROPERTY_VCLOUD_XML_SCHEMA) String schema) { + this.ns = ns; + this.schema = schema; + } + + private static final String RESOURCE_ALLOCATION_NS = "http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData"; + + @Override + public R bindToRequest(R request, Object payload) { + checkArgument(checkNotNull(payload, "memoryInMB") instanceof Integer, "this binder is only valid for Integers!"); + Integer memoryInMB = Integer.class.cast(payload); + XMLBuilder cpuItem; + try { + cpuItem = XMLBuilder.create("Item").a("xmlns", ns).a("xmlns:rasd", RESOURCE_ALLOCATION_NS); + cpuItem.e("rasd:AllocationUnits").t("byte * 2^20"); + cpuItem.e("rasd:Description").t("Memory Size"); + cpuItem.e("rasd:ElementName").t(memoryInMB.toString() + " MB of memory"); + cpuItem.e("rasd:InstanceID").t("5"); + cpuItem.e("rasd:Reservation").t("0"); + cpuItem.e("rasd:ResourceType").t(ResourceType.MEMORY.value()); + cpuItem.e("rasd:VirtualQuantity").t(memoryInMB.toString()); + cpuItem.e("rasd:Weight").t("0"); + Properties outputProperties = new Properties(); + outputProperties.put(javax.xml.transform.OutputKeys.OMIT_XML_DECLARATION, "yes"); + request = super.bindToRequest(request, cpuItem.asString(outputProperties)); + } catch (Exception e) { + Throwables.propagate(e); + } + return request; + } + +} diff --git a/apis/vcloud/src/main/java/org/jclouds/vcloud/compute/strategy/InstantiateVAppTemplateWithGroupEncodedIntoNameThenCustomizeDeployAndPowerOn.java b/apis/vcloud/src/main/java/org/jclouds/vcloud/compute/strategy/InstantiateVAppTemplateWithGroupEncodedIntoNameThenCustomizeDeployAndPowerOn.java index 9b68db19c0..fb6c9e00a7 100644 --- a/apis/vcloud/src/main/java/org/jclouds/vcloud/compute/strategy/InstantiateVAppTemplateWithGroupEncodedIntoNameThenCustomizeDeployAndPowerOn.java +++ b/apis/vcloud/src/main/java/org/jclouds/vcloud/compute/strategy/InstantiateVAppTemplateWithGroupEncodedIntoNameThenCustomizeDeployAndPowerOn.java @@ -18,15 +18,13 @@ */ package org.jclouds.vcloud.compute.strategy; -import static org.jclouds.compute.util.ComputeServiceUtils.getCores; -import static org.jclouds.vcloud.options.InstantiateVAppTemplateOptions.Builder.processorCount; - import java.net.URI; import javax.annotation.Resource; import javax.inject.Inject; import javax.inject.Named; import javax.inject.Singleton; +import static org.jclouds.compute.util.ComputeServiceUtils.getCores; import org.jclouds.compute.domain.NodeMetadata; import org.jclouds.compute.domain.Template; @@ -74,21 +72,19 @@ public class InstantiateVAppTemplateWithGroupEncodedIntoNameThenCustomizeDeployA @Override public NodeMetadata createNodeWithGroupEncodedIntoName(String tag, String name, Template template) { - InstantiateVAppTemplateOptions options = processorCount((int) getCores(template.getHardware())).memory( - template.getHardware().getRam()).disk( - (long) ((template.getHardware().getVolumes().get(0).getSize()) * 1024 * 1024l)); + InstantiateVAppTemplateOptions options = new InstantiateVAppTemplateOptions(); - String customizationScript = null; - IpAddressAllocationMode ipAddressAllocationMode = null; - if (template.getOptions() instanceof VCloudTemplateOptions) { - customizationScript = VCloudTemplateOptions.class.cast(template.getOptions()).getCustomizationScript(); - ipAddressAllocationMode = VCloudTemplateOptions.class.cast(template.getOptions()).getIpAddressAllocationMode(); - if (customizationScript != null || ipAddressAllocationMode != null) { - options.customizeOnInstantiate(false); - options.deploy(false); - options.powerOn(false); - } - } + // TODO make disk size specifiable + // disk((long) ((template.getHardware().getVolumes().get(0).getSize()) * + // 1024 * 1024l)); + + String customizationScript = VCloudTemplateOptions.class.cast(template.getOptions()).getCustomizationScript(); + IpAddressAllocationMode ipAddressAllocationMode = VCloudTemplateOptions.class.cast(template.getOptions()) + .getIpAddressAllocationMode(); + + options.customizeOnInstantiate(false); + options.deploy(false); + options.powerOn(false); if (!template.getOptions().shouldBlockUntilRunning()) options.block(false); @@ -99,44 +95,53 @@ public class InstantiateVAppTemplateWithGroupEncodedIntoNameThenCustomizeDeployA logger.debug(">> instantiating vApp vDC(%s) template(%s) name(%s) options(%s) ", VDC, templateId, name, options); VApp vAppResponse = client.instantiateVAppTemplateInVDC(VDC, templateId, name, options); + waitForTask(vAppResponse.getTasks().get(0), vAppResponse); logger.debug("<< instantiated VApp(%s)", vAppResponse.getName()); - Task task = vAppResponse.getTasks().get(0); - - if (customizationScript == null && ipAddressAllocationMode == null) { - return blockOnDeployAndPowerOnIfConfigured(options, vAppResponse, task); - } else { - if (!successTester.apply(task.getHref())) { - throw new RuntimeException( - String.format("failed to %s %s: %s", "instantiate", vAppResponse.getName(), task)); - } - Vm vm = Iterables.get(client.getVApp(vAppResponse.getHref()).getChildren(), 0); - if (customizationScript != null) - updateVmWithCustomizationScript(vm, customizationScript); - if (ipAddressAllocationMode != null) - updateVmWithIpAddressAllocationMode(vm, ipAddressAllocationMode); - task = client.deployAndPowerOnVAppOrVm(vAppResponse.getHref()); - return blockOnDeployAndPowerOnIfConfigured(options, vAppResponse, task); + // note customization is a serial concern at the moment + Vm vm = Iterables.get(client.getVApp(vAppResponse.getHref()).getChildren(), 0); + if (customizationScript != null) { + logger.trace(">> updating customization vm(%s) ", vm.getName()); + waitForTask(updateVmWithCustomizationScript(vm, customizationScript), vAppResponse); + logger.trace("<< updated customization vm(%s) ", vm.getName()); } + if (ipAddressAllocationMode != null) { + logger.trace(">> updating ipAddressAllocationMode(%s) vm(%s) ", ipAddressAllocationMode, vm.getName()); + waitForTask(updateVmWithIpAddressAllocationMode(vm, ipAddressAllocationMode), vAppResponse); + logger.trace("<< updated ipAddressAllocationMode vm(%s) ", vm.getName()); + } + int cpuCount = new Double(getCores(template.getHardware())).intValue(); + logger.trace(">> updating cpuCount(%d) vm(%s) ", cpuCount, vm.getName()); + waitForTask(updateCPUCountOfVm(vm, cpuCount), vAppResponse); + logger.trace("<< updated cpuCount vm(%s) ", vm.getName()); + int memoryMB = template.getHardware().getRam(); + logger.trace(">> updating memoryMB(%d) vm(%s) ", memoryMB, vm.getName()); + waitForTask(updateMemoryMBOfVm(vm, memoryMB), vAppResponse); + logger.trace("<< updated memoryMB vm(%s) ", vm.getName()); + logger.trace(">> deploying and powering on vApp(%s) ", vAppResponse.getName()); + return blockOnDeployAndPowerOnIfConfigured(options, vAppResponse, + client.deployAndPowerOnVAppOrVm(vAppResponse.getHref())); } - public void updateVmWithCustomizationScript(Vm vm, String customizationScript) { - Task task; + public void waitForTask(Task task, VApp vAppResponse) { + if (!successTester.apply(task.getHref())) { + throw new RuntimeException(String.format("failed to %s %s: %s", task.getName(), vAppResponse.getName(), task)); + } + } + + public Task updateVmWithCustomizationScript(Vm vm, String customizationScript) { GuestCustomizationSection guestConfiguration = vm.getGuestCustomizationSection(); - // TODO: determine if the server version is beyond 1.0.0, and if so append to, but - // not overwrite the customization script. In version 1.0.0, the api returns a script that + // TODO: determine if the server version is beyond 1.0.0, and if so append + // to, but + // not overwrite the customization script. In version 1.0.0, the api + // returns a script that // loses newlines. guestConfiguration.setCustomizationScript(customizationScript); - task = client.updateGuestCustomizationOfVm(vm.getHref(), guestConfiguration); - if (!successTester.apply(task.getHref())) { - throw new RuntimeException(String.format("failed to %s %s: %s", "updateGuestCustomizationOfVm", vm.getName(), - task)); - } + return client.updateGuestCustomizationOfVm(vm.getHref(), guestConfiguration); } - public void updateVmWithIpAddressAllocationMode(Vm vm, final IpAddressAllocationMode ipAddressAllocationMode) { - Task task; + public Task updateVmWithIpAddressAllocationMode(Vm vm, final IpAddressAllocationMode ipAddressAllocationMode) { NetworkConnectionSection net = vm.getNetworkConnectionSection(); Builder builder = net.toBuilder(); builder.connections(Iterables.transform(net.getConnections(), @@ -148,20 +153,21 @@ public class InstantiateVAppTemplateWithGroupEncodedIntoNameThenCustomizeDeployA } })); - task = client.updateNetworkConnectionOfVm(vm.getHref(), builder.build()); - if (!successTester.apply(task.getHref())) { - throw new RuntimeException(String.format("failed to %s %s: %s", "updateNetworkConnectionOfVm", vm.getName(), - task)); - } + return client.updateNetworkConnectionOfVm(vm.getHref(), builder.build()); + } + + public Task updateCPUCountOfVm(Vm vm, int cpuCount) { + return client.updateCPUCountOfVm(vm.getHref(), cpuCount); + } + + public Task updateMemoryMBOfVm(Vm vm, int memoryInMB) { + return client.updateMemoryMBOfVm(vm.getHref(), memoryInMB); } private NodeMetadata blockOnDeployAndPowerOnIfConfigured(InstantiateVAppTemplateOptions options, VApp vAppResponse, Task task) { if (options.shouldBlock()) { - if (!successTester.apply(task.getHref())) { - throw new RuntimeException(String.format("failed to %s %s: %s", "deploy and power on", - vAppResponse.getName(), task)); - } + waitForTask(task, vAppResponse); logger.debug("<< ready vApp(%s)", vAppResponse.getName()); } return getNode.getNode(vAppResponse.getHref().toASCIIString()); diff --git a/apis/vcloud/src/main/java/org/jclouds/vcloud/options/InstantiateVAppTemplateOptions.java b/apis/vcloud/src/main/java/org/jclouds/vcloud/options/InstantiateVAppTemplateOptions.java new file mode 100644 index 0000000000..a67f227668 --- /dev/null +++ b/apis/vcloud/src/main/java/org/jclouds/vcloud/options/InstantiateVAppTemplateOptions.java @@ -0,0 +1,207 @@ +/** + * + * Copyright (C) 2011 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ +package org.jclouds.vcloud.options; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.util.Set; + +import org.jclouds.vcloud.domain.network.NetworkConfig; + +import com.google.common.collect.Sets; + +/** + * + * @author Adrian Cole + * + */ +public class InstantiateVAppTemplateOptions { + private Set networkConfig = Sets.newLinkedHashSet(); + + private Boolean customizeOnInstantiate; + + private boolean block = true; + private boolean deploy = true; + private boolean powerOn = true; + + public boolean shouldBlock() { + return block; + } + + public boolean shouldDeploy() { + return deploy; + } + + public boolean shouldPowerOn() { + return powerOn; + } + + /** + * deploy the vapp after it is instantiated? + */ + public InstantiateVAppTemplateOptions deploy(boolean deploy) { + this.deploy = deploy; + return this; + } + + /** + * powerOn the vapp after it is instantiated? + */ + public InstantiateVAppTemplateOptions powerOn(boolean powerOn) { + this.powerOn = powerOn; + return this; + } + + /** + * block until instantiate or deployment operations complete? + */ + public InstantiateVAppTemplateOptions block(boolean block) { + this.block = block; + return this; + } + + /** + * If true, then customization is executed for all children that include a + * GuestCustomizationSection. + */ + public InstantiateVAppTemplateOptions customizeOnInstantiate(boolean customizeOnInstantiate) { + this.customizeOnInstantiate = customizeOnInstantiate; + return this; + } + + /** + * {@networkConfig VAppTemplate}s have internal networks that can be + * connected in order to access the internet or other external networks. + * + *

default behaviour if you don't use this option

By default, we + * connect the first internal {@networkConfig + * org.jclouds.vcloud.domain.VAppTemplate#getNetworkSection network in the + * vapp template}to a default chosen from the org or specified via + * {@networkConfig + * org.jclouds.vcloud.reference.VCloudConstants# + * PROPERTY_VCLOUD_DEFAULT_NETWORK} using the {@networkConfig + * org.jclouds.vcloud.domain.FenceMode#BRIDGED} or an + * override set by the property {@networkConfig + * org.jclouds.vcloud.reference.VCloudConstants# + * PROPERTY_VCLOUD_DEFAULT_FENCEMODE}. + */ + public InstantiateVAppTemplateOptions addNetworkConfig(NetworkConfig networkConfig) { + this.networkConfig.add(checkNotNull(networkConfig, "networkConfig")); + return this; + } + + public Set getNetworkConfig() { + return networkConfig; + } + + public Boolean shouldCustomizeOnInstantiate() { + return customizeOnInstantiate; + } + + public static class Builder { + + /** + * @see InstantiateVAppTemplateOptions#block + */ + public static InstantiateVAppTemplateOptions block(boolean block) { + InstantiateVAppTemplateOptions options = new InstantiateVAppTemplateOptions(); + return options.block(block); + } + + /** + * @see InstantiateVAppTemplateOptions#deploy + */ + public static InstantiateVAppTemplateOptions deploy(boolean deploy) { + InstantiateVAppTemplateOptions options = new InstantiateVAppTemplateOptions(); + return options.deploy(deploy); + } + + /** + * @see InstantiateVAppTemplateOptions#powerOn + */ + public static InstantiateVAppTemplateOptions powerOn(boolean powerOn) { + InstantiateVAppTemplateOptions options = new InstantiateVAppTemplateOptions(); + return options.powerOn(powerOn); + } + + /** + * @see InstantiateVAppTemplateOptions#customizeOnInstantiate + */ + public static InstantiateVAppTemplateOptions customizeOnInstantiate(Boolean customizeOnInstantiate) { + InstantiateVAppTemplateOptions options = new InstantiateVAppTemplateOptions(); + return options.customizeOnInstantiate(customizeOnInstantiate); + } + + /** + * @see InstantiateVAppTemplateOptions#addNetworkConfig + */ + public static InstantiateVAppTemplateOptions addNetworkConfig(NetworkConfig networkConfig) { + InstantiateVAppTemplateOptions options = new InstantiateVAppTemplateOptions(); + return options.addNetworkConfig(networkConfig); + } + + } + + @Override + public String toString() { + return "[networkConfig=" + networkConfig + ", customizeOnInstantiate=" + customizeOnInstantiate + ", deploy=" + + (deploy) + ", powerOn=" + (powerOn) + "]"; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + (block ? 1231 : 1237); + result = prime * result + ((customizeOnInstantiate == null) ? 0 : customizeOnInstantiate.hashCode()); + result = prime * result + (deploy ? 1231 : 1237); + result = prime * result + ((networkConfig == null) ? 0 : networkConfig.hashCode()); + result = prime * result + (powerOn ? 1231 : 1237); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + InstantiateVAppTemplateOptions other = (InstantiateVAppTemplateOptions) obj; + if (block != other.block) + return false; + if (customizeOnInstantiate == null) { + if (other.customizeOnInstantiate != null) + return false; + } else if (!customizeOnInstantiate.equals(other.customizeOnInstantiate)) + return false; + if (deploy != other.deploy) + return false; + if (networkConfig == null) { + if (other.networkConfig != null) + return false; + } else if (!networkConfig.equals(other.networkConfig)) + return false; + if (powerOn != other.powerOn) + return false; + return true; + } + +} diff --git a/apis/vcloud/src/test/java/org/jclouds/vcloud/VCloudAsyncClientTest.java b/apis/vcloud/src/test/java/org/jclouds/vcloud/VCloudAsyncClientTest.java index ac66bfcea6..4a9c652a87 100644 --- a/apis/vcloud/src/test/java/org/jclouds/vcloud/VCloudAsyncClientTest.java +++ b/apis/vcloud/src/test/java/org/jclouds/vcloud/VCloudAsyncClientTest.java @@ -22,7 +22,6 @@ import static org.jclouds.Constants.PROPERTY_API_VERSION; import static org.jclouds.Constants.PROPERTY_IDENTITY; import static org.jclouds.Constants.PROPERTY_SESSION_INTERVAL; import static org.jclouds.vcloud.options.InstantiateVAppTemplateOptions.Builder.addNetworkConfig; -import static org.jclouds.vcloud.options.InstantiateVAppTemplateOptions.Builder.processorCount; import static org.testng.Assert.assertEquals; import java.io.IOException; @@ -92,20 +91,20 @@ import com.google.inject.Injector; import com.google.inject.Module; import com.google.inject.TypeLiteral; - /** * Tests behavior of {@code VCloudAsyncClient} * * @author Adrian Cole */ -// NOTE:without testName, this will not call @Before* and fail w/NPE during surefire +// NOTE:without testName, this will not call @Before* and fail w/NPE during +// surefire @Test(groups = "unit", testName = "VCloudAsyncClientTest") public class VCloudAsyncClientTest extends RestClientTest { public void testGetThumbnailOfVm() throws SecurityException, NoSuchMethodException, IOException { Method method = VCloudAsyncClient.class.getMethod("getThumbnailOfVm", URI.class); HttpRequest request = processor - .createRequest(method, URI.create("http://vcloud.example.com/api/v1.0/vApp/vm-12")); + .createRequest(method, URI.create("http://vcloud.example.com/api/v1.0/vApp/vm-12")); assertRequestLineEquals(request, "GET http://vcloud.example.com/api/v1.0/vApp/vm-12/screen HTTP/1.1"); assertNonPayloadHeadersEqual(request, "Accept: image/png\n"); @@ -120,18 +119,55 @@ public class VCloudAsyncClientTest extends RestClientTest { public void testUpdateGuestConfiguration() throws SecurityException, NoSuchMethodException, IOException { Method method = VCloudAsyncClient.class.getMethod("updateGuestCustomizationOfVm", URI.class, - GuestCustomizationSection.class); - GuestCustomizationSection guest = new GuestCustomizationSection(URI - .create("http://vcloud.example.com/api/v1.0/vApp/vm-12/guestCustomizationSection")); + GuestCustomizationSection.class); + GuestCustomizationSection guest = new GuestCustomizationSection( + URI.create("http://vcloud.example.com/api/v1.0/vApp/vm-12/guestCustomizationSection")); guest.setCustomizationScript("cat > /tmp/foo.txt< { } public void testInstantiateVAppTemplateInVDCURIOptions() throws SecurityException, NoSuchMethodException, - IOException { + IOException { Method method = VCloudAsyncClient.class.getMethod("instantiateVAppTemplateInVDC", URI.class, URI.class, - String.class, InstantiateVAppTemplateOptions[].class); - HttpRequest request = processor.createRequest(method, URI - .create("https://vcenterprise.bluelock.com/api/v1.0/vdc/1"), URI - .create("https://vcenterprise.bluelock.com/api/v1.0/vAppTemplate/3"), "my-vapp", - addNetworkConfig(new NetworkConfig("aloha", URI - .create("https://vcenterprise.bluelock.com/api/v1.0/network/1991"), FenceMode.NAT_ROUTED))); + String.class, InstantiateVAppTemplateOptions[].class); + HttpRequest request = processor.createRequest( + method, + URI.create("https://vcenterprise.bluelock.com/api/v1.0/vdc/1"), + URI.create("https://vcenterprise.bluelock.com/api/v1.0/vAppTemplate/3"), + "my-vapp", + addNetworkConfig(new NetworkConfig("aloha", URI + .create("https://vcenterprise.bluelock.com/api/v1.0/network/1991"), FenceMode.NAT_ROUTED))); assertRequestLineEquals(request, - "POST https://vcenterprise.bluelock.com/api/v1.0/vdc/1/action/instantiateVAppTemplate HTTP/1.1"); + "POST https://vcenterprise.bluelock.com/api/v1.0/vdc/1/action/instantiateVAppTemplate HTTP/1.1"); assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.vApp+xml\n"); - assertPayloadEquals(request, Strings2.toStringAndClose(getClass().getResourceAsStream( - "/instantiationparams-network.xml")), "application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml", - false); + assertPayloadEquals(request, + Strings2.toStringAndClose(getClass().getResourceAsStream("/instantiationparams-network.xml")), + "application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml", false); assertResponseParserClassEquals(method, request, ParseSax.class); assertSaxResponseParserClassEquals(method, VAppHandler.class); @@ -166,28 +204,30 @@ public class VCloudAsyncClientTest extends RestClientTest { @Test(expectedExceptions = IllegalArgumentException.class) public void testInstantiateVAppTemplateInOrgOptionsIllegalName() throws SecurityException, NoSuchMethodException, - IOException { + IOException { Method method = VCloudAsyncClient.class.getMethod("instantiateVAppTemplateInVDC", URI.class, URI.class, - String.class, InstantiateVAppTemplateOptions[].class); - processor.createRequest(method, URI.create("https://vcenterprise.bluelock.com/api/v1.0/vdc/1"), URI - .create("https://vcenterprise.bluelock.com/api/v1.0/vdc/1"), "CentOS 01", processorCount(1).memory(512) - .disk(1024).addNetworkConfig( - new NetworkConfig(null, URI.create("https://vcenterprise.bluelock.com/api/v1.0/network/1991"), - null))); + String.class, InstantiateVAppTemplateOptions[].class); + processor.createRequest( + method, + URI.create("https://vcenterprise.bluelock.com/api/v1.0/vdc/1"), + URI.create("https://vcenterprise.bluelock.com/api/v1.0/vdc/1"), + "CentOS 01", + addNetworkConfig(new NetworkConfig(null, URI + .create("https://vcenterprise.bluelock.com/api/v1.0/network/1991"), null))); } public void testCloneVAppInVDC() throws SecurityException, NoSuchMethodException, IOException { Method method = VCloudAsyncClient.class.getMethod("cloneVAppInVDC", URI.class, URI.class, String.class, - CloneVAppOptions[].class); - HttpRequest request = processor.createRequest(method, URI - .create("https://vcenterprise.bluelock.com/api/v1.0/vdc/1"), URI - .create("https://vcenterprise.bluelock.com/api/v1.0/vapp/4181"), "my-vapp"); + CloneVAppOptions[].class); + HttpRequest request = processor.createRequest(method, + URI.create("https://vcenterprise.bluelock.com/api/v1.0/vdc/1"), + URI.create("https://vcenterprise.bluelock.com/api/v1.0/vapp/4181"), "my-vapp"); assertRequestLineEquals(request, - "POST https://vcenterprise.bluelock.com/api/v1.0/vdc/1/action/cloneVApp HTTP/1.1"); + "POST https://vcenterprise.bluelock.com/api/v1.0/vdc/1/action/cloneVApp HTTP/1.1"); assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.task+xml\n"); assertPayloadEquals(request, Strings2.toStringAndClose(getClass().getResourceAsStream("/cloneVApp-default.xml")), - "application/vnd.vmware.vcloud.cloneVAppParams+xml", false); + "application/vnd.vmware.vcloud.cloneVAppParams+xml", false); assertResponseParserClassEquals(method, request, ParseSax.class); assertSaxResponseParserClassEquals(method, TaskHandler.class); @@ -198,17 +238,17 @@ public class VCloudAsyncClientTest extends RestClientTest { public void testCloneVAppInVDCOptions() throws SecurityException, NoSuchMethodException, IOException { Method method = VCloudAsyncClient.class.getMethod("cloneVAppInVDC", URI.class, URI.class, String.class, - CloneVAppOptions[].class); - HttpRequest request = processor.createRequest(method, URI - .create("https://vcenterprise.bluelock.com/api/v1.0/vdc/1"), URI - .create("https://vcenterprise.bluelock.com/api/v1.0/vapp/201"), "new-linux-server", - new CloneVAppOptions().deploy().powerOn().withDescription("The description of the new vApp")); + CloneVAppOptions[].class); + HttpRequest request = processor.createRequest(method, + URI.create("https://vcenterprise.bluelock.com/api/v1.0/vdc/1"), + URI.create("https://vcenterprise.bluelock.com/api/v1.0/vapp/201"), "new-linux-server", + new CloneVAppOptions().deploy().powerOn().withDescription("The description of the new vApp")); assertRequestLineEquals(request, - "POST https://vcenterprise.bluelock.com/api/v1.0/vdc/1/action/cloneVApp HTTP/1.1"); + "POST https://vcenterprise.bluelock.com/api/v1.0/vdc/1/action/cloneVApp HTTP/1.1"); assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.task+xml\n"); assertPayloadEquals(request, Strings2.toStringAndClose(getClass().getResourceAsStream("/cloneVApp.xml")), - "application/vnd.vmware.vcloud.cloneVAppParams+xml", false); + "application/vnd.vmware.vcloud.cloneVAppParams+xml", false); assertResponseParserClassEquals(method, request, ParseSax.class); assertSaxResponseParserClassEquals(method, TaskHandler.class); @@ -219,16 +259,17 @@ public class VCloudAsyncClientTest extends RestClientTest { public void testCaptureVAppInVDC() throws SecurityException, NoSuchMethodException, IOException { Method method = VCloudAsyncClient.class.getMethod("captureVAppInVDC", URI.class, URI.class, String.class, - CaptureVAppOptions[].class); - HttpRequest request = processor.createRequest(method, URI - .create("https://vcenterprise.bluelock.com/api/v1.0/vdc/1"), URI - .create("https://vcenterprise.bluelock.com/api/v1.0/vapp/4181"), "my-template"); + CaptureVAppOptions[].class); + HttpRequest request = processor.createRequest(method, + URI.create("https://vcenterprise.bluelock.com/api/v1.0/vdc/1"), + URI.create("https://vcenterprise.bluelock.com/api/v1.0/vapp/4181"), "my-template"); assertRequestLineEquals(request, - "POST https://vcenterprise.bluelock.com/api/v1.0/vdc/1/action/captureVApp HTTP/1.1"); + "POST https://vcenterprise.bluelock.com/api/v1.0/vdc/1/action/captureVApp HTTP/1.1"); assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.vAppTemplate+xml\n"); - assertPayloadEquals(request, Strings2.toStringAndClose(getClass().getResourceAsStream("/captureVApp-default.xml")), - "application/vnd.vmware.vcloud.captureVAppParams+xml", false); + assertPayloadEquals(request, + Strings2.toStringAndClose(getClass().getResourceAsStream("/captureVApp-default.xml")), + "application/vnd.vmware.vcloud.captureVAppParams+xml", false); assertResponseParserClassEquals(method, request, ParseSax.class); assertSaxResponseParserClassEquals(method, VAppTemplateHandler.class); @@ -239,17 +280,17 @@ public class VCloudAsyncClientTest extends RestClientTest { public void testCaptureVAppInVDCOptions() throws SecurityException, NoSuchMethodException, IOException { Method method = VCloudAsyncClient.class.getMethod("captureVAppInVDC", URI.class, URI.class, String.class, - CaptureVAppOptions[].class); - HttpRequest request = processor.createRequest(method, URI - .create("https://vcenterprise.bluelock.com/api/v1.0/vdc/1"), URI - .create("https://vcenterprise.bluelock.com/api/v1.0/vapp/201"), "my-template", new CaptureVAppOptions() - .withDescription("The description of the new vApp Template")); + CaptureVAppOptions[].class); + HttpRequest request = processor.createRequest(method, + URI.create("https://vcenterprise.bluelock.com/api/v1.0/vdc/1"), + URI.create("https://vcenterprise.bluelock.com/api/v1.0/vapp/201"), "my-template", + new CaptureVAppOptions().withDescription("The description of the new vApp Template")); assertRequestLineEquals(request, - "POST https://vcenterprise.bluelock.com/api/v1.0/vdc/1/action/captureVApp HTTP/1.1"); + "POST https://vcenterprise.bluelock.com/api/v1.0/vdc/1/action/captureVApp HTTP/1.1"); assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.vAppTemplate+xml\n"); assertPayloadEquals(request, Strings2.toStringAndClose(getClass().getResourceAsStream("/captureVApp.xml")), - "application/vnd.vmware.vcloud.captureVAppParams+xml", false); + "application/vnd.vmware.vcloud.captureVAppParams+xml", false); assertResponseParserClassEquals(method, request, ParseSax.class); assertSaxResponseParserClassEquals(method, VAppTemplateHandler.class); @@ -275,8 +316,8 @@ public class VCloudAsyncClientTest extends RestClientTest { public void testOrg() throws SecurityException, NoSuchMethodException, IOException { Method method = VCloudAsyncClient.class.getMethod("getOrg", URI.class); - HttpRequest request = processor.createRequest(method, URI - .create("https://vcenterprise.bluelock.com/api/v1.0/org/1")); + HttpRequest request = processor.createRequest(method, + URI.create("https://vcenterprise.bluelock.com/api/v1.0/org/1")); assertRequestLineEquals(request, "GET https://vcenterprise.bluelock.com/api/v1.0/org/1 HTTP/1.1"); assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.org+xml\n"); @@ -306,8 +347,8 @@ public class VCloudAsyncClientTest extends RestClientTest { public void testCatalog() throws SecurityException, NoSuchMethodException, IOException { Method method = VCloudAsyncClient.class.getMethod("getCatalog", URI.class); - HttpRequest request = processor.createRequest(method, URI - .create("https://vcenterprise.bluelock.com/api/v1.0/catalog/1")); + HttpRequest request = processor.createRequest(method, + URI.create("https://vcenterprise.bluelock.com/api/v1.0/catalog/1")); assertRequestLineEquals(request, "GET https://vcenterprise.bluelock.com/api/v1.0/catalog/1 HTTP/1.1"); assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.catalog+xml\n"); @@ -337,8 +378,8 @@ public class VCloudAsyncClientTest extends RestClientTest { public void testNetwork() throws SecurityException, NoSuchMethodException, IOException { Method method = VCloudAsyncClient.class.getMethod("getNetwork", URI.class); - HttpRequest request = processor.createRequest(method, URI - .create("https://vcenterprise.bluelock.com/api/v1.0/network/2")); + HttpRequest request = processor.createRequest(method, + URI.create("https://vcenterprise.bluelock.com/api/v1.0/network/2")); assertRequestLineEquals(request, "GET https://vcenterprise.bluelock.com/api/v1.0/network/2 HTTP/1.1"); assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.network+xml\n"); @@ -353,7 +394,7 @@ public class VCloudAsyncClientTest extends RestClientTest { public void testFindNetworkInOrgVDCNamed() throws SecurityException, NoSuchMethodException, IOException { Method method = VCloudAsyncClient.class.getMethod("findNetworkInOrgVDCNamed", String.class, String.class, - String.class); + String.class); HttpRequest request = processor.createRequest(method, "org", "vdc", "network"); assertRequestLineEquals(request, "GET https://vcenterprise.bluelock.com/api/v1.0/vdcItem/2 HTTP/1.1"); @@ -369,8 +410,8 @@ public class VCloudAsyncClientTest extends RestClientTest { public void testCatalogItemURI() throws SecurityException, NoSuchMethodException, IOException { Method method = VCloudAsyncClient.class.getMethod("getCatalogItem", URI.class); - HttpRequest request = processor.createRequest(method, URI - .create("https://vcenterprise.bluelock.com/api/v1.0/catalogItem/2")); + HttpRequest request = processor.createRequest(method, + URI.create("https://vcenterprise.bluelock.com/api/v1.0/catalogItem/2")); assertRequestLineEquals(request, "GET https://vcenterprise.bluelock.com/api/v1.0/catalogItem/2 HTTP/1.1"); assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.catalogItem+xml\n"); @@ -385,7 +426,7 @@ public class VCloudAsyncClientTest extends RestClientTest { public void testFindCatalogItemInOrgCatalogNamed() throws SecurityException, NoSuchMethodException, IOException { Method method = VCloudAsyncClient.class.getMethod("findCatalogItemInOrgCatalogNamed", String.class, String.class, - String.class); + String.class); HttpRequest request = processor.createRequest(method, "org", "catalog", "item"); assertRequestLineEquals(request, "GET https://vcenterprise.bluelock.com/api/v1.0/catalogItem/1 HTTP/1.1"); @@ -401,7 +442,7 @@ public class VCloudAsyncClientTest extends RestClientTest { public void testFindVAppTemplate() throws SecurityException, NoSuchMethodException, IOException { Method method = VCloudAsyncClient.class.getMethod("findVAppTemplateInOrgCatalogNamed", String.class, - String.class, String.class); + String.class, String.class); HttpRequest request = processor.createRequest(method, "org", "catalog", "template"); assertRequestLineEquals(request, "GET https://vcenterprise.bluelock.com/api/v1.0/vAppTemplate/2 HTTP/1.1"); @@ -417,8 +458,8 @@ public class VCloudAsyncClientTest extends RestClientTest { public void testVAppTemplateURI() throws SecurityException, NoSuchMethodException, IOException { Method method = VCloudAsyncClient.class.getMethod("getVAppTemplate", URI.class); - HttpRequest request = processor.createRequest(method, URI - .create("https://vcenterprise.bluelock.com/api/v1.0/vAppTemplate/2")); + HttpRequest request = processor.createRequest(method, + URI.create("https://vcenterprise.bluelock.com/api/v1.0/vAppTemplate/2")); assertRequestLineEquals(request, "GET https://vcenterprise.bluelock.com/api/v1.0/vAppTemplate/2 HTTP/1.1"); assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.vAppTemplate+xml\n"); @@ -433,8 +474,8 @@ public class VCloudAsyncClientTest extends RestClientTest { public void testGetOvfEnvelopeForVAppTemplate() throws SecurityException, NoSuchMethodException, IOException { Method method = VCloudAsyncClient.class.getMethod("getOvfEnvelopeForVAppTemplate", URI.class); - HttpRequest request = processor.createRequest(method, URI - .create("https://vcenterprise.bluelock.com/api/v1.0/vAppTemplate/2")); + HttpRequest request = processor.createRequest(method, + URI.create("https://vcenterprise.bluelock.com/api/v1.0/vAppTemplate/2")); assertRequestLineEquals(request, "GET https://vcenterprise.bluelock.com/api/v1.0/vAppTemplate/2/ovf HTTP/1.1"); assertNonPayloadHeadersEqual(request, "Accept: text/xml\n"); @@ -506,8 +547,8 @@ public class VCloudAsyncClientTest extends RestClientTest { public void testGetVDC() throws SecurityException, NoSuchMethodException, IOException { Method method = VCloudAsyncClient.class.getMethod("getVDC", URI.class); - HttpRequest request = processor.createRequest(method, URI - .create("https://vcenterprise.bluelock.com/api/v1.0/vdc/1")); + HttpRequest request = processor.createRequest(method, + URI.create("https://vcenterprise.bluelock.com/api/v1.0/vdc/1")); assertRequestLineEquals(request, "GET https://vcenterprise.bluelock.com/api/v1.0/vdc/1 HTTP/1.1"); assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.vdc+xml\n"); @@ -522,8 +563,8 @@ public class VCloudAsyncClientTest extends RestClientTest { public void testGetTasksList() throws SecurityException, NoSuchMethodException, IOException { Method method = VCloudAsyncClient.class.getMethod("getTasksList", URI.class); - HttpRequest request = processor.createRequest(method, URI - .create("https://vcenterprise.bluelock.com/api/v1.0/tasksList/1")); + HttpRequest request = processor.createRequest(method, + URI.create("https://vcenterprise.bluelock.com/api/v1.0/tasksList/1")); assertRequestLineEquals(request, "GET https://vcenterprise.bluelock.com/api/v1.0/tasksList/1 HTTP/1.1"); assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.tasksList+xml\n"); @@ -553,13 +594,13 @@ public class VCloudAsyncClientTest extends RestClientTest { public void testDeployVAppOrVm() throws SecurityException, NoSuchMethodException, IOException { Method method = VCloudAsyncClient.class.getMethod("deployVAppOrVm", URI.class); - HttpRequest request = processor.createRequest(method, URI - .create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1")); + HttpRequest request = processor.createRequest(method, + URI.create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1")); assertRequestLineEquals(request, "POST https://vcenterprise.bluelock.com/api/v1.0/vApp/1/action/deploy HTTP/1.1"); assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.task+xml\n"); assertPayloadEquals(request, "", - "application/vnd.vmware.vcloud.deployVAppParams+xml", false); + "application/vnd.vmware.vcloud.deployVAppParams+xml", false); assertResponseParserClassEquals(method, request, ParseSax.class); assertSaxResponseParserClassEquals(method, TaskHandler.class); @@ -570,13 +611,13 @@ public class VCloudAsyncClientTest extends RestClientTest { public void testDeployAndPowerOnVAppOrVm() throws SecurityException, NoSuchMethodException, IOException { Method method = VCloudAsyncClient.class.getMethod("deployAndPowerOnVAppOrVm", URI.class); - HttpRequest request = processor.createRequest(method, URI - .create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1")); + HttpRequest request = processor.createRequest(method, + URI.create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1")); assertRequestLineEquals(request, "POST https://vcenterprise.bluelock.com/api/v1.0/vApp/1/action/deploy HTTP/1.1"); assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.task+xml\n"); assertPayloadEquals(request, "", - "application/vnd.vmware.vcloud.deployVAppParams+xml", false); + "application/vnd.vmware.vcloud.deployVAppParams+xml", false); assertResponseParserClassEquals(method, request, ParseSax.class); assertSaxResponseParserClassEquals(method, TaskHandler.class); @@ -587,8 +628,8 @@ public class VCloudAsyncClientTest extends RestClientTest { public void testGetVApp() throws SecurityException, NoSuchMethodException, IOException { Method method = VCloudAsyncClient.class.getMethod("getVApp", URI.class); - HttpRequest request = processor.createRequest(method, URI - .create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1")); + HttpRequest request = processor.createRequest(method, + URI.create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1")); assertRequestLineEquals(request, "GET https://vcenterprise.bluelock.com/api/v1.0/vApp/1 HTTP/1.1"); assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.vApp+xml\n"); @@ -603,8 +644,8 @@ public class VCloudAsyncClientTest extends RestClientTest { public void testGetVm() throws SecurityException, NoSuchMethodException, IOException { Method method = VCloudAsyncClient.class.getMethod("getVm", URI.class); - HttpRequest request = processor.createRequest(method, URI - .create("https://vcenterprise.bluelock.com/api/v1.0/vm/1")); + HttpRequest request = processor.createRequest(method, + URI.create("https://vcenterprise.bluelock.com/api/v1.0/vm/1")); assertRequestLineEquals(request, "GET https://vcenterprise.bluelock.com/api/v1.0/vm/1 HTTP/1.1"); assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.vm+xml\n"); @@ -619,11 +660,11 @@ public class VCloudAsyncClientTest extends RestClientTest { public void testRebootVAppOrVm() throws SecurityException, NoSuchMethodException, IOException { Method method = VCloudAsyncClient.class.getMethod("rebootVAppOrVm", URI.class); - HttpRequest request = processor.createRequest(method, URI - .create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1")); + HttpRequest request = processor.createRequest(method, + URI.create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1")); assertRequestLineEquals(request, - "POST https://vcenterprise.bluelock.com/api/v1.0/vApp/1/power/action/reboot HTTP/1.1"); + "POST https://vcenterprise.bluelock.com/api/v1.0/vApp/1/power/action/reboot HTTP/1.1"); assertNonPayloadHeadersEqual(request, ""); assertPayloadEquals(request, null, null, false); @@ -636,14 +677,14 @@ public class VCloudAsyncClientTest extends RestClientTest { public void testUndeployVAppOrVm() throws SecurityException, NoSuchMethodException, IOException { Method method = VCloudAsyncClient.class.getMethod("undeployVAppOrVm", URI.class); - HttpRequest request = processor.createRequest(method, URI - .create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1")); + HttpRequest request = processor.createRequest(method, + URI.create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1")); assertRequestLineEquals(request, - "POST https://vcenterprise.bluelock.com/api/v1.0/vApp/1/action/undeploy HTTP/1.1"); + "POST https://vcenterprise.bluelock.com/api/v1.0/vApp/1/action/undeploy HTTP/1.1"); assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.task+xml\n"); assertPayloadEquals(request, "", - "application/vnd.vmware.vcloud.undeployVAppParams+xml", false); + "application/vnd.vmware.vcloud.undeployVAppParams+xml", false); assertResponseParserClassEquals(method, request, ParseSax.class); assertSaxResponseParserClassEquals(method, TaskHandler.class); @@ -653,17 +694,17 @@ public class VCloudAsyncClientTest extends RestClientTest { } public void testUndeployAndSaveStateOfVAppOrVmSaveState() throws SecurityException, NoSuchMethodException, - IOException { + IOException { Method method = VCloudAsyncClient.class.getMethod("undeployAndSaveStateOfVAppOrVm", URI.class); - HttpRequest request = processor.createRequest(method, URI - .create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1")); + HttpRequest request = processor.createRequest(method, + URI.create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1")); assertRequestLineEquals(request, - "POST https://vcenterprise.bluelock.com/api/v1.0/vApp/1/action/undeploy HTTP/1.1"); + "POST https://vcenterprise.bluelock.com/api/v1.0/vApp/1/action/undeploy HTTP/1.1"); assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.task+xml\n"); assertPayloadEquals(request, - "", - "application/vnd.vmware.vcloud.undeployVAppParams+xml", false); + "", + "application/vnd.vmware.vcloud.undeployVAppParams+xml", false); assertResponseParserClassEquals(method, request, ParseSax.class); assertSaxResponseParserClassEquals(method, TaskHandler.class); @@ -674,8 +715,8 @@ public class VCloudAsyncClientTest extends RestClientTest { public void testDeleteVApp() throws SecurityException, NoSuchMethodException, IOException { Method method = VCloudAsyncClient.class.getMethod("deleteVApp", URI.class); - HttpRequest request = processor.createRequest(method, URI - .create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1")); + HttpRequest request = processor.createRequest(method, + URI.create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1")); assertRequestLineEquals(request, "DELETE https://vcenterprise.bluelock.com/api/v1.0/vApp/1 HTTP/1.1"); assertNonPayloadHeadersEqual(request, ""); @@ -690,11 +731,11 @@ public class VCloudAsyncClientTest extends RestClientTest { public void testPowerOnVAppOrVm() throws SecurityException, NoSuchMethodException, IOException { Method method = VCloudAsyncClient.class.getMethod("powerOnVAppOrVm", URI.class); - HttpRequest request = processor.createRequest(method, URI - .create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1")); + HttpRequest request = processor.createRequest(method, + URI.create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1")); assertRequestLineEquals(request, - "POST https://vcenterprise.bluelock.com/api/v1.0/vApp/1/power/action/powerOn HTTP/1.1"); + "POST https://vcenterprise.bluelock.com/api/v1.0/vApp/1/power/action/powerOn HTTP/1.1"); assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.task+xml\n"); assertPayloadEquals(request, null, null, false); @@ -707,11 +748,11 @@ public class VCloudAsyncClientTest extends RestClientTest { public void testPowerOffVAppOrVm() throws SecurityException, NoSuchMethodException, IOException { Method method = VCloudAsyncClient.class.getMethod("powerOffVAppOrVm", URI.class); - HttpRequest request = processor.createRequest(method, URI - .create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1")); + HttpRequest request = processor.createRequest(method, + URI.create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1")); assertRequestLineEquals(request, - "POST https://vcenterprise.bluelock.com/api/v1.0/vApp/1/power/action/powerOff HTTP/1.1"); + "POST https://vcenterprise.bluelock.com/api/v1.0/vApp/1/power/action/powerOff HTTP/1.1"); assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.task+xml\n"); assertPayloadEquals(request, null, null, false); @@ -724,11 +765,11 @@ public class VCloudAsyncClientTest extends RestClientTest { public void testResetVAppOrVm() throws SecurityException, NoSuchMethodException, IOException { Method method = VCloudAsyncClient.class.getMethod("resetVAppOrVm", URI.class); - HttpRequest request = processor.createRequest(method, URI - .create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1")); + HttpRequest request = processor.createRequest(method, + URI.create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1")); assertRequestLineEquals(request, - "POST https://vcenterprise.bluelock.com/api/v1.0/vApp/1/power/action/reset HTTP/1.1"); + "POST https://vcenterprise.bluelock.com/api/v1.0/vApp/1/power/action/reset HTTP/1.1"); assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.task+xml\n"); assertPayloadEquals(request, null, null, false); @@ -741,11 +782,11 @@ public class VCloudAsyncClientTest extends RestClientTest { public void testSuspendVAppOrVm() throws SecurityException, NoSuchMethodException, IOException { Method method = VCloudAsyncClient.class.getMethod("suspendVAppOrVm", URI.class); - HttpRequest request = processor.createRequest(method, URI - .create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1")); + HttpRequest request = processor.createRequest(method, + URI.create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1")); assertRequestLineEquals(request, - "POST https://vcenterprise.bluelock.com/api/v1.0/vApp/1/power/action/suspend HTTP/1.1"); + "POST https://vcenterprise.bluelock.com/api/v1.0/vApp/1/power/action/suspend HTTP/1.1"); assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.task+xml\n"); assertPayloadEquals(request, null, null, false); @@ -758,11 +799,11 @@ public class VCloudAsyncClientTest extends RestClientTest { public void testShutdownVAppOrVm() throws SecurityException, NoSuchMethodException, IOException { Method method = VCloudAsyncClient.class.getMethod("shutdownVAppOrVm", URI.class); - HttpRequest request = processor.createRequest(method, URI - .create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1")); + HttpRequest request = processor.createRequest(method, + URI.create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1")); assertRequestLineEquals(request, - "POST https://vcenterprise.bluelock.com/api/v1.0/vApp/1/power/action/shutdown HTTP/1.1"); + "POST https://vcenterprise.bluelock.com/api/v1.0/vApp/1/power/action/shutdown HTTP/1.1"); assertNonPayloadHeadersEqual(request, ""); assertPayloadEquals(request, null, null, false); @@ -775,8 +816,8 @@ public class VCloudAsyncClientTest extends RestClientTest { public void testGetTask() throws SecurityException, NoSuchMethodException, IOException { Method method = VCloudAsyncClient.class.getMethod("getTask", URI.class); - HttpRequest request = processor.createRequest(method, URI - .create("https://vcenterprise.bluelock.com/api/v1.0/task/1")); + HttpRequest request = processor.createRequest(method, + URI.create("https://vcenterprise.bluelock.com/api/v1.0/task/1")); assertRequestLineEquals(request, "GET https://vcenterprise.bluelock.com/api/v1.0/task/1 HTTP/1.1"); assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.task+xml\n"); @@ -791,8 +832,8 @@ public class VCloudAsyncClientTest extends RestClientTest { public void testCancelTask() throws SecurityException, NoSuchMethodException, IOException { Method method = VCloudAsyncClient.class.getMethod("cancelTask", URI.class); - HttpRequest request = processor.createRequest(method, URI - .create("https://vcenterprise.bluelock.com/api/v1.0/task/1")); + HttpRequest request = processor.createRequest(method, + URI.create("https://vcenterprise.bluelock.com/api/v1.0/task/1")); assertRequestLineEquals(request, "POST https://vcenterprise.bluelock.com/api/v1.0/task/1/action/cancel HTTP/1.1"); assertNonPayloadHeadersEqual(request, ""); @@ -834,7 +875,7 @@ public class VCloudAsyncClientTest extends RestClientTest { public static class VCloudRestClientModuleExtension extends VCloudRestClientModule { @Override protected URI provideAuthenticationURI(VCloudVersionsAsyncClient versionService, - @Named(PROPERTY_API_VERSION) String version) { + @Named(PROPERTY_API_VERSION) String version) { return URI.create("https://vcenterprise.bluelock.com/api/v1.0/login"); } @@ -872,7 +913,7 @@ public class VCloudAsyncClientTest extends RestClientTest { @Override protected String provideDefaultVDCName( - @org.jclouds.vcloud.endpoints.VDC Supplier> vDCtoOrgSupplier) { + @org.jclouds.vcloud.endpoints.VDC Supplier> vDCtoOrgSupplier) { return "vdc"; } @@ -883,13 +924,13 @@ public class VCloudAsyncClientTest extends RestClientTest { @Override protected Supplier provideVCloudTokenCache(@Named(PROPERTY_SESSION_INTERVAL) long seconds, - final VCloudLoginAsyncClient login) { + final VCloudLoginAsyncClient login) { return Suppliers. ofInstance(new VCloudSession() { @Override public Map getOrgs() { return ImmutableMap. of("org", new ReferenceTypeImpl("org", - VCloudMediaType.ORG_XML, URI.create("https://vcenterprise.bluelock.com/api/v1.0/org/1"))); + VCloudMediaType.ORG_XML, URI.create("https://vcenterprise.bluelock.com/api/v1.0/org/1"))); } @Override @@ -910,45 +951,23 @@ public class VCloudAsyncClientTest extends RestClientTest { } protected Supplier>> provideOrgVDCSupplierCache( - @Named(PROPERTY_SESSION_INTERVAL) long seconds, final OrgVDCSupplier supplier) { + @Named(PROPERTY_SESSION_INTERVAL) long seconds, final OrgVDCSupplier supplier) { - return Suppliers - .>> ofInstance(ImmutableMap - .> of( - "org", + return Suppliers.>> ofInstance(ImmutableMap + .> of("org", - ImmutableMap - . of( - "vdc", - new VDCImpl( - "vdc", - null, - URI - .create("https://vcenterprise.bluelock.com/api/v1.0/vdc/1"), - VDCStatus.READY, - null, - "description", - ImmutableSet. of(), - AllocationModel.ALLOCATION_POOL, - null, - null, - null, - ImmutableMap - . of( - "vapp", - new ReferenceTypeImpl( - "vapp", - "application/vnd.vmware.vcloud.vApp+xml", - URI - .create("https://vcenterprise.bluelock.com/api/v1.0/vApp/188849-1")), - "network", - new ReferenceTypeImpl( - "network", - "application/vnd.vmware.vcloud.vAppTemplate+xml", - URI - .create("https://vcenterprise.bluelock.com/api/v1.0/vdcItem/2"))), - ImmutableMap. of(), 0, 0, 0, - false)))); + ImmutableMap. of( + "vdc", + new VDCImpl("vdc", null, URI.create("https://vcenterprise.bluelock.com/api/v1.0/vdc/1"), + VDCStatus.READY, null, "description", ImmutableSet. of(), + AllocationModel.ALLOCATION_POOL, null, null, null, ImmutableMap. of( + "vapp", + new ReferenceTypeImpl("vapp", "application/vnd.vmware.vcloud.vApp+xml", URI + .create("https://vcenterprise.bluelock.com/api/v1.0/vApp/188849-1")), + "network", + new ReferenceTypeImpl("network", "application/vnd.vmware.vcloud.vAppTemplate+xml", URI + .create("https://vcenterprise.bluelock.com/api/v1.0/vdcItem/2"))), ImmutableMap + . of(), 0, 0, 0, false)))); } @@ -961,17 +980,20 @@ public class VCloudAsyncClientTest extends RestClientTest { @Override public Map get() { - return ImmutableMap. of("org", new OrgImpl("org", null, URI - .create("https://vcenterprise.bluelock.com/api/v1.0/org/1"), "org", "description", ImmutableMap - . of("catalog", new ReferenceTypeImpl("catalog", - VCloudMediaType.CATALOG_XML, URI - .create("https://vcenterprise.bluelock.com/api/v1.0/catalog/1"))), ImmutableMap - . of("vdc", new ReferenceTypeImpl("vdc", VCloudMediaType.VDC_XML, URI - .create("https://vcenterprise.bluelock.com/api/v1.0/vdc/1"))), ImmutableMap - . of("network", new ReferenceTypeImpl("network", - VCloudMediaType.NETWORK_XML, URI - .create("https://vcenterprise.bluelock.com/api/v1.0/network/1"))), - new ReferenceTypeImpl("tasksList", VCloudMediaType.TASKSLIST_XML, URI + return ImmutableMap. of( + "org", + new OrgImpl("org", null, URI.create("https://vcenterprise.bluelock.com/api/v1.0/org/1"), "org", + "description", ImmutableMap. of( + "catalog", + new ReferenceTypeImpl("catalog", VCloudMediaType.CATALOG_XML, URI + .create("https://vcenterprise.bluelock.com/api/v1.0/catalog/1"))), ImmutableMap + . of("vdc", new ReferenceTypeImpl("vdc", VCloudMediaType.VDC_XML, + URI.create("https://vcenterprise.bluelock.com/api/v1.0/vdc/1"))), ImmutableMap + . of( + "network", + new ReferenceTypeImpl("network", VCloudMediaType.NETWORK_XML, URI + .create("https://vcenterprise.bluelock.com/api/v1.0/network/1"))), + new ReferenceTypeImpl("tasksList", VCloudMediaType.TASKSLIST_XML, URI .create("https://vcenterprise.bluelock.com/api/v1.0/tasksList/1")), ImmutableList . of())); } @@ -988,15 +1010,18 @@ public class VCloudAsyncClientTest extends RestClientTest { public Map> get() { return ImmutableMap.> of("org", - ImmutableMap. of("catalog", new CatalogImpl("catalog", "type", - URI.create("https://vcenterprise.bluelock.com/api/v1.0/catalog/1"), null, "description", - ImmutableMap. of("item", new ReferenceTypeImpl("item", - "application/vnd.vmware.vcloud.catalogItem+xml", URI - .create("https://vcenterprise.bluelock.com/api/v1.0/catalogItem/1")), - "template", new ReferenceTypeImpl("template", - "application/vnd.vmware.vcloud.vAppTemplate+xml", URI - .create("https://vcenterprise.bluelock.com/api/v1.0/catalogItem/2"))), - ImmutableList. of(), true))); + ImmutableMap. of( + "catalog", + new CatalogImpl("catalog", "type", + URI.create("https://vcenterprise.bluelock.com/api/v1.0/catalog/1"), null, "description", + ImmutableMap. of( + "item", + new ReferenceTypeImpl("item", "application/vnd.vmware.vcloud.catalogItem+xml", URI + .create("https://vcenterprise.bluelock.com/api/v1.0/catalogItem/1")), + "template", + new ReferenceTypeImpl("template", "application/vnd.vmware.vcloud.vAppTemplate+xml", URI + .create("https://vcenterprise.bluelock.com/api/v1.0/catalogItem/2"))), + ImmutableList. of(), true))); } } @@ -1008,26 +1033,15 @@ public class VCloudAsyncClientTest extends RestClientTest { @Override public Map>> get() { - return ImmutableMap - .>> of( - "org", - ImmutableMap - .> of( - "catalog", - ImmutableMap - . of( - "template", - new CatalogItemImpl( - "template", - URI - .create("https://vcenterprise.bluelock.com/api/v1.0/catalogItem/2"), - "description", - new ReferenceTypeImpl( - "template", - "application/vnd.vmware.vcloud.vAppTemplate+xml", - URI - .create("https://vcenterprise.bluelock.com/api/v1.0/vAppTemplate/2")), - ImmutableMap. of())))); + return ImmutableMap.>> of( + "org", ImmutableMap.> of( + "catalog", ImmutableMap. of( + "template", + new CatalogItemImpl("template", URI + .create("https://vcenterprise.bluelock.com/api/v1.0/catalogItem/2"), "description", + new ReferenceTypeImpl("template", "application/vnd.vmware.vcloud.vAppTemplate+xml", + URI.create("https://vcenterprise.bluelock.com/api/v1.0/vAppTemplate/2")), + ImmutableMap. of())))); } } diff --git a/apis/vcloud/src/test/java/org/jclouds/vcloud/binders/BindInstantiateVAppTemplateParamsToXmlPayloadTest.java b/apis/vcloud/src/test/java/org/jclouds/vcloud/binders/BindInstantiateVAppTemplateParamsToXmlPayloadTest.java index eaadfa9240..c6d7130bd3 100644 --- a/apis/vcloud/src/test/java/org/jclouds/vcloud/binders/BindInstantiateVAppTemplateParamsToXmlPayloadTest.java +++ b/apis/vcloud/src/test/java/org/jclouds/vcloud/binders/BindInstantiateVAppTemplateParamsToXmlPayloadTest.java @@ -152,7 +152,6 @@ public class BindInstantiateVAppTemplateParamsToXmlPayloadTest { VAppTemplate template = null; InstantiateVAppTemplateOptions options = new InstantiateVAppTemplateOptions(); - options.processorCount(1).memory(512).disk(1024); String expected = Strings2.toStringAndClose(getClass().getResourceAsStream("/instantiationparams.xml")); GeneratedHttpRequest request = createMock(GeneratedHttpRequest.class); diff --git a/apis/vcloud/src/test/java/org/jclouds/vcloud/options/InstantiateVAppTemplateOptionsTest.java b/apis/vcloud/src/test/java/org/jclouds/vcloud/options/InstantiateVAppTemplateOptionsTest.java new file mode 100644 index 0000000000..50bd524bb8 --- /dev/null +++ b/apis/vcloud/src/test/java/org/jclouds/vcloud/options/InstantiateVAppTemplateOptionsTest.java @@ -0,0 +1,77 @@ +/** + * + * Copyright (C) 2011 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ +package org.jclouds.vcloud.options; + +import static org.jclouds.vcloud.options.InstantiateVAppTemplateOptions.Builder.addNetworkConfig; +import static org.jclouds.vcloud.options.InstantiateVAppTemplateOptions.Builder.customizeOnInstantiate; +import static org.testng.Assert.assertEquals; + +import java.net.URI; + +import org.jclouds.http.functions.config.SaxParserModule; +import org.jclouds.vcloud.domain.network.FenceMode; +import org.jclouds.vcloud.domain.network.NetworkConfig; +import org.testng.annotations.Test; + +import com.google.common.collect.Iterables; +import com.google.inject.Guice; +import com.google.inject.Injector; + +/** + * Tests behavior of {@code InstantiateVAppTemplateOptions} + * + * @author Adrian Cole + */ +@Test(groups = "unit") +public class InstantiateVAppTemplateOptionsTest { + + Injector injector = Guice.createInjector(new SaxParserModule()); + + @Test + public void testAddNetworkConfig() { + InstantiateVAppTemplateOptions options = new InstantiateVAppTemplateOptions(); + options.addNetworkConfig(new NetworkConfig("default", URI.create("http://localhost"), FenceMode.BRIDGED)); + assertEquals(Iterables.get(options.getNetworkConfig(), 0).getNetworkName(), "default"); + assertEquals(Iterables.get(options.getNetworkConfig(), 0).getParentNetwork(), URI.create("http://localhost")); + assertEquals(Iterables.get(options.getNetworkConfig(), 0).getFenceMode(), FenceMode.BRIDGED); + } + + @Test + public void testAddNetworkConfigStatic() { + InstantiateVAppTemplateOptions options = addNetworkConfig(new NetworkConfig("default", + URI.create("http://localhost"), FenceMode.BRIDGED)); + assertEquals(Iterables.get(options.getNetworkConfig(), 0).getNetworkName(), "default"); + assertEquals(Iterables.get(options.getNetworkConfig(), 0).getParentNetwork(), URI.create("http://localhost")); + assertEquals(Iterables.get(options.getNetworkConfig(), 0).getFenceMode(), FenceMode.BRIDGED); + } + + @Test + public void testCustomizeOnInstantiate() { + InstantiateVAppTemplateOptions options = new InstantiateVAppTemplateOptions(); + options.customizeOnInstantiate(true); + assertEquals(options.shouldCustomizeOnInstantiate(), new Boolean(true)); + } + + @Test + public void testCustomizeOnInstantiateStatic() { + InstantiateVAppTemplateOptions options = customizeOnInstantiate(true); + assertEquals(options.shouldCustomizeOnInstantiate(), new Boolean(true)); + } + +} diff --git a/apis/vcloud/src/test/resources/cpuItem.xml b/apis/vcloud/src/test/resources/cpuItem.xml new file mode 100644 index 0000000000..d5e437b849 --- /dev/null +++ b/apis/vcloud/src/test/resources/cpuItem.xml @@ -0,0 +1 @@ +hertz * 10^6Number of Virtual CPUs2 virtual CPU(s)4320 \ No newline at end of file diff --git a/apis/vcloud/src/test/resources/memoryItem.xml b/apis/vcloud/src/test/resources/memoryItem.xml new file mode 100644 index 0000000000..df35b837a5 --- /dev/null +++ b/apis/vcloud/src/test/resources/memoryItem.xml @@ -0,0 +1 @@ +byte * 2^20Memory Size512 MB of memory5045120 \ No newline at end of file diff --git a/common/vcloud/src/main/java/org/jclouds/vcloud/options/InstantiateVAppTemplateOptions.java b/apis/vcloudexpress/src/main/java/org/jclouds/vcloud/options/InstantiateVAppTemplateOptions.java similarity index 100% rename from common/vcloud/src/main/java/org/jclouds/vcloud/options/InstantiateVAppTemplateOptions.java rename to apis/vcloudexpress/src/main/java/org/jclouds/vcloud/options/InstantiateVAppTemplateOptions.java diff --git a/common/vcloud/src/test/java/org/jclouds/vcloud/options/InstantiateVAppTemplateOptionsTest.java b/apis/vcloudexpress/src/test/java/org/jclouds/vcloud/options/InstantiateVAppTemplateOptionsTest.java similarity index 100% rename from common/vcloud/src/test/java/org/jclouds/vcloud/options/InstantiateVAppTemplateOptionsTest.java rename to apis/vcloudexpress/src/test/java/org/jclouds/vcloud/options/InstantiateVAppTemplateOptionsTest.java diff --git a/common/vcloud/src/main/java/org/jclouds/vcloud/VCloudMediaType.java b/common/vcloud/src/main/java/org/jclouds/vcloud/VCloudMediaType.java index dce107890c..5fb0d444e1 100644 --- a/common/vcloud/src/main/java/org/jclouds/vcloud/VCloudMediaType.java +++ b/common/vcloud/src/main/java/org/jclouds/vcloud/VCloudMediaType.java @@ -35,7 +35,7 @@ public interface VCloudMediaType { * "application/vnd.vmware.vcloud.error+xml" */ public final static MediaType ERROR_XML_TYPE = new MediaType("application", "vnd.vmware.vcloud.error+xml"); - + /** * "application/vnd.vmware.vcloud.vcloud+xml" */ @@ -98,7 +98,7 @@ public interface VCloudMediaType { * "application/vnd.vmware.vcloud.catalogItem+xml" */ public final static MediaType CATALOGITEM_XML_TYPE = new MediaType("application", - "vnd.vmware.vcloud.catalogItem+xml"); + "vnd.vmware.vcloud.catalogItem+xml"); /** * "application/vnd.vmware.vcloud.networkConnectionSection+xml" */ @@ -107,7 +107,7 @@ public interface VCloudMediaType { * "application/vnd.vmware.vcloud.networkConnectionSection+xml" */ public final static MediaType NETWORKCONNECTIONSECTION_XML_TYPE = new MediaType("application", - "vnd.vmware.vcloud.networkConnectionSection+xml"); + "vnd.vmware.vcloud.networkConnectionSection+xml"); /** * "application/vnd.vmware.vcloud.virtualHardwareSection+xml" */ @@ -116,7 +116,7 @@ public interface VCloudMediaType { * "application/vnd.vmware.vcloud.virtualHardwareSection+xml" */ public final static MediaType VIRTUALHARDWARESECTION_XML_TYPE = new MediaType("application", - "vnd.vmware.vcloud.virtualHardwareSection+xml"); + "vnd.vmware.vcloud.virtualHardwareSection+xml"); /** * "application/vnd.vmware.vcloud.guestCustomizationSection+xml" */ @@ -125,7 +125,7 @@ public interface VCloudMediaType { * "application/vnd.vmware.vcloud.guestCustomizationSection+xml" */ public final static MediaType GUESTCUSTOMIZATIONSECTION_XML_TYPE = new MediaType("application", - "vnd.vmware.vcloud.guestCustomizationSection+xml"); + "vnd.vmware.vcloud.guestCustomizationSection+xml"); /** * "application/vnd.vmware.vcloud.networkSection+xml" @@ -135,7 +135,7 @@ public interface VCloudMediaType { * "application/vnd.vmware.vcloud.networkSection+xml" */ public final static MediaType NETWORKSECTION_XML_TYPE = new MediaType("application", - "vnd.vmware.vcloud.networkSection+xml"); + "vnd.vmware.vcloud.networkSection+xml"); /** * "application/vnd.vmware.vcloud.task+xml" @@ -154,7 +154,7 @@ public interface VCloudMediaType { * "application/vnd.vmware.vcloud.undeployVAppParams+xml" */ public final static MediaType UNDEPLOYVAPPPARAMS_XML_TYPE = new MediaType("application", - "vnd.vmware.vcloud.undeployVAppParams+xml"); + "vnd.vmware.vcloud.undeployVAppParams+xml"); /** * "application/vnd.vmware.vcloud.deployVAppParams+xml" @@ -164,7 +164,7 @@ public interface VCloudMediaType { * "application/vnd.vmware.vcloud.deployVAppParams+xml" */ public final static MediaType DEPLOYVAPPPARAMS_XML_TYPE = new MediaType("application", - "vnd.vmware.vcloud.deployVAppParams+xml"); + "vnd.vmware.vcloud.deployVAppParams+xml"); /** * "application/vnd.vmware.vcloud.vApp+xml" @@ -202,4 +202,13 @@ public interface VCloudMediaType { */ public final static MediaType NETWORK_XML_TYPE = new MediaType("application", "vnd.vmware.vcloud.network+xml"); + /** + * "application/vnd.vmware.vcloud.rasdItem+xml" + */ + public final static String RASDITEM_XML = "application/vnd.vmware.vcloud.rasdItem+xml"; + /** + * "application/vnd.vmware.vcloud.rasdItem+xml" + */ + public final static MediaType RASDITEM_XML_TYPE = new MediaType("application", "vnd.vmware.vcloud.rasdItem+xml"); + }