fixed OVF where we didn't match relationships in spec

This commit is contained in:
Adrian Cole 2011-03-22 02:07:46 -07:00
parent 5ae1ba44d2
commit da29745ac2
40 changed files with 2109 additions and 587 deletions

View File

@ -42,8 +42,8 @@ import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import org.jclouds.ovf.OvfEnvelope;
import org.jclouds.ovf.xml.OvfEnvelopeHandler;
import org.jclouds.ovf.Envelope;
import org.jclouds.ovf.xml.EnvelopeHandler;
import org.jclouds.predicates.validators.DnsNameValidator;
import org.jclouds.rest.annotations.BinderParam;
import org.jclouds.rest.annotations.Endpoint;
@ -131,9 +131,9 @@ public interface VCloudAsyncClient extends CommonVCloudAsyncClient {
@GET
@Consumes(MediaType.TEXT_XML)
@Path("/ovf")
@XMLResponseParser(OvfEnvelopeHandler.class)
@XMLResponseParser(EnvelopeHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<? extends OvfEnvelope> getOvfEnvelopeForVAppTemplate(@EndpointParam URI vAppTemplate);
ListenableFuture<? extends Envelope> getOvfEnvelopeForVAppTemplate(@EndpointParam URI vAppTemplate);
/**
* @see VCloudClient#findVAppTemplateInOrgCatalogNamed

View File

@ -28,7 +28,7 @@ import java.util.concurrent.TimeUnit;
import javax.annotation.Nullable;
import org.jclouds.concurrent.Timeout;
import org.jclouds.ovf.OvfEnvelope;
import org.jclouds.ovf.Envelope;
import org.jclouds.vcloud.domain.GuestCustomizationSection;
import org.jclouds.vcloud.domain.NetworkConnectionSection;
import org.jclouds.vcloud.domain.ReferenceType;
@ -84,7 +84,7 @@ public interface VCloudClient extends CommonVCloudClient {
VAppTemplate getVAppTemplate(URI vAppTemplate);
OvfEnvelope getOvfEnvelopeForVAppTemplate(URI vAppTemplate);
Envelope getOvfEnvelopeForVAppTemplate(URI vAppTemplate);
/**
* Modify the Guest Customization Section of a Virtual Machine

View File

@ -28,7 +28,7 @@ import org.jclouds.compute.domain.Hardware;
import org.jclouds.compute.domain.HardwareBuilder;
import org.jclouds.compute.predicates.ImagePredicates;
import org.jclouds.logging.Logger;
import org.jclouds.ovf.OvfEnvelope;
import org.jclouds.ovf.Envelope;
import org.jclouds.ovf.VirtualHardwareSection;
import org.jclouds.vcloud.VCloudClient;
import org.jclouds.vcloud.domain.ReferenceType;
@ -73,19 +73,19 @@ public class HardwareForVAppTemplate implements Function<VAppTemplate, Hardware>
return null;
}
OvfEnvelope ovf = client.getOvfEnvelopeForVAppTemplate(from.getHref());
Envelope ovf = client.getOvfEnvelopeForVAppTemplate(from.getHref());
if (ovf == null) {
logger.warn("cannot parse hardware as no ovf envelope found for %s", from);
return null;
}
if (ovf.getVirtualSystem().getHardware().size() == 0) {
if (ovf.getVirtualSystem().getVirtualHardwareSections().size() == 0) {
logger.warn("cannot parse hardware for %s as no hardware sections exist in ovf %s", ovf);
return null;
}
if (ovf.getVirtualSystem().getHardware().size() > 1) {
if (ovf.getVirtualSystem().getVirtualHardwareSections().size() > 1) {
logger.warn("multiple hardware choices found. using first", ovf);
}
VirtualHardwareSection hardware = Iterables.get(ovf.getVirtualSystem().getHardware(), 0);
VirtualHardwareSection hardware = Iterables.get(ovf.getVirtualSystem().getVirtualHardwareSections(), 0);
HardwareBuilder builder = rasdToHardwareBuilder.apply(hardware.getResourceAllocations());
builder.location(findLocationForResource.apply(checkNotNull(parent, "parent")));
builder.ids(from.getHref().toASCIIString()).name(from.getName()).supportsImage(

View File

@ -27,7 +27,7 @@ import org.jclouds.compute.domain.CIMOperatingSystem;
import org.jclouds.compute.domain.Image;
import org.jclouds.compute.domain.ImageBuilder;
import org.jclouds.compute.strategy.PopulateDefaultLoginCredentialsForImageStrategy;
import org.jclouds.ovf.OvfEnvelope;
import org.jclouds.ovf.Envelope;
import org.jclouds.vcloud.VCloudClient;
import org.jclouds.vcloud.domain.ReferenceType;
import org.jclouds.vcloud.domain.VAppTemplate;
@ -64,7 +64,7 @@ public class ImageForVAppTemplate implements Function<VAppTemplate, Image> {
builder.name(from.getName());
builder.location(findLocationForResource.apply(checkNotNull(parent, "parent")));
builder.description(from.getDescription() != null ? from.getDescription() : from.getName());
OvfEnvelope ovf = client.getOvfEnvelopeForVAppTemplate(from.getHref());
Envelope ovf = client.getOvfEnvelopeForVAppTemplate(from.getHref());
builder.operatingSystem(CIMOperatingSystem.toComputeOs(ovf));
builder.defaultCredentials(credentialsProvider.execute(from));
return builder.build();

View File

@ -32,9 +32,10 @@ public class VCloudVirtualHardwareSection extends VirtualHardwareSection {
protected final String type;
protected final URI href;
public VCloudVirtualHardwareSection(String type, URI href, String info, VirtualSystemSettingData virtualSystem,
public VCloudVirtualHardwareSection(String type, URI href, String info, Iterable<String> transports,
VirtualSystemSettingData virtualSystem,
Iterable<? extends ResourceAllocationSettingData> resourceAllocations) {
super(info, virtualSystem, resourceAllocations);
super(info, transports, virtualSystem, resourceAllocations);
this.type = type;
this.href = href;
}

View File

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

View File

@ -42,7 +42,7 @@ import org.jclouds.http.RequiresHttp;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.http.functions.ReleasePayloadAndReturn;
import org.jclouds.http.functions.ReturnInputStream;
import org.jclouds.ovf.xml.OvfEnvelopeHandler;
import org.jclouds.ovf.xml.EnvelopeHandler;
import org.jclouds.rest.ConfiguresRestClient;
import org.jclouds.rest.RestClientTest;
import org.jclouds.rest.RestContextFactory;
@ -442,7 +442,7 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
assertPayloadEquals(request, null, null, false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, OvfEnvelopeHandler.class);
assertSaxResponseParserClassEquals(method, EnvelopeHandler.class);
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
checkFilters(request);

View File

@ -31,7 +31,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
* />
*
*/
public abstract class SettingData {
public abstract class SettingData implements Comparable<SettingData> {
public static Builder builder() {
return new Builder();
@ -123,4 +123,14 @@ public abstract class SettingData {
return String.format("[elementName=%s, instanceID=%s]", elementName, instanceID);
}
/**
* {@inheritDoc}
*/
@Override
public int compareTo(SettingData o) {
if (instanceID == null)
return -1;
return (this == o) ? 0 : instanceID.compareTo(o.instanceID);
}
}

View File

@ -22,7 +22,7 @@ package org.jclouds.compute.domain;
import javax.annotation.Nullable;
import org.jclouds.cim.OSType;
import org.jclouds.ovf.OvfEnvelope;
import org.jclouds.ovf.Envelope;
import com.google.common.annotations.Beta;
@ -123,8 +123,8 @@ public class CIMOperatingSystem extends OperatingSystem {
return new CIMOperatingSystem(OSType.fromValue(os.getId()), "", null, os.getDescription());
}
public static CIMOperatingSystem toComputeOs(OvfEnvelope ovf) {
return toComputeOs(ovf.getVirtualSystem().getOperatingSystem());
public static CIMOperatingSystem toComputeOs(Envelope ovf) {
return toComputeOs(ovf.getVirtualSystem().getOperatingSystemSection());
}
private OSType osType;

View File

@ -0,0 +1,120 @@
/**
*
* 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 Configuration {
public static Builder builder() {
return new Builder();
}
public static class Builder {
protected String id;
protected String label;
protected String description;
/**
* @see Configuration#getId
*/
public Builder id(String id) {
this.id = id;
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 Configuration build() {
return new Configuration(id, label, description);
}
public Builder fromNetwork(Configuration in) {
return id(in.getId()).description(in.getDescription()).label(in.getLabel());
}
}
private final String id;
private final String label;
private final String description;
public Configuration(String id, String label, String description) {
this.id = id;
this.label = label;
this.description = description;
}
@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;
Configuration other = (Configuration) 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("Configuration [id=%s, label=%s, description=%s]", id, label, description);
}
public String getId() {
return id;
}
public String getDescription() {
return description;
}
public String getLabel() {
return label;
}
}

View File

@ -0,0 +1,144 @@
/**
*
* 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 DeploymentOptionSection specifies a discrete set of intended resource configurations. The
* author of an OVF package can include sizing metadata for different configurations. A consumer of
* the OVF shall select a configuration, for example, by prompting the user. The selected
* configuration is visible in the OVF environment, enabling guest software to adapt to the selected
* configuration.
*
* @author Adrian Cole
*/
public class DeploymentOptionSection extends Section<DeploymentOptionSection> {
@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<DeploymentOptionSection> {
protected Set<Configuration> configurations = Sets.newLinkedHashSet();
/**
* @see DeploymentOptionSection#getConfigurations
*/
public Builder configuration(Configuration configuration) {
this.configurations.add(checkNotNull(configuration, "configuration"));
return this;
}
/**
* @see DeploymentOptionSection#getConfigurations
*/
public Builder configurations(Iterable<Configuration> configurations) {
this.configurations = ImmutableSet.<Configuration> copyOf(checkNotNull(configurations, "configurations"));
return this;
}
/**
* {@inheritDoc}
*/
@Override
public DeploymentOptionSection build() {
return new DeploymentOptionSection(info, configurations);
}
public Builder fromDeploymentOptionSection(DeploymentOptionSection in) {
return info(in.getInfo()).configurations(in.getConfigurations());
}
/**
* {@inheritDoc}
*/
@Override
public Builder fromSection(Section<DeploymentOptionSection> 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<Configuration> configurations;
public DeploymentOptionSection(String info, Iterable<Configuration> configurations) {
super(info);
this.configurations = ImmutableSet.<Configuration> copyOf(checkNotNull(configurations, "configurations"));
}
@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result + ((configurations == null) ? 0 : configurations.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;
DeploymentOptionSection other = (DeploymentOptionSection) obj;
if (configurations == null) {
if (other.configurations != null)
return false;
} else if (!configurations.equals(other.configurations))
return false;
return true;
}
@Override
public String toString() {
return String.format("[info=%s, configurations=%s]", info, configurations);
}
public Set<Configuration> getConfigurations() {
return configurations;
}
}

View File

@ -0,0 +1,237 @@
/**
*
* 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;
import java.net.URI;
/**
*
* @author Adrian Cole
*/
public class Disk implements Comparable<Disk>{
public static Builder builder() {
return new Builder();
}
public static class Builder {
private String id;
private Long capacity;
private String parentRef;
private String fileRef;
private URI format;
private Long populatedSize;
private String capacityAllocationUnits;
/**
* @see Disk#getId
*/
public Builder id(String id) {
this.id = id;
return this;
}
/**
* @see Disk#getCapacity
*/
public Builder capacity(Long capacity) {
this.capacity = capacity;
return this;
}
/**
* @see Disk#getParentRef
*/
public Builder parentRef(String parentRef) {
this.parentRef = parentRef;
return this;
}
/**
* @see Disk#getFileRef
*/
public Builder fileRef(String fileRef) {
this.fileRef = fileRef;
return this;
}
/**
* @see Disk#getFormat
*/
public Builder format(URI format) {
this.format = format;
return this;
}
/**
* @see Disk#getPopulatedSize
*/
public Builder populatedSize(Long populatedSize) {
this.populatedSize = populatedSize;
return this;
}
/**
* @see Disk#getCapacityAllocationUnits
*/
public Builder capacityAllocationUnits(String capacityAllocationUnits) {
this.capacityAllocationUnits = capacityAllocationUnits;
return this;
}
public Disk build() {
return new Disk(id, capacity, parentRef, fileRef, format, populatedSize, capacityAllocationUnits);
}
public Builder fromDisk(Disk in) {
return id(in.getId()).capacity(in.getCapacity()).parentRef(in.getParentRef()).fileRef(in.getFileRef()).format(
in.getFormat()).populatedSize(in.getPopulatedSize()).capacityAllocationUnits(
in.getCapacityAllocationUnits());
}
}
private final String id;
private final Long capacity;
private final String parentRef;
private final String fileRef;
private final URI format;
private final Long populatedSize;
private final String capacityAllocationUnits;
public Disk(String id, Long capacity, String parentRef, String fileRef, URI format, Long populatedSize,
String capacityAllocationUnits) {
this.id = id;
this.capacity = capacity;
this.parentRef = parentRef;
this.fileRef = fileRef;
this.format = format;
this.populatedSize = populatedSize;
this.capacityAllocationUnits = capacityAllocationUnits;
}
/**
* Each virtual disk is represented by a Disk element that shall be given a identifier using the
* {@code id} attribute, the identifier shall be unique within the {@link DiskSection}.
*/
public String getId() {
return id;
}
/**
* The capacity of a virtual disk shall be specified by the {@code capacity} attribute with an
* xs:long integer value. The default unit of allocation shall be bytes.
*/
public Long getCapacity() {
return capacity;
}
/**
* OVF allows a disk image to be represented as a set of modified blocks in comparison to a
* parent image. The use of parent disks can often significantly reduce the size of an OVF
* package, if it contains multiple disks with similar content. For a Disk element, a parent disk
* may optionally be specified using the {@code parentRef} attribute, which shall contain a valid
* ovf:id reference to a different Disk element. If a disk block does not exist locally, lookup
* for that disk block then occurs in the parent disk. In {@link DiskSection}, parent Disk
* elements shall occur before child Disk elements that refer to them.
*/
public String getParentRef() {
return parentRef;
}
/**
* The ovf:fileRef attribute denotes the virtual disk content by identifying an existing File
* element in the References element, the File element is identified by matching its {@code id}
* attribute value with the {@code fileRef} attribute value. Omitting the {@code fileRef}
* attribute shall indicate an empty disk. In this case, the disk shall be created and the entire
* disk content zeroed at installation time. The guest software will typically format empty disks
* in some file system format.
*/
public String getFileRef() {
return fileRef;
}
/**
* The format URI of a non-empty virtual disk shall be specified by the {@code format} attribute.
*/
public URI getFormat() {
return format;
}
/**
* For non-empty disks, the actual used size of the disk may optionally be specified using the
* {@code populatedSize} attribute. The unit of this attribute is always bytes. {@code
* populatedSize} is allowed to be an estimate of used disk size but shall not be larger than
* {@code capacity}.
*/
public Long getPopulatedSize() {
return populatedSize;
}
/**
* The optional string attribute {@code ovf:capacityAllocationUnits} may be used to specify a
* particular unit of allocation. Values for {@code ovf:capacityAllocationUnits} shall match the
* format for programmatic units defined in DSP0004.
*/
public String getCapacityAllocationUnits() {
return capacityAllocationUnits;
}
@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;
Disk other = (Disk) 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, capacity=%s, capacityAllocationUnits=%s, fileRef=%s, format=%s, parentRef=%s, populatedSize=%s]",
id, capacity, capacityAllocationUnits, fileRef, format, parentRef, populatedSize);
}
/**
* {@inheritDoc}
*/
@Override
public int compareTo(Disk o) {
if (id == null)
return -1;
return (this == o) ? 0 : id.compareTo(o.id);
}
}

View File

@ -0,0 +1,153 @@
/**
*
* 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;
/**
* A DiskSection describes meta-information about virtual disks in the OVF package. Virtual disks
* and their metadata are described outside the virtual hardware to facilitate sharing between
* virtual machines within an OVF package.
*
* @author Adrian Cole
*/
public class DiskSection extends Section<DiskSection> {
@SuppressWarnings("unchecked")
public static Builder builder() {
return new Builder();
}
/**
* {@inheritDoc}
*/
@Override
public Builder toBuilder() {
return new Builder().fromDiskSection(this);
}
public static class Builder extends Section.Builder<DiskSection> {
protected Set<Disk> disks = Sets.newLinkedHashSet();
/**
* @see DiskSection#getDisks
*/
public Builder disk(Disk disk) {
this.disks.add(checkNotNull(disk, "disk"));
return this;
}
/**
* @see DiskSection#getDisks
*/
public Builder disks(Iterable<Disk> disks) {
this.disks = ImmutableSet.<Disk> copyOf(checkNotNull(disks, "disks"));
return this;
}
/**
* {@inheritDoc}
*/
@Override
public DiskSection build() {
return new DiskSection(info, disks);
}
public Builder fromDiskSection(DiskSection in) {
return disks(in.getDisks()).info(in.getInfo());
}
/**
* {@inheritDoc}
*/
@Override
public Builder fromSection(Section<DiskSection> in) {
return (Builder) super.fromSection(in);
}
/**
* {@inheritDoc}
*/
@Override
public Builder info(String info) {
return (Builder) super.info(info);
}
}
private final Set<Disk> disks;
public DiskSection(String info, Iterable<Disk> disks) {
super(info);
this.disks = ImmutableSet.<Disk> copyOf(checkNotNull(disks, "disks"));
}
/**
* All disks referred to from Connection elements in all {@link VirtualHardwareSection} elements
* shall be defined in the DiskSection.
*
* @return
*/
public Set<Disk> getDisks() {
return disks;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((info == null) ? 0 : info.hashCode());
result = prime * result + ((disks == null) ? 0 : disks.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;
DiskSection other = (DiskSection) obj;
if (info == null) {
if (other.info != null)
return false;
} else if (!info.equals(other.info))
return false;
if (disks == null) {
if (other.disks != null)
return false;
} else if (!disks.equals(other.disks))
return false;
return true;
}
@Override
public String toString() {
return String.format("[info=%s, disks=%s]", info, disks);
}
}

View File

@ -0,0 +1,205 @@
/**
*
* 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;
/**
* @author Adrian Cole
*/
public class Envelope {
public static Builder builder() {
return new Builder();
}
/**
* {@inheritDoc}
*/
public Builder toBuilder() {
return new Builder().fromEnvelope(this);
}
public static class Builder {
protected Set<DiskSection> diskSections = Sets.newLinkedHashSet();
protected Set<NetworkSection> networkSections = Sets.newLinkedHashSet();
@SuppressWarnings("unchecked")
protected Set<Section> additionalSections = Sets.newLinkedHashSet();
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(Section additionalSection) {
this.additionalSections.add(checkNotNull(additionalSection, "additionalSection"));
return this;
}
/**
* @see Envelope#getAdditionalSections
*/
@SuppressWarnings("unchecked")
public Builder additionalSections(Iterable<? extends Section> additionalSections) {
this.additionalSections = ImmutableSet
.<Section> copyOf(checkNotNull(additionalSections, "additionalSections"));
return this;
}
/**
* @see Envelope#getVirtualSystem
*/
public Builder virtualSystem(VirtualSystem virtualSystem) {
this.virtualSystem = virtualSystem;
return this;
}
/**
* {@inheritDoc}
*/
public Envelope build() {
return new Envelope(diskSections, networkSections, additionalSections, virtualSystem);
}
public Builder fromEnvelope(Envelope 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 Set<? extends Section> additionalSections;
private final VirtualSystem virtualSystem;
@SuppressWarnings("unchecked")
public Envelope(Iterable<? extends DiskSection> diskSections, Iterable<? extends NetworkSection> networkSections,
Iterable<? extends Section> additionalSections, VirtualSystem virtualSystem) {
this.diskSections = ImmutableSet.copyOf(checkNotNull(diskSections, "diskSections"));
this.networkSections = ImmutableSet.copyOf(checkNotNull(networkSections, "networkSections"));
this.additionalSections = ImmutableSet.copyOf(checkNotNull(additionalSections, "additionalSections"));
this.virtualSystem = checkNotNull(virtualSystem, "virtualSystem");
}
public VirtualSystem getVirtualSystem() {
return virtualSystem;
}
public Set<? extends DiskSection> getDiskSections() {
return diskSections;
}
@SuppressWarnings("unchecked")
public Set<? extends 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

@ -1,6 +1,6 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
* Copyright (C) 2010 Cloud Conscious, LLC. <description@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@ -19,11 +19,45 @@
package org.jclouds.ovf;
/**
*
* @author Adrian Cole
*/
public class Network {
public static Builder builder() {
return new Builder();
}
public static class Builder {
protected String name;
protected String description;
/**
* @see Network#getName
*/
public Builder name(String name) {
this.name = name;
return this;
}
/**
* @see Section#getDescription
*/
public Builder description(String description) {
this.description = description;
return this;
}
public Network build() {
return new Network(name, description);
}
public Builder fromNetwork(Network in) {
return name(in.getName()).description(in.getDescription());
}
}
private final String name;
private final String description;
@ -65,7 +99,7 @@ public class Network {
@Override
public String toString() {
return "Network [name=" + name + ", description=" + description + "]";
return "[name=" + name + ", description=" + description + "]";
}
public String getName() {

View File

@ -19,31 +19,92 @@
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 NetworkSection element shall list all logical networks used in the OVF package.
*
* @author Adrian Cole
*/
public class NetworkSection {
private final String info;
private final Set<Network> networks;
public class NetworkSection extends Section<NetworkSection> {
public NetworkSection(String info, Iterable<Network> networks) {
this.info = info;
this.networks = ImmutableSet.<Network> copyOf(networks);
}
public String getInfo() {
return info;
@SuppressWarnings("unchecked")
public static Builder builder() {
return new Builder();
}
/**
* All networks referred to from Connection elements in all {@link VirtualHardwareSection} elements shall
* be defined in the NetworkSection.
* {@inheritDoc}
*/
@Override
public Builder toBuilder() {
return builder().fromNetworkSection(this);
}
public static class Builder extends Section.Builder<NetworkSection> {
protected Set<Network> networks = Sets.newLinkedHashSet();
/**
* @see NetworkSection#getNetworks
*/
public Builder network(Network network) {
this.networks.add(checkNotNull(network, "network"));
return this;
}
/**
* @see NetworkSection#getNetworks
*/
public Builder networks(Iterable<Network> networks) {
this.networks = ImmutableSet.<Network> copyOf(checkNotNull(networks, "networks"));
return this;
}
/**
* {@inheritDoc}
*/
@Override
public NetworkSection build() {
return new NetworkSection(info, networks);
}
public Builder fromNetworkSection(NetworkSection in) {
return networks(in.getNetworks()).info(in.getInfo());
}
/**
* {@inheritDoc}
*/
@Override
public Builder fromSection(Section<NetworkSection> in) {
return Builder.class.cast(super.fromSection(in));
}
/**
* {@inheritDoc}
*/
@Override
public Builder info(String info) {
return Builder.class.cast(super.info(info));
}
}
private final Set<Network> networks;
public NetworkSection(String info, Iterable<Network> networks) {
super(info);
this.networks = ImmutableSet.<Network> copyOf(checkNotNull(networks, "networks"));
}
/**
* All networks referred to from Connection elements in all {@link VirtualHardwareSection}
* elements shall be defined in the NetworkSection.
*
* @return
*/
@ -84,7 +145,7 @@ public class NetworkSection {
@Override
public String toString() {
return "[info=" + info + ", networks=" + networks + "]";
return String.format("[info=%s, networks=%s]", info, networks);
}
}

View File

@ -28,15 +28,23 @@ import org.jclouds.cim.OSType;
*
* @author Adrian Cole
*/
public class OperatingSystemSection {
public class OperatingSystemSection extends Section<OperatingSystemSection> {
@SuppressWarnings("unchecked")
public static Builder builder() {
return new Builder();
}
public static class Builder {
/**
* {@inheritDoc}
*/
@Override
public Builder toBuilder() {
return builder().fromOperatingSystemSection(this);
}
public static class Builder extends Section.Builder<OperatingSystemSection> {
protected Integer id;
protected String info;
protected String description;
/**
@ -47,14 +55,6 @@ public class OperatingSystemSection {
return this;
}
/**
* @see OperatingSystemSection#getInfo
*/
public Builder info(String info) {
this.info = info;
return this;
}
/**
* @see OperatingSystemSection#getDescription
*/
@ -63,6 +63,10 @@ public class OperatingSystemSection {
return this;
}
/**
* {@inheritDoc}
*/
@Override
public OperatingSystemSection build() {
return new OperatingSystemSection(id, info, description);
}
@ -70,15 +74,31 @@ public class OperatingSystemSection {
public Builder fromOperatingSystemSection(OperatingSystemSection in) {
return id(in.getId()).info(in.getInfo()).description(in.getDescription());
}
/**
* {@inheritDoc}
*/
@Override
public Builder fromSection(Section<OperatingSystemSection> in) {
return Builder.class.cast(super.fromSection(in));
}
/**
* {@inheritDoc}
*/
@Override
public Builder info(String info) {
return Builder.class.cast(super.info(info));
}
}
protected final Integer id;
protected final String info;
protected final String description;
public OperatingSystemSection(@Nullable Integer id, @Nullable String info, @Nullable String description) {
super(info);
this.id = id;
this.info = info;
this.description = description;
}
@ -91,14 +111,6 @@ public class OperatingSystemSection {
return id;
}
/**
*
* @return ovf info
*/
public String getInfo() {
return info;
}
/**
*
* @return description or null
@ -144,13 +156,9 @@ public class OperatingSystemSection {
return true;
}
public Builder toBuilder() {
return builder().fromOperatingSystemSection(this);
}
@Override
public String toString() {
return "[id=" + getId() + ", info=" + getInfo() + ", description=" + getDescription() + "]";
return String.format("[info=%s, id=%s, description=%s]", info, id, description);
}
}

View File

@ -19,29 +19,62 @@
package org.jclouds.ovf;
import static com.google.common.base.Preconditions.checkNotNull;
import javax.annotation.Nullable;
/**
*
* Metadata about a virtual machine or grouping of them
*
* @author Adrian Cole
*/
public class OvfEnvelope {
private final VirtualSystem virtualSystem;
public class Section<T extends Section<T>> {
public OvfEnvelope(VirtualSystem virtualSystem) {
this.virtualSystem = checkNotNull(virtualSystem, "virtualSystem");
public static <T extends Section<T>> Builder<T> builder() {
return new Builder<T>();
}
public VirtualSystem getVirtualSystem() {
return virtualSystem;
public Builder<T> toBuilder() {
return new Builder<T>().fromSection(this);
}
public static class Builder<T extends Section<T>> {
protected String info;
/**
* @see Section#getInfo
*/
public Builder<T> info(String info) {
this.info = info;
return this;
}
public Section<T> build() {
return new Section<T>(info);
}
public Builder<T> fromSection(Section<T> in) {
return info(in.getInfo());
}
}
protected final String info;
public Section(@Nullable String info) {
this.info = info;
}
/**
*
* @return ovf info
*/
public String getInfo() {
return info;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((virtualSystem == null) ? 0 : virtualSystem.hashCode());
result = prime * result + ((info == null) ? 0 : info.hashCode());
return result;
}
@ -53,17 +86,18 @@ public class OvfEnvelope {
return false;
if (getClass() != obj.getClass())
return false;
OvfEnvelope other = (OvfEnvelope) obj;
if (virtualSystem == null) {
if (other.virtualSystem != null)
Section<?> other = (Section<?>) obj;
if (info == null) {
if (other.info != null)
return false;
} else if (!virtualSystem.equals(other.virtualSystem))
} else if (!info.equals(other.info))
return false;
return true;
}
@Override
public String toString() {
return "[virtualSystem=" + virtualSystem + "]";
return "[info=" + getInfo() + "]";
}
}

View File

@ -27,30 +27,141 @@ import org.jclouds.cim.ResourceAllocationSettingData;
import org.jclouds.cim.VirtualSystemSettingData;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;
/**
*
* The virtual hardware required by a virtual machine is specified in VirtualHardwareSection.
* <p/>
* This specification supports abstract or incomplete hardware descriptions in which only the major
* devices are described. The hypervisor is allowed to create additional virtual hardware
* controllers and devices, as long as the required devices listed in the descriptor are realized.
*
* @author Adrian Cole
*/
public class VirtualHardwareSection {
public class VirtualHardwareSection extends Section<VirtualHardwareSection> {
protected final String info;
protected final VirtualSystemSettingData virtualSystem;
protected final Set<ResourceAllocationSettingData> resourceAllocations;
public VirtualHardwareSection(String info, VirtualSystemSettingData virtualSystem,
Iterable<? extends ResourceAllocationSettingData> resourceAllocations) {
this.info = info;
this.virtualSystem = virtualSystem;
this.resourceAllocations = ImmutableSet.copyOf(checkNotNull(resourceAllocations, "resourceAllocations"));
@SuppressWarnings("unchecked")
public static Builder builder() {
return new Builder();
}
public String getInfo() {
return info;
/**
* {@inheritDoc}
*/
@Override
public Builder toBuilder() {
return builder().fromVirtualHardwareSection(this);
}
public static class Builder extends Section.Builder<VirtualHardwareSection> {
protected VirtualSystemSettingData virtualSystem;
protected Set<String> transports = Sets.newLinkedHashSet();
protected Set<ResourceAllocationSettingData> resourceAllocations = Sets.newLinkedHashSet();
/**
* @see VirtualHardwareSection#getSystem
*/
public Builder system(VirtualSystemSettingData virtualSystem) {
this.virtualSystem = virtualSystem;
return this;
}
/**
* @see VirtualHardwareSection#getTransports
*/
public Builder transport(String transport) {
this.transports.add(checkNotNull(transport, "transport"));
return this;
}
/**
* @see VirtualHardwareSection#getTransports
*/
public Builder transports(Iterable<String> transports) {
this.transports = ImmutableSet.<String> copyOf(checkNotNull(transports, "transports"));
return this;
}
/**
* @see VirtualHardwareSection#getResourceAllocations
*/
public Builder resourceAllocation(ResourceAllocationSettingData resourceAllocation) {
this.resourceAllocations.add(checkNotNull(resourceAllocation, "resourceAllocation"));
return this;
}
/**
* @see VirtualHardwareSection#getResourceAllocations
*/
public Builder resourceAllocations(Iterable<? extends ResourceAllocationSettingData> resourceAllocations) {
this.resourceAllocations = ImmutableSet.<ResourceAllocationSettingData> copyOf(checkNotNull(
resourceAllocations, "resourceAllocations"));
return this;
}
/**
* {@inheritDoc}
*/
@Override
public VirtualHardwareSection build() {
return new VirtualHardwareSection(info, transports, virtualSystem, resourceAllocations);
}
public Builder fromVirtualHardwareSection(VirtualHardwareSection in) {
return resourceAllocations(in.getResourceAllocations()).transports(in.getTransports()).system(
in.getSystem()).info(in.getInfo());
}
/**
* {@inheritDoc}
*/
@Override
public Builder fromSection(Section<VirtualHardwareSection> in) {
return Builder.class.cast(super.fromSection(in));
}
/**
* {@inheritDoc}
*/
@Override
public Builder info(String info) {
return Builder.class.cast(super.info(info));
}
}
protected final VirtualSystemSettingData virtualSystem;
protected final Set<String> transports;
protected final Set<ResourceAllocationSettingData> resourceAllocations;
public VirtualHardwareSection(String info, Iterable<String> transports, VirtualSystemSettingData virtualSystem,
Iterable<? extends ResourceAllocationSettingData> resourceAllocations) {
super(info);
this.virtualSystem = virtualSystem;
this.transports = ImmutableSet.<String> copyOf(checkNotNull(transports, "transports"));
this.resourceAllocations = ImmutableSet.<ResourceAllocationSettingData> copyOf(checkNotNull(resourceAllocations,
"resourceAllocations"));
}
/**
* transport types define methods by which the environment document is communicated from the
* deployment platform to the guest software.
* <p/>
* To enable interoperability, this specification defines an "iso" transport type which all
* implementations that support CD-ROM devices are required to support. The iso transport
* communicates the environment 1346 document by making a dynamically generated ISO image
* available to the guest software. To support the iso transport type, prior to booting a virtual
* machine, an implementation shall make an ISO 9660 read-only disk image available as backing
* for a disconnected CD-ROM. If the iso transport is selected for a VirtualHardwareSection, at
* least one disconnected CD-ROM device shall be present in this section.
* <p/>
* Support for the "iso" transport type is not a requirement for virtual hardware architectures
* or guest 1351 operating systems which do not have CD-ROM device support.
*
* @return
*/
public Set<String> getTransports() {
return transports;
}
public VirtualSystemSettingData getSystem() {
@ -61,17 +172,12 @@ public class VirtualHardwareSection {
return resourceAllocations;
}
@Override
public String toString() {
return "[info=" + getInfo() + ", virtualSystem=" + getSystem() + "]";
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((info == null) ? 0 : info.hashCode());
int result = super.hashCode();
result = prime * result + ((resourceAllocations == null) ? 0 : resourceAllocations.hashCode());
result = prime * result + ((transports == null) ? 0 : transports.hashCode());
result = prime * result + ((virtualSystem == null) ? 0 : virtualSystem.hashCode());
return result;
}
@ -80,21 +186,21 @@ public class VirtualHardwareSection {
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
if (!super.equals(obj))
return false;
if (getClass() != obj.getClass())
return false;
VirtualHardwareSection other = (VirtualHardwareSection) obj;
if (info == null) {
if (other.info != null)
return false;
} else if (!info.equals(other.info))
return false;
if (resourceAllocations == null) {
if (other.resourceAllocations != null)
return false;
} else if (!resourceAllocations.equals(other.resourceAllocations))
return false;
if (transports == null) {
if (other.transports != null)
return false;
} else if (!transports.equals(other.transports))
return false;
if (virtualSystem == null) {
if (other.virtualSystem != null)
return false;
@ -103,4 +209,10 @@ public class VirtualHardwareSection {
return true;
}
@Override
public String toString() {
return String.format("[info=%s, resourceAllocations=%s, transports=%s, virtualSystem=%s]", info,
resourceAllocations, transports, virtualSystem);
}
}

View File

@ -23,63 +23,175 @@ import static com.google.common.base.Preconditions.checkNotNull;
import java.util.Set;
import com.google.common.collect.Iterables;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;
/**
* @author Adrian Cole
*/
public class VirtualSystem {
public class VirtualSystem extends Section<VirtualSystem> {
@SuppressWarnings("unchecked")
public static Builder builder() {
return new Builder();
}
/**
* {@inheritDoc}
*/
@Override
public Builder toBuilder() {
return new Builder().fromVirtualSystem(this);
}
public static class Builder extends Section.Builder<VirtualSystem> {
protected String id;
protected String name;
protected OperatingSystemSection operatingSystem;
protected Set<VirtualHardwareSection> hardwareSections = Sets.newLinkedHashSet();
@SuppressWarnings("unchecked")
protected Set<Section> additionalSections = Sets.newLinkedHashSet();
/**
* @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(Section additionalSection) {
this.additionalSections.add(checkNotNull(additionalSection, "additionalSection"));
return this;
}
/**
* @see VirtualSystem#getAdditionalSections
*/
@SuppressWarnings("unchecked")
public Builder additionalSections(Iterable<? extends Section> additionalSections) {
this.additionalSections = ImmutableSet
.<Section> copyOf(checkNotNull(additionalSections, "additionalSections"));
return this;
}
/**
* {@inheritDoc}
*/
@Override
public VirtualSystem build() {
return new VirtualSystem(id, info, name, operatingSystem, hardwareSections, additionalSections);
}
public Builder fromVirtualSystem(VirtualSystem in) {
return fromSection(in).id(in.getId()).name(in.getName())
.operatingSystemSection(in.getOperatingSystemSection()).hardwareSections(
in.getVirtualHardwareSections()).additionalSections(in.getAdditionalSections());
}
/**
* {@inheritDoc}
*/
@Override
public Builder fromSection(Section<VirtualSystem> in) {
return (Builder) super.fromSection(in);
}
/**
* {@inheritDoc}
*/
@Override
public Builder info(String info) {
return (Builder) super.info(info);
}
}
private final String id;
private final String info;
private final String name;
private final OperatingSystemSection operatingSystem;
private final Set<VirtualHardwareSection> hardware = Sets.newLinkedHashSet();
private final Set<VirtualHardwareSection> hardwareSections;
@SuppressWarnings("unchecked")
private final Set<? extends Section> additionalSections;
@SuppressWarnings("unchecked")
public VirtualSystem(String id, String info, String name, OperatingSystemSection operatingSystem,
Iterable<? extends VirtualHardwareSection> hardware) {
Iterable<? extends VirtualHardwareSection> hardwareSections, Iterable<? extends Section> additionalSections) {
super(info);
this.id = id;
this.info = info;
this.name = name;
this.operatingSystem = checkNotNull(operatingSystem, "operatingSystem");
Iterables.addAll(this.hardware, checkNotNull(hardware, "hardware"));
this.hardwareSections = ImmutableSet.copyOf(checkNotNull(hardwareSections, "hardwareSections"));
this.additionalSections = ImmutableSet.copyOf(checkNotNull(additionalSections, "additionalSections"));
}
public String getId() {
return id;
}
public String getInfo() {
return info;
}
public String getName() {
return name;
}
public OperatingSystemSection getOperatingSystem() {
public OperatingSystemSection getOperatingSystemSection() {
return operatingSystem;
}
/**
* Each VirtualSystem element may contain one or more VirtualHardwareSection elements, each of
* which describes the virtual hardware required by the virtual system.
* which describes the virtual hardwareSections required by the virtual system.
* */
public Set<? extends VirtualHardwareSection> getHardware() {
return hardware;
public Set<? extends VirtualHardwareSection> getVirtualHardwareSections() {
return hardwareSections;
}
@SuppressWarnings("unchecked")
public Set<? extends Section> getAdditionalSections() {
return additionalSections;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((hardware == null) ? 0 : hardware.hashCode());
result = prime * result + ((id == null) ? 0 : id.hashCode());
result = prime * result + ((info == null) ? 0 : info.hashCode());
result = prime * result + ((name == null) ? 0 : name.hashCode());
result = prime * result + ((operatingSystem == null) ? 0 : operatingSystem.hashCode());
return result;
}
@ -92,37 +204,17 @@ public class VirtualSystem {
if (getClass() != obj.getClass())
return false;
VirtualSystem other = (VirtualSystem) obj;
if (hardware == null) {
if (other.hardware != null)
return false;
} else if (!hardware.equals(other.hardware))
return false;
if (id == null) {
if (other.id != null)
return false;
} else if (!id.equals(other.id))
return false;
if (info == null) {
if (other.info != null)
return false;
} else if (!info.equals(other.info))
return false;
if (name == null) {
if (other.name != null)
return false;
} else if (!name.equals(other.name))
return false;
if (operatingSystem == null) {
if (other.operatingSystem != null)
return false;
} else if (!operatingSystem.equals(other.operatingSystem))
return false;
return true;
}
@Override
public String toString() {
return "[id=" + getId() + ", name=" + getName() + ", info=" + getInfo() + ", os=" + getOperatingSystem()
+ ", hardware=" + getHardware() + "]";
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,72 @@
/**
*
* 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.Configuration;
import org.jclouds.ovf.DeploymentOptionSection;
import org.jclouds.util.SaxUtils;
import org.xml.sax.Attributes;
/**
* @author Adrian Cole
*/
public class DeploymentOptionSectionHandler extends
SectionHandler<DeploymentOptionSection, DeploymentOptionSection.Builder> {
protected Configuration.Builder configBuilder = Configuration.builder();
@Inject
public DeploymentOptionSectionHandler(Provider<DeploymentOptionSection.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, "Configuration")) {
configBuilder.id(attributes.get("id"));
// TODO default;
}
}
@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, "Configuration")) {
try {
builder.configuration(configBuilder.build());
} finally {
configBuilder = Configuration.builder();
}
}
super.endElement(uri, localName, qName);
}
}

View File

@ -0,0 +1,93 @@
/**
*
* 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.net.URI;
import java.util.Map;
import javax.annotation.Resource;
import javax.inject.Inject;
import javax.inject.Provider;
import org.jclouds.logging.Logger;
import org.jclouds.ovf.Disk;
import org.jclouds.ovf.DiskSection;
import org.jclouds.util.SaxUtils;
import org.xml.sax.Attributes;
/**
* @author Adrian Cole
*/
public class DiskSectionHandler extends SectionHandler<DiskSection, DiskSection.Builder> {
@Resource
protected Logger logger = Logger.NULL;
protected Disk.Builder diskBuilder = Disk.builder();
@Inject
public DiskSectionHandler(Provider<DiskSection.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, "Disk")) {
diskBuilder.id(attributes.get("diskId"));
diskBuilder.capacity(attemptToParse(attributes.get("capacity"), "capacity", attributes.get("diskId")));
diskBuilder.parentRef(attributes.get("parentRef"));
diskBuilder.fileRef(attributes.get("fileRef"));
if (attributes.containsKey("format"))
diskBuilder.format(URI.create(attributes.get("format")));
diskBuilder.populatedSize(attemptToParse(attributes.get("populatedSize"), "populatedSize", attributes
.get("diskId")));
diskBuilder.capacityAllocationUnits(attributes.get("capacityAllocationUnits"));
}
}
private Long attemptToParse(String toParse, String key, String diskId) {
Long val = null;
if (toParse != null) {
try {
val = new Long(toParse);
} catch (NumberFormatException e) {
logger.warn("%s for disk %s not a number [%s]", key, diskId, toParse);
}
}
return val;
}
@Override
public void endElement(String uri, String localName, String qName) {
if (equalsOrSuffix(qName, "Info")) {
builder.info(currentOrNull(currentText));
} else if (equalsOrSuffix(qName, "Disk")) {
try {
builder.disk(diskBuilder.build());
} finally {
diskBuilder = Disk.builder();
}
}
super.endElement(uri, localName, qName);
}
}

View File

@ -0,0 +1,162 @@
/**
*
* 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.equalsOrSuffix;
import java.util.Map;
import javax.inject.Named;
import javax.inject.Provider;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.ovf.Envelope;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import com.google.common.collect.ImmutableMap;
import com.google.inject.Inject;
/**
* @author Adrian Cole
*/
public class EnvelopeHandler extends ParseSax.HandlerWithResult<Envelope> {
protected StringBuilder currentText = new StringBuilder();
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
public EnvelopeHandler(DiskSectionHandler diskHandler, NetworkSectionHandler networkHandler,
VirtualSystemHandler osHandler) {
this.virtualSystemHandler = osHandler;
this.diskHandler = diskHandler;
this.networkHandler = networkHandler;
}
@SuppressWarnings("unchecked")
protected SectionHandler defaultSectionHandler = SectionHandler.create();
@SuppressWarnings("unchecked")
@Inject(optional = true)
@Named("VirtualSystem")
Map<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;
public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
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) {
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(extensionHandler.getResult());
inExtensionSection = false;
} else if (qName.endsWith("Section")) {
builder.additionalSection(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);
} else {
currentText = new StringBuilder();
}
}
@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);
} else {
currentText.append(ch, start, length);
}
}
}

View File

@ -23,56 +23,46 @@ import static org.jclouds.util.SaxUtils.currentOrNull;
import static org.jclouds.util.SaxUtils.equalsOrSuffix;
import java.util.Map;
import java.util.Set;
import org.jclouds.http.functions.ParseSax;
import javax.inject.Inject;
import javax.inject.Provider;
import org.jclouds.ovf.Network;
import org.jclouds.ovf.NetworkSection;
import org.jclouds.util.SaxUtils;
import org.xml.sax.Attributes;
import com.google.common.collect.Sets;
/**
* @author Adrian Cole
*/
public class NetworkSectionHandler extends ParseSax.HandlerWithResult<NetworkSection> {
protected StringBuilder currentText = new StringBuilder();
public class NetworkSectionHandler extends SectionHandler<NetworkSection, NetworkSection.Builder> {
protected Network.Builder networkBuilder = Network.builder();
protected String info;
protected String name;
protected String description;
protected Set<Network> networks = Sets.newLinkedHashSet();
public NetworkSection getResult() {
NetworkSection system = new NetworkSection(info, networks);
this.info = null;
this.networks = Sets.newLinkedHashSet();
return system;
@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")) {
name = attributes.get("name");
networkBuilder.name(attributes.get("name"));
}
}
@Override
public void endElement(String uri, String localName, String qName) {
if (equalsOrSuffix(qName, "Info")) {
this.info = currentOrNull(currentText);
builder.info(currentOrNull(currentText));
} else if (equalsOrSuffix(qName, "Description")) {
this.description = currentOrNull(currentText);
networkBuilder.description(currentOrNull(currentText));
} else if (equalsOrSuffix(qName, "Network")) {
this.networks.add(new Network(name, description));
try {
builder.network(networkBuilder.build());
} finally {
networkBuilder = Network.builder();
}
currentText = new StringBuilder();
}
public void characters(char ch[], int start, int length) {
currentText.append(ch, start, length);
super.endElement(uri, localName, qName);
}
}

View File

@ -25,26 +25,20 @@ import static org.jclouds.util.SaxUtils.equalsOrSuffix;
import java.util.Map;
import org.jclouds.http.functions.ParseSax;
import javax.inject.Inject;
import javax.inject.Provider;
import org.jclouds.ovf.OperatingSystemSection;
import org.xml.sax.Attributes;
/**
* @author Adrian Cole
*/
public class OperatingSystemSectionHandler extends ParseSax.HandlerWithResult<OperatingSystemSection> {
private StringBuilder currentText = new StringBuilder();
protected Integer id;
protected String info;
protected String description;
public OperatingSystemSection getResult() {
OperatingSystemSection system = new OperatingSystemSection(id, info, description);
id = null;
info = null;
description = null;
return system;
public class OperatingSystemSectionHandler extends
SectionHandler<OperatingSystemSection, OperatingSystemSection.Builder> {
@Inject
public OperatingSystemSectionHandler(Provider<OperatingSystemSection.Builder> builderProvider) {
super(builderProvider);
}
@Override
@ -52,21 +46,17 @@ public class OperatingSystemSectionHandler extends ParseSax.HandlerWithResult<Op
Map<String, String> attributes = cleanseAttributes(attrs);
if (equalsOrSuffix(qName, "OperatingSystemSection")) {
if (attributes.containsKey("id"))
this.id = Integer.parseInt(attributes.get("id"));
builder.id(Integer.parseInt(attributes.get("id")));
}
}
@Override
public void endElement(String uri, String localName, String qName) {
if (equalsOrSuffix(qName, "Info")) {
this.info = currentOrNull(currentText);
builder.info(currentOrNull(currentText));
} else if (equalsOrSuffix(qName, "Description")) {
this.description = currentOrNull(currentText);
builder.description(currentOrNull(currentText));
}
currentText = new StringBuilder();
}
public void characters(char ch[], int start, int length) {
currentText.append(ch, start, length);
super.endElement(uri, localName, qName);
}
}

View File

@ -1,87 +0,0 @@
/**
*
* 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.vdc/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.vcloud.util.Utils.cleanseAttributes;
import javax.inject.Inject;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.ovf.OvfEnvelope;
import org.jclouds.ovf.VirtualSystem;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
/**
* @author Adrian Cole
*/
public class OvfEnvelopeHandler extends ParseSax.HandlerWithResult<OvfEnvelope> {
protected final VirtualSystemHandler virtualSystemHandler;
@Inject
public OvfEnvelopeHandler(VirtualSystemHandler virtualSystemHandler) {
this.virtualSystemHandler = virtualSystemHandler;
}
protected StringBuilder currentText = new StringBuilder();
private VirtualSystem virtualSystem;
private boolean inVirtualSystem;
public OvfEnvelope getResult() {
return new OvfEnvelope(virtualSystem);
}
@Override
public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
// Map<String, String> attributes = cleanseAttributes(attrs);
if (qName.endsWith("VirtualSystem")) {
inVirtualSystem = true;
}
if (inVirtualSystem) {
virtualSystemHandler.startElement(uri, localName, qName, attrs);
}
}
public void endElement(String uri, String name, String qName) {
if (qName.endsWith("VirtualSystem")) {
inVirtualSystem = false;
virtualSystem = virtualSystemHandler.getResult();
}
if (inVirtualSystem) {
virtualSystemHandler.endElement(uri, name, qName);
}
currentText = new StringBuilder();
}
public void characters(char ch[], int start, int length) {
if (inVirtualSystem)
virtualSystemHandler.characters(ch, start, length);
else
currentText.append(ch, start, length);
}
protected String currentOrNull() {
String returnVal = currentText.toString().trim();
return returnVal.equals("") ? null : returnVal;
}
}

View File

@ -0,0 +1,76 @@
/**
*
* 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 javax.inject.Provider;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.ovf.Section;
import org.jclouds.ovf.Section.Builder;
/**
* @author Adrian Cole
*/
public class SectionHandler<T extends Section<T>, B extends Section.Builder<T>> extends ParseSax.HandlerWithResult<T> {
@SuppressWarnings("unchecked")
public static SectionHandler create() {
return new SectionHandler(new Provider<Section.Builder>() {
@Override
public Builder get() {
return new Section.Builder();
}
});
}
protected final Provider<? extends Section.Builder<T>> builderProvider;
protected StringBuilder currentText = new StringBuilder();
protected B builder;
public SectionHandler(Provider<B> builderProvider) {
this.builderProvider = builderProvider;
this.builder = builderProvider.get();
}
@SuppressWarnings("unchecked")
public T getResult() {
try {
return (T) builder.build();
} finally {
builder = (B) builderProvider.get();
}
}
@Override
public void endElement(String uri, String localName, String qName) {
if (equalsOrSuffix(qName, "Info")) {
builder.info(currentOrNull(currentText));
}
currentText = new StringBuilder();
}
public void characters(char ch[], int start, int length) {
currentText.append(ch, start, length);
}
}

View File

@ -19,53 +19,53 @@
package org.jclouds.ovf.xml;
import java.util.Set;
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.Inject;
import javax.inject.Provider;
import org.jclouds.cim.ResourceAllocationSettingData;
import org.jclouds.cim.VirtualSystemSettingData;
import org.jclouds.cim.xml.ResourceAllocationSettingDataHandler;
import org.jclouds.cim.xml.VirtualSystemSettingDataHandler;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.ovf.VirtualHardwareSection;
import org.xml.sax.Attributes;
import com.google.common.collect.Sets;
import com.google.common.base.Splitter;
/**
* @author Adrian Cole
*/
public class VirtualHardwareSectionHandler extends ParseSax.HandlerWithResult<VirtualHardwareSection> {
protected StringBuilder currentText = new StringBuilder();
public class VirtualHardwareSectionHandler extends
SectionHandler<VirtualHardwareSection, VirtualHardwareSection.Builder> {
private final VirtualSystemSettingDataHandler systemHandler;
private final ResourceAllocationSettingDataHandler allocationHandler;
@Inject
public VirtualHardwareSectionHandler(VirtualSystemSettingDataHandler systemHandler,
ResourceAllocationSettingDataHandler allocationHandler) {
public VirtualHardwareSectionHandler(Provider<VirtualHardwareSection.Builder> builderProvider,
VirtualSystemSettingDataHandler systemHandler, ResourceAllocationSettingDataHandler allocationHandler) {
super(builderProvider);
this.systemHandler = systemHandler;
this.allocationHandler = allocationHandler;
}
private String info;
protected VirtualSystemSettingData system;
protected Set<ResourceAllocationSettingData> allocations = Sets.newLinkedHashSet();
private boolean inItem;
private boolean inSystem;
public VirtualHardwareSection getResult() {
return new VirtualHardwareSection(info, system, allocations);
}
public void startElement(String uri, String localName, String qName, Attributes attrs) {
if (qName.endsWith("System")) {
Map<String, String> attributes = cleanseAttributes(attrs);
if (equalsOrSuffix(qName, "VirtualHardwareSection")) {
if (attributes.containsKey("transport"))
builder.transports(Splitter.on(' ').split(attributes.get("transport")));
} else if (equalsOrSuffix(qName, "System")) {
inSystem = true;
} else if (!inSystem && qName.endsWith("Item")) {
} else if (!inSystem && equalsOrSuffix(qName, "Item")) {
inItem = true;
}
if (inSystem) {
systemHandler.startElement(uri, localName, qName, attrs);
} else if (inItem) {
@ -75,30 +75,33 @@ public class VirtualHardwareSectionHandler extends ParseSax.HandlerWithResult<Vi
@Override
public void endElement(String uri, String localName, String qName) {
if (qName.endsWith("System")) {
if (equalsOrSuffix(qName, "System")) {
inSystem = false;
system = systemHandler.getResult();
} else if (qName.endsWith("Item")) {
builder.system(systemHandler.getResult());
} else if (equalsOrSuffix(qName, "Item")) {
inItem = false;
allocations.add(allocationHandler.getResult());
builder.resourceAllocation(allocationHandler.getResult());
}
if (inSystem) {
systemHandler.endElement(uri, localName, qName);
} else if (inItem) {
allocationHandler.endElement(uri, localName, qName);
} else if (qName.endsWith("Info")) {
this.info = currentText.toString().trim();
} else {
if (equalsOrSuffix(qName, "Info"))
builder.info(currentOrNull(currentText));
super.endElement(uri, localName, qName);
}
currentText = new StringBuilder();
}
@Override
public void characters(char ch[], int start, int length) {
currentText.append(ch, start, length);
if (inSystem)
if (inSystem) {
systemHandler.characters(ch, start, length);
if (inItem)
} else if (inItem) {
allocationHandler.characters(ch, start, length);
} else {
super.characters(ch, start, length);
}
}
}

View File

@ -20,78 +20,77 @@
package org.jclouds.ovf.xml;
import static org.jclouds.util.SaxUtils.cleanseAttributes;
import static org.jclouds.util.SaxUtils.currentOrNull;
import static org.jclouds.util.SaxUtils.equalsOrSuffix;
import java.util.Map;
import java.util.Set;
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Provider;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.ovf.OperatingSystemSection;
import org.jclouds.ovf.VirtualHardwareSection;
import org.jclouds.ovf.VirtualSystem;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import com.google.common.collect.Sets;
import com.google.common.collect.ImmutableMap;
import com.google.inject.Inject;
/**
* @author Adrian Cole
*/
public class VirtualSystemHandler extends ParseSax.HandlerWithResult<VirtualSystem> {
protected StringBuilder currentText = new StringBuilder();
public class VirtualSystemHandler extends SectionHandler<VirtualSystem, VirtualSystem.Builder> {
private final OperatingSystemSectionHandler osHandler;
private final VirtualHardwareSectionHandler hardwareHandler;
@Inject
public VirtualSystemHandler(OperatingSystemSectionHandler osHandler, VirtualHardwareSectionHandler hardwareHandler) {
public VirtualSystemHandler(Provider<VirtualSystem.Builder> builderProvider,
OperatingSystemSectionHandler osHandler, VirtualHardwareSectionHandler hardwareHandler) {
super(builderProvider);
this.osHandler = osHandler;
this.hardwareHandler = hardwareHandler;
}
protected String id;
protected String info;
protected String name;
protected OperatingSystemSection operatingSystem;
protected Set<VirtualHardwareSection> hardware = Sets.newLinkedHashSet();
@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 inNetwork;
private boolean inGuest;
private boolean inSection;
private boolean inExtensionSection;
public VirtualSystem getResult() {
VirtualSystem vs = new VirtualSystem(id, info, name, operatingSystem, hardware);
id = null;
info = null;
name = null;
operatingSystem = null;
hardware = Sets.newLinkedHashSet();
return vs;
}
public void startElement(String uri, String localName, String qName, Attributes attrs) {
public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
Map<String, String> attributes = cleanseAttributes(attrs);
if (equalsOrSuffix(qName, "VirtualHardwareSection")) {
inHardware = true;
} else if (equalsOrSuffix(qName, "OperatingSystemSection")) {
inOs = true;
} else if (equalsOrSuffix(qName, "NetworkConnectionSection")) {
inNetwork = true;
} else if (equalsOrSuffix(qName, "GuestCustomizationSection")) {
inGuest = 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 (inNetwork) {
// TODO
} else if (inGuest) {
// TODO
} else if (inExtensionSection) {
extensionHandler.startElement(uri, localName, qName, attrs);
} else if (inSection) {
defaultSectionHandler.startElement(uri, localName, qName, attrs);
} else if (equalsOrSuffix(qName, "VirtualSystem")) {
id = attributes.get("id");
builder.id(attributes.get("id"));
}
}
@ -100,42 +99,49 @@ public class VirtualSystemHandler extends ParseSax.HandlerWithResult<VirtualSyst
public void endElement(String uri, String localName, String qName) {
if (equalsOrSuffix(qName, "VirtualHardwareSection")) {
inHardware = false;
hardware.add(hardwareHandler.getResult());
builder.hardwareSection(hardwareHandler.getResult());
} else if (equalsOrSuffix(qName, "OperatingSystemSection")) {
inOs = false;
operatingSystem = osHandler.getResult();
} else if (equalsOrSuffix(qName, "NetworkConnectionSection")) {
inNetwork = false;
// TODO
} else if (equalsOrSuffix(qName, "GuestCustomizationSection")) {
inNetwork = false;
// TODO
builder.operatingSystemSection(osHandler.getResult());
} else if (extensionHandlers.containsKey(qName)) {
builder.additionalSection(extensionHandler.getResult());
inExtensionSection = false;
} else if (qName.endsWith("Section")) {
builder.additionalSection(defaultSectionHandler.getResult());
inSection = false;
}
if (inHardware) {
hardwareHandler.endElement(uri, localName, qName);
} else if (inOs) {
osHandler.endElement(uri, localName, qName);
} else if (inNetwork) {
// TODO
} else if (inGuest) {
// TODO
} else if (equalsOrSuffix(qName, "Info")) {
info = currentText.toString().trim();
} 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")) {
name = currentText.toString().trim();
builder.name(currentOrNull(currentText));
}
super.endElement(uri, localName, qName);
}
currentText = new StringBuilder();
}
@Override
public void characters(char ch[], int start, int length) {
if (inHardware)
if (inHardware) {
hardwareHandler.characters(ch, start, length);
else if (inOs)
} else if (inOs) {
osHandler.characters(ch, start, length);
else
currentText.append(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

@ -75,8 +75,8 @@ public class VirtualSystemSettingDataHandlerTest extends BaseHandlerTest {
assertEquals(result.getId(), "Ubuntu1004");
assertEquals(result.getName(), "Ubuntu1004");
assertEquals(result.getInfo(), "A virtual machine:");
checkHardware(Iterables.get(result.getHardware(), 0));
checkOs(result.getOperatingSystem());
checkHardware(Iterables.get(result.getVirtualHardwareSections(), 0));
checkOs(result.getOperatingSystemSection());
}
@Test(enabled = false)

View File

@ -0,0 +1,61 @@
/**
*
* 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 java.net.URI;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.http.functions.ParseSax.Factory;
import org.jclouds.http.functions.config.SaxParserModule;
import org.jclouds.ovf.Disk;
import org.jclouds.ovf.DiskSection;
import org.testng.annotations.Test;
import com.google.inject.Guice;
import com.google.inject.Injector;
/**
* Tests behavior of {@code DiskSectionHandler}
*
* @author Adrian Cole
*/
@Test(groups = "unit")
public class DiskSectionHandlerTest {
public void test() {
InputStream is = getClass().getResourceAsStream("/disksection.xml");
Injector injector = Guice.createInjector(new SaxParserModule());
Factory factory = injector.getInstance(ParseSax.Factory.class);
DiskSection result = factory.create(injector.getInstance(DiskSectionHandler.class)).parse(is);
assertEquals(result.toString(), DiskSection.builder().info("Describes the set of virtual disks").disk(
Disk.builder().id("vmdisk1")
.fileRef("file1").capacity(8589934592l).populatedSize(3549324972l).format(
URI.create("http://www.vmware.com/interfaces/specifications/vmdk.html#sparse")).build()).disk(
Disk.builder().id("vmdisk2").capacity(536870912l).build()).disk(
Disk.builder().id("vmdisk3").capacityAllocationUnits("byte * 2^30").build())
.build().toString()
);
}
}

View File

@ -25,29 +25,28 @@ import org.jclouds.cim.xml.VirtualSystemSettingDataHandlerTest;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.http.functions.ParseSax.Factory;
import org.jclouds.http.functions.config.SaxParserModule;
import org.jclouds.ovf.OvfEnvelope;
import org.jclouds.ovf.xml.OvfEnvelopeHandler;
import org.jclouds.ovf.Envelope;
import org.testng.annotations.Test;
import com.google.inject.Guice;
import com.google.inject.Injector;
/**
* Tests behavior of {@code OvfEnvelopeHandler}
* Tests behavior of {@code EnvelopeHandler}
*
* @author Adrian Cole
*/
@Test(groups = "unit")
public class OvfEnvelopeHandlerTest {
public class EnvelopeHandlerTest {
public void testVCloud1_0() {
InputStream is = getClass().getResourceAsStream("/ovf.xml");
Injector injector = Guice.createInjector(new SaxParserModule());
Factory factory = injector.getInstance(ParseSax.Factory.class);
OvfEnvelope result = factory.create(injector.getInstance(OvfEnvelopeHandler.class)).parse(is);
Envelope result = factory.create(injector.getInstance(EnvelopeHandler.class)).parse(is);
checkOvfEnvelope(result);
}
static void checkOvfEnvelope(OvfEnvelope result) {
static void checkOvfEnvelope(Envelope result) {
VirtualSystemSettingDataHandlerTest.checkVirtualSystem(result.getVirtualSystem());
}

View File

@ -0,0 +1,58 @@
/**
*
* 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.Network;
import org.jclouds.ovf.NetworkSection;
import org.testng.annotations.Test;
import com.google.inject.Guice;
import com.google.inject.Injector;
/**
* Tests behavior of {@code NetworkSectionHandler}
*
* @author Adrian Cole
*/
@Test(groups = "unit")
public class NetworkSectionHandlerTest {
public void test() {
InputStream is = getClass().getResourceAsStream("/networksection.xml");
Injector injector = Guice.createInjector(new SaxParserModule());
Factory factory = injector.getInstance(ParseSax.Factory.class);
NetworkSection result = factory.create(injector.getInstance(NetworkSectionHandler.class)).parse(is);
assertEquals(result.toString(), NetworkSection.builder().info("List of logical networks used in the package")
.network(
Network.builder().name("red").description("The network the Red service is available on")
.build()).network(
Network.builder().name("blue").description("The network the Blue service is available on")
.build())
.build().toString()
);
}
}

View File

@ -0,0 +1,53 @@
/**
*
* 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.OperatingSystemSection;
import org.testng.annotations.Test;
import com.google.inject.Guice;
import com.google.inject.Injector;
/**
* Tests behavior of {@code OperatingSystemSectionHandler}
*
* @author Adrian Cole
*/
@Test(groups = "unit")
public class OperatingSystemSectionHandlerTest {
public void test() {
InputStream is = getClass().getResourceAsStream("/operatingsystemsection.xml");
Injector injector = Guice.createInjector(new SaxParserModule());
Factory factory = injector.getInstance(ParseSax.Factory.class);
OperatingSystemSection result = factory.create(injector.getInstance(OperatingSystemSectionHandler.class)).parse(
is);
assertEquals(result.toString(), OperatingSystemSection.builder().info("Specifies the operating system installed")
.description("Microsoft Windows Server 2008").id(76).build().toString()
);
}
}

View File

@ -0,0 +1,10 @@
<DiskSection>
<Info>Describes the set of virtual disks</Info>
<Disk ovf:diskId="vmdisk1" ovf:fileRef="file1" ovf:capacity="8589934592"
ovf:populatedSize="3549324972"
ovf:format="http://www.vmware.com/interfaces/specifications/vmdk.html#sparse">
</Disk>
<Disk ovf:diskId="vmdisk2" ovf:capacity="536870912" />
<Disk ovf:diskId="vmdisk3" ovf:capacity="${disk.size}"
ovf:capacityAllocationUnits="byte * 2^30" />
</DiskSection>

View File

@ -0,0 +1,11 @@
<NetworkSection>
<Info>List of logical networks used in the package</Info>
<Network ovf:name="red">
<Description>The network the Red service is available on
</Description>
</Network>
<Network ovf:name="blue">
<Description>The network the Blue service is available on
</Description>
</Network>
</NetworkSection>

View File

@ -0,0 +1,4 @@
<OperatingSystemSection ovf:id="76">
<Info>Specifies the operating system installed</Info>
<Description>Microsoft Windows Server 2008</Description>
</OperatingSystemSection>

View File

@ -132,7 +132,7 @@ public class CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptions
credentialsMap.put(key, pair);
} else {
if (hasPublicKeyMaterial.apply(options)) {
logger.warn("to avoid creating extra keys in aws-ec2, use templateOption overrideLoginCredentialWith(id_rsa)");
logger.warn("to avoid creating temporary keys in aws-ec2, use templateOption overrideLoginCredentialWith(id_rsa)");
}
return createUniqueKeyPairAndPutIntoMap(region, group);
}

View File

@ -1,209 +0,0 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <name@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.cim.OSType;
import org.jclouds.compute.domain.OsFamily;
/**
* Savvis Operating System Specification
*
* @see <a href="https://api.sandbox.symphonyvpdc.savvis.net/doc/spec/api/addSingleVM.html" />
* @author Adrian Cole
*/
public class SavvisOperatingSystemSpecification {
public static Builder builder() {
return new Builder();
}
public static class Builder {
private int savvisId;
private int typeId;
private String name;
private OsFamily family;
private String description;
private boolean supportedBySavvis;
/**
* @see SavvisOperatingSystemSpecification#getSavvisId
*/
public Builder savvisId(int savvisId) {
this.savvisId = savvisId;
return this;
}
/**
* @see SavvisOperatingSystemSpecification#getTypeId
*/
public Builder typeId(int typeId) {
this.typeId = typeId;
return this;
}
/**
* @see SavvisOperatingSystemSpecification#getOsFamily
*/
public Builder family(OsFamily family) {
this.family = family;
return this;
}
/**
* @see SavvisOperatingSystemSpecification#getInfo
*/
public Builder name(String name) {
this.name = name;
return this;
}
/**
* @see SavvisOperatingSystemSpecification#getDescription
*/
public Builder description(String description) {
this.description = description;
return this;
}
/**
* @see SavvisOperatingSystemSpecification#isSupportedBySavvis
*/
public Builder supportedBySavvis(boolean supportedBySavvis) {
this.supportedBySavvis = supportedBySavvis;
return this;
}
public SavvisOperatingSystemSpecification build() {
return new SavvisOperatingSystemSpecification(savvisId, typeId, family, name, description, supportedBySavvis);
}
public Builder fromSavvisOperatingSystemSpecification(SavvisOperatingSystemSpecification in) {
return savvisId(in.getSavvisId()).typeId(in.getTypeId()).family(in.getFamily()).name(in.getName())
.description(in.getDescription()).supportedBySavvis(in.isSupportedBySavvis());
}
}
private final int savvisId;
private final int typeId;
private final OsFamily family;
private final String name;
private final String description;
private final boolean supportedBySavvis;
public SavvisOperatingSystemSpecification(int savvisId, int typeId, OsFamily family, String name,
String description, boolean supportedBySavvis) {
this.savvisId = savvisId;
this.typeId = typeId;
this.family = family;
this.name = name;
this.description = description;
this.supportedBySavvis = supportedBySavvis;
}
/**
* @return Internal name used by Savvis
*/
public int getSavvisId() {
return savvisId;
}
/**
*
* @return CIM OS Type Id
* @see OSType#getCode()
*/
public int getTypeId() {
return typeId;
}
/**
*
* @return the name of the OS
*/
public String getName() {
return name;
}
/**
*
* @return the operating system family
*/
public OsFamily getFamily() {
return family;
}
/**
*
* @return description
*/
public String getDescription() {
return description;
}
/**
*
* @return whether or not this operating system is supported by Savvis
*/
public boolean isSupportedBySavvis() {
return supportedBySavvis;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((name == null) ? 0 : name.hashCode());
result = prime * result + typeId;
result = prime * result + savvisId;
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
SavvisOperatingSystemSpecification other = (SavvisOperatingSystemSpecification) obj;
if (name == null) {
if (other.name != null)
return false;
} else if (!name.equals(other.name))
return false;
if (typeId != other.typeId)
return false;
if (savvisId != other.savvisId)
return false;
return true;
}
public Builder toBuilder() {
return builder().fromSavvisOperatingSystemSpecification(this);
}
@Override
public String toString() {
return String.format("[description=%s, family=%s, name=%s, typeId=%s, savvisId=%s, supportedBySavvis=%s]",
description, family, name, typeId, savvisId, supportedBySavvis);
}
}

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.vapp;
/**