Revision a895fa19 src/Ganeti/DataCollectors/Types.hs
b/src/Ganeti/DataCollectors/Types.hs | ||
---|---|---|
6 | 6 |
|
7 | 7 |
{- |
8 | 8 |
|
9 |
Copyright (C) 2012 Google Inc. |
|
9 |
Copyright (C) 2012, 2013 Google Inc.
|
|
10 | 10 |
|
11 | 11 |
This program is free software; you can redistribute it and/or modify |
12 | 12 |
it under the terms of the GNU General Public License as published by |
... | ... | |
27 | 27 |
|
28 | 28 |
module Ganeti.DataCollectors.Types |
29 | 29 |
( DCReport(..) |
30 |
, DCVersion(..) |
|
30 | 31 |
, buildReport |
31 | 32 |
) where |
32 | 33 |
|
33 |
import Data.Maybe |
|
34 | 34 |
import Text.JSON |
35 | 35 |
|
36 | 36 |
import Ganeti.Constants as C |
37 | 37 |
import Ganeti.THH |
38 | 38 |
import Ganeti.Utils (getCurrentTime) |
39 | 39 |
|
40 |
-- | Type representing the version number of a data collector. |
|
41 |
data DCVersion = DCVerBuiltin | DCVersion String deriving (Show, Eq) |
|
42 |
|
|
43 |
-- | The JSON instance for DCVersion. |
|
44 |
instance JSON DCVersion where |
|
45 |
showJSON DCVerBuiltin = showJSON C.builtinDataCollectorVersion |
|
46 |
showJSON (DCVersion v) = showJSON v |
|
47 |
readJSON = error "JSON read instance not implemented for type DCVersion" |
|
48 |
|
|
40 | 49 |
-- | This is the format of the report produced by each data collector. |
41 | 50 |
$(buildObject "DCReport" "dcReport" |
42 | 51 |
[ simpleField "name" [t| String |] |
43 |
, simpleField "version" [t| String |]
|
|
52 |
, simpleField "version" [t| DCVersion |]
|
|
44 | 53 |
, simpleField "format_version" [t| Int |] |
45 | 54 |
, simpleField "timestamp" [t| Integer |] |
46 | 55 |
, simpleField "data" [t| JSValue |] |
... | ... | |
50 | 59 |
-- timestamp (rounded up to seconds). |
51 | 60 |
-- If the version is not specified, it will be set to the value indicating |
52 | 61 |
-- a builtin collector. |
53 |
buildReport :: String -> Maybe String -> Int -> JSValue -> IO DCReport
|
|
62 |
buildReport :: String -> DCVersion -> Int -> JSValue -> IO DCReport
|
|
54 | 63 |
buildReport name version format_version jsonData = do |
55 | 64 |
now <- getCurrentTime |
56 | 65 |
let timestamp = now * 1000000000 :: Integer |
57 |
ver = fromMaybe C.builtinDataCollectorVersion version |
|
58 |
return $ DCReport name ver format_version timestamp jsonData |
|
66 |
return $ DCReport name version format_version timestamp jsonData |
Also available in: Unified diff