Liron Ar has uploaded a new change for review.

Change subject: core: MoveOrCopyDiskCommand - reduce query count
......................................................................

core: MoveOrCopyDiskCommand - reduce query count

When loading the vms for a disk, the vm device information is already
loaded - therefore there's no need to filter it out and then reload it
for each vm, we can use the values that were loaded during the first
query execution.

Change-Id: Ic4b15114bc72dc07de917692b60703008008ae13
Signed-off-by: Liron Aravot <lara...@redhat.com>
---
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/MoveOrCopyDiskCommand.java
M 
backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/MoveOrCopyDiskCommandTest.java
2 files changed, 20 insertions(+), 25 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/75/20975/1

diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/MoveOrCopyDiskCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/MoveOrCopyDiskCommand.java
index 406f19f..84eaec3 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/MoveOrCopyDiskCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/MoveOrCopyDiskCommand.java
@@ -28,7 +28,6 @@
 import org.ovirt.engine.core.common.businessentities.VM;
 import org.ovirt.engine.core.common.businessentities.VMStatus;
 import org.ovirt.engine.core.common.businessentities.VmDevice;
-import org.ovirt.engine.core.common.businessentities.VmDeviceId;
 import org.ovirt.engine.core.common.businessentities.VmEntityType;
 import org.ovirt.engine.core.common.businessentities.VmTemplate;
 import org.ovirt.engine.core.common.errors.VdcBllMessages;
@@ -44,7 +43,7 @@
         implements QuotaStorageDependent {
 
     private List<PermissionSubject> cachedPermsList;
-    private List<VM> cachedListVms;
+    private List<Pair<VM, VmDevice>> cachedListVms;
     private String cachedDiskIsBeingMigratedMessage;
 
     public MoveOrCopyDiskCommand(T parameters) {
@@ -208,13 +207,12 @@
      * @return
      */
     protected boolean checkCanBeMoveInVm() {
-        List<VM> vmsForDisk = getVmsForDiskId();
+        List<Pair<VM, VmDevice>> vmsForDisk = 
getVmsWithVmDeviceInfoForDiskId();
 
-        for (VM currVm : vmsForDisk) {
+        for (Pair<VM, VmDevice> pair : vmsForDisk) {
+            VM currVm = pair.getFirst();
             if (VMStatus.Down != currVm.getStatus()) {
-                VmDevice vmDevice =
-                        getVmDeviceDAO().get(new 
VmDeviceId(getImage().getId(), currVm.getId()));
-                if (vmDevice.getIsPlugged()) {
+                if (pair.getSecond().getIsPlugged()) {
                     
addCanDoActionMessage(VdcBllMessages.ACTION_TYPE_FAILED_VM_IS_NOT_DOWN);
                     return false;
                 }
@@ -228,9 +226,9 @@
      * Cache method to retrieve all the VMs related to image
      * @return List of Vms.
      */
-    private List<VM> getVmsForDiskId() {
+    private List<Pair<VM, VmDevice>> getVmsWithVmDeviceInfoForDiskId() {
         if (cachedListVms == null) {
-            cachedListVms = getVmDAO().getVmsListForDisk(getImage().getId(), 
true);
+            cachedListVms = getVmDAO().getVmsWithPlugInfo(getImage().getId());
         }
         return cachedListVms;
     }
@@ -371,11 +369,11 @@
                         
LockMessagesMatchUtil.makeLockingPair(LockingGroup.TEMPLATE, 
getDiskIsBeingMigratedMessage()));
             }
         } else {
-            List<VM> vmsForDisk = getVmsForDiskId();
+            List<Pair<VM, VmDevice>> vmsForDisk = 
getVmsWithVmDeviceInfoForDiskId();
             if (!vmsForDisk.isEmpty()) {
                 Map<String, Pair<String, String>> lockMap = new HashMap<>();
-                for (VM currVm : vmsForDisk) {
-                    lockMap.put(currVm.getId().toString(),
+                for (Pair<VM, VmDevice> pair : vmsForDisk) {
+                    lockMap.put(pair.getFirst().getId().toString(),
                             
LockMessagesMatchUtil.makeLockingPair(LockingGroup.VM, 
getDiskIsBeingMigratedMessage()));
                 }
                 return lockMap;
diff --git 
a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/MoveOrCopyDiskCommandTest.java
 
b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/MoveOrCopyDiskCommandTest.java
index 4dab5db..8d9f276 100644
--- 
a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/MoveOrCopyDiskCommandTest.java
+++ 
b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/MoveOrCopyDiskCommandTest.java
@@ -3,7 +3,6 @@
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
 import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.anyBoolean;
 import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.spy;
 import static org.mockito.Mockito.when;
@@ -28,11 +27,11 @@
 import org.ovirt.engine.core.common.businessentities.VM;
 import org.ovirt.engine.core.common.businessentities.VMStatus;
 import org.ovirt.engine.core.common.businessentities.VmDevice;
-import org.ovirt.engine.core.common.businessentities.VmDeviceId;
 import org.ovirt.engine.core.common.businessentities.VmEntityType;
 import org.ovirt.engine.core.common.businessentities.VmTemplate;
 import org.ovirt.engine.core.common.config.ConfigValues;
 import org.ovirt.engine.core.common.errors.VdcBllMessages;
+import org.ovirt.engine.core.common.utils.Pair;
 import org.ovirt.engine.core.compat.Guid;
 import org.ovirt.engine.core.dao.DiskImageDAO;
 import org.ovirt.engine.core.dao.StorageDomainDAO;
@@ -131,7 +130,6 @@
         initVm();
         initSrcStorageDomain();
         initDestStorageDomain();
-        initVmDevice();
         doReturn(vmDeviceDao).when(command).getVmDeviceDAO();
         assertFalse(command.canDoAction());
         assertTrue(command.getReturnValue()
@@ -173,14 +171,19 @@
     }
 
     private void mockGetVmsListForDisk() {
-        List<VM> vmList = new ArrayList<VM>();
+        List<Pair<VM, VmDevice>> vmList = new ArrayList<>();
         VM vm1 = new VM();
         vm1.setStatus(VMStatus.PoweringDown);
         VM vm2 = new VM();
         vm2.setStatus(VMStatus.Down);
-        vmList.add(vm1);
-        vmList.add(vm2);
-        when(vmDao.getVmsListForDisk(any(Guid.class), 
anyBoolean())).thenReturn(vmList);
+        VmDevice device1 = new VmDevice();
+        device1.setIsPlugged(true);
+        VmDevice device2 = new VmDevice();
+        device2.setIsPlugged(true);
+        vmList.add(new Pair<>(vm1, device1));
+        vmList.add(new Pair<>(vm1, device2));
+
+        when(vmDao.getVmsWithPlugInfo(any(Guid.class))).thenReturn(vmList);
     }
 
     private void initSrcStorageDomain() {
@@ -195,12 +198,6 @@
         destDomain.setStatus(StorageDomainStatus.Active);
         destDomain.setStorageType(StorageType.NFS);
         doReturn(destDomain).when(command).getStorageDomain();
-    }
-
-    private void initVmDevice() {
-        VmDevice vmDevice = new VmDevice();
-        vmDevice.setIsPlugged(true);
-        when(vmDeviceDao.get(any(VmDeviceId.class))).thenReturn(vmDevice);
     }
 
     @SuppressWarnings("unchecked")


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

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

Reply via email to