Revision 442d5aae src/Ganeti/HTools/Program/Hroller.hs
b/src/Ganeti/HTools/Program/Hroller.hs | ||
---|---|---|
29 | 29 |
, arguments |
30 | 30 |
) where |
31 | 31 |
|
32 |
import Control.Applicative |
|
32 | 33 |
import Control.Monad |
33 | 34 |
import Data.List |
34 | 35 |
import Data.Ord |
... | ... | |
86 | 87 |
| otherwise = (elsize, str ++ " LOOSE " ++ algostat el) |
87 | 88 |
where elsize = (IntMap.size.snd) el |
88 | 89 |
|
89 |
-- | Filter the output list. |
|
90 |
-- Only online nodes are shown, optionally belonging to a particular target |
|
91 |
-- nodegroup. Output groups which are empty after being filtered are removed |
|
92 |
-- as well. |
|
93 |
filterOutput :: Maybe Group.Group -> [[Node.Node]] -> [[Node.Node]] |
|
94 |
filterOutput g l = |
|
95 |
let onlineOnly = filter (not . Node.offline) |
|
96 |
hasGroup grp node = Node.group node == Group.idx grp |
|
97 |
byGroupOnly Nothing xs = xs |
|
98 |
byGroupOnly (Just grp) xs = filter (hasGroup grp) xs |
|
99 |
nonNullOnly = filter (not . null) |
|
100 |
in nonNullOnly (map (onlineOnly . byGroupOnly g) l) |
|
90 |
-- | Predicate of belonging to a given group restriction. |
|
91 |
hasGroup :: Maybe Group.Group -> Node.Node -> Bool |
|
92 |
hasGroup Nothing _ = True |
|
93 |
hasGroup (Just grp) node = Node.group node == Group.idx grp |
|
101 | 94 |
|
102 | 95 |
-- | Put the master node last. |
103 | 96 |
-- Reorder a list of lists of nodes such that the master node (if present) |
... | ... | |
137 | 130 |
Nothing -> exitErr "Cannot find target group." |
138 | 131 |
Just grp -> return (Just grp) |
139 | 132 |
|
133 |
let nodes = IntMap.filter |
|
134 |
(liftA2 (&&) (not . Node.offline) (hasGroup wantedGroup)) |
|
135 |
nlf |
|
136 |
|
|
140 | 137 |
-- TODO: fail if instances are running (with option to warn only) |
141 | 138 |
|
142 |
nodeGraph <- case Node.mkNodeGraph nlf ilf of
|
|
139 |
nodeGraph <- case Node.mkNodeGraph nodes ilf of
|
|
143 | 140 |
Nothing -> exitErr "Cannot create node graph" |
144 | 141 |
Just g -> return g |
145 | 142 |
|
... | ... | |
152 | 149 |
colorings = map (\(v,a) -> (v,(colorVertMap.a) nodeGraph)) colorAlgorithms |
153 | 150 |
smallestColoring = |
154 | 151 |
(snd . minimumBy (comparing (IntMap.size . snd))) colorings |
155 |
idToNode = (`Container.find` nlf) |
|
156 |
nodesRebootGroups = map (map idToNode) $ IntMap.elems smallestColoring |
|
157 |
outputRebootGroups = masterLast $ |
|
158 |
filterOutput wantedGroup nodesRebootGroups |
|
152 |
idToNode = (`Container.find` nodes) |
|
153 |
nodesRebootGroups = |
|
154 |
map (map idToNode . filter (`IntMap.member` nodes)) $ |
|
155 |
IntMap.elems smallestColoring |
|
156 |
outputRebootGroups = masterLast nodesRebootGroups |
|
159 | 157 |
outputRebootNames = map (map Node.name) outputRebootGroups |
160 | 158 |
|
161 | 159 |
when (verbose > 1) . putStrLn $ getStats colorings |
Also available in: Unified diff