Search in sources :

Example 11 with StoragePoolIsoMapId

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

the class ExportVmCommand method validate.

@Override
protected boolean validate() {
    if (getVm() == null) {
        return failValidation(EngineMessage.ACTION_TYPE_FAILED_VM_NOT_FOUND);
    }
    setDescription(getVmName());
    setStoragePoolId(getVm().getStoragePoolId());
    // check that target domain exists
    StorageDomainValidator targetstorageDomainValidator = new StorageDomainValidator(getStorageDomain());
    if (!validate(targetstorageDomainValidator.isDomainExistAndActive())) {
        return false;
    }
    // load the disks of vm from database
    vmHandler.updateDisksFromDb(getVm());
    List<DiskImage> disksForExport = getDisksBasedOnImage();
    DiskImagesValidator diskImagesValidator = new DiskImagesValidator(disksForExport);
    if (!validate(diskImagesValidator.diskImagesNotIllegal()) || !validate(diskImagesValidator.diskImagesNotLocked())) {
        return false;
    }
    // update vm snapshots for storage free space check
    imagesHandler.fillImagesBySnapshots(getVm());
    // check that the target and source domain are in the same storage_pool
    if (storagePoolIsoMapDao.get(new StoragePoolIsoMapId(getStorageDomain().getId(), getVm().getStoragePoolId())) == null) {
        return failValidation(EngineMessage.ACTION_TYPE_FAILED_STORAGE_POOL_NOT_MATCH);
    }
    // check if template exists only if asked for
    if (getParameters().getTemplateMustExists()) {
        if (!checkTemplateInStorageDomain(getVm().getStoragePoolId(), getParameters().getStorageDomainId(), getVm().getVmtGuid(), getContext().getEngineContext())) {
            return failValidation(EngineMessage.ACTION_TYPE_FAILED_TEMPLATE_NOT_FOUND_ON_EXPORT_DOMAIN, String.format("$TemplateName %1$s", getVm().getVmtName()));
        }
    }
    Map<Guid, ? extends Disk> images = getVm().getDiskMap();
    if (getParameters().getCopyCollapse()) {
        for (DiskImage img : disksForExport) {
            if (images.containsKey(img.getId())) {
                // check that no RAW format exists (we are in collapse mode)
                if (((DiskImage) images.get(img.getId())).getVolumeFormat() == VolumeFormat.RAW && img.getVolumeFormat() != VolumeFormat.RAW) {
                    return failValidation(EngineMessage.VM_CANNOT_EXPORT_RAW_FORMAT);
                }
            }
        }
    }
    // check destination storage is Export domain
    if (getStorageDomain().getStorageDomainType() != StorageDomainType.ImportExport) {
        return failValidation(EngineMessage.ACTION_TYPE_FAILED_SPECIFY_DOMAIN_IS_NOT_EXPORT_DOMAIN, String.format("$storageDomainName %1$s", getStorageDomainName()));
    }
    // get the snapshots that are going to be exported and have memory
    snapshotsWithMemory = getSnapshotsToBeExportedWithMemory();
    // check destination storage have free space
    if (!handleDestStorageDomain(disksForExport)) {
        return false;
    }
    if (!(checkVmInStorageDomain() && validate(new StoragePoolValidator(getStoragePool()).existsAndUp()) && validate(snapshotsValidator.vmNotDuringSnapshot(getVmId())) && validate(snapshotsValidator.vmNotInPreview(getVmId())) && validate(new VmValidator(getVm()).vmDown()) && validate(new MultipleStorageDomainsValidator(getVm().getStoragePoolId(), ImagesHandler.getAllStorageIdsForImageIds(disksForExport)).allDomainsExistAndActive()))) {
        return false;
    }
    return true;
}
Also used : StoragePoolValidator(org.ovirt.engine.core.bll.validator.storage.StoragePoolValidator) StorageDomainValidator(org.ovirt.engine.core.bll.validator.storage.StorageDomainValidator) StoragePoolIsoMapId(org.ovirt.engine.core.common.businessentities.StoragePoolIsoMapId) Guid(org.ovirt.engine.core.compat.Guid) MultipleStorageDomainsValidator(org.ovirt.engine.core.bll.validator.storage.MultipleStorageDomainsValidator) DiskImagesValidator(org.ovirt.engine.core.bll.validator.storage.DiskImagesValidator) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) VmValidator(org.ovirt.engine.core.bll.validator.VmValidator)

Example 12 with StoragePoolIsoMapId

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

the class ExportVmTemplateCommand method validate.

@Override
protected boolean validate() {
    if (getVmTemplate() == null) {
        return failValidation(EngineMessage.ACTION_TYPE_FAILED_TEMPLATE_DOES_NOT_EXIST);
    }
    StorageDomainValidator storageDomainValidator = new StorageDomainValidator(getStorageDomain());
    if (!validate(storageDomainValidator.isDomainExistAndActive())) {
        return false;
    }
    // export must be to export domain
    if (getStorageDomain().getStorageDomainType() != StorageDomainType.ImportExport) {
        return failValidation(EngineMessage.ACTION_TYPE_FAILED_SPECIFY_DOMAIN_IS_NOT_EXPORT_DOMAIN);
    }
    if (getTemplateDisks() != null && !getTemplateDisks().isEmpty()) {
        ensureDomainMap(getTemplateDisks(), getParameters().getStorageDomainId());
        // check that images are ok
        imagesHandler.fillImagesMapBasedOnTemplate(getVmTemplate(), imageFromSourceDomainMap, null);
        if (getVmTemplate().getDiskTemplateMap().values().size() != imageFromSourceDomainMap.size()) {
            log.error("Can not found any default active domain for one of the disks of template with id '{}'", getVmTemplate().getId());
            return failValidation(EngineMessage.ACTION_TYPE_FAILED_MISSED_STORAGES_FOR_SOME_DISKS);
        }
        if (validate(vmTemplateHandler.isVmTemplateImagesReady(getVmTemplate(), null, true, true, true, false, getTemplateDisks()))) {
            setStoragePoolId(getVmTemplate().getStoragePoolId());
            StorageDomainValidator sdValidator = createStorageDomainValidator(getStorageDomain());
            if (!validate(sdValidator.isDomainExistAndActive()) || !validate(sdValidator.isDomainWithinThresholds()) || !(getParameters().getForceOverride() || (!getParameters().isImagesExistOnTargetStorageDomain() && checkIfDisksExist(getTemplateDisks()))) || !validateFreeSpaceOnDestinationDomain(sdValidator, getTemplateDisks())) {
                return false;
            }
        }
        if (storagePoolIsoMapDao.get(new StoragePoolIsoMapId(getStorageDomain().getId(), getVmTemplate().getStoragePoolId())) == null) {
            return failValidation(EngineMessage.ACTION_TYPE_FAILED_STORAGE_POOL_NOT_MATCH);
        }
    }
    // check if template (with no override option)
    if (!getParameters().getForceOverride()) {
        if (ExportVmCommand.checkTemplateInStorageDomain(getVmTemplate().getStoragePoolId(), getParameters().getStorageDomainId(), getVmTemplateId(), getContext().getEngineContext())) {
            return failValidation(EngineMessage.ACTION_TYPE_FAILED_NAME_ALREADY_USED);
        }
    }
    return true;
}
Also used : StorageDomainValidator(org.ovirt.engine.core.bll.validator.storage.StorageDomainValidator) StoragePoolIsoMapId(org.ovirt.engine.core.common.businessentities.StoragePoolIsoMapId)

Example 13 with StoragePoolIsoMapId

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

the class AttachDiskToVmCommand method validate.

@Override
protected boolean validate() {
    if (disk == null) {
        return failValidation(EngineMessage.ACTION_TYPE_FAILED_VM_IMAGE_DOES_NOT_EXIST);
    }
    DiskValidator oldDiskValidator = new DiskValidator(disk);
    ValidationResult isHostedEngineDisk = oldDiskValidator.validateNotHostedEngineDisk();
    if (!isHostedEngineDisk.isValid()) {
        return validate(isHostedEngineDisk);
    }
    if (!checkOperationAllowedOnDiskContentType(disk)) {
        return false;
    }
    if (isOperationPerformedOnDiskSnapshot() && (!validate(snapshotsValidator.snapshotExists(getSnapshot())) || !validate(snapshotsValidator.isRegularSnapshot(getSnapshot())))) {
        return false;
    }
    boolean isImageDisk = disk.getDiskStorageType().isInternal();
    if (isImageDisk) {
        // TODO : this load and check of the active disk will be removed
        // after inspecting upgrade
        Disk activeDisk = diskHandler.loadActiveDisk(disk.getId());
        if (((DiskImage) activeDisk).getImageStatus() == ImageStatus.ILLEGAL) {
            return failValidation(EngineMessage.ACTION_TYPE_FAILED_ILLEGAL_DISK_OPERATION);
        }
        if (((DiskImage) disk).getImageStatus() == ImageStatus.LOCKED) {
            addValidationMessage(EngineMessage.ACTION_TYPE_FAILED_DISKS_LOCKED);
            addValidationMessageVariable("diskAliases", disk.getDiskAlias());
            return false;
        }
    }
    if (!validate(new VmValidator(getVm()).isVmExists()) || !isVmInUpPausedDownStatus()) {
        return false;
    }
    if (!validateDiskVmData()) {
        return false;
    }
    if (!canRunActionOnNonManagedVm()) {
        return false;
    }
    updateDisksFromDb();
    if (getDiskVmElement().isBoot() && !validate(getDiskValidator(disk).isVmNotContainsBootDisk(getVm()))) {
        return false;
    }
    if (!isDiskPassPciAndIdeLimit()) {
        return false;
    }
    if (vmDeviceDao.exists(new VmDeviceId(disk.getId(), getVmId()))) {
        return failValidation(EngineMessage.ACTION_TYPE_FAILED_DISK_ALREADY_ATTACHED);
    }
    if (!isOperationPerformedOnDiskSnapshot() && !disk.isShareable() && disk.getNumberOfVms() > 0) {
        return failValidation(EngineMessage.ACTION_TYPE_FAILED_NOT_SHAREABLE_DISK_ALREADY_ATTACHED);
    }
    if (isImageDisk && storagePoolIsoMapDao.get(new StoragePoolIsoMapId(((DiskImage) disk).getStorageIds().get(0), getVm().getStoragePoolId())) == null) {
        return failValidation(EngineMessage.ACTION_TYPE_FAILED_STORAGE_POOL_NOT_MATCH);
    }
    if (isImageDisk) {
        StorageDomain storageDomain = storageDomainDao.getForStoragePool(((DiskImage) disk).getStorageIds().get(0), ((DiskImage) disk).getStoragePoolId());
        StorageDomainValidator storageDomainValidator = getStorageDomainValidator(storageDomain);
        if (!validate(storageDomainValidator.isDomainExistAndActive())) {
            return false;
        }
    }
    DiskVmElementValidator diskVmElementValidator = getDiskVmElementValidator(disk, getDiskVmElement());
    if (!validate(diskVmElementValidator.isReadOnlyPropertyCompatibleWithInterface())) {
        return false;
    }
    if (!validate(diskVmElementValidator.isVirtIoScsiValid(getVm()))) {
        return false;
    }
    if (!validate(diskVmElementValidator.isDiskInterfaceSupported(getVm()))) {
        return false;
    }
    Guid storageDomainId = disk.getDiskStorageType() == DiskStorageType.IMAGE ? ((DiskImage) disk).getStorageIds().get(0) : null;
    if (!validate(diskVmElementValidator.isPassDiscardSupported(storageDomainId))) {
        return false;
    }
    if (!isVmNotInPreviewSnapshot()) {
        return false;
    }
    if (getParameters().isPlugUnPlug() && getVm().getStatus() != VMStatus.Down) {
        return isDiskSupportedForPlugUnPlug(getDiskVmElement(), disk.getDiskAlias());
    }
    return true;
}
Also used : DiskValidator(org.ovirt.engine.core.bll.validator.storage.DiskValidator) StorageDomain(org.ovirt.engine.core.common.businessentities.StorageDomain) StorageDomainValidator(org.ovirt.engine.core.bll.validator.storage.StorageDomainValidator) DiskVmElementValidator(org.ovirt.engine.core.bll.validator.storage.DiskVmElementValidator) StoragePoolIsoMapId(org.ovirt.engine.core.common.businessentities.StoragePoolIsoMapId) Guid(org.ovirt.engine.core.compat.Guid) ValidationResult(org.ovirt.engine.core.bll.ValidationResult) Disk(org.ovirt.engine.core.common.businessentities.storage.Disk) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) VmValidator(org.ovirt.engine.core.bll.validator.VmValidator) VmDeviceId(org.ovirt.engine.core.common.businessentities.VmDeviceId)

Example 14 with StoragePoolIsoMapId

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

the class CINDERStorageHelper method updateCinderDomainStatus.

private void updateCinderDomainStatus(final Guid storageDomainId, final Guid storagePoolId, final StorageDomainStatus storageDomainStatus) {
    StoragePoolIsoMap map = storagePoolIsoMapDao.get(new StoragePoolIsoMapId(storageDomainId, storagePoolId));
    map.setStatus(storageDomainStatus);
    storagePoolIsoMapDao.updateStatus(map.getId(), map.getStatus());
}
Also used : StoragePoolIsoMap(org.ovirt.engine.core.common.businessentities.StoragePoolIsoMap) StoragePoolIsoMapId(org.ovirt.engine.core.common.businessentities.StoragePoolIsoMapId)

Example 15 with StoragePoolIsoMapId

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

the class IrsProxy method handleMonitoredDomainsForHost.

/**
 * Provides handling for the domains that are monitored by the given host.
 * @return map between the domain id and the reason for domains that
 * the host reporting is problematic for.
 */
private Map<Guid, DomainMonitoringResult> handleMonitoredDomainsForHost(final Guid vdsId, final String vdsName, final ArrayList<VDSDomainsData> data, Collection<Guid> monitoredDomains) {
    Map<Guid, DomainMonitoringResult> domainsProblematicReportInfo = new HashMap<>();
    // build a list of all domains in pool
    // which are in status Active or Unknown
    Set<Guid> activeDomainsInPool = new HashSet<>(storageDomainStaticDao.getAllIds(storagePoolId, StorageDomainStatus.Active));
    Set<Guid> unknownDomainsInPool = new HashSet<>(storageDomainStaticDao.getAllIds(storagePoolId, StorageDomainStatus.Unknown));
    Set<Guid> inActiveDomainsInPool = new HashSet<>(storageDomainStaticDao.getAllIds(storagePoolId, StorageDomainStatus.Inactive));
    // visible by the host.
    for (Guid tempDomainId : activeDomainsInPool) {
        if (!monitoredDomains.contains(tempDomainId)) {
            domainsProblematicReportInfo.put(tempDomainId, DomainMonitoringResult.NOT_REPORTED);
        }
    }
    for (Guid tempDomainId : unknownDomainsInPool) {
        if (!monitoredDomains.contains(tempDomainId)) {
            domainsProblematicReportInfo.put(tempDomainId, DomainMonitoringResult.NOT_REPORTED);
        }
    }
    Collection<Guid> storageDomainsToSync = new LinkedList<>();
    // Unknown domains in pool
    for (VDSDomainsData tempData : data) {
        StorageDomainStatic storageDomain = storageDomainStaticDao.get(tempData.getDomainId());
        if (activeDomainsInPool.contains(tempData.getDomainId()) || unknownDomainsInPool.contains(tempData.getDomainId())) {
            DomainMonitoringResult domainMonitoringResult = analyzeDomainReport(tempData, false);
            if (domainMonitoringResult.invalidAndActual()) {
                domainsProblematicReportInfo.put(tempData.getDomainId(), domainMonitoringResult);
            } else if (domainMonitoringResult.actual() && tempData.getDelay() > Config.<Double>getValue(ConfigValues.MaxStorageVdsDelayCheckSec)) {
                logDelayedDomain(vdsName, storageDomain.getName(), tempData.getDelay());
            }
        } else if (inActiveDomainsInPool.contains(tempData.getDomainId()) && analyzeDomainReport(tempData, false).validAndActual()) {
            log.warn("Storage Domain '{}' was reported by Host '{}' as Active in Pool '{}', moving to active status", getDomainIdTuple(tempData.getDomainId()), vdsName, storagePoolId);
            StoragePoolIsoMap map = storagePoolIsoMapDao.get(new StoragePoolIsoMapId(tempData.getDomainId(), storagePoolId));
            map.setStatus(StorageDomainStatus.Active);
            storagePoolIsoMapDao.update(map);
            if (storageDomain.getStorageType().isBlockDomain()) {
                storageDomainsToSync.add(storageDomain.getId());
            }
        }
    }
    // For block domains, synchronize LUN details comprising the storage domain with the DB
    if (!storageDomainsToSync.isEmpty()) {
        getEventListener().syncStorageDomainsLuns(vdsId, storageDomainsToSync);
    }
    return domainsProblematicReportInfo;
}
Also used : StorageDomainStatic(org.ovirt.engine.core.common.businessentities.StorageDomainStatic) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) StoragePoolIsoMap(org.ovirt.engine.core.common.businessentities.StoragePoolIsoMap) VDSDomainsData(org.ovirt.engine.core.common.businessentities.VDSDomainsData) StoragePoolIsoMapId(org.ovirt.engine.core.common.businessentities.StoragePoolIsoMapId) Guid(org.ovirt.engine.core.compat.Guid) LinkedList(java.util.LinkedList) HashSet(java.util.HashSet)

Aggregations

StoragePoolIsoMapId (org.ovirt.engine.core.common.businessentities.StoragePoolIsoMapId)16 Guid (org.ovirt.engine.core.compat.Guid)12 StoragePoolIsoMap (org.ovirt.engine.core.common.businessentities.StoragePoolIsoMap)10 StorageDomain (org.ovirt.engine.core.common.businessentities.StorageDomain)5 StorageDomainStatic (org.ovirt.engine.core.common.businessentities.StorageDomainStatic)4 DiskImage (org.ovirt.engine.core.common.businessentities.storage.DiskImage)4 Pair (org.ovirt.engine.core.common.utils.Pair)4 StorageDomainValidator (org.ovirt.engine.core.bll.validator.storage.StorageDomainValidator)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 LinkedList (java.util.LinkedList)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 StorageDomainType (org.ovirt.engine.core.common.businessentities.StorageDomainType)2 VDS (org.ovirt.engine.core.common.businessentities.VDS)2 Event (org.ovirt.engine.core.common.eventqueue.Event)2 DisconnectStoragePoolVDSCommandParameters (org.ovirt.engine.core.common.vdscommands.DisconnectStoragePoolVDSCommandParameters)2 VDSReturnValue (org.ovirt.engine.core.common.vdscommands.VDSReturnValue)2 MessageFormat (java.text.MessageFormat)1 Arrays (java.util.Arrays)1