Search in sources :

Example 11 with StorageDomain

use of org.ovirt.engine.core.common.businessentities.StorageDomain in project ovirt-engine by oVirt.

the class ImportVmTemplateCommand method validate.

@Override
protected boolean validate() {
    if (getVmTemplate() == null) {
        return failValidation(EngineMessage.ACTION_TYPE_FAILED_VM_NOT_FOUND);
    }
    if (getCluster() == null) {
        return failValidation(EngineMessage.ACTION_TYPE_FAILED_CLUSTER_CAN_NOT_BE_EMPTY);
    }
    if (!getCluster().getStoragePoolId().equals(getStoragePoolId())) {
        return failValidation(EngineMessage.ACTION_TYPE_FAILED_CLUSTER_IS_NOT_VALID);
    }
    setDescription(getVmTemplateName());
    // check that the storage pool is valid
    if (!validate(createStoragePoolValidator().existsAndUp()) || !validateTemplateArchitecture() || !isClusterCompatible()) {
        return false;
    }
    // set the source domain and check that it is ImportExport type and active
    setSourceDomainId(getParameters().getSourceDomainId());
    StorageDomainValidator sourceDomainValidator = new StorageDomainValidator(getSourceDomain());
    if (!validate(sourceDomainValidator.isDomainExistAndActive())) {
        return false;
    }
    if ((getSourceDomain().getStorageDomainType() != StorageDomainType.ImportExport) && !getParameters().isImagesExistOnTargetStorageDomain()) {
        return failValidation(EngineMessage.ACTION_TYPE_FAILED_STORAGE_DOMAIN_TYPE_ILLEGAL);
    }
    if (!getParameters().isImagesExistOnTargetStorageDomain()) {
        // Set the template images from the Export domain and change each image id storage is to the import domain
        GetAllFromExportDomainQueryParameters tempVar = new GetAllFromExportDomainQueryParameters(getParameters().getStoragePoolId(), getParameters().getSourceDomainId());
        QueryReturnValue qretVal = runInternalQuery(QueryType.GetTemplatesFromExportDomain, tempVar);
        if (!qretVal.getSucceeded()) {
            return false;
        }
        Map<VmTemplate, List<DiskImage>> templates = qretVal.getReturnValue();
        ArrayList<DiskImage> images = new ArrayList<>();
        for (Map.Entry<VmTemplate, List<DiskImage>> entry : templates.entrySet()) {
            if (entry.getKey().getId().equals(getVmTemplate().getId())) {
                images = new ArrayList<>(entry.getValue());
                getVmTemplate().setInterfaces(entry.getKey().getInterfaces());
                getVmTemplate().setOvfVersion(entry.getKey().getOvfVersion());
                break;
            }
        }
        getParameters().setImages(images);
        getVmTemplate().setImages(images);
        ensureDomainMap(getImages(), getParameters().getDestDomainId());
        HashMap<Guid, DiskImage> imageMap = new HashMap<>();
        for (DiskImage image : images) {
            if (Guid.Empty.equals(image.getVmSnapshotId())) {
                return failValidation(EngineMessage.ACTION_TYPE_FAILED_CORRUPTED_VM_SNAPSHOT_ID);
            }
            StorageDomain storageDomain = getStorageDomain(imageToDestinationDomainMap.get(image.getId()));
            StorageDomainValidator validator = new StorageDomainValidator(storageDomain);
            if (!validate(validator.isDomainExistAndActive()) || !validate(validator.domainIsValidDestination())) {
                return false;
            }
            StorageDomainStatic targetDomain = storageDomain.getStorageStaticData();
            changeRawToCowIfSparseOnBlockDevice(targetDomain.getStorageType(), image);
            if (!ImagesHandler.checkImageConfiguration(targetDomain, image, getReturnValue().getValidationMessages())) {
                return false;
            }
            image.setStoragePoolId(getParameters().getStoragePoolId());
            image.setStorageIds(new ArrayList<>(Collections.singletonList(storageDomain.getId())));
            imageMap.put(image.getImageId(), image);
        }
        getVmTemplate().setDiskImageMap(imageMap);
    }
    sourceTemplateId = getVmTemplateId();
    if (getParameters().isImportAsNewEntity()) {
        initImportClonedTemplate();
    }
    VmTemplate duplicateTemplate = vmTemplateDao.get(getParameters().getVmTemplate().getId());
    // check that the template does not exists in the target domain
    if (duplicateTemplate != null) {
        return failValidation(EngineMessage.VMT_CANNOT_IMPORT_TEMPLATE_EXISTS, String.format("$TemplateName %1$s", duplicateTemplate.getName()));
    }
    if (getVmTemplate().isBaseTemplate() && isVmTemplateWithSameNameExist()) {
        return failValidation(EngineMessage.VM_CANNOT_IMPORT_TEMPLATE_NAME_EXISTS);
    }
    if (!validateNoDuplicateDiskImages(getImages())) {
        return false;
    }
    if (getImages() != null && !getImages().isEmpty() && !getParameters().isImagesExistOnTargetStorageDomain()) {
        if (!validateSpaceRequirements(getImages())) {
            return false;
        }
    }
    List<VmNetworkInterface> vmNetworkInterfaces = getVmTemplate().getInterfaces();
    vmNicMacsUtils.replaceInvalidEmptyStringMacAddressesWithNull(vmNetworkInterfaces);
    if (!validate(vmNicMacsUtils.validateMacAddress(vmNetworkInterfaces))) {
        return false;
    }
    // if this is a template version, check base template exist
    if (!getVmTemplate().isBaseTemplate()) {
        VmTemplate baseTemplate = vmTemplateDao.get(getVmTemplate().getBaseTemplateId());
        if (baseTemplate == null) {
            return failValidation(EngineMessage.VMT_CANNOT_IMPORT_TEMPLATE_VERSION_MISSING_BASE);
        }
    }
    if (!setAndValidateDiskProfiles()) {
        return false;
    }
    if (!setAndValidateCpuProfile()) {
        return false;
    }
    if (!validate(vmHandler.validateMaxMemorySize(getVmTemplate(), getEffectiveCompatibilityVersion()))) {
        return false;
    }
    List<EngineMessage> msgs = openStackMetadataAdapter.validate(getVmTemplate().getVmInit());
    if (!CollectionUtils.isEmpty(msgs)) {
        return failValidation(msgs);
    }
    return true;
}
Also used : StorageDomainStatic(org.ovirt.engine.core.common.businessentities.StorageDomainStatic) HashMap(java.util.HashMap) StorageDomainValidator(org.ovirt.engine.core.bll.validator.storage.StorageDomainValidator) ArrayList(java.util.ArrayList) Guid(org.ovirt.engine.core.compat.Guid) EngineMessage(org.ovirt.engine.core.common.errors.EngineMessage) QueryReturnValue(org.ovirt.engine.core.common.queries.QueryReturnValue) StorageDomain(org.ovirt.engine.core.common.businessentities.StorageDomain) VmTemplate(org.ovirt.engine.core.common.businessentities.VmTemplate) VmNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface) List(java.util.List) ArrayList(java.util.ArrayList) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) Map(java.util.Map) HashMap(java.util.HashMap) ImageStorageDomainMap(org.ovirt.engine.core.common.businessentities.storage.ImageStorageDomainMap) GetAllFromExportDomainQueryParameters(org.ovirt.engine.core.common.queries.GetAllFromExportDomainQueryParameters)

Example 12 with StorageDomain

use of org.ovirt.engine.core.common.businessentities.StorageDomain 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 13 with StorageDomain

use of org.ovirt.engine.core.common.businessentities.StorageDomain in project ovirt-engine by oVirt.

the class ImportVmCommand method findDomainForMemoryImagesAndCreateDummies.

private StorageDomain findDomainForMemoryImagesAndCreateDummies(List<DiskImage> disksList) {
    List<DiskImage> memoryDisksList = MemoryUtils.createDiskDummies(vmOverheadCalculator.getSnapshotMemorySizeInBytes(getVm()), MemoryUtils.METADATA_SIZE_IN_BYTES);
    StorageDomain storageDomain = memoryStorageHandler.findStorageDomainForMemory(getParameters().getStoragePoolId(), memoryDisksList, getVmDisksDummies(), getVm());
    disksList.addAll(memoryDisksList);
    return storageDomain;
}
Also used : StorageDomain(org.ovirt.engine.core.common.businessentities.StorageDomain) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage)

Example 14 with StorageDomain

use of org.ovirt.engine.core.common.businessentities.StorageDomain in project ovirt-engine by oVirt.

the class LibvirtSecretCommandBase method getStorageDomain.

@Override
public StorageDomain getStorageDomain() {
    if (storageDomain == null) {
        Guid providerId = getParameters().getLibvirtSecret().getProviderId();
        List<StorageDomain> storageDomains = storageDomainDao.getAllByConnectionId(providerId);
        storageDomain = storageDomains.get(0);
    }
    return storageDomain;
}
Also used : StorageDomain(org.ovirt.engine.core.common.businessentities.StorageDomain) Guid(org.ovirt.engine.core.compat.Guid)

Example 15 with StorageDomain

use of org.ovirt.engine.core.common.businessentities.StorageDomain in project ovirt-engine by oVirt.

the class AbstractOpenStackStorageProviderProxy method onRemoval.

@Override
public void onRemoval() {
    List<StorageDomain> storageDomains = getDbFacade().getStorageDomainDao().getAllByConnectionId(provider.getId());
    // removing the static and dynamic storage domain entries
    StorageDomain storageDomainEntry = storageDomains.get(0);
    getDbFacade().getStorageDomainDynamicDao().remove(storageDomainEntry.getId());
    getDbFacade().getStorageDomainStaticDao().remove(storageDomainEntry.getId());
}
Also used : StorageDomain(org.ovirt.engine.core.common.businessentities.StorageDomain)

Aggregations

StorageDomain (org.ovirt.engine.core.common.businessentities.StorageDomain)345 ArrayList (java.util.ArrayList)108 Guid (org.ovirt.engine.core.compat.Guid)103 Test (org.junit.Test)91 StoragePool (org.ovirt.engine.core.common.businessentities.StoragePool)75 List (java.util.List)58 DiskImage (org.ovirt.engine.core.common.businessentities.storage.DiskImage)58 StorageDomainStatic (org.ovirt.engine.core.common.businessentities.StorageDomainStatic)49 UICommand (org.ovirt.engine.ui.uicommonweb.UICommand)47 QueryReturnValue (org.ovirt.engine.core.common.queries.QueryReturnValue)46 QueryType (org.ovirt.engine.core.common.queries.QueryType)43 StorageServerConnections (org.ovirt.engine.core.common.businessentities.StorageServerConnections)42 AsyncDataProvider (org.ovirt.engine.ui.uicommonweb.dataprovider.AsyncDataProvider)41 ConstantsManager (org.ovirt.engine.ui.uicompat.ConstantsManager)41 ConfirmationModel (org.ovirt.engine.ui.uicommonweb.models.ConfirmationModel)40 VDS (org.ovirt.engine.core.common.businessentities.VDS)39 Frontend (org.ovirt.engine.ui.frontend.Frontend)39 HelpTag (org.ovirt.engine.ui.uicommonweb.help.HelpTag)36 EntityModel (org.ovirt.engine.ui.uicommonweb.models.EntityModel)36 StorageType (org.ovirt.engine.core.common.businessentities.storage.StorageType)35