Daniel Erez has uploaded a new change for review.

Change subject: core: introduce customized snapshot preview support
......................................................................

core: introduce customized snapshot preview support

* Updated the commands used for preview/commit/undo snapshots
  to support customized snapshots (by identifying and handling
  a custom disks list)

* SnapshotManager:
** added addActiveSnapshot method signature that accepts disks list argument.
** generateVmConfiguration method now also accepts an argument for
   specified disks list (needed for custom preview).

Feature: http://www.ovirt.org/Features/Single_Disk_Snapshot

Change-Id: I89332a1538c7259dd3ea62d693ac062f47e52cd0
Signed-off-by: Daniel Erez <[email protected]>
---
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/GetVmConfigurationBySnapshotQuery.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ImagesHandler.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RestoreAllSnapshotsCommand.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/TryBackToAllSnapshotsOfVmCommand.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/snapshots/SnapshotsManager.java
M 
backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/ImagesHandlerTest.java
M 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/RestoreAllSnapshotsParameters.java
M 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/TryBackToAllSnapshotsOfVmParameters.java
8 files changed, 275 insertions(+), 30 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/76/22776/1

diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/GetVmConfigurationBySnapshotQuery.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/GetVmConfigurationBySnapshotQuery.java
index c78dc63e..461edbb 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/GetVmConfigurationBySnapshotQuery.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/GetVmConfigurationBySnapshotQuery.java
@@ -38,7 +38,12 @@
         VM result = null;
         if (configuration != null) {
             result = getVmFromConfiguration(configuration);
-            markImagesIllegalIfNotInDb(result);
+
+            // For 'PREVIEW' snapshots, no need to mark disks as illegal
+            // (since no changes can be made while VM is in preview mode).
+            if (snapshot.getType() != Snapshot.SnapshotType.PREVIEW) {
+                markImagesIllegalIfNotInDb(result);
+            }
         } else {
             result = getVmWithoutConfiguration();
         }
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ImagesHandler.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ImagesHandler.java
index dd19bf1..ff285dc 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ImagesHandler.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ImagesHandler.java
@@ -706,4 +706,33 @@
     public static void updateAllDiskImageSnapshotsStatus(Guid diskId, 
ImageStatus status) {
         
DbFacade.getInstance().getImageDao().updateStatusOfImagesByImageGroupId(diskId, 
status);
     }
+
+    public static DiskImage getDiskImageById(Guid id, List<DiskImage> 
diskImages) {
+        for (DiskImage diskImage : diskImages) {
+            if (diskImage.getId().equals(id)) {
+                return diskImage;
+            }
+        }
+        return null;
+    }
+
+    public static List<DiskImage> imagesIntersection(List<DiskImage> images1, 
List<DiskImage> images2) {
+        List<DiskImage> intersection = new ArrayList<>();
+        for (DiskImage image : images1) {
+            if (ImagesHandler.getDiskImageById(image.getId(), images2) != 
null) {
+                intersection.add(image);
+            }
+        }
+        return intersection;
+    }
+
+    public static List<DiskImage> imagesSubtract(List<DiskImage> images1, 
List<DiskImage> images2) {
+        List<DiskImage> subtract = new ArrayList<>();
+        for (DiskImage image : images1) {
+            if (ImagesHandler.getDiskImageById(image.getId(), images2) == 
null) {
+                subtract.add(image);
+            }
+        }
+        return subtract;
+    }
 }
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RestoreAllSnapshotsCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RestoreAllSnapshotsCommand.java
index d0381ed..46ff74b 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RestoreAllSnapshotsCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RestoreAllSnapshotsCommand.java
@@ -7,6 +7,7 @@
 import java.util.Map;
 import java.util.Set;
 
+import org.apache.commons.collections.CollectionUtils;
 import org.ovirt.engine.core.bll.job.ExecutionHandler;
 import org.ovirt.engine.core.bll.quota.QuotaConsumptionParameter;
 import org.ovirt.engine.core.bll.quota.QuotaStorageConsumptionParameter;
@@ -58,6 +59,7 @@
 
     private final Set<Guid> snapshotsToRemove = new HashSet<Guid>();
     private Snapshot targetSnapshot;
+    List<DiskImage> imagesToRestore = new ArrayList<>();
 
     /**
      * The snapshot id which will be removed (the stateless/preview/active 
image).
@@ -99,7 +101,7 @@
         restoreSnapshotAndRemoveObsoleteSnapshots(targetSnapshot);
 
         boolean succeeded = true;
-        for (DiskImage image : getImagesList()) {
+        for (DiskImage image : imagesToRestore) {
             if (image.getImageStatus() != ImageStatus.ILLEGAL) {
                 ImagesContainterParametersBase params = new 
RestoreFromSnapshotParameters(image.getImageId(),
                         getVmId(), targetSnapshot, removedSnapshotId);
@@ -225,14 +227,27 @@
      * Additionally, remove all obsolete snapshots (The one after stateless, 
or the preview chain which was not chosen).
      */
     protected void restoreSnapshotAndRemoveObsoleteSnapshots(Snapshot 
targetSnapshot) {
+        Guid activeSnapshotId = getSnapshotDao().getId(getVmId(), 
SnapshotType.ACTIVE);
+        List<DiskImage> imagesFromActiveSnapshot = 
getDiskImageDao().getAllSnapshotsForVmSnapshot(activeSnapshotId);
+
+        Guid previewSnapshotId = getSnapshotDao().getId(getVmId(), 
SnapshotType.PREVIEW);
+        List<DiskImage> imagesFromPreviewSnapshot = 
getDiskImageDao().getAllSnapshotsForVmSnapshot(previewSnapshotId);
+
+        List<DiskImage> intersection = 
ImagesHandler.imagesIntersection(imagesFromActiveSnapshot, 
imagesFromPreviewSnapshot);
 
         switch (targetSnapshot.getType()) {
         case PREVIEW:
             getSnapshotDao().updateStatus(
                     getSnapshotDao().getId(getVmId(), SnapshotType.REGULAR, 
SnapshotStatus.IN_PREVIEW),
                     SnapshotStatus.OK);
+
         case STATELESS:
             restoreConfiguration(targetSnapshot);
+
+            getParameters().setImagesList((List<DiskImage>) 
CollectionUtils.union(imagesFromPreviewSnapshot, intersection));
+            imagesToRestore = imagesFromPreviewSnapshot;
+            updateSnapshotIdForSkipRestoreImages(
+                    ImagesHandler.imagesSubtract(imagesFromActiveSnapshot, 
imagesToRestore), targetSnapshot.getId());
             break;
 
         // Currently UI sends the "in preview" snapshot to restore when 
"Commit" is pressed.
@@ -241,13 +256,21 @@
                 prepareToDeletePreviewBranch();
 
                 // Set the active snapshot's images as target images for 
restore, because they are what we keep.
-                
getParameters().setImagesList(getDiskImageDao().getAllSnapshotsForVmSnapshot(
-                        getSnapshotDao().getId(getVmId(), 
SnapshotType.ACTIVE)));
+                getParameters().setImagesList(imagesFromActiveSnapshot);
+                imagesToRestore = 
ImagesHandler.imagesIntersection(imagesFromActiveSnapshot, 
imagesFromPreviewSnapshot);
+                updateSnapshotIdForSkipRestoreImages(
+                        ImagesHandler.imagesSubtract(imagesFromActiveSnapshot, 
imagesToRestore), activeSnapshotId);
                 break;
             }
         default:
             throw new VdcBLLException(VdcBllErrors.ENGINE, "No support for 
restoring to snapshot type: "
                     + targetSnapshot.getType());
+        }
+    }
+
+    private void updateSnapshotIdForSkipRestoreImages(List<DiskImage> 
skipRestoreImages, Guid snapshotId) {
+        for (DiskImage image : skipRestoreImages) {
+            getImageDao().updateImageVmSnapshotId(image.getImageId(), 
snapshotId);
         }
     }
 
@@ -267,6 +290,7 @@
         snapshotsManager.attempToRestoreVmConfigurationFromSnapshot(getVm(),
                 targetSnapshot,
                 targetSnapshot.getId(),
+                getParameters().getImages(),
                 getCompensationContext(), 
getVm().getVdsGroupCompatibilityVersion(), getCurrentUser());
         getSnapshotDao().remove(targetSnapshot.getId());
         // add active snapshot with status locked, so that other commands that 
depend on the VM's snapshots won't run in parallel
@@ -274,6 +298,7 @@
                 getVm(),
                 SnapshotStatus.LOCKED,
                 targetSnapshot.getMemoryVolume(),
+                getParameters().getImages(),
                 getCompensationContext());
     }
 
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/TryBackToAllSnapshotsOfVmCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/TryBackToAllSnapshotsOfVmCommand.java
index 485d486..7f02e80 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/TryBackToAllSnapshotsOfVmCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/TryBackToAllSnapshotsOfVmCommand.java
@@ -1,10 +1,12 @@
 package org.ovirt.engine.core.bll;
 
+import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
+import org.apache.commons.collections.CollectionUtils;
 import org.apache.commons.lang.StringUtils;
 import org.ovirt.engine.core.bll.job.ExecutionHandler;
 import org.ovirt.engine.core.bll.snapshots.SnapshotsManager;
@@ -112,27 +114,34 @@
         snapshotsManager.attempToRestoreVmConfigurationFromSnapshot(getVm(),
                 getDstSnapshot(),
                 getSnapshotDao().getId(getVm().getId(), SnapshotType.ACTIVE),
+                getParameters().getImages(),
                 getCompensationContext(), 
getVm().getVdsGroupCompatibilityVersion(), getCurrentUser());
     }
 
     @Override
     protected void executeVmCommand() {
+        final boolean restoreMemory = getParameters().isRestoreMemory() &&
+                
FeatureSupported.memorySnapshot(getVm().getVdsGroupCompatibilityVersion());
 
         final Guid newActiveSnapshotId = Guid.newGuid();
         final Snapshot snapshotToBePreviewed = getDstSnapshot();
-        final List<DiskImage> images = DbFacade
-                .getInstance()
-                .getDiskImageDao()
-                .getAllSnapshotsForVmSnapshot(snapshotToBePreviewed.getId());
-        final boolean restoreMemory = getParameters().isRestoreMemory() &&
-                
FeatureSupported.memorySnapshot(getVm().getVdsGroupCompatibilityVersion());
+
+        final Snapshot previousActiveSnapshot = 
getSnapshotDao().get(getVmId(), SnapshotType.ACTIVE);
+        final Guid previousActiveSnapshotId = previousActiveSnapshot.getId();
+
+        final List<DiskImage> images = getParameters().getImages() != null ? 
getParameters().getImages() :
+                DbFacade.getInstance()
+                        .getDiskImageDao()
+                        
.getAllSnapshotsForVmSnapshot(snapshotToBePreviewed.getId());
+
+        // Images list without those that are excluded from preview
+        final List<DiskImage> filteredImages = (List<DiskImage>) 
CollectionUtils.subtract(
+                images, getImagesExcludedFromPreview(images, 
previousActiveSnapshotId, newActiveSnapshotId));
 
         TransactionSupport.executeInNewTransaction(new 
TransactionMethod<Void>() {
             @Override
             public Void runInTransaction() {
-                Snapshot previousActiveSnapshot = 
getSnapshotDao().get(getVmId(), SnapshotType.ACTIVE);
                 
getCompensationContext().snapshotEntity(previousActiveSnapshot);
-                Guid previousActiveSnapshotId = previousActiveSnapshot.getId();
                 getSnapshotDao().remove(previousActiveSnapshotId);
                 snapshotsManager.addSnapshot(previousActiveSnapshotId,
                         "Active VM before the preview",
@@ -143,10 +152,12 @@
                 snapshotsManager.addActiveSnapshot(newActiveSnapshotId,
                         getVm(),
                         restoreMemory ? 
snapshotToBePreviewed.getMemoryVolume() : StringUtils.EMPTY,
+                        images,
                         getCompensationContext());
+
                 // if there are no images there's no reason to save the 
compensation data to DB as the update is
                 // being executed in the same transaction so we can restore 
the vm config and end the command.
-                if (!images.isEmpty()) {
+                if (!filteredImages.isEmpty()) {
                     getCompensationContext().stateChanged();
                 } else {
                     getVmStaticDAO().incrementDbGeneration(getVm().getId());
@@ -156,13 +167,13 @@
             }
         });
 
-        if (!images.isEmpty()) {
+        if (!filteredImages.isEmpty()) {
             VmHandler.lockVm(getVm().getDynamicData(), 
getCompensationContext());
             freeLock();
             TransactionSupport.executeInNewTransaction(new 
TransactionMethod<Void>() {
                 @Override
                 public Void runInTransaction() {
-                    for (DiskImage image : images) {
+                    for (DiskImage image : filteredImages) {
                         VdcReturnValueBase vdcReturnValue =
                                 
Backend.getInstance().runInternalAction(VdcActionType.TryBackToSnapshot,
                                         
buildTryBackToSnapshotParameters(newActiveSnapshotId, image),
@@ -195,6 +206,23 @@
             });
         }
         setSucceeded(true);
+    }
+
+    /**
+     * Returns the list of images that haven't been selected for preview 
(remain the images from current active VM).
+     */
+    private List<DiskImage> getImagesExcludedFromPreview(List<DiskImage> 
images, Guid previousActiveSnapshotId, Guid newActiveSnapshotId) {
+        List<DiskImage> excludedImages = new ArrayList<>();
+
+        for (DiskImage image : images) {
+            if (image.getVmSnapshotId().equals(previousActiveSnapshotId)) {
+                // Image is already active, hence only update snapshot ID.
+                getImageDao().updateImageVmSnapshotId(image.getImageId(), 
newActiveSnapshotId);
+                excludedImages.add(image);
+            }
+        }
+
+        return excludedImages;
     }
 
     @Override
@@ -259,7 +287,8 @@
                 return disk.getVmSnapshotId();
             }
         });
-        if (snapshotIds.contains(getParameters().getDstSnapshotId())) {
+        // Allow active VM custom preview (i.e. block only when no images are 
specified).
+        if (snapshotIds.contains(getParameters().getDstSnapshotId()) && 
getParameters().getImages() == null) {
             return failCanDoAction(VdcBllMessages.CANNOT_PREIEW_CURRENT_IMAGE);
         }
 
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/snapshots/SnapshotsManager.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/snapshots/SnapshotsManager.java
index 5161c70..1cb4e4d 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/snapshots/SnapshotsManager.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/snapshots/SnapshotsManager.java
@@ -2,7 +2,9 @@
 
 import java.util.ArrayList;
 import java.util.Date;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 import java.util.Set;
 
 import org.apache.commons.lang.StringUtils;
@@ -77,6 +79,7 @@
                 vm,
                 SnapshotStatus.OK,
                 "",
+                null,
                 compensationContext);
     }
 
@@ -103,6 +106,7 @@
                 vm,
                 snapshotStatus,
                 "",
+                null,
                 compensationContext);
     }
 
@@ -129,6 +133,36 @@
                 vm,
                 SnapshotStatus.OK,
                 memoryVolume,
+                null,
+                compensationContext);
+    }
+
+    /**
+     * Save an active snapshot for the VM, without saving the 
configuration.<br>
+     * The snapshot is created in status {@link SnapshotStatus#OK} by default.
+     *
+     * @param snapshotId
+     *            The ID for the snapshot.
+     * @param vm
+     *            The VM to save the snapshot for.
+     * @param memoryVolume
+     *            The memory state for the created snapshot
+     * @param disks
+     *            The disks contained in the snapshot
+     * @param compensationContext
+     *            Context for saving compensation details.
+     * @return the newly created snapshot
+     */
+    public Snapshot addActiveSnapshot(Guid snapshotId,
+            VM vm,
+            String memoryVolume,
+            List<DiskImage> disks,
+            final CompensationContext compensationContext) {
+        return addActiveSnapshot(snapshotId,
+                vm,
+                SnapshotStatus.OK,
+                memoryVolume,
+                disks,
                 compensationContext);
     }
 
@@ -142,6 +176,8 @@
      *            The VM to save the snapshot for.
      * @param snapshotStatus
      *            The initial status of the snapshot
+     * @param disks
+     *            The disks contained in the snapshot
      * @param compensationContext
      *            Context for saving compensation details.
      */
@@ -149,6 +185,7 @@
             VM vm,
             SnapshotStatus snapshotStatus,
             String memoryVolume,
+            List<DiskImage> disks,
             final CompensationContext compensationContext) {
         return addSnapshot(snapshotId,
                 "Active VM",
@@ -157,6 +194,7 @@
                 vm,
                 false,
                 memoryVolume,
+                disks,
                 compensationContext);
     }
 
@@ -186,7 +224,39 @@
             String memoryVolume,
             final CompensationContext compensationContext) {
         return addSnapshot(snapshotId, description, SnapshotStatus.LOCKED,
-                snapshotType, vm, true, memoryVolume, compensationContext);
+                snapshotType, vm, true, memoryVolume, null, 
compensationContext);
+    }
+
+    /**
+     * Add a new snapshot, saving it to the DB (with compensation). The VM's 
current configuration (including Disks &
+     * NICs) will be saved in the snapshot.<br>
+     * The snapshot is created in status {@link SnapshotStatus#LOCKED} by 
default.
+     *
+     * @param snapshotId
+     *            The ID for the snapshot.
+     * @param description
+     *            The snapshot description.
+     * @param snapshotType
+     *            The snapshot type.
+     * @param vm
+     *            The VM to save in configuration.
+     * @param memoryVolume
+     *            the volume in which the snapshot's memory is stored
+     * @param disks
+     *            The disks contained in the snapshot
+     * @param compensationContext
+     *            Context for saving compensation details.
+     * @return the added snapshot
+     */
+    public Snapshot addSnapshot(Guid snapshotId,
+                                String description,
+                                SnapshotType snapshotType,
+                                VM vm,
+                                String memoryVolume,
+                                List<DiskImage> disks,
+                                final CompensationContext compensationContext) 
{
+        return addSnapshot(snapshotId, description, SnapshotStatus.LOCKED,
+                snapshotType, vm, true, memoryVolume, disks, 
compensationContext);
     }
 
     /**
@@ -215,11 +285,12 @@
             VM vm,
             boolean saveVmConfiguration,
             String memoryVolume,
+            List<DiskImage> disks,
             final CompensationContext compensationContext) {
         final Snapshot snapshot = new Snapshot(snapshotId,
                 snapshotStatus,
                 vm.getId(),
-                saveVmConfiguration ? generateVmConfiguration(vm) : null,
+                saveVmConfiguration ? generateVmConfiguration(vm, disks) : 
null,
                 snapshotType,
                 description,
                 new Date(),
@@ -238,7 +309,7 @@
      *            The VM to generate configuration from.
      * @return A String containing the VM configuration.
      */
-    protected String generateVmConfiguration(VM vm) {
+    protected String generateVmConfiguration(VM vm, List<DiskImage> disks) {
         if (vm.getInterfaces() == null || vm.getInterfaces().isEmpty()) {
             
vm.setInterfaces(getVmNetworkInterfaceDao().getAllForVm(vm.getId()));
         }
@@ -249,13 +320,13 @@
         }
 
         VmDeviceUtils.setVmDevices(vm.getStaticData());
-        ArrayList<DiskImage> images =
-                new 
ArrayList<DiskImage>(ImagesHandler.filterImageDisks(getDiskDao().getAllForVm(vm.getId()),
-                        false, true, true));
-        for (DiskImage image : images) {
+        if (disks == null) {
+            disks = 
ImagesHandler.filterImageDisks(getDiskDao().getAllForVm(vm.getId()), false, 
true, true);
+        }
+        for (DiskImage image : disks) {
             image.setStorageIds(null);
         }
-        return new OvfManager().ExportVm(vm, images, 
ClusterUtils.getCompatibilityVersion(vm));
+        return new OvfManager().ExportVm(vm, new ArrayList<>(disks), 
ClusterUtils.getCompatibilityVersion(vm));
     }
 
     /**
@@ -307,10 +378,15 @@
     public void attempToRestoreVmConfigurationFromSnapshot(VM vm,
             Snapshot snapshot,
             Guid activeSnapshotId,
+            List<DiskImage> images,
             CompensationContext compensationContext, Version version, DbUser 
user) {
         boolean vmUpdatedFromConfiguration = false;
         if (snapshot.getVmConfiguration() != null) {
             vmUpdatedFromConfiguration = updateVmFromConfiguration(vm, 
snapshot.getVmConfiguration());
+
+            if (images != null) {
+                vmUpdatedFromConfiguration &= updateImagesByConfiguration(vm, 
images);
+            }
         }
 
         if (!vmUpdatedFromConfiguration) {
@@ -335,6 +411,34 @@
         }
     }
 
+    private boolean updateImagesByConfiguration(VM vm, List<DiskImage> images) 
{
+        Map<Guid, VM> snapshotVmConfigurations = new HashMap<>();
+        ArrayList<DiskImage> imagesFromVmConf = new ArrayList<>();
+
+        for (DiskImage image : images) {
+            Guid vmSnapshotId = image.getVmSnapshotId();
+            VM vmFromConf = snapshotVmConfigurations.get(vmSnapshotId);
+            if (vmFromConf == null) {
+                vmFromConf = new VM();
+                Snapshot snapshot = 
getSnapshotDao().get(image.getVmSnapshotId());
+                if (!updateVmFromConfiguration(vmFromConf, 
snapshot.getVmConfiguration())) {
+                    return false;
+                }
+                snapshotVmConfigurations.put(vmSnapshotId, vmFromConf);
+            }
+
+            for (DiskImage imageFromVmConf : vmFromConf.getImages()) {
+                if (imageFromVmConf.getId().equals(image.getId())) {
+                    imageFromVmConf.setStorageIds(image.getStorageIds());
+                    imagesFromVmConf.add(imageFromVmConf);
+                }
+            }
+            vm.setImages(imagesFromVmConf);
+        }
+
+        return true;
+    }
+
     /**
      * @param vmDevice
      * @return true if the device can be removed (disk which allows snapshot 
can be removed as it is part
diff --git 
a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/ImagesHandlerTest.java
 
b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/ImagesHandlerTest.java
index ff59681..2cdf095 100644
--- 
a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/ImagesHandlerTest.java
+++ 
b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/ImagesHandlerTest.java
@@ -5,6 +5,7 @@
 
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Collections;
 import java.util.List;
 import java.util.Set;
 
@@ -22,11 +23,13 @@
     /** The disks to use for testing */
     private DiskImage disk1;
     private DiskImage disk2;
+    private DiskImage disk3;
 
     @Before
     public void setUp() {
         disk1 = new DiskImage();
         disk2 = new DiskImage();
+        disk3 = new DiskImage();
     }
 
     @Test
@@ -87,4 +90,32 @@
         assertEquals("Wrong number of Guids returned", 1, result.size());
         assertTrue("The result should contain the active image disk", 
result.contains(disk1));
     }
+
+    @Test
+    public void testImagesIntersection() {
+        disk1.setId(Guid.newGuid());
+        disk2.setId(Guid.newGuid());
+        disk3.setId(Guid.newGuid());
+
+        List<DiskImage> list1 = new ArrayList<>(Arrays.asList(disk1, disk2));
+        List<DiskImage> list2 = new ArrayList<>(Arrays.asList(disk1, disk3));
+
+        List<DiskImage> intersection = ImagesHandler.imagesIntersection(list1, 
list2);
+
+        assertTrue("Intersection should contain only disk1", 
intersection.size() == 1 && intersection.contains(disk1));
+    }
+
+    @Test
+    public void testImagesSubtract() {
+        disk1.setId(Guid.newGuid());
+        disk2.setId(Guid.newGuid());
+        disk3.setId(Guid.newGuid());
+
+        List<DiskImage> list1 = new ArrayList<>(Arrays.asList(disk1, disk2, 
disk3));
+        List<DiskImage> list2 = new ArrayList<>(Arrays.asList(disk2, disk3));
+
+        List<DiskImage> intersection = ImagesHandler.imagesSubtract(list1, 
list2);
+
+        assertTrue("Intersection should contain only disk1", 
intersection.size() == 1 && intersection.contains(disk1));
+    }
 }
diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/RestoreAllSnapshotsParameters.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/RestoreAllSnapshotsParameters.java
index 6a31665..a366828 100644
--- 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/RestoreAllSnapshotsParameters.java
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/RestoreAllSnapshotsParameters.java
@@ -8,18 +8,23 @@
 public class RestoreAllSnapshotsParameters extends 
TryBackToAllSnapshotsOfVmParameters implements java.io.Serializable {
     private static final long serialVersionUID = -8756081739745132849L;
 
+    private List<DiskImage> images;
+
     public RestoreAllSnapshotsParameters(Guid vmId, Guid dstSnapshotId) {
         super(vmId, dstSnapshotId);
     }
 
-    private List<DiskImage> privateImagesList;
-
-    public List<DiskImage> getImagesList() {
-        return privateImagesList;
+    public RestoreAllSnapshotsParameters(Guid vmId, Guid dstSnapshotId, 
List<DiskImage> images) {
+        this(vmId, dstSnapshotId);
+        this.images = images;
     }
 
-    public void setImagesList(List<DiskImage> value) {
-        privateImagesList = value;
+    public List<DiskImage> getImagesList() {
+        return images;
+    }
+
+    public void setImagesList(List<DiskImage> images) {
+        this.images = images;
     }
 
     public RestoreAllSnapshotsParameters() {
diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/TryBackToAllSnapshotsOfVmParameters.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/TryBackToAllSnapshotsOfVmParameters.java
index 777130a..d3149e6 100644
--- 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/TryBackToAllSnapshotsOfVmParameters.java
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/TryBackToAllSnapshotsOfVmParameters.java
@@ -1,11 +1,15 @@
 package org.ovirt.engine.core.common.action;
 
+import org.ovirt.engine.core.common.businessentities.DiskImage;
 import org.ovirt.engine.core.compat.Guid;
+
+import java.util.List;
 
 public class TryBackToAllSnapshotsOfVmParameters extends 
VmOperationParameterBase implements java.io.Serializable {
     private static final long serialVersionUID = 1862924807826485840L;
     private Guid dstSnapshotId;
     private boolean restoreMemory;
+    private List<DiskImage> images;
 
     public TryBackToAllSnapshotsOfVmParameters() {
         dstSnapshotId = Guid.Empty;
@@ -21,6 +25,11 @@
         this.restoreMemory = restoreMemory;
     }
 
+    public TryBackToAllSnapshotsOfVmParameters(Guid vmId, Guid dstSnapshotId, 
boolean restoreMemory, List<DiskImage> images) {
+        this(vmId, dstSnapshotId, restoreMemory);
+        this.images = images;
+    }
+
     public Guid getDstSnapshotId() {
         return dstSnapshotId;
     }
@@ -32,4 +41,12 @@
     public void setRestoreMemory(boolean restoreMemory) {
         this.restoreMemory = restoreMemory;
     }
+
+    public List<DiskImage> getImages() {
+        return images;
+    }
+
+    public void setImages(List<DiskImage> images) {
+        this.images = images;
+    }
 }


-- 
To view, visit http://gerrit.ovirt.org/22776
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I89332a1538c7259dd3ea62d693ac062f47e52cd0
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

Reply via email to