LGTM

On Mon, Mar 3, 2014 at 2:48 PM, Klaus Aehlig <[email protected]> wrote:

> Add a module describing how abstract requests, like lock requests are
> passed over the wire to WConfD.
>
> Signed-off-by: Klaus Aehlig <[email protected]>
> ---
>  Makefile.am                   |  1 +
>  src/Ganeti/WConfd/Language.hs | 67
> +++++++++++++++++++++++++++++++++++++++++++
>  2 files changed, 68 insertions(+)
>  create mode 100644 src/Ganeti/WConfd/Language.hs
>
> diff --git a/Makefile.am b/Makefile.am
> index cc76bc2..064a1c3 100644
> --- a/Makefile.am
> +++ b/Makefile.am
> @@ -814,6 +814,7 @@ HS_LIB_SRCS = \
>         src/Ganeti/WConfd/ConfigState.hs \
>         src/Ganeti/WConfd/ConfigWriter.hs \
>         src/Ganeti/WConfd/Core.hs \
> +       src/Ganeti/WConfd/Language.hs \
>         src/Ganeti/WConfd/Monad.hs \
>         src/Ganeti/WConfd/Server.hs
>
> diff --git a/src/Ganeti/WConfd/Language.hs b/src/Ganeti/WConfd/Language.hs
> new file mode 100644
> index 0000000..f609e79
> --- /dev/null
> +++ b/src/Ganeti/WConfd/Language.hs
> @@ -0,0 +1,67 @@
> +{-| Function related to serialisation of WConfD requests
> +
> +-}
> +
> +{-
> +
> +Copyright (C) 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
> +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.WConfd.Language
> +  ( LockRequestType(..)
> +  , GanetiLockRequest
> +  , fromGanetiLockRequest
> +  ) where
> +
> +import qualified Text.JSON as J
> +
> +import Ganeti.Locking.Allocation
> +import Ganeti.Locking.Locks (GanetiLocks)
> +
> +-- * Serialisation related to locking
> +
> +-- | Operation to be carried out on a lock (request exclusive/shared
> ownership,
> +-- or release).
> +data LockRequestType = ReqExclusive | ReqShared | ReqRelease deriving
> (Eq, Show)
> +
> +instance J.JSON LockRequestType where
> +  showJSON ReqExclusive = J.showJSON "exclusive"
> +  showJSON ReqShared = J.showJSON "shared"
> +  showJSON ReqRelease = J.showJSON "release"
> +  readJSON (J.JSString x) = let s = J.fromJSString x
> +                            in case s of
> +                              "exclusive" -> J.Ok ReqExclusive
> +                              "shared" -> J.Ok ReqShared
> +                              "release" -> J.Ok ReqRelease
> +                              _ -> J.Error $ "Unknown lock update request
> " ++ s
> +  readJSON _ = J.Error "Update requests need to be strings"
> +
> +-- | The type describing how lock update requests are passed over the
> wire.
> +type GanetiLockRequest = [(GanetiLocks, LockRequestType)]
> +
> +-- | Transform a Lock LockReqeustType pair into a LockRequest.
> +toLockRequest :: (GanetiLocks, LockRequestType) -> LockRequest GanetiLocks
> +toLockRequest (a, ReqExclusive) = requestExclusive a
> +toLockRequest (a, ReqShared) = requestShared a
> +toLockRequest (a, ReqRelease) = requestRelease a
> +
> +-- | From a GanetiLockRequest obtain a list of
> +-- Ganeti.Lock.Allocation.LockRequest, suitable to updateLocks.
> +fromGanetiLockRequest :: GanetiLockRequest -> [LockRequest GanetiLocks]
> +fromGanetiLockRequest = map toLockRequest
> --
> 1.9.0.279.gdc9e3eb
>
>

Reply via email to