use of org.ovirt.engine.core.common.businessentities.Snapshot in project ovirt-engine by oVirt.
the class CreateSnapshotForVmCommand method performNextOperation.
@Override
public boolean performNextOperation(int completedChildCount) {
if (getParameters().getCreateSnapshotStage() == CreateSnapshotForVmParameters.CreateSnapshotStage.CREATE_VOLUME) {
Snapshot createdSnapshot = snapshotDao.get(getParameters().getCreatedSnapshotId());
// if the snapshot was not created in the DB
// the command should also be handled as a failure
getParameters().setTaskGroupSuccess(createdSnapshot != null && getParameters().getTaskGroupSuccess());
if (getParameters().getTaskGroupSuccess()) {
snapshotDao.updateStatus(createdSnapshot.getId(), Snapshot.SnapshotStatus.OK);
getParameters().setLiveSnapshotRequired(shouldPerformLiveSnapshot(createdSnapshot));
if (getParameters().isLiveSnapshotRequired()) {
getParameters().setLiveSnapshotSucceeded(performLiveSnapshot(createdSnapshot));
} else if (snapshotWithMemory(createdSnapshot)) {
logMemorySavingFailed();
snapshotDao.removeMemoryFromSnapshot(createdSnapshot.getId());
removeMemoryVolumesOfSnapshot(createdSnapshot);
}
} else {
if (createdSnapshot != null) {
revertToActiveSnapshot(createdSnapshot.getId());
// Note that the memory volumes might not have been created
if (snapshotWithMemory(createdSnapshot)) {
removeMemoryVolumesOfSnapshot(createdSnapshot);
}
} else {
log.warn("No snapshot was created for VM '{}' which is in LOCKED status", getVmId());
}
}
getParameters().setCreateSnapshotStage(CreateSnapshotForVmParameters.CreateSnapshotStage.CREATE_SNAPSHOT_COMPLETED);
return true;
}
return false;
}
use of org.ovirt.engine.core.common.businessentities.Snapshot in project ovirt-engine by oVirt.
the class GetAllVmSnapshotsWithLeasesFromConfigurationByVmIdQuery method executeQueryCommand.
@Override
protected void executeQueryCommand() {
Map<Snapshot, Guid> snapshotLeaseDomainIdMap = new HashMap<>();
SnapshotVmConfigurationHelper snapshotVmConfigurationHelper = getSnapshotVmConfigurationHelper();
List<Snapshot> snapshots = snapshotDao.getAllWithConfiguration(getParameters().getId());
for (Snapshot snapshot : snapshots) {
VM vm = snapshotVmConfigurationHelper.getVmFromConfiguration(snapshot.getVmConfiguration(), snapshot.getVmId(), snapshot.getId());
if (vm != null) {
snapshot.setDiskImages(vm.getImages());
snapshotLeaseDomainIdMap.put(snapshot, vm.getLeaseStorageDomainId());
}
}
getQueryReturnValue().setReturnValue(snapshotLeaseDomainIdMap);
}
use of org.ovirt.engine.core.common.businessentities.Snapshot in project ovirt-engine by oVirt.
the class RemoveSnapshotCommand method getAllDisksSnapshot.
/**
* The base snapshot is the parent of the top snapshot. This is reversed the if old cold merge
* is performed (pre-4.1).
*
* @param snapshots list of the parent snapshot disks
* @return list of subchains which contain the base and top snapshots.
*/
protected List<SubchainInfo> getAllDisksSnapshot(List<DiskImage> snapshots) {
Set<DiskImage> topSnapshots = diskImageDao.getAllSnapshotsForParents(snapshots.stream().map(DiskImage::getImageId).collect(Collectors.toList()));
Map<Guid, DiskImage> baseSnapshotMap = snapshots.stream().collect(Collectors.toMap(DiskImage::getImageId, Function.identity()));
return topSnapshots.stream().map(topSnapshot -> {
if (!isQemuimgCommitSupported() && getSnapshotActionType() == ActionType.RemoveSnapshotSingleDisk) {
return new SubchainInfo(topSnapshot, baseSnapshotMap.get(topSnapshot.getParentId()));
} else {
return new SubchainInfo(baseSnapshotMap.get(topSnapshot.getParentId()), topSnapshot);
}
}).collect(Collectors.toList());
}
use of org.ovirt.engine.core.common.businessentities.Snapshot in project ovirt-engine by oVirt.
the class RemoveSnapshotCommand method executeCommand.
@Override
protected void executeCommand() {
if (!getVm().isDown() && !getVm().isQualifiedForSnapshotMerge()) {
log.error("Cannot remove VM snapshot. Vm is not Down, Up or Paused");
throw new EngineException(EngineError.VM_NOT_QUALIFIED_FOR_SNAPSHOT_MERGE);
}
final Snapshot snapshot = snapshotDao.get(getParameters().getSnapshotId());
boolean snapshotHasImages = hasImages();
boolean removeSnapshotMemory = isMemoryVolumeRemoveable(snapshot);
// No need for locking, VDSM tasks, and all that jazz.
if (!snapshotHasImages && !removeSnapshotMemory) {
snapshotDao.remove(getParameters().getSnapshotId());
setSucceeded(true);
return;
}
lockSnapshot(snapshot);
if (getParameters().isFreeLockNeeded()) {
freeLock();
}
getParameters().setEntityInfo(new EntityInfo(VdcObjectType.VM, getVmId()));
boolean useTaskManagerToRemoveMemory = false;
if (snapshotHasImages) {
removeImages();
if (getSnapshotActionType() == ActionType.RemoveSnapshotSingleDiskLive) {
persistCommand(getParameters().getParentCommand(), true);
useTaskManagerToRemoveMemory = true;
}
}
if (removeSnapshotMemory) {
removeMemory(snapshot, useTaskManagerToRemoveMemory);
if (!snapshotHasImages) {
// no async tasks - ending command manually
endVmCommand();
}
}
setSucceeded(true);
}
use of org.ovirt.engine.core.common.businessentities.Snapshot in project ovirt-engine by oVirt.
the class RemoveSnapshotSingleDiskCommand method endSuccessfully.
@Override
protected void endSuccessfully() {
// original state (before the merge-attempt).
if (getDestinationDiskImage() != null) {
Set<Guid> imagesToUpdate = new HashSet<>();
DiskImage curr = getDestinationDiskImage();
while (!curr.getParentId().equals(getDiskImage().getParentId())) {
curr = diskImageDao.getSnapshotById(curr.getParentId());
imagesToUpdate.add(curr.getImageId());
}
syncDbRecords(VmBlockJobType.PULL, getImageInfoFromVdsm(getDestinationDiskImage()), imagesToUpdate, true);
}
if (getParameters().getVmSnapshotId() != null) {
lockVmSnapshotsWithWait(getVm());
Snapshot snapshot = snapshotDao.get(getParameters().getVmSnapshotId());
Snapshot snapshotWithoutImage = imagesHandler.prepareSnapshotConfigWithoutImageSingleImage(snapshot, getParameters().getImageId(), ovfManager);
snapshotDao.update(snapshotWithoutImage);
if (getSnapshotsEngineLock() != null) {
lockManager.releaseLock(getSnapshotsEngineLock());
}
}
setSucceeded(true);
}
Aggregations