StatusUpdater statusUpdator, boolean ignoreUnavailableNodes) {
logger.info("syncDeleteVMs, start to create store procedures.");
List<Callable<Void>> storeProcedures = new ArrayList<Callable<Void>>();
List<BaseNode> toBeDeleted = new ArrayList<BaseNode>();
for (int i = 0; i < badNodes.size(); i++) {
BaseNode node = badNodes.get(i);
if (node.getVmMobId() == null) {
// vm is already deleted
node.setSuccess(true);
continue;
}
DeleteVmByIdSP deleteSp = new DeleteVmByIdSP(node.getVmMobId());
storeProcedures.add(deleteSp);
toBeDeleted.add(node);
}
try {
if (storeProcedures.isEmpty()) {
logger.info("no VM is created. Return directly.");
return true;
}
Callable<Void>[] storeProceduresArray =
storeProcedures.toArray(new Callable[0]);
// execute store procedures to delete VMs
logger.info("ClusteringService, start to delete vms.");
BaseProgressCallback callback =
new BaseProgressCallback(statusUpdator, 0, 50);
ExecutionResult[] result =
Scheduler
.executeStoredProcedures(
com.vmware.aurora.composition.concurrent.Priority.BACKGROUND,
storeProceduresArray, callback);
if (result == null) {
logger.error("No VM is deleted.");
return false;
}
int total = 0;
boolean failed = false;
for (int i = 0; i < storeProceduresArray.length; i++) {
BaseNode vNode = toBeDeleted.get(i);
vNode.setFinished(true);
if (result[i].finished && result[i].throwable == null) {
vNode.setSuccess(true);
vNode.setVmMobId(null);
++total;
} else if (result[i].throwable != null) {
vNode.setSuccess(false);
vNode.setErrMessage(getErrorMessage(result[i].throwable));
if (ignoreUnavailableNodes) {
DeleteVmByIdSP sp = (DeleteVmByIdSP) storeProceduresArray[i];
VcVirtualMachine vcVm = sp.getVcVm();
if (!vcVm.isConnected()
|| vcVm.getHost().isUnavailbleForManagement()) {
logger.error("Failed to delete VM " + vcVm.getName()
+ " in connection state "
+ vcVm.getConnectionState()
+ " or in maintenance mode.");
logger.error("Ignore this failure and continue cluster operations.");
continue;
}
}
logger.error("Failed to delete VM " + vNode.getVmName(),
result[i].throwable);
failed = true;
}
vNode.setFinished(true);
}
logger.info(total + " VMs are deleted.");
return !failed;
} catch (InterruptedException e) {
logger.error("error in deleting VMs", e);