Skip to content
Snippets Groups Projects
Commit dd69cd3c authored by Michele Tartara's avatar Michele Tartara
Browse files

Factor out the mergeStatuses function


It will be used by multiple data collectors, not only the DRBD collector.

Signed-off-by: default avatarMichele Tartara <mtartara@google.com>
Reviewed-by: default avatarKlaus Aehlig <aehlig@google.com>
parent 42b50796
No related branches found
No related tags found
No related merge requests found
......@@ -137,17 +137,6 @@ computeStatus (DRBDStatus _ devInfos) =
(code, strList) = foldr mergeStatuses (DCSCOk, [""]) statuses
in DCStatus code $ intercalate "\n" strList
-- | Helper function for merging statuses.
mergeStatuses :: (DCStatusCode, String) -> (DCStatusCode, [String])
-> (DCStatusCode, [String])
mergeStatuses (newStat, newStr) (storedStat, storedStrs) =
let resStat = max newStat storedStat
resStrs =
if newStr == ""
then storedStrs
else storedStrs ++ [newStr]
in (resStat, resStrs)
-- | Compute the status of a DRBD device and its error message.
computeDevStatus :: DeviceInfo -> (DCStatusCode, String)
computeDevStatus (UnconfiguredDevice _) = (DCSCOk, "")
......
......@@ -34,6 +34,7 @@ module Ganeti.DataCollectors.Types
, DCStatusCode(..)
, DCVersion(..)
, buildReport
, mergeStatuses
) where
import Data.Char
......@@ -116,6 +117,17 @@ addStatus dcStatus value = makeObj
, ("data", value)
]
-- | Helper function for merging statuses.
mergeStatuses :: (DCStatusCode, String) -> (DCStatusCode, [String])
-> (DCStatusCode, [String])
mergeStatuses (newStat, newStr) (storedStat, storedStrs) =
let resStat = max newStat storedStat
resStrs =
if newStr == ""
then storedStrs
else storedStrs ++ [newStr]
in (resStat, resStrs)
-- | Utility function for building a report automatically adding the current
-- timestamp (rounded up to seconds).
-- If the version is not specified, it will be set to the value indicating
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment