Search in sources :

Example 1 with ImportValidator

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

the class ImportVmTemplateFromConfigurationCommand method validateUnregisteredEntity.

private boolean validateUnregisteredEntity(VmTemplate entityFromConfiguration, OvfEntityData ovfEntityData) {
    if (ovfEntityData == null && !getParameters().isImportAsNewEntity()) {
        return failValidation(EngineMessage.ACTION_TYPE_FAILED_UNSUPPORTED_OVF);
    }
    if (entityFromConfiguration == null) {
        return failValidation(EngineMessage.ACTION_TYPE_FAILED_OVF_CONFIGURATION_NOT_SUPPORTED);
    }
    ImportValidator importValidator = new ImportValidator(getParameters());
    if (!validate(importValidator.validateDiskNotAlreadyExistOnDB(getImages(), getParameters().isAllowPartialImport(), imageToDestinationDomainMap, failedDisksToImportForAuditLog))) {
        return false;
    }
    for (DiskImage image : new ArrayList<>(getImages())) {
        DiskImage fromIrs = null;
        Guid storageDomainId = image.getStorageIds().get(0);
        Guid imageGroupId = image.getId() != null ? image.getId() : Guid.Empty;
        try {
            fromIrs = (DiskImage) runVdsCommand(VDSCommandType.GetImageInfo, new GetImageInfoVDSCommandParameters(getStoragePool().getId(), storageDomainId, imageGroupId, image.getImageId())).getReturnValue();
        } catch (Exception e) {
            log.debug("Unable to get image info from storage", e);
        }
        if (fromIrs == null) {
            if (!getParameters().isAllowPartialImport()) {
                return failValidation(EngineMessage.TEMPLATE_IMAGE_NOT_EXIST);
            }
            log.warn("Disk image '{}/{}' doesn't exist on storage domain '{}'. Ignoring since force flag in on", imageGroupId, image.getImageId(), storageDomainId);
            getImages().remove(image);
            failedDisksToImportForAuditLog.putIfAbsent(image.getId(), image.getDiskAlias());
        }
    }
    for (DiskImage image : getImages()) {
        StorageDomain sd = storageDomainDao.getForStoragePool(image.getStorageIds().get(0), getStoragePool().getId());
        ValidationResult result = new StorageDomainValidator(sd).isDomainExistAndActive();
        if (!result.isValid()) {
            if (!getParameters().isAllowPartialImport()) {
                return validate(result);
            } else {
                log.warn("storage domain '{}' does not exists. Ignoring since force flag in on", image.getStorageIds().get(0));
                getImages().remove(image);
                failedDisksToImportForAuditLog.putIfAbsent(image.getId(), image.getDiskAlias());
            }
        }
    }
    if (!getStorageDomain().getStorageDomainType().isDataDomain()) {
        return failValidation(EngineMessage.ACTION_TYPE_FAILED_STORAGE_DOMAIN_TYPE_UNSUPPORTED, String.format("$domainId %1$s", getParameters().getStorageDomainId()), String.format("$domainType %1$s", getStorageDomain().getStorageDomainType()));
    }
    return true;
}
Also used : StorageDomain(org.ovirt.engine.core.common.businessentities.StorageDomain) GetImageInfoVDSCommandParameters(org.ovirt.engine.core.common.vdscommands.GetImageInfoVDSCommandParameters) StorageDomainValidator(org.ovirt.engine.core.bll.validator.storage.StorageDomainValidator) ArrayList(java.util.ArrayList) ImportValidator(org.ovirt.engine.core.bll.validator.ImportValidator) Guid(org.ovirt.engine.core.compat.Guid) ValidationResult(org.ovirt.engine.core.bll.ValidationResult) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) OvfReaderException(org.ovirt.engine.core.utils.ovf.OvfReaderException)

Example 2 with ImportValidator

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

the class ImportVmCommandTest method setupDiskSpaceTest.

private void setupDiskSpaceTest() {
    final ImportValidator validator = spy(new ImportValidator(cmd.getParameters()));
    doReturn(validator).when(cmd).getImportValidator();
    cmd.init();
    cmd.getParameters().setCopyCollapse(true);
    doReturn(true).when(cmd).validateNoDuplicateVm();
    doReturn(true).when(cmd).validateVdsCluster();
    doReturn(true).when(cmd).validateUniqueVmName();
    doReturn(true).when(cmd).checkTemplateInStorageDomain();
    doReturn(true).when(cmd).checkImagesGUIDsLegal();
    doReturn(true).when(cmd).setAndValidateDiskProfiles();
    doReturn(true).when(cmd).setAndValidateCpuProfile();
    doReturn(true).when(cmd).validateNoDuplicateDiskImages(any());
    doReturn(createSourceDomain()).when(cmd).getSourceDomain();
    doReturn(createStorageDomain()).when(cmd).getStorageDomain(any());
    doReturn(cmd.getParameters().getVm()).when(cmd).getVmFromExportDomain(any());
    doReturn(new VmTemplate()).when(cmd).getVmTemplate();
    StoragePool sp = new StoragePool();
    sp.setStatus(StoragePoolStatus.Up);
    doReturn(sp).when(cmd).getStoragePool();
    Cluster cluster = new Cluster();
    cluster.setStoragePoolId(cmd.getParameters().getStoragePoolId());
    cluster.setClusterId(cmd.getParameters().getClusterId());
    doReturn(cluster).when(cmd).getCluster();
    doReturn(macPool).when(cmd).getMacPool();
    when(poolPerCluster.getMacPoolForCluster(any())).thenReturn(macPool);
    ArrayList<Guid> sdIds = new ArrayList<>(Collections.singletonList(Guid.newGuid()));
    for (DiskImage image : cmd.getParameters().getVm().getImages()) {
        image.setStorageIds(sdIds);
    }
    doReturn(Collections.emptyList()).when(cmd).createDiskDummiesForSpaceValidations(any());
}
Also used : StoragePool(org.ovirt.engine.core.common.businessentities.StoragePool) VmTemplate(org.ovirt.engine.core.common.businessentities.VmTemplate) ArrayList(java.util.ArrayList) ImportValidator(org.ovirt.engine.core.bll.validator.ImportValidator) MacPoolPerCluster(org.ovirt.engine.core.bll.network.macpool.MacPoolPerCluster) Cluster(org.ovirt.engine.core.common.businessentities.Cluster) Guid(org.ovirt.engine.core.compat.Guid) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage)

Example 3 with ImportValidator

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

the class ImportVmFromConfigurationCommand method validateEntityPropertiesWhenImagesOnTarget.

private boolean validateEntityPropertiesWhenImagesOnTarget() {
    ImportValidator importValidator = getImportValidator();
    if (isImagesAlreadyOnTarget()) {
        if (!validate(importValidator.validateUnregisteredEntity(ovfEntityData))) {
            return false;
        }
        removeInvalidAffinityGroups(importValidator);
        removeInvalidAffinityLabels(importValidator);
        removeInavlidUsers(importValidator);
        removeInavlidRoles(importValidator);
        setImagesWithStoragePoolId(getParameters().getStoragePoolId(), getVm().getImages());
    }
    return true;
}
Also used : ImportValidator(org.ovirt.engine.core.bll.validator.ImportValidator)

Aggregations

ImportValidator (org.ovirt.engine.core.bll.validator.ImportValidator)3 ArrayList (java.util.ArrayList)2 DiskImage (org.ovirt.engine.core.common.businessentities.storage.DiskImage)2 Guid (org.ovirt.engine.core.compat.Guid)2 ValidationResult (org.ovirt.engine.core.bll.ValidationResult)1 MacPoolPerCluster (org.ovirt.engine.core.bll.network.macpool.MacPoolPerCluster)1 StorageDomainValidator (org.ovirt.engine.core.bll.validator.storage.StorageDomainValidator)1 Cluster (org.ovirt.engine.core.common.businessentities.Cluster)1 StorageDomain (org.ovirt.engine.core.common.businessentities.StorageDomain)1 StoragePool (org.ovirt.engine.core.common.businessentities.StoragePool)1 VmTemplate (org.ovirt.engine.core.common.businessentities.VmTemplate)1 GetImageInfoVDSCommandParameters (org.ovirt.engine.core.common.vdscommands.GetImageInfoVDSCommandParameters)1 OvfReaderException (org.ovirt.engine.core.utils.ovf.OvfReaderException)1