Maor Lipchuk has uploaded a new change for review.

Change subject: core: Refactor updateOldImageAsActive to baseImagesCommand
......................................................................

core: Refactor updateOldImageAsActive to baseImagesCommand

Refactor method updateOldImageAsActive to baseImagesCommand so it can be
re-used with TryBackToCinderSnapshotCommand.

Change-Id: Idbc3563310cc447de19dedf2c6b5302aff27c8f6
Bug-Url: https://bugzilla.redhat.com/1185826
Signed-off-by: Maor Lipchuk <mlipc...@redhat.com>
---
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/TryBackToSnapshotCommand.java
2 files changed, 25 insertions(+), 27 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/10/42310/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 577c51a..f09b13f 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
@@ -175,6 +175,29 @@
     }
 
     /**
+     * Update the old image that represents the disk of the command's image to 
be in the given active state.
+     *
+     * @param snapshotType
+     *            The type of snapshot to look for the same image in.
+     * @param active
+     *            The active state.
+     */
+    protected void updateOldImageAsActive(SnapshotType snapshotType, boolean 
active) {
+        Guid oldImageId = findImageForSameDrive(snapshotType);
+        if (oldImageId == null) {
+            log.error("Can't find image to update to active '{}', snapshot 
type '{}', original image id '{}'",
+                    active,
+                    snapshotType,
+                    getImageId());
+            return;
+        }
+
+        DiskImage oldImage = getDiskImageDao().getSnapshotById(oldImageId);
+        oldImage.setActive(active);
+        getImageDao().update(oldImage.getImage());
+    }
+
+    /**
      * Find the image for the same drive by the snapshot ID:<br>
      * The image is the image from the given snapshot, which represents the 
same drive.
      *
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/TryBackToSnapshotCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/TryBackToSnapshotCommand.java
index da3bc25..96bab10 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/TryBackToSnapshotCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/TryBackToSnapshotCommand.java
@@ -3,8 +3,6 @@
 import org.ovirt.engine.core.bll.context.CommandContext;
 import org.ovirt.engine.core.common.action.ImagesContainterParametersBase;
 import org.ovirt.engine.core.common.businessentities.Snapshot.SnapshotType;
-import org.ovirt.engine.core.common.businessentities.storage.DiskImage;
-import org.ovirt.engine.core.compat.Guid;
 
 /**
  * This command responsible to creating new snapshot from non leaf snapshot. 
Its
@@ -26,30 +24,7 @@
      */
     @Override
     protected void processOldImageFromDb() {
-        updateOldImageActive(SnapshotType.PREVIEW, false);
-    }
-
-    /**
-     * Update the old image that represents the disk of the command's image to 
be in the given active state.
-     *
-     * @param snapshotType
-     *            The type of snapshot to look for the same image in.
-     * @param active
-     *            The active state.
-     */
-    protected void updateOldImageActive(SnapshotType snapshotType, boolean 
active) {
-        Guid oldImageId = findImageForSameDrive(snapshotType);
-        if (oldImageId == null) {
-            log.error("Can't find image to update to active '{}', snapshot 
type '{}', original image id '{}'",
-                    active,
-                    snapshotType,
-                    getImageId());
-            return;
-        }
-
-        DiskImage oldImage = getDiskImageDao().getSnapshotById(oldImageId);
-        oldImage.setActive(active);
-        getImageDao().update(oldImage.getImage());
+        updateOldImageAsActive(SnapshotType.PREVIEW, false);
     }
 
     @Override
@@ -60,7 +35,7 @@
 
     @Override
     protected void endWithFailure() {
-        updateOldImageActive(SnapshotType.ACTIVE, true);
+        updateOldImageAsActive(SnapshotType.ACTIVE, true);
 
         // Remove destination, unlock source:
         undoActionOnSourceAndDestination();


-- 
To view, visit https://gerrit.ovirt.org/42310
To unsubscribe, visit https://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Idbc3563310cc447de19dedf2c6b5302aff27c8f6
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Maor Lipchuk <mlipc...@redhat.com>
_______________________________________________
Engine-patches mailing list
Engine-patches@ovirt.org
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to