Search in sources :

Example 1 with MultipleStorageDomainsValidator

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

the class AddVmTemplateCommand method validateSpaceRequirements.

protected boolean validateSpaceRequirements() {
    // update vm snapshots for storage free space check
    imagesHandler.fillImagesBySnapshots(getVm());
    List<DiskImage> disksList = DisksFilter.filterImageDisks(getVm().getDiskMap().values(), ONLY_NOT_SHAREABLE, ONLY_ACTIVE);
    List<DiskImage> disksListForStorageChecks = createDiskDummiesForSpaceValidations(disksList);
    MultipleStorageDomainsValidator multipleSdValidator = getStorageDomainsValidator(getVm().getStoragePoolId(), getStorageGuidSet());
    return validate(multipleSdValidator.allDomainsWithinThresholds()) && validate(multipleSdValidator.allDomainsHaveSpaceForClonedDisks(disksListForStorageChecks));
}
Also used : MultipleStorageDomainsValidator(org.ovirt.engine.core.bll.validator.storage.MultipleStorageDomainsValidator) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage)

Example 2 with MultipleStorageDomainsValidator

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

the class RemoveVmCommand method validate.

@Override
protected boolean validate() {
    if (getVm() == null) {
        return failValidation(EngineMessage.ACTION_TYPE_FAILED_VM_NOT_FOUND);
    }
    if (!canRunActionOnNonManagedVm()) {
        return false;
    }
    if (getVm().isDeleteProtected()) {
        return failValidation(EngineMessage.ACTION_TYPE_FAILED_DELETE_PROTECTION_ENABLED);
    }
    vmHandler.updateDisksFromDb(getVm());
    getParameters().setUseCinderCommandCallback(getParameters().isRemoveDisks() && !getCinderDisks().isEmpty());
    if (!getParameters().isRemoveDisks() && !canRemoveVmWithDetachDisks()) {
        return false;
    }
    switch(getVm().getStatus()) {
        case Unassigned:
        case Down:
        case ImageIllegal:
        case ImageLocked:
            break;
        case Suspended:
            return failValidation(EngineMessage.VM_CANNOT_REMOVE_VM_WHEN_STATUS_IS_NOT_DOWN);
        default:
            return (getVm().isHostedEngine() && isInternalExecution()) || failValidation(EngineMessage.ACTION_TYPE_FAILED_VM_IS_RUNNING);
    }
    if (getVm().getVmPoolId() != null) {
        return failValidation(EngineMessage.ACTION_TYPE_FAILED_VM_ATTACHED_TO_POOL);
    }
    // enable to remove vms without images
    if (!validate(snapshotsValidator.vmNotDuringSnapshot(getVmId()))) {
        return false;
    }
    Collection<Disk> vmDisks = getVm().getDiskMap().values();
    List<DiskImage> vmImages = DisksFilter.filterImageDisks(vmDisks, ONLY_NOT_SHAREABLE, ONLY_ACTIVE);
    if (!vmImages.isEmpty() && !validate(new StoragePoolValidator(getStoragePool()).existsAndUp())) {
        return false;
    }
    vmImages.addAll(DisksFilter.filterCinderDisks(vmDisks));
    if (!vmImages.isEmpty()) {
        Set<Guid> storageIds = ImagesHandler.getAllStorageIdsForImageIds(vmImages);
        MultipleStorageDomainsValidator storageValidator = new MultipleStorageDomainsValidator(getVm().getStoragePoolId(), storageIds);
        if (!validate(storageValidator.allDomainsExistAndActive())) {
            return false;
        }
        DiskImagesValidator diskImagesValidator = new DiskImagesValidator(vmImages);
        if (!getParameters().getForce() && !validate(diskImagesValidator.diskImagesNotLocked())) {
            return false;
        }
    }
    // Handle VM status with ImageLocked
    VmValidator vmValidator = new VmValidator(getVm());
    ValidationResult vmLockedValidatorResult = vmValidator.vmNotLocked();
    if (!vmLockedValidatorResult.isValid()) {
        // without force remove, we can't remove the VM
        if (!getParameters().getForce()) {
            return failValidation(vmLockedValidatorResult.getMessages());
        }
        // If it is force, we cannot remove if there are task
        if (commandCoordinatorUtil.hasTasksByStoragePoolId(getVm().getStoragePoolId())) {
            return failValidation(EngineMessage.VM_CANNOT_REMOVE_HAS_RUNNING_TASKS);
        }
    }
    if (getParameters().isRemoveDisks() && !validate(vmValidator.vmNotHavingDeviceSnapshotsAttachedToOtherVms(false))) {
        return false;
    }
    return true;
}
Also used : StoragePoolValidator(org.ovirt.engine.core.bll.validator.storage.StoragePoolValidator) 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) CinderDisk(org.ovirt.engine.core.common.businessentities.storage.CinderDisk) LunDisk(org.ovirt.engine.core.common.businessentities.storage.LunDisk) 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)

Example 3 with MultipleStorageDomainsValidator

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

the class RestoreAllSnapshotsCommand method validate.

@Override
protected boolean validate() {
    if (getVm() == null) {
        return failValidation(EngineMessage.ACTION_TYPE_FAILED_VM_NOT_FOUND);
    }
    if (!canRunActionOnNonManagedVm()) {
        return false;
    }
    if (!validate(snapshotsValidator.snapshotExists(getSnapshot())) || !validate(snapshotsValidator.snapshotExists(getVmId(), getSnapshot().getId())) || !validate(new StoragePoolValidator(getStoragePool()).existsAndUp())) {
        return false;
    }
    if (Guid.Empty.equals(getSnapshot().getId())) {
        return failValidation(EngineMessage.ACTION_TYPE_FAILED_CORRUPTED_VM_SNAPSHOT_ID);
    }
    VmValidator vmValidator = createVmValidator(getVm());
    MultipleStorageDomainsValidator storageValidator = createStorageDomainValidator();
    if (!validate(storageValidator.allDomainsExistAndActive()) || !performImagesChecks() || !validate(vmValidator.vmDown()) || // if the user choose to commit a snapshot the vm can't have disk snapshots attached to other vms.
    getSnapshot().getType() == SnapshotType.REGULAR && !validate(vmValidator.vmNotHavingDeviceSnapshotsAttachedToOtherVms(false))) {
        return false;
    }
    if (getSnapshot().getType() == SnapshotType.REGULAR && getSnapshot().getStatus() != SnapshotStatus.IN_PREVIEW) {
        return failValidation(EngineMessage.ACTION_TYPE_FAILED_VM_SNAPSHOT_NOT_IN_PREVIEW);
    }
    if (!canRestoreVmConfigFromSnapshot()) {
        return failValidation(EngineMessage.MAC_POOL_NOT_ENOUGH_MAC_ADDRESSES);
    }
    return true;
}
Also used : StoragePoolValidator(org.ovirt.engine.core.bll.validator.storage.StoragePoolValidator) MultipleStorageDomainsValidator(org.ovirt.engine.core.bll.validator.storage.MultipleStorageDomainsValidator) VmValidator(org.ovirt.engine.core.bll.validator.VmValidator)

Example 4 with MultipleStorageDomainsValidator

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

the class ImportValidator method validateSpaceRequirements.

public ValidationResult validateSpaceRequirements(Collection<DiskImage> diskImages) {
    MultipleStorageDomainsValidator sdValidator = createMultipleStorageDomainsValidator(diskImages);
    ValidationResult result = sdValidator.allDomainsExistAndActive();
    if (!result.isValid()) {
        return result;
    }
    result = sdValidator.allDomainsWithinThresholds();
    if (!result.isValid()) {
        return result;
    }
    if (params.getCopyCollapse()) {
        return sdValidator.allDomainsHaveSpaceForClonedDisks(diskImages);
    }
    return sdValidator.allDomainsHaveSpaceForDisksWithSnapshots(diskImages);
}
Also used : MultipleStorageDomainsValidator(org.ovirt.engine.core.bll.validator.storage.MultipleStorageDomainsValidator) ValidationResult(org.ovirt.engine.core.bll.ValidationResult)

Example 5 with MultipleStorageDomainsValidator

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

the class AddVmAndCloneImageCommand method validate.

@Override
protected boolean validate() {
    List<DiskImage> disksToCheck = getDiskImagesToValidate();
    DiskImagesValidator diskImagesValidator = new DiskImagesValidator(disksToCheck);
    if (!validate(diskImagesValidator.diskImagesNotLocked())) {
        return false;
    }
    Set<Guid> storageIds = ImagesHandler.getAllStorageIdsForImageIds(disksToCheck);
    MultipleStorageDomainsValidator storageValidator = new MultipleStorageDomainsValidator(getStoragePoolId(), storageIds);
    if (!validate(storageValidator.allDomainsExistAndActive())) {
        return false;
    }
    if (!validate(new VmValidator(getSourceVmFromDb()).vmNotLocked())) {
        return false;
    }
    // Run all checks for AddVm, now that it is determined snapshot exists
    if (!super.validate()) {
        return false;
    }
    for (DiskImage diskImage : getDiskImagesToBeCloned()) {
        if (diskImage.getDiskStorageType() == DiskStorageType.IMAGE && !checkImageConfiguration(diskImage)) {
            return false;
        }
    }
    return true;
}
Also used : 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

MultipleStorageDomainsValidator (org.ovirt.engine.core.bll.validator.storage.MultipleStorageDomainsValidator)12 DiskImage (org.ovirt.engine.core.common.businessentities.storage.DiskImage)9 Guid (org.ovirt.engine.core.compat.Guid)8 VmValidator (org.ovirt.engine.core.bll.validator.VmValidator)5 DiskImagesValidator (org.ovirt.engine.core.bll.validator.storage.DiskImagesValidator)5 StoragePoolValidator (org.ovirt.engine.core.bll.validator.storage.StoragePoolValidator)5 ValidationResult (org.ovirt.engine.core.bll.ValidationResult)3 ArrayList (java.util.ArrayList)2 CinderDisk (org.ovirt.engine.core.common.businessentities.storage.CinderDisk)2 Disk (org.ovirt.engine.core.common.businessentities.storage.Disk)2 CinderDisksValidator (org.ovirt.engine.core.bll.validator.storage.CinderDisksValidator)1 DiskSnapshotsValidator (org.ovirt.engine.core.bll.validator.storage.DiskSnapshotsValidator)1 StorageDomainValidator (org.ovirt.engine.core.bll.validator.storage.StorageDomainValidator)1 StorageDomain (org.ovirt.engine.core.common.businessentities.StorageDomain)1 StoragePoolIsoMapId (org.ovirt.engine.core.common.businessentities.StoragePoolIsoMapId)1 BaseDisk (org.ovirt.engine.core.common.businessentities.storage.BaseDisk)1 LunDisk (org.ovirt.engine.core.common.businessentities.storage.LunDisk)1