commit 36162faf63d491ce6c8db9cd104459cde5925e26
Author: Iustin Pop <iustin@google.com>
Date:   Fri Feb 22 14:59:31 2013 +0100

    Rename/make uniform the other query entities
    
    Following the new naming style introduced in Exports.hs, this patch
    renames the other resources to export non-qualified names (fieldMap as
    opposed to nodeFieldMap), and to use qualified module imports.
    
    Also fixes a haddock issue in a docstring.
    
    Signed-off-by: Iustin Pop <iustin@google.com>
    Reviewed-by: Guido Trotter <ultrotter@google.com>

diff --git a/src/Ganeti/Query/Group.hs b/src/Ganeti/Query/Group.hs
index 7711dea..53ba1fd 100644
--- a/src/Ganeti/Query/Group.hs
+++ b/src/Ganeti/Query/Group.hs
@@ -4,7 +4,7 @@
 
 {-
 
-Copyright (C) 2012 Google Inc.
+Copyright (C) 2012, 2013 Google Inc.
 
 This program is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
@@ -24,8 +24,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 -}
 
 module Ganeti.Query.Group
-  ( GroupRuntime(..)
-  , groupFieldsMap
+  ( Runtime(..)
+  , fieldsMap
   ) where
 
 import qualified Data.Map as Map
@@ -37,9 +37,9 @@ import Ganeti.Query.Common
 import Ganeti.Query.Types
 
 -- | There is no runtime.
-data GroupRuntime = GroupRuntime
+data Runtime = Runtime
 
-groupFields :: FieldList NodeGroup GroupRuntime
+groupFields :: FieldList NodeGroup Runtime
 groupFields =
   [ (FieldDefinition "alloc_policy" "AllocPolicy" QFTText
        "Allocation policy for group",
@@ -86,6 +86,6 @@ groupFields =
   tagsFields
 
 -- | The group fields map.
-groupFieldsMap :: FieldMap NodeGroup GroupRuntime
-groupFieldsMap =
+fieldsMap :: FieldMap NodeGroup Runtime
+fieldsMap =
   Map.fromList $ map (\v@(f, _, _) -> (fdefName f, v)) groupFields
diff --git a/src/Ganeti/Query/Network.hs b/src/Ganeti/Query/Network.hs
index a9c46c7..52c6f8b 100644
--- a/src/Ganeti/Query/Network.hs
+++ b/src/Ganeti/Query/Network.hs
@@ -4,7 +4,7 @@
 
 {-
 
-Copyright (C) 2012 Google Inc.
+Copyright (C) 2012, 2013 Google Inc.
 
 This program is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
@@ -27,11 +27,11 @@ module Ganeti.Query.Network
   ( getGroupConnection
   , getNetworkUuid
   , instIsConnected
-  , NetworkRuntime(..)
-  , networkFieldsMap
+  , Runtime(..)
+  , fieldsMap
   ) where
 
--- FIXME: everything except NetworkRuntime(..) and networkFieldsMap
+-- FIXME: everything except Runtime(..) and fieldsMap
 -- is only exported for testing.
 
 import qualified Data.Map as Map
@@ -46,9 +46,10 @@ import Ganeti.Query.Common
 import Ganeti.Query.Types
 import Ganeti.Types
 
-data NetworkRuntime = NetworkRuntime
+-- | There is no actual runtime.
+data Runtime = Runtime
 
-networkFields :: FieldList Network NetworkRuntime
+networkFields :: FieldList Network Runtime
 networkFields =
   [ (FieldDefinition "name" "Name" QFTText "Network name",
      FieldSimple (rsNormal . networkName), QffNormal)
@@ -90,8 +91,8 @@ networkFields =
   tagsFields
 
 -- | The group fields map.
-networkFieldsMap :: FieldMap Network NetworkRuntime
-networkFieldsMap =
+fieldsMap :: FieldMap Network Runtime
+fieldsMap =
   Map.fromList $ map (\v@(f, _, _) -> (fdefName f, v)) networkFields
 
 -- TODO: the following fields are not implemented yet: external_reservations
diff --git a/src/Ganeti/Query/Node.hs b/src/Ganeti/Query/Node.hs
index 53bf6d1..5583054 100644
--- a/src/Ganeti/Query/Node.hs
+++ b/src/Ganeti/Query/Node.hs
@@ -4,7 +4,7 @@
 
 {-
 
-Copyright (C) 2012 Google Inc.
+Copyright (C) 2012, 2013 Google Inc.
 
 This program is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
@@ -24,9 +24,9 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 -}
 
 module Ganeti.Query.Node
-  ( NodeRuntime
-  , nodeFieldsMap
-  , maybeCollectLiveData
+  ( Runtime
+  , fieldsMap
+  , collectLiveData
   ) where
 
 import Control.Applicative
@@ -42,8 +42,8 @@ import Ganeti.Query.Language
 import Ganeti.Query.Common
 import Ganeti.Query.Types
 
--- | NodeRuntime is the resulting type for NodeInfo call.
-type NodeRuntime = Either RpcError RpcResultNodeInfo
+-- | Runtime is the resulting type for NodeInfo call.
+type Runtime = Either RpcError RpcResultNodeInfo
 
 -- | List of node live fields.
 nodeLiveFieldsDefs :: [(FieldName, FieldTitle, FieldType, String, FieldDoc)]
@@ -93,7 +93,7 @@ nodeLiveFieldExtract "mtotal" res =
 nodeLiveFieldExtract _ _ = J.JSNull
 
 -- | Helper for extracting field from RPC result.
-nodeLiveRpcCall :: FieldName -> NodeRuntime -> Node -> ResultEntry
+nodeLiveRpcCall :: FieldName -> Runtime -> Node -> ResultEntry
 nodeLiveRpcCall fname (Right res) _ =
   case nodeLiveFieldExtract fname res of
     J.JSNull -> rsNoData
@@ -103,7 +103,7 @@ nodeLiveRpcCall _ (Left err) _ =
 
 -- | Builder for node live fields.
 nodeLiveFieldBuilder :: (FieldName, FieldTitle, FieldType, String, FieldDoc)
-                     -> FieldData Node NodeRuntime
+                     -> FieldData Node Runtime
 nodeLiveFieldBuilder (fname, ftitle, ftype, _, fdoc) =
   ( FieldDefinition fname ftitle ftype fdoc
   , FieldRuntime $ nodeLiveRpcCall fname
@@ -129,7 +129,7 @@ getNodePower cfg node =
                   else rsNormal (nodePowered node)
 
 -- | List of all node fields.
-nodeFields :: FieldList Node NodeRuntime
+nodeFields :: FieldList Node Runtime
 nodeFields =
   [ (FieldDefinition "drained" "Drained" QFTBool "Whether node is drained",
      FieldSimple (rsNormal . nodeDrained), QffNormal)
@@ -208,19 +208,19 @@ nodeFields =
   tagsFields
 
 -- | The node fields map.
-nodeFieldsMap :: FieldMap Node NodeRuntime
-nodeFieldsMap =
+fieldsMap :: FieldMap Node Runtime
+fieldsMap =
   Map.fromList $ map (\v@(f, _, _) -> (fdefName f, v)) nodeFields
 
 -- | Collect live data from RPC query if enabled.
 --
 -- FIXME: Check which fields we actually need and possibly send empty
--- hvs/vgs if no info from hypervisor/volume group respectively is
+-- hvs\/vgs if no info from hypervisor\/volume group respectively is
 -- required
-maybeCollectLiveData:: Bool -> ConfigData -> [Node] -> IO [(Node, NodeRuntime)]
-maybeCollectLiveData False _ nodes =
+collectLiveData:: Bool -> ConfigData -> [Node] -> IO [(Node, Runtime)]
+collectLiveData False _ nodes =
   return $ zip nodes (repeat $ Left (RpcResultError "Live data disabled"))
-maybeCollectLiveData True cfg nodes = do
+collectLiveData True cfg nodes = do
   let vgs = [clusterVolumeGroupName $ configCluster cfg]
       hvs = [getDefaultHypervisor cfg]
       step n (bn, gn, em) =
diff --git a/src/Ganeti/Query/Query.hs b/src/Ganeti/Query/Query.hs
index 3e5d7ec..d6836b4 100644
--- a/src/Ganeti/Query/Query.hs
+++ b/src/Ganeti/Query/Query.hs
@@ -70,10 +70,10 @@ import Ganeti.Query.Common
 import qualified Ganeti.Query.Export as Export
 import Ganeti.Query.Filter
 import qualified Ganeti.Query.Job as Query.Job
-import Ganeti.Query.Group
+import qualified Ganeti.Query.Group as Group
 import Ganeti.Query.Language
-import Ganeti.Query.Network
-import Ganeti.Query.Node
+import qualified Ganeti.Query.Network as Network
+import qualified Ganeti.Query.Node as Node
 import Ganeti.Query.Types
 import Ganeti.Path
 import Ganeti.Types
@@ -168,8 +168,8 @@ queryInner :: ConfigData   -- ^ The current configuration
 
 queryInner cfg live (Query (ItemTypeOpCode QRNode) fields qfilter) wanted =
   runResultT $ do
-  cfilter <- resultT $ compileFilter nodeFieldsMap qfilter
-  let selected = getSelectedFields nodeFieldsMap fields
+  cfilter <- resultT $ compileFilter Node.fieldsMap qfilter
+  let selected = getSelectedFields Node.fieldsMap fields
       (fdefs, fgetters, _) = unzip3 selected
       live' = live && needsLiveData fgetters
   nodes <- resultT $ case wanted of
@@ -182,15 +182,15 @@ queryInner cfg live (Query (ItemTypeOpCode QRNode) fields qfilter) wanted =
                       nodes
   -- here we would run the runtime data gathering, then filter again
   -- the nodes, based on existing runtime data
-  nruntimes <- lift $ maybeCollectLiveData live' cfg fnodes
+  nruntimes <- lift $ Node.collectLiveData live' cfg fnodes
   let fdata = map (\(node, nrt) -> map (execGetter cfg nrt node) fgetters)
               nruntimes
   return QueryResult { qresFields = fdefs, qresData = fdata }
 
 queryInner cfg _ (Query (ItemTypeOpCode QRGroup) fields qfilter) wanted =
   return $ do
-  cfilter <- compileFilter groupFieldsMap qfilter
-  let selected = getSelectedFields groupFieldsMap fields
+  cfilter <- compileFilter Group.fieldsMap qfilter
+  let selected = getSelectedFields Group.fieldsMap fields
       (fdefs, fgetters, _) = unzip3 selected
   groups <- case wanted of
               [] -> Ok . niceSortKey groupName .
@@ -199,13 +199,13 @@ queryInner cfg _ (Query (ItemTypeOpCode QRGroup) fields qfilter) wanted =
   -- there is no live data for groups, so filtering is much simpler
   fgroups <- filterM (\n -> evaluateFilter cfg Nothing n cfilter) groups
   let fdata = map (\node ->
-                       map (execGetter cfg GroupRuntime node) fgetters) fgroups
+                     map (execGetter cfg Group.Runtime node) fgetters) fgroups
   return QueryResult { qresFields = fdefs, qresData = fdata }
 
 queryInner cfg _ (Query (ItemTypeOpCode QRNetwork) fields qfilter) wanted =
   return $ do
-  cfilter <- compileFilter networkFieldsMap qfilter
-  let selected = getSelectedFields networkFieldsMap fields
+  cfilter <- compileFilter Network.fieldsMap qfilter
+  let selected = getSelectedFields Network.fieldsMap fields
       (fdefs, fgetters, _) = unzip3 selected
   networks <- case wanted of
                 [] -> Ok . niceSortKey (fromNonEmpty . networkName) .
@@ -213,7 +213,7 @@ queryInner cfg _ (Query (ItemTypeOpCode QRNetwork) fields qfilter) wanted =
                 _  -> mapM (getNetwork cfg) wanted
   fnetworks <- filterM (\n -> evaluateFilter cfg Nothing n cfilter) networks
   let fdata = map (\network ->
-                   map (execGetter cfg NetworkRuntime network) fgetters)
+                   map (execGetter cfg Network.Runtime network) fgetters)
                    fnetworks
   return QueryResult { qresFields = fdefs, qresData = fdata }
 
@@ -308,10 +308,10 @@ fieldsExtractor fieldsMap fields =
 -- | Query fields call.
 queryFields :: QueryFields -> ErrorResult QueryFieldsResult
 queryFields (QueryFields (ItemTypeOpCode QRNode) fields) =
-  Ok $ fieldsExtractor nodeFieldsMap fields
+  Ok $ fieldsExtractor Node.fieldsMap fields
 
 queryFields (QueryFields (ItemTypeOpCode QRGroup) fields) =
-  Ok $ fieldsExtractor groupFieldsMap fields
+  Ok $ fieldsExtractor Group.fieldsMap fields
 
 queryFields (QueryFields (ItemTypeLuxi QRJob) fields) =
   Ok $ fieldsExtractor Query.Job.fieldsMap fields
diff --git a/test/hs/Test/Ganeti/Query/Query.hs b/test/hs/Test/Ganeti/Query/Query.hs
index 3b9ca53..3cf345c 100644
--- a/test/hs/Test/Ganeti/Query/Query.hs
+++ b/test/hs/Test/Ganeti/Query/Query.hs
@@ -7,7 +7,7 @@
 
 {-
 
-Copyright (C) 2009, 2010, 2011, 2012 Google Inc.
+Copyright (C) 2009, 2010, 2011, 2012, 2013 Google Inc.
 
 This program is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
@@ -45,9 +45,9 @@ import Test.Ganeti.Objects (genEmptyCluster)
 import Ganeti.BasicTypes
 import Ganeti.Errors
 import Ganeti.Query.Filter
-import Ganeti.Query.Group
+import qualified Ganeti.Query.Group as Group
 import Ganeti.Query.Language
-import Ganeti.Query.Node
+import qualified Ganeti.Query.Node as Node
 import Ganeti.Query.Query
 import qualified Ganeti.Query.Job as Job
 
@@ -68,7 +68,7 @@ hasUnknownFields = (QFTUnknown `notElem`) . map fdefKind
 prop_queryNode_noUnknown :: Property
 prop_queryNode_noUnknown =
   forAll (choose (0, maxNodes) >>= genEmptyCluster) $ \cluster ->
-  forAll (elements (Map.keys nodeFieldsMap)) $ \field -> monadicIO $ do
+  forAll (elements (Map.keys Node.fieldsMap)) $ \field -> monadicIO $ do
   QueryResult fdefs fdata <-
     run (query cluster False (Query (ItemTypeOpCode QRNode)
                               [field] EmptyFilter)) >>= resultProp
@@ -88,7 +88,7 @@ prop_queryNode_noUnknown =
 prop_queryNode_Unknown :: Property
 prop_queryNode_Unknown =
   forAll (choose (0, maxNodes) >>= genEmptyCluster) $ \cluster ->
-  forAll (arbitrary `suchThat` (`notElem` Map.keys nodeFieldsMap))
+  forAll (arbitrary `suchThat` (`notElem` Map.keys Node.fieldsMap))
     $ \field -> monadicIO $ do
   QueryResult fdefs fdata <-
     run (query cluster False (Query (ItemTypeOpCode QRNode)
@@ -136,7 +136,7 @@ prop_queryNode_types :: Property
 prop_queryNode_types =
   forAll (choose (0, maxNodes)) $ \numnodes ->
   forAll (genEmptyCluster numnodes) $ \cfg ->
-  forAll (elements (Map.keys nodeFieldsMap)) $ \field -> monadicIO $ do
+  forAll (elements (Map.keys Node.fieldsMap)) $ \field -> monadicIO $ do
   QueryResult fdefs fdata <-
     run (query cfg False (Query (ItemTypeOpCode QRNode)
                           [field] EmptyFilter)) >>= resultProp
@@ -160,7 +160,7 @@ case_queryNode_allfields = do
               Ok (QueryFieldsResult v) -> return v
    let field_sort = compare `on` fdefName
    assertEqual "Mismatch in all fields list"
-     (sortBy field_sort . map (\(f, _, _) -> f) $ Map.elems nodeFieldsMap)
+     (sortBy field_sort . map (\(f, _, _) -> f) $ Map.elems Node.fieldsMap)
      (sortBy field_sort fdefs)
 
 -- ** Group queries
@@ -168,7 +168,7 @@ case_queryNode_allfields = do
 prop_queryGroup_noUnknown :: Property
 prop_queryGroup_noUnknown =
   forAll (choose (0, maxNodes) >>= genEmptyCluster) $ \cluster ->
-   forAll (elements (Map.keys groupFieldsMap)) $ \field -> monadicIO $ do
+   forAll (elements (Map.keys Group.fieldsMap)) $ \field -> monadicIO $ do
    QueryResult fdefs fdata <-
      run (query cluster False (Query (ItemTypeOpCode QRGroup)
                                [field] EmptyFilter)) >>=
@@ -188,7 +188,7 @@ prop_queryGroup_noUnknown =
 prop_queryGroup_Unknown :: Property
 prop_queryGroup_Unknown =
   forAll (choose (0, maxNodes) >>= genEmptyCluster) $ \cluster ->
-  forAll (arbitrary `suchThat` (`notElem` Map.keys groupFieldsMap))
+  forAll (arbitrary `suchThat` (`notElem` Map.keys Group.fieldsMap))
     $ \field -> monadicIO $ do
   QueryResult fdefs fdata <-
     run (query cluster False (Query (ItemTypeOpCode QRGroup)
@@ -212,7 +212,7 @@ prop_queryGroup_types :: Property
 prop_queryGroup_types =
   forAll (choose (0, maxNodes)) $ \numnodes ->
   forAll (genEmptyCluster numnodes) $ \cfg ->
-  forAll (elements (Map.keys groupFieldsMap)) $ \field -> monadicIO $ do
+  forAll (elements (Map.keys Group.fieldsMap)) $ \field -> monadicIO $ do
   QueryResult fdefs fdata <-
     run (query cfg False (Query (ItemTypeOpCode QRGroup)
                           [field] EmptyFilter)) >>= resultProp
@@ -232,7 +232,7 @@ case_queryGroup_allfields = do
               Ok (QueryFieldsResult v) -> return v
    let field_sort = compare `on` fdefName
    assertEqual "Mismatch in all fields list"
-     (sortBy field_sort . map (\(f, _, _) -> f) $ Map.elems groupFieldsMap)
+     (sortBy field_sort . map (\(f, _, _) -> f) $ Map.elems Group.fieldsMap)
      (sortBy field_sort fdefs)
 
 -- ** Job queries
