Revision 01f6a5d2 src/Cluster.hs

b/src/Cluster.hs
588 588
                  (zip [0..] kerows)
589 589
    in unzip idxrows
590 590

  
591
-- | Set the primary or secondary node indices on the instance list.
592
fixInstances :: [(Int, Node.Node)]
593
             -> (Node.Node -> [Int]) -- ^ Either 'Node.slist' or 'Node.plist'
594
             -> (Instance.Instance -> Int -> Instance.Instance)
595
                -- ^ Either 'Instance.setSec' or 'Instance.setPri'
596
             -> [(Int, Instance.Instance)]
597
             -> [(Int, Instance.Instance)]
598
fixInstances nl list_fn set_fn il =
599
    concat $ map
600
               (\ (n_idx, n) ->
601
                   map
602
                   (\ i_idx ->
603
                        let oldi = fromJust (lookup i_idx il)
604
                        in
605
                          (i_idx, set_fn oldi n_idx)
606
                   ) (list_fn n)
607
              ) nl
608

  
609
-- | Splits and returns a list of indexes based on an Instance assoc list.
610
csi :: String -> [(String, Int)] -> [Int]
611
csi values il =
612
    map
613
    (\ x -> fromJust (lookup x il))
614
    (commaSplit values)
591
-- | For each instance, add its index to its primary and secondary nodes
592
fixNodes :: [(Int, Node.Node)]
593
         -> [(Int, Instance.Instance)]
594
         -> [(Int, Node.Node)]
595
fixNodes nl il =
596
    foldl (\accu (idx, inst) ->
597
               let
598
                   assocEqual = (\ (i, _) (j, _) -> i == j)
599
                   pdx = Instance.pnode inst
600
                   sdx = Instance.snode inst
601
                   pold = fromJust $ lookup pdx nl
602
                   sold = fromJust $ lookup sdx nl
603
                   pnew = Node.setPri pold idx
604
                   snew = Node.setSec sold idx
605
                   ac1 = deleteBy assocEqual (pdx, pold) accu
606
                   ac2 = deleteBy assocEqual (sdx, sold) ac1
607
                   ac3 = (pdx, pnew):(sdx, snew):ac2
608
               in ac3) nl il
609

  
615 610

  
616 611
{-| Initializer function that loads the data from a node and list file
617 612
    and massages it into the correct format. -}
......
621 616
             Container.Container Instance.Instance,
622 617
             [(Int, String)], [(Int, String)])
623 618
loadData ndata idata =
624
    {- instance file: name mem disk -}
625
    let (kti, il) = loadTabular idata
626
                    (\ (i:j:k:[]) -> (i, Instance.create j k)) Instance.setIdx
627
    {- node file: name mem disk plist slist -}
619
    let
620
    {- node file: name mem disk -}
628 621
        (ktn, nl) = loadTabular ndata
629
                    (\ (i:jt:jf:kt:kf:l:m:[]) ->
630
                         (i, Node.create jt jf kt kf (csi l kti) (csi m kti)))
622
                    (\ (i:jt:jf:kt:kf:[]) -> (i, Node.create jt jf kt kf))
631 623
                    Node.setIdx
632
        il2 = fixInstances nl Node.slist Instance.setSec $
633
              fixInstances nl Node.plist Instance.setPri il
634
        il3 = Container.fromAssocList il2
624
    {- instance file: name mem disk -}
625
        (kti, il) = loadTabular idata
626
                    (\ (i:j:k:l:m:[]) -> (i,
627
                                           Instance.create j k
628
                                               (fromJust $ lookup l ktn)
629
                                               (fromJust $ lookup m ktn)))
630
                    Instance.setIdx
631
        nl2 = fixNodes nl il
632
        il3 = Container.fromAssocList il
635 633
        nl3 = Container.fromAssocList
636
             (map (\ (k, v) -> (k, Node.buildPeers v il3 (length nl))) nl)
634
             (map (\ (k, v) -> (k, Node.buildPeers v il3 (length nl2))) nl2)
637 635
    in
638 636
      (nl3, il3, swapPairs ktn, swapPairs kti)

Also available in: Unified diff