Search in sources :

Example 66 with Snapshot

use of org.ovirt.engine.core.common.businessentities.Snapshot in project ovirt-engine by oVirt.

the class VmSnapshotListModel method onCloneTemplate.

private void onCloneTemplate() {
    final UnitVmModel model = (UnitVmModel) getWindow();
    NewTemplateVmModelBehavior behavior = (NewTemplateVmModelBehavior) model.getBehavior();
    Snapshot snapshot = getSelectedItem();
    if (snapshot == null) {
        cancel();
        return;
    }
    final VM vm = behavior.getVm();
    if (!model.validate(false)) {
        model.setIsValid(false);
    } else if (model.getIsSubTemplate().getEntity()) {
        postNameUniqueCheck(vm);
    } else {
        String name = model.getName().getEntity();
        // Check name uniqueness.
        AsyncDataProvider.getInstance().isTemplateNameUnique(new AsyncQuery<>(isNameUnique -> {
            if (!isNameUnique) {
                model.getInvalidityReasons().clear();
                model.getName().getInvalidityReasons().add(ConstantsManager.getInstance().getConstants().nameMustBeUniqueInvalidReason());
                model.getName().setIsValid(false);
                model.setIsValid(false);
                model.fireValidationCompleteEvent();
            } else {
                postNameUniqueCheck(vm);
            }
        }), name, model.getSelectedDataCenter().getId());
    }
}
Also used : Snapshot(org.ovirt.engine.core.common.businessentities.Snapshot) VM(org.ovirt.engine.core.common.businessentities.VM)

Example 67 with Snapshot

use of org.ovirt.engine.core.common.businessentities.Snapshot in project ovirt-engine by oVirt.

the class RemoveImageCommand method removeImageFromDB.

private void removeImageFromDB() {
    final DiskImage diskImage = getDiskImage();
    final List<Snapshot> updatedSnapshots;
    try {
        VM vm = getVmForNonShareableDiskImage(diskImage);
        // so no lock is required.
        if (getParameters().isRemoveFromSnapshots() && vm != null) {
            lockVmSnapshotsWithWait(vm);
            updatedSnapshots = prepareSnapshotConfigWithoutImage(diskImage.getId());
        } else {
            updatedSnapshots = Collections.emptyList();
        }
        TransactionSupport.executeInScope(TransactionScopeOption.Required, () -> {
            diskImageDynamicDao.remove(diskImage.getImageId());
            Guid imageTemplate = diskImage.getImageTemplateId();
            Guid currentGuid = diskImage.getImageId();
            // the storage).
            while (!currentGuid.equals(imageTemplate) && !currentGuid.equals(Guid.Empty)) {
                removeChildren(currentGuid);
                DiskImage image = diskImageDao.getSnapshotById(currentGuid);
                if (image != null) {
                    removeSnapshot(image);
                    currentGuid = image.getParentId();
                } else {
                    currentGuid = Guid.Empty;
                    log.warn("'image' (snapshot of image '{}') is null, cannot remove it.", diskImage.getImageId());
                }
            }
            baseDiskDao.remove(diskImage.getId());
            vmDeviceDao.remove(new VmDeviceId(diskImage.getId(), null));
            updatedSnapshots.forEach(snapshotDao::update);
            return null;
        });
    } finally {
        if (getSnapshotsEngineLock() != null) {
            lockManager.releaseLock(getSnapshotsEngineLock());
        }
    }
}
Also used : Snapshot(org.ovirt.engine.core.common.businessentities.Snapshot) VM(org.ovirt.engine.core.common.businessentities.VM) Guid(org.ovirt.engine.core.compat.Guid) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) VmDeviceId(org.ovirt.engine.core.common.businessentities.VmDeviceId)

Example 68 with Snapshot

use of org.ovirt.engine.core.common.businessentities.Snapshot in project ovirt-engine by oVirt.

the class RemoveImageCommand method prepareSnapshotConfigWithoutImage.

/**
 * Prepare a {@link List} of {@link Snapshot} objects with the given disk (image group) removed from it.
 */
protected List<Snapshot> prepareSnapshotConfigWithoutImage(Guid imageGroupToRemove) {
    List<Snapshot> result = new LinkedList<>();
    List<DiskImage> snapshotDisks = diskImageDao.getAllSnapshotsForImageGroup(imageGroupToRemove);
    for (DiskImage snapshotDisk : snapshotDisks) {
        Guid vmSnapshotId = snapshotDisk.getVmSnapshotId();
        if (vmSnapshotId != null && !Guid.Empty.equals(vmSnapshotId)) {
            Snapshot snapshot = snapshotDao.get(vmSnapshotId);
            Snapshot updated = imagesHandler.prepareSnapshotConfigWithoutImageSingleImage(snapshot, snapshotDisk.getImageId(), ovfManager);
            if (updated != null) {
                result.add(updated);
            }
        }
    }
    return result;
}
Also used : Snapshot(org.ovirt.engine.core.common.businessentities.Snapshot) Guid(org.ovirt.engine.core.compat.Guid) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) LinkedList(java.util.LinkedList)

Example 69 with Snapshot

use of org.ovirt.engine.core.common.businessentities.Snapshot in project ovirt-engine by oVirt.

the class DiskImagesValidatorTest method prepareForCheckingIfDisksSnapshotsAttachedToOtherVms.

private List<VmDevice> prepareForCheckingIfDisksSnapshotsAttachedToOtherVms() {
    VmDevice device1 = createVmDeviceForDisk(disk1);
    VmDevice device2 = createVmDeviceForDisk(disk2);
    when(vmDeviceDao.getVmDevicesByDeviceId(disk1.getId(), null)).thenReturn(Collections.singletonList(device1));
    when(vmDeviceDao.getVmDevicesByDeviceId(disk2.getId(), null)).thenReturn(Collections.singletonList(device2));
    when(vmDao.get(any())).thenReturn(new VM());
    when(snapshotDao.get(any())).thenReturn(new Snapshot());
    return Arrays.asList(device1, device2);
}
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)

Example 70 with Snapshot

use of org.ovirt.engine.core.common.businessentities.Snapshot in project ovirt-engine by oVirt.

the class DiskSnapshotsValidatorTest method getActiveSnapshot.

private Snapshot getActiveSnapshot() {
    Snapshot snapshot = new Snapshot();
    snapshot.setId(Guid.newGuid());
    snapshot.setType(Snapshot.SnapshotType.ACTIVE);
    return snapshot;
}
Also used : Snapshot(org.ovirt.engine.core.common.businessentities.Snapshot)

Aggregations

Snapshot (org.ovirt.engine.core.common.businessentities.Snapshot)96 DiskImage (org.ovirt.engine.core.common.businessentities.storage.DiskImage)33 VM (org.ovirt.engine.core.common.businessentities.VM)32 Guid (org.ovirt.engine.core.compat.Guid)30 Test (org.junit.Test)21 ArrayList (java.util.ArrayList)15 ActionReturnValue (org.ovirt.engine.core.common.action.ActionReturnValue)12 List (java.util.List)11 SnapshotStatus (org.ovirt.engine.core.common.businessentities.Snapshot.SnapshotStatus)9 Collections (java.util.Collections)8 Date (java.util.Date)8 Set (java.util.Set)8 Collectors (java.util.stream.Collectors)8 SnapshotType (org.ovirt.engine.core.common.businessentities.Snapshot.SnapshotType)8 EngineException (org.ovirt.engine.core.common.errors.EngineException)8 ActionType (org.ovirt.engine.core.common.action.ActionType)7 DiskStorageType (org.ovirt.engine.core.common.businessentities.storage.DiskStorageType)6 EngineMessage (org.ovirt.engine.core.common.errors.EngineMessage)6 HashMap (java.util.HashMap)5 HashSet (java.util.HashSet)5