Skip to content
Snippets Groups Projects
Commit 740ec004 authored by Iustin Pop's avatar Iustin Pop
Browse files

Add a separate type for the [(Int, String)] list

This is added for better readability, since this is very often used in
declarations.
parent 19777638
No related branches found
No related tags found
No related merge requests found
...@@ -10,6 +10,7 @@ module Ganeti.HTools.Cluster ...@@ -10,6 +10,7 @@ module Ganeti.HTools.Cluster
-- * Types -- * Types
NodeList NodeList
, InstanceList , InstanceList
, NameList
, Placement , Placement
, Solution(..) , Solution(..)
, Table(..) , Table(..)
...@@ -45,6 +46,8 @@ import Ganeti.HTools.Utils ...@@ -45,6 +46,8 @@ import Ganeti.HTools.Utils
type NodeList = Container.Container Node.Node type NodeList = Container.Container Node.Node
type InstanceList = Container.Container Instance.Instance type InstanceList = Container.Container Instance.Instance
-- | The type used to hold idx-to-name mappings
type NameList = [(Int, String)]
-- | A separate name for the cluster score type -- | A separate name for the cluster score type
type Score = Double type Score = Double
...@@ -584,8 +587,8 @@ computeMoves i a b c d = ...@@ -584,8 +587,8 @@ computeMoves i a b c d =
{-| Converts a placement to string format -} {-| Converts a placement to string format -}
printSolutionLine :: InstanceList printSolutionLine :: InstanceList
-> [(Int, String)] -> NameList
-> [(Int, String)] -> NameList
-> Int -> Int
-> Int -> Int
-> Placement -> Placement
...@@ -619,8 +622,8 @@ formatCmds cmd_strs = ...@@ -619,8 +622,8 @@ formatCmds cmd_strs =
{-| Converts a solution to string format -} {-| Converts a solution to string format -}
printSolution :: InstanceList printSolution :: InstanceList
-> [(Int, String)] -> NameList
-> [(Int, String)] -> NameList
-> [Placement] -> [Placement]
-> ([String], [[String]]) -> ([String], [[String]])
printSolution il ktn kti sol = printSolution il ktn kti sol =
...@@ -633,7 +636,7 @@ printSolution il ktn kti sol = ...@@ -633,7 +636,7 @@ printSolution il ktn kti sol =
zip sol [1..] zip sol [1..]
-- | Print the node list. -- | Print the node list.
printNodes :: [(Int, String)] -> NodeList -> String printNodes :: NameList -> NodeList -> String
printNodes ktn nl = printNodes ktn nl =
let snl = sortBy (compare `on` Node.idx) (Container.elems nl) let snl = sortBy (compare `on` Node.idx) (Container.elems nl)
snl' = map (\ n -> ((fromJust $ lookup (Node.idx n) ktn), n)) snl snl' = map (\ n -> ((fromJust $ lookup (Node.idx n) ktn), n)) snl
...@@ -719,9 +722,9 @@ fixNodes nl il = ...@@ -719,9 +722,9 @@ fixNodes nl il =
ac3 = (pdx, pnew):(sdx, snew):ac2 ac3 = (pdx, pnew):(sdx, snew):ac2
in ac3) nl il in ac3) nl il
-- | Compute the longest common suffix of a [(Int, String)] list that -- | Compute the longest common suffix of a NameList list that
-- | starts with a dot -- | starts with a dot
longestDomain :: [(Int, String)] -> String longestDomain :: NameList -> String
longestDomain [] = "" longestDomain [] = ""
longestDomain ((_,x):xs) = longestDomain ((_,x):xs) =
let let
...@@ -733,7 +736,7 @@ longestDomain ((_,x):xs) = ...@@ -733,7 +736,7 @@ longestDomain ((_,x):xs) =
"" $ filter (isPrefixOf ".") (tails x) "" $ filter (isPrefixOf ".") (tails x)
-- | Remove tails from the (Int, String) lists -- | Remove tails from the (Int, String) lists
stripSuffix :: String -> [(Int, String)] -> [(Int, String)] stripSuffix :: String -> NameList -> NameList
stripSuffix suffix lst = stripSuffix suffix lst =
let sflen = length suffix in let sflen = length suffix in
map (\ (key, name) -> (key, take ((length name) - sflen) name)) lst map (\ (key, name) -> (key, take ((length name) - sflen) name)) lst
...@@ -744,7 +747,7 @@ loadData :: String -- ^ Node data in text format ...@@ -744,7 +747,7 @@ loadData :: String -- ^ Node data in text format
-> String -- ^ Instance data in text format -> String -- ^ Instance data in text format
-> (Container.Container Node.Node, -> (Container.Container Node.Node,
Container.Container Instance.Instance, Container.Container Instance.Instance,
String, [(Int, String)], [(Int, String)]) String, NameList, NameList)
loadData ndata idata = loadData ndata idata =
let let
{- node file: name mem disk -} {- node file: name mem disk -}
......
...@@ -104,8 +104,8 @@ we find a valid solution or we exceed the maximum depth. ...@@ -104,8 +104,8 @@ we find a valid solution or we exceed the maximum depth.
-} -}
iterateDepth :: Cluster.Table -- ^ The starting table iterateDepth :: Cluster.Table -- ^ The starting table
-> Int -- ^ Remaining length -> Int -- ^ Remaining length
-> [(Int, String)] -- ^ Node idx to name list -> Cluster.NameList -- ^ Node idx to name list
-> [(Int, String)] -- ^ Inst idx to name list -> Cluster.NameList -- ^ Inst idx to name list
-> Int -- ^ Max node name len -> Int -- ^ Max node name len
-> Int -- ^ Max instance name len -> Int -- ^ Max instance name len
-> [[String]] -- ^ Current command list -> [[String]] -- ^ Current command list
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment