use of org.ovirt.engine.core.common.businessentities.storage.CinderDisk 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.storage.CinderDisk in project ovirt-engine by oVirt.
the class TryBackToAllSnapshotsOfVmCommand method tryBackAllCinderDisks.
protected boolean tryBackAllCinderDisks(List<CinderDisk> cinderDisks, Guid newSnapshotId) {
for (CinderDisk disk : cinderDisks) {
ImagesContainterParametersBase params = buildCinderChildCommandParameters(disk, newSnapshotId);
ActionReturnValue actionReturnValue = runInternalAction(ActionType.TryBackToCinderSnapshot, params, cloneContextAndDetachFromParent());
if (!actionReturnValue.getSucceeded()) {
log.error("Error cloning Cinder disk for preview. '{}': {}", disk.getDiskAlias());
getReturnValue().setFault(actionReturnValue.getFault());
return false;
}
}
return true;
}
use of org.ovirt.engine.core.common.businessentities.storage.CinderDisk 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);
}
use of org.ovirt.engine.core.common.businessentities.storage.CinderDisk in project ovirt-engine by oVirt.
the class RestoreAllSnapshotsCommand method restoreSnapshotAndRemoveObsoleteSnapshots.
/**
* Restore the snapshot - if it is not the active snapshot, then the VM configuration will be restored.<br>
* Additionally, remove all obsolete snapshots (The one after stateless, or the preview chain which was not chosen).
*/
protected void restoreSnapshotAndRemoveObsoleteSnapshots(Snapshot targetSnapshot) {
Guid activeSnapshotId = snapshotDao.getId(getVmId(), SnapshotType.ACTIVE);
List<DiskImage> imagesFromActiveSnapshot = diskImageDao.getAllSnapshotsForVmSnapshot(activeSnapshotId);
Snapshot previewedSnapshot = snapshotDao.get(getVmId(), SnapshotType.PREVIEW);
if (previewedSnapshot != null) {
VM vmFromConf = snapshotVmConfigurationHelper.getVmFromConfiguration(previewedSnapshot.getVmConfiguration(), previewedSnapshot.getVmId(), previewedSnapshot.getId());
List<DiskImage> previewedImagesFromDB = diskImageDao.getAllSnapshotsForVmSnapshot(previewedSnapshot.getId());
imagesFromPreviewSnapshot.addAll(ImagesHandler.imagesIntersection(vmFromConf.getImages(), previewedImagesFromDB));
}
List<DiskImage> intersection = ImagesHandler.imagesIntersection(imagesFromActiveSnapshot, imagesFromPreviewSnapshot);
switch(targetSnapshot.getType()) {
case PREVIEW:
snapshotDao.updateStatus(snapshotDao.getId(getVmId(), SnapshotType.REGULAR, SnapshotStatus.IN_PREVIEW), SnapshotStatus.OK);
getParameters().setImages((List<DiskImage>) CollectionUtils.union(imagesFromPreviewSnapshot, intersection));
imagesFromPreviewSnapshot.forEach(image -> {
if (image.getDiskStorageType() != DiskStorageType.CINDER) {
imagesToRestore.add(image);
} else {
List<DiskImage> cinderDiskFromPreviewSnapshot = intersection.stream().filter(diskImage -> diskImage.getId().equals(image.getId())).collect(Collectors.toList());
if (!cinderDiskFromPreviewSnapshot.isEmpty()) {
imagesToRestore.add(cinderDiskFromPreviewSnapshot.get(0));
}
}
});
updateSnapshotIdForSkipRestoreImages(ImagesHandler.imagesSubtract(imagesFromActiveSnapshot, imagesToRestore), targetSnapshot.getId());
restoreConfiguration(targetSnapshot);
break;
case STATELESS:
imagesToRestore = getParameters().getImages();
restoreConfiguration(targetSnapshot);
break;
case REGULAR:
prepareToDeletePreviewBranch(imagesFromActiveSnapshot);
// Set the active snapshot's images as target images for restore, because they are what we keep.
getParameters().setImages(imagesFromActiveSnapshot);
imagesFromActiveSnapshot.forEach(image -> {
List<DiskImage> cinderDiskFromPreviewSnapshot = imagesFromPreviewSnapshot.stream().filter(diskImage -> diskImage.getId().equals(image.getId())).collect(Collectors.toList());
if (!cinderDiskFromPreviewSnapshot.isEmpty()) {
if (image.getDiskStorageType() == DiskStorageType.IMAGE) {
imagesToRestore.add(image);
} else if (image.getDiskStorageType() == DiskStorageType.CINDER) {
CinderDisk cinderVolume = getInitialCinderVolumeToDelete(image);
if (cinderVolume != null) {
imagesToRestore.add(cinderVolume);
}
}
}
});
updateSnapshotIdForSkipRestoreImages(ImagesHandler.imagesSubtract(imagesFromActiveSnapshot, imagesToRestore), activeSnapshotId);
break;
default:
throw new EngineException(EngineError.ENGINE, "No support for restoring to snapshot type: " + targetSnapshot.getType());
}
}
use of org.ovirt.engine.core.common.businessentities.storage.CinderDisk in project ovirt-engine by oVirt.
the class RemoveSnapshotCommand method removeImages.
private void removeImages() {
List<CinderDisk> cinderDisks = new ArrayList<>();
for (final DiskImage source : getSourceImages()) {
if (source.getDiskStorageType() == DiskStorageType.CINDER) {
cinderDisks.add((CinderDisk) source);
continue;
}
// The following is ok because we have tested in the validate that the vm
// is not a template and the vm is not in preview mode and that
// this is not the active snapshot.
List<DiskImage> images = diskImageDao.getAllSnapshotsForParent(source.getImageId());
DiskImage dest = null;
if (!images.isEmpty()) {
dest = images.get(0);
}
if (getSnapshotActionType() == ActionType.RemoveSnapshotSingleDiskLive) {
commandCoordinatorUtil.executeAsyncCommand(getSnapshotActionType(), buildRemoveSnapshotSingleDiskParameters(source, dest, getSnapshotActionType()), cloneContextAndDetachFromParent());
} else {
RemoveSnapshotSingleDiskParameters parameters = buildRemoveSnapshotSingleDiskParameters(source, dest, getSnapshotActionType());
ActionReturnValue actionReturnValueturnValue = runInternalActionWithTasksContext(getSnapshotActionType(), parameters);
getTaskIdList().addAll(actionReturnValueturnValue.getInternalVdsmTaskIdList());
}
List<Guid> quotasToRemoveFromCache = new ArrayList<>();
quotasToRemoveFromCache.add(source.getQuotaId());
if (dest != null) {
quotasToRemoveFromCache.add(dest.getQuotaId());
}
getQuotaManager().removeQuotaFromCache(getStoragePoolId(), quotasToRemoveFromCache);
}
if (!cinderDisks.isEmpty()) {
handleCinderSnapshotDisks(cinderDisks);
}
}
Aggregations