Commit 47a8bade authored by Iustin Pop's avatar Iustin Pop
Browse files

Pass actual types to node/instance constructors

This patch changes the parameters passed to the node and instance
constructors from generic Strings (which are then parsed via “read”) to
the actual used types, by converting them earlier in Cluster.loadData.
parent 670b57ad
......@@ -750,16 +750,19 @@ loadData :: String -- ^ Node data in text format
String, NameList, NameList)
loadData ndata idata =
let
{- node file: name mem disk -}
{- node file: name t_mem f_mem t_disk f_disk -}
(ktn, nl) = loadTabular ndata
(\ (i:jt:jf:kt:kf:[]) -> (i, Node.create jt jf kt kf))
(\ (name:tm:fm:td:fd:[]) ->
(name,
Node.create (read tm) (read fm) (read td) (read fd)))
Node.setIdx
{- instance file: name mem disk pnode snode -}
(kti, il) = loadTabular idata
(\ (i:j:k:l:m:[]) -> (i,
Instance.create j k
(fromJust $ lookup l ktn)
(fromJust $ lookup m ktn)))
(\ (name:mem:dsk:pnode:snode:[]) ->
(name,
Instance.create (read mem) (read dsk)
(fromJust $ lookup pnode ktn)
(fromJust $ lookup snode ktn)))
Instance.setIdx
nl2 = fixNodes nl il
il3 = Container.fromAssocList il
......
......@@ -13,14 +13,15 @@ data Instance = Instance { mem :: Int -- ^ memory of the instance
, idx :: Int -- ^ internal index for book-keeping
} deriving (Show)
create :: String -> String -> Int -> Int -> Instance
create mem_init dsk_init pn sn = Instance {
mem = read mem_init,
dsk = read dsk_init,
pnode = pn,
snode = sn,
idx = -1
}
create :: Int -> Int -> Int -> Int -> Instance
create mem_init dsk_init pn sn =
Instance {
mem = mem_init,
dsk = dsk_init,
pnode = pn,
snode = sn,
idx = -1
}
-- | Changes the primary node of the instance.
setPri :: Instance -- ^ the original instance
......
......@@ -59,30 +59,25 @@ 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 -> Node
create :: Double -> Int -> Double -> Int -> Node
create mem_t_init mem_f_init dsk_t_init dsk_f_init =
let mem_t = read mem_t_init
mem_f = read mem_f_init
dsk_t = read dsk_t_init
dsk_f = read dsk_f_init
in
Node
{
t_mem = read mem_t_init,
f_mem = read mem_f_init,
t_dsk = read dsk_t_init,
f_dsk = read dsk_f_init,
plist = [],
slist = [],
failN1 = True,
idx = -1,
peers = PeerMap.empty,
r_mem = 0,
p_mem = (fromIntegral mem_f) / (fromIntegral mem_t),
p_dsk = (fromIntegral dsk_f) / (fromIntegral dsk_t),
p_rem = 0,
offline = False
}
Node
{
t_mem = mem_t_init,
f_mem = mem_f_init,
t_dsk = dsk_t_init,
f_dsk = dsk_f_init,
plist = [],
slist = [],
failN1 = True,
idx = -1,
peers = PeerMap.empty,
r_mem = 0,
p_mem = (fromIntegral mem_f_init) / mem_t_init,
p_dsk = (fromIntegral dsk_f_init) / dsk_t_init,
p_rem = 0,
offline = False
}
-- | Changes the index.
-- This is used only during the building of the data structures.
......
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