Search in sources :

Example 1 with RemoveSnapshotSingleDiskParameters

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

the class RemoveDiskSnapshotsCommand method buildRemoveSnapshotSingleDiskLiveParameters.

private RemoveSnapshotSingleDiskParameters buildRemoveSnapshotSingleDiskLiveParameters(Guid imageId, int completedChildren) {
    DiskImage dest = diskImageDao.getAllSnapshotsForParent(imageId).get(0);
    RemoveSnapshotSingleDiskParameters parameters = new RemoveSnapshotSingleDiskParameters(imageId, getVmId());
    parameters.setDestinationImageId(dest.getImageId());
    parameters.setEntityInfo(getParameters().getEntityInfo());
    parameters.setParentParameters(getParameters());
    parameters.setParentCommand(getActionType());
    parameters.setCommandType(ActionType.RemoveSnapshotSingleDiskLive);
    parameters.setVdsId(getVm().getRunOnVds());
    parameters.setSessionId(getParameters().getSessionId());
    parameters.setEndProcedure(EndProcedure.COMMAND_MANAGED);
    return parameters;
}
Also used : RemoveSnapshotSingleDiskParameters(org.ovirt.engine.core.common.action.RemoveSnapshotSingleDiskParameters) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage)

Example 2 with RemoveSnapshotSingleDiskParameters

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

the class RemoveDiskSnapshotsCommand method buildRemoveSnapshotSingleDiskParameters.

private ImagesContainterParametersBase buildRemoveSnapshotSingleDiskParameters(Guid imageId) {
    RemoveSnapshotSingleDiskParameters parameters = new RemoveSnapshotSingleDiskParameters(imageId, getVmId());
    DiskImage dest = diskImageDao.getAllSnapshotsForParent(imageId).get(0);
    parameters.setDestinationImageId(dest.getImageId());
    parameters.setEntityInfo(getParameters().getEntityInfo());
    parameters.setParentParameters(getParameters());
    parameters.setParentCommand(getActionType());
    parameters.setWipeAfterDelete(dest.isWipeAfterDelete());
    parameters.setSessionId(getParameters().getSessionId());
    parameters.setVmSnapshotId(diskImageDao.getSnapshotById(imageId).getVmSnapshotId());
    parameters.setEndProcedure(EndProcedure.COMMAND_MANAGED);
    return parameters;
}
Also used : RemoveSnapshotSingleDiskParameters(org.ovirt.engine.core.common.action.RemoveSnapshotSingleDiskParameters) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage)

Example 3 with RemoveSnapshotSingleDiskParameters

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

Example 4 with RemoveSnapshotSingleDiskParameters

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

the class RemoveSnapshotCommand method buildRemoveSnapshotSingleDiskParameters.

private RemoveSnapshotSingleDiskParameters buildRemoveSnapshotSingleDiskParameters(final DiskImage source, DiskImage dest, ActionType snapshotActionType) {
    RemoveSnapshotSingleDiskParameters parameters = new RemoveSnapshotSingleDiskParameters(source.getImageId(), getVmId());
    parameters.setStorageDomainId(source.getStorageIds().get(0));
    parameters.setDestinationImageId(dest != null ? dest.getImageId() : null);
    parameters.setEntityInfo(getParameters().getEntityInfo());
    parameters.setParentParameters(getParameters());
    parameters.setParentCommand(getActionType());
    parameters.setCommandType(snapshotActionType);
    parameters.setVdsId(getVm().getRunOnVds());
    parameters.setEndProcedure(EndProcedure.COMMAND_MANAGED);
    return parameters;
}
Also used : RemoveSnapshotSingleDiskParameters(org.ovirt.engine.core.common.action.RemoveSnapshotSingleDiskParameters)

Example 5 with RemoveSnapshotSingleDiskParameters

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

the class DestroyImageCommand method executeCommand.

@Override
protected void executeCommand() {
    getParameters().setEntityInfo(new EntityInfo(VdcObjectType.Disk, getParameters().getImageGroupId()));
    VDSReturnValue vdsReturnValue = null;
    try {
        vdsReturnValue = runVdsCommand(VDSCommandType.DestroyImage, createVDSParameters());
    } catch (EngineException e) {
        log.error("Failed to delete image {}/{}", getParameters().getImageGroupId(), getParameters().getImageList().stream().findFirst().get(), e);
        if (!getParameters().isLiveMerge()) {
            throw e;
        }
    }
    if (vdsReturnValue != null && vdsReturnValue.getCreationInfo() != null) {
        Guid taskId = persistAsyncTaskPlaceHolder(getParameters().getParentCommand());
        Guid result = createTask(taskId, vdsReturnValue.getCreationInfo(), getParameters().getParentCommand(), VdcObjectType.Storage, getParameters().getStorageDomainId());
        getTaskIdList().add(result);
        log.info("Successfully started task to remove orphaned volumes resulting from live merge");
    } else {
        log.info("Retrying deleting image {}/{}", getParameters().getImageGroupId(), getParameters().getImageList().stream().findFirst().get());
        MergeStatusReturnValue returnValue = new MergeStatusReturnValue(VmBlockJobType.COMMIT, new HashSet<>(getParameters().getImageList()));
        getReturnValue().setActionReturnValue(returnValue);
        // At this point, we know that this command was executed during live merge and it is safe to do
        // the casting in the next line.
        ((RemoveSnapshotSingleDiskParameters) getParameters().getParentParameters()).setNextCommandStep(RemoveSnapshotSingleDiskStep.DESTROY_IMAGE);
    }
    setSucceeded(true);
    setCommandStatus(CommandStatus.SUCCEEDED);
}
Also used : EntityInfo(org.ovirt.engine.core.common.asynctasks.EntityInfo) EngineException(org.ovirt.engine.core.common.errors.EngineException) Guid(org.ovirt.engine.core.compat.Guid) RemoveSnapshotSingleDiskParameters(org.ovirt.engine.core.common.action.RemoveSnapshotSingleDiskParameters) VDSReturnValue(org.ovirt.engine.core.common.vdscommands.VDSReturnValue) 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