}
// 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