Search in sources :

Example 21 with Snapshot

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

the class RemoveSnapshotSingleDiskCommandBase method updateVmConfigurationForImageRemoval.

private void updateVmConfigurationForImageRemoval(final Guid snapshotId, final Guid imageId) {
    try {
        lockVmSnapshotsWithWait(getVm());
        TransactionSupport.executeInNewTransaction(() -> {
            Snapshot s = snapshotDao.get(snapshotId);
            s = imagesHandler.prepareSnapshotConfigWithoutImageSingleImage(s, imageId, ovfManager);
            snapshotDao.update(s);
            return null;
        });
    } finally {
        if (getSnapshotsEngineLock() != null) {
            lockManager.releaseLock(getSnapshotsEngineLock());
        }
    }
}
Also used : Snapshot(org.ovirt.engine.core.common.businessentities.Snapshot)

Example 22 with Snapshot

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

the class RemoveSnapshotSingleDiskCommandBase method updateVmConfigurationForImageChange.

private void updateVmConfigurationForImageChange(final Guid snapshotId, final Guid oldImageId, final DiskImage newImage) {
    try {
        lockVmSnapshotsWithWait(getVm());
        TransactionSupport.executeInNewTransaction(() -> {
            Snapshot s = snapshotDao.get(snapshotId);
            s = imagesHandler.prepareSnapshotConfigWithAlternateImage(s, oldImageId, newImage, ovfManager);
            snapshotDao.update(s);
            return null;
        });
    } finally {
        if (getSnapshotsEngineLock() != null) {
            lockManager.releaseLock(getSnapshotsEngineLock());
        }
    }
}
Also used : Snapshot(org.ovirt.engine.core.common.businessentities.Snapshot)

Example 23 with Snapshot

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

the class RestoreAllSnapshotsCommand method initializeSnapshotsLeasesDomainIds.

private void initializeSnapshotsLeasesDomainIds() {
    previewedSnapshotLeaseDomainId = getVm().getLeaseStorageDomainId();
    Snapshot activeBeforeSnapshot = snapshotDao.get(getVmId(), SnapshotType.PREVIEW);
    // activeBeforeSnapshot can be null in case of restore of stateless VM
    if (activeBeforeSnapshot != null && activeBeforeSnapshot.getVmConfiguration() != null) {
        activeBeforeSnapshotLeaseDomainId = OvfUtils.fetchLeaseDomainId(activeBeforeSnapshot.getVmConfiguration());
    }
}
Also used : Snapshot(org.ovirt.engine.core.common.businessentities.Snapshot)

Example 24 with Snapshot

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

the class RestoreAllSnapshotsCommand method findSnapshotsWithOnlyIllegalDisks.

private Set<Guid> findSnapshotsWithOnlyIllegalDisks() {
    List<Snapshot> newerSnapshots = getNewerSnapshots(snapshot);
    Set<Guid> snapshotsToRemove = new HashSet<>();
    newerSnapshots.forEach(snapshot -> {
        VM vm = snapshotVmConfigurationHelper.getVmFromConfiguration(snapshot.getVmConfiguration(), snapshot.getVmId(), snapshot.getId());
        if (vm != null) {
            boolean shouldRemove = vm.getImages().isEmpty() || vm.getImages().stream().allMatch(diskImage -> diskImage.getImageStatus() == ImageStatus.ILLEGAL);
            if (shouldRemove) {
                snapshotsToRemove.add(snapshot.getId());
            }
        }
    });
    return snapshotsToRemove;
}
Also used : LockMessagesMatchUtil(org.ovirt.engine.core.bll.LockMessagesMatchUtil) CinderDisk(org.ovirt.engine.core.common.businessentities.storage.CinderDisk) EngineException(org.ovirt.engine.core.common.errors.EngineException) SnapshotDao(org.ovirt.engine.core.dao.SnapshotDao) VmDynamicDao(org.ovirt.engine.core.dao.VmDynamicDao) ActionReturnValue(org.ovirt.engine.core.common.action.ActionReturnValue) RestoreAllSnapshotsParameters(org.ovirt.engine.core.common.action.RestoreAllSnapshotsParameters) VmStaticDao(org.ovirt.engine.core.dao.VmStaticDao) CommandContext(org.ovirt.engine.core.bll.context.CommandContext) ActionType(org.ovirt.engine.core.common.action.ActionType) Future(java.util.concurrent.Future) 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) DiskImagesValidator(org.ovirt.engine.core.bll.validator.storage.DiskImagesValidator) DiskStorageType(org.ovirt.engine.core.common.businessentities.storage.DiskStorageType) EngineMessage(org.ovirt.engine.core.common.errors.EngineMessage) Set(java.util.Set) Collectors(java.util.stream.Collectors) ConcurrentChildCommandsExecutionCallback(org.ovirt.engine.core.bll.ConcurrentChildCommandsExecutionCallback) SnapshotType(org.ovirt.engine.core.common.businessentities.Snapshot.SnapshotType) Objects(java.util.Objects) ONLY_NOT_SHAREABLE(org.ovirt.engine.core.bll.storage.disk.image.DisksFilter.ONLY_NOT_SHAREABLE) List(java.util.List) VmValidator(org.ovirt.engine.core.bll.validator.VmValidator) Optional(java.util.Optional) MultipleStorageDomainsValidator(org.ovirt.engine.core.bll.validator.storage.MultipleStorageDomainsValidator) AuditLogType(org.ovirt.engine.core.common.AuditLogType) VdcObjectType(org.ovirt.engine.core.common.VdcObjectType) QuotaConsumptionParameter(org.ovirt.engine.core.bll.quota.QuotaConsumptionParameter) VmLeaseVDSParameters(org.ovirt.engine.core.common.vdscommands.VmLeaseVDSParameters) 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) RestoreAllCinderSnapshotsParameters(org.ovirt.engine.core.common.action.RestoreAllCinderSnapshotsParameters) SnapshotActionEnum(org.ovirt.engine.core.common.businessentities.SnapshotActionEnum) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) OvfUtils(org.ovirt.engine.core.utils.OvfUtils) ArrayList(java.util.ArrayList) CommandCoordinatorUtil(org.ovirt.engine.core.bll.tasks.CommandCoordinatorUtil) ImageStatus(org.ovirt.engine.core.common.businessentities.storage.ImageStatus) HashSet(java.util.HashSet) Inject(javax.inject.Inject) CollectionUtils(org.apache.commons.collections.CollectionUtils) DiskImageDao(org.ovirt.engine.core.dao.DiskImageDao) ONLY_ACTIVE(org.ovirt.engine.core.bll.storage.disk.image.DisksFilter.ONLY_ACTIVE) VmCommand(org.ovirt.engine.core.bll.VmCommand) Pair(org.ovirt.engine.core.common.utils.Pair) RestoreFromSnapshotParameters(org.ovirt.engine.core.common.action.RestoreFromSnapshotParameters) 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) VDSReturnValue(org.ovirt.engine.core.common.vdscommands.VDSReturnValue) Scope(org.ovirt.engine.core.common.action.LockProperties.Scope) Typed(javax.enterprise.inject.Typed) QuotaStorageConsumptionParameter(org.ovirt.engine.core.bll.quota.QuotaStorageConsumptionParameter) EngineError(org.ovirt.engine.core.common.errors.EngineError) ExecutionException(java.util.concurrent.ExecutionException) VM(org.ovirt.engine.core.common.businessentities.VM) CommandCallback(org.ovirt.engine.core.bll.tasks.interfaces.CommandCallback) PermissionSubject(org.ovirt.engine.core.bll.utils.PermissionSubject) RemoveImageParameters(org.ovirt.engine.core.common.action.RemoveImageParameters) VDSCommandType(org.ovirt.engine.core.common.vdscommands.VDSCommandType) Collections(java.util.Collections) VmInterfaceManager(org.ovirt.engine.core.bll.network.VmInterfaceManager) ImageDao(org.ovirt.engine.core.dao.ImageDao) Snapshot(org.ovirt.engine.core.common.businessentities.Snapshot) VM(org.ovirt.engine.core.common.businessentities.VM) Guid(org.ovirt.engine.core.compat.Guid) HashSet(java.util.HashSet)

Example 25 with Snapshot

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

the class ColdMergeSnapshotSingleDiskCommand method endSuccessfully.

@Override
public void endSuccessfully() {
    syncDbRecords(VmBlockJobType.COMMIT, getImageInfoFromVdsm(getDiskImage()), Collections.singleton(getDestinationImageId()), 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)

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