Commit b3f0710c authored by Iustin Pop's avatar Iustin Pop
Browse files

Luxi loader: split parsing from loading

parent 748bfcc2
...@@ -26,6 +26,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA ...@@ -26,6 +26,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
module Ganeti.HTools.Luxi module Ganeti.HTools.Luxi
( (
loadData loadData
, parseData
) where ) where
import qualified Control.Exception as E import qualified Control.Exception as E
...@@ -145,9 +146,9 @@ getClusterTags v = do ...@@ -145,9 +146,9 @@ getClusterTags v = do
-- * Main loader functionality -- * Main loader functionality
-- | Builds the cluster data from an URL. -- | Builds the cluster data from an URL.
loadData :: String -- ^ Unix socket to use as source readData :: String -- ^ Unix socket to use as source
-> IO (Result (Node.AssocList, Instance.AssocList, [String])) -> IO (Result JSValue, Result JSValue, Result JSValue)
loadData master = readData master =
E.bracket E.bracket
(L.getClient master) (L.getClient master)
L.closeClient L.closeClient
...@@ -155,11 +156,20 @@ loadData master = ...@@ -155,11 +156,20 @@ loadData master =
nodes <- queryNodes s nodes <- queryNodes s
instances <- queryInstances s instances <- queryInstances s
cinfo <- queryClusterInfo s cinfo <- queryClusterInfo s
return $ do -- Result monad return (nodes, instances, cinfo)
node_data <- nodes >>= getNodes
let (node_names, node_idx) = assignIndices node_data
inst_data <- instances >>= getInstances node_names
let (_, inst_idx) = assignIndices inst_data
ctags <- cinfo >>= getClusterTags
return (node_idx, inst_idx, ctags)
) )
parseData :: (Result JSValue, Result JSValue, Result JSValue)
-> Result (Node.AssocList, Instance.AssocList, [String])
parseData (nodes, instances, cinfo) = do
node_data <- nodes >>= getNodes
let (node_names, node_idx) = assignIndices node_data
inst_data <- instances >>= getInstances node_names
let (_, inst_idx) = assignIndices inst_data
ctags <- cinfo >>= getClusterTags
return (node_idx, inst_idx, ctags)
-- | Top level function for data loading
loadData :: String -- ^ Unix socket to use as source
-> IO (Result (Node.AssocList, Instance.AssocList, [String]))
loadData master = readData master >>= return . parseData
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