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
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'.
(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. -}
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)
, removeSec
, addPri
, addSec
+ , setPri
+ , setSec
-- * Statistics
, normUsed
-- * Formatting
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,
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 =