Search in sources :

Example 31 with StorageDomainValidator

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

the class VmCommand method validateLeaseStorageDomain.

protected boolean validateLeaseStorageDomain(Guid leaseStorageDomainId) {
    StorageDomain domain = storageDomainDao.getForStoragePool(leaseStorageDomainId, getStoragePoolId());
    StorageDomainValidator validator = new StorageDomainValidator(domain);
    return validate(validator.isDomainExistAndActive()) && validate(validator.isDataDomain());
}
Also used : StorageDomain(org.ovirt.engine.core.common.businessentities.StorageDomain) StorageDomainValidator(org.ovirt.engine.core.bll.validator.storage.StorageDomainValidator)

Example 32 with StorageDomainValidator

use of org.ovirt.engine.core.bll.validator.storage.StorageDomainValidator 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 33 with StorageDomainValidator

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

the class VmTemplateHandler method isVmTemplateImagesReady.

public ValidationResult isVmTemplateImagesReady(VmTemplate vmTemplate, Guid storageDomainId, boolean checkImagesExists, boolean checkLocked, boolean checkIllegal, boolean checkStorageDomain, List<DiskImage> providedVmtImages) {
    List<DiskImage> vmtImages = providedVmtImages;
    if (checkStorageDomain) {
        StorageDomainValidator storageDomainValidator = new StorageDomainValidator(storageDomainDao.getForStoragePool(storageDomainId, vmTemplate.getStoragePoolId()));
        ValidationResult returnValue = storageDomainValidator.isDomainExistAndActive();
        if (!returnValue.isValid()) {
            return returnValue;
        }
    }
    if (checkImagesExists) {
        if (vmtImages == null) {
            vmtImages = DisksFilter.filterImageDisks(diskDao.getAllForVm(vmTemplate.getId()), ONLY_ACTIVE);
        }
        if (vmtImages.size() > 0 && !imagesHandler.isImagesExists(vmtImages, vmtImages.get(0).getStoragePoolId())) {
            return new ValidationResult(EngineMessage.TEMPLATE_IMAGE_NOT_EXIST);
        }
    }
    if (checkLocked) {
        if (vmTemplate.getStatus() == VmTemplateStatus.Locked) {
            return new ValidationResult(EngineMessage.VM_TEMPLATE_IMAGE_IS_LOCKED);
        }
        if (vmtImages != null) {
            for (DiskImage image : vmtImages) {
                if (image.getImageStatus() == ImageStatus.LOCKED) {
                    return new ValidationResult(EngineMessage.VM_TEMPLATE_IMAGE_IS_LOCKED);
                }
            }
        }
    }
    if (checkIllegal && (vmTemplate.getStatus() == VmTemplateStatus.Illegal)) {
        return new ValidationResult(EngineMessage.VM_TEMPLATE_IMAGE_IS_ILLEGAL);
    }
    return ValidationResult.VALID;
}
Also used : StorageDomainValidator(org.ovirt.engine.core.bll.validator.storage.StorageDomainValidator) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage)

Example 34 with StorageDomainValidator

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

the class AddVmCommand method validateProvidedDestinations.

private boolean validateProvidedDestinations() {
    for (DiskImage diskImage : diskInfoDestinationMap.values()) {
        if (diskImage.getStorageIds() == null || diskImage.getStorageIds().isEmpty()) {
            diskImage.setStorageIds(new ArrayList<>());
            diskImage.getStorageIds().add(getParameters().getStorageDomainId());
        }
        Guid storageDomainId = diskImage.getStorageIds().get(0);
        if (destStorages.get(storageDomainId) == null) {
            StorageDomain storage = storageDomainDao.getForStoragePool(storageDomainId, getStoragePoolId());
            StorageDomainValidator validator = new StorageDomainValidator(storage);
            if (!validate(validator.isDomainExistAndActive()) || !validate(validator.domainIsValidDestination())) {
                return false;
            }
            destStorages.put(storage.getId(), storage);
        }
    }
    return true;
}
Also used : StorageDomain(org.ovirt.engine.core.common.businessentities.StorageDomain) StorageDomainValidator(org.ovirt.engine.core.bll.validator.storage.StorageDomainValidator) Guid(org.ovirt.engine.core.compat.Guid) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage)

Example 35 with StorageDomainValidator

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

the class RunVmValidator method validateVmLease.

public ValidationResult validateVmLease() {
    if (vm.getLeaseStorageDomainId() == null) {
        return ValidationResult.VALID;
    }
    if (vm.getLeaseInfo() == null) {
        return new ValidationResult(EngineMessage.ACTION_TYPE_FAILED_INVALID_VM_LEASE);
    }
    StorageDomain leaseStorageDomain = storageDomainDao.getForStoragePool(vm.getLeaseStorageDomainId(), vm.getStoragePoolId());
    StorageDomainValidator storageDomainValidator = new StorageDomainValidator(leaseStorageDomain);
    ValidationResult validationResult = storageDomainValidator.isDomainExistAndActive();
    if (!validationResult.isValid()) {
        return new ValidationResult(EngineMessage.ACTION_TYPE_FAILED_INVALID_VM_LEASE_STORAGE_DOMAIN_STATUS, String.format("$LeaseStorageDomainName %1$s", leaseStorageDomain.getName()));
    }
    return ValidationResult.VALID;
}
Also used : StorageDomain(org.ovirt.engine.core.common.businessentities.StorageDomain) StorageDomainValidator(org.ovirt.engine.core.bll.validator.storage.StorageDomainValidator) ValidationResult(org.ovirt.engine.core.bll.ValidationResult)

Aggregations

StorageDomainValidator (org.ovirt.engine.core.bll.validator.storage.StorageDomainValidator)36 DiskImage (org.ovirt.engine.core.common.businessentities.storage.DiskImage)17 StorageDomain (org.ovirt.engine.core.common.businessentities.StorageDomain)16 Guid (org.ovirt.engine.core.compat.Guid)11 ArrayList (java.util.ArrayList)7 StoragePoolValidator (org.ovirt.engine.core.bll.validator.storage.StoragePoolValidator)7 ValidationResult (org.ovirt.engine.core.bll.ValidationResult)6 VmValidator (org.ovirt.engine.core.bll.validator.VmValidator)5 HashMap (java.util.HashMap)4 DiskImagesValidator (org.ovirt.engine.core.bll.validator.storage.DiskImagesValidator)4 DiskValidator (org.ovirt.engine.core.bll.validator.storage.DiskValidator)4 Disk (org.ovirt.engine.core.common.businessentities.storage.Disk)4 List (java.util.List)3 Map (java.util.Map)3 StoragePoolIsoMapId (org.ovirt.engine.core.common.businessentities.StoragePoolIsoMapId)3 DiskVmElementValidator (org.ovirt.engine.core.bll.validator.storage.DiskVmElementValidator)2 ActionReturnValue (org.ovirt.engine.core.common.action.ActionReturnValue)2 VM (org.ovirt.engine.core.common.businessentities.VM)2 VmTemplate (org.ovirt.engine.core.common.businessentities.VmTemplate)2 CinderDisk (org.ovirt.engine.core.common.businessentities.storage.CinderDisk)2