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