Revision db1bcfe8

b/Ganeti/HTools/Cluster.hs
580 580
                      printf "replace-disks -n %s %s" d i])
581 581

  
582 582
{-| Converts a placement to string format -}
583
printSolutionLine :: InstanceList
584
              -> NameList
585
              -> Int
586
              -> Int
587
              -> Placement
588
              -> Int
589
              -> (String, [String])
590
printSolutionLine il ktn nmlen imlen plc pos =
583
printSolutionLine :: NodeList
584
                  -> InstanceList
585
                  -> Int
586
                  -> Int
587
                  -> Placement
588
                  -> Int
589
                  -> (String, [String])
590
printSolutionLine nl il nmlen imlen plc pos =
591 591
    let
592 592
        pmlen = (2*nmlen + 1)
593 593
        (i, p, s, c) = plc
594 594
        inst = Container.find i il
595 595
        inam = Instance.name inst
596
        npri = fromJust $ lookup p ktn
597
        nsec = fromJust $ lookup s ktn
598
        opri = fromJust $ lookup (Instance.pnode inst) ktn
599
        osec = fromJust $ lookup (Instance.snode inst) ktn
596
        npri = cNameOf nl p
597
        nsec = cNameOf nl s
598
        opri = cNameOf nl $ Instance.pnode inst
599
        osec = cNameOf nl $ Instance.snode inst
600 600
        (moves, cmds) =  computeMoves inam opri osec npri nsec
601 601
        ostr = (printf "%s:%s" opri osec)::String
602 602
        nstr = (printf "%s:%s" npri nsec)::String
......
616 616
        zip [1..] cmd_strs
617 617

  
618 618
{-| Converts a solution to string format -}
619
printSolution :: InstanceList
620
              -> NameList
621
              -> NameList
619
printSolution :: NodeList
620
              -> InstanceList
622 621
              -> [Placement]
623 622
              -> ([String], [[String]])
624
printSolution il ktn kti sol =
623
printSolution nl il sol =
625 624
    let
626
        mlen_fn = maximum . (map length) . snd . unzip
627
        imlen = mlen_fn kti
628
        nmlen = mlen_fn ktn
625
        nmlen = cMaxNamelen nl
626
        imlen = cMaxNamelen il
629 627
    in
630
      unzip $ map (uncurry $ printSolutionLine il ktn nmlen imlen) $
628
      unzip $ map (uncurry $ printSolutionLine nl il nmlen imlen) $
631 629
            zip sol [1..]
632 630

  
633 631
-- | Print the node list.
b/hbal.hs
126 126
-}
127 127
iterateDepth :: Cluster.Table    -- ^ The starting table
128 128
             -> Int              -- ^ Remaining length
129
             -> Cluster.NameList -- ^ Node idx to name list
130 129
             -> Int              -- ^ Max node name len
131 130
             -> Int              -- ^ Max instance name len
132 131
             -> [[String]]       -- ^ Current command list
......
134 133
             -> Cluster.Score    -- ^ Score at which to stop
135 134
             -> IO (Cluster.Table, [[String]]) -- ^ The resulting table and
136 135
                                               -- commands
137
iterateDepth ini_tbl max_rounds ktn nmlen imlen
136
iterateDepth ini_tbl max_rounds nmlen imlen
138 137
             cmd_strs oneline min_score =
139 138
    let Cluster.Table ini_nl ini_il ini_cv ini_plc = ini_tbl
140 139
        all_inst = Container.elems ini_il
......
148 147
    in
149 148
      do
150 149
        let
151
            (sol_line, cmds) = Cluster.printSolutionLine ini_il ktn
150
            (sol_line, cmds) = Cluster.printSolutionLine ini_nl ini_il
152 151
                               nmlen imlen (head fin_plc) fin_plc_len
153 152
            upd_cmd_strs = cmds:cmd_strs
154 153
        unless (oneline || fin_plc_len == ini_plc_len) $ do
......
156 155
          hFlush stdout
157 156
        (if fin_cv < ini_cv then -- this round made success, try deeper
158 157
             if allowed_next && fin_cv > min_score
159
             then iterateDepth fin_tbl max_rounds ktn
158
             then iterateDepth fin_tbl max_rounds
160 159
                  nmlen imlen upd_cmd_strs oneline min_score
161 160
             -- don't go deeper, but return the better solution
162 161
             else return (fin_tbl, upd_cmd_strs)
......
182 181
  let oneline = optOneline opts
183 182
      verbose = optVerbose opts
184 183

  
185
  (fixed_nl, il, csf, ktn, kti) <- CLI.loadExternalData opts
184
  (fixed_nl, il, csf, _, _) <- CLI.loadExternalData opts
186 185

  
187 186
  let offline_names = optOffline opts
188
      all_names = snd . unzip $ ktn
187
      all_nodes = Container.elems fixed_nl
188
      all_names = map Node.name all_nodes
189 189
      offline_wrong = filter (\n -> not $ elem n all_names) offline_names
190
      offline_indices = fst . unzip .
191
                        filter (\(_, n) -> elem n offline_names) $ ktn
190
      offline_indices = map Node.idx $
191
                        filter (\n -> elem (Node.name n) offline_names)
192
                               all_nodes
192 193

  
193 194
  when (length offline_wrong > 0) $ do
194 195
         printf "Wrong node name(s) set as offline: %s\n"
......
244 245
                      printf "Initial score: %.8f\n" ini_cv)
245 246

  
246 247
  unless oneline $ putStrLn "Trying to minimize the CV..."
247
  let mlen_fn = maximum . (map length) . snd . unzip
248
      imlen = mlen_fn kti
249
      nmlen = mlen_fn ktn
248
  let imlen = cMaxNamelen il
249
      nmlen = cMaxNamelen nl
250 250

  
251 251
  (fin_tbl, cmd_strs) <- iterateDepth ini_tbl (optMaxLength opts)
252
                         ktn nmlen imlen [] oneline min_cv
252
                         nmlen imlen [] oneline min_cv
253 253
  let (Cluster.Table fin_nl _ fin_cv fin_plc) = fin_tbl
254 254
      ord_plc = reverse fin_plc
255 255
      sol_msg = if null fin_plc
b/hn1.hs
145 145
         hPutStrLn stderr "Error: this program doesn't take any arguments."
146 146
         exitWith $ ExitFailure 1
147 147

  
148
  (nl, il, csf, ktn, kti) <- CLI.loadExternalData opts
148
  (nl, il, csf, _, _) <- CLI.loadExternalData opts
149 149

  
150 150
  printf "Loaded %d nodes, %d instances\n"
151 151
             (Container.size nl)
......
197 197
         (Cluster.printStats ns)
198 198

  
199 199
  printf "Solution (delta=%d):\n" $! min_d
200
  let (sol_strs, cmd_strs) = Cluster.printSolution il ktn kti solution
200
  let (sol_strs, cmd_strs) = Cluster.printSolution ns il solution
201 201
  putStr $ unlines $ sol_strs
202 202
  when (optShowCmds opts) $
203 203
       do
b/hscan.hs
92 92
    in unlines nlines
93 93

  
94 94
-- | Generate instance file data from instance objects
95
serializeInstances :: Cluster.InstanceList -> String
96
                   -> Cluster.NameList -> String
97
serializeInstances il csf ktn =
98
    let etn = map (\(idx, name) -> (idx, name ++ csf)) ktn
99
        instances = Container.elems il
95
serializeInstances :: Cluster.NodeList -> Cluster.InstanceList
96
                   -> String -> String
97
serializeInstances nl il csf =
98
    let instances = Container.elems il
100 99
        nlines = map
101 100
                 (\inst ->
102 101
                      let
103 102
                          iname = Instance.name inst ++ csf
104
                          pnode = fromJust $ lookup (Instance.pnode inst) etn
105
                          snode = fromJust $ lookup (Instance.snode inst) etn
103
                          pnode = cNameOf nl $ Instance.pnode inst
104
                          snode = cNameOf nl $ Instance.snode inst
106 105
                      in
107 106
                        printf "%s|%d|%d|%s|%s|%s"
108 107
                               iname (Instance.mem inst) (Instance.dsk inst)
......
163 162
                 Bad err -> printf "\nError: failed to load data. \
164 163
                                   \Details:\n%s\n" err
165 164
                 Ok x -> do
166
                   let (nl, il, csf, ktn, _) = x
165
                   let (nl, il, csf, _, _) = x
167 166
                       (_, fix_nl) = Loader.checkData nl il
168 167
                   putStrLn $ printCluster fix_nl il
169 168
                   when (optShowNodes opts) $ do
170 169
                           putStr $ Cluster.printNodes fix_nl
171 170
                   let ndata = serializeNodes nl csf
172
                       idata = serializeInstances il csf ktn
171
                       idata = serializeInstances nl il csf
173 172
                       oname = odir </> (fixSlash name)
174 173
                   writeFile (oname <.> "nodes") ndata
175 174
                   writeFile (oname <.> "instances") idata)

Also available in: Unified diff