Revision 4b77c2a2

b/htools/Ganeti/HTools/Program/Hcheck.hs
180 180
  let prefix = phaseLevelDescr phase level name
181 181
      descr = descrData level
182 182
  unless (verbose == 0) $ do
183
    printf "\n%s" prefix :: IO ()
183
    putStrLn ""
184
    putStr prefix
184 185
    mapM_ (\(a,b) -> printf "    %s: %s\n" a b) (zip descr values)
185 186

  
186 187
-- | Extract name or idx from group.
......
199 200
  map show stats ++ map (printBool machineread) bstats
200 201

  
201 202
-- | Print all the statistics on a group level.
202
printGroupStats :: Int -> Bool -> Phase -> Group.Group -> [Int] -> Double
203
printGroupStats :: Int -> Bool -> Phase -> ((Group.Group, Double), [Int])
203 204
                -> IO ()
204
printGroupStats verbose machineread phase grp stats score = do
205
printGroupStats verbose machineread phase ((grp, score), stats) = do
205 206
  let values = prepareGroupValues stats score
206 207
      extradata = extractGroupData machineread grp
207 208
  printStats verbose machineread GroupLvl phase values (Just extradata)
......
220 221
instances residing on offline nodes.
221 222

  
222 223
-}
223
perGroupChecks :: Int -> Bool -> Phase -> Group.List
224
               -> (Gdx, (Node.List, Instance.List)) -> IO ([Int])
225
perGroupChecks verbose machineread phase gl (gidx, (nl, il)) = do
224
perGroupChecks :: Group.List
225
               -> (Gdx, (Node.List, Instance.List))
226
               -> ((Group.Group, Double), [Int])
227
perGroupChecks gl (gidx, (nl, il)) =
226 228
  let grp = Container.find gidx gl
227 229
      offnl = filter Node.offline (Container.elems nl)
228 230
      n1violated = length $ fst $ Cluster.computeBadItems nl il
......
236 238
                   , offline_pri
237 239
                   , offline_sec
238 240
                   ]
239
  printGroupStats verbose machineread phase grp groupstats score
240
  return groupstats
241
  in ((grp, score), groupstats)
241 242

  
242 243
-- | Use Hbal's iterateDepth to simulate group rebalance.
243 244
executeSimulation :: Options -> Cluster.Table -> Double
......
300 301

  
301 302
  when machineread $ printGroupsMappings gl
302 303

  
303
  groupsstats <- mapM (perGroupChecks verbose machineread Initial gl)
304
                 splitcluster
305
  let clusterstats = map sum (transpose groupsstats) :: [Int]
304
  let groupsstats = map (perGroupChecks gl) splitcluster
305
      clusterstats = map sum . transpose . map snd $ groupsstats
306 306
      needrebalance = clusterNeedsRebalance clusterstats
307
  printClusterStats verbose machineread Initial clusterstats needrebalance
308 307

  
309
  when nosimulation $ do
310
    unless (verbose == 0 || machineread) $
311
      putStrLn "Running in no-simulation mode. Exiting."
308
  unless (verbose == 0 || machineread) $
309
    if nosimulation
310
      then putStrLn "Running in no-simulation mode."
311
      else if needrebalance
312
             then putStrLn "Cluster needs rebalancing."
313
             else putStrLn "No need to rebalance cluster, no problems found."
314

  
315
  mapM_ (printGroupStats verbose machineread Initial) groupsstats
312 316

  
313
  unless needrebalance $ do
314
    unless (verbose == 0 || machineread) $
315
      putStrLn "No need to rebalance cluster, no problems found. Exiting."
317
  printClusterStats verbose machineread Initial clusterstats needrebalance
316 318

  
317 319
  let exitOK = nosimulation || not needrebalance
318 320
      simulate = not nosimulation && needrebalance
......
320 322
  rebalancedcluster <- maybeSimulateRebalance simulate opts splitcluster
321 323

  
322 324
  when (simulate || machineread) $ do
323
    newgroupstats <- mapM (perGroupChecks verbose machineread Rebalanced gl)
324
                     rebalancedcluster
325
    let newclusterstats = map sum (transpose newgroupstats) :: [Int]
325
    let newgroupstats = map (perGroupChecks gl) rebalancedcluster
326
        newclusterstats = map sum . transpose . map snd $ newgroupstats
326 327
        newneedrebalance = clusterNeedsRebalance clusterstats
327 328

  
329
    mapM_ (printGroupStats verbose machineread Rebalanced) newgroupstats
330

  
328 331
    printClusterStats verbose machineread Rebalanced newclusterstats
329 332
                           newneedrebalance
330 333

  

Also available in: Unified diff