Search in sources :

Example 1 with RestoreFromSnapshotParameters

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);
}
Also used : ActionReturnValue(org.ovirt.engine.core.common.action.ActionReturnValue) ImagesContainterParametersBase(org.ovirt.engine.core.common.action.ImagesContainterParametersBase) ArrayList(java.util.ArrayList) CinderDisk(org.ovirt.engine.core.common.businessentities.storage.CinderDisk) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) RestoreFromSnapshotParameters(org.ovirt.engine.core.common.action.RestoreFromSnapshotParameters)

Aggregations

ArrayList (java.util.ArrayList)1 ActionReturnValue (org.ovirt.engine.core.common.action.ActionReturnValue)1 ImagesContainterParametersBase (org.ovirt.engine.core.common.action.ImagesContainterParametersBase)1 RestoreFromSnapshotParameters (org.ovirt.engine.core.common.action.RestoreFromSnapshotParameters)1 CinderDisk (org.ovirt.engine.core.common.businessentities.storage.CinderDisk)1 DiskImage (org.ovirt.engine.core.common.businessentities.storage.DiskImage)1