LGTM, thanks!

On Wed, Apr 2, 2014 at 11:11 AM, Jose A. Lopes <[email protected]> wrote:

> Currently, the metadata daemon is mainly a web server.  However, a new
> configuration server will be introduced along with other metadata
> related modules.  Therefore, this patch moves the current metadata
> daemon web server to its own directory.  This module is also renamed
> from 'Server' to 'WebServer'.
>
> Signed-off-by: Jose A. Lopes <[email protected]>
> ---
>  Makefile.am                   |  3 +-
>  src/Ganeti/Metad.hs           | 94
> -------------------------------------------
>  src/Ganeti/Metad/WebServer.hs | 94
> +++++++++++++++++++++++++++++++++++++++++++
>  src/ganeti-metad.hs           |  4 +-
>  4 files changed, 98 insertions(+), 97 deletions(-)
>  delete mode 100644 src/Ganeti/Metad.hs
>  create mode 100644 src/Ganeti/Metad/WebServer.hs
>
> diff --git a/Makefile.am b/Makefile.am
> index 5deaffb..64fa6a0 100644
> --- a/Makefile.am
> +++ b/Makefile.am
> @@ -129,6 +129,7 @@ HS_DIRS = \
>         src/Ganeti/Locking \
>         src/Ganeti/Logging \
>         src/Ganeti/Monitoring \
> +       src/Ganeti/Metad \
>         src/Ganeti/Objects \
>         src/Ganeti/Query \
>         src/Ganeti/Storage \
> @@ -772,8 +773,8 @@ HS_LIB_SRCS = \
>         src/Ganeti/Logging.hs \
>         src/Ganeti/Logging/Lifted.hs \
>         src/Ganeti/Luxi.hs \
> +       src/Ganeti/Metad/WebServer.hs \
>         src/Ganeti/Monitoring/Server.hs \
> -       src/Ganeti/Metad.hs \
>         src/Ganeti/Network.hs \
>         src/Ganeti/Objects.hs \
>         src/Ganeti/Objects/Lens.hs \
> diff --git a/src/Ganeti/Metad.hs b/src/Ganeti/Metad.hs
> deleted file mode 100644
> index 535d9a0..0000000
> --- a/src/Ganeti/Metad.hs
> +++ /dev/null
> @@ -1,94 +0,0 @@
> -{-| Metadata daemon
> -
> --}
> -
> -{-
> -
> -Copyright (C) 2014 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
> -the Free Software Foundation; either version 2 of the License, or
> -(at your option) any later version.
> -
> -This program is distributed in the hope that it will be useful, but
> -WITHOUT ANY WARRANTY; without even the implied warranty of
> -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> -General Public License for more details.
> -
> -You should have received a copy of the GNU General Public License
> -along with this program; if not, write to the Free Software
> -Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
> -02110-1301, USA.
> -
> --}
> -
> -module Ganeti.Metad (start) where
> -
> -import Control.Applicative
> -import Control.Monad.IO.Class (liftIO)
> -import qualified Data.ByteString.Char8 as ByteString (pack, unpack)
> -import Snap.Core
> -import Snap.Http.Server
> -
> -import Ganeti.Daemon
> -import qualified Ganeti.Constants as Constants
> -import qualified Ganeti.Logging as Logging
> -import Ganeti.Runtime (GanetiDaemon(..), ExtraLogReason(..))
> -import qualified Ganeti.Runtime as Runtime
> -
> -type MetaM = Snap ()
> -
> -error404 :: MetaM
> -error404 = do
> -  modifyResponse . setResponseStatus 404 $ ByteString.pack "Not found"
> -  writeBS $ ByteString.pack "Resource not found"
> -
> -handleMetadata :: Method -> String -> String -> String -> MetaM
> -handleMetadata GET  "ganeti" "latest" "meta_data.json" =
> -  liftIO $ Logging.logInfo "ganeti metadata"
> -handleMetadata GET  "ganeti" "latest" "os/parameters.json" =
> -  liftIO $ Logging.logInfo "ganeti OS parameters"
> -handleMetadata GET  "ganeti" "latest" "read" =
> -  liftIO $ Logging.logInfo "ganeti READ"
> -handleMetadata POST "ganeti" "latest" "write" =
> -  liftIO $ Logging.logInfo "ganeti WRITE"
> -handleMetadata _ _ _ _ = error404
> -
> -routeMetadata :: MetaM
> -routeMetadata =
> -  route [ (providerRoute1, dispatchMetadata)
> -        , (providerRoute2, dispatchMetadata)
> -        ] <|> dispatchMetadata
> -  where provider = "provider"
> -        version  = "version"
> -
> -        providerRoute1 = ByteString.pack $ ':':provider ++ "/" ++
> ':':version
> -        providerRoute2 = ByteString.pack $ ':':version
> -
> -        getParamString :: String -> Snap String
> -        getParamString =
> -          fmap (maybe "" ByteString.unpack) . getParam . ByteString.pack
> -
> -        dispatchMetadata =
> -          do m <- rqMethod <$> getRequest
> -             p <- getParamString provider
> -             v <- getParamString version
> -             r <- ByteString.unpack . rqPathInfo <$> getRequest
> -             handleMetadata m p v r
> -
> -defaultHttpConf :: DaemonOptions -> FilePath -> FilePath -> Config Snap ()
> -defaultHttpConf opts accessLog errorLog =
> -  maybe id (setBind . ByteString.pack) (optBindAddress opts) .
> -  setAccessLog (ConfigFileLog accessLog) .
> -  setCompression False .
> -  setErrorLog (ConfigFileLog errorLog) .
> -  setPort (maybe Constants.defaultMetadPort fromIntegral (optPort opts)) .
> -  setVerbose False $
> -  emptyConfig
> -
> -start :: DaemonOptions -> IO ()
> -start opts = do
> -  accessLog <- Runtime.daemonsExtraLogFile GanetiMetad AccessLog
> -  errorLog <- Runtime.daemonsExtraLogFile GanetiMetad ErrorLog
> -  httpServe (defaultHttpConf opts accessLog errorLog) routeMetadata
> diff --git a/src/Ganeti/Metad/WebServer.hs b/src/Ganeti/Metad/WebServer.hs
> new file mode 100644
> index 0000000..1758fc9
> --- /dev/null
> +++ b/src/Ganeti/Metad/WebServer.hs
> @@ -0,0 +1,94 @@
> +{-| Metadata daemon
> +
> +-}
> +
> +{-
> +
> +Copyright (C) 2014 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
> +the Free Software Foundation; either version 2 of the License, or
> +(at your option) any later version.
> +
> +This program is distributed in the hope that it will be useful, but
> +WITHOUT ANY WARRANTY; without even the implied warranty of
> +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> +General Public License for more details.
> +
> +You should have received a copy of the GNU General Public License
> +along with this program; if not, write to the Free Software
> +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
> +02110-1301, USA.
> +
> +-}
> +
> +module Ganeti.Metad.WebServer (start) where
> +
> +import Control.Applicative
> +import Control.Monad.IO.Class (liftIO)
> +import qualified Data.ByteString.Char8 as ByteString (pack, unpack)
> +import Snap.Core
> +import Snap.Http.Server
> +
> +import Ganeti.Daemon
> +import qualified Ganeti.Constants as Constants
> +import qualified Ganeti.Logging as Logging
> +import Ganeti.Runtime (GanetiDaemon(..), ExtraLogReason(..))
> +import qualified Ganeti.Runtime as Runtime
> +
> +type MetaM = Snap ()
> +
> +error404 :: MetaM
> +error404 = do
> +  modifyResponse . setResponseStatus 404 $ ByteString.pack "Not found"
> +  writeBS $ ByteString.pack "Resource not found"
> +
> +handleMetadata :: Method -> String -> String -> String -> MetaM
> +handleMetadata GET  "ganeti" "latest" "meta_data.json" =
> +  liftIO $ Logging.logInfo "ganeti metadata"
> +handleMetadata GET  "ganeti" "latest" "os/parameters.json" =
> +  liftIO $ Logging.logInfo "ganeti OS parameters"
> +handleMetadata GET  "ganeti" "latest" "read" =
> +  liftIO $ Logging.logInfo "ganeti READ"
> +handleMetadata POST "ganeti" "latest" "write" =
> +  liftIO $ Logging.logInfo "ganeti WRITE"
> +handleMetadata _ _ _ _ = error404
> +
> +routeMetadata :: MetaM
> +routeMetadata =
> +  route [ (providerRoute1, dispatchMetadata)
> +        , (providerRoute2, dispatchMetadata)
> +        ] <|> dispatchMetadata
> +  where provider = "provider"
> +        version  = "version"
> +
> +        providerRoute1 = ByteString.pack $ ':':provider ++ "/" ++
> ':':version
> +        providerRoute2 = ByteString.pack $ ':':version
> +
> +        getParamString :: String -> Snap String
> +        getParamString =
> +          fmap (maybe "" ByteString.unpack) . getParam . ByteString.pack
> +
> +        dispatchMetadata =
> +          do m <- rqMethod <$> getRequest
> +             p <- getParamString provider
> +             v <- getParamString version
> +             r <- ByteString.unpack . rqPathInfo <$> getRequest
> +             handleMetadata m p v r
> +
> +defaultHttpConf :: DaemonOptions -> FilePath -> FilePath -> Config Snap ()
> +defaultHttpConf opts accessLog errorLog =
> +  maybe id (setBind . ByteString.pack) (optBindAddress opts) .
> +  setAccessLog (ConfigFileLog accessLog) .
> +  setCompression False .
> +  setErrorLog (ConfigFileLog errorLog) .
> +  setPort (maybe Constants.defaultMetadPort fromIntegral (optPort opts)) .
> +  setVerbose False $
> +  emptyConfig
> +
> +start :: DaemonOptions -> IO ()
> +start opts = do
> +  accessLog <- Runtime.daemonsExtraLogFile GanetiMetad AccessLog
> +  errorLog <- Runtime.daemonsExtraLogFile GanetiMetad ErrorLog
> +  httpServe (defaultHttpConf opts accessLog errorLog) routeMetadata
> diff --git a/src/ganeti-metad.hs b/src/ganeti-metad.hs
> index 28529b6..d38287a 100644
> --- a/src/ganeti-metad.hs
> +++ b/src/ganeti-metad.hs
> @@ -28,7 +28,7 @@ module Main (main) where
>  import qualified Ganeti.Constants as Constants
>  import Ganeti.Daemon (OptType)
>  import qualified Ganeti.Daemon as Daemon
> -import qualified Ganeti.Metad as Metad
> +import qualified Ganeti.Metad.WebServer as WebServer
>  import qualified Ganeti.Runtime as Runtime
>
>  options :: [OptType]
> @@ -45,4 +45,4 @@ main =
>    Daemon.genericMain Runtime.GanetiMetad options
>      (\_ -> return . Right $ ())
>      (\_ _ -> return ())
> -    (\opts _ _ -> Metad.start opts)
> +    (\opts _ _ -> WebServer.start opts)
> --
> 1.9.1.423.g4596e3a
>
>

Reply via email to