Hi!

On Wed, Apr 24, 2013 at 1:03 PM, Michele Tartara <[email protected]>wrote:

> Implement the handler for outputting the list of collectors
> (name, category, kind) in JSON format.
>
> Signed-off-by: Michele Tartara <[email protected]>
> ---
>  src/Ganeti/Monitoring/Server.hs |   29 +++++++++++++++++++++++++++--
>  1 file changed, 27 insertions(+), 2 deletions(-)
>
> diff --git a/src/Ganeti/Monitoring/Server.hs
> b/src/Ganeti/Monitoring/Server.hs
> index fc9174e..8c080c7 100644
> --- a/src/Ganeti/Monitoring/Server.hs
> +++ b/src/Ganeti/Monitoring/Server.hs
> @@ -35,10 +35,12 @@ import Control.Applicative
>  import Control.Monad
>  import Snap.Core
>  import Snap.Http.Server
> -import Data.ByteString.Char8
> +import Data.ByteString.Char8 hiding (map)
>  import qualified Text.JSON as J
>
>  import Ganeti.Daemon
> +import qualified Ganeti.DataCollectors.Drbd as Drbd
> +import Ganeti.DataCollectors.Types
>  import qualified Ganeti.Constants as C
>
>  -- * Types and constants definitions
> @@ -53,6 +55,19 @@ type PrepResult = Config Snap ()
>  latestAPIVersion :: Int
>  latestAPIVersion = 1
>
> +data DataCollector = DataCollector
> +  { dName     :: String
> +  , dCategory :: Maybe DCCategory
> +  , dKind     :: DCKind
> +  }
>

Please add some comment what is captured by "category" and "kind" (maybe
with examples) since those variable names are rather general.


> +
> +-- | The list of available builtin data collectors.
> +collectors :: [DataCollector]
> +collectors =
> +  [ DataCollector Drbd.dcName Drbd.dcCategory Drbd.dcKind
> +  ]
> +
> +
>  -- * Configuration handling
>
>  -- | The default configuration for the HTTP server.
> @@ -93,10 +108,20 @@ version1Api =
>         , ("report", reportHandler)
>         ]
>
> +-- | Get the JSON representation of a data collector to be used in the
> collector
> +-- list.
> +dcListItem :: DataCollector -> J.JSValue
> +dcListItem dc =
> +  J.JSArray
> +    [ J.showJSON $ dName dc
> +    , maybe J.JSNull J.showJSON $ dCategory dc
> +    , J.showJSON $ dKind dc
> +    ]
> +
>  -- | Handler for returning lists.
>  listHandler :: Snap ()
>  listHandler =
> -  dir "collectors" $ writeText "TODO: return the list of collectors"
> +  dir "collectors" . writeBS . pack . J.encode $ map dcListItem collectors
>
>  -- | Handler for returning data collector reports.
>  reportHandler :: Snap ()
> --
> 1.7.10.4
>
>
LGTM, thanks.

Cheers,
Helga

Reply via email to