The extractNl function is supposed to provide the new state of the nodes after an instance was allocated. To be able to properly work with this list, all the indices need to be fixed as well, as the new instance is only assigned an index at this point.
Signed-off-by: Klaus Aehlig <[email protected]> --- src/Ganeti/HTools/Cluster.hs | 2 +- src/Ganeti/HTools/Cluster/AllocationSolution.hs | 15 +++++++++++++-- src/Ganeti/HTools/Dedicated.hs | 2 +- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/Ganeti/HTools/Cluster.hs b/src/Ganeti/HTools/Cluster.hs index b7191fe..9ff8fef 100644 --- a/src/Ganeti/HTools/Cluster.hs +++ b/src/Ganeti/HTools/Cluster.hs @@ -705,7 +705,7 @@ allocList opts gl nl il ((xi, AllocDetails xicnt mgn):xies) result = do Nothing -> tryMGAlloc opts gl nl il xi xicnt Just gn -> tryGroupAlloc opts gl nl il gn xi xicnt let sol = asSolution ares - nl' = extractNl nl sol + nl' = extractNl nl il sol il' = updateIl il sol allocList opts gl nl' il' xies ((xi, ares):result) diff --git a/src/Ganeti/HTools/Cluster/AllocationSolution.hs b/src/Ganeti/HTools/Cluster/AllocationSolution.hs index 267d4cf..8dfabd8 100644 --- a/src/Ganeti/HTools/Cluster/AllocationSolution.hs +++ b/src/Ganeti/HTools/Cluster/AllocationSolution.hs @@ -92,11 +92,22 @@ updateIl il (Just (_, xi, _, _)) = Container.add (Container.size il) xi il -- | Extract the the new node list from the allocation solution. extractNl :: Node.List -- ^ The original node list + -> Instance.List -- ^ The original instance list -> Maybe (GenericAllocElement a) -- ^ The result of the -- allocation attempt -> Node.List -- ^ The new node list -extractNl nl Nothing = nl -extractNl _ (Just (xnl, _, _, _)) = xnl +extractNl nl _ Nothing = nl +extractNl _ il (Just (xnl, _, ns, _)) = + let newIndex = Container.size il + fixIndex = map (\i -> if i < 0 then newIndex else i) + fixIndices nodes node = + let nidx = Node.idx node + n = Container.find nidx nodes + n' = n { Node.pList = fixIndex $ Node.pList n + , Node.sList = fixIndex $ Node.sList n + } + in Container.add nidx n' nodes + in foldl fixIndices xnl ns -- | Compares two Maybe AllocElement and chooses the best score. bestAllocElement :: Ord a diff --git a/src/Ganeti/HTools/Dedicated.hs b/src/Ganeti/HTools/Dedicated.hs index d31641d..b77803f 100644 --- a/src/Ganeti/HTools/Dedicated.hs +++ b/src/Ganeti/HTools/Dedicated.hs @@ -250,7 +250,7 @@ runDedicatedAllocation opts request = $ findAllocation opts gl nl gdx inst count) maybeGroup let sol = AllocSol.asSolution ares - nl'' = AllocSol.extractNl nl' sol + nl'' = AllocSol.extractNl nl' il' sol il'' = AllocSol.updateIl il' sol return (nl'', il'', (inst, ares):res)) (nl, il, []) insts -- 2.2.0.rc0.207.ga3a616c
