Search in sources :

Example 16 with DiskImagesValidator

use of org.ovirt.engine.core.bll.validator.storage.DiskImagesValidator in project ovirt-engine by oVirt.

the class VmPoolHandler method isNonPrestartedVmFree.

/**
 * Check if a specific VM is free. A VM is considered free if it isn't attached to a user and not during preview
 * @param vmId The VM ID
 * @param errorProcessor the error messages processor object or lambda expression (may be <code>null</code>)
 * @return True if the VM is free, false otherwise
 */
public boolean isNonPrestartedVmFree(Guid vmId, ErrorProcessor errorProcessor) {
    List<String> messages = new ArrayList<>();
    // check that there is no user already attached to this VM
    if (vmAssignedToUser(vmId, messages)) {
        return failVmFree(errorProcessor, vmId, messages);
    }
    // check that VN can be run
    if (!canRunPoolVm(vmId, messages)) {
        return failVmFree(errorProcessor, vmId, messages);
    }
    // check VM images
    ValidationResult vmDuringSnapshotResult = snapshotsValidator.vmNotDuringSnapshot(vmId);
    if (!vmDuringSnapshotResult.isValid()) {
        return failVmFree(errorProcessor, vmId, vmDuringSnapshotResult.getMessagesAsStrings());
    }
    ValidationResult vmInPreviewResult = snapshotsValidator.vmNotInPreview(vmId);
    if (!vmInPreviewResult.isValid()) {
        return failVmFree(errorProcessor, vmId, vmInPreviewResult.getMessagesAsStrings());
    }
    List<Disk> disks = diskDao.getAllForVm(vmId);
    List<DiskImage> vmImages = DisksFilter.filterImageDisks(disks, ONLY_NOT_SHAREABLE, ONLY_SNAPABLE);
    VM vm = vmDao.get(vmId);
    StoragePool sp = storagePoolDao.get(vm.getStoragePoolId());
    ValidationResult spUpResult = new StoragePoolValidator(sp).existsAndUp();
    if (!spUpResult.isValid()) {
        return failVmFree(errorProcessor, vmId, spUpResult.getMessagesAsStrings());
    }
    Guid storageDomainId = vmImages.size() > 0 ? vmImages.get(0).getStorageIds().get(0) : Guid.Empty;
    if (!Guid.Empty.equals(storageDomainId)) {
        StorageDomainValidator storageDomainValidator = new StorageDomainValidator(storageDomainDao.getForStoragePool(storageDomainId, sp.getId()));
        ValidationResult domainActiveResult = storageDomainValidator.isDomainExistAndActive();
        if (!domainActiveResult.isValid()) {
            return failVmFree(errorProcessor, vmId, domainActiveResult.getMessagesAsStrings());
        }
    }
    DiskImagesValidator diskImagesValidator = new DiskImagesValidator(vmImages);
    ValidationResult disksNotLockedResult = diskImagesValidator.diskImagesNotLocked();
    if (!disksNotLockedResult.isValid()) {
        messages.addAll(disksNotLockedResult.getMessagesAsStrings());
        messages.addAll(disksNotLockedResult.getVariableReplacements());
        return failVmFree(errorProcessor, vmId, messages);
    }
    ValidationResult vmNotLockResult = new VmValidator(vm).vmNotLocked();
    if (!vmNotLockResult.isValid()) {
        return failVmFree(errorProcessor, vmId, vmNotLockResult.getMessagesAsStrings());
    }
    return true;
}
Also used : StoragePool(org.ovirt.engine.core.common.businessentities.StoragePool) StorageDomainValidator(org.ovirt.engine.core.bll.validator.storage.StorageDomainValidator) ArrayList(java.util.ArrayList) Guid(org.ovirt.engine.core.compat.Guid) StoragePoolValidator(org.ovirt.engine.core.bll.validator.storage.StoragePoolValidator) VM(org.ovirt.engine.core.common.businessentities.VM) DiskImagesValidator(org.ovirt.engine.core.bll.validator.storage.DiskImagesValidator) Disk(org.ovirt.engine.core.common.businessentities.storage.Disk) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) RunVmValidator(org.ovirt.engine.core.bll.validator.RunVmValidator) VmValidator(org.ovirt.engine.core.bll.validator.VmValidator)

Example 17 with DiskImagesValidator

use of org.ovirt.engine.core.bll.validator.storage.DiskImagesValidator in project ovirt-engine by oVirt.

the class MigrateVmCommand method validateImpl.

@Override
protected boolean validateImpl() {
    final VM vm = getVm();
    if (vm == null) {
        return failValidation(EngineMessage.ACTION_TYPE_FAILED_VM_NOT_FOUND);
    }
    if (!canRunActionOnNonManagedVm()) {
        return false;
    }
    VmValidator vmValidator = getVmValidator();
    if (!validate(vmValidator.isVmPluggedDiskNotUsingScsiReservation())) {
        return false;
    }
    if (!FeatureSupported.isMigrationSupported(getCluster().getArchitecture(), getCluster().getCompatibilityVersion())) {
        return failValidation(EngineMessage.MIGRATION_IS_NOT_SUPPORTED);
    }
    // If VM is pinned to host, no migration can occur
    if (vm.getMigrationSupport() == MigrationSupport.PINNED_TO_HOST) {
        return failValidation(EngineMessage.ACTION_TYPE_FAILED_VM_IS_PINNED_TO_HOST);
    }
    if (vm.getMigrationSupport() == MigrationSupport.IMPLICITLY_NON_MIGRATABLE && !getParameters().isForceMigrationForNonMigratableVm()) {
        return failValidation(EngineMessage.ACTION_TYPE_FAILED_VM_IS_NON_MIGRTABLE_AND_IS_NOT_FORCED_BY_USER_TO_MIGRATE);
    }
    switch(vm.getStatus()) {
        case MigratingFrom:
            return failValidation(EngineMessage.ACTION_TYPE_FAILED_MIGRATION_IN_PROGRESS);
        case NotResponding:
            return failVmStatusIllegal();
        case Paused:
            if (vm.getVmPauseStatus() == VmPauseStatus.EIO) {
                return failValidation(EngineMessage.MIGRATE_PAUSED_EIO_VM_IS_NOT_SUPPORTED);
            }
            break;
        default:
    }
    if (!vm.isQualifyToMigrate()) {
        return failValidation(EngineMessage.ACTION_TYPE_FAILED_VM_IS_NOT_RUNNING);
    }
    if (!validate(new MultipleVmsValidator(vm).vmNotHavingPluggedDiskSnapshots(EngineMessage.ACTION_TYPE_FAILED_VM_HAS_PLUGGED_DISK_SNAPSHOT)) || !validate(vmValidator.allPassthroughVnicsMigratable())) {
        return false;
    }
    if (getParameters().getTargetClusterId() != null) {
        ChangeVmClusterValidator changeVmClusterValidator = ChangeVmClusterValidator.create(this, getParameters().getTargetClusterId(), getVm().getCustomCompatibilityVersion());
        if (!changeVmClusterValidator.validate()) {
            return false;
        }
    }
    if (isInternalExecution() && getVm().getMigrationSupport() != MigrationSupport.MIGRATABLE) {
        return failValidation(EngineMessage.ACTION_TYPE_FAILED_VM_IS_NON_MIGRTABLE);
    }
    return validate(snapshotsValidator.vmNotDuringSnapshot(vm.getId())) && // TODO: replace it with a better solution
    validate(new DiskImagesValidator(callFilterImageDisks(vm)).diskImagesNotLocked()) && !schedulingManager.canSchedule(getCluster(), getVm(), getVdsBlackList(), getVdsWhiteList(), getReturnValue().getValidationMessages()).isEmpty();
}
Also used : VM(org.ovirt.engine.core.common.businessentities.VM) MultipleVmsValidator(org.ovirt.engine.core.bll.validator.MultipleVmsValidator) DiskImagesValidator(org.ovirt.engine.core.bll.validator.storage.DiskImagesValidator) VmValidator(org.ovirt.engine.core.bll.validator.VmValidator)

Example 18 with DiskImagesValidator

use of org.ovirt.engine.core.bll.validator.storage.DiskImagesValidator in project ovirt-engine by oVirt.

the class AddVmTemplateCommand method validateImages.

protected boolean validateImages() {
    // images related checks
    if (!images.isEmpty()) {
        if (!validateVmNotDuringSnapshot()) {
            return false;
        }
        if (!validate(new StoragePoolValidator(getStoragePool()).existsAndUp())) {
            return false;
        }
        List<CinderDisk> cinderDisks = getCinderDisks();
        CinderDisksValidator cinderDisksValidator = new CinderDisksValidator(cinderDisks);
        if (!validate(cinderDisksValidator.validateCinderDiskLimits())) {
            return false;
        }
        if (!validate(isPassDiscardSupportedForImagesDestSds())) {
            return false;
        }
        List<DiskImage> diskImagesToCheck = DisksFilter.filterImageDisks(images, ONLY_NOT_SHAREABLE, ONLY_ACTIVE);
        diskImagesToCheck.addAll(cinderDisks);
        DiskImagesValidator diskImagesValidator = new DiskImagesValidator(diskImagesToCheck);
        if (!validate(diskImagesValidator.diskImagesNotIllegal()) || !validate(diskImagesValidator.diskImagesNotLocked())) {
            return false;
        }
        MultipleStorageDomainsValidator storageDomainsValidator = getStorageDomainsValidator(getStoragePoolId(), sourceImageDomainsImageMap.keySet());
        if (!validate(storageDomainsValidator.allDomainsExistAndActive())) {
            return false;
        }
        Set<Guid> destImageDomains = getStorageGuidSet();
        destImageDomains.removeAll(sourceImageDomainsImageMap.keySet());
        for (Guid destImageDomain : destImageDomains) {
            StorageDomain storage = storageDomainDao.getForStoragePool(destImageDomain, getVm().getStoragePoolId());
            if (storage == null) {
                // domain is not in the same storage pool as the vm
                if (storageDomainStaticDao.get(destImageDomain) == null) {
                    addValidationMessage(EngineMessage.ACTION_TYPE_FAILED_STORAGE_DOMAIN_NOT_EXIST);
                } else {
                    addValidationMessage(EngineMessage.ACTION_TYPE_FAILED_STORAGE_DOMAIN_NOT_IN_STORAGE_POOL);
                }
                return false;
            }
            if (storage.getStatus() == null || storage.getStatus() != StorageDomainStatus.Active) {
                addValidationMessage(EngineMessage.ACTION_TYPE_FAILED_STORAGE_DOMAIN_STATUS_ILLEGAL);
                return false;
            }
            if (storage.getStorageDomainType().isIsoOrImportExportDomain()) {
                addValidationMessage(EngineMessage.ACTION_TYPE_FAILED_STORAGE_DOMAIN_TYPE_ILLEGAL);
                return false;
            }
        }
        return validateSpaceRequirements();
    }
    return true;
}
Also used : StoragePoolValidator(org.ovirt.engine.core.bll.validator.storage.StoragePoolValidator) StorageDomain(org.ovirt.engine.core.common.businessentities.StorageDomain) CinderDisksValidator(org.ovirt.engine.core.bll.validator.storage.CinderDisksValidator) MultipleStorageDomainsValidator(org.ovirt.engine.core.bll.validator.storage.MultipleStorageDomainsValidator) Guid(org.ovirt.engine.core.compat.Guid) CinderDisk(org.ovirt.engine.core.common.businessentities.storage.CinderDisk) DiskImagesValidator(org.ovirt.engine.core.bll.validator.storage.DiskImagesValidator) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage)

Example 19 with DiskImagesValidator

use of org.ovirt.engine.core.bll.validator.storage.DiskImagesValidator in project ovirt-engine by oVirt.

the class VmValidator method vmNotHavingDeviceSnapshotsAttachedToOtherVms.

/**
 * @return ValidationResult indicating whether snapshots of disks are attached to other vms.
 */
public ValidationResult vmNotHavingDeviceSnapshotsAttachedToOtherVms(boolean onlyPlugged) {
    List<Disk> vmDisks = getDbFacade().getDiskDao().getAllForVm(vm.getId());
    ValidationResult result = new DiskImagesValidator(DisksFilter.filterImageDisks(vmDisks, ONLY_NOT_SHAREABLE, ONLY_ACTIVE)).diskImagesSnapshotsNotAttachedToOtherVms(onlyPlugged);
    if (result != ValidationResult.VALID) {
        return result;
    }
    return ValidationResult.VALID;
}
Also used : ValidationResult(org.ovirt.engine.core.bll.ValidationResult) DiskImagesValidator(org.ovirt.engine.core.bll.validator.storage.DiskImagesValidator) Disk(org.ovirt.engine.core.common.businessentities.storage.Disk)

Example 20 with DiskImagesValidator

use of org.ovirt.engine.core.bll.validator.storage.DiskImagesValidator in project ovirt-engine by oVirt.

the class RemoveDiskSnapshotsCommandTest method setUp.

@Before
public void setUp() {
    doReturn(storageDomainValidator).when(cmd).getStorageDomainValidator();
    doReturn(STORAGE_POOLD_ID).when(cmd).getStoragePoolId();
    doReturn(mockImages()).when(cmd).getImages();
    mockVm();
    vmValidator = spy(new VmValidator(cmd.getVm()));
    doReturn(vmValidator).when(cmd).createVmValidator(any());
    DiskImagesValidator diskImagesValidator = spy(new DiskImagesValidator(mockImages()));
    doReturn(diskImagesValidator).when(cmd).createDiskImageValidator(any());
    doReturn(ValidationResult.VALID).when(diskImagesValidator).diskImagesSnapshotsNotAttachedToOtherVms(false);
}
Also used : DiskImagesValidator(org.ovirt.engine.core.bll.validator.storage.DiskImagesValidator) VmValidator(org.ovirt.engine.core.bll.validator.VmValidator) Before(org.junit.Before)

Aggregations

DiskImagesValidator (org.ovirt.engine.core.bll.validator.storage.DiskImagesValidator)20 DiskImage (org.ovirt.engine.core.common.businessentities.storage.DiskImage)13 VmValidator (org.ovirt.engine.core.bll.validator.VmValidator)10 StoragePoolValidator (org.ovirt.engine.core.bll.validator.storage.StoragePoolValidator)9 Guid (org.ovirt.engine.core.compat.Guid)8 MultipleStorageDomainsValidator (org.ovirt.engine.core.bll.validator.storage.MultipleStorageDomainsValidator)6 DiskValidator (org.ovirt.engine.core.bll.validator.storage.DiskValidator)4 StorageDomainValidator (org.ovirt.engine.core.bll.validator.storage.StorageDomainValidator)4 Disk (org.ovirt.engine.core.common.businessentities.storage.Disk)4 VM (org.ovirt.engine.core.common.businessentities.VM)3 CinderDisk (org.ovirt.engine.core.common.businessentities.storage.CinderDisk)3 ArrayList (java.util.ArrayList)2 ValidationResult (org.ovirt.engine.core.bll.ValidationResult)2 DiskSnapshotsValidator (org.ovirt.engine.core.bll.validator.storage.DiskSnapshotsValidator)2 StoragePool (org.ovirt.engine.core.common.businessentities.StoragePool)2 Collection (java.util.Collection)1 Collections (java.util.Collections)1 Comparator (java.util.Comparator)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1