Revision 1f4ae205

b/htools/Ganeti/HTools/Cluster.hs
832 832
tryMGEvac _ nl il ex_ndx =
833 833
    let ex_nodes = map (`Container.find` nl) ex_ndx
834 834
        all_insts = nub . concatMap Node.sList $ ex_nodes
835
        gni = splitCluster nl il
836
        -- we run the instance index list through a couple of maps to
837
        -- get finally to a structure of the type [(group index,
838
        -- [instance indices])]
839
        all_insts' = map (\idx ->
840
                              (instancePriGroup nl (Container.find idx il),
841
                               idx)) all_insts
842
        all_insts'' = groupBy ((==) `on` fst) all_insts'
843
        all_insts3 = map (\xs -> let (gdxs, idxs) = unzip xs
844
                                 in (head gdxs, idxs)) all_insts''
835
        all_insts' = associateIdxs all_insts $ splitCluster nl il
845 836
    in do
846
      -- that done, we now add the per-group nl/il to the tuple
847
      all_insts4 <-
848
          mapM (\(gdx, idxs) ->
849
                case lookup gdx gni of
850
                    Nothing -> fail $ "Can't find group index " ++ show gdx
851
                    Just (gnl, gil) -> return (gdx, gnl, gil, idxs))
852
          all_insts3
853
      results <- mapM (\(_, gnl, gil, idxs) -> tryEvac gnl gil idxs ex_ndx)
854
                 all_insts4
837
      results <- mapM (\(_, (gnl, gil, idxs)) -> tryEvac gnl gil idxs ex_ndx)
838
                 all_insts'
855 839
      let sol = foldl' sumAllocs emptySolution results
856 840
      return $ annotateSolution sol
857 841

  
......
1110 1094
               nodes' = zip nidxs nodes
1111 1095
               instances = Container.filter ((`elem` nidxs) . Instance.pNode) il
1112 1096
           in (guuid, (Container.fromList nodes', instances))) ngroups
1097

  
1098
-- | Split a global instance index map into per-group, and associate
1099
-- it with the group/node/instance lists.
1100
associateIdxs :: [Idx] -- ^ Instance indices to be split/associated
1101
              -> [(Gdx, (Node.List, Instance.List))]        -- ^ Input groups
1102
              -> [(Gdx, (Node.List, Instance.List, [Idx]))] -- ^ Result
1103
associateIdxs idxs =
1104
    map (\(gdx, (nl, il)) ->
1105
             (gdx, (nl, il, filter (`Container.member` il) idxs)))
b/htools/Ganeti/HTools/Container.hs
7 7

  
8 8
{-
9 9

  
10
Copyright (C) 2009, 2010 Google Inc.
10
Copyright (C) 2009, 2010, 2011 Google Inc.
11 11

  
12 12
This program is free software; you can redistribute it and/or modify
13 13
it under the terms of the GNU General Public License as published by
......
40 40
    , IntMap.null
41 41
    , find
42 42
    , IntMap.findMax
43
    , IntMap.member
43 44
     -- * Update
44 45
    , add
45 46
    , addTwo

Also available in: Unified diff