Pair<Callable<Void>, Callable<Void>>[] storeProcedures =
new Pair[consumers.size()];
for (int i = 0; i < consumers.size(); i++) {
VmCreateSpec consumer = consumers.get(i);
CreateVmSP cloneVmSp =
new CreateVmSP(consumer.getVmName(), consumer.getSchema(),
consumer.getTargetRp(), consumer.getTargetDs(),
consumer.getPrePowerOn(), consumer.getPostPowerOn(),
consumer.getBootupConfigs(), false,
consumer.getTargetFolder(), consumer.getTargetHost());
CompensateCreateVmSP deleteVmSp = new CompensateCreateVmSP(cloneVmSp);
storeProcedures[i] =
new Pair<Callable<Void>, Callable<Void>>(cloneVmSp, deleteVmSp);
}
try {
// execute store procedures to create VMs
logger.info("ClusterCloneService, start to create vms.");
Pair<ExecutionResult, ExecutionResult>[] result =
Scheduler
.executeStoredProcedures(
com.vmware.aurora.composition.concurrent.Priority.BACKGROUND,
storeProcedures, storeProcedures.length, callback);
if (result == null) {
logger.error("No VM is created.");
return null;
}
int total = 0;
List<VmCreateResult<?>> cloned = new ArrayList<VmCreateResult<?>>();
for (int i = 0; i < storeProcedures.length; i++) {
Pair<ExecutionResult, ExecutionResult> pair = result[i];
VmCreateResult<VmCreateSpec> createResult = new VmCreateResult<VmCreateSpec>();
VmCreateSpec node = consumers.get(i);
createResult.setSpec(node);
CreateVmSP sp = (CreateVmSP) storeProcedures[i].first;
if (sp.getVM() != null) {
node.setVmId(sp.getVM().getId());
}
if (pair.first.finished && pair.first.throwable == null
&& pair.second.finished == false) {
++total;
createResult.setSuccess(true);