Commit 9a94c848 authored by Iustin Pop's avatar Iustin Pop
Browse files

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: default avatarIustin Pop <iustin@google.com>
Reviewed-by: default avatarAgata Murawska <agatamurawska@google.com>
parent e8a25d62
......@@ -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)
......
......@@ -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 <*>
......
......@@ -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
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment