From 017a0c3d6c9dbfe65c81612ccc388a40ed3e81fc Mon Sep 17 00:00:00 2001 From: Iustin Pop <iustin@google.com> Date: Tue, 21 Dec 2010 11:24:19 +0100 Subject: [PATCH] Move part of the loader pipeline to ClusterData Signed-off-by: Iustin Pop <iustin@google.com> Reviewed-by: Balazs Lecz <leczb@google.com> --- Ganeti/HTools/ExtLoader.hs | 18 ++++++++---------- Ganeti/HTools/IAlloc.hs | 5 +++-- Ganeti/HTools/Loader.hs | 4 ++-- Ganeti/HTools/QC.hs | 2 +- hail.hs | 4 ++-- hbal.hs | 3 ++- hscan.hs | 6 +++--- hspace.hs | 3 ++- 8 files changed, 23 insertions(+), 22 deletions(-) diff --git a/Ganeti/HTools/ExtLoader.hs b/Ganeti/HTools/ExtLoader.hs index 9db8f8114..17726d106 100644 --- a/Ganeti/HTools/ExtLoader.hs +++ b/Ganeti/HTools/ExtLoader.hs @@ -31,7 +31,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA module Ganeti.HTools.ExtLoader ( loadExternalData - , Loader.commonSuffix + , commonSuffix ) where import Data.Maybe (isJust, fromJust) @@ -46,10 +46,8 @@ import qualified Ganeti.HTools.Rapi as Rapi #endif import qualified Ganeti.HTools.Simu as Simu import qualified Ganeti.HTools.Text as Text -import qualified Ganeti.HTools.Loader as Loader -import qualified Ganeti.HTools.Instance as Instance -import qualified Ganeti.HTools.Node as Node -import qualified Ganeti.HTools.Group as Group +import Ganeti.HTools.Loader (mergeData, checkData, ClusterData(..) + , commonSuffix) import Ganeti.HTools.Types import Ganeti.HTools.CLI @@ -75,7 +73,7 @@ parseUtilisation line = -- | External tool data loader from a variety of sources. loadExternalData :: Options - -> IO (Group.List, Node.List, Instance.List, [String]) + -> IO ClusterData loadExternalData opts = do let mhost = optMaster opts lsock = optLuxi opts @@ -120,8 +118,8 @@ loadExternalData opts = do | setFile -> wrapIO $ Text.loadData $ fromJust tfile | otherwise -> return $ Bad "No backend selected! Exiting." - let ldresult = input_data >>= Loader.mergeData util_data' exTags exInsts - (gl, loaded_nl, il, tags) <- + let ldresult = input_data >>= mergeData util_data' exTags exInsts + cdata <- (case ldresult of Ok x -> return x Bad s -> do @@ -129,10 +127,10 @@ loadExternalData opts = do :: IO () exitWith $ ExitFailure 1 ) - let (fix_msgs, fixed_nl) = Loader.checkData loaded_nl il + let (fix_msgs, nl) = checkData (cdNodes cdata) (cdInstances cdata) unless (null fix_msgs || optVerbose opts == 0) $ do hPutStrLn stderr "Warning: cluster has inconsistent data:" hPutStrLn stderr . unlines . map (printf " - %s") $ fix_msgs - return (gl, fixed_nl, il, tags) + return cdata {cdNodes = nl} diff --git a/Ganeti/HTools/IAlloc.hs b/Ganeti/HTools/IAlloc.hs index 68a598f5b..e55d0e3bd 100644 --- a/Ganeti/HTools/IAlloc.hs +++ b/Ganeti/HTools/IAlloc.hs @@ -130,7 +130,8 @@ parseData body = do let (kti, il) = assignIndices iobj -- cluster tags ctags <- fromObj "cluster_tags" obj - (map_g, map_n, map_i, ptags) <- mergeData [] [] [] (gl, nl, il, ctags) + cdata <- mergeData [] [] [] (gl, nl, il, ctags) + let map_n = cdNodes cdata optype <- fromObj "type" request rqtype <- case optype of @@ -156,7 +157,7 @@ parseData body = do let ex_ndx = map Node.idx ex_nodes return $ Evacuate ex_ndx other -> fail ("Invalid request type '" ++ other ++ "'") - return $ Request rqtype (ClusterData map_g map_n map_i ptags) + return $ Request rqtype cdata -- | Format the result formatRVal :: RqType -> [Node.AllocElement] -> JSValue diff --git a/Ganeti/HTools/Loader.hs b/Ganeti/HTools/Loader.hs index 13c10d655..cddbd9f50 100644 --- a/Ganeti/HTools/Loader.hs +++ b/Ganeti/HTools/Loader.hs @@ -185,7 +185,7 @@ mergeData :: [(String, DynUtil)] -- ^ Instance utilisation data -> [String] -- ^ Untouchable instances -> (Group.List, Node.List, Instance.List, [String]) -- ^ Data from backends - -> Result (Group.List, Node.List, Instance.List, [String]) + -> Result ClusterData mergeData um extags exinsts (gl, nl, il2, tags) = let il = Container.elems il2 il3 = foldl' (\im (name, n_util) -> @@ -209,7 +209,7 @@ mergeData um extags exinsts (gl, nl, il2, tags) = in if not $ all (`elem` all_inst_names) exinsts then Bad $ "Some of the excluded instances are unknown: " ++ show (exinsts \\ all_inst_names) - else Ok (gl, snl, sil, tags) + else Ok (ClusterData gl snl sil tags) -- | Checks the cluster data for consistency. checkData :: Node.List -> Instance.List diff --git a/Ganeti/HTools/QC.hs b/Ganeti/HTools/QC.hs index 536d1bf2d..d574bb0e9 100644 --- a/Ganeti/HTools/QC.hs +++ b/Ganeti/HTools/QC.hs @@ -852,7 +852,7 @@ prop_Loader_mergeData ns = in case Loader.mergeData [] [] [] (Container.empty, na, Container.empty, []) of Types.Bad _ -> False - Types.Ok (_, nl, il, _) -> + Types.Ok (Loader.ClusterData _ nl il _) -> let nodes = Container.elems nl instances = Container.elems il in (sum . map (length . Node.pList)) nodes == 0 && diff --git a/hail.hs b/hail.hs index ed6700571..78eb8e11a 100644 --- a/hail.hs +++ b/hail.hs @@ -89,9 +89,9 @@ readRequest opts args = do Ok rq -> return rq r2 <- if isJust (optDataFile opts) || (not . null . optNodeSim) opts then do - (gl, nl, il, ctags) <- loadExternalData opts + cdata <- loadExternalData opts let Request rqt _ = r1 - return $ Request rqt (ClusterData gl nl il ctags) + return $ Request rqt cdata else return r1 return r2 diff --git a/hbal.hs b/hbal.hs index 455a751cc..7db7b601f 100644 --- a/hbal.hs +++ b/hbal.hs @@ -49,6 +49,7 @@ import Ganeti.HTools.CLI import Ganeti.HTools.ExtLoader import Ganeti.HTools.Utils import Ganeti.HTools.Types +import Ganeti.HTools.Loader (ClusterData(..)) import Ganeti.HTools.Text (serializeCluster) @@ -235,7 +236,7 @@ main = do verbose = optVerbose opts shownodes = optShowNodes opts - (gl, fixed_nl, ilf, ctags) <- loadExternalData opts + (ClusterData gl fixed_nl ilf ctags) <- loadExternalData opts let offline_names = optOffline opts all_nodes = Container.elems fixed_nl diff --git a/hscan.hs b/hscan.hs index e99efebfd..3c5876963 100644 --- a/hscan.hs +++ b/hscan.hs @@ -45,7 +45,7 @@ import qualified Ganeti.HTools.Instance as Instance import qualified Ganeti.HTools.Rapi as Rapi #endif import qualified Ganeti.HTools.Luxi as Luxi -import qualified Ganeti.HTools.Loader as Loader +import Ganeti.HTools.Loader (checkData, mergeData, ClusterData(..)) import Ganeti.HTools.Text (serializeCluster) import Ganeti.HTools.CLI @@ -93,8 +93,8 @@ fixSlash = map (\x -> if x == '/' then '_' else x) processData :: Result (Group.List, Node.List, Instance.List, [String]) -> Result (Group.List, Node.List, Instance.List, String) processData input_data = do - (gl, nl, il, ctags) <- input_data >>= Loader.mergeData [] [] [] - let (_, fix_nl) = Loader.checkData nl il + (ClusterData gl nl il ctags) <- input_data >>= mergeData [] [] [] + let (_, fix_nl) = checkData nl il adata = serializeCluster gl nl il ctags return (gl, fix_nl, il, adata) diff --git a/hspace.hs b/hspace.hs index 2678c9dae..434a77c5a 100644 --- a/hspace.hs +++ b/hspace.hs @@ -47,6 +47,7 @@ import Ganeti.HTools.Types import Ganeti.HTools.CLI import Ganeti.HTools.ExtLoader import Ganeti.HTools.Text (serializeCluster) +import Ganeti.HTools.Loader (ClusterData(..)) -- | Options list and functions options :: [OptType] @@ -206,7 +207,7 @@ main = do ispec = optISpec opts shownodes = optShowNodes opts - (gl, fixed_nl, il, ctags) <- loadExternalData opts + (ClusterData gl fixed_nl il ctags) <- loadExternalData opts printKeys $ map (\(a, fn) -> ("SPEC_" ++ a, fn ispec)) specData printKeys [ ("SPEC_RQN", printf "%d" (optINodes opts)) ] -- GitLab