Revision 3603605a htools/Ganeti/HTools/Program/Hbal.hs

b/htools/Ganeti/HTools/Program/Hbal.hs
143 143
saveBalanceCommands opts cmd_data = do
144 144
  let out_path = fromJust $ optShowCmds opts
145 145
  putStrLn ""
146
  (if out_path == "-" then
147
       printf "Commands to run to reach the above solution:\n%s"
148
                  (unlines . map ("  " ++) .
149
                   filter (/= "  check") .
150
                   lines $ cmd_data)
151
   else do
152
     writeFile out_path (shTemplate ++ cmd_data)
153
     printf "The commands have been written to file '%s'\n" out_path)
146
  if out_path == "-"
147
    then printf "Commands to run to reach the above solution:\n%s"
148
           (unlines . map ("  " ++) .
149
            filter (/= "  check") .
150
            lines $ cmd_data)
151
    else do
152
      writeFile out_path (shTemplate ++ cmd_data)
153
      printf "The commands have been written to file '%s'\n" out_path
154 154

  
155 155
-- | Polls a set of jobs at a fixed interval until all are finished
156 156
-- one way or another.
......
176 176
execWrapper _      _  _  _    [] = return True
177 177
execWrapper master nl il cref alljss = do
178 178
  cancel <- readIORef cref
179
  (if cancel > 0
180
   then do
181
     hPrintf stderr "Exiting early due to user request, %d\
182
                    \ jobset(s) remaining." (length alljss)::IO ()
183
     return False
184
   else execJobSet master nl il cref alljss)
179
  if cancel > 0
180
    then do
181
      hPrintf stderr "Exiting early due to user request, %d\
182
                     \ jobset(s) remaining." (length alljss)::IO ()
183
      return False
184
    else execJobSet master nl il cref alljss
185 185

  
186 186
-- | Execute an entire jobset.
187 187
execJobSet :: String -> Node.List
......
202 202
                putStrLn $ "Got job IDs " ++ commaJoin x
203 203
                waitForJobs client x
204 204
         )
205
  (case jrs of
206
     Bad x -> do
207
       hPutStrLn stderr $ "Cannot compute job status, aborting: " ++ show x
208
       return False
209
     Ok x -> if checkJobsStatus x
210
             then execWrapper master nl il cref jss
211
             else do
212
               hPutStrLn stderr $ "Not all jobs completed successfully: " ++
213
                         show x
214
               hPutStrLn stderr "Aborting."
215
               return False)
205
  case jrs of
206
    Bad x -> do
207
      hPutStrLn stderr $ "Cannot compute job status, aborting: " ++ show x
208
      return False
209
    Ok x -> if checkJobsStatus x
210
              then execWrapper master nl il cref jss
211
              else do
212
                hPutStrLn stderr $ "Not all jobs completed successfully: " ++
213
                          show x
214
                hPutStrLn stderr "Aborting."
215
                return False
216 216

  
217 217
-- | Executes the jobs, if possible and desired.
218 218
maybeExecJobs :: Options
......
279 279
        exitWith $ ExitFailure 1
280 280
      Just grp ->
281 281
          case lookup (Group.idx grp) ngroups of
282
            Nothing -> do
282
            Nothing ->
283 283
              -- This will only happen if there are no nodes assigned
284 284
              -- to this group
285 285
              return (Group.name grp, (Container.empty, Container.empty))
......
375 375

  
376 376
  checkNeedRebalance opts ini_cv
377 377

  
378
  (if verbose > 2
379
   then printf "Initial coefficients: overall %.8f, %s\n"
380
        ini_cv (Cluster.printStats nl)::IO ()
381
   else printf "Initial score: %.8f\n" ini_cv)
378
  if verbose > 2
379
    then printf "Initial coefficients: overall %.8f, %s\n"
380
           ini_cv (Cluster.printStats nl)::IO ()
381
    else printf "Initial score: %.8f\n" ini_cv
382 382

  
383 383
  putStrLn "Trying to minimize the CV..."
384 384
  let imlen = maximum . map (length . Instance.alias) $ Container.elems il

Also available in: Unified diff