Search in sources :

Example 36 with StorageDomainValidator

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

the class ImportValidator method validateStorageExistForUnregisteredEntity.

/**
 * Validate the storage domains' existence of the VM's disks. If a storage domain will fail to be active or does not
 * exist in the engine, the engine should fail the validation, unless the allowPartial flag is true. Once the
 * allowPartial flag is true the operation should not fail and the disk will be removed from the VM's disk list and
 * also from the imageToDestinationDomainMap, so the operation will pass the execute phase and import the VM
 * partially without the invalid disks.
 *
 * @param images
 *            - The images list to validate their storage domains. This list might be filtered if the allowPartial
 *            flag is true
 * @param allowPartial
 *            - Flag which determine if the VM can be imported partially.
 * @param imageToDestinationDomainMap
 *            - Map from src storage to dst storage which might be filtered if the allowPartial flag is true.
 * @return - The validation result.
 */
public ValidationResult validateStorageExistForUnregisteredEntity(List<DiskImage> images, boolean allowPartial, Map<Guid, Guid> imageToDestinationDomainMap, Map<Guid, String> failedDisksToImport) {
    for (DiskImage image : new ArrayList<>(images)) {
        StorageDomain sd = getStorageDomainDao().getForStoragePool(image.getStorageIds().get(0), params.getStoragePoolId());
        ValidationResult result = new StorageDomainValidator(sd).isDomainExistAndActive();
        if (!result.isValid()) {
            log.error("Storage Domain '{}' with id '{}', could not be found for disk alias '{}' with image id '{}'", sd == null ? null : sd.getStorageName(), image.getStorageIds().get(0), image.getDiskAlias(), image.getId());
            if (!allowPartial) {
                return result;
            }
            failedDisksToImport.putIfAbsent(image.getId(), image.getDiskAlias());
            imageToDestinationDomainMap.remove(image.getId());
            images.remove(image);
        }
    }
    return ValidationResult.VALID;
}
Also used : StorageDomain(org.ovirt.engine.core.common.businessentities.StorageDomain) StorageDomainValidator(org.ovirt.engine.core.bll.validator.storage.StorageDomainValidator) ArrayList(java.util.ArrayList) ValidationResult(org.ovirt.engine.core.bll.ValidationResult) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage)

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