Revision 9188aeef Ganeti/HTools/Node.hs
b/Ganeti/HTools/Node.hs | ||
---|---|---|
18 | 18 |
, setOffline |
19 | 19 |
, setXmem |
20 | 20 |
, setFmem |
21 |
, setPri |
|
22 |
, setSec |
|
21 | 23 |
-- * Instance (re)location |
22 | 24 |
, removePri |
23 | 25 |
, removeSec |
24 | 26 |
, addPri |
25 | 27 |
, addSec |
26 |
, setPri |
|
27 |
, setSec |
|
28 | 28 |
-- * Formatting |
29 | 29 |
, list |
30 | 30 |
-- * Misc stuff |
... | ... | |
41 | 41 |
|
42 | 42 |
import qualified Ganeti.HTools.Types as T |
43 | 43 |
|
44 |
data Node = Node { name :: String -- ^ the node name |
|
45 |
, t_mem :: Double -- ^ total memory (MiB) |
|
46 |
, n_mem :: Int -- ^ node memory (MiB) |
|
47 |
, f_mem :: Int -- ^ free memory (MiB) |
|
48 |
, x_mem :: Int -- ^ unaccounted memory (MiB) |
|
49 |
, t_dsk :: Double -- ^ total disk space (MiB) |
|
50 |
, f_dsk :: Int -- ^ free disk space (MiB) |
|
51 |
, plist :: [T.Idx]-- ^ list of primary instance indices |
|
52 |
, slist :: [T.Idx]-- ^ list of secondary instance indices |
|
53 |
, idx :: T.Ndx -- ^ internal index for book-keeping |
|
54 |
, peers :: PeerMap.PeerMap -- ^ pnode to instance mapping |
|
55 |
, failN1:: Bool -- ^ whether the node has failed n1 |
|
56 |
, r_mem :: Int -- ^ maximum memory needed for |
|
44 |
-- * Type declarations |
|
45 |
|
|
46 |
-- | The node type. |
|
47 |
data Node = Node { name :: String -- ^ The node name |
|
48 |
, t_mem :: Double -- ^ Total memory (MiB) |
|
49 |
, n_mem :: Int -- ^ Node memory (MiB) |
|
50 |
, f_mem :: Int -- ^ Free memory (MiB) |
|
51 |
, x_mem :: Int -- ^ Unaccounted memory (MiB) |
|
52 |
, t_dsk :: Double -- ^ Total disk space (MiB) |
|
53 |
, f_dsk :: Int -- ^ Free disk space (MiB) |
|
54 |
, plist :: [T.Idx]-- ^ List of primary instance indices |
|
55 |
, slist :: [T.Idx]-- ^ List of secondary instance indices |
|
56 |
, idx :: T.Ndx -- ^ Internal index for book-keeping |
|
57 |
, peers :: PeerMap.PeerMap -- ^ Pnode to instance mapping |
|
58 |
, failN1:: Bool -- ^ Whether the node has failed n1 |
|
59 |
, r_mem :: Int -- ^ Maximum memory needed for |
|
57 | 60 |
-- failover by primaries of this node |
58 |
, p_mem :: Double -- ^ percent of free memory
|
|
59 |
, p_dsk :: Double -- ^ percent of free disk
|
|
60 |
, p_rem :: Double -- ^ percent of reserved memory
|
|
61 |
, offline :: Bool -- ^ whether the node should not be used
|
|
61 |
, p_mem :: Double -- ^ Percent of free memory
|
|
62 |
, p_dsk :: Double -- ^ Percent of free disk
|
|
63 |
, p_rem :: Double -- ^ Percent of reserved memory
|
|
64 |
, offline :: Bool -- ^ Whether the node should not be used
|
|
62 | 65 |
-- for allocations and skipped from |
63 | 66 |
-- score computations |
64 | 67 |
} deriving (Show) |
... | ... | |
69 | 72 |
setName = setName |
70 | 73 |
setIdx = setIdx |
71 | 74 |
|
72 |
-- | A simple name for the int, node association list |
|
75 |
-- | A simple name for the int, node association list.
|
|
73 | 76 |
type AssocList = [(T.Ndx, Node)] |
74 | 77 |
|
75 |
-- | A simple name for a node map |
|
78 |
-- | A simple name for a node map.
|
|
76 | 79 |
type List = Container.Container Node |
77 | 80 |
|
78 |
-- | Constant node index for a non-moveable instance |
|
81 |
-- | Constant node index for a non-moveable instance.
|
|
79 | 82 |
noSecondary :: T.Ndx |
80 | 83 |
noSecondary = -1 |
81 | 84 |
|
82 |
{- | Create a new node. |
|
83 |
|
|
84 |
The index and the peers maps are empty, and will be need to be update |
|
85 |
later via the 'setIdx' and 'buildPeers' functions. |
|
85 |
-- * Initialization functions |
|
86 | 86 |
|
87 |
-} |
|
87 |
-- | Create a new node. |
|
88 |
-- |
|
89 |
-- The index and the peers maps are empty, and will be need to be |
|
90 |
-- update later via the 'setIdx' and 'buildPeers' functions. |
|
88 | 91 |
create :: String -> Double -> Int -> Int -> Double -> Int -> Bool -> Node |
89 | 92 |
create name_init mem_t_init mem_n_init mem_f_init |
90 | 93 |
dsk_t_init dsk_f_init offline_init = |
... | ... | |
110 | 113 |
} |
111 | 114 |
|
112 | 115 |
-- | Changes the index. |
116 |
-- |
|
113 | 117 |
-- This is used only during the building of the data structures. |
114 | 118 |
setIdx :: Node -> T.Ndx -> Node |
115 | 119 |
setIdx t i = t {idx = i} |
116 | 120 |
|
117 |
-- | Changes the name |
|
121 |
-- | Changes the name. |
|
122 |
-- |
|
118 | 123 |
-- This is used only during the building of the data structures. |
124 |
setName :: Node -> String -> Node |
|
119 | 125 |
setName t s = t {name = s} |
120 | 126 |
|
121 |
-- | Sets the offline attribute |
|
127 |
-- | Sets the offline attribute.
|
|
122 | 128 |
setOffline :: Node -> Bool -> Node |
123 | 129 |
setOffline t val = t { offline = val } |
124 | 130 |
|
125 |
-- | Sets the unnaccounted memory |
|
131 |
-- | Sets the unnaccounted memory.
|
|
126 | 132 |
setXmem :: Node -> Int -> Node |
127 | 133 |
setXmem t val = t { x_mem = val } |
128 | 134 |
|
129 |
-- | Sets the free memory |
|
130 |
setFmem :: Node -> Int -> Node |
|
131 |
setFmem t new_mem = |
|
132 |
let new_n1 = computeFailN1 (r_mem t) new_mem (f_dsk t) |
|
133 |
new_mp = (fromIntegral new_mem) / (t_mem t) |
|
134 |
in |
|
135 |
t { f_mem = new_mem, failN1 = new_n1, p_mem = new_mp } |
|
136 |
|
|
137 |
-- | Given the rmem, free memory and disk, computes the failn1 status. |
|
138 |
computeFailN1 :: Int -> Int -> Int -> Bool |
|
139 |
computeFailN1 new_rmem new_mem new_dsk = |
|
140 |
new_mem <= new_rmem || new_dsk <= 0 |
|
141 |
|
|
142 |
-- | Given the new free memory and disk, fail if any of them is below zero. |
|
143 |
failHealth :: Int -> Int -> Bool |
|
144 |
failHealth new_mem new_dsk = new_mem <= 0 || new_dsk <= 0 |
|
145 |
|
|
146 | 135 |
-- | Computes the maximum reserved memory for peers from a peer map. |
147 | 136 |
computeMaxRes :: PeerMap.PeerMap -> PeerMap.Elem |
148 | 137 |
computeMaxRes new_peers = PeerMap.maxElem new_peers |
... | ... | |
160 | 149 |
new_prem = (fromIntegral new_rmem) / (t_mem t) |
161 | 150 |
in t {peers=pmap, failN1 = new_failN1, r_mem = new_rmem, p_rem = new_prem} |
162 | 151 |
|
152 |
-- | Assigns an instance to a node as primary without other updates. |
|
153 |
setPri :: Node -> T.Idx -> Node |
|
154 |
setPri t idx = t { plist = idx:(plist t) } |
|
155 |
|
|
156 |
-- | Assigns an instance to a node as secondary without other updates. |
|
157 |
setSec :: Node -> T.Idx -> Node |
|
158 |
setSec t idx = t { slist = idx:(slist t) } |
|
159 |
|
|
160 |
-- * Update functions |
|
161 |
|
|
162 |
-- | Sets the free memory. |
|
163 |
setFmem :: Node -> Int -> Node |
|
164 |
setFmem t new_mem = |
|
165 |
let new_n1 = computeFailN1 (r_mem t) new_mem (f_dsk t) |
|
166 |
new_mp = (fromIntegral new_mem) / (t_mem t) |
|
167 |
in |
|
168 |
t { f_mem = new_mem, failN1 = new_n1, p_mem = new_mp } |
|
169 |
|
|
170 |
-- | Given the rmem, free memory and disk, computes the failn1 status. |
|
171 |
computeFailN1 :: Int -> Int -> Int -> Bool |
|
172 |
computeFailN1 new_rmem new_mem new_dsk = |
|
173 |
new_mem <= new_rmem || new_dsk <= 0 |
|
174 |
|
|
175 |
-- | Given the new free memory and disk, fail if any of them is below zero. |
|
176 |
failHealth :: Int -> Int -> Bool |
|
177 |
failHealth new_mem new_dsk = new_mem <= 0 || new_dsk <= 0 |
|
178 |
|
|
163 | 179 |
-- | Removes a primary instance. |
164 | 180 |
removePri :: Node -> Instance.Instance -> Node |
165 | 181 |
removePri t inst = |
... | ... | |
236 | 252 |
r_mem = new_rmem, p_dsk = new_dp, |
237 | 253 |
p_rem = new_prem} |
238 | 254 |
|
239 |
-- | Add a primary instance to a node without other updates |
|
240 |
setPri :: Node -> T.Idx -> Node |
|
241 |
setPri t idx = t { plist = idx:(plist t) } |
|
242 |
|
|
243 |
-- | Add a secondary instance to a node without other updates |
|
244 |
setSec :: Node -> T.Idx -> Node |
|
245 |
setSec t idx = t { slist = idx:(slist t) } |
|
255 |
-- * Display functions |
|
246 | 256 |
|
247 | 257 |
-- | String converter for the node list functionality. |
248 | 258 |
list :: Int -> Node -> String |
Also available in: Unified diff