Commit c8c071cb authored by Bernardo Dal Seno's avatar Bernardo Dal Seno
Browse files

Load CPUs used by the node OS in htools



A new field is added to the Node type, and it's used to initialize the used
CPUs field.

The signature of Node.create has been split among lines to match the
parameter list.
Signed-off-by: default avatarBernardo Dal Seno <bdalseno@google.com>
Reviewed-by: default avatarKlaus Aehlig <aehlig@google.com>
parent f43c898d
......@@ -181,6 +181,7 @@ support all options. Some common options are:
- node tags
- exclusive storage value (``Y`` if active, ``N`` otherwise)
- node free spindles
- virtual CPUs used by the node OS
The third section contains instance data, with the fields:
......
......@@ -147,8 +147,9 @@ parseNode ktg n a = do
dtotal <- lvextract 0.0 "total_disk"
dfree <- lvextract 0 "free_disk"
ctotal <- lvextract 0.0 "total_cpus"
let node = Node.create n mtotal mnode mfree dtotal dfree ctotal (not live)
sptotal spfree gidx excl_stor
cnos <- lvextract 0 "reserved_cpus"
let node = Node.create n mtotal mnode mfree dtotal dfree ctotal cnos
(not live) sptotal spfree gidx excl_stor
return (n, node)
-- | Parses a group as found in the cluster group list.
......
......@@ -117,7 +117,7 @@ queryNodesMsg :: L.LuxiOp
queryNodesMsg =
L.Query (Qlang.ItemTypeOpCode Qlang.QRNode)
["name", "mtotal", "mnode", "mfree", "dtotal", "dfree",
"ctotal", "offline", "drained", "vm_capable",
"ctotal", "cnos", "offline", "drained", "vm_capable",
"ndp/spindle_count", "group.uuid", "tags",
"ndp/exclusive_storage", "sptotal", "spfree"] Qlang.EmptyFilter
......@@ -204,7 +204,7 @@ getNodes ktg arr = extractArray arr >>= mapM (parseNode ktg)
-- | Construct a node from a JSON object.
parseNode :: NameAssoc -> [(JSValue, JSValue)] -> Result (String, Node.Node)
parseNode ktg [ name, mtotal, mnode, mfree, dtotal, dfree
, ctotal, offline, drained, vm_capable, spindles, g_uuid
, ctotal, cnos, offline, drained, vm_capable, spindles, g_uuid
, tags, excl_stor, sptotal, spfree ]
= do
xname <- annotateResult "Parsing new node" (fromJValWithStatus name)
......@@ -227,9 +227,10 @@ parseNode ktg [ name, mtotal, mnode, mfree, dtotal, dfree
xdtotal <- lvconvert 0.0 "dtotal" dtotal
xdfree <- lvconvert 0 "dfree" dfree
xctotal <- lvconvert 0.0 "ctotal" ctotal
xcnos <- lvconvert 0 "cnos" cnos
let node = flip Node.setNodeTags xtags $
Node.create xname xmtotal xmnode xmfree xdtotal xdfree
xctotal (not live) xsptotal xspfree xgdx xexcl_stor
xctotal xcnos (not live) xsptotal xspfree xgdx xexcl_stor
return (xname, node)
parseNode _ v = fail ("Invalid node query result: " ++ show v)
......
......@@ -171,10 +171,11 @@ parseNode ktg a = do
dtotal <- lvextract 0.0 "dtotal"
dfree <- lvextract 0 "dfree"
ctotal <- lvextract 0.0 "ctotal"
cnos <- lvextract 0 "cnos"
tags <- extract "tags"
let node = flip Node.setNodeTags tags $
Node.create name mtotal mnode mfree dtotal dfree ctotal (not live)
sptotal spfree guuid' excl_stor
Node.create name mtotal mnode mfree dtotal dfree ctotal cnos
(not live) sptotal spfree guuid' excl_stor
return (name, node)
-- | Construct a group from a JSON object.
......
......@@ -85,7 +85,7 @@ createGroup grpIndex spec = do
Node.create (printf "node-%02d-%03d" grpIndex idx)
(fromIntegral mem) 0 mem
(fromIntegral disk) disk
(fromIntegral cpu) False spindles 0 grpIndex excl_stor
(fromIntegral cpu) 1 False spindles 0 grpIndex excl_stor
) [1..ncount]
-- TODO: parse networks to which this group is connected
grp = Group.create (printf "group-%02d" grpIndex)
......
......@@ -84,7 +84,7 @@ serializeNode :: Group.List -- ^ The list of groups (needed for group uuid)
-> Node.Node -- ^ The node to be serialised
-> String
serializeNode gl node =
printf "%s|%.0f|%d|%d|%.0f|%d|%.0f|%c|%s|%d|%s|%s|%d" (Node.name node)
printf "%s|%.0f|%d|%d|%.0f|%d|%.0f|%c|%s|%d|%s|%s|%d|%d" (Node.name node)
(Node.tMem node) (Node.nMem node) (Node.fMem node)
(Node.tDsk node) (Node.fDsk node) (Node.tCpu node)
(if Node.offline node then 'Y' else
......@@ -94,6 +94,7 @@ serializeNode gl node =
(intercalate "," (Node.nTags node))
(if Node.exclStorage node then "Y" else "N")
(Node.fSpindles node)
(Node.nCpu node)
where grp = Container.find (Node.group node) gl
-- | Generate node file data from node objects.
......@@ -206,11 +207,11 @@ loadNode :: (Monad m) =>
-> m (String, Node.Node) -- ^ The result, a tuple o node name
-- and node object
loadNode ktg [name, tm, nm, fm, td, fd, tc, fo, gu, spindles, tags,
excl_stor, free_spindles] = do
excl_stor, free_spindles, nos_cpu] = do
gdx <- lookupGroup ktg name gu
new_node <-
if "?" `elem` [tm,nm,fm,td,fd,tc] || fo == "Y" then
return $ Node.create name 0 0 0 0 0 0 True 0 0 gdx False
return $ Node.create name 0 0 0 0 0 0 0 True 0 0 gdx False
else do
let vtags = commaSplit tags
vtm <- tryRead name tm
......@@ -219,6 +220,7 @@ loadNode ktg [name, tm, nm, fm, td, fd, tc, fo, gu, spindles, tags,
vtd <- tryRead name td
vfd <- tryRead name fd
vtc <- tryRead name tc
vnc <- tryRead name nos_cpu
vspindles <- tryRead name spindles
vfree_spindles <- tryRead name free_spindles
vexcl_stor <- case excl_stor of
......@@ -228,7 +230,7 @@ loadNode ktg [name, tm, nm, fm, td, fd, tc, fo, gu, spindles, tags,
"Invalid exclusive_storage value for node '" ++
name ++ "': " ++ excl_stor
return . flip Node.setMaster (fo == "M") . flip Node.setNodeTags vtags $
Node.create name vtm vnm vfm vtd vfd vtc False vspindles
Node.create name vtm vnm vfm vtd vfd vtc vnc False vspindles
vfree_spindles gdx vexcl_stor
return (name, new_node)
......@@ -246,6 +248,11 @@ loadNode ktg [name, tm, nm, fm, td, fd, tc, fo, gu, spindles, tags,
loadNode ktg [name, tm, nm, fm, td, fd, tc, fo, gu, spindles, tags,
excl_stor, "0"]
loadNode ktg [name, tm, nm, fm, td, fd, tc, fo, gu, spindles, tags,
excl_stor, free_spindles] =
loadNode ktg [name, tm, nm, fm, td, fd, tc, fo, gu, spindles, tags,
excl_stor, free_spindles, "1"]
loadNode _ s = fail $ "Invalid/incomplete node data: '" ++ show s ++ "'"
-- | Load an instance from a field list.
......
......@@ -111,6 +111,7 @@ data Node = Node
, tDsk :: Double -- ^ Total disk space (MiB)
, fDsk :: Int -- ^ Free disk space (MiB)
, tCpu :: Double -- ^ Total CPU count
, nCpu :: Int -- ^ VCPUs used by the node OS
, uCpu :: Int -- ^ Used VCPU count
, tSpindles :: Int -- ^ Node spindles (spindle_count node parameter,
-- or actual spindles, see note below)
......@@ -234,11 +235,13 @@ haveExclStorage nl =
--
-- The index and the peers maps are empty, and will be need to be
-- update later via the 'setIdx' and 'buildPeers' functions.
create :: String -> Double -> Int -> Int -> Double
-> Int -> Double -> Bool -> Int -> Int -> T.Gdx -> Bool -> Node
create :: String -> Double -> Int -> Int
-> Double -> Int -> Double -> Int -> Bool
-> Int -> Int -> T.Gdx -> Bool
-> Node
create name_init mem_t_init mem_n_init mem_f_init
dsk_t_init dsk_f_init cpu_t_init offline_init spindles_t_init
spindles_f_init group_init excl_stor =
dsk_t_init dsk_f_init cpu_t_init cpu_n_init offline_init
spindles_t_init spindles_f_init group_init excl_stor =
Node { name = name_init
, alias = name_init
, tMem = mem_t_init
......@@ -247,9 +250,10 @@ create name_init mem_t_init mem_n_init mem_f_init
, tDsk = dsk_t_init
, fDsk = dsk_f_init
, tCpu = cpu_t_init
, nCpu = cpu_n_init
, uCpu = cpu_n_init
, tSpindles = spindles_t_init
, fSpindles = spindles_f_init
, uCpu = 0
, pList = []
, sList = []
, failN1 = True
......@@ -261,7 +265,7 @@ create name_init mem_t_init mem_n_init mem_f_init
then computePDsk spindles_f_init $ fromIntegral spindles_t_init
else computePDsk dsk_f_init dsk_t_init
, pRem = 0
, pCpu = 0
, pCpu = fromIntegral cpu_n_init / cpu_t_init
, offline = offline_init
, isMaster = False
, nTags = []
......
......@@ -429,6 +429,7 @@
"exclusive_storage": false
},
"reserved_memory": 1017,
"reserved_cpus": 1,
"master_capable": true,
"free_disk": 1377280,
"drained": false,
......@@ -455,6 +456,7 @@
"exclusive_storage": false
},
"reserved_memory": 1017,
"reserved_cpus": 1,
"master_capable": true,
"free_disk": 1376640,
"drained": false,
......@@ -481,6 +483,7 @@
"exclusive_storage": false
},
"reserved_memory": 1017,
"reserved_cpus": 1,
"master_capable": true,
"free_disk": 1373336,
"drained": false,
......@@ -507,6 +510,7 @@
"exclusive_storage": false
},
"reserved_memory": 1017,
"reserved_cpus": 1,
"master_capable": true,
"free_disk": 1371520,
"drained": false,
......
......@@ -106,6 +106,7 @@
},
"offline": false,
"reserved_memory": 1017,
"reserved_cpus": 1,
"total_cpus": 4,
"total_disk": 7168,
"total_memory": 4096,
......@@ -123,6 +124,7 @@
},
"offline": false,
"reserved_memory": 1017,
"reserved_cpus": 1,
"total_cpus": 4,
"total_disk": 7168,
"total_memory": 4096,
......
......@@ -65,6 +65,7 @@
},
"offline": false,
"reserved_memory": 1017,
"reserved_cpus": 1,
"total_cpus": 4,
"total_disk": 1377280,
"total_memory": 32763,
......
......@@ -197,6 +197,7 @@
},
"offline": false,
"reserved_memory": 1017,
"reserved_cpus": 1,
"total_cpus": 4,
"total_disk": 7168,
"total_memory": 4096,
......@@ -214,6 +215,7 @@
},
"offline": false,
"reserved_memory": 1017,
"reserved_cpus": 1,
"total_cpus": 4,
"total_disk": 7168,
"total_memory": 32763,
......@@ -231,6 +233,7 @@
},
"offline": false,
"reserved_memory": 1017,
"reserved_cpus": 1,
"total_cpus": 4,
"total_disk": 7168,
"total_memory": 4096,
......@@ -248,6 +251,7 @@
},
"offline": false,
"reserved_memory": 1017,
"reserved_cpus": 1,
"total_cpus": 4,
"total_disk": 7168,
"total_memory": 4096,
......
......@@ -284,6 +284,7 @@
"exclusive_storage": false
},
"reserved_memory": 1017,
"reserved_cpus": 1,
"master_capable": true,
"free_disk": 687280,
"drained": false,
......@@ -310,6 +311,7 @@
"exclusive_storage": false
},
"reserved_memory": 1017,
"reserved_cpus": 1,
"master_capable": true,
"free_disk": 1377024,
"drained": false,
......@@ -336,6 +338,7 @@
"exclusive_storage": false
},
"reserved_memory": 1017,
"reserved_cpus": 1,
"master_capable": true,
"free_disk": 687280,
"drained": false,
......@@ -362,6 +365,7 @@
"exclusive_storage": false
},
"reserved_memory": 1017,
"reserved_cpus": 1,
"master_capable": true,
"free_disk": 1377024,
"drained": false,
......
......@@ -65,6 +65,7 @@
},
"offline": false,
"reserved_memory": 1017,
"reserved_cpus": 1,
"total_cpus": 4,
"total_disk": 1377280,
"total_memory": 32763,
......
......@@ -476,6 +476,7 @@
"exclusive_storage": false
},
"reserved_memory": 1017,
"reserved_cpus": 1,
"master_capable": true,
"free_disk": 1377280,
"drained": false,
......@@ -502,6 +503,7 @@
"exclusive_storage": false
},
"reserved_memory": 1017,
"reserved_cpus": 1,
"master_capable": true,
"free_disk": 1373336,
"drained": false,
......@@ -528,6 +530,7 @@
"exclusive_storage": false
},
"reserved_memory": 1017,
"reserved_cpus": 1,
"master_capable": true,
"free_disk": 1371520,
"drained": false,
......@@ -554,6 +557,7 @@
"exclusive_storage": false
},
"reserved_memory": 1017,
"reserved_cpus": 1,
"master_capable": true,
"free_disk": 1376640,
"drained": false,
......@@ -580,6 +584,7 @@
"exclusive_storage": false
},
"reserved_memory": 1017,
"reserved_cpus": 1,
"master_capable": true,
"free_disk": 1376640,
"drained": false,
......
......@@ -425,6 +425,7 @@
"exclusive_storage": false
},
"reserved_memory": 1017,
"reserved_cpus": 1,
"master_capable": true,
"free_disk": 1377280,
"drained": false,
......@@ -451,6 +452,7 @@
"exclusive_storage": false
},
"reserved_memory": 1017,
"reserved_cpus": 1,
"master_capable": true,
"free_disk": 1376640,
"drained": false,
......@@ -477,6 +479,7 @@
"exclusive_storage": false
},
"reserved_memory": 1017,
"reserved_cpus": 1,
"master_capable": true,
"free_disk": 1373336,
"drained": false,
......@@ -503,6 +506,7 @@
"exclusive_storage": false
},
"reserved_memory": 1017,
"reserved_cpus": 1,
"master_capable": true,
"free_disk": 1371520,
"drained": false,
......
......@@ -429,6 +429,7 @@
"exclusive_storage": false
},
"reserved_memory": 1017,
"reserved_cpus": 1,
"master_capable": true,
"free_disk": 1377280,
"drained": false,
......@@ -455,6 +456,7 @@
"exclusive_storage": false
},
"reserved_memory": 1017,
"reserved_cpus": 1,
"master_capable": true,
"free_disk": 1376640,
"drained": false,
......@@ -481,6 +483,7 @@
"exclusive_storage": false
},
"reserved_memory": 1017,
"reserved_cpus": 1,
"master_capable": true,
"free_disk": 1373336,
"drained": false,
......@@ -507,6 +510,7 @@
"exclusive_storage": false
},
"reserved_memory": 1017,
"reserved_cpus": 1,
"master_capable": true,
"free_disk": 1371520,
"drained": false,
......
[
{
"cnodes": 2,
"cnos": 1,
"csockets": 2,
"ctime": 1324472016.2968869,
"ctotal": 4,
......@@ -37,6 +38,7 @@
},
{
"cnodes": 2,
"cnos": 1,
"csockets": 2,
"ctime": 1324472016.2968869,
"ctotal": 4,
......@@ -73,6 +75,7 @@
},
{
"cnodes": 2,
"cnos": 1,
"dfree": 1373336,
"drained": false,
"dtotal": 1377304,
......@@ -117,6 +120,7 @@
},
{
"cnodes": 2,
"cnos": 1,
"dfree": 1371520,
"drained": false,
"dtotal": 1377280,
......
......@@ -107,7 +107,7 @@ prop_Score_Zero node =
forAll (choose (1, 1024)) $ \count ->
(not (Node.offline node) && not (Node.failN1 node) && (count > 0) &&
(Node.tDsk node > 0) && (Node.tMem node > 0) &&
(Node.tSpindles node > 0)) ==>
(Node.tSpindles node > 0) && (Node.tCpu node > 0)) ==>
let fn = Node.buildPeers node Container.empty
nlst = replicate count fn
score = Cluster.compCVNodes nlst
......
......@@ -90,10 +90,11 @@ genNode min_multiplier max_multiplier = do
dsk_t <- choose (base_dsk, top_dsk)
dsk_f <- choose (base_dsk, dsk_t)
cpu_t <- choose (base_cpu, top_cpu)
cpu_n <- choose (base_cpu, cpu_t)
offl <- arbitrary
spindles <- choose (base_spindles, top_spindles)
let n = Node.create name (fromIntegral mem_t) mem_n mem_f
(fromIntegral dsk_t) dsk_f (fromIntegral cpu_t) offl spindles
(fromIntegral dsk_t) dsk_f (fromIntegral cpu_t) cpu_n offl spindles
0 0 False
n' = Node.setPolicy nullIPolicy n
return $ Node.buildPeers n' Container.empty
......
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