Commit 82437b28 authored by Michele Tartara's avatar Michele Tartara
Browse files

Add DCStatus data type for the data collectors



Also adds the DCStatusCode, part of DCStatus, and the addStatus
utility function for adding the "status" field to an already existing
JSValue.

The design document is updated to have the status codes sorted by increasing
seriousness.
Signed-off-by: default avatarMichele Tartara <mtartara@google.com>
Reviewed-by: default avatarBernardo Dal Seno <bdalseno@google.com>
parent 54c7dff7
......@@ -185,14 +185,14 @@ in its ``data`` section, at least the following field:
There is no need of external intervention.
``2``
The collector can determine that something is wrong and Ganeti has no
way to fix it autonomously. External intervention is required.
``4``
The collector has failed to understand whether the status is good or
bad. Further analysis is required. Interpret this status as a
potentially dangerous situation.
``4``
The collector can determine that something is wrong and Ganeti has no
way to fix it autonomously. External intervention is required.
``message``
A message to better explain the reason of the status.
The exact format of the message string is data collector dependent.
......
......@@ -26,9 +26,12 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-}
module Ganeti.DataCollectors.Types
( DCReport(..)
( addStatus
, DCCategory(..)
, DCKind(..)
, DCReport(..)
, DCStatus(..)
, DCStatusCode(..)
, DCVersion(..)
, buildReport
) where
......@@ -49,6 +52,27 @@ instance JSON DCCategory where
readJSON =
error "JSON read instance not implemented for type DCCategory"
-- | The possible status codes of a data collector.
data DCStatusCode = DCSCOk -- ^ Everything is OK
| DCSCTempBad -- ^ Bad, but being automatically fixed
| DCSCUnknown -- ^ Unable to determine the status
| DCSCBad -- ^ Bad. External intervention required
deriving (Show, Eq, Ord)
-- | The JSON instance for CollectorStatus.
instance JSON DCStatusCode where
showJSON DCSCOk = showJSON (0 :: Int)
showJSON DCSCTempBad = showJSON (1 :: Int)
showJSON DCSCUnknown = showJSON (2 :: Int)
showJSON DCSCBad = showJSON (4 :: Int)
readJSON = error "JSON read instance not implemented for type DCStatusCode"
-- | The status of a \"status reporting data collector\".
$(buildObject "DCStatus" "dcStatus"
[ simpleField "code" [t| DCStatusCode |]
, simpleField "message" [t| String |]
])
-- | The type representing the kind of the collector.
data DCKind = DCKPerf -- ^ Performance reporting collector
| DCKStatus -- ^ Status reporting collector
......@@ -81,6 +105,16 @@ $(buildObject "DCReport" "dcReport"
, simpleField "data" [t| JSValue |]
])
-- | Add the data collector status information to the JSON representation of
-- the collector data.
addStatus :: DCStatus -> JSValue -> JSValue
addStatus dcStatus (JSObject obj) =
makeObj $ ("status", showJSON dcStatus) : fromJSObject obj
addStatus dcStatus value = makeObj
[ ("status", showJSON dcStatus)
, ("data", value)
]
-- | 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
......
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