From 37587fdfeb017914347633976d580eac28fe7d1f Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Tue, 17 May 2011 22:48:50 -0700 Subject: [PATCH] Issue 435 added more test cases to savvis and cleaned up VMSpec binding --- providers/savvis-symphonyvpdc/pom.xml | 8 +- .../binders/BaseBindVMSpecToXmlPayload.java | 210 ++++++++++++++ .../vpdc/binders/BindVMSpecToXmlPayload.java | 184 +----------- .../vpdc/binders/BindVMSpecsToXmlPayload.java | 64 ++++ .../strategy/VPDCComputeServiceAdapter.java | 4 +- .../jclouds/savvis/vpdc/domain/VMSpec.java | 62 ++-- .../savvis/vpdc/features/VMAsyncClient.java | 40 ++- .../savvis/vpdc/features/VMClient.java | 52 ++-- ....java => BindVMSpecsToXmlPayloadTest.java} | 28 +- .../features/BrowsingAsyncClientTest.java | 26 +- .../features/FirewallAsyncClientTest.java | 58 ++-- .../ServiceManagementAsyncClientTest.java | 12 +- .../vpdc/features/VMAsyncClientTest.java | 108 +++++-- .../vpdc/features/VMClientLiveTest.java | 273 +++++++++--------- 14 files changed, 661 insertions(+), 468 deletions(-) create mode 100644 providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/binders/BaseBindVMSpecToXmlPayload.java create mode 100644 providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/binders/BindVMSpecsToXmlPayload.java rename providers/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/binders/{BindVMSpecToXmlPayloadTest.java => BindVMSpecsToXmlPayloadTest.java} (70%) diff --git a/providers/savvis-symphonyvpdc/pom.xml b/providers/savvis-symphonyvpdc/pom.xml index b6b25baa52..0c19c904d2 100644 --- a/providers/savvis-symphonyvpdc/pom.xml +++ b/providers/savvis-symphonyvpdc/pom.xml @@ -53,11 +53,11 @@ node-924 - https://api.symphonyvpdc.savvis.net/rest/api - 0.8 + https://api.symphonyvpdc.savvis.net/vpdc + 1.0 FIXME FIXME - FIXME + FIXME FIXME FIXME @@ -144,7 +144,7 @@ ${test.savvis-symphonyvpdc.credential} - savvis-symphonyvpdc.vpdc-email + test.savvis-symphonyvpdc.vdc-email ${test.savvis-symphonyvpdc.vdc-email} diff --git a/providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/binders/BaseBindVMSpecToXmlPayload.java b/providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/binders/BaseBindVMSpecToXmlPayload.java new file mode 100644 index 0000000000..7737be725a --- /dev/null +++ b/providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/binders/BaseBindVMSpecToXmlPayload.java @@ -0,0 +1,210 @@ +/** + * + * 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.savvis.vpdc.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 java.util.Map; +import java.util.Properties; +import java.util.Map.Entry; + +import javax.ws.rs.core.MediaType; +import javax.xml.parsers.FactoryConfigurationError; +import javax.xml.parsers.ParserConfigurationException; + +import org.jclouds.cim.ResourceAllocationSettingData.ResourceType; +import org.jclouds.compute.domain.CIMOperatingSystem; +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.savvis.vpdc.domain.VMSpec; + +import com.google.common.base.Throwables; +import com.jamesmurty.utils.XMLBuilder; + +/** + * + * @author Adrian Cole + * + */ +public abstract class BaseBindVMSpecToXmlPayload extends BindToStringPayload implements MapBinder { + @Override + public R bindToRequest(R request, Object toBind) { + throw new IllegalStateException("BindVMSpecToXmlPayload needs parameters"); + } + + protected abstract T findSpecInArgsOrNull(GeneratedHttpRequest gRequest); + + @Override + public R bindToRequest(R request, Map postParams) { + 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"); + + request = super.bindToRequest(request, generateXml(findSpecInArgsOrNull(gRequest))); + request.getPayload().getContentMetadata().setContentType(MediaType.APPLICATION_XML); + return request; + } + + public String generateXml(T spec) { + try { + XMLBuilder rootBuilder = buildRoot(); + bindSpec(spec, rootBuilder); + Properties outputProperties = new Properties(); + outputProperties.put(javax.xml.transform.OutputKeys.OMIT_XML_DECLARATION, "yes"); + return rootBuilder.asString(outputProperties); + } catch (Exception e) { + Throwables.propagate(e); + return null; + } + } + + protected abstract void bindSpec(T spec, XMLBuilder rootBuilder) throws ParserConfigurationException, + FactoryConfigurationError; + + protected void checkSpec(VMSpec spec) { + checkNotNull(spec, "VMSpec"); + checkNotNull(spec.getName(), "name"); + checkNotNull(spec.getNetworkTierName(), "networkTierName"); + } + + protected void addOperatingSystemAndVirtualHardware(VMSpec spec, XMLBuilder vAppBuilder) { + addOperatingSystemSection(vAppBuilder, spec.getOperatingSystem()); + // TODO: Savvis returns network names with a - instead of space on getNetworkInVDC + // call, + // fix this once savvis api starts returning correctly + addVirtualHardwareSection(vAppBuilder, spec.getName(), spec.getNetworkTierName().replace("-", " "), spec); + } + + void addVirtualHardwareSection(XMLBuilder rootBuilder, String name, String networkName, VMSpec spec) { + XMLBuilder virtualHardwareSectionBuilder = rootBuilder.e("ovf:VirtualHardwareSection"); + virtualHardwareSectionBuilder.e("ovf:Info").t("Virtual Hardware"); + addSystem(virtualHardwareSectionBuilder, name); + addItems(virtualHardwareSectionBuilder, spec, networkName); + } + + void addItems(XMLBuilder virtualHardwareSectionBuilder, VMSpec spec, String networkName) { + // todo make this work with fractional, which I think means setting speed to half + addCPU(virtualHardwareSectionBuilder, (int) spec.getProcessorCount()); + addMemory(virtualHardwareSectionBuilder, spec.getMemoryInGig()); + addNetwork(virtualHardwareSectionBuilder, networkName); + addDisks(virtualHardwareSectionBuilder, spec); + } + + private void addSystem(XMLBuilder virtualHardwareSectionBuilder, String name) { + XMLBuilder systemBuilder = virtualHardwareSectionBuilder.e("ovf:System"); + systemBuilder.e("vssd:Description").t("Virtual Hardware Family"); + systemBuilder.e("vssd:ElementName").t(name); + systemBuilder.e("vssd:InstanceID").t("1"); + systemBuilder.e("vssd:VirtualSystemIdentifier").t(name); + } + + private void addOperatingSystemSection(XMLBuilder rootBuilder, CIMOperatingSystem operatingSystem) { + XMLBuilder sectionBuilder = rootBuilder.e("ovf:OperatingSystemSection").a("ovf:id", + operatingSystem.getOsType().getCode() + ""); + sectionBuilder.e("ovf:Info").t("Specifies the operating system installed"); + sectionBuilder.e("ovf:Description").t(operatingSystem.getDescription()); + } + + private void addCPU(XMLBuilder sectionBuilder, int processorCount) { + XMLBuilder cpuBuilder = sectionBuilder.e("ovf:Item"); + cpuBuilder.e("rasd:AllocationUnits").t("3 GHz"); + cpuBuilder.e("rasd:Description").t("Number of Virtual CPUs"); + cpuBuilder.e("rasd:ElementName").t(processorCount + " CPU"); + cpuBuilder.e("rasd:InstanceID").t("1"); + cpuBuilder.e("rasd:ResourceType").t(ResourceType.PROCESSOR.value()); + cpuBuilder.e("rasd:VirtualQuantity").t(processorCount + ""); + } + + private void addMemory(XMLBuilder sectionBuilder, int memoryInGig) { + XMLBuilder memoryBuilder = sectionBuilder.e("ovf:Item"); + memoryBuilder.e("rasd:AllocationUnits").t("Gigabytes"); + memoryBuilder.e("rasd:Description").t("Memory Size"); + memoryBuilder.e("rasd:ElementName").t("Memory"); + memoryBuilder.e("rasd:InstanceID").t("2"); + memoryBuilder.e("rasd:ResourceType").t(ResourceType.MEMORY.value()); + memoryBuilder.e("rasd:VirtualQuantity").t(memoryInGig + ""); + } + + private void addNetwork(XMLBuilder sectionBuilder, String networkName) { + XMLBuilder networkBuilder = sectionBuilder.e("ovf:Item"); + networkBuilder.e("rasd:Caption").t("false"); + networkBuilder.e("rasd:Connection").t(networkName); + networkBuilder.e("rasd:ElementName").t("Network"); + networkBuilder.e("rasd:InstanceID").t("3"); + networkBuilder.e("rasd:ResourceType").t(ResourceType.ETHERNET_ADAPTER.value()); + networkBuilder.e("rasd:VirtualQuantity").t("1"); + } + + private void addDisks(XMLBuilder sectionBuilder, VMSpec spec) { + XMLBuilder bootDiskBuilder = sectionBuilder.e("ovf:Item"); + bootDiskBuilder.e("rasd:AllocationUnits").t("Gigabytes"); + bootDiskBuilder.e("rasd:Caption").t(""); + bootDiskBuilder.e("rasd:Description").t("Hard Disk"); + bootDiskBuilder.e("rasd:ElementName").t(spec.getBootDeviceName()); + bootDiskBuilder.e("rasd:HostResource").t("boot"); + bootDiskBuilder.e("rasd:InstanceID").t("4"); + bootDiskBuilder.e("rasd:ResourceType").t(ResourceType.BASE_PARTITIONABLE_UNIT.value()); + bootDiskBuilder.e("rasd:VirtualQuantity").t(spec.getBootDiskSize() + ""); + + int instanceId = 5; + for (Entry dataDisk : spec.getDataDiskDeviceNameToSizeInGig().entrySet()) { + XMLBuilder dataDiskBuilder = sectionBuilder.e("ovf:Item"); + dataDiskBuilder.e("rasd:AllocationUnits").t("Gigabytes"); + dataDiskBuilder.e("rasd:Caption").t(""); + dataDiskBuilder.e("rasd:Description").t("Hard Disk"); + dataDiskBuilder.e("rasd:ElementName").t(dataDisk.getKey()); + dataDiskBuilder.e("rasd:HostResource").t("data"); + dataDiskBuilder.e("rasd:InstanceID").t("" + instanceId++); + dataDiskBuilder.e("rasd:ResourceType").t(ResourceType.PARTITIONABLE_UNIT.value()); + dataDiskBuilder.e("rasd:VirtualQuantity").t(dataDisk.getValue() + ""); + } + } + + protected XMLBuilder buildRoot() throws ParserConfigurationException, FactoryConfigurationError { + XMLBuilder rootBuilder = XMLBuilder.create("vApp:VApp").a("xmlns:vApp", "http://www.vmware.com/vcloud/v0.8").a( + "xmlns:ovf", "http://schemas.dmtf.org/ovf/envelope/1").a("xmlns:vssd", + "http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_VirtualSystemSettingData").a("xmlns:common", + "http://schemas.dmtf.org/wbem/wscim/1/common").a("xmlns:rasd", + "http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData"); + return rootBuilder; + } + + protected XMLBuilder buildChildren(XMLBuilder rootBuilder) throws ParserConfigurationException, + FactoryConfigurationError { + XMLBuilder vAppChildrenBuilder = rootBuilder.e("vApp:Children"); + return vAppChildrenBuilder; + } + + protected XMLBuilder buildRootForName(XMLBuilder rootBuilder, String name) throws ParserConfigurationException, + FactoryConfigurationError { + XMLBuilder vAppBuilder = rootBuilder.e("vApp:VApp").a("name", name).a("type", + "application/vnd.vmware.vcloud.vApp+xml"); + return vAppBuilder; + } + + protected String ifNullDefaultTo(String value, String defaultValue) { + return value != null ? value : checkNotNull(defaultValue, "defaultValue"); + } + +} diff --git a/providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/binders/BindVMSpecToXmlPayload.java b/providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/binders/BindVMSpecToXmlPayload.java index c80178d6b9..a3e8a4f18e 100644 --- a/providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/binders/BindVMSpecToXmlPayload.java +++ b/providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/binders/BindVMSpecToXmlPayload.java @@ -18,26 +18,10 @@ */ package org.jclouds.savvis.vpdc.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 java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Properties; - import javax.inject.Singleton; -import javax.ws.rs.core.MediaType; import javax.xml.parsers.FactoryConfigurationError; import javax.xml.parsers.ParserConfigurationException; -import org.jclouds.cim.ResourceAllocationSettingData.ResourceType; -import org.jclouds.compute.domain.CIMOperatingSystem; -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.savvis.vpdc.domain.VMSpec; @@ -49,173 +33,23 @@ import com.jamesmurty.utils.XMLBuilder; * */ @Singleton -public class BindVMSpecToXmlPayload extends BindToStringPayload implements MapBinder { - @Override - public R bindToRequest(R request, Object toBind) { - throw new IllegalStateException("BindVMSpecToXmlPayload needs parameters"); +public class BindVMSpecToXmlPayload extends BaseBindVMSpecToXmlPayload { - } - - protected List findSpecInArgsOrNull(GeneratedHttpRequest gRequest) { + protected VMSpec findSpecInArgsOrNull(GeneratedHttpRequest gRequest) { for (Object arg : gRequest.getArgs()) { if (arg instanceof VMSpec) { - List vmSpecs = new ArrayList(); - vmSpecs.add((VMSpec) arg); - return vmSpecs; - } else if (arg instanceof ArrayList) { - List configurations = (List) arg; - return (configurations.size() > 0) ? configurations : null; + return VMSpec.class.cast(arg); } } - return null; + throw new IllegalArgumentException("Iterbable must be included in the argument list"); } @Override - public R bindToRequest(R request, Map postParams) { - 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"); - - request = super.bindToRequest(request, - generateXml(findSpecInArgsOrNull(gRequest))); - request.getPayload().getContentMetadata().setContentType(MediaType.APPLICATION_XML); - return request; - } - - public String generateXml(List specs) { - try { - XMLBuilder rootBuilder = buildRoot(); - XMLBuilder vAppChildrenBuilder = buildChildren(rootBuilder); - for (VMSpec spec : specs) { - checkNotNull(spec, "VMSpec"); - checkNotNull(spec.getName(), "name"); - checkNotNull(spec.getNetwork(), "network"); - checkNotNull(spec.getNetwork().getName(), "networkName"); - XMLBuilder vAppBuilder = buildRootForName(vAppChildrenBuilder, spec.getName()); - addOperatingSystemSection(vAppBuilder, spec.getOperatingSystem()); - // TODO: Savvis returns network names with a - instead of space on getNetworkInVDC call, - // fix this once savvis api starts returning correctly - addVirtualHardwareSection(vAppBuilder, spec.getName(), spec.getNetwork().getName().replace("-", " "), spec); - } - Properties outputProperties = new Properties(); - outputProperties.put(javax.xml.transform.OutputKeys.OMIT_XML_DECLARATION, "yes"); - return rootBuilder.asString(outputProperties); - } catch (Exception e) { - return null; - } - } - - void addVirtualHardwareSection(XMLBuilder rootBuilder, String name, String networkName, VMSpec spec) { - XMLBuilder virtualHardwareSectionBuilder = rootBuilder.e("ovf:VirtualHardwareSection"); - virtualHardwareSectionBuilder.e("ovf:Info").t("Virtual Hardware"); - addSystem(virtualHardwareSectionBuilder, name); - addItems(virtualHardwareSectionBuilder, spec, networkName); - } - - void addItems(XMLBuilder virtualHardwareSectionBuilder, VMSpec spec, String networkName) { - //todo make this work with fractional, which I think means setting speed to half - addCPU(virtualHardwareSectionBuilder, (int)spec.getProcessorCount()); - addMemory(virtualHardwareSectionBuilder, spec.getMemoryInGig()); - addNetwork(virtualHardwareSectionBuilder, networkName); - addDisks(virtualHardwareSectionBuilder, spec); - } - - private void addSystem(XMLBuilder virtualHardwareSectionBuilder, String name) { - XMLBuilder systemBuilder = virtualHardwareSectionBuilder.e("ovf:System"); - systemBuilder.e("vssd:Description").t("Virtual Hardware Family"); - systemBuilder.e("vssd:ElementName").t(name); - systemBuilder.e("vssd:InstanceID").t("1"); - systemBuilder.e("vssd:VirtualSystemIdentifier").t(name); - } - - private void addOperatingSystemSection(XMLBuilder rootBuilder, CIMOperatingSystem operatingSystem) { - XMLBuilder sectionBuilder = rootBuilder.e("ovf:OperatingSystemSection").a("ovf:id", - operatingSystem.getOsType().getCode() + ""); - sectionBuilder.e("ovf:Info").t("Specifies the operating system installed"); - sectionBuilder.e("ovf:Description").t(operatingSystem.getDescription()); - } - - private void addCPU(XMLBuilder sectionBuilder, int processorCount) { - XMLBuilder cpuBuilder = sectionBuilder.e("ovf:Item"); - cpuBuilder.e("rasd:AllocationUnits").t("3 GHz"); - cpuBuilder.e("rasd:Description").t("Number of Virtual CPUs"); - cpuBuilder.e("rasd:ElementName").t(processorCount + " CPU"); - cpuBuilder.e("rasd:InstanceID").t("1"); - cpuBuilder.e("rasd:ResourceType").t(ResourceType.PROCESSOR.value()); - cpuBuilder.e("rasd:VirtualQuantity").t(processorCount + ""); - } - - private void addMemory(XMLBuilder sectionBuilder, int memoryInGig) { - XMLBuilder memoryBuilder = sectionBuilder.e("ovf:Item"); - memoryBuilder.e("rasd:AllocationUnits").t("Gigabytes"); - memoryBuilder.e("rasd:Description").t("Memory Size"); - memoryBuilder.e("rasd:ElementName").t("Memory"); - memoryBuilder.e("rasd:InstanceID").t("2"); - memoryBuilder.e("rasd:ResourceType").t(ResourceType.MEMORY.value()); - memoryBuilder.e("rasd:VirtualQuantity").t(memoryInGig + ""); - } - - private void addNetwork(XMLBuilder sectionBuilder, String networkName) { - XMLBuilder networkBuilder = sectionBuilder.e("ovf:Item"); - networkBuilder.e("rasd:Caption").t("false"); - networkBuilder.e("rasd:Connection").t(networkName); - networkBuilder.e("rasd:ElementName").t("Network"); - networkBuilder.e("rasd:InstanceID").t("3"); - networkBuilder.e("rasd:ResourceType").t(ResourceType.ETHERNET_ADAPTER.value()); - networkBuilder.e("rasd:VirtualQuantity").t("1"); - } - - private void addDisks(XMLBuilder sectionBuilder, VMSpec spec) { - XMLBuilder bootDiskBuilder = sectionBuilder.e("ovf:Item"); - bootDiskBuilder.e("rasd:AllocationUnits").t("Gigabytes"); - bootDiskBuilder.e("rasd:Caption").t(""); - bootDiskBuilder.e("rasd:Description").t("Hard Disk"); - bootDiskBuilder.e("rasd:ElementName").t(spec.getBootDeviceName()); - bootDiskBuilder.e("rasd:HostResource").t("boot"); - bootDiskBuilder.e("rasd:InstanceID").t("4"); - bootDiskBuilder.e("rasd:ResourceType").t(ResourceType.BASE_PARTITIONABLE_UNIT.value()); - bootDiskBuilder.e("rasd:VirtualQuantity").t(spec.getBootDiskSize() + ""); - - int instanceId = 5; - for (Entry dataDisk : spec.getDataDiskDeviceNameToSizeInGig().entrySet()) { - XMLBuilder dataDiskBuilder = sectionBuilder.e("ovf:Item"); - dataDiskBuilder.e("rasd:AllocationUnits").t("Gigabytes"); - dataDiskBuilder.e("rasd:Caption").t(""); - dataDiskBuilder.e("rasd:Description").t("Hard Disk"); - dataDiskBuilder.e("rasd:ElementName").t(dataDisk.getKey()); - dataDiskBuilder.e("rasd:HostResource").t("data"); - dataDiskBuilder.e("rasd:InstanceID").t("" + instanceId++); - dataDiskBuilder.e("rasd:ResourceType").t(ResourceType.PARTITIONABLE_UNIT.value()); - dataDiskBuilder.e("rasd:VirtualQuantity").t(dataDisk.getValue() + ""); - } - } - - protected XMLBuilder buildRoot() throws ParserConfigurationException, FactoryConfigurationError { - XMLBuilder rootBuilder = XMLBuilder.create("vApp:VApp") - .a("xmlns:vApp", "http://www.vmware.com/vcloud/v0.8") - .a("xmlns:ovf", "http://schemas.dmtf.org/ovf/envelope/1") - .a("xmlns:vssd", "http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_VirtualSystemSettingData") - .a("xmlns:common", "http://schemas.dmtf.org/wbem/wscim/1/common") - .a("xmlns:rasd", "http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData") - .a("name", ""); - return rootBuilder; - } - - protected XMLBuilder buildChildren(XMLBuilder rootBuilder) throws ParserConfigurationException, FactoryConfigurationError { - XMLBuilder vAppChildrenBuilder = rootBuilder.e("vApp:Children"); - return vAppChildrenBuilder; - } - - protected XMLBuilder buildRootForName(XMLBuilder rootBuilder, String name) throws ParserConfigurationException, FactoryConfigurationError { - XMLBuilder vAppBuilder = rootBuilder.e("vApp:VApp") - .a("name", name) - .a("type", "application/vnd.vmware.vcloud.vApp+xml"); - return vAppBuilder; - } - - protected String ifNullDefaultTo(String value, String defaultValue) { - return value != null ? value : checkNotNull(defaultValue, "defaultValue"); + protected void bindSpec(VMSpec spec, XMLBuilder rootBuilder) throws ParserConfigurationException, + FactoryConfigurationError { + checkSpec(spec); + rootBuilder.a("name", spec.getName()).a("type", "application/vnd.vmware.vcloud.vApp+xml").a("href", ""); + addOperatingSystemAndVirtualHardware(spec, rootBuilder); } } diff --git a/providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/binders/BindVMSpecsToXmlPayload.java b/providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/binders/BindVMSpecsToXmlPayload.java new file mode 100644 index 0000000000..583dc63716 --- /dev/null +++ b/providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/binders/BindVMSpecsToXmlPayload.java @@ -0,0 +1,64 @@ +/** + * + * 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.savvis.vpdc.binders; + +import static com.google.common.base.Preconditions.checkArgument; + +import javax.inject.Singleton; +import javax.xml.parsers.FactoryConfigurationError; +import javax.xml.parsers.ParserConfigurationException; + +import org.jclouds.rest.internal.GeneratedHttpRequest; +import org.jclouds.savvis.vpdc.domain.VMSpec; + +import com.google.common.collect.Iterables; +import com.jamesmurty.utils.XMLBuilder; + +/** + * + * @author Adrian Cole + * + */ +@Singleton +public class BindVMSpecsToXmlPayload extends BaseBindVMSpecToXmlPayload> { + + @SuppressWarnings("unchecked") + protected Iterable findSpecInArgsOrNull(GeneratedHttpRequest gRequest) { + for (Object arg : gRequest.getArgs()) { + if (arg instanceof Iterable) { + Iterable specs = (Iterable) arg; + checkArgument(Iterables.size(specs) > 0, + "At least one VMSpec must be included in the argument list"); + return specs; + } + } + throw new IllegalArgumentException("Iterbable must be included in the argument list"); + } + + @Override + protected void bindSpec(Iterable specs, XMLBuilder rootBuilder) throws ParserConfigurationException, FactoryConfigurationError { + rootBuilder.a("name", ""); + XMLBuilder specBuilder = buildChildren(rootBuilder); + for (VMSpec spec : specs) { + checkSpec(spec); + XMLBuilder vAppBuilder = buildRootForName(specBuilder, spec.getName()); + addOperatingSystemAndVirtualHardware(spec, vAppBuilder); + } + } +} diff --git a/providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/compute/strategy/VPDCComputeServiceAdapter.java b/providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/compute/strategy/VPDCComputeServiceAdapter.java index 37a133747f..e8f6e1bbee 100644 --- a/providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/compute/strategy/VPDCComputeServiceAdapter.java +++ b/providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/compute/strategy/VPDCComputeServiceAdapter.java @@ -85,6 +85,8 @@ public class VPDCComputeServiceAdapter implements ComputeServiceAdapter dataDriveDeviceNameToSizeInGig = Maps.newLinkedHashMap(); public Builder name(String name) { - this.name = checkNotNull(name, "name"); - return this; - } - - public Builder network(Network network) { - this.network = checkNotNull(network, "network"); - return this; + this.name = checkNotNull(name, "name"); + return this; } - + + public Builder networkTierName(String networkTierName) { + this.networkTierName = checkNotNull(networkTierName, "networkTierName"); + return this; + } + public Builder operatingSystem(CIMOperatingSystem operatingSystem) { this.operatingSystem = checkNotNull(operatingSystem, "operatingSystem"); return this; @@ -96,19 +96,19 @@ public class VMSpec { public Builder addDataDrives(Map dataDriveDeviceNameToSizeInGig) { this.dataDriveDeviceNameToSizeInGig = ImmutableMap.copyOf(checkNotNull(dataDriveDeviceNameToSizeInGig, - "dataDriveDeviceNameToSizeInGig")); + "dataDriveDeviceNameToSizeInGig")); return this; } public VMSpec build() { - return new VMSpec(name, network, operatingSystem, processorCount, memoryInGig, bootDeviceName, bootDriveSize, - dataDriveDeviceNameToSizeInGig); + return new VMSpec(name, networkTierName, operatingSystem, processorCount, memoryInGig, bootDeviceName, + bootDriveSize, dataDriveDeviceNameToSizeInGig); } public static Builder fromVMSpec(VMSpec in) { - return new Builder().operatingSystem(in.getOperatingSystem()).memoryInGig(in.getMemoryInGig()) - .bootDeviceName(in.getBootDeviceName()).bootDiskSize(in.getBootDiskSize()) - .addDataDrives(in.getDataDiskDeviceNameToSizeInGig()).processorCount(in.getProcessorCount()); + return new Builder().operatingSystem(in.getOperatingSystem()).memoryInGig(in.getMemoryInGig()).bootDeviceName( + in.getBootDeviceName()).bootDiskSize(in.getBootDiskSize()).addDataDrives( + in.getDataDiskDeviceNameToSizeInGig()).processorCount(in.getProcessorCount()); } } @@ -119,7 +119,7 @@ public class VMSpec { } private final String name; - private final Network network; + private final String networkTierName; private final CIMOperatingSystem operatingSystem; private final int processorCount; private final int memoryInGig; @@ -127,10 +127,11 @@ public class VMSpec { private final int bootDriveSize; private final Map dataDriveDeviceNameToSizeInGig; - protected VMSpec(String name, Network network, CIMOperatingSystem operatingSystem, int processorCount, int memoryInGig, String bootDeviceName, - int bootDriveSize, Map dataDriveDeviceNameToSizeInGig) { - this.name = name; - this.network = network; + protected VMSpec(String name, String networkTierName, CIMOperatingSystem operatingSystem, int processorCount, + int memoryInGig, String bootDeviceName, int bootDriveSize, + Map dataDriveDeviceNameToSizeInGig) { + this.name = name; + this.networkTierName = networkTierName; this.operatingSystem = checkNotNull(operatingSystem, "operatingSystem not specified"); checkProcessorCount(processorCount); this.processorCount = processorCount; @@ -140,16 +141,16 @@ public class VMSpec { checkArgument(bootDriveSize > 0, "bootDriveSize must be positive"); this.bootDriveSize = bootDriveSize; this.dataDriveDeviceNameToSizeInGig = ImmutableMap.copyOf(checkNotNull(dataDriveDeviceNameToSizeInGig, - "dataDriveDeviceNameToSizeInGig")); + "dataDriveDeviceNameToSizeInGig")); } public String getName() { - return name; - } + return name; + } - public Network getNetwork() { - return network; - } + public String getNetworkTierName() { + return networkTierName; + } public CIMOperatingSystem getOperatingSystem() { return operatingSystem; @@ -228,9 +229,10 @@ public class VMSpec { @Override public String toString() { - return "[name= " + name + ", operatingSystem=" + operatingSystem + ", processorCount=" + processorCount + ", memoryInGig=" - + memoryInGig + ", network=" + network.getName() + ", bootDeviceName=" + bootDeviceName + ", bootDriveSize=" + bootDriveSize - + ", dataDriveDeviceNameToSizeInGig=" + dataDriveDeviceNameToSizeInGig + "]"; + return "[name= " + name + ", operatingSystem=" + operatingSystem + ", processorCount=" + processorCount + + ", memoryInGig=" + memoryInGig + ", networkTierName=" + networkTierName + ", bootDeviceName=" + + bootDeviceName + ", bootDriveSize=" + bootDriveSize + ", dataDriveDeviceNameToSizeInGig=" + + dataDriveDeviceNameToSizeInGig + "]"; } } \ No newline at end of file diff --git a/providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/features/VMAsyncClient.java b/providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/features/VMAsyncClient.java index a1175f4420..02d71715bb 100644 --- a/providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/features/VMAsyncClient.java +++ b/providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/features/VMAsyncClient.java @@ -19,7 +19,6 @@ package org.jclouds.savvis.vpdc.features; import java.net.URI; -import java.util.List; import java.util.Set; import javax.annotation.Nullable; @@ -40,6 +39,7 @@ import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; import org.jclouds.savvis.vpdc.binders.BindCaptureVAppTemplateToXmlPayload; import org.jclouds.savvis.vpdc.binders.BindCloneVMToXmlPayload; import org.jclouds.savvis.vpdc.binders.BindVMSpecToXmlPayload; +import org.jclouds.savvis.vpdc.binders.BindVMSpecsToXmlPayload; import org.jclouds.savvis.vpdc.domain.Task; import org.jclouds.savvis.vpdc.domain.VMSpec; import org.jclouds.savvis.vpdc.filters.SetVCloudTokenCookie; @@ -68,8 +68,7 @@ public interface VMAsyncClient { @MapBinder(BindVMSpecToXmlPayload.class) ListenableFuture addVMIntoVDC( @PathParam("billingSiteId") @Nullable @ParamParser(DefaultOrgIfNull.class) String billingSiteId, - @PathParam("vpdcId") String vpdcId, @PayloadParam("networkName") String networkTierName, - @PayloadParam("name") String vAppName, VMSpec spec); + @PathParam("vpdcId") String vpdcId, VMSpec spec); /** * @see VMClient#addVMIntoVDC @@ -78,8 +77,18 @@ public interface VMAsyncClient { @XMLResponseParser(TaskHandler.class) @Path("vApp/") @MapBinder(BindVMSpecToXmlPayload.class) - ListenableFuture addVMIntoVDC(@EndpointParam URI vpdc, @PayloadParam("networkName") String networkTierName, - @PayloadParam("name") String vAppName, VMSpec spec); + ListenableFuture addVMIntoVDC(@EndpointParam URI vpdc, VMSpec spec); + + /** + * @see VMClient#addMultipleVMsIntoVDC + */ + @GET + @XMLResponseParser(TasksListHandler.class) + @Path("v{jclouds.api-version}/org/{billingSiteId}/vdc/{vpdcId}/vApp/") + @MapBinder(BindVMSpecsToXmlPayload.class) + ListenableFuture> addMultipleVMsIntoVDC( + @PathParam("billingSiteId") @Nullable @ParamParser(DefaultOrgIfNull.class) String billingSiteId, + @PathParam("vpdcId") String vpdcId, Iterable vmSpecs); /** * @see VMClient#addMultipleVMsIntoVDC @@ -87,8 +96,8 @@ public interface VMAsyncClient { @GET @XMLResponseParser(TasksListHandler.class) @Path("vApp/") - @MapBinder(BindVMSpecToXmlPayload.class) - ListenableFuture> addMultipleVMsIntoVDC(@EndpointParam URI vpdc, List vmSpecs); + @MapBinder(BindVMSpecsToXmlPayload.class) + ListenableFuture> addMultipleVMsIntoVDC(@EndpointParam URI vpdc, Iterable vmSpecs); /** * @see VMClient#captureVApp @@ -97,9 +106,10 @@ public interface VMAsyncClient { @XMLResponseParser(TaskHandler.class) @Path("v{jclouds.api-version}/org/{billingSiteId}/vdc/{vpdcId}/action/captureVApp") @MapBinder(BindCaptureVAppTemplateToXmlPayload.class) - ListenableFuture captureVApp(@PathParam("billingSiteId") @Nullable @ParamParser(DefaultOrgIfNull.class) String billingSiteId, - @PathParam("vpdcId") String vpdcId, URI vAppUri); - + ListenableFuture captureVApp( + @PathParam("billingSiteId") @Nullable @ParamParser(DefaultOrgIfNull.class) String billingSiteId, + @PathParam("vpdcId") String vpdcId, URI vAppUri); + /** * @see VMClient#cloneVApp */ @@ -107,9 +117,9 @@ public interface VMAsyncClient { @XMLResponseParser(TaskHandler.class) @Path("action/cloneVApp") @MapBinder(BindCloneVMToXmlPayload.class) - ListenableFuture cloneVApp(@EndpointParam URI vAppUri, @PayloadParam("name") String newVAppName, - @PayloadParam("networkTierName") String networkTierName); - + ListenableFuture cloneVApp(@EndpointParam URI vAppUri, @PayloadParam("name") String newVAppName, + @PayloadParam("networkTierName") String networkTierName); + /** * @see VMClient#removeVMFromVDC */ @@ -128,7 +138,7 @@ public interface VMAsyncClient { @XMLResponseParser(TaskHandler.class) @ExceptionParser(ReturnNullOnNotFoundOr404.class) ListenableFuture removeVM(@EndpointParam URI vm); - + /** * @see VMClient#powerOffVM */ @@ -137,7 +147,7 @@ public interface VMAsyncClient { @Path("action/powerOff") @ExceptionParser(ReturnNullOnNotFoundOr404.class) ListenableFuture powerOffVM(@EndpointParam URI vm); - + /** * @see VMClient#powerOnVM */ diff --git a/providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/features/VMClient.java b/providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/features/VMClient.java index 086d4120b7..c94038d527 100644 --- a/providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/features/VMClient.java +++ b/providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/features/VMClient.java @@ -19,7 +19,6 @@ package org.jclouds.savvis.vpdc.features; import java.net.URI; -import java.util.List; import java.util.Set; import java.util.concurrent.TimeUnit; @@ -44,14 +43,12 @@ public interface VMClient { * billing site Id, or null for default * @param vpdcId * vpdc Id - * @param networkTierName - * network tier name * @param spec * how to * * @return VM in progress */ - Task addVMIntoVDC(String billingSiteId, String vpdcId, String networkTierName, String name, VMSpec spec); + Task addVMIntoVDC(String billingSiteId, String vpdcId, VMSpec spec); /** * @@ -59,43 +56,56 @@ public interface VMClient { * href of the vpdc * @see #addVMIntoVDC */ - Task addVMIntoVDC(URI vpdc, String networkTierName, String name, VMSpec spec); - + Task addVMIntoVDC(URI vpdc, VMSpec spec); + /** + * Add/Deploy new VMs into VDC + * + * @param billingSiteId + * billing site Id, or null for default + * @param vpdcId + * vpdc Id + * @param vmSpecs + * vm configurations + * @return VM's in progress + */ + Set addMultipleVMsIntoVDC(String billingSiteId, String vpdcId, Iterable vmSpecs); + + /** + * Add/Deploy new VMs into VDC * * @param vpdc * href of the vpdc * @param vmSpecs - * vm configurations + * vm configurations * @return VM's in progress */ - Set addMultipleVMsIntoVDC(URI vpdc, List vmSpecs); + Set addMultipleVMsIntoVDC(URI vpdc, Iterable vmSpecs); /** * - * @param billingSiteId + * @param billingSiteId * billing site Id, or null for default * @param vpdcId * vpdc Id * @param vAppUri - * href of the vApp - * @return - * Task with vAppTemplate href + * href of the vApp + * @return Task with vAppTemplate href */ Task captureVApp(String billingSiteId, String vpdcId, URI vAppUri); - + /** * * @param vAppUri - * href of the vApp + * href of the vApp * @param newVAppName - * name for the new vApp + * name for the new vApp * @param networkTierName - * network tier name for vApp + * network tier name for vApp * @return */ Task cloneVApp(URI vAppUri, String newVAppName, String networkTierName); - + /** * Remove a VM *

@@ -126,21 +136,21 @@ public interface VMClient { * @see #removeVMFromVDC */ Task removeVM(URI vm); - + /** * Power off a VM * * @param vm - * href of the vm + * href of the vm * @return */ Task powerOffVM(URI vm); - + /** * Power on a VM * * @param vm - * href of the vm + * href of the vm * @return */ Task powerOnVM(URI vm); diff --git a/providers/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/binders/BindVMSpecToXmlPayloadTest.java b/providers/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/binders/BindVMSpecsToXmlPayloadTest.java similarity index 70% rename from providers/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/binders/BindVMSpecToXmlPayloadTest.java rename to providers/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/binders/BindVMSpecsToXmlPayloadTest.java index ad60d2bd90..6d3c49eeb9 100644 --- a/providers/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/binders/BindVMSpecToXmlPayloadTest.java +++ b/providers/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/binders/BindVMSpecsToXmlPayloadTest.java @@ -21,36 +21,34 @@ package org.jclouds.savvis.vpdc.binders; import static org.testng.Assert.assertEquals; import java.io.IOException; -import java.util.ArrayList; -import java.util.List; import java.util.Set; import org.jclouds.cim.OSType; import org.jclouds.compute.domain.CIMOperatingSystem; -import org.jclouds.savvis.vpdc.domain.Network; import org.jclouds.savvis.vpdc.domain.VMSpec; import org.jclouds.util.Strings2; import org.testng.annotations.Test; import com.google.common.base.Predicate; +import com.google.common.collect.ImmutableSet; import com.google.common.collect.Iterables; import com.google.gson.Gson; import com.google.inject.TypeLiteral; /** - * Tests behavior of {@code BindVMSpecToXmlPayload} + * Tests behavior of {@code BindVMSpecsToXmlPayload} * * @author Adrian Cole */ @Test(groups = "unit") -public class BindVMSpecToXmlPayloadTest { +public class BindVMSpecsToXmlPayloadTest { public void test() throws IOException { - CIMOperatingSystem os = Iterables.find(new Gson().> fromJson( - Strings2.toStringAndClose(getClass().getResourceAsStream( - "/savvis-symphonyvpdc/predefined_operatingsystems.json")), - new TypeLiteral>() { - }.getType()), new Predicate() { + CIMOperatingSystem os = Iterables.find(new Gson().> fromJson(Strings2 + .toStringAndClose(getClass() + .getResourceAsStream("/savvis-symphonyvpdc/predefined_operatingsystems.json")), + new TypeLiteral>() { + }.getType()), new Predicate() { @Override public boolean apply(CIMOperatingSystem arg0) { @@ -59,14 +57,10 @@ public class BindVMSpecToXmlPayloadTest { }); - Network network = Network.builder().name("VM Tier01").build(); - String expected = Strings2.toStringAndClose(getClass().getResourceAsStream("/vm-multiple-default.xml")); - VMSpec spec = VMSpec.builder().name("Test VM").operatingSystem(os).network(network).build(); - List specs = new ArrayList(); - specs.add(spec); - - assertEquals(new BindVMSpecToXmlPayload().generateXml(specs), expected); + VMSpec spec = VMSpec.builder().name("Test VM").operatingSystem(os).networkTierName("VM Tier01").build(); + + assertEquals(new BindVMSpecsToXmlPayload().generateXml(ImmutableSet.of(spec)), expected); } } diff --git a/providers/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/features/BrowsingAsyncClientTest.java b/providers/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/features/BrowsingAsyncClientTest.java index 4fd1ffa750..a18477b625 100644 --- a/providers/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/features/BrowsingAsyncClientTest.java +++ b/providers/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/features/BrowsingAsyncClientTest.java @@ -49,7 +49,7 @@ public class BrowsingAsyncClientTest extends BaseVPDCAsyncClientTest { - public void testAddFirewallRule() throws NoSuchMethodException, IOException{ - Method method = FirewallAsyncClient.class.getMethod("addFirewallRule", String.class, String.class, FirewallRule.class); - HttpRequest request = processor.createRequest(method, "11", "22", FirewallRule.builder().firewallType("SERVER_TIER_FIREWALL").isEnabled(true).source("internet") - .destination("VM Tier01").port("22").protocol("Tcp").policy("allow").description("Server Tier Firewall Rule").isLogged(false).build()); + public void testAddFirewallRule() throws NoSuchMethodException, IOException { + Method method = FirewallAsyncClient.class.getMethod("addFirewallRule", String.class, String.class, + FirewallRule.class); + HttpRequest request = processor.createRequest(method, "11", "22", FirewallRule.builder().firewallType( + "SERVER_TIER_FIREWALL").isEnabled(true).source("internet").destination("VM Tier01").port("22").protocol( + "Tcp").policy("allow").description("Server Tier Firewall Rule").isLogged(false).build()); - assertRequestLineEquals(request, "PUT https://api.symphonyvpdc.savvis.net/rest/api/v0.8/org/11/vdc/22/FirewallService/ HTTP/1.1"); - assertNonPayloadHeadersEqual(request, ""); - assertPayloadEquals(request, Strings2.toStringAndClose(getClass().getResourceAsStream("/firewallService-default.xml")), - "application/xml", false); + assertRequestLineEquals(request, + "PUT https://api.symphonyvpdc.savvis.net/vpdc/v1.0/org/11/vdc/22/FirewallService/ HTTP/1.1"); + assertNonPayloadHeadersEqual(request, ""); + assertPayloadEquals(request, Strings2.toStringAndClose(getClass().getResourceAsStream( + "/firewallService-default.xml")), "application/xml", false); - assertResponseParserClassEquals(method, request, ParseSax.class); - assertSaxResponseParserClassEquals(method, TaskHandler.class); + assertResponseParserClassEquals(method, request, ParseSax.class); + assertSaxResponseParserClassEquals(method, TaskHandler.class); - checkFilters(request); - } - - public void testDeleteFirewallRule() throws NoSuchMethodException, IOException{ - Method method = FirewallAsyncClient.class.getMethod("deleteFirewallRule", String.class, String.class, FirewallRule.class); - HttpRequest request = processor.createRequest(method, "11", "22", FirewallRule.builder().firewallType("SERVER_TIER_FIREWALL").isEnabled(true).source("internet") - .destination("VM Tier01").port("22").protocol("Tcp").policy("allow").description("Server Tier Firewall Rule").isLogged(false).build()); + checkFilters(request); + } - assertRequestLineEquals(request, "DELETE https://api.symphonyvpdc.savvis.net/rest/api/v0.8/org/11/vdc/22/FirewallService/ HTTP/1.1"); - assertNonPayloadHeadersEqual(request, ""); - assertPayloadEquals(request, Strings2.toStringAndClose(getClass().getResourceAsStream("/firewallService-default.xml")), - "application/xml", false); + public void testDeleteFirewallRule() throws NoSuchMethodException, IOException { + Method method = FirewallAsyncClient.class.getMethod("deleteFirewallRule", String.class, String.class, + FirewallRule.class); + HttpRequest request = processor.createRequest(method, "11", "22", FirewallRule.builder().firewallType( + "SERVER_TIER_FIREWALL").isEnabled(true).source("internet").destination("VM Tier01").port("22").protocol( + "Tcp").policy("allow").description("Server Tier Firewall Rule").isLogged(false).build()); - assertResponseParserClassEquals(method, request, ParseSax.class); - assertSaxResponseParserClassEquals(method, TaskHandler.class); - assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); + assertRequestLineEquals(request, + "DELETE https://api.symphonyvpdc.savvis.net/vpdc/v1.0/org/11/vdc/22/FirewallService/ HTTP/1.1"); + assertNonPayloadHeadersEqual(request, ""); + assertPayloadEquals(request, Strings2.toStringAndClose(getClass().getResourceAsStream( + "/firewallService-default.xml")), "application/xml", false); - checkFilters(request); - } + assertResponseParserClassEquals(method, request, ParseSax.class); + assertSaxResponseParserClassEquals(method, TaskHandler.class); + assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); + + checkFilters(request); + } @Override protected TypeLiteral> createTypeLiteral() { diff --git a/providers/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/features/ServiceManagementAsyncClientTest.java b/providers/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/features/ServiceManagementAsyncClientTest.java index b9bbe955e3..f4316579bb 100644 --- a/providers/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/features/ServiceManagementAsyncClientTest.java +++ b/providers/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/features/ServiceManagementAsyncClientTest.java @@ -51,7 +51,7 @@ public class ServiceManagementAsyncClientTest extends BaseVPDCAsyncClientTest { public void testAddVMIntoVDCURI() throws SecurityException, NoSuchMethodException, IOException { - Method method = VMAsyncClient.class - .getMethod("addVMIntoVDC", URI.class, String.class, String.class, VMSpec.class); + Method method = VMAsyncClient.class.getMethod("addVMIntoVDC", URI.class, VMSpec.class); CIMOperatingSystem os = Iterables.find(injector.getInstance(Key.get(new TypeLiteral>() { })), new Predicate() { @@ -63,8 +64,8 @@ public class VMAsyncClientTest extends BaseVPDCAsyncClientTest { }); HttpRequest request = processor.createRequest(method, URI - .create("https://api.symphonyvpdc.savvis.net/rest/api/v0.8/org/11/vdc/22"), "VM Tier01", "DemoHost-1", - VMSpec.builder().operatingSystem(os).build()); + .create("https://api.symphonyvpdc.savvis.net/rest/api/v0.8/org/11/vdc/22"), VMSpec.builder().name( + "DemoHost-1").networkTierName("VM Tier01").operatingSystem(os).build()); assertRequestLineEquals(request, "GET https://api.symphonyvpdc.savvis.net/rest/api/v0.8/org/11/vdc/22/vApp/ HTTP/1.1"); @@ -80,8 +81,7 @@ public class VMAsyncClientTest extends BaseVPDCAsyncClientTest { } public void testAddVMIntoVDC() throws SecurityException, NoSuchMethodException, IOException { - Method method = VMAsyncClient.class.getMethod("addVMIntoVDC", String.class, String.class, String.class, - String.class, VMSpec.class); + Method method = VMAsyncClient.class.getMethod("addVMIntoVDC", String.class, String.class, VMSpec.class); CIMOperatingSystem os = Iterables.find(injector.getInstance(Key.get(new TypeLiteral>() { })), new Predicate() { @@ -93,11 +93,10 @@ public class VMAsyncClientTest extends BaseVPDCAsyncClientTest { }); - HttpRequest request = processor.createRequest(method, "11", "22", "VM Tier01", "DemoHost-1", VMSpec.builder() - .operatingSystem(os).build()); + HttpRequest request = processor.createRequest(method, "11", "22", VMSpec.builder().operatingSystem(os).name( + "DemoHost-1").networkTierName("VM Tier01").build()); - assertRequestLineEquals(request, - "GET https://api.symphonyvpdc.savvis.net/rest/api/v0.8/org/11/vdc/22/vApp/ HTTP/1.1"); + assertRequestLineEquals(request, "GET https://api.symphonyvpdc.savvis.net/vpdc/v1.0/org/11/vdc/22/vApp/ HTTP/1.1"); assertNonPayloadHeadersEqual(request, ""); assertPayloadEquals(request, Strings2.toStringAndClose(getClass().getResourceAsStream("/vm-default.xml")), "application/xml", false); @@ -109,12 +108,71 @@ public class VMAsyncClientTest extends BaseVPDCAsyncClientTest { checkFilters(request); } + public void testAddMultipleVMsIntoVDCURI() throws SecurityException, NoSuchMethodException, IOException { + Method method = VMAsyncClient.class.getMethod("addMultipleVMsIntoVDC", URI.class, Iterable.class); + + CIMOperatingSystem os = Iterables.find(injector.getInstance(Key.get(new TypeLiteral>() { + })), new Predicate() { + + @Override + public boolean apply(CIMOperatingSystem arg0) { + return arg0.getOsType() == OSType.RHEL_64; + } + + }); + + HttpRequest request = processor.createRequest(method, URI + .create("https://api.symphonyvpdc.savvis.net/rest/api/v0.8/org/11/vdc/22"), ImmutableSet.of(VMSpec + .builder().name("Test VM").networkTierName("VM Tier01").operatingSystem(os).build())); + + assertRequestLineEquals(request, + "GET https://api.symphonyvpdc.savvis.net/rest/api/v0.8/org/11/vdc/22/vApp/ HTTP/1.1"); + assertNonPayloadHeadersEqual(request, ""); + assertPayloadEquals(request, Strings2.toStringAndClose(getClass().getResourceAsStream("/vm-multiple-default.xml")), + "application/xml", false); + + assertResponseParserClassEquals(method, request, ParseSax.class); + assertSaxResponseParserClassEquals(method, TasksListHandler.class); + assertExceptionParserClassEquals(method, MapHttp4xxCodesToExceptions.class); + + checkFilters(request); + } + + public void testAddMultipleVMsIntoVDC() throws SecurityException, NoSuchMethodException, IOException { + Method method = VMAsyncClient.class + .getMethod("addMultipleVMsIntoVDC", String.class, String.class, Iterable.class); + + CIMOperatingSystem os = Iterables.find(injector.getInstance(Key.get(new TypeLiteral>() { + })), new Predicate() { + + @Override + public boolean apply(CIMOperatingSystem arg0) { + return arg0.getOsType() == OSType.RHEL_64; + } + + }); + + HttpRequest request = processor.createRequest(method, "11", "22", ImmutableSet.of(VMSpec.builder() + .operatingSystem(os).name("Test VM").networkTierName("VM Tier01").build())); + + assertRequestLineEquals(request, "GET https://api.symphonyvpdc.savvis.net/vpdc/v1.0/org/11/vdc/22/vApp/ HTTP/1.1"); + assertNonPayloadHeadersEqual(request, ""); + assertPayloadEquals(request, Strings2.toStringAndClose(getClass().getResourceAsStream("/vm-multiple-default.xml")), + "application/xml", false); + + assertResponseParserClassEquals(method, request, ParseSax.class); + assertSaxResponseParserClassEquals(method, TasksListHandler.class); + assertExceptionParserClassEquals(method, MapHttp4xxCodesToExceptions.class); + + checkFilters(request); + } + public void testRemoveVMFromVDC() throws SecurityException, NoSuchMethodException, IOException { Method method = VMAsyncClient.class.getMethod("removeVMFromVDC", String.class, String.class, String.class); HttpRequest request = processor.createRequest(method, "11", "22", "33"); assertRequestLineEquals(request, - "DELETE https://api.symphonyvpdc.savvis.net/rest/api/v0.8/org/11/vdc/22/vApp/33 HTTP/1.1"); + "DELETE https://api.symphonyvpdc.savvis.net/vpdc/v1.0/org/11/vdc/22/vApp/33 HTTP/1.1"); assertNonPayloadHeadersEqual(request, ""); assertPayloadEquals(request, null, null, false); @@ -141,7 +199,7 @@ public class VMAsyncClientTest extends BaseVPDCAsyncClientTest { checkFilters(request); } - + public void testPowerOffVM() throws SecurityException, NoSuchMethodException, IOException { Method method = VMAsyncClient.class.getMethod("powerOffVM", URI.class); HttpRequest request = processor.createRequest(method, URI @@ -158,23 +216,23 @@ public class VMAsyncClientTest extends BaseVPDCAsyncClientTest { checkFilters(request); } - + public void testPowerOnVM() throws SecurityException, NoSuchMethodException, IOException { - Method method = VMAsyncClient.class.getMethod("powerOnVM", URI.class); - HttpRequest request = processor.createRequest(method, URI - .create("https://api.symphonyvpdc.savvis.net/rest/api/v0.8/org/11/vdc/22/vApp/33")); + Method method = VMAsyncClient.class.getMethod("powerOnVM", URI.class); + HttpRequest request = processor.createRequest(method, URI + .create("https://api.symphonyvpdc.savvis.net/rest/api/v0.8/org/11/vdc/22/vApp/33")); - assertRequestLineEquals(request, - "POST https://api.symphonyvpdc.savvis.net/rest/api/v0.8/org/11/vdc/22/vApp/33/action/powerOn HTTP/1.1"); - assertNonPayloadHeadersEqual(request, ""); - assertPayloadEquals(request, null, null, false); + assertRequestLineEquals(request, + "POST https://api.symphonyvpdc.savvis.net/rest/api/v0.8/org/11/vdc/22/vApp/33/action/powerOn HTTP/1.1"); + assertNonPayloadHeadersEqual(request, ""); + assertPayloadEquals(request, null, null, false); - assertResponseParserClassEquals(method, request, ParseSax.class); - assertSaxResponseParserClassEquals(method, TaskHandler.class); - assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); + assertResponseParserClassEquals(method, request, ParseSax.class); + assertSaxResponseParserClassEquals(method, TaskHandler.class); + assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); - checkFilters(request); - } + checkFilters(request); + } @Override protected TypeLiteral> createTypeLiteral() { diff --git a/providers/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/features/VMClientLiveTest.java b/providers/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/features/VMClientLiveTest.java index 78a5747e06..1a6bc1eb18 100644 --- a/providers/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/features/VMClientLiveTest.java +++ b/providers/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/features/VMClientLiveTest.java @@ -22,8 +22,6 @@ import static com.google.common.base.Preconditions.checkNotNull; import static org.testng.Assert.assertEquals; import java.net.URI; -import java.util.ArrayList; -import java.util.List; import java.util.Set; import java.util.concurrent.TimeUnit; @@ -39,8 +37,8 @@ import org.jclouds.savvis.vpdc.domain.Resource; import org.jclouds.savvis.vpdc.domain.Task; import org.jclouds.savvis.vpdc.domain.VDC; import org.jclouds.savvis.vpdc.domain.VM; -import org.jclouds.savvis.vpdc.domain.VM.Status; import org.jclouds.savvis.vpdc.domain.VMSpec; +import org.jclouds.savvis.vpdc.domain.VM.Status; import org.jclouds.savvis.vpdc.options.GetVMOptions; import org.jclouds.savvis.vpdc.reference.VCloudMediaType; import org.jclouds.ssh.SshClient; @@ -50,7 +48,9 @@ import org.testng.annotations.BeforeGroups; import org.testng.annotations.Test; import com.google.common.base.Predicate; +import com.google.common.collect.ImmutableSet; import com.google.common.collect.Iterables; +import com.google.common.collect.ImmutableSet.Builder; import com.google.common.net.HostSpecifier; @Test(groups = "live") @@ -59,7 +59,7 @@ public class VMClientLiveTest extends BaseVPDCClientLiveTest { private VMClient client; private VM vm; private RetryablePredicate socketTester; - + private String username = checkNotNull(System.getProperty("test." + provider + ".loginUser"), "test." + provider + ".loginUser"); private String password = checkNotNull(System.getProperty("test." + provider + ".loginPassword"), "test." + provider @@ -118,8 +118,8 @@ public class VMClientLiveTest extends BaseVPDCClientLiveTest { // TODO: determine the sizes available in the VDC, for example there's // a minimum size of boot disk, and also a preset combination of cpu count vs ram - Task task = client.addVMIntoVDC(billingSiteId, vpdcId, networkTierName, name, VMSpec.builder() - .operatingSystem(os).memoryInGig(2).addDataDrive("/data01", 25).build()); + Task task = client.addVMIntoVDC(billingSiteId, vpdcId, VMSpec.builder().name(name).networkTierName( + networkTierName).operatingSystem(os).memoryInGig(2).addDataDrive("/data01", 25).build()); // make sure there's no error assert task.getId() != null && task.getError() == null : task; @@ -139,9 +139,9 @@ public class VMClientLiveTest extends BaseVPDCClientLiveTest { // the jclouds-wire.log @Override public boolean apply(Resource arg0) { - String description = restContext.getApi().getBrowsingClient().getVDCInOrg(billingSiteId, - arg0.getId()).getDescription(); - return description.indexOf(email) != -1; + String description = restContext.getApi().getBrowsingClient().getVDCInOrg(billingSiteId, + arg0.getId()).getDescription(); + return description.indexOf(email) != -1; } }).getId(); @@ -149,8 +149,9 @@ public class VMClientLiveTest extends BaseVPDCClientLiveTest { String networkTierName = Iterables.get( restContext.getApi().getBrowsingClient().getVDCInOrg(billingSiteId, vpdcId).getAvailableNetworks(), 0) .getId(); - Network networkTier = restContext.getApi().getBrowsingClient().getNetworkInVDC(billingSiteId, vpdcId, networkTierName); - + Network networkTier = restContext.getApi().getBrowsingClient().getNetworkInVDC(billingSiteId, vpdcId, + networkTierName); + String name = prefix; // delete any old VM @@ -164,32 +165,34 @@ public class VMClientLiveTest extends BaseVPDCClientLiveTest { } }); - - // TODO: Savvis returns network names with a - instead of space on getNetworkInVDC call, - // fix this once savvis api starts returning correctly - System.out.printf("vpdcId %s, vpdcName %s, networkName %s, name %s, os %s%n", vpdcId, vpdc.getName(), networkTier.getName().replace("-", " "), name, os); - List vmSpecs = new ArrayList(); + // TODO: Savvis returns network names with a - instead of space on getNetworkInVDC call, + // fix this once savvis api starts returning correctly + System.out.printf("vpdcId %s, vpdcName %s, networkName %s, name %s, os %s%n", vpdcId, vpdc.getName(), networkTier + .getName().replace("-", " "), name, os); + + Builder vmSpecs = ImmutableSet. builder(); int noOfVms = 2; for (int i = 0; i < noOfVms; i++) { - // TODO: determine the sizes available in the VDC, for example there's - // a minimum size of boot disk, and also a preset combination of cpu count vs ram - VMSpec vmSpec = VMSpec.builder().name(name + i).operatingSystem(os).memoryInGig(2).network(networkTier).addDataDrive("/data01", 25).build(); - vmSpecs.add(vmSpec); + // TODO: determine the sizes available in the VDC, for example there's + // a minimum size of boot disk, and also a preset combination of cpu count vs ram + VMSpec vmSpec = VMSpec.builder().name(name + i).operatingSystem(os).memoryInGig(2).networkTierName( + networkTierName).addDataDrive("/data01", 25).build(); + vmSpecs.add(vmSpec); } - - Set tasks = client.addMultipleVMsIntoVDC(vpdc.getHref(), vmSpecs); - + + Set tasks = client.addMultipleVMsIntoVDC(vpdc.getHref(), vmSpecs.build()); + for (Task task : tasks) { - // make sure there's no error - assert task.getId() != null && task.getError() == null : task; - - assert this.taskTester.apply(task.getId()); + // make sure there's no error + assert task.getId() != null && task.getError() == null : task; + + assert this.taskTester.apply(task.getId()); } } - + public void testCaptureVAppTemplate() throws Exception { - billingSiteId = restContext.getApi().getBrowsingClient().getOrg(null).getId();// default + billingSiteId = restContext.getApi().getBrowsingClient().getOrg(null).getId();// default vpdcId = Iterables.find(restContext.getApi().getBrowsingClient().getOrg(billingSiteId).getVDCs(), new Predicate() { @@ -198,36 +201,36 @@ public class VMClientLiveTest extends BaseVPDCClientLiveTest { // the jclouds-wire.log @Override public boolean apply(Resource arg0) { - String description = restContext.getApi().getBrowsingClient().getVDCInOrg(billingSiteId, - arg0.getId()).getDescription(); - return description.indexOf(email) != -1; + String description = restContext.getApi().getBrowsingClient().getVDCInOrg(billingSiteId, + arg0.getId()).getDescription(); + return description.indexOf(email) != -1; } }).getId(); - VDC vpdc = restContext.getApi().getBrowsingClient().getVDCInOrg(billingSiteId, vpdcId); - - for (Resource vApp : Iterables.filter(vpdc.getResourceEntities(), new Predicate() { + VDC vpdc = restContext.getApi().getBrowsingClient().getVDCInOrg(billingSiteId, vpdcId); - @Override - public boolean apply(Resource arg0) { - return VCloudMediaType.VAPP_XML.equals(arg0.getType()); - } + for (Resource vApp : Iterables.filter(vpdc.getResourceEntities(), new Predicate() { - })) { - - System.out.printf("Capturing VAppTemplate for vApp - %s%n", vApp.getName()); - Task task = client.captureVApp(billingSiteId, vpdcId, vApp.getHref()); - - // make sure there's no error - assert task.getId() != null && task.getError() == null : task; + @Override + public boolean apply(Resource arg0) { + return VCloudMediaType.VAPP_XML.equals(arg0.getType()); + } - assert this.taskTester.apply(task.getId()); - } + })) { + + System.out.printf("Capturing VAppTemplate for vApp - %s%n", vApp.getName()); + Task task = client.captureVApp(billingSiteId, vpdcId, vApp.getHref()); + + // make sure there's no error + assert task.getId() != null && task.getError() == null : task; + + assert this.taskTester.apply(task.getId()); + } } - + public void testCloneVApp() throws Exception { - billingSiteId = restContext.getApi().getBrowsingClient().getOrg(null).getId();// default + billingSiteId = restContext.getApi().getBrowsingClient().getOrg(null).getId();// default vpdcId = Iterables.find(restContext.getApi().getBrowsingClient().getOrg(billingSiteId).getVDCs(), new Predicate() { @@ -236,37 +239,37 @@ public class VMClientLiveTest extends BaseVPDCClientLiveTest { // the jclouds-wire.log @Override public boolean apply(Resource arg0) { - String description = restContext.getApi().getBrowsingClient().getVDCInOrg(billingSiteId, - arg0.getId()).getDescription(); - return description.indexOf(email) != -1; + String description = restContext.getApi().getBrowsingClient().getVDCInOrg(billingSiteId, + arg0.getId()).getDescription(); + return description.indexOf(email) != -1; } }).getId(); - VDC vpdc = restContext.getApi().getBrowsingClient().getVDCInOrg(billingSiteId, vpdcId); - - String networkTierName = Iterables.get(vpdc.getAvailableNetworks(), 0).getId(); - - for (Resource vApp : Iterables.filter(vpdc.getResourceEntities(), new Predicate() { + VDC vpdc = restContext.getApi().getBrowsingClient().getVDCInOrg(billingSiteId, vpdcId); - @Override - public boolean apply(Resource arg0) { - return VCloudMediaType.VAPP_XML.equals(arg0.getType()); - } + String networkTierName = Iterables.get(vpdc.getAvailableNetworks(), 0).getId(); - })) { - - System.out.printf("Cloning VApp - %s%n", vApp.getName()); - - Task task = client.cloneVApp(vApp.getHref(), "clonedvm", networkTierName); - - // make sure there's no error - assert task.getId() != null && task.getError() == null : task; + for (Resource vApp : Iterables.filter(vpdc.getResourceEntities(), new Predicate() { - assert this.taskTester.apply(task.getId()); - } + @Override + public boolean apply(Resource arg0) { + return VCloudMediaType.VAPP_XML.equals(arg0.getType()); + } + + })) { + + System.out.printf("Cloning VApp - %s%n", vApp.getName()); + + Task task = client.cloneVApp(vApp.getHref(), "clonedvm", networkTierName); + + // make sure there's no error + assert task.getId() != null && task.getError() == null : task; + + assert this.taskTester.apply(task.getId()); + } } - + private void conditionallyCheckSSH() { String ip = Iterables.get(vm.getNetworkConnectionSections(), 0).getIpAddress(); assert HostSpecifier.isValid(ip); @@ -296,88 +299,88 @@ public class VMClientLiveTest extends BaseVPDCClientLiveTest { @Test(enabled = false) public void testPowerOffVM() throws Exception { - billingSiteId = restContext.getApi().getBrowsingClient().getOrg(null).getId();// default - vpdcId = Iterables.find(restContext.getApi().getBrowsingClient().getOrg(billingSiteId).getVDCs(), - new Predicate() { - - // try to find the first VDC owned by the current user - // check here for what the email property might be, or in - // the jclouds-wire.log - @Override - public boolean apply(Resource arg0) { - String description = restContext.getApi().getBrowsingClient().getVDCInOrg(billingSiteId, - arg0.getId()).getDescription(); - return description.indexOf(email) != -1; - } - - }).getId(); + billingSiteId = restContext.getApi().getBrowsingClient().getOrg(null).getId();// default + vpdcId = Iterables.find(restContext.getApi().getBrowsingClient().getOrg(billingSiteId).getVDCs(), + new Predicate() { + + // try to find the first VDC owned by the current user + // check here for what the email property might be, or in + // the jclouds-wire.log + @Override + public boolean apply(Resource arg0) { + String description = restContext.getApi().getBrowsingClient().getVDCInOrg(billingSiteId, + arg0.getId()).getDescription(); + return description.indexOf(email) != -1; + } + + }).getId(); VDC vpdc = restContext.getApi().getBrowsingClient().getVDCInOrg(billingSiteId, vpdcId); URI vmURI = Iterables.find(vpdc.getResourceEntities(), new Predicate() { - @Override - public boolean apply(Resource arg0) { - if(VCloudMediaType.VAPP_XML.equals(arg0.getType())){ - VM response1 = restContext.getApi().getBrowsingClient().getVM(arg0.getHref(), (GetVMOptions[]) null); - System.out.printf("powering off vm - %s%n", response1.getName()); - if(response1.getStatus().equals(Status.ON)){ - return true; - } - } - return false; - } - - }).getHref(); - + @Override + public boolean apply(Resource arg0) { + if (VCloudMediaType.VAPP_XML.equals(arg0.getType())) { + VM response1 = restContext.getApi().getBrowsingClient().getVM(arg0.getHref(), (GetVMOptions[]) null); + System.out.printf("powering off vm - %s%n", response1.getName()); + if (response1.getStatus().equals(Status.ON)) { + return true; + } + } + return false; + } + + }).getHref(); + Task task = client.powerOffVM(vmURI); - + // make sure there's no error assert task.getId() != null && task.getError() == null : task; assert this.taskTester.apply(task.getId()); } - + @Test(enabled = false) public void testPowerOnVM() throws Exception { - billingSiteId = restContext.getApi().getBrowsingClient().getOrg(null).getId();// default - vpdcId = Iterables.find(restContext.getApi().getBrowsingClient().getOrg(billingSiteId).getVDCs(), - new Predicate() { - - // try to find the first VDC owned by the current user - // check here for what the email property might be, or in - // the jclouds-wire.log - @Override - public boolean apply(Resource arg0) { - String description = restContext.getApi().getBrowsingClient().getVDCInOrg(billingSiteId, - arg0.getId()).getDescription(); - return description.indexOf(email) != -1; - } - - }).getId(); + billingSiteId = restContext.getApi().getBrowsingClient().getOrg(null).getId();// default + vpdcId = Iterables.find(restContext.getApi().getBrowsingClient().getOrg(billingSiteId).getVDCs(), + new Predicate() { + + // try to find the first VDC owned by the current user + // check here for what the email property might be, or in + // the jclouds-wire.log + @Override + public boolean apply(Resource arg0) { + String description = restContext.getApi().getBrowsingClient().getVDCInOrg(billingSiteId, + arg0.getId()).getDescription(); + return description.indexOf(email) != -1; + } + + }).getId(); VDC vpdc = restContext.getApi().getBrowsingClient().getVDCInOrg(billingSiteId, vpdcId); URI vmURI = Iterables.find(vpdc.getResourceEntities(), new Predicate() { - @Override - public boolean apply(Resource arg0) { - if(VCloudMediaType.VAPP_XML.equals(arg0.getType())){ - VM response1 = restContext.getApi().getBrowsingClient().getVM(arg0.getHref(), (GetVMOptions[]) null); - System.out.printf("powering on vm - %s%n", response1.getName()); - if(response1.getStatus().equals(Status.OFF)){ - return true; - } - } - return false; - } - - }).getHref(); - + @Override + public boolean apply(Resource arg0) { + if (VCloudMediaType.VAPP_XML.equals(arg0.getType())) { + VM response1 = restContext.getApi().getBrowsingClient().getVM(arg0.getHref(), (GetVMOptions[]) null); + System.out.printf("powering on vm - %s%n", response1.getName()); + if (response1.getStatus().equals(Status.OFF)) { + return true; + } + } + return false; + } + + }).getHref(); + Task task = client.powerOnVM(vmURI); - + // make sure there's no error assert task.getId() != null && task.getError() == null : task; assert this.taskTester.apply(task.getId()); } - + @AfterGroups(groups = "live") protected void tearDown() { if (vm != null) {