Search in sources :

Example 21 with StoragePoolValidator

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

the class ImportRepoImageCommand method validate.

@Override
protected boolean validate() {
    if (!validate(new StoragePoolValidator(getStoragePool()).existsAndUp())) {
        return false;
    }
    if (getParameters().getImportAsTemplate()) {
        if (getParameters().getClusterId() == null) {
            addValidationMessage(EngineMessage.VDS_CLUSTER_IS_NOT_VALID);
            return false;
        }
        setClusterId(getParameters().getClusterId());
        if (getCluster() == null) {
            addValidationMessage(EngineMessage.VDS_CLUSTER_IS_NOT_VALID);
            return false;
        }
        // A Template cannot be added in a cluster without a defined architecture
        if (getCluster().getArchitecture() == ArchitectureType.undefined) {
            return failValidation(EngineMessage.ACTION_TYPE_FAILED_CLUSTER_UNDEFINED_ARCHITECTURE);
        }
        setStoragePoolId(getParameters().getStoragePoolId());
    }
    DiskImage diskImage = null;
    try {
        diskImage = getDiskImage();
    } catch (OpenStackImageException e) {
        log.error("Unable to get the disk image from the provider proxy: ({}) {}", e.getErrorType(), e.getMessage());
        switch(e.getErrorType()) {
            case UNSUPPORTED_CONTAINER_FORMAT:
            case UNSUPPORTED_DISK_FORMAT:
                return failValidation(EngineMessage.ACTION_TYPE_FAILED_IMAGE_NOT_SUPPORTED);
            case UNABLE_TO_DOWNLOAD_IMAGE:
                return failValidation(EngineMessage.ACTION_TYPE_FAILED_IMAGE_DOWNLOAD_ERROR);
            case UNRECOGNIZED_IMAGE_FORMAT:
                return failValidation(EngineMessage.ACTION_TYPE_FAILED_IMAGE_UNRECOGNIZED);
        }
    }
    if (diskImage == null) {
        return failValidation(EngineMessage.ACTION_TYPE_FAILED_DISK_NOT_EXIST);
    }
    diskImage.setStoragePoolId(getStoragePoolId());
    if (!validate(createDiskImagesValidator(diskImage).isQcowVersionSupportedForDcVersion())) {
        return false;
    }
    return validateSpaceRequirements(diskImage);
}
Also used : StoragePoolValidator(org.ovirt.engine.core.bll.validator.storage.StoragePoolValidator) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) OpenStackImageException(org.ovirt.engine.core.bll.provider.storage.OpenStackImageException)

Example 22 with StoragePoolValidator

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

the class ExportOvaCommand method validate.

@Override
protected boolean validate() {
    if (getVm() == null) {
        return failValidation(EngineMessage.ACTION_TYPE_FAILED_VM_NOT_FOUND);
    }
    if (getParameters().getProxyHostId() == null) {
        return failValidation(EngineMessage.ACTION_TYPE_FAILED_PROXY_HOST_MUST_BE_SPECIFIED);
    }
    HostValidator hostValidator = HostValidator.createInstance(getVds());
    if (!validate(hostValidator.hostExists())) {
        return false;
    }
    if (!validate(hostValidator.isUp())) {
        return false;
    }
    StoragePoolValidator spValidator = new StoragePoolValidator(getStoragePool());
    if (!validate(spValidator.exists())) {
        return false;
    }
    if (!validate(spValidator.isInStatus(StoragePoolStatus.Up))) {
        return false;
    }
    if (!getStoragePoolId().equals(getVds().getStoragePoolId())) {
        return failValidation(EngineMessage.ACTION_TYPE_FAILED_PROXY_HOST_NOT_IN_VM_DATA_CENTER);
    }
    if (!validate(validateTargetFolder())) {
        return false;
    }
    return true;
}
Also used : StoragePoolValidator(org.ovirt.engine.core.bll.validator.storage.StoragePoolValidator) HostValidator(org.ovirt.engine.core.bll.validator.HostValidator)

Example 23 with StoragePoolValidator

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

the class ImportVmCommand method validateBeforeCloneVm.

protected boolean validateBeforeCloneVm(Map<Guid, StorageDomain> domainsMap) {
    if (getVm() != null) {
        setDescription(getVmName());
    }
    StoragePoolValidator spValidator = new StoragePoolValidator(getStoragePool());
    if (!validate(spValidator.existsAndUp())) {
        return false;
    }
    Set<Guid> destGuids = new HashSet<>(imageToDestinationDomainMap.values());
    for (Guid destGuid : destGuids) {
        StorageDomain storageDomain = getStorageDomain(destGuid);
        StorageDomainValidator validator = new StorageDomainValidator(storageDomain);
        if (!validate(validator.isDomainExistAndActive()) || !validate(validator.domainIsValidDestination())) {
            return false;
        }
        domainsMap.put(destGuid, storageDomain);
    }
    if (!isImagesAlreadyOnTarget() && getParameters().isImportAsNewEntity() && isCopyCollapseDisabledWithSnapshotsOrWithTemplate()) {
        return failValidation(EngineMessage.ACTION_TYPE_FAILED_IMPORT_CLONE_NOT_COLLAPSED, String.format("$VmName %1$s", getVmName()));
    }
    // Register can never happen with copyCollapse = true since there's no copy operation involved.
    if (isImagesAlreadyOnTarget() && getParameters().getCopyCollapse()) {
        return failValidation(EngineMessage.ACTION_TYPE_FAILED_IMPORT_UNREGISTERED_NOT_COLLAPSED);
    }
    if (!isImagesAlreadyOnTarget()) {
        setSourceDomainId(getParameters().getSourceDomainId());
        StorageDomainValidator validator = new StorageDomainValidator(getSourceDomain());
        if (validator.isDomainExistAndActive().isValid() && getSourceDomain().getStorageDomainType() != StorageDomainType.ImportExport) {
            return failValidation(EngineMessage.ACTION_TYPE_FAILED_STORAGE_DOMAIN_TYPE_ILLEGAL);
        }
        if (!validateAndSetVmFromExportDomain()) {
            return failValidation(EngineMessage.ACTION_TYPE_FAILED_VM_NOT_FOUND_ON_EXPORT_DOMAIN);
        }
    }
    if (!validateImages(domainsMap)) {
        return false;
    }
    List<VmNetworkInterface> vmNetworkInterfaces = getVm().getInterfaces();
    vmNicMacsUtils.replaceInvalidEmptyStringMacAddressesWithNull(vmNetworkInterfaces);
    return true;
}
Also used : StoragePoolValidator(org.ovirt.engine.core.bll.validator.storage.StoragePoolValidator) StorageDomain(org.ovirt.engine.core.common.businessentities.StorageDomain) VmNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface) StorageDomainValidator(org.ovirt.engine.core.bll.validator.storage.StorageDomainValidator) Guid(org.ovirt.engine.core.compat.Guid) HashSet(java.util.HashSet)

Example 24 with StoragePoolValidator

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

the class VmPoolHandler method isNonPrestartedVmFree.

/**
 * Check if a specific VM is free. A VM is considered free if it isn't attached to a user and not during preview
 * @param vmId The VM ID
 * @param errorProcessor the error messages processor object or lambda expression (may be <code>null</code>)
 * @return True if the VM is free, false otherwise
 */
public boolean isNonPrestartedVmFree(Guid vmId, ErrorProcessor errorProcessor) {
    List<String> messages = new ArrayList<>();
    // check that there is no user already attached to this VM
    if (vmAssignedToUser(vmId, messages)) {
        return failVmFree(errorProcessor, vmId, messages);
    }
    // check that VN can be run
    if (!canRunPoolVm(vmId, messages)) {
        return failVmFree(errorProcessor, vmId, messages);
    }
    // check VM images
    ValidationResult vmDuringSnapshotResult = snapshotsValidator.vmNotDuringSnapshot(vmId);
    if (!vmDuringSnapshotResult.isValid()) {
        return failVmFree(errorProcessor, vmId, vmDuringSnapshotResult.getMessagesAsStrings());
    }
    ValidationResult vmInPreviewResult = snapshotsValidator.vmNotInPreview(vmId);
    if (!vmInPreviewResult.isValid()) {
        return failVmFree(errorProcessor, vmId, vmInPreviewResult.getMessagesAsStrings());
    }
    List<Disk> disks = diskDao.getAllForVm(vmId);
    List<DiskImage> vmImages = DisksFilter.filterImageDisks(disks, ONLY_NOT_SHAREABLE, ONLY_SNAPABLE);
    VM vm = vmDao.get(vmId);
    StoragePool sp = storagePoolDao.get(vm.getStoragePoolId());
    ValidationResult spUpResult = new StoragePoolValidator(sp).existsAndUp();
    if (!spUpResult.isValid()) {
        return failVmFree(errorProcessor, vmId, spUpResult.getMessagesAsStrings());
    }
    Guid storageDomainId = vmImages.size() > 0 ? vmImages.get(0).getStorageIds().get(0) : Guid.Empty;
    if (!Guid.Empty.equals(storageDomainId)) {
        StorageDomainValidator storageDomainValidator = new StorageDomainValidator(storageDomainDao.getForStoragePool(storageDomainId, sp.getId()));
        ValidationResult domainActiveResult = storageDomainValidator.isDomainExistAndActive();
        if (!domainActiveResult.isValid()) {
            return failVmFree(errorProcessor, vmId, domainActiveResult.getMessagesAsStrings());
        }
    }
    DiskImagesValidator diskImagesValidator = new DiskImagesValidator(vmImages);
    ValidationResult disksNotLockedResult = diskImagesValidator.diskImagesNotLocked();
    if (!disksNotLockedResult.isValid()) {
        messages.addAll(disksNotLockedResult.getMessagesAsStrings());
        messages.addAll(disksNotLockedResult.getVariableReplacements());
        return failVmFree(errorProcessor, vmId, messages);
    }
    ValidationResult vmNotLockResult = new VmValidator(vm).vmNotLocked();
    if (!vmNotLockResult.isValid()) {
        return failVmFree(errorProcessor, vmId, vmNotLockResult.getMessagesAsStrings());
    }
    return true;
}
Also used : StoragePool(org.ovirt.engine.core.common.businessentities.StoragePool) StorageDomainValidator(org.ovirt.engine.core.bll.validator.storage.StorageDomainValidator) ArrayList(java.util.ArrayList) Guid(org.ovirt.engine.core.compat.Guid) StoragePoolValidator(org.ovirt.engine.core.bll.validator.storage.StoragePoolValidator) VM(org.ovirt.engine.core.common.businessentities.VM) DiskImagesValidator(org.ovirt.engine.core.bll.validator.storage.DiskImagesValidator) Disk(org.ovirt.engine.core.common.businessentities.storage.Disk) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) RunVmValidator(org.ovirt.engine.core.bll.validator.RunVmValidator) VmValidator(org.ovirt.engine.core.bll.validator.VmValidator)

Example 25 with StoragePoolValidator

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

the class RemoveVmTemplateCommand method validate.

@Override
protected boolean validate() {
    Guid vmTemplateId = getVmTemplateId();
    VmTemplate template = getVmTemplate();
    if (!super.validate()) {
        return false;
    }
    boolean isInstanceType = getVmTemplate().getTemplateType() == VmEntityType.INSTANCE_TYPE;
    if (getCluster() == null && !isInstanceType) {
        addValidationMessage(EngineMessage.ACTION_TYPE_FAILED_CLUSTER_CAN_NOT_BE_EMPTY);
        return false;
    }
    // check template exists
    if (!validate(templateExists())) {
        return false;
    }
    // check not blank template
    if (VmTemplateHandler.BLANK_VM_TEMPLATE_ID.equals(vmTemplateId)) {
        return failValidation(EngineMessage.VMT_CANNOT_REMOVE_BLANK_TEMPLATE);
    }
    // check storage pool valid
    if (!isInstanceType && !validate(new StoragePoolValidator(getStoragePool()).existsAndUp())) {
        return false;
    }
    // check if delete protected
    if (template.isDeleteProtected()) {
        return failValidation(EngineMessage.ACTION_TYPE_FAILED_DELETE_PROTECTION_ENABLED);
    }
    if (!isInstanceType) {
        getImageTemplates();
    }
    // populate all the domains of the template
    Set<Guid> allDomainsList = getStorageDomainsByDisks(imageTemplates);
    getParameters().setStorageDomainsList(new ArrayList<>(allDomainsList));
    // check template images for selected domains
    for (Guid domainId : getParameters().getStorageDomainsList()) {
        if (!validate(vmTemplateHandler.isVmTemplateImagesReady(getVmTemplate(), domainId, getParameters().isCheckDisksExists(), true, false, true, storageToDisksMap.get(domainId)))) {
            return false;
        }
    }
    // check no vms from this template on selected domains
    List<VM> vms = vmDao.getAllWithTemplate(vmTemplateId);
    List<String> problematicVmNames = new ArrayList<>();
    for (VM vm : vms) {
        problematicVmNames.add(vm.getName());
    }
    if (!problematicVmNames.isEmpty()) {
        return failValidation(EngineMessage.VMT_CANNOT_REMOVE_DETECTED_DERIVED_VM, String.format("$vmsList %1$s", StringUtils.join(problematicVmNames, ",")));
    }
    if (template.isBaseTemplate() && !tryLockSubVersionIfExists()) {
        return false;
    }
    if (!isInstanceType && !validate(checkNoDisksBasedOnTemplateDisks())) {
        return false;
    }
    return true;
}
Also used : StoragePoolValidator(org.ovirt.engine.core.bll.validator.storage.StoragePoolValidator) VmTemplate(org.ovirt.engine.core.common.businessentities.VmTemplate) VM(org.ovirt.engine.core.common.businessentities.VM) ArrayList(java.util.ArrayList) Guid(org.ovirt.engine.core.compat.Guid)

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