Search in sources :

Example 26 with StoragePoolValidator

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

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

the class CommonVmPoolCommand method validate.

@Override
protected boolean validate() {
    if (getCluster() == null) {
        return failValidation(EngineMessage.VDS_CLUSTER_IS_NOT_VALID);
    }
    // A Pool cannot be added in a cluster without a defined architecture
    if (getCluster().getArchitecture() == ArchitectureType.undefined) {
        return failValidation(EngineMessage.ACTION_TYPE_FAILED_CLUSTER_UNDEFINED_ARCHITECTURE);
    }
    VmPool pool = vmPoolDao.getByName(getParameters().getVmPool().getName());
    if (pool != null && (getActionType() == ActionType.AddVmPool || !pool.getVmPoolId().equals(getParameters().getVmPoolId()))) {
        return failValidation(EngineMessage.ACTION_TYPE_FAILED_NAME_ALREADY_USED);
    }
    setStoragePoolId(getCluster().getStoragePoolId());
    if (!validate(new StoragePoolValidator(getStoragePool()).existsAndUp())) {
        return false;
    }
    ensureDestinationImageMap();
    // check if the selected template is compatible with Cluster architecture.
    if (!getVmTemplate().getId().equals(VmTemplateHandler.BLANK_VM_TEMPLATE_ID) && getCluster().getArchitecture() != getVmTemplate().getClusterArch()) {
        return failValidation(EngineMessage.ACTION_TYPE_FAILED_TEMPLATE_IS_INCOMPATIBLE);
    }
    final int nicsCount = getParameters().getVmsCount() * vmNicDao.getAllForTemplate(getVmTemplateId()).size();
    if (!validate(vmHandler.verifyMacPool(nicsCount, getMacPool()))) {
        return false;
    }
    final int priority = getParameters().getVmStaticData().getPriority();
    if (!validate(vmHandler.isVmPriorityValueLegal(priority))) {
        return false;
    }
    if (getVmTemplate().getDiskTemplateMap().values().size() != diskInfoDestinationMap.size()) {
        log.error("Can not found any default active domain for one of the disks of template with id '{}'", getVmTemplate().getId());
        addValidationMessage(EngineMessage.ACTION_TYPE_FAILED_MISSED_STORAGES_FOR_SOME_DISKS);
        return false;
    }
    List<Guid> storageIds = new ArrayList<>();
    for (DiskImage diskImage : diskInfoDestinationMap.values()) {
        Guid storageId = diskImage.getStorageIds().get(0);
        if (!storageIds.contains(storageId) && !areTemplateImagesInStorageReady(storageId)) {
            return false;
        }
        storageIds.add(storageId);
    }
    if (getActionType() == ActionType.AddVmPool && getParameters().getVmsCount() < 1) {
        return failValidation(EngineMessage.VM_POOL_CANNOT_CREATE_WITH_NO_VMS);
    }
    if (getParameters().getVmPool().getPrestartedVms() > getParameters().getVmPool().getAssignedVmsCount() + getParameters().getVmsCount()) {
        return failValidation(EngineMessage.ACTION_TYPE_FAILED_PRESTARTED_VMS_CANNOT_EXCEED_VMS_COUNT);
    }
    if (!setAndValidateDiskProfiles()) {
        return false;
    }
    if (!setAndValidateCpuProfile()) {
        return false;
    }
    return checkDestDomains();
}
Also used : StoragePoolValidator(org.ovirt.engine.core.bll.validator.storage.StoragePoolValidator) VmPool(org.ovirt.engine.core.common.businessentities.VmPool) ArrayList(java.util.ArrayList) Guid(org.ovirt.engine.core.compat.Guid) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage)

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