use of org.ovirt.engine.core.common.businessentities.Snapshot in project ovirt-engine by oVirt.
the class RemoveDiskSnapshotsCommand method removeCinderSnapshotDisks.
private void removeCinderSnapshotDisks() {
List<CinderDisk> cinderDisks = DisksFilter.filterCinderDisks(getImages());
if (cinderDisks.isEmpty()) {
return;
}
Future<ActionReturnValue> future = commandCoordinatorUtil.executeAsyncCommand(ActionType.RemoveAllCinderSnapshotDisks, buildRemoveCinderSnapshotDiskParameters(cinderDisks), cloneContextAndDetachFromParent());
try {
ActionReturnValue actionReturnValue = future.get();
if (!actionReturnValue.getSucceeded()) {
log.error("Error removing snapshots for Cinder disks");
endWithFailure();
getParameters().setTaskGroupSuccess(false);
} else {
Snapshot snapshotWithoutImage = null;
Snapshot snapshot = snapshotDao.get(cinderDisks.get(0).getSnapshotId());
lockVmSnapshotsWithWait(getVm());
for (CinderDisk cinderDisk : cinderDisks) {
snapshotWithoutImage = imagesHandler.prepareSnapshotConfigWithoutImageSingleImage(snapshot, cinderDisk.getImageId(), ovfManager);
}
snapshotDao.update(snapshotWithoutImage);
if (getSnapshotsEngineLock() != null) {
lockManager.releaseLock(getSnapshotsEngineLock());
}
endSuccessfully();
getParameters().setTaskGroupSuccess(true);
}
} catch (InterruptedException | ExecutionException e) {
log.error("Error removing snapshots for Cinder disks");
endWithFailure();
getParameters().setTaskGroupSuccess(false);
}
}
use of org.ovirt.engine.core.common.businessentities.Snapshot in project ovirt-engine by oVirt.
the class SnapshotsManager method updateImagesByConfiguration.
private boolean updateImagesByConfiguration(VM vm, List<DiskImage> images) {
Map<Guid, VM> snapshotVmConfigurations = new HashMap<>();
ArrayList<DiskImage> imagesFromVmConf = new ArrayList<>();
for (DiskImage image : images) {
Guid vmSnapshotId = image.getVmSnapshotId();
VM vmFromConf = snapshotVmConfigurations.get(vmSnapshotId);
if (vmFromConf == null) {
vmFromConf = new VM();
Snapshot snapshot = snapshotDao.get(image.getVmSnapshotId());
if (!updateVmFromConfiguration(vmFromConf, snapshot.getVmConfiguration())) {
return false;
}
snapshotVmConfigurations.put(vmSnapshotId, vmFromConf);
}
for (DiskImage imageFromVmConf : vmFromConf.getImages()) {
if (imageFromVmConf.getId().equals(image.getId())) {
imageFromVmConf.setStorageIds(image.getStorageIds());
imagesFromVmConf.add(imageFromVmConf);
break;
}
}
}
vm.setImages(imagesFromVmConf);
return true;
}
use of org.ovirt.engine.core.common.businessentities.Snapshot in project ovirt-engine by oVirt.
the class SnapshotsManager method addSnapshot.
/**
*addSnapshot
* Save snapshot to DB with compensation data.
*
* @param snapshotId
* The snapshot ID.
* @param description
* The snapshot description.
* @param snapshotStatus
* The snapshot status.
* @param snapshotType
* The snapshot type.
* @param vm
* The VM to link to & save configuration for (if necessary).
* @param saveVmConfiguration
* Should VM configuration be generated and saved?
* @param memoryDumpDiskId
* The memory dump disk ID
* @param memoryConfDiskId
* The memory metadata disk ID
* @param creationDate
* predefined creation date for the snapshot, null indicates 'now'
* @param disks
* The disks contained in the snapshot
* @param vmDevices
* The devices contained in the snapshot
* @param compensationContext
* In case compensation is needed.
* @return the saved snapshot
*/
public Snapshot addSnapshot(Guid snapshotId, String description, SnapshotStatus snapshotStatus, SnapshotType snapshotType, VM vm, boolean saveVmConfiguration, Guid memoryDumpDiskId, Guid memoryConfDiskId, Date creationDate, List<DiskImage> disks, Map<Guid, VmDevice> vmDevices, final CompensationContext compensationContext) {
final Snapshot snapshot = new Snapshot(snapshotId, snapshotStatus, vm.getId(), saveVmConfiguration ? generateVmConfiguration(vm, disks, vmDevices) : null, snapshotType, description, creationDate != null ? creationDate : new Date(), vm.getAppList(), memoryDumpDiskId, memoryConfDiskId);
snapshotDao.save(snapshot);
compensationContext.snapshotNewEntity(snapshot);
return snapshot;
}
use of org.ovirt.engine.core.common.businessentities.Snapshot in project ovirt-engine by oVirt.
the class TryBackToAllSnapshotsOfVmCommand method endWithFailure.
@Override
protected void endWithFailure() {
Snapshot previouslyActiveSnapshot = snapshotDao.get(getVmId(), SnapshotType.PREVIEW, SnapshotStatus.LOCKED);
snapshotDao.remove(previouslyActiveSnapshot.getId());
snapshotDao.remove(snapshotDao.getId(getVmId(), SnapshotType.ACTIVE));
getSnapshotsManager().addActiveSnapshot(previouslyActiveSnapshot.getId(), getVm(), SnapshotStatus.OK, previouslyActiveSnapshot.getMemoryDiskId(), previouslyActiveSnapshot.getMetadataDiskId(), getCompensationContext());
super.endWithFailure();
}
use of org.ovirt.engine.core.common.businessentities.Snapshot in project ovirt-engine by oVirt.
the class TryBackToAllSnapshotsOfVmCommand method executeVmCommand.
@Override
protected void executeVmCommand() {
final boolean restoreMemory = isRestoreMemory();
final Guid newActiveSnapshotId = Guid.newGuid();
final Snapshot snapshotToBePreviewed = getDstSnapshot();
final Snapshot previousActiveSnapshot = snapshotDao.get(getVmId(), SnapshotType.ACTIVE);
final Guid previousActiveSnapshotId = previousActiveSnapshot.getId();
final List<DiskImage> images = getImagesToPreview();
// Images list without those that are excluded from preview
final List<DiskImage> filteredImages = (List<DiskImage>) CollectionUtils.subtract(images, getImagesExcludedFromPreview(images, previousActiveSnapshotId, newActiveSnapshotId));
if (log.isInfoEnabled()) {
log.info("Previewing snapshot {} with the disks:\n{}", getSnapshotName(), filteredImages.stream().map(disk -> String.format("%s (%s) to imageId %s", disk.getName(), disk.getId().toString(), disk.getImageId().toString())).collect(Collectors.joining("\n")));
}
final List<CinderDisk> cinderDisks = new ArrayList<>();
TransactionSupport.executeInNewTransaction(() -> {
getCompensationContext().snapshotEntity(previousActiveSnapshot);
snapshotDao.remove(previousActiveSnapshotId);
getSnapshotsManager().addSnapshot(previousActiveSnapshotId, "Active VM before the preview", SnapshotStatus.LOCKED, SnapshotType.PREVIEW, getVm(), true, previousActiveSnapshot.getMemoryDiskId(), previousActiveSnapshot.getMetadataDiskId(), null, null, null, getCompensationContext());
getSnapshotsManager().addActiveSnapshot(newActiveSnapshotId, getVm(), SnapshotStatus.OK, restoreMemory ? snapshotToBePreviewed.getMemoryDiskId() : null, restoreMemory ? snapshotToBePreviewed.getMetadataDiskId() : null, snapshotToBePreviewed.getCreationDate(), images, getCompensationContext());
// being executed in the same transaction so we can restore the vm config and end the command.
if (!filteredImages.isEmpty()) {
getCompensationContext().stateChanged();
} else {
vmStaticDao.incrementDbGeneration(getVm().getId());
restoreVmConfigFromSnapshot();
}
return null;
});
initializeSnapshotsLeasesParams();
if (!filteredImages.isEmpty()) {
vmHandler.lockVm(getVm().getDynamicData(), getCompensationContext());
freeLock();
TransactionSupport.executeInNewTransaction(new TransactionMethod<Void>() {
@Override
public Void runInTransaction() {
for (DiskImage image : filteredImages) {
if (image.getDiskStorageType() == DiskStorageType.CINDER) {
cinderDisks.add((CinderDisk) image);
continue;
}
ActionReturnValue actionReturnValue = runInternalActionWithTasksContext(ActionType.TryBackToSnapshot, buildTryBackToSnapshotParameters(newActiveSnapshotId, image));
if (actionReturnValue.getSucceeded()) {
getTaskIdList().addAll(actionReturnValue.getInternalVdsmTaskIdList());
} else if (actionReturnValue.getFault() != null) {
// if we have a fault, forward it to the user
throw new EngineException(actionReturnValue.getFault().getError(), actionReturnValue.getFault().getMessage());
} else {
log.error("Cannot create snapshot");
throw new EngineException(EngineError.IRS_IMAGE_STATUS_ILLEGAL);
}
}
if (getParameters().getLeaseAction() == LeaseAction.CREATE_NEW_LEASE) {
if (!addVmLease(getParameters().getDstLeaseDomainId(), getVm().getId(), false)) {
log.error("Failed to create lease for VM '{}' on storage domain '{}'", getVm().getName(), getParameters().getDstLeaseDomainId());
throw new EngineException(EngineError.FailedToCreateLease);
}
}
if (!cinderDisks.isEmpty() && !tryBackAllCinderDisks(cinderDisks, newActiveSnapshotId)) {
throw new EngineException(EngineError.CINDER_ERROR, "Failed to preview a snapshot!");
}
return null;
}
private ImagesContainterParametersBase buildTryBackToSnapshotParameters(final Guid newActiveSnapshotId, DiskImage image) {
ImagesContainterParametersBase params = new ImagesContainterParametersBase(image.getImageId());
params.setParentCommand(ActionType.TryBackToAllSnapshotsOfVm);
params.setVmSnapshotId(newActiveSnapshotId);
params.setEntityInfo(getParameters().getEntityInfo());
params.setParentParameters(getParameters());
params.setQuotaId(image.getQuotaId());
return params;
}
});
} else {
// if there are no disks to restore, no compensation context is saved and the VM Configuration
// (including clusterCompatibilityVersionOrigin) is already restored at this point. Otherwise,
// if disks are being restored, the VM Configuration is restored later in endSuccessfully()
updateClusterCompatibilityVersionToOldCluster(true);
}
setSucceeded(true);
}
Aggregations