Commit 017a0c3d authored by Iustin Pop's avatar Iustin Pop
Browse files

Move part of the loader pipeline to ClusterData


Signed-off-by: default avatarIustin Pop <iustin@google.com>
Reviewed-by: default avatarBalazs Lecz <leczb@google.com>
parent 34c00528
......@@ -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}
......@@ -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
......
......@@ -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
......
......@@ -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 &&
......
......@@ -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
......
......@@ -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
......
......@@ -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)
......
......@@ -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)) ]
......
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