Commit 446d8827 authored by Iustin Pop's avatar Iustin Pop
Browse files

Move checkData from Cluster to Loader

This moves the remaining loading function to Loader (together with its
associated support functions).
parent 75d1edf8
......@@ -31,8 +31,6 @@ module Ganeti.HTools.Cluster
, checkMove
, compCV
, printStats
-- * Loading functions
, checkData
) where
import Data.List
......@@ -681,50 +679,3 @@ printStats nl =
let (mem_cv, dsk_cv, n1_score, res_cv, off_score) = compDetailedCV nl
in printf "f_mem=%.8f, r_mem=%.8f, f_dsk=%.8f, n1=%.3f, uf=%.3f"
mem_cv res_cv dsk_cv n1_score off_score
-- Balancing functions
-- Loading functions
-- | Compute the amount of memory used by primary instances on a node.
nodeImem :: Node.Node -> InstanceList -> Int
nodeImem node il =
let rfind = flip Container.find $ il
in sum . map Instance.mem .
map rfind $ Node.plist node
-- | Compute the amount of disk used by instances on a node (either primary
-- or secondary).
nodeIdsk :: Node.Node -> InstanceList -> Int
nodeIdsk node il =
let rfind = flip Container.find $ il
in sum . map Instance.dsk .
map rfind $ (Node.plist node) ++ (Node.slist node)
-- | Check cluster data for consistency
checkData :: NodeList -> InstanceList -> NameList -> NameList
-> ([String], NodeList)
checkData nl il ktn _ =
Container.mapAccum
(\ msgs node ->
let nname = fromJust $ lookup (Node.idx node) ktn
nilst = map (flip Container.find $ il) (Node.plist node)
dilst = filter (not . Instance.running) nilst
adj_mem = sum . map Instance.mem $ dilst
delta_mem = (truncate $ Node.t_mem node)
- (Node.n_mem node)
- (Node.f_mem node)
- (nodeImem node il)
+ adj_mem
delta_dsk = (truncate $ Node.t_dsk node)
- (Node.f_dsk node)
- (nodeIdsk node il)
newn = Node.setFmem (Node.setXmem node delta_mem)
(Node.f_mem node - adj_mem)
umsg1 = if delta_mem > 512 || delta_dsk > 1024
then [printf "node %s is missing %d MB ram \
\and %d GB disk"
nname delta_mem (delta_dsk `div` 1024)]
else []
in (msgs ++ umsg1, newn)
) [] nl
......@@ -5,10 +5,16 @@ This module holds the common code for loading the cluster state from external so
-}
module Ganeti.HTools.Loader
where
( mergeData
, checkData
, assignIndices
, lookupNode
, swapPairs
) where
import Data.List
import Data.Maybe (isNothing, fromJust)
import Data.Maybe (fromJust)
import Text.Printf (printf)
import qualified Ganeti.HTools.Container as Container
import qualified Ganeti.HTools.Instance as Instance
......@@ -99,3 +105,46 @@ mergeData (ktn, nl, kti, il) = do
stn = stripSuffix common_suffix xtn
sti = stripSuffix common_suffix xti
return (nl3, il3, common_suffix, stn, sti)
-- | Check cluster data for consistency
checkData :: NodeList -> InstanceList -> NameList -> NameList
-> ([String], NodeList)
checkData nl il ktn _ =
Container.mapAccum
(\ msgs node ->
let nname = fromJust $ lookup (Node.idx node) ktn
nilst = map (flip Container.find $ il) (Node.plist node)
dilst = filter (not . Instance.running) nilst
adj_mem = sum . map Instance.mem $ dilst
delta_mem = (truncate $ Node.t_mem node)
- (Node.n_mem node)
- (Node.f_mem node)
- (nodeImem node il)
+ adj_mem
delta_dsk = (truncate $ Node.t_dsk node)
- (Node.f_dsk node)
- (nodeIdsk node il)
newn = Node.setFmem (Node.setXmem node delta_mem)
(Node.f_mem node - adj_mem)
umsg1 = if delta_mem > 512 || delta_dsk > 1024
then [printf "node %s is missing %d MB ram \
\and %d GB disk"
nname delta_mem (delta_dsk `div` 1024)]
else []
in (msgs ++ umsg1, newn)
) [] nl
-- | Compute the amount of memory used by primary instances on a node.
nodeImem :: Node.Node -> InstanceList -> Int
nodeImem node il =
let rfind = flip Container.find $ il
in sum . map Instance.mem .
map rfind $ Node.plist node
-- | Compute the amount of disk used by instances on a node (either primary
-- or secondary).
nodeIdsk :: Node.Node -> InstanceList -> Int
nodeIdsk node il =
let rfind = flip Container.find $ il
in sum . map Instance.dsk .
map rfind $ (Node.plist node) ++ (Node.slist node)
......@@ -196,7 +196,7 @@ main = do
printf "Error: failed to load data. Details:\n%s\n" s
exitWith $ ExitFailure 1
)
let (fix_msgs, fixed_nl) = Cluster.checkData loaded_nl il ktn kti
let (fix_msgs, fixed_nl) = Loader.checkData loaded_nl il ktn kti
unless (null fix_msgs || verbose == 0) $ do
putStrLn "Warning: cluster has inconsistent data:"
......
......@@ -160,7 +160,7 @@ main = do
printf "Error: failed to load data. Details:\n%s\n" s
exitWith $ ExitFailure 1
)
let (fix_msgs, nl) = Cluster.checkData loaded_nl il ktn kti
let (fix_msgs, nl) = Loader.checkData loaded_nl il ktn kti
unless (null fix_msgs) $ do
putStrLn "Warning: cluster has inconsistent data:"
......
......@@ -166,7 +166,7 @@ main = do
\Details:\n%s\n" err
Ok x -> do
let (nl, il, csf, ktn, kti) = x
(_, fix_nl) = Cluster.checkData nl il ktn kti
(_, fix_nl) = Loader.checkData nl il ktn kti
putStrLn $ printCluster fix_nl il ktn kti
when (optShowNodes opts) $ do
putStr $ Cluster.printNodes ktn fix_nl
......
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