Commit 7f119c27 authored by Iustin Pop's avatar Iustin Pop

hcheck: add two simple type aliases for readability

The same types are reused a couple of times, so let's add a couple of
type aliases for easier change later and readability.
Signed-off-by: default avatarIustin Pop <iustin@google.com>
Reviewed-by: default avatarAgata Murawska <agatamurawska@google.com>
parent 4b77c2a2
...@@ -81,6 +81,12 @@ data Phase = Initial ...@@ -81,6 +81,12 @@ data Phase = Initial
data Level = GroupLvl data Level = GroupLvl
| ClusterLvl | ClusterLvl
-- | A type alias for a group index and node\/instance lists.
type GroupInfo = (Gdx, (Node.List, Instance.List))
-- | A type alias for group stats.
type GroupStats = ((Group.Group, Double), [Int])
-- | Prefix for machine readable names. -- | Prefix for machine readable names.
htcPrefix :: String htcPrefix :: String
htcPrefix = "HCHECK" htcPrefix = "HCHECK"
...@@ -200,8 +206,7 @@ prepareClusterValues machineread stats bstats = ...@@ -200,8 +206,7 @@ prepareClusterValues machineread stats bstats =
map show stats ++ map (printBool machineread) bstats map show stats ++ map (printBool machineread) bstats
-- | Print all the statistics on a group level. -- | Print all the statistics on a group level.
printGroupStats :: Int -> Bool -> Phase -> ((Group.Group, Double), [Int]) printGroupStats :: Int -> Bool -> Phase -> GroupStats -> IO ()
-> IO ()
printGroupStats verbose machineread phase ((grp, score), stats) = do printGroupStats verbose machineread phase ((grp, score), stats) = do
let values = prepareGroupValues stats score let values = prepareGroupValues stats score
extradata = extractGroupData machineread grp extradata = extractGroupData machineread grp
...@@ -221,9 +226,7 @@ clusterNeedsRebalance stats = sum stats > 0 ...@@ -221,9 +226,7 @@ clusterNeedsRebalance stats = sum stats > 0
instances residing on offline nodes. instances residing on offline nodes.
-} -}
perGroupChecks :: Group.List perGroupChecks :: Group.List -> GroupInfo -> GroupStats
-> (Gdx, (Node.List, Instance.List))
-> ((Group.Group, Double), [Int])
perGroupChecks gl (gidx, (nl, il)) = perGroupChecks gl (gidx, (nl, il)) =
let grp = Container.find gidx gl let grp = Container.find gidx gl
offnl = filter Node.offline (Container.elems nl) offnl = filter Node.offline (Container.elems nl)
...@@ -243,7 +246,7 @@ perGroupChecks gl (gidx, (nl, il)) = ...@@ -243,7 +246,7 @@ perGroupChecks gl (gidx, (nl, il)) =
-- | Use Hbal's iterateDepth to simulate group rebalance. -- | Use Hbal's iterateDepth to simulate group rebalance.
executeSimulation :: Options -> Cluster.Table -> Double executeSimulation :: Options -> Cluster.Table -> Double
-> Gdx -> Node.List -> Instance.List -> Gdx -> Node.List -> Instance.List
-> IO (Gdx, (Node.List, Instance.List)) -> IO GroupInfo
executeSimulation opts ini_tbl min_cv gidx nl il = do executeSimulation opts ini_tbl min_cv gidx nl il = do
let imlen = maximum . map (length . Instance.alias) $ Container.elems il let imlen = maximum . map (length . Instance.alias) $ Container.elems il
nmlen = maximum . map (length . Node.alias) $ Container.elems nl nmlen = maximum . map (length . Node.alias) $ Container.elems nl
...@@ -260,8 +263,7 @@ executeSimulation opts ini_tbl min_cv gidx nl il = do ...@@ -260,8 +263,7 @@ executeSimulation opts ini_tbl min_cv gidx nl il = do
return (gidx, (fin_nl, fin_il)) return (gidx, (fin_nl, fin_il))
-- | Simulate group rebalance if group's score is not good -- | Simulate group rebalance if group's score is not good
maybeSimulateGroupRebalance :: Options -> (Gdx, (Node.List, Instance.List)) maybeSimulateGroupRebalance :: Options -> GroupInfo -> IO GroupInfo
-> IO (Gdx, (Node.List, Instance.List))
maybeSimulateGroupRebalance opts (gidx, (nl, il)) = do maybeSimulateGroupRebalance opts (gidx, (nl, il)) = do
let ini_cv = Cluster.compCV nl let ini_cv = Cluster.compCV nl
ini_tbl = Cluster.Table nl il ini_cv [] ini_tbl = Cluster.Table nl il ini_cv []
...@@ -273,8 +275,8 @@ maybeSimulateGroupRebalance opts (gidx, (nl, il)) = do ...@@ -273,8 +275,8 @@ maybeSimulateGroupRebalance opts (gidx, (nl, il)) = do
-- | Decide whether to simulate rebalance. -- | Decide whether to simulate rebalance.
maybeSimulateRebalance :: Bool -- ^ Whether to simulate rebalance maybeSimulateRebalance :: Bool -- ^ Whether to simulate rebalance
-> Options -- ^ Command line options -> Options -- ^ Command line options
-> [(Gdx, (Node.List, Instance.List))] -- ^ Group data -> [GroupInfo] -- ^ Group data
-> IO [(Gdx, (Node.List, Instance.List))] -> IO [GroupInfo]
maybeSimulateRebalance True opts cluster = maybeSimulateRebalance True opts cluster =
mapM (maybeSimulateGroupRebalance opts) cluster mapM (maybeSimulateGroupRebalance opts) cluster
maybeSimulateRebalance False _ cluster = return cluster maybeSimulateRebalance False _ cluster = return cluster
......
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