Search in sources :

Example 1 with NetworkValidator

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

the class RemoveProviderValidatorTest method networksUsedTest.

private void networksUsedTest(boolean vmsNotUsingNetwork, boolean templatesNotUsingNetwork, Matcher<ValidationResult> matcher) {
    NetworkValidator networkValidator = mock(NetworkValidator.class);
    for (Network network : networks) {
        when(validator.getValidator(network)).thenReturn(networkValidator);
    }
    when(networkValidator.networkNotUsedByVms()).thenReturn(createValidationResult(vmsNotUsingNetwork));
    when(networkValidator.networkNotUsedByTemplates()).thenReturn(createValidationResult(templatesNotUsingNetwork));
    assertThat(validator.providerNetworksNotUsed(), matcher);
}
Also used : NetworkValidator(org.ovirt.engine.core.bll.validator.NetworkValidator) Network(org.ovirt.engine.core.common.businessentities.network.Network)

Example 2 with NetworkValidator

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

the class ImportExternalNetworkCommand method validate.

@Override
protected boolean validate() {
    NetworkProviderValidator providerValidator = new NetworkProviderValidator(getProvider());
    NetworkValidator networkValidator = new NetworkValidator(null, getNetwork());
    return validate(providerValidator.providerIsSet()) && validate(providerValidator.providerTypeIsNetwork()) && validate(providerValidator.validateAuthentication()) && validate(networkValidator.networkIsSet(getParameters().getNetworkExternalId()));
}
Also used : NetworkValidator(org.ovirt.engine.core.bll.validator.NetworkValidator) NetworkProviderValidator(org.ovirt.engine.core.bll.provider.NetworkProviderValidator)

Example 3 with NetworkValidator

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

the class UpdateNetworkCommand method validate.

@Override
protected boolean validate() {
    if (onlyPermittedFieldsChanged() && allowedNetworkLabelManipulation()) {
        return true;
    }
    final HasStoragePoolValidator hasStoragePoolValidator = new HasStoragePoolValidator(getNetwork());
    final NetworkValidator validatorNew = new NetworkValidator(vmDao, getNetwork());
    final UpdateNetworkValidator validatorOld = new UpdateNetworkValidator(getOldNetwork(), vmDao, interfaceDao);
    return validate(hasStoragePoolValidator.storagePoolExists()) && validate(validatorNew.stpForVmNetworkOnly()) && validate(validatorNew.mtuValid()) && validate(validatorNew.networkPrefixValid()) && validate(validatorNew.qosExistsInDc()) && validate(validatorOld.networkIsSet(getNetwork().getId())) && validate(validatorOld.notChangingDataCenterId(getNetwork().getDataCenterId())) && validate(validatorNew.networkNameNotUsed()) && validate(validatorNew.networkNameNotUsedAsVdsmName()) && validate(validatorOld.nonVmNetworkNotUsedByVms(getNetwork())) && validate(validatorOld.nonVmNetworkNotUsedByTemplates(getNetwork())) && validate(validatorOld.notRenamingUsedNetwork(getNetworkName())) && validate(validatorOld.notRenamingLabel(getNetwork().getLabel())) && (oldAndNewNetworkIsNotExternal() || validate(validatorOld.externalNetworkDetailsUnchanged(getNetwork())));
}
Also used : NetworkValidator(org.ovirt.engine.core.bll.validator.NetworkValidator) HasStoragePoolValidator(org.ovirt.engine.core.bll.validator.HasStoragePoolValidator)

Example 4 with NetworkValidator

use of org.ovirt.engine.core.bll.validator.NetworkValidator 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 5 with NetworkValidator

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

the class UpdateStoragePoolCommandTest method setupNetworkValidator.

private void setupNetworkValidator(boolean valid) {
    NetworkValidator validator = mock(NetworkValidator.class);
    when(validator.canNetworkCompatibilityBeDecreased()).thenReturn(valid);
    when(cmd.getNetworkValidator(any())).thenReturn(validator);
}
Also used : NetworkValidator(org.ovirt.engine.core.bll.validator.NetworkValidator)

Aggregations

NetworkValidator (org.ovirt.engine.core.bll.validator.NetworkValidator)5 Network (org.ovirt.engine.core.common.businessentities.network.Network)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 Inject (javax.inject.Inject)1 StringUtils (org.apache.commons.lang.StringUtils)1 MoveMacs (org.ovirt.engine.core.bll.MoveMacs)1 NonTransactiveCommandAttribute (org.ovirt.engine.core.bll.NonTransactiveCommandAttribute)1 RenamedEntityInfoProvider (org.ovirt.engine.core.bll.RenamedEntityInfoProvider)1 ValidationResult (org.ovirt.engine.core.bll.ValidationResult)1 CommandContext (org.ovirt.engine.core.bll.context.CommandContext)1 ManagementNetworkUtil (org.ovirt.engine.core.bll.network.cluster.ManagementNetworkUtil)1 NetworkProviderValidator (org.ovirt.engine.core.bll.provider.NetworkProviderValidator)1 VersionSupport (org.ovirt.engine.core.bll.utils.VersionSupport)1 HasStoragePoolValidator (org.ovirt.engine.core.bll.validator.HasStoragePoolValidator)1 StorageDomainToPoolRelationValidator (org.ovirt.engine.core.bll.validator.storage.StorageDomainToPoolRelationValidator)1 StoragePoolValidator (org.ovirt.engine.core.bll.validator.storage.StoragePoolValidator)1 AuditLogType (org.ovirt.engine.core.common.AuditLogType)1 FeatureSupported (org.ovirt.engine.core.common.FeatureSupported)1