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;
}
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;
}
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;
}
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);
}
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);
}
Aggregations