use of org.ovirt.engine.core.common.action.RestoreFromSnapshotParameters in project ovirt-engine by oVirt.
the class RestoreAllSnapshotsCommand method executeVmCommand.
@Override
protected void executeVmCommand() {
if (!getImagesList().isEmpty()) {
lockVmWithCompensationIfNeeded();
if (!isInternalExecution()) {
freeLock();
}
}
initializeSnapshotsLeasesDomainIds();
restoreSnapshotAndRemoveObsoleteSnapshots(getSnapshot());
boolean succeeded = removeLeaseIfNeeded();
List<CinderDisk> cinderDisksToRestore = new ArrayList<>();
for (DiskImage image : imagesToRestore) {
if (image.getImageStatus() != ImageStatus.ILLEGAL) {
if (image.getDiskStorageType() == DiskStorageType.CINDER) {
cinderDisksToRestore.add((CinderDisk) image);
continue;
}
ImagesContainterParametersBase params = new RestoreFromSnapshotParameters(image.getImageId(), getVmId(), getSnapshot(), removedSnapshot.getId());
ActionReturnValue returnValue = runAsyncTask(ActionType.RestoreFromSnapshot, params);
// Save the first fault
if (succeeded && !returnValue.getSucceeded()) {
succeeded = false;
getReturnValue().setFault(returnValue.getFault());
}
}
}
List<CinderDisk> cinderVolumesToRemove = new ArrayList<>();
List<CinderDisk> cinderDisksToRemove = new ArrayList<>();
removeUnusedImages(cinderVolumesToRemove);
if (getSnapshot().getType() == SnapshotType.REGULAR) {
snapshotsToRemove.addAll(findSnapshotsWithOnlyIllegalDisks());
setNewerVmConfigurationsAsBroken();
}
removeSnapshotsFromDB();
succeeded = updateLeaseInfoIfNeeded() && succeeded;
if (!getTaskIdList().isEmpty() || !cinderDisksToRestore.isEmpty() || !cinderVolumesToRemove.isEmpty()) {
deleteOrphanedImages(cinderDisksToRemove);
if (!restoreCinderDisks(removedSnapshot.getId(), cinderDisksToRestore, cinderDisksToRemove, cinderVolumesToRemove)) {
log.error("Error to restore Cinder volumes snapshots");
}
} else {
vmStaticDao.incrementDbGeneration(getVm().getId());
snapshotDao.updateStatus(getSnapshot().getId(), SnapshotStatus.OK);
unlockVm();
}
setSucceeded(succeeded);
}
Aggregations