Isue 112: hostingdotcom progress

git-svn-id: http://jclouds.googlecode.com/svn/trunk@2367 3d8758e0-26b5-11de-8745-db77d3ebf521
This commit is contained in:
adrian.f.cole 2009-12-03 07:56:25 +00:00
parent 1173689417
commit dcd2eb3403
12 changed files with 106 additions and 42 deletions

View File

@ -54,9 +54,9 @@ public class TaskImpl extends LinkImpl implements Task {
@Nullable DateTime endTime, NamedLink owner, @Nullable NamedLink result) {
super(type, location);
this.status = checkNotNull(status, "status");
this.startTime = checkNotNull(startTime, "startTime");
this.startTime = startTime;
this.endTime = endTime;
this.owner = checkNotNull(owner, "owner");
this.owner = owner;
this.result = result;
}

View File

@ -25,9 +25,11 @@ package org.jclouds.vcloud.xml;
import java.text.ParseException;
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;
@ -53,6 +55,9 @@ public class TaskHandler extends ParseSax.HandlerWithResult<Task> {
private DateTime endTime;
private Task task;
@Resource
protected Logger logger = Logger.NULL;
@Inject
public TaskHandler(DateService dateService) {
this.dateService = dateService;
@ -65,15 +70,19 @@ public class TaskHandler extends ParseSax.HandlerWithResult<Task> {
@Override
public void startElement(String uri, String localName, String qName, Attributes attributes)
throws SAXException {
if (qName.equals("Task")) {
if (qName.equalsIgnoreCase("Task")) {
if (attributes.getIndex("type") != -1)
taskLink = Utils.newLink(attributes);
status = TaskStatus.fromValue(attributes.getValue(attributes.getIndex("status")));
if (attributes.getIndex("startTime") != -1)
startTime = parseDate(attributes, "startTime");
if (attributes.getIndex("endTime") != -1) {
endTime = parseDate(attributes, "endTime");
}
} else if (qName.equals("Owner")) {
owner = Utils.newNamedLink(attributes);
} else if (qName.equals("Link")) {
taskLink = Utils.newNamedLink(attributes);
} else if (qName.equals("Result")) {
result = Utils.newNamedLink(attributes);
}
@ -85,17 +94,22 @@ public class TaskHandler extends ParseSax.HandlerWithResult<Task> {
} catch (RuntimeException e) {
if (e.getCause() instanceof ParseException) {
try {
return dateService.iso8601SecondsDateParse(attributes.getValue(attributes
.getIndex(attribute)));
} catch (RuntimeException ex) {
logger.error(e, "error parsing date");
}
} else {
throw e;
logger.error(e, "error parsing date");
}
}
return null;
}
@Override
public void endElement(String uri, String localName, String qName) throws SAXException {
if (qName.equals("Task")) {
if (qName.equalsIgnoreCase("Task")) {
this.task = new TaskImpl(taskLink.getType(), taskLink.getLocation(), status, startTime,
endTime, owner, result);
taskLink = null;

View File

@ -46,7 +46,6 @@ public class SetVCloudTokenCookieTest {
@BeforeTest
void setUp() {
filter = new SetVCloudTokenCookie(new Provider<String>() {
public String get() {
return "token";
}

View File

@ -56,7 +56,7 @@ public class TaskHandlerTest extends BaseHandlerTest {
}
public void testApplyInputStream() {
InputStream is = getClass().getResourceAsStream("/taskslist.xml");
InputStream is = getClass().getResourceAsStream("/task.xml");
Task result = factory.create(injector.getInstance(TaskHandler.class)).parse(is);
@ -75,4 +75,31 @@ public class TaskHandlerTest extends BaseHandlerTest {
assertEquals(result, expects);
}
public void testApplyInputStream3() {
InputStream is = getClass().getResourceAsStream("/task-hosting-baddate.xml");
Task result = factory.create(injector.getInstance(TaskHandler.class)).parse(is);
Task expects = new TaskImpl(VCloudMediaType.TASK_XML, URI
.create("https://vcloud.safesecureweb.com/api/v0.8/task/d188849-37"),
TaskStatus.RUNNING, null, null, new NamedLinkImpl("188849", VCloudMediaType.VDC_XML,
URI.create("https://vcloud.safesecureweb.com/api/v0.8/vdc/188849")), null
);
assertEquals(result, expects);
}
public void testApplyInputStream2() {
InputStream is = getClass().getResourceAsStream("/task-hosting.xml");
Task result = factory.create(injector.getInstance(TaskHandler.class)).parse(is);
Task expects = new TaskImpl(VCloudMediaType.TASK_XML, URI
.create("https://vcloud.safesecureweb.com/api/v0.8/task/d188849-34"),
TaskStatus.QUEUED, null, null, null, null);
assertEquals(result, expects);
}
}

View File

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<Task xmlns="http://www.vmware.com/vcloud/v0.8/task"
xmlns:common="http://www.vmware.com/vcloud/common"
xsi:schemaLocation="http://www.vmware.com/vcloud/v0.8/task
https://vcloud.safesecureweb.com/ns/vcloud/task-1.0.xsd
http://www.vmware.com/vcloud/common
https://vcloud.safesecureweb.com/ns/vcloud/common-1.0.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
status="running" startTime="1/1/2001 12:00:00 AM">
<Link rel="self" href="https://vcloud.safesecureweb.com/api/v0.8/task/d188849-37" type="application/vnd.vmware.vcloud.task+xml" />
<Owner href="https://vcloud.safesecureweb.com/api/v0.8/vdc/188849" type="application/vnd.vmware.vcloud.vdc+xml" name="188849" />
</Task>

View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<task xmlns="http://www.vmware.com/vcloud/v0.8/task"
xmlns:common="http://www/vmware.com/vcloud/common"
xsi:schemaLocation="http://www/vmware.com/vcloud/task
https://vcloud.safesecureweb.com/ns/vcloud/task-1.0.xsd
http://www.vmware.com/vcloud/common
https://vcloud.safesecureweb.com/ns/vcloud/common-1.0.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
status="queued">
<Link rel="self" href="https://vcloud.safesecureweb.com/api/v0.8/task/d188849-34" type="application/vnd.vmware.vcloud.task+xml" />
</task>

View File

@ -37,10 +37,11 @@ import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions;
* @see <a href="https://community.vcloudexpress.terremark.com/en-us/discussion_forums/f/60.aspx" />
* @author Adrian Cole
*/
@Timeout(duration = 45, timeUnit = TimeUnit.SECONDS)
@Timeout(duration = 90, timeUnit = TimeUnit.SECONDS)
public interface HostingDotComVCloudClient extends VCloudClient {
@Override
@Timeout(duration = 180, timeUnit = TimeUnit.SECONDS)
HostingDotComVApp instantiateVAppTemplate(String appName, String templateId,
InstantiateVAppTemplateOptions... options);

View File

@ -7,6 +7,7 @@ import org.jclouds.vcloud.hostingdotcom.domain.internal.HostingDotComVAppImpl;
import org.jclouds.vcloud.xml.ResourceAllocationHandler;
import org.jclouds.vcloud.xml.VAppHandler;
import org.jclouds.vcloud.xml.VirtualSystemHandler;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
/**
@ -29,15 +30,17 @@ public class HostingDotComVAppHandler extends VAppHandler {
}
@Override
public void endElement(String uri, String localName, String qName) throws SAXException {
if (qName.equals("hmsns:username")) {
username = currentText.toString().trim();
} else if (qName.equals("hmsns:password")) {
password = currentText.toString().trim();
} else {
super.endElement(uri, localName, qName);
public void startElement(String uri, String localName, String qName, Attributes attributes)
throws SAXException {
super.startElement(uri, localName, qName, attributes);
if (attributes.getIndex("key") != -1) {
String key = attributes.getValue(attributes.getIndex("key"));
if ("username".equals(key)) {
username = attributes.getValue(attributes.getIndex("value"));
} else if ("password".equals(key)) {
password = attributes.getValue(attributes.getIndex("value"));
}
}
currentText = new StringBuilder();
}
}

View File

@ -93,16 +93,9 @@ public class HostingDotComVCloudComputeClient {
minMegs));
this.username = vAppResponse.getUsername();
this.password = vAppResponse.getPassword();
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
}
tmClient.getVApp(vAppResponse.getId());
logger.debug("<< instantiated VApp(%s)", vAppResponse.getId());
logger.debug(">> deploying vApp(%s)", vAppResponse.getId());
VApp vApp = blockUntilVAppStatusOrThrowException(vAppResponse, tmClient
.deployVApp(vAppResponse.getId()), "deploy", VAppStatus.OFF);
logger.debug("<< deployed vApp(%s)", vApp.getId());

View File

@ -158,7 +158,7 @@ public class HostingDotComVCloudComputeClientLiveTest {
@SuppressWarnings("unused")
@Provides
private Predicate<URI> successTester(TaskSuccess success) {
return new RetryablePredicate<URI>(success, 300, 10, TimeUnit.SECONDS);
return new RetryablePredicate<URI>(success, 600, 10, TimeUnit.SECONDS);
}
}).buildInjector();

View File

@ -54,12 +54,11 @@ public class HostingDotComVAppHandlerTest extends BaseHandlerTest {
HostingDotComVApp result = (HostingDotComVApp) factory.create(
injector.getInstance(HostingDotComVAppHandler.class)).parse(is);
HostingDotComVApp expects = new HostingDotComVAppImpl("188849-13", "188849-13", URI
.create("https://vcloud.safesecureweb.com/api/v0.8/vapp/188849-13"),
HostingDotComVApp expects = new HostingDotComVAppImpl("188849-33", "188849-33", URI
.create("https://vcloud.safesecureweb.com/api/v0.8/vapp/188849-33"),
VAppStatus.TODO_I_DONT_KNOW, ImmutableListMultimap.<String, InetAddress> of(), null,
null, ImmutableSortedSet.<ResourceAllocation> of(), "root", "peoplearelovely");
null, ImmutableSortedSet.<ResourceAllocation> of(), "root", "meatisyummy");
assertEquals(result, expects);
}
}

View File

@ -1,13 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<VApp name="188849-13" status="1"
href="https://vcloud.safesecureweb.com/api/v0.8/vapp/188849-13"
xmlns="http://www.vmware.com/vcloud/v0.8" xmlns:hmsns="https://vcloud.safesecureweb.com/ns/v1/VApp"
xmlns:ovf="http://schemas.dmtf.org/ovf/envelope/1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<VApp name="188849-33" status="1"
href="https://vcloud.safesecureweb.com/api/v0.8/vapp/188849-33"
xmlns="http://www.vmware.com/vcloud/v0.8"
xmlns:hmsns="https://vcloud.safesecureweb.com/ns/v1/VApp"
xmlns:ovf="http://schemas.dmtf.org/ovf/envelope/1"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.vmware.com/vcloud/1
https://vcloud.safesecureweb.com/ns/vcloud.xsd">
<Link rel="up"
href="https://vcloud.safesecureweb.com/api/v0.8/vdc/188849"
type="application/vnd.vmware.vcloud.vdc+xml" />
<hmsns:username>root</hmsns:username>
<hmsns:password>peoplearelovely</hmsns:password>
<Link rel="up" href="https://vcloud.safesecureweb.com/api/v0.8/vdc/188849" type="application/vnd.vmware.vcloud.vdc+xml" />
<ovf:ProductSection>
<ovf:Info>Product Section Details</ovf:Info>
<Property key="username" value="root" />
<Property key="password" value="meatisyummy" />
</ovf:ProductSection>
</VApp>