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