updated xml parsers in savvis

This commit is contained in:
Adrian Cole 2011-03-24 14:52:07 -07:00
parent 2f3bd3d66a
commit 0e55bff1cd
17 changed files with 153 additions and 116 deletions

View File

@ -56,6 +56,7 @@
<test.savvis-symphonyvpdc.apiversion>0.8</test.savvis-symphonyvpdc.apiversion> <test.savvis-symphonyvpdc.apiversion>0.8</test.savvis-symphonyvpdc.apiversion>
<test.savvis-symphonyvpdc.identity>FIXME</test.savvis-symphonyvpdc.identity> <test.savvis-symphonyvpdc.identity>FIXME</test.savvis-symphonyvpdc.identity>
<test.savvis-symphonyvpdc.credential>FIXME</test.savvis-symphonyvpdc.credential> <test.savvis-symphonyvpdc.credential>FIXME</test.savvis-symphonyvpdc.credential>
<test.savvis-symphonyvpdc.email>FIXME</test.savvis-symphonyvpdc.email>
<test.savvis-symphonyvpdc.loginUser>FIXME</test.savvis-symphonyvpdc.loginUser> <test.savvis-symphonyvpdc.loginUser>FIXME</test.savvis-symphonyvpdc.loginUser>
<test.savvis-symphonyvpdc.loginPassword>FIXME</test.savvis-symphonyvpdc.loginPassword> <test.savvis-symphonyvpdc.loginPassword>FIXME</test.savvis-symphonyvpdc.loginPassword>
</properties> </properties>
@ -141,6 +142,10 @@
<name>test.savvis-symphonyvpdc.credential</name> <name>test.savvis-symphonyvpdc.credential</name>
<value>${test.savvis-symphonyvpdc.credential}</value> <value>${test.savvis-symphonyvpdc.credential}</value>
</property> </property>
<property>
<name>test.savvis-symphonyvpdc.email</name>
<value>${test.savvis-symphonyvpdc.email}</value>
</property>
<property> <property>
<name>test.savvis-symphonyvpdc.loginUser</name> <name>test.savvis-symphonyvpdc.loginUser</name>
<value>${test.savvis-symphonyvpdc.loginUser}</value> <value>${test.savvis-symphonyvpdc.loginUser}</value>

View File

@ -207,8 +207,9 @@ public class Task extends Resource {
@Override @Override
public String toString() { public String toString() {
return "[status=" + status + ", startTime=" + startTime + ", endTime=" + endTime + ", owner=" + owner return "[id=" + id + ", name=" + name + ", type=" + type + ", href=" + href + ", status=" + status
+ ", result=" + result + ", error=" + error + "]"; + ", startTime=" + startTime + ", endTime=" + endTime + ", owner=" + owner + ", result=" + result
+ ", error=" + error + "]";
} }
} }

View File

@ -1,5 +1,7 @@
package org.jclouds.savvis.vpdc.predicates; package org.jclouds.savvis.vpdc.predicates;
import static com.google.common.base.Preconditions.checkNotNull;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.inject.Singleton; import javax.inject.Singleton;
@ -30,13 +32,18 @@ public class TaskSuccess implements Predicate<String> {
} }
public boolean apply(String taskId) { public boolean apply(String taskId) {
logger.trace("looking for status on task %s", taskId); logger.trace("looking for status on task %s", checkNotNull(taskId, "taskId"));
Task task = refresh(taskId);
Task task = client.getBrowsingClient().getTask(taskId); if (task == null)
logger.trace("%s: looking for status %s: currently: %s", task, Task.Status.SUCCESS, task.getStatus()); return false;
if (task.getStatus() == Task.Status.ERROR || task.getStatus() == Task.Status.NONE) logger.trace("%s: looking for task status %s: currently: %s", task.getId(), Task.Status.SUCCESS, task.getStatus());
throw new RuntimeException("error on task: " + task.getHref() + " error: " + task.getError()); if (task.getError() != null)
throw new IllegalStateException(String.format("task %s failed with exception %s", task.getId(), task
.getError().toString()));
return task.getStatus() == Task.Status.SUCCESS; return task.getStatus() == Task.Status.SUCCESS;
} }
private Task refresh(String taskId) {
return client.getBrowsingClient().getTask(taskId);
}
} }

View File

@ -20,6 +20,7 @@
package org.jclouds.savvis.vpdc.xml; package org.jclouds.savvis.vpdc.xml;
import static org.jclouds.util.SaxUtils.currentOrNull; import static org.jclouds.util.SaxUtils.currentOrNull;
import static org.jclouds.util.SaxUtils.equalsOrSuffix;
import org.jclouds.http.functions.ParseSax; import org.jclouds.http.functions.ParseSax;
import org.jclouds.savvis.vpdc.domain.FirewallRule; import org.jclouds.savvis.vpdc.domain.FirewallRule;
@ -47,33 +48,33 @@ public class FirewallRuleHandler extends ParseSax.HandlerWithResult<FirewallRule
@Override @Override
public void endElement(String uri, String localName, String qName) throws SAXException { public void endElement(String uri, String localName, String qName) throws SAXException {
String current = currentOrNull(currentText); String current = currentOrNull(currentText);
if(current != null){ if (current != null) {
if (qName.endsWith("Type")) { if (equalsOrSuffix(qName, "Type")) {
builder.firewallType(current); builder.firewallType(current);
} else if (qName.endsWith("IsEnabled")) { } else if (equalsOrSuffix(qName, "IsEnabled")) {
builder.isEnabled(Boolean.parseBoolean(current)); builder.isEnabled(Boolean.parseBoolean(current));
} else if (qName.endsWith("Source")) { } else if (equalsOrSuffix(qName, "Source")) {
builder.source(current); builder.source(current);
} else if (qName.endsWith("Destination")) { } else if (equalsOrSuffix(qName, "Destination")) {
builder.destination(current); builder.destination(current);
} else if (qName.endsWith("Port")) { } else if (equalsOrSuffix(qName, "Port")) {
builder.port(current); builder.port(current);
} else if (qName.endsWith("Policy")) { } else if (equalsOrSuffix(qName, "Policy")) {
builder.policy(current); builder.policy(current);
} else if (qName.endsWith("Description")) { } else if (equalsOrSuffix(qName, "Description")) {
builder.description(current); builder.description(current);
} else if (qName.endsWith("Log")) { } else if (equalsOrSuffix(qName, "Log")) {
builder.isLogged(Boolean.parseBoolean(current)); builder.isLogged(Boolean.parseBoolean(current));
} else if (qName.endsWith("Tcp")) { } else if (equalsOrSuffix(qName, "Tcp")) {
builder.protocol("Tcp"); builder.protocol("Tcp");
} else if (qName.contains("Udp") || qName.contains("udp")) { } else if (qName.contains("Udp") || qName.contains("udp")) {
builder.protocol("Udp"); builder.protocol("Udp");
} else if (qName.contains("Icmp") || qName.contains("icmp") || } else if (qName.contains("Icmp") || qName.contains("icmp") || qName.contains("Ping")
qName.contains("Ping") || qName.contains("ping")) { || qName.contains("ping")) {
builder.protocol("Icmp-ping"); builder.protocol("Icmp-ping");
} }
} }
currentText = new StringBuilder(); currentText = new StringBuilder();
} }

View File

@ -20,6 +20,7 @@
package org.jclouds.savvis.vpdc.xml; package org.jclouds.savvis.vpdc.xml;
import static org.jclouds.util.SaxUtils.currentOrNull; import static org.jclouds.util.SaxUtils.currentOrNull;
import static org.jclouds.util.SaxUtils.equalsOrSuffix;
import javax.inject.Inject; import javax.inject.Inject;
@ -52,32 +53,32 @@ public class FirewallServiceHandler extends ParseSax.HandlerWithResult<FirewallS
} }
public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException { public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
if (qName.endsWith("FirewallService")) { if (equalsOrSuffix(qName, "FirewallService")) {
inFirewallService = true; inFirewallService = true;
} else if (qName.endsWith("FirewallRule")) { } else if (equalsOrSuffix(qName, "FirewallRule")) {
inFirewallRule = true; inFirewallRule = true;
firewallRuleHandler.startElement(uri, localName, qName, attrs); firewallRuleHandler.startElement(uri, localName, qName, attrs);
} }
} }
@Override @Override
public void endElement(String uri, String localName, String qName) throws SAXException { public void endElement(String uri, String localName, String qName) throws SAXException {
if (qName.endsWith("FirewallService")) { if (equalsOrSuffix(qName, "FirewallService")) {
inFirewallService = false; inFirewallService = false;
} else if(qName.endsWith("FirewallRule")) { } else if (equalsOrSuffix(qName, "FirewallRule")) {
builder.firewallRule(firewallRuleHandler.getResult()); builder.firewallRule(firewallRuleHandler.getResult());
inFirewallRule = false; inFirewallRule = false;
} else if (qName.endsWith("isEnabled")) { } else if (equalsOrSuffix(qName, "isEnabled")) {
if(inFirewallService){ if (inFirewallService) {
String current = currentOrNull(currentText); String current = currentOrNull(currentText);
if(current != null){ if (current != null) {
builder.isEnabled(Boolean.parseBoolean(current)); builder.isEnabled(Boolean.parseBoolean(current));
} }
} }
} }
if (inFirewallRule) { if (inFirewallRule) {
firewallRuleHandler.endElement(uri, localName, qName); firewallRuleHandler.endElement(uri, localName, qName);
} }
currentText = new StringBuilder(); currentText = new StringBuilder();
} }

View File

@ -22,6 +22,7 @@ package org.jclouds.savvis.vpdc.xml;
import static org.jclouds.savvis.vpdc.util.Utils.cleanseAttributes; import static org.jclouds.savvis.vpdc.util.Utils.cleanseAttributes;
import static org.jclouds.savvis.vpdc.util.Utils.currentOrNull; import static org.jclouds.savvis.vpdc.util.Utils.currentOrNull;
import static org.jclouds.savvis.vpdc.util.Utils.newResource; import static org.jclouds.savvis.vpdc.util.Utils.newResource;
import static org.jclouds.util.SaxUtils.equalsOrSuffix;
import java.util.Map; import java.util.Map;
@ -53,22 +54,22 @@ public class NetworkHandler extends ParseSax.HandlerWithResult<Network> {
@Override @Override
public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException { public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
Map<String, String> attributes = cleanseAttributes(attrs); Map<String, String> attributes = cleanseAttributes(attrs);
if (qName.endsWith("Network")) { if (equalsOrSuffix(qName, "Network")) {
// savvis doesn't add href in the header for some reason // savvis doesn't add href in the header for some reason
if (!attributes.containsKey("href") && getRequest() != null) if (!attributes.containsKey("href") && getRequest() != null)
attributes = ImmutableMap.<String, String> builder().putAll(attributes) attributes = ImmutableMap.<String, String> builder().putAll(attributes)
.put("href", getRequest().getEndpoint().toASCIIString()).build(); .put("href", getRequest().getEndpoint().toASCIIString()).build();
Resource org = newResource(attributes); Resource org = newResource(attributes);
builder.name(org.getName()).type(org.getType()).id(org.getId()).href(org.getHref()); builder.name(org.getName()).type(org.getType()).id(org.getId()).href(org.getHref());
} else if (qName.endsWith("NatRule")) { } else if (equalsOrSuffix(qName, "NatRule")) {
builder.internalToExternalNATRule(attributes.get("internalIP"), attributes.get("externalIP")); builder.internalToExternalNATRule(attributes.get("internalIP"), attributes.get("externalIP"));
} }
} }
public void endElement(String uri, String name, String qName) { public void endElement(String uri, String name, String qName) {
if (qName.endsWith("Gateway")) { if (equalsOrSuffix(qName, "Gateway")) {
builder.gateway(currentOrNull(currentText)); builder.gateway(currentOrNull(currentText));
} else if (qName.endsWith("Netmask")) { } else if (equalsOrSuffix(qName, "Netmask")) {
builder.netmask(currentOrNull(currentText)); builder.netmask(currentOrNull(currentText));
} }
currentText = new StringBuilder(); currentText = new StringBuilder();

View File

@ -22,6 +22,7 @@ package org.jclouds.savvis.vpdc.xml;
import static org.jclouds.savvis.vpdc.util.Utils.cleanseAttributes; import static org.jclouds.savvis.vpdc.util.Utils.cleanseAttributes;
import static org.jclouds.savvis.vpdc.util.Utils.currentOrNull; import static org.jclouds.savvis.vpdc.util.Utils.currentOrNull;
import static org.jclouds.savvis.vpdc.util.Utils.newResource; import static org.jclouds.savvis.vpdc.util.Utils.newResource;
import static org.jclouds.util.SaxUtils.equalsOrSuffix;
import java.util.Map; import java.util.Map;
@ -54,14 +55,14 @@ public class OrgHandler extends ParseSax.HandlerWithResult<Org> {
@Override @Override
public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException { public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
Map<String, String> attributes = cleanseAttributes(attrs); Map<String, String> attributes = cleanseAttributes(attrs);
if (qName.endsWith("Org")) { if (equalsOrSuffix(qName, "Org")) {
// savvis doesn't add href in the header for some reason // savvis doesn't add href in the header for some reason
if (!attributes.containsKey("href") && getRequest() != null) if (!attributes.containsKey("href") && getRequest() != null)
attributes = ImmutableMap.<String, String> builder().putAll(attributes) attributes = ImmutableMap.<String, String> builder().putAll(attributes)
.put("href", getRequest().getEndpoint().toASCIIString()).build(); .put("href", getRequest().getEndpoint().toASCIIString()).build();
Resource org = newResource(attributes); Resource org = newResource(attributes);
builder.name(org.getName()).type(org.getType()).id(org.getId()).href(org.getHref()); builder.name(org.getName()).type(org.getType()).id(org.getId()).href(org.getHref());
} else if (qName.endsWith("Link")) { } else if (equalsOrSuffix(qName, "Link")) {
Link link = Link.class.cast(newResource(attributes)); Link link = Link.class.cast(newResource(attributes));
if ("down".equals(link.getRel())) if ("down".equals(link.getRel()))
builder.vDC(link); builder.vDC(link);
@ -71,7 +72,7 @@ public class OrgHandler extends ParseSax.HandlerWithResult<Org> {
} }
public void endElement(String uri, String name, String qName) { public void endElement(String uri, String name, String qName) {
if (qName.endsWith("Description")) { if (equalsOrSuffix(qName, "Description")) {
builder.description(currentOrNull(currentText)); builder.description(currentOrNull(currentText));
} }
currentText = new StringBuilder(); currentText = new StringBuilder();

View File

@ -2,6 +2,7 @@ package org.jclouds.savvis.vpdc.xml;
import static org.jclouds.savvis.vpdc.util.Utils.cleanseAttributes; import static org.jclouds.savvis.vpdc.util.Utils.cleanseAttributes;
import static org.jclouds.savvis.vpdc.util.Utils.newResource; import static org.jclouds.savvis.vpdc.util.Utils.newResource;
import static org.jclouds.util.SaxUtils.equalsOrSuffix;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
@ -32,7 +33,7 @@ public class OrgListHandler extends ParseSax.HandlerWithResult<Set<Resource>> {
@Override @Override
public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException { public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
Map<String, String> attributes = cleanseAttributes(attrs); Map<String, String> attributes = cleanseAttributes(attrs);
if (qName.endsWith("Org")) { if (equalsOrSuffix(qName, "Org")) {
org.add(newResource(attributes)); org.add(newResource(attributes));
} }
} }

View File

@ -21,6 +21,7 @@ package org.jclouds.savvis.vpdc.xml;
import static org.jclouds.savvis.vpdc.util.Utils.cleanseAttributes; import static org.jclouds.savvis.vpdc.util.Utils.cleanseAttributes;
import static org.jclouds.savvis.vpdc.util.Utils.newResource; import static org.jclouds.savvis.vpdc.util.Utils.newResource;
import static org.jclouds.util.SaxUtils.equalsOrSuffix;
import java.util.Date; import java.util.Date;
import java.util.Map; import java.util.Map;
@ -65,7 +66,7 @@ public class TaskHandler extends ParseSax.HandlerWithResult<Task> {
@Override @Override
public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException { public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
Map<String, String> attributes = cleanseAttributes(attrs); Map<String, String> attributes = cleanseAttributes(attrs);
if (qName.endsWith("Task")) { if (equalsOrSuffix(qName, "Task")) {
Resource task = newResource(attributes); Resource task = newResource(attributes);
builder.id(task.getId()); builder.id(task.getId());
builder.type(task.getType()); builder.type(task.getType());
@ -75,11 +76,11 @@ public class TaskHandler extends ParseSax.HandlerWithResult<Task> {
if (attributes.containsKey("endTime")) if (attributes.containsKey("endTime"))
builder.endTime(parseDate(attributes.get("endTime"))); builder.endTime(parseDate(attributes.get("endTime")));
builder.status(Task.Status.fromValue(attributes.get("status"))); builder.status(Task.Status.fromValue(attributes.get("status")));
} else if (qName.endsWith("Owner")) { } else if (equalsOrSuffix(qName, "Owner")) {
builder.owner(Utils.newResource(attributes)); builder.owner(Utils.newResource(attributes));
} else if (qName.endsWith("Result")) { } else if (equalsOrSuffix(qName, "Result")) {
builder.result(Utils.newResource(attributes)); builder.result(Utils.newResource(attributes));
} else if (qName.endsWith("Error")) { } else if (equalsOrSuffix(qName, "Error")) {
builder.error(new TaskError(attributes.get("message"), Integer.parseInt(attributes.get("majorErrorCode")), builder.error(new TaskError(attributes.get("message"), Integer.parseInt(attributes.get("majorErrorCode")),
Integer.parseInt(attributes.get("minorErrorCode")), attributes.get("vendorSpecificErrorCode"))); Integer.parseInt(attributes.get("minorErrorCode")), attributes.get("vendorSpecificErrorCode")));
} }

View File

@ -19,6 +19,8 @@
package org.jclouds.savvis.vpdc.xml; package org.jclouds.savvis.vpdc.xml;
import static org.jclouds.util.SaxUtils.equalsOrSuffix;
import java.util.Set; import java.util.Set;
import javax.inject.Inject; import javax.inject.Inject;
@ -60,7 +62,7 @@ public class TasksListHandler extends ParseSax.HandlerWithResult<Set<Task>> {
@Override @Override
public void endElement(String uri, String localName, String qName) throws SAXException { public void endElement(String uri, String localName, String qName) throws SAXException {
taskHandler.endElement(uri, localName, qName); taskHandler.endElement(uri, localName, qName);
if (qName.equals("Task")) { if (equalsOrSuffix(qName, "Task")) {
this.tasks.add(taskHandler.getResult()); this.tasks.add(taskHandler.getResult());
} }
} }

View File

@ -22,6 +22,7 @@ package org.jclouds.savvis.vpdc.xml;
import static org.jclouds.savvis.vpdc.util.Utils.cleanseAttributes; import static org.jclouds.savvis.vpdc.util.Utils.cleanseAttributes;
import static org.jclouds.savvis.vpdc.util.Utils.currentOrNull; import static org.jclouds.savvis.vpdc.util.Utils.currentOrNull;
import static org.jclouds.savvis.vpdc.util.Utils.newResource; import static org.jclouds.savvis.vpdc.util.Utils.newResource;
import static org.jclouds.util.SaxUtils.equalsOrSuffix;
import java.util.Map; import java.util.Map;
@ -54,24 +55,24 @@ public class VDCHandler extends ParseSax.HandlerWithResult<VDC> {
@Override @Override
public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException { public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
Map<String, String> attributes = cleanseAttributes(attrs); Map<String, String> attributes = cleanseAttributes(attrs);
if (qName.endsWith("Vdc")) { if (equalsOrSuffix(qName, "Vdc")) {
// savvis doesn't add href in the header for some reason // savvis doesn't add href in the header for some reason
if (!attributes.containsKey("href") && getRequest() != null) if (!attributes.containsKey("href") && getRequest() != null)
attributes = ImmutableMap.<String, String> builder().putAll(attributes) attributes = ImmutableMap.<String, String> builder().putAll(attributes)
.put("href", getRequest().getEndpoint().toASCIIString()).build(); .put("href", getRequest().getEndpoint().toASCIIString()).build();
Resource vDC = newResource(attributes); Resource vDC = newResource(attributes);
builder.name(vDC.getName()).type(vDC.getType()).id(vDC.getId()).href(vDC.getHref()); builder.name(vDC.getName()).type(vDC.getType()).id(vDC.getId()).href(vDC.getHref());
} else if (qName.endsWith("Network")) { } else if (equalsOrSuffix(qName, "Network")) {
builder.availableNetwork(newResource(attributes)); builder.availableNetwork(newResource(attributes));
} else if (qName.endsWith("ResourceEntity")) { } else if (equalsOrSuffix(qName, "ResourceEntity")) {
builder.resourceEntity(newResource(attributes)); builder.resourceEntity(newResource(attributes));
} }
} }
public void endElement(String uri, String name, String qName) { public void endElement(String uri, String name, String qName) {
if (qName.endsWith("Description")) { if (equalsOrSuffix(qName, "Description")) {
builder.description(currentOrNull(currentText)); builder.description(currentOrNull(currentText));
} else if (qName.endsWith("OfferingTag")) { } else if (equalsOrSuffix(qName, "OfferingTag")) {
builder.status(Status.fromValue(currentOrNull(currentText))); builder.status(Status.fromValue(currentOrNull(currentText)));
} }
currentText = new StringBuilder(); currentText = new StringBuilder();

View File

@ -20,6 +20,7 @@
package org.jclouds.savvis.vpdc.xml; package org.jclouds.savvis.vpdc.xml;
import static org.jclouds.savvis.vpdc.util.Utils.newResource; import static org.jclouds.savvis.vpdc.util.Utils.newResource;
import static org.jclouds.util.SaxUtils.equalsOrSuffix;
import java.util.Map; import java.util.Map;
@ -63,7 +64,7 @@ public class VMHandler extends ParseSax.HandlerWithResult<VM> {
public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException { public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
Map<String, String> attributes = Utils.cleanseAttributes(attrs); Map<String, String> attributes = Utils.cleanseAttributes(attrs);
if (qName.endsWith("VApp")) { if (equalsOrSuffix(qName, "VApp")) {
// savvis doesn't add href in the header for some reason // savvis doesn't add href in the header for some reason
if (!attributes.containsKey("href") && getRequest() != null) if (!attributes.containsKey("href") && getRequest() != null)
attributes = ImmutableMap.<String, String> builder().putAll(attributes) attributes = ImmutableMap.<String, String> builder().putAll(attributes)
@ -71,7 +72,7 @@ public class VMHandler extends ParseSax.HandlerWithResult<VM> {
Resource vApp = newResource(attributes); Resource vApp = newResource(attributes);
builder.name(vApp.getName()).type(vApp.getType()).id(vApp.getId()).href(vApp.getHref()); builder.name(vApp.getName()).type(vApp.getType()).id(vApp.getId()).href(vApp.getHref());
builder.status(VM.Status.fromValue(attributes.get("status"))); builder.status(VM.Status.fromValue(attributes.get("status")));
} else if (qName.endsWith("OperatingSystemSection")) { } else if (equalsOrSuffix(qName, "OperatingSystemSection")) {
inOs = true; inOs = true;
if (attributes.containsKey("id")) if (attributes.containsKey("id"))
builder.osType(Integer.parseInt(attributes.get("id"))); builder.osType(Integer.parseInt(attributes.get("id")));
@ -84,16 +85,16 @@ public class VMHandler extends ParseSax.HandlerWithResult<VM> {
@Override @Override
public void endElement(String uri, String localName, String qName) throws SAXException { public void endElement(String uri, String localName, String qName) throws SAXException {
if (qName.endsWith("OperatingSystemSection")) { if (equalsOrSuffix(qName, "OperatingSystemSection")) {
inOs = false; inOs = false;
} else if (inOs && qName.endsWith("Description")) { } else if (inOs && equalsOrSuffix(qName, "Description")) {
builder.osDescripton(Utils.currentOrNull(currentText)); builder.osDescripton(Utils.currentOrNull(currentText));
} else if (qName.endsWith("IpAddress")) { } else if (equalsOrSuffix(qName, "IpAddress")) {
builder.ipAddress(Utils.currentOrNull(currentText)); builder.ipAddress(Utils.currentOrNull(currentText));
} else if (qName.endsWith("NetworkSection")) { } else if (equalsOrSuffix(qName, "NetworkSection")) {
networkSectionHandler.endElement(uri, localName, qName); networkSectionHandler.endElement(uri, localName, qName);
builder.networkSection(networkSectionHandler.getResult()); builder.networkSection(networkSectionHandler.getResult());
} else if (qName.endsWith("Item")) { } else if (equalsOrSuffix(qName, "Item")) {
allocationHandler.endElement(uri, localName, qName); allocationHandler.endElement(uri, localName, qName);
builder.resourceAllocation(allocationHandler.getResult()); builder.resourceAllocation(allocationHandler.getResult());
} else { } else {

View File

@ -32,6 +32,7 @@ import org.jclouds.domain.Credentials;
import org.jclouds.net.IPSocket; import org.jclouds.net.IPSocket;
import org.jclouds.predicates.RetryablePredicate; import org.jclouds.predicates.RetryablePredicate;
import org.jclouds.predicates.SocketOpen; import org.jclouds.predicates.SocketOpen;
import org.jclouds.savvis.vpdc.domain.Resource;
import org.jclouds.savvis.vpdc.domain.Task; import org.jclouds.savvis.vpdc.domain.Task;
import org.jclouds.savvis.vpdc.domain.VM; import org.jclouds.savvis.vpdc.domain.VM;
import org.jclouds.savvis.vpdc.domain.VMSpec; import org.jclouds.savvis.vpdc.domain.VMSpec;
@ -58,6 +59,7 @@ public class VMClientLiveTest extends BaseVPDCClientLiveTest {
private RetryablePredicate<IPSocket> socketTester; private RetryablePredicate<IPSocket> socketTester;
private RetryablePredicate<String> taskTester; private RetryablePredicate<String> taskTester;
private String email = checkNotNull(System.getProperty("test." + provider + ".email"), "test." + provider + ".email");
private String username = checkNotNull(System.getProperty("test." + provider + ".loginUser"), "test." + provider private String username = checkNotNull(System.getProperty("test." + provider + ".loginUser"), "test." + provider
+ ".loginUser"); + ".loginUser");
private String password = checkNotNull(System.getProperty("test." + provider + ".loginPassword"), "test." + provider private String password = checkNotNull(System.getProperty("test." + provider + ".loginPassword"), "test." + provider
@ -79,7 +81,20 @@ public class VMClientLiveTest extends BaseVPDCClientLiveTest {
public void testCreateVirtualMachine() throws Exception { public void testCreateVirtualMachine() throws Exception {
billingSiteId = context.getApi().getBrowsingClient().getOrg(null).getId();// default billingSiteId = context.getApi().getBrowsingClient().getOrg(null).getId();// default
vpdcId = Iterables.get(context.getApi().getBrowsingClient().getOrg(billingSiteId).getVDCs(), 0).getId(); vpdcId = Iterables.find(context.getApi().getBrowsingClient().getOrg(billingSiteId).getVDCs(),
new Predicate<Resource>() {
// try to find the first VDC owned by the current user
// check here for what the email property might be, or in
// the jclouds-wire.log
@Override
public boolean apply(Resource arg0) {
String description = context.getApi().getBrowsingClient().getVDCInOrg(billingSiteId, arg0.getId())
.getDescription();
return description.indexOf(email) != -1;
}
}).getId();
String networkTierName = Iterables.get( String networkTierName = Iterables.get(
context.getApi().getBrowsingClient().getVDCInOrg(billingSiteId, vpdcId).getAvailableNetworks(), 0) context.getApi().getBrowsingClient().getVDCInOrg(billingSiteId, vpdcId).getAvailableNetworks(), 0)
.getName(); .getName();
@ -95,8 +110,13 @@ public class VMClientLiveTest extends BaseVPDCClientLiveTest {
}); });
System.out.printf("vpdcId %s, networkName %s, name %s, os %s%n", vpdcId, networkTierName, name, os); System.out.printf("vpdcId %s, networkName %s, name %s, os %s%n", vpdcId, networkTierName, name, os);
// TODO: determine the sizes available in the VDC, for example there's
// a minimum size of boot disk, and also a preset combination of cpu count vs ram
Task task = client.addVMIntoVDC(billingSiteId, vpdcId, networkTierName, name, VMSpec.builder() Task task = client.addVMIntoVDC(billingSiteId, vpdcId, networkTierName, name, VMSpec.builder()
.operatingSystem(os).build()); .operatingSystem(os).memoryInGig(2).build());
// make sure there's no error
assert task.getId() != null && task.getError() != null : task;
assert this.taskTester.apply(task.getId()); assert this.taskTester.apply(task.getId());
vm = context.getApi().getBrowsingClient().getVMInVDC(billingSiteId, vpdcId, task.getOwner().getId()); vm = context.getApi().getBrowsingClient().getVMInVDC(billingSiteId, vpdcId, task.getOwner().getId());

View File

@ -37,6 +37,7 @@ public class TaskHandlerTest extends BaseHandlerTest {
Task result = factory.create(injector.getInstance(TaskHandler.class)).parse(is); Task result = factory.create(injector.getInstance(TaskHandler.class)).parse(is);
Task expects = Task Task expects = Task
.builder() .builder()
.id("21-1002")
.endTime(dateService.iso8601DateParse("2010-05-26T08:09:09.000+08:00")) .endTime(dateService.iso8601DateParse("2010-05-26T08:09:09.000+08:00"))
.startTime(dateService.iso8601DateParse("2010-05-26T08:08:08.000+08:00")) .startTime(dateService.iso8601DateParse("2010-05-26T08:08:08.000+08:00"))
.status(Task.Status.SUCCESS) .status(Task.Status.SUCCESS)
@ -70,6 +71,7 @@ public class TaskHandlerTest extends BaseHandlerTest {
Task result = factory.create(injector.getInstance(TaskHandler.class)).parse(is); Task result = factory.create(injector.getInstance(TaskHandler.class)).parse(is);
Task expects = Task Task expects = Task
.builder() .builder()
.id("21-1002")
.endTime(dateService.iso8601DateParse("2010-05-26T08:09:09.000+08:00")) .endTime(dateService.iso8601DateParse("2010-05-26T08:09:09.000+08:00"))
.startTime(dateService.iso8601DateParse("2010-05-26T08:08:08.000+08:00")) .startTime(dateService.iso8601DateParse("2010-05-26T08:08:08.000+08:00"))
.status(Task.Status.SUCCESS) .status(Task.Status.SUCCESS)
@ -103,10 +105,11 @@ public class TaskHandlerTest extends BaseHandlerTest {
Task result = factory.create(injector.getInstance(TaskHandler.class)).parse(is); Task result = factory.create(injector.getInstance(TaskHandler.class)).parse(is);
Task expects = Task Task expects = Task
.builder() .builder()
.id("6904")
.startTime(dateService.iso8601DateParse("2010-05-26T08:08:08.000+08:00")) .startTime(dateService.iso8601DateParse("2010-05-26T08:08:08.000+08:00"))
.status(Task.Status.RUNNING) .status(Task.Status.RUNNING)
.type("application/vnd.vmware.vcloud.task+xml") .type("application/vnd.vmware.vcloud.task+xml")
.href(URI.create("https://api.symphonyvpdc.savvis.net/rest/api/v0.8/task/21-1002")) .href(URI.create("https://api.symphonyvpdc.savvis.net/rest/api/v0.8/task/6904"))
.owner( .owner(
Resource Resource
.builder() .builder()
@ -136,31 +139,31 @@ public class TaskHandlerTest extends BaseHandlerTest {
Task result = factory.create(injector.getInstance(TaskHandler.class)).parse(is); Task result = factory.create(injector.getInstance(TaskHandler.class)).parse(is);
Task expects = Task Task expects = Task
.builder() .builder()
.id("6904") .id("113927-1005")
.startTime(dateService.iso8601DateParse("2010-05-26T08:08:08.000+08:00")) .startTime(dateService.iso8601DateParse("2011-03-24T20:37:34.000Z"))
.status(Task.Status.QUEUED) .status(Task.Status.QUEUED)
.type("application/vnd.vmware.vcloud.task+xml") .href(URI.create("https://api.symphonyVPDC.savvis.net/rest/api/v0.8/task/113927-1005"))
.href(URI.create("https://api.symphonyvpdc.savvis.net/rest/api/v0.8/task/6904"))
.owner( .owner(
Resource Resource
.builder() .builder()
.id("2736") .id("4253")
.name("mockVpdc8") .name("Foo")
.type("application/vnd.vmware.vcloud.vdc+xml") .type("application/vnd.vmware.vcloud.vdc+xml")
.href(URI .href(URI
.create("https://api.symphonyvpdc.savvis.net/rest/api/v0.8/org/100000.0/vdc/2736")) .create("https://api.symphonyVPDC.savvis.net/rest/api/v0.8/org/606677.0/vdc/4253"))
.build()) .build())
.result( .result(
Resource Resource
.builder() .builder()
.id("1002") .id("1005")
.name("mock_vpdc_item_007") .name("adriancole")
.type("application/vnd.vmware.vcloud.catalogItem+xml") .type("application/vnd.vmware.vcloud.vApp+xml")
.href(URI .href(URI
.create("https://api.symphonyvpdc.savvis.net/rest/api/v0.8/org/100000.0/vdc/2736/vApp/1002")) .create("https://api.symphonyVPDC.savvis.net/rest/api/v0.8/org/606677.0/vdc/4253/vApp/1005"))
.build()).build(); .build()).build();
assertEquals(result.toString(), expects.toString()); assertEquals(result.toString(), expects.toString());
assertEquals(result.getError(), null);
assert result.getId() != null;
} }
public void testFailed() { public void testFailed() {
@ -203,12 +206,9 @@ public class TaskHandlerTest extends BaseHandlerTest {
Task result = factory.create(injector.getInstance(TaskHandler.class)).parse(is); Task result = factory.create(injector.getInstance(TaskHandler.class)).parse(is);
Task expects = Task Task expects = Task
.builder() .builder()
.id("6904-123")
.startTime(dateService.iso8601DateParse("2010-05-26T08:08:08.000+08:00")) .startTime(dateService.iso8601DateParse("2010-05-26T08:08:08.000+08:00"))
.endTime(dateService.iso8601DateParse("2010-05-26T08:09:09.000+08:00")) .endTime(dateService.iso8601DateParse("2010-05-26T08:09:09.000+08:00"))
.status(Task.Status.ERROR) .status(Task.Status.ERROR)
.type("application/vnd.vmware.vcloud.task+xml")
.href(URI.create("https://api.symphonyvpdc.savvis.net/rest/api/v0.8/task/6904-123"))
.error( .error(
TaskError TaskError
.builder() .builder()
@ -228,12 +228,12 @@ public class TaskHandlerTest extends BaseHandlerTest {
Task result = factory.create(injector.getInstance(TaskHandler.class)).parse(is); Task result = factory.create(injector.getInstance(TaskHandler.class)).parse(is);
Task expects = Task Task expects = Task
.builder() .builder()
.id("6904-123") .id("3904-1002")
.startTime(dateService.iso8601DateParse("2010-05-26T08:08:08.000+08:00")) .startTime(dateService.iso8601DateParse("2010-05-26T08:08:08.000+08:00"))
.endTime(dateService.iso8601DateParse("2010-05-26T08:09:09.000+08:00")) .endTime(dateService.iso8601DateParse("2010-05-26T08:09:09.000+08:00"))
.status(Task.Status.NONE) .status(Task.Status.NONE)
.type("application/vnd.vmware.vcloud.task+xml") .type("application/vnd.vmware.vcloud.task+xml")
.href(URI.create("https://api.symphonyvpdc.savvis.net/rest/api/v0.8/task/6904-123")) .href(URI.create("https://api.symphonyvpdc.savvis.net/rest/api/v0.8/task/3904-1002"))
.error( .error(
TaskError TaskError
.builder() .builder()

View File

@ -0,0 +1 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><vApp:TasksList xmlns:common="http://schemas.dmtf.org/wbem/wscim/1/common" xmlns:vApp="http://www.vmware.com/vcloud/v0.8" xmlns:rasd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData" xmlns:vssd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_VirtualSystemSettingData" xmlns:ovf="http://schemas.dmtf.org/ovf/envelope/1"><vApp:Task status="error"><vApp:Error vendorSpecificErrorCode="1016" minorErrorCode="471" majorErrorCode="500" message="The vApp CPU : {3 GHz * 1} and Memory : {1} is not to be supported."/></vApp:Task></vApp:TasksList>

View File

@ -1,15 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<vApp:TasksList xmlns:common="http://schemas.dmtf.org/wbem/wscim/1/common" <vApp:TasksList xmlns:common="http://schemas.dmtf.org/wbem/wscim/1/common" xmlns:vApp="http://www.vmware.com/vcloud/v0.8" xmlns:rasd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData" xmlns:vssd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_VirtualSystemSettingData" xmlns:ovf="http://schemas.dmtf.org/ovf/envelope/1">
xmlns:vApp="http://www.vmware.com/vcloud/v0.8" <vApp:Task startTime="2011-03-24T20:37:34.000Z" status="queued" href="https://api.symphonyVPDC.savvis.net/rest/api/v0.8/task/113927-1005">
xmlns:rasd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData" <vApp:Owner name="Foo" type="application/vnd.vmware.vcloud.vdc+xml" href="https://api.symphonyVPDC.savvis.net/rest/api/v0.8/org/606677.0/vdc/4253"/>
xmlns:vssd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_VirtualSystemSettingData" <vApp:Result name="adriancole" type="application/vnd.vmware.vcloud.vApp+xml" href="https://api.symphonyVPDC.savvis.net/rest/api/v0.8/org/606677.0/vdc/4253/vApp/1005"/>
xmlns:ovf="http://schemas.dmtf.org/ovf/envelope/1"> </vApp:Task>
<!--If Task status is queued, Savvis is not displaying endTime.-->
<vApp:Task startTime="2010-05-26T08:08:08.000+08:00" status="queued" type="application/vnd.vmware.vcloud.task+xml"
href="https://api.symphonyvpdc.savvis.net/rest/api/v0.8/task/6904">
<vApp:Owner name="mockVpdc8" type="application/vnd.vmware.vcloud.vdc+xml"
href="https://api.symphonyvpdc.savvis.net/rest/api/v0.8/org/100000.0/vdc/2736"/>
<vApp:Result name="mock_vpdc_item_007" type="application/vnd.vmware.vcloud.catalogItem+xml"
href="https://api.symphonyvpdc.savvis.net/rest/api/v0.8/org/100000.0/vdc/2736/vApp/1002"/>
</vApp:Task>
</vApp:TasksList> </vApp:TasksList>

View File

@ -0,0 +1 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><vApp:TasksList xmlns:common="http://schemas.dmtf.org/wbem/wscim/1/common" xmlns:vApp="http://www.vmware.com/vcloud/v0.8" xmlns:rasd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData" xmlns:vssd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_VirtualSystemSettingData" xmlns:ovf="http://schemas.dmtf.org/ovf/envelope/1"><vApp:Task status="error"><vApp:Error vendorSpecificErrorCode="-1" minorErrorCode="0" majorErrorCode="500" message="Please finish your previously deployment for vpdcId:1619"/></vApp:Task></vApp:TasksList>