diff --git a/src/Ganeti/DataCollectors/Drbd.hs b/src/Ganeti/DataCollectors/Drbd.hs index b81973061ba8d17020737b19378ad47014c84472..92f53eef28bf7d62c17d50ab4c4f7be11c68adde 100644 --- a/src/Ganeti/DataCollectors/Drbd.hs +++ b/src/Ganeti/DataCollectors/Drbd.hs @@ -28,6 +28,7 @@ module Ganeti.DataCollectors.Drbd , options , arguments , dcName + , dcVersion ) where @@ -67,6 +68,10 @@ defaultCharNum = 80*20 dcName :: String dcName = "drbd" +-- | The version of this data collector. +dcVersion :: DCVersion +dcVersion = DCVerBuiltin + -- | The version number for the data format of this data collector. dcFormatVersion :: Int dcFormatVersion = 1 @@ -119,7 +124,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 Nothing dcFormatVersion jsonData + buildReport dcName dcVersion dcFormatVersion jsonData -- | Main function. main :: Options -> [String] -> IO () diff --git a/src/Ganeti/DataCollectors/Types.hs b/src/Ganeti/DataCollectors/Types.hs index c423a47e6c63a38daab27936125400cec772a99e..acd2dbcb2020279cb8ee1ef63aec93e0fe86d117 100644 --- a/src/Ganeti/DataCollectors/Types.hs +++ b/src/Ganeti/DataCollectors/Types.hs @@ -6,7 +6,7 @@ {- -Copyright (C) 2012 Google Inc. +Copyright (C) 2012, 2013 Google Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -27,20 +27,29 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA module Ganeti.DataCollectors.Types ( DCReport(..) + , DCVersion(..) , buildReport ) where -import Data.Maybe import Text.JSON import Ganeti.Constants as C import Ganeti.THH import Ganeti.Utils (getCurrentTime) +-- | Type representing the version number of a data collector. +data DCVersion = DCVerBuiltin | DCVersion String deriving (Show, Eq) + +-- | The JSON instance for DCVersion. +instance JSON DCVersion where + showJSON DCVerBuiltin = showJSON C.builtinDataCollectorVersion + showJSON (DCVersion v) = showJSON v + readJSON = error "JSON read instance not implemented for type DCVersion" + -- | This is the format of the report produced by each data collector. $(buildObject "DCReport" "dcReport" [ simpleField "name" [t| String |] - , simpleField "version" [t| String |] + , simpleField "version" [t| DCVersion |] , simpleField "format_version" [t| Int |] , simpleField "timestamp" [t| Integer |] , simpleField "data" [t| JSValue |] @@ -50,9 +59,8 @@ $(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 -> Maybe String -> Int -> JSValue -> IO DCReport +buildReport :: String -> DCVersion -> Int -> JSValue -> IO DCReport buildReport name version format_version jsonData = do now <- getCurrentTime let timestamp = now * 1000000000 :: Integer - ver = fromMaybe C.builtinDataCollectorVersion version - return $ DCReport name ver format_version timestamp jsonData + return $ DCReport name version format_version timestamp jsonData