{-| Implementation of cluster-wide logic.
This module holds all pure cluster-logic; I\/O related functionality
-goes into the "Main" module.
+goes into the "Main" module for the individual binaries.
-}
type NodeList = Container.Container Node.Node
type InstanceList = Container.Container Instance.Instance
+-- | A separate name for the cluster score type
type Score = Double
-- | The description of an instance placement.
in
compareTables cur_tbl upd_tbl
+-- | Given the status of the current secondary as a valid new node
+-- and the current candidate target node,
+-- generate the possible moves for a instance.
+possibleMoves :: Bool -> Int -> [IMove]
+possibleMoves True tdx =
+ [ReplaceSecondary tdx,
+ ReplaceAndFailover tdx,
+ ReplacePrimary tdx,
+ FailoverAndReplace tdx]
+
+possibleMoves False tdx =
+ [ReplaceSecondary tdx,
+ ReplaceAndFailover tdx]
+
+-- | Compute the best move for a given instance.
checkInstanceMove :: [Int] -- Allowed target node indices
-> Table -- Original table
-> Instance.Instance -- Instance to move
opdx = Instance.pnode target
osdx = Instance.snode target
nodes = filter (\idx -> idx /= opdx && idx /= osdx) nodes_idx
- aft_failover = checkSingleStep ini_tbl target ini_tbl Failover
- all_moves = concatMap (\idx -> [ReplacePrimary idx,
- ReplaceSecondary idx,
- ReplaceAndFailover idx,
- FailoverAndReplace idx]) nodes
+ use_secondary = elem osdx nodes_idx
+ aft_failover = if use_secondary -- if allowed to failover
+ then checkSingleStep ini_tbl target ini_tbl Failover
+ else ini_tbl
+ all_moves = concatMap (possibleMoves use_secondary) nodes
in
-- iterate over the possible nodes for this instance
foldl' (checkSingleStep ini_tbl target) aft_failover all_moves