Since the data about pending locks is now contained in the lock
queries' run-time data, these queries can be answered. Just reorganize
in the requested format.

Signed-off-by: Klaus Aehlig <[email protected]>
---
 src/Ganeti/Query/Locks.hs | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/src/Ganeti/Query/Locks.hs b/src/Ganeti/Query/Locks.hs
index a915b3a..07942ee 100644
--- a/src/Ganeti/Query/Locks.hs
+++ b/src/Ganeti/Query/Locks.hs
@@ -33,6 +33,8 @@ module Ganeti.Query.Locks
 
 import qualified Text.JSON as J
 
+import Control.Arrow ((***))
+
 import Ganeti.Locking.Allocation (OwnerState(..))
 import Ganeti.Locking.Locks (GanetiLocks, ClientId, ciIdentifier)
 import Ganeti.Query.Common
@@ -63,6 +65,12 @@ getMode (Just (_, ownerinfo, _)) _
   | otherwise = rsNormal "shared"
 getMode _ _ = rsNormal J.JSNull
 
+-- | Obtain the pending requests from the runtime data.
+getPending :: RuntimeData -> a -> ResultEntry
+getPending (Just (_, _, pending)) _ =
+  rsNormal . map ((J.encode . ciIdentifier) *** (:[])) $ pending
+getPending _ _ = rsNormal ([]:: [(String, [ClientId])])
+
 -- | List of all lock fields.
 lockFields :: FieldList String RuntimeData
 lockFields =
@@ -75,8 +83,7 @@ lockFields =
   , (FieldDefinition "owner" "Owner" QFTOther "Current lock owner(s)",
      FieldRuntime getOwners, QffNormal)
   , (FieldDefinition "pending" "Pending" QFTOther "Jobs waiting for the lock",
-     FieldSimple (const $ rsNormal ([] :: [ClientId])), QffNormal)
-    -- TODO: as soon as jobs stop polling, report the pending locks
+     FieldRuntime getPending, QffNormal)
   ]
 
 -- | The lock fields map.
-- 
2.0.0.526.g5318336

Reply via email to