Commit d6eec019 authored by Iustin Pop's avatar Iustin Pop
Browse files

Set group policy on nodes



In order to be able to use the group policy during allocation, we have
a few choices:

- pass the group policy as a separate argument to all involved
  functions, or
- add the policy as an attribute to nodes, or
- add the group (not only the group index) as an attribute to nodes

The first and last one would change more than wanted for this patch,
so I went with the second one; it will allow easily checking the
target policy at runtime (based on the instance's primary node), with
the only downside that without a node, we can't check the policy.

Note that the first option also would complicate the allocation
routines, which examine (big) lists of node/node pairs, so adding the
group to this would complicate things even more.
Signed-off-by: default avatarIustin Pop <iustin@google.com>
Reviewed-by: default avatarRené Nussbaumer <rn@google.com>
parent cdbab531
......@@ -7,7 +7,7 @@ has been loaded from external sources.
{-
Copyright (C) 2009, 2010, 2011 Google Inc.
Copyright (C) 2009, 2010, 2011, 2012 Google Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -219,6 +219,15 @@ fixNodes accu inst =
in Container.add sdx snew ac2
else ac2
-- | Set the node's policy to its group one. Note that this requires
-- the group to exist (should have been checked before), otherwise it
-- will abort with a runtime error.
setNodePolicy :: Group.List -> Node.Node -> Node.Node
setNodePolicy gl node =
let grp = Container.find (Node.group node) gl
gpol = Group.iPolicy grp
in Node.setPolicy gpol node
-- | Remove non-selected tags from the exclusion list.
filterExTags :: [String] -> Instance.Instance -> Instance.Instance
filterExTags tl inst =
......@@ -269,7 +278,7 @@ mergeData :: [(String, DynUtil)] -- ^ Instance utilisation data
-> [String] -- ^ Excluded instances
-> ClusterData -- ^ Data from backends
-> Result ClusterData -- ^ Fixed cluster data
mergeData um extags selinsts exinsts cdata@(ClusterData _ nl il2 tags _) =
mergeData um extags selinsts exinsts cdata@(ClusterData gl nl il2 tags _) =
let il = Container.elems il2
il3 = foldl' (\im (name, n_util) ->
case Container.findByName im name of
......@@ -291,7 +300,8 @@ mergeData um extags selinsts exinsts cdata@(ClusterData _ nl il2 tags _) =
filterExTags allextags .
updateMovable selinst_names exinst_names) il3
nl2 = foldl' fixNodes nl (Container.elems il4)
nl3 = Container.map (computeAlias common_suffix .
nl3 = Container.map (setNodePolicy gl .
computeAlias common_suffix .
(`Node.buildPeers` il4)) nl2
in if' (null lkp_unknown)
(Ok cdata { cdNodes = nl3, cdInstances = il4 })
......
......@@ -6,7 +6,7 @@
{-
Copyright (C) 2009, 2010, 2011 Google Inc.
Copyright (C) 2009, 2010, 2011, 2012 Google Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -41,6 +41,7 @@ module Ganeti.HTools.Node
, setSec
, setMdsk
, setMcpu
, setPolicy
-- * Tag maps
, addTags
, delTags
......@@ -124,6 +125,7 @@ data Node = Node
, utilLoad :: T.DynUtil -- ^ Sum of instance utilisation
, pTags :: TagMap -- ^ Map of primary instance tags and their count
, group :: T.Gdx -- ^ The node's group (index)
, iPolicy :: T.IPolicy -- ^ The instance policy (of the node's group)
} deriving (Show, Read, Eq)
instance T.Element Node where
......@@ -219,6 +221,7 @@ create name_init mem_t_init mem_n_init mem_f_init
, utilLoad = T.zeroUtil
, pTags = Map.empty
, group = group_init
, iPolicy = T.defIPolicy
}
-- | Conversion formula from mDsk\/tDsk to loDsk.
......@@ -257,6 +260,10 @@ setMdsk t val = t { mDsk = val, loDsk = mDskToloDsk val (tDsk t) }
setMcpu :: Node -> Double -> Node
setMcpu t val = t { mCpu = val, hiCpu = mCpuTohiCpu val (tCpu t) }
-- | Sets the policy.
setPolicy :: T.IPolicy -> Node -> Node
setPolicy pol node = node { iPolicy = pol }
-- | Computes the maximum reserved memory for peers from a peer map.
computeMaxRes :: P.PeerMap -> P.Elem
computeMaxRes = P.maxElem
......
......@@ -6,7 +6,7 @@
{-
Copyright (C) 2009, 2010, 2011 Google Inc.
Copyright (C) 2009, 2010, 2011, 2012 Google Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -262,7 +262,8 @@ genNode min_multiplier max_multiplier = do
offl <- arbitrary
let n = Node.create name (fromIntegral mem_t) mem_n mem_f
(fromIntegral dsk_t) dsk_f (fromIntegral cpu_t) offl 0
return $ Node.buildPeers n Container.empty
n' = Node.setPolicy nullIPolicy n
return $ Node.buildPeers n' Container.empty
-- and a random node
instance Arbitrary Node.Node where
......@@ -679,7 +680,8 @@ prop_Text_NodeLSIdempotent node =
Utils.sepSplit '|' . Text.serializeNode defGroupList) n ==
Just (Node.name n, n)
-- override failN1 to what loadNode returns by default
where n = node { Node.failN1 = True, Node.offline = False }
where n = node { Node.failN1 = True, Node.offline = False
, Node.iPolicy = Types.defIPolicy }
testSuite "Text"
[ 'prop_Text_Load_Instance
......
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