use of org.ovirt.engine.core.bll.VmHandler in project ovirt-engine by oVirt.
the class StorageDomainValidator method isRunningVmsOrVmLeasesForBackupDomain.
public ValidationResult isRunningVmsOrVmLeasesForBackupDomain(VmHandler vmHandler) {
Set<String> invalidVmsForBackupStorageDomain = new HashSet<>();
QueryReturnValue ret = getEntitiesWithLeaseIdForStorageDomain(storageDomain.getId());
if (!ret.getSucceeded()) {
return new ValidationResult(EngineMessage.ACTION_TYPE_FAILED_RETRIEVE_VMS_FOR_WITH_LEASES);
}
getRetVal(ret).forEach(vmBase -> {
VmDynamic vm = getVmDynamicDao().get(vmBase.getId());
if (vm != null && vm.getStatus() != VMStatus.Down) {
invalidVmsForBackupStorageDomain.add(vmBase.getName());
}
});
List<VM> vms = getVmDao().getAllActiveForStorageDomain(storageDomain.getId());
vms.forEach(vmHandler::updateDisksFromDb);
invalidVmsForBackupStorageDomain.addAll(vms.stream().filter(vm -> vm.getDiskMap().values().stream().filter(DisksFilter.ONLY_IMAGES).filter(DisksFilter.ONLY_PLUGGED).map(DiskImage.class::cast).anyMatch(vmDisk -> vmDisk.getStorageIds().get(0).equals(storageDomain.getId()))).map(VM::getName).collect(Collectors.toList()));
if (!invalidVmsForBackupStorageDomain.isEmpty()) {
log.warn("Can't update the backup property of the storage domain since it contains VMs with " + "leases or active disks which are attached to running VMs." + "The following VMs list are: '{}'", invalidVmsForBackupStorageDomain);
return new ValidationResult(EngineMessage.ACTION_TYPE_FAILED_RUNNING_VM_OR_VM_LEASES_PRESENT_ON_STORAGE_DOMAIN);
}
return ValidationResult.VALID;
}
Aggregations