Search in sources :

Example 6 with DiskImagesValidator

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

the class TransferDiskImageCommand method validateImageTransfer.

@Override
protected boolean validateImageTransfer() {
    DiskImage diskImage = getDiskImage();
    DiskValidator diskValidator = getDiskValidator(diskImage);
    DiskImagesValidator diskImagesValidator = getDiskImagesValidator(diskImage);
    StorageDomainValidator storageDomainValidator = getStorageDomainValidator(storageDomainDao.getForStoragePool(diskImage.getStorageIds().get(0), diskImage.getStoragePoolId()));
    return validate(diskValidator.isDiskExists()) && validateActiveDiskPluggedToAnyNonDownVm(diskImage, diskValidator) && validate(diskImagesValidator.diskImagesNotIllegal()) && validate(diskImagesValidator.diskImagesNotLocked()) && validate(storageDomainValidator.isDomainExistAndActive());
}
Also used : DiskValidator(org.ovirt.engine.core.bll.validator.storage.DiskValidator) StorageDomainValidator(org.ovirt.engine.core.bll.validator.storage.StorageDomainValidator) DiskImagesValidator(org.ovirt.engine.core.bll.validator.storage.DiskImagesValidator) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage)

Example 7 with DiskImagesValidator

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

the class AmendImageGroupVolumesCommand method validate.

@Override
protected boolean validate() {
    DiskValidator diskValidator = createDiskValidator();
    if (!validate(diskValidator.isDiskExists())) {
        return false;
    }
    if (!validate(diskValidator.isDiskPluggedToAnyNonDownVm(false))) {
        return false;
    }
    setStoragePoolId(getDiskImage().getStoragePoolId());
    if (!validate(new StoragePoolValidator(getStoragePool()).existsAndUp())) {
        return false;
    }
    if (!FeatureSupported.qcowCompatSupported(getStoragePool().getCompatibilityVersion())) {
        return failValidation(EngineMessage.ACTION_TYPE_FAILED_AMEND_NOT_SUPPORTED_BY_DC_VERSION, String.format("$dataCenterVersion %s", getStoragePool().getCompatibilityVersion().toString()));
    }
    if (getDiskImage().getVmEntityType().isTemplateType()) {
        return failValidation(EngineMessage.ACTION_TYPE_FAILED_CANT_AMEND_TEMPLATE_DISK);
    }
    setStorageDomainId(getDiskImage().getStorageIds().get(0));
    StorageDomainValidator storageDomainValidator = new StorageDomainValidator(getStorageDomain());
    if (!validate(storageDomainValidator.isDomainExistAndActive())) {
        return false;
    }
    DiskImagesValidator diskImagesValidator = new DiskImagesValidator(Collections.singletonList(getDiskImage()));
    return validate(diskImagesValidator.diskImagesNotIllegal()) && validate(diskImagesValidator.diskImagesNotLocked());
}
Also used : DiskValidator(org.ovirt.engine.core.bll.validator.storage.DiskValidator) StoragePoolValidator(org.ovirt.engine.core.bll.validator.storage.StoragePoolValidator) StorageDomainValidator(org.ovirt.engine.core.bll.validator.storage.StorageDomainValidator) DiskImagesValidator(org.ovirt.engine.core.bll.validator.storage.DiskImagesValidator)

Example 8 with DiskImagesValidator

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

the class ExportVmCommand method validate.

@Override
protected boolean validate() {
    if (getVm() == null) {
        return failValidation(EngineMessage.ACTION_TYPE_FAILED_VM_NOT_FOUND);
    }
    setDescription(getVmName());
    setStoragePoolId(getVm().getStoragePoolId());
    // check that target domain exists
    StorageDomainValidator targetstorageDomainValidator = new StorageDomainValidator(getStorageDomain());
    if (!validate(targetstorageDomainValidator.isDomainExistAndActive())) {
        return false;
    }
    // load the disks of vm from database
    vmHandler.updateDisksFromDb(getVm());
    List<DiskImage> disksForExport = getDisksBasedOnImage();
    DiskImagesValidator diskImagesValidator = new DiskImagesValidator(disksForExport);
    if (!validate(diskImagesValidator.diskImagesNotIllegal()) || !validate(diskImagesValidator.diskImagesNotLocked())) {
        return false;
    }
    // update vm snapshots for storage free space check
    imagesHandler.fillImagesBySnapshots(getVm());
    // check that the target and source domain are in the same storage_pool
    if (storagePoolIsoMapDao.get(new StoragePoolIsoMapId(getStorageDomain().getId(), getVm().getStoragePoolId())) == null) {
        return failValidation(EngineMessage.ACTION_TYPE_FAILED_STORAGE_POOL_NOT_MATCH);
    }
    // check if template exists only if asked for
    if (getParameters().getTemplateMustExists()) {
        if (!checkTemplateInStorageDomain(getVm().getStoragePoolId(), getParameters().getStorageDomainId(), getVm().getVmtGuid(), getContext().getEngineContext())) {
            return failValidation(EngineMessage.ACTION_TYPE_FAILED_TEMPLATE_NOT_FOUND_ON_EXPORT_DOMAIN, String.format("$TemplateName %1$s", getVm().getVmtName()));
        }
    }
    Map<Guid, ? extends Disk> images = getVm().getDiskMap();
    if (getParameters().getCopyCollapse()) {
        for (DiskImage img : disksForExport) {
            if (images.containsKey(img.getId())) {
                // check that no RAW format exists (we are in collapse mode)
                if (((DiskImage) images.get(img.getId())).getVolumeFormat() == VolumeFormat.RAW && img.getVolumeFormat() != VolumeFormat.RAW) {
                    return failValidation(EngineMessage.VM_CANNOT_EXPORT_RAW_FORMAT);
                }
            }
        }
    }
    // check destination storage is Export domain
    if (getStorageDomain().getStorageDomainType() != StorageDomainType.ImportExport) {
        return failValidation(EngineMessage.ACTION_TYPE_FAILED_SPECIFY_DOMAIN_IS_NOT_EXPORT_DOMAIN, String.format("$storageDomainName %1$s", getStorageDomainName()));
    }
    // get the snapshots that are going to be exported and have memory
    snapshotsWithMemory = getSnapshotsToBeExportedWithMemory();
    // check destination storage have free space
    if (!handleDestStorageDomain(disksForExport)) {
        return false;
    }
    if (!(checkVmInStorageDomain() && validate(new StoragePoolValidator(getStoragePool()).existsAndUp()) && validate(snapshotsValidator.vmNotDuringSnapshot(getVmId())) && validate(snapshotsValidator.vmNotInPreview(getVmId())) && validate(new VmValidator(getVm()).vmDown()) && validate(new MultipleStorageDomainsValidator(getVm().getStoragePoolId(), ImagesHandler.getAllStorageIdsForImageIds(disksForExport)).allDomainsExistAndActive()))) {
        return false;
    }
    return true;
}
Also used : StoragePoolValidator(org.ovirt.engine.core.bll.validator.storage.StoragePoolValidator) StorageDomainValidator(org.ovirt.engine.core.bll.validator.storage.StorageDomainValidator) StoragePoolIsoMapId(org.ovirt.engine.core.common.businessentities.StoragePoolIsoMapId) 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)

Example 9 with DiskImagesValidator

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

the class RemoveDiskCommand method canRemoveVmImageDisk.

private boolean canRemoveVmImageDisk() {
    if (!listVms.isEmpty()) {
        Guid storagePoolId = listVms.get(0).getStoragePoolId();
        StoragePool sp = storagePoolDao.get(storagePoolId);
        if (!validate(new StoragePoolValidator(sp).existsAndUp())) {
            return false;
        }
        List<DiskImage> diskList = DisksFilter.filterImageDisks(Collections.singletonList(getDisk()), ONLY_NOT_SHAREABLE, ONLY_ACTIVE);
        DiskImagesValidator diskImagesValidator = new DiskImagesValidator(diskList);
        if (!validate(diskImagesValidator.diskImagesNotLocked())) {
            return false;
        }
    }
    for (VM vm : listVms) {
        if (!validate(snapshotsValidator.vmNotDuringSnapshot(vm.getId())) || !validate(snapshotsValidator.vmNotInPreview(vm.getId()))) {
            return false;
        }
    }
    return true;
}
Also used : StoragePoolValidator(org.ovirt.engine.core.bll.validator.storage.StoragePoolValidator) StoragePool(org.ovirt.engine.core.common.businessentities.StoragePool) VM(org.ovirt.engine.core.common.businessentities.VM) Guid(org.ovirt.engine.core.compat.Guid) DiskImagesValidator(org.ovirt.engine.core.bll.validator.storage.DiskImagesValidator) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage)

Example 10 with DiskImagesValidator

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

the class SparsifyImageCommand method validate.

@Override
protected boolean validate() {
    DiskValidator diskValidator = new DiskValidator(getDiskImage());
    if (!validate(diskValidator.isDiskExists()) || !validate(diskValidator.isDiskPluggedToAnyNonDownVm(false)) || !validate(diskValidator.isSparsifySupported())) {
        return false;
    }
    if (diskImageDao.getAllSnapshotsForImageGroup(getDiskImage().getId()).size() > 1) {
        return failValidation(EngineMessage.ACTION_TYPE_FAILED_DISK_HAS_SNAPSHOTS);
    }
    DiskImagesValidator diskImagesValidator = new DiskImagesValidator(Collections.singletonList(getDiskImage()));
    return validate(diskImagesValidator.diskImagesNotIllegal()) && validate(diskImagesValidator.diskImagesNotLocked()) && validate(diskImagesValidator.diskImagesHaveNoDerivedDisks(null));
}
Also used : DiskValidator(org.ovirt.engine.core.bll.validator.storage.DiskValidator) DiskImagesValidator(org.ovirt.engine.core.bll.validator.storage.DiskImagesValidator)

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