From 86ea20e88c9030bb15efaeb1480411dc421d11f3 Mon Sep 17 00:00:00 2001 From: Iustin Pop <iustin@google.com> Date: Tue, 21 Dec 2010 11:59:11 +0100 Subject: [PATCH] Simplify the codeflow in hscan.hs We change processData to just load the data, and return a simpler type. Signed-off-by: Iustin Pop <iustin@google.com> Reviewed-by: Balazs Lecz <leczb@google.com> --- hscan.hs | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/hscan.hs b/hscan.hs index 631c06157..b2a4a9f7d 100644 --- a/hscan.hs +++ b/hscan.hs @@ -38,7 +38,6 @@ import Text.Printf (printf) import qualified Ganeti.HTools.Container as Container import qualified Ganeti.HTools.Cluster as Cluster -import qualified Ganeti.HTools.Group as Group import qualified Ganeti.HTools.Node as Node import qualified Ganeti.HTools.Instance as Instance #ifndef NO_CURL @@ -89,26 +88,25 @@ fixSlash :: String -> String fixSlash = map (\x -> if x == '/' then '_' else x) --- | Generates serialized data from loader input -processData :: Result ClusterData - -> Result (Group.List, Node.List, Instance.List, String) +-- | Generates serialized data from loader input. +processData :: Result ClusterData -> Result ClusterData processData input_data = do - cdata@(ClusterData gl nl il _) <- input_data >>= mergeData [] [] [] + cdata@(ClusterData _ nl il _) <- input_data >>= mergeData [] [] [] let (_, fix_nl) = checkData nl il - adata = serializeCluster cdata - return (gl, fix_nl, il, adata) + return cdata { cdNodes = fix_nl } -- | Writes cluster data out writeData :: Int -> String -> Options - -> Result (Group.List, Node.List, Instance.List, String) + -> Result ClusterData -> IO Bool writeData _ name _ (Bad err) = printf "\nError for %s: failed to load data. Details:\n%s\n" name err >> return False -writeData nlen name opts (Ok (_, nl, il, adata)) = do +writeData nlen name opts (Ok cdata) = do + let (ClusterData _ nl il _) = cdata printf "%-*s " nlen name :: IO () hFlush stdout let shownodes = optShowNodes opts @@ -118,7 +116,7 @@ writeData nlen name opts (Ok (_, nl, il, adata)) = do hFlush stdout when (isJust shownodes) $ putStr $ Cluster.printNodes nl (fromJust shownodes) - writeFile (oname <.> "data") adata + writeFile (oname <.> "data") (serializeCluster cdata) return True -- | Main function. -- GitLab