Search in sources :

Example 41 with ValidationResult

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

the class NetworkPolicyUnit method filter.

@Override
public List<VDS> filter(Cluster cluster, List<VDS> hosts, VM vm, Map<String, String> parameters, PerHostMessages messages) {
    if (hosts == null || hosts.isEmpty()) {
        return Collections.emptyList();
    }
    List<VDS> toRemoveHostList = new ArrayList<>();
    List<VmNetworkInterface> vmNICs = vmNetworkInterfaceDao.getAllForVm(vm.getId());
    Guid clusterId = hosts.get(0).getClusterId();
    List<Network> clusterNetworks = networkDao.getAllForCluster(clusterId);
    Map<String, Network> networksByName = Entities.entitiesByName(clusterNetworks);
    Map<Guid, List<String>> hostNics = interfaceDao.getHostNetworksByCluster(clusterId);
    Network displayNetwork = NetworkUtils.getDisplayNetwork(clusterNetworks);
    Map<Guid, VdsNetworkInterface> hostDisplayNics = getDisplayNics(displayNetwork);
    for (VDS host : hosts) {
        ValidationResult result = validateRequiredNetworksAvailable(host, vm, vmNICs, displayNetwork, networksByName, hostNics.get(host.getId()), hostDisplayNics.get(host.getId()));
        if (result.isValid()) {
            result = validatePassthroughVnics(vm.getId(), host, vmNICs);
        }
        if (!result.isValid()) {
            toRemoveHostList.add(host);
            messages.addMessages(host.getId(), result.getVariableReplacements());
            messages.addMessages(host.getId(), result.getMessagesAsStrings());
        }
    }
    hosts.removeAll(toRemoveHostList);
    return hosts;
}
Also used : VDS(org.ovirt.engine.core.common.businessentities.VDS) ArrayList(java.util.ArrayList) Guid(org.ovirt.engine.core.compat.Guid) ValidationResult(org.ovirt.engine.core.bll.ValidationResult) VmNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface) Network(org.ovirt.engine.core.common.businessentities.network.Network) VdsNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface) ArrayList(java.util.ArrayList) List(java.util.List)

Example 42 with ValidationResult

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

the class DiskValidator method isSparsifySupported.

public ValidationResult isSparsifySupported() {
    if (disk.getDiskStorageType() != DiskStorageType.IMAGE) {
        return new ValidationResult(EngineMessage.ACTION_TYPE_FAILED_DISK_SPARSIFY_NOT_SUPPORTED_BY_DISK_STORAGE_TYPE, getDiskAliasVarReplacement(), ReplacementUtils.createSetVariableString("diskStorageType", disk.getDiskStorageType()));
    }
    if (((DiskImage) disk).getImage().getVolumeType() == VolumeType.Preallocated) {
        return new ValidationResult(EngineMessage.ACTION_TYPE_FAILED_DISK_SPARSIFY_NOT_SUPPORTED_FOR_PREALLOCATED, getDiskAliasVarReplacement());
    }
    StorageDomain diskStorageDomain = Injector.get(StorageDomainDao.class).get(((DiskImage) disk).getStorageIds().get(0));
    StorageType domainStorageType = diskStorageDomain.getStorageType();
    if (!domainStorageType.isFileDomain() && !domainStorageType.isBlockDomain()) {
        return new ValidationResult(EngineMessage.ACTION_TYPE_FAILED_DISK_SPARSIFY_NOT_SUPPORTED_BY_STORAGE_TYPE, getDiskAliasVarReplacement(), getStorageDomainNameVarReplacement(diskStorageDomain), ReplacementUtils.createSetVariableString("storageType", domainStorageType));
    }
    if (domainStorageType.isBlockDomain() && disk.isWipeAfterDelete()) {
        return new ValidationResult(EngineMessage.ACTION_TYPE_FAILED_DISK_SPARSIFY_NOT_SUPPORTED_BY_UNDERLYING_STORAGE_WHEN_WAD_IS_ENABLED, getStorageDomainNameVarReplacement(diskStorageDomain), getDiskAliasVarReplacement());
    }
    return ValidationResult.VALID;
}
Also used : StorageDomain(org.ovirt.engine.core.common.businessentities.StorageDomain) StorageType(org.ovirt.engine.core.common.businessentities.storage.StorageType) DiskStorageType(org.ovirt.engine.core.common.businessentities.storage.DiskStorageType) ValidationResult(org.ovirt.engine.core.bll.ValidationResult) StorageDomainDao(org.ovirt.engine.core.dao.StorageDomainDao) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage)

Example 43 with ValidationResult

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

the class StorageConnectionValidator method isSameStorageType.

public ValidationResult isSameStorageType(StorageDomain storageDomain) {
    StorageType connectionStorageType = connection.getStorageType();
    StorageType storageDomainType = storageDomain.getStorageType();
    if (!connectionStorageType.equals(storageDomainType)) {
        return new ValidationResult(EngineMessage.ACTION_TYPE_FAILED_STORAGE_CONNECTION_UNSUPPORTED_ACTION_NOT_SAME_STORAGE_TYPE);
    }
    return ValidationResult.VALID;
}
Also used : StorageType(org.ovirt.engine.core.common.businessentities.storage.StorageType) ValidationResult(org.ovirt.engine.core.bll.ValidationResult)

Example 44 with ValidationResult

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

the class StorageDomainToPoolRelationValidator method validateAmountOfIsoAndExportDomainsInDC.

/**
 * Check that we are not trying to attach more than one ISO or export
 * domain to the same data center.
 */
public ValidationResult validateAmountOfIsoAndExportDomainsInDC() {
    // Nothing to check if the storage domain is not an ISO or export:
    if (!isStorageDomainOfTypeIsoOrExport()) {
        return ValidationResult.VALID;
    }
    final StorageDomainType type = storageDomainStatic.getStorageDomainType();
    // Check if such a domain type is already present in the pool
    boolean hasSuchType = getStorageDomainDao().getAllForStoragePool(storagePool.getId()).stream().anyMatch(a -> a.getStorageDomainType() == type);
    // If it's the first domain of that type, we are okay, we can add a new one:
    if (!hasSuchType) {
        return ValidationResult.VALID;
    }
    // so when have to prepare a friendly message for the user (see #713160) and fail:
    if (type == StorageDomainType.ISO) {
        return new ValidationResult(EngineMessage.ERROR_CANNOT_ATTACH_MORE_THAN_ONE_ISO_DOMAIN);
    } else {
        return new ValidationResult(EngineMessage.ERROR_CANNOT_ATTACH_MORE_THAN_ONE_EXPORT_DOMAIN);
    }
}
Also used : StorageDomainType(org.ovirt.engine.core.common.businessentities.StorageDomainType) ValidationResult(org.ovirt.engine.core.bll.ValidationResult)

Example 45 with ValidationResult

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

the class StorageDomainValidator method isStorageFormatCompatibleWithDomain.

public ValidationResult isStorageFormatCompatibleWithDomain() {
    StorageFormatType storageFormat = storageDomain.getStorageFormat();
    StorageType storageType = storageDomain.getStorageType();
    StorageDomainType storageDomainFunction = storageDomain.getStorageDomainType();
    boolean validationSucceeded = true;
    if (storageFormat == null) {
        validationSucceeded = false;
    }
    // V2 is applicable only for block data storage domains
    if (validationSucceeded && storageFormat == StorageFormatType.V2) {
        if (!(storageDomainFunction.isDataDomain() && storageType.isBlockDomain())) {
            validationSucceeded = false;
        }
    }
    if (validationSucceeded && storageFormat.compareTo(StorageFormatType.V3) >= 0) {
        // Above V3 is applicable only for data storage domains
        if (!storageDomainFunction.isDataDomain()) {
            validationSucceeded = false;
        }
    }
    return validationSucceeded ? ValidationResult.VALID : new ValidationResult(EngineMessage.ACTION_TYPE_FAILED_STORAGE_DOMAIN_FORMAT_ILLEGAL_HOST, String.format("$storageFormat %1$s", storageDomain.getStorageFormat()));
}
Also used : StorageDomainType(org.ovirt.engine.core.common.businessentities.StorageDomainType) StorageType(org.ovirt.engine.core.common.businessentities.storage.StorageType) StorageFormatType(org.ovirt.engine.core.common.businessentities.StorageFormatType) ValidationResult(org.ovirt.engine.core.bll.ValidationResult)

Aggregations

ValidationResult (org.ovirt.engine.core.bll.ValidationResult)239 Test (org.junit.Test)132 BaseCommandTest (org.ovirt.engine.core.bll.BaseCommandTest)49 Guid (org.ovirt.engine.core.compat.Guid)40 ArrayList (java.util.ArrayList)31 EngineMessage (org.ovirt.engine.core.common.errors.EngineMessage)31 DiskImage (org.ovirt.engine.core.common.businessentities.storage.DiskImage)30 Network (org.ovirt.engine.core.common.businessentities.network.Network)21 NetworkAttachment (org.ovirt.engine.core.common.businessentities.network.NetworkAttachment)19 VdsNetworkInterface (org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface)16 GlusterVolumeEntity (org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeEntity)15 CreateOrUpdateBond (org.ovirt.engine.core.common.action.CreateOrUpdateBond)13 StorageDomain (org.ovirt.engine.core.common.businessentities.StorageDomain)12 List (java.util.List)11 VM (org.ovirt.engine.core.common.businessentities.VM)11 HashSet (java.util.HashSet)10 FindActiveVmsUsingNetwork (org.ovirt.engine.core.bll.network.FindActiveVmsUsingNetwork)10 GlusterBrickEntity (org.ovirt.engine.core.common.businessentities.gluster.GlusterBrickEntity)9 StorageDomainValidator (org.ovirt.engine.core.bll.validator.storage.StorageDomainValidator)7 Disk (org.ovirt.engine.core.common.businessentities.storage.Disk)7