diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudClient.java b/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudClient.java index 737ea3d42c..c6c800f2df 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudClient.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudClient.java @@ -46,6 +46,8 @@ import org.jclouds.vcloud.domain.Task; import org.jclouds.vcloud.domain.TasksList; import org.jclouds.vcloud.domain.VDC; import org.jclouds.vcloud.filters.SetVCloudTokenCookie; +import org.jclouds.vcloud.terremark.domain.VApp; +import org.jclouds.vcloud.terremark.xml.TerremarkVAppHandler; import org.jclouds.vcloud.xml.CatalogHandler; import org.jclouds.vcloud.xml.TaskHandler; import org.jclouds.vcloud.xml.TasksListHandler; @@ -148,13 +150,7 @@ public interface VCloudClient { @GET @Consumes(VAPP_XML) - // TODO parse - String getVApp(@Endpoint URI vApp); - - // - // @GET - // @Endpoint(vDC.class) - // public Set getvDCs(); - // + @XMLResponseParser(TerremarkVAppHandler.class) + Future getVApp(@Endpoint URI vApp); } diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/domain/ResourceType.java b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/ResourceType.java new file mode 100644 index 0000000000..a49778b7c7 --- /dev/null +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/ResourceType.java @@ -0,0 +1,59 @@ +package org.jclouds.vcloud.domain; + +import static com.google.common.base.Preconditions.checkNotNull; + +import org.jclouds.vcloud.VCloudClient; + +/** + * + * VirtualResource such as disks or CPU + * + * @author Adrian Cole + * @see VCloudClient#getVApp + * + * + */ +public enum ResourceType { + + VIRTUAL_CPU, + + MEMORY, + + SCSI_CONTROLLER, + + VIRTUAL_DISK; + + public String value() { + switch (this) { + case VIRTUAL_CPU: + return "3"; + case MEMORY: + return "4"; + case SCSI_CONTROLLER: + return "6"; + case VIRTUAL_DISK: + return "17"; + default: + throw new IllegalArgumentException("invalid type:" + this); + } + } + + public static ResourceType fromValue(String type) { + return fromValue(Integer.parseInt(checkNotNull(type, "type"))); + } + + public static ResourceType fromValue(int v) { + switch (v) { + case 3: + return VIRTUAL_CPU; + case 4: + return MEMORY; + case 6: + return SCSI_CONTROLLER; + case 17: + return VIRTUAL_DISK; + default: + throw new IllegalArgumentException("invalid type:" + v); + } + } +} \ No newline at end of file diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/domain/VAppStatus.java b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/VAppStatus.java new file mode 100644 index 0000000000..2565e638f3 --- /dev/null +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/VAppStatus.java @@ -0,0 +1,64 @@ +/** + * + * Copyright (C) 2009 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * ==================================================================== + */ +package org.jclouds.vcloud.domain; + +import static com.google.common.base.Preconditions.checkNotNull; + +/** + * @author Adrian Cole + */ +public enum VAppStatus { + CREATING, OFF, ON; + + public String value() { + switch (this) { + case CREATING: + return "0"; + case OFF: + return "2"; + case ON: + return "4"; + default: + throw new IllegalArgumentException("invalid status:" + this); + } + } + + public static VAppStatus fromValue(String status) { + return fromValue(Integer.parseInt(checkNotNull(status, "status"))); + } + + public static VAppStatus fromValue(int v) { + switch (v) { + case 0: + return CREATING; + case 2: + return OFF; + case 4: + return ON; + default: + throw new IllegalArgumentException("invalid status:" + v); + } + } + +} \ No newline at end of file diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/terremark/domain/ResourceAllocation.java b/vcloud/core/src/main/java/org/jclouds/vcloud/terremark/domain/ResourceAllocation.java new file mode 100644 index 0000000000..bf6f3b0064 --- /dev/null +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/terremark/domain/ResourceAllocation.java @@ -0,0 +1,348 @@ +/** + * + * Copyright (C) 2009 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * ==================================================================== + */ +package org.jclouds.vcloud.terremark.domain; + +import static com.google.common.base.Preconditions.checkNotNull; + +/** + * @author Adrian Cole + */ +public class ResourceAllocation implements Comparable { + private final Integer address; + private final Integer addressOnParent; + private final String allocationUnits; + private final String automaticAllocation; + private final String automaticDeallocation; + private final String caption; + private final String consumerVisibility; + private final String description; + private final String elementName; + private final String hostResource; + private final int instanceID; + private final String limit; + private final String mappingBehavior; + private final String otherResourceType; + private final Integer parent; + private final String poolID; + private final String reservation; + private final String resourceSubType; + private final ResourceType resourceType; + private final long virtualQuantity; + private final String virtualQuantityUnits; + private final String weight; + + public ResourceAllocation(Integer address, Integer addressOnParent, String allocationUnits, + String automaticAllocation, String automaticDeallocation, String caption, + String consumerVisibility, String description, String elementName, String hostResource, + int instanceID, String limit, String mappingBehavior, String otherResourceType, + Integer parent, String poolID, String reservation, String resourceSubType, + ResourceType resourceType, long virtualQuantity, String virtualQuantityUnits, + String weight) { + this.address = address; + this.addressOnParent = addressOnParent; + this.allocationUnits = allocationUnits; + this.automaticAllocation = automaticAllocation; + this.automaticDeallocation = automaticDeallocation; + this.caption = caption; + this.consumerVisibility = consumerVisibility; + this.description = description; + this.elementName = elementName; + this.hostResource = hostResource; + this.instanceID = checkNotNull(instanceID, "instanceID"); + this.limit = limit; + this.mappingBehavior = mappingBehavior; + this.otherResourceType = otherResourceType; + this.parent = parent; + this.poolID = poolID; + this.reservation = reservation; + this.resourceSubType = resourceSubType; + this.resourceType = checkNotNull(resourceType, "resourceType"); + this.virtualQuantity = virtualQuantity; + this.virtualQuantityUnits = virtualQuantityUnits; + this.weight = weight; + } + + public Integer getAddress() { + return address; + } + + public Integer getAddressOnParent() { + return addressOnParent; + } + + public String getAllocationUnits() { + return allocationUnits; + } + + public String getAutomaticAllocation() { + return automaticAllocation; + } + + public String getAutomaticDeallocation() { + return automaticDeallocation; + } + + public String getCaption() { + return caption; + } + + public String getConsumerVisibility() { + return consumerVisibility; + } + + public String getDescription() { + return description; + } + + public String getElementName() { + return elementName; + } + + public int getInstanceID() { + return instanceID; + } + + public String getLimit() { + return limit; + } + + public String getMappingBehavior() { + return mappingBehavior; + } + + public String getOtherResourceType() { + return otherResourceType; + } + + public Integer getParent() { + return parent; + } + + public String getPoolID() { + return poolID; + } + + public String getReservation() { + return reservation; + } + + public String getResourceSubType() { + return resourceSubType; + } + + public ResourceType getResourceType() { + return resourceType; + } + + public long getVirtualQuantity() { + return virtualQuantity; + } + + public String getVirtualQuantityUnits() { + return virtualQuantityUnits; + } + + public String getWeight() { + return weight; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((address == null) ? 0 : address.hashCode()); + result = prime * result + ((addressOnParent == null) ? 0 : addressOnParent.hashCode()); + result = prime * result + ((allocationUnits == null) ? 0 : allocationUnits.hashCode()); + result = prime * result + + ((automaticAllocation == null) ? 0 : automaticAllocation.hashCode()); + result = prime * result + + ((automaticDeallocation == null) ? 0 : automaticDeallocation.hashCode()); + result = prime * result + ((caption == null) ? 0 : caption.hashCode()); + result = prime * result + ((consumerVisibility == null) ? 0 : consumerVisibility.hashCode()); + result = prime * result + ((description == null) ? 0 : description.hashCode()); + result = prime * result + ((elementName == null) ? 0 : elementName.hashCode()); + result = prime * result + instanceID; + result = prime * result + ((limit == null) ? 0 : limit.hashCode()); + result = prime * result + ((mappingBehavior == null) ? 0 : mappingBehavior.hashCode()); + result = prime * result + ((otherResourceType == null) ? 0 : otherResourceType.hashCode()); + result = prime * result + ((parent == null) ? 0 : parent.hashCode()); + result = prime * result + ((poolID == null) ? 0 : poolID.hashCode()); + result = prime * result + ((reservation == null) ? 0 : reservation.hashCode()); + result = prime * result + ((resourceSubType == null) ? 0 : resourceSubType.hashCode()); + result = prime * result + ((resourceType == null) ? 0 : resourceType.hashCode()); + result = prime * result + (int) (virtualQuantity ^ (virtualQuantity >>> 32)); + result = prime * result + + ((virtualQuantityUnits == null) ? 0 : virtualQuantityUnits.hashCode()); + result = prime * result + ((weight == null) ? 0 : weight.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; + ResourceAllocation other = (ResourceAllocation) obj; + if (address == null) { + if (other.address != null) + return false; + } else if (!address.equals(other.address)) + return false; + if (addressOnParent == null) { + if (other.addressOnParent != null) + return false; + } else if (!addressOnParent.equals(other.addressOnParent)) + return false; + if (allocationUnits == null) { + if (other.allocationUnits != null) + return false; + } else if (!allocationUnits.equals(other.allocationUnits)) + return false; + if (automaticAllocation == null) { + if (other.automaticAllocation != null) + return false; + } else if (!automaticAllocation.equals(other.automaticAllocation)) + return false; + if (automaticDeallocation == null) { + if (other.automaticDeallocation != null) + return false; + } else if (!automaticDeallocation.equals(other.automaticDeallocation)) + return false; + if (caption == null) { + if (other.caption != null) + return false; + } else if (!caption.equals(other.caption)) + return false; + if (consumerVisibility == null) { + if (other.consumerVisibility != null) + return false; + } else if (!consumerVisibility.equals(other.consumerVisibility)) + return false; + if (description == null) { + if (other.description != null) + return false; + } else if (!description.equals(other.description)) + return false; + if (elementName == null) { + if (other.elementName != null) + return false; + } else if (!elementName.equals(other.elementName)) + return false; + if (instanceID != other.instanceID) + return false; + if (limit == null) { + if (other.limit != null) + return false; + } else if (!limit.equals(other.limit)) + return false; + if (mappingBehavior == null) { + if (other.mappingBehavior != null) + return false; + } else if (!mappingBehavior.equals(other.mappingBehavior)) + return false; + if (otherResourceType == null) { + if (other.otherResourceType != null) + return false; + } else if (!otherResourceType.equals(other.otherResourceType)) + return false; + if (parent == null) { + if (other.parent != null) + return false; + } else if (!parent.equals(other.parent)) + return false; + if (poolID == null) { + if (other.poolID != null) + return false; + } else if (!poolID.equals(other.poolID)) + return false; + if (reservation == null) { + if (other.reservation != null) + return false; + } else if (!reservation.equals(other.reservation)) + return false; + if (resourceSubType == null) { + if (other.resourceSubType != null) + return false; + } else if (!resourceSubType.equals(other.resourceSubType)) + return false; + if (resourceType == null) { + if (other.resourceType != null) + return false; + } else if (!resourceType.equals(other.resourceType)) + return false; + if (virtualQuantity != other.virtualQuantity) + return false; + if (virtualQuantityUnits == null) { + if (other.virtualQuantityUnits != null) + return false; + } else if (!virtualQuantityUnits.equals(other.virtualQuantityUnits)) + return false; + if (weight == null) { + if (other.weight != null) + return false; + } else if (!weight.equals(other.weight)) + return false; + return true; + } + + @Override + public String toString() { + return "ResourceAllocation [address=" + address + ", addressOnParent=" + addressOnParent + + ", allocationUnits=" + allocationUnits + ", automaticAllocation=" + + automaticAllocation + ", automaticDeallocation=" + automaticDeallocation + + ", caption=" + caption + ", consumerVisibility=" + consumerVisibility + + ", description=" + description + ", elementName=" + elementName + ", instanceID=" + + instanceID + ", limit=" + limit + ", mappingBehavior=" + mappingBehavior + + ", otherResourceType=" + otherResourceType + ", parent=" + parent + ", poolID=" + + poolID + ", reservation=" + reservation + ", resourceSubType=" + resourceSubType + + ", resourceType=" + resourceType + ", virtualQuantity=" + virtualQuantity + + ", virtualQuantityUnits=" + virtualQuantityUnits + ", weight=" + weight + "]"; + } + + public int compareTo(ResourceAllocation that) { + final int BEFORE = -1; + final int EQUAL = 0; + final int AFTER = 1; + + if (this == that) + return EQUAL; + + int comparison = this.resourceType.compareTo(that.resourceType); + if (comparison != EQUAL) + return comparison; + + if (this.instanceID < that.instanceID) + return BEFORE; + if (this.instanceID > that.instanceID) + return AFTER; + return EQUAL; + } + + public String getHostResource() { + return hostResource; + } +} \ No newline at end of file diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/terremark/domain/ResourceType.java b/vcloud/core/src/main/java/org/jclouds/vcloud/terremark/domain/ResourceType.java new file mode 100644 index 0000000000..eac072b6dc --- /dev/null +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/terremark/domain/ResourceType.java @@ -0,0 +1,59 @@ +package org.jclouds.vcloud.terremark.domain; + +import static com.google.common.base.Preconditions.checkNotNull; + +import org.jclouds.vcloud.VCloudClient; + +/** + * + * VirtualResource such as disks or CPU + * + * @author Adrian Cole + * @see VCloudClient#getVApp + * + * + */ +public enum ResourceType { + + VIRTUAL_CPU, + + MEMORY, + + SCSI_CONTROLLER, + + VIRTUAL_DISK; + + public String value() { + switch (this) { + case VIRTUAL_CPU: + return "3"; + case MEMORY: + return "4"; + case SCSI_CONTROLLER: + return "6"; + case VIRTUAL_DISK: + return "17"; + default: + throw new IllegalArgumentException("invalid type:" + this); + } + } + + public static ResourceType fromValue(String type) { + return fromValue(Integer.parseInt(checkNotNull(type, "type"))); + } + + public static ResourceType fromValue(int v) { + switch (v) { + case 3: + return VIRTUAL_CPU; + case 4: + return MEMORY; + case 6: + return SCSI_CONTROLLER; + case 17: + return VIRTUAL_DISK; + default: + throw new IllegalArgumentException("invalid type:" + v); + } + } +} \ No newline at end of file diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/terremark/domain/VApp.java b/vcloud/core/src/main/java/org/jclouds/vcloud/terremark/domain/VApp.java index 5f393c891e..d8acea370a 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/terremark/domain/VApp.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/terremark/domain/VApp.java @@ -23,10 +23,16 @@ */ package org.jclouds.vcloud.terremark.domain; +import java.net.InetAddress; +import java.util.Map; +import java.util.SortedSet; + import org.jclouds.rest.domain.Link; import org.jclouds.rest.domain.NamedLink; +import org.jclouds.vcloud.domain.VAppStatus; import org.jclouds.vcloud.terremark.domain.internal.VAppImpl; +import com.google.common.collect.ListMultimap; import com.google.inject.ImplementedBy; /** @@ -35,10 +41,24 @@ import com.google.inject.ImplementedBy; @ImplementedBy(VAppImpl.class) public interface VApp extends NamedLink { - int getStatus(); + VAppStatus getStatus(); - int getSize(); + long getSize(); Link getVDC(); + Link getComputeOptions(); + + Link getCustomizationOptions(); + + ListMultimap getNetworkToAddresses(); + + String getOperatingSystemDescription(); + + VirtualSystem getSystem(); + + SortedSet getResourceAllocations(); + + Map getResourceAllocationByType(); + } \ No newline at end of file diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/terremark/domain/VirtualSystem.java b/vcloud/core/src/main/java/org/jclouds/vcloud/terremark/domain/VirtualSystem.java new file mode 100644 index 0000000000..b1d6b5e8f9 --- /dev/null +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/terremark/domain/VirtualSystem.java @@ -0,0 +1,330 @@ +/** + * + * Copyright (C) 2009 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * ==================================================================== + */ +package org.jclouds.vcloud.terremark.domain; + +import org.joda.time.DateTime; + +/** + * @author Adrian Cole + */ +public class VirtualSystem { + + private final String automaticRecoveryAction; + private final String automaticShutdownAction; + private final String automaticStartupAction; + private final String automaticStartupActionDelay; + private final String automaticStartupActionSequenceNumber; + private final String caption; + private final String configurationDataRoot; + private final String configurationFile; + private final String configurationID; + private final DateTime creationTime; + private final String description; + private final String elementName; + private final int instanceID; + private final String logDataRoot; + private final String recoveryFile; + private final String snapshotDataRoot; + private final String suspendDataRoot; + private final String swapFileDataRoot; + private final String virtualSystemIdentifier; + private final String virtualSystemType; + + public VirtualSystem(String automaticRecoveryAction, String automaticShutdownAction, + String automaticStartupAction, String automaticStartupActionDelay, + String automaticStartupActionSequenceNumber, String caption, + String configurationDataRoot, String configurationFile, String configurationID, + DateTime creationTime, String description, String elementName, int instanceID, + String logDataRoot, String recoveryFile, String snapshotDataRoot, + String suspendDataRoot, String swapFileDataRoot, String virtualSystemIdentifier, + String virtualSystemType) { + this.automaticRecoveryAction = automaticRecoveryAction; + this.automaticShutdownAction = automaticShutdownAction; + this.automaticStartupAction = automaticStartupAction; + this.automaticStartupActionDelay = automaticStartupActionDelay; + this.automaticStartupActionSequenceNumber = automaticStartupActionSequenceNumber; + this.caption = caption; + this.configurationDataRoot = configurationDataRoot; + this.configurationFile = configurationFile; + this.configurationID = configurationID; + this.creationTime = creationTime; + this.description = description; + this.elementName = elementName; + this.instanceID = instanceID; + this.logDataRoot = logDataRoot; + this.recoveryFile = recoveryFile; + this.snapshotDataRoot = snapshotDataRoot; + this.suspendDataRoot = suspendDataRoot; + this.swapFileDataRoot = swapFileDataRoot; + this.virtualSystemIdentifier = virtualSystemIdentifier; + this.virtualSystemType = virtualSystemType; + } + + public String getAutomaticRecoveryAction() { + return automaticRecoveryAction; + } + + public String getAutomaticShutdownAction() { + return automaticShutdownAction; + } + + public String getAutomaticStartupAction() { + return automaticStartupAction; + } + + public String getAutomaticStartupActionDelay() { + return automaticStartupActionDelay; + } + + public String getAutomaticStartupActionSequenceNumber() { + return automaticStartupActionSequenceNumber; + } + + public String getCaption() { + return caption; + } + + public String getConfigurationDataRoot() { + return configurationDataRoot; + } + + public String getConfigurationFile() { + return configurationFile; + } + + public String getConfigurationID() { + return configurationID; + } + + public DateTime getCreationTime() { + return creationTime; + } + + public String getDescription() { + return description; + } + + public String getElementName() { + return elementName; + } + + public int getInstanceID() { + return instanceID; + } + + public String getLogDataRoot() { + return logDataRoot; + } + + public String getRecoveryFile() { + return recoveryFile; + } + + public String getSnapshotDataRoot() { + return snapshotDataRoot; + } + + public String getSuspendDataRoot() { + return suspendDataRoot; + } + + public String getSwapFileDataRoot() { + return swapFileDataRoot; + } + + public String getVirtualSystemIdentifier() { + return virtualSystemIdentifier; + } + + public String getVirtualSystemType() { + return virtualSystemType; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + + ((automaticRecoveryAction == null) ? 0 : automaticRecoveryAction.hashCode()); + result = prime * result + + ((automaticShutdownAction == null) ? 0 : automaticShutdownAction.hashCode()); + result = prime * result + + ((automaticStartupAction == null) ? 0 : automaticStartupAction.hashCode()); + result = prime + * result + + ((automaticStartupActionDelay == null) ? 0 : automaticStartupActionDelay + .hashCode()); + result = prime + * result + + ((automaticStartupActionSequenceNumber == null) ? 0 + : automaticStartupActionSequenceNumber.hashCode()); + result = prime * result + ((caption == null) ? 0 : caption.hashCode()); + result = prime * result + + ((configurationDataRoot == null) ? 0 : configurationDataRoot.hashCode()); + result = prime * result + ((configurationFile == null) ? 0 : configurationFile.hashCode()); + result = prime * result + ((configurationID == null) ? 0 : configurationID.hashCode()); + result = prime * result + ((creationTime == null) ? 0 : creationTime.hashCode()); + result = prime * result + ((description == null) ? 0 : description.hashCode()); + result = prime * result + ((elementName == null) ? 0 : elementName.hashCode()); + result = prime * result + instanceID; + result = prime * result + ((logDataRoot == null) ? 0 : logDataRoot.hashCode()); + result = prime * result + ((recoveryFile == null) ? 0 : recoveryFile.hashCode()); + result = prime * result + ((snapshotDataRoot == null) ? 0 : snapshotDataRoot.hashCode()); + result = prime * result + ((suspendDataRoot == null) ? 0 : suspendDataRoot.hashCode()); + result = prime * result + ((swapFileDataRoot == null) ? 0 : swapFileDataRoot.hashCode()); + result = prime * result + + ((virtualSystemIdentifier == null) ? 0 : virtualSystemIdentifier.hashCode()); + result = prime * result + ((virtualSystemType == null) ? 0 : virtualSystemType.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + VirtualSystem other = (VirtualSystem) obj; + if (automaticRecoveryAction == null) { + if (other.automaticRecoveryAction != null) + return false; + } else if (!automaticRecoveryAction.equals(other.automaticRecoveryAction)) + return false; + if (automaticShutdownAction == null) { + if (other.automaticShutdownAction != null) + return false; + } else if (!automaticShutdownAction.equals(other.automaticShutdownAction)) + return false; + if (automaticStartupAction == null) { + if (other.automaticStartupAction != null) + return false; + } else if (!automaticStartupAction.equals(other.automaticStartupAction)) + return false; + if (automaticStartupActionDelay == null) { + if (other.automaticStartupActionDelay != null) + return false; + } else if (!automaticStartupActionDelay.equals(other.automaticStartupActionDelay)) + return false; + if (automaticStartupActionSequenceNumber == null) { + if (other.automaticStartupActionSequenceNumber != null) + return false; + } else if (!automaticStartupActionSequenceNumber + .equals(other.automaticStartupActionSequenceNumber)) + return false; + if (caption == null) { + if (other.caption != null) + return false; + } else if (!caption.equals(other.caption)) + return false; + if (configurationDataRoot == null) { + if (other.configurationDataRoot != null) + return false; + } else if (!configurationDataRoot.equals(other.configurationDataRoot)) + return false; + if (configurationFile == null) { + if (other.configurationFile != null) + return false; + } else if (!configurationFile.equals(other.configurationFile)) + return false; + if (configurationID == null) { + if (other.configurationID != null) + return false; + } else if (!configurationID.equals(other.configurationID)) + return false; + if (creationTime == null) { + if (other.creationTime != null) + return false; + } else if (!creationTime.equals(other.creationTime)) + return false; + if (description == null) { + if (other.description != null) + return false; + } else if (!description.equals(other.description)) + return false; + if (elementName == null) { + if (other.elementName != null) + return false; + } else if (!elementName.equals(other.elementName)) + return false; + if (instanceID != other.instanceID) + return false; + if (logDataRoot == null) { + if (other.logDataRoot != null) + return false; + } else if (!logDataRoot.equals(other.logDataRoot)) + return false; + if (recoveryFile == null) { + if (other.recoveryFile != null) + return false; + } else if (!recoveryFile.equals(other.recoveryFile)) + return false; + if (snapshotDataRoot == null) { + if (other.snapshotDataRoot != null) + return false; + } else if (!snapshotDataRoot.equals(other.snapshotDataRoot)) + return false; + if (suspendDataRoot == null) { + if (other.suspendDataRoot != null) + return false; + } else if (!suspendDataRoot.equals(other.suspendDataRoot)) + return false; + if (swapFileDataRoot == null) { + if (other.swapFileDataRoot != null) + return false; + } else if (!swapFileDataRoot.equals(other.swapFileDataRoot)) + return false; + if (virtualSystemIdentifier == null) { + if (other.virtualSystemIdentifier != null) + return false; + } else if (!virtualSystemIdentifier.equals(other.virtualSystemIdentifier)) + return false; + if (virtualSystemType == null) { + if (other.virtualSystemType != null) + return false; + } else if (!virtualSystemType.equals(other.virtualSystemType)) + return false; + return true; + } + + @Override + public String toString() { + return "VirtualSystem [automaticRecoveryAction=" + automaticRecoveryAction + + ", automaticShutdownAction=" + automaticShutdownAction + + ", automaticStartupAction=" + automaticStartupAction + + ", automaticStartupActionDelay=" + automaticStartupActionDelay + + ", automaticStartupActionSequenceNumber=" + automaticStartupActionSequenceNumber + + ", caption=" + caption + ", configurationDataRoot=" + configurationDataRoot + + ", configurationFile=" + configurationFile + ", configurationID=" + + configurationID + ", creationTime=" + creationTime + ", description=" + + description + ", elementName=" + elementName + ", instanceID=" + instanceID + + ", logDataRoot=" + logDataRoot + ", recoveryFile=" + recoveryFile + + ", snapshotDataRoot=" + snapshotDataRoot + ", suspendDataRoot=" + suspendDataRoot + + ", swapFileDataRoot=" + swapFileDataRoot + ", virtualSystemIdentifier=" + + virtualSystemIdentifier + ", virtualSystemType=" + virtualSystemType + "]"; + } + + +} \ No newline at end of file diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/terremark/domain/internal/VAppImpl.java b/vcloud/core/src/main/java/org/jclouds/vcloud/terremark/domain/internal/VAppImpl.java index bf6fc51e52..2e7ccb88c2 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/terremark/domain/internal/VAppImpl.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/terremark/domain/internal/VAppImpl.java @@ -23,13 +23,22 @@ */ package org.jclouds.vcloud.terremark.domain.internal; -import static com.google.common.base.Preconditions.checkNotNull; - +import java.net.InetAddress; import java.net.URI; +import java.util.Map; +import java.util.SortedSet; import org.jclouds.rest.domain.Link; import org.jclouds.rest.domain.internal.NamedLinkImpl; +import org.jclouds.vcloud.domain.VAppStatus; +import org.jclouds.vcloud.terremark.domain.ResourceAllocation; +import org.jclouds.vcloud.terremark.domain.ResourceType; import org.jclouds.vcloud.terremark.domain.VApp; +import org.jclouds.vcloud.terremark.domain.VirtualSystem; + +import com.google.common.base.Function; +import com.google.common.collect.ListMultimap; +import com.google.common.collect.Maps; /** * Locations of resources in vCloud @@ -39,25 +48,49 @@ import org.jclouds.vcloud.terremark.domain.VApp; */ public class VAppImpl extends NamedLinkImpl implements VApp { - private final int status; - private final int size; + private final VAppStatus status; + private final long size; private final Link vDC; + private final Link computeOptions; + private final Link customizationOptions; + private final ListMultimap networkToAddresses; + private final String operatingSystemDescription; + private final VirtualSystem system; + private final SortedSet resourceAllocations; + private final Map resourceAllocationByType; /** The serialVersionUID */ private static final long serialVersionUID = 8464716396538298809L; - public VAppImpl(String name, String type, URI location, int status, int size, Link vDC) { + public VAppImpl(String name, String type, URI location, VAppStatus status, long size, Link vDC, + Link computeOptions, Link customizationOptions, + ListMultimap networkToAddresses, + String operatingSystemDescription, VirtualSystem system, + SortedSet resourceAllocations) { super(name, type, location); this.status = status; this.size = size; - this.vDC = checkNotNull(vDC, "vDC"); + this.vDC = vDC; + this.computeOptions = computeOptions; + this.customizationOptions = customizationOptions; + this.networkToAddresses = networkToAddresses; + this.operatingSystemDescription = operatingSystemDescription; + this.system = system; + this.resourceAllocations = resourceAllocations; + resourceAllocationByType = Maps.uniqueIndex(resourceAllocations, + new Function() { + @Override + public ResourceType apply(ResourceAllocation from) { + return from.getResourceType(); + } + }); } - public int getStatus() { + public VAppStatus getStatus() { return status; } - public int getSize() { + public long getSize() { return size; } @@ -65,4 +98,112 @@ public class VAppImpl extends NamedLinkImpl implements VApp { return vDC; } + public Link getComputeOptions() { + return computeOptions; + } + + public Link getCustomizationOptions() { + return customizationOptions; + } + + public ListMultimap getNetworkToAddresses() { + return networkToAddresses; + } + + public String getOperatingSystemDescription() { + return operatingSystemDescription; + } + + public VirtualSystem getSystem() { + return system; + } + + public SortedSet getResourceAllocations() { + return resourceAllocations; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = super.hashCode(); + result = prime * result + ((computeOptions == null) ? 0 : computeOptions.hashCode()); + result = prime * result + + ((customizationOptions == null) ? 0 : customizationOptions.hashCode()); + result = prime * result + ((networkToAddresses == null) ? 0 : networkToAddresses.hashCode()); + result = prime * result + + ((operatingSystemDescription == null) ? 0 : operatingSystemDescription.hashCode()); + result = prime * result + + ((resourceAllocationByType == null) ? 0 : resourceAllocationByType.hashCode()); + result = prime * result + + ((resourceAllocations == null) ? 0 : resourceAllocations.hashCode()); + result = prime * result + (int) (size ^ (size >>> 32)); + result = prime * result + ((status == null) ? 0 : status.hashCode()); + result = prime * result + ((system == null) ? 0 : system.hashCode()); + result = prime * result + ((vDC == null) ? 0 : vDC.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; + VAppImpl other = (VAppImpl) obj; + if (computeOptions == null) { + if (other.computeOptions != null) + return false; + } else if (!computeOptions.equals(other.computeOptions)) + return false; + if (customizationOptions == null) { + if (other.customizationOptions != null) + return false; + } else if (!customizationOptions.equals(other.customizationOptions)) + return false; + if (networkToAddresses == null) { + if (other.networkToAddresses != null) + return false; + } else if (!networkToAddresses.equals(other.networkToAddresses)) + return false; + if (operatingSystemDescription == null) { + if (other.operatingSystemDescription != null) + return false; + } else if (!operatingSystemDescription.equals(other.operatingSystemDescription)) + return false; + if (resourceAllocationByType == null) { + if (other.resourceAllocationByType != null) + return false; + } else if (!resourceAllocationByType.equals(other.resourceAllocationByType)) + return false; + if (resourceAllocations == null) { + if (other.resourceAllocations != null) + return false; + } else if (!resourceAllocations.equals(other.resourceAllocations)) + return false; + if (size != other.size) + return false; + if (status == null) { + if (other.status != null) + return false; + } else if (!status.equals(other.status)) + return false; + if (system == null) { + if (other.system != null) + return false; + } else if (!system.equals(other.system)) + return false; + if (vDC == null) { + if (other.vDC != null) + return false; + } else if (!vDC.equals(other.vDC)) + return false; + return true; + } + + public Map getResourceAllocationByType() { + return resourceAllocationByType; + } + } \ No newline at end of file diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/terremark/xml/ResourceAllocationHandler.java b/vcloud/core/src/main/java/org/jclouds/vcloud/terremark/xml/ResourceAllocationHandler.java new file mode 100644 index 0000000000..1fec95f9fb --- /dev/null +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/terremark/xml/ResourceAllocationHandler.java @@ -0,0 +1,177 @@ +/** + * + * Copyright (C) 2009 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * ==================================================================== + */ +package org.jclouds.vcloud.terremark.xml; + +import org.jclouds.http.functions.ParseSax; +import org.jclouds.vcloud.terremark.domain.ResourceAllocation; +import org.jclouds.vcloud.terremark.domain.ResourceType; +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; + +/** + * @author Adrian Cole + */ +public class ResourceAllocationHandler extends ParseSax.HandlerWithResult { + private StringBuilder currentText = new StringBuilder(); + + private Integer address; + private Integer addressOnParent; + private String allocationUnits; + private String automaticAllocation; + private String automaticDeallocation; + private String caption; + private String consumerVisibility; + private String description; + private String elementName; + private String hostResource; + private int instanceID; + private String limit; + private String mappingBehavior; + private String otherResourceType; + private Integer parent; + private String poolID; + private String reservation; + private String resourceSubType; + private ResourceType resourceType; + private long virtualQuantity = 1; + private String virtualQuantityUnits; + private String weight; + + private ResourceAllocation item; + + private boolean skip; + + public ResourceAllocation getResult() { + return item; + } + + public void startElement(String uri, String localName, String qName, Attributes attributes) + throws SAXException { + if (attributes.getIndex("xsi:nil") != -1 || attributes.getIndex("xmlns") == -1) { + String ns = attributes.getValue(attributes.getIndex("xmlns")); + if ("http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData" + .equals(ns)) { + skip = false; + } else { + skip = true; + return; + } + } else { + skip = false; + } + } + + @Override + public void endElement(String uri, String localName, String qName) throws SAXException { + if (!skip) { + if (qName.equals("Address")) { + String address = currentText.toString().trim(); + if (address != null && !address.equals("")) + this.address = Integer.parseInt(address); + } else if (qName.equals("AddressOnParent")) { + String addressOnParent = currentText.toString().trim(); + if (addressOnParent != null && !addressOnParent.equals("")) + this.addressOnParent = Integer.parseInt(addressOnParent); + } else if (qName.equals("AllocationUnits")) { + this.allocationUnits = currentText.toString().trim(); + } else if (qName.equals("AutomaticAllocation")) { + this.automaticAllocation = currentText.toString().trim(); + } else if (qName.equals("AutomaticDeallocation")) { + this.automaticDeallocation = currentText.toString().trim(); + } else if (qName.equals("Caption")) { + this.caption = currentText.toString().trim(); + } else if (qName.equals("ConsumerVisibility")) { + this.consumerVisibility = currentText.toString().trim(); + } else if (qName.equals("Description")) { + this.description = currentText.toString().trim(); + } else if (qName.equals("ElementName")) { + this.elementName = currentText.toString().trim(); + } else if (qName.equals("HostResource")) { + this.hostResource = currentText.toString().trim(); + } else if (qName.equals("InstanceID")) { + this.instanceID = Integer.parseInt(currentText.toString().trim()); + } else if (qName.equals("Limit")) { + this.limit = currentText.toString().trim(); + } else if (qName.equals("MappingBehavior")) { + this.mappingBehavior = currentText.toString().trim(); + } else if (qName.equals("OtherResourceType")) { + this.otherResourceType = currentText.toString().trim(); + } else if (qName.equals("Parent")) { + String parent = currentText.toString().trim(); + if (parent != null && !parent.equals("")) + this.parent = Integer.parseInt(parent); + } else if (qName.equals("PoolID")) { + this.poolID = currentText.toString().trim(); + } else if (qName.equals("Reservation")) { + this.reservation = currentText.toString().trim(); + } else if (qName.equals("ResourceSubType")) { + this.resourceSubType = currentText.toString().trim(); + } else if (qName.equals("ResourceType")) { + this.resourceType = ResourceType.fromValue(currentText.toString().trim()); + } else if (qName.equals("VirtualQuantity")) { + String quantity = currentText.toString().trim(); + if (quantity != null && !quantity.equals("")) + this.virtualQuantity = Long.parseLong(quantity); + } else if (qName.equals("VirtualQuantityUnits")) { + this.virtualQuantityUnits = currentText.toString().trim(); + } else if (qName.equals("Weight")) { + this.weight = currentText.toString().trim(); + } else if (qName.equals("q2:Item")) { + this.item = new ResourceAllocation(address, addressOnParent, allocationUnits, + automaticAllocation, automaticDeallocation, caption, consumerVisibility, + description, elementName, hostResource, instanceID, limit, mappingBehavior, + otherResourceType, parent, poolID, reservation, resourceSubType, resourceType, + virtualQuantity, virtualQuantityUnits, weight); + this.address = null; + this.addressOnParent = null; + this.allocationUnits = null; + this.automaticAllocation = null; + this.automaticDeallocation = null; + this.caption = null; + this.consumerVisibility = null; + this.description = null; + this.elementName = null; + this.hostResource = null; + this.instanceID = -1; + this.limit = null; + this.mappingBehavior = null; + this.otherResourceType = null; + this.parent = null; + this.poolID = null; + this.reservation = null; + this.resourceSubType = null; + this.resourceType = null; + this.virtualQuantity = 1; + this.virtualQuantityUnits = null; + this.weight = null; + } + } + currentText = new StringBuilder(); + + } + + public void characters(char ch[], int start, int length) { + currentText.append(ch, start, length); + } +} diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/terremark/xml/TerremarkVAppHandler.java b/vcloud/core/src/main/java/org/jclouds/vcloud/terremark/xml/TerremarkVAppHandler.java index 86e3fc72d1..8698cabcc5 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/terremark/xml/TerremarkVAppHandler.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/terremark/xml/TerremarkVAppHandler.java @@ -23,39 +23,140 @@ */ package org.jclouds.vcloud.terremark.xml; +import java.net.InetAddress; +import java.net.UnknownHostException; +import java.util.SortedSet; + +import javax.annotation.Resource; +import javax.inject.Inject; + import org.jclouds.http.functions.ParseSax; +import org.jclouds.logging.Logger; import org.jclouds.rest.domain.Link; import org.jclouds.rest.domain.NamedLink; import org.jclouds.rest.util.Utils; +import org.jclouds.vcloud.VCloudMediaType; +import org.jclouds.vcloud.domain.VAppStatus; +import org.jclouds.vcloud.terremark.domain.ResourceAllocation; import org.jclouds.vcloud.terremark.domain.VApp; +import org.jclouds.vcloud.terremark.domain.VirtualSystem; import org.jclouds.vcloud.terremark.domain.internal.VAppImpl; import org.xml.sax.Attributes; import org.xml.sax.SAXException; +import com.google.common.collect.ArrayListMultimap; +import com.google.common.collect.ListMultimap; +import com.google.common.collect.Sets; + /** * @author Adrian Cole */ public class TerremarkVAppHandler extends ParseSax.HandlerWithResult { + private final VirtualSystemHandler systemHandler; + private final ResourceAllocationHandler allocationHandler; + @Resource + protected Logger logger = Logger.NULL; + + @Inject + public TerremarkVAppHandler(VirtualSystemHandler systemHandler, + ResourceAllocationHandler allocationHandler) { + this.systemHandler = systemHandler; + this.allocationHandler = allocationHandler; + } + + private VirtualSystem system; + private SortedSet allocations = Sets.newTreeSet(); private NamedLink vApp; private Link vDC; - private int status; + private VAppStatus status; private int size; + private boolean skip; + private Link computeOptions; + private Link customizationOptions; + private final ListMultimap networkToAddresses = ArrayListMultimap.create(); + private StringBuilder currentText = new StringBuilder(); + private String operatingSystemDescription; + private boolean inOs; + private String networkName; public VApp getResult() { - return new VAppImpl(vApp.getName(), vApp.getType(), vApp.getLocation(), status, size, vDC); + return new VAppImpl(vApp.getName(), vApp.getType(), vApp.getLocation(), status, size, vDC, + computeOptions, customizationOptions, networkToAddresses, + operatingSystemDescription, system, allocations); } public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { + if (attributes.getIndex("xsi:nil") != -1) { + skip = true; + return; + } else { + skip = false; + } if (qName.equals("Link")) { - vDC = Utils.newLink(attributes); + if (attributes.getValue(attributes.getIndex("type")).equals(VCloudMediaType.VDC_XML)) { + vDC = Utils.newLink(attributes); + } else if (attributes.getValue(attributes.getIndex("name")).equals("Compute Options")) { + this.computeOptions = Utils.newLink(attributes); + } else if (attributes.getValue(attributes.getIndex("name")) + .equals("Customization Options")) { + this.customizationOptions = Utils.newLink(attributes); + } } else if (qName.equals("VApp")) { vApp = Utils.newNamedLink(attributes); - status = Integer.parseInt(attributes.getValue(attributes.getIndex("status"))); + status = VAppStatus.fromValue(attributes.getValue(attributes.getIndex("status"))); size = Integer.parseInt(attributes.getValue(attributes.getIndex("size"))); + } else if (qName.equals("OperatingSystemSection")) { + inOs = true; + } else if (qName.equals("q1:NetworkConnection")) { + networkName = attributes.getValue(attributes.getIndex("Network")); + } else { + systemHandler.startElement(uri, localName, qName, attributes); + allocationHandler.startElement(uri, localName, qName, attributes); } } + @Override + public void endElement(String uri, String localName, String qName) throws SAXException { + if (qName.equals("OperatingSystemSection")) { + inOs = false; + } else if (inOs && qName.equals("Description")) { + operatingSystemDescription = currentText.toString().trim(); + } else if (qName.equals("q1:IpAddress")) { + networkToAddresses.put(networkName, parseInetAddress(currentText.toString().trim())); + } else if (qName.equals("q2:System")) { + systemHandler.endElement(uri, localName, qName); + system = systemHandler.getResult(); + } else if (qName.equals("q2:Item")) { + allocationHandler.endElement(uri, localName, qName); + allocations.add(allocationHandler.getResult()); + } else if (!skip) { + systemHandler.endElement(uri, localName, qName); + allocationHandler.endElement(uri, localName, qName); + } + currentText = new StringBuilder(); + } + + @Override + public void characters(char ch[], int start, int length) { + currentText.append(ch, start, length); + systemHandler.characters(ch, start, length); + allocationHandler.characters(ch, start, length); + } + + private InetAddress parseInetAddress(String string) { + String[] byteStrings = string.split("\\."); + byte[] bytes = new byte[4]; + for (int i = 0; i < 4; i++) { + bytes[i] = (byte) Integer.parseInt(byteStrings[i]); + } + try { + return InetAddress.getByAddress(bytes); + } catch (UnknownHostException e) { + logger.warn(e, "error parsing ipAddress", currentText); + } + return null; + } } diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/terremark/xml/VirtualSystemHandler.java b/vcloud/core/src/main/java/org/jclouds/vcloud/terremark/xml/VirtualSystemHandler.java new file mode 100644 index 0000000000..8888316115 --- /dev/null +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/terremark/xml/VirtualSystemHandler.java @@ -0,0 +1,169 @@ +/** + * + * Copyright (C) 2009 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * ==================================================================== + */ +package org.jclouds.vcloud.terremark.xml; + +import javax.inject.Inject; + +import org.jclouds.http.functions.ParseSax; +import org.jclouds.util.DateService; +import org.joda.time.DateTime; +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; + +/** + * @author Adrian Cole + */ +public class VirtualSystemHandler extends + ParseSax.HandlerWithResult { + private StringBuilder currentText = new StringBuilder(); + + protected DateService dateService; + + private String automaticRecoveryAction; + private String automaticShutdownAction; + private String automaticStartupAction; + private String automaticStartupActionDelay; + private String automaticStartupActionSequenceNumber; + private String caption; + private String configurationDataRoot; + private String configurationFile; + private String configurationID; + private DateTime creationTime; + private String description; + private String elementName; + private int instanceID; + private String logDataRoot; + private String recoveryFile; + private String snapshotDataRoot; + private String suspendDataRoot; + private String swapFileDataRoot; + private String virtualSystemIdentifier; + private String virtualSystemType; + + private org.jclouds.vcloud.terremark.domain.VirtualSystem system; + + private boolean skip; + + @Inject + public VirtualSystemHandler(DateService dateService) { + this.dateService = dateService; + } + + public org.jclouds.vcloud.terremark.domain.VirtualSystem getResult() { + return system; + } + + public void startElement(String uri, String localName, String qName, Attributes attributes) + throws SAXException { + if (attributes.getIndex("xsi:nil") != -1 + || attributes.getIndex("xmlns") == -1 || !"http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_VirtualSystemSettingData" + .equals(attributes.getValue("xmlns"))) { + skip = true; + return; + } else { + skip = false; + } + } + + @Override + public void endElement(String uri, String localName, String qName) throws SAXException { + if (!skip) { + if (qName.equals("AutomaticRecoveryAction")) { + this.automaticRecoveryAction = currentText.toString().trim(); + } else if (qName.equals("AutomaticShutdownAction")) { + this.automaticShutdownAction = currentText.toString().trim(); + } else if (qName.equals("AutomaticStartupAction")) { + this.automaticStartupAction = currentText.toString().trim(); + } else if (qName.equals("AutomaticStartupActionDelay")) { + this.automaticStartupActionDelay = currentText.toString().trim(); + } else if (qName.equals("AutomaticStartupActionSequenceNumber")) { + this.automaticStartupActionSequenceNumber = currentText.toString().trim(); + } else if (qName.equals("Caption")) { + this.caption = currentText.toString().trim(); + } else if (qName.equals("ConfigurationDataRoot")) { + this.configurationDataRoot = currentText.toString().trim(); + } else if (qName.equals("ConfigurationDataRoot")) { + this.configurationDataRoot = currentText.toString().trim(); + } else if (qName.equals("ConfigurationFile")) { + this.configurationFile = currentText.toString().trim(); + } else if (qName.equals("ConfigurationID")) { + this.configurationID = currentText.toString().trim(); + } else if (qName.equals("CreationTime")) { + this.creationTime = dateService.iso8601DateParse(currentText.toString().trim()); + } else if (qName.equals("Description")) { + this.description = currentText.toString().trim(); + } else if (qName.equals("ElementName")) { + this.elementName = currentText.toString().trim(); + } else if (qName.equals("InstanceID")) { + this.instanceID = Integer.parseInt(currentText.toString().trim()); + } else if (qName.equals("LogDataRoot")) { + this.logDataRoot = currentText.toString().trim(); + } else if (qName.equals("RecoveryFile")) { + this.recoveryFile = currentText.toString().trim(); + } else if (qName.equals("SnapshotDataRoot")) { + this.snapshotDataRoot = currentText.toString().trim(); + } else if (qName.equals("SuspendDataRoot")) { + this.suspendDataRoot = currentText.toString().trim(); + } else if (qName.equals("SwapFileDataRoot")) { + this.swapFileDataRoot = currentText.toString().trim(); + } else if (qName.equals("VirtualSystemIdentifier")) { + this.virtualSystemIdentifier = currentText.toString().trim(); + } else if (qName.equals("VirtualSystemType")) { + this.virtualSystemType = currentText.toString().trim(); + } else if (qName.equals("q2:System")) { + this.system = new org.jclouds.vcloud.terremark.domain.VirtualSystem(automaticRecoveryAction, + automaticShutdownAction, automaticStartupAction, automaticStartupActionDelay, + automaticStartupActionSequenceNumber, caption, configurationDataRoot, + configurationFile, configurationID, creationTime, description, elementName, + instanceID, logDataRoot, recoveryFile, snapshotDataRoot, suspendDataRoot, + swapFileDataRoot, virtualSystemIdentifier, virtualSystemType); + this.automaticRecoveryAction = null; + this.automaticShutdownAction = null; + this.automaticStartupAction = null; + this.automaticStartupActionDelay = null; + this.automaticStartupActionSequenceNumber = null; + this.caption = null; + this.configurationDataRoot = null; + this.configurationFile = null; + this.configurationID = null; + this.creationTime = null; + this.description = null; + this.elementName = null; + this.instanceID = -1; + this.logDataRoot = null; + this.recoveryFile = null; + this.snapshotDataRoot = null; + this.suspendDataRoot = null; + this.swapFileDataRoot = null; + this.virtualSystemIdentifier = null; + this.virtualSystemType = null; + } + } + currentText = new StringBuilder(); + } + + public void characters(char ch[], int start, int length) { + currentText.append(ch, start, length); + } +} diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/xml/BaseTaskHandler.java b/vcloud/core/src/main/java/org/jclouds/vcloud/xml/BaseTaskHandler.java deleted file mode 100644 index f29bdd3057..0000000000 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/xml/BaseTaskHandler.java +++ /dev/null @@ -1,96 +0,0 @@ -/** - * - * Copyright (C) 2009 Cloud Conscious, LLC. - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - */ -package org.jclouds.vcloud.xml; - -import java.text.ParseException; - -import javax.inject.Inject; - -import org.jclouds.http.functions.ParseSax; -import org.jclouds.rest.domain.Link; -import org.jclouds.rest.domain.NamedLink; -import org.jclouds.rest.util.Utils; -import org.jclouds.util.DateService; -import org.jclouds.vcloud.domain.Task; -import org.jclouds.vcloud.domain.TaskStatus; -import org.jclouds.vcloud.domain.internal.TaskImpl; -import org.joda.time.DateTime; -import org.xml.sax.Attributes; -import org.xml.sax.SAXException; - -/** - * @author Adrian Cole - */ -public abstract class BaseTaskHandler extends ParseSax.HandlerWithResult { - - protected final DateService dateService; - - private Link taskLink; - private NamedLink owner; - private NamedLink result; - private TaskStatus status; - private DateTime startTime; - private DateTime endTime; - - @Inject - public BaseTaskHandler(DateService dateService) { - this.dateService = dateService; - } - - @Override - public void startElement(String uri, String localName, String qName, Attributes attributes) - throws SAXException { - if (qName.equals("Task")) { - taskLink = Utils.newLink(attributes); - status = TaskStatus.fromValue(attributes.getValue(attributes.getIndex("status"))); - startTime = dateService.iso8601DateParse(attributes.getValue(attributes - .getIndex("startTime"))); - if (attributes.getIndex("endTime") != -1) { - try { - endTime = dateService.iso8601DateParse(attributes.getValue(attributes - .getIndex("endTime"))); - } catch (RuntimeException e) { - if (!(e.getCause() instanceof ParseException)) // TODO.. format doesn't parse - // endTime="2009-11-11T02:27:25Z" - throw e; - } - } - } else if (qName.equals("Owner")) { - owner = Utils.newNamedLink(attributes); - } else if (qName.equals("Result")) { - result = Utils.newNamedLink(attributes); - } - } - - @Override - public void endElement(String uri, String localName, String qName) throws SAXException { - if (qName.equals("Task")) { - newTask(new TaskImpl(taskLink.getType(), taskLink.getLocation(), status, startTime, - endTime, owner, result)); - } - } - - protected abstract void newTask(Task task); - -} diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/xml/TaskHandler.java b/vcloud/core/src/main/java/org/jclouds/vcloud/xml/TaskHandler.java index a9fed5efd5..68cd501f45 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/xml/TaskHandler.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/xml/TaskHandler.java @@ -23,30 +23,82 @@ */ package org.jclouds.vcloud.xml; +import java.text.ParseException; + import javax.inject.Inject; +import org.jclouds.http.functions.ParseSax; +import org.jclouds.rest.domain.Link; +import org.jclouds.rest.domain.NamedLink; +import org.jclouds.rest.util.Utils; import org.jclouds.util.DateService; import org.jclouds.vcloud.domain.Task; +import org.jclouds.vcloud.domain.TaskStatus; +import org.jclouds.vcloud.domain.internal.TaskImpl; +import org.joda.time.DateTime; +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; /** * @author Adrian Cole */ -public class TaskHandler extends BaseTaskHandler { +public class TaskHandler extends ParseSax.HandlerWithResult { + protected final DateService dateService; + + private Link taskLink; + private NamedLink owner; + private NamedLink result; + private TaskStatus status; + private DateTime startTime; + private DateTime endTime; + private Task task; @Inject public TaskHandler(DateService dateService) { - super(dateService); + this.dateService = dateService; } - private Task task; - public Task getResult() { return task; } @Override - protected void newTask(Task task) { - this.task = task; + public void startElement(String uri, String localName, String qName, Attributes attributes) + throws SAXException { + if (qName.equals("Task")) { + taskLink = Utils.newLink(attributes); + status = TaskStatus.fromValue(attributes.getValue(attributes.getIndex("status"))); + startTime = dateService.iso8601DateParse(attributes.getValue(attributes + .getIndex("startTime"))); + if (attributes.getIndex("endTime") != -1) { + try { + endTime = dateService.iso8601DateParse(attributes.getValue(attributes + .getIndex("endTime"))); + } catch (RuntimeException e) { + if (!(e.getCause() instanceof ParseException)) // TODO.. format doesn't parse + // endTime="2009-11-11T02:27:25Z" + throw e; + } + } + } else if (qName.equals("Owner")) { + owner = Utils.newNamedLink(attributes); + } else if (qName.equals("Result")) { + result = Utils.newNamedLink(attributes); + } + } + + @Override + public void endElement(String uri, String localName, String qName) throws SAXException { + if (qName.equals("Task")) { + this.task = new TaskImpl(taskLink.getType(), taskLink.getLocation(), status, startTime, + endTime, owner, result); + taskLink = null; + status = null; + startTime = null; + endTime = null; + owner = null; + result = null; + } } } diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/xml/TasksListHandler.java b/vcloud/core/src/main/java/org/jclouds/vcloud/xml/TasksListHandler.java index f6225f3550..3a3cad7cc6 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/xml/TasksListHandler.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/xml/TasksListHandler.java @@ -28,8 +28,8 @@ import java.util.SortedSet; import javax.inject.Inject; +import org.jclouds.http.functions.ParseSax; import org.jclouds.rest.util.Utils; -import org.jclouds.util.DateService; import org.jclouds.vcloud.domain.Task; import org.jclouds.vcloud.domain.TasksList; import org.jclouds.vcloud.domain.internal.TasksListImpl; @@ -41,31 +41,36 @@ import com.google.common.collect.Sets; /** * @author Adrian Cole */ -public class TasksListHandler extends BaseTaskHandler { +public class TasksListHandler extends ParseSax.HandlerWithResult { private SortedSet tasks = Sets.newTreeSet(); + private final TaskHandler taskHandler; private URI location; @Inject - public TasksListHandler(DateService dateService) { - super(dateService); + public TasksListHandler(TaskHandler taskHandler) { + this.taskHandler = taskHandler; } public TasksList getResult() { return new TasksListImpl(location, tasks); } - protected void newTask(Task task) { - this.tasks.add(task); - } - @Override public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { if (qName.equals("TasksList")) { location = Utils.newLink(attributes).getLocation(); } else { - super.startElement(uri, localName, qName, attributes); + taskHandler.startElement(uri, localName, qName, attributes); + } + } + + @Override + public void endElement(String uri, String localName, String qName) throws SAXException { + taskHandler.endElement(uri, localName, qName); + if (qName.equals("Task")) { + this.tasks.add(taskHandler.getResult()); } } diff --git a/vcloud/core/src/test/java/org/jclouds/vcloud/terremark/TerremarkVCloudClientLiveTest.java b/vcloud/core/src/test/java/org/jclouds/vcloud/terremark/TerremarkVCloudClientLiveTest.java index 772fa5998e..da5ce1ae85 100644 --- a/vcloud/core/src/test/java/org/jclouds/vcloud/terremark/TerremarkVCloudClientLiveTest.java +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/terremark/TerremarkVCloudClientLiveTest.java @@ -37,6 +37,8 @@ import org.jclouds.logging.log4j.config.Log4JLoggingModule; import org.jclouds.vcloud.VCloudClientLiveTest; import org.jclouds.vcloud.domain.Task; import org.jclouds.vcloud.domain.TaskStatus; +import org.jclouds.vcloud.domain.VAppStatus; +import org.jclouds.vcloud.terremark.domain.ResourceType; import org.jclouds.vcloud.terremark.domain.TerremarkVDC; import org.jclouds.vcloud.terremark.domain.VApp; import org.testng.annotations.BeforeGroups; @@ -66,18 +68,24 @@ public class TerremarkVCloudClientLiveTest extends VCloudClientLiveTest { } @Test - // disabled until stop functionality is added public void testInstantiate() throws InterruptedException, ExecutionException, TimeoutException { - URI template = tmClient.getCatalog().get(45, TimeUnit.SECONDS).get( - "Ubuntu Server 9.04 (32-bit)").getLocation(); + String serverName = "adriantest4"; + int processorCount = 1; + int memory = 512; + String catalogOs = "Ubuntu Server 9.04 (32-bit)"; + String expectedOs = "Ubuntu Linux (32-bit)"; + + URI template = tmClient.getCatalog().get(45, TimeUnit.SECONDS).get(catalogOs).getLocation(); URI network = tmClient.getDefaultVDC().get(45, TimeUnit.SECONDS).getAvailableNetworks() .values().iterator().next().getLocation(); - VApp vApp = tmClient.instantiateVAppTemplate("adriantest1", template, 1, 512, network).get( - 45, TimeUnit.SECONDS); + VApp vApp = tmClient.instantiateVAppTemplate(serverName, template, processorCount, memory, + network).get(45, TimeUnit.SECONDS); + assertEquals(vApp.getStatus(), VAppStatus.CREATING); Task instantiateTask = getLastTaskFor(vApp.getVDC().getLocation()); + assertEquals(instantiateTask.getStatus(), TaskStatus.QUEUED); // in terremark, this should be a no-op, as it should simply return the above task, which is // already deploying @@ -88,6 +96,9 @@ public class TerremarkVCloudClientLiveTest extends VCloudClientLiveTest { deployTask = tmClient.deploy(vApp.getLocation()).get(45, TimeUnit.SECONDS); assertEquals(deployTask.getLocation(), instantiateTask.getLocation()); + vApp = tmClient.getVApp(vApp.getLocation()).get(45, TimeUnit.SECONDS); + assertEquals(vApp.getStatus(), VAppStatus.CREATING); + try {// per docs, this is not supported tmClient.cancelTask(deployTask.getLocation()).get(45, TimeUnit.SECONDS); } catch (ExecutionException e) { @@ -96,7 +107,11 @@ public class TerremarkVCloudClientLiveTest extends VCloudClientLiveTest { } deployTask = blockUntilSuccess(deployTask); - // TODO verify from vapp status + + vApp = tmClient.getVApp(vApp.getLocation()).get(45, TimeUnit.SECONDS); + verifyConfigurationOfVApp(vApp, serverName, expectedOs, processorCount, memory); + assertEquals(vApp.getStatus(), VAppStatus.OFF); + try {// per docs, this is not supported tmClient.undeploy(deployTask.getResult().getLocation()).get(45, TimeUnit.SECONDS); } catch (ExecutionException e) { @@ -106,7 +121,8 @@ public class TerremarkVCloudClientLiveTest extends VCloudClientLiveTest { deployTask = blockUntilSuccess(tmClient.powerOn(deployTask.getResult().getLocation()).get(45, TimeUnit.SECONDS)); - // TODO verify from vapp status + vApp = tmClient.getVApp(vApp.getLocation()).get(45, TimeUnit.SECONDS); + assertEquals(vApp.getStatus(), VAppStatus.ON); try {// per docs, this is not supported tmClient.suspend(deployTask.getResult().getLocation()).get(45, TimeUnit.SECONDS); @@ -117,18 +133,37 @@ public class TerremarkVCloudClientLiveTest extends VCloudClientLiveTest { deployTask = blockUntilSuccess(tmClient.reset(deployTask.getResult().getLocation()).get(45, TimeUnit.SECONDS)); - // TODO verify from vapp status + vApp = tmClient.getVApp(vApp.getLocation()).get(45, TimeUnit.SECONDS); + assertEquals(vApp.getStatus(), VAppStatus.ON); tmClient.shutdown(deployTask.getResult().getLocation()).get(45, TimeUnit.SECONDS); - // TODO verify from vapp status + vApp = tmClient.getVApp(vApp.getLocation()).get(45, TimeUnit.SECONDS); + assertEquals(vApp.getStatus(), VAppStatus.ON); deployTask = blockUntilSuccess(tmClient.powerOff(deployTask.getResult().getLocation()).get( 45, TimeUnit.SECONDS)); - // TODO verify from vapp status + vApp = tmClient.getVApp(vApp.getLocation()).get(45, TimeUnit.SECONDS); + assertEquals(vApp.getStatus(), VAppStatus.OFF); tmClient.delete(deployTask.getResult().getLocation()).get(45, TimeUnit.SECONDS); - // TODO verify from vapp status + //TODO verify not present anymore + } + private void verifyConfigurationOfVApp(VApp vApp, String serverName, String expectedOs, + int processorCount, int memory) { + assertEquals(vApp.getName(), serverName); + assertEquals(vApp.getOperatingSystemDescription(), expectedOs); + assertEquals(vApp.getResourceAllocationByType().get(ResourceType.VIRTUAL_CPU) + .getVirtualQuantity(), processorCount); + assertEquals(vApp.getResourceAllocationByType().get(ResourceType.SCSI_CONTROLLER) + .getVirtualQuantity(), 1); + assertEquals( + vApp.getResourceAllocationByType().get(ResourceType.MEMORY).getVirtualQuantity(), + memory); + assertEquals(vApp.getResourceAllocationByType().get(ResourceType.VIRTUAL_DISK) + .getVirtualQuantity(), memory * 8192); + assertEquals(vApp.getSize(), vApp.getResourceAllocationByType() + .get(ResourceType.VIRTUAL_DISK).getVirtualQuantity()); } private Task blockUntilSuccess(Task task) throws InterruptedException, ExecutionException, diff --git a/vcloud/core/src/test/java/org/jclouds/vcloud/terremark/xml/ResourceAllocationHandlerTest.java b/vcloud/core/src/test/java/org/jclouds/vcloud/terremark/xml/ResourceAllocationHandlerTest.java new file mode 100644 index 0000000000..77c2dbbe1b --- /dev/null +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/terremark/xml/ResourceAllocationHandlerTest.java @@ -0,0 +1,64 @@ +/** + * + * Copyright (C) 2009 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * ==================================================================== + */ +package org.jclouds.vcloud.terremark.xml; + +import static org.testng.Assert.assertEquals; + +import java.io.InputStream; + +import org.jclouds.http.functions.BaseHandlerTest; +import org.jclouds.vcloud.terremark.domain.ResourceAllocation; +import org.jclouds.vcloud.terremark.domain.ResourceType; +import org.testng.annotations.BeforeTest; +import org.testng.annotations.Test; + +/** + * Tests behavior of {@code ResourceAllocationHandler} + * + * @author Adrian Cole + */ +@Test(groups = "unit", testName = "vcloud.ResourceAllocationHandlerTest") +public class ResourceAllocationHandlerTest extends BaseHandlerTest { + + @BeforeTest + @Override + protected void setUpInjector() { + super.setUpInjector(); + } + + public void testApplyInputStream() { + InputStream is = getClass().getResourceAsStream("/terremark/item.xml"); + + ResourceAllocation result = (ResourceAllocation) factory.create( + injector.getInstance(ResourceAllocationHandler.class)).parse(is); + assertEquals(result.getAddress(), new Integer(0)); + assertEquals(result.getDescription(), "SCSI Controller"); + assertEquals(result.getElementName(), "SCSI Controller 0"); + assertEquals(result.getInstanceID(), 3); + assertEquals(result.getResourceSubType(), "lsilogic"); + assertEquals(result.getResourceType(), ResourceType.SCSI_CONTROLLER); + assertEquals(result.getVirtualQuantity(), 1); + + } +} diff --git a/vcloud/core/src/test/java/org/jclouds/vcloud/terremark/xml/TerremarkVAppHandlerTest.java b/vcloud/core/src/test/java/org/jclouds/vcloud/terremark/xml/TerremarkVAppHandlerTest.java index e90dc5b6b5..f99924eb6e 100644 --- a/vcloud/core/src/test/java/org/jclouds/vcloud/terremark/xml/TerremarkVAppHandlerTest.java +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/terremark/xml/TerremarkVAppHandlerTest.java @@ -26,14 +26,26 @@ package org.jclouds.vcloud.terremark.xml; import static org.testng.Assert.assertEquals; import java.io.InputStream; +import java.net.InetAddress; import java.net.URI; +import java.net.UnknownHostException; + +import javax.ws.rs.core.MediaType; import org.jclouds.http.functions.BaseHandlerTest; import org.jclouds.rest.domain.internal.LinkImpl; +import org.jclouds.vcloud.VCloudMediaType; +import org.jclouds.vcloud.domain.VAppStatus; +import org.jclouds.vcloud.terremark.domain.ResourceAllocation; +import org.jclouds.vcloud.terremark.domain.ResourceType; import org.jclouds.vcloud.terremark.domain.VApp; +import org.jclouds.vcloud.terremark.domain.VirtualSystem; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableSortedSet; + /** * Tests behavior of {@code TerremarkVAppHandler} * @@ -54,7 +66,7 @@ public class TerremarkVAppHandlerTest extends BaseHandlerTest { VApp result = (VApp) factory.create(injector.getInstance(TerremarkVAppHandler.class)).parse( is); assertEquals(result.getName(), "adriantest"); - assertEquals(result.getStatus(), 0); + assertEquals(result.getStatus(), VAppStatus.CREATING); assertEquals(result.getSize(), 4); @@ -65,4 +77,64 @@ public class TerremarkVAppHandlerTest extends BaseHandlerTest { .create("https://services.vcloudexpress.terremark.com/api/v0.8/vdc/32"))); } + + public void testGetVApp() throws UnknownHostException { + InputStream is = getClass().getResourceAsStream("/terremark/get_vapp.xml"); + + VApp result = (VApp) factory.create(injector.getInstance(TerremarkVAppHandler.class)).parse( + is); + assertEquals(result.getName(), "adriantest1"); + assertEquals(result.getStatus(), VAppStatus.OFF); + + assertEquals(result.getSize(), 4194304); + assertEquals(result.getOperatingSystemDescription(), "Ubuntu Linux (32-bit)"); + + assertEquals(result.getLocation(), URI + .create("https://services.vcloudexpress.terremark.com/api/v0.8/vapp/13850")); + assertEquals(result.getType(), "application/vnd.vmware.vcloud.vApp+xml"); + assertEquals(result.getVDC(), new LinkImpl(VCloudMediaType.VDC_XML, URI + .create("https://services.vcloudexpress.terremark.com/api/v0.8/vdc/32"))); + assertEquals( + result.getComputeOptions(), + new LinkImpl( + MediaType.APPLICATION_XML, + URI + .create("https://services.vcloudexpress.terremark.com/api/v0.8/vapp/13850/options/compute"))); + assertEquals( + result.getCustomizationOptions(), + new LinkImpl( + MediaType.APPLICATION_XML, + URI + .create("https://services.vcloudexpress.terremark.com/api/v0.8/vapp/13850/options/customization"))); + assertEquals(result.getSystem(), new VirtualSystem(null, null, null, null, null, null, null, + null, null, null, null, "Virtual Hardware Family", 0, null, null, null, null, null, + "adriantest1", "vmx-07")); + assertEquals(result.getNetworkToAddresses().get("Internal"), ImmutableList.of(InetAddress + .getByName("10.114.34.132"))); + + ResourceAllocation cpu = new ResourceAllocation(null, null, "hertz * 10^6", null, null, null, + null, "Number of Virtual CPUs", "1 virtual CPU(s)", null, 1, null, null, null, null, + null, null, null, ResourceType.VIRTUAL_CPU, 1, "count", null); + ResourceAllocation controller = new ResourceAllocation(0, null, null, null, null, null, null, + "SCSI Controller", "SCSI Controller 0", null, 3, null, null, null, null, null, null, + "lsilogic", ResourceType.SCSI_CONTROLLER, 1, null, null); + ResourceAllocation memory = new ResourceAllocation(null, null, "byte * 2^20", null, null, + null, null, "Memory Size", "512MB of memory", null, 2, null, null, null, null, null, + null, null, ResourceType.MEMORY, 512, "byte * 2^20", null); + ResourceAllocation disk = new ResourceAllocation(null, 0, null, null, null, null, null, null, + "Hard Disk 1", "4194304", 9, null, null, null, 3, null, null, null, + ResourceType.VIRTUAL_DISK, 4194304, null, null); + assertEquals(result.getResourceAllocations(), ImmutableSortedSet.of(cpu, controller, memory, + disk)); + assertEquals(result.getResourceAllocationByType().get(ResourceType.VIRTUAL_CPU) + .getVirtualQuantity(), 1); + assertEquals(result.getResourceAllocationByType().get(ResourceType.SCSI_CONTROLLER) + .getVirtualQuantity(), 1); + assertEquals(result.getResourceAllocationByType().get(ResourceType.MEMORY) + .getVirtualQuantity(), 512); + assertEquals(result.getResourceAllocationByType().get(ResourceType.VIRTUAL_DISK) + .getVirtualQuantity(), 4194304); + assertEquals(result.getSize(), result.getResourceAllocationByType().get( + ResourceType.VIRTUAL_DISK).getVirtualQuantity()); + } } diff --git a/vcloud/core/src/test/java/org/jclouds/vcloud/terremark/xml/VirtualSystemHandlerTest.java b/vcloud/core/src/test/java/org/jclouds/vcloud/terremark/xml/VirtualSystemHandlerTest.java new file mode 100644 index 0000000000..2fc3115e74 --- /dev/null +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/terremark/xml/VirtualSystemHandlerTest.java @@ -0,0 +1,59 @@ +/** + * + * Copyright (C) 2009 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * ==================================================================== + */ +package org.jclouds.vcloud.terremark.xml; + +import static org.testng.Assert.assertEquals; + +import java.io.InputStream; + +import org.jclouds.http.functions.BaseHandlerTest; +import org.jclouds.vcloud.terremark.domain.VirtualSystem; +import org.testng.annotations.BeforeTest; +import org.testng.annotations.Test; + +/** + * Tests behavior of {@code VirtualSystemHandler} + * + * @author Adrian Cole + */ +@Test(groups = "unit", testName = "vcloud.VirtualSystemHandlerTest") +public class VirtualSystemHandlerTest extends BaseHandlerTest { + + @BeforeTest + @Override + protected void setUpInjector() { + super.setUpInjector(); + } + + public void testApplyInputStream() { + InputStream is = getClass().getResourceAsStream("/terremark/system.xml"); + + VirtualSystem result = (VirtualSystem) factory.create( + injector.getInstance(VirtualSystemHandler.class)).parse(is); + assertEquals(result.getElementName(), "Virtual Hardware Family"); + assertEquals(result.getInstanceID(), 0); + assertEquals(result.getVirtualSystemIdentifier(), "adriantest1"); + assertEquals(result.getVirtualSystemType(), "vmx-07"); + } +} diff --git a/vcloud/core/src/test/resources/terremark/item.xml b/vcloud/core/src/test/resources/terremark/item.xml new file mode 100644 index 0000000000..e39f97f81f --- /dev/null +++ b/vcloud/core/src/test/resources/terremark/item.xml @@ -0,0 +1,45 @@ + + +
0
+ + + + + + + SCSI Controller + SCSI Controller 0 + 3 + + + + + + + lsilogic + 6 + + + +
\ No newline at end of file diff --git a/vcloud/core/src/test/resources/terremark/system.xml b/vcloud/core/src/test/resources/terremark/system.xml new file mode 100644 index 0000000000..d6977fbc05 --- /dev/null +++ b/vcloud/core/src/test/resources/terremark/system.xml @@ -0,0 +1,43 @@ + + + + + + + + + + + + + Virtual Hardware Family + 0 + + + + + + adriantest1 + vmx-07 + \ No newline at end of file