Arik Hadas has uploaded a new change for review.

Change subject: core: simplified memory states removal code
......................................................................

core: simplified memory states removal code

This patch simplifies the MemoryImageRemover#removeMemoryVolumes(String,
boolean) method:
1. split the long method into several methods
2. reorganize the tasks polling related code

Change-Id: Ib0b5b9d77458db7c2a7e97fe0d36fd2b8679d20d
Signed-off-by: Arik Hadas <aha...@redhat.com>
---
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/memory/MemoryImageRemover.java
1 file changed, 54 insertions(+), 39 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/27/16827/1

diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/memory/MemoryImageRemover.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/memory/MemoryImageRemover.java
index d9d3f2f..a4282b4 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/memory/MemoryImageRemover.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/memory/MemoryImageRemover.java
@@ -50,54 +50,69 @@
 
         if (guids.size() == 6) {
 
-            Guid taskId1 = 
enclosingCommand.persistAsyncTaskPlaceHolder(VmCommand.DELETE_PRIMARY_IMAGE_TASK_KEY);
-            // delete first image
-            // the next 'DeleteImageGroup' command should also take care of 
the image removal:
-            VDSReturnValue vdsRetValue =
-                    Backend
-                    .getInstance()
-                    .getResourceManager()
-                    .RunVdsCommand(
-                            VDSCommandType.DeleteImageGroup,
-                            buildDeleteMemoryImageParams(guids));
-
-            if (!vdsRetValue.getSucceeded()) {
+            Guid guid1 = removeMemoryImage(guids);
+            if (guid1 == null) {
                 return false;
             }
 
-            Guid guid1 =
-                    enclosingCommand.createTask(taskId1, 
vdsRetValue.getCreationInfo(),
-                            enclosingCommand.getActionType(), 
VdcObjectType.Storage, guids.get(0));
-            enclosingCommand.getTaskIdList().add(guid1);
-
-            Guid taskId2 = 
enclosingCommand.persistAsyncTaskPlaceHolder(VmCommand.DELETE_SECONDARY_IMAGES_TASK_KEY);
-            // delete second image
-            // the next 'DeleteImageGroup' command should also take care of 
the image removal:
-            vdsRetValue =
-                    Backend
-                    .getInstance()
-                    .getResourceManager()
-                    .RunVdsCommand(
-                            VDSCommandType.DeleteImageGroup,
-                            buildDeleteMemoryConfParams(guids));
-
-            if (!vdsRetValue.getSucceeded()) {
-                if (startPollingTasks) {
-                    AsyncTaskManager.getInstance().StartPollingTask(guid1);
-                }
-                return false;
-            }
-
-            Guid guid2 = enclosingCommand.createTask(taskId2, 
vdsRetValue.getCreationInfo(),
-                    enclosingCommand.getActionType());
-            enclosingCommand.getTaskIdList().add(guid2);
+            Guid guid2 = removeConfImage(guids);
 
             if (startPollingTasks) {
                 AsyncTaskManager.getInstance().StartPollingTask(guid1);
-                AsyncTaskManager.getInstance().StartPollingTask(guid2);
+
+                if (guid2 != null) {
+                    AsyncTaskManager.getInstance().StartPollingTask(guid2);
+                }
             }
+
+            return guid2 != null;
         }
 
         return true;
     }
+
+    protected Guid removeMemoryImage(List<Guid> guids) {
+        Guid taskId1 = 
enclosingCommand.persistAsyncTaskPlaceHolder(VmCommand.DELETE_PRIMARY_IMAGE_TASK_KEY);
+        // delete first image
+        // the next 'DeleteImageGroup' command should also take care of the 
image removal:
+        VDSReturnValue vdsRetValue =
+                Backend
+                .getInstance()
+                .getResourceManager()
+                .RunVdsCommand(
+                        VDSCommandType.DeleteImageGroup,
+                        buildDeleteMemoryImageParams(guids));
+
+        if (!vdsRetValue.getSucceeded()) {
+            return null;
+        }
+
+        Guid guid1 =
+                enclosingCommand.createTask(taskId1, 
vdsRetValue.getCreationInfo(),
+                        enclosingCommand.getActionType(), 
VdcObjectType.Storage, guids.get(0));
+        enclosingCommand.getTaskIdList().add(guid1);
+        return guid1;
+    }
+
+    protected Guid removeConfImage(List<Guid> guids) {
+        Guid taskId2 = 
enclosingCommand.persistAsyncTaskPlaceHolder(VmCommand.DELETE_SECONDARY_IMAGES_TASK_KEY);
+        // delete second image
+        // the next 'DeleteImageGroup' command should also take care of the 
image removal:
+        VDSReturnValue vdsRetValue =
+                Backend
+                .getInstance()
+                .getResourceManager()
+                .RunVdsCommand(
+                        VDSCommandType.DeleteImageGroup,
+                        buildDeleteMemoryConfParams(guids));
+
+        if (!vdsRetValue.getSucceeded()) {
+            return null;
+        }
+
+        Guid guid2 = enclosingCommand.createTask(taskId2, 
vdsRetValue.getCreationInfo(),
+                enclosingCommand.getActionType());
+        enclosingCommand.getTaskIdList().add(guid2);
+        return guid2;
+    }
 }


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

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

Reply via email to