From f0e4b2a48888f222ca9d9e160d4e5f08a700158a Mon Sep 17 00:00:00 2001 From: Michele Tartara <mtartara@google.com> Date: Thu, 14 Mar 2013 12:39:23 +0000 Subject: [PATCH] Add data type for data collector category Also, update the DRBD data collector to use and export it. Signed-off-by: Michele Tartara <mtartara@google.com> Reviewed-by: Bernardo Dal Seno <bdalseno@google.com> --- src/Ganeti/DataCollectors/Drbd.hs | 7 ++++++- src/Ganeti/DataCollectors/Types.hs | 20 +++++++++++++++++--- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/Ganeti/DataCollectors/Drbd.hs b/src/Ganeti/DataCollectors/Drbd.hs index 5f5079340..805c7e157 100644 --- a/src/Ganeti/DataCollectors/Drbd.hs +++ b/src/Ganeti/DataCollectors/Drbd.hs @@ -30,6 +30,7 @@ module Ganeti.DataCollectors.Drbd , dcName , dcVersion , dcFormatVersion + , dcCategory ) where @@ -77,6 +78,10 @@ dcVersion = DCVerBuiltin dcFormatVersion :: Int dcFormatVersion = 1 +-- | The category of this data collector. +dcCategory :: Maybe DCCategory +dcCategory = Just DCStorage + -- * Command line options options :: IO [OptType] @@ -125,7 +130,7 @@ buildDRBDReport statusFile pairingFile = do show (Prelude.take defaultCharNum $ unpack unparsedText) ++ "\n" ++ show contexts ++ "\n" ++ errorMessage A.Done _ drbdStatus -> return $ J.showJSON drbdStatus - buildReport dcName dcVersion dcFormatVersion jsonData + buildReport dcName dcVersion dcFormatVersion dcCategory jsonData -- | Main function. main :: Options -> [String] -> IO () diff --git a/src/Ganeti/DataCollectors/Types.hs b/src/Ganeti/DataCollectors/Types.hs index acd2dbcb2..ed1854682 100644 --- a/src/Ganeti/DataCollectors/Types.hs +++ b/src/Ganeti/DataCollectors/Types.hs @@ -27,6 +27,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA module Ganeti.DataCollectors.Types ( DCReport(..) + , DCCategory(..) , DCVersion(..) , buildReport ) where @@ -37,6 +38,16 @@ import Ganeti.Constants as C import Ganeti.THH import Ganeti.Utils (getCurrentTime) +-- | The possible classes a data collector can belong to. +data DCCategory = DCInstance | DCStorage | DCDaemon | DCHypervisor + deriving (Show, Eq) + +-- | The JSON instance for DCCategory. +instance JSON DCCategory where + showJSON = showJSON . show + readJSON = + error "JSON read instance not implemented for type DCCategory" + -- | Type representing the version number of a data collector. data DCVersion = DCVerBuiltin | DCVersion String deriving (Show, Eq) @@ -52,6 +63,8 @@ $(buildObject "DCReport" "dcReport" , simpleField "version" [t| DCVersion |] , simpleField "format_version" [t| Int |] , simpleField "timestamp" [t| Integer |] + , optionalNullSerField $ + simpleField "category" [t| DCCategory |] , simpleField "data" [t| JSValue |] ]) @@ -59,8 +72,9 @@ $(buildObject "DCReport" "dcReport" -- timestamp (rounded up to seconds). -- If the version is not specified, it will be set to the value indicating -- a builtin collector. -buildReport :: String -> DCVersion -> Int -> JSValue -> IO DCReport -buildReport name version format_version jsonData = do +buildReport :: String -> DCVersion -> Int -> Maybe DCCategory -> JSValue + -> IO DCReport +buildReport name version format_version category jsonData = do now <- getCurrentTime let timestamp = now * 1000000000 :: Integer - return $ DCReport name version format_version timestamp jsonData + return $ DCReport name version format_version timestamp category jsonData -- GitLab