moved interim version of savvis out of sandbox

This commit is contained in:
Adrian Cole 2011-03-27 17:34:08 -07:00
parent a44abb0768
commit 72e93e96d4
145 changed files with 4744 additions and 1462 deletions

View File

@ -62,7 +62,7 @@ public class HardwareForVApp implements Function<VApp, Hardware> {
return null; return null;
VirtualHardwareSection hardware = vm.getVirtualHardwareSection(); 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.location(findLocationForResource.apply(checkNotNull(from, "from").getVDC()));
builder.ids(from.getHref().toASCIIString()).name(from.getName()).supportsImage( builder.ids(from.getHref().toASCIIString()).name(from.getName()).supportsImage(
ImagePredicates.idEquals(from.getHref().toASCIIString())); ImagePredicates.idEquals(from.getHref().toASCIIString()));

View File

@ -86,7 +86,7 @@ public class HardwareForVAppTemplate implements Function<VAppTemplate, Hardware>
logger.warn("multiple hardware choices found. using first", ovf); logger.warn("multiple hardware choices found. using first", ovf);
} }
VirtualHardwareSection hardware = Iterables.get(ovf.getVirtualSystem().getVirtualHardwareSections(), 0); 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.location(findLocationForResource.apply(checkNotNull(parent, "parent")));
builder.ids(from.getHref().toASCIIString()).name(from.getName()).supportsImage( builder.ids(from.getHref().toASCIIString()).name(from.getName()).supportsImage(
ImagePredicates.idEquals(from.getHref().toASCIIString())); ImagePredicates.idEquals(from.getHref().toASCIIString()));

View File

@ -97,7 +97,7 @@ public class VCloudComputeUtils {
ips.add(connection.getExternalIpAddress()); ips.add(connection.getExternalIpAddress());
} }
} else { } else {
for (ResourceAllocationSettingData net : filter(vm.getVirtualHardwareSection().getResourceAllocations(), for (ResourceAllocationSettingData net : filter(vm.getVirtualHardwareSection().getItems(),
CIMPredicates.resourceTypeIn(ResourceType.ETHERNET_ADAPTER))) { CIMPredicates.resourceTypeIn(ResourceType.ETHERNET_ADAPTER))) {
if (net instanceof VCloudNetworkAdapter) { if (net instanceof VCloudNetworkAdapter) {
VCloudNetworkAdapter vNet = VCloudNetworkAdapter.class.cast(net); VCloudNetworkAdapter vNet = VCloudNetworkAdapter.class.cast(net);

View File

@ -50,7 +50,7 @@ public class VCloudVirtualHardwareHandler extends ParseSax.HandlerWithResult<VCl
public VCloudVirtualHardwareSection getResult() { public VCloudVirtualHardwareSection getResult() {
VirtualHardwareSection hardware = hardwareHandler.getResult(); VirtualHardwareSection hardware = hardwareHandler.getResult();
return new VCloudVirtualHardwareSection(this.hardware.getType(), this.hardware.getHref(), hardware.getInfo(), hardware return new VCloudVirtualHardwareSection(this.hardware.getType(), this.hardware.getHref(), hardware.getInfo(), hardware
.getTransports(), hardware.getSystem(), hardware.getResourceAllocations()); .getTransports(), hardware.getSystem(), hardware.getItems());
} }
public void startElement(String uri, String localName, String qName, Attributes attrs) { public void startElement(String uri, String localName, String qName, Attributes attrs) {

View File

@ -86,35 +86,35 @@ public class VCloudVirtualHardwareSectionHandlerTest extends BaseHandlerTest {
assertEquals(result.getSystem().toString(), system.toString()); assertEquals(result.getSystem().toString(), system.toString());
assertEquals(result.getInfo(), "Virtual hardware requirements"); assertEquals(result.getInfo(), "Virtual hardware requirements");
assertEquals(Iterables.get(result.getResourceAllocations(), 0).toString(), VCloudNetworkAdapter.builder() assertEquals(Iterables.get(result.getItems(), 0).toString(), VCloudNetworkAdapter.builder()
.instanceID("1").elementName("Network adapter 0").description("PCNet32 ethernet adapter").resourceType( .instanceID("1").elementName("Network adapter 0").description("PCNet32 ethernet adapter").resourceType(
ResourceType.ETHERNET_ADAPTER).resourceSubType("PCNet32").automaticAllocation(true).connection( ResourceType.ETHERNET_ADAPTER).resourceSubType("PCNet32").automaticAllocation(true).connection(
"internet01").address("00:50:56:01:01:f2").addressOnParent("0").ipAddress("174.47.101.164") "internet01").address("00:50:56:01:01:f2").addressOnParent("0").ipAddress("174.47.101.164")
.primaryNetworkConnection(true).ipAddressingMode("POOL").build().toString()); .primaryNetworkConnection(true).ipAddressingMode("POOL").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( .builder().instanceID("2").elementName("SCSI Controller 0").description("SCSI Controller").resourceType(
ResourceType.PARALLEL_SCSI_HBA).resourceSubType("lsilogic").address("0").build().toString()); ResourceType.PARALLEL_SCSI_HBA).resourceSubType("lsilogic").address("0").build().toString());
assertEquals(Iterables.get(result.getResourceAllocations(), 2).toString(), VCloudHardDisk.builder().instanceID( assertEquals(Iterables.get(result.getItems(), 2).toString(), VCloudHardDisk.builder().instanceID(
"2000").elementName("Hard disk 1").description("Hard disk").resourceType(ResourceType.DISK_DRIVE) "2000").elementName("Hard disk 1").description("Hard disk").resourceType(ResourceType.DISK_DRIVE)
.addressOnParent("0").parent("2").capacity(30720).busType(6).busSubType("lsilogic").build().toString()); .addressOnParent("0").parent("2").capacity(30720).busType(6).busSubType("lsilogic").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( .builder().instanceID("3").elementName("IDE Controller 0").description("IDE Controller").resourceType(
ResourceType.IDE_CONTROLLER).address("0").build().toString()); 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( .builder().instanceID("3002").elementName("CD/DVD Drive 1").description("CD/DVD Drive").resourceType(
ResourceType.CD_DRIVE).addressOnParent("0").automaticAllocation(false).parent("3").build() ResourceType.CD_DRIVE).addressOnParent("0").automaticAllocation(false).parent("3").build()
.toString()); .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( .builder().instanceID("8000").elementName("Floppy Drive 1").description("Floppy Drive").resourceType(
ResourceType.FLOPPY_DRIVE).addressOnParent("0").automaticAllocation(false).build().toString()); ResourceType.FLOPPY_DRIVE).addressOnParent("0").automaticAllocation(false).build().toString());
assertEquals( assertEquals(
Iterables.get(result.getResourceAllocations(), 6).toString(), Iterables.get(result.getItems(), 6).toString(),
EditableResourceAllocationSettingData EditableResourceAllocationSettingData
.builder() .builder()
.instanceID("4") .instanceID("4")
@ -134,7 +134,7 @@ public class VCloudVirtualHardwareSectionHandlerTest extends BaseHandlerTest {
.build().toString()); .build().toString());
assertEquals( assertEquals(
Iterables.get(result.getResourceAllocations(), 7).toString(), Iterables.get(result.getItems(), 7).toString(),
EditableResourceAllocationSettingData EditableResourceAllocationSettingData
.builder() .builder()
.instanceID("5") .instanceID("5")

View File

@ -49,6 +49,11 @@ public class HardwareBuilder extends ComputeMetadataBuilder {
super(ComputeType.HARDWARE); super(ComputeType.HARDWARE);
} }
public HardwareBuilder processor(Processor processor) {
this.processors.add(checkNotNull(processor, "processor"));
return this;
}
public HardwareBuilder processors(Iterable<Processor> processors) { public HardwareBuilder processors(Iterable<Processor> processors) {
this.processors = ImmutableList.copyOf(checkNotNull(processors, "processors")); this.processors = ImmutableList.copyOf(checkNotNull(processors, "processors"));
return this; return this;
@ -59,6 +64,11 @@ public class HardwareBuilder extends ComputeMetadataBuilder {
return this; return this;
} }
public HardwareBuilder volume(Volume volume) {
this.volumes.add(checkNotNull(volume, "volume"));
return this;
}
public HardwareBuilder volumes(Iterable<Volume> volumes) { public HardwareBuilder volumes(Iterable<Volume> volumes) {
this.volumes = ImmutableList.copyOf(checkNotNull(volumes, "volumes")); this.volumes = ImmutableList.copyOf(checkNotNull(volumes, "volumes"));
return this; return this;
@ -117,9 +127,9 @@ public class HardwareBuilder extends ComputeMetadataBuilder {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public static HardwareBuilder fromHardware(Hardware in) { public static HardwareBuilder fromHardware(Hardware in) {
return new HardwareBuilder().id(in.getId()).providerId(in.getProviderId()).location(in.getLocation()) return new HardwareBuilder().id(in.getId()).providerId(in.getProviderId()).location(in.getLocation()).name(
.name(in.getName()).uri(in.getUri()).userMetadata(in.getUserMetadata()) in.getName()).uri(in.getUri()).userMetadata(in.getUserMetadata()).processors(
.processors(List.class.cast(in.getProcessors())).ram(in.getRam()).volumes(List.class.cast(in.getVolumes())) List.class.cast(in.getProcessors())).ram(in.getRam()).volumes(List.class.cast(in.getVolumes()))
.supportsImage(in.supportsImage()); .supportsImage(in.supportsImage());
} }
} }

View File

@ -61,7 +61,7 @@ public class Configuration {
return new Configuration(id, label, description); 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()); return id(in.getId()).description(in.getDescription()).label(in.getLabel());
} }
} }
@ -103,7 +103,7 @@ public class Configuration {
@Override @Override
public String toString() { 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() { public String getId() {

View File

@ -19,21 +19,16 @@
package org.jclouds.ovf; 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.Multimap;
import com.google.common.collect.Sets;
/** /**
* @author Adrian Cole * @author Adrian Cole
*/ */
public class Envelope { public class Envelope extends BaseEnvelope<VirtualSystem, Envelope> {
@SuppressWarnings("unchecked")
public static Builder builder() { public static Builder builder() {
return new Builder(); return new Builder();
} }
@ -45,71 +40,7 @@ public class Envelope {
return new Builder().fromEnvelope(this); return new Builder().fromEnvelope(this);
} }
public static class Builder { public static class Builder extends BaseEnvelope.Builder<VirtualSystem, Envelope> {
protected Set<DiskSection> diskSections = Sets.newLinkedHashSet();
protected Set<NetworkSection> networkSections = Sets.newLinkedHashSet();
@SuppressWarnings("unchecked")
protected Multimap<String, Section> 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<? extends DiskSection> diskSections) {
this.diskSections = ImmutableSet.<DiskSection> 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<? extends NetworkSection> networkSections) {
this.networkSections = ImmutableSet.<NetworkSection> 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<String, Section> additionalSections) {
this.additionalSections = ImmutableMultimap.<String, Section> copyOf(checkNotNull(additionalSections,
"additionalSections"));
return this;
}
/**
* @see Envelope#getVirtualSystem
*/
public Builder virtualSystem(VirtualSystem virtualSystem) {
this.virtualSystem = virtualSystem;
return this;
}
/** /**
* {@inheritDoc} * {@inheritDoc}
@ -118,91 +49,78 @@ public class Envelope {
return new Envelope(diskSections, networkSections, additionalSections, virtualSystem); return new Envelope(diskSections, networkSections, additionalSections, virtualSystem);
} }
public Builder fromEnvelope(Envelope in) { /**
return virtualSystem(in.getVirtualSystem()).diskSections(in.getDiskSections()) * {@inheritDoc}
.networkSections(networkSections).additionalSections(in.getAdditionalSections()); */
}
}
private final Set<DiskSection> diskSections;
private final Set<NetworkSection> networkSections;
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
private final Multimap<String, Section> additionalSections; @Override
private final VirtualSystem virtualSystem; public Builder additionalSection(String name, Section additionalSection) {
return Builder.class.cast(super.additionalSection(name, additionalSection));
}
/**
* {@inheritDoc}
*/
@SuppressWarnings("unchecked")
@Override
public Builder additionalSections(Multimap<String, Section> 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<? extends DiskSection> diskSections) {
return Builder.class.cast(super.diskSections(diskSections));
}
/**
* {@inheritDoc}
*/
@Override
public Builder fromEnvelope(BaseEnvelope<VirtualSystem, Envelope> 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<? extends NetworkSection> networkSections) {
return Builder.class.cast(super.networkSections(networkSections));
}
/**
* {@inheritDoc}
*/
@Override
public Builder virtualSystem(VirtualSystem virtualSystem) {
return Builder.class.cast(super.virtualSystem(virtualSystem));
}
}
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public Envelope(Iterable<? extends DiskSection> diskSections, Iterable<? extends NetworkSection> networkSections, public Envelope(Iterable<? extends DiskSection> diskSections, Iterable<? extends NetworkSection> networkSections,
Multimap<String, Section> additionalSections, VirtualSystem virtualSystem) { Multimap<String, Section> additionalSections, VirtualSystem virtualSystem) {
this.diskSections = ImmutableSet.copyOf(checkNotNull(diskSections, "diskSections")); super(diskSections, networkSections, additionalSections, virtualSystem);
this.networkSections = ImmutableSet.copyOf(checkNotNull(networkSections, "networkSections"));
this.additionalSections = ImmutableMultimap.copyOf(checkNotNull(additionalSections, "additionalSections"));
this.virtualSystem = checkNotNull(virtualSystem, "virtualSystem");
} }
public VirtualSystem getVirtualSystem() {
return virtualSystem;
}
public Set<? extends DiskSection> getDiskSections() {
return diskSections;
}
@SuppressWarnings("unchecked")
public Multimap<String, Section> 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<NetworkSection> getNetworkSections() {
return networkSections;
}
} }

View File

@ -0,0 +1,141 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.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<ProductSection> {
@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<ProductSection> {
protected Set<Property> 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<Property> properties) {
this.properties = ImmutableSet.<Property> 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<ProductSection> 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<Property> properties;
public ProductSection(String info, Iterable<Property> properties) {
super(info);
this.properties = ImmutableSet.<Property> 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<Property> getProperties() {
return properties;
}
}

View File

@ -0,0 +1,135 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <description@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.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;
}
}

View File

@ -56,7 +56,7 @@ public class VirtualHardwareSection extends Section<VirtualHardwareSection> {
public static class Builder extends Section.Builder<VirtualHardwareSection> { public static class Builder extends Section.Builder<VirtualHardwareSection> {
protected VirtualSystemSettingData virtualSystem; protected VirtualSystemSettingData virtualSystem;
protected Set<String> transports = Sets.newLinkedHashSet(); protected Set<String> transports = Sets.newLinkedHashSet();
protected Set<ResourceAllocationSettingData> resourceAllocations = Sets.newLinkedHashSet(); protected Set<ResourceAllocationSettingData> items = Sets.newLinkedHashSet();
/** /**
* @see VirtualHardwareSection#getSystem * @see VirtualHardwareSection#getSystem
@ -83,19 +83,19 @@ public class VirtualHardwareSection extends Section<VirtualHardwareSection> {
} }
/** /**
* @see VirtualHardwareSection#getResourceAllocations * @see VirtualHardwareSection#getItems
*/ */
public Builder resourceAllocation(ResourceAllocationSettingData resourceAllocation) { public Builder item(ResourceAllocationSettingData item) {
this.resourceAllocations.add(checkNotNull(resourceAllocation, "resourceAllocation")); this.items.add(checkNotNull(item, "item"));
return this; return this;
} }
/** /**
* @see VirtualHardwareSection#getResourceAllocations * @see VirtualHardwareSection#getItems
*/ */
public Builder resourceAllocations(Iterable<? extends ResourceAllocationSettingData> resourceAllocations) { public Builder items(Iterable<? extends ResourceAllocationSettingData> items) {
this.resourceAllocations = ImmutableSet.<ResourceAllocationSettingData> copyOf(checkNotNull( this.items = ImmutableSet.<ResourceAllocationSettingData> copyOf(checkNotNull(
resourceAllocations, "resourceAllocations")); items, "items"));
return this; return this;
} }
@ -104,11 +104,11 @@ public class VirtualHardwareSection extends Section<VirtualHardwareSection> {
*/ */
@Override @Override
public VirtualHardwareSection build() { public VirtualHardwareSection build() {
return new VirtualHardwareSection(info, transports, virtualSystem, resourceAllocations); return new VirtualHardwareSection(info, transports, virtualSystem, items);
} }
public Builder fromVirtualHardwareSection(VirtualHardwareSection in) { 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()); in.getSystem()).info(in.getInfo());
} }
@ -132,15 +132,15 @@ public class VirtualHardwareSection extends Section<VirtualHardwareSection> {
protected final VirtualSystemSettingData virtualSystem; protected final VirtualSystemSettingData virtualSystem;
protected final Set<String> transports; protected final Set<String> transports;
protected final Set<ResourceAllocationSettingData> resourceAllocations; protected final Set<ResourceAllocationSettingData> items;
public VirtualHardwareSection(String info, Iterable<String> transports, VirtualSystemSettingData virtualSystem, public VirtualHardwareSection(String info, Iterable<String> transports, VirtualSystemSettingData virtualSystem,
Iterable<? extends ResourceAllocationSettingData> resourceAllocations) { Iterable<? extends ResourceAllocationSettingData> items) {
super(info); super(info);
this.virtualSystem = virtualSystem; this.virtualSystem = virtualSystem;
this.transports = ImmutableSet.<String> copyOf(checkNotNull(transports, "transports")); this.transports = ImmutableSet.<String> copyOf(checkNotNull(transports, "transports"));
this.resourceAllocations = ImmutableSet.<ResourceAllocationSettingData> copyOf(checkNotNull(resourceAllocations, this.items = ImmutableSet.<ResourceAllocationSettingData> copyOf(checkNotNull(items,
"resourceAllocations")); "items"));
} }
/** /**
@ -168,15 +168,15 @@ public class VirtualHardwareSection extends Section<VirtualHardwareSection> {
return virtualSystem; return virtualSystem;
} }
public Set<? extends ResourceAllocationSettingData> getResourceAllocations() { public Set<? extends ResourceAllocationSettingData> getItems() {
return resourceAllocations; return items;
} }
@Override @Override
public int hashCode() { public int hashCode() {
final int prime = 31; final int prime = 31;
int result = super.hashCode(); 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 + ((transports == null) ? 0 : transports.hashCode());
result = prime * result + ((virtualSystem == null) ? 0 : virtualSystem.hashCode()); result = prime * result + ((virtualSystem == null) ? 0 : virtualSystem.hashCode());
return result; return result;
@ -191,10 +191,10 @@ public class VirtualHardwareSection extends Section<VirtualHardwareSection> {
if (getClass() != obj.getClass()) if (getClass() != obj.getClass())
return false; return false;
VirtualHardwareSection other = (VirtualHardwareSection) obj; VirtualHardwareSection other = (VirtualHardwareSection) obj;
if (resourceAllocations == null) { if (items == null) {
if (other.resourceAllocations != null) if (other.items != null)
return false; return false;
} else if (!resourceAllocations.equals(other.resourceAllocations)) } else if (!items.equals(other.items))
return false; return false;
if (transports == null) { if (transports == null) {
if (other.transports != null) if (other.transports != null)
@ -211,8 +211,8 @@ public class VirtualHardwareSection extends Section<VirtualHardwareSection> {
@Override @Override
public String toString() { public String toString() {
return String.format("[info=%s, resourceAllocations=%s, transports=%s, virtualSystem=%s]", info, return String.format("[info=%s, items=%s, transports=%s, virtualSystem=%s]", info,
resourceAllocations, transports, virtualSystem); items, transports, virtualSystem);
} }
} }

View File

@ -19,114 +19,42 @@
package org.jclouds.ovf; 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.Multimap;
import com.google.common.collect.Sets;
/** /**
* @author Adrian Cole * @author Adrian Cole
*/ */
public class VirtualSystem extends Section<VirtualSystem> { public class VirtualSystem extends BaseVirtualSystem<VirtualSystem> {
@SuppressWarnings("unchecked") public static class Builder extends BaseVirtualSystem.Builder<VirtualSystem> {
public static Builder builder() {
return new Builder();
}
/**
* {@inheritDoc}
*/
@Override
public Builder toBuilder() {
return new Builder().fromVirtualSystem(this);
}
public static class Builder extends Section.Builder<VirtualSystem> {
protected String id;
protected String name;
protected OperatingSystemSection operatingSystem;
protected Set<VirtualHardwareSection> hardwareSections = Sets.newLinkedHashSet();
@SuppressWarnings("unchecked")
protected Multimap<String, Section> 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<? extends VirtualHardwareSection> hardwareSections) {
this.hardwareSections = ImmutableSet.<VirtualHardwareSection> 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<String, Section> additionalSections) {
this.additionalSections = ImmutableMultimap.<String, Section> copyOf(checkNotNull(additionalSections,
"additionalSections"));
return this;
}
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
public VirtualSystem build() { 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()) * {@inheritDoc}
.operatingSystemSection(in.getOperatingSystemSection()).hardwareSections( */
in.getVirtualHardwareSections()).additionalSections(in.getAdditionalSections()); @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<String, Section> additionalSections) {
return Builder.class.cast(super.additionalSections(additionalSections));
} }
/** /**
@ -134,7 +62,39 @@ public class VirtualSystem extends Section<VirtualSystem> {
*/ */
@Override @Override
public Builder fromSection(Section<VirtualSystem> in) { public Builder fromSection(Section<VirtualSystem> in) {
return (Builder) super.fromSection(in); return Builder.class.cast(super.fromSection(in));
}
/**
* {@inheritDoc}
*/
@Override
public Builder fromVirtualSystem(BaseVirtualSystem<VirtualSystem> 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<? extends VirtualHardwareSection> 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<VirtualSystem> {
*/ */
@Override @Override
public Builder info(String info) { public Builder info(String info) {
return (Builder) super.info(info); return Builder.class.cast(super.info(info));
}
}
private final String id;
private final String name;
private final OperatingSystemSection operatingSystem;
private final Set<VirtualHardwareSection> hardwareSections;
@SuppressWarnings("unchecked")
private final Multimap<String, Section> additionalSections;
@SuppressWarnings("unchecked")
public VirtualSystem(String id, String info, String name, OperatingSystemSection operatingSystem,
Iterable<? extends VirtualHardwareSection> hardwareSections, Multimap<String, Section> 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 * {@inheritDoc}
* which describes the virtual hardwareSections required by the virtual system. */
* */ @Override
public Set<? extends VirtualHardwareSection> getVirtualHardwareSections() { public Builder name(String name) {
return hardwareSections; 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<? extends ProductSection> productSections) {
return Builder.class.cast(super.productSections(productSections));
}
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public Multimap<String, Section> getAdditionalSections() { public VirtualSystem(String id, String info, String name, OperatingSystemSection operatingSystem,
return additionalSections; Iterable<? extends VirtualHardwareSection> virtualHardwareSections,
} Iterable<? extends ProductSection> productSections, Multimap<String, Section> additionalSections) {
super(id, info, name, operatingSystem, virtualHardwareSections, productSections, 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);
} }
} }

View File

@ -0,0 +1,213 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.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<V extends BaseVirtualSystem<V>, E extends BaseEnvelope<V, E>> {
public static <V extends BaseVirtualSystem<V>, E extends BaseEnvelope<V, E>> Builder<V, E> builder() {
return new Builder<V, E>();
}
/**
* {@inheritDoc}
*/
public Builder<V, E> toBuilder() {
return new Builder<V, E>().fromEnvelope(this);
}
public static class Builder<V extends BaseVirtualSystem<V>, E extends BaseEnvelope<V, E>> {
protected Set<DiskSection> diskSections = Sets.newLinkedHashSet();
protected Set<NetworkSection> networkSections = Sets.newLinkedHashSet();
@SuppressWarnings("unchecked")
protected Multimap<String, Section> additionalSections = LinkedHashMultimap.create();
protected V virtualSystem;
/**
* @see BaseEnvelope#getDiskSections
*/
public Builder<V, E> diskSection(DiskSection diskSection) {
this.diskSections.add(checkNotNull(diskSection, "diskSection"));
return this;
}
/**
* @see BaseEnvelope#getDiskSections
*/
public Builder<V, E> diskSections(Iterable<? extends DiskSection> diskSections) {
this.diskSections = ImmutableSet.<DiskSection> copyOf(checkNotNull(diskSections, "diskSections"));
return this;
}
/**
* @see BaseEnvelope#getNetworkSections
*/
public Builder<V, E> networkSection(NetworkSection networkSection) {
this.networkSections.add(checkNotNull(networkSection, "networkSection"));
return this;
}
/**
* @see BaseEnvelope#getNetworkSections
*/
public Builder<V, E> networkSections(Iterable<? extends NetworkSection> networkSections) {
this.networkSections = ImmutableSet.<NetworkSection> copyOf(checkNotNull(networkSections, "networkSections"));
return this;
}
/**
* @see BaseEnvelope#getAdditionalSections
*/
@SuppressWarnings("unchecked")
public Builder<V, E> additionalSection(String name, Section additionalSection) {
this.additionalSections.put(checkNotNull(name, "name"), checkNotNull(additionalSection, "additionalSection"));
return this;
}
/**
* @see BaseEnvelope#getAdditionalSections
*/
@SuppressWarnings("unchecked")
public Builder<V, E> additionalSections(Multimap<String, Section> additionalSections) {
this.additionalSections = ImmutableMultimap.<String, Section> copyOf(checkNotNull(additionalSections,
"additionalSections"));
return this;
}
/**
* @see BaseEnvelope#getVirtualSystem
*/
public Builder<V, E> virtualSystem(V virtualSystem) {
this.virtualSystem = virtualSystem;
return this;
}
/**
* {@inheritDoc}
*/
@SuppressWarnings("unchecked")
public E build() {
return (E) new BaseEnvelope<V, E>(diskSections, networkSections, additionalSections, virtualSystem);
}
public Builder<V, E> fromEnvelope(BaseEnvelope<V, E> in) {
return virtualSystem(in.getVirtualSystem()).diskSections(in.getDiskSections())
.networkSections(networkSections).additionalSections(in.getAdditionalSections());
}
}
private final Set<DiskSection> diskSections;
private final Set<NetworkSection> networkSections;
@SuppressWarnings("unchecked")
private final Multimap<String, Section> additionalSections;
private final V virtualSystem;
@SuppressWarnings("unchecked")
public BaseEnvelope(Iterable<? extends DiskSection> diskSections, Iterable<? extends NetworkSection> networkSections,
Multimap<String, Section> 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<? extends DiskSection> getDiskSections() {
return diskSections;
}
@SuppressWarnings("unchecked")
public Multimap<String, Section> 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<NetworkSection> getNetworkSections() {
return networkSections;
}
}

View File

@ -0,0 +1,260 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.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<T extends BaseVirtualSystem<T>> extends Section<T> {
@SuppressWarnings("unchecked")
public static Builder builder() {
return new Builder();
}
/**
* {@inheritDoc}
*/
@Override
public Builder<T> toBuilder() {
return new Builder<T>().fromVirtualSystem(this);
}
public static class Builder<T extends BaseVirtualSystem<T>> extends Section.Builder<T> {
protected String id;
protected String name;
protected OperatingSystemSection operatingSystem;
protected Set<VirtualHardwareSection> virtualHardwareSections = Sets.newLinkedHashSet();
protected Set<ProductSection> productSections = Sets.newLinkedHashSet();
@SuppressWarnings("unchecked")
protected Multimap<String, Section> additionalSections = LinkedHashMultimap.create();
/**
* @see BaseVirtualSystem#getName
*/
public Builder<T> name(String name) {
this.name = name;
return this;
}
/**
* @see BaseVirtualSystem#getId
*/
public Builder<T> id(String id) {
this.id = id;
return this;
}
/**
* @see BaseVirtualSystem#getOperatingSystemSection
*/
public Builder<T> operatingSystemSection(OperatingSystemSection operatingSystem) {
this.operatingSystem = operatingSystem;
return this;
}
/**
* @see BaseVirtualSystem#getVirtualHardwareSections
*/
public Builder<T> virtualHardwareSection(VirtualHardwareSection virtualHardwareSection) {
this.virtualHardwareSections.add(checkNotNull(virtualHardwareSection, "virtualHardwareSection"));
return this;
}
/**
* @see BaseVirtualSystem#getVirtualHardwareSections
*/
public Builder<T> virtualHardwareSections(Iterable<? extends VirtualHardwareSection> virtualHardwareSections) {
this.virtualHardwareSections = ImmutableSet.<VirtualHardwareSection> copyOf(checkNotNull(virtualHardwareSections,
"virtualHardwareSections"));
return this;
}
/**
* @see BaseVirtualSystem#getProductSections
*/
public Builder<T> productSection(ProductSection productSection) {
this.productSections.add(checkNotNull(productSection, "productSection"));
return this;
}
/**
* @see BaseVirtualSystem#getProductSections
*/
public Builder<T> productSections(Iterable<? extends ProductSection> productSections) {
this.productSections = ImmutableSet.<ProductSection> copyOf(checkNotNull(productSections, "productSections"));
return this;
}
/**
* @see BaseVirtualSystem#getAdditionalSections
*/
@SuppressWarnings("unchecked")
public Builder<T> additionalSection(String name, Section additionalSection) {
this.additionalSections.put(checkNotNull(name, "name"), checkNotNull(additionalSection, "additionalSection"));
return this;
}
/**
* @see BaseVirtualSystem#getAdditionalSections
*/
@SuppressWarnings("unchecked")
public Builder<T> additionalSections(Multimap<String, Section> additionalSections) {
this.additionalSections = ImmutableMultimap.<String, Section> copyOf(checkNotNull(additionalSections,
"additionalSections"));
return this;
}
/**
* {@inheritDoc}
*/
@Override
public BaseVirtualSystem<T> build() {
return new BaseVirtualSystem<T>(id, info, name, operatingSystem, virtualHardwareSections, productSections,
additionalSections);
}
public Builder<T> fromVirtualSystem(BaseVirtualSystem<T> 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<T> fromSection(Section<T> in) {
return (Builder<T>) super.fromSection(in);
}
/**
* {@inheritDoc}
*/
@Override
public Builder<T> info(String info) {
return (Builder<T>) super.info(info);
}
}
protected final String id;
protected final String name;
protected final OperatingSystemSection operatingSystem;
protected final Set<VirtualHardwareSection> virtualHardwareSections;
protected final Set<ProductSection> productSections;
@SuppressWarnings("unchecked")
protected final Multimap<String, Section> additionalSections;
@SuppressWarnings("unchecked")
public BaseVirtualSystem(String id, String info, String name, OperatingSystemSection operatingSystem,
Iterable<? extends VirtualHardwareSection> virtualHardwareSections,
Iterable<? extends ProductSection> productSections, Multimap<String, Section> 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<? extends VirtualHardwareSection> 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<? extends ProductSection> getProductSections() {
return productSections;
}
@SuppressWarnings("unchecked")
public Multimap<String, Section> 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);
}
}

View File

@ -19,147 +19,24 @@
package org.jclouds.ovf.xml; package org.jclouds.ovf.xml;
import static org.jclouds.util.SaxUtils.equalsOrSuffix; import javax.inject.Inject;
import java.util.Map;
import javax.inject.Named;
import javax.inject.Provider; import javax.inject.Provider;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.ovf.Envelope; import org.jclouds.ovf.Envelope;
import org.xml.sax.Attributes; import org.jclouds.ovf.VirtualSystem;
import org.xml.sax.SAXException; import org.jclouds.ovf.Envelope.Builder;
import org.jclouds.ovf.xml.internal.BaseEnvelopeHandler;
import com.google.common.collect.ImmutableMap;
import com.google.inject.Inject;
/** /**
* @author Adrian Cole * @author Adrian Cole
*/ */
public class EnvelopeHandler extends ParseSax.HandlerWithResult<Envelope> { public class EnvelopeHandler extends
BaseEnvelopeHandler<VirtualSystem, VirtualSystem.Builder, VirtualSystemHandler, Envelope, Envelope.Builder> {
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;
@Inject @Inject
public EnvelopeHandler(DiskSectionHandler diskHandler, NetworkSectionHandler networkHandler, public EnvelopeHandler(DiskSectionHandler diskHandler, NetworkSectionHandler networkHandler,
VirtualSystemHandler osHandler) { VirtualSystemHandler virtualSystemHandler, Provider<Builder> envelopeBuilderProvider) {
this.virtualSystemHandler = osHandler; super(diskHandler, networkHandler, virtualSystemHandler, envelopeBuilderProvider);
this.diskHandler = diskHandler;
this.networkHandler = networkHandler;
}
@SuppressWarnings("unchecked")
protected SectionHandler defaultSectionHandler = SectionHandler.create();
@SuppressWarnings("unchecked")
@Inject(optional = true)
@Named("VirtualSystem")
Map<String, Provider<? extends SectionHandler>> extensionHandlers = ImmutableMap
.<String, Provider<? extends SectionHandler>> 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);
}
} }
} }

View File

@ -29,6 +29,7 @@ import javax.inject.Provider;
import org.jclouds.ovf.Network; import org.jclouds.ovf.Network;
import org.jclouds.ovf.NetworkSection; import org.jclouds.ovf.NetworkSection;
import org.jclouds.ovf.xml.SectionHandler;
import org.jclouds.util.SaxUtils; import org.jclouds.util.SaxUtils;
import org.xml.sax.Attributes; import org.xml.sax.Attributes;

View File

@ -0,0 +1,71 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.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<ProductSection, ProductSection.Builder> {
protected Property.Builder configBuilder = Property.builder();
@Inject
public ProductSectionHandler(Provider<ProductSection.Builder> builderProvider) {
super(builderProvider);
}
public void startElement(String uri, String localName, String qName, Attributes attrs) {
Map<String, String> 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);
}
}

View File

@ -65,7 +65,6 @@ public class VirtualHardwareSectionHandler extends
} else if (!inSystem && equalsOrSuffix(qName, "Item")) { } else if (!inSystem && equalsOrSuffix(qName, "Item")) {
inItem = true; inItem = true;
} }
if (inSystem) { if (inSystem) {
systemHandler.startElement(uri, localName, qName, attrs); systemHandler.startElement(uri, localName, qName, attrs);
} else if (inItem) { } else if (inItem) {
@ -80,7 +79,7 @@ public class VirtualHardwareSectionHandler extends
builder.system(systemHandler.getResult()); builder.system(systemHandler.getResult());
} else if (equalsOrSuffix(qName, "Item")) { } else if (equalsOrSuffix(qName, "Item")) {
inItem = false; inItem = false;
builder.resourceAllocation(allocationHandler.getResult()); builder.item(allocationHandler.getResult());
} }
if (inSystem) { if (inSystem) {
systemHandler.endElement(uri, localName, qName); systemHandler.endElement(uri, localName, qName);

View File

@ -19,135 +19,22 @@
package org.jclouds.ovf.xml; package org.jclouds.ovf.xml;
import static org.jclouds.util.SaxUtils.cleanseAttributes; import javax.inject.Inject;
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 javax.inject.Provider;
import org.jclouds.ovf.VirtualSystem; import org.jclouds.ovf.VirtualSystem;
import org.xml.sax.Attributes; import org.jclouds.ovf.xml.internal.BaseVirtualSystemHandler;
import org.xml.sax.SAXException;
import com.google.common.collect.ImmutableMap;
import com.google.inject.Inject;
/** /**
* @author Adrian Cole * @author Adrian Cole
*/ */
public class VirtualSystemHandler extends SectionHandler<VirtualSystem, VirtualSystem.Builder> { public class VirtualSystemHandler extends BaseVirtualSystemHandler<VirtualSystem, VirtualSystem.Builder> {
private final OperatingSystemSectionHandler osHandler;
private final VirtualHardwareSectionHandler hardwareHandler;
@Inject @Inject
public VirtualSystemHandler(Provider<VirtualSystem.Builder> builderProvider, public VirtualSystemHandler(Provider<VirtualSystem.Builder> builderProvider,
OperatingSystemSectionHandler osHandler, VirtualHardwareSectionHandler hardwareHandler) { OperatingSystemSectionHandler osHandler, VirtualHardwareSectionHandler hardwareHandler,
super(builderProvider); ProductSectionHandler productHandler) {
this.osHandler = osHandler; super(builderProvider, osHandler, hardwareHandler, productHandler);
this.hardwareHandler = hardwareHandler;
}
@SuppressWarnings("unchecked")
protected SectionHandler defaultSectionHandler = SectionHandler.create();
@SuppressWarnings("unchecked")
@Inject(optional = true)
@Named("VirtualSystem")
Map<String, Provider<? extends SectionHandler>> extensionHandlers = ImmutableMap
.<String, Provider<? extends SectionHandler>> 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<String, String> 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);
}
} }
} }

View File

@ -0,0 +1,175 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.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<V extends BaseVirtualSystem<V>, B extends BaseVirtualSystem.Builder<V>, H extends BaseVirtualSystemHandler<V, B>, E extends BaseEnvelope<V, E>, T extends BaseEnvelope.Builder<V, E>>
extends ParseSax.HandlerWithResult<E> {
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<T> envelopeBuilderProvider;
protected T builder;
@Inject
public BaseEnvelopeHandler(DiskSectionHandler diskHandler, NetworkSectionHandler networkHandler,
H virtualSystemHandler, Provider<T> 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<String, Provider<? extends SectionHandler>> extensionHandlers = ImmutableMap
.<String, Provider<? extends SectionHandler>> 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<String, String> 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);
}
}
}

View File

@ -0,0 +1,190 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.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<T extends BaseVirtualSystem<T>, B extends BaseVirtualSystem.Builder<T>> extends
SectionHandler<T, B> {
private final OperatingSystemSectionHandler osHandler;
private final VirtualHardwareSectionHandler hardwareHandler;
private final ProductSectionHandler productHandler;
@Inject
public BaseVirtualSystemHandler(Provider<B> 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<String, Provider<? extends SectionHandler>> extensionHandlers = ImmutableMap
.<String, Provider<? extends SectionHandler>> of();
@SuppressWarnings("unchecked")
@Inject(optional = true)
protected void setExtensionHandlers(
@Named("VirtualSystem") Map<String, Provider<? extends SectionHandler>> extensionHandlers) {
extensionHandlers = ImmutableMap.<String, Provider<? extends SectionHandler>> 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<String, String> 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);
}
}
}

View File

@ -26,7 +26,6 @@ import java.io.InputStream;
import org.jclouds.cim.ResourceAllocationSettingData; import org.jclouds.cim.ResourceAllocationSettingData;
import org.jclouds.cim.VirtualSystemSettingData; import org.jclouds.cim.VirtualSystemSettingData;
import org.jclouds.cim.ResourceAllocationSettingData.ResourceType; import org.jclouds.cim.ResourceAllocationSettingData.ResourceType;
import org.jclouds.cim.xml.VirtualSystemSettingDataHandler;
import org.jclouds.http.functions.BaseHandlerTest; import org.jclouds.http.functions.BaseHandlerTest;
import org.jclouds.http.functions.ParseSax; import org.jclouds.http.functions.ParseSax;
import org.jclouds.http.functions.ParseSax.Factory; 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.OperatingSystemSection;
import org.jclouds.ovf.VirtualHardwareSection; import org.jclouds.ovf.VirtualHardwareSection;
import org.jclouds.ovf.VirtualSystem; import org.jclouds.ovf.VirtualSystem;
import org.jclouds.ovf.internal.BaseVirtualSystem;
import org.jclouds.ovf.xml.VirtualSystemHandler; import org.jclouds.ovf.xml.VirtualSystemHandler;
import org.testng.annotations.Test; import org.testng.annotations.Test;
@ -71,7 +71,7 @@ public class VirtualSystemSettingDataHandlerTest extends BaseHandlerTest {
} }
@Test(enabled = false) @Test(enabled = false)
public static void checkVirtualSystem(VirtualSystem result) { public static <T extends BaseVirtualSystem<T>> void checkVirtualSystem(BaseVirtualSystem<T> result) {
assertEquals(result.getId(), "Ubuntu1004"); assertEquals(result.getId(), "Ubuntu1004");
assertEquals(result.getName(), "Ubuntu1004"); assertEquals(result.getName(), "Ubuntu1004");
assertEquals(result.getInfo(), "A virtual machine:"); assertEquals(result.getInfo(), "A virtual machine:");
@ -85,38 +85,38 @@ public class VirtualSystemSettingDataHandlerTest extends BaseHandlerTest {
"Virtual Hardware Family").virtualSystemIdentifier("Ubuntu1004").virtualSystemType("vmx-07").build()); "Virtual Hardware Family").virtualSystemIdentifier("Ubuntu1004").virtualSystemType("vmx-07").build());
assertEquals(result.getInfo(), "Virtual hardware requirements"); 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") .builder().instanceID("1").elementName("Network adapter 0").description("PCNet32 ethernet adapter")
.resourceType(ResourceType.ETHERNET_ADAPTER).resourceSubType("PCNet32").address("00:50:56:8c:00:13") .resourceType(ResourceType.ETHERNET_ADAPTER).resourceSubType("PCNet32").address("00:50:56:8c:00:13")
.automaticAllocation(true).connection("vAppNet-vApp Internal").addressOnParent("0").build().toString()); .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( .builder().instanceID("2").elementName("SCSI Controller 0").description("SCSI Controller").resourceType(
ResourceType.PARALLEL_SCSI_HBA).resourceSubType("lsilogic").address("0").build().toString()); 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( .builder().instanceID("2000").elementName("Hard disk 1").description("Hard disk").resourceType(
ResourceType.DISK_DRIVE).addressOnParent("0").parent("2").build().toString()); 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( .builder().instanceID("3").elementName("IDE Controller 0").description("IDE Controller").resourceType(
ResourceType.IDE_CONTROLLER).address("0").build().toString()); 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( .builder().instanceID("3002").elementName("CD/DVD Drive 1").description("CD/DVD Drive").resourceType(
ResourceType.CD_DRIVE).addressOnParent("0").parent("3").automaticAllocation(false).build() ResourceType.CD_DRIVE).addressOnParent("0").parent("3").automaticAllocation(false).build()
.toString()); .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( .builder().instanceID("8000").elementName("Floppy Drive 1").description("Floppy Drive").resourceType(
ResourceType.FLOPPY_DRIVE).addressOnParent("0").automaticAllocation(false).build().toString()); 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") .builder().instanceID("4").elementName("1 virtual CPU(s)").description("Number of Virtual CPUs")
.resourceType(ResourceType.PROCESSOR).virtualQuantity(1l).allocationUnits("hertz * 10^6") .resourceType(ResourceType.PROCESSOR).virtualQuantity(1l).allocationUnits("hertz * 10^6")
.reservation(0l).weight(0).build().toString()); .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( .builder().instanceID("5").elementName("512 MB of memory").description("Memory Size").resourceType(
ResourceType.MEMORY).virtualQuantity(512l).allocationUnits("byte * 2^20").reservation(0l) ResourceType.MEMORY).virtualQuantity(512l).allocationUnits("byte * 2^20").reservation(0l)
.weight(0).build().toString()); .weight(0).build().toString());

View File

@ -0,0 +1,77 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.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()
);
}
}

View File

@ -0,0 +1,38 @@
<ovf:ProductSection>
<ovf:Info>vCenter Information</ovf:Info>
<ovf:Property ovf:value="false" ovf:type="String" ovf:key="vmwareToolsEnabled">
<ovf:Label>VMWare Tools Enabled status</ovf:Label>
<ovf:Description>VMWare Tools Enabled status</ovf:Description>
</ovf:Property>
<ovf:Property ovf:value="10.12.46.171" ovf:type="String" ovf:key="vmwareESXHost">
<ovf:Label>VMWare ESXHost Ipaddress</ovf:Label>
<ovf:Description>VMWare ESXHost Ipaddress</ovf:Description>
</ovf:Property>
<ovf:Property ovf:value="cussl01s01c01alun088bal,cussl01s01c01alun089bal" ovf:type="String" ovf:key="datastores">
<ovf:Label>Datastore Name</ovf:Label>
<ovf:Description>Datastore Name</ovf:Description>
</ovf:Property>
<!-- **** capacity unit : bytes *** -->
<ovf:Property ovf:value="[Totalcapacity=1335915184128,UsedCapacity=549755813888]" ovf:type="String"
ovf:key="cussl01s01c01alun088bal">
<ovf:Label>Datastore Capacity</ovf:Label>
<ovf:Description>Datastore cussl01s01c01alun088bal Total Capacity, Used Capacity in comma separated
</ovf:Description>
</ovf:Property>
<ovf:Property ovf:value="[Totalcapacity=1335915184129,UsedCapacity=549755813889]" ovf:type="String"
ovf:key="cussl01s01c01alun089bal">
<ovf:Label>Datastore Capacity</ovf:Label>
<ovf:Description>Datastore cussl01s01c01alun089bal Total Capacity, Used Capacity in comma separated
</ovf:Description>
</ovf:Property>
<ovf:Property ovf:value="[name=3282176-1949-bal-tier01,ip=0.0.0.0,mac=00:50:56:8c:3f:3c]" ovf:type="String"
ovf:key="customerPortprofile">
<ovf:Label>customerPortprofile</ovf:Label>
<ovf:Description>customerPortprofile</ovf:Description>
</ovf:Property>
<ovf:Property ovf:value="[name=vm-server-mgmt,ip=0.0.0.0,mac=00:50:56:8c:39:75]" ovf:type="String"
ovf:key="savvisPortprofile">
<ovf:Label>savvisPortprofile</ovf:Label>
<ovf:Description>savvisPortprofile</ovf:Description>
</ovf:Property>
</ovf:ProductSection>

View File

@ -59,5 +59,6 @@
<module>openhosting-east1</module> <module>openhosting-east1</module>
<module>serverlove-z1-man</module> <module>serverlove-z1-man</module>
<module>skalicloud-sdg-my</module> <module>skalicloud-sdg-my</module>
<module>savvis-symphonyvpdc</module>
</modules> </modules>
</project> </project>

View File

@ -56,7 +56,7 @@
<test.savvis-symphonyvpdc.apiversion>0.8</test.savvis-symphonyvpdc.apiversion> <test.savvis-symphonyvpdc.apiversion>0.8</test.savvis-symphonyvpdc.apiversion>
<test.savvis-symphonyvpdc.identity>FIXME</test.savvis-symphonyvpdc.identity> <test.savvis-symphonyvpdc.identity>FIXME</test.savvis-symphonyvpdc.identity>
<test.savvis-symphonyvpdc.credential>FIXME</test.savvis-symphonyvpdc.credential> <test.savvis-symphonyvpdc.credential>FIXME</test.savvis-symphonyvpdc.credential>
<test.savvis-symphonyvpdc.email>FIXME</test.savvis-symphonyvpdc.email> <test.savvis-symphonyvpdc.vpdc-email>FIXME</test.savvis-symphonyvpdc.vpdc-email>
<test.savvis-symphonyvpdc.loginUser>FIXME</test.savvis-symphonyvpdc.loginUser> <test.savvis-symphonyvpdc.loginUser>FIXME</test.savvis-symphonyvpdc.loginUser>
<test.savvis-symphonyvpdc.loginPassword>FIXME</test.savvis-symphonyvpdc.loginPassword> <test.savvis-symphonyvpdc.loginPassword>FIXME</test.savvis-symphonyvpdc.loginPassword>
</properties> </properties>
@ -143,8 +143,8 @@
<value>${test.savvis-symphonyvpdc.credential}</value> <value>${test.savvis-symphonyvpdc.credential}</value>
</property> </property>
<property> <property>
<name>test.savvis-symphonyvpdc.email</name> <name>savvis-symphonyvpdc.vpdc-email</name>
<value>${test.savvis-symphonyvpdc.email}</value> <value>${test.savvis-symphonyvpdc.vdc-email}</value>
</property> </property>
<property> <property>
<name>test.savvis-symphonyvpdc.loginUser</name> <name>test.savvis-symphonyvpdc.loginUser</name>

View File

@ -26,6 +26,7 @@ import org.jclouds.rest.annotations.Delegate;
import org.jclouds.savvis.vpdc.domain.Resource; import org.jclouds.savvis.vpdc.domain.Resource;
import org.jclouds.savvis.vpdc.features.BrowsingAsyncClient; import org.jclouds.savvis.vpdc.features.BrowsingAsyncClient;
import org.jclouds.savvis.vpdc.features.FirewallAsyncClient; 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.features.VMAsyncClient;
import org.jclouds.savvis.vpdc.internal.Org; import org.jclouds.savvis.vpdc.internal.Org;
@ -60,6 +61,12 @@ public interface VPDCAsyncClient {
FirewallAsyncClient getFirewallClient(); 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. * @return a listing of all orgs that the current user has access to.
*/ */
@ -68,8 +75,8 @@ public interface VPDCAsyncClient {
Set<Resource> listOrgs(); Set<Resource> listOrgs();
/** /**
* predefined by default in the classpath resource * predefined by default in the classpath resource {@code
* {@code /savvis-symphonyvpdc/predefined_operatingsystems.json} * /savvis-symphonyvpdc/predefined_operatingsystems.json}
* *
* @return the operating systems that are predefined in the provider * @return the operating systems that are predefined in the provider
* @see <a href="https://api.sandbox.symphonyvpdc.savvis.net/doc/spec/api/addSingleVM.html" /> * @see <a href="https://api.sandbox.symphonyvpdc.savvis.net/doc/spec/api/addSingleVM.html" />

View File

@ -28,6 +28,7 @@ import org.jclouds.rest.annotations.Delegate;
import org.jclouds.savvis.vpdc.domain.Resource; import org.jclouds.savvis.vpdc.domain.Resource;
import org.jclouds.savvis.vpdc.features.BrowsingClient; import org.jclouds.savvis.vpdc.features.BrowsingClient;
import org.jclouds.savvis.vpdc.features.FirewallClient; import org.jclouds.savvis.vpdc.features.FirewallClient;
import org.jclouds.savvis.vpdc.features.ServiceManagementClient;
import org.jclouds.savvis.vpdc.features.VMClient; import org.jclouds.savvis.vpdc.features.VMClient;
/** /**
@ -59,6 +60,12 @@ public interface VPDCClient {
@Delegate @Delegate
FirewallClient getFirewallClient(); 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. * @return a listing of all orgs that the current user has access to.

View File

@ -23,6 +23,7 @@ import java.util.List;
import java.util.Properties; import java.util.Properties;
import org.jclouds.compute.ComputeServiceContextBuilder; import org.jclouds.compute.ComputeServiceContextBuilder;
import org.jclouds.savvis.vpdc.compute.config.VPDCComputeServiceContextModule;
import org.jclouds.savvis.vpdc.config.VPDCRestClientModule; import org.jclouds.savvis.vpdc.config.VPDCRestClientModule;
import com.google.inject.Module; import com.google.inject.Module;
@ -41,4 +42,9 @@ public class VPDCContextBuilder extends ComputeServiceContextBuilder<VPDCClient,
modules.add(new VPDCRestClientModule()); modules.add(new VPDCRestClientModule());
} }
@Override
protected void addContextModule(List<Module> modules) {
modules.add(new VPDCComputeServiceContextModule());
}
} }

View File

@ -21,7 +21,7 @@ package org.jclouds.savvis.vpdc;
import static org.jclouds.Constants.PROPERTY_API_VERSION; import static org.jclouds.Constants.PROPERTY_API_VERSION;
import static org.jclouds.Constants.PROPERTY_ENDPOINT; 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; import java.util.Properties;
@ -38,7 +38,7 @@ public class VPDCPropertiesBuilder extends PropertiesBuilder {
Properties properties = super.defaultProperties(); Properties properties = super.defaultProperties();
properties.setProperty(PROPERTY_API_VERSION, "0.8"); properties.setProperty(PROPERTY_API_VERSION, "0.8");
properties.setProperty(PROPERTY_ENDPOINT, "https://api.symphonyvpdc.savvis.net/rest/api"); 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; return properties;
} }

View File

@ -0,0 +1,79 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.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<VPDCClient, VPDCAsyncClient, VM, VMSpec, CIMOperatingSystem, Network> {
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<ComputeServiceAdapter<VM, VMSpec, CIMOperatingSystem, Network>>() {
}).to(VPDCComputeServiceAdapter.class);
bind(new TypeLiteral<Function<VM, NodeMetadata>>() {
}).to(VMToNodeMetadata.class);
bind(new TypeLiteral<Function<CIMOperatingSystem, org.jclouds.compute.domain.Image>>() {
}).to(CIMOperatingSystemToImage.class);
bind(new TypeLiteral<Function<VMSpec, org.jclouds.compute.domain.Hardware>>() {
}).to(VMSpecToHardware.class);
bind(new TypeLiteral<Function<Network, Location>>() {
}).to(NetworkToLocation.class);
bind(new TypeLiteral<Supplier<Location>>() {
}).to(FirstNetwork.class);
}
}

View File

@ -0,0 +1,46 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.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<CIMOperatingSystem, Image> {
@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();
}
}

View File

@ -0,0 +1,90 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.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<Network, Location> {
// 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<String> isoCodes;
private VPDCClient client;
@Inject
public NetworkToLocation(@Iso3166 Set<String> 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);
}
}
}

View File

@ -0,0 +1,56 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.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<VMSpec, Hardware> {
@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<String, Integer> 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();
}
}

View File

@ -0,0 +1,106 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.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<VM, NodeMetadata> {
public static final Map<VM.Status, NodeState> VAPPSTATUS_TO_NODESTATE = ImmutableMap
.<VM.Status, NodeState> 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<String, Credentials> credentialStore;
@Inject
VMToNodeMetadata(Map<String, Credentials> 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<String> 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<VM, Location> {
@Inject
public FindLocationForVM(@Memoized Supplier<Set<? extends Location>> hardware) {
super(hardware);
}
@Override
public boolean matches(VM from, Location input) {
return input.getId().equals(Iterables.get(from.getNetworkSection().getNetworks(), 0).getName());
}
}
}

View File

@ -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<VM, VMSpec, CIMOperatingSystem, Network> {
private final VPDCClient client;
private final RetryablePredicate<String> 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<String>(checkNotNull(taskSuccess, "taskSuccess"), 650, 10,
TimeUnit.SECONDS);
this.email = email;
}
@Override
public VM createNodeWithGroupEncodedIntoNameThenStoreCredentials(String tag, String name, Template template,
Map<String, Credentials> 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<VMSpec> 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<CIMOperatingSystem> listImages() {
return client.listPredefinedOperatingSystems();
}
@Override
public Iterable<VM> listNodes() {
Builder<VM> builder = ImmutableSet.<VM> 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<Resource>() {
@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<Network> listLocations() {
Builder<Network> builder = ImmutableSet.<Network> 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());
}
}

View File

@ -0,0 +1,71 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.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<Location> {
@Singleton
public static final class IsNetwork implements Predicate<Location> {
@Override
public boolean apply(Location input) {
return input.getScope() == LocationScope.NETWORK;
}
@Override
public String toString() {
return "isNetwork()";
}
}
private final Supplier<Set<? extends Location>> locationsSupplier;
private final IsNetwork isNetwork;
@Inject
FirstNetwork(@Memoized Supplier<Set<? extends Location>> locationsSupplier, IsNetwork isNetwork) {
this.locationsSupplier = checkNotNull(locationsSupplier, "locationsSupplierSupplier");
this.isNetwork = checkNotNull(isNetwork, "isNetwork");
}
@Override
public Location get() {
return find(locationsSupplier.get(), isNetwork);
}
}

View File

@ -24,7 +24,7 @@ import static com.google.common.base.Preconditions.checkState;
import static com.google.common.base.Throwables.propagate; import static com.google.common.base.Throwables.propagate;
import static org.jclouds.Constants.PROPERTY_IDENTITY; import static org.jclouds.Constants.PROPERTY_IDENTITY;
import static org.jclouds.Constants.PROPERTY_SESSION_INTERVAL; 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.io.IOException;
import java.util.Map; 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.BrowsingClient;
import org.jclouds.savvis.vpdc.features.FirewallAsyncClient; import org.jclouds.savvis.vpdc.features.FirewallAsyncClient;
import org.jclouds.savvis.vpdc.features.FirewallClient; 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.VMAsyncClient;
import org.jclouds.savvis.vpdc.features.VMClient; import org.jclouds.savvis.vpdc.features.VMClient;
import org.jclouds.savvis.vpdc.handlers.VPDCErrorHandler; import org.jclouds.savvis.vpdc.handlers.VPDCErrorHandler;
@ -111,7 +113,7 @@ public class VPDCRestClientModule extends RestClientModule<VPDCClient, VPDCAsync
@Provides @Provides
@Singleton @Singleton
protected Predicate<String> successTester(Injector injector, protected Predicate<String> successTester(Injector injector,
@Named(PROPERTY_VCLOUD_TIMEOUT_TASK_COMPLETED) long completed) { @Named(PROPERTY_VPDC_TIMEOUT_TASK_COMPLETED) long completed) {
return new RetryablePredicate<String>(injector.getInstance(TaskSuccess.class), completed); return new RetryablePredicate<String>(injector.getInstance(TaskSuccess.class), completed);
} }
@ -119,6 +121,7 @@ public class VPDCRestClientModule extends RestClientModule<VPDCClient, VPDCAsync
.put(BrowsingClient.class, BrowsingAsyncClient.class)// .put(BrowsingClient.class, BrowsingAsyncClient.class)//
.put(VMClient.class, VMAsyncClient.class)// .put(VMClient.class, VMAsyncClient.class)//
.put(FirewallClient.class, FirewallAsyncClient.class)// .put(FirewallClient.class, FirewallAsyncClient.class)//
.put(ServiceManagementClient.class, ServiceManagementAsyncClient.class)//
.build(); .build();
public VPDCRestClientModule() { public VPDCRestClientModule() {

View File

@ -26,13 +26,13 @@ import java.net.URI;
* *
* @author Kedar Dave * @author Kedar Dave
*/ */
public class FirewallRule extends Resource { public class FirewallRule extends ResourceImpl {
public static Builder builder() { public static Builder builder() {
return new Builder(); return new Builder();
} }
public static class Builder extends Resource.Builder { public static class Builder extends ResourceImpl.Builder {
private String firewallType; private String firewallType;
private boolean isEnabled; private boolean isEnabled;

View File

@ -32,13 +32,13 @@ import com.google.common.collect.Sets;
* *
* @author Kedar Dave * @author Kedar Dave
*/ */
public class FirewallService extends Resource { public class FirewallService extends ResourceImpl {
public static Builder builder() { public static Builder builder() {
return new Builder(); return new Builder();
} }
public static class Builder extends Resource.Builder { public static class Builder extends ResourceImpl.Builder {
private boolean isEnabled; private boolean isEnabled;
private Set<FirewallRule> firewallRules = Sets.newLinkedHashSet(); private Set<FirewallRule> firewallRules = Sets.newLinkedHashSet();

View File

@ -8,7 +8,7 @@ import java.net.URI;
* @author Adrian Cole * @author Adrian Cole
* *
*/ */
public class Link extends Resource { public class Link extends ResourceImpl {
protected final String rel; protected final String rel;
public Link( String id,String name, String type, URI href, String rel) { public Link( String id,String name, String type, URI href, String rel) {

View File

@ -34,12 +34,12 @@ import com.google.common.collect.Maps;
* *
* @author Adrian Cole * @author Adrian Cole
*/ */
public class Network extends Resource { public class Network extends ResourceImpl {
public static Builder builder() { public static Builder builder() {
return new Builder(); return new Builder();
} }
public static class Builder extends Resource.Builder { public static class Builder extends ResourceImpl.Builder {
private String gateway; private String gateway;
private String netmask; private String netmask;
private Map<String, String> internalToExternalNATRules = Maps.newLinkedHashMap(); private Map<String, String> internalToExternalNATRules = Maps.newLinkedHashMap();
@ -70,7 +70,7 @@ public class Network extends Resource {
return new Network(id, name, type, href, gateway, netmask, internalToExternalNATRules); 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()) return new Builder().id(in.getId()).name(in.getName()).type(in.getType()).href(in.getHref())
.gateway(in.getGateway()).internalToExternalNATRules(in.getInternalToExternalNATRules()) .gateway(in.getGateway()).internalToExternalNATRules(in.getInternalToExternalNATRules())
.netmask(in.getNetmask()); .netmask(in.getNetmask());
@ -135,7 +135,7 @@ public class Network extends Resource {
@Override @Override
public Builder toBuilder() { public Builder toBuilder() {
return Builder.fromOrg(this); return Builder.fromNetwork(this);
} }
@Override @Override

View File

@ -0,0 +1,210 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.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<NetworkConfigSection> {
@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<NetworkConfigSection> {
private String network;
private String fenceMode;
private Boolean dhcp;
private String gateway;
private String netmask;
private Map<String, String> 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<String, String> 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<NetworkConfigSection> 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<String, String> internalToExternalNATRules;
public NetworkConfigSection(String info, String network, String fenceMode, Boolean dhcp, String gateway,
String netmask, Map<String, String> 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<String, String> 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);
}
}

View File

@ -0,0 +1,134 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.savvis.vpdc.domain;
import org.jclouds.ovf.Section;
/**
*
* @author Adrian Cole
*/
public class NetworkConnectionSection extends Section<NetworkConnectionSection> {
@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<NetworkConnectionSection> {
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<NetworkConnectionSection> 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);
}
}

View File

@ -46,12 +46,12 @@ import com.google.common.collect.Sets;
* *
* @author Adrian Cole * @author Adrian Cole
*/ */
public class Org extends Resource { public class Org extends ResourceImpl {
public static Builder builder() { public static Builder builder() {
return new Builder(); return new Builder();
} }
public static class Builder extends Resource.Builder { public static class Builder extends ResourceImpl.Builder {
private String description; private String description;
private Set<Link> vDCs = Sets.newLinkedHashSet(); private Set<Link> vDCs = Sets.newLinkedHashSet();
private Set<Link> images = Sets.newLinkedHashSet(); private Set<Link> images = Sets.newLinkedHashSet();

View File

@ -0,0 +1,42 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.savvis.vpdc.domain;
import java.net.URI;
/**
* Location of a Rest resource
*
* @author Adrian Cole
*
*/
public interface Resource extends Comparable<Resource> {
String getId();
String getName();
String getType();
URI getHref();
int compareTo(Resource that);
}

View File

@ -1,3 +1,22 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.savvis.vpdc.domain; package org.jclouds.savvis.vpdc.domain;
import java.net.URI; import java.net.URI;
@ -8,7 +27,7 @@ import java.net.URI;
* @author Adrian Cole * @author Adrian Cole
* *
*/ */
public class Resource { public class ResourceImpl implements Resource {
public static Builder builder() { public static Builder builder() {
return new Builder(); return new Builder();
} }
@ -39,11 +58,11 @@ public class Resource {
return this; return this;
} }
public Resource build() { public ResourceImpl build() {
return new Resource(id, name, type, href); 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()); 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 String type;
protected final URI href; 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.id = id;
this.name = name; this.name = name;
this.type = type; this.type = type;
@ -99,7 +118,7 @@ public class Resource {
return false; return false;
if (getClass() != obj.getClass()) if (getClass() != obj.getClass())
return false; return false;
Resource other = (Resource) obj; ResourceImpl other = (ResourceImpl) obj;
if (href == null) { if (href == null) {
if (other.href != null) if (other.href != null)
return false; return false;

View File

@ -14,12 +14,12 @@ import javax.annotation.Nullable;
* *
* @see <a href="https://api.sandbox.symphonyvpdc.savvis.net/doc/spec/api/getTask.html" /> * @see <a href="https://api.sandbox.symphonyvpdc.savvis.net/doc/spec/api/getTask.html" />
*/ */
public class Task extends Resource { public class Task extends ResourceImpl {
public static Builder builder() { public static Builder builder() {
return new Builder(); return new Builder();
} }
public static class Builder extends Resource.Builder { public static class Builder extends ResourceImpl.Builder {
private Status status; private Status status;
private Date startTime; private Date startTime;
private Date endTime; private Date endTime;

View File

@ -35,12 +35,12 @@ import com.google.common.collect.Sets;
* *
* @author Adrian Cole * @author Adrian Cole
*/ */
public class VDC extends Resource { public class VDC extends ResourceImpl {
public static Builder builder() { public static Builder builder() {
return new Builder(); return new Builder();
} }
public static class Builder extends Resource.Builder { public static class Builder extends ResourceImpl.Builder {
private String description; private String description;
private Status status; private Status status;
private Set<Resource> resourceEntities = Sets.newLinkedHashSet(); private Set<Resource> resourceEntities = Sets.newLinkedHashSet();

View File

@ -0,0 +1,377 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.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<VM> 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.
*
* <h2>NOTE</h2>
* <p/>
* 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<VM> {
protected String type;
protected URI href;
protected Status status;
protected NetworkSection networkSection;
protected Set<NetworkConfigSection> networkConfigSections = Sets.newLinkedHashSet();
protected Set<NetworkConnectionSection> 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<NetworkConfigSection> networkConfigSections) {
this.networkConfigSections = ImmutableSet.<NetworkConfigSection> 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<NetworkConnectionSection> networkConnectionSections) {
this.networkConnectionSections = ImmutableSet.<NetworkConnectionSection> 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<String, Section> additionalSections) {
return Builder.class.cast(super.additionalSections(additionalSections));
}
/**
* {@inheritDoc}
*/
@Override
public Builder fromSection(Section<VM> in) {
return Builder.class.cast(super.fromSection(in));
}
/**
* {@inheritDoc}
*/
@Override
public Builder fromVirtualSystem(BaseVirtualSystem<VM> 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<? extends VirtualHardwareSection> 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<? extends ProductSection> 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<NetworkConfigSection> networkConfigSections;
protected final Set<NetworkConnectionSection> networkConnectionSections;
@SuppressWarnings("unchecked")
public VM(String id, String info, String name, OperatingSystemSection operatingSystem,
Iterable<? extends VirtualHardwareSection> virtualHardwareSections,
Iterable<? extends ProductSection> productSections, Multimap<String, Section> additionalSections,
String type, URI href, Status status, NetworkSection networkSection,
Iterable<NetworkConfigSection> networkConfigSections,
Iterable<NetworkConnectionSection> 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<NetworkConfigSection> getNetworkConfigSections() {
return networkConfigSections;
}
public Set<NetworkConnectionSection> 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);
}
}

View File

@ -42,8 +42,7 @@ public class VMSpec {
public static class Builder { public static class Builder {
private CIMOperatingSystem operatingSystem; private CIMOperatingSystem operatingSystem;
// TODO docs suggest fractions are possible, but xml isn't accepted on add private int processorCount = 1;
private float processorCount = 1f;
private int memoryInGig = 1; private int memoryInGig = 1;
private String bootDeviceName = "/"; private String bootDeviceName = "/";
// TODO doesn't seem to be changeable // TODO doesn't seem to be changeable
@ -61,7 +60,7 @@ public class VMSpec {
return this; return this;
} }
public Builder processorCount(float processorCount) { public Builder processorCount(int processorCount) {
checkProcessorCount(processorCount); checkProcessorCount(processorCount);
this.processorCount = processorCount; this.processorCount = processorCount;
return this; 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 > 0, "processorCount must be positive and an increment of 0.5");
checkArgument(processorCount % .5 == 0, "processorCount must be an increment of 0.5"); checkArgument(processorCount % .5 == 0, "processorCount must be an increment of 0.5");
} }
private final CIMOperatingSystem operatingSystem; private final CIMOperatingSystem operatingSystem;
private final float processorCount; private final int processorCount;
private final int memoryInGig; private final int memoryInGig;
private final String bootDeviceName; private final String bootDeviceName;
private final int bootDriveSize; private final int bootDriveSize;
private final Map<String, Integer> dataDriveDeviceNameToSizeInGig; private final Map<String, Integer> dataDriveDeviceNameToSizeInGig;
protected VMSpec(CIMOperatingSystem operatingSystem, float processorCount, int memoryInGig, String bootDeviceName, protected VMSpec(CIMOperatingSystem operatingSystem, int processorCount, int memoryInGig, String bootDeviceName,
int bootDriveSize, Map<String, Integer> dataDriveDeviceNameToSizeInGig) { int bootDriveSize, Map<String, Integer> dataDriveDeviceNameToSizeInGig) {
this.operatingSystem = checkNotNull(operatingSystem, "operatingSystem not specified"); this.operatingSystem = checkNotNull(operatingSystem, "operatingSystem not specified");
checkProcessorCount(processorCount); checkProcessorCount(processorCount);
@ -133,7 +132,7 @@ public class VMSpec {
return operatingSystem; return operatingSystem;
} }
public float getProcessorCount() { public int getProcessorCount() {
return processorCount; return processorCount;
} }
@ -155,7 +154,7 @@ public class VMSpec {
+ ((dataDriveDeviceNameToSizeInGig == null) ? 0 : dataDriveDeviceNameToSizeInGig.hashCode()); + ((dataDriveDeviceNameToSizeInGig == null) ? 0 : dataDriveDeviceNameToSizeInGig.hashCode());
result = prime * result + memoryInGig; result = prime * result + memoryInGig;
result = prime * result + ((operatingSystem == null) ? 0 : operatingSystem.hashCode()); result = prime * result + ((operatingSystem == null) ? 0 : operatingSystem.hashCode());
result = prime * result + Float.floatToIntBits(processorCount); result = prime * result + processorCount;
return result; return result;
} }
@ -187,7 +186,7 @@ public class VMSpec {
return false; return false;
} else if (!operatingSystem.equals(other.operatingSystem)) } else if (!operatingSystem.equals(other.operatingSystem))
return false; return false;
if (Float.floatToIntBits(processorCount) != Float.floatToIntBits(other.processorCount)) if (processorCount != other.processorCount)
return false; return false;
return true; return true;
} }

View File

@ -19,12 +19,15 @@
package org.jclouds.savvis.vpdc.features; package org.jclouds.savvis.vpdc.features;
import java.net.URI;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import javax.ws.rs.GET; import javax.ws.rs.GET;
import javax.ws.rs.Path; import javax.ws.rs.Path;
import javax.ws.rs.PathParam; import javax.ws.rs.PathParam;
import org.jclouds.rest.annotations.BinderParam; import org.jclouds.rest.annotations.BinderParam;
import org.jclouds.rest.annotations.EndpointParam;
import org.jclouds.rest.annotations.ExceptionParser; import org.jclouds.rest.annotations.ExceptionParser;
import org.jclouds.rest.annotations.ParamParser; import org.jclouds.rest.annotations.ParamParser;
import org.jclouds.rest.annotations.RequestFilters; import org.jclouds.rest.annotations.RequestFilters;
@ -57,7 +60,6 @@ import com.google.common.util.concurrent.ListenableFuture;
* @author Adrian Cole * @author Adrian Cole
*/ */
@RequestFilters(SetVCloudTokenCookie.class) @RequestFilters(SetVCloudTokenCookie.class)
@Path("v{jclouds.api-version}")
public interface BrowsingAsyncClient { public interface BrowsingAsyncClient {
/** /**
@ -66,7 +68,7 @@ public interface BrowsingAsyncClient {
@GET @GET
@XMLResponseParser(OrgHandler.class) @XMLResponseParser(OrgHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class) @ExceptionParser(ReturnNullOnNotFoundOr404.class)
@Path("org/{billingSiteId}") @Path("v{jclouds.api-version}/org/{billingSiteId}")
ListenableFuture<Org> getOrg( ListenableFuture<Org> getOrg(
@PathParam("billingSiteId") @Nullable @ParamParser(DefaultOrgIfNull.class) String billingSiteId); @PathParam("billingSiteId") @Nullable @ParamParser(DefaultOrgIfNull.class) String billingSiteId);
@ -76,7 +78,7 @@ public interface BrowsingAsyncClient {
@GET @GET
@XMLResponseParser(VDCHandler.class) @XMLResponseParser(VDCHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class) @ExceptionParser(ReturnNullOnNotFoundOr404.class)
@Path("org/{billingSiteId}/vdc/{vpdcId}") @Path("v{jclouds.api-version}/org/{billingSiteId}/vdc/{vpdcId}")
ListenableFuture<VDC> getVDCInOrg( ListenableFuture<VDC> getVDCInOrg(
@PathParam("billingSiteId") @Nullable @ParamParser(DefaultOrgIfNull.class) String billingSiteId, @PathParam("billingSiteId") @Nullable @ParamParser(DefaultOrgIfNull.class) String billingSiteId,
@PathParam("vpdcId") String vpdcId); @PathParam("vpdcId") String vpdcId);
@ -87,7 +89,7 @@ public interface BrowsingAsyncClient {
@GET @GET
@XMLResponseParser(NetworkHandler.class) @XMLResponseParser(NetworkHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.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<Network> getNetworkInVDC( ListenableFuture<Network> getNetworkInVDC(
@PathParam("billingSiteId") @Nullable @ParamParser(DefaultOrgIfNull.class) String billingSiteId, @PathParam("billingSiteId") @Nullable @ParamParser(DefaultOrgIfNull.class) String billingSiteId,
@PathParam("vpdcId") String vpdcId, @PathParam("network-tier-name") String networkTierName); @PathParam("vpdcId") String vpdcId, @PathParam("network-tier-name") String networkTierName);
@ -98,19 +100,27 @@ public interface BrowsingAsyncClient {
@GET @GET
@XMLResponseParser(VMHandler.class) @XMLResponseParser(VMHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class) @ExceptionParser(ReturnNullOnNotFoundOr404.class)
@Path("org/{billingSiteId}/vdc/{vpdcId}/vApp/{vAppId}") @Path("v{jclouds.api-version}/org/{billingSiteId}/vdc/{vpdcId}/vApp/{vAppId}")
ListenableFuture<VM> getVMInVDC( ListenableFuture<VM> 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, @PathParam("vpdcId") String vpdcId, @PathParam("vAppId") String vAppId,
@BinderParam(BindGetVMOptions.class) GetVMOptions... options); @BinderParam(BindGetVMOptions.class) GetVMOptions... options);
/**
* @see BrowsingClient#getVM
*/
@GET
@XMLResponseParser(VMHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<VM> getVM(@EndpointParam URI vm, @BinderParam(BindGetVMOptions.class) GetVMOptions... options);
/** /**
* @see BrowsingClient#getTask * @see BrowsingClient#getTask
*/ */
@GET @GET
@XMLResponseParser(TaskHandler.class) @XMLResponseParser(TaskHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class) @ExceptionParser(ReturnNullOnNotFoundOr404.class)
@Path("task/{taskId}") @Path("v{jclouds.api-version}/task/{taskId}")
ListenableFuture<Task> getTask(@PathParam("taskId") String taskId); ListenableFuture<Task> getTask(@PathParam("taskId") String taskId);
/** /**
@ -119,8 +129,9 @@ public interface BrowsingAsyncClient {
@GET @GET
@XMLResponseParser(FirewallServiceHandler.class) @XMLResponseParser(FirewallServiceHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class) @ExceptionParser(ReturnNullOnNotFoundOr404.class)
@Path("org/{billingSiteId}/vdc/{vpdcId}/FirewallService") @Path("v{jclouds.api-version}/org/{billingSiteId}/vdc/{vpdcId}/FirewallService")
ListenableFuture<FirewallService> listFirewallRules(@PathParam("billingSiteId") @Nullable @ParamParser(DefaultOrgIfNull.class) String billingSiteId, ListenableFuture<FirewallService> listFirewallRules(
@PathParam("billingSiteId") @Nullable @ParamParser(DefaultOrgIfNull.class) String billingSiteId,
@PathParam("vpdcId") String vpdcId); @PathParam("vpdcId") String vpdcId);
} }

View File

@ -19,6 +19,7 @@
package org.jclouds.savvis.vpdc.features; package org.jclouds.savvis.vpdc.features;
import java.net.URI;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import javax.annotation.Nullable; 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.Network;
import org.jclouds.savvis.vpdc.domain.Org; import org.jclouds.savvis.vpdc.domain.Org;
import org.jclouds.savvis.vpdc.domain.Task; 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.VDC;
import org.jclouds.savvis.vpdc.domain.VM;
import org.jclouds.savvis.vpdc.options.GetVMOptions; 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 getVMInVDC(String billingSiteId, String vpdcId, String vAppId, GetVMOptions... options);
VM getVM(URI vm, GetVMOptions... options);
/** /**
* Gets an existing task. * Gets an existing task.
* *
* @param taskId * @param taskId
* task id * task id
* @return If the request is successful, caller could get the VM/VMDK details as specified in * @return If the request is successful, caller could get the VM/VMDK details as specified in the
* the result element and if the request is not successful, caller would get empty * result element and if the request is not successful, caller would get empty VAPP/VMDK
* VAPP/VMDK URL and respective validation (error) message. * URL and respective validation (error) message.
*/ */
Task getTask(String taskId); Task getTask(String taskId);
@ -115,8 +118,8 @@ public interface BrowsingClient {
* vpdc Id * vpdc Id
* *
* @return If the request is successful, caller could get the firewall rules as specified in the * @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 * result element and if the request is not successful, caller would get empty rules list
* rules list and respective validation (error) message. * and respective validation (error) message.
*/ */
FirewallService listFirewallRules(String billingSiteId, String vpdcId); FirewallService listFirewallRules(String billingSiteId, String vpdcId);

View File

@ -0,0 +1,86 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.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.
* <p/>
*
* @see <a href="https://api.sandbox.symphonyvpdc.savvis.net/doc/spec/api/index.html" />
* @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<Task> 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<Task> 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<Task> 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<Task> powerOffVM(@EndpointParam URI vm);
}

View File

@ -0,0 +1,87 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.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.
* <p/>
*
* @see <a href="https://api.sandbox.symphonyvpdc.savvis.net/doc/spec/api/" />
* @author Adrian Cole
*/
@Timeout(duration = 300, timeUnit = TimeUnit.SECONDS)
public interface ServiceManagementClient {
/**
* Powers on the VM
* <p/>
* <h4>Pre-conditions:</h4>
* <p/>
* 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
* <p/>
* <h4>Pre-conditions:</h4>
* <p/>
* 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);
}

View File

@ -19,12 +19,15 @@
package org.jclouds.savvis.vpdc.features; package org.jclouds.savvis.vpdc.features;
import java.net.URI;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import javax.ws.rs.DELETE; import javax.ws.rs.DELETE;
import javax.ws.rs.GET; import javax.ws.rs.GET;
import javax.ws.rs.Path; import javax.ws.rs.Path;
import javax.ws.rs.PathParam; import javax.ws.rs.PathParam;
import org.jclouds.rest.annotations.EndpointParam;
import org.jclouds.rest.annotations.ExceptionParser; import org.jclouds.rest.annotations.ExceptionParser;
import org.jclouds.rest.annotations.MapBinder; import org.jclouds.rest.annotations.MapBinder;
import org.jclouds.rest.annotations.ParamParser; import org.jclouds.rest.annotations.ParamParser;
@ -49,7 +52,6 @@ import com.google.common.util.concurrent.ListenableFuture;
* @author Adrian Cole * @author Adrian Cole
*/ */
@RequestFilters(SetVCloudTokenCookie.class) @RequestFilters(SetVCloudTokenCookie.class)
@Path("v{jclouds.api-version}")
public interface VMAsyncClient { public interface VMAsyncClient {
/** /**
@ -57,7 +59,7 @@ public interface VMAsyncClient {
*/ */
@GET @GET
@XMLResponseParser(TaskHandler.class) @XMLResponseParser(TaskHandler.class)
@Path("org/{billingSiteId}/vdc/{vpdcId}/vApp/") @Path("v{jclouds.api-version}/org/{billingSiteId}/vdc/{vpdcId}/vApp/")
@MapBinder(BindVMSpecToXmlPayload.class) @MapBinder(BindVMSpecToXmlPayload.class)
ListenableFuture<Task> addVMIntoVDC( ListenableFuture<Task> addVMIntoVDC(
@PathParam("billingSiteId") @Nullable @ParamParser(DefaultOrgIfNull.class) String billingSiteId, @PathParam("billingSiteId") @Nullable @ParamParser(DefaultOrgIfNull.class) String billingSiteId,
@ -69,10 +71,17 @@ public interface VMAsyncClient {
*/ */
@DELETE @DELETE
@XMLResponseParser(TaskHandler.class) @XMLResponseParser(TaskHandler.class)
@Path("org/{billingSiteId}/vdc/{vpdcId}/vApp/{vAppId}") @Path("v{jclouds.api-version}/org/{billingSiteId}/vdc/{vpdcId}/vApp/{vAppId}")
@ExceptionParser(ReturnNullOnNotFoundOr404.class) @ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<Task> removeVMFromVDC( ListenableFuture<Task> removeVMFromVDC(
@PathParam("billingSiteId") @Nullable @ParamParser(DefaultOrgIfNull.class) String billingSiteId, @PathParam("billingSiteId") @Nullable @ParamParser(DefaultOrgIfNull.class) String billingSiteId,
@PathParam("vpdcId") String vpdcId, @PathParam("vAppId") String vAppId); @PathParam("vpdcId") String vpdcId, @PathParam("vAppId") String vAppId);
/**
* @see VMClient#removeVM
*/
@DELETE
@XMLResponseParser(TaskHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<Task> removeVM(@EndpointParam URI vm);
} }

View File

@ -19,6 +19,7 @@
package org.jclouds.savvis.vpdc.features; package org.jclouds.savvis.vpdc.features;
import java.net.URI;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import org.jclouds.concurrent.Timeout; import org.jclouds.concurrent.Timeout;
@ -63,10 +64,22 @@ public interface VMClient {
* </ul> * </ul>
* *
* @param billingSiteId * @param billingSiteId
* billing site Id, or null for default
* @param vpdcId * @param vpdcId
* @param vAppId * vpdc Id
* @return * @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);
/**
*
* Remove a VM
*
* @param vm
* href of the vm
* @see #removeVMFromVDC
*/
Task removeVM(URI vm);
} }

View File

@ -24,18 +24,13 @@ package org.jclouds.savvis.vpdc.reference;
* *
* @author Adrian Cole * @author Adrian Cole
*/ */
public interface VCloudConstants { public interface VPDCConstants {
public static final String PROPERTY_VCLOUD_VERSION_SCHEMA = "jclouds.vcloud.version.schema";
/** /**
* 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_VPDC_VDC_EMAIL = "savvis-symphonyvpdc.vdc-email";
public static final String PROPERTY_VCLOUD_DEFAULT_FENCEMODE = "jclouds.vcloud.defaults.fencemode";
public static final String PROPERTY_VCLOUD_XML_NAMESPACE = "jclouds.vcloud.xml.ns"; public static final String PROPERTY_VPDC_TIMEOUT_TASK_COMPLETED = "jclouds.vpdc.timeout.task-complete";
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";
} }

View File

@ -19,14 +19,26 @@
package org.jclouds.savvis.vpdc.util; 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.net.URI;
import java.util.Map; import java.util.Map;
import java.util.Set;
import org.jclouds.savvis.vpdc.domain.Link; 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.Resource;
import org.jclouds.savvis.vpdc.domain.ResourceImpl;
import org.jclouds.savvis.vpdc.domain.VM;
import org.xml.sax.Attributes; import org.xml.sax.Attributes;
import com.google.common.base.Function;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableMap.Builder; import com.google.common.collect.ImmutableMap.Builder;
/** /**
@ -46,8 +58,27 @@ public class Utils {
id = uri.substring(uri.lastIndexOf('/') + 1); id = uri.substring(uri.lastIndexOf('/') + 1);
} }
return (attributes.containsKey("rel")) ? new Link(id, attributes.get("name"), type != null ? type : defaultType, 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, attributes.get("rel")) : new ResourceImpl(id, attributes.get("name"), type != null ? type
href); : defaultType, href);
}
public static Set<String> getIpsFromVM(VM vm) {
Iterable<String> ipFromConnections = transform(vm.getNetworkConnectionSections(),
new Function<NetworkConnectionSection, String>() {
@Override
public String apply(NetworkConnectionSection input) {
return input.getIpAddress();
};
});
Iterable<String> ipsFromNat = concat(transform(vm.getNetworkConfigSections(),
new Function<NetworkConfigSection, Iterable<String>>() {
@Override
public Iterable<String> apply(NetworkConfigSection input) {
return concat(input.getInternalToExternalNATRules().keySet(), input
.getInternalToExternalNATRules().values());
};
}));
return ImmutableSet.copyOf(filter(concat(ipFromConnections, ipsFromNat), notNull()));
} }
public static Map<String, String> cleanseAttributes(Attributes in) { public static Map<String, String> cleanseAttributes(Attributes in) {

View File

@ -0,0 +1,65 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.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<NetworkConfigSection, NetworkConfigSection.Builder> {
@Inject
public NetworkConfigSectionHandler(Provider<NetworkConfigSection.Builder> builderProvider) {
super(builderProvider);
}
public void startElement(String uri, String localName, String qName, Attributes attrs) {
Map<String, String> 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);
}
}

View File

@ -0,0 +1,60 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.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<NetworkConnectionSection, NetworkConnectionSection.Builder> {
@Inject
public NetworkConnectionSectionHandler(Provider<NetworkConnectionSection.Builder> builderProvider) {
super(builderProvider);
}
public void startElement(String uri, String localName, String qName, Attributes attrs) {
Map<String, String> 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);
}
}

View File

@ -0,0 +1,69 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.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<NetworkSection, NetworkSection.Builder> {
protected Network.Builder networkBuilder = Network.builder();
@Inject
public NetworkSectionHandler(Provider<NetworkSection.Builder> builderProvider) {
super(builderProvider);
}
public void startElement(String uri, String localName, String qName, Attributes attrs) {
Map<String, String> 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);
}
}

View File

@ -0,0 +1,94 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.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<VM, VM.Builder> {
@SuppressWarnings("unchecked")
@Inject
public VMHandler(Provider<VM.Builder> builderProvider, OperatingSystemSectionHandler osHandler,
VirtualHardwareSectionHandler hardwareHandler, ProductSectionHandler productHandler,
Provider<NetworkSectionHandler> networkSectionHandler,
Provider<NetworkConfigSectionHandler> networkConfigSectionHandler,
Provider<NetworkConnectionSectionHandler> networkConnectionSectionHandler) {
super(builderProvider, osHandler, hardwareHandler, productHandler);
this.extensionHandlers = ImmutableMap.<String, Provider<? extends SectionHandler>> of("ovf:NetworkSection",
networkSectionHandler, "vApp:NetworkConfigSectionType", networkConfigSectionHandler,
"vApp:NetworkConnectionType", networkConnectionSectionHandler);
}
public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
Map<String, String> 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.<String, String> 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);
}
}
}

View File

@ -0,0 +1,94 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.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<OsFamilyVersion64Bit> defineUnsupportedOperatingSystems() {
return new Predicate<OsFamilyVersion64Bit>() {
@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<String> getIso3166Codes() {
// TODO make region aware
return ImmutableSet.<String> 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;
}
}

View File

@ -38,10 +38,12 @@ import org.jclouds.savvis.vpdc.VPDCAsyncClient;
import org.jclouds.savvis.vpdc.VPDCClient; import org.jclouds.savvis.vpdc.VPDCClient;
import org.jclouds.savvis.vpdc.config.VPDCRestClientModule; import org.jclouds.savvis.vpdc.config.VPDCRestClientModule;
import org.jclouds.savvis.vpdc.domain.Resource; 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.domain.internal.VCloudSession;
import org.jclouds.savvis.vpdc.filters.SetVCloudTokenCookie; import org.jclouds.savvis.vpdc.filters.SetVCloudTokenCookie;
import org.jclouds.savvis.vpdc.internal.LoginAsyncClient; import org.jclouds.savvis.vpdc.internal.LoginAsyncClient;
import org.jclouds.savvis.vpdc.reference.VCloudMediaType; 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.Supplier;
import com.google.common.base.Suppliers; import com.google.common.base.Suppliers;
@ -81,7 +83,7 @@ public abstract class BaseVPDCAsyncClientTest<T> extends RestClientTest<T> {
@Override @Override
public Set<Resource> getOrgs() { public Set<Resource> getOrgs() {
return ImmutableSet.of(new Resource("1", "org", VCloudMediaType.ORG_XML, URI return ImmutableSet.<Resource> of(new ResourceImpl("1", "org", VCloudMediaType.ORG_XML, URI
.create("https://api.symphonyvpdc.savvis.net/rest/api/v0.8/org/1"))); .create("https://api.symphonyvpdc.savvis.net/rest/api/v0.8/org/1")));
} }
@ -96,4 +98,11 @@ public abstract class BaseVPDCAsyncClientTest<T> extends RestClientTest<T> {
} }
@Override
protected Properties getProperties() {
Properties props = super.getProperties();
props.setProperty(VPDCConstants.PROPERTY_VPDC_VDC_EMAIL, "test");
return props;
}
} }

View File

@ -22,22 +22,24 @@ package org.jclouds.savvis.vpdc.features;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import java.util.Properties; 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.logging.log4j.config.Log4JLoggingModule;
import org.jclouds.predicates.RetryablePredicate;
import org.jclouds.rest.RestContext; import org.jclouds.rest.RestContext;
import org.jclouds.rest.RestContextFactory;
import org.jclouds.savvis.vpdc.VPDCAsyncClient; import org.jclouds.savvis.vpdc.VPDCAsyncClient;
import org.jclouds.savvis.vpdc.VPDCClient; 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.jclouds.ssh.jsch.config.JschSshClientModule;
import org.testng.annotations.AfterGroups; import org.testng.annotations.AfterGroups;
import org.testng.annotations.BeforeGroups; import org.testng.annotations.BeforeGroups;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.common.collect.ImmutableSet; 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.Module;
import com.google.inject.TypeLiteral;
/** /**
* Tests behavior of {@code VPDCClient} * Tests behavior of {@code VPDCClient}
@ -47,18 +49,23 @@ import com.google.inject.TypeLiteral;
@Test(groups = "live") @Test(groups = "live")
public class BaseVPDCClientLiveTest { public class BaseVPDCClientLiveTest {
protected RestContext<VPDCClient, VPDCAsyncClient> context; protected RestContext<VPDCClient, VPDCAsyncClient> restContext;
protected String provider = "savvis-symphonyvpdc"; protected String provider = "savvis-symphonyvpdc";
protected String identity; protected String identity;
protected String credential; protected String credential;
protected String endpoint; protected String endpoint;
protected String apiversion; protected String apiversion;
protected Injector injector; protected ComputeServiceContext context;
protected String email;
protected RetryablePredicate<String> taskTester;
protected String prefix = System.getProperty("user.name");
protected void setupCredentials() { protected void setupCredentials() {
identity = checkNotNull(System.getProperty("test." + provider + ".identity"), "test." + provider + ".identity"); identity = checkNotNull(System.getProperty("test." + provider + ".identity"), "test." + provider + ".identity");
credential = checkNotNull(System.getProperty("test." + provider + ".credential"), "test." + provider 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"); endpoint = System.getProperty("test." + provider + ".endpoint");
apiversion = System.getProperty("test." + provider + ".apiversion"); apiversion = System.getProperty("test." + provider + ".apiversion");
} }
@ -67,6 +74,7 @@ public class BaseVPDCClientLiveTest {
Properties overrides = new Properties(); Properties overrides = new Properties();
overrides.setProperty(provider + ".identity", identity); overrides.setProperty(provider + ".identity", identity);
overrides.setProperty(provider + ".credential", credential); overrides.setProperty(provider + ".credential", credential);
overrides.setProperty(VPDCConstants.PROPERTY_VPDC_VDC_EMAIL, email);
if (endpoint != null) if (endpoint != null)
overrides.setProperty(provider + ".endpoint", endpoint); overrides.setProperty(provider + ".endpoint", endpoint);
if (apiversion != null) if (apiversion != null)
@ -78,13 +86,10 @@ public class BaseVPDCClientLiveTest {
public void setupClient() { public void setupClient() {
setupCredentials(); setupCredentials();
Properties overrides = setupProperties(); Properties overrides = setupProperties();
// context = new RestContextFactory().createContext(provider, ImmutableSet.<Module> of(new context = new ComputeServiceContextFactory().createContext(provider, ImmutableSet.<Module> of(
// Log4JLoggingModule()), new Log4JLoggingModule(), new JschSshClientModule()), overrides);
// overrides); restContext = context.getProviderSpecificContext();
injector = new RestContextFactory().createContextBuilder(provider, taskTester = new RetryablePredicate<String>(new TaskSuccess(restContext.getApi()), 650, 10, TimeUnit.SECONDS);
ImmutableSet.<Module> of(new Log4JLoggingModule(), new JschSshClientModule()), overrides).buildInjector();
context = injector.getInstance(Key.get(new TypeLiteral<RestContext<VPDCClient, VPDCAsyncClient>>() {
}));
} }
@AfterGroups(groups = "live") @AfterGroups(groups = "live")

View File

@ -21,6 +21,7 @@ package org.jclouds.savvis.vpdc.features;
import java.io.IOException; import java.io.IOException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.net.URI;
import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpRequest;
import org.jclouds.http.functions.ParseSax; import org.jclouds.http.functions.ParseSax;
@ -106,8 +107,7 @@ public class BrowsingAsyncClientTest extends BaseVPDCAsyncClientTest<BrowsingAsy
} }
public void testNetwork() throws SecurityException, NoSuchMethodException, IOException { public void testNetwork() throws SecurityException, NoSuchMethodException, IOException {
Method method = BrowsingAsyncClient.class.getMethod("getNetworkInVDC", String.class, String.class, Method method = BrowsingAsyncClient.class.getMethod("getNetworkInVDC", String.class, String.class, String.class);
String.class);
HttpRequest request = processor.createRequest(method, "11", "22", "VM-Tier01"); HttpRequest request = processor.createRequest(method, "11", "22", "VM-Tier01");
assertRequestLineEquals(request, assertRequestLineEquals(request,
@ -123,8 +123,7 @@ public class BrowsingAsyncClientTest extends BaseVPDCAsyncClientTest<BrowsingAsy
} }
public void testNetworkWhenOrgNull() throws SecurityException, NoSuchMethodException, IOException { public void testNetworkWhenOrgNull() throws SecurityException, NoSuchMethodException, IOException {
Method method = BrowsingAsyncClient.class.getMethod("getNetworkInVDC", String.class, String.class, Method method = BrowsingAsyncClient.class.getMethod("getNetworkInVDC", String.class, String.class, String.class);
String.class);
HttpRequest request = processor.createRequest(method, (String) null, "22", "VM-Tier01"); HttpRequest request = processor.createRequest(method, (String) null, "22", "VM-Tier01");
assertRequestLineEquals(request, assertRequestLineEquals(request,
@ -139,13 +138,30 @@ public class BrowsingAsyncClientTest extends BaseVPDCAsyncClientTest<BrowsingAsy
checkFilters(request); checkFilters(request);
} }
public void testVM() throws SecurityException, NoSuchMethodException, IOException { public void testVMVDC() throws SecurityException, NoSuchMethodException, IOException {
Method method = BrowsingAsyncClient.class.getMethod("getVMInVDC", String.class, String.class, Method method = BrowsingAsyncClient.class.getMethod("getVMInVDC", String.class, String.class, String.class,
String.class, GetVMOptions[].class); GetVMOptions[].class);
HttpRequest request = processor.createRequest(method, "11", "22", "VM-Tier01"); HttpRequest request = processor.createRequest(method, "11", "22", "33");
assertRequestLineEquals(request, assertRequestLineEquals(request,
"GET https://api.symphonyvpdc.savvis.net/rest/api/v0.8/org/11/vdc/22/vApp/VM-Tier01 HTTP/1.1"); "GET 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, VMHandler.class);
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
checkFilters(request);
}
public void testVM() throws SecurityException, NoSuchMethodException, IOException {
Method method = BrowsingAsyncClient.class.getMethod("getVM", URI.class, GetVMOptions[].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,
"GET https://api.symphonyvpdc.savvis.net/rest/api/v0.8/org/11/vdc/22/vApp/33 HTTP/1.1");
assertNonPayloadHeadersEqual(request, ""); assertNonPayloadHeadersEqual(request, "");
assertPayloadEquals(request, null, null, false); assertPayloadEquals(request, null, null, false);
@ -157,8 +173,8 @@ public class BrowsingAsyncClientTest extends BaseVPDCAsyncClientTest<BrowsingAsy
} }
public void testVMWithPowerState() throws SecurityException, NoSuchMethodException, IOException { public void testVMWithPowerState() throws SecurityException, NoSuchMethodException, IOException {
Method method = BrowsingAsyncClient.class.getMethod("getVMInVDC", String.class, String.class, Method method = BrowsingAsyncClient.class.getMethod("getVMInVDC", String.class, String.class, String.class,
String.class, GetVMOptions[].class); GetVMOptions[].class);
HttpRequest request = processor.createRequest(method, "11", "22", "VM-Tier01", GetVMOptions.Builder HttpRequest request = processor.createRequest(method, "11", "22", "VM-Tier01", GetVMOptions.Builder
.withPowerState()); .withPowerState());
@ -175,8 +191,8 @@ public class BrowsingAsyncClientTest extends BaseVPDCAsyncClientTest<BrowsingAsy
} }
public void testVMWhenOrgNull() throws SecurityException, NoSuchMethodException, IOException { public void testVMWhenOrgNull() throws SecurityException, NoSuchMethodException, IOException {
Method method = BrowsingAsyncClient.class.getMethod("getVMInVDC", String.class, String.class, Method method = BrowsingAsyncClient.class.getMethod("getVMInVDC", String.class, String.class, String.class,
String.class, GetVMOptions[].class); GetVMOptions[].class);
HttpRequest request = processor.createRequest(method, (String) null, "22", "VM-Tier01"); HttpRequest request = processor.createRequest(method, (String) null, "22", "VM-Tier01");
assertRequestLineEquals(request, assertRequestLineEquals(request,

View File

@ -29,16 +29,19 @@ import java.util.Set;
import org.jclouds.savvis.vpdc.domain.FirewallRule; import org.jclouds.savvis.vpdc.domain.FirewallRule;
import org.jclouds.savvis.vpdc.domain.FirewallService; import org.jclouds.savvis.vpdc.domain.FirewallService;
import org.jclouds.savvis.vpdc.domain.Network; 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.Org;
import org.jclouds.savvis.vpdc.domain.Resource; 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.VDC;
import org.jclouds.savvis.vpdc.domain.VM;
import org.jclouds.savvis.vpdc.reference.VCloudMediaType; import org.jclouds.savvis.vpdc.reference.VCloudMediaType;
import org.jclouds.util.InetAddresses2;
import org.testng.annotations.BeforeGroups; import org.testng.annotations.BeforeGroups;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.common.base.Predicate; import com.google.common.base.Predicate;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
import com.google.common.net.HostSpecifier;
@Test(groups = "live") @Test(groups = "live")
public class BrowsingClientLiveTest extends BaseVPDCClientLiveTest { public class BrowsingClientLiveTest extends BaseVPDCClientLiveTest {
@ -49,12 +52,12 @@ public class BrowsingClientLiveTest extends BaseVPDCClientLiveTest {
@BeforeGroups(groups = { "live" }) @BeforeGroups(groups = { "live" })
public void setupClient() { public void setupClient() {
super.setupClient(); super.setupClient();
client = context.getApi().getBrowsingClient(); client = restContext.getApi().getBrowsingClient();
} }
@Test @Test
public void testOrg() throws Exception { public void testOrg() throws Exception {
for (Resource org : context.getApi().listOrgs()) { for (Resource org : restContext.getApi().listOrgs()) {
Org response = client.getOrg(org.getId()); Org response = client.getOrg(org.getId());
assertNotNull(response); assertNotNull(response);
@ -72,7 +75,7 @@ public class BrowsingClientLiveTest extends BaseVPDCClientLiveTest {
@Test @Test
public void testVDC() throws Exception { public void testVDC() throws Exception {
for (Resource org1 : context.getApi().listOrgs()) { for (Resource org1 : restContext.getApi().listOrgs()) {
Org org = client.getOrg(org1.getId()); Org org = client.getOrg(org1.getId());
for (Resource vdc : org.getVDCs()) { for (Resource vdc : org.getVDCs()) {
VDC response = client.getVDCInOrg(org.getId(), vdc.getId()); VDC response = client.getVDCInOrg(org.getId(), vdc.getId());
@ -92,7 +95,7 @@ public class BrowsingClientLiveTest extends BaseVPDCClientLiveTest {
@Test @Test
public void testNetwork() throws Exception { public void testNetwork() throws Exception {
for (Resource org1 : context.getApi().listOrgs()) { for (Resource org1 : restContext.getApi().listOrgs()) {
Org org = client.getOrg(org1.getId()); Org org = client.getOrg(org1.getId());
for (Resource vdc : org.getVDCs()) { for (Resource vdc : org.getVDCs()) {
VDC VDC = client.getVDCInOrg(org.getId(), vdc.getId()); VDC VDC = client.getVDCInOrg(org.getId(), vdc.getId());
@ -106,8 +109,8 @@ public class BrowsingClientLiveTest extends BaseVPDCClientLiveTest {
assertNotNull(response.getNetmask()); assertNotNull(response.getNetmask());
assertNotNull(response.getGateway()); assertNotNull(response.getGateway());
assertNotNull(response.getInternalToExternalNATRules()); assertNotNull(response.getInternalToExternalNATRules());
assertEquals(client.getNetworkInVDC(org.getId(), vdc.getId(), response.getId()).toString(), assertEquals(client.getNetworkInVDC(org.getId(), vdc.getId(), response.getId()).toString(), response
response.toString()); .toString());
} }
} }
} }
@ -115,7 +118,7 @@ public class BrowsingClientLiveTest extends BaseVPDCClientLiveTest {
@Test @Test
public void testVM() throws Exception { public void testVM() throws Exception {
for (Resource org1 : context.getApi().listOrgs()) { for (Resource org1 : restContext.getApi().listOrgs()) {
Org org = client.getOrg(org1.getId()); Org org = client.getOrg(org1.getId());
for (Resource vdc : org.getVDCs()) { for (Resource vdc : org.getVDCs()) {
VDC VDC = client.getVDCInOrg(org.getId(), vdc.getId()); VDC VDC = client.getVDCInOrg(org.getId(), vdc.getId());
@ -133,16 +136,25 @@ public class BrowsingClientLiveTest extends BaseVPDCClientLiveTest {
assertNotNull(response.getHref()); assertNotNull(response.getHref());
assertNotNull(response.getName()); assertNotNull(response.getName());
assertEquals(response.getType(), "application/vnd.vmware.vcloud.vApp+xml"); 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.getStatus());
assertNotNull(response.getOsDescripton()); assertNotNull(response.getOperatingSystemSection().getDescription());
assertNotNull(response.getOsType()); assertNotNull(response.getOperatingSystemSection().getId());
assertNotNull(response.getNetworkSection()); assertNotNull(response.getNetworkSection());
assertNotNull(response.getResourceAllocations()); assertNotNull(response.getVirtualHardwareSections());
// power state is the only thing that should change // power state is the only thing that should change
assertEquals(client.getVMInVDC(org.getId(), vdc.getId(), response.getId(), withPowerState()) assertEquals(client.getVMInVDC(org.getId(), vdc.getId(), response.getId(), withPowerState()).toString()
.toString().replaceFirst("status=[A-Z]+", ""), response.toString().replaceFirst( .replaceFirst("status=[A-Z]+", ""), response.toString().replaceFirst("status=[A-Z]+", ""));
"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;
} }
} }
@ -151,14 +163,14 @@ public class BrowsingClientLiveTest extends BaseVPDCClientLiveTest {
@Test @Test
public void testGetFirewallRules() throws Exception { public void testGetFirewallRules() throws Exception {
for (Resource org1 : context.getApi().listOrgs()) { for (Resource org1 : restContext.getApi().listOrgs()) {
Org org = client.getOrg(org1.getId()); Org org = client.getOrg(org1.getId());
for (Resource vdc : org.getVDCs()) { for (Resource vdc : org.getVDCs()) {
FirewallService response = client.listFirewallRules(org.getId(), vdc.getId()); FirewallService response = client.listFirewallRules(org.getId(), vdc.getId());
Set<FirewallRule> firewallRules = response.getFirewallRules(); Set<FirewallRule> firewallRules = response.getFirewallRules();
if(firewallRules != null){ if (firewallRules != null) {
Iterator<FirewallRule> iter = firewallRules.iterator(); Iterator<FirewallRule> iter = firewallRules.iterator();
while(iter.hasNext()){ while (iter.hasNext()) {
FirewallRule firewallRule = iter.next(); FirewallRule firewallRule = iter.next();
assertNotNull(firewallRule); assertNotNull(firewallRule);
// these are null for firewall rules // these are null for firewall rules

View File

@ -32,7 +32,7 @@ public class FirewallClientLiveTest extends BaseVPDCClientLiveTest {
@BeforeGroups(groups = { "live" }) @BeforeGroups(groups = { "live" })
public void setupClient() { public void setupClient() {
super.setupClient(); super.setupClient();
client = context.getApi().getFirewallClient(); client = restContext.getApi().getFirewallClient();
} }

Some files were not shown because too many files have changed in this diff Show More