Search in sources :

Example 11 with VmValidator

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

the class AddDiskCommand method checkIfLunDiskCanBeAdded.

protected boolean checkIfLunDiskCanBeAdded(DiskValidator diskValidator) {
    LunDisk lunDisk = (LunDisk) getParameters().getDiskInfo();
    LUNs lun = lunDisk.getLun();
    if (!validate(diskValidator.validateConnectionsInLun(lun.getLunType()))) {
        return false;
    }
    if (!validate(diskValidator.validateLunAlreadyInUse())) {
        return false;
    }
    if (getVm() != null && !(validate(new VmValidator(getVm()).vmNotLocked()) && isVmNotInPreviewSnapshot())) {
        return false;
    }
    DiskVmElementValidator diskVmElementValidator = getDiskVmElementValidator(getParameters().getDiskInfo(), getDiskVmElement());
    if (!validate(diskVmElementValidator.isVirtIoScsiValid(getVm()))) {
        return false;
    }
    if (!validate(diskVmElementValidator.isDiskInterfaceSupported(getVm()))) {
        return false;
    }
    if (getVds() != null) {
        lunFromStorage = getLunDisk(lun, getVds());
        if (lunFromStorage == null) {
            return failValidation(EngineMessage.ACTION_TYPE_FAILED_DISK_LUN_INVALID);
        }
    }
    if (!validate(diskValidator.isUsingScsiReservationValid(getVm(), getDiskVmElement(), lunDisk))) {
        return false;
    }
    return true;
}
Also used : DiskVmElementValidator(org.ovirt.engine.core.bll.validator.storage.DiskVmElementValidator) LunDisk(org.ovirt.engine.core.common.businessentities.storage.LunDisk) LUNs(org.ovirt.engine.core.common.businessentities.storage.LUNs) VmValidator(org.ovirt.engine.core.bll.validator.VmValidator)

Example 12 with VmValidator

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

the class UpdateVmDiskCommand method validate.

@Override
protected boolean validate() {
    if (!validate(new VmValidator(getVm()).isVmExists()) || !isDiskExistAndAttachedToVm(getOldDisk()) || !validateDiskVmData()) {
        return false;
    }
    boolean isDiskImageOrCinder = DiskStorageType.IMAGE == getOldDisk().getDiskStorageType() || DiskStorageType.CINDER == getOldDisk().getDiskStorageType();
    if (isDiskImageOrCinder) {
        ValidationResult imagesNotLocked = new DiskImagesValidator((DiskImage) getOldDisk()).diskImagesNotLocked();
        if (!imagesNotLocked.isValid()) {
            return validate(imagesNotLocked);
        }
    }
    DiskValidator oldDiskValidator = getDiskValidator(getOldDisk());
    ValidationResult isHostedEngineDisk = oldDiskValidator.validateNotHostedEngineDisk();
    if (!isHostedEngineDisk.isValid()) {
        return validate(isHostedEngineDisk);
    }
    if (!checkOperationAllowedOnDiskContentType(getOldDisk())) {
        return false;
    }
    if (!canRunActionOnNonManagedVm()) {
        return false;
    }
    boolean isDiskInterfaceUpdated = getOldDiskVmElement().getDiskInterface() != getDiskVmElement().getDiskInterface();
    if (!vmsDiskOrSnapshotPluggedTo.isEmpty()) {
        // only virtual drive size can be updated when VMs is running
        if (isAtLeastOneVmIsNotDown(vmsDiskOrSnapshotPluggedTo) && updateParametersRequiringVmDownRequested()) {
            return failValidation(EngineMessage.ACTION_TYPE_FAILED_VM_IS_NOT_DOWN);
        }
        boolean isUpdatedAsBootable = !getOldDiskVmElement().isBoot() && getDiskVmElement().isBoot();
        // multiple boot disk snapshot can be attached to a single vm
        if (isUpdatedAsBootable && !validate(oldDiskValidator.isVmNotContainsBootDisk(getVm()))) {
            return false;
        }
        if (isDiskInterfaceUpdated && !isDiskPassPciAndIdeLimit()) {
            return false;
        }
    }
    if (isDiskImageOrCinder && !validateCanResizeDisk()) {
        return false;
    }
    if (resizeDiskImageRequested() && amendDiskRequested()) {
        return failValidation(EngineMessage.ACTION_TYPE_FAILED_AMEND_AND_EXTEND_IN_ONE_OPERATION);
    }
    if (isQcowCompatChangedOnRawDisk()) {
        return failValidation(EngineMessage.ACTION_TYPE_FAILED_CANT_AMEND_RAW_DISK);
    }
    DiskVmElementValidator diskVmElementValidator = getDiskVmElementValidator(getNewDisk(), getDiskVmElement());
    return validateCanUpdateShareable() && validateCanUpdateReadOnly() && validateVmPoolProperties() && validateQuota() && validate(diskVmElementValidator.isVirtIoScsiValid(getVm())) && (!isDiskInterfaceUpdated || validate(diskVmElementValidator.isDiskInterfaceSupported(getVm()))) && setAndValidateDiskProfiles() && validatePassDiscardSupported(diskVmElementValidator);
}
Also used : DiskValidator(org.ovirt.engine.core.bll.validator.storage.DiskValidator) DiskVmElementValidator(org.ovirt.engine.core.bll.validator.storage.DiskVmElementValidator) ValidationResult(org.ovirt.engine.core.bll.ValidationResult) DiskImagesValidator(org.ovirt.engine.core.bll.validator.storage.DiskImagesValidator) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) VmValidator(org.ovirt.engine.core.bll.validator.VmValidator)

Example 13 with VmValidator

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

the class AttachDiskToVmCommand method validate.

@Override
protected boolean validate() {
    if (disk == null) {
        return failValidation(EngineMessage.ACTION_TYPE_FAILED_VM_IMAGE_DOES_NOT_EXIST);
    }
    DiskValidator oldDiskValidator = new DiskValidator(disk);
    ValidationResult isHostedEngineDisk = oldDiskValidator.validateNotHostedEngineDisk();
    if (!isHostedEngineDisk.isValid()) {
        return validate(isHostedEngineDisk);
    }
    if (!checkOperationAllowedOnDiskContentType(disk)) {
        return false;
    }
    if (isOperationPerformedOnDiskSnapshot() && (!validate(snapshotsValidator.snapshotExists(getSnapshot())) || !validate(snapshotsValidator.isRegularSnapshot(getSnapshot())))) {
        return false;
    }
    boolean isImageDisk = disk.getDiskStorageType().isInternal();
    if (isImageDisk) {
        // TODO : this load and check of the active disk will be removed
        // after inspecting upgrade
        Disk activeDisk = diskHandler.loadActiveDisk(disk.getId());
        if (((DiskImage) activeDisk).getImageStatus() == ImageStatus.ILLEGAL) {
            return failValidation(EngineMessage.ACTION_TYPE_FAILED_ILLEGAL_DISK_OPERATION);
        }
        if (((DiskImage) disk).getImageStatus() == ImageStatus.LOCKED) {
            addValidationMessage(EngineMessage.ACTION_TYPE_FAILED_DISKS_LOCKED);
            addValidationMessageVariable("diskAliases", disk.getDiskAlias());
            return false;
        }
    }
    if (!validate(new VmValidator(getVm()).isVmExists()) || !isVmInUpPausedDownStatus()) {
        return false;
    }
    if (!validateDiskVmData()) {
        return false;
    }
    if (!canRunActionOnNonManagedVm()) {
        return false;
    }
    updateDisksFromDb();
    if (getDiskVmElement().isBoot() && !validate(getDiskValidator(disk).isVmNotContainsBootDisk(getVm()))) {
        return false;
    }
    if (!isDiskPassPciAndIdeLimit()) {
        return false;
    }
    if (vmDeviceDao.exists(new VmDeviceId(disk.getId(), getVmId()))) {
        return failValidation(EngineMessage.ACTION_TYPE_FAILED_DISK_ALREADY_ATTACHED);
    }
    if (!isOperationPerformedOnDiskSnapshot() && !disk.isShareable() && disk.getNumberOfVms() > 0) {
        return failValidation(EngineMessage.ACTION_TYPE_FAILED_NOT_SHAREABLE_DISK_ALREADY_ATTACHED);
    }
    if (isImageDisk && storagePoolIsoMapDao.get(new StoragePoolIsoMapId(((DiskImage) disk).getStorageIds().get(0), getVm().getStoragePoolId())) == null) {
        return failValidation(EngineMessage.ACTION_TYPE_FAILED_STORAGE_POOL_NOT_MATCH);
    }
    if (isImageDisk) {
        StorageDomain storageDomain = storageDomainDao.getForStoragePool(((DiskImage) disk).getStorageIds().get(0), ((DiskImage) disk).getStoragePoolId());
        StorageDomainValidator storageDomainValidator = getStorageDomainValidator(storageDomain);
        if (!validate(storageDomainValidator.isDomainExistAndActive())) {
            return false;
        }
    }
    DiskVmElementValidator diskVmElementValidator = getDiskVmElementValidator(disk, getDiskVmElement());
    if (!validate(diskVmElementValidator.isReadOnlyPropertyCompatibleWithInterface())) {
        return false;
    }
    if (!validate(diskVmElementValidator.isVirtIoScsiValid(getVm()))) {
        return false;
    }
    if (!validate(diskVmElementValidator.isDiskInterfaceSupported(getVm()))) {
        return false;
    }
    Guid storageDomainId = disk.getDiskStorageType() == DiskStorageType.IMAGE ? ((DiskImage) disk).getStorageIds().get(0) : null;
    if (!validate(diskVmElementValidator.isPassDiscardSupported(storageDomainId))) {
        return false;
    }
    if (!isVmNotInPreviewSnapshot()) {
        return false;
    }
    if (getParameters().isPlugUnPlug() && getVm().getStatus() != VMStatus.Down) {
        return isDiskSupportedForPlugUnPlug(getDiskVmElement(), disk.getDiskAlias());
    }
    return true;
}
Also used : DiskValidator(org.ovirt.engine.core.bll.validator.storage.DiskValidator) StorageDomain(org.ovirt.engine.core.common.businessentities.StorageDomain) StorageDomainValidator(org.ovirt.engine.core.bll.validator.storage.StorageDomainValidator) DiskVmElementValidator(org.ovirt.engine.core.bll.validator.storage.DiskVmElementValidator) StoragePoolIsoMapId(org.ovirt.engine.core.common.businessentities.StoragePoolIsoMapId) Guid(org.ovirt.engine.core.compat.Guid) ValidationResult(org.ovirt.engine.core.bll.ValidationResult) Disk(org.ovirt.engine.core.common.businessentities.storage.Disk) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) VmValidator(org.ovirt.engine.core.bll.validator.VmValidator) VmDeviceId(org.ovirt.engine.core.common.businessentities.VmDeviceId)

Example 14 with VmValidator

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

the class RemoveDiskSnapshotsCommand method validate.

@Override
protected boolean validate() {
    if (getVm() == null) {
        return failValidation(EngineMessage.ACTION_TYPE_FAILED_VM_NOT_FOUND);
    }
    DiskSnapshotsValidator diskSnapshotsValidator = createDiskSnapshotsValidator(getImages());
    if (!validate(diskSnapshotsValidator.diskSnapshotsNotExist(getParameters().getImageIds())) || !validate(diskSnapshotsValidator.diskImagesBelongToSameImageGroup()) || !validate(diskSnapshotsValidator.imagesAreSnapshots())) {
        return false;
    }
    // Validate all chain of images in the disk
    if (!validateAllDiskImages()) {
        return false;
    }
    DiskImagesValidator diskImagesValidator = createDiskImageValidator(getImages());
    if (!validate(diskImagesValidator.diskImagesSnapshotsNotAttachedToOtherVms(false))) {
        return false;
    }
    if (!canRunActionOnNonManagedVm()) {
        return false;
    }
    if (isDiskPlugged()) {
        VmValidator vmValidator = createVmValidator(getVm());
        if (!validate(vmValidator.vmQualifiedForSnapshotMerge())) {
            return false;
        }
    }
    if (!validate(new StoragePoolValidator(getStoragePool()).existsAndUp()) || !validateVmNotDuringSnapshot() || !validateVmNotInPreview() || !validateSnapshotExists() || !validateSnapshotType() || !validateStorageDomainActive()) {
        return false;
    }
    if (!validateStorageDomainAvailableSpace()) {
        return false;
    }
    return true;
}
Also used : StoragePoolValidator(org.ovirt.engine.core.bll.validator.storage.StoragePoolValidator) DiskSnapshotsValidator(org.ovirt.engine.core.bll.validator.storage.DiskSnapshotsValidator) DiskImagesValidator(org.ovirt.engine.core.bll.validator.storage.DiskImagesValidator) VmValidator(org.ovirt.engine.core.bll.validator.VmValidator)

Example 15 with VmValidator

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

the class TryBackToAllSnapshotsOfVmCommand method validate.

@Override
protected boolean validate() {
    if (Guid.Empty.equals(getParameters().getDstSnapshotId())) {
        return failValidation(EngineMessage.ACTION_TYPE_FAILED_CORRUPTED_VM_SNAPSHOT_ID);
    }
    // verify that the destination lease domain ID belongs to one of the VM's snapshots
    if (getParameters().getDstLeaseDomainId() != null) {
        if (!validate(snapshotsValidator.isLeaseDomainIdBelongsToSnapshot(getVmId(), getParameters().getDstLeaseDomainId())) && !getParameters().getDstLeaseDomainId().equals(getVm().getLeaseStorageDomainId())) {
            return failValidation(EngineMessage.ACTION_TYPE_FAILED_LEASE_DOMAIN_ID_IS_NOT_VALID);
        }
    }
    VmValidator vmValidator = new VmValidator(getVm());
    if (!validate(vmValidator.isVmExists()) || !validate(vmValidator.vmDown()) || !validate(snapshotsValidator.snapshotExists(getVmId(), getParameters().getDstSnapshotId())) || !validate(snapshotsValidator.vmNotDuringSnapshot(getVmId())) || !validate(snapshotsValidator.vmNotInPreview(getVmId())) || !validate(snapshotsValidator.snapshotVmConfigurationBroken(getDstSnapshot(), getVmName()))) {
        return false;
    }
    updateVmDisksFromDb();
    List<DiskImage> diskImages = DisksFilter.filterImageDisks(getVm().getDiskMap().values(), ONLY_NOT_SHAREABLE, ONLY_SNAPABLE, ONLY_ACTIVE);
    diskImages.addAll(DisksFilter.filterCinderDisks(getVm().getDiskMap().values(), ONLY_PLUGGED));
    if (!diskImages.isEmpty()) {
        if (!validate(new StoragePoolValidator(getStoragePool()).existsAndUp())) {
            return false;
        }
        DiskImagesValidator diskImagesValidator = new DiskImagesValidator(diskImages);
        if (!validate(diskImagesValidator.diskImagesNotIllegal()) || !validate(diskImagesValidator.diskImagesNotLocked())) {
            return false;
        }
        List<DiskImage> images = getImagesToPreview();
        DiskImagesValidator diskImagesToPreviewValidator = new DiskImagesValidator(images);
        if (!validate(diskImagesToPreviewValidator.noDuplicatedIds()) || !validate(diskImagesToPreviewValidator.diskImagesSnapshotsAttachedToVm(getVmId())) || !validate(diskImagesToPreviewValidator.diskImagesNotIllegal()) || !validate(diskImagesToPreviewValidator.diskImagesNotLocked())) {
            return false;
        }
        Set<Guid> storageIds = ImagesHandler.getAllStorageIdsForImageIds(diskImages);
        // verify lease storage domain status
        if (getParameters().getDstLeaseDomainId() != null) {
            storageIds.add(getParameters().getDstLeaseDomainId());
        } else if (getDstSnapshot().getVmConfiguration() != null) {
            Guid leaseDomainId = OvfUtils.fetchLeaseDomainId(getDstSnapshot().getVmConfiguration());
            if (leaseDomainId != null) {
                storageIds.add(leaseDomainId);
            }
        }
        MultipleStorageDomainsValidator storageValidator = new MultipleStorageDomainsValidator(getVm().getStoragePoolId(), storageIds);
        if (!validate(storageValidator.allDomainsExistAndActive()) || !validate(storageValidator.allDomainsWithinThresholds()) || !validateCinder()) {
            return false;
        }
    }
    DiskSnapshotsValidator diskSnapshotsValidator = new DiskSnapshotsValidator(getParameters().getDisks());
    if (!validate(diskSnapshotsValidator.canDiskSnapshotsBePreviewed(getParameters().getDstSnapshotId()))) {
        return false;
    }
    if (isRestoreMemory() && !validateMemoryTakenInSupportedVersion()) {
        return false;
    }
    if (!canRestoreVmConfigFromSnapshot()) {
        return failValidation(EngineMessage.MAC_POOL_NOT_ENOUGH_MAC_ADDRESSES);
    }
    return true;
}
Also used : StoragePoolValidator(org.ovirt.engine.core.bll.validator.storage.StoragePoolValidator) DiskSnapshotsValidator(org.ovirt.engine.core.bll.validator.storage.DiskSnapshotsValidator) Guid(org.ovirt.engine.core.compat.Guid) MultipleStorageDomainsValidator(org.ovirt.engine.core.bll.validator.storage.MultipleStorageDomainsValidator) DiskImagesValidator(org.ovirt.engine.core.bll.validator.storage.DiskImagesValidator) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) VmValidator(org.ovirt.engine.core.bll.validator.VmValidator)

Aggregations

VmValidator (org.ovirt.engine.core.bll.validator.VmValidator)20 DiskImagesValidator (org.ovirt.engine.core.bll.validator.storage.DiskImagesValidator)10 StoragePoolValidator (org.ovirt.engine.core.bll.validator.storage.StoragePoolValidator)9 DiskImage (org.ovirt.engine.core.common.businessentities.storage.DiskImage)9 Guid (org.ovirt.engine.core.compat.Guid)7 MultipleStorageDomainsValidator (org.ovirt.engine.core.bll.validator.storage.MultipleStorageDomainsValidator)6 StorageDomainValidator (org.ovirt.engine.core.bll.validator.storage.StorageDomainValidator)5 VM (org.ovirt.engine.core.common.businessentities.VM)5 Disk (org.ovirt.engine.core.common.businessentities.storage.Disk)5 DiskVmElementValidator (org.ovirt.engine.core.bll.validator.storage.DiskVmElementValidator)4 CinderDisk (org.ovirt.engine.core.common.businessentities.storage.CinderDisk)3 LunDisk (org.ovirt.engine.core.common.businessentities.storage.LunDisk)3 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 Before (org.junit.Before)2 ValidationResult (org.ovirt.engine.core.bll.ValidationResult)2 CinderDisksValidator (org.ovirt.engine.core.bll.validator.storage.CinderDisksValidator)2 DiskSnapshotsValidator (org.ovirt.engine.core.bll.validator.storage.DiskSnapshotsValidator)2 DiskValidator (org.ovirt.engine.core.bll.validator.storage.DiskValidator)2 EngineMessage (org.ovirt.engine.core.common.errors.EngineMessage)2