Search in sources :

Example 6 with RemoveSnapshotSingleDiskParameters

use of org.ovirt.engine.core.common.action.RemoveSnapshotSingleDiskParameters in project ovirt-engine by oVirt.

the class MergeStatusCommand method attemptResolution.

public void attemptResolution() {
    Set<Guid> images;
    if (vmDynamicDao.get(getParameters().getVmId()).getStatus().isNotRunning()) {
        StoragePool pool = storagePoolDao.get(getParameters().getStoragePoolId());
        if (pool.getSpmVdsId() == null || pool.getStatus() != StoragePoolStatus.Up) {
            log.info("VM down, waiting on SPM election to resolve Live Merge");
            setSucceeded(true);
            return;
        } else {
            log.error("VM is not running, proceeding with Live Merge recovery");
            images = getVolumeChainFromRecovery();
        }
    } else {
        images = getVolumeChain();
    }
    if (images == null || images.isEmpty()) {
        log.error("Failed to retrieve images list of VM {}. Retrying ...", getParameters().getVmId());
        setCommandStatus(CommandStatus.SUCCEEDED);
        setSucceeded(true);
        // As this command is executed only during live merge flow, the following casting is safe.
        ((RemoveSnapshotSingleDiskParameters) getParameters().getParentParameters()).setNextCommandStep(RemoveSnapshotSingleDiskStep.MERGE_STATUS);
        return;
    }
    Set<Guid> imagesToRemove = getImagesToRemove();
    images.retainAll(imagesToRemove);
    if (images.size() != 1) {
        log.error("Failed to live merge, still in volume chain: {}", images);
        setCommandStatus(CommandStatus.FAILED);
        return;
    }
    if (!images.contains(getParameters().getBaseImage().getImageId())) {
        // If the base image isn't found in qemu chain, it means that the image was already deleted.
        // In this case, we will not allow PULL merge but rather ask the user to check if the parent
        // snapshot contains illegal volume(s). If so, that snapshot must be deleted before deleting
        // other snapshots
        addCustomValue("SnapshotName", snapshotDao.get(getParameters().getBaseImage().getSnapshotId()).getDescription());
        addCustomValue("BaseVolumeId", getParameters().getBaseImage().getImageId().toString());
        auditLog(this, AuditLogType.USER_REMOVE_SNAPSHOT_FINISHED_FAILURE_BASE_IMAGE_NOT_FOUND);
        setCommandStatus(CommandStatus.FAILED);
        return;
    }
    imagesToRemove.removeAll(images);
    log.info("Successfully removed volume(s): {}", imagesToRemove);
    // For now, only COMMIT type is supported
    log.info("Volume merge type '{}'", VmBlockJobType.COMMIT.name());
    MergeStatusReturnValue returnValue = new MergeStatusReturnValue(VmBlockJobType.COMMIT, imagesToRemove);
    getReturnValue().setActionReturnValue(returnValue);
    setSucceeded(true);
    persistCommand(getParameters().getParentCommand(), true);
    setCommandStatus(CommandStatus.SUCCEEDED);
}
Also used : StoragePool(org.ovirt.engine.core.common.businessentities.StoragePool) Guid(org.ovirt.engine.core.compat.Guid) RemoveSnapshotSingleDiskParameters(org.ovirt.engine.core.common.action.RemoveSnapshotSingleDiskParameters) MergeStatusReturnValue(org.ovirt.engine.core.common.action.MergeStatusReturnValue)

Aggregations

RemoveSnapshotSingleDiskParameters (org.ovirt.engine.core.common.action.RemoveSnapshotSingleDiskParameters)6 DiskImage (org.ovirt.engine.core.common.businessentities.storage.DiskImage)3 Guid (org.ovirt.engine.core.compat.Guid)3 MergeStatusReturnValue (org.ovirt.engine.core.common.action.MergeStatusReturnValue)2 ArrayList (java.util.ArrayList)1 ActionReturnValue (org.ovirt.engine.core.common.action.ActionReturnValue)1 EntityInfo (org.ovirt.engine.core.common.asynctasks.EntityInfo)1 StoragePool (org.ovirt.engine.core.common.businessentities.StoragePool)1 CinderDisk (org.ovirt.engine.core.common.businessentities.storage.CinderDisk)1 EngineException (org.ovirt.engine.core.common.errors.EngineException)1 VDSReturnValue (org.ovirt.engine.core.common.vdscommands.VDSReturnValue)1