Search in sources :

Example 46 with Snapshot

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

the class RemoveCinderVolumeParentCommand method removeDiskFromDbCallBack.

public void removeDiskFromDbCallBack(final CinderDisk cinderVolume) {
    final Snapshot updated = getParameters().isUpdateSnapshot() ? getSnapshotWithoutCinderVolume(cinderVolume) : null;
    TransactionSupport.executeInScope(TransactionScopeOption.Required, () -> {
        removeDiskFromDb(cinderVolume, updated);
        return null;
    });
}
Also used : Snapshot(org.ovirt.engine.core.common.businessentities.Snapshot)

Example 47 with Snapshot

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

the class RemoveCinderDiskCommand method handleRemoveCinderVolumesForIllegal.

private void handleRemoveCinderVolumesForIllegal() {
    final List<DiskImage> diskSnapshots = diskImageDao.getAllSnapshotsForImageGroup(cinderDisk.getId());
    ImagesHandler.sortImageList(diskSnapshots);
    TransactionSupport.executeInScope(TransactionScopeOption.Required, () -> {
        int indCinderVolumeToDelete = diskSnapshots.size() - 1;
        while (indCinderVolumeToDelete >= 0) {
            CinderDisk cinderVolume = (CinderDisk) diskSnapshots.get(indCinderVolumeToDelete);
            Snapshot updated = getSnapshotWithoutCinderVolume(cinderVolume);
            removeDiskFromDb(cinderVolume, updated);
            indCinderVolumeToDelete--;
        }
        return null;
    });
}
Also used : Snapshot(org.ovirt.engine.core.common.businessentities.Snapshot) CinderDisk(org.ovirt.engine.core.common.businessentities.storage.CinderDisk) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage)

Example 48 with Snapshot

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

the class RemoveImageCommandTest method testRemoveImageFromSnapshotConfiguration.

@Test
public void testRemoveImageFromSnapshotConfiguration() throws OvfReaderException {
    Guid vmId = Guid.newGuid();
    VM vm = new VM();
    vm.setId(vmId);
    vm.setStoragePoolId(Guid.newGuid());
    vm.setVmtName(RandomUtils.instance().nextString(10));
    vm.setOrigin(OriginType.OVIRT);
    vm.setDbGeneration(1L);
    Guid vmSnapshotId = Guid.newGuid();
    DiskImage disk1 = addTestDisk(vm, vmSnapshotId);
    DiskVmElement dve1 = new DiskVmElement(disk1.getId(), vm.getId());
    dve1.setDiskInterface(DiskInterface.VirtIO);
    disk1.setDiskVmElements(Collections.singletonList(dve1));
    DiskImage disk2 = addTestDisk(vm, vmSnapshotId);
    DiskVmElement dve2 = new DiskVmElement(disk2.getId(), vm.getId());
    dve2.setDiskInterface(DiskInterface.IDE);
    disk2.setDiskVmElements(Collections.singletonList(dve2));
    mcr.mockConfigValue(ConfigValues.PassDiscardSupported, Version.getLast(), true);
    mcr.mockConfigValue(ConfigValues.PassDiscardSupported, Version.ALL.get(0), true);
    mcr.mockConfigValue(ConfigValues.MaxNumOfVmSockets, Version.getLast(), 16);
    mcr.mockConfigValue(ConfigValues.MaxNumOfVmSockets, Version.ALL.get(0), 16);
    mcr.mockConfigValue(ConfigValues.MaxNumOfVmCpus, Version.getLast(), 16);
    mcr.mockConfigValue(ConfigValues.MaxNumOfVmCpus, Version.ALL.get(0), 16);
    ArrayList<DiskImage> disks = new ArrayList<>(Arrays.asList(disk1, disk2));
    FullEntityOvfData fullEntityOvfDataForExport = new FullEntityOvfData(vm);
    fullEntityOvfDataForExport.setDiskImages(disks);
    String ovf = ovfManager.exportVm(vm, fullEntityOvfDataForExport, Version.getLast());
    Snapshot snap = new Snapshot();
    snap.setVmConfiguration(ovf);
    snap.setId(vmSnapshotId);
    doReturn(disk2).when(cmd).getDiskImage();
    doReturn(disk2).when(cmd).getImage();
    doReturn(disk2.getId()).when(cmd).getImageId();
    Snapshot actual = imagesHandler.prepareSnapshotConfigWithAlternateImage(snap, disk2.getImageId(), null, ovfManager);
    String actualOvf = actual.getVmConfiguration();
    VM emptyVm = new VM();
    FullEntityOvfData fullEntityOvfData = new FullEntityOvfData(emptyVm);
    ovfManager.importVm(actualOvf, emptyVm, fullEntityOvfData);
    assertEquals("Wrong number of disks", 1, fullEntityOvfData.getDiskImages().size());
    assertEquals("Wrong disk", disk1, fullEntityOvfData.getDiskImages().get(0));
}
Also used : Snapshot(org.ovirt.engine.core.common.businessentities.Snapshot) VM(org.ovirt.engine.core.common.businessentities.VM) ArrayList(java.util.ArrayList) DiskVmElement(org.ovirt.engine.core.common.businessentities.storage.DiskVmElement) Guid(org.ovirt.engine.core.compat.Guid) FullEntityOvfData(org.ovirt.engine.core.common.businessentities.storage.FullEntityOvfData) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) Test(org.junit.Test) BaseCommandTest(org.ovirt.engine.core.bll.BaseCommandTest)

Example 49 with Snapshot

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

the class CreateSnapshotForVmCommand method updateActiveSnapshotId.

private Guid updateActiveSnapshotId() {
    final Snapshot activeSnapshot = snapshotDao.get(getVmId(), Snapshot.SnapshotType.ACTIVE);
    final Guid activeSnapshotId = activeSnapshot.getId();
    TransactionSupport.executeInScope(TransactionScopeOption.Required, () -> {
        getCompensationContext().snapshotEntity(activeSnapshot);
        snapshotDao.updateId(activeSnapshotId, newActiveSnapshotId);
        activeSnapshot.setId(newActiveSnapshotId);
        getCompensationContext().snapshotNewEntity(activeSnapshot);
        getCompensationContext().stateChanged();
        return null;
    });
    return activeSnapshotId;
}
Also used : Snapshot(org.ovirt.engine.core.common.businessentities.Snapshot) Guid(org.ovirt.engine.core.compat.Guid)

Example 50 with Snapshot

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

the class GetAllDiskSnapshotsByStorageDomainIdQuery method executeQueryCommand.

@Override
protected void executeQueryCommand() {
    List<DiskImage> diskImages = diskImageDao.getAllSnapshotsForStorageDomain(getParameters().getId());
    // Filter out active volumes
    diskImages = diskImages.stream().filter(d -> !d.getActive()).collect(Collectors.toList());
    // Retrieving snapshots objects for setting description
    Map<Guid, Snapshot> snapshots = Entities.businessEntitiesById(snapshotDao.getAllByStorageDomain(getParameters().getId()));
    List<DiskImage> diskImagesToReturn = new ArrayList<>();
    for (final DiskImage diskImage : diskImages) {
        Snapshot snapshot = snapshots.get(diskImage.getVmSnapshotId());
        // Verify snapshot is not null to mitigate possible race conditions
        if (snapshot != null) {
            diskImage.setVmSnapshotDescription(snapshot.getDescription());
            diskImagesToReturn.add(diskImage);
        }
    }
    getQueryReturnValue().setReturnValue(diskImagesToReturn);
}
Also used : Snapshot(org.ovirt.engine.core.common.businessentities.Snapshot) ArrayList(java.util.ArrayList) Guid(org.ovirt.engine.core.compat.Guid) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage)

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