From 6d0bc5cadbfae324472cadc2348bd1b509a42809 Mon Sep 17 00:00:00 2001 From: Iustin Pop <iustin@google.com> Date: Tue, 1 Feb 2011 15:31:40 +0100 Subject: [PATCH] Prevent allocation on unallocable node groups This patch changes genAllocNodes so that it also takes the group list, using it to filter out any nodes which live on unallocable groups. Signed-off-by: Iustin Pop <iustin@google.com> Reviewed-by: Adeodato Simo <dato@google.com> --- Ganeti/HTools/Cluster.hs | 16 ++++++++++++---- Ganeti/HTools/QC.hs | 10 ++++++---- hspace.hs | 2 +- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/Ganeti/HTools/Cluster.hs b/Ganeti/HTools/Cluster.hs index 5918a77b0..e1cec712c 100644 --- a/Ganeti/HTools/Cluster.hs +++ b/Ganeti/HTools/Cluster.hs @@ -623,11 +623,18 @@ annotateSolution :: AllocSolution -> AllocSolution annotateSolution as = as { asLog = describeSolution as : asLog as } -- | Generate the valid node allocation singles or pairs for a new instance. -genAllocNodes :: Node.List -- ^ The node map +genAllocNodes :: Group.List -- ^ Group list + -> Node.List -- ^ The node map -> Int -- ^ The number of nodes required + -> Bool -- ^ Whether to drop or not + -- unallocable nodes -> Result AllocNodes -- ^ The (monadic) result -genAllocNodes nl count = - let all_nodes = getOnline nl +genAllocNodes gl nl count drop_unalloc = + let filter_fn = if drop_unalloc + then filter ((/=) AllocUnallocable . Group.allocPolicy . + flip Container.find gl . Node.group) + else id + all_nodes = filter_fn $ getOnline nl all_pairs = liftM2 (,) all_nodes all_nodes ok_pairs = filter (\(x, y) -> Node.idx x /= Node.idx y && Node.group x == Node.group y) all_pairs @@ -703,7 +710,8 @@ tryMGAlloc mggl mgnl mgil inst cnt = let groups = splitCluster mgnl mgil -- TODO: currently we consider all groups preferred sols = map (\(gid, (nl, il)) -> - (gid, genAllocNodes nl cnt >>= tryAlloc nl il inst)) + (gid, genAllocNodes mggl nl cnt False >>= + tryAlloc nl il inst)) groups::[(Gdx, Result AllocSolution)] all_msgs = concatMap (solutionDescription mggl) sols goodSols = filterMGResults mggl sols diff --git a/Ganeti/HTools/QC.hs b/Ganeti/HTools/QC.hs index 9257939c8..534a7b1dc 100644 --- a/Ganeti/HTools/QC.hs +++ b/Ganeti/HTools/QC.hs @@ -684,7 +684,8 @@ prop_ClusterAlloc_sane node inst = let nl = makeSmallCluster node count il = Container.empty inst' = setInstanceSmallerThanNode node inst - in case Cluster.genAllocNodes nl 2 >>= Cluster.tryAlloc nl il inst' of + in case Cluster.genAllocNodes defGroupList nl 2 True >>= + Cluster.tryAlloc nl il inst' of Types.Bad _ -> False Types.Ok as -> case Cluster.asSolutions as of @@ -707,7 +708,7 @@ prop_ClusterCanTieredAlloc node inst = ==> let nl = makeSmallCluster node count il = Container.empty - allocnodes = Cluster.genAllocNodes nl rqnodes + allocnodes = Cluster.genAllocNodes defGroupList nl rqnodes True in case allocnodes >>= \allocnodes' -> Cluster.tieredAlloc nl il inst allocnodes' [] [] of Types.Bad _ -> False @@ -726,7 +727,8 @@ prop_ClusterAllocEvac node inst = let nl = makeSmallCluster node count il = Container.empty inst' = setInstanceSmallerThanNode node inst - in case Cluster.genAllocNodes nl 2 >>= Cluster.tryAlloc nl il inst' of + in case Cluster.genAllocNodes defGroupList nl 2 True >>= + Cluster.tryAlloc nl il inst' of Types.Bad _ -> False Types.Ok as -> case Cluster.asSolutions as of @@ -751,7 +753,7 @@ prop_ClusterAllocBalance node = let nl = makeSmallCluster node count (hnode, nl') = IntMap.deleteFindMax nl il = Container.empty - allocnodes = Cluster.genAllocNodes nl' 2 + allocnodes = Cluster.genAllocNodes defGroupList nl' 2 True i_templ = createInstance Types.unitMem Types.unitDsk Types.unitCpu in case allocnodes >>= \allocnodes' -> Cluster.iterateAlloc nl' il i_templ allocnodes' [] [] of diff --git a/hspace.hs b/hspace.hs index e20756657..57d0302d7 100644 --- a/hspace.hs +++ b/hspace.hs @@ -290,7 +290,7 @@ main = do let reqinst = iofspec ispec - allocnodes <- exitifbad $ Cluster.genAllocNodes nl req_nodes + allocnodes <- exitifbad $ Cluster.genAllocNodes gl nl req_nodes True -- Run the tiered allocation, if enabled -- GitLab