Alona Kaplan has uploaded a new change for review.

Change subject: engine: Remove from host_device table the ids of vms which are 
down
......................................................................

engine: Remove from host_device table the ids of vms which are down

Change-Id: I728fadd7d9d4c10f905866353e07912cc55d1c9e
Signed-off-by: Alona Kaplan <alkap...@redhat.com>
---
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/hostdev/HostDeviceManager.java
1 file changed, 31 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/94/39894/1

diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/hostdev/HostDeviceManager.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/hostdev/HostDeviceManager.java
index 37c20f9..7f84993 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/hostdev/HostDeviceManager.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/hostdev/HostDeviceManager.java
@@ -1,6 +1,9 @@
 package org.ovirt.engine.core.bll.hostdev;
 
 import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
 
 import javax.enterprise.context.ApplicationScoped;
 import javax.inject.Inject;
@@ -9,15 +12,26 @@
 import org.ovirt.engine.core.common.action.VdcActionParametersBase;
 import org.ovirt.engine.core.common.action.VdcActionType;
 import org.ovirt.engine.core.common.action.VdsActionParameters;
+import org.ovirt.engine.core.common.businessentities.HostDevice;
 import org.ovirt.engine.core.common.businessentities.VDS;
 import org.ovirt.engine.core.common.businessentities.VDSStatus;
+import org.ovirt.engine.core.common.businessentities.VM;
+import org.ovirt.engine.core.compat.Guid;
+import org.ovirt.engine.core.dao.HostDeviceDao;
 import org.ovirt.engine.core.dao.VdsDAO;
+import org.ovirt.engine.core.dao.VmDAO;
 
 @ApplicationScoped
 public class HostDeviceManager {
 
     @Inject
     private VdsDAO vdsDao;
+
+    @Inject
+    private HostDeviceDao hostDeviceDao;
+
+    @Inject
+    private VmDAO vmDao;
 
     @Inject
     private BackendInternal backend;
@@ -32,5 +46,22 @@
             }
         }
         backend.runInternalMultipleActions(VdcActionType.RefreshHostDevices, 
parameters);
+        cleanupDownVmsFromDeviceTable();
+    }
+
+    private void cleanupDownVmsFromDeviceTable() {
+        List<HostDevice> hostDevices = hostDeviceDao.getAll();
+        Map<Guid, VM> chachedVms = new HashMap<>();
+
+        for (HostDevice hostDevice : hostDevices) {
+            Guid vmId = hostDevice.getVmId();
+            if (vmId != null) {
+                VM vm = chachedVms.containsKey(vmId) ? chachedVms.get(vmId) : 
vmDao.get(vmId);
+
+                if (vm.isDown()) {
+                    hostDeviceDao.setVmIdOnHostDevice(hostDevice.getId(), 
null);
+                }
+            }
+        }
     }
 }


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

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

Reply via email to