Search in sources :

Example 16 with VmValidator

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

the class UpdateVmCommandTest method mockVmValidator.

private void mockVmValidator() {
    VmValidator vmValidator = spy(new VmValidator(vm));
    doReturn(vmValidator).when(command).createVmValidator(vm);
    doReturn(diskDao).when(vmValidator).getDiskDao();
    doReturn(getNoVirtioScsiDiskElement()).when(diskVmElementDao).get(any());
    doReturn(diskVmElementDao).when(vmValidator).getDiskVmElementDao();
}
Also used : VmValidator(org.ovirt.engine.core.bll.validator.VmValidator)

Example 17 with VmValidator

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

the class VmPoolHandler method isNonPrestartedVmFree.

/**
 * Check if a specific VM is free. A VM is considered free if it isn't attached to a user and not during preview
 * @param vmId The VM ID
 * @param errorProcessor the error messages processor object or lambda expression (may be <code>null</code>)
 * @return True if the VM is free, false otherwise
 */
public boolean isNonPrestartedVmFree(Guid vmId, ErrorProcessor errorProcessor) {
    List<String> messages = new ArrayList<>();
    // check that there is no user already attached to this VM
    if (vmAssignedToUser(vmId, messages)) {
        return failVmFree(errorProcessor, vmId, messages);
    }
    // check that VN can be run
    if (!canRunPoolVm(vmId, messages)) {
        return failVmFree(errorProcessor, vmId, messages);
    }
    // check VM images
    ValidationResult vmDuringSnapshotResult = snapshotsValidator.vmNotDuringSnapshot(vmId);
    if (!vmDuringSnapshotResult.isValid()) {
        return failVmFree(errorProcessor, vmId, vmDuringSnapshotResult.getMessagesAsStrings());
    }
    ValidationResult vmInPreviewResult = snapshotsValidator.vmNotInPreview(vmId);
    if (!vmInPreviewResult.isValid()) {
        return failVmFree(errorProcessor, vmId, vmInPreviewResult.getMessagesAsStrings());
    }
    List<Disk> disks = diskDao.getAllForVm(vmId);
    List<DiskImage> vmImages = DisksFilter.filterImageDisks(disks, ONLY_NOT_SHAREABLE, ONLY_SNAPABLE);
    VM vm = vmDao.get(vmId);
    StoragePool sp = storagePoolDao.get(vm.getStoragePoolId());
    ValidationResult spUpResult = new StoragePoolValidator(sp).existsAndUp();
    if (!spUpResult.isValid()) {
        return failVmFree(errorProcessor, vmId, spUpResult.getMessagesAsStrings());
    }
    Guid storageDomainId = vmImages.size() > 0 ? vmImages.get(0).getStorageIds().get(0) : Guid.Empty;
    if (!Guid.Empty.equals(storageDomainId)) {
        StorageDomainValidator storageDomainValidator = new StorageDomainValidator(storageDomainDao.getForStoragePool(storageDomainId, sp.getId()));
        ValidationResult domainActiveResult = storageDomainValidator.isDomainExistAndActive();
        if (!domainActiveResult.isValid()) {
            return failVmFree(errorProcessor, vmId, domainActiveResult.getMessagesAsStrings());
        }
    }
    DiskImagesValidator diskImagesValidator = new DiskImagesValidator(vmImages);
    ValidationResult disksNotLockedResult = diskImagesValidator.diskImagesNotLocked();
    if (!disksNotLockedResult.isValid()) {
        messages.addAll(disksNotLockedResult.getMessagesAsStrings());
        messages.addAll(disksNotLockedResult.getVariableReplacements());
        return failVmFree(errorProcessor, vmId, messages);
    }
    ValidationResult vmNotLockResult = new VmValidator(vm).vmNotLocked();
    if (!vmNotLockResult.isValid()) {
        return failVmFree(errorProcessor, vmId, vmNotLockResult.getMessagesAsStrings());
    }
    return true;
}
Also used : StoragePool(org.ovirt.engine.core.common.businessentities.StoragePool) StorageDomainValidator(org.ovirt.engine.core.bll.validator.storage.StorageDomainValidator) ArrayList(java.util.ArrayList) Guid(org.ovirt.engine.core.compat.Guid) StoragePoolValidator(org.ovirt.engine.core.bll.validator.storage.StoragePoolValidator) VM(org.ovirt.engine.core.common.businessentities.VM) DiskImagesValidator(org.ovirt.engine.core.bll.validator.storage.DiskImagesValidator) Disk(org.ovirt.engine.core.common.businessentities.storage.Disk) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) RunVmValidator(org.ovirt.engine.core.bll.validator.RunVmValidator) VmValidator(org.ovirt.engine.core.bll.validator.VmValidator)

Example 18 with VmValidator

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

the class MigrateVmCommand method validateImpl.

@Override
protected boolean validateImpl() {
    final VM vm = getVm();
    if (vm == null) {
        return failValidation(EngineMessage.ACTION_TYPE_FAILED_VM_NOT_FOUND);
    }
    if (!canRunActionOnNonManagedVm()) {
        return false;
    }
    VmValidator vmValidator = getVmValidator();
    if (!validate(vmValidator.isVmPluggedDiskNotUsingScsiReservation())) {
        return false;
    }
    if (!FeatureSupported.isMigrationSupported(getCluster().getArchitecture(), getCluster().getCompatibilityVersion())) {
        return failValidation(EngineMessage.MIGRATION_IS_NOT_SUPPORTED);
    }
    // If VM is pinned to host, no migration can occur
    if (vm.getMigrationSupport() == MigrationSupport.PINNED_TO_HOST) {
        return failValidation(EngineMessage.ACTION_TYPE_FAILED_VM_IS_PINNED_TO_HOST);
    }
    if (vm.getMigrationSupport() == MigrationSupport.IMPLICITLY_NON_MIGRATABLE && !getParameters().isForceMigrationForNonMigratableVm()) {
        return failValidation(EngineMessage.ACTION_TYPE_FAILED_VM_IS_NON_MIGRTABLE_AND_IS_NOT_FORCED_BY_USER_TO_MIGRATE);
    }
    switch(vm.getStatus()) {
        case MigratingFrom:
            return failValidation(EngineMessage.ACTION_TYPE_FAILED_MIGRATION_IN_PROGRESS);
        case NotResponding:
            return failVmStatusIllegal();
        case Paused:
            if (vm.getVmPauseStatus() == VmPauseStatus.EIO) {
                return failValidation(EngineMessage.MIGRATE_PAUSED_EIO_VM_IS_NOT_SUPPORTED);
            }
            break;
        default:
    }
    if (!vm.isQualifyToMigrate()) {
        return failValidation(EngineMessage.ACTION_TYPE_FAILED_VM_IS_NOT_RUNNING);
    }
    if (!validate(new MultipleVmsValidator(vm).vmNotHavingPluggedDiskSnapshots(EngineMessage.ACTION_TYPE_FAILED_VM_HAS_PLUGGED_DISK_SNAPSHOT)) || !validate(vmValidator.allPassthroughVnicsMigratable())) {
        return false;
    }
    if (getParameters().getTargetClusterId() != null) {
        ChangeVmClusterValidator changeVmClusterValidator = ChangeVmClusterValidator.create(this, getParameters().getTargetClusterId(), getVm().getCustomCompatibilityVersion());
        if (!changeVmClusterValidator.validate()) {
            return false;
        }
    }
    if (isInternalExecution() && getVm().getMigrationSupport() != MigrationSupport.MIGRATABLE) {
        return failValidation(EngineMessage.ACTION_TYPE_FAILED_VM_IS_NON_MIGRTABLE);
    }
    return validate(snapshotsValidator.vmNotDuringSnapshot(vm.getId())) && // TODO: replace it with a better solution
    validate(new DiskImagesValidator(callFilterImageDisks(vm)).diskImagesNotLocked()) && !schedulingManager.canSchedule(getCluster(), getVm(), getVdsBlackList(), getVdsWhiteList(), getReturnValue().getValidationMessages()).isEmpty();
}
Also used : VM(org.ovirt.engine.core.common.businessentities.VM) MultipleVmsValidator(org.ovirt.engine.core.bll.validator.MultipleVmsValidator) DiskImagesValidator(org.ovirt.engine.core.bll.validator.storage.DiskImagesValidator) VmValidator(org.ovirt.engine.core.bll.validator.VmValidator)

Example 19 with VmValidator

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

the class RemoveDiskSnapshotsCommandTest method setUp.

@Before
public void setUp() {
    doReturn(storageDomainValidator).when(cmd).getStorageDomainValidator();
    doReturn(STORAGE_POOLD_ID).when(cmd).getStoragePoolId();
    doReturn(mockImages()).when(cmd).getImages();
    mockVm();
    vmValidator = spy(new VmValidator(cmd.getVm()));
    doReturn(vmValidator).when(cmd).createVmValidator(any());
    DiskImagesValidator diskImagesValidator = spy(new DiskImagesValidator(mockImages()));
    doReturn(diskImagesValidator).when(cmd).createDiskImageValidator(any());
    doReturn(ValidationResult.VALID).when(diskImagesValidator).diskImagesSnapshotsNotAttachedToOtherVms(false);
}
Also used : DiskImagesValidator(org.ovirt.engine.core.bll.validator.storage.DiskImagesValidator) VmValidator(org.ovirt.engine.core.bll.validator.VmValidator) Before(org.junit.Before)

Example 20 with VmValidator

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

the class RemoveSnapshotCommandTest method setUp.

@Before
public void setUp() {
    mockVm();
    VmValidator vmValidator = spy(new VmValidator(cmd.getVm()));
    doReturn(ValidationResult.VALID).when(vmValidator).vmNotHavingDeviceSnapshotsAttachedToOtherVms(anyBoolean());
    doReturn(vmValidator).when(cmd).createVmValidator(any());
    doReturn(STORAGE_POOL_ID).when(cmd).getStoragePoolId();
    mockSnapshot(SnapshotType.REGULAR);
    spySdValidator();
}
Also used : VmValidator(org.ovirt.engine.core.bll.validator.VmValidator) Before(org.junit.Before)

Aggregations

VmValidator (org.ovirt.engine.core.bll.validator.VmValidator)20 DiskImagesValidator (org.ovirt.engine.core.bll.validator.storage.DiskImagesValidator)10 StoragePoolValidator (org.ovirt.engine.core.bll.validator.storage.StoragePoolValidator)9 DiskImage (org.ovirt.engine.core.common.businessentities.storage.DiskImage)9 Guid (org.ovirt.engine.core.compat.Guid)7 MultipleStorageDomainsValidator (org.ovirt.engine.core.bll.validator.storage.MultipleStorageDomainsValidator)6 StorageDomainValidator (org.ovirt.engine.core.bll.validator.storage.StorageDomainValidator)5 VM (org.ovirt.engine.core.common.businessentities.VM)5 Disk (org.ovirt.engine.core.common.businessentities.storage.Disk)5 DiskVmElementValidator (org.ovirt.engine.core.bll.validator.storage.DiskVmElementValidator)4 CinderDisk (org.ovirt.engine.core.common.businessentities.storage.CinderDisk)3 LunDisk (org.ovirt.engine.core.common.businessentities.storage.LunDisk)3 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 Before (org.junit.Before)2 ValidationResult (org.ovirt.engine.core.bll.ValidationResult)2 CinderDisksValidator (org.ovirt.engine.core.bll.validator.storage.CinderDisksValidator)2 DiskSnapshotsValidator (org.ovirt.engine.core.bll.validator.storage.DiskSnapshotsValidator)2 DiskValidator (org.ovirt.engine.core.bll.validator.storage.DiskValidator)2 EngineMessage (org.ovirt.engine.core.common.errors.EngineMessage)2