Search in sources :

Example 26 with StorageDomainValidator

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

the class UpdateVmDiskCommandTest method initializeCommand.

protected void initializeCommand(VM vm) {
    mockGetForDisk(vm);
    mockGetVmsListForDisk(vm);
    doNothing().when(command).reloadDisks();
    doAnswer(invocation -> invocation.getArguments()[0] != null ? invocation.getArguments()[0] : Guid.newGuid()).when(quotaManager).getDefaultQuotaIfNull(any(), any());
    doReturn(diskValidator).when(command).getDiskValidator(any());
    doReturn(diskVmElementValidator).when(command).getDiskVmElementValidator(any(), any());
    doReturn(true).when(command).setAndValidateDiskProfiles();
    doReturn(true).when(command).validateQuota();
    mockVmsStoragePoolInfo(vm);
    mockToUpdateDiskVm(vm);
    StorageDomain sd = new StorageDomain();
    sd.setAvailableDiskSize(Integer.MAX_VALUE);
    sd.setStatus(StorageDomainStatus.Active);
    when(storageDomainDao.get(any())).thenReturn(sd);
    when(storageDomainDao.getForStoragePool(any(), any())).thenReturn(sd);
    StorageDomainValidator sdValidator = new StorageDomainValidator(sd);
    doReturn(sdValidator).when(command).getStorageDomainValidator(any());
    ActionReturnValue ret = new ActionReturnValue();
    ret.setSucceeded(true);
    when(backend.runInternalAction(eq(ActionType.AmendImageGroupVolumes), any(), any())).thenReturn(ret);
    command.init();
    doReturn(ActionType.UpdateVmDisk).when(command).getActionType();
}
Also used : StorageDomain(org.ovirt.engine.core.common.businessentities.StorageDomain) ActionReturnValue(org.ovirt.engine.core.common.action.ActionReturnValue) StorageDomainValidator(org.ovirt.engine.core.bll.validator.storage.StorageDomainValidator)

Example 27 with StorageDomainValidator

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

the class AddStorageDomainCommand method validate.

@Override
protected boolean validate() {
    if (!super.validate() || !initializeVds() || !checkStorageDomainNameLengthValid()) {
        return false;
    }
    if (getStorageDomain().getStorageDomainType() == StorageDomainType.ISO && !getStorageDomain().getStorageType().isFileDomain()) {
        addValidationMessageVariable("domainType", StorageConstants.ISO);
        addValidationMessageVariable("storageTypes", StorageConstants.FILE);
        return failValidation(EngineMessage.ACTION_TYPE_FAILED_DOMAIN_TYPE_CAN_BE_CREATED_ONLY_ON_SPECIFIC_STORAGE_DOMAINS);
    }
    if (getStorageDomain().getStorageDomainType() == StorageDomainType.ImportExport && getStorageDomain().getStorageType().isBlockDomain()) {
        addValidationMessageVariable("domainType", StorageConstants.EXPORT);
        addValidationMessageVariable("storageTypes", StorageConstants.FILE);
        return failValidation(EngineMessage.ACTION_TYPE_FAILED_DOMAIN_TYPE_CAN_BE_CREATED_ONLY_ON_SPECIFIC_STORAGE_DOMAINS);
    }
    if (getStorageDomain().getStorageDomainType() == StorageDomainType.Master) {
        return failValidation(EngineMessage.ACTION_TYPE_FAILED_STORAGE_DOMAIN_TYPE_ILLEGAL);
    }
    StorageDomainValidator sdValidator = getStorageDomainValidator();
    if (!validate(sdValidator.isNotIsoOrExportForBackup())) {
        return false;
    }
    ensureStorageFormatInitialized();
    if (!validate(sdValidator.isStorageFormatCompatibleWithDomain())) {
        return false;
    }
    initStorageDomainDiscardAfterDeleteIfNeeded();
    if (!validateDiscardAfterDeleteLegal(sdValidator)) {
        return false;
    }
    if (!canAddDomain()) {
        return false;
    }
    if (isStorageWithSameNameExists()) {
        return failValidation(EngineMessage.ACTION_TYPE_FAILED_STORAGE_DOMAIN_NAME_ALREADY_EXIST);
    }
    return true;
}
Also used : StorageDomainValidator(org.ovirt.engine.core.bll.validator.storage.StorageDomainValidator)

Example 28 with StorageDomainValidator

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

the class VmLeaseCommandBase method validate.

@Override
protected boolean validate() {
    StorageDomain domain = storageDomainDao.getForStoragePool(getParameters().getStorageDomainId(), getParameters().getStoragePoolId());
    StorageDomainValidator validator = new StorageDomainValidator(domain);
    return validate(validator.isDomainExistAndActive()) && validate(validator.isDataDomain());
}
Also used : StorageDomain(org.ovirt.engine.core.common.businessentities.StorageDomain) StorageDomainValidator(org.ovirt.engine.core.bll.validator.storage.StorageDomainValidator)

Example 29 with StorageDomainValidator

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

the class UpdateStorageDomainCommand method validateStoragePropertiesUpdate.

private boolean validateStoragePropertiesUpdate() {
    StorageDomainValidator storageDomainValidator = getStorageDomainValidator();
    if (!checkStorageDomainStatusNotEqual(StorageDomainStatus.Locked) || !validateStorageNameUpdate() || !validateDiscardAfterDeleteLegal(storageDomainValidator) || !validateDiskOnBackupDomain(storageDomainValidator)) {
        return false;
    }
    // Collect changed fields to update in a list.
    List<String> props = ObjectIdentityChecker.getChangedFields(oldDomain, getStorageDomain().getStorageStaticData());
    // Allow changes to the following fields only:
    props.remove("storageName");
    props.remove("description");
    props.remove("comment");
    props.remove("wipeAfterDelete");
    props.remove("discardAfterDelete");
    props.remove("warningLowSpaceIndicator");
    props.remove("criticalSpaceActionBlocker");
    props.remove("backup");
    if (!props.isEmpty()) {
        log.warn("There was an attempt to update the following fields although they are not allowed to be updated: {}", StringUtils.join(props, ","));
        return failValidation(EngineMessage.ERROR_CANNOT_CHANGE_STORAGE_DOMAIN_FIELDS);
    }
    return true;
}
Also used : StorageDomainValidator(org.ovirt.engine.core.bll.validator.storage.StorageDomainValidator)

Example 30 with StorageDomainValidator

use of org.ovirt.engine.core.bll.validator.storage.StorageDomainValidator 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)

Aggregations

StorageDomainValidator (org.ovirt.engine.core.bll.validator.storage.StorageDomainValidator)36 DiskImage (org.ovirt.engine.core.common.businessentities.storage.DiskImage)17 StorageDomain (org.ovirt.engine.core.common.businessentities.StorageDomain)16 Guid (org.ovirt.engine.core.compat.Guid)11 ArrayList (java.util.ArrayList)7 StoragePoolValidator (org.ovirt.engine.core.bll.validator.storage.StoragePoolValidator)7 ValidationResult (org.ovirt.engine.core.bll.ValidationResult)6 VmValidator (org.ovirt.engine.core.bll.validator.VmValidator)5 HashMap (java.util.HashMap)4 DiskImagesValidator (org.ovirt.engine.core.bll.validator.storage.DiskImagesValidator)4 DiskValidator (org.ovirt.engine.core.bll.validator.storage.DiskValidator)4 Disk (org.ovirt.engine.core.common.businessentities.storage.Disk)4 List (java.util.List)3 Map (java.util.Map)3 StoragePoolIsoMapId (org.ovirt.engine.core.common.businessentities.StoragePoolIsoMapId)3 DiskVmElementValidator (org.ovirt.engine.core.bll.validator.storage.DiskVmElementValidator)2 ActionReturnValue (org.ovirt.engine.core.common.action.ActionReturnValue)2 VM (org.ovirt.engine.core.common.businessentities.VM)2 VmTemplate (org.ovirt.engine.core.common.businessentities.VmTemplate)2 CinderDisk (org.ovirt.engine.core.common.businessentities.storage.CinderDisk)2