Commit 01f6a5d2 authored by Iustin Pop's avatar Iustin Pop
Browse files

Change the input file formats

This patch changes the format of the input node and instance lists. It
removes the list of primary and secondary instances from the nodes, and
adds the primary and secondary nodes to the instance list.

This is done so that we can have the same input data from commands as
from the RAPI.
parent a7654563
......@@ -30,7 +30,7 @@ the same minimum length.
So basically we aim to determine here: what is the minimum number of instances
that need to be removed (this is called the removal depth) and which are the
actual combinations that fit (called the list of removal sets).
actual combinations that fit (called the list of removal sets).
In phase 2, for each removal set computed in the previous phase, we take the
removed instances and try to determine where we can put them so that the
......@@ -228,9 +228,9 @@ Integration with Ganeti
The programs needs only the output of the node list and instance list. That is,
they need the following two commands to be run::
gnt-node list -oname,mtotal,mfree,dtotal,dfree,pinst_list,sinst_list \
gnt-node list -oname,mtotal,mfree,dtotal,dfree \
--separator '|' --no-headers > nodes
gnt-instance list -oname,admin_ram,sda_size \
gnt-instance list -oname,admin_ram,sda_size,pnode,snodes \
--separator '|' --no-head > instances
These two files should be saved under the names of 'nodes' and 'instances'.
......
......@@ -588,30 +588,25 @@ loadTabular text_data convert_fn set_fn =
(zip [0..] kerows)
in unzip idxrows
-- | Set the primary or secondary node indices on the instance list.
fixInstances :: [(Int, Node.Node)]
-> (Node.Node -> [Int]) -- ^ Either 'Node.slist' or 'Node.plist'
-> (Instance.Instance -> Int -> Instance.Instance)
-- ^ Either 'Instance.setSec' or 'Instance.setPri'
-> [(Int, Instance.Instance)]
-> [(Int, Instance.Instance)]
fixInstances nl list_fn set_fn il =
concat $ map
(\ (n_idx, n) ->
map
(\ i_idx ->
let oldi = fromJust (lookup i_idx il)
in
(i_idx, set_fn oldi n_idx)
) (list_fn n)
) nl
-- | Splits and returns a list of indexes based on an Instance assoc list.
csi :: String -> [(String, Int)] -> [Int]
csi values il =
map
(\ x -> fromJust (lookup x il))
(commaSplit values)
-- | For each instance, add its index to its primary and secondary nodes
fixNodes :: [(Int, Node.Node)]
-> [(Int, Instance.Instance)]
-> [(Int, Node.Node)]
fixNodes nl il =
foldl (\accu (idx, inst) ->
let
assocEqual = (\ (i, _) (j, _) -> i == j)
pdx = Instance.pnode inst
sdx = Instance.snode inst
pold = fromJust $ lookup pdx nl
sold = fromJust $ lookup sdx nl
pnew = Node.setPri pold idx
snew = Node.setSec sold idx
ac1 = deleteBy assocEqual (pdx, pold) accu
ac2 = deleteBy assocEqual (sdx, sold) ac1
ac3 = (pdx, pnew):(sdx, snew):ac2
in ac3) nl il
{-| Initializer function that loads the data from a node and list file
and massages it into the correct format. -}
......@@ -621,18 +616,21 @@ loadData :: String -- ^ Node data in text format
Container.Container Instance.Instance,
[(Int, String)], [(Int, String)])
loadData ndata idata =
{- instance file: name mem disk -}
let (kti, il) = loadTabular idata
(\ (i:j:k:[]) -> (i, Instance.create j k)) Instance.setIdx
{- node file: name mem disk plist slist -}
let
{- node file: name mem disk -}
(ktn, nl) = loadTabular ndata
(\ (i:jt:jf:kt:kf:l:m:[]) ->
(i, Node.create jt jf kt kf (csi l kti) (csi m kti)))
(\ (i:jt:jf:kt:kf:[]) -> (i, Node.create jt jf kt kf))
Node.setIdx
il2 = fixInstances nl Node.slist Instance.setSec $
fixInstances nl Node.plist Instance.setPri il
il3 = Container.fromAssocList il2
{- instance file: name mem disk -}
(kti, il) = loadTabular idata
(\ (i:j:k:l:m:[]) -> (i,
Instance.create j k
(fromJust $ lookup l ktn)
(fromJust $ lookup m ktn)))
Instance.setIdx
nl2 = fixNodes nl il
il3 = Container.fromAssocList il
nl3 = Container.fromAssocList
(map (\ (k, v) -> (k, Node.buildPeers v il3 (length nl))) nl)
(map (\ (k, v) -> (k, Node.buildPeers v il3 (length nl2))) nl2)
in
(nl3, il3, swapPairs ktn, swapPairs kti)
......@@ -13,12 +13,12 @@ data Instance = Instance { mem :: Int -- ^ memory of the instance
, idx :: Int -- ^ internal index for book-keeping
} deriving (Show)
create :: String -> String -> Instance
create mem_init disk_init = Instance {
create :: String -> String -> Int -> Int -> Instance
create mem_init disk_init pn sn = Instance {
mem = read mem_init,
disk = read disk_init,
pnode = -1,
snode = -1,
pnode = pn,
snode = sn,
idx = -1
}
......
......@@ -17,6 +17,8 @@ module Node
, removeSec
, addPri
, addSec
, setPri
, setSec
-- * Statistics
, normUsed
-- * Formatting
......@@ -52,16 +54,16 @@ The index and the peers maps are empty, and will be need to be update
later via the 'setIdx' and 'buildPeers' functions.
-}
create :: String -> String -> String -> String -> [Int] -> [Int] -> Node
create :: String -> String -> String -> String -> Node
create mem_t_init mem_f_init disk_t_init disk_f_init
plist_init slist_init = Node
= Node
{
t_mem = read mem_t_init,
f_mem = read mem_f_init,
t_disk = read disk_t_init,
f_disk = read disk_f_init,
plist = plist_init,
slist = slist_init,
plist = [],
slist = [],
failN1 = True,
idx = -1,
peers = PeerMap.empty,
......@@ -158,6 +160,14 @@ addSec t inst pdx =
peers = new_peers, failN1 = new_failn1,
maxRes = new_rmem}
-- | Add a primary instance to a node without other updates
setPri :: Node -> Int -> Node
setPri t idx = t { plist = idx:(plist t) }
-- | Add a secondary instance to a node without other updates
setSec :: Node -> Int -> Node
setSec t idx = t { slist = idx:(slist t) }
-- | Simple converter to string.
str :: Node -> String
str t =
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment