Search in sources :

Example 1 with DiskImagesValidator

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

the class OvfHelper method generateOvfConfigurationForVm.

public String generateOvfConfigurationForVm(VM vm) {
    if (VMStatus.ImageLocked != vm.getStatus()) {
        vmHandler.updateDisksFromDb(vm);
        DiskImagesValidator validator = new DiskImagesValidator(vm.getDiskList());
        if (validator.diskImagesNotLocked().isValid()) {
            loadVmData(vm);
            Long currentDbGeneration = vmStaticDao.getDbGeneration(vm.getId());
            // currentDbGeneration can be null in case that the vm was deleted during the run of OvfDataUpdater.
            if (currentDbGeneration != null && vm.getStaticData().getDbGeneration() == currentDbGeneration) {
                return buildMetadataDictionaryForVm(vm);
            }
        }
    }
    return null;
}
Also used : DiskImagesValidator(org.ovirt.engine.core.bll.validator.storage.DiskImagesValidator)

Example 2 with DiskImagesValidator

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

the class RemoveVmCommand method validate.

@Override
protected boolean validate() {
    if (getVm() == null) {
        return failValidation(EngineMessage.ACTION_TYPE_FAILED_VM_NOT_FOUND);
    }
    if (!canRunActionOnNonManagedVm()) {
        return false;
    }
    if (getVm().isDeleteProtected()) {
        return failValidation(EngineMessage.ACTION_TYPE_FAILED_DELETE_PROTECTION_ENABLED);
    }
    vmHandler.updateDisksFromDb(getVm());
    getParameters().setUseCinderCommandCallback(getParameters().isRemoveDisks() && !getCinderDisks().isEmpty());
    if (!getParameters().isRemoveDisks() && !canRemoveVmWithDetachDisks()) {
        return false;
    }
    switch(getVm().getStatus()) {
        case Unassigned:
        case Down:
        case ImageIllegal:
        case ImageLocked:
            break;
        case Suspended:
            return failValidation(EngineMessage.VM_CANNOT_REMOVE_VM_WHEN_STATUS_IS_NOT_DOWN);
        default:
            return (getVm().isHostedEngine() && isInternalExecution()) || failValidation(EngineMessage.ACTION_TYPE_FAILED_VM_IS_RUNNING);
    }
    if (getVm().getVmPoolId() != null) {
        return failValidation(EngineMessage.ACTION_TYPE_FAILED_VM_ATTACHED_TO_POOL);
    }
    // enable to remove vms without images
    if (!validate(snapshotsValidator.vmNotDuringSnapshot(getVmId()))) {
        return false;
    }
    Collection<Disk> vmDisks = getVm().getDiskMap().values();
    List<DiskImage> vmImages = DisksFilter.filterImageDisks(vmDisks, ONLY_NOT_SHAREABLE, ONLY_ACTIVE);
    if (!vmImages.isEmpty() && !validate(new StoragePoolValidator(getStoragePool()).existsAndUp())) {
        return false;
    }
    vmImages.addAll(DisksFilter.filterCinderDisks(vmDisks));
    if (!vmImages.isEmpty()) {
        Set<Guid> storageIds = ImagesHandler.getAllStorageIdsForImageIds(vmImages);
        MultipleStorageDomainsValidator storageValidator = new MultipleStorageDomainsValidator(getVm().getStoragePoolId(), storageIds);
        if (!validate(storageValidator.allDomainsExistAndActive())) {
            return false;
        }
        DiskImagesValidator diskImagesValidator = new DiskImagesValidator(vmImages);
        if (!getParameters().getForce() && !validate(diskImagesValidator.diskImagesNotLocked())) {
            return false;
        }
    }
    // Handle VM status with ImageLocked
    VmValidator vmValidator = new VmValidator(getVm());
    ValidationResult vmLockedValidatorResult = vmValidator.vmNotLocked();
    if (!vmLockedValidatorResult.isValid()) {
        // without force remove, we can't remove the VM
        if (!getParameters().getForce()) {
            return failValidation(vmLockedValidatorResult.getMessages());
        }
        // If it is force, we cannot remove if there are task
        if (commandCoordinatorUtil.hasTasksByStoragePoolId(getVm().getStoragePoolId())) {
            return failValidation(EngineMessage.VM_CANNOT_REMOVE_HAS_RUNNING_TASKS);
        }
    }
    if (getParameters().isRemoveDisks() && !validate(vmValidator.vmNotHavingDeviceSnapshotsAttachedToOtherVms(false))) {
        return false;
    }
    return true;
}
Also used : StoragePoolValidator(org.ovirt.engine.core.bll.validator.storage.StoragePoolValidator) 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) CinderDisk(org.ovirt.engine.core.common.businessentities.storage.CinderDisk) LunDisk(org.ovirt.engine.core.common.businessentities.storage.LunDisk) 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)

Example 3 with DiskImagesValidator

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

the class CreateSnapshotForVmCommand method validate.

@Override
protected boolean validate() {
    if (getVm() == null) {
        addValidationMessage(EngineMessage.ACTION_TYPE_FAILED_VM_NOT_FOUND);
        return false;
    }
    if (!canRunActionOnNonManagedVm()) {
        return false;
    }
    Set<Guid> specifiedDiskIds = getParameters().getDiskIds();
    if (specifiedDiskIds != null && !specifiedDiskIds.isEmpty()) {
        if (!isSpecifiedDisksExist(specifiedDiskIds)) {
            return false;
        }
        List<Disk> allDisksForVm = diskDao.getAllForVm(getVm().getId());
        String notAllowSnapshot = allDisksForVm.stream().filter(disk -> specifiedDiskIds.contains(disk.getId())).filter(disk -> !disk.isAllowSnapshot()).map(BaseDisk::getDiskAlias).collect(Collectors.joining(", "));
        if (!notAllowSnapshot.isEmpty()) {
            return failValidation(EngineMessage.ACTION_TYPE_FAILED_DISK_SNAPSHOT_NOT_SUPPORTED, String.format("$diskAliases %s", notAllowSnapshot));
        }
        Set<Guid> guidsOfVmDisks = allDisksForVm.stream().map(BaseDisk::getId).collect(Collectors.toSet());
        String notAttachedToVm = specifiedDiskIds.stream().filter(guid -> !guidsOfVmDisks.contains(guid)).map(guid -> diskDao.get(guid)).map(BaseDisk::getDiskAlias).collect(Collectors.joining(", "));
        if (!notAttachedToVm.isEmpty()) {
            String[] replacements = { ReplacementUtils.createSetVariableString("VmName", getVm().getName()), ReplacementUtils.createSetVariableString("diskAliases", notAttachedToVm) };
            return failValidation(EngineMessage.ACTION_TYPE_FAILED_DISKS_NOT_ATTACHED_TO_VM, replacements);
        }
    }
    // Initialize validators.
    VmValidator vmValidator = createVmValidator();
    StoragePoolValidator spValidator = createStoragePoolValidator();
    if (!(validateVM(vmValidator) && validate(spValidator.existsAndUp()) && validate(vmValidator.vmNotIlegal()) && validate(vmValidator.vmNotLocked()) && validate(snapshotsValidator.vmNotDuringSnapshot(getVmId())) && validate(snapshotsValidator.vmNotInPreview(getVmId())) && validate(vmValidator.vmNotDuringMigration()) && validate(vmValidator.vmNotRunningStateless()) && (!getParameters().isSaveMemory() || validate(vmValidator.vmNotHavingPciPassthroughDevices())))) {
        return false;
    }
    List<DiskImage> disksList = getDisksListForChecks();
    if (disksList.size() > 0) {
        DiskImagesValidator diskImagesValidator = createDiskImageValidator(disksList);
        if (!(validate(diskImagesValidator.diskImagesNotLocked()) && validate(diskImagesValidator.diskImagesNotIllegal()) && validate(vmValidator.vmWithoutLocalDiskUserProperty()))) {
            return false;
        }
    }
    return validateStorage();
}
Also used : LockMessagesMatchUtil(org.ovirt.engine.core.bll.LockMessagesMatchUtil) DiskExistenceValidator(org.ovirt.engine.core.bll.validator.storage.DiskExistenceValidator) CinderDisk(org.ovirt.engine.core.common.businessentities.storage.CinderDisk) EngineException(org.ovirt.engine.core.common.errors.EngineException) SnapshotDao(org.ovirt.engine.core.dao.SnapshotDao) SerialChildExecutingCommand(org.ovirt.engine.core.bll.SerialChildExecutingCommand) StatelessSnapshotMemoryImageBuilder(org.ovirt.engine.core.bll.memory.StatelessSnapshotMemoryImageBuilder) ActionReturnValue(org.ovirt.engine.core.common.action.ActionReturnValue) VmStaticDao(org.ovirt.engine.core.dao.VmStaticDao) CommandContext(org.ovirt.engine.core.bll.context.CommandContext) ActionType(org.ovirt.engine.core.common.action.ActionType) MemoryImageBuilder(org.ovirt.engine.core.bll.memory.MemoryImageBuilder) DisksFilter(org.ovirt.engine.core.bll.storage.disk.image.DisksFilter) CinderDisksValidator(org.ovirt.engine.core.bll.validator.storage.CinderDisksValidator) Map(java.util.Map) Snapshot(org.ovirt.engine.core.common.businessentities.Snapshot) Instance(javax.enterprise.inject.Instance) RemoveMemoryVolumesParameters(org.ovirt.engine.core.common.action.RemoveMemoryVolumesParameters) BaseDisk(org.ovirt.engine.core.common.businessentities.storage.BaseDisk) CreateEntity(org.ovirt.engine.core.common.validation.group.CreateEntity) LiveSnapshotMemoryImageBuilder(org.ovirt.engine.core.bll.memory.LiveSnapshotMemoryImageBuilder) ONLY_SNAPABLE(org.ovirt.engine.core.bll.storage.disk.image.DisksFilter.ONLY_SNAPABLE) LockMessage(org.ovirt.engine.core.bll.LockMessage) DiskImagesValidator(org.ovirt.engine.core.bll.validator.storage.DiskImagesValidator) DiskStorageType(org.ovirt.engine.core.common.businessentities.storage.DiskStorageType) VmOverheadCalculator(org.ovirt.engine.core.common.scheduling.VmOverheadCalculator) CreateSnapshotForVmParameters(org.ovirt.engine.core.common.action.CreateSnapshotForVmParameters) Collection(java.util.Collection) EngineMessage(org.ovirt.engine.core.common.errors.EngineMessage) Set(java.util.Set) Collectors(java.util.stream.Collectors) VmDao(org.ovirt.engine.core.dao.VmDao) CreateSnapshotDiskParameters(org.ovirt.engine.core.common.action.CreateSnapshotDiskParameters) ONLY_NOT_SHAREABLE(org.ovirt.engine.core.bll.storage.disk.image.DisksFilter.ONLY_NOT_SHAREABLE) List(java.util.List) Injector(org.ovirt.engine.core.di.Injector) VmValidator(org.ovirt.engine.core.bll.validator.VmValidator) MultipleStorageDomainsValidator(org.ovirt.engine.core.bll.validator.storage.MultipleStorageDomainsValidator) AuditLogType(org.ovirt.engine.core.common.AuditLogType) VdcObjectType(org.ovirt.engine.core.common.VdcObjectType) QuotaConsumptionParameter(org.ovirt.engine.core.bll.quota.QuotaConsumptionParameter) FeatureSupported(org.ovirt.engine.core.common.FeatureSupported) QuotaStorageDependent(org.ovirt.engine.core.bll.quota.QuotaStorageDependent) SnapshotVDSCommandParameters(org.ovirt.engine.core.common.vdscommands.SnapshotVDSCommandParameters) EntityInfo(org.ovirt.engine.core.common.asynctasks.EntityInfo) LockProperties(org.ovirt.engine.core.common.action.LockProperties) Guid(org.ovirt.engine.core.compat.Guid) StorageDomain(org.ovirt.engine.core.common.businessentities.StorageDomain) ReplacementUtils(org.ovirt.engine.core.utils.ReplacementUtils) TransactionSupport(org.ovirt.engine.core.utils.transaction.TransactionSupport) ActionParametersBase(org.ovirt.engine.core.common.action.ActionParametersBase) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) MemoryStorageHandler(org.ovirt.engine.core.bll.memory.MemoryStorageHandler) ArrayList(java.util.ArrayList) CommandCoordinatorUtil(org.ovirt.engine.core.bll.tasks.CommandCoordinatorUtil) Inject(javax.inject.Inject) ExecutionHandler(org.ovirt.engine.core.bll.job.ExecutionHandler) MemoryUtils(org.ovirt.engine.core.bll.memory.MemoryUtils) SerialChildCommandsExecutionCallback(org.ovirt.engine.core.bll.SerialChildCommandsExecutionCallback) NullableMemoryImageBuilder(org.ovirt.engine.core.bll.memory.NullableMemoryImageBuilder) ONLY_ACTIVE(org.ovirt.engine.core.bll.storage.disk.image.DisksFilter.ONLY_ACTIVE) LinkedList(java.util.LinkedList) VmCommand(org.ovirt.engine.core.bll.VmCommand) Pair(org.ovirt.engine.core.common.utils.Pair) ImagesHandler(org.ovirt.engine.core.bll.storage.disk.image.ImagesHandler) StoragePoolValidator(org.ovirt.engine.core.bll.validator.storage.StoragePoolValidator) LockingGroup(org.ovirt.engine.core.common.locks.LockingGroup) AuditLogDirector(org.ovirt.engine.core.dal.dbbroker.auditloghandling.AuditLogDirector) VDSReturnValue(org.ovirt.engine.core.common.vdscommands.VDSReturnValue) Typed(javax.enterprise.inject.Typed) Disk(org.ovirt.engine.core.common.businessentities.storage.Disk) ImagesActionsParametersBase(org.ovirt.engine.core.common.action.ImagesActionsParametersBase) CommandStatus(org.ovirt.engine.core.compat.CommandStatus) QuotaStorageConsumptionParameter(org.ovirt.engine.core.bll.quota.QuotaStorageConsumptionParameter) EngineError(org.ovirt.engine.core.common.errors.EngineError) TransactionScopeOption(org.ovirt.engine.core.compat.TransactionScopeOption) CommandCallback(org.ovirt.engine.core.bll.tasks.interfaces.CommandCallback) DiskDao(org.ovirt.engine.core.dao.DiskDao) VDSCommandType(org.ovirt.engine.core.common.vdscommands.VDSCommandType) VdsAndVmIDVDSParametersBase(org.ovirt.engine.core.common.vdscommands.VdsAndVmIDVDSParametersBase) Comparator(java.util.Comparator) Collections(java.util.Collections) VMStatus(org.ovirt.engine.core.common.businessentities.VMStatus) ImageDao(org.ovirt.engine.core.dao.ImageDao) StoragePoolValidator(org.ovirt.engine.core.bll.validator.storage.StoragePoolValidator) Guid(org.ovirt.engine.core.compat.Guid) DiskImagesValidator(org.ovirt.engine.core.bll.validator.storage.DiskImagesValidator) CinderDisk(org.ovirt.engine.core.common.businessentities.storage.CinderDisk) BaseDisk(org.ovirt.engine.core.common.businessentities.storage.BaseDisk) 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)

Example 4 with DiskImagesValidator

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

the class RemoveDiskSnapshotsCommand method validateAllDiskImages.

protected boolean validateAllDiskImages() {
    List<DiskImage> images = diskImageDao.getAllSnapshotsForImageGroup(getDiskImage().getId());
    DiskImagesValidator diskImagesValidator = new DiskImagesValidator(images);
    return validate(diskImagesValidator.diskImagesNotLocked()) && validate(diskImagesValidator.diskImagesNotIllegal());
}
Also used : DiskImagesValidator(org.ovirt.engine.core.bll.validator.storage.DiskImagesValidator) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage)

Example 5 with DiskImagesValidator

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

the class AddVmAndCloneImageCommand method validate.

@Override
protected boolean validate() {
    List<DiskImage> disksToCheck = getDiskImagesToValidate();
    DiskImagesValidator diskImagesValidator = new DiskImagesValidator(disksToCheck);
    if (!validate(diskImagesValidator.diskImagesNotLocked())) {
        return false;
    }
    Set<Guid> storageIds = ImagesHandler.getAllStorageIdsForImageIds(disksToCheck);
    MultipleStorageDomainsValidator storageValidator = new MultipleStorageDomainsValidator(getStoragePoolId(), storageIds);
    if (!validate(storageValidator.allDomainsExistAndActive())) {
        return false;
    }
    if (!validate(new VmValidator(getSourceVmFromDb()).vmNotLocked())) {
        return false;
    }
    // Run all checks for AddVm, now that it is determined snapshot exists
    if (!super.validate()) {
        return false;
    }
    for (DiskImage diskImage : getDiskImagesToBeCloned()) {
        if (diskImage.getDiskStorageType() == DiskStorageType.IMAGE && !checkImageConfiguration(diskImage)) {
            return false;
        }
    }
    return true;
}
Also used : 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)

Aggregations

DiskImagesValidator (org.ovirt.engine.core.bll.validator.storage.DiskImagesValidator)20 DiskImage (org.ovirt.engine.core.common.businessentities.storage.DiskImage)13 VmValidator (org.ovirt.engine.core.bll.validator.VmValidator)10 StoragePoolValidator (org.ovirt.engine.core.bll.validator.storage.StoragePoolValidator)9 Guid (org.ovirt.engine.core.compat.Guid)8 MultipleStorageDomainsValidator (org.ovirt.engine.core.bll.validator.storage.MultipleStorageDomainsValidator)6 DiskValidator (org.ovirt.engine.core.bll.validator.storage.DiskValidator)4 StorageDomainValidator (org.ovirt.engine.core.bll.validator.storage.StorageDomainValidator)4 Disk (org.ovirt.engine.core.common.businessentities.storage.Disk)4 VM (org.ovirt.engine.core.common.businessentities.VM)3 CinderDisk (org.ovirt.engine.core.common.businessentities.storage.CinderDisk)3 ArrayList (java.util.ArrayList)2 ValidationResult (org.ovirt.engine.core.bll.ValidationResult)2 DiskSnapshotsValidator (org.ovirt.engine.core.bll.validator.storage.DiskSnapshotsValidator)2 StoragePool (org.ovirt.engine.core.common.businessentities.StoragePool)2 Collection (java.util.Collection)1 Collections (java.util.Collections)1 Comparator (java.util.Comparator)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1