From 6eaa7bb88a42abed08499bd935bd66bba5a35410 Mon Sep 17 00:00:00 2001 From: Iustin Pop <iustin@google.com> Date: Tue, 21 Dec 2010 15:03:21 +0100 Subject: [PATCH] hspace: abstract the listing of the allocation map Just another cleanup of duplicate code. Signed-off-by: Iustin Pop <iustin@google.com> Reviewed-by: Balazs Lecz <leczb@google.com> --- hspace.hs | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/hspace.hs b/hspace.hs index 349a85a34..16638b7e7 100644 --- a/hspace.hs +++ b/hspace.hs @@ -191,6 +191,19 @@ printInstance nl i = [ Instance.name i , show (Instance.vcpus i) ] +-- | Optionally print the allocation map +printAllocationMap :: Int -> String + -> Node.List -> [Instance.Instance] -> IO () +printAllocationMap verbose msg nl ixes = + when (verbose > 1) $ do + hPutStrLn stderr msg + hPutStr stderr . unlines . map ((:) ' ' . intercalate " ") $ + formatTable (map (printInstance nl) (reverse ixes)) + -- This is the numberic-or-not field + -- specification; the first three fields are + -- strings, whereas the rest are numeric + [False, False, False, True, True, True] + -- | Main function. main :: IO () main = do @@ -289,11 +302,7 @@ main = do req_nodes []) let spec_map' = Cluster.tieredSpecMap trl_ixes - when (verbose > 1) $ do - hPutStrLn stderr "Tiered allocation map" - hPutStr stderr . unlines . map ((:) ' ' . intercalate " ") $ - formatTable (map (printInstance trl_nl) (reverse trl_ixes)) - [False, False, False, True, True, True] + printAllocationMap verbose "Tiered allocation map" trl_nl trl_ixes maybePrintNodes shownodes "Tiered allocation" (Cluster.printNodes trl_nl) @@ -313,14 +322,10 @@ main = do else exitifbad (Cluster.iterateAlloc nl il reqinst req_nodes []) let allocs = length ixes - fin_ixes = reverse ixes sreason = reverse $ sortBy (comparing snd) ereason - when (verbose > 1) $ do - hPutStrLn stderr "Instance map" - hPutStr stderr . unlines . map ((:) ' ' . intercalate " ") $ - formatTable (map (printInstance fin_nl) fin_ixes) - [False, False, False, True, True, True] + printAllocationMap verbose "Standard allocation map" fin_nl ixes + maybePrintNodes shownodes "Standard allocation" (Cluster.printNodes fin_nl) maybeSaveData (optSaveCluster opts) "alloc" "after standard allocation" -- GitLab