t_dsk, f_dsk,
t_cpu, u_cpu,
p_mem, p_dsk, p_rem, p_cpu,
+ m_dsk, m_cpu,
plist, slist, offline)
, List
-- * Constructor
, setFmem
, setPri
, setSec
+ , setMdsk
+ , setMcpu
, addCpus
-- * Instance (re)location
, removePri
, p_dsk :: Double -- ^ Percent of free disk
, p_rem :: Double -- ^ Percent of reserved memory
, p_cpu :: Double -- ^ Ratio of virtual to physical CPUs
+ , m_dsk :: Double -- ^ Minimum free disk ratio
+ , m_cpu :: Double -- ^ Max ratio of virt-to-phys CPUs
, offline :: Bool -- ^ Whether the node should not be used
-- for allocations and skipped from
-- score computations
noSecondary :: T.Ndx
noSecondary = -1
+-- | No limit value
+noLimit :: Double
+noLimit = -1
+
-- * Initialization functions
-- | Create a new node.
p_rem = 0,
p_cpu = 0,
offline = offline_init,
- x_mem = 0
+ x_mem = 0,
+ m_dsk = noLimit,
+ m_cpu = noLimit
}
-- | Changes the index.
setXmem :: Node -> Int -> Node
setXmem t val = t { x_mem = val }
+-- | Sets the max disk usage ratio
+setMdsk :: Node -> Double -> Node
+setMdsk t val = t { m_dsk = val }
+
+-- | Sets the max cpu usage ratio
+setMcpu :: Node -> Double -> Node
+setMcpu t val = t { m_cpu = val }
+
-- | Computes the maximum reserved memory for peers from a peer map.
computeMaxRes :: PeerMap.PeerMap -> PeerMap.Elem
computeMaxRes new_peers = PeerMap.maxElem new_peers
failHealth :: Int -> Int -> Bool
failHealth new_mem new_dsk = new_mem <= 0 || new_dsk <= 0
+-- | Given new limits, check if any of them are overtaken
+failLimits :: Node -> Double -> Double -> Bool
+failLimits t new_dsk new_cpu =
+ let l_dsk = m_dsk t
+ l_cpu = m_cpu t
+ in (l_dsk > new_dsk) || (l_cpu >= 0 && l_cpu < new_cpu)
+
-- | Removes a primary instance.
removePri :: Node -> Instance.Instance -> Node
removePri t inst =
new_failn1 = computeFailN1 (r_mem t) new_mem new_dsk
new_ucpu = (u_cpu t) + (Instance.vcpus inst)
new_pcpu = (fromIntegral new_ucpu) / (t_cpu t)
+ new_dp = (fromIntegral new_dsk) / (t_dsk t)
in
- if (failHealth new_mem new_dsk) || (new_failn1 && not (failN1 t)) then
+ if (failHealth new_mem new_dsk) || (new_failn1 && not (failN1 t)) ||
+ (failLimits t new_dp new_pcpu)
+ then
Nothing
else
let new_plist = iname:(plist t)
new_mp = (fromIntegral new_mem) / (t_mem t)
- new_dp = (fromIntegral new_dsk) / (t_dsk t)
in
Just t {plist = new_plist, f_mem = new_mem, f_dsk = new_dsk,
failN1 = new_failn1, p_mem = new_mp, p_dsk = new_dp,
new_peers = PeerMap.add pdx new_peem old_peers
new_rmem = max (r_mem t) new_peem
new_prem = (fromIntegral new_rmem) / (t_mem t)
- new_failn1 = computeFailN1 new_rmem old_mem new_dsk in
- if (failHealth old_mem new_dsk) || (new_failn1 && not (failN1 t)) then
- Nothing
- else
- let new_slist = iname:(slist t)
- new_dp = (fromIntegral new_dsk) / (t_dsk t)
- in
- Just t {slist = new_slist, f_dsk = new_dsk,
- peers = new_peers, failN1 = new_failn1,
- r_mem = new_rmem, p_dsk = new_dp,
- p_rem = new_prem}
+ new_failn1 = computeFailN1 new_rmem old_mem new_dsk
+ new_dp = (fromIntegral new_dsk) / (t_dsk t)
+ in if (failHealth old_mem new_dsk) || (new_failn1 && not (failN1 t)) ||
+ (failLimits t new_dp noLimit)
+ then
+ Nothing
+ else
+ let new_slist = iname:(slist t)
+ in
+ Just t {slist = new_slist, f_dsk = new_dsk,
+ peers = new_peers, failN1 = new_failn1,
+ r_mem = new_rmem, p_dsk = new_dp,
+ p_rem = new_prem}
-- * Display functions