Search in sources :

Example 1 with VmHandler

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;
}
Also used : QueryType(org.ovirt.engine.core.common.queries.QueryType) Backend(org.ovirt.engine.core.bll.Backend) Guid(org.ovirt.engine.core.compat.Guid) VmDynamicDao(org.ovirt.engine.core.dao.VmDynamicDao) StorageDomain(org.ovirt.engine.core.common.businessentities.StorageDomain) LoggerFactory(org.slf4j.LoggerFactory) StorageDomainStatus(org.ovirt.engine.core.common.businessentities.StorageDomainStatus) Supplier(java.util.function.Supplier) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) IdQueryParameters(org.ovirt.engine.core.common.queries.IdQueryParameters) DbFacade(org.ovirt.engine.core.dal.dbbroker.DbFacade) HashSet(java.util.HashSet) ActionType(org.ovirt.engine.core.common.action.ActionType) DisksFilter(org.ovirt.engine.core.bll.storage.disk.image.DisksFilter) BackendInternal(org.ovirt.engine.core.bll.interfaces.BackendInternal) StorageDomainStatic(org.ovirt.engine.core.common.businessentities.StorageDomainStatic) VolumeFormat(org.ovirt.engine.core.common.businessentities.storage.VolumeFormat) StorageDomainDynamic(org.ovirt.engine.core.common.businessentities.StorageDomainDynamic) Version(org.ovirt.engine.core.compat.Version) StorageFormatType(org.ovirt.engine.core.common.businessentities.StorageFormatType) StorageType(org.ovirt.engine.core.common.businessentities.storage.StorageType) QueryReturnValue(org.ovirt.engine.core.common.queries.QueryReturnValue) ImagesHandler(org.ovirt.engine.core.bll.storage.disk.image.ImagesHandler) Logger(org.slf4j.Logger) VmHandler(org.ovirt.engine.core.bll.VmHandler) VmBase(org.ovirt.engine.core.common.businessentities.VmBase) Collection(java.util.Collection) EngineMessage(org.ovirt.engine.core.common.errors.EngineMessage) StorageConstants(org.ovirt.engine.core.common.constants.StorageConstants) Set(java.util.Set) BlockStorageDiscardFunctionalityHelper(org.ovirt.engine.core.bll.storage.utils.BlockStorageDiscardFunctionalityHelper) VolumeType(org.ovirt.engine.core.common.businessentities.storage.VolumeType) Collectors(java.util.stream.Collectors) VmDao(org.ovirt.engine.core.dao.VmDao) List(java.util.List) VM(org.ovirt.engine.core.common.businessentities.VM) Injector(org.ovirt.engine.core.di.Injector) ValidationResult(org.ovirt.engine.core.bll.ValidationResult) StorageDomainType(org.ovirt.engine.core.common.businessentities.StorageDomainType) SubchainInfo(org.ovirt.engine.core.common.businessentities.SubchainInfo) Collections(java.util.Collections) VmDynamic(org.ovirt.engine.core.common.businessentities.VmDynamic) FeatureSupported(org.ovirt.engine.core.common.FeatureSupported) VMStatus(org.ovirt.engine.core.common.businessentities.VMStatus) StoragePoolIsoMap(org.ovirt.engine.core.common.businessentities.StoragePoolIsoMap) LUNs(org.ovirt.engine.core.common.businessentities.storage.LUNs) QueryReturnValue(org.ovirt.engine.core.common.queries.QueryReturnValue) VmDynamic(org.ovirt.engine.core.common.businessentities.VmDynamic) VM(org.ovirt.engine.core.common.businessentities.VM) ValidationResult(org.ovirt.engine.core.bll.ValidationResult) HashSet(java.util.HashSet)

Aggregations

Collection (java.util.Collection)1 Collections (java.util.Collections)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Set (java.util.Set)1 Supplier (java.util.function.Supplier)1 Collectors (java.util.stream.Collectors)1 Backend (org.ovirt.engine.core.bll.Backend)1 ValidationResult (org.ovirt.engine.core.bll.ValidationResult)1 VmHandler (org.ovirt.engine.core.bll.VmHandler)1 BackendInternal (org.ovirt.engine.core.bll.interfaces.BackendInternal)1 DisksFilter (org.ovirt.engine.core.bll.storage.disk.image.DisksFilter)1 ImagesHandler (org.ovirt.engine.core.bll.storage.disk.image.ImagesHandler)1 BlockStorageDiscardFunctionalityHelper (org.ovirt.engine.core.bll.storage.utils.BlockStorageDiscardFunctionalityHelper)1 FeatureSupported (org.ovirt.engine.core.common.FeatureSupported)1 ActionType (org.ovirt.engine.core.common.action.ActionType)1 StorageDomain (org.ovirt.engine.core.common.businessentities.StorageDomain)1 StorageDomainDynamic (org.ovirt.engine.core.common.businessentities.StorageDomainDynamic)1 StorageDomainStatic (org.ovirt.engine.core.common.businessentities.StorageDomainStatic)1 StorageDomainStatus (org.ovirt.engine.core.common.businessentities.StorageDomainStatus)1