Commit 756df409 authored by Iustin Pop's avatar Iustin Pop
Browse files

htools: move tiered spec map helper to Hspace.hs



This is used just in hspace, so let's help in making Cluster.hs
smaller. We also split the function in two, as computing the spec map
and formatting it are two different tasks.
Signed-off-by: default avatarIustin Pop <iustin@google.com>
Reviewed-by: default avatarGuido Trotter <ultrotter@google.com>
parent 33b9d92d
......@@ -68,14 +68,12 @@ module Ganeti.HTools.Cluster
-- * Allocation functions
, iterateAlloc
, tieredAlloc
, tieredSpecMap
-- * Node group functions
, instanceGroup
, findSplitInstances
, splitCluster
) where
import Data.Function (on)
import qualified Data.IntSet as IntSet
import Data.List
import Data.Maybe (fromJust)
......@@ -1171,18 +1169,6 @@ tieredAlloc nl il limit newinst allocnodes ixes cstats =
Ok newinst' -> tieredAlloc nl' il' newlimit
newinst' allocnodes ixes' cstats'
-- | Compute the tiered spec string description from a list of
-- allocated instances.
tieredSpecMap :: [Instance.Instance]
-> [String]
tieredSpecMap trl_ixes =
let fin_trl_ixes = reverse trl_ixes
ix_byspec = groupBy ((==) `on` Instance.specOf) fin_trl_ixes
spec_map = map (\ixs -> (Instance.specOf $ head ixs, length ixs))
ix_byspec
in map (\(spec, cnt) -> printf "%d,%d,%d=%d" (rspecMem spec)
(rspecDsk spec) (rspecCpu spec) cnt) spec_map
-- * Formatting functions
-- | Given the original and final nodes, computes the relocation description.
......
......@@ -27,6 +27,7 @@ module Ganeti.HTools.Program.Hspace (main) where
import Control.Monad
import Data.Char (toUpper, isAlphaNum)
import Data.Function (on)
import Data.List
import Data.Maybe (isJust, fromJust)
import Data.Ord (comparing)
......@@ -152,6 +153,23 @@ printResults fin_nl num_instances allocs sreason = do
-- this should be the final entry
printKeys [("OK", "1")]
-- | Compute the tiered spec counts from a list of allocated
-- instances.
tieredSpecMap :: [Instance.Instance]
-> [(RSpec, Int)]
tieredSpecMap trl_ixes =
let fin_trl_ixes = reverse trl_ixes
ix_byspec = groupBy ((==) `on` Instance.specOf) fin_trl_ixes
spec_map = map (\ixs -> (Instance.specOf $ head ixs, length ixs))
ix_byspec
in spec_map
-- | Formats a spec map to strings.
formatSpecMap :: [(RSpec, Int)] -> [String]
formatSpecMap =
map (\(spec, cnt) -> printf "%d,%d,%d=%d" (rspecMem spec)
(rspecDsk spec) (rspecCpu spec) cnt)
formatRSpec :: Double -> String -> RSpec -> [(String, String)]
formatRSpec m_cpu s r =
[ ("KM_" ++ s ++ "_CPU", show $ rspecCpu r)
......@@ -304,7 +322,7 @@ main = do
then return result_noalloc
else exitifbad (Cluster.tieredAlloc nl il Nothing (iofspec tspec)
allocnodes [] [])
let spec_map' = Cluster.tieredSpecMap trl_ixes
let spec_map' = tieredSpecMap trl_ixes
printAllocationMap verbose "Tiered allocation map" trl_nl trl_ixes
......@@ -316,7 +334,7 @@ main = do
printKeys $ map (\(a, fn) -> ("TSPEC_INI_" ++ a, fn tspec)) specData
printKeys $ printStats PTiered (Cluster.totalResources trl_nl)
printKeys [("TSPEC", intercalate " " spec_map')]
printKeys [("TSPEC", intercalate " " (formatSpecMap spec_map'))]
printAllocationStats m_cpu nl trl_nl)
-- Run the standard (avg-mode) allocation
......
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