Arik Hadas has uploaded a new change for review.

Change subject: core: refactor ProcessDownVmCommand
......................................................................

core: refactor ProcessDownVmCommand

Minor refactoring in the newly introduced command

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


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/46/28146/1

diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ProcessDownVmCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ProcessDownVmCommand.java
index f4028b0..1b9f06a 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ProcessDownVmCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ProcessDownVmCommand.java
@@ -3,7 +3,6 @@
 import java.util.Date;
 import java.util.List;
 
-import org.ovirt.engine.core.bll.context.CommandContext;
 import org.ovirt.engine.core.bll.job.ExecutionHandler;
 import org.ovirt.engine.core.bll.quota.QuotaManager;
 import org.ovirt.engine.core.bll.snapshots.SnapshotsManager;
@@ -15,6 +14,7 @@
 import org.ovirt.engine.core.common.action.VmPoolSimpleUserParameters;
 import org.ovirt.engine.core.common.businessentities.DbUser;
 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.VmDevice;
 import org.ovirt.engine.core.common.businessentities.VmPayload;
@@ -22,10 +22,11 @@
 import org.ovirt.engine.core.common.businessentities.VmPoolMap;
 import org.ovirt.engine.core.common.businessentities.VmPoolType;
 import org.ovirt.engine.core.common.businessentities.VmWatchdog;
-import org.ovirt.engine.core.common.businessentities.Snapshot.SnapshotType;
 import org.ovirt.engine.core.common.utils.VmDeviceType;
 import org.ovirt.engine.core.compat.Guid;
 import org.ovirt.engine.core.dal.dbbroker.DbFacade;
+import org.ovirt.engine.core.dao.SnapshotDao;
+import org.ovirt.engine.core.dao.VmPoolDAO;
 import org.ovirt.engine.core.utils.log.Log;
 import org.ovirt.engine.core.utils.log.LogFactory;
 
@@ -46,11 +47,11 @@
     @Override
     protected void executeCommand() {
         Guid vmId = getParameters().getId();
-        VmPoolMap map = 
DbFacade.getInstance().getVmPoolDao().getVmPoolMapByVmGuid(vmId);
-        List<DbUser> users = 
DbFacade.getInstance().getDbUserDao().getAllForVm(vmId);
+        VmPoolMap map = getVmPoolDAO().getVmPoolMapByVmGuid(vmId);
+        List<DbUser> users = getDbUserDAO().getAllForVm(vmId);
         // Check if this is a Vm from a Vm pool, and is attached to a user
         if (map != null && users != null && !users.isEmpty()) {
-            VmPool pool = 
DbFacade.getInstance().getVmPoolDao().get(map.getvm_pool_id());
+            VmPool pool = getVmPoolDAO().get(map.getvm_pool_id());
             if (pool != null && pool.getVmPoolType() == VmPoolType.Automatic) {
                 // should be only one user in the collection
                 for (DbUser dbUser : users) {
@@ -62,14 +63,21 @@
         } else {
             // If we are dealing with a prestarted Vm or a regular Vm - clean 
stateless images
             // Otherwise this was already done in 
DetachUserFromVmFromPoolCommand
-            removeVmStatelessImages(vmId,
-                    
ExecutionHandler.createDefaultContexForTasks(getExecutionContext(), getLock()));
+            removeVmStatelessImages(vmId);
         }
 
         QuotaManager.getInstance().rollbackQuotaByVmId(vmId);
         VmHandler.removeStatelessVmUnmanagedDevices(vmId);
 
         ApplyNextRunConfiguration(vmId);
+    }
+
+    private VmPoolDAO getVmPoolDAO() {
+        return DbFacade.getInstance().getVmPoolDao();
+    }
+
+    private SnapshotDao getSnapshotDAO() {
+        return DbFacade.getInstance().getSnapshotDao();
     }
 
     @Override
@@ -81,12 +89,12 @@
      * Update vm configuration with NEXT_RUN configuration, if exists
      * @param vmId
      */
-    private static void ApplyNextRunConfiguration(Guid vmId) {
+    private void ApplyNextRunConfiguration(Guid vmId) {
         // Remove snpashot first, in case other update is in progress, it will 
block this one with exclusive lock
         // and any newer update should be preffered to this one.
-        Snapshot runSnap = DbFacade.getInstance().getSnapshotDao().get(vmId, 
SnapshotType.NEXT_RUN);
+        Snapshot runSnap = getSnapshotDAO().get(vmId, SnapshotType.NEXT_RUN);
         if (runSnap != null) {
-            DbFacade.getInstance().getSnapshotDao().remove(runSnap.getId());
+            getSnapshotDAO().remove(runSnap.getId());
             VM vm = DbFacade.getInstance().getVmDao().get(vmId);
             if (vm != null) {
                 Date originalCreationDate = vm.getVmCreationDate();
@@ -101,7 +109,7 @@
         }
     }
 
-    private static VmManagementParametersBase createUpdateVmParameters(VM vm) {
+    private VmManagementParametersBase createUpdateVmParameters(VM vm) {
         // clear non updateable fields got from config
         vm.setExportDate(null);
         vm.setOvfVersion(null);
@@ -148,12 +156,12 @@
         return updateVmParams;
     }
 
-    public static void removeVmStatelessImages(Guid vmId, CommandContext 
context) {
-        if (DbFacade.getInstance().getSnapshotDao().exists(vmId, 
SnapshotType.STATELESS)) {
+    private void removeVmStatelessImages(Guid vmId) {
+        if (getSnapshotDAO().exists(vmId, SnapshotType.STATELESS)) {
             log.infoFormat("Deleting snapshot for stateless vm {0}", vmId);
             
Backend.getInstance().runInternalAction(VdcActionType.RestoreStatelessVm,
                     new VmOperationParameterBase(vmId),
-                    context);
+                    
ExecutionHandler.createDefaultContexForTasks(getExecutionContext(), getLock()));
         }
     }
 }


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

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