mirror of https://github.com/apache/jclouds.git
Issue 830: Add logging output during cleanUp and fix VApp deletion
This commit is contained in:
parent
35391b876b
commit
704d0c00fb
|
@ -32,6 +32,7 @@ import java.io.IOException;
|
|||
import java.math.BigInteger;
|
||||
import java.net.URI;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.GuestCustomizationSection;
|
||||
|
@ -54,6 +55,7 @@ import org.jclouds.vcloud.director.v1_5.predicates.ReferenceTypePredicates;
|
|||
import org.jclouds.xml.internal.JAXBParser;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.AfterClass;
|
||||
import org.testng.annotations.AfterTest;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
|
@ -179,6 +181,7 @@ public abstract class AbstractVAppClientLiveTest extends BaseVCloudDirectorClien
|
|||
|
||||
@AfterClass(alwaysRun = true, description = "Cleans up the environment by deleting created VApps")
|
||||
protected void cleanUp() {
|
||||
vdc = vdcClient.getVdc(vdcURI); // Refresh
|
||||
// Find references in the Vdc with the VApp type and in the list of instantiated VApp names
|
||||
Iterable<Reference> vApps = Iterables.filter(
|
||||
vdc.getResourceEntities(),
|
||||
|
@ -193,6 +196,8 @@ public abstract class AbstractVAppClientLiveTest extends BaseVCloudDirectorClien
|
|||
for (Reference ref : vApps) {
|
||||
cleanUpVApp(ref.getHref()); // NOTE may fail, but should continue deleting
|
||||
}
|
||||
} else {
|
||||
logger.warn("No VApps in list found in Vdc %s (%s)", vdc.getName(), Iterables.toString(vAppNames));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -317,16 +322,18 @@ public abstract class AbstractVAppClientLiveTest extends BaseVCloudDirectorClien
|
|||
}
|
||||
|
||||
/**
|
||||
* Marshals a JAXB annotated object into XML. The XML is output on {@link System#err}.
|
||||
* Marshals a JAXB annotated object into XML.
|
||||
*
|
||||
* The XML is output using {@link org.jclouds.logging.Logger#debug(String)}
|
||||
*/
|
||||
protected void debug(Object object) {
|
||||
JAXBParser parser = new JAXBParser();
|
||||
try {
|
||||
String xml = parser.toXML(object);
|
||||
|
||||
System.err.println(Strings.padStart(Strings.padEnd(" " + object.getClass().toString() + " ", 70, '-'), 80, '-'));
|
||||
System.err.println(xml);
|
||||
System.err.println(Strings.repeat("-", 80));
|
||||
logger.debug(Strings.padStart(Strings.padEnd(" " + object.getClass().toString() + " ", 70, '-'), 80, '-'));
|
||||
logger.debug(xml);
|
||||
logger.debug(Strings.repeat("-", 80));
|
||||
} catch (IOException ioe) {
|
||||
Throwables.propagate(ioe);
|
||||
}
|
||||
|
|
|
@ -356,14 +356,16 @@ public abstract class BaseVCloudDirectorClientLiveTest extends BaseVersionedServ
|
|||
}
|
||||
|
||||
// TODO code tidy for cleanUpVApp? Seems extremely verbose!
|
||||
protected void cleanUpVApp(URI vAppUri) {
|
||||
VAppClient vappClient = context.getApi().getVAppClient();
|
||||
protected void cleanUpVApp(URI vAppURI) {
|
||||
VAppClient vAppClient = context.getApi().getVAppClient();
|
||||
|
||||
VApp vApp;
|
||||
try {
|
||||
vApp = vappClient.getVApp(vAppUri); // update
|
||||
vApp = vAppClient.getVApp(vAppURI); // Refresh
|
||||
logger.debug("Deleting VApp %s (%s)", vApp.getName(), vAppURI.getPath());
|
||||
} catch (VCloudDirectorException e) {
|
||||
// presumably vApp has already been deleted; ignore
|
||||
// Presumably vApp has already been deleted. Ignore.
|
||||
logger.info("Cannot find VApp at %s", vAppURI.getPath());
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -378,11 +380,11 @@ public abstract class BaseVCloudDirectorClientLiveTest extends BaseVersionedServ
|
|||
// Shutdown and power off the VApp if necessary
|
||||
if (vApp.getStatus().equals(Status.POWERED_ON.getValue())) {
|
||||
try {
|
||||
Task shutdownTask = vappClient.shutdown(vAppUri);
|
||||
Task shutdownTask = vAppClient.shutdown(vAppURI);
|
||||
retryTaskSuccess.apply(shutdownTask);
|
||||
} catch (Exception e) {
|
||||
// keep going; cleanup as much as possible
|
||||
logger.warn(e, "Continuing cleanup after error shutting down VApp %s", vApp);
|
||||
logger.warn(e, "Continuing cleanup after error shutting down VApp %s", vApp.getName());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -390,26 +392,27 @@ public abstract class BaseVCloudDirectorClientLiveTest extends BaseVersionedServ
|
|||
if (vApp.isDeployed()) {
|
||||
try {
|
||||
UndeployVAppParams params = UndeployVAppParams.builder().build();
|
||||
Task undeployTask = vappClient.undeploy(vAppUri, params);
|
||||
Task undeployTask = vAppClient.undeploy(vAppURI, params);
|
||||
retryTaskSuccess.apply(undeployTask);
|
||||
} catch (Exception e) {
|
||||
// keep going; cleanup as much as possible
|
||||
logger.warn(e, "Continuing cleanup after error undeploying VApp %s", vApp);
|
||||
logger.warn(e, "Continuing cleanup after error undeploying VApp %s", vApp.getName());
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
Task task = vappClient.deleteVApp(vAppUri);
|
||||
Task task = vAppClient.deleteVApp(vAppURI);
|
||||
assertTaskSucceeds(task);
|
||||
vAppNames.remove(vApp.getName());
|
||||
logger.info("Deleted VApp %s", vApp.getName());
|
||||
} catch (Exception e) {
|
||||
try {
|
||||
vApp = vappClient.getVApp(vAppUri); // refresh
|
||||
vApp = vAppClient.getVApp(vAppURI); // Refresh
|
||||
} catch (Exception e2) {
|
||||
// ignore
|
||||
// Ignore
|
||||
}
|
||||
|
||||
logger.warn(e, "Deleting vApp failed: vApp="+vApp);
|
||||
logger.warn(e, "Deleting VApp %s failed (%s)", vApp.getName(), vAppURI.getPath());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue