+-- | Assigns an instance to a node as primary without other updates.
+setPri :: Node -> T.Idx -> Node
+setPri t idx = t { plist = idx:(plist t) }
+
+-- | Assigns an instance to a node as secondary without other updates.
+setSec :: Node -> T.Idx -> Node
+setSec t idx = t { slist = idx:(slist t) }
+
+-- | Add primary cpus to a node
+addCpus :: Node -> Int -> Node
+addCpus t count =
+ let new_count = (u_cpu t) + count
+ in t { u_cpu = new_count, p_cpu = (fromIntegral new_count) / (t_cpu t) }
+
+-- * Update functions
+
+-- | Sets the free memory.
+setFmem :: Node -> Int -> Node
+setFmem t new_mem =
+ let new_n1 = computeFailN1 (r_mem t) new_mem (f_dsk t)
+ new_mp = (fromIntegral new_mem) / (t_mem t)
+ in
+ t { f_mem = new_mem, failN1 = new_n1, p_mem = new_mp }
+
+-- | Given the rmem, free memory and disk, computes the failn1 status.
+computeFailN1 :: Int -> Int -> Int -> Bool
+computeFailN1 new_rmem new_mem new_dsk =
+ new_mem <= new_rmem || new_dsk <= 0
+
+-- | Given the new free memory and disk, fail if any of them is below zero.
+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)
+