Daniel Erez has uploaded a new change for review. Change subject: core: extract PrepareSnapshotConfig method to BaseImagesCommand ......................................................................
core: extract PrepareSnapshotConfig method to BaseImagesCommand Extracted PrepareSnapshotConfigWithoutImageSingleImage from RemoveImageCommand into BaseImagesCommand for reusability in other derivative commands. Change-Id: I965a099ce8d048eb0b19bda96b387140b26bdf2b Signed-off-by: Daniel Erez <[email protected]> --- M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/BaseImagesCommand.java M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RemoveImageCommand.java 2 files changed, 47 insertions(+), 44 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/26/26326/1 diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/BaseImagesCommand.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/BaseImagesCommand.java index faad1fb..f9f7efe 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/BaseImagesCommand.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/BaseImagesCommand.java @@ -1,6 +1,9 @@ package org.ovirt.engine.core.bll; +import java.util.ArrayList; +import java.util.Collections; import java.util.Date; +import java.util.Iterator; import java.util.List; import java.util.Map; @@ -8,14 +11,17 @@ import org.ovirt.engine.core.bll.context.CompensationContext; import org.ovirt.engine.core.bll.snapshots.SnapshotsValidator; import org.ovirt.engine.core.bll.storage.StorageDomainCommandBase; +import org.ovirt.engine.core.bll.utils.ClusterUtils; import org.ovirt.engine.core.common.action.ImagesActionsParametersBase; import org.ovirt.engine.core.common.action.ImagesContainterParametersBase; import org.ovirt.engine.core.common.businessentities.DiskImage; import org.ovirt.engine.core.common.businessentities.DiskImageDynamic; import org.ovirt.engine.core.common.businessentities.ImageStatus; +import org.ovirt.engine.core.common.businessentities.Snapshot; import org.ovirt.engine.core.common.businessentities.Snapshot.SnapshotType; import org.ovirt.engine.core.common.businessentities.VM; import org.ovirt.engine.core.common.businessentities.image_storage_domain_map; +import org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface; import org.ovirt.engine.core.common.errors.VdcBLLException; import org.ovirt.engine.core.common.errors.VdcBllMessages; import org.ovirt.engine.core.common.locks.LockingGroup; @@ -30,6 +36,8 @@ import org.ovirt.engine.core.dao.ImageDao; import org.ovirt.engine.core.dao.SnapshotDao; import org.ovirt.engine.core.utils.lock.EngineLock; +import org.ovirt.engine.core.utils.ovf.OvfManager; +import org.ovirt.engine.core.utils.ovf.OvfReaderException; /** * Base class for all image handling commands @@ -407,4 +415,43 @@ snapshotsEngineLock.setExclusiveLocks(snapshotsExlusiveLockMap); getLockManager().acquireLockWait(snapshotsEngineLock); } + + /** + * Prepare a single {@link org.ovirt.engine.core.common.businessentities.Snapshot} object representing a snapshot of a given VM without the give disk. + */ + protected Snapshot prepareSnapshotConfigWithoutImageSingleImage(Guid vmSnapshotId, Guid imageId) { + Snapshot snap = null; + try { + OvfManager ovfManager = new OvfManager(); + snap = getSnapshotDao().get(vmSnapshotId); + String snapConfig = snap.getVmConfiguration(); + + if (snap.isVmConfigurationAvailable() && snapConfig != null) { + VM vmSnapshot = new VM(); + ArrayList<DiskImage> snapshotImages = new ArrayList<DiskImage>(); + + ovfManager.ImportVm(snapConfig, + vmSnapshot, + snapshotImages, + new ArrayList<VmNetworkInterface>()); + + // Remove the image form the disk list + Iterator<DiskImage> diskIter = snapshotImages.iterator(); + while (diskIter.hasNext()) { + DiskImage imageInList = diskIter.next(); + if (imageInList.getImageId().equals(imageId)) { + log.debugFormat("Recreating vmSnapshot {0} without the image {1}", vmSnapshotId, imageId); + diskIter.remove(); + break; + } + } + + String newOvf = ovfManager.ExportVm(vmSnapshot, snapshotImages, ClusterUtils.getCompatibilityVersion(vmSnapshot)); + snap.setVmConfiguration(newOvf); + } + } catch (OvfReaderException e) { + log.errorFormat("Can't remove image {0} from snapshot {1}", imageId, vmSnapshotId); + } + return snap; + } } diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RemoveImageCommand.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RemoveImageCommand.java index 6bc67d2..913fb8b 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RemoveImageCommand.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RemoveImageCommand.java @@ -2,11 +2,9 @@ import java.util.ArrayList; import java.util.Collections; -import java.util.Iterator; import java.util.LinkedList; import java.util.List; -import org.ovirt.engine.core.bll.utils.ClusterUtils; import org.ovirt.engine.core.common.VdcObjectType; import org.ovirt.engine.core.common.action.RemoveImageParameters; import org.ovirt.engine.core.common.action.VdcActionType; @@ -17,7 +15,6 @@ import org.ovirt.engine.core.common.businessentities.Snapshot; import org.ovirt.engine.core.common.businessentities.VM; import org.ovirt.engine.core.common.businessentities.VmDeviceId; -import org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface; import org.ovirt.engine.core.common.errors.VdcBLLException; import org.ovirt.engine.core.common.errors.VdcBllErrors; import org.ovirt.engine.core.common.vdscommands.DeleteImageGroupVDSCommandParameters; @@ -27,8 +24,6 @@ import org.ovirt.engine.core.compat.Guid; import org.ovirt.engine.core.compat.TransactionScopeOption; import org.ovirt.engine.core.dao.VmDeviceDAO; -import org.ovirt.engine.core.utils.ovf.OvfManager; -import org.ovirt.engine.core.utils.ovf.OvfReaderException; import org.ovirt.engine.core.utils.transaction.TransactionMethod; import org.ovirt.engine.core.utils.transaction.TransactionSupport; @@ -245,45 +240,6 @@ } return result; - } - - /** - * Prepare a single {@link Snapshot} object representing a snapshot of a given VM without the give disk. - */ - protected Snapshot prepareSnapshotConfigWithoutImageSingleImage(Guid vmSnapshotId, Guid imageId) { - Snapshot snap = null; - try { - OvfManager ovfManager = new OvfManager(); - snap = getSnapshotDao().get(vmSnapshotId); - String snapConfig = snap.getVmConfiguration(); - - if (snap.isVmConfigurationAvailable() && snapConfig != null) { - VM vmSnapshot = new VM(); - ArrayList<DiskImage> snapshotImages = new ArrayList<DiskImage>(); - - ovfManager.ImportVm(snapConfig, - vmSnapshot, - snapshotImages, - new ArrayList<VmNetworkInterface>()); - - // Remove the image form the disk list - Iterator<DiskImage> diskIter = snapshotImages.iterator(); - while (diskIter.hasNext()) { - DiskImage imageInList = diskIter.next(); - if (imageInList.getImageId().equals(imageId)) { - log.debugFormat("Recreating vmSnapshot {0} without the image {1}", vmSnapshotId, imageId); - diskIter.remove(); - break; - } - } - - String newOvf = ovfManager.ExportVm(vmSnapshot, snapshotImages, ClusterUtils.getCompatibilityVersion(vmSnapshot)); - snap.setVmConfiguration(newOvf); - } - } catch (OvfReaderException e) { - log.errorFormat("Can't remove image {0} from snapshot {1}", imageId, vmSnapshotId); - } - return snap; } @Override -- To view, visit http://gerrit.ovirt.org/26326 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I965a099ce8d048eb0b19bda96b387140b26bdf2b Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Daniel Erez <[email protected]> _______________________________________________ Engine-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/engine-patches
