Search in sources :

Example 61 with ValidationResult

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

the class DiskImagesValidator method childDiskWasExtended.

/**
 * Block the move/copy of a disk that has snapshots created before it's extension
 * on block pre-V4 domains.
 * @see <a href="https://bugzilla.redhat.com/1523614">https://bugzilla.redhat.com/1523614</a>
 * @see <a href="https://bugzilla.redhat.com/1523614">https://bugzilla.redhat.com/1554028</a>
 */
public ValidationResult childDiskWasExtended(StorageDomain storageDomain) {
    if (StorageFormatType.V4.compareTo(storageDomain.getStorageFormat()) > 0 && storageDomain.getStorageType().isBlockDomain()) {
        DiskImage diskImage = diskImages.iterator().next();
        List<DiskImage> diskImages = getDiskImageDao().getAllSnapshotsForImageGroup(diskImage.getId());
        Guid imageTemplateId = diskImage.getImageTemplateId();
        if (!Guid.isNullOrEmpty(imageTemplateId)) {
            DiskImage templateDiskImage = getDiskImageDao().get(imageTemplateId);
            if (templateDiskImage.getSize() < diskImage.getSize()) {
                return new ValidationResult(EngineMessage.CANNOT_MOVE_DISK_TEMPLATE);
            }
        }
        boolean badSnapshotPresent = diskImages.stream().anyMatch(d -> d.getSize() < diskImage.getSize());
        if (badSnapshotPresent) {
            return new ValidationResult(EngineMessage.CANNOT_MOVE_DISK_SNAPSHOTS, ReplacementUtils.createSetVariableString("Snapshots", diskImages.stream().filter(d -> !d.getActive()).map(DiskImage::getDescription).collect(Collectors.joining(", "))));
        }
    }
    return ValidationResult.VALID;
}
Also used : Guid(org.ovirt.engine.core.compat.Guid) ValidationResult(org.ovirt.engine.core.bll.ValidationResult) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage)

Example 62 with ValidationResult

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

the class DiskImagesValidator method diskImagesOnStorage.

/**
 * checks that the given disks do not exist on the target storage domains
 * @param imageToDestinationDomainMap map containing the destination domain for each of the disks
 * @param storagePoolId the storage pool ID to check whether the disks are residing on
 * @return validation result indicating whether the disks don't exist on the target storage domains
 */
public ValidationResult diskImagesOnStorage(Map<Guid, Guid> imageToDestinationDomainMap, Guid storagePoolId) {
    Map<Guid, List<Guid>> domainImages = new HashMap<>();
    for (DiskImage diskImage : diskImages) {
        Guid targetStorageDomainId = imageToDestinationDomainMap.get(diskImage.getId());
        List<Guid> imagesOnStorageDomain = domainImages.get(targetStorageDomainId);
        if (imagesOnStorageDomain == null) {
            VDSReturnValue returnValue = Backend.getInstance().getResourceManager().runVdsCommand(VDSCommandType.GetImagesList, new GetImagesListVDSCommandParameters(targetStorageDomainId, storagePoolId));
            if (returnValue.getSucceeded()) {
                imagesOnStorageDomain = (List<Guid>) returnValue.getReturnValue();
                domainImages.put(targetStorageDomainId, imagesOnStorageDomain);
            } else {
                return new ValidationResult(EngineMessage.ERROR_GET_IMAGE_LIST, String.format("$sdName %1$s", getStorageDomainStaticDao().get(targetStorageDomainId).getName()));
            }
        }
        if (imagesOnStorageDomain.contains(diskImage.getId())) {
            return new ValidationResult(EngineMessage.ACTION_TYPE_FAILED_STORAGE_DOMAIN_ALREADY_CONTAINS_DISK);
        }
    }
    return ValidationResult.VALID;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) Guid(org.ovirt.engine.core.compat.Guid) ValidationResult(org.ovirt.engine.core.bll.ValidationResult) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) GetImagesListVDSCommandParameters(org.ovirt.engine.core.common.vdscommands.GetImagesListVDSCommandParameters) VDSReturnValue(org.ovirt.engine.core.common.vdscommands.VDSReturnValue)

Example 63 with ValidationResult

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

the class DiskImagesValidator method diskImagesSnapshotsAttachedToVm.

public ValidationResult diskImagesSnapshotsAttachedToVm(Guid vmId) {
    LinkedList<String> diskSnapshotInfo = new LinkedList<>();
    VM vm = getVmDao().get(vmId);
    for (DiskImage diskImage : diskImages) {
        List<VmDevice> devices = getVmDeviceDao().getVmDevicesByDeviceId(diskImage.getId(), vmId);
        if (devices.isEmpty()) {
            // The specified disk image does not belong to the vm
            Snapshot snapshot = getSnapshotDao().get(diskImage.getSnapshotId());
            Disk disk = getDbFacade().getDiskDao().get(diskImage.getId());
            diskSnapshotInfo.add(String.format("%s ,%s", disk.getDiskAlias(), snapshot.getDescription()));
        }
    }
    if (!diskSnapshotInfo.isEmpty()) {
        EngineMessage message = EngineMessage.ACTION_TYPE_FAILED_VM_DISK_SNAPSHOT_NOT_ATTACHED_TO_VM;
        return new ValidationResult(message, String.format("$disksInfo %s", String.format(StringUtils.join(diskSnapshotInfo, "%n"))), String.format("$vmName %s", vm.getName()));
    }
    return ValidationResult.VALID;
}
Also used : VmDevice(org.ovirt.engine.core.common.businessentities.VmDevice) Snapshot(org.ovirt.engine.core.common.businessentities.Snapshot) VM(org.ovirt.engine.core.common.businessentities.VM) ValidationResult(org.ovirt.engine.core.bll.ValidationResult) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) Disk(org.ovirt.engine.core.common.businessentities.storage.Disk) LinkedList(java.util.LinkedList) EngineMessage(org.ovirt.engine.core.common.errors.EngineMessage)

Example 64 with ValidationResult

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

the class MoveOrCopyDiskCommandTest method validateImageNotFound.

@Test
public void validateImageNotFound() {
    initializeCommand(new DiskImage(), VmEntityType.VM);
    when(diskValidator.isDiskExists()).thenReturn(new ValidationResult(EngineMessage.ACTION_TYPE_FAILED_DISK_NOT_EXIST));
    ValidateTestUtils.runAndAssertValidateFailure(command, EngineMessage.ACTION_TYPE_FAILED_DISK_NOT_EXIST);
}
Also used : ValidationResult(org.ovirt.engine.core.bll.ValidationResult) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) Test(org.junit.Test) BaseCommandTest(org.ovirt.engine.core.bll.BaseCommandTest)

Example 65 with ValidationResult

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

the class MoveOrCopyDiskCommandTest method validateVmInPreview.

@Test
public void validateVmInPreview() {
    initializeCommand(new DiskImage(), VmEntityType.VM);
    initVmForSpace();
    initSrcStorageDomain();
    initDestStorageDomain(StorageType.NFS);
    when(snapshotsValidator.vmNotInPreview(any())).thenReturn(new ValidationResult(EngineMessage.ACTION_TYPE_FAILED_VM_IN_PREVIEW));
    ValidateTestUtils.runAndAssertValidateFailure(command, EngineMessage.ACTION_TYPE_FAILED_VM_IN_PREVIEW);
}
Also used : ValidationResult(org.ovirt.engine.core.bll.ValidationResult) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) Test(org.junit.Test) BaseCommandTest(org.ovirt.engine.core.bll.BaseCommandTest)

Aggregations

ValidationResult (org.ovirt.engine.core.bll.ValidationResult)239 Test (org.junit.Test)132 BaseCommandTest (org.ovirt.engine.core.bll.BaseCommandTest)49 Guid (org.ovirt.engine.core.compat.Guid)40 ArrayList (java.util.ArrayList)31 EngineMessage (org.ovirt.engine.core.common.errors.EngineMessage)31 DiskImage (org.ovirt.engine.core.common.businessentities.storage.DiskImage)30 Network (org.ovirt.engine.core.common.businessentities.network.Network)21 NetworkAttachment (org.ovirt.engine.core.common.businessentities.network.NetworkAttachment)19 VdsNetworkInterface (org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface)16 GlusterVolumeEntity (org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeEntity)15 CreateOrUpdateBond (org.ovirt.engine.core.common.action.CreateOrUpdateBond)13 StorageDomain (org.ovirt.engine.core.common.businessentities.StorageDomain)12 List (java.util.List)11 VM (org.ovirt.engine.core.common.businessentities.VM)11 HashSet (java.util.HashSet)10 FindActiveVmsUsingNetwork (org.ovirt.engine.core.bll.network.FindActiveVmsUsingNetwork)10 GlusterBrickEntity (org.ovirt.engine.core.common.businessentities.gluster.GlusterBrickEntity)9 StorageDomainValidator (org.ovirt.engine.core.bll.validator.storage.StorageDomainValidator)7 Disk (org.ovirt.engine.core.common.businessentities.storage.Disk)7