Arik Hadas has uploaded a new change for review.

Change subject: core: query long-time locks
......................................................................

core: query long-time locks

Add a method in LockManager that returns the long-time locks for a given
key. By "long-time lock" we refer to locks that are used in
async-commands for their whole execution.

This patch contains only the infrastructure. This change will be used by
queries (searches) from the UI, so entities will be returned with their
locks state, so it could be presented in the UI.

Change-Id: Iafcab44ef52d21405eeaaeb2cda4c03864a0e8e8
Signed-off-by: Arik Hadas <[email protected]>
---
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/lock/InMemoryLockManager.java
A 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/locks/Lock.java
M 
backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/lock/LockManager.java
M 
frontend/webadmin/modules/gwt-common/src/main/resources/org/ovirt/engine/core/Common.gwt.xml
4 files changed, 66 insertions(+), 0 deletions(-)


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

diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/lock/InMemoryLockManager.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/lock/InMemoryLockManager.java
index 73151b3..62fa402 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/lock/InMemoryLockManager.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/lock/InMemoryLockManager.java
@@ -25,6 +25,7 @@
 import javax.management.MBeanServer;
 import javax.management.ObjectName;
 
+import org.ovirt.engine.core.common.errors.VdcBllMessages;
 import org.ovirt.engine.core.common.utils.Pair;
 import org.ovirt.engine.core.utils.lock.EngineLock;
 import org.ovirt.engine.core.utils.lock.LockManager;
@@ -304,6 +305,26 @@
         }
     }
 
+    @Override
+    public org.ovirt.engine.core.common.locks.Lock query(String key) {
+        InternalLockView internalLockView = locks.get(key);
+        if (internalLockView == null) {
+            return null;
+        }
+
+        Set<String> messages = internalLockView.getMessages();
+        messages.remove(VdcBllMessages.ACTION_TYPE_FAILED_OBJECT_LOCKED);
+        if (messages.isEmpty()) {
+            // VdcBllMessages.ACTION_TYPE_FAILED_OBJECT_LOCKED should only be 
used for
+            // short locks (locks for the execute phase) so we filter it and 
if no
+            // other lock exists, the entity should be displayed as unlocked
+            return null;
+        }
+
+        return new org.ovirt.engine.core.common.locks.Lock(
+                internalLockView.getExclusive(), messages);
+    }
+
     /**
      * The following class represents different locks which are kept inside 
InMemoryLockManager
      */
diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/locks/Lock.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/locks/Lock.java
new file mode 100644
index 0000000..93a6578
--- /dev/null
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/locks/Lock.java
@@ -0,0 +1,37 @@
+package org.ovirt.engine.core.common.locks;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+
+public class Lock implements Serializable {
+    private static final long serialVersionUID = -4454507217567224398L;
+
+    private boolean exclusive;
+    private List<String> messages;
+
+    public Lock() {
+    }
+
+    public Lock(boolean exclusive, Set<String> messages) {
+        setExclusive(exclusive);
+        setMessages(new ArrayList(messages));
+    }
+
+    public boolean isExclusive() {
+        return exclusive;
+    }
+
+    public void setExclusive(boolean exclusive) {
+        this.exclusive = exclusive;
+    }
+
+    public List<String> getMessages() {
+        return messages;
+    }
+
+    public void setMessages(List<String> messages) {
+        this.messages = messages;
+    }
+}
diff --git 
a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/lock/LockManager.java
 
b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/lock/LockManager.java
index 9527af7..0466031 100644
--- 
a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/lock/LockManager.java
+++ 
b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/lock/LockManager.java
@@ -2,6 +2,7 @@
 
 import java.util.Set;
 
+import org.ovirt.engine.core.common.locks.Lock;
 import org.ovirt.engine.core.common.utils.Pair;
 
 
@@ -36,4 +37,10 @@
      */
     void clear();
 
+    /**
+     * Query for lock for a given key
+     * @param key - key that the lock is mapped to
+     * @return lock for the given key, null if does not exist
+     */
+    Lock query(String key);
 }
diff --git 
a/frontend/webadmin/modules/gwt-common/src/main/resources/org/ovirt/engine/core/Common.gwt.xml
 
b/frontend/webadmin/modules/gwt-common/src/main/resources/org/ovirt/engine/core/Common.gwt.xml
index 1aec05d..b529f28 100644
--- 
a/frontend/webadmin/modules/gwt-common/src/main/resources/org/ovirt/engine/core/Common.gwt.xml
+++ 
b/frontend/webadmin/modules/gwt-common/src/main/resources/org/ovirt/engine/core/Common.gwt.xml
@@ -202,6 +202,7 @@
                <include name="common/businessentities/ImageType.java" />
                <include 
name="common/businessentities/SnapshotActionEnum.java"/>
         <include name="common/businessentities/VmRngDevice.java" />
+        <include name="common/locks/Lock.java" />
                <include name="common/job/*.java" />
 
                <!-- Profiles -->


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Iafcab44ef52d21405eeaaeb2cda4c03864a0e8e8
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Arik Hadas <[email protected]>
_______________________________________________
Engine-patches mailing list
[email protected]
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to