Search in sources :

Example 16 with Snapshot

use of org.ovirt.engine.core.common.businessentities.Snapshot in project ovirt-engine by oVirt.

the class CreateSnapshotForVmCommand method performNextOperation.

@Override
public boolean performNextOperation(int completedChildCount) {
    if (getParameters().getCreateSnapshotStage() == CreateSnapshotForVmParameters.CreateSnapshotStage.CREATE_VOLUME) {
        Snapshot createdSnapshot = snapshotDao.get(getParameters().getCreatedSnapshotId());
        // if the snapshot was not created in the DB
        // the command should also be handled as a failure
        getParameters().setTaskGroupSuccess(createdSnapshot != null && getParameters().getTaskGroupSuccess());
        if (getParameters().getTaskGroupSuccess()) {
            snapshotDao.updateStatus(createdSnapshot.getId(), Snapshot.SnapshotStatus.OK);
            getParameters().setLiveSnapshotRequired(shouldPerformLiveSnapshot(createdSnapshot));
            if (getParameters().isLiveSnapshotRequired()) {
                getParameters().setLiveSnapshotSucceeded(performLiveSnapshot(createdSnapshot));
            } else if (snapshotWithMemory(createdSnapshot)) {
                logMemorySavingFailed();
                snapshotDao.removeMemoryFromSnapshot(createdSnapshot.getId());
                removeMemoryVolumesOfSnapshot(createdSnapshot);
            }
        } else {
            if (createdSnapshot != null) {
                revertToActiveSnapshot(createdSnapshot.getId());
                // Note that the memory volumes might not have been created
                if (snapshotWithMemory(createdSnapshot)) {
                    removeMemoryVolumesOfSnapshot(createdSnapshot);
                }
            } else {
                log.warn("No snapshot was created for VM '{}' which is in LOCKED status", getVmId());
            }
        }
        getParameters().setCreateSnapshotStage(CreateSnapshotForVmParameters.CreateSnapshotStage.CREATE_SNAPSHOT_COMPLETED);
        return true;
    }
    return false;
}
Also used : Snapshot(org.ovirt.engine.core.common.businessentities.Snapshot)

Example 17 with Snapshot

use of org.ovirt.engine.core.common.businessentities.Snapshot in project ovirt-engine by oVirt.

the class GetAllVmSnapshotsWithLeasesFromConfigurationByVmIdQuery method executeQueryCommand.

@Override
protected void executeQueryCommand() {
    Map<Snapshot, Guid> snapshotLeaseDomainIdMap = new HashMap<>();
    SnapshotVmConfigurationHelper snapshotVmConfigurationHelper = getSnapshotVmConfigurationHelper();
    List<Snapshot> snapshots = snapshotDao.getAllWithConfiguration(getParameters().getId());
    for (Snapshot snapshot : snapshots) {
        VM vm = snapshotVmConfigurationHelper.getVmFromConfiguration(snapshot.getVmConfiguration(), snapshot.getVmId(), snapshot.getId());
        if (vm != null) {
            snapshot.setDiskImages(vm.getImages());
            snapshotLeaseDomainIdMap.put(snapshot, vm.getLeaseStorageDomainId());
        }
    }
    getQueryReturnValue().setReturnValue(snapshotLeaseDomainIdMap);
}
Also used : Snapshot(org.ovirt.engine.core.common.businessentities.Snapshot) HashMap(java.util.HashMap) VM(org.ovirt.engine.core.common.businessentities.VM) Guid(org.ovirt.engine.core.compat.Guid)

Example 18 with Snapshot

use of org.ovirt.engine.core.common.businessentities.Snapshot in project ovirt-engine by oVirt.

the class RemoveSnapshotCommand method getAllDisksSnapshot.

/**
 * The base snapshot is the parent of the top snapshot. This is reversed the if old cold merge
 * is performed (pre-4.1).
 *
 * @param snapshots list of the parent snapshot disks
 * @return list of subchains which contain the base and top snapshots.
 */
protected List<SubchainInfo> getAllDisksSnapshot(List<DiskImage> snapshots) {
    Set<DiskImage> topSnapshots = diskImageDao.getAllSnapshotsForParents(snapshots.stream().map(DiskImage::getImageId).collect(Collectors.toList()));
    Map<Guid, DiskImage> baseSnapshotMap = snapshots.stream().collect(Collectors.toMap(DiskImage::getImageId, Function.identity()));
    return topSnapshots.stream().map(topSnapshot -> {
        if (!isQemuimgCommitSupported() && getSnapshotActionType() == ActionType.RemoveSnapshotSingleDisk) {
            return new SubchainInfo(topSnapshot, baseSnapshotMap.get(topSnapshot.getParentId()));
        } else {
            return new SubchainInfo(baseSnapshotMap.get(topSnapshot.getParentId()), topSnapshot);
        }
    }).collect(Collectors.toList());
}
Also used : LockMessagesMatchUtil(org.ovirt.engine.core.bll.LockMessagesMatchUtil) StringUtils(org.apache.commons.lang.StringUtils) CinderDisk(org.ovirt.engine.core.common.businessentities.storage.CinderDisk) RemoveSnapshotParameters(org.ovirt.engine.core.common.action.RemoveSnapshotParameters) EngineException(org.ovirt.engine.core.common.errors.EngineException) SnapshotDao(org.ovirt.engine.core.dao.SnapshotDao) ActionReturnValue(org.ovirt.engine.core.common.action.ActionReturnValue) VmTemplateDao(org.ovirt.engine.core.dao.VmTemplateDao) CommandContext(org.ovirt.engine.core.bll.context.CommandContext) ActionType(org.ovirt.engine.core.common.action.ActionType) DisksFilter(org.ovirt.engine.core.bll.storage.disk.image.DisksFilter) Map(java.util.Map) Snapshot(org.ovirt.engine.core.common.businessentities.Snapshot) Instance(javax.enterprise.inject.Instance) RemoveMemoryVolumesParameters(org.ovirt.engine.core.common.action.RemoveMemoryVolumesParameters) DiskImagesValidator(org.ovirt.engine.core.bll.validator.storage.DiskImagesValidator) DiskStorageType(org.ovirt.engine.core.common.businessentities.storage.DiskStorageType) Collection(java.util.Collection) EngineMessage(org.ovirt.engine.core.common.errors.EngineMessage) Set(java.util.Set) Collectors(java.util.stream.Collectors) ConcurrentChildCommandsExecutionCallback(org.ovirt.engine.core.bll.ConcurrentChildCommandsExecutionCallback) ONLY_NOT_SHAREABLE(org.ovirt.engine.core.bll.storage.disk.image.DisksFilter.ONLY_NOT_SHAREABLE) List(java.util.List) ValidationResult(org.ovirt.engine.core.bll.ValidationResult) VmValidator(org.ovirt.engine.core.bll.validator.VmValidator) MultipleStorageDomainsValidator(org.ovirt.engine.core.bll.validator.storage.MultipleStorageDomainsValidator) AuditLogType(org.ovirt.engine.core.common.AuditLogType) VdcObjectType(org.ovirt.engine.core.common.VdcObjectType) SubchainInfo(org.ovirt.engine.core.common.businessentities.SubchainInfo) QuotaConsumptionParameter(org.ovirt.engine.core.bll.quota.QuotaConsumptionParameter) FeatureSupported(org.ovirt.engine.core.common.FeatureSupported) QuotaStorageDependent(org.ovirt.engine.core.bll.quota.QuotaStorageDependent) EntityInfo(org.ovirt.engine.core.common.asynctasks.EntityInfo) LockProperties(org.ovirt.engine.core.common.action.LockProperties) Guid(org.ovirt.engine.core.compat.Guid) TransactionSupport(org.ovirt.engine.core.utils.transaction.TransactionSupport) Function(java.util.function.Function) ActionParametersBase(org.ovirt.engine.core.common.action.ActionParametersBase) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) ArrayList(java.util.ArrayList) CommandCoordinatorUtil(org.ovirt.engine.core.bll.tasks.CommandCoordinatorUtil) Inject(javax.inject.Inject) DiskImageDao(org.ovirt.engine.core.dao.DiskImageDao) OvfManager(org.ovirt.engine.core.utils.ovf.OvfManager) ONLY_ACTIVE(org.ovirt.engine.core.bll.storage.disk.image.DisksFilter.ONLY_ACTIVE) RemoveSnapshotSingleDiskParameters(org.ovirt.engine.core.common.action.RemoveSnapshotSingleDiskParameters) VmCommand(org.ovirt.engine.core.bll.VmCommand) Pair(org.ovirt.engine.core.common.utils.Pair) DisableInPrepareMode(org.ovirt.engine.core.bll.DisableInPrepareMode) ImagesHandler(org.ovirt.engine.core.bll.storage.disk.image.ImagesHandler) StoragePoolValidator(org.ovirt.engine.core.bll.validator.storage.StoragePoolValidator) SnapshotStatus(org.ovirt.engine.core.common.businessentities.Snapshot.SnapshotStatus) LockingGroup(org.ovirt.engine.core.common.locks.LockingGroup) EndProcedure(org.ovirt.engine.core.common.action.ActionParametersBase.EndProcedure) ImagesContainterParametersBase(org.ovirt.engine.core.common.action.ImagesContainterParametersBase) AuditLogDirector(org.ovirt.engine.core.dal.dbbroker.auditloghandling.AuditLogDirector) Scope(org.ovirt.engine.core.common.action.LockProperties.Scope) Typed(javax.enterprise.inject.Typed) Disk(org.ovirt.engine.core.common.businessentities.storage.Disk) EngineError(org.ovirt.engine.core.common.errors.EngineError) VM(org.ovirt.engine.core.common.businessentities.VM) CommandCallback(org.ovirt.engine.core.bll.tasks.interfaces.CommandCallback) DiskDao(org.ovirt.engine.core.dao.DiskDao) Collections(java.util.Collections) SubchainInfo(org.ovirt.engine.core.common.businessentities.SubchainInfo) Guid(org.ovirt.engine.core.compat.Guid) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage)

Example 19 with Snapshot

use of org.ovirt.engine.core.common.businessentities.Snapshot in project ovirt-engine by oVirt.

the class RemoveSnapshotCommand method executeCommand.

@Override
protected void executeCommand() {
    if (!getVm().isDown() && !getVm().isQualifiedForSnapshotMerge()) {
        log.error("Cannot remove VM snapshot. Vm is not Down, Up or Paused");
        throw new EngineException(EngineError.VM_NOT_QUALIFIED_FOR_SNAPSHOT_MERGE);
    }
    final Snapshot snapshot = snapshotDao.get(getParameters().getSnapshotId());
    boolean snapshotHasImages = hasImages();
    boolean removeSnapshotMemory = isMemoryVolumeRemoveable(snapshot);
    // No need for locking, VDSM tasks, and all that jazz.
    if (!snapshotHasImages && !removeSnapshotMemory) {
        snapshotDao.remove(getParameters().getSnapshotId());
        setSucceeded(true);
        return;
    }
    lockSnapshot(snapshot);
    if (getParameters().isFreeLockNeeded()) {
        freeLock();
    }
    getParameters().setEntityInfo(new EntityInfo(VdcObjectType.VM, getVmId()));
    boolean useTaskManagerToRemoveMemory = false;
    if (snapshotHasImages) {
        removeImages();
        if (getSnapshotActionType() == ActionType.RemoveSnapshotSingleDiskLive) {
            persistCommand(getParameters().getParentCommand(), true);
            useTaskManagerToRemoveMemory = true;
        }
    }
    if (removeSnapshotMemory) {
        removeMemory(snapshot, useTaskManagerToRemoveMemory);
        if (!snapshotHasImages) {
            // no async tasks - ending command manually
            endVmCommand();
        }
    }
    setSucceeded(true);
}
Also used : Snapshot(org.ovirt.engine.core.common.businessentities.Snapshot) EntityInfo(org.ovirt.engine.core.common.asynctasks.EntityInfo) EngineException(org.ovirt.engine.core.common.errors.EngineException)

Example 20 with Snapshot

use of org.ovirt.engine.core.common.businessentities.Snapshot in project ovirt-engine by oVirt.

the class RemoveSnapshotSingleDiskCommand method endSuccessfully.

@Override
protected void endSuccessfully() {
    // original state (before the merge-attempt).
    if (getDestinationDiskImage() != null) {
        Set<Guid> imagesToUpdate = new HashSet<>();
        DiskImage curr = getDestinationDiskImage();
        while (!curr.getParentId().equals(getDiskImage().getParentId())) {
            curr = diskImageDao.getSnapshotById(curr.getParentId());
            imagesToUpdate.add(curr.getImageId());
        }
        syncDbRecords(VmBlockJobType.PULL, getImageInfoFromVdsm(getDestinationDiskImage()), imagesToUpdate, true);
    }
    if (getParameters().getVmSnapshotId() != null) {
        lockVmSnapshotsWithWait(getVm());
        Snapshot snapshot = snapshotDao.get(getParameters().getVmSnapshotId());
        Snapshot snapshotWithoutImage = imagesHandler.prepareSnapshotConfigWithoutImageSingleImage(snapshot, getParameters().getImageId(), ovfManager);
        snapshotDao.update(snapshotWithoutImage);
        if (getSnapshotsEngineLock() != null) {
            lockManager.releaseLock(getSnapshotsEngineLock());
        }
    }
    setSucceeded(true);
}
Also used : Snapshot(org.ovirt.engine.core.common.businessentities.Snapshot) Guid(org.ovirt.engine.core.compat.Guid) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) HashSet(java.util.HashSet)

Aggregations

Snapshot (org.ovirt.engine.core.common.businessentities.Snapshot)96 DiskImage (org.ovirt.engine.core.common.businessentities.storage.DiskImage)33 VM (org.ovirt.engine.core.common.businessentities.VM)32 Guid (org.ovirt.engine.core.compat.Guid)30 Test (org.junit.Test)21 ArrayList (java.util.ArrayList)15 ActionReturnValue (org.ovirt.engine.core.common.action.ActionReturnValue)12 List (java.util.List)11 SnapshotStatus (org.ovirt.engine.core.common.businessentities.Snapshot.SnapshotStatus)9 Collections (java.util.Collections)8 Date (java.util.Date)8 Set (java.util.Set)8 Collectors (java.util.stream.Collectors)8 SnapshotType (org.ovirt.engine.core.common.businessentities.Snapshot.SnapshotType)8 EngineException (org.ovirt.engine.core.common.errors.EngineException)8 ActionType (org.ovirt.engine.core.common.action.ActionType)7 DiskStorageType (org.ovirt.engine.core.common.businessentities.storage.DiskStorageType)6 EngineMessage (org.ovirt.engine.core.common.errors.EngineMessage)6 HashMap (java.util.HashMap)5 HashSet (java.util.HashSet)5