Search in sources :

Example 11 with StoragePoolValidator

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

the class AttachStorageDomainToPoolCommand method validate.

@Override
protected boolean validate() {
    StoragePoolValidator spValidator = createStoragePoolValidator();
    if (!validate(spValidator.exists()) || !initializeVds() || !checkStorageDomain()) {
        return false;
    }
    StorageDomainToPoolRelationValidator storageDomainToPoolRelationValidator = new StorageDomainToPoolRelationValidator(getStorageDomain().getStorageStaticData(), getStoragePool());
    if (!validate(storageDomainToPoolRelationValidator.validateDomainCanBeAttachedToPool())) {
        return false;
    }
    if (!spValidator.isNotInStatus(StoragePoolStatus.Uninitialized).isValid() && getStorageDomain().getStorageDomainType() != StorageDomainType.Data) {
        return failValidation(EngineMessage.ERROR_CANNOT_ADD_STORAGE_POOL_WITHOUT_DATA_DOMAIN);
    }
    StorageDomainValidator storageDomainValidator = new StorageDomainValidator(getStorageDomain());
    if (!validate(storageDomainValidator.isDiscardAfterDeleteSupportedByDcVersion(getStoragePool().getCompatibilityVersion()))) {
        return false;
    }
    if (spValidator.isNotInStatus(StoragePoolStatus.Uninitialized).isValid()) {
        return checkMasterDomainIsUp();
    }
    return true;
}
Also used : StoragePoolValidator(org.ovirt.engine.core.bll.validator.storage.StoragePoolValidator) StorageDomainValidator(org.ovirt.engine.core.bll.validator.storage.StorageDomainValidator) StorageDomainToPoolRelationValidator(org.ovirt.engine.core.bll.validator.storage.StorageDomainToPoolRelationValidator)

Example 12 with StoragePoolValidator

use of org.ovirt.engine.core.bll.validator.storage.StoragePoolValidator 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 13 with StoragePoolValidator

use of org.ovirt.engine.core.bll.validator.storage.StoragePoolValidator 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 14 with StoragePoolValidator

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

the class UpdateStoragePoolCommand method validate.

@Override
protected boolean validate() {
    StoragePoolValidator spValidator = createStoragePoolValidator();
    if (!validate(spValidator.exists())) {
        return false;
    }
    // Name related validations
    if (!StringUtils.equals(getOldStoragePool().getName(), getStoragePool().getName()) && !isStoragePoolUnique(getStoragePool().getName())) {
        return failValidation(EngineMessage.ACTION_TYPE_FAILED_STORAGE_POOL_NAME_ALREADY_EXIST);
    }
    if (!checkStoragePoolNameLengthValid()) {
        return false;
    }
    List<StorageDomainStatic> poolDomains = storageDomainStaticDao.getAllForStoragePool(getStoragePool().getId());
    if (getOldStoragePool().isLocal() && !getStoragePool().isLocal() && poolDomains.stream().anyMatch(sdc -> sdc.getStorageType() == StorageType.LOCALFS)) {
        return failValidation(EngineMessage.ERROR_CANNOT_CHANGE_STORAGE_POOL_TYPE_WITH_LOCAL);
    }
    if (!getOldStoragePool().isLocal() && getStoragePool().isLocal()) {
        List<Cluster> clusters = clusterDao.getAllForStoragePool(getStoragePool().getId());
        if (clusters.size() > 1) {
            return failValidation(EngineMessage.CLUSTER_CANNOT_ADD_MORE_THEN_ONE_HOST_TO_LOCAL_STORAGE);
        }
        List<VDS> hosts = vdsDao.getAllForStoragePool(getStoragePool().getId());
        if (hosts.size() > 1) {
            return failValidation(EngineMessage.VDS_CANNOT_ADD_MORE_THEN_ONE_HOST_TO_LOCAL_STORAGE);
        }
    }
    if (!getOldStoragePool().getCompatibilityVersion().equals(getStoragePool().getCompatibilityVersion())) {
        if (!isStoragePoolVersionSupported()) {
            return failValidation(VersionSupport.getUnsupportedVersionMessage());
        } else // decreasing of compatibility version is allowed under conditions
        if (getStoragePool().getCompatibilityVersion().compareTo(getOldStoragePool().getCompatibilityVersion()) < 0) {
            if (!poolDomains.isEmpty() && !isCompatibilityVersionChangeAllowedForDomains(poolDomains)) {
                return false;
            }
            List<Network> networks = networkDao.getAllForDataCenter(getStoragePoolId());
            for (Network network : networks) {
                NetworkValidator validator = getNetworkValidator(network);
                if (!getManagementNetworkUtil().isManagementNetwork(network.getId()) || !validator.canNetworkCompatibilityBeDecreased()) {
                    return failValidation(EngineMessage.ACTION_TYPE_FAILED_CANNOT_DECREASE_DATA_CENTER_COMPATIBILITY_VERSION);
                }
            }
        } else if (!checkAllClustersLevel()) {
            // Check all clusters has at least the same compatibility version.
            return false;
        }
    }
    return validate(spValidator.isNotLocalfsWithDefaultCluster()) && validate(allMacsInEveryClusterCanBeMigratedToAnotherPool());
}
Also used : StorageDomainStatic(org.ovirt.engine.core.common.businessentities.StorageDomainStatic) ClusterDao(org.ovirt.engine.core.dao.ClusterDao) StringUtils(org.apache.commons.lang.StringUtils) NonTransactiveCommandAttribute(org.ovirt.engine.core.bll.NonTransactiveCommandAttribute) EngineException(org.ovirt.engine.core.common.errors.EngineException) SyncLunsParameters(org.ovirt.engine.core.common.action.SyncLunsParameters) DiskLunMap(org.ovirt.engine.core.common.businessentities.storage.DiskLunMap) VmStaticDao(org.ovirt.engine.core.dao.VmStaticDao) CommandContext(org.ovirt.engine.core.bll.context.CommandContext) ActionType(org.ovirt.engine.core.common.action.ActionType) VdsDao(org.ovirt.engine.core.dao.VdsDao) StoragePoolDao(org.ovirt.engine.core.dao.StoragePoolDao) Version(org.ovirt.engine.core.compat.Version) StorageFormatType(org.ovirt.engine.core.common.businessentities.StorageFormatType) StorageType(org.ovirt.engine.core.common.businessentities.storage.StorageType) EngineMessage(org.ovirt.engine.core.common.errors.EngineMessage) ManagementNetworkUtil(org.ovirt.engine.core.bll.network.cluster.ManagementNetworkUtil) NetworkDao(org.ovirt.engine.core.dao.network.NetworkDao) Collectors(java.util.stream.Collectors) VmDao(org.ovirt.engine.core.dao.VmDao) List(java.util.List) Cluster(org.ovirt.engine.core.common.businessentities.Cluster) ValidationResult(org.ovirt.engine.core.bll.ValidationResult) AuditLogType(org.ovirt.engine.core.common.AuditLogType) VdcObjectType(org.ovirt.engine.core.common.VdcObjectType) FeatureSupported(org.ovirt.engine.core.common.FeatureSupported) StoragePool(org.ovirt.engine.core.common.businessentities.StoragePool) DiskLunMapDao(org.ovirt.engine.core.dao.DiskLunMapDao) Guid(org.ovirt.engine.core.compat.Guid) ReplacementUtils(org.ovirt.engine.core.utils.ReplacementUtils) TransactionSupport(org.ovirt.engine.core.utils.transaction.TransactionSupport) ArrayList(java.util.ArrayList) StoragePoolManagementParameter(org.ovirt.engine.core.common.action.StoragePoolManagementParameter) Inject(javax.inject.Inject) StorageDomainToPoolRelationValidator(org.ovirt.engine.core.bll.validator.storage.StorageDomainToPoolRelationValidator) StorageDomainStatic(org.ovirt.engine.core.common.businessentities.StorageDomainStatic) Network(org.ovirt.engine.core.common.businessentities.network.Network) StorageDomainStaticDao(org.ovirt.engine.core.dao.StorageDomainStaticDao) VersionStorageFormatUtil(org.ovirt.engine.core.common.utils.VersionStorageFormatUtil) NetworkValidator(org.ovirt.engine.core.bll.validator.NetworkValidator) StoragePoolValidator(org.ovirt.engine.core.bll.validator.storage.StoragePoolValidator) StoragePoolStatus(org.ovirt.engine.core.common.businessentities.StoragePoolStatus) AuditLogDirector(org.ovirt.engine.core.dal.dbbroker.auditloghandling.AuditLogDirector) VersionSupport(org.ovirt.engine.core.bll.utils.VersionSupport) EngineError(org.ovirt.engine.core.common.errors.EngineError) TransactionScopeOption(org.ovirt.engine.core.compat.TransactionScopeOption) AuditLogable(org.ovirt.engine.core.dal.dbbroker.auditloghandling.AuditLogable) MoveMacs(org.ovirt.engine.core.bll.MoveMacs) UpgradeStoragePoolVDSCommandParameters(org.ovirt.engine.core.common.vdscommands.UpgradeStoragePoolVDSCommandParameters) RenamedEntityInfoProvider(org.ovirt.engine.core.bll.RenamedEntityInfoProvider) VDSCommandType(org.ovirt.engine.core.common.vdscommands.VDSCommandType) StorageDomainType(org.ovirt.engine.core.common.businessentities.StorageDomainType) VDS(org.ovirt.engine.core.common.businessentities.VDS) StoragePoolValidator(org.ovirt.engine.core.bll.validator.storage.StoragePoolValidator) NetworkValidator(org.ovirt.engine.core.bll.validator.NetworkValidator) VDS(org.ovirt.engine.core.common.businessentities.VDS) Network(org.ovirt.engine.core.common.businessentities.network.Network) Cluster(org.ovirt.engine.core.common.businessentities.Cluster) List(java.util.List) ArrayList(java.util.ArrayList)

Example 15 with StoragePoolValidator

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

the class AddDiskCommand method checkIfImageDiskCanBeAdded.

protected boolean checkIfImageDiskCanBeAdded(VM vm, DiskVmElementValidator diskVmElementValidator) {
    if (Guid.Empty.equals(getStorageDomainId())) {
        return failValidation(EngineMessage.ACTION_TYPE_FAILED_STORAGE_DOMAIN_NOT_SPECIFIED);
    }
    boolean returnValue;
    StorageDomainValidator storageDomainValidator = createStorageDomainValidator();
    // vm agnostic checks
    returnValue = (getParameters().isSkipDomainCheck() || validate(storageDomainValidator.isDomainExistAndActive())) && validateShareableDiskOnGlusterDomain() && checkImageConfiguration() && validate(storageDomainValidator.hasSpaceForNewDisk(getDiskImageInfo())) && validate(storageDomainValidator.isDomainWithinThresholds()) && checkExceedingMaxBlockDiskSize() && canAddShareableDisk() && validate(diskVmElementValidator.isVirtIoScsiValid(vm)) && validate(diskVmElementValidator.isDiskInterfaceSupported(getVm()));
    if (returnValue && vm != null) {
        // Note this is done according to the VM's spId.
        StoragePool sp = getStoragePool();
        returnValue = validate(new StoragePoolValidator(sp).existsAndUp()) && isStoragePoolMatching(vm) && validate(new VmValidator(getVm()).vmNotLocked()) && isVmNotInPreviewSnapshot();
    }
    return returnValue;
}
Also used : StoragePoolValidator(org.ovirt.engine.core.bll.validator.storage.StoragePoolValidator) StoragePool(org.ovirt.engine.core.common.businessentities.StoragePool) StorageDomainValidator(org.ovirt.engine.core.bll.validator.storage.StorageDomainValidator) VmValidator(org.ovirt.engine.core.bll.validator.VmValidator)

Aggregations

StoragePoolValidator (org.ovirt.engine.core.bll.validator.storage.StoragePoolValidator)27 Guid (org.ovirt.engine.core.compat.Guid)11 VmValidator (org.ovirt.engine.core.bll.validator.VmValidator)9 DiskImagesValidator (org.ovirt.engine.core.bll.validator.storage.DiskImagesValidator)9 DiskImage (org.ovirt.engine.core.common.businessentities.storage.DiskImage)9 StorageDomainValidator (org.ovirt.engine.core.bll.validator.storage.StorageDomainValidator)7 MultipleStorageDomainsValidator (org.ovirt.engine.core.bll.validator.storage.MultipleStorageDomainsValidator)6 ArrayList (java.util.ArrayList)5 StorageDomain (org.ovirt.engine.core.common.businessentities.StorageDomain)5 StoragePool (org.ovirt.engine.core.common.businessentities.StoragePool)4 CinderDisk (org.ovirt.engine.core.common.businessentities.storage.CinderDisk)4 CinderDisksValidator (org.ovirt.engine.core.bll.validator.storage.CinderDisksValidator)3 VM (org.ovirt.engine.core.common.businessentities.VM)3 Disk (org.ovirt.engine.core.common.businessentities.storage.Disk)3 EngineMessage (org.ovirt.engine.core.common.errors.EngineMessage)3 List (java.util.List)2 Map (java.util.Map)2 Collectors (java.util.stream.Collectors)2 Inject (javax.inject.Inject)2 ValidationResult (org.ovirt.engine.core.bll.ValidationResult)2