From 9a94c848ea6c47871b700f7770adc8340d0679f4 Mon Sep 17 00:00:00 2001
From: Iustin Pop <iustin@google.com>
Date: Sun, 19 Aug 2012 00:04:45 +0200
Subject: [PATCH] Switch Luxi Query operation to use a proper filter

Until now, since we didn't have a proper type for the encoded query
filters, we were ignoring the filters and handled them as null values
(JSNull and respectively ()). With the current Query2 implementation,
we can actually use correct filters (we can send filters the client
side, and on server side we can decode them).

Signed-off-by: Iustin Pop <iustin@google.com>
Reviewed-by: Agata Murawska <agatamurawska@google.com>
---
 htools/Ganeti/HTools/Luxi.hs |  8 +++++---
 htools/Ganeti/HTools/QC.hs   |  2 +-
 htools/Ganeti/Luxi.hs        | 17 +++++++++--------
 3 files changed, 15 insertions(+), 12 deletions(-)

diff --git a/htools/Ganeti/HTools/Luxi.hs b/htools/Ganeti/HTools/Luxi.hs
index 44d90b894..109ccdb50 100644
--- a/htools/Ganeti/HTools/Luxi.hs
+++ b/htools/Ganeti/HTools/Luxi.hs
@@ -39,6 +39,7 @@ import qualified Ganeti.HTools.Group as Group
 import qualified Ganeti.HTools.Node as Node
 import qualified Ganeti.HTools.Instance as Instance
 import Ganeti.HTools.JSON
+import Ganeti.Query2 as Query2
 
 {-# ANN module "HLint: ignore Eta reduce" #-}
 
@@ -99,7 +100,7 @@ queryNodesMsg :: L.LuxiOp
 queryNodesMsg =
   L.Query L.QRNode ["name", "mtotal", "mnode", "mfree", "dtotal", "dfree",
                     "ctotal", "offline", "drained", "vm_capable",
-                    "ndp/spindle_count", "group.uuid"] ()
+                    "ndp/spindle_count", "group.uuid"] Query2.EmptyFilter
 
 -- | The input data for instance query.
 queryInstancesMsg :: L.LuxiOp
@@ -107,7 +108,7 @@ queryInstancesMsg =
   L.Query L.QRInstance ["name", "disk_usage", "be/memory", "be/vcpus",
                         "status", "pnode", "snodes", "tags", "oper_ram",
                         "be/auto_balance", "disk_template",
-                        "be/spindle_use"] ()
+                        "be/spindle_use"] Query2.EmptyFilter
 
 -- | The input data for cluster query.
 queryClusterInfoMsg :: L.LuxiOp
@@ -116,7 +117,8 @@ queryClusterInfoMsg = L.QueryClusterInfo
 -- | The input data for node group query.
 queryGroupsMsg :: L.LuxiOp
 queryGroupsMsg =
-  L.Query L.QRGroup ["uuid", "name", "alloc_policy", "ipolicy"] ()
+  L.Query L.QRGroup ["uuid", "name", "alloc_policy", "ipolicy"]
+   Query2.EmptyFilter
 
 -- | Wraper over 'callMethod' doing node query.
 queryNodes :: L.Client -> IO (Result JSValue)
diff --git a/htools/Ganeti/HTools/QC.hs b/htools/Ganeti/HTools/QC.hs
index 1053a15e5..4b902a7b9 100644
--- a/htools/Ganeti/HTools/QC.hs
+++ b/htools/Ganeti/HTools/QC.hs
@@ -1854,7 +1854,7 @@ instance Arbitrary Luxi.LuxiOp where
   arbitrary = do
     lreq <- arbitrary
     case lreq of
-      Luxi.ReqQuery -> Luxi.Query <$> arbitrary <*> getFields <*> arbitrary
+      Luxi.ReqQuery -> Luxi.Query <$> arbitrary <*> getFields <*> genFilter
       Luxi.ReqQueryNodes -> Luxi.QueryNodes <$> (listOf getFQDN) <*>
                             getFields <*> arbitrary
       Luxi.ReqQueryGroups -> Luxi.QueryGroups <$> arbitrary <*>
diff --git a/htools/Ganeti/Luxi.hs b/htools/Ganeti/Luxi.hs
index f9eacab0d..1e59ce651 100644
--- a/htools/Ganeti/Luxi.hs
+++ b/htools/Ganeti/Luxi.hs
@@ -76,6 +76,7 @@ import Ganeti.HTools.Utils
 import Ganeti.Constants
 import Ganeti.Jobs (JobStatus)
 import Ganeti.OpCodes (OpCode)
+import qualified Ganeti.Query2 as Query2
 import Ganeti.THH
 
 -- * Utility functions
@@ -100,11 +101,12 @@ data RecvResult = RecvConnClosed    -- ^ Connection closed
 type JobId = Int
 
 $(declareSADT "QrViaLuxi"
-  [ ("QRLock", 'qrLock)
+  [ ("QRLock",     'qrLock)
   , ("QRInstance", 'qrInstance)
-  , ("QRNode", 'qrNode)
-  , ("QRGroup", 'qrGroup)
-  , ("QROs", 'qrOs)
+  , ("QRNode",     'qrNode)
+  , ("QRGroup",    'qrGroup)
+  , ("QROs",       'qrOs)
+  , ("QRJob",      'qrJob)
   ])
 $(makeJSONInstance ''QrViaLuxi)
 
@@ -113,7 +115,7 @@ $(genLuxiOp "LuxiOp"
   [(luxiReqQuery,
     [ ("what",    [t| QrViaLuxi |], [| id |])
     , ("fields",  [t| [String]  |], [| id |])
-    , ("qfilter", [t| ()        |], [| const JSNull |])
+    , ("qfilter", [t| Query2.Filter  |], [| id |])
     ])
   , (luxiReqQueryNodes,
      [ ("names",  [t| [String] |], [| id |])
@@ -360,9 +362,8 @@ decodeCall (LuxiCall call args) =
     ReqQueryClusterInfo -> do
               return QueryClusterInfo
     ReqQuery -> do
-              (what, fields, _) <-
-                fromJVal args::Result (QrViaLuxi, [String], JSValue)
-              return $ Query what fields ()
+              (what, fields, qfilter) <- fromJVal args
+              return $ Query what fields qfilter
     ReqSubmitJob -> do
               [ops1] <- fromJVal args
               ops2 <- mapM (fromJResult (luxiReqToRaw call) . J.readJSON) ops1
-- 
GitLab