logger.warn(e, "Error deleting template '%s'", vAppTemplate.getName());
}
}
protected void cleanUpVApp(VApp vApp) {
VAppApi vAppApi = context.getApi().getVAppApi();
String vAppUrn = vApp.getId();
vApp = vAppApi.get(vAppUrn); // Refresh
if (vApp == null) {
logger.info("Cannot find VApp at %s", vAppUrn);
return; // Presumably vApp has already been removed. Ignore.
}
logger.debug("Deleting VApp %s (%s)", vApp.getName(), vAppUrn);
// Wait for busy tasks to complete (don't care if it's failed or successful)
// Otherwise, get error on remove "entity is busy completing an operation.
if (vApp.getTasks() != null) {
for (Task task : vApp.getTasks()) {
if (!taskDoneEventually(task)) {
logger.warn("Task '%s' did not complete", task.getOperationName());
}
}
}
// power off the VApp if necessary
if (vApp.getStatus() == Status.POWERED_ON) {
try {
Task shutdownTask = vAppApi.powerOff(vAppUrn);
taskDoneEventually(shutdownTask);
} catch (Exception e) {
// keep going; cleanup as much as possible
logger.warn(e, "Continuing cleanup after error shutting down VApp %s", vApp.getName());
}
}
// Undeploy the VApp if necessary
if (vApp.isDeployed()) {
try {
UndeployVAppParams params = UndeployVAppParams.builder()
.undeployPowerAction(UndeployVAppParams.PowerAction.SHUTDOWN).build();
Task undeployTask = vAppApi.undeploy(vAppUrn, params);
taskDoneEventually(undeployTask);
} catch (Exception e) {
// keep going; cleanup as much as possible
logger.warn(e, "Continuing cleanup after error undeploying VApp %s", vApp.getName());
}
}
try {
Task task = vAppApi.remove(vAppUrn);
taskDoneEventually(task);
vAppNames.remove(vApp.getName());
logger.info("Deleted VApp %s", vApp.getName());
} catch (Exception e) {
vApp = vAppApi.get(vApp.getId()); // Refresh
logger.warn(e, "Deleting VApp %s failed (%s)", vApp.getName(), vAppUrn);
}
}