mirror of https://github.com/apache/jclouds.git
stabilized bluelock
This commit is contained in:
parent
ccb9709d05
commit
86129df416
|
@ -67,50 +67,47 @@ public class VCloudDestroyNodeStrategy implements DestroyNodeStrategy {
|
|||
VApp vApp = client.getVAppClient().getVApp(vappId);
|
||||
if (vApp == null)
|
||||
return null;
|
||||
vApp = powerOffVAppIfDeployed(vApp);
|
||||
|
||||
waitForPendingTasksToComplete(vApp);
|
||||
|
||||
vApp = undeployVAppIfDeployed(vApp);
|
||||
deleteVApp(vappId);
|
||||
deleteVApp(vApp);
|
||||
try {
|
||||
return getNode.getNode(id);
|
||||
} catch (AuthorizationException e) {
|
||||
// vcloud bug will sometimes throw an exception getting the vapp right after deleting it.
|
||||
logger.trace("authorization error getting %s after deletion: %s", id, e.getMessage());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
void deleteVApp(URI vappId) {
|
||||
logger.debug(">> deleting vApp(%s)", vappId);
|
||||
Task task = client.getVAppClient().deleteVApp(vappId);
|
||||
if (!successTester.apply(task.getHref())) {
|
||||
throw new RuntimeException(String.format("failed to %s %s: %s", "delete", vappId, task));
|
||||
void waitForPendingTasksToComplete(VApp vApp) {
|
||||
for (Task task : vApp.getTasks())
|
||||
waitForTask(task, vApp);
|
||||
}
|
||||
logger.debug("<< deleted vApp(%s)", vappId);
|
||||
|
||||
public void waitForTask(Task task, VApp vAppResponse) {
|
||||
if (!successTester.apply(task.getHref())) {
|
||||
throw new RuntimeException(String.format("failed to %s %s: %s", task.getName(), vAppResponse.getName(), task));
|
||||
}
|
||||
}
|
||||
|
||||
void deleteVApp(VApp vApp) {
|
||||
logger.debug(">> deleting vApp(%s)", vApp.getHref());
|
||||
waitForTask(client.getVAppClient().deleteVApp(vApp.getHref()), vApp);
|
||||
logger.debug("<< deleted vApp(%s)", vApp.getHref());
|
||||
}
|
||||
|
||||
VApp undeployVAppIfDeployed(VApp vApp) {
|
||||
if (vApp.getStatus().compareTo(Status.RESOLVED) > 0) {
|
||||
if (vApp.getStatus() != Status.OFF) {
|
||||
logger.debug(">> undeploying vApp(%s), current status: %s", vApp.getName(), vApp.getStatus());
|
||||
Task task = client.getVAppClient().undeployVApp(vApp.getHref());
|
||||
if (!successTester.apply(task.getHref())) {
|
||||
// TODO timeout
|
||||
throw new RuntimeException(String.format("failed to %s %s: %s", "undeploy", vApp.getName(), task));
|
||||
}
|
||||
try {
|
||||
waitForTask(client.getVAppClient().undeployVApp(vApp.getHref()), vApp);
|
||||
vApp = client.getVAppClient().getVApp(vApp.getHref());
|
||||
logger.debug("<< %s vApp(%s)", vApp.getStatus(), vApp.getName());
|
||||
} catch (IllegalStateException e) {
|
||||
logger.warn(e, "<< %s vApp(%s)", vApp.getStatus(), vApp.getName());
|
||||
}
|
||||
return vApp;
|
||||
}
|
||||
|
||||
VApp powerOffVAppIfDeployed(VApp vApp) {
|
||||
if (vApp.getStatus().compareTo(Status.OFF) > 0) {
|
||||
logger.debug(">> powering off vApp(%s), current status: %s", vApp.getName(), vApp.getStatus());
|
||||
Task task = client.getVAppClient().powerOffVApp(vApp.getHref());
|
||||
if (!successTester.apply(task.getHref())) {
|
||||
// TODO timeout
|
||||
throw new RuntimeException(String.format("failed to %s %s: %s", "powerOff", vApp.getName(), task));
|
||||
}
|
||||
vApp = client.getVAppClient().getVApp(vApp.getHref());
|
||||
logger.debug("<< %s vApp(%s)", vApp.getStatus(), vApp.getName());
|
||||
}
|
||||
return vApp;
|
||||
}
|
||||
|
|
|
@ -34,7 +34,9 @@ import org.jclouds.vcloud.domain.Catalog;
|
|||
import org.jclouds.vcloud.domain.CatalogItem;
|
||||
import org.jclouds.vcloud.domain.Org;
|
||||
import org.jclouds.vcloud.domain.ReferenceType;
|
||||
import org.jclouds.vcloud.domain.Status;
|
||||
import org.jclouds.vcloud.domain.Task;
|
||||
import org.jclouds.vcloud.domain.VApp;
|
||||
import org.jclouds.vcloud.domain.VAppTemplate;
|
||||
import org.jclouds.vcloud.options.CatalogItemOptions;
|
||||
import org.jclouds.vcloud.predicates.TaskSuccess;
|
||||
|
@ -125,20 +127,17 @@ public class VAppTemplateClientLiveTest extends BaseVCloudClientLiveTest {
|
|||
Predicate<URI> taskTester = new RetryablePredicate<URI>(new TaskSuccess(getVCloudApi()), 600, 5,
|
||||
TimeUnit.SECONDS);
|
||||
|
||||
// I have to powerOff first
|
||||
Task task = getVCloudApi().getVAppClient().powerOffVApp(URI.create(node.getId()));
|
||||
|
||||
// wait up to ten minutes per above
|
||||
assert taskTester.apply(task.getHref()) : node;
|
||||
|
||||
// having a problem where the api is returning an error telling us to stop!
|
||||
|
||||
// I have to undeploy first
|
||||
task = getVCloudApi().getVAppClient().undeployVApp(URI.create(node.getId()));
|
||||
Task task = getVCloudApi().getVAppClient().undeployVApp(URI.create(node.getId()));
|
||||
|
||||
// wait up to ten minutes per above
|
||||
assert taskTester.apply(task.getHref()) : node;
|
||||
|
||||
VApp vApp = getVCloudApi().getVAppClient().getVApp(URI.create(node.getId()));
|
||||
|
||||
// wait up to ten minutes per above
|
||||
assertEquals(vApp.getStatus(), Status.OFF);
|
||||
|
||||
// vdc is equiv to the node's location
|
||||
// vapp uri is the same as the node's id
|
||||
vappTemplate = getVCloudApi().getVAppTemplateClient().captureVAppAsTemplateInVDC(URI.create(node.getId()),
|
||||
|
@ -159,7 +158,7 @@ public class VAppTemplateClientLiveTest extends BaseVCloudClientLiveTest {
|
|||
assertEquals(item.getName(), "fooname");
|
||||
assertEquals(item.getDescription(), "description");
|
||||
assertEquals(item.getProperties(), ImmutableMap.of("foo", "bar"));
|
||||
assertEquals(item.getEntity().getName(), vappTemplate.getName());
|
||||
assertEquals(item.getEntity().getName(), "fooname");
|
||||
assertEquals(item.getEntity().getHref(), vappTemplate.getHref());
|
||||
assertEquals(item.getEntity().getType(), vappTemplate.getType());
|
||||
|
||||
|
|
|
@ -161,9 +161,9 @@ public class VmClientLiveTest extends BaseVCloudClientLiveTest {
|
|||
}
|
||||
|
||||
protected void checkVmOutput(String fooTxtContentsMadeByVMwareTools, String decodedVMwareToolsOutput) {
|
||||
assertEquals(decodedVMwareToolsOutput, script);
|
||||
// note that vmwaretools throws in \r characters when executing scripts
|
||||
assertEquals(fooTxtContentsMadeByVMwareTools, iLoveAscii + "\r\n");
|
||||
assertEquals(decodedVMwareToolsOutput, script);
|
||||
}
|
||||
|
||||
protected IPSocket getSocket(NodeMetadata node) {
|
||||
|
|
|
@ -88,8 +88,9 @@ public class ParseVCloudErrorFromHttpResponse implements HttpErrorHandler {
|
|||
|
||||
switch (response.getStatusCode()) {
|
||||
case 400:
|
||||
if (error != null && error.getMinorErrorCode() != null
|
||||
&& error.getMinorErrorCode() == MinorCode.BUSY_ENTITY)
|
||||
if (error != null
|
||||
&& (error.getMinorErrorCode() != null && error.getMinorErrorCode() == MinorCode.BUSY_ENTITY)
|
||||
|| (error.getMessage() != null && error.getMessage().indexOf("is not running") != -1))
|
||||
exception = new IllegalStateException(message, exception);
|
||||
else
|
||||
exception = new IllegalArgumentException(message, exception);
|
||||
|
|
|
@ -25,6 +25,7 @@ import org.jclouds.http.HttpErrorHandler;
|
|||
import org.jclouds.http.HttpResponseException;
|
||||
import org.jclouds.rest.AuthorizationException;
|
||||
import org.jclouds.rest.ResourceNotFoundException;
|
||||
import org.jclouds.vcloud.VCloudMediaType;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
/**
|
||||
|
@ -36,23 +37,32 @@ public class ParseVCloudErrorFromHttpResponseTest extends BaseHttpErrorHandlerTe
|
|||
|
||||
@Test
|
||||
public void testGet404SetsResourceNotFoundException() {
|
||||
assertCodeMakes("GET", URI
|
||||
.create("https://services.vcloudexpress.terremark.com/api/v0.8a-ext1.6/vdc/32"),
|
||||
404, "", "", ResourceNotFoundException.class);
|
||||
assertCodeMakes("GET", URI.create("https://services.vcloudexpress.terremark.com/api/v0.8a-ext1.6/vdc/32"), 404,
|
||||
"", "", ResourceNotFoundException.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDelete404SetsHttpResponseException() {
|
||||
assertCodeMakes("DELETE", URI
|
||||
.create("https://services.vcloudexpress.terremark.com/api/v0.8a-ext1.6/vdc/32"),
|
||||
assertCodeMakes("DELETE", URI.create("https://services.vcloudexpress.terremark.com/api/v0.8a-ext1.6/vdc/32"),
|
||||
404, "", "", HttpResponseException.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPOSTNotRunningSetsIllegalStateException() {
|
||||
assertCodeMakes(
|
||||
"POST",
|
||||
URI.create("https://vcenterprise.bluelock.com/api/v1.0/vApp/vapp-138351019/action/undeploy"),
|
||||
400,
|
||||
"HTTP/1.1 400 Bad Request",
|
||||
VCloudMediaType.ERROR_XML,
|
||||
"<Error xmlns=\"http://www.vmware.com/vcloud/v1\" minorErrorCode=\"BAD_REQUEST\" message=\"The requested operation could not be executed since vApp "adriancolecap-78c" is not running.\" majorErrorCode=\"400\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://www.vmware.com/vcloud/v1 http://vcenterprise.bluelock.com/api/v1.0/schema/master.xsd\"></Error>\n",
|
||||
IllegalStateException.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test401SetsAuthorizationException() {
|
||||
assertCodeMakes("GET", URI
|
||||
.create("https://services.vcloudexpress.terremark.com/api/v0.8a-ext1.6/vdc/32"),
|
||||
401, "", "", AuthorizationException.class);
|
||||
assertCodeMakes("GET", URI.create("https://services.vcloudexpress.terremark.com/api/v0.8a-ext1.6/vdc/32"), 401,
|
||||
"", "", AuthorizationException.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -561,7 +561,7 @@ public abstract class BaseComputeServiceLiveTest {
|
|||
}
|
||||
}
|
||||
|
||||
protected int nonBlockDuration = 30 * 1000;
|
||||
protected int nonBlockDurationSeconds = 30;
|
||||
|
||||
public void testOptionToNotBlock() throws Exception {
|
||||
String group = this.group + "block";
|
||||
|
@ -577,9 +577,9 @@ public abstract class BaseComputeServiceLiveTest {
|
|||
Set<? extends NodeMetadata> nodes = client.createNodesInGroup(group, 1, options);
|
||||
NodeMetadata node = getOnlyElement(nodes);
|
||||
assert node.getState() != NodeState.RUNNING;
|
||||
long duration = System.currentTimeMillis() - time;
|
||||
assert duration < nonBlockDuration : String.format("duration(%d) longer than expected(%d) seconds! ",
|
||||
duration / 1000, nonBlockDuration);
|
||||
long duration = (System.currentTimeMillis() - time) / 1000;
|
||||
assert duration < nonBlockDurationSeconds : String.format("duration(%d) longer than expected(%d) seconds! ",
|
||||
duration, nonBlockDurationSeconds);
|
||||
} finally {
|
||||
client.destroyNodesMatching(inGroup(group));
|
||||
}
|
||||
|
|
|
@ -59,15 +59,21 @@ public abstract class BaseHttpErrorHandlerTest {
|
|||
|
||||
protected abstract Class<? extends HttpErrorHandler> getHandlerClass();
|
||||
|
||||
protected void assertCodeMakes(String method, URI uri, int statusCode, String message,
|
||||
protected void assertCodeMakes(String method, URI uri, int statusCode, String message, String content,
|
||||
Class<? extends Exception> expected) {
|
||||
assertCodeMakes(method, uri, statusCode, message, null, content, expected);
|
||||
}
|
||||
|
||||
protected void assertCodeMakes(String method, URI uri, int statusCode, String message, String contentType,
|
||||
String content, Class<? extends Exception> expected) {
|
||||
|
||||
HttpErrorHandler function = Guice.createInjector(new SaxParserModule()).getInstance(
|
||||
getHandlerClass());
|
||||
HttpErrorHandler function = Guice.createInjector(new SaxParserModule()).getInstance(getHandlerClass());
|
||||
|
||||
HttpCommand command = createMock(HttpCommand.class);
|
||||
HttpRequest request = new HttpRequest(method, uri);
|
||||
HttpResponse response = new HttpResponse(statusCode, message, Payloads.newStringPayload(content));
|
||||
if (contentType != null)
|
||||
response.getPayload().getContentMetadata().setContentType(contentType);
|
||||
|
||||
expect(command.getCurrentRequest()).andReturn(request).atLeastOnce();
|
||||
command.setException(classEq(expected));
|
||||
|
|
|
@ -39,7 +39,7 @@ public class BluelockVCloudDirectorComputeServiceLiveTest extends VCloudComputeS
|
|||
public BluelockVCloudDirectorComputeServiceLiveTest() {
|
||||
provider = "bluelock-vcdirector";
|
||||
// vcloud requires instantiate before deploy, which takes longer than 30 seconds
|
||||
nonBlockDuration = 300;
|
||||
nonBlockDurationSeconds = 300;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in New Issue