From dc6a0f82eb5d3e9b8a725a467fa0ade387ff13ee Mon Sep 17 00:00:00 2001 From: Iustin Pop <iustin@google.com> Date: Sun, 19 Aug 2012 00:33:08 +0200 Subject: [PATCH] Rename Query2.hs to Qlang.hs While starting to use the new filter types, I realised that what is currently implemented is the equivalent of `lib/qlang.py', not `lib/query.py', since we only deal with data types for now and not the actual query runtime functionality (RPC, config, etc.). Let's rename the file to be more consistent with the Python code base. Signed-off-by: Iustin Pop <iustin@google.com> Reviewed-by: Agata Murawska <agatamurawska@google.com> --- Makefile.am | 4 +-- htools/Ganeti/HTools/Luxi.hs | 8 ++--- htools/Ganeti/HTools/QC.hs | 48 +++++++++++++-------------- htools/Ganeti/Luxi.hs | 4 +-- htools/Ganeti/{Query2.hs => Qlang.hs} | 6 ++-- htools/test.hs | 2 +- 6 files changed, 36 insertions(+), 36 deletions(-) rename htools/Ganeti/{Query2.hs => Qlang.hs} (98%) diff --git a/Makefile.am b/Makefile.am index 8d412c406..0402bc9c2 100644 --- a/Makefile.am +++ b/Makefile.am @@ -413,11 +413,11 @@ HS_LIB_SRCS = \ htools/Ganeti/Objects.hs \ htools/Ganeti/OpCodes.hs \ htools/Ganeti/Rpc.hs \ + htools/Ganeti/Qlang.hs \ htools/Ganeti/Queryd.hs \ htools/Ganeti/Runtime.hs \ htools/Ganeti/Ssconf.hs \ - htools/Ganeti/THH.hs \ - htools/Ganeti/Query2.hs + htools/Ganeti/THH.hs HS_BUILT_SRCS = htools/Ganeti/HTools/Version.hs htools/Ganeti/Constants.hs HS_BUILT_SRCS_IN = $(patsubst %,%.in,$(HS_BUILT_SRCS)) diff --git a/htools/Ganeti/HTools/Luxi.hs b/htools/Ganeti/HTools/Luxi.hs index 109ccdb50..1374f3311 100644 --- a/htools/Ganeti/HTools/Luxi.hs +++ b/htools/Ganeti/HTools/Luxi.hs @@ -39,7 +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 +import Ganeti.Qlang as Qlang {-# ANN module "HLint: ignore Eta reduce" #-} @@ -100,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"] Query2.EmptyFilter + "ndp/spindle_count", "group.uuid"] Qlang.EmptyFilter -- | The input data for instance query. queryInstancesMsg :: L.LuxiOp @@ -108,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"] Query2.EmptyFilter + "be/spindle_use"] Qlang.EmptyFilter -- | The input data for cluster query. queryClusterInfoMsg :: L.LuxiOp @@ -118,7 +118,7 @@ queryClusterInfoMsg = L.QueryClusterInfo queryGroupsMsg :: L.LuxiOp queryGroupsMsg = L.Query L.QRGroup ["uuid", "name", "alloc_policy", "ipolicy"] - Query2.EmptyFilter + Qlang.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 4b902a7b9..825bea437 100644 --- a/htools/Ganeti/HTools/QC.hs +++ b/htools/Ganeti/HTools/QC.hs @@ -49,7 +49,7 @@ module Ganeti.HTools.QC , testLUXI , testSsconf , testRpc - , testQuery2 + , testQlang ) where import Test.QuickCheck @@ -79,7 +79,7 @@ import qualified Ganeti.Logging as Logging import qualified Ganeti.Luxi as Luxi import qualified Ganeti.Objects as Objects import qualified Ganeti.OpCodes as OpCodes -import qualified Ganeti.Query2 as Query2 +import qualified Ganeti.Qlang as Qlang import qualified Ganeti.Rpc as Rpc import qualified Ganeti.Runtime as Runtime import qualified Ganeti.Ssconf as Ssconf @@ -558,33 +558,33 @@ instance Arbitrary Rpc.RpcCallInstanceList where instance Arbitrary Rpc.RpcCallNodeInfo where arbitrary = Rpc.RpcCallNodeInfo <$> arbitrary <*> arbitrary --- | Custom 'Query2.Filter' generator (top-level), which enforces a +-- | Custom 'Qlang.Filter' generator (top-level), which enforces a -- (sane) limit on the depth of the generated filters. -genFilter :: Gen Query2.Filter +genFilter :: Gen Qlang.Filter genFilter = choose (0, 10) >>= genFilter' -- | Custom generator for filters that correctly halves the state of -- the generators at each recursive step, per the QuickCheck -- documentation, in order not to run out of memory. -genFilter' :: Int -> Gen Query2.Filter +genFilter' :: Int -> Gen Qlang.Filter genFilter' 0 = - oneof [ return Query2.EmptyFilter - , Query2.TrueFilter <$> getName - , Query2.EQFilter <$> getName <*> value - , Query2.LTFilter <$> getName <*> value - , Query2.GTFilter <$> getName <*> value - , Query2.LEFilter <$> getName <*> value - , Query2.GEFilter <$> getName <*> value - , Query2.RegexpFilter <$> getName <*> getName - , Query2.ContainsFilter <$> getName <*> value + oneof [ return Qlang.EmptyFilter + , Qlang.TrueFilter <$> getName + , Qlang.EQFilter <$> getName <*> value + , Qlang.LTFilter <$> getName <*> value + , Qlang.GTFilter <$> getName <*> value + , Qlang.LEFilter <$> getName <*> value + , Qlang.GEFilter <$> getName <*> value + , Qlang.RegexpFilter <$> getName <*> getName + , Qlang.ContainsFilter <$> getName <*> value ] - where value = oneof [ Query2.QuotedString <$> getName - , Query2.NumericValue <$> arbitrary + where value = oneof [ Qlang.QuotedString <$> getName + , Qlang.NumericValue <$> arbitrary ] genFilter' n = do - oneof [ Query2.AndFilter <$> vectorOf n'' (genFilter' n') - , Query2.OrFilter <$> vectorOf n'' (genFilter' n') - , Query2.NotFilter <$> genFilter' n' + oneof [ Qlang.AndFilter <$> vectorOf n'' (genFilter' n') + , Qlang.OrFilter <$> vectorOf n'' (genFilter' n') + , Qlang.NotFilter <$> genFilter' n' ] where n' = n `div` 2 -- sub-filter generator size n'' = max n' 2 -- but we don't want empty or 1-element lists, @@ -1988,15 +1988,15 @@ testSuite "Rpc" , 'prop_Rpc_noffl_request_nodeinfo ] --- * Query2 tests +-- * Qlang tests -- | Tests that serialisation/deserialisation of filters is -- idempotent. -prop_Query2_Serialisation :: Property -prop_Query2_Serialisation = +prop_Qlang_Serialisation :: Property +prop_Qlang_Serialisation = forAll genFilter $ \flt -> J.readJSON (J.showJSON flt) ==? J.Ok flt -testSuite "Query2" - [ 'prop_Query2_Serialisation +testSuite "Qlang" + [ 'prop_Qlang_Serialisation ] diff --git a/htools/Ganeti/Luxi.hs b/htools/Ganeti/Luxi.hs index 1e59ce651..8f0c2967e 100644 --- a/htools/Ganeti/Luxi.hs +++ b/htools/Ganeti/Luxi.hs @@ -76,7 +76,7 @@ import Ganeti.HTools.Utils import Ganeti.Constants import Ganeti.Jobs (JobStatus) import Ganeti.OpCodes (OpCode) -import qualified Ganeti.Query2 as Query2 +import qualified Ganeti.Qlang as Qlang import Ganeti.THH -- * Utility functions @@ -115,7 +115,7 @@ $(genLuxiOp "LuxiOp" [(luxiReqQuery, [ ("what", [t| QrViaLuxi |], [| id |]) , ("fields", [t| [String] |], [| id |]) - , ("qfilter", [t| Query2.Filter |], [| id |]) + , ("qfilter", [t| Qlang.Filter |], [| id |]) ]) , (luxiReqQueryNodes, [ ("names", [t| [String] |], [| id |]) diff --git a/htools/Ganeti/Query2.hs b/htools/Ganeti/Qlang.hs similarity index 98% rename from htools/Ganeti/Query2.hs rename to htools/Ganeti/Qlang.hs index e37e2d0be..3a7fde2b2 100644 --- a/htools/Ganeti/Query2.hs +++ b/htools/Ganeti/Qlang.hs @@ -25,7 +25,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -} -module Ganeti.Query2 +module Ganeti.Qlang ( Filter(..) , FilterValue(..) , Query(..) @@ -69,7 +69,7 @@ $(declareSADT "FieldType" ]) $(makeJSONInstance ''FieldType) --- | Supported items on which Query2 works. +-- | Supported items on which Qlang works. $(declareSADT "ItemType" [ ("QRCluster", 'C.qrCluster ) , ("QRInstance", 'C.qrInstance ) @@ -82,7 +82,7 @@ $(declareSADT "ItemType" ]) $(makeJSONInstance ''ItemType) --- * Main Query2 queries and responses. +-- * Main Qlang queries and responses. -- | Query2 query. data Query = Query ItemType Fields (Maybe Filter) diff --git a/htools/test.hs b/htools/test.hs index 24fd9e6da..7693c00b0 100644 --- a/htools/test.hs +++ b/htools/test.hs @@ -126,7 +126,7 @@ allTests = , (fast, testJSON) , (fast, testLUXI) , (fast, testSsconf) - , (fast, testQuery2) + , (fast, testQlang) , (slow, testCluster) , (fast, testRpc) ] -- GitLab