Issue 830: Add logging output during cleanUp and fix VApp deletion

This commit is contained in:
Andrew Donald Kennedy 2012-03-21 23:32:49 +00:00
parent 35391b876b
commit 704d0c00fb
2 changed files with 26 additions and 16 deletions

View File

@ -32,6 +32,7 @@ import java.io.IOException;
import java.math.BigInteger; import java.math.BigInteger;
import java.net.URI; import java.net.URI;
import java.util.List; import java.util.List;
import java.util.Map;
import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType; import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType;
import org.jclouds.vcloud.director.v1_5.domain.GuestCustomizationSection; 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.jclouds.xml.internal.JAXBParser;
import org.testng.Assert; import org.testng.Assert;
import org.testng.annotations.AfterClass; import org.testng.annotations.AfterClass;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeClass;
import com.google.common.base.Function; 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") @AfterClass(alwaysRun = true, description = "Cleans up the environment by deleting created VApps")
protected void cleanUp() { 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 // Find references in the Vdc with the VApp type and in the list of instantiated VApp names
Iterable<Reference> vApps = Iterables.filter( Iterable<Reference> vApps = Iterables.filter(
vdc.getResourceEntities(), vdc.getResourceEntities(),
@ -193,6 +196,8 @@ public abstract class AbstractVAppClientLiveTest extends BaseVCloudDirectorClien
for (Reference ref : vApps) { for (Reference ref : vApps) {
cleanUpVApp(ref.getHref()); // NOTE may fail, but should continue deleting 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) { protected void debug(Object object) {
JAXBParser parser = new JAXBParser(); JAXBParser parser = new JAXBParser();
try { try {
String xml = parser.toXML(object); String xml = parser.toXML(object);
System.err.println(Strings.padStart(Strings.padEnd(" " + object.getClass().toString() + " ", 70, '-'), 80, '-')); logger.debug(Strings.padStart(Strings.padEnd(" " + object.getClass().toString() + " ", 70, '-'), 80, '-'));
System.err.println(xml); logger.debug(xml);
System.err.println(Strings.repeat("-", 80)); logger.debug(Strings.repeat("-", 80));
} catch (IOException ioe) { } catch (IOException ioe) {
Throwables.propagate(ioe); Throwables.propagate(ioe);
} }

View File

@ -356,14 +356,16 @@ public abstract class BaseVCloudDirectorClientLiveTest extends BaseVersionedServ
} }
// TODO code tidy for cleanUpVApp? Seems extremely verbose! // TODO code tidy for cleanUpVApp? Seems extremely verbose!
protected void cleanUpVApp(URI vAppUri) { protected void cleanUpVApp(URI vAppURI) {
VAppClient vappClient = context.getApi().getVAppClient(); VAppClient vAppClient = context.getApi().getVAppClient();
VApp vApp; VApp vApp;
try { try {
vApp = vappClient.getVApp(vAppUri); // update vApp = vAppClient.getVApp(vAppURI); // Refresh
logger.debug("Deleting VApp %s (%s)", vApp.getName(), vAppURI.getPath());
} catch (VCloudDirectorException e) { } 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; return;
} }
@ -378,11 +380,11 @@ public abstract class BaseVCloudDirectorClientLiveTest extends BaseVersionedServ
// Shutdown and power off the VApp if necessary // Shutdown and power off the VApp if necessary
if (vApp.getStatus().equals(Status.POWERED_ON.getValue())) { if (vApp.getStatus().equals(Status.POWERED_ON.getValue())) {
try { try {
Task shutdownTask = vappClient.shutdown(vAppUri); Task shutdownTask = vAppClient.shutdown(vAppURI);
retryTaskSuccess.apply(shutdownTask); retryTaskSuccess.apply(shutdownTask);
} catch (Exception e) { } catch (Exception e) {
// keep going; cleanup as much as possible // 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()) { if (vApp.isDeployed()) {
try { try {
UndeployVAppParams params = UndeployVAppParams.builder().build(); UndeployVAppParams params = UndeployVAppParams.builder().build();
Task undeployTask = vappClient.undeploy(vAppUri, params); Task undeployTask = vAppClient.undeploy(vAppURI, params);
retryTaskSuccess.apply(undeployTask); retryTaskSuccess.apply(undeployTask);
} catch (Exception e) { } catch (Exception e) {
// keep going; cleanup as much as possible // 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 { try {
Task task = vappClient.deleteVApp(vAppUri); Task task = vAppClient.deleteVApp(vAppURI);
assertTaskSucceeds(task); assertTaskSucceeds(task);
vAppNames.remove(vApp.getName()); vAppNames.remove(vApp.getName());
logger.info("Deleted VApp %s", vApp.getName());
} catch (Exception e) { } catch (Exception e) {
try { try {
vApp = vappClient.getVApp(vAppUri); // refresh vApp = vAppClient.getVApp(vAppURI); // Refresh
} catch (Exception e2) { } 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());
} }
} }