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

Some small style fixes

parent 8c9af2f0
......@@ -48,13 +48,11 @@ data Instance = Instance { name :: String -- ^ The instance name
, mem :: Int -- ^ Memory of the instance
, dsk :: Int -- ^ Disk size of instance
, vcpus :: Int -- ^ Number of VCPUs
, running :: Bool -- ^ Whether the instance
-- is running
, running :: Bool -- ^ Is the instance running?
, runSt :: String -- ^ Original (text) run status
, pNode :: T.Ndx -- ^ Original primary node
, sNode :: T.Ndx -- ^ Original secondary node
, idx :: T.Idx -- ^ Internal index for
-- book-keeping
, idx :: T.Idx -- ^ Internal index
, util :: T.DynUtil -- ^ Dynamic resource usage
} deriving (Show)
......@@ -82,10 +80,7 @@ create name_init mem_init dsk_init vcpus_init run_init pn sn =
, mem = mem_init
, dsk = dsk_init
, vcpus = vcpus_init
, running = case run_init of
"running" -> True
"ERROR_up" -> True
_ -> False
, running = run_init == "running" || run_init == "ERROR_up"
, runSt = run_init
, pNode = pn
, sNode = sn
......
......@@ -67,7 +67,7 @@ import qualified Ganeti.HTools.Types as T
-- * Type declarations
-- | The node type.
data Node = Node { name :: String -- ^ The node name
data Node = Node { name :: String -- ^ The node name
, tMem :: Double -- ^ Total memory (MiB)
, nMem :: Int -- ^ Node memory (MiB)
, fMem :: Int -- ^ Free memory (MiB)
......@@ -80,7 +80,7 @@ data Node = Node { name :: String -- ^ The node name
, sList :: [T.Idx]-- ^ List of secondary instance indices
, idx :: T.Ndx -- ^ Internal index for book-keeping
, peers :: PeerMap.PeerMap -- ^ Pnode to instance mapping
, failN1:: Bool -- ^ Whether the node has failed n1
, failN1 :: Bool -- ^ Whether the node has failed n1
, rMem :: Int -- ^ Maximum memory needed for
-- failover by primaries of this node
, pMem :: Double -- ^ Percent of free memory
......@@ -235,8 +235,7 @@ setFmem :: Node -> Int -> Node
setFmem t new_mem =
let new_n1 = new_mem <= rMem t
new_mp = fromIntegral new_mem / tMem t
in
t { fMem = new_mem, failN1 = new_n1, pMem = new_mp }
in t { fMem = new_mem, failN1 = new_n1, pMem = new_mp }
-- | Removes a primary instance.
removePri :: Node -> Instance.Instance -> Node
......@@ -251,9 +250,9 @@ removePri t inst =
new_ucpu = uCpu t - Instance.vcpus inst
new_rcpu = fromIntegral new_ucpu / tCpu t
new_load = utilLoad t `T.subUtil` Instance.util inst
in t {pList = new_plist, fMem = new_mem, fDsk = new_dsk,
failN1 = new_failn1, pMem = new_mp, pDsk = new_dp,
uCpu = new_ucpu, pCpu = new_rcpu, utilLoad = new_load}
in t { pList = new_plist, fMem = new_mem, fDsk = new_dsk
, failN1 = new_failn1, pMem = new_mp, pDsk = new_dp
, uCpu = new_ucpu, pCpu = new_rcpu, utilLoad = new_load }
-- | Removes a secondary instance.
removeSec :: Node -> Instance.Instance -> Node
......@@ -267,19 +266,18 @@ removeSec t inst =
new_peem = old_peem - Instance.mem inst
new_peers = PeerMap.add pnode new_peem old_peers
old_rmem = rMem t
new_rmem = if old_peem < old_rmem then
old_rmem
else
computeMaxRes new_peers
new_rmem = if old_peem < old_rmem
then old_rmem
else computeMaxRes new_peers
new_prem = fromIntegral new_rmem / tMem t
new_failn1 = fMem t <= new_rmem
new_dp = fromIntegral new_dsk / tDsk t
old_load = utilLoad t
new_load = old_load { T.dskWeight = T.dskWeight old_load -
T.dskWeight (Instance.util inst) }
in t {sList = new_slist, fDsk = new_dsk, peers = new_peers,
failN1 = new_failn1, rMem = new_rmem, pDsk = new_dp,
pRem = new_prem, utilLoad = new_load}
in t { sList = new_slist, fDsk = new_dsk, peers = new_peers
, failN1 = new_failn1, rMem = new_rmem, pDsk = new_dp
, pRem = new_prem, utilLoad = new_load }
-- | Adds a primary instance.
addPri :: Node -> Instance.Instance -> T.OpResult Node
......@@ -300,9 +298,9 @@ addPri t inst =
else
let new_plist = iname:pList t
new_mp = fromIntegral new_mem / tMem t
r = t { pList = new_plist, fMem = new_mem, fDsk = new_dsk,
failN1 = new_failn1, pMem = new_mp, pDsk = new_dp,
uCpu = new_ucpu, pCpu = new_pcpu, utilLoad = new_load }
r = t { pList = new_plist, fMem = new_mem, fDsk = new_dsk
, failN1 = new_failn1, pMem = new_mp, pDsk = new_dp
, uCpu = new_ucpu, pCpu = new_pcpu, utilLoad = new_load }
in T.OpGood r
-- | Adds a secondary instance.
......@@ -324,11 +322,11 @@ addSec t inst pdx =
in if new_dsk <= 0 || mDsk t > new_dp then T.OpFail T.FailDisk
else if new_failn1 && not (failN1 t) then T.OpFail T.FailMem
else let new_slist = iname:sList t
r = t { sList = new_slist, fDsk = new_dsk,
peers = new_peers, failN1 = new_failn1,
rMem = new_rmem, pDsk = new_dp,
pRem = new_prem, utilLoad = new_load }
in T.OpGood r
r = t { sList = new_slist, fDsk = new_dsk
, peers = new_peers, failN1 = new_failn1
, rMem = new_rmem, pDsk = new_dp
, pRem = new_prem, utilLoad = new_load }
in T.OpGood r
-- * Stats functions
......
......@@ -64,20 +64,16 @@ pmCompare a b = (compare `on` snd) b a
-- | Add or update (via a custom function) an element.
addWith :: (Elem -> Elem -> Elem) -> Key -> Elem -> PeerMap -> PeerMap
addWith fn k v lst =
let r = lookup k lst
in
case r of
Nothing -> insertBy pmCompare (k, v) lst
Just o -> insertBy pmCompare (k, fn o v) (remove k lst)
case lookup k lst of
Nothing -> insertBy pmCompare (k, v) lst
Just o -> insertBy pmCompare (k, fn o v) (remove k lst)
-- | Create a PeerMap from an association list, with possible duplicates
accumArray :: (Elem -> Elem -> Elem) -- ^ function used to merge the elements
-> [(Key, Elem)] -- ^ source data
-> PeerMap -- ^ results
accumArray fn lst =
case lst of
[] -> empty
(k, v):xs -> addWith fn k v $ accumArray fn xs
accumArray _ [] = empty
accumArray fn ((k, v):xs) = addWith fn k v $ accumArray fn xs
-- * Basic operations
......@@ -91,9 +87,9 @@ add = addWith (flip const)
-- | Remove an element from a peermap
remove :: Key -> PeerMap -> PeerMap
remove k c = case c of
[] -> []
(x@(x', _)):xs -> if k == x' then xs
remove _ [] = []
remove k ((x@(x', _)):xs) = if k == x'
then xs
else x:remove k xs
-- | Find the maximum element.
......@@ -101,4 +97,5 @@ remove k c = case c of
-- Since this is a sorted list, we just get the value at the head of
-- the list, or zero for a null list
maxElem :: PeerMap -> Elem
maxElem c = if null c then 0 else snd . head $ c
maxElem (x:_) = snd x
maxElem _ = 0
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