Commit cb0c77ff authored by Iustin Pop's avatar Iustin Pop

Container: remove fromAssocList

Container.fromAssocList is just a re-export of IntMap.fromList; it
makes sense to remove it and simply export the original name, as it
needs just a bit of renaming in the rest of the code.
Signed-off-by: default avatarIustin Pop <iustin@google.com>
Reviewed-by: default avatarBalazs Lecz <leczb@google.com>
parent a3eee4ad
...@@ -999,4 +999,4 @@ splitCluster nl il = ...@@ -999,4 +999,4 @@ splitCluster nl il =
let nidxs = map Node.idx nodes let nidxs = map Node.idx nodes
nodes' = zip nidxs nodes nodes' = zip nidxs nodes
instances = Container.filter ((`elem` nidxs) . Instance.pNode) il instances = Container.filter ((`elem` nidxs) . Instance.pNode) il
in (guuid, (Container.fromAssocList nodes', instances))) ngroups in (guuid, (Container.fromList nodes', instances))) ngroups
...@@ -7,7 +7,7 @@ give the best performance for our workload. ...@@ -7,7 +7,7 @@ give the best performance for our workload.
{- {-
Copyright (C) 2009 Google Inc. Copyright (C) 2009, 2010 Google Inc.
This program is free software; you can redistribute it and/or modify This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
...@@ -34,7 +34,7 @@ module Ganeti.HTools.Container ...@@ -34,7 +34,7 @@ module Ganeti.HTools.Container
-- * Creation -- * Creation
, IntMap.empty , IntMap.empty
, IntMap.singleton , IntMap.singleton
, fromAssocList , IntMap.fromList
-- * Query -- * Query
, IntMap.size , IntMap.size
, IntMap.null , IntMap.null
...@@ -69,10 +69,6 @@ find k = (IntMap.! k) ...@@ -69,10 +69,6 @@ find k = (IntMap.! k)
add :: Key -> a -> Container a -> Container a add :: Key -> a -> Container a -> Container a
add = IntMap.insert add = IntMap.insert
-- | Create a map from an association list.
fromAssocList :: [(Key, a)] -> Container a
fromAssocList = IntMap.fromList
-- | Add or update two elements of the map. -- | Add or update two elements of the map.
addTwo :: Key -> a -> Key -> a -> Container a -> Container a addTwo :: Key -> a -> Key -> a -> Container a -> Container a
addTwo k1 v1 k2 v2 = add k1 v1 . add k2 v2 addTwo k1 v1 k2 v2 = add k1 v1 . add k2 v2
......
...@@ -119,7 +119,7 @@ assignIndices nodes = ...@@ -119,7 +119,7 @@ assignIndices nodes =
let (na, idx_node) = let (na, idx_node) =
unzip . map (\ (idx, (k, v)) -> ((k, idx), (idx, setIdx v idx))) unzip . map (\ (idx, (k, v)) -> ((k, idx), (idx, setIdx v idx)))
. zip [0..] $ nodes . zip [0..] $ nodes
in (M.fromList na, Container.fromAssocList idx_node) in (M.fromList na, Container.fromList idx_node)
-- | For each instance, add its index to its primary and secondary nodes. -- | For each instance, add its index to its primary and secondary nodes.
fixNodes :: Node.List fixNodes :: Node.List
......
...@@ -85,7 +85,7 @@ defGroup = flip Group.setIdx 0 $ ...@@ -85,7 +85,7 @@ defGroup = flip Group.setIdx 0 $
Types.AllocPreferred Types.AllocPreferred
defGroupList :: Group.List defGroupList :: Group.List
defGroupList = Container.fromAssocList [(Group.idx defGroup, defGroup)] defGroupList = Container.fromList [(Group.idx defGroup, defGroup)]
defGroupAssoc :: Data.Map.Map String Types.Gdx defGroupAssoc :: Data.Map.Map String Types.Gdx
defGroupAssoc = Data.Map.singleton (Group.uuid defGroup) (Group.idx defGroup) defGroupAssoc = Data.Map.singleton (Group.uuid defGroup) (Group.idx defGroup)
...@@ -325,7 +325,7 @@ prop_Container_findByName node othername = ...@@ -325,7 +325,7 @@ prop_Container_findByName node othername =
nn { Node.name = name, nn { Node.name = name,
Node.alias = alias })) Node.alias = alias }))
$ zip names nodes $ zip names nodes
nl' = Container.fromAssocList nodes' nl' = Container.fromList nodes'
target = snd (nodes' !! fidx) target = snd (nodes' !! fidx)
in Container.findByName nl' (Node.name target) == Just target && in Container.findByName nl' (Node.name target) == Just target &&
Container.findByName nl' (Node.alias target) == Just target && Container.findByName nl' (Node.alias target) == Just target &&
...@@ -655,7 +655,7 @@ prop_Score_Zero node count = ...@@ -655,7 +655,7 @@ prop_Score_Zero node count =
(Node.tDsk node > 0) && (Node.tMem node > 0)) ==> (Node.tDsk node > 0) && (Node.tMem node > 0)) ==>
let fn = Node.buildPeers node Container.empty let fn = Node.buildPeers node Container.empty
nlst = zip [1..] $ replicate count fn::[(Types.Ndx, Node.Node)] nlst = zip [1..] $ replicate count fn::[(Types.Ndx, Node.Node)]
nl = Container.fromAssocList nlst nl = Container.fromList nlst
score = Cluster.compCV nl score = Cluster.compCV nl
-- we can't say == 0 here as the floating point errors accumulate; -- we can't say == 0 here as the floating point errors accumulate;
-- this should be much lower than the default score in CLI.hs -- this should be much lower than the default score in CLI.hs
...@@ -667,7 +667,7 @@ prop_CStats_sane node count = ...@@ -667,7 +667,7 @@ prop_CStats_sane node count =
(Node.availDisk node > 0) && (Node.availMem node > 0)) ==> (Node.availDisk node > 0) && (Node.availMem node > 0)) ==>
let fn = Node.buildPeers node Container.empty let fn = Node.buildPeers node Container.empty
nlst = zip [1..] $ replicate count fn::[(Types.Ndx, Node.Node)] nlst = zip [1..] $ replicate count fn::[(Types.Ndx, Node.Node)]
nl = Container.fromAssocList nlst nl = Container.fromList nlst
cstats = Cluster.totalResources nl cstats = Cluster.totalResources nl
in Cluster.csAdsk cstats >= 0 && in Cluster.csAdsk cstats >= 0 &&
Cluster.csAdsk cstats <= Cluster.csFdsk cstats Cluster.csAdsk cstats <= Cluster.csFdsk cstats
...@@ -770,7 +770,7 @@ prop_ClusterCheckConsistency node inst = ...@@ -770,7 +770,7 @@ prop_ClusterCheckConsistency node inst =
inst1 = Instance.setBoth inst (Node.idx node1) (Node.idx node2) inst1 = Instance.setBoth inst (Node.idx node1) (Node.idx node2)
inst2 = Instance.setBoth inst (Node.idx node1) Node.noSecondary inst2 = Instance.setBoth inst (Node.idx node1) Node.noSecondary
inst3 = Instance.setBoth inst (Node.idx node1) (Node.idx node3) inst3 = Instance.setBoth inst (Node.idx node1) (Node.idx node3)
ccheck = Cluster.findSplitInstances nl' . Container.fromAssocList ccheck = Cluster.findSplitInstances nl' . Container.fromList
in null (ccheck [(0, inst1)]) && in null (ccheck [(0, inst1)]) &&
null (ccheck [(0, inst2)]) && null (ccheck [(0, inst2)]) &&
(not . null $ ccheck [(0, inst3)]) (not . null $ ccheck [(0, inst3)])
...@@ -849,7 +849,7 @@ prop_Loader_assignIndices nodes = ...@@ -849,7 +849,7 @@ prop_Loader_assignIndices nodes =
-- | Checks that the number of primary instances recorded on the nodes -- | Checks that the number of primary instances recorded on the nodes
-- is zero -- is zero
prop_Loader_mergeData ns = prop_Loader_mergeData ns =
let na = Container.fromAssocList $ map (\n -> (Node.idx n, n)) ns let na = Container.fromList $ map (\n -> (Node.idx n, n)) ns
in case Loader.mergeData [] [] [] in case Loader.mergeData [] [] []
(Loader.emptyCluster {Loader.cdNodes = na}) of (Loader.emptyCluster {Loader.cdNodes = na}) of
Types.Bad _ -> False Types.Bad _ -> False
......
...@@ -82,8 +82,8 @@ parseData ndata = do ...@@ -82,8 +82,8 @@ parseData ndata = do
let ktn = map (\(idx, n) -> (idx, Node.setIdx n idx)) let ktn = map (\(idx, n) -> (idx, Node.setIdx n idx))
$ zip [1..] nodes' $ zip [1..] nodes'
ktg = map (\g -> (Group.idx g, g)) groups ktg = map (\g -> (Group.idx g, g)) groups
return (ClusterData (Container.fromAssocList ktg) return (ClusterData (Container.fromList ktg)
(Container.fromAssocList ktn) Container.empty []) (Container.fromList ktn) Container.empty [])
-- | Builds the cluster data from node\/instance files. -- | Builds the cluster data from node\/instance files.
loadData :: [String] -- ^ Cluster description in text format loadData :: [String] -- ^ Cluster description in text format
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment