diff --git a/apis/vcloud/src/main/java/org/jclouds/vcloud/compute/functions/HardwareForVApp.java b/apis/vcloud/src/main/java/org/jclouds/vcloud/compute/functions/HardwareForVApp.java index 659a685b3c..e8be6187fd 100644 --- a/apis/vcloud/src/main/java/org/jclouds/vcloud/compute/functions/HardwareForVApp.java +++ b/apis/vcloud/src/main/java/org/jclouds/vcloud/compute/functions/HardwareForVApp.java @@ -62,7 +62,7 @@ public class HardwareForVApp implements Function { return null; VirtualHardwareSection hardware = vm.getVirtualHardwareSection(); - HardwareBuilder builder = rasdToHardwareBuilder.apply(hardware.getResourceAllocations()); + HardwareBuilder builder = rasdToHardwareBuilder.apply(hardware.getItems()); builder.location(findLocationForResource.apply(checkNotNull(from, "from").getVDC())); builder.ids(from.getHref().toASCIIString()).name(from.getName()).supportsImage( ImagePredicates.idEquals(from.getHref().toASCIIString())); diff --git a/apis/vcloud/src/main/java/org/jclouds/vcloud/compute/functions/HardwareForVAppTemplate.java b/apis/vcloud/src/main/java/org/jclouds/vcloud/compute/functions/HardwareForVAppTemplate.java index f190e19771..65c18c11bc 100644 --- a/apis/vcloud/src/main/java/org/jclouds/vcloud/compute/functions/HardwareForVAppTemplate.java +++ b/apis/vcloud/src/main/java/org/jclouds/vcloud/compute/functions/HardwareForVAppTemplate.java @@ -86,7 +86,7 @@ public class HardwareForVAppTemplate implements Function logger.warn("multiple hardware choices found. using first", ovf); } VirtualHardwareSection hardware = Iterables.get(ovf.getVirtualSystem().getVirtualHardwareSections(), 0); - HardwareBuilder builder = rasdToHardwareBuilder.apply(hardware.getResourceAllocations()); + HardwareBuilder builder = rasdToHardwareBuilder.apply(hardware.getItems()); builder.location(findLocationForResource.apply(checkNotNull(parent, "parent"))); builder.ids(from.getHref().toASCIIString()).name(from.getName()).supportsImage( ImagePredicates.idEquals(from.getHref().toASCIIString())); diff --git a/apis/vcloud/src/main/java/org/jclouds/vcloud/compute/util/VCloudComputeUtils.java b/apis/vcloud/src/main/java/org/jclouds/vcloud/compute/util/VCloudComputeUtils.java index a32d6445be..b44a76afc2 100644 --- a/apis/vcloud/src/main/java/org/jclouds/vcloud/compute/util/VCloudComputeUtils.java +++ b/apis/vcloud/src/main/java/org/jclouds/vcloud/compute/util/VCloudComputeUtils.java @@ -97,7 +97,7 @@ public class VCloudComputeUtils { ips.add(connection.getExternalIpAddress()); } } else { - for (ResourceAllocationSettingData net : filter(vm.getVirtualHardwareSection().getResourceAllocations(), + for (ResourceAllocationSettingData net : filter(vm.getVirtualHardwareSection().getItems(), CIMPredicates.resourceTypeIn(ResourceType.ETHERNET_ADAPTER))) { if (net instanceof VCloudNetworkAdapter) { VCloudNetworkAdapter vNet = VCloudNetworkAdapter.class.cast(net); diff --git a/apis/vcloud/src/main/java/org/jclouds/vcloud/xml/VCloudVirtualHardwareHandler.java b/apis/vcloud/src/main/java/org/jclouds/vcloud/xml/VCloudVirtualHardwareHandler.java index 63efc8c484..2156c76cfe 100644 --- a/apis/vcloud/src/main/java/org/jclouds/vcloud/xml/VCloudVirtualHardwareHandler.java +++ b/apis/vcloud/src/main/java/org/jclouds/vcloud/xml/VCloudVirtualHardwareHandler.java @@ -50,7 +50,7 @@ public class VCloudVirtualHardwareHandler extends ParseSax.HandlerWithResult processors) { - this.processors = ImmutableList.copyOf(checkNotNull(processors, "processors")); + this.processors = ImmutableList.copyOf(checkNotNull(processors, "processors")); return this; } @@ -59,6 +64,11 @@ public class HardwareBuilder extends ComputeMetadataBuilder { return this; } + public HardwareBuilder volume(Volume volume) { + this.volumes.add(checkNotNull(volume, "volume")); + return this; + } + public HardwareBuilder volumes(Iterable volumes) { this.volumes = ImmutableList.copyOf(checkNotNull(volumes, "volumes")); return this; @@ -112,14 +122,14 @@ public class HardwareBuilder extends ComputeMetadataBuilder { @Override public Hardware build() { return new HardwareImpl(providerId, name, id, location, uri, userMetadata, processors, ram, volumes, - supportsImage); + supportsImage); } @SuppressWarnings("unchecked") public static HardwareBuilder fromHardware(Hardware in) { - return new HardwareBuilder().id(in.getId()).providerId(in.getProviderId()).location(in.getLocation()) - .name(in.getName()).uri(in.getUri()).userMetadata(in.getUserMetadata()) - .processors(List.class.cast(in.getProcessors())).ram(in.getRam()).volumes(List.class.cast(in.getVolumes())) - .supportsImage(in.supportsImage()); + return new HardwareBuilder().id(in.getId()).providerId(in.getProviderId()).location(in.getLocation()).name( + in.getName()).uri(in.getUri()).userMetadata(in.getUserMetadata()).processors( + List.class.cast(in.getProcessors())).ram(in.getRam()).volumes(List.class.cast(in.getVolumes())) + .supportsImage(in.supportsImage()); } } \ No newline at end of file diff --git a/compute/src/main/java/org/jclouds/ovf/Configuration.java b/compute/src/main/java/org/jclouds/ovf/Configuration.java index 157970d2cf..fbb76e4e8a 100644 --- a/compute/src/main/java/org/jclouds/ovf/Configuration.java +++ b/compute/src/main/java/org/jclouds/ovf/Configuration.java @@ -61,7 +61,7 @@ public class Configuration { return new Configuration(id, label, description); } - public Builder fromNetwork(Configuration in) { + public Builder fromConfiguration(Configuration in) { return id(in.getId()).description(in.getDescription()).label(in.getLabel()); } } @@ -103,7 +103,7 @@ public class Configuration { @Override public String toString() { - return String.format("Configuration [id=%s, label=%s, description=%s]", id, label, description); + return String.format("[id=%s, label=%s, description=%s]", id, label, description); } public String getId() { diff --git a/compute/src/main/java/org/jclouds/ovf/Envelope.java b/compute/src/main/java/org/jclouds/ovf/Envelope.java index 34f19cf4b1..c585379d1b 100644 --- a/compute/src/main/java/org/jclouds/ovf/Envelope.java +++ b/compute/src/main/java/org/jclouds/ovf/Envelope.java @@ -19,21 +19,16 @@ package org.jclouds.ovf; -import static com.google.common.base.Preconditions.checkNotNull; +import org.jclouds.ovf.internal.BaseEnvelope; -import java.util.Set; - -import com.google.common.collect.ImmutableMultimap; -import com.google.common.collect.ImmutableSet; -import com.google.common.collect.LinkedHashMultimap; import com.google.common.collect.Multimap; -import com.google.common.collect.Sets; /** * @author Adrian Cole */ -public class Envelope { +public class Envelope extends BaseEnvelope { + @SuppressWarnings("unchecked") public static Builder builder() { return new Builder(); } @@ -45,71 +40,7 @@ public class Envelope { return new Builder().fromEnvelope(this); } - public static class Builder { - protected Set diskSections = Sets.newLinkedHashSet(); - protected Set networkSections = Sets.newLinkedHashSet(); - @SuppressWarnings("unchecked") - protected Multimap additionalSections = LinkedHashMultimap.create(); - protected VirtualSystem virtualSystem; - - /** - * @see Envelope#getDiskSections - */ - public Builder diskSection(DiskSection diskSection) { - this.diskSections.add(checkNotNull(diskSection, "diskSection")); - return this; - } - - /** - * @see Envelope#getDiskSections - */ - public Builder diskSections(Iterable diskSections) { - this.diskSections = ImmutableSet. copyOf(checkNotNull(diskSections, "diskSections")); - return this; - } - - /** - * @see Envelope#getNetworkSections - */ - public Builder networkSection(NetworkSection networkSection) { - this.networkSections.add(checkNotNull(networkSection, "networkSection")); - return this; - } - - /** - * @see Envelope#getNetworkSections - */ - public Builder networkSections(Iterable networkSections) { - this.networkSections = ImmutableSet. copyOf(checkNotNull(networkSections, "networkSections")); - return this; - } - - /** - * @see Envelope#getAdditionalSections - */ - @SuppressWarnings("unchecked") - public Builder additionalSection(String name, Section additionalSection) { - this.additionalSections.put(checkNotNull(name, "name"), checkNotNull(additionalSection, "additionalSection")); - return this; - } - - /** - * @see Envelope#getAdditionalSections - */ - @SuppressWarnings("unchecked") - public Builder additionalSections(Multimap additionalSections) { - this.additionalSections = ImmutableMultimap. copyOf(checkNotNull(additionalSections, - "additionalSections")); - return this; - } - - /** - * @see Envelope#getVirtualSystem - */ - public Builder virtualSystem(VirtualSystem virtualSystem) { - this.virtualSystem = virtualSystem; - return this; - } + public static class Builder extends BaseEnvelope.Builder { /** * {@inheritDoc} @@ -118,91 +49,78 @@ public class Envelope { return new Envelope(diskSections, networkSections, additionalSections, virtualSystem); } - public Builder fromEnvelope(Envelope in) { - return virtualSystem(in.getVirtualSystem()).diskSections(in.getDiskSections()) - .networkSections(networkSections).additionalSections(in.getAdditionalSections()); + /** + * {@inheritDoc} + */ + @SuppressWarnings("unchecked") + @Override + public Builder additionalSection(String name, Section additionalSection) { + return Builder.class.cast(super.additionalSection(name, additionalSection)); + } + + /** + * {@inheritDoc} + */ + @SuppressWarnings("unchecked") + @Override + public Builder additionalSections(Multimap additionalSections) { + return Builder.class.cast(super.additionalSections(additionalSections)); + } + + /** + * {@inheritDoc} + */ + @Override + public Builder diskSection(DiskSection diskSection) { + return Builder.class.cast(super.diskSection(diskSection)); + } + + /** + * {@inheritDoc} + */ + @Override + public Builder diskSections(Iterable diskSections) { + return Builder.class.cast(super.diskSections(diskSections)); + } + + /** + * {@inheritDoc} + */ + @Override + public Builder fromEnvelope(BaseEnvelope in) { + return Builder.class.cast(super.fromEnvelope(in)); + } + + /** + * {@inheritDoc} + */ + @Override + public Builder networkSection(NetworkSection networkSection) { + return Builder.class.cast(super.networkSection(networkSection)); + } + + /** + * {@inheritDoc} + */ + @Override + public Builder networkSections(Iterable networkSections) { + return Builder.class.cast(super.networkSections(networkSections)); + } + + /** + * {@inheritDoc} + */ + @Override + public Builder virtualSystem(VirtualSystem virtualSystem) { + return Builder.class.cast(super.virtualSystem(virtualSystem)); } } - private final Set diskSections; - private final Set networkSections; - @SuppressWarnings("unchecked") - private final Multimap additionalSections; - private final VirtualSystem virtualSystem; - @SuppressWarnings("unchecked") public Envelope(Iterable diskSections, Iterable networkSections, Multimap additionalSections, VirtualSystem virtualSystem) { - this.diskSections = ImmutableSet.copyOf(checkNotNull(diskSections, "diskSections")); - this.networkSections = ImmutableSet.copyOf(checkNotNull(networkSections, "networkSections")); - this.additionalSections = ImmutableMultimap.copyOf(checkNotNull(additionalSections, "additionalSections")); - this.virtualSystem = checkNotNull(virtualSystem, "virtualSystem"); + super(diskSections, networkSections, additionalSections, virtualSystem); } - public VirtualSystem getVirtualSystem() { - return virtualSystem; - } - - public Set getDiskSections() { - return diskSections; - } - - @SuppressWarnings("unchecked") - public Multimap getAdditionalSections() { - return additionalSections; - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((additionalSections == null) ? 0 : additionalSections.hashCode()); - result = prime * result + ((diskSections == null) ? 0 : diskSections.hashCode()); - result = prime * result + ((networkSections == null) ? 0 : networkSections.hashCode()); - result = prime * result + ((virtualSystem == null) ? 0 : virtualSystem.hashCode()); - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - Envelope other = (Envelope) obj; - if (additionalSections == null) { - if (other.additionalSections != null) - return false; - } else if (!additionalSections.equals(other.additionalSections)) - return false; - if (diskSections == null) { - if (other.diskSections != null) - return false; - } else if (!diskSections.equals(other.diskSections)) - return false; - if (networkSections == null) { - if (other.networkSections != null) - return false; - } else if (!networkSections.equals(other.networkSections)) - return false; - if (virtualSystem == null) { - if (other.virtualSystem != null) - return false; - } else if (!virtualSystem.equals(other.virtualSystem)) - return false; - return true; - } - - @Override - public String toString() { - return String.format("[diskSections=%s, networkSections=%s, additionalSections=%s, virtualSystem=%s]", - diskSections, networkSections, additionalSections, virtualSystem); - } - - public Set getNetworkSections() { - return networkSections; - } } \ No newline at end of file diff --git a/compute/src/main/java/org/jclouds/ovf/ProductSection.java b/compute/src/main/java/org/jclouds/ovf/ProductSection.java new file mode 100644 index 0000000000..8df5b4fec8 --- /dev/null +++ b/compute/src/main/java/org/jclouds/ovf/ProductSection.java @@ -0,0 +1,141 @@ +/** + * + * Copyright (C) 2010 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.ovf; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.util.Set; + +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Sets; + +/** + * The ProductSection element specifies product-information for an appliance, such as product name, + * version, and vendor. + * + * @author Adrian Cole + */ +public class ProductSection extends Section { + + @SuppressWarnings("unchecked") + public static Builder builder() { + return new Builder(); + } + + /** + * {@inheritDoc} + */ + @Override + public Builder toBuilder() { + return builder().fromDeploymentOptionSection(this); + } + + public static class Builder extends Section.Builder { + protected Set properties = Sets.newLinkedHashSet(); + + /** + * @see ProductSection#getPropertys + */ + public Builder property(Property property) { + this.properties.add(checkNotNull(property, "property")); + return this; + } + + /** + * @see ProductSection#getPropertys + */ + public Builder properties(Iterable properties) { + this.properties = ImmutableSet. copyOf(checkNotNull(properties, "properties")); + return this; + } + + /** + * {@inheritDoc} + */ + @Override + public ProductSection build() { + return new ProductSection(info, properties); + } + + public Builder fromDeploymentOptionSection(ProductSection in) { + return info(in.getInfo()).properties(in.getProperties()); + } + + /** + * {@inheritDoc} + */ + @Override + public Builder fromSection(Section in) { + return Builder.class.cast(super.fromSection(in)); + } + + /** + * {@inheritDoc} + */ + @Override + public Builder info(String info) { + return Builder.class.cast(super.info(info)); + } + + } + + protected final Set properties; + + public ProductSection(String info, Iterable properties) { + super(info); + this.properties = ImmutableSet. copyOf(checkNotNull(properties, "properties")); + + } + + @Override + public int hashCode() { + final int prime = 31; + int result = super.hashCode(); + result = prime * result + ((properties == null) ? 0 : properties.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (!super.equals(obj)) + return false; + if (getClass() != obj.getClass()) + return false; + ProductSection other = (ProductSection) obj; + if (properties == null) { + if (other.properties != null) + return false; + } else if (!properties.equals(other.properties)) + return false; + return true; + } + + @Override + public String toString() { + return String.format("[info=%s, properties=%s]", info, properties); + } + + public Set getProperties() { + return properties; + } + +} \ No newline at end of file diff --git a/compute/src/main/java/org/jclouds/ovf/Property.java b/compute/src/main/java/org/jclouds/ovf/Property.java new file mode 100644 index 0000000000..73d78ce041 --- /dev/null +++ b/compute/src/main/java/org/jclouds/ovf/Property.java @@ -0,0 +1,135 @@ +/** + * + * Copyright (C) 2010 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.ovf; + +/** + * + * @author Adrian Cole + */ +public class Property { + public static Builder builder() { + return new Builder(); + } + + public static class Builder { + protected String key; + protected String value; + protected String label; + protected String description; + + /** + * @see Property#getKey + */ + public Builder key(String key) { + this.key = key; + return this; + } + + /** + * @see Property#getValue + */ + public Builder value(String value) { + this.value = value; + return this; + } + + /** + * @see Section#getLabel + */ + public Builder label(String label) { + this.label = label; + return this; + } + + /** + * @see Section#getDescription + */ + public Builder description(String description) { + this.description = description; + return this; + } + + public Property build() { + return new Property(key, value, label, description); + } + + public Builder fromProperty(Property in) { + return key(in.getKey()).value(in.getValue()).description(in.getDescription()).label(in.getLabel()); + } + } + + private final String key; + private final String value; + private final String label; + private final String description; + + public Property(String key, String value, String label, String description) { + this.key = key; + this.value = value; + this.label = label; + this.description = description; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((key == null) ? 0 : key.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Property other = (Property) obj; + if (key == null) { + if (other.key != null) + return false; + } else if (!key.equals(other.key)) + return false; + return true; + } + + @Override + public String toString() { + return String.format("[key=%s, value=%s, label=%s, description=%s]", key, value, label, description); + } + + public String getKey() { + return key; + } + + public String getDescription() { + return description; + } + + public String getLabel() { + return label; + } + + public String getValue() { + return value; + } +} \ No newline at end of file diff --git a/compute/src/main/java/org/jclouds/ovf/VirtualHardwareSection.java b/compute/src/main/java/org/jclouds/ovf/VirtualHardwareSection.java index 7c6ad39551..db7b70d791 100644 --- a/compute/src/main/java/org/jclouds/ovf/VirtualHardwareSection.java +++ b/compute/src/main/java/org/jclouds/ovf/VirtualHardwareSection.java @@ -56,7 +56,7 @@ public class VirtualHardwareSection extends Section { public static class Builder extends Section.Builder { protected VirtualSystemSettingData virtualSystem; protected Set transports = Sets.newLinkedHashSet(); - protected Set resourceAllocations = Sets.newLinkedHashSet(); + protected Set items = Sets.newLinkedHashSet(); /** * @see VirtualHardwareSection#getSystem @@ -83,19 +83,19 @@ public class VirtualHardwareSection extends Section { } /** - * @see VirtualHardwareSection#getResourceAllocations + * @see VirtualHardwareSection#getItems */ - public Builder resourceAllocation(ResourceAllocationSettingData resourceAllocation) { - this.resourceAllocations.add(checkNotNull(resourceAllocation, "resourceAllocation")); + public Builder item(ResourceAllocationSettingData item) { + this.items.add(checkNotNull(item, "item")); return this; } /** - * @see VirtualHardwareSection#getResourceAllocations + * @see VirtualHardwareSection#getItems */ - public Builder resourceAllocations(Iterable resourceAllocations) { - this.resourceAllocations = ImmutableSet. copyOf(checkNotNull( - resourceAllocations, "resourceAllocations")); + public Builder items(Iterable items) { + this.items = ImmutableSet. copyOf(checkNotNull( + items, "items")); return this; } @@ -104,11 +104,11 @@ public class VirtualHardwareSection extends Section { */ @Override public VirtualHardwareSection build() { - return new VirtualHardwareSection(info, transports, virtualSystem, resourceAllocations); + return new VirtualHardwareSection(info, transports, virtualSystem, items); } public Builder fromVirtualHardwareSection(VirtualHardwareSection in) { - return resourceAllocations(in.getResourceAllocations()).transports(in.getTransports()).system( + return items(in.getItems()).transports(in.getTransports()).system( in.getSystem()).info(in.getInfo()); } @@ -132,15 +132,15 @@ public class VirtualHardwareSection extends Section { protected final VirtualSystemSettingData virtualSystem; protected final Set transports; - protected final Set resourceAllocations; + protected final Set items; public VirtualHardwareSection(String info, Iterable transports, VirtualSystemSettingData virtualSystem, - Iterable resourceAllocations) { + Iterable items) { super(info); this.virtualSystem = virtualSystem; this.transports = ImmutableSet. copyOf(checkNotNull(transports, "transports")); - this.resourceAllocations = ImmutableSet. copyOf(checkNotNull(resourceAllocations, - "resourceAllocations")); + this.items = ImmutableSet. copyOf(checkNotNull(items, + "items")); } /** @@ -168,15 +168,15 @@ public class VirtualHardwareSection extends Section { return virtualSystem; } - public Set getResourceAllocations() { - return resourceAllocations; + public Set getItems() { + return items; } @Override public int hashCode() { final int prime = 31; int result = super.hashCode(); - result = prime * result + ((resourceAllocations == null) ? 0 : resourceAllocations.hashCode()); + result = prime * result + ((items == null) ? 0 : items.hashCode()); result = prime * result + ((transports == null) ? 0 : transports.hashCode()); result = prime * result + ((virtualSystem == null) ? 0 : virtualSystem.hashCode()); return result; @@ -191,10 +191,10 @@ public class VirtualHardwareSection extends Section { if (getClass() != obj.getClass()) return false; VirtualHardwareSection other = (VirtualHardwareSection) obj; - if (resourceAllocations == null) { - if (other.resourceAllocations != null) + if (items == null) { + if (other.items != null) return false; - } else if (!resourceAllocations.equals(other.resourceAllocations)) + } else if (!items.equals(other.items)) return false; if (transports == null) { if (other.transports != null) @@ -211,8 +211,8 @@ public class VirtualHardwareSection extends Section { @Override public String toString() { - return String.format("[info=%s, resourceAllocations=%s, transports=%s, virtualSystem=%s]", info, - resourceAllocations, transports, virtualSystem); + return String.format("[info=%s, items=%s, transports=%s, virtualSystem=%s]", info, + items, transports, virtualSystem); } } \ No newline at end of file diff --git a/compute/src/main/java/org/jclouds/ovf/VirtualSystem.java b/compute/src/main/java/org/jclouds/ovf/VirtualSystem.java index 6eaaef5f84..c99eddb146 100644 --- a/compute/src/main/java/org/jclouds/ovf/VirtualSystem.java +++ b/compute/src/main/java/org/jclouds/ovf/VirtualSystem.java @@ -19,114 +19,42 @@ package org.jclouds.ovf; -import static com.google.common.base.Preconditions.checkNotNull; +import org.jclouds.ovf.internal.BaseVirtualSystem; -import java.util.Set; - -import com.google.common.collect.ImmutableMultimap; -import com.google.common.collect.ImmutableSet; -import com.google.common.collect.LinkedHashMultimap; import com.google.common.collect.Multimap; -import com.google.common.collect.Sets; /** * @author Adrian Cole */ -public class VirtualSystem extends Section { +public class VirtualSystem extends BaseVirtualSystem { - @SuppressWarnings("unchecked") - public static Builder builder() { - return new Builder(); - } - - /** - * {@inheritDoc} - */ - @Override - public Builder toBuilder() { - return new Builder().fromVirtualSystem(this); - } - - public static class Builder extends Section.Builder { - protected String id; - protected String name; - protected OperatingSystemSection operatingSystem; - protected Set hardwareSections = Sets.newLinkedHashSet(); - @SuppressWarnings("unchecked") - protected Multimap additionalSections = LinkedHashMultimap.create(); - - /** - * @see VirtualSystem#getName - */ - public Builder name(String name) { - this.name = name; - return this; - } - - /** - * @see VirtualSystem#getId - */ - public Builder id(String id) { - this.id = id; - return this; - } - - /** - * @see VirtualSystem#getOperatingSystemSection - */ - public Builder operatingSystemSection(OperatingSystemSection operatingSystem) { - this.operatingSystem = operatingSystem; - return this; - } - - /** - * @see VirtualSystem#getVirtualHardwareSections - */ - public Builder hardwareSection(VirtualHardwareSection hardwareSection) { - this.hardwareSections.add(checkNotNull(hardwareSection, "hardwareSection")); - return this; - } - - /** - * @see VirtualSystem#getVirtualHardwareSections - */ - public Builder hardwareSections(Iterable hardwareSections) { - this.hardwareSections = ImmutableSet. copyOf(checkNotNull(hardwareSections, - "hardwareSections")); - return this; - } - - /** - * @see VirtualSystem#getAdditionalSections - */ - @SuppressWarnings("unchecked") - public Builder additionalSection(String name, Section additionalSection) { - this.additionalSections.put(checkNotNull(name, "name"), checkNotNull(additionalSection, "additionalSection")); - return this; - } - - /** - * @see VirtualSystem#getAdditionalSections - */ - @SuppressWarnings("unchecked") - public Builder additionalSections(Multimap additionalSections) { - this.additionalSections = ImmutableMultimap. copyOf(checkNotNull(additionalSections, - "additionalSections")); - return this; - } + public static class Builder extends BaseVirtualSystem.Builder { /** * {@inheritDoc} */ @Override public VirtualSystem build() { - return new VirtualSystem(id, info, name, operatingSystem, hardwareSections, additionalSections); + return new VirtualSystem(id, info, name, operatingSystem, virtualHardwareSections, productSections, + additionalSections); } - public Builder fromVirtualSystem(VirtualSystem in) { - return fromSection(in).id(in.getId()).name(in.getName()) - .operatingSystemSection(in.getOperatingSystemSection()).hardwareSections( - in.getVirtualHardwareSections()).additionalSections(in.getAdditionalSections()); + /** + * {@inheritDoc} + */ + @SuppressWarnings("unchecked") + @Override + public Builder additionalSection(String name, Section additionalSection) { + return Builder.class.cast(super.additionalSection(name, additionalSection)); + } + + /** + * {@inheritDoc} + */ + @SuppressWarnings("unchecked") + @Override + public Builder additionalSections(Multimap additionalSections) { + return Builder.class.cast(super.additionalSections(additionalSections)); } /** @@ -134,7 +62,39 @@ public class VirtualSystem extends Section { */ @Override public Builder fromSection(Section in) { - return (Builder) super.fromSection(in); + return Builder.class.cast(super.fromSection(in)); + } + + /** + * {@inheritDoc} + */ + @Override + public Builder fromVirtualSystem(BaseVirtualSystem in) { + return Builder.class.cast(super.fromVirtualSystem(in)); + } + + /** + * {@inheritDoc} + */ + @Override + public Builder virtualHardwareSection(VirtualHardwareSection virtualHardwareSection) { + return Builder.class.cast(super.virtualHardwareSection(virtualHardwareSection)); + } + + /** + * {@inheritDoc} + */ + @Override + public Builder virtualHardwareSections(Iterable virtualHardwareSections) { + return Builder.class.cast(super.virtualHardwareSections(virtualHardwareSections)); + } + + /** + * {@inheritDoc} + */ + @Override + public Builder id(String id) { + return Builder.class.cast(super.id(id)); } /** @@ -142,82 +102,47 @@ public class VirtualSystem extends Section { */ @Override public Builder info(String info) { - return (Builder) super.info(info); + return Builder.class.cast(super.info(info)); + } + + /** + * {@inheritDoc} + */ + @Override + public Builder name(String name) { + return Builder.class.cast(super.name(name)); + } + + /** + * {@inheritDoc} + */ + @Override + public Builder operatingSystemSection(OperatingSystemSection operatingSystem) { + return Builder.class.cast(super.operatingSystemSection(operatingSystem)); + } + + /** + * {@inheritDoc} + */ + @Override + public Builder productSection(ProductSection productSection) { + return Builder.class.cast(super.productSection(productSection)); + } + + /** + * {@inheritDoc} + */ + @Override + public Builder productSections(Iterable productSections) { + return Builder.class.cast(super.productSections(productSections)); } } - private final String id; - private final String name; - private final OperatingSystemSection operatingSystem; - private final Set hardwareSections; - @SuppressWarnings("unchecked") - private final Multimap additionalSections; - @SuppressWarnings("unchecked") public VirtualSystem(String id, String info, String name, OperatingSystemSection operatingSystem, - Iterable hardwareSections, Multimap additionalSections) { - super(info); - this.id = id; - this.name = name; - this.operatingSystem = checkNotNull(operatingSystem, "operatingSystem"); - this.hardwareSections = ImmutableSet.copyOf(checkNotNull(hardwareSections, "hardwareSections")); - this.additionalSections = ImmutableMultimap.copyOf(checkNotNull(additionalSections, "additionalSections")); - } - - public String getId() { - return id; - } - - public String getName() { - return name; - } - - public OperatingSystemSection getOperatingSystemSection() { - return operatingSystem; - } - - /** - * Each VirtualSystem element may contain one or more VirtualHardwareSection elements, each of - * which describes the virtual hardwareSections required by the virtual system. - * */ - public Set getVirtualHardwareSections() { - return hardwareSections; - } - - @SuppressWarnings("unchecked") - public Multimap getAdditionalSections() { - return additionalSections; - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((id == null) ? 0 : id.hashCode()); - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - VirtualSystem other = (VirtualSystem) obj; - if (id == null) { - if (other.id != null) - return false; - } else if (!id.equals(other.id)) - return false; - return true; - } - - @Override - public String toString() { - return String.format("[id=%s, name=%s, info=%s, operatingSystem=%s, hardwareSections=%s, additionalSections=%s]", - id, name, info, operatingSystem, hardwareSections, additionalSections); + Iterable virtualHardwareSections, + Iterable productSections, Multimap additionalSections) { + super(id, info, name, operatingSystem, virtualHardwareSections, productSections, additionalSections); } } \ No newline at end of file diff --git a/compute/src/main/java/org/jclouds/ovf/internal/BaseEnvelope.java b/compute/src/main/java/org/jclouds/ovf/internal/BaseEnvelope.java new file mode 100644 index 0000000000..595eb2a2bc --- /dev/null +++ b/compute/src/main/java/org/jclouds/ovf/internal/BaseEnvelope.java @@ -0,0 +1,213 @@ +/** + * + * Copyright (C) 2010 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.ovf.internal; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.util.Set; + +import org.jclouds.ovf.DiskSection; +import org.jclouds.ovf.NetworkSection; +import org.jclouds.ovf.Section; + +import com.google.common.collect.ImmutableMultimap; +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.LinkedHashMultimap; +import com.google.common.collect.Multimap; +import com.google.common.collect.Sets; + +/** + * @author Adrian Cole + */ +public class BaseEnvelope, E extends BaseEnvelope> { + + public static , E extends BaseEnvelope> Builder builder() { + return new Builder(); + } + + /** + * {@inheritDoc} + */ + public Builder toBuilder() { + return new Builder().fromEnvelope(this); + } + + public static class Builder, E extends BaseEnvelope> { + protected Set diskSections = Sets.newLinkedHashSet(); + protected Set networkSections = Sets.newLinkedHashSet(); + @SuppressWarnings("unchecked") + protected Multimap additionalSections = LinkedHashMultimap.create(); + protected V virtualSystem; + + /** + * @see BaseEnvelope#getDiskSections + */ + public Builder diskSection(DiskSection diskSection) { + this.diskSections.add(checkNotNull(diskSection, "diskSection")); + return this; + } + + /** + * @see BaseEnvelope#getDiskSections + */ + public Builder diskSections(Iterable diskSections) { + this.diskSections = ImmutableSet. copyOf(checkNotNull(diskSections, "diskSections")); + return this; + } + + /** + * @see BaseEnvelope#getNetworkSections + */ + public Builder networkSection(NetworkSection networkSection) { + this.networkSections.add(checkNotNull(networkSection, "networkSection")); + return this; + } + + /** + * @see BaseEnvelope#getNetworkSections + */ + public Builder networkSections(Iterable networkSections) { + this.networkSections = ImmutableSet. copyOf(checkNotNull(networkSections, "networkSections")); + return this; + } + + /** + * @see BaseEnvelope#getAdditionalSections + */ + @SuppressWarnings("unchecked") + public Builder additionalSection(String name, Section additionalSection) { + this.additionalSections.put(checkNotNull(name, "name"), checkNotNull(additionalSection, "additionalSection")); + return this; + } + + /** + * @see BaseEnvelope#getAdditionalSections + */ + @SuppressWarnings("unchecked") + public Builder additionalSections(Multimap additionalSections) { + this.additionalSections = ImmutableMultimap. copyOf(checkNotNull(additionalSections, + "additionalSections")); + return this; + } + + /** + * @see BaseEnvelope#getVirtualSystem + */ + public Builder virtualSystem(V virtualSystem) { + this.virtualSystem = virtualSystem; + return this; + } + + /** + * {@inheritDoc} + */ + @SuppressWarnings("unchecked") + public E build() { + return (E) new BaseEnvelope(diskSections, networkSections, additionalSections, virtualSystem); + } + + public Builder fromEnvelope(BaseEnvelope in) { + return virtualSystem(in.getVirtualSystem()).diskSections(in.getDiskSections()) + .networkSections(networkSections).additionalSections(in.getAdditionalSections()); + } + + } + + private final Set diskSections; + private final Set networkSections; + @SuppressWarnings("unchecked") + private final Multimap additionalSections; + private final V virtualSystem; + + @SuppressWarnings("unchecked") + public BaseEnvelope(Iterable diskSections, Iterable networkSections, + Multimap additionalSections, V virtualSystem) { + this.diskSections = ImmutableSet.copyOf(checkNotNull(diskSections, "diskSections")); + this.networkSections = ImmutableSet.copyOf(checkNotNull(networkSections, "networkSections")); + this.additionalSections = ImmutableMultimap.copyOf(checkNotNull(additionalSections, "additionalSections")); + this.virtualSystem = checkNotNull(virtualSystem, "virtualSystem"); + } + + public V getVirtualSystem() { + return virtualSystem; + } + + public Set getDiskSections() { + return diskSections; + } + + @SuppressWarnings("unchecked") + public Multimap getAdditionalSections() { + return additionalSections; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((additionalSections == null) ? 0 : additionalSections.hashCode()); + result = prime * result + ((diskSections == null) ? 0 : diskSections.hashCode()); + result = prime * result + ((networkSections == null) ? 0 : networkSections.hashCode()); + result = prime * result + ((virtualSystem == null) ? 0 : virtualSystem.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + BaseEnvelope other = (BaseEnvelope) obj; + if (additionalSections == null) { + if (other.additionalSections != null) + return false; + } else if (!additionalSections.equals(other.additionalSections)) + return false; + if (diskSections == null) { + if (other.diskSections != null) + return false; + } else if (!diskSections.equals(other.diskSections)) + return false; + if (networkSections == null) { + if (other.networkSections != null) + return false; + } else if (!networkSections.equals(other.networkSections)) + return false; + if (virtualSystem == null) { + if (other.virtualSystem != null) + return false; + } else if (!virtualSystem.equals(other.virtualSystem)) + return false; + return true; + } + + @Override + public String toString() { + return String.format("[diskSections=%s, networkSections=%s, additionalSections=%s, virtualSystem=%s]", + diskSections, networkSections, additionalSections, virtualSystem); + } + + public Set getNetworkSections() { + return networkSections; + } +} \ No newline at end of file diff --git a/compute/src/main/java/org/jclouds/ovf/internal/BaseVirtualSystem.java b/compute/src/main/java/org/jclouds/ovf/internal/BaseVirtualSystem.java new file mode 100644 index 0000000000..487c14fc46 --- /dev/null +++ b/compute/src/main/java/org/jclouds/ovf/internal/BaseVirtualSystem.java @@ -0,0 +1,260 @@ +/** + * + * Copyright (C) 2010 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.ovf.internal; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.util.Set; + +import org.jclouds.ovf.OperatingSystemSection; +import org.jclouds.ovf.ProductSection; +import org.jclouds.ovf.Section; +import org.jclouds.ovf.VirtualHardwareSection; + +import com.google.common.collect.ImmutableMultimap; +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.LinkedHashMultimap; +import com.google.common.collect.Multimap; +import com.google.common.collect.Sets; + +/** + * @author Adrian Cole + */ +public class BaseVirtualSystem> extends Section { + + @SuppressWarnings("unchecked") + public static Builder builder() { + return new Builder(); + } + + /** + * {@inheritDoc} + */ + @Override + public Builder toBuilder() { + return new Builder().fromVirtualSystem(this); + } + + public static class Builder> extends Section.Builder { + protected String id; + protected String name; + protected OperatingSystemSection operatingSystem; + protected Set virtualHardwareSections = Sets.newLinkedHashSet(); + protected Set productSections = Sets.newLinkedHashSet(); + @SuppressWarnings("unchecked") + protected Multimap additionalSections = LinkedHashMultimap.create(); + + /** + * @see BaseVirtualSystem#getName + */ + public Builder name(String name) { + this.name = name; + return this; + } + + /** + * @see BaseVirtualSystem#getId + */ + public Builder id(String id) { + this.id = id; + return this; + } + + /** + * @see BaseVirtualSystem#getOperatingSystemSection + */ + public Builder operatingSystemSection(OperatingSystemSection operatingSystem) { + this.operatingSystem = operatingSystem; + return this; + } + + /** + * @see BaseVirtualSystem#getVirtualHardwareSections + */ + public Builder virtualHardwareSection(VirtualHardwareSection virtualHardwareSection) { + this.virtualHardwareSections.add(checkNotNull(virtualHardwareSection, "virtualHardwareSection")); + return this; + } + + /** + * @see BaseVirtualSystem#getVirtualHardwareSections + */ + public Builder virtualHardwareSections(Iterable virtualHardwareSections) { + this.virtualHardwareSections = ImmutableSet. copyOf(checkNotNull(virtualHardwareSections, + "virtualHardwareSections")); + return this; + } + + /** + * @see BaseVirtualSystem#getProductSections + */ + public Builder productSection(ProductSection productSection) { + this.productSections.add(checkNotNull(productSection, "productSection")); + return this; + } + + /** + * @see BaseVirtualSystem#getProductSections + */ + public Builder productSections(Iterable productSections) { + this.productSections = ImmutableSet. copyOf(checkNotNull(productSections, "productSections")); + return this; + } + + /** + * @see BaseVirtualSystem#getAdditionalSections + */ + @SuppressWarnings("unchecked") + public Builder additionalSection(String name, Section additionalSection) { + this.additionalSections.put(checkNotNull(name, "name"), checkNotNull(additionalSection, "additionalSection")); + return this; + } + + /** + * @see BaseVirtualSystem#getAdditionalSections + */ + @SuppressWarnings("unchecked") + public Builder additionalSections(Multimap additionalSections) { + this.additionalSections = ImmutableMultimap. copyOf(checkNotNull(additionalSections, + "additionalSections")); + return this; + } + + /** + * {@inheritDoc} + */ + @Override + public BaseVirtualSystem build() { + return new BaseVirtualSystem(id, info, name, operatingSystem, virtualHardwareSections, productSections, + additionalSections); + } + + public Builder fromVirtualSystem(BaseVirtualSystem in) { + return fromSection(in).id(in.getId()).name(in.getName()) + .operatingSystemSection(in.getOperatingSystemSection()).virtualHardwareSections( + in.getVirtualHardwareSections()).productSections(in.getProductSections()) + .additionalSections(in.getAdditionalSections()); + } + + /** + * {@inheritDoc} + */ + @Override + public Builder fromSection(Section in) { + return (Builder) super.fromSection(in); + } + + /** + * {@inheritDoc} + */ + @Override + public Builder info(String info) { + return (Builder) super.info(info); + } + + } + + protected final String id; + protected final String name; + protected final OperatingSystemSection operatingSystem; + protected final Set virtualHardwareSections; + protected final Set productSections; + @SuppressWarnings("unchecked") + protected final Multimap additionalSections; + + @SuppressWarnings("unchecked") + public BaseVirtualSystem(String id, String info, String name, OperatingSystemSection operatingSystem, + Iterable virtualHardwareSections, + Iterable productSections, Multimap additionalSections) { + super(info); + this.id = id; + this.name = name; + this.operatingSystem = checkNotNull(operatingSystem, "operatingSystem"); + this.virtualHardwareSections = ImmutableSet.copyOf(checkNotNull(virtualHardwareSections, "virtualHardwareSections")); + this.productSections = ImmutableSet.copyOf(checkNotNull(productSections, "productSections")); + this.additionalSections = ImmutableMultimap.copyOf(checkNotNull(additionalSections, "additionalSections")); + } + + public String getId() { + return id; + } + + public String getName() { + return name; + } + + public OperatingSystemSection getOperatingSystemSection() { + return operatingSystem; + } + + /** + * Each VirtualSystem element may contain one or more VirtualHardwareSection elements, each of + * which describes the virtual virtualHardwareSections required by the virtual system. + */ + public Set getVirtualHardwareSections() { + return virtualHardwareSections; + } + + /** + * Specifies product-information for a package, such as product name and version, along with a + * set of properties that can be configured + */ + public Set getProductSections() { + return productSections; + } + + @SuppressWarnings("unchecked") + public Multimap getAdditionalSections() { + return additionalSections; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((id == null) ? 0 : id.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + BaseVirtualSystem other = (BaseVirtualSystem) obj; + if (id == null) { + if (other.id != null) + return false; + } else if (!id.equals(other.id)) + return false; + return true; + } + + @Override + public String toString() { + return String + .format( + "[id=%s, name=%s, info=%s, operatingSystem=%s, virtualHardwareSections=%s, productSections=%s, additionalSections=%s]", + id, name, info, operatingSystem, virtualHardwareSections, productSections, additionalSections); + } +} \ No newline at end of file diff --git a/compute/src/main/java/org/jclouds/ovf/xml/EnvelopeHandler.java b/compute/src/main/java/org/jclouds/ovf/xml/EnvelopeHandler.java index 4dd0cc1c2c..556d346dbc 100644 --- a/compute/src/main/java/org/jclouds/ovf/xml/EnvelopeHandler.java +++ b/compute/src/main/java/org/jclouds/ovf/xml/EnvelopeHandler.java @@ -19,147 +19,24 @@ package org.jclouds.ovf.xml; -import static org.jclouds.util.SaxUtils.equalsOrSuffix; - -import java.util.Map; - -import javax.inject.Named; +import javax.inject.Inject; import javax.inject.Provider; -import org.jclouds.http.functions.ParseSax; import org.jclouds.ovf.Envelope; -import org.xml.sax.Attributes; -import org.xml.sax.SAXException; - -import com.google.common.collect.ImmutableMap; -import com.google.inject.Inject; +import org.jclouds.ovf.VirtualSystem; +import org.jclouds.ovf.Envelope.Builder; +import org.jclouds.ovf.xml.internal.BaseEnvelopeHandler; /** * @author Adrian Cole */ -public class EnvelopeHandler extends ParseSax.HandlerWithResult { - - protected Envelope.Builder builder = Envelope.builder(); - - public Envelope getResult() { - try { - return builder.build(); - } finally { - builder = Envelope.builder(); - } - } - - private final VirtualSystemHandler virtualSystemHandler; - private final DiskSectionHandler diskHandler; - private final NetworkSectionHandler networkHandler; +public class EnvelopeHandler extends + BaseEnvelopeHandler { @Inject public EnvelopeHandler(DiskSectionHandler diskHandler, NetworkSectionHandler networkHandler, - VirtualSystemHandler osHandler) { - this.virtualSystemHandler = osHandler; - this.diskHandler = diskHandler; - this.networkHandler = networkHandler; - } - - @SuppressWarnings("unchecked") - protected SectionHandler defaultSectionHandler = SectionHandler.create(); - - @SuppressWarnings("unchecked") - @Inject(optional = true) - @Named("VirtualSystem") - Map> extensionHandlers = ImmutableMap - .> of(); - - @SuppressWarnings("unchecked") - protected SectionHandler extensionHandler; - - private boolean inDisk; - private boolean inNetwork; - private boolean inVirtualSystem; - private boolean inSection; - private boolean inExtensionSection; - - private int depth = 0; - - public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException { - depth++; - if (depth == 2) { - if (equalsOrSuffix(qName, "DiskSection")) { - inDisk = true; - } else if (equalsOrSuffix(qName, "NetworkSection")) { - inNetwork = true; - } else if (equalsOrSuffix(qName, "VirtualSystem")) { - inVirtualSystem = true; - } else if (extensionHandlers.containsKey(qName)) { - inExtensionSection = true; - extensionHandler = extensionHandlers.get(qName).get(); - } else if (qName.endsWith("Section")) { - inSection = true; - } - } - - if (inDisk) { - diskHandler.startElement(uri, localName, qName, attrs); - } else if (inNetwork) { - networkHandler.startElement(uri, localName, qName, attrs); - } else if (inVirtualSystem) { - virtualSystemHandler.startElement(uri, localName, qName, attrs); - } else if (inExtensionSection) { - extensionHandler.startElement(uri, localName, qName, attrs); - } else if (inSection) { - defaultSectionHandler.startElement(uri, localName, qName, attrs); - } - - } - - @Override - public void endElement(String uri, String localName, String qName) { - depth--; - if (depth == 1) { - if (equalsOrSuffix(qName, "DiskSection")) { - inDisk = false; - builder.diskSection(diskHandler.getResult()); - } else if (equalsOrSuffix(qName, "NetworkSection")) { - inNetwork = false; - builder.networkSection(networkHandler.getResult()); - } else if (equalsOrSuffix(qName, "VirtualSystem")) { - inVirtualSystem = false; - builder.virtualSystem(virtualSystemHandler.getResult()); - } else if (extensionHandlers.containsKey(qName)) { - builder.additionalSection(qName, extensionHandler.getResult()); - inExtensionSection = false; - } else if (qName.endsWith("Section")) { - builder.additionalSection(qName, defaultSectionHandler.getResult()); - inSection = false; - } - } - - if (inDisk) { - diskHandler.endElement(uri, localName, qName); - } else if (inNetwork) { - networkHandler.endElement(uri, localName, qName); - } else if (inVirtualSystem) { - virtualSystemHandler.endElement(uri, localName, qName); - } else if (inExtensionSection) { - extensionHandler.endElement(uri, localName, qName); - } else if (inSection) { - defaultSectionHandler.endElement(uri, localName, qName); - } - } - - @Override - public void characters(char ch[], int start, int length) { - if (inDisk) { - diskHandler.characters(ch, start, length); - } else if (inNetwork) { - networkHandler.characters(ch, start, length); - } else if (inVirtualSystem) { - virtualSystemHandler.characters(ch, start, length); - } else if (inExtensionSection) { - extensionHandler.characters(ch, start, length); - } else if (inSection) { - defaultSectionHandler.characters(ch, start, length); - } + VirtualSystemHandler virtualSystemHandler, Provider envelopeBuilderProvider) { + super(diskHandler, networkHandler, virtualSystemHandler, envelopeBuilderProvider); } } diff --git a/compute/src/main/java/org/jclouds/ovf/xml/NetworkSectionHandler.java b/compute/src/main/java/org/jclouds/ovf/xml/NetworkSectionHandler.java index 0209a4c543..9b980c4f77 100644 --- a/compute/src/main/java/org/jclouds/ovf/xml/NetworkSectionHandler.java +++ b/compute/src/main/java/org/jclouds/ovf/xml/NetworkSectionHandler.java @@ -29,6 +29,7 @@ import javax.inject.Provider; import org.jclouds.ovf.Network; import org.jclouds.ovf.NetworkSection; +import org.jclouds.ovf.xml.SectionHandler; import org.jclouds.util.SaxUtils; import org.xml.sax.Attributes; diff --git a/compute/src/main/java/org/jclouds/ovf/xml/ProductSectionHandler.java b/compute/src/main/java/org/jclouds/ovf/xml/ProductSectionHandler.java new file mode 100644 index 0000000000..d5b4635609 --- /dev/null +++ b/compute/src/main/java/org/jclouds/ovf/xml/ProductSectionHandler.java @@ -0,0 +1,71 @@ +/** + * + * Copyright (C) 2010 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.ovf.xml; + +import static org.jclouds.util.SaxUtils.currentOrNull; +import static org.jclouds.util.SaxUtils.equalsOrSuffix; + +import java.util.Map; + +import javax.inject.Inject; +import javax.inject.Provider; + +import org.jclouds.ovf.ProductSection; +import org.jclouds.ovf.Property; +import org.jclouds.util.SaxUtils; +import org.xml.sax.Attributes; + +/** + * @author Adrian Cole + */ +public class ProductSectionHandler extends SectionHandler { + protected Property.Builder configBuilder = Property.builder(); + + @Inject + public ProductSectionHandler(Provider builderProvider) { + super(builderProvider); + } + + public void startElement(String uri, String localName, String qName, Attributes attrs) { + Map attributes = SaxUtils.cleanseAttributes(attrs); + if (equalsOrSuffix(qName, "Property")) { + configBuilder.key(attributes.get("key")); + configBuilder.value(attributes.get("value")); + } + } + + @Override + public void endElement(String uri, String localName, String qName) { + if (equalsOrSuffix(qName, "Info")) { + builder.info(currentOrNull(currentText)); + } else if (equalsOrSuffix(qName, "Label")) { + configBuilder.label(currentOrNull(currentText)); + } else if (equalsOrSuffix(qName, "Description")) { + configBuilder.description(currentOrNull(currentText)); + } else if (equalsOrSuffix(qName, "Property")) { + try { + builder.property(configBuilder.build()); + } finally { + configBuilder = Property.builder(); + } + } + super.endElement(uri, localName, qName); + } +} diff --git a/compute/src/main/java/org/jclouds/ovf/xml/VirtualHardwareSectionHandler.java b/compute/src/main/java/org/jclouds/ovf/xml/VirtualHardwareSectionHandler.java index ce76830aa8..c3b3736e60 100644 --- a/compute/src/main/java/org/jclouds/ovf/xml/VirtualHardwareSectionHandler.java +++ b/compute/src/main/java/org/jclouds/ovf/xml/VirtualHardwareSectionHandler.java @@ -65,7 +65,6 @@ public class VirtualHardwareSectionHandler extends } else if (!inSystem && equalsOrSuffix(qName, "Item")) { inItem = true; } - if (inSystem) { systemHandler.startElement(uri, localName, qName, attrs); } else if (inItem) { @@ -80,7 +79,7 @@ public class VirtualHardwareSectionHandler extends builder.system(systemHandler.getResult()); } else if (equalsOrSuffix(qName, "Item")) { inItem = false; - builder.resourceAllocation(allocationHandler.getResult()); + builder.item(allocationHandler.getResult()); } if (inSystem) { systemHandler.endElement(uri, localName, qName); diff --git a/compute/src/main/java/org/jclouds/ovf/xml/VirtualSystemHandler.java b/compute/src/main/java/org/jclouds/ovf/xml/VirtualSystemHandler.java index b54078c7e3..b919ecbbd1 100644 --- a/compute/src/main/java/org/jclouds/ovf/xml/VirtualSystemHandler.java +++ b/compute/src/main/java/org/jclouds/ovf/xml/VirtualSystemHandler.java @@ -19,135 +19,22 @@ package org.jclouds.ovf.xml; -import static org.jclouds.util.SaxUtils.cleanseAttributes; -import static org.jclouds.util.SaxUtils.currentOrNull; -import static org.jclouds.util.SaxUtils.equalsOrSuffix; - -import java.util.Map; - -import javax.inject.Named; +import javax.inject.Inject; import javax.inject.Provider; import org.jclouds.ovf.VirtualSystem; -import org.xml.sax.Attributes; -import org.xml.sax.SAXException; - -import com.google.common.collect.ImmutableMap; -import com.google.inject.Inject; +import org.jclouds.ovf.xml.internal.BaseVirtualSystemHandler; /** * @author Adrian Cole */ -public class VirtualSystemHandler extends SectionHandler { - - private final OperatingSystemSectionHandler osHandler; - private final VirtualHardwareSectionHandler hardwareHandler; +public class VirtualSystemHandler extends BaseVirtualSystemHandler { @Inject public VirtualSystemHandler(Provider builderProvider, - OperatingSystemSectionHandler osHandler, VirtualHardwareSectionHandler hardwareHandler) { - super(builderProvider); - this.osHandler = osHandler; - this.hardwareHandler = hardwareHandler; - } - - @SuppressWarnings("unchecked") - protected SectionHandler defaultSectionHandler = SectionHandler.create(); - - @SuppressWarnings("unchecked") - @Inject(optional = true) - @Named("VirtualSystem") - Map> extensionHandlers = ImmutableMap - .> of(); - - @SuppressWarnings("unchecked") - protected SectionHandler extensionHandler; - - private boolean inHardware; - private boolean inOs; - private boolean inSection; - private boolean inExtensionSection; - private int depth; - - public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException { - Map attributes = cleanseAttributes(attrs); - depth++; - if (depth == 2) { - if (equalsOrSuffix(qName, "VirtualHardwareSection")) { - inHardware = true; - } else if (equalsOrSuffix(qName, "OperatingSystemSection")) { - inOs = true; - } else if (extensionHandlers.containsKey(qName)) { - inExtensionSection = true; - extensionHandler = extensionHandlers.get(qName).get(); - } else if (qName.endsWith("Section")) { - inSection = true; - } - } - if (inHardware) { - hardwareHandler.startElement(uri, localName, qName, attrs); - } else if (inOs) { - osHandler.startElement(uri, localName, qName, attrs); - } else if (inExtensionSection) { - extensionHandler.startElement(uri, localName, qName, attrs); - } else if (inSection) { - defaultSectionHandler.startElement(uri, localName, qName, attrs); - } else if (equalsOrSuffix(qName, "VirtualSystem")) { - builder.id(attributes.get("id")); - } - - } - - @Override - public void endElement(String uri, String localName, String qName) { - depth--; - if (depth == 1) { - if (equalsOrSuffix(qName, "VirtualHardwareSection")) { - inHardware = false; - builder.hardwareSection(hardwareHandler.getResult()); - } else if (equalsOrSuffix(qName, "OperatingSystemSection")) { - inOs = false; - builder.operatingSystemSection(osHandler.getResult()); - } else if (extensionHandlers.containsKey(qName)) { - builder.additionalSection(qName, extensionHandler.getResult()); - inExtensionSection = false; - } else if (qName.endsWith("Section")) { - builder.additionalSection(qName, defaultSectionHandler.getResult()); - inSection = false; - } - } - - if (inHardware) { - hardwareHandler.endElement(uri, localName, qName); - } else if (inOs) { - osHandler.endElement(uri, localName, qName); - } else if (inExtensionSection) { - extensionHandler.endElement(uri, localName, qName); - } else if (inSection) { - defaultSectionHandler.endElement(uri, localName, qName); - } else { - if (equalsOrSuffix(qName, "Info")) { - builder.info(currentOrNull(currentText)); - } else if (equalsOrSuffix(qName, "Name")) { - builder.name(currentOrNull(currentText)); - } - super.endElement(uri, localName, qName); - } - } - - @Override - public void characters(char ch[], int start, int length) { - if (inHardware) { - hardwareHandler.characters(ch, start, length); - } else if (inOs) { - osHandler.characters(ch, start, length); - } else if (inExtensionSection) { - extensionHandler.characters(ch, start, length); - } else if (inSection) { - defaultSectionHandler.characters(ch, start, length); - } else { - super.characters(ch, start, length); - } + OperatingSystemSectionHandler osHandler, VirtualHardwareSectionHandler hardwareHandler, + ProductSectionHandler productHandler) { + super(builderProvider, osHandler, hardwareHandler, productHandler); } } diff --git a/compute/src/main/java/org/jclouds/ovf/xml/internal/BaseEnvelopeHandler.java b/compute/src/main/java/org/jclouds/ovf/xml/internal/BaseEnvelopeHandler.java new file mode 100644 index 0000000000..f547922df3 --- /dev/null +++ b/compute/src/main/java/org/jclouds/ovf/xml/internal/BaseEnvelopeHandler.java @@ -0,0 +1,175 @@ +/** + * + * Copyright (C) 2010 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.ovf.xml.internal; + +import static org.jclouds.util.SaxUtils.equalsOrSuffix; + +import java.util.Map; + +import javax.inject.Named; +import javax.inject.Provider; + +import org.jclouds.http.functions.ParseSax; +import org.jclouds.ovf.internal.BaseEnvelope; +import org.jclouds.ovf.internal.BaseVirtualSystem; +import org.jclouds.ovf.xml.DiskSectionHandler; +import org.jclouds.ovf.xml.NetworkSectionHandler; +import org.jclouds.ovf.xml.SectionHandler; +import org.jclouds.util.SaxUtils; +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; + +import com.google.common.collect.ImmutableMap; +import com.google.inject.Inject; + +/** + * @author Adrian Cole + */ +public class BaseEnvelopeHandler, B extends BaseVirtualSystem.Builder, H extends BaseVirtualSystemHandler, E extends BaseEnvelope, T extends BaseEnvelope.Builder> + extends ParseSax.HandlerWithResult { + + public E getResult() { + try { + return builder.build(); + } finally { + builder = envelopeBuilderProvider.get(); + } + } + + protected final H virtualSystemHandler; + protected final DiskSectionHandler diskHandler; + protected final NetworkSectionHandler networkHandler; + protected final Provider envelopeBuilderProvider; + protected T builder; + + @Inject + public BaseEnvelopeHandler(DiskSectionHandler diskHandler, NetworkSectionHandler networkHandler, + H virtualSystemHandler, Provider envelopeBuilderProvider) { + this.virtualSystemHandler = virtualSystemHandler; + this.diskHandler = diskHandler; + this.networkHandler = networkHandler; + this.envelopeBuilderProvider = envelopeBuilderProvider; + this.builder = envelopeBuilderProvider.get(); + } + + @SuppressWarnings("unchecked") + protected SectionHandler defaultSectionHandler = SectionHandler.create(); + + @SuppressWarnings("unchecked") + @Inject(optional = true) + @Named("Envelope") + Map> extensionHandlers = ImmutableMap + .> of(); + + @SuppressWarnings("unchecked") + protected SectionHandler extensionHandler; + + protected boolean inDisk; + protected boolean inNetwork; + protected boolean inVirtualSystem; + protected boolean inSection; + protected boolean inExtensionSection; + + protected int depth = 0; + + public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException { + Map attributes = SaxUtils.cleanseAttributes(attrs); + depth++; + if (depth == 2) { + if (equalsOrSuffix(qName, "DiskSection")) { + inDisk = true; + } else if (equalsOrSuffix(qName, "NetworkSection")) { + inNetwork = true; + } else if (equalsOrSuffix(qName, "VirtualSystem")) { + inVirtualSystem = true; + } else if (extensionHandlers.containsKey(qName) || attributes.containsKey("type") + && extensionHandlers.containsKey(attributes.get("type"))) { + inExtensionSection = true; + extensionHandler = extensionHandlers.get(qName).get(); + } else if (qName.endsWith("Section")) { + inSection = true; + } + } + + if (inDisk) { + diskHandler.startElement(uri, localName, qName, attrs); + } else if (inNetwork) { + networkHandler.startElement(uri, localName, qName, attrs); + } else if (inVirtualSystem) { + virtualSystemHandler.startElement(uri, localName, qName, attrs); + } else if (inExtensionSection) { + extensionHandler.startElement(uri, localName, qName, attrs); + } else if (inSection) { + defaultSectionHandler.startElement(uri, localName, qName, attrs); + } + + } + + @Override + public void endElement(String uri, String localName, String qName) { + depth--; + if (depth == 1) { + if (equalsOrSuffix(qName, "DiskSection")) { + inDisk = false; + builder.diskSection(diskHandler.getResult()); + } else if (equalsOrSuffix(qName, "NetworkSection")) { + inNetwork = false; + builder.networkSection(networkHandler.getResult()); + } else if (equalsOrSuffix(qName, "VirtualSystem")) { + inVirtualSystem = false; + builder.virtualSystem(virtualSystemHandler.getResult()); + } else if (extensionHandlers.containsKey(qName)) { + builder.additionalSection(qName, extensionHandler.getResult()); + inExtensionSection = false; + } else if (qName.endsWith("Section")) { + builder.additionalSection(qName, defaultSectionHandler.getResult()); + inSection = false; + } + } + + if (inDisk) { + diskHandler.endElement(uri, localName, qName); + } else if (inNetwork) { + networkHandler.endElement(uri, localName, qName); + } else if (inVirtualSystem) { + virtualSystemHandler.endElement(uri, localName, qName); + } else if (inExtensionSection) { + extensionHandler.endElement(uri, localName, qName); + } else if (inSection) { + defaultSectionHandler.endElement(uri, localName, qName); + } + } + + @Override + public void characters(char ch[], int start, int length) { + if (inDisk) { + diskHandler.characters(ch, start, length); + } else if (inNetwork) { + networkHandler.characters(ch, start, length); + } else if (inVirtualSystem) { + virtualSystemHandler.characters(ch, start, length); + } else if (inExtensionSection) { + extensionHandler.characters(ch, start, length); + } else if (inSection) { + defaultSectionHandler.characters(ch, start, length); + } + } + +} diff --git a/compute/src/main/java/org/jclouds/ovf/xml/internal/BaseVirtualSystemHandler.java b/compute/src/main/java/org/jclouds/ovf/xml/internal/BaseVirtualSystemHandler.java new file mode 100644 index 0000000000..3172061b97 --- /dev/null +++ b/compute/src/main/java/org/jclouds/ovf/xml/internal/BaseVirtualSystemHandler.java @@ -0,0 +1,190 @@ +/** + * + * Copyright (C) 2010 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.ovf.xml.internal; + +import static org.jclouds.util.SaxUtils.cleanseAttributes; +import static org.jclouds.util.SaxUtils.currentOrNull; +import static org.jclouds.util.SaxUtils.equalsOrSuffix; + +import java.util.Map; + +import javax.inject.Named; +import javax.inject.Provider; + +import org.jclouds.ovf.Section; +import org.jclouds.ovf.internal.BaseVirtualSystem; +import org.jclouds.ovf.xml.OperatingSystemSectionHandler; +import org.jclouds.ovf.xml.ProductSectionHandler; +import org.jclouds.ovf.xml.SectionHandler; +import org.jclouds.ovf.xml.VirtualHardwareSectionHandler; +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; + +import com.google.common.collect.ImmutableMap; +import com.google.inject.Inject; + +/** + * @author Adrian Cole + */ +public class BaseVirtualSystemHandler, B extends BaseVirtualSystem.Builder> extends + SectionHandler { + + private final OperatingSystemSectionHandler osHandler; + private final VirtualHardwareSectionHandler hardwareHandler; + private final ProductSectionHandler productHandler; + + @Inject + public BaseVirtualSystemHandler(Provider builderProvider, OperatingSystemSectionHandler osHandler, + VirtualHardwareSectionHandler hardwareHandler, ProductSectionHandler productHandler) { + super(builderProvider); + this.osHandler = osHandler; + this.hardwareHandler = hardwareHandler; + this.productHandler = productHandler; + } + + @SuppressWarnings("unchecked") + protected SectionHandler defaultSectionHandler = SectionHandler.create(); + + @SuppressWarnings("unchecked") + protected Map> extensionHandlers = ImmutableMap + .> of(); + + @SuppressWarnings("unchecked") + @Inject(optional = true) + protected void setExtensionHandlers( + @Named("VirtualSystem") Map> extensionHandlers) { + extensionHandlers = ImmutableMap.> builder().putAll( + this.extensionHandlers).putAll(extensionHandlers).build(); + } + + @SuppressWarnings("unchecked") + protected SectionHandler extensionHandler; + + private boolean inHardware; + private boolean inOs; + private boolean inProduct; + private boolean inSection; + private boolean inExtensionSection; + private int depth; + + public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException { + Map attributes = cleanseAttributes(attrs); + depth++; + if (depth == 2) { + if (equalsOrSuffix(qName, "VirtualHardwareSection")) { + inHardware = true; + } else if (equalsOrSuffix(qName, "OperatingSystemSection")) { + inOs = true; + } else if (equalsOrSuffix(qName, "ProductSection")) { + inProduct = true; + } else if (extensionHandlers.containsKey(qName)) { + inExtensionSection = true; + extensionHandler = extensionHandlers.get(qName).get(); + } else if (attributes.containsKey("type") && extensionHandlers.containsKey(attributes.get("type"))) { + inExtensionSection = true; + extensionHandler = extensionHandlers.get(attributes.get("type")).get(); + } else if (qName.endsWith("Section")) { + inSection = true; + } + } + if (inHardware) { + hardwareHandler.startElement(uri, localName, qName, attrs); + } else if (inOs) { + osHandler.startElement(uri, localName, qName, attrs); + } else if (inProduct) { + productHandler.startElement(uri, localName, qName, attrs); + } else if (inExtensionSection) { + extensionHandler.startElement(uri, localName, qName, attrs); + } else if (inSection) { + defaultSectionHandler.startElement(uri, localName, qName, attrs); + } else if (equalsOrSuffix(qName, "VirtualSystem")) { + builder.id(attributes.get("id")); + } + + } + + @Override + public void endElement(String uri, String localName, String qName) { + depth--; + if (depth == 1) { + if (equalsOrSuffix(qName, "VirtualHardwareSection")) { + inHardware = false; + builder.virtualHardwareSection(hardwareHandler.getResult()); + } else if (equalsOrSuffix(qName, "OperatingSystemSection")) { + inOs = false; + builder.operatingSystemSection(osHandler.getResult()); + } else if (equalsOrSuffix(qName, "ProductSection")) { + inProduct = false; + builder.productSection(productHandler.getResult()); + } else if (extensionHandlers.containsKey(qName)) { + addAdditionalSection(qName, extensionHandler.getResult()); + inSection = false; + inExtensionSection = false; + } else if (qName.endsWith("Section")) { + addAdditionalSection(qName, inExtensionSection ? extensionHandler.getResult() : defaultSectionHandler + .getResult()); + inSection = false; + inExtensionSection = false; + } + } + + if (inHardware) { + hardwareHandler.endElement(uri, localName, qName); + } else if (inOs) { + osHandler.endElement(uri, localName, qName); + } else if (inProduct) { + productHandler.endElement(uri, localName, qName); + } else if (inExtensionSection) { + extensionHandler.endElement(uri, localName, qName); + } else if (inSection) { + defaultSectionHandler.endElement(uri, localName, qName); + } else { + if (equalsOrSuffix(qName, "Info")) { + builder.info(currentOrNull(currentText)); + } else if (equalsOrSuffix(qName, "Name")) { + builder.name(currentOrNull(currentText)); + } + super.endElement(uri, localName, qName); + } + } + + @SuppressWarnings("unchecked") + protected void addAdditionalSection(String qName, Section additionalSection) { + builder.additionalSection(qName, additionalSection); + } + + @Override + public void characters(char ch[], int start, int length) { + if (inHardware) { + hardwareHandler.characters(ch, start, length); + } else if (inOs) { + osHandler.characters(ch, start, length); + } else if (inProduct) { + productHandler.characters(ch, start, length); + } else if (inExtensionSection) { + extensionHandler.characters(ch, start, length); + } else if (inSection) { + defaultSectionHandler.characters(ch, start, length); + } else { + super.characters(ch, start, length); + } + } + +} diff --git a/compute/src/test/java/org/jclouds/cim/xml/VirtualSystemSettingDataHandlerTest.java b/compute/src/test/java/org/jclouds/cim/xml/VirtualSystemSettingDataHandlerTest.java index 7b8bc3a912..4e36a07391 100644 --- a/compute/src/test/java/org/jclouds/cim/xml/VirtualSystemSettingDataHandlerTest.java +++ b/compute/src/test/java/org/jclouds/cim/xml/VirtualSystemSettingDataHandlerTest.java @@ -26,7 +26,6 @@ import java.io.InputStream; import org.jclouds.cim.ResourceAllocationSettingData; import org.jclouds.cim.VirtualSystemSettingData; import org.jclouds.cim.ResourceAllocationSettingData.ResourceType; -import org.jclouds.cim.xml.VirtualSystemSettingDataHandler; import org.jclouds.http.functions.BaseHandlerTest; import org.jclouds.http.functions.ParseSax; import org.jclouds.http.functions.ParseSax.Factory; @@ -34,6 +33,7 @@ import org.jclouds.http.functions.config.SaxParserModule; import org.jclouds.ovf.OperatingSystemSection; import org.jclouds.ovf.VirtualHardwareSection; import org.jclouds.ovf.VirtualSystem; +import org.jclouds.ovf.internal.BaseVirtualSystem; import org.jclouds.ovf.xml.VirtualSystemHandler; import org.testng.annotations.Test; @@ -71,7 +71,7 @@ public class VirtualSystemSettingDataHandlerTest extends BaseHandlerTest { } @Test(enabled = false) - public static void checkVirtualSystem(VirtualSystem result) { + public static > void checkVirtualSystem(BaseVirtualSystem result) { assertEquals(result.getId(), "Ubuntu1004"); assertEquals(result.getName(), "Ubuntu1004"); assertEquals(result.getInfo(), "A virtual machine:"); @@ -85,38 +85,38 @@ public class VirtualSystemSettingDataHandlerTest extends BaseHandlerTest { "Virtual Hardware Family").virtualSystemIdentifier("Ubuntu1004").virtualSystemType("vmx-07").build()); assertEquals(result.getInfo(), "Virtual hardware requirements"); - assertEquals(Iterables.get(result.getResourceAllocations(), 0).toString(), ResourceAllocationSettingData + assertEquals(Iterables.get(result.getItems(), 0).toString(), ResourceAllocationSettingData .builder().instanceID("1").elementName("Network adapter 0").description("PCNet32 ethernet adapter") .resourceType(ResourceType.ETHERNET_ADAPTER).resourceSubType("PCNet32").address("00:50:56:8c:00:13") .automaticAllocation(true).connection("vAppNet-vApp Internal").addressOnParent("0").build().toString()); - assertEquals(Iterables.get(result.getResourceAllocations(), 1).toString(), ResourceAllocationSettingData + assertEquals(Iterables.get(result.getItems(), 1).toString(), ResourceAllocationSettingData .builder().instanceID("2").elementName("SCSI Controller 0").description("SCSI Controller").resourceType( ResourceType.PARALLEL_SCSI_HBA).resourceSubType("lsilogic").address("0").build().toString()); - assertEquals(Iterables.get(result.getResourceAllocations(), 2).toString(), ResourceAllocationSettingData + assertEquals(Iterables.get(result.getItems(), 2).toString(), ResourceAllocationSettingData .builder().instanceID("2000").elementName("Hard disk 1").description("Hard disk").resourceType( ResourceType.DISK_DRIVE).addressOnParent("0").parent("2").build().toString()); - assertEquals(Iterables.get(result.getResourceAllocations(), 3).toString(), ResourceAllocationSettingData + assertEquals(Iterables.get(result.getItems(), 3).toString(), ResourceAllocationSettingData .builder().instanceID("3").elementName("IDE Controller 0").description("IDE Controller").resourceType( ResourceType.IDE_CONTROLLER).address("0").build().toString()); - assertEquals(Iterables.get(result.getResourceAllocations(), 4).toString(), ResourceAllocationSettingData + assertEquals(Iterables.get(result.getItems(), 4).toString(), ResourceAllocationSettingData .builder().instanceID("3002").elementName("CD/DVD Drive 1").description("CD/DVD Drive").resourceType( ResourceType.CD_DRIVE).addressOnParent("0").parent("3").automaticAllocation(false).build() .toString()); - assertEquals(Iterables.get(result.getResourceAllocations(), 5).toString(), ResourceAllocationSettingData + assertEquals(Iterables.get(result.getItems(), 5).toString(), ResourceAllocationSettingData .builder().instanceID("8000").elementName("Floppy Drive 1").description("Floppy Drive").resourceType( ResourceType.FLOPPY_DRIVE).addressOnParent("0").automaticAllocation(false).build().toString()); - assertEquals(Iterables.get(result.getResourceAllocations(), 6).toString(), ResourceAllocationSettingData + assertEquals(Iterables.get(result.getItems(), 6).toString(), ResourceAllocationSettingData .builder().instanceID("4").elementName("1 virtual CPU(s)").description("Number of Virtual CPUs") .resourceType(ResourceType.PROCESSOR).virtualQuantity(1l).allocationUnits("hertz * 10^6") .reservation(0l).weight(0).build().toString()); - assertEquals(Iterables.get(result.getResourceAllocations(), 7).toString(), ResourceAllocationSettingData + assertEquals(Iterables.get(result.getItems(), 7).toString(), ResourceAllocationSettingData .builder().instanceID("5").elementName("512 MB of memory").description("Memory Size").resourceType( ResourceType.MEMORY).virtualQuantity(512l).allocationUnits("byte * 2^20").reservation(0l) .weight(0).build().toString()); diff --git a/compute/src/test/java/org/jclouds/ovf/xml/ProductSectionHandlerTest.java b/compute/src/test/java/org/jclouds/ovf/xml/ProductSectionHandlerTest.java new file mode 100644 index 0000000000..fbba701f27 --- /dev/null +++ b/compute/src/test/java/org/jclouds/ovf/xml/ProductSectionHandlerTest.java @@ -0,0 +1,77 @@ +/** + * + * Copyright (C) 2010 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.ovf.xml; + +import static org.testng.Assert.assertEquals; + +import java.io.InputStream; + +import org.jclouds.http.functions.ParseSax; +import org.jclouds.http.functions.ParseSax.Factory; +import org.jclouds.http.functions.config.SaxParserModule; +import org.jclouds.ovf.ProductSection; +import org.jclouds.ovf.Property; +import org.testng.annotations.Test; + +import com.google.inject.Guice; +import com.google.inject.Injector; + +/** + * Tests behavior of {@code ProductSectionHandler} + * + * @author Adrian Cole + */ +@Test(groups = "unit") +public class ProductSectionHandlerTest { + public void test() { + InputStream is = getClass().getResourceAsStream("/productsection.xml"); + Injector injector = Guice.createInjector(new SaxParserModule()); + Factory factory = injector.getInstance(ParseSax.Factory.class); + ProductSection result = factory.create(injector.getInstance(ProductSectionHandler.class)).parse(is); + assertEquals(result.toString(), ProductSection.builder().info("vCenter Information").property( + Property.builder().value("false").key("vmwareToolsEnabled").label("VMWare Tools Enabled status") + .description("VMWare Tools Enabled status").build()).property( + + Property.builder().value("10.12.46.171").key("vmwareESXHost").label("VMWare ESXHost Ipaddress") + .description("VMWare ESXHost Ipaddress").build()).property( + + Property.builder().value("cussl01s01c01alun088bal,cussl01s01c01alun089bal").key("datastores").label( + "Datastore Name").description("Datastore Name").build()).property( + Property.builder().value("[Totalcapacity=1335915184128,UsedCapacity=549755813888]").key( + "cussl01s01c01alun088bal").label("Datastore Capacity").description( + "Datastore cussl01s01c01alun088bal Total Capacity, Used Capacity in comma separated").build()) + .property( + + Property.builder().value("[Totalcapacity=1335915184129,UsedCapacity=549755813889]").key( + "cussl01s01c01alun089bal").label("Datastore Capacity").description( + "Datastore cussl01s01c01alun089bal Total Capacity, Used Capacity in comma separated") + .build()).property( + + Property.builder().value("[name=3282176-1949-bal-tier01,ip=0.0.0.0,mac=00:50:56:8c:3f:3c]") + .key("customerPortprofile").label("customerPortprofile").description( + "customerPortprofile").build()).property( + + Property.builder().value("[name=vm-server-mgmt,ip=0.0.0.0,mac=00:50:56:8c:39:75]").key( + "savvisPortprofile").label("savvisPortprofile").description("savvisPortprofile") + .build()).build().toString() + + ); + } +} diff --git a/compute/src/test/resources/productsection.xml b/compute/src/test/resources/productsection.xml new file mode 100644 index 0000000000..8ed834e17c --- /dev/null +++ b/compute/src/test/resources/productsection.xml @@ -0,0 +1,38 @@ + + vCenter Information + + VMWare Tools Enabled status + VMWare Tools Enabled status + + + VMWare ESXHost Ipaddress + VMWare ESXHost Ipaddress + + + Datastore Name + Datastore Name + + + + Datastore Capacity + Datastore cussl01s01c01alun088bal Total Capacity, Used Capacity in comma separated + + + + Datastore Capacity + Datastore cussl01s01c01alun089bal Total Capacity, Used Capacity in comma separated + + + + customerPortprofile + customerPortprofile + + + savvisPortprofile + savvisPortprofile + + \ No newline at end of file diff --git a/providers/pom.xml b/providers/pom.xml index 91908b24c6..a98fc44ae0 100644 --- a/providers/pom.xml +++ b/providers/pom.xml @@ -59,5 +59,6 @@ openhosting-east1 serverlove-z1-man skalicloud-sdg-my + savvis-symphonyvpdc diff --git a/sandbox-providers/savvis-symphonyvpdc/pom.xml b/providers/savvis-symphonyvpdc/pom.xml similarity index 97% rename from sandbox-providers/savvis-symphonyvpdc/pom.xml rename to providers/savvis-symphonyvpdc/pom.xml index 7ed2fcdc29..34edc7e952 100644 --- a/sandbox-providers/savvis-symphonyvpdc/pom.xml +++ b/providers/savvis-symphonyvpdc/pom.xml @@ -56,7 +56,7 @@ 0.8 FIXME FIXME - FIXME + FIXME FIXME FIXME @@ -143,8 +143,8 @@ ${test.savvis-symphonyvpdc.credential} - test.savvis-symphonyvpdc.email - ${test.savvis-symphonyvpdc.email} + savvis-symphonyvpdc.vpdc-email + ${test.savvis-symphonyvpdc.vdc-email} test.savvis-symphonyvpdc.loginUser diff --git a/sandbox-providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/VPDCAsyncClient.java b/providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/VPDCAsyncClient.java similarity index 86% rename from sandbox-providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/VPDCAsyncClient.java rename to providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/VPDCAsyncClient.java index bcbe4b8108..0dca578eac 100644 --- a/sandbox-providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/VPDCAsyncClient.java +++ b/providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/VPDCAsyncClient.java @@ -26,6 +26,7 @@ import org.jclouds.rest.annotations.Delegate; import org.jclouds.savvis.vpdc.domain.Resource; import org.jclouds.savvis.vpdc.features.BrowsingAsyncClient; import org.jclouds.savvis.vpdc.features.FirewallAsyncClient; +import org.jclouds.savvis.vpdc.features.ServiceManagementAsyncClient; import org.jclouds.savvis.vpdc.features.VMAsyncClient; import org.jclouds.savvis.vpdc.internal.Org; @@ -60,6 +61,12 @@ public interface VPDCAsyncClient { FirewallAsyncClient getFirewallClient(); /** + * Provides asynchronous access to ServiceManagement Operation features. + */ + @Delegate + ServiceManagementAsyncClient getServiceManagementClient(); + + /**s * * @return a listing of all orgs that the current user has access to. */ @@ -68,8 +75,8 @@ public interface VPDCAsyncClient { Set listOrgs(); /** - * predefined by default in the classpath resource - * {@code /savvis-symphonyvpdc/predefined_operatingsystems.json} + * predefined by default in the classpath resource {@code + * /savvis-symphonyvpdc/predefined_operatingsystems.json} * * @return the operating systems that are predefined in the provider * @see diff --git a/sandbox-providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/VPDCClient.java b/providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/VPDCClient.java similarity index 91% rename from sandbox-providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/VPDCClient.java rename to providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/VPDCClient.java index 47ceb48f0b..bef6a684c3 100644 --- a/sandbox-providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/VPDCClient.java +++ b/providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/VPDCClient.java @@ -28,6 +28,7 @@ import org.jclouds.rest.annotations.Delegate; import org.jclouds.savvis.vpdc.domain.Resource; import org.jclouds.savvis.vpdc.features.BrowsingClient; import org.jclouds.savvis.vpdc.features.FirewallClient; +import org.jclouds.savvis.vpdc.features.ServiceManagementClient; import org.jclouds.savvis.vpdc.features.VMClient; /** @@ -59,6 +60,12 @@ public interface VPDCClient { @Delegate FirewallClient getFirewallClient(); + /** + * Provides synchronous access to ServiceManagement Operation features. + */ + @Delegate + ServiceManagementClient getServiceManagementClient(); + /** * * @return a listing of all orgs that the current user has access to. diff --git a/sandbox-providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/VPDCContextBuilder.java b/providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/VPDCContextBuilder.java similarity index 86% rename from sandbox-providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/VPDCContextBuilder.java rename to providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/VPDCContextBuilder.java index dd4533340b..8b9a9c69b4 100644 --- a/sandbox-providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/VPDCContextBuilder.java +++ b/providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/VPDCContextBuilder.java @@ -23,6 +23,7 @@ import java.util.List; import java.util.Properties; import org.jclouds.compute.ComputeServiceContextBuilder; +import org.jclouds.savvis.vpdc.compute.config.VPDCComputeServiceContextModule; import org.jclouds.savvis.vpdc.config.VPDCRestClientModule; import com.google.inject.Module; @@ -41,4 +42,9 @@ public class VPDCContextBuilder extends ComputeServiceContextBuilder modules) { + modules.add(new VPDCComputeServiceContextModule()); + } + } diff --git a/sandbox-providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/VPDCPropertiesBuilder.java b/providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/VPDCPropertiesBuilder.java similarity index 88% rename from sandbox-providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/VPDCPropertiesBuilder.java rename to providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/VPDCPropertiesBuilder.java index 4ee290529b..c3fd60228a 100644 --- a/sandbox-providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/VPDCPropertiesBuilder.java +++ b/providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/VPDCPropertiesBuilder.java @@ -21,7 +21,7 @@ package org.jclouds.savvis.vpdc; import static org.jclouds.Constants.PROPERTY_API_VERSION; import static org.jclouds.Constants.PROPERTY_ENDPOINT; -import static org.jclouds.savvis.vpdc.reference.VCloudConstants.PROPERTY_VCLOUD_TIMEOUT_TASK_COMPLETED; +import static org.jclouds.savvis.vpdc.reference.VPDCConstants.PROPERTY_VPDC_TIMEOUT_TASK_COMPLETED; import java.util.Properties; @@ -38,7 +38,7 @@ public class VPDCPropertiesBuilder extends PropertiesBuilder { Properties properties = super.defaultProperties(); properties.setProperty(PROPERTY_API_VERSION, "0.8"); properties.setProperty(PROPERTY_ENDPOINT, "https://api.symphonyvpdc.savvis.net/rest/api"); - properties.setProperty(PROPERTY_VCLOUD_TIMEOUT_TASK_COMPLETED, 600l * 1000l + ""); + properties.setProperty(PROPERTY_VPDC_TIMEOUT_TASK_COMPLETED, 600l * 1000l + ""); return properties; } diff --git a/sandbox-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 similarity index 100% rename from sandbox-providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/binders/BindVMSpecToXmlPayload.java rename to providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/binders/BindVMSpecToXmlPayload.java diff --git a/providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/compute/config/VPDCComputeServiceContextModule.java b/providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/compute/config/VPDCComputeServiceContextModule.java new file mode 100644 index 0000000000..8d5803d27a --- /dev/null +++ b/providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/compute/config/VPDCComputeServiceContextModule.java @@ -0,0 +1,79 @@ +/** + * + * Copyright (C) 2010 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.compute.config; + +import static org.jclouds.compute.domain.OsFamily.RHEL; + +import org.jclouds.compute.ComputeServiceAdapter; +import org.jclouds.compute.config.ComputeServiceAdapterContextModule; +import org.jclouds.compute.domain.CIMOperatingSystem; +import org.jclouds.compute.domain.NodeMetadata; +import org.jclouds.compute.domain.TemplateBuilder; +import org.jclouds.domain.Location; +import org.jclouds.savvis.vpdc.VPDCAsyncClient; +import org.jclouds.savvis.vpdc.VPDCClient; +import org.jclouds.savvis.vpdc.compute.functions.CIMOperatingSystemToImage; +import org.jclouds.savvis.vpdc.compute.functions.NetworkToLocation; +import org.jclouds.savvis.vpdc.compute.functions.VMSpecToHardware; +import org.jclouds.savvis.vpdc.compute.functions.VMToNodeMetadata; +import org.jclouds.savvis.vpdc.compute.strategy.VPDCComputeServiceAdapter; +import org.jclouds.savvis.vpdc.compute.suppliers.FirstNetwork; +import org.jclouds.savvis.vpdc.domain.Network; +import org.jclouds.savvis.vpdc.domain.VM; +import org.jclouds.savvis.vpdc.domain.VMSpec; + +import com.google.common.base.Function; +import com.google.common.base.Supplier; +import com.google.inject.Injector; +import com.google.inject.TypeLiteral; + +/** + * + * @author Adrian Cole + */ +public class VPDCComputeServiceContextModule extends + ComputeServiceAdapterContextModule { + + public VPDCComputeServiceContextModule() { + super(VPDCClient.class, VPDCAsyncClient.class); + } + + @Override + protected TemplateBuilder provideTemplate(Injector injector, TemplateBuilder template) { + return template.osFamily(RHEL).os64Bit(true); + } + + @Override + protected void configure() { + super.configure(); + bind(new TypeLiteral>() { + }).to(VPDCComputeServiceAdapter.class); + bind(new TypeLiteral>() { + }).to(VMToNodeMetadata.class); + bind(new TypeLiteral>() { + }).to(CIMOperatingSystemToImage.class); + bind(new TypeLiteral>() { + }).to(VMSpecToHardware.class); + bind(new TypeLiteral>() { + }).to(NetworkToLocation.class); + bind(new TypeLiteral>() { + }).to(FirstNetwork.class); + } +} diff --git a/providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/compute/functions/CIMOperatingSystemToImage.java b/providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/compute/functions/CIMOperatingSystemToImage.java new file mode 100644 index 0000000000..cafedf704f --- /dev/null +++ b/providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/compute/functions/CIMOperatingSystemToImage.java @@ -0,0 +1,46 @@ +/** + * + * Copyright (C) 2010 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.compute.functions; + +import javax.inject.Singleton; + +import org.jclouds.compute.domain.CIMOperatingSystem; +import org.jclouds.compute.domain.Image; +import org.jclouds.compute.domain.ImageBuilder; + +import com.google.common.base.Function; + +/** + * @author Adrian Cole + */ +@Singleton +public class CIMOperatingSystemToImage implements Function { + + @Override + public Image apply(CIMOperatingSystem from) { + ImageBuilder builder = new ImageBuilder(); + builder.ids(from.getOsType().getCode() + ""); + builder.name(from.getName()); + builder.description(from.getDescription()); + builder.operatingSystem(from); + return builder.build(); + } + +} diff --git a/providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/compute/functions/NetworkToLocation.java b/providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/compute/functions/NetworkToLocation.java new file mode 100644 index 0000000000..f277988989 --- /dev/null +++ b/providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/compute/functions/NetworkToLocation.java @@ -0,0 +1,90 @@ +/** + * + * Copyright (C) 2010 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.compute.functions; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.net.URI; +import java.util.Set; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import javax.inject.Inject; +import javax.inject.Singleton; + +import org.jclouds.domain.Location; +import org.jclouds.domain.LocationBuilder; +import org.jclouds.domain.LocationScope; +import org.jclouds.location.Iso3166; +import org.jclouds.location.Provider; +import org.jclouds.savvis.vpdc.VPDCClient; +import org.jclouds.savvis.vpdc.domain.Network; +import org.jclouds.savvis.vpdc.domain.Org; +import org.jclouds.savvis.vpdc.domain.VDC; + +import com.google.common.base.Function; + +/** + * @author Adrian Cole + */ +@Singleton +public class NetworkToLocation implements Function { + // rest/api/v0.8/org/1/vdc/22/network/VM-Tier01 + public static final Pattern netPattern = Pattern.compile(".*org/([0-9.]+)/vdc/([0-9.]+)/network/(.*)$"); + + private final String providerName; + private final URI endpoint; + private final Set isoCodes; + private VPDCClient client; + + @Inject + public NetworkToLocation(@Iso3166 Set isoCodes, @Provider String providerName, @Provider URI endpoint, + VPDCClient client) { + this.providerName = checkNotNull(providerName, "providerName"); + this.endpoint = checkNotNull(endpoint, "endpoint"); + this.isoCodes = checkNotNull(isoCodes, "isoCodes"); + this.client = checkNotNull(client, "client"); + } + + @Override + public Location apply(Network from) { + Matcher matcher = netPattern.matcher(from.getHref().toASCIIString()); + if (matcher.find()) { + Location provider = new LocationBuilder().scope(LocationScope.PROVIDER).id(providerName).description( + endpoint.toASCIIString()).iso3166Codes(isoCodes).build(); + + Org org = client.getBrowsingClient().getOrg(matcher.group(1)); + + Location orgLocation = new LocationBuilder().scope(LocationScope.REGION).id(org.getId()).description( + org.getDescription()).parent(provider).build(); + + VDC vdc = client.getBrowsingClient().getVDCInOrg(org.getId(), matcher.group(2)); + + Location vdcLocation = new LocationBuilder().scope(LocationScope.ZONE).id(vdc.getId()).description( + vdc.getDescription()).parent(orgLocation).build(); + + return new LocationBuilder().scope(LocationScope.NETWORK).id(from.getId()).description(from.getName()).parent( + vdcLocation).build(); + } else { + throw new IllegalArgumentException("network unparsable: " + from); + } + + } +} diff --git a/providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/compute/functions/VMSpecToHardware.java b/providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/compute/functions/VMSpecToHardware.java new file mode 100644 index 0000000000..6d6e6a60a3 --- /dev/null +++ b/providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/compute/functions/VMSpecToHardware.java @@ -0,0 +1,56 @@ +/** + * + * Copyright (C) 2010 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.compute.functions; + +import java.util.Map.Entry; + +import javax.inject.Singleton; + +import org.jclouds.compute.domain.Hardware; +import org.jclouds.compute.domain.HardwareBuilder; +import org.jclouds.compute.domain.Processor; +import org.jclouds.compute.domain.Volume; +import org.jclouds.compute.domain.VolumeBuilder; +import org.jclouds.savvis.vpdc.domain.VMSpec; + +import com.google.common.base.Function; + +/** + * @author Adrian Cole + */ +@Singleton +public class VMSpecToHardware implements Function { + + @Override + public Hardware apply(VMSpec from) { + HardwareBuilder builder = new HardwareBuilder(); + builder.ids(from.toString()); + for (int i = 0; i < from.getProcessorCount(); i++) + builder.processor(new Processor(1, 3.0)); + builder.ram(from.getMemoryInGig() * 1024); + builder.volume(new VolumeBuilder().type(Volume.Type.LOCAL).device(from.getBootDeviceName()).size( + new Float(from.getBootDiskSize())).bootDevice(true).durable(true).build()); + for (Entry disk : from.getDataDiskDeviceNameToSizeInGig().entrySet()) + builder.volume(new VolumeBuilder().type(Volume.Type.LOCAL).device(disk.getKey()).size( + new Float(disk.getValue())).durable(true).build()); + return builder.build(); + } + +} diff --git a/providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/compute/functions/VMToNodeMetadata.java b/providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/compute/functions/VMToNodeMetadata.java new file mode 100644 index 0000000000..153224fae5 --- /dev/null +++ b/providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/compute/functions/VMToNodeMetadata.java @@ -0,0 +1,106 @@ +/** + * + * Copyright (C) 2010 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.compute.functions; + +import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.base.Predicates.not; +import static com.google.common.collect.Iterables.filter; +import static org.jclouds.compute.util.ComputeServiceUtils.parseGroupFromName; + +import java.util.Map; +import java.util.Set; + +import javax.inject.Inject; +import javax.inject.Singleton; + +import org.jclouds.collect.FindResourceInSet; +import org.jclouds.collect.Memoized; +import org.jclouds.compute.domain.CIMOperatingSystem; +import org.jclouds.compute.domain.NodeMetadata; +import org.jclouds.compute.domain.NodeMetadataBuilder; +import org.jclouds.compute.domain.NodeState; +import org.jclouds.domain.Credentials; +import org.jclouds.domain.Location; +import org.jclouds.savvis.vpdc.domain.VM; +import org.jclouds.savvis.vpdc.util.Utils; +import org.jclouds.util.InetAddresses2.IsPrivateIPAddress; + +import com.google.common.base.Function; +import com.google.common.base.Supplier; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.Iterables; + +/** + * @author Adrian Cole + */ +@Singleton +public class VMToNodeMetadata implements Function { + + public static final Map VAPPSTATUS_TO_NODESTATE = ImmutableMap + . builder().put(VM.Status.OFF, NodeState.SUSPENDED).put(VM.Status.ON, + NodeState.RUNNING).put(VM.Status.RESOLVED, NodeState.PENDING).put(VM.Status.UNRECOGNIZED, + NodeState.UNRECOGNIZED).put(VM.Status.UNKNOWN, NodeState.UNRECOGNIZED).put(VM.Status.SUSPENDED, + NodeState.SUSPENDED).put(VM.Status.UNRESOLVED, NodeState.PENDING).build(); + + private final FindLocationForVM findLocationForVM; + private final Map credentialStore; + + @Inject + VMToNodeMetadata(Map credentialStore, FindLocationForVM findLocationForVM) { + this.credentialStore = checkNotNull(credentialStore, "credentialStore"); + this.findLocationForVM = checkNotNull(findLocationForVM, "findLocationForVM"); + } + + @Override + public NodeMetadata apply(VM from) { + NodeMetadataBuilder builder = new NodeMetadataBuilder(); + builder.ids(from.getHref().toASCIIString()); + builder.name(from.getName()); + builder.location(findLocationForVM.apply(from)); + builder.group(parseGroupFromName(from.getName())); + try { + builder.operatingSystem(CIMOperatingSystem.toComputeOs(from.getOperatingSystemSection())); + } catch (NullPointerException e) { + // os section was null + } + // TODO build from resource allocation section + // builder.hardware(findHardwareForVM.apply(from)); + builder.state(VAPPSTATUS_TO_NODESTATE.get(from.getStatus())); + Set addresses = Utils.getIpsFromVM(from); + builder.publicAddresses(filter(addresses, not(IsPrivateIPAddress.INSTANCE))); + builder.privateAddresses(filter(addresses, IsPrivateIPAddress.INSTANCE)); + builder.credentials(credentialStore.get(from.getHref().toASCIIString())); + return builder.build(); + } + + @Singleton + public static class FindLocationForVM extends FindResourceInSet { + + @Inject + public FindLocationForVM(@Memoized Supplier> hardware) { + super(hardware); + } + + @Override + public boolean matches(VM from, Location input) { + return input.getId().equals(Iterables.get(from.getNetworkSection().getNetworks(), 0).getName()); + } + } +} 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 new file mode 100644 index 0000000000..acb680b955 --- /dev/null +++ b/providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/compute/strategy/VPDCComputeServiceAdapter.java @@ -0,0 +1,175 @@ +package org.jclouds.savvis.vpdc.compute.strategy; + +import static com.google.common.base.Preconditions.checkNotNull; +import static org.jclouds.savvis.vpdc.options.GetVMOptions.Builder.withPowerState; +import static org.jclouds.savvis.vpdc.reference.VPDCConstants.PROPERTY_VPDC_VDC_EMAIL; + +import java.net.URI; +import java.util.Map; +import java.util.concurrent.TimeUnit; + +import javax.inject.Inject; +import javax.inject.Named; +import javax.inject.Singleton; + +import org.jclouds.compute.ComputeService; +import org.jclouds.compute.ComputeServiceAdapter; +import org.jclouds.compute.domain.CIMOperatingSystem; +import org.jclouds.compute.domain.Template; +import org.jclouds.compute.domain.Volume; +import org.jclouds.domain.Credentials; +import org.jclouds.predicates.RetryablePredicate; +import org.jclouds.savvis.vpdc.VPDCClient; +import org.jclouds.savvis.vpdc.domain.Network; +import org.jclouds.savvis.vpdc.domain.Org; +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.VMSpec; +import org.jclouds.savvis.vpdc.predicates.TaskSuccess; +import org.jclouds.savvis.vpdc.reference.VCloudMediaType; + +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; + +; + +/** + * defines the connection between the {@link VPDCClient} implementation and the jclouds + * {@link ComputeService} + * + */ +@Singleton +public class VPDCComputeServiceAdapter implements ComputeServiceAdapter { + private final VPDCClient client; + private final RetryablePredicate taskTester; + private final String email; + + @Inject + public VPDCComputeServiceAdapter(VPDCClient client, TaskSuccess taskSuccess, + @Named(PROPERTY_VPDC_VDC_EMAIL) String email) { + this.client = checkNotNull(client, "client"); + // TODO: parameterize + this.taskTester = new RetryablePredicate(checkNotNull(taskSuccess, "taskSuccess"), 650, 10, + TimeUnit.SECONDS); + this.email = email; + } + + @Override + public VM createNodeWithGroupEncodedIntoNameThenStoreCredentials(String tag, String name, Template template, + Map credentialStore) { + String networkTierName = template.getLocation().getId(); + String vpdcId = template.getLocation().getParent().getId(); + String billingSiteId = template.getLocation().getParent().getParent().getId(); + + VMSpec.Builder specBuilder = VMSpec.builder(); + specBuilder.operatingSystem(CIMOperatingSystem.class.cast(template.getImage().getOperatingSystem())); + specBuilder.processorCount(template.getHardware().getProcessors().size()); + specBuilder.memoryInGig(template.getHardware().getRam() / 1024); + + for (Volume volume : template.getHardware().getVolumes()) { + if (volume.isBootDevice()) + specBuilder.bootDeviceName(volume.getDevice()).bootDiskSize(volume.getSize().intValue()); + else + specBuilder.addDataDrive(volume.getDevice(), volume.getSize().intValue()); + } + + Task task = client.getVMClient().addVMIntoVDC(billingSiteId, vpdcId, networkTierName, name, specBuilder.build()); + // make sure there's no error + if (task.getError() != null) + throw new RuntimeException("cloud not add vm: " + task.getError().toString()); + + if (taskTester.apply(task.getId())) { + try { + return this.getNode(task.getResult().getHref().toASCIIString()); + } finally { + // TODO: get the credentials relevant to the billingSiteId/Org + // credentialStore.put(id, new Credentials(orgId, orgUser)); + } + } else { + throw new RuntimeException("task timed out: " + task); + } + } + + @Override + public Iterable listHardwareProfiles() { + // TODO don't depend on OS + return ImmutableSet.of(VMSpec.builder().operatingSystem(Iterables.get(listImages(), 0)).memoryInGig(2) + .addDataDrive("/data01", 25).build()); + } + + @Override + public Iterable listImages() { + return client.listPredefinedOperatingSystems(); + } + + @Override + public Iterable listNodes() { + Builder builder = ImmutableSet. builder(); + for (Resource org1 : client.listOrgs()) { + Org org = client.getBrowsingClient().getOrg(org1.getId()); + for (Resource vdc : org.getVDCs()) { + VDC VDC = client.getBrowsingClient().getVDCInOrg(org.getId(), vdc.getId()); + for (Resource vApp : Iterables.filter(VDC.getResourceEntities(), new Predicate() { + + @Override + public boolean apply(Resource arg0) { + return VCloudMediaType.VAPP_XML.equals(arg0.getType()); + } + + })) { + builder.add(client.getBrowsingClient().getVMInVDC(org.getId(), vdc.getId(), vApp.getId(), + withPowerState())); + } + } + } + return builder.build(); + } + + @Override + public Iterable listLocations() { + Builder builder = ImmutableSet. builder(); + for (Resource org1 : client.listOrgs()) { + Org org = client.getBrowsingClient().getOrg(org1.getId()); + for (Resource vdc : org.getVDCs()) { + VDC VDC = client.getBrowsingClient().getVDCInOrg(org.getId(), vdc.getId()); + if (VDC.getDescription().indexOf(email) != -1) + continue; + for (Resource network : VDC.getAvailableNetworks()) { + builder.add(client.getBrowsingClient().getNetworkInVDC(org.getId(), vdc.getId(), network.getId())); + } + } + } + return builder.build(); + } + + @Override + public VM getNode(String id) { + return client.getBrowsingClient().getVM(URI.create(checkNotNull(id, "id")), withPowerState()); + } + + @Override + public void destroyNode(String id) { + taskTester.apply(client.getVMClient().removeVM(URI.create(checkNotNull(id, "id"))).getId()); + } + + @Override + public void rebootNode(String id) { + // there is no support for restart in savvis yet + suspendNode(id); + resumeNode(id); + } + + @Override + public void resumeNode(String id) { + taskTester.apply(client.getServiceManagementClient().powerOnVM(URI.create(checkNotNull(id, "id"))).getId()); + } + + @Override + public void suspendNode(String id) { + taskTester.apply(client.getServiceManagementClient().powerOffVM(URI.create(checkNotNull(id, "id"))).getId()); + } +} \ No newline at end of file diff --git a/providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/compute/suppliers/FirstNetwork.java b/providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/compute/suppliers/FirstNetwork.java new file mode 100644 index 0000000000..d65175c0e8 --- /dev/null +++ b/providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/compute/suppliers/FirstNetwork.java @@ -0,0 +1,71 @@ +/** + * + * Copyright (C) 2010 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.compute.suppliers; + +import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.collect.Iterables.find; + +import java.util.Set; + +import javax.inject.Inject; +import javax.inject.Singleton; + +import org.jclouds.collect.Memoized; +import org.jclouds.domain.Location; +import org.jclouds.domain.LocationScope; + +import com.google.common.base.Predicate; +import com.google.common.base.Supplier; + +/** + * + * @author Adrian Cole + * + */ +@Singleton +public class FirstNetwork implements Supplier { + @Singleton + public static final class IsNetwork implements Predicate { + @Override + public boolean apply(Location input) { + return input.getScope() == LocationScope.NETWORK; + } + + @Override + public String toString() { + return "isNetwork()"; + } + } + + private final Supplier> locationsSupplier; + private final IsNetwork isNetwork; + + @Inject + FirstNetwork(@Memoized Supplier> locationsSupplier, IsNetwork isNetwork) { + this.locationsSupplier = checkNotNull(locationsSupplier, "locationsSupplierSupplier"); + this.isNetwork = checkNotNull(isNetwork, "isNetwork"); + } + + @Override + public Location get() { + return find(locationsSupplier.get(), isNetwork); + } + +} \ No newline at end of file diff --git a/sandbox-providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/config/VPDCRestClientModule.java b/providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/config/VPDCRestClientModule.java similarity index 94% rename from sandbox-providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/config/VPDCRestClientModule.java rename to providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/config/VPDCRestClientModule.java index 707963a3fa..6e7b2c4ebf 100644 --- a/sandbox-providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/config/VPDCRestClientModule.java +++ b/providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/config/VPDCRestClientModule.java @@ -24,7 +24,7 @@ import static com.google.common.base.Preconditions.checkState; import static com.google.common.base.Throwables.propagate; import static org.jclouds.Constants.PROPERTY_IDENTITY; import static org.jclouds.Constants.PROPERTY_SESSION_INTERVAL; -import static org.jclouds.savvis.vpdc.reference.VCloudConstants.PROPERTY_VCLOUD_TIMEOUT_TASK_COMPLETED; +import static org.jclouds.savvis.vpdc.reference.VPDCConstants.PROPERTY_VPDC_TIMEOUT_TASK_COMPLETED; import java.io.IOException; import java.util.Map; @@ -55,6 +55,8 @@ import org.jclouds.savvis.vpdc.features.BrowsingAsyncClient; import org.jclouds.savvis.vpdc.features.BrowsingClient; import org.jclouds.savvis.vpdc.features.FirewallAsyncClient; import org.jclouds.savvis.vpdc.features.FirewallClient; +import org.jclouds.savvis.vpdc.features.ServiceManagementAsyncClient; +import org.jclouds.savvis.vpdc.features.ServiceManagementClient; import org.jclouds.savvis.vpdc.features.VMAsyncClient; import org.jclouds.savvis.vpdc.features.VMClient; import org.jclouds.savvis.vpdc.handlers.VPDCErrorHandler; @@ -111,7 +113,7 @@ public class VPDCRestClientModule extends RestClientModule successTester(Injector injector, - @Named(PROPERTY_VCLOUD_TIMEOUT_TASK_COMPLETED) long completed) { + @Named(PROPERTY_VPDC_TIMEOUT_TASK_COMPLETED) long completed) { return new RetryablePredicate(injector.getInstance(TaskSuccess.class), completed); } @@ -119,6 +121,7 @@ public class VPDCRestClientModule extends RestClientModule firewallRules = Sets.newLinkedHashSet(); diff --git a/sandbox-providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/domain/Link.java b/providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/domain/Link.java similarity index 96% rename from sandbox-providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/domain/Link.java rename to providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/domain/Link.java index 0e1dd4f474..c001736058 100644 --- a/sandbox-providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/domain/Link.java +++ b/providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/domain/Link.java @@ -8,7 +8,7 @@ import java.net.URI; * @author Adrian Cole * */ -public class Link extends Resource { +public class Link extends ResourceImpl { protected final String rel; public Link( String id,String name, String type, URI href, String rel) { diff --git a/sandbox-providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/domain/Network.java b/providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/domain/Network.java similarity index 95% rename from sandbox-providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/domain/Network.java rename to providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/domain/Network.java index bd0fdea8b0..efa48c8e70 100644 --- a/sandbox-providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/domain/Network.java +++ b/providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/domain/Network.java @@ -34,12 +34,12 @@ import com.google.common.collect.Maps; * * @author Adrian Cole */ -public class Network extends Resource { +public class Network extends ResourceImpl { public static Builder builder() { return new Builder(); } - public static class Builder extends Resource.Builder { + public static class Builder extends ResourceImpl.Builder { private String gateway; private String netmask; private Map internalToExternalNATRules = Maps.newLinkedHashMap(); @@ -70,7 +70,7 @@ public class Network extends Resource { return new Network(id, name, type, href, gateway, netmask, internalToExternalNATRules); } - public static Builder fromOrg(Network in) { + public static Builder fromNetwork(Network in) { return new Builder().id(in.getId()).name(in.getName()).type(in.getType()).href(in.getHref()) .gateway(in.getGateway()).internalToExternalNATRules(in.getInternalToExternalNATRules()) .netmask(in.getNetmask()); @@ -135,7 +135,7 @@ public class Network extends Resource { @Override public Builder toBuilder() { - return Builder.fromOrg(this); + return Builder.fromNetwork(this); } @Override diff --git a/providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/domain/NetworkConfigSection.java b/providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/domain/NetworkConfigSection.java new file mode 100644 index 0000000000..c4931a39ac --- /dev/null +++ b/providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/domain/NetworkConfigSection.java @@ -0,0 +1,210 @@ +/** + * + * Copyright (C) 2010 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.domain; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.util.Map; + +import org.jclouds.ovf.Section; + +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.Maps; + +/** + * + * @author Adrian Cole + */ +public class NetworkConfigSection extends Section { + + @SuppressWarnings("unchecked") + public static Builder builder() { + return new Builder(); + } + + /** + * {@inheritDoc} + */ + @Override + public Builder toBuilder() { + return builder().fromNetworkConfigSection(this); + } + + public static class Builder extends Section.Builder { + private String network; + private String fenceMode; + private Boolean dhcp; + private String gateway; + private String netmask; + private Map internalToExternalNATRules = Maps.newLinkedHashMap(); + + public Builder network(String network) { + this.network = network; + return this; + } + + public Builder fenceMode(String fenceMode) { + this.fenceMode = fenceMode; + return this; + } + + public Builder dhcp(Boolean dhcp) { + this.dhcp = dhcp; + return this; + } + + public Builder gateway(String gateway) { + this.gateway = gateway; + return this; + } + + public Builder netmask(String netmask) { + this.netmask = netmask; + return this; + } + + public Builder internalToExternalNATRule(String internalIP, String externalIP) { + this.internalToExternalNATRules.put(checkNotNull(internalIP, "internalIP"), checkNotNull(externalIP, + "externalIP")); + return this; + } + + public Builder internalToExternalNATRules(Map internalToExternalNATRules) { + this.internalToExternalNATRules.putAll(checkNotNull(internalToExternalNATRules, "internalToExternalNATRules")); + return this; + } + + /** + * {@inheritDoc} + */ + @Override + public NetworkConfigSection build() { + return new NetworkConfigSection(info, network, fenceMode, dhcp, gateway, netmask, internalToExternalNATRules); + } + + public Builder fromNetworkConfigSection(NetworkConfigSection in) { + return fromSection(in).network(in.getNetwork()).fenceMode(in.getFenceMode()).dhcp(in.getDhcp()).gateway( + in.getGateway()).netmask(in.getNetmask()).internalToExternalNATRules( + in.getInternalToExternalNATRules()); + } + + /** + * {@inheritDoc} + */ + @Override + public Builder fromSection(Section in) { + return Builder.class.cast(super.fromSection(in)); + } + + /** + * {@inheritDoc} + */ + @Override + public Builder info(String info) { + return Builder.class.cast(super.info(info)); + } + + } + + private final String network; + private final String fenceMode; + private final Boolean dhcp; + private final String gateway; + private final String netmask; + private final Map internalToExternalNATRules; + + public NetworkConfigSection(String info, String network, String fenceMode, Boolean dhcp, String gateway, + String netmask, Map internalToExternalNATRules) { + super(info); + this.network = network; + this.fenceMode = fenceMode; + this.dhcp = dhcp; + this.gateway = gateway; + this.netmask = netmask; + this.internalToExternalNATRules = ImmutableMap.copyOf(checkNotNull(internalToExternalNATRules, + "internalToExternalNATRules")); + } + + /** + * @return IP of the network's gateway + */ + public String getGateway() { + return gateway; + } + + /** + * @return IP of the network's netmask + */ + public String getNetmask() { + return netmask; + } + + /** + * @return map of internal to external ip when it has any nat1to1 enabled deployed VApp + */ + public Map getInternalToExternalNATRules() { + return internalToExternalNATRules; + } + + public String getNetwork() { + return network; + } + + public String getFenceMode() { + return fenceMode; + } + + public Boolean getDhcp() { + return dhcp; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = super.hashCode(); + result = prime * result + ((network == null) ? 0 : network.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (!super.equals(obj)) + return false; + if (getClass() != obj.getClass()) + return false; + NetworkConfigSection other = (NetworkConfigSection) obj; + if (network == null) { + if (other.network != null) + return false; + } else if (!network.equals(other.network)) + return false; + return true; + } + + @Override + public String toString() { + return String.format( + "[info=%s, network=%s, dhcp=%s, fenceMode=%s, gateway=%s, internalToExternalNATRules=%s, netmask=%s]", + info, network, dhcp, fenceMode, gateway, internalToExternalNATRules, netmask); + } + +} \ No newline at end of file diff --git a/providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/domain/NetworkConnectionSection.java b/providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/domain/NetworkConnectionSection.java new file mode 100644 index 0000000000..28da0171e9 --- /dev/null +++ b/providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/domain/NetworkConnectionSection.java @@ -0,0 +1,134 @@ +/** + * + * Copyright (C) 2010 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.domain; + +import org.jclouds.ovf.Section; + +/** + * + * @author Adrian Cole + */ +public class NetworkConnectionSection extends Section { + + @SuppressWarnings("unchecked") + public static Builder builder() { + return new Builder(); + } + + /** + * {@inheritDoc} + */ + @Override + public Builder toBuilder() { + return builder().fromNetworkConectionSection(this); + } + + public static class Builder extends Section.Builder { + private String network; + private String ipAddress; + + public Builder network(String network) { + this.network = network; + return this; + } + + public Builder ipAddress(String ipAddress) { + this.ipAddress = ipAddress; + return this; + } + + /** + * {@inheritDoc} + */ + @Override + public NetworkConnectionSection build() { + return new NetworkConnectionSection(info, network, ipAddress); + } + + public Builder fromNetworkConectionSection(NetworkConnectionSection in) { + return fromSection(in).network(in.getNetwork()).ipAddress(in.getIpAddress()); + } + + /** + * {@inheritDoc} + */ + @Override + public Builder fromSection(Section in) { + return Builder.class.cast(super.fromSection(in)); + } + + /** + * {@inheritDoc} + */ + @Override + public Builder info(String info) { + return Builder.class.cast(super.info(info)); + } + + } + + private final String network; + private final String ipAddress; + + public NetworkConnectionSection(String info, String network, String ipAddress) { + super(info); + this.network = network; + this.ipAddress = ipAddress; + } + + public String getNetwork() { + return network; + } + + public String getIpAddress() { + return ipAddress; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = super.hashCode(); + result = prime * result + ((network == null) ? 0 : network.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (!super.equals(obj)) + return false; + if (getClass() != obj.getClass()) + return false; + NetworkConnectionSection other = (NetworkConnectionSection) obj; + if (network == null) { + if (other.network != null) + return false; + } else if (!network.equals(other.network)) + return false; + return true; + } + + @Override + public String toString() { + return String.format("[info=%s, network=%s, ipAddress=%s]", info, network, ipAddress); + } + +} \ No newline at end of file diff --git a/sandbox-providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/domain/Org.java b/providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/domain/Org.java similarity index 97% rename from sandbox-providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/domain/Org.java rename to providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/domain/Org.java index 282a54143d..3ef09df550 100644 --- a/sandbox-providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/domain/Org.java +++ b/providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/domain/Org.java @@ -46,12 +46,12 @@ import com.google.common.collect.Sets; * * @author Adrian Cole */ -public class Org extends Resource { +public class Org extends ResourceImpl { public static Builder builder() { return new Builder(); } - public static class Builder extends Resource.Builder { + public static class Builder extends ResourceImpl.Builder { private String description; private Set vDCs = Sets.newLinkedHashSet(); private Set images = Sets.newLinkedHashSet(); diff --git a/providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/domain/Resource.java b/providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/domain/Resource.java new file mode 100644 index 0000000000..f74fe122b3 --- /dev/null +++ b/providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/domain/Resource.java @@ -0,0 +1,42 @@ +/** + * + * Copyright (C) 2010 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.domain; + +import java.net.URI; + +/** + * Location of a Rest resource + * + * @author Adrian Cole + * + */ +public interface Resource extends Comparable { + + String getId(); + + String getName(); + + String getType(); + + URI getHref(); + + int compareTo(Resource that); + +} \ No newline at end of file diff --git a/sandbox-providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/domain/Resource.java b/providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/domain/ResourceImpl.java similarity index 72% rename from sandbox-providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/domain/Resource.java rename to providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/domain/ResourceImpl.java index 8f3ac09192..8ce25639a9 100644 --- a/sandbox-providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/domain/Resource.java +++ b/providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/domain/ResourceImpl.java @@ -1,3 +1,22 @@ +/** + * + * Copyright (C) 2010 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.domain; import java.net.URI; @@ -8,7 +27,7 @@ import java.net.URI; * @author Adrian Cole * */ -public class Resource { +public class ResourceImpl implements Resource { public static Builder builder() { return new Builder(); } @@ -39,11 +58,11 @@ public class Resource { return this; } - public Resource build() { - return new Resource(id, name, type, href); + public ResourceImpl build() { + return new ResourceImpl(id, name, type, href); } - public static Builder fromResource(Resource in) { + public static Builder fromResource(ResourceImpl in) { return new Builder().id(in.getId()).name(in.getName()).type(in.getType()).href(in.getHref()); } } @@ -53,7 +72,7 @@ public class Resource { protected final String type; protected final URI href; - public Resource(String id, String name, String type, URI href) { + public ResourceImpl(String id, String name, String type, URI href) { this.id = id; this.name = name; this.type = type; @@ -99,7 +118,7 @@ public class Resource { return false; if (getClass() != obj.getClass()) return false; - Resource other = (Resource) obj; + ResourceImpl other = (ResourceImpl) obj; if (href == null) { if (other.href != null) return false; diff --git a/sandbox-providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/domain/Task.java b/providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/domain/Task.java similarity index 98% rename from sandbox-providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/domain/Task.java rename to providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/domain/Task.java index 8cdd84d2df..2c5cdd3331 100644 --- a/sandbox-providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/domain/Task.java +++ b/providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/domain/Task.java @@ -14,12 +14,12 @@ import javax.annotation.Nullable; * * @see */ -public class Task extends Resource { +public class Task extends ResourceImpl { public static Builder builder() { return new Builder(); } - public static class Builder extends Resource.Builder { + public static class Builder extends ResourceImpl.Builder { private Status status; private Date startTime; private Date endTime; diff --git a/sandbox-providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/domain/TaskError.java b/providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/domain/TaskError.java similarity index 100% rename from sandbox-providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/domain/TaskError.java rename to providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/domain/TaskError.java diff --git a/sandbox-providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/domain/VDC.java b/providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/domain/VDC.java similarity index 98% rename from sandbox-providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/domain/VDC.java rename to providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/domain/VDC.java index 6a970aa1ef..424dd1e7f2 100644 --- a/sandbox-providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/domain/VDC.java +++ b/providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/domain/VDC.java @@ -35,12 +35,12 @@ import com.google.common.collect.Sets; * * @author Adrian Cole */ -public class VDC extends Resource { +public class VDC extends ResourceImpl { public static Builder builder() { return new Builder(); } - public static class Builder extends Resource.Builder { + public static class Builder extends ResourceImpl.Builder { private String description; private Status status; private Set resourceEntities = Sets.newLinkedHashSet(); diff --git a/providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/domain/VM.java b/providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/domain/VM.java new file mode 100644 index 0000000000..43926e1026 --- /dev/null +++ b/providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/domain/VM.java @@ -0,0 +1,377 @@ +/** + * + * Copyright (C) 2010 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.domain; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.net.URI; +import java.util.Set; + +import org.jclouds.ovf.NetworkSection; +import org.jclouds.ovf.OperatingSystemSection; +import org.jclouds.ovf.ProductSection; +import org.jclouds.ovf.Section; +import org.jclouds.ovf.VirtualHardwareSection; +import org.jclouds.ovf.internal.BaseVirtualSystem; + +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Multimap; +import com.google.common.collect.Sets; + +/** + * A virtual application (vApp) is a software solution, packaged in OVF containing one or more + * virtual machines. A vApp can be authored by Developers at ISVs and VARs or by IT Administrators + * in Enterprises and Service Providers. + * + * @author Adrian Cole + */ +public class VM extends BaseVirtualSystem implements Resource { + /** + * Objects such as vAppTemplate, vApp, and Vm have a status attribute whose value indicates the + * state of the object. Status for an object, such as a vAppTemplate or vApp, whose Children (Vm + * objects) each have a status of their own, is computed from the status of the Children. + * + *

NOTE

+ *

+ * The deployment status of an object is indicated by the value of its deployed attribute. + * + * @since vcloud api 0.8 + * + * @author Adrian Cole + */ + public enum Status { + + /** + * When the VM is in Designing,Saved,Inqueue, has issue in pre provisioning or any exception + * cases. VM is not in Savvis VPDC (may the VM has been removed) or cannot get VM state due to + * unknown exception + */ + UNRESOLVED, + /** + * When the Savvis VPDC is in Provisioning, PartiallyDeployed, Failed and the VM failed in + * provisioning or pending infrastructure notification + */ + RESOLVED, + /** + * When the VM is deployed in vmware and powered off. + */ + OFF, + /** + * We do not support suspended state. + */ + SUSPENDED, + /** + * When the VM is deployed in vmware and powered on. + */ + ON, + /** + * The VM is deployed in vmware but the state of VM may be Uninitialized, Start, Stop, Resume, + * Reset, RebootGuest, Error, Failed, Unknown, PoweringOn, PoweringOff, Suspending, Stopping, + * Starting, Resetting, RebootingGuest. Please call back the Get VApp Power State API after + * few minute. + */ + UNKNOWN, UNRECOGNIZED; + + public String value() { + switch (this) { + case UNRESOLVED: + return "0"; + case RESOLVED: + return "1"; + case OFF: + return "2"; + case SUSPENDED: + return "3"; + case ON: + return "4"; + case UNKNOWN: + return "5"; + default: + return "UNRECOGNIZED"; + } + } + + public static Status fromValue(String status) { + try { + return fromValue(Integer.parseInt(checkNotNull(status, "status"))); + } catch (IllegalArgumentException e) { + return UNRECOGNIZED; + } + } + + public static Status fromValue(int v) { + switch (v) { + case 0: + return UNRESOLVED; + case 1: + return RESOLVED; + case 2: + return OFF; + case 3: + return SUSPENDED; + case 4: + return ON; + case 5: + return UNKNOWN; + default: + return UNRECOGNIZED; + } + } + + } + + public static Builder builder() { + return new Builder(); + } + + public static class Builder extends BaseVirtualSystem.Builder { + protected String type; + protected URI href; + protected Status status; + protected NetworkSection networkSection; + protected Set networkConfigSections = Sets.newLinkedHashSet(); + protected Set networkConnectionSections = Sets.newLinkedHashSet(); + + public Builder id(String id) { + this.id = id; + return this; + } + + public Builder name(String name) { + this.name = name; + return this; + } + + public Builder type(String type) { + this.type = type; + return this; + } + + public Builder href(URI href) { + this.href = href; + return this; + } + + public Builder status(Status status) { + this.status = status; + return this; + } + + public Builder networkSection(NetworkSection networkSection) { + this.networkSection = networkSection; + return this; + } + + /** + * @see VM#getNetworkConfigSections + */ + public Builder networkConfigSection(NetworkConfigSection networkConfigSection) { + this.networkConfigSections.add(checkNotNull(networkConfigSection, "networkConfigSection")); + return this; + } + + /** + * @see VM#getNetworkConfigSections + */ + public Builder networkConfigSections(Iterable networkConfigSections) { + this.networkConfigSections = ImmutableSet. copyOf(checkNotNull(networkConfigSections, + "networkConfigSections")); + return this; + } + + /** + * @see VM#getNetworkConnectionSections + */ + public Builder networkConnectionSection(NetworkConnectionSection networkConnectionSection) { + this.networkConnectionSections.add(checkNotNull(networkConnectionSection, "networkConnectionSection")); + return this; + } + + /** + * @see VM#getNetworkConnectionSections + */ + public Builder networkConnectionSections(Iterable networkConnectionSections) { + this.networkConnectionSections = ImmutableSet. copyOf(checkNotNull( + networkConnectionSections, "networkConnectionSections")); + return this; + } + + @Override + public VM build() { + return new VM(id, info, name, operatingSystem, virtualHardwareSections, productSections, additionalSections, type, + href, status, networkSection, networkConfigSections, networkConnectionSections); + } + + public Builder fromVM(VM in) { + return fromVirtualSystem(in).type(in.getType()).href(in.getHref()).status(in.getStatus()).networkSection( + in.getNetworkSection()).networkConfigSections(in.getNetworkConfigSections()) + .networkConnectionSections(in.getNetworkConnectionSections()); + } + + /** + * {@inheritDoc} + */ + @SuppressWarnings("unchecked") + @Override + public Builder additionalSection(String name, Section additionalSection) { + return Builder.class.cast(super.additionalSection(name, additionalSection)); + } + + /** + * {@inheritDoc} + */ + @SuppressWarnings("unchecked") + @Override + public Builder additionalSections(Multimap additionalSections) { + return Builder.class.cast(super.additionalSections(additionalSections)); + } + + /** + * {@inheritDoc} + */ + @Override + public Builder fromSection(Section in) { + return Builder.class.cast(super.fromSection(in)); + } + + /** + * {@inheritDoc} + */ + @Override + public Builder fromVirtualSystem(BaseVirtualSystem in) { + return Builder.class.cast(super.fromVirtualSystem(in)); + } + + /** + * {@inheritDoc} + */ + @Override + public Builder virtualHardwareSection(VirtualHardwareSection virtualHardwareSection) { + return Builder.class.cast(super.virtualHardwareSection(virtualHardwareSection)); + } + + /** + * {@inheritDoc} + */ + @Override + public Builder virtualHardwareSections(Iterable virtualHardwareSections) { + return Builder.class.cast(super.virtualHardwareSections(virtualHardwareSections)); + } + + /** + * {@inheritDoc} + */ + @Override + public Builder info(String info) { + return Builder.class.cast(super.info(info)); + } + + /** + * {@inheritDoc} + */ + @Override + public Builder operatingSystemSection(OperatingSystemSection operatingSystem) { + return Builder.class.cast(super.operatingSystemSection(operatingSystem)); + } + + /** + * {@inheritDoc} + */ + @Override + public Builder productSection(ProductSection productSection) { + return Builder.class.cast(super.productSection(productSection)); + } + + /** + * {@inheritDoc} + */ + @Override + public Builder productSections(Iterable productSections) { + return Builder.class.cast(super.productSections(productSections)); + } + } + + protected final String type; + protected final URI href; + protected final Status status; + protected final NetworkSection networkSection; + protected final Set networkConfigSections; + protected final Set networkConnectionSections; + + @SuppressWarnings("unchecked") + public VM(String id, String info, String name, OperatingSystemSection operatingSystem, + Iterable virtualHardwareSections, + Iterable productSections, Multimap additionalSections, + String type, URI href, Status status, NetworkSection networkSection, + Iterable networkConfigSections, + Iterable networkConnectionSections) { + super(id, info, name, operatingSystem, virtualHardwareSections, productSections, additionalSections); + this.type = type; + this.href = href; + this.status = status; + this.networkSection = networkSection; + this.networkConfigSections = ImmutableSet.copyOf(checkNotNull(networkConfigSections, "networkConfigSections")); + this.networkConnectionSections = ImmutableSet.copyOf(checkNotNull(networkConnectionSections, + "networkConnectionSections")); + } + + public Status getStatus() { + return status; + } + + public NetworkSection getNetworkSection() { + return networkSection; + } + + public Set getNetworkConfigSections() { + return networkConfigSections; + } + + public Set getNetworkConnectionSections() { + return networkConnectionSections; + } + + public String getType() { + return type; + } + + public URI getHref() { + return href; + } + + @Override + public String toString() { + return String + .format( + "[id=%s, name=%s, info=%s, href=%s,status=%s, type=%s, virtualHardwareSections=%s, operatingSystem=%s, productSections=%s, networkSection=%s, networkConfigSections=%s, networkConnectionSections=%s, additionalSections=%s]", + id, name, info, href, status, type, virtualHardwareSections, operatingSystem, productSections, + networkSection, networkConfigSections, networkConnectionSections, additionalSections); + } + + @Override + public int compareTo(Resource that) { + return (this == that) ? 0 : getHref().compareTo(that.getHref()); + } + + public Builder toBuilder() { + return builder().fromVM(this); + } + +} \ No newline at end of file diff --git a/sandbox-providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/domain/VMSpec.java b/providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/domain/VMSpec.java similarity index 91% rename from sandbox-providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/domain/VMSpec.java rename to providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/domain/VMSpec.java index ef56b800aa..5ee1233ea5 100644 --- a/sandbox-providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/domain/VMSpec.java +++ b/providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/domain/VMSpec.java @@ -42,8 +42,7 @@ public class VMSpec { public static class Builder { private CIMOperatingSystem operatingSystem; - // TODO docs suggest fractions are possible, but xml isn't accepted on add - private float processorCount = 1f; + private int processorCount = 1; private int memoryInGig = 1; private String bootDeviceName = "/"; // TODO doesn't seem to be changeable @@ -61,7 +60,7 @@ public class VMSpec { return this; } - public Builder processorCount(float processorCount) { + public Builder processorCount(int processorCount) { checkProcessorCount(processorCount); this.processorCount = processorCount; return this; @@ -103,19 +102,19 @@ public class VMSpec { } - static void checkProcessorCount(float processorCount) { + static void checkProcessorCount(int processorCount) { checkArgument(processorCount > 0, "processorCount must be positive and an increment of 0.5"); checkArgument(processorCount % .5 == 0, "processorCount must be an increment of 0.5"); } private final CIMOperatingSystem operatingSystem; - private final float processorCount; + private final int processorCount; private final int memoryInGig; private final String bootDeviceName; private final int bootDriveSize; private final Map dataDriveDeviceNameToSizeInGig; - protected VMSpec(CIMOperatingSystem operatingSystem, float processorCount, int memoryInGig, String bootDeviceName, + protected VMSpec(CIMOperatingSystem operatingSystem, int processorCount, int memoryInGig, String bootDeviceName, int bootDriveSize, Map dataDriveDeviceNameToSizeInGig) { this.operatingSystem = checkNotNull(operatingSystem, "operatingSystem not specified"); checkProcessorCount(processorCount); @@ -133,7 +132,7 @@ public class VMSpec { return operatingSystem; } - public float getProcessorCount() { + public int getProcessorCount() { return processorCount; } @@ -152,10 +151,10 @@ public class VMSpec { result = prime * result + ((bootDeviceName == null) ? 0 : bootDeviceName.hashCode()); result = prime * result + bootDriveSize; result = prime * result - + ((dataDriveDeviceNameToSizeInGig == null) ? 0 : dataDriveDeviceNameToSizeInGig.hashCode()); + + ((dataDriveDeviceNameToSizeInGig == null) ? 0 : dataDriveDeviceNameToSizeInGig.hashCode()); result = prime * result + memoryInGig; result = prime * result + ((operatingSystem == null) ? 0 : operatingSystem.hashCode()); - result = prime * result + Float.floatToIntBits(processorCount); + result = prime * result + processorCount; return result; } @@ -187,7 +186,7 @@ public class VMSpec { return false; } else if (!operatingSystem.equals(other.operatingSystem)) return false; - if (Float.floatToIntBits(processorCount) != Float.floatToIntBits(other.processorCount)) + if (processorCount != other.processorCount) return false; return true; } diff --git a/sandbox-providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/domain/internal/VCloudSession.java b/providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/domain/internal/VCloudSession.java similarity index 100% rename from sandbox-providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/domain/internal/VCloudSession.java rename to providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/domain/internal/VCloudSession.java diff --git a/sandbox-providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/domain/vapp/Network.java b/providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/domain/vapp/Network.java similarity index 100% rename from sandbox-providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/domain/vapp/Network.java rename to providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/domain/vapp/Network.java diff --git a/sandbox-providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/features/BrowsingAsyncClient.java b/providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/features/BrowsingAsyncClient.java similarity index 70% rename from sandbox-providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/features/BrowsingAsyncClient.java rename to providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/features/BrowsingAsyncClient.java index 9840600c49..8c0fa339aa 100644 --- a/sandbox-providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/features/BrowsingAsyncClient.java +++ b/providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/features/BrowsingAsyncClient.java @@ -19,12 +19,15 @@ package org.jclouds.savvis.vpdc.features; +import java.net.URI; + import javax.annotation.Nullable; import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import org.jclouds.rest.annotations.BinderParam; +import org.jclouds.rest.annotations.EndpointParam; import org.jclouds.rest.annotations.ExceptionParser; import org.jclouds.rest.annotations.ParamParser; import org.jclouds.rest.annotations.RequestFilters; @@ -57,7 +60,6 @@ import com.google.common.util.concurrent.ListenableFuture; * @author Adrian Cole */ @RequestFilters(SetVCloudTokenCookie.class) -@Path("v{jclouds.api-version}") public interface BrowsingAsyncClient { /** @@ -66,9 +68,9 @@ public interface BrowsingAsyncClient { @GET @XMLResponseParser(OrgHandler.class) @ExceptionParser(ReturnNullOnNotFoundOr404.class) - @Path("org/{billingSiteId}") + @Path("v{jclouds.api-version}/org/{billingSiteId}") ListenableFuture getOrg( - @PathParam("billingSiteId") @Nullable @ParamParser(DefaultOrgIfNull.class) String billingSiteId); + @PathParam("billingSiteId") @Nullable @ParamParser(DefaultOrgIfNull.class) String billingSiteId); /** * @see BrowsingClient#getVDCInOrg @@ -76,10 +78,10 @@ public interface BrowsingAsyncClient { @GET @XMLResponseParser(VDCHandler.class) @ExceptionParser(ReturnNullOnNotFoundOr404.class) - @Path("org/{billingSiteId}/vdc/{vpdcId}") + @Path("v{jclouds.api-version}/org/{billingSiteId}/vdc/{vpdcId}") ListenableFuture getVDCInOrg( - @PathParam("billingSiteId") @Nullable @ParamParser(DefaultOrgIfNull.class) String billingSiteId, - @PathParam("vpdcId") String vpdcId); + @PathParam("billingSiteId") @Nullable @ParamParser(DefaultOrgIfNull.class) String billingSiteId, + @PathParam("vpdcId") String vpdcId); /** * @see BrowsingClient#getNetworkInVDC @@ -87,10 +89,10 @@ public interface BrowsingAsyncClient { @GET @XMLResponseParser(NetworkHandler.class) @ExceptionParser(ReturnNullOnNotFoundOr404.class) - @Path("org/{billingSiteId}/vdc/{vpdcId}/network/{network-tier-name}") + @Path("v{jclouds.api-version}/org/{billingSiteId}/vdc/{vpdcId}/network/{network-tier-name}") ListenableFuture getNetworkInVDC( - @PathParam("billingSiteId") @Nullable @ParamParser(DefaultOrgIfNull.class) String billingSiteId, - @PathParam("vpdcId") String vpdcId, @PathParam("network-tier-name") String networkTierName); + @PathParam("billingSiteId") @Nullable @ParamParser(DefaultOrgIfNull.class) String billingSiteId, + @PathParam("vpdcId") String vpdcId, @PathParam("network-tier-name") String networkTierName); /** * @see BrowsingClient#getVMInVDC @@ -98,19 +100,27 @@ public interface BrowsingAsyncClient { @GET @XMLResponseParser(VMHandler.class) @ExceptionParser(ReturnNullOnNotFoundOr404.class) - @Path("org/{billingSiteId}/vdc/{vpdcId}/vApp/{vAppId}") + @Path("v{jclouds.api-version}/org/{billingSiteId}/vdc/{vpdcId}/vApp/{vAppId}") ListenableFuture getVMInVDC( - @PathParam("billingSiteId") @Nullable @ParamParser(DefaultOrgIfNull.class) String billingSiteId, + @PathParam("billingSiteId") @Nullable @ParamParser(DefaultOrgIfNull.class) String billingSiteId, @PathParam("vpdcId") String vpdcId, @PathParam("vAppId") String vAppId, @BinderParam(BindGetVMOptions.class) GetVMOptions... options); + /** + * @see BrowsingClient#getVM + */ + @GET + @XMLResponseParser(VMHandler.class) + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + ListenableFuture getVM(@EndpointParam URI vm, @BinderParam(BindGetVMOptions.class) GetVMOptions... options); + /** * @see BrowsingClient#getTask */ @GET @XMLResponseParser(TaskHandler.class) @ExceptionParser(ReturnNullOnNotFoundOr404.class) - @Path("task/{taskId}") + @Path("v{jclouds.api-version}/task/{taskId}") ListenableFuture getTask(@PathParam("taskId") String taskId); /** @@ -119,8 +129,9 @@ public interface BrowsingAsyncClient { @GET @XMLResponseParser(FirewallServiceHandler.class) @ExceptionParser(ReturnNullOnNotFoundOr404.class) - @Path("org/{billingSiteId}/vdc/{vpdcId}/FirewallService") - ListenableFuture listFirewallRules(@PathParam("billingSiteId") @Nullable @ParamParser(DefaultOrgIfNull.class) String billingSiteId, - @PathParam("vpdcId") String vpdcId); - + @Path("v{jclouds.api-version}/org/{billingSiteId}/vdc/{vpdcId}/FirewallService") + ListenableFuture listFirewallRules( + @PathParam("billingSiteId") @Nullable @ParamParser(DefaultOrgIfNull.class) String billingSiteId, + @PathParam("vpdcId") String vpdcId); + } diff --git a/sandbox-providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/features/BrowsingClient.java b/providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/features/BrowsingClient.java similarity index 90% rename from sandbox-providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/features/BrowsingClient.java rename to providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/features/BrowsingClient.java index eec8a91741..d17370623a 100644 --- a/sandbox-providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/features/BrowsingClient.java +++ b/providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/features/BrowsingClient.java @@ -19,6 +19,7 @@ package org.jclouds.savvis.vpdc.features; +import java.net.URI; import java.util.concurrent.TimeUnit; import javax.annotation.Nullable; @@ -28,8 +29,8 @@ import org.jclouds.savvis.vpdc.domain.FirewallService; import org.jclouds.savvis.vpdc.domain.Network; import org.jclouds.savvis.vpdc.domain.Org; import org.jclouds.savvis.vpdc.domain.Task; -import org.jclouds.savvis.vpdc.domain.VM; import org.jclouds.savvis.vpdc.domain.VDC; +import org.jclouds.savvis.vpdc.domain.VM; import org.jclouds.savvis.vpdc.options.GetVMOptions; /** @@ -95,14 +96,16 @@ public interface BrowsingClient { */ VM getVMInVDC(String billingSiteId, String vpdcId, String vAppId, GetVMOptions... options); + VM getVM(URI vm, GetVMOptions... options); + /** * Gets an existing task. * * @param taskId * task id - * @return If the request is successful, caller could get the VM/VMDK details as specified in - * the result element and if the request is not successful, caller would get empty - * VAPP/VMDK URL and respective validation (error) message. + * @return If the request is successful, caller could get the VM/VMDK details as specified in the + * result element and if the request is not successful, caller would get empty VAPP/VMDK + * URL and respective validation (error) message. */ Task getTask(String taskId); @@ -115,9 +118,9 @@ public interface BrowsingClient { * vpdc Id * * @return If the request is successful, caller could get the firewall rules as specified in the - * result element and if the request is not successful, caller would get empty - * rules list and respective validation (error) message. + * result element and if the request is not successful, caller would get empty rules list + * and respective validation (error) message. */ FirewallService listFirewallRules(String billingSiteId, String vpdcId); - + } \ No newline at end of file diff --git a/sandbox-providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/features/FirewallAsyncClient.java b/providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/features/FirewallAsyncClient.java similarity index 100% rename from sandbox-providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/features/FirewallAsyncClient.java rename to providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/features/FirewallAsyncClient.java diff --git a/sandbox-providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/features/FirewallClient.java b/providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/features/FirewallClient.java similarity index 100% rename from sandbox-providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/features/FirewallClient.java rename to providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/features/FirewallClient.java diff --git a/providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/features/ServiceManagementAsyncClient.java b/providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/features/ServiceManagementAsyncClient.java new file mode 100644 index 0000000000..99691aa8a8 --- /dev/null +++ b/providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/features/ServiceManagementAsyncClient.java @@ -0,0 +1,86 @@ +/** + * + * Copyright (C) 2010 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.features; + +import java.net.URI; + +import javax.annotation.Nullable; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; + +import org.jclouds.rest.annotations.EndpointParam; +import org.jclouds.rest.annotations.ParamParser; +import org.jclouds.rest.annotations.RequestFilters; +import org.jclouds.rest.annotations.XMLResponseParser; +import org.jclouds.savvis.vpdc.domain.Task; +import org.jclouds.savvis.vpdc.filters.SetVCloudTokenCookie; +import org.jclouds.savvis.vpdc.functions.DefaultOrgIfNull; +import org.jclouds.savvis.vpdc.xml.TaskHandler; + +import com.google.common.util.concurrent.ListenableFuture; + +/** + * Provides access to Symphony VPDC resources via their REST API. + *

+ * + * @see + * @author Adrian Cole + */ +@RequestFilters(SetVCloudTokenCookie.class) +public interface ServiceManagementAsyncClient { + + /** + * @see VMClient#powerOnVMInVDC + */ + @POST + @XMLResponseParser(TaskHandler.class) + @Path("v{jclouds.api-version}/org/{billingSiteId}/vdc/{vpdcId}/vApp/{vAppId}/action/powerOn") + ListenableFuture powerOnVMInVDC( + @PathParam("billingSiteId") @Nullable @ParamParser(DefaultOrgIfNull.class) String billingSiteId, + @PathParam("vpdcId") String vpdcId, @PathParam("vAppId") String vAppId); + + /** + * @see VMClient#powerOnVM + */ + @POST + @XMLResponseParser(TaskHandler.class) + @Path("/action/powerOn") + ListenableFuture powerOnVM(@EndpointParam URI vm); + + /** + * @see VMClient#powerOffVMInVDC + */ + @POST + @XMLResponseParser(TaskHandler.class) + @Path("v{jclouds.api-version}/org/{billingSiteId}/vdc/{vpdcId}/vApp/{vAppId}/action/powerOff") + ListenableFuture powerOffVMInVDC( + @PathParam("billingSiteId") @Nullable @ParamParser(DefaultOrgIfNull.class) String billingSiteId, + @PathParam("vpdcId") String vpdcId, @PathParam("vAppId") String vAppId); + + /** + * @see VMClient#powerOffVM + */ + @POST + @XMLResponseParser(TaskHandler.class) + @Path("/action/powerOff") + ListenableFuture powerOffVM(@EndpointParam URI vm); + +} diff --git a/providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/features/ServiceManagementClient.java b/providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/features/ServiceManagementClient.java new file mode 100644 index 0000000000..c0e7528e62 --- /dev/null +++ b/providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/features/ServiceManagementClient.java @@ -0,0 +1,87 @@ +/** + * + * Copyright (C) 2010 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.features; + +import java.net.URI; +import java.util.concurrent.TimeUnit; + +import org.jclouds.concurrent.Timeout; +import org.jclouds.savvis.vpdc.domain.Task; + +/** + * Provides access to Symphony VPDC resources via their REST API. + *

+ * + * @see + * @author Adrian Cole + */ +@Timeout(duration = 300, timeUnit = TimeUnit.SECONDS) +public interface ServiceManagementClient { + /** + * Powers on the VM + *

+ *

Pre-conditions:

+ *

+ * No other API operation is being performed on the VM. + * + * @param billingSiteId + * billing site Id, or null for default + * @param vpdcId + * vpdc Id + * @param vmId + * vm you wish to remove + * @return task of the power operation + */ + Task powerOnVMInVDC(String billingSiteId, String vpdcId, String vmId); + + /** + * + * @param vm + * href of the vm + * @see #powerOnVMInVDC + */ + Task powerOnVM(URI vm); + + /** + * Powers off the VM + *

+ *

Pre-conditions:

+ *

+ * No other API operation is being performed on the VM. + * + * @param billingSiteId + * billing site Id, or null for default + * @param vpdcId + * vpdc Id + * @param vmId + * vm you wish to remove + * @return task of the power operation + */ + Task powerOffVMInVDC(String billingSiteId, String vpdcId, String vmId); + + /** + * + * @param vm + * href of the vm + * @see #powerOffVMInVDC + */ + Task powerOffVM(URI vm); + +} \ No newline at end of file diff --git a/sandbox-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 similarity index 72% rename from sandbox-providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/features/VMAsyncClient.java rename to providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/features/VMAsyncClient.java index 574b1db53c..b52066ebc0 100644 --- a/sandbox-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,12 +19,15 @@ package org.jclouds.savvis.vpdc.features; +import java.net.URI; + import javax.annotation.Nullable; import javax.ws.rs.DELETE; import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.PathParam; +import org.jclouds.rest.annotations.EndpointParam; import org.jclouds.rest.annotations.ExceptionParser; import org.jclouds.rest.annotations.MapBinder; import org.jclouds.rest.annotations.ParamParser; @@ -49,7 +52,6 @@ import com.google.common.util.concurrent.ListenableFuture; * @author Adrian Cole */ @RequestFilters(SetVCloudTokenCookie.class) -@Path("v{jclouds.api-version}") public interface VMAsyncClient { /** @@ -57,22 +59,29 @@ public interface VMAsyncClient { */ @GET @XMLResponseParser(TaskHandler.class) - @Path("org/{billingSiteId}/vdc/{vpdcId}/vApp/") + @Path("v{jclouds.api-version}/org/{billingSiteId}/vdc/{vpdcId}/vApp/") @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("billingSiteId") @Nullable @ParamParser(DefaultOrgIfNull.class) String billingSiteId, + @PathParam("vpdcId") String vpdcId, @PayloadParam("networkName") String networkTierName, + @PayloadParam("name") String vAppName, VMSpec spec); /** * @see VMClient#removeVMFromVDC */ @DELETE @XMLResponseParser(TaskHandler.class) - @Path("org/{billingSiteId}/vdc/{vpdcId}/vApp/{vAppId}") + @Path("v{jclouds.api-version}/org/{billingSiteId}/vdc/{vpdcId}/vApp/{vAppId}") @ExceptionParser(ReturnNullOnNotFoundOr404.class) ListenableFuture removeVMFromVDC( - @PathParam("billingSiteId") @Nullable @ParamParser(DefaultOrgIfNull.class) String billingSiteId, - @PathParam("vpdcId") String vpdcId, @PathParam("vAppId") String vAppId); + @PathParam("billingSiteId") @Nullable @ParamParser(DefaultOrgIfNull.class) String billingSiteId, + @PathParam("vpdcId") String vpdcId, @PathParam("vAppId") String vAppId); + /** + * @see VMClient#removeVM + */ + @DELETE + @XMLResponseParser(TaskHandler.class) + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + ListenableFuture removeVM(@EndpointParam URI vm); } diff --git a/sandbox-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 similarity index 85% rename from sandbox-providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/features/VMClient.java rename to providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/features/VMClient.java index 2c0bef2225..133998c96a 100644 --- a/sandbox-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,6 +19,7 @@ package org.jclouds.savvis.vpdc.features; +import java.net.URI; import java.util.concurrent.TimeUnit; import org.jclouds.concurrent.Timeout; @@ -63,10 +64,22 @@ public interface VMClient { * * * @param billingSiteId + * billing site Id, or null for default * @param vpdcId - * @param vAppId - * @return + * vpdc Id + * @param vmId + * vm you wish to remove + * @return null, if the vm was not found */ - Task removeVMFromVDC(String billingSiteId, String vpdcId, String vAppId); + Task removeVMFromVDC(String billingSiteId, String vpdcId, String vmId); -} \ No newline at end of file + /** + * + * Remove a VM + * + * @param vm + * href of the vm + * @see #removeVMFromVDC + */ + Task removeVM(URI vm); +} diff --git a/sandbox-providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/filters/SetVCloudTokenCookie.java b/providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/filters/SetVCloudTokenCookie.java similarity index 100% rename from sandbox-providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/filters/SetVCloudTokenCookie.java rename to providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/filters/SetVCloudTokenCookie.java diff --git a/sandbox-providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/functions/DefaultOrgIfNull.java b/providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/functions/DefaultOrgIfNull.java similarity index 100% rename from sandbox-providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/functions/DefaultOrgIfNull.java rename to providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/functions/DefaultOrgIfNull.java diff --git a/sandbox-providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/functions/ParseLoginResponseFromHeaders.java b/providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/functions/ParseLoginResponseFromHeaders.java similarity index 100% rename from sandbox-providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/functions/ParseLoginResponseFromHeaders.java rename to providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/functions/ParseLoginResponseFromHeaders.java diff --git a/sandbox-providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/handlers/VPDCErrorHandler.java b/providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/handlers/VPDCErrorHandler.java similarity index 100% rename from sandbox-providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/handlers/VPDCErrorHandler.java rename to providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/handlers/VPDCErrorHandler.java diff --git a/sandbox-providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/internal/LoginAsyncClient.java b/providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/internal/LoginAsyncClient.java similarity index 100% rename from sandbox-providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/internal/LoginAsyncClient.java rename to providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/internal/LoginAsyncClient.java diff --git a/sandbox-providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/internal/Network.java b/providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/internal/Network.java similarity index 100% rename from sandbox-providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/internal/Network.java rename to providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/internal/Network.java diff --git a/sandbox-providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/internal/Org.java b/providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/internal/Org.java similarity index 100% rename from sandbox-providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/internal/Org.java rename to providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/internal/Org.java diff --git a/sandbox-providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/internal/VCloudToken.java b/providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/internal/VCloudToken.java similarity index 100% rename from sandbox-providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/internal/VCloudToken.java rename to providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/internal/VCloudToken.java diff --git a/sandbox-providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/internal/VDC.java b/providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/internal/VDC.java similarity index 100% rename from sandbox-providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/internal/VDC.java rename to providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/internal/VDC.java diff --git a/sandbox-providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/options/BindGetVMOptions.java b/providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/options/BindGetVMOptions.java similarity index 100% rename from sandbox-providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/options/BindGetVMOptions.java rename to providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/options/BindGetVMOptions.java diff --git a/sandbox-providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/options/GetVMOptions.java b/providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/options/GetVMOptions.java similarity index 100% rename from sandbox-providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/options/GetVMOptions.java rename to providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/options/GetVMOptions.java diff --git a/sandbox-providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/predicates/TaskSuccess.java b/providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/predicates/TaskSuccess.java similarity index 100% rename from sandbox-providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/predicates/TaskSuccess.java rename to providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/predicates/TaskSuccess.java diff --git a/sandbox-providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/reference/VCloudMediaType.java b/providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/reference/VCloudMediaType.java similarity index 100% rename from sandbox-providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/reference/VCloudMediaType.java rename to providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/reference/VCloudMediaType.java diff --git a/sandbox-providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/reference/VCloudConstants.java b/providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/reference/VPDCConstants.java similarity index 57% rename from sandbox-providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/reference/VCloudConstants.java rename to providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/reference/VPDCConstants.java index 38874dcc59..f3c0fdf13c 100644 --- a/sandbox-providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/reference/VCloudConstants.java +++ b/providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/reference/VPDCConstants.java @@ -24,18 +24,13 @@ package org.jclouds.savvis.vpdc.reference; * * @author Adrian Cole */ -public interface VCloudConstants { - public static final String PROPERTY_VCLOUD_VERSION_SCHEMA = "jclouds.vcloud.version.schema"; +public interface VPDCConstants { /** - * name of the default network, in the default VDC that your vApp will join. + * which email must be present for VDCs to be considered yours */ - public static final String PROPERTY_VCLOUD_DEFAULT_NETWORK = "jclouds.vcloud.defaults.network"; - public static final String PROPERTY_VCLOUD_DEFAULT_FENCEMODE = "jclouds.vcloud.defaults.fencemode"; + public static final String PROPERTY_VPDC_VDC_EMAIL = "savvis-symphonyvpdc.vdc-email"; - public static final String PROPERTY_VCLOUD_XML_NAMESPACE = "jclouds.vcloud.xml.ns"; - public static final String PROPERTY_VCLOUD_XML_SCHEMA = "jclouds.vcloud.xml.schema"; - - public static final String PROPERTY_VCLOUD_TIMEOUT_TASK_COMPLETED = "jclouds.vcloud.timeout.task-complete"; + public static final String PROPERTY_VPDC_TIMEOUT_TASK_COMPLETED = "jclouds.vpdc.timeout.task-complete"; } diff --git a/sandbox-providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/util/Utils.java b/providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/util/Utils.java similarity index 58% rename from sandbox-providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/util/Utils.java rename to providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/util/Utils.java index 3558729a60..6c2a166cde 100644 --- a/sandbox-providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/util/Utils.java +++ b/providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/util/Utils.java @@ -19,14 +19,26 @@ package org.jclouds.savvis.vpdc.util; +import static com.google.common.base.Predicates.notNull; +import static com.google.common.collect.Iterables.concat; +import static com.google.common.collect.Iterables.filter; +import static com.google.common.collect.Iterables.transform; + import java.net.URI; import java.util.Map; +import java.util.Set; import org.jclouds.savvis.vpdc.domain.Link; +import org.jclouds.savvis.vpdc.domain.NetworkConfigSection; +import org.jclouds.savvis.vpdc.domain.NetworkConnectionSection; import org.jclouds.savvis.vpdc.domain.Resource; +import org.jclouds.savvis.vpdc.domain.ResourceImpl; +import org.jclouds.savvis.vpdc.domain.VM; import org.xml.sax.Attributes; +import com.google.common.base.Function; import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableMap.Builder; /** @@ -34,7 +46,7 @@ import com.google.common.collect.ImmutableMap.Builder; * @author Adrian Cole */ public class Utils { - + public static Resource newResource(Map attributes, String defaultType) { String uri = attributes.get("href"); String type = attributes.get("type"); @@ -46,8 +58,27 @@ public class Utils { id = uri.substring(uri.lastIndexOf('/') + 1); } return (attributes.containsKey("rel")) ? new Link(id, attributes.get("name"), type != null ? type : defaultType, - href, attributes.get("rel")) : new Resource(id, attributes.get("name"), type != null ? type : defaultType, - href); + href, attributes.get("rel")) : new ResourceImpl(id, attributes.get("name"), type != null ? type + : defaultType, href); + } + + public static Set getIpsFromVM(VM vm) { + Iterable ipFromConnections = transform(vm.getNetworkConnectionSections(), + new Function() { + @Override + public String apply(NetworkConnectionSection input) { + return input.getIpAddress(); + }; + }); + Iterable ipsFromNat = concat(transform(vm.getNetworkConfigSections(), + new Function>() { + @Override + public Iterable apply(NetworkConfigSection input) { + return concat(input.getInternalToExternalNATRules().keySet(), input + .getInternalToExternalNATRules().values()); + }; + })); + return ImmutableSet.copyOf(filter(concat(ipFromConnections, ipsFromNat), notNull())); } public static Map cleanseAttributes(Attributes in) { diff --git a/sandbox-providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/xml/FirewallRuleHandler.java b/providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/xml/FirewallRuleHandler.java similarity index 100% rename from sandbox-providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/xml/FirewallRuleHandler.java rename to providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/xml/FirewallRuleHandler.java diff --git a/sandbox-providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/xml/FirewallServiceHandler.java b/providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/xml/FirewallServiceHandler.java similarity index 100% rename from sandbox-providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/xml/FirewallServiceHandler.java rename to providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/xml/FirewallServiceHandler.java diff --git a/providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/xml/NetworkConfigSectionHandler.java b/providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/xml/NetworkConfigSectionHandler.java new file mode 100644 index 0000000000..c050f3bcad --- /dev/null +++ b/providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/xml/NetworkConfigSectionHandler.java @@ -0,0 +1,65 @@ +/** + * + * Copyright (C) 2010 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.xml; + +import static org.jclouds.util.SaxUtils.currentOrNull; +import static org.jclouds.util.SaxUtils.equalsOrSuffix; + +import java.util.Map; + +import javax.inject.Inject; +import javax.inject.Provider; + +import org.jclouds.ovf.xml.SectionHandler; +import org.jclouds.savvis.vpdc.domain.NetworkConfigSection; +import org.jclouds.util.SaxUtils; +import org.xml.sax.Attributes; + +/** + * @author Adrian Cole + */ +public class NetworkConfigSectionHandler extends SectionHandler { + + @Inject + public NetworkConfigSectionHandler(Provider builderProvider) { + super(builderProvider); + } + + public void startElement(String uri, String localName, String qName, Attributes attrs) { + Map attributes = SaxUtils.cleanseAttributes(attrs); + if (equalsOrSuffix(qName, "Section") && "vApp:NetworkConfigSectionType".equals(attributes.get("type"))) { + builder.network(attributes.get("Network")); + builder.netmask(attributes.get("Netmask")); + builder.gateway(attributes.get("Gateway")); + } else if (equalsOrSuffix(qName, "NatRule")) { + builder.internalToExternalNATRule(attributes.get("internalIP"), attributes.get("externalIP")); + } + } + + @Override + public void endElement(String uri, String localName, String qName) { + if (equalsOrSuffix(qName, "FenceMode")) { + builder.fenceMode(currentOrNull(currentText)); + } else if (equalsOrSuffix(qName, "Dhcp")) { + builder.dhcp(new Boolean(currentOrNull(currentText))); + } + super.endElement(uri, localName, qName); + } +} diff --git a/providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/xml/NetworkConnectionSectionHandler.java b/providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/xml/NetworkConnectionSectionHandler.java new file mode 100644 index 0000000000..b3bb596818 --- /dev/null +++ b/providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/xml/NetworkConnectionSectionHandler.java @@ -0,0 +1,60 @@ +/** + * + * Copyright (C) 2010 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.xml; + +import static org.jclouds.util.SaxUtils.currentOrNull; +import static org.jclouds.util.SaxUtils.equalsOrSuffix; + +import java.util.Map; + +import javax.inject.Inject; +import javax.inject.Provider; + +import org.jclouds.ovf.xml.SectionHandler; +import org.jclouds.savvis.vpdc.domain.NetworkConnectionSection; +import org.jclouds.util.SaxUtils; +import org.xml.sax.Attributes; + +/** + * @author Adrian Cole + */ +public class NetworkConnectionSectionHandler extends + SectionHandler { + + @Inject + public NetworkConnectionSectionHandler(Provider builderProvider) { + super(builderProvider); + } + + public void startElement(String uri, String localName, String qName, Attributes attrs) { + Map attributes = SaxUtils.cleanseAttributes(attrs); + if (equalsOrSuffix(qName, "Section") && "vApp:NetworkConnectionType".equals(attributes.get("type"))) { + builder.network(attributes.get("Network")); + } + } + + @Override + public void endElement(String uri, String localName, String qName) { + if (equalsOrSuffix(qName, "IpAddress")) { + builder.ipAddress(currentOrNull(currentText)); + } + super.endElement(uri, localName, qName); + } +} diff --git a/sandbox-providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/xml/NetworkHandler.java b/providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/xml/NetworkHandler.java similarity index 100% rename from sandbox-providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/xml/NetworkHandler.java rename to providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/xml/NetworkHandler.java diff --git a/providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/xml/NetworkSectionHandler.java b/providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/xml/NetworkSectionHandler.java new file mode 100644 index 0000000000..0325fbc24e --- /dev/null +++ b/providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/xml/NetworkSectionHandler.java @@ -0,0 +1,69 @@ +/** + * + * Copyright (C) 2010 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.xml; + +import static org.jclouds.util.SaxUtils.currentOrNull; +import static org.jclouds.util.SaxUtils.equalsOrSuffix; + +import java.util.Map; + +import javax.inject.Inject; +import javax.inject.Provider; + +import org.jclouds.ovf.Network; +import org.jclouds.ovf.NetworkSection; +import org.jclouds.ovf.xml.SectionHandler; +import org.jclouds.util.SaxUtils; +import org.xml.sax.Attributes; + +/** + * @author Adrian Cole + */ +public class NetworkSectionHandler extends SectionHandler { + protected Network.Builder networkBuilder = Network.builder(); + + @Inject + public NetworkSectionHandler(Provider builderProvider) { + super(builderProvider); + } + + public void startElement(String uri, String localName, String qName, Attributes attrs) { + Map attributes = SaxUtils.cleanseAttributes(attrs); + if (equalsOrSuffix(qName, "Network")) { + networkBuilder.name(attributes.get("name")); + } + } + + @Override + public void endElement(String uri, String localName, String qName) { + if (equalsOrSuffix(qName, "Info")) { + builder.info(currentOrNull(currentText)); + } else if (equalsOrSuffix(qName, "Description")) { + networkBuilder.description(currentOrNull(currentText)); + } else if (equalsOrSuffix(qName, "Network")) { + try { + builder.network(networkBuilder.build()); + } finally { + networkBuilder = Network.builder(); + } + } + super.endElement(uri, localName, qName); + } +} diff --git a/sandbox-providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/xml/OrgHandler.java b/providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/xml/OrgHandler.java similarity index 100% rename from sandbox-providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/xml/OrgHandler.java rename to providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/xml/OrgHandler.java diff --git a/sandbox-providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/xml/OrgListHandler.java b/providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/xml/OrgListHandler.java similarity index 100% rename from sandbox-providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/xml/OrgListHandler.java rename to providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/xml/OrgListHandler.java diff --git a/sandbox-providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/xml/TaskHandler.java b/providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/xml/TaskHandler.java similarity index 100% rename from sandbox-providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/xml/TaskHandler.java rename to providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/xml/TaskHandler.java diff --git a/sandbox-providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/xml/TasksListHandler.java b/providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/xml/TasksListHandler.java similarity index 100% rename from sandbox-providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/xml/TasksListHandler.java rename to providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/xml/TasksListHandler.java diff --git a/sandbox-providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/xml/VDCHandler.java b/providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/xml/VDCHandler.java similarity index 100% rename from sandbox-providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/xml/VDCHandler.java rename to providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/xml/VDCHandler.java diff --git a/providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/xml/VMHandler.java b/providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/xml/VMHandler.java new file mode 100644 index 0000000000..7801858b25 --- /dev/null +++ b/providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/xml/VMHandler.java @@ -0,0 +1,94 @@ +/** + * + * Copyright (C) 2010 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.xml; + +import static org.jclouds.savvis.vpdc.util.Utils.newResource; +import static org.jclouds.util.SaxUtils.equalsOrSuffix; + +import java.util.Map; + +import javax.inject.Inject; +import javax.inject.Provider; + +import org.jclouds.ovf.NetworkSection; +import org.jclouds.ovf.Section; +import org.jclouds.ovf.xml.NetworkSectionHandler; +import org.jclouds.ovf.xml.OperatingSystemSectionHandler; +import org.jclouds.ovf.xml.ProductSectionHandler; +import org.jclouds.ovf.xml.SectionHandler; +import org.jclouds.ovf.xml.VirtualHardwareSectionHandler; +import org.jclouds.ovf.xml.internal.BaseVirtualSystemHandler; +import org.jclouds.savvis.vpdc.domain.NetworkConfigSection; +import org.jclouds.savvis.vpdc.domain.NetworkConnectionSection; +import org.jclouds.savvis.vpdc.domain.Resource; +import org.jclouds.savvis.vpdc.domain.VM; +import org.jclouds.savvis.vpdc.util.Utils; +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; + +import com.google.common.collect.ImmutableMap; + +/** + * @author Kedar Dave + */ +public class VMHandler extends BaseVirtualSystemHandler { + + @SuppressWarnings("unchecked") + @Inject + public VMHandler(Provider builderProvider, OperatingSystemSectionHandler osHandler, + VirtualHardwareSectionHandler hardwareHandler, ProductSectionHandler productHandler, + Provider networkSectionHandler, + Provider networkConfigSectionHandler, + Provider networkConnectionSectionHandler) { + super(builderProvider, osHandler, hardwareHandler, productHandler); + this.extensionHandlers = ImmutableMap.> of("ovf:NetworkSection", + networkSectionHandler, "vApp:NetworkConfigSectionType", networkConfigSectionHandler, + "vApp:NetworkConnectionType", networkConnectionSectionHandler); + } + + public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException { + Map attributes = Utils.cleanseAttributes(attrs); + if (equalsOrSuffix(qName, "VApp")) { + // savvis doesn't add href in the header for some reason + if (!attributes.containsKey("href") && getRequest() != null) + attributes = ImmutableMap. builder().putAll(attributes).put("href", + getRequest().getEndpoint().toASCIIString()).build(); + Resource vApp = newResource(attributes); + builder.name(vApp.getName()).type(vApp.getType()).id(vApp.getId()).href(vApp.getHref()); + builder.status(VM.Status.fromValue(attributes.get("status"))); + } + super.startElement(uri, localName, qName, attrs); + } + + @Override + @SuppressWarnings("unchecked") + protected void addAdditionalSection(String qName, Section additionalSection) { + if (additionalSection instanceof NetworkSection) { + builder.networkSection(NetworkSection.class.cast(additionalSection)); + } else if (additionalSection instanceof NetworkConfigSection) { + builder.networkConfigSection(NetworkConfigSection.class.cast(additionalSection)); + } else if (additionalSection instanceof NetworkConnectionSection) { + builder.networkConnectionSection(NetworkConnectionSection.class.cast(additionalSection)); + } else { + builder.additionalSection(qName, additionalSection); + } + } + +} diff --git a/sandbox-providers/savvis-symphonyvpdc/src/main/resources/savvis-symphonyvpdc/predefined_operatingsystems.json b/providers/savvis-symphonyvpdc/src/main/resources/savvis-symphonyvpdc/predefined_operatingsystems.json similarity index 100% rename from sandbox-providers/savvis-symphonyvpdc/src/main/resources/savvis-symphonyvpdc/predefined_operatingsystems.json rename to providers/savvis-symphonyvpdc/src/main/resources/savvis-symphonyvpdc/predefined_operatingsystems.json diff --git a/sandbox-providers/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/VPDCAsyncClientTest.java b/providers/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/VPDCAsyncClientTest.java similarity index 100% rename from sandbox-providers/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/VPDCAsyncClientTest.java rename to providers/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/VPDCAsyncClientTest.java diff --git a/sandbox-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/BindVMSpecToXmlPayloadTest.java similarity index 100% rename from sandbox-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/BindVMSpecToXmlPayloadTest.java diff --git a/providers/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/compute/VPDCTemplateBuilderLiveTest.java b/providers/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/compute/VPDCTemplateBuilderLiveTest.java new file mode 100644 index 0000000000..256ceedc6c --- /dev/null +++ b/providers/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/compute/VPDCTemplateBuilderLiveTest.java @@ -0,0 +1,94 @@ +/** + * + * Copyright (C) 2010 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.compute; + +import static com.google.common.base.Preconditions.checkNotNull; +import static org.jclouds.compute.util.ComputeServiceUtils.getCores; +import static org.testng.Assert.assertEquals; + +import java.io.IOException; +import java.util.Properties; +import java.util.Set; + +import org.jclouds.compute.BaseTemplateBuilderLiveTest; +import org.jclouds.compute.domain.OsFamily; +import org.jclouds.compute.domain.OsFamilyVersion64Bit; +import org.jclouds.compute.domain.Template; +import org.jclouds.domain.LocationScope; +import org.jclouds.savvis.vpdc.reference.VPDCConstants; +import org.testng.annotations.Test; + +import com.google.common.base.Predicate; +import com.google.common.collect.ImmutableSet; + +/** + * + * @author Adrian Cole + */ +@Test(groups = "live") +public class VPDCTemplateBuilderLiveTest extends BaseTemplateBuilderLiveTest { + + public VPDCTemplateBuilderLiveTest() { + provider = "savvis-symphonyvpdc"; + } + + @Override + protected Predicate defineUnsupportedOperatingSystems() { + return new Predicate() { + + @Override + public boolean apply(OsFamilyVersion64Bit input) { + switch (input.family) { + case RHEL: + return !(input.version.equals("5") || input.version.equals("")); + case WINDOWS: + return !((input.version.equals("2008") || input.version.equals("")) && input.is64Bit); + default: + return true; + } + } + + }; + } + + @Override + public void testDefaultTemplateBuilder() throws IOException { + Template defaultTemplate = context.getComputeService().templateBuilder().build(); + assertEquals(defaultTemplate.getImage().getOperatingSystem().getVersion(), "5"); + assertEquals(defaultTemplate.getImage().getOperatingSystem().is64Bit(), true); + assertEquals(defaultTemplate.getImage().getOperatingSystem().getFamily(), OsFamily.RHEL); + assertEquals(defaultTemplate.getLocation().getScope(), LocationScope.NETWORK); + assertEquals(getCores(defaultTemplate.getHardware()), 1.0d); + } + + @Override + protected Set getIso3166Codes() { + // TODO make region aware + return ImmutableSet. of(); + } + + @Override + protected Properties setupProperties() { + Properties props = super.setupProperties(); + props.setProperty(VPDCConstants.PROPERTY_VPDC_VDC_EMAIL, checkNotNull(System.getProperty("test." + + VPDCConstants.PROPERTY_VPDC_VDC_EMAIL), "test." + VPDCConstants.PROPERTY_VPDC_VDC_EMAIL)); + return props; + } +} \ No newline at end of file diff --git a/sandbox-providers/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/features/BaseVPDCAsyncClientTest.java b/providers/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/features/BaseVPDCAsyncClientTest.java similarity index 84% rename from sandbox-providers/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/features/BaseVPDCAsyncClientTest.java rename to providers/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/features/BaseVPDCAsyncClientTest.java index dd573a2364..9a9bd0e4db 100644 --- a/sandbox-providers/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/features/BaseVPDCAsyncClientTest.java +++ b/providers/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/features/BaseVPDCAsyncClientTest.java @@ -38,10 +38,12 @@ import org.jclouds.savvis.vpdc.VPDCAsyncClient; import org.jclouds.savvis.vpdc.VPDCClient; import org.jclouds.savvis.vpdc.config.VPDCRestClientModule; import org.jclouds.savvis.vpdc.domain.Resource; +import org.jclouds.savvis.vpdc.domain.ResourceImpl; import org.jclouds.savvis.vpdc.domain.internal.VCloudSession; import org.jclouds.savvis.vpdc.filters.SetVCloudTokenCookie; import org.jclouds.savvis.vpdc.internal.LoginAsyncClient; import org.jclouds.savvis.vpdc.reference.VCloudMediaType; +import org.jclouds.savvis.vpdc.reference.VPDCConstants; import com.google.common.base.Supplier; import com.google.common.base.Suppliers; @@ -76,13 +78,13 @@ public abstract class BaseVPDCAsyncClientTest extends RestClientTest { @Override protected Supplier provideVCloudTokenCache(@Named(PROPERTY_SESSION_INTERVAL) long seconds, - final LoginAsyncClient login) { + final LoginAsyncClient login) { return Suppliers. ofInstance(new VCloudSession() { @Override public Set getOrgs() { - return ImmutableSet.of(new Resource("1", "org", VCloudMediaType.ORG_XML, URI - .create("https://api.symphonyvpdc.savvis.net/rest/api/v0.8/org/1"))); + return ImmutableSet. of(new ResourceImpl("1", "org", VCloudMediaType.ORG_XML, URI + .create("https://api.symphonyvpdc.savvis.net/rest/api/v0.8/org/1"))); } @Override @@ -96,4 +98,11 @@ public abstract class BaseVPDCAsyncClientTest extends RestClientTest { } + @Override + protected Properties getProperties() { + Properties props = super.getProperties(); + props.setProperty(VPDCConstants.PROPERTY_VPDC_VDC_EMAIL, "test"); + return props; + } + } \ No newline at end of file diff --git a/sandbox-providers/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/features/BaseVPDCClientLiveTest.java b/providers/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/features/BaseVPDCClientLiveTest.java similarity index 70% rename from sandbox-providers/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/features/BaseVPDCClientLiveTest.java rename to providers/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/features/BaseVPDCClientLiveTest.java index 215b5dc094..d33a359a24 100644 --- a/sandbox-providers/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/features/BaseVPDCClientLiveTest.java +++ b/providers/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/features/BaseVPDCClientLiveTest.java @@ -22,22 +22,24 @@ package org.jclouds.savvis.vpdc.features; import static com.google.common.base.Preconditions.checkNotNull; import java.util.Properties; +import java.util.concurrent.TimeUnit; +import org.jclouds.compute.ComputeServiceContext; +import org.jclouds.compute.ComputeServiceContextFactory; import org.jclouds.logging.log4j.config.Log4JLoggingModule; +import org.jclouds.predicates.RetryablePredicate; import org.jclouds.rest.RestContext; -import org.jclouds.rest.RestContextFactory; import org.jclouds.savvis.vpdc.VPDCAsyncClient; import org.jclouds.savvis.vpdc.VPDCClient; +import org.jclouds.savvis.vpdc.predicates.TaskSuccess; +import org.jclouds.savvis.vpdc.reference.VPDCConstants; import org.jclouds.ssh.jsch.config.JschSshClientModule; import org.testng.annotations.AfterGroups; import org.testng.annotations.BeforeGroups; import org.testng.annotations.Test; import com.google.common.collect.ImmutableSet; -import com.google.inject.Injector; -import com.google.inject.Key; import com.google.inject.Module; -import com.google.inject.TypeLiteral; /** * Tests behavior of {@code VPDCClient} @@ -47,18 +49,23 @@ import com.google.inject.TypeLiteral; @Test(groups = "live") public class BaseVPDCClientLiveTest { - protected RestContext context; + protected RestContext restContext; protected String provider = "savvis-symphonyvpdc"; protected String identity; protected String credential; protected String endpoint; protected String apiversion; - protected Injector injector; + protected ComputeServiceContext context; + protected String email; + protected RetryablePredicate taskTester; + protected String prefix = System.getProperty("user.name"); protected void setupCredentials() { identity = checkNotNull(System.getProperty("test." + provider + ".identity"), "test." + provider + ".identity"); credential = checkNotNull(System.getProperty("test." + provider + ".credential"), "test." + provider - + ".credential"); + + ".credential"); + email = checkNotNull(System.getProperty("test." + VPDCConstants.PROPERTY_VPDC_VDC_EMAIL), "test." + + VPDCConstants.PROPERTY_VPDC_VDC_EMAIL); endpoint = System.getProperty("test." + provider + ".endpoint"); apiversion = System.getProperty("test." + provider + ".apiversion"); } @@ -67,6 +74,7 @@ public class BaseVPDCClientLiveTest { Properties overrides = new Properties(); overrides.setProperty(provider + ".identity", identity); overrides.setProperty(provider + ".credential", credential); + overrides.setProperty(VPDCConstants.PROPERTY_VPDC_VDC_EMAIL, email); if (endpoint != null) overrides.setProperty(provider + ".endpoint", endpoint); if (apiversion != null) @@ -78,13 +86,10 @@ public class BaseVPDCClientLiveTest { public void setupClient() { setupCredentials(); Properties overrides = setupProperties(); - // context = new RestContextFactory().createContext(provider, ImmutableSet. of(new - // Log4JLoggingModule()), - // overrides); - injector = new RestContextFactory().createContextBuilder(provider, - ImmutableSet. of(new Log4JLoggingModule(), new JschSshClientModule()), overrides).buildInjector(); - context = injector.getInstance(Key.get(new TypeLiteral>() { - })); + context = new ComputeServiceContextFactory().createContext(provider, ImmutableSet. of( + new Log4JLoggingModule(), new JschSshClientModule()), overrides); + restContext = context.getProviderSpecificContext(); + taskTester = new RetryablePredicate(new TaskSuccess(restContext.getApi()), 650, 10, TimeUnit.SECONDS); } @AfterGroups(groups = "live") diff --git a/sandbox-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 similarity index 87% rename from sandbox-providers/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/features/BrowsingAsyncClientTest.java rename to providers/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/features/BrowsingAsyncClientTest.java index 33a5297bf2..9ad8824441 100644 --- a/sandbox-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 @@ -21,6 +21,7 @@ package org.jclouds.savvis.vpdc.features; import java.io.IOException; import java.lang.reflect.Method; +import java.net.URI; import org.jclouds.http.HttpRequest; import org.jclouds.http.functions.ParseSax; @@ -106,8 +107,7 @@ public class BrowsingAsyncClientTest extends BaseVPDCAsyncClientTest> createTypeLiteral() { return new TypeLiteral>() { diff --git a/sandbox-providers/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/features/BrowsingClientLiveTest.java b/providers/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/features/BrowsingClientLiveTest.java similarity index 66% rename from sandbox-providers/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/features/BrowsingClientLiveTest.java rename to providers/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/features/BrowsingClientLiveTest.java index f472d79b6c..7ca6b02938 100644 --- a/sandbox-providers/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/features/BrowsingClientLiveTest.java +++ b/providers/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/features/BrowsingClientLiveTest.java @@ -29,16 +29,19 @@ import java.util.Set; import org.jclouds.savvis.vpdc.domain.FirewallRule; import org.jclouds.savvis.vpdc.domain.FirewallService; import org.jclouds.savvis.vpdc.domain.Network; +import org.jclouds.savvis.vpdc.domain.NetworkConnectionSection; import org.jclouds.savvis.vpdc.domain.Org; import org.jclouds.savvis.vpdc.domain.Resource; -import org.jclouds.savvis.vpdc.domain.VM; import org.jclouds.savvis.vpdc.domain.VDC; +import org.jclouds.savvis.vpdc.domain.VM; import org.jclouds.savvis.vpdc.reference.VCloudMediaType; +import org.jclouds.util.InetAddresses2; import org.testng.annotations.BeforeGroups; import org.testng.annotations.Test; import com.google.common.base.Predicate; import com.google.common.collect.Iterables; +import com.google.common.net.HostSpecifier; @Test(groups = "live") public class BrowsingClientLiveTest extends BaseVPDCClientLiveTest { @@ -49,12 +52,12 @@ public class BrowsingClientLiveTest extends BaseVPDCClientLiveTest { @BeforeGroups(groups = { "live" }) public void setupClient() { super.setupClient(); - client = context.getApi().getBrowsingClient(); + client = restContext.getApi().getBrowsingClient(); } @Test public void testOrg() throws Exception { - for (Resource org : context.getApi().listOrgs()) { + for (Resource org : restContext.getApi().listOrgs()) { Org response = client.getOrg(org.getId()); assertNotNull(response); @@ -72,7 +75,7 @@ public class BrowsingClientLiveTest extends BaseVPDCClientLiveTest { @Test public void testVDC() throws Exception { - for (Resource org1 : context.getApi().listOrgs()) { + for (Resource org1 : restContext.getApi().listOrgs()) { Org org = client.getOrg(org1.getId()); for (Resource vdc : org.getVDCs()) { VDC response = client.getVDCInOrg(org.getId(), vdc.getId()); @@ -92,7 +95,7 @@ public class BrowsingClientLiveTest extends BaseVPDCClientLiveTest { @Test public void testNetwork() throws Exception { - for (Resource org1 : context.getApi().listOrgs()) { + for (Resource org1 : restContext.getApi().listOrgs()) { Org org = client.getOrg(org1.getId()); for (Resource vdc : org.getVDCs()) { VDC VDC = client.getVDCInOrg(org.getId(), vdc.getId()); @@ -106,16 +109,16 @@ public class BrowsingClientLiveTest extends BaseVPDCClientLiveTest { assertNotNull(response.getNetmask()); assertNotNull(response.getGateway()); assertNotNull(response.getInternalToExternalNATRules()); - assertEquals(client.getNetworkInVDC(org.getId(), vdc.getId(), response.getId()).toString(), - response.toString()); + assertEquals(client.getNetworkInVDC(org.getId(), vdc.getId(), response.getId()).toString(), response + .toString()); } } } } - + @Test public void testVM() throws Exception { - for (Resource org1 : context.getApi().listOrgs()) { + for (Resource org1 : restContext.getApi().listOrgs()) { Org org = client.getOrg(org1.getId()); for (Resource vdc : org.getVDCs()) { VDC VDC = client.getVDCInOrg(org.getId(), vdc.getId()); @@ -133,44 +136,53 @@ public class BrowsingClientLiveTest extends BaseVPDCClientLiveTest { assertNotNull(response.getHref()); assertNotNull(response.getName()); assertEquals(response.getType(), "application/vnd.vmware.vcloud.vApp+xml"); - assertNotNull(response.getIpAddress()); + assert (response.getNetworkConnectionSections().size() > 0) : response; + for (NetworkConnectionSection networkConnection : response.getNetworkConnectionSections()) + assertNotNull(networkConnection.getIpAddress()); assertNotNull(response.getStatus()); - assertNotNull(response.getOsDescripton()); - assertNotNull(response.getOsType()); + assertNotNull(response.getOperatingSystemSection().getDescription()); + assertNotNull(response.getOperatingSystemSection().getId()); assertNotNull(response.getNetworkSection()); - assertNotNull(response.getResourceAllocations()); + assertNotNull(response.getVirtualHardwareSections()); // power state is the only thing that should change - assertEquals(client.getVMInVDC(org.getId(), vdc.getId(), response.getId(), withPowerState()) - .toString().replaceFirst("status=[A-Z]+", ""), response.toString().replaceFirst( - "status=[A-Z]+", "")); + assertEquals(client.getVMInVDC(org.getId(), vdc.getId(), response.getId(), withPowerState()).toString() + .replaceFirst("status=[A-Z]+", ""), response.toString().replaceFirst("status=[A-Z]+", "")); + + // check one ip is valid + String ip = Iterables.get(response.getNetworkConnectionSections(), 0).getIpAddress(); + assert HostSpecifier.isValid(ip) : response; + if (InetAddresses2.isPrivateIPAddress(ip)) { + ip = Iterables.get(response.getNetworkConfigSections(), 0).getInternalToExternalNATRules().get(ip); + } + assert HostSpecifier.isValid(ip) : response; } } } } - + @Test public void testGetFirewallRules() throws Exception { - for (Resource org1 : context.getApi().listOrgs()) { - Org org = client.getOrg(org1.getId()); - for (Resource vdc : org.getVDCs()) { - FirewallService response = client.listFirewallRules(org.getId(), vdc.getId()); - Set firewallRules = response.getFirewallRules(); - if(firewallRules != null){ - Iterator iter = firewallRules.iterator(); - while(iter.hasNext()){ - FirewallRule firewallRule = iter.next(); - assertNotNull(firewallRule); - // these are null for firewall rules - assertEquals(response.getHref(), null); - assertEquals(response.getType(), null); - assertNotNull(firewallRule.getFirewallType()); - assertNotNull(firewallRule.getProtocol()); - assertNotNull(firewallRule.getSource()); - assertNotNull(firewallRule.getDestination()); - } - } - } - } + for (Resource org1 : restContext.getApi().listOrgs()) { + Org org = client.getOrg(org1.getId()); + for (Resource vdc : org.getVDCs()) { + FirewallService response = client.listFirewallRules(org.getId(), vdc.getId()); + Set firewallRules = response.getFirewallRules(); + if (firewallRules != null) { + Iterator iter = firewallRules.iterator(); + while (iter.hasNext()) { + FirewallRule firewallRule = iter.next(); + assertNotNull(firewallRule); + // these are null for firewall rules + assertEquals(response.getHref(), null); + assertEquals(response.getType(), null); + assertNotNull(firewallRule.getFirewallType()); + assertNotNull(firewallRule.getProtocol()); + assertNotNull(firewallRule.getSource()); + assertNotNull(firewallRule.getDestination()); + } + } + } + } } } \ No newline at end of file diff --git a/sandbox-providers/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/features/FirewallAsyncClientTest.java b/providers/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/features/FirewallAsyncClientTest.java similarity index 100% rename from sandbox-providers/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/features/FirewallAsyncClientTest.java rename to providers/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/features/FirewallAsyncClientTest.java diff --git a/sandbox-providers/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/features/FirewallClientLiveTest.java b/providers/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/features/FirewallClientLiveTest.java similarity index 95% rename from sandbox-providers/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/features/FirewallClientLiveTest.java rename to providers/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/features/FirewallClientLiveTest.java index b185b807d2..8c5d642c4a 100644 --- a/sandbox-providers/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/features/FirewallClientLiveTest.java +++ b/providers/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/features/FirewallClientLiveTest.java @@ -32,7 +32,7 @@ public class FirewallClientLiveTest extends BaseVPDCClientLiveTest { @BeforeGroups(groups = { "live" }) public void setupClient() { super.setupClient(); - client = context.getApi().getFirewallClient(); + client = restContext.getApi().getFirewallClient(); } 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 new file mode 100644 index 0000000000..bdf6f90440 --- /dev/null +++ b/providers/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/features/ServiceManagementAsyncClientTest.java @@ -0,0 +1,117 @@ +/** + * + * Copyright (C) 2010 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.features; + +import java.io.IOException; +import java.lang.reflect.Method; +import java.net.URI; + +import org.jclouds.http.HttpRequest; +import org.jclouds.http.functions.ParseSax; +import org.jclouds.rest.functions.MapHttp4xxCodesToExceptions; +import org.jclouds.rest.internal.RestAnnotationProcessor; +import org.jclouds.savvis.vpdc.xml.TaskHandler; +import org.testng.annotations.Test; + +import com.google.inject.TypeLiteral; + +/** + * Tests annotation parsing of {@code ServiceManagementAsyncClient} + * + * @author Adrian Cole + */ +@Test(groups = "unit") +public class ServiceManagementAsyncClientTest extends BaseVPDCAsyncClientTest { + + @Override + protected TypeLiteral> createTypeLiteral() { + return new TypeLiteral>() { + }; + } + + public void testPowerOnVMVDC() throws SecurityException, NoSuchMethodException, IOException { + Method method = ServiceManagementAsyncClient.class.getMethod("powerOnVMInVDC", String.class, String.class, + String.class); + HttpRequest request = processor.createRequest(method, "11", "22", "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); + + assertResponseParserClassEquals(method, request, ParseSax.class); + assertSaxResponseParserClassEquals(method, TaskHandler.class); + assertExceptionParserClassEquals(method, MapHttp4xxCodesToExceptions.class); + + checkFilters(request); + } + + public void testPowerOnVM() throws SecurityException, NoSuchMethodException, IOException { + Method method = ServiceManagementAsyncClient.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); + + assertResponseParserClassEquals(method, request, ParseSax.class); + assertSaxResponseParserClassEquals(method, TaskHandler.class); + assertExceptionParserClassEquals(method, MapHttp4xxCodesToExceptions.class); + + checkFilters(request); + } + + public void testPowerOffVMVDC() throws SecurityException, NoSuchMethodException, IOException { + Method method = ServiceManagementAsyncClient.class.getMethod("powerOffVMInVDC", String.class, String.class, + String.class); + HttpRequest request = processor.createRequest(method, "11", "22", "33"); + + assertRequestLineEquals(request, + "POST https://api.symphonyvpdc.savvis.net/rest/api/v0.8/org/11/vdc/22/vApp/33/action/powerOff HTTP/1.1"); + assertNonPayloadHeadersEqual(request, ""); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseSax.class); + assertSaxResponseParserClassEquals(method, TaskHandler.class); + assertExceptionParserClassEquals(method, MapHttp4xxCodesToExceptions.class); + + checkFilters(request); + } + + public void testPowerOffVM() throws SecurityException, NoSuchMethodException, IOException { + Method method = ServiceManagementAsyncClient.class.getMethod("powerOffVM", 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/powerOff HTTP/1.1"); + assertNonPayloadHeadersEqual(request, ""); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseSax.class); + assertSaxResponseParserClassEquals(method, TaskHandler.class); + assertExceptionParserClassEquals(method, MapHttp4xxCodesToExceptions.class); + + checkFilters(request); + } + +} diff --git a/providers/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/features/ServiceManagementClientLiveTest.java b/providers/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/features/ServiceManagementClientLiveTest.java new file mode 100644 index 0000000000..4a7c631608 --- /dev/null +++ b/providers/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/features/ServiceManagementClientLiveTest.java @@ -0,0 +1,82 @@ +/** + * + * Copyright (C) 2010 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.features; + +import static org.jclouds.savvis.vpdc.options.GetVMOptions.Builder.withPowerState; +import static org.testng.Assert.assertEquals; + +import java.io.IOException; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeoutException; + +import org.jclouds.savvis.vpdc.domain.Org; +import org.jclouds.savvis.vpdc.domain.Resource; +import org.jclouds.savvis.vpdc.domain.VDC; +import org.jclouds.savvis.vpdc.domain.VM; +import org.jclouds.savvis.vpdc.reference.VCloudMediaType; +import org.testng.annotations.BeforeGroups; +import org.testng.annotations.Test; + +import com.google.common.base.Predicate; +import com.google.common.collect.Iterables; + +@Test(groups = "live") +public class ServiceManagementClientLiveTest extends BaseVPDCClientLiveTest { + + private ServiceManagementClient client; + + @Override + @BeforeGroups(groups = { "live" }) + public void setupClient() { + super.setupClient(); + client = restContext.getApi().getServiceManagementClient(); + } + + public void testLifeCycle() throws InterruptedException, ExecutionException, TimeoutException, IOException { + for (Resource org1 : restContext.getApi().listOrgs()) { + Org org = restContext.getApi().getBrowsingClient().getOrg(org1.getId()); + for (Resource vdc : org.getVDCs()) { + VDC VDC = restContext.getApi().getBrowsingClient().getVDCInOrg(org.getId(), vdc.getId()); + for (Resource vmHandle : Iterables.filter(VDC.getResourceEntities(), new Predicate() { + + @Override + public boolean apply(Resource arg0) { + return VCloudMediaType.VAPP_XML.equals(arg0.getType()); + } + + })) { + + assert taskTester.apply(client.powerOffVM(vmHandle.getHref()).getId()); + + VM vm = restContext.getApi().getBrowsingClient().getVM(vmHandle.getHref(), withPowerState()); + assertEquals(vm.getStatus(), VM.Status.OFF); + + assert taskTester.apply(client.powerOnVM(vmHandle.getHref()).getId()); + + vm = restContext.getApi().getBrowsingClient().getVM(vmHandle.getHref(), withPowerState()); + + assertEquals(vm.getStatus(), VM.Status.ON); + + } + } + } + } + +} \ No newline at end of file diff --git a/sandbox-providers/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/features/VMAsyncClientTest.java b/providers/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/features/VMAsyncClientTest.java similarity index 75% rename from sandbox-providers/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/features/VMAsyncClientTest.java rename to providers/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/features/VMAsyncClientTest.java index 0e736e87b2..1067daefab 100644 --- a/sandbox-providers/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/features/VMAsyncClientTest.java +++ b/providers/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/features/VMAsyncClientTest.java @@ -21,6 +21,7 @@ package org.jclouds.savvis.vpdc.features; import java.io.IOException; import java.lang.reflect.Method; +import java.net.URI; import java.util.Set; import org.jclouds.cim.OSType; @@ -50,7 +51,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); + String.class, VMSpec.class); CIMOperatingSystem os = Iterables.find(injector.getInstance(Key.get(new TypeLiteral>() { })), new Predicate() { @@ -63,13 +64,13 @@ public class VMAsyncClientTest extends BaseVPDCAsyncClientTest { }); HttpRequest request = processor.createRequest(method, "11", "22", "VM Tier01", "DemoHost-1", VMSpec.builder() - .operatingSystem(os).build()); + .operatingSystem(os).build()); assertRequestLineEquals(request, - "GET https://api.symphonyvpdc.savvis.net/rest/api/v0.8/org/11/vdc/22/vApp/ HTTP/1.1"); + "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-default.xml")), - "application/xml", false); + "application/xml", false); assertResponseParserClassEquals(method, request, ParseSax.class); assertSaxResponseParserClassEquals(method, TaskHandler.class); @@ -78,12 +79,29 @@ public class VMAsyncClientTest extends BaseVPDCAsyncClientTest { checkFilters(request); } - public void testRemoveVM() throws SecurityException, NoSuchMethodException, IOException { + 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", "VM-Tier01"); + 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/VM-Tier01 HTTP/1.1"); + "DELETE https://api.symphonyvpdc.savvis.net/rest/api/v0.8/org/11/vdc/22/vApp/33 HTTP/1.1"); + assertNonPayloadHeadersEqual(request, ""); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseSax.class); + assertSaxResponseParserClassEquals(method, TaskHandler.class); + assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); + + checkFilters(request); + } + + public void testRemoveVM() throws SecurityException, NoSuchMethodException, IOException { + Method method = VMAsyncClient.class.getMethod("removeVM", 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, + "DELETE https://api.symphonyvpdc.savvis.net/rest/api/v0.8/org/11/vdc/22/vApp/33 HTTP/1.1"); assertNonPayloadHeadersEqual(request, ""); assertPayloadEquals(request, null, null, false); diff --git a/sandbox-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 similarity index 57% rename from sandbox-providers/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/features/VMClientLiveTest.java rename to providers/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/features/VMClientLiveTest.java index 99f14b1709..7ddfbfdb75 100644 --- a/sandbox-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,7 +22,6 @@ package org.jclouds.savvis.vpdc.features; import static com.google.common.base.Preconditions.checkNotNull; import static org.testng.Assert.assertEquals; -import java.util.Set; import java.util.concurrent.TimeUnit; import org.jclouds.cim.OSType; @@ -30,16 +29,14 @@ import org.jclouds.compute.domain.CIMOperatingSystem; import org.jclouds.compute.domain.ExecResponse; import org.jclouds.domain.Credentials; import org.jclouds.net.IPSocket; +import org.jclouds.predicates.InetSocketAddressConnect; import org.jclouds.predicates.RetryablePredicate; -import org.jclouds.predicates.SocketOpen; 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.VMSpec; -import org.jclouds.savvis.vpdc.predicates.TaskSuccess; import org.jclouds.ssh.SshClient; -import org.jclouds.ssh.SshClient.Factory; import org.jclouds.util.InetAddresses2; import org.testng.annotations.AfterGroups; import org.testng.annotations.BeforeGroups; @@ -48,107 +45,99 @@ import org.testng.annotations.Test; import com.google.common.base.Predicate; import com.google.common.collect.Iterables; import com.google.common.net.HostSpecifier; -import com.google.inject.Key; -import com.google.inject.TypeLiteral; @Test(groups = "live") public class VMClientLiveTest extends BaseVPDCClientLiveTest { private VMClient client; - private Factory sshFactory; private VM vm; private RetryablePredicate socketTester; - private RetryablePredicate taskTester; - - private String email = checkNotNull(System.getProperty("test." + provider + ".email"), "test." + provider + ".email"); + private String username = checkNotNull(System.getProperty("test." + provider + ".loginUser"), "test." + provider - + ".loginUser"); + + ".loginUser"); private String password = checkNotNull(System.getProperty("test." + provider + ".loginPassword"), "test." + provider - + ".loginPassword"); + + ".loginPassword"); @Override @BeforeGroups(groups = { "live" }) public void setupClient() { super.setupClient(); - client = context.getApi().getVMClient(); - sshFactory = injector.getInstance(SshClient.Factory.class); - socketTester = new RetryablePredicate(injector.getInstance(SocketOpen.class), 130, 10, TimeUnit.SECONDS);// make - taskTester = new RetryablePredicate(injector.getInstance(TaskSuccess.class), 650, 10, TimeUnit.SECONDS); + client = restContext.getApi().getVMClient(); + socketTester = new RetryablePredicate(new InetSocketAddressConnect(), 130, 10, TimeUnit.SECONDS);// make } - protected String prefix = System.getProperty("user.name"); private String billingSiteId; private String vpdcId; public void testCreateVirtualMachine() throws Exception { - billingSiteId = context.getApi().getBrowsingClient().getOrg(null).getId();// default - vpdcId = Iterables.find(context.getApi().getBrowsingClient().getOrg(billingSiteId).getVDCs(), - new Predicate() { + 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 = context.getApi().getBrowsingClient().getVDCInOrg(billingSiteId, arg0.getId()) - .getDescription(); - return description.indexOf(email) != -1; - } + // 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(); + }).getId(); String networkTierName = Iterables.get( - context.getApi().getBrowsingClient().getVDCInOrg(billingSiteId, vpdcId).getAvailableNetworks(), 0) - .getName(); + restContext.getApi().getBrowsingClient().getVDCInOrg(billingSiteId, vpdcId).getAvailableNetworks(), 0) + .getName(); String name = prefix; // delete any old VM - VDC vpdc = context.getApi().getBrowsingClient().getVDCInOrg(billingSiteId, vpdcId); + VDC vpdc = restContext.getApi().getBrowsingClient().getVDCInOrg(billingSiteId, vpdcId); for (Resource resource : vpdc.getResourceEntities()) { if (resource.getName().equals(prefix)) { taskTester.apply(client.removeVMFromVDC(billingSiteId, vpdcId, resource.getId()).getId()); } } - CIMOperatingSystem os = Iterables.find(injector.getInstance(Key.get(new TypeLiteral>() { - })), new Predicate() { + CIMOperatingSystem os = Iterables.find(restContext.getApi().listPredefinedOperatingSystems(), + new Predicate() { - @Override - public boolean apply(CIMOperatingSystem arg0) { - return arg0.getOsType() == OSType.RHEL_64; - } + @Override + public boolean apply(CIMOperatingSystem arg0) { + return arg0.getOsType() == OSType.RHEL_64; + } - }); + }); System.out.printf("vpdcId %s, networkName %s, name %s, os %s%n", vpdcId, networkTierName, name, os); // 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()); + .operatingSystem(os).memoryInGig(2).addDataDrive("/data01", 25).build()); // make sure there's no error assert task.getId() != null && task.getError() != null : task; assert this.taskTester.apply(task.getId()); - vm = context.getApi().getBrowsingClient().getVMInVDC(billingSiteId, vpdcId, task.getOwner().getId()); + vm = restContext.getApi().getBrowsingClient().getVMInVDC(billingSiteId, vpdcId, task.getOwner().getId()); conditionallyCheckSSH(); } private void conditionallyCheckSSH() { - assert HostSpecifier.isValid(vm.getIpAddress()); - if (!InetAddresses2.isPrivateIPAddress(vm.getIpAddress())) { - // not sure if the network is public or not, so we have to test - IPSocket socket = new IPSocket(vm.getIpAddress(), 22); - System.err.printf("testing socket %s%n", socket); - System.err.printf("testing ssh %s%n", socket); - checkSSH(socket); - } else { - System.err.printf("skipping ssh %s, as private%n", vm.getIpAddress()); + String ip = Iterables.get(vm.getNetworkConnectionSections(), 0).getIpAddress(); + assert HostSpecifier.isValid(ip); + if (InetAddresses2.isPrivateIPAddress(ip)) { + ip = Iterables.get(vm.getNetworkConfigSections(), 0).getInternalToExternalNATRules().get(ip); } + // not sure if the network is public or not, so we have to test + IPSocket socket = new IPSocket(ip, 22); + System.err.printf("testing socket %s%n", socket); + System.err.printf("testing ssh %s%n", socket); + checkSSH(socket); } protected void checkSSH(IPSocket socket) { socketTester.apply(socket); - SshClient client = sshFactory.create(socket, new Credentials(username, password)); + SshClient client = context.utils().sshFactory().create(socket, new Credentials(username, password)); try { client.connect(); ExecResponse exec = client.exec("echo hello"); diff --git a/sandbox-providers/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/filters/SetVCloudTokenCookieTest.java b/providers/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/filters/SetVCloudTokenCookieTest.java similarity index 100% rename from sandbox-providers/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/filters/SetVCloudTokenCookieTest.java rename to providers/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/filters/SetVCloudTokenCookieTest.java diff --git a/sandbox-providers/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/handlers/VPDCErrorHandlerTest.java b/providers/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/handlers/VPDCErrorHandlerTest.java similarity index 100% rename from sandbox-providers/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/handlers/VPDCErrorHandlerTest.java rename to providers/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/handlers/VPDCErrorHandlerTest.java diff --git a/sandbox-providers/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/xml/FirewallServiceHandlerTest.java b/providers/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/xml/FirewallServiceHandlerTest.java similarity index 100% rename from sandbox-providers/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/xml/FirewallServiceHandlerTest.java rename to providers/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/xml/FirewallServiceHandlerTest.java diff --git a/providers/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/xml/NetworkConfigSectionHandlerTest.java b/providers/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/xml/NetworkConfigSectionHandlerTest.java new file mode 100644 index 0000000000..981b2e84f5 --- /dev/null +++ b/providers/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/xml/NetworkConfigSectionHandlerTest.java @@ -0,0 +1,52 @@ +/** + * + * Copyright (C) 2010 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.xml; + +import static org.testng.Assert.assertEquals; + +import java.io.InputStream; + +import org.jclouds.http.functions.ParseSax; +import org.jclouds.http.functions.ParseSax.Factory; +import org.jclouds.http.functions.config.SaxParserModule; +import org.jclouds.savvis.vpdc.domain.NetworkConfigSection; +import org.testng.annotations.Test; + +import com.google.inject.Guice; +import com.google.inject.Injector; + +/** + * Tests behavior of {@code NetworkConfigSectionHandler} + * + * @author Adrian Cole + */ +@Test(groups = "unit") +public class NetworkConfigSectionHandlerTest { + + public void test() { + InputStream is = getClass().getResourceAsStream("/networkconfigsection.xml"); + Injector injector = Guice.createInjector(new SaxParserModule()); + Factory factory = injector.getInstance(ParseSax.Factory.class); + NetworkConfigSection result = factory.create(injector.getInstance(NetworkConfigSectionHandler.class)).parse(is); + assertEquals(result.toString(), NetworkConfigSection.builder().network("VM Tier01").gateway("0.0.0.0").netmask( + "0.0.0.0").info("MAC=00:00:00:00:00:00").fenceMode("allowInOut").dhcp(true).internalToExternalNATRule( + "10.76.2.4", "206.24.124.1").build().toString()); + } +} diff --git a/providers/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/xml/NetworkConnectionSectionHandlerTest.java b/providers/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/xml/NetworkConnectionSectionHandlerTest.java new file mode 100644 index 0000000000..03d2405cc1 --- /dev/null +++ b/providers/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/xml/NetworkConnectionSectionHandlerTest.java @@ -0,0 +1,53 @@ +/** + * + * Copyright (C) 2010 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.xml; + +import static org.testng.Assert.assertEquals; + +import java.io.InputStream; + +import org.jclouds.http.functions.ParseSax; +import org.jclouds.http.functions.ParseSax.Factory; +import org.jclouds.http.functions.config.SaxParserModule; +import org.jclouds.savvis.vpdc.domain.NetworkConnectionSection; +import org.testng.annotations.Test; + +import com.google.inject.Guice; +import com.google.inject.Injector; + +/** + * Tests behavior of {@code NetworkConnectionSectionHandler} + * + * @author Adrian Cole + */ +@Test(groups = "unit") +public class NetworkConnectionSectionHandlerTest { + + public void test() { + InputStream is = getClass().getResourceAsStream("/networkconnectionsection.xml"); + Injector injector = Guice.createInjector(new SaxParserModule()); + Factory factory = injector.getInstance(ParseSax.Factory.class); + NetworkConnectionSection result = factory.create(injector.getInstance(NetworkConnectionSectionHandler.class)) + .parse(is); + assertEquals(result.toString(), NetworkConnectionSection.builder().network("VM Tier01").info( + "Read only description of a network connection to a deployed vApp").ipAddress("10.76.0.5").build() + .toString()); + } +} diff --git a/sandbox-providers/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/xml/NetworkHandlerTest.java b/providers/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/xml/NetworkHandlerTest.java similarity index 100% rename from sandbox-providers/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/xml/NetworkHandlerTest.java rename to providers/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/xml/NetworkHandlerTest.java diff --git a/sandbox-providers/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/xml/OrgHandlerTest.java b/providers/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/xml/OrgHandlerTest.java similarity index 100% rename from sandbox-providers/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/xml/OrgHandlerTest.java rename to providers/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/xml/OrgHandlerTest.java diff --git a/sandbox-providers/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/xml/OrgListHandlerTest.java b/providers/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/xml/OrgListHandlerTest.java similarity index 92% rename from sandbox-providers/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/xml/OrgListHandlerTest.java rename to providers/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/xml/OrgListHandlerTest.java index d21725134f..0a4cd00213 100644 --- a/sandbox-providers/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/xml/OrgListHandlerTest.java +++ b/providers/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/xml/OrgListHandlerTest.java @@ -29,6 +29,7 @@ import org.jclouds.http.functions.ParseSax; import org.jclouds.http.functions.ParseSax.Factory; import org.jclouds.http.functions.config.SaxParserModule; import org.jclouds.savvis.vpdc.domain.Resource; +import org.jclouds.savvis.vpdc.domain.ResourceImpl; import org.testng.annotations.Test; import com.google.common.collect.ImmutableSet; @@ -48,7 +49,7 @@ public class OrgListHandlerTest { Injector injector = Guice.createInjector(new SaxParserModule()); Factory factory = injector.getInstance(ParseSax.Factory.class); Set result = factory.create(injector.getInstance(OrgListHandler.class)).parse(is); - assertEquals(result, ImmutableSet.of(new Resource("100000.0", "SAVVISStation Integration Testing", + assertEquals(result, ImmutableSet.of(new ResourceImpl("100000.0", "SAVVISStation Integration Testing", "application/vnd.vmware.vcloud.org+xml", URI .create("https://api.sandbox.symphonyvpdc.savvis.net/rest/api/v0.8/org/100000.0")))); diff --git a/sandbox-providers/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/xml/TaskHandlerTest.java b/providers/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/xml/TaskHandlerTest.java similarity index 96% rename from sandbox-providers/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/xml/TaskHandlerTest.java rename to providers/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/xml/TaskHandlerTest.java index e6c1397f24..251c6664fb 100644 --- a/sandbox-providers/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/xml/TaskHandlerTest.java +++ b/providers/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/xml/TaskHandlerTest.java @@ -7,7 +7,7 @@ import java.net.URI; import org.jclouds.date.DateService; import org.jclouds.http.functions.BaseHandlerTest; -import org.jclouds.savvis.vpdc.domain.Resource; +import org.jclouds.savvis.vpdc.domain.ResourceImpl; import org.jclouds.savvis.vpdc.domain.Task; import org.jclouds.savvis.vpdc.domain.TaskError; import org.testng.annotations.BeforeTest; @@ -44,7 +44,7 @@ public class TaskHandlerTest extends BaseHandlerTest { .type("application/vnd.vmware.vcloud.task+xml") .href(URI.create("https://api.symphonyvpdc.savvis.net/rest/api/v0.8/task/21-1002")) .owner( - Resource + ResourceImpl .builder() .id("2736") .name("mockVpdc8") @@ -53,7 +53,7 @@ public class TaskHandlerTest extends BaseHandlerTest { .create("https://api.symphonyvpdc.savvis.net/rest/api/v0.8/org/100000.0/vdc/2736")) .build()) .result( - Resource + ResourceImpl .builder() .id("1002") .name("mock_vpdc_item_007") @@ -78,7 +78,7 @@ public class TaskHandlerTest extends BaseHandlerTest { .type("application/vnd.vmware.vcloud.task+xml") .href(URI.create("https://api.symphonyvpdc.savvis.net/rest/api/v0.8/task/21-1002")) .owner( - Resource + ResourceImpl .builder() .id("2736") .name("mockVpdc8") @@ -87,7 +87,7 @@ public class TaskHandlerTest extends BaseHandlerTest { .create("https://api.symphonyvpdc.savvis.net/rest/api/v0.8/org/100000.0/vdc/2736")) .build()) .result( - Resource + ResourceImpl .builder() .id("1234567") .name("mock_vpdc_item_008") @@ -111,7 +111,7 @@ public class TaskHandlerTest extends BaseHandlerTest { .type("application/vnd.vmware.vcloud.task+xml") .href(URI.create("https://api.symphonyvpdc.savvis.net/rest/api/v0.8/task/6904")) .owner( - Resource + ResourceImpl .builder() .id("2736") .name("mockVpdc8") @@ -120,7 +120,7 @@ public class TaskHandlerTest extends BaseHandlerTest { .create("https://api.symphonyvpdc.savvis.net/rest/api/v0.8/org/100000.0/vdc/2736")) .build()) .result( - Resource + ResourceImpl .builder() .id("1002") .name("mock_vpdc_item_007") @@ -144,7 +144,7 @@ public class TaskHandlerTest extends BaseHandlerTest { .status(Task.Status.QUEUED) .href(URI.create("https://api.symphonyVPDC.savvis.net/rest/api/v0.8/task/113927-1005")) .owner( - Resource + ResourceImpl .builder() .id("4253") .name("Foo") @@ -153,7 +153,7 @@ public class TaskHandlerTest extends BaseHandlerTest { .create("https://api.symphonyVPDC.savvis.net/rest/api/v0.8/org/606677.0/vdc/4253")) .build()) .result( - Resource + ResourceImpl .builder() .id("1005") .name("adriancole") @@ -179,7 +179,7 @@ public class TaskHandlerTest extends BaseHandlerTest { .type("application/vnd.vmware.vcloud.task+xml") .href(URI.create("https://api.symphonyvpdc.savvis.net/rest/api/v0.8/task/6904-123")) .owner( - Resource + ResourceImpl .builder() .id("2736") .name("mockVpdc8") @@ -188,7 +188,7 @@ public class TaskHandlerTest extends BaseHandlerTest { .create("https://api.symphonyvpdc.savvis.net/rest/api/v0.8/org/100000.0/vdc/2736")) .build()) .result( - Resource + ResourceImpl .builder() .id("1002") .name("mock_vpdc_item_007") diff --git a/providers/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/xml/VDCHandlerTest.java b/providers/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/xml/VDCHandlerTest.java new file mode 100644 index 0000000000..f3e3f35ce0 --- /dev/null +++ b/providers/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/xml/VDCHandlerTest.java @@ -0,0 +1,194 @@ +/** + * + * Copyright (C) 2010 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.xml; + +import static org.testng.Assert.assertEquals; + +import java.io.InputStream; +import java.net.URI; + +import org.jclouds.http.functions.ParseSax; +import org.jclouds.http.functions.ParseSax.Factory; +import org.jclouds.http.functions.config.SaxParserModule; +import org.jclouds.savvis.vpdc.domain.Resource; +import org.jclouds.savvis.vpdc.domain.ResourceImpl; +import org.jclouds.savvis.vpdc.domain.VDC; +import org.jclouds.savvis.vpdc.domain.VDC.Status; +import org.jclouds.savvis.vpdc.reference.VCloudMediaType; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableSet; +import com.google.inject.Guice; +import com.google.inject.Injector; + +/** + * Tests behavior of {@code VDCHandler} + * + * @author Adrian Cole + */ +@Test(groups = "unit") +public class VDCHandlerTest { + + public void test() { + InputStream is = getClass().getResourceAsStream("/vdc.xml"); + Injector injector = Guice.createInjector(new SaxParserModule()); + Factory factory = injector.getInstance(ParseSax.Factory.class); + VDC result = factory.create(injector.getInstance(VDCHandler.class)).parse(is); + assertEquals(result.getName(), "demo_vpdcname"); + assertEquals(result.getDescription(), + "ServiceProfileName = Balanced; ServiceLocation = North America; Email = jim@company.com;"); + assertEquals(result.getStatus(), Status.DEPLOYED); + assertEquals( + result.getResourceEntities(), + ImmutableSet + . of( + new ResourceImpl( + "1001", + "DemoHost-1", + VCloudMediaType.VAPP_XML, + URI + .create("https://api.sandbox.symphonyvpdc.savvis.net/rest/api/v0.8/org/100000.0/vdc/2736/vApp/1001")), + new ResourceImpl( + "1002", + "DemoHost-2", + VCloudMediaType.VAPP_XML, + URI + .create("https://api.sandbox.symphonyvpdc.savvis.net/rest/api/v0.8/org/100000.0/vdc/2736/vApp/1002")), + new ResourceImpl( + "1003", + "DemoHost-3", + VCloudMediaType.VAPP_XML, + URI + .create("https://api.sandbox.symphonyvpdc.savvis.net/rest/api/v0.8/org/100000.0/vdc/2736/vApp/1003")), + new ResourceImpl( + "1234", + "CustomerTemplateName", + VCloudMediaType.VAPPTEMPLATE_XML, + URI + .create("https://api.sandbox.symphonyvpdc.savvis.net/rest/api/v0.8/org/100000.0/vdc/2736/vAppTemplate/1234")), + new ResourceImpl( + "FirewallService", + "firewall", + "api.symphonyvpdc.savvis.net+xml", + URI + .create("https://api.sandbox.symphonyvpdc.savvis.net/rest/api/v0.8/org/100000.0/vdc/2736/FirewallService")))); + assertEquals(result.getAvailableNetworks(), ImmutableSet.of()); + } + + public void test1net() { + InputStream is = getClass().getResourceAsStream("/vdc-1net.xml"); + Injector injector = Guice.createInjector(new SaxParserModule()); + Factory factory = injector.getInstance(ParseSax.Factory.class); + VDC result = factory.create(injector.getInstance(VDCHandler.class)).parse(is); + assertEquals(result.getName(), "demo6"); + assertEquals(result.getDescription(), + "ServiceProfileName = Essential; ServiceLocation = US_WEST; Email = red@chair.com;"); + assertEquals(result.getStatus(), Status.DEPLOYED); + assertEquals(result.getResourceEntities(), ImmutableSet.of(new ResourceImpl("1001", "Host1", + VCloudMediaType.VAPP_XML, URI + .create("https://api.symphonyVPDC.savvis.net/rest/api/v0.8/org/606677.0/vdc/1619/vApp/1001")), + new ResourceImpl("1002", "Host2", VCloudMediaType.VAPP_XML, URI + .create("https://api.symphonyVPDC.savvis.net/rest/api/v0.8/org/606677.0/vdc/1619/vApp/1002")), + new ResourceImpl("1003", "Host3", VCloudMediaType.VAPP_XML, URI + .create("https://api.symphonyVPDC.savvis.net/rest/api/v0.8/org/606677.0/vdc/1619/vApp/1003")), + new ResourceImpl("1004", "Host4", VCloudMediaType.VAPP_XML, URI + .create("https://api.symphonyVPDC.savvis.net/rest/api/v0.8/org/606677.0/vdc/1619/vApp/1004")))); + assertEquals(result.getAvailableNetworks(), ImmutableSet.of(ResourceImpl.builder().id("VM-Tier01").name( + "VM Tier01").type(VCloudMediaType.NETWORK_XML).href( + URI.create("https://api.symphonyVPDC.savvis.net/rest/api/v0.8/org/606677.0/vdc/1619/network/VM-Tier01")) + .build())); + + } + + public void testFailed() { + InputStream is = getClass().getResourceAsStream("/vdc-failed.xml"); + Injector injector = Guice.createInjector(new SaxParserModule()); + Factory factory = injector.getInstance(ParseSax.Factory.class); + VDC result = factory.create(injector.getInstance(VDCHandler.class)).parse(is); + assertEquals(result.getName(), "Demo7"); + assertEquals(result.getDescription(), + "ServiceProfileName = Essential; ServiceLocation = US_WEST; Email = red@chair.com;"); + assertEquals(result.getStatus(), Status.FAILED); + assertEquals(result.getResourceEntities(), ImmutableSet.of(new ResourceImpl("1001", "Host1", + VCloudMediaType.VAPP_XML, URI + .create("https://api.symphonyVPDC.savvis.net/rest/api/v0.8/org/606677.0/vdc/1641/vApp/1001")))); + assertEquals(result.getAvailableNetworks(), ImmutableSet.of(ResourceImpl.builder().id("VM-Tier01").name( + "VM Tier01").type(VCloudMediaType.NETWORK_XML).href( + URI.create("https://api.symphonyVPDC.savvis.net/rest/api/v0.8/org/606677.0/vdc/1641/network/VM-Tier01")) + .build())); + + } + + public void testSaved() { + InputStream is = getClass().getResourceAsStream("/vdc-saved.xml"); + Injector injector = Guice.createInjector(new SaxParserModule()); + Factory factory = injector.getInstance(ParseSax.Factory.class); + VDC result = factory.create(injector.getInstance(VDCHandler.class)).parse(is); + assertEquals(result.getName(), "CloudBurst1"); + assertEquals(result.getDescription(), + "ServiceProfileName = Essential; ServiceLocation = US_WEST; Email = me@my.com;"); + assertEquals(result.getStatus(), Status.SAVED); + assertEquals( + result.getResourceEntities(), + ImmutableSet + .of( + ResourceImpl + .builder() + .name("templateHost") + .type("application/vnd.vmware.vcloud.vApp+xml") + .id("1001") + .href( + URI + .create("https://api.symphonyVPDC.savvis.net/rest/api/v0.8/org/606677.0/vdc/2555/vApp/1001")) + .build(), + ResourceImpl + .builder() + .name("host-c501") + .type("application/vnd.vmware.vcloud.vApp+xml") + .id("1037") + .href( + URI + .create("https://api.symphonyVPDC.savvis.net/rest/api/v0.8/org/606677.0/vdc/2555/vApp/1037")) + .build(), + ResourceImpl + .builder() + .name("host-c501") + .type("application/vnd.vmware.vcloud.vApp+xml") + .id("1038") + .href( + URI + .create("https://api.symphonyVPDC.savvis.net/rest/api/v0.8/org/606677.0/vdc/2555/vApp/1038")) + .build(), + ResourceImpl + .builder() + .name("host-c601") + .type("application/vnd.vmware.vcloud.vApp+xml") + .id("1039") + .href( + URI + .create("https://api.symphonyVPDC.savvis.net/rest/api/v0.8/org/606677.0/vdc/2555/vApp/1039")) + .build())); + assertEquals(result.getAvailableNetworks(), ImmutableSet.of(ResourceImpl.builder().id("VM-Tier01").name( + "VM Tier01").type(VCloudMediaType.NETWORK_XML).href( + URI.create("https://api.symphonyVPDC.savvis.net/rest/api/v0.8/org/606677.0/vdc/2555/network/VM-Tier01")) + .build())); + + } +} diff --git a/providers/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/xml/VMHandlerTest.java b/providers/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/xml/VMHandlerTest.java new file mode 100644 index 0000000000..f6e1bbd52c --- /dev/null +++ b/providers/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/xml/VMHandlerTest.java @@ -0,0 +1,132 @@ +package org.jclouds.savvis.vpdc.xml; + +import static org.testng.Assert.assertEquals; + +import java.io.InputStream; +import java.net.URI; + +import org.jclouds.cim.ResourceAllocationSettingData; +import org.jclouds.cim.VirtualSystemSettingData; +import org.jclouds.cim.ResourceAllocationSettingData.ResourceType; +import org.jclouds.http.functions.ParseSax; +import org.jclouds.http.functions.ParseSax.Factory; +import org.jclouds.http.functions.config.SaxParserModule; +import org.jclouds.ovf.OperatingSystemSection; +import org.jclouds.ovf.ProductSection; +import org.jclouds.ovf.Property; +import org.jclouds.ovf.VirtualHardwareSection; +import org.jclouds.savvis.vpdc.domain.NetworkConfigSection; +import org.jclouds.savvis.vpdc.domain.NetworkConnectionSection; +import org.jclouds.savvis.vpdc.domain.VM; +import org.testng.annotations.Test; + +import com.google.inject.Guice; +import com.google.inject.Injector; + +/** + * Tests behavior of {@code VMHandler} + * + * @author Adrian Cole + */ +@Test(groups = "unit") +public class VMHandlerTest { + public void testVCloud1_0() { + InputStream is = getClass().getResourceAsStream("/vm.xml"); + Injector injector = Guice.createInjector(new SaxParserModule()); + Factory factory = injector.getInstance(ParseSax.Factory.class); + VM result = factory.create(injector.getInstance(VMHandler.class)).parse(is); + + VM expected = VM + .builder() + .id("1001") + .status(VM.Status.ON) + .name("znHost2") + .type("application/vnd.vmware.vcloud.vApp+xml") + .href( + URI + .create("https://api.sandbox.symphonyVPDC.savvis.net/rest/api/v0.8/org/100000.0/vdc/2736/vApp/1001")) + .networkConfigSection( + NetworkConfigSection.builder().network("VM Tier01").gateway("0.0.0.0").netmask("0.0.0.0").info( + "MAC=00:00:00:00:00:00").fenceMode("allowInOut").dhcp(true).internalToExternalNATRule( + "10.76.2.4", "206.24.124.1").build()) + .networkConnectionSection( + NetworkConnectionSection.builder().network("VM Tier01").info( + "Read only description of a network connection to a deployed vApp").ipAddress( + "10.76.0.5").build()) + .operatingSystemSection( + OperatingSystemSection.builder().id(80).info("Specifies the operating system installed") + .description("Red Hat Enterprise Linux 5.x 64bit").build()) + .productSection( + ProductSection + .builder() + .info("vCenter Information") + .property( + Property.builder().value("false").key("vmwareToolsEnabled").label( + "VMWare Tools Enabled status").description( + "VMWare Tools Enabled status").build()) + .property( + + Property.builder().value("10.12.46.171").key("vmwareESXHost").label( + "VMWare ESXHost Ipaddress").description("VMWare ESXHost Ipaddress") + .build()) + .property( + + Property.builder().value("cussl01s01c01alun088bal,cussl01s01c01alun089bal") + .key("datastores").label("Datastore Name").description( + "Datastore Name").build()) + .property( + Property + .builder() + .value("[Totalcapacity=1335915184128,UsedCapacity=549755813888]") + .key("cussl01s01c01alun088bal") + .label("Datastore Capacity") + .description( + "Datastore cussl01s01c01alun088bal Total Capacity, Used Capacity in comma separated") + .build()) + .property( + + Property + .builder() + .value("[Totalcapacity=1335915184129,UsedCapacity=549755813889]") + .key("cussl01s01c01alun089bal") + .label("Datastore Capacity") + .description( + "Datastore cussl01s01c01alun089bal Total Capacity, Used Capacity in comma separated") + .build()).property( + + Property.builder().value( + "[name=3282176-1949-bal-tier01,ip=0.0.0.0,mac=00:50:56:8c:3f:3c]") + .key("customerPortprofile").label("customerPortprofile") + .description("customerPortprofile").build()).property( + + Property.builder().value( + "[name=vm-server-mgmt,ip=0.0.0.0,mac=00:50:56:8c:39:75]").key( + "savvisPortprofile").label("savvisPortprofile").description( + "savvisPortprofile").build()).build()).virtualHardwareSection( + VirtualHardwareSection.builder().info("UUID=52254cd2-d848-4e7d-b8f3-3d257fed7666").system( + VirtualSystemSettingData.builder().description("Virtual Hardware Family").elementName( + "znHost2").instanceID("1").virtualSystemIdentifier("znHost2").build()).item( + ResourceAllocationSettingData.builder().allocationUnits("3 GHz").description( + "Number of Virtual CPUs").elementName("1 CPU").instanceID("2").resourceType( + ResourceType.PROCESSOR).virtualQuantity(1l).build()).item( + ResourceAllocationSettingData.builder().allocationUnits("Gigabytes").description( + "Memory Size").elementName("Memory").instanceID("3").resourceType( + ResourceType.MEMORY).virtualQuantity(2l).build()).item( + ResourceAllocationSettingData.builder().connection("VM Tier01").elementName("Network") + .instanceID("4").resourceType(ResourceType.ETHERNET_ADAPTER).virtualQuantity( + 1l).build()).item( + ResourceAllocationSettingData.builder().allocationUnits("Gigabytes") + .caption("1234567").description("Hard Disk").elementName("C:\\") + .hostResource("boot").instanceID("5").resourceType( + ResourceType.BASE_PARTITIONABLE_UNIT).virtualQuantity(25l).build()) + .item( + ResourceAllocationSettingData.builder().allocationUnits("Gigabytes").caption( + "1234568").description("Hard Disk").elementName("D:\\") + .hostResource("data").instanceID("6").resourceType( + ResourceType.PARTITIONABLE_UNIT).virtualQuantity(50l) + .build()).build()) + + .build(); + assertEquals(result, expected); + } +} diff --git a/sandbox-providers/savvis-symphonyvpdc/src/test/resources/firewallService.xml b/providers/savvis-symphonyvpdc/src/test/resources/firewallService.xml similarity index 100% rename from sandbox-providers/savvis-symphonyvpdc/src/test/resources/firewallService.xml rename to providers/savvis-symphonyvpdc/src/test/resources/firewallService.xml diff --git a/sandbox-providers/savvis-symphonyvpdc/src/test/resources/log4j.xml b/providers/savvis-symphonyvpdc/src/test/resources/log4j.xml similarity index 100% rename from sandbox-providers/savvis-symphonyvpdc/src/test/resources/log4j.xml rename to providers/savvis-symphonyvpdc/src/test/resources/log4j.xml diff --git a/sandbox-providers/savvis-symphonyvpdc/src/test/resources/network-nat.xml b/providers/savvis-symphonyvpdc/src/test/resources/network-nat.xml similarity index 100% rename from sandbox-providers/savvis-symphonyvpdc/src/test/resources/network-nat.xml rename to providers/savvis-symphonyvpdc/src/test/resources/network-nat.xml diff --git a/sandbox-providers/savvis-symphonyvpdc/src/test/resources/network-unused.xml b/providers/savvis-symphonyvpdc/src/test/resources/network-unused.xml similarity index 100% rename from sandbox-providers/savvis-symphonyvpdc/src/test/resources/network-unused.xml rename to providers/savvis-symphonyvpdc/src/test/resources/network-unused.xml diff --git a/sandbox-providers/savvis-symphonyvpdc/src/test/resources/network.xml b/providers/savvis-symphonyvpdc/src/test/resources/network.xml similarity index 100% rename from sandbox-providers/savvis-symphonyvpdc/src/test/resources/network.xml rename to providers/savvis-symphonyvpdc/src/test/resources/network.xml diff --git a/providers/savvis-symphonyvpdc/src/test/resources/networkconfigsection.xml b/providers/savvis-symphonyvpdc/src/test/resources/networkconfigsection.xml new file mode 100644 index 0000000000..a1f7cd7b56 --- /dev/null +++ b/providers/savvis-symphonyvpdc/src/test/resources/networkconfigsection.xml @@ -0,0 +1,13 @@ + + MAC=00:00:00:00:00:00 + + + allowInOut + true + + + + + + \ No newline at end of file diff --git a/providers/savvis-symphonyvpdc/src/test/resources/networkconnectionsection.xml b/providers/savvis-symphonyvpdc/src/test/resources/networkconnectionsection.xml new file mode 100644 index 0000000000..c241b04d56 --- /dev/null +++ b/providers/savvis-symphonyvpdc/src/test/resources/networkconnectionsection.xml @@ -0,0 +1,5 @@ + + Read only description of a network connection to a deployed vApp + 10.76.0.5 + \ No newline at end of file diff --git a/sandbox-providers/savvis-symphonyvpdc/src/test/resources/org.xml b/providers/savvis-symphonyvpdc/src/test/resources/org.xml similarity index 100% rename from sandbox-providers/savvis-symphonyvpdc/src/test/resources/org.xml rename to providers/savvis-symphonyvpdc/src/test/resources/org.xml diff --git a/sandbox-providers/savvis-symphonyvpdc/src/test/resources/org_no_vdc.xml b/providers/savvis-symphonyvpdc/src/test/resources/org_no_vdc.xml similarity index 100% rename from sandbox-providers/savvis-symphonyvpdc/src/test/resources/org_no_vdc.xml rename to providers/savvis-symphonyvpdc/src/test/resources/org_no_vdc.xml diff --git a/sandbox-providers/savvis-symphonyvpdc/src/test/resources/orglist.xml b/providers/savvis-symphonyvpdc/src/test/resources/orglist.xml similarity index 100% rename from sandbox-providers/savvis-symphonyvpdc/src/test/resources/orglist.xml rename to providers/savvis-symphonyvpdc/src/test/resources/orglist.xml diff --git a/sandbox-providers/savvis-symphonyvpdc/src/test/resources/task-error.xml b/providers/savvis-symphonyvpdc/src/test/resources/task-error.xml similarity index 100% rename from sandbox-providers/savvis-symphonyvpdc/src/test/resources/task-error.xml rename to providers/savvis-symphonyvpdc/src/test/resources/task-error.xml diff --git a/sandbox-providers/savvis-symphonyvpdc/src/test/resources/task-failed.xml b/providers/savvis-symphonyvpdc/src/test/resources/task-failed.xml similarity index 100% rename from sandbox-providers/savvis-symphonyvpdc/src/test/resources/task-failed.xml rename to providers/savvis-symphonyvpdc/src/test/resources/task-failed.xml diff --git a/sandbox-providers/savvis-symphonyvpdc/src/test/resources/task-invalidsize.xml b/providers/savvis-symphonyvpdc/src/test/resources/task-invalidsize.xml similarity index 100% rename from sandbox-providers/savvis-symphonyvpdc/src/test/resources/task-invalidsize.xml rename to providers/savvis-symphonyvpdc/src/test/resources/task-invalidsize.xml diff --git a/sandbox-providers/savvis-symphonyvpdc/src/test/resources/task-queued.xml b/providers/savvis-symphonyvpdc/src/test/resources/task-queued.xml similarity index 100% rename from sandbox-providers/savvis-symphonyvpdc/src/test/resources/task-queued.xml rename to providers/savvis-symphonyvpdc/src/test/resources/task-queued.xml diff --git a/sandbox-providers/savvis-symphonyvpdc/src/test/resources/task-running.xml b/providers/savvis-symphonyvpdc/src/test/resources/task-running.xml similarity index 100% rename from sandbox-providers/savvis-symphonyvpdc/src/test/resources/task-running.xml rename to providers/savvis-symphonyvpdc/src/test/resources/task-running.xml diff --git a/sandbox-providers/savvis-symphonyvpdc/src/test/resources/task-undeployedvdc.xml b/providers/savvis-symphonyvpdc/src/test/resources/task-undeployedvdc.xml similarity index 100% rename from sandbox-providers/savvis-symphonyvpdc/src/test/resources/task-undeployedvdc.xml rename to providers/savvis-symphonyvpdc/src/test/resources/task-undeployedvdc.xml diff --git a/sandbox-providers/savvis-symphonyvpdc/src/test/resources/task-unsupported.xml b/providers/savvis-symphonyvpdc/src/test/resources/task-unsupported.xml similarity index 100% rename from sandbox-providers/savvis-symphonyvpdc/src/test/resources/task-unsupported.xml rename to providers/savvis-symphonyvpdc/src/test/resources/task-unsupported.xml diff --git a/sandbox-providers/savvis-symphonyvpdc/src/test/resources/task-vapp.xml b/providers/savvis-symphonyvpdc/src/test/resources/task-vapp.xml similarity index 100% rename from sandbox-providers/savvis-symphonyvpdc/src/test/resources/task-vapp.xml rename to providers/savvis-symphonyvpdc/src/test/resources/task-vapp.xml diff --git a/sandbox-providers/savvis-symphonyvpdc/src/test/resources/task-vmdk.xml b/providers/savvis-symphonyvpdc/src/test/resources/task-vmdk.xml similarity index 100% rename from sandbox-providers/savvis-symphonyvpdc/src/test/resources/task-vmdk.xml rename to providers/savvis-symphonyvpdc/src/test/resources/task-vmdk.xml diff --git a/sandbox-providers/savvis-symphonyvpdc/src/test/resources/vdc-1net.xml b/providers/savvis-symphonyvpdc/src/test/resources/vdc-1net.xml similarity index 100% rename from sandbox-providers/savvis-symphonyvpdc/src/test/resources/vdc-1net.xml rename to providers/savvis-symphonyvpdc/src/test/resources/vdc-1net.xml diff --git a/sandbox-providers/savvis-symphonyvpdc/src/test/resources/vdc-failed.xml b/providers/savvis-symphonyvpdc/src/test/resources/vdc-failed.xml similarity index 100% rename from sandbox-providers/savvis-symphonyvpdc/src/test/resources/vdc-failed.xml rename to providers/savvis-symphonyvpdc/src/test/resources/vdc-failed.xml diff --git a/sandbox-providers/savvis-symphonyvpdc/src/test/resources/vdc-saved.xml b/providers/savvis-symphonyvpdc/src/test/resources/vdc-saved.xml similarity index 100% rename from sandbox-providers/savvis-symphonyvpdc/src/test/resources/vdc-saved.xml rename to providers/savvis-symphonyvpdc/src/test/resources/vdc-saved.xml diff --git a/sandbox-providers/savvis-symphonyvpdc/src/test/resources/vdc.xml b/providers/savvis-symphonyvpdc/src/test/resources/vdc.xml similarity index 100% rename from sandbox-providers/savvis-symphonyvpdc/src/test/resources/vdc.xml rename to providers/savvis-symphonyvpdc/src/test/resources/vdc.xml diff --git a/sandbox-providers/savvis-symphonyvpdc/src/test/resources/vm-default.xml b/providers/savvis-symphonyvpdc/src/test/resources/vm-default.xml similarity index 100% rename from sandbox-providers/savvis-symphonyvpdc/src/test/resources/vm-default.xml rename to providers/savvis-symphonyvpdc/src/test/resources/vm-default.xml diff --git a/sandbox-providers/savvis-symphonyvpdc/src/test/resources/vm-withdisks.xml b/providers/savvis-symphonyvpdc/src/test/resources/vm-withdisks.xml similarity index 100% rename from sandbox-providers/savvis-symphonyvpdc/src/test/resources/vm-withdisks.xml rename to providers/savvis-symphonyvpdc/src/test/resources/vm-withdisks.xml diff --git a/providers/savvis-symphonyvpdc/src/test/resources/vm.xml b/providers/savvis-symphonyvpdc/src/test/resources/vm.xml new file mode 100644 index 0000000000..7b974677f2 --- /dev/null +++ b/providers/savvis-symphonyvpdc/src/test/resources/vm.xml @@ -0,0 +1,235 @@ + + + The list of logical networks + + Customer Production Network used by this appliance + + + + MAC=00:00:00:00:00:00 + + + allowInOut + true + + + + + + + + Read only description of a network connection to a deployed vApp + 10.76.0.5 + + + Specifies the operating system installed + Red Hat Enterprise Linux 5.x 64bit + + + + vCenter Information + + VMWare Tools Enabled status + VMWare Tools Enabled status + + + VMWare ESXHost Ipaddress + VMWare ESXHost Ipaddress + + + Datastore Name + Datastore Name + + + + Datastore Capacity + Datastore cussl01s01c01alun088bal Total Capacity, Used Capacity in comma separated + + + + Datastore Capacity + Datastore cussl01s01c01alun089bal Total Capacity, Used Capacity in comma separated + + + + customerPortprofile + customerPortprofile + + + savvisPortprofile + savvisPortprofile + + + + + UUID=52254cd2-d848-4e7d-b8f3-3d257fed7666 + + + + + + + + + + + + + + Virtual Hardware Family + znHost2 + + 1 + + + + + + znHost2 + + + + + + 3 GHz + + + + + + + Number of Virtual CPUs + 1 CPU + + 2 + + + + + + + + 3 + 1 + + + + + + Gigabytes + + + + + + + Memory Size + Memory + + 3 + + + + + + + + 4 + 2 + + + + + + + + + + + + VM Tier01 + + + Network + + 4 + + + + + + + + 10 + 1 + + + + + + Gigabytes + + + 1234567 + + + + Hard Disk + C:\ + + boot + 5 + + + + + + + + 27 + 25 + + + + + + Gigabytes + + + 1234568 + + + + Hard Disk + D:\ + + data + 6 + + + + + + + + 26 + 50 + + + + \ No newline at end of file diff --git a/sandbox-providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/compute/config/VPDCComputeServiceContextModule.java b/sandbox-providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/compute/config/VPDCComputeServiceContextModule.java deleted file mode 100644 index bccd56f516..0000000000 --- a/sandbox-providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/compute/config/VPDCComputeServiceContextModule.java +++ /dev/null @@ -1,53 +0,0 @@ -/** - * - * Copyright (C) 2010 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.compute.config; - -import java.util.Map; - -import javax.inject.Singleton; - -import org.jclouds.compute.config.BaseComputeServiceContextModule; -import org.jclouds.compute.domain.NodeState; -import org.jclouds.savvis.vpdc.domain.VM; - -import com.google.common.annotations.VisibleForTesting; -import com.google.common.collect.ImmutableMap; -import com.google.inject.Provides; - -/** - * - * @author Adrian Cole - */ -public class VPDCComputeServiceContextModule extends BaseComputeServiceContextModule { - - @VisibleForTesting - public static final Map VAPPSTATUS_TO_NODESTATE = ImmutableMap - . builder().put(VM.Status.OFF, NodeState.SUSPENDED) - .put(VM.Status.ON, NodeState.RUNNING).put(VM.Status.RESOLVED, NodeState.PENDING) - .put(VM.Status.UNRECOGNIZED, NodeState.UNRECOGNIZED).put(VM.Status.UNKNOWN, NodeState.UNRECOGNIZED) - .put(VM.Status.SUSPENDED, NodeState.SUSPENDED).put(VM.Status.UNRESOLVED, NodeState.PENDING).build(); - - @Singleton - @Provides - protected Map provideVAppStatusToNodeState() { - return VAPPSTATUS_TO_NODESTATE; - } - -} diff --git a/sandbox-providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/domain/VM.java b/sandbox-providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/domain/VM.java deleted file mode 100644 index 2e0e112cf9..0000000000 --- a/sandbox-providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/domain/VM.java +++ /dev/null @@ -1,252 +0,0 @@ -package org.jclouds.savvis.vpdc.domain; - -import static com.google.common.base.Preconditions.checkNotNull; - -import java.net.URI; -import java.util.Set; - -import org.jclouds.cim.ResourceAllocationSettingData; -import org.jclouds.ovf.NetworkSection; - -import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Sets; - -/** - * A virtual application (vApp) is a software solution, packaged in OVF containing one or more - * virtual machines. A vApp can be authored by Developers at ISVs and VARs or by IT Administrators - * in Enterprises and Service Providers. - * - * @author Adrian Cole - */ -public class VM extends Resource { - /** - * Objects such as vAppTemplate, vApp, and Vm have a status attribute whose value indicates the - * state of the object. Status for an object, such as a vAppTemplate or vApp, whose Children (Vm - * objects) each have a status of their own, is computed from the status of the Children. - * - *

NOTE

- *

- * The deployment status of an object is indicated by the value of its deployed attribute. - * - * @since vcloud api 0.8 - * - * @author Adrian Cole - */ - public enum Status { - - /** - * When the VM is in Designing,Saved,Inqueue, has issue in pre provisioning or any exception - * cases. VM is not in Savvis VPDC (may the VM has been removed) or cannot get VM state due to - * unknown exception - */ - UNRESOLVED, - /** - * When the Savvis VPDC is in Provisioning, PartiallyDeployed, Failed and the VM failed in - * provisioning or pending infrastructure notification - */ - RESOLVED, - /** - * When the VM is deployed in vmware and powered off. - */ - OFF, - /** - * We do not support suspended state. - */ - SUSPENDED, - /** - * When the VM is deployed in vmware and powered on. - */ - ON, - /** - * The VM is deployed in vmware but the state of VM may be Uninitialized, Start, Stop, Resume, - * Reset, RebootGuest, Error, Failed, Unknown, PoweringOn, PoweringOff, Suspending, Stopping, - * Starting, Resetting, RebootingGuest. Please call back the Get VApp Power State API after - * few minute. - */ - UNKNOWN, UNRECOGNIZED; - - public String value() { - switch (this) { - case UNRESOLVED: - return "0"; - case RESOLVED: - return "1"; - case OFF: - return "2"; - case SUSPENDED: - return "3"; - case ON: - return "4"; - case UNKNOWN: - return "5"; - default: - return "UNRECOGNIZED"; - } - } - - public static Status fromValue(String status) { - try { - return fromValue(Integer.parseInt(checkNotNull(status, "status"))); - } catch (IllegalArgumentException e) { - return UNRECOGNIZED; - } - } - - public static Status fromValue(int v) { - switch (v) { - case 0: - return UNRESOLVED; - case 1: - return RESOLVED; - case 2: - return OFF; - case 3: - return SUSPENDED; - case 4: - return ON; - case 5: - return UNKNOWN; - default: - return UNRECOGNIZED; - } - } - - } - - public static Builder builder() { - return new Builder(); - } - - public static class Builder extends Resource.Builder { - private Status status; - private String ipAddress; - private Integer osType; - private String osDescripton; - private NetworkSection networkSection; - private Set resourceAllocations = Sets.newLinkedHashSet(); - - public Builder ipAddress(String ipAddress) { - this.ipAddress = ipAddress; - return this; - } - - public Builder status(Status status) { - this.status = status; - return this; - } - - public Builder osType(Integer osType) { - this.osType = osType; - return this; - } - - public Builder networkSection(NetworkSection networkSection) { - this.networkSection = networkSection; - return this; - } - - public Builder osDescripton(String osDescripton) { - this.osDescripton = osDescripton; - return this; - } - - public Builder resourceAllocation(ResourceAllocationSettingData in) { - this.resourceAllocations.add(checkNotNull(in, "resourceAllocation")); - return this; - } - - public Builder resourceAllocations(Set resourceAllocations) { - this.resourceAllocations.addAll(checkNotNull(resourceAllocations, "resourceAllocations")); - return this; - } - - @Override - public VM build() { - return new VM(id, name, type, href, status, ipAddress, osType, osDescripton, networkSection, - resourceAllocations); - } - - public static Builder fromVApp(VM in) { - return new Builder().id(in.getId()).name(in.getName()).type(in.getType()).href(in.getHref()) - .status(in.getStatus()).ipAddress(in.getIpAddress()).osType(in.getOsType()) - .networkSection(in.getNetworkSection()).resourceAllocations(in.getResourceAllocations()) - .osDescripton(in.getOsDescripton()); - } - - @Override - public Builder id(String id) { - return Builder.class.cast(super.id(id)); - } - - @Override - public Builder name(String name) { - return Builder.class.cast(super.name(name)); - } - - @Override - public Builder type(String type) { - return Builder.class.cast(super.type(type)); - } - - @Override - public Builder href(URI href) { - return Builder.class.cast(super.href(href)); - } - - } - - private final Status status; - private final String ipAddress; - private final Integer osType; - private final String osDescripton; - private final NetworkSection networkSection; - private final Set resourceAllocations; - - public VM(String id, String name, String type, URI href, Status status, String ipAddress, Integer osType, - String osDescripton, NetworkSection networkSection, Set resourceAllocations) { - super(id, name, type, href); - this.status = status; - this.ipAddress = ipAddress; - this.osType = osType; - this.osDescripton = osDescripton; - this.networkSection = networkSection; - this.resourceAllocations = ImmutableSet.copyOf(checkNotNull(resourceAllocations, "resourceAllocations")); - } - - public Status getStatus() { - return status; - } - - public String getIpAddress() { - return ipAddress; - } - - public Integer getOsType() { - return osType; - } - - public String getOsDescripton() { - return osDescripton; - } - - public NetworkSection getNetworkSection() { - return networkSection; - } - - public Set getResourceAllocations() { - return resourceAllocations; - } - - @Override - public Builder toBuilder() { - return Builder.fromVApp(this); - } - - @Override - public String toString() { - return "[id=" + id + ", href=" + href + ", name=" + name + ", type=" + type + ", status=" + status - + ", ipAddress=" + ipAddress + ", osType=" + osType + ", osDescripton=" + osDescripton - + ", networkSection=" + networkSection + ", resourceAllocations=" + resourceAllocations + "]"; - } - -} \ No newline at end of file diff --git a/sandbox-providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/xml/VMHandler.java b/sandbox-providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/xml/VMHandler.java deleted file mode 100644 index 871515b93a..0000000000 --- a/sandbox-providers/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/xml/VMHandler.java +++ /dev/null @@ -1,114 +0,0 @@ -/** - * - * Copyright (C) 2010 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.xml; - -import static org.jclouds.savvis.vpdc.util.Utils.newResource; -import static org.jclouds.util.SaxUtils.equalsOrSuffix; - -import java.util.Map; - -import javax.inject.Inject; - -import org.jclouds.cim.xml.ResourceAllocationSettingDataHandler; -import org.jclouds.http.functions.ParseSax; -import org.jclouds.ovf.xml.NetworkSectionHandler; -import org.jclouds.savvis.vpdc.domain.Resource; -import org.jclouds.savvis.vpdc.domain.VM; -import org.jclouds.savvis.vpdc.util.Utils; -import org.xml.sax.Attributes; -import org.xml.sax.SAXException; - -import com.google.common.collect.ImmutableMap; - -/** - * @author Kedar Dave - */ -public class VMHandler extends ParseSax.HandlerWithResult { - protected StringBuilder currentText = new StringBuilder(); - private final NetworkSectionHandler networkSectionHandler; - private final ResourceAllocationSettingDataHandler allocationHandler; - - @Inject - public VMHandler(NetworkSectionHandler networkSectionHandler, ResourceAllocationSettingDataHandler allocationHandler) { - this.networkSectionHandler = networkSectionHandler; - this.allocationHandler = allocationHandler; - } - - private VM.Builder builder = VM.builder(); - protected boolean inOs; - - public VM getResult() { - try { - return builder.build(); - } finally { - builder = VM.builder(); - } - } - - public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException { - Map attributes = Utils.cleanseAttributes(attrs); - if (equalsOrSuffix(qName, "VApp")) { - // savvis doesn't add href in the header for some reason - if (!attributes.containsKey("href") && getRequest() != null) - attributes = ImmutableMap. builder().putAll(attributes) - .put("href", getRequest().getEndpoint().toASCIIString()).build(); - Resource vApp = newResource(attributes); - builder.name(vApp.getName()).type(vApp.getType()).id(vApp.getId()).href(vApp.getHref()); - builder.status(VM.Status.fromValue(attributes.get("status"))); - } else if (equalsOrSuffix(qName, "OperatingSystemSection")) { - inOs = true; - if (attributes.containsKey("id")) - builder.osType(Integer.parseInt(attributes.get("id"))); - } else { - networkSectionHandler.startElement(uri, localName, qName, attrs); - allocationHandler.startElement(uri, localName, qName, attrs); - } - - } - - @Override - public void endElement(String uri, String localName, String qName) throws SAXException { - if (equalsOrSuffix(qName, "OperatingSystemSection")) { - inOs = false; - } else if (inOs && equalsOrSuffix(qName, "Description")) { - builder.osDescripton(Utils.currentOrNull(currentText)); - } else if (equalsOrSuffix(qName, "IpAddress")) { - builder.ipAddress(Utils.currentOrNull(currentText)); - } else if (equalsOrSuffix(qName, "NetworkSection")) { - networkSectionHandler.endElement(uri, localName, qName); - builder.networkSection(networkSectionHandler.getResult()); - } else if (equalsOrSuffix(qName, "Item")) { - allocationHandler.endElement(uri, localName, qName); - builder.resourceAllocation(allocationHandler.getResult()); - } else { - networkSectionHandler.endElement(uri, localName, qName); - allocationHandler.endElement(uri, localName, qName); - } - currentText = new StringBuilder(); - } - - @Override - public void characters(char ch[], int start, int length) { - currentText.append(ch, start, length); - networkSectionHandler.characters(ch, start, length); - allocationHandler.characters(ch, start, length); - } - -} diff --git a/sandbox-providers/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/xml/VDCHandlerTest.java b/sandbox-providers/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/xml/VDCHandlerTest.java deleted file mode 100644 index 2bce26a353..0000000000 --- a/sandbox-providers/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/xml/VDCHandlerTest.java +++ /dev/null @@ -1,194 +0,0 @@ -/** - * - * Copyright (C) 2010 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.xml; - -import static org.testng.Assert.assertEquals; - -import java.io.InputStream; -import java.net.URI; - -import org.jclouds.http.functions.ParseSax; -import org.jclouds.http.functions.ParseSax.Factory; -import org.jclouds.http.functions.config.SaxParserModule; -import org.jclouds.savvis.vpdc.domain.Resource; -import org.jclouds.savvis.vpdc.domain.VDC; -import org.jclouds.savvis.vpdc.domain.VDC.Status; -import org.jclouds.savvis.vpdc.reference.VCloudMediaType; -import org.testng.annotations.Test; - -import com.google.common.collect.ImmutableSet; -import com.google.inject.Guice; -import com.google.inject.Injector; - -/** - * Tests behavior of {@code VDCHandler} - * - * @author Adrian Cole - */ -@Test(groups = "unit") -public class VDCHandlerTest { - - public void test() { - InputStream is = getClass().getResourceAsStream("/vdc.xml"); - Injector injector = Guice.createInjector(new SaxParserModule()); - Factory factory = injector.getInstance(ParseSax.Factory.class); - VDC result = factory.create(injector.getInstance(VDCHandler.class)).parse(is); - assertEquals(result.getName(), "demo_vpdcname"); - assertEquals(result.getDescription(), - "ServiceProfileName = Balanced; ServiceLocation = North America; Email = jim@company.com;"); - assertEquals(result.getStatus(), Status.DEPLOYED); - assertEquals( - result.getResourceEntities(), - ImmutableSet. of( - new Resource( - "1001", - "DemoHost-1", - VCloudMediaType.VAPP_XML, - URI.create("https://api.sandbox.symphonyvpdc.savvis.net/rest/api/v0.8/org/100000.0/vdc/2736/vApp/1001")), - new Resource( - "1002", - "DemoHost-2", - VCloudMediaType.VAPP_XML, - URI.create("https://api.sandbox.symphonyvpdc.savvis.net/rest/api/v0.8/org/100000.0/vdc/2736/vApp/1002")), - new Resource( - "1003", - "DemoHost-3", - VCloudMediaType.VAPP_XML, - URI.create("https://api.sandbox.symphonyvpdc.savvis.net/rest/api/v0.8/org/100000.0/vdc/2736/vApp/1003")), - new Resource( - "1234", - "CustomerTemplateName", - VCloudMediaType.VAPPTEMPLATE_XML, - URI.create("https://api.sandbox.symphonyvpdc.savvis.net/rest/api/v0.8/org/100000.0/vdc/2736/vAppTemplate/1234")), - new Resource( - "FirewallService", - "firewall", - "api.symphonyvpdc.savvis.net+xml", - URI.create("https://api.sandbox.symphonyvpdc.savvis.net/rest/api/v0.8/org/100000.0/vdc/2736/FirewallService")))); - assertEquals(result.getAvailableNetworks(), ImmutableSet.of()); - } - - public void test1net() { - InputStream is = getClass().getResourceAsStream("/vdc-1net.xml"); - Injector injector = Guice.createInjector(new SaxParserModule()); - Factory factory = injector.getInstance(ParseSax.Factory.class); - VDC result = factory.create(injector.getInstance(VDCHandler.class)).parse(is); - assertEquals(result.getName(), "demo6"); - assertEquals(result.getDescription(), - "ServiceProfileName = Essential; ServiceLocation = US_WEST; Email = red@chair.com;"); - assertEquals(result.getStatus(), Status.DEPLOYED); - assertEquals(result.getResourceEntities(), ImmutableSet.of( - new Resource("1001", "Host1", VCloudMediaType.VAPP_XML, URI - .create("https://api.symphonyVPDC.savvis.net/rest/api/v0.8/org/606677.0/vdc/1619/vApp/1001")), - new Resource("1002", "Host2", VCloudMediaType.VAPP_XML, URI - .create("https://api.symphonyVPDC.savvis.net/rest/api/v0.8/org/606677.0/vdc/1619/vApp/1002")), - new Resource("1003", "Host3", VCloudMediaType.VAPP_XML, URI - .create("https://api.symphonyVPDC.savvis.net/rest/api/v0.8/org/606677.0/vdc/1619/vApp/1003")), - new Resource("1004", "Host4", VCloudMediaType.VAPP_XML, URI - .create("https://api.symphonyVPDC.savvis.net/rest/api/v0.8/org/606677.0/vdc/1619/vApp/1004")))); - assertEquals(result.getAvailableNetworks(), ImmutableSet.of(Resource - .builder() - .id("VM-Tier01") - .name("VM Tier01") - .type(VCloudMediaType.NETWORK_XML) - .href(URI - .create("https://api.symphonyVPDC.savvis.net/rest/api/v0.8/org/606677.0/vdc/1619/network/VM-Tier01")) - .build())); - - } - - public void testFailed() { - InputStream is = getClass().getResourceAsStream("/vdc-failed.xml"); - Injector injector = Guice.createInjector(new SaxParserModule()); - Factory factory = injector.getInstance(ParseSax.Factory.class); - VDC result = factory.create(injector.getInstance(VDCHandler.class)).parse(is); - assertEquals(result.getName(), "Demo7"); - assertEquals(result.getDescription(), - "ServiceProfileName = Essential; ServiceLocation = US_WEST; Email = red@chair.com;"); - assertEquals(result.getStatus(), Status.FAILED); - assertEquals(result.getResourceEntities(), ImmutableSet.of(new Resource("1001", "Host1", - VCloudMediaType.VAPP_XML, URI - .create("https://api.symphonyVPDC.savvis.net/rest/api/v0.8/org/606677.0/vdc/1641/vApp/1001")))); - assertEquals(result.getAvailableNetworks(), ImmutableSet.of(Resource - .builder() - .id("VM-Tier01") - .name("VM Tier01") - .type(VCloudMediaType.NETWORK_XML) - .href(URI - .create("https://api.symphonyVPDC.savvis.net/rest/api/v0.8/org/606677.0/vdc/1641/network/VM-Tier01")) - .build())); - - } - - public void testSaved() { - InputStream is = getClass().getResourceAsStream("/vdc-saved.xml"); - Injector injector = Guice.createInjector(new SaxParserModule()); - Factory factory = injector.getInstance(ParseSax.Factory.class); - VDC result = factory.create(injector.getInstance(VDCHandler.class)).parse(is); - assertEquals(result.getName(), "CloudBurst1"); - assertEquals(result.getDescription(), - "ServiceProfileName = Essential; ServiceLocation = US_WEST; Email = me@my.com;"); - assertEquals(result.getStatus(), Status.SAVED); - assertEquals( - result.getResourceEntities(), - ImmutableSet.of( - Resource - .builder() - .name("templateHost") - .type("application/vnd.vmware.vcloud.vApp+xml") - .id("1001") - .href(URI - .create("https://api.symphonyVPDC.savvis.net/rest/api/v0.8/org/606677.0/vdc/2555/vApp/1001")) - .build(), - Resource - .builder() - .name("host-c501") - .type("application/vnd.vmware.vcloud.vApp+xml") - .id("1037") - .href(URI - .create("https://api.symphonyVPDC.savvis.net/rest/api/v0.8/org/606677.0/vdc/2555/vApp/1037")) - .build(), - Resource - .builder() - .name("host-c501") - .type("application/vnd.vmware.vcloud.vApp+xml") - .id("1038") - .href(URI - .create("https://api.symphonyVPDC.savvis.net/rest/api/v0.8/org/606677.0/vdc/2555/vApp/1038")) - .build(), - Resource - .builder() - .name("host-c601") - .type("application/vnd.vmware.vcloud.vApp+xml") - .id("1039") - .href(URI - .create("https://api.symphonyVPDC.savvis.net/rest/api/v0.8/org/606677.0/vdc/2555/vApp/1039")) - .build())); - assertEquals(result.getAvailableNetworks(), ImmutableSet.of(Resource - .builder() - .id("VM-Tier01") - .name("VM Tier01") - .type(VCloudMediaType.NETWORK_XML) - .href(URI - .create("https://api.symphonyVPDC.savvis.net/rest/api/v0.8/org/606677.0/vdc/2555/network/VM-Tier01")) - .build())); - - } -}