Commit dc6a0f82 authored by Iustin Pop's avatar Iustin Pop

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: default avatarIustin Pop <iustin@google.com>
Reviewed-by: default avatarAgata Murawska <agatamurawska@google.com>
parent 9a94c848
......@@ -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))
......
......@@ -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)
......
......@@ -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
]
......@@ -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 |])
......
......@@ -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)
......
......@@ -126,7 +126,7 @@ allTests =
, (fast, testJSON)
, (fast, testLUXI)
, (fast, testSsconf)
, (fast, testQuery2)
, (fast, testQlang)
, (slow, testCluster)
, (fast, testRpc)
]
......
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