Commit 07423850 authored by Klaus Aehlig's avatar Klaus Aehlig
Browse files

Instance JSON LockRequest



...as pending requests need to be serialized when serializing
lock waiting structures.
Signed-off-by: default avatarKlaus Aehlig <aehlig@google.com>
Reviewed-by: default avatarPetr Pudlak <pudlak@google.com>
parent f8d6da22
......@@ -44,7 +44,7 @@ module Ganeti.Locking.Allocation
, opportunisticLockUnion
) where
import Control.Applicative (liftA2, (<$>), (<*>))
import Control.Applicative (liftA2, (<$>), (<*>), pure)
import Control.Arrow (second, (***))
import Control.Monad
import Data.Foldable (for_, find)
......@@ -156,6 +156,18 @@ data LockRequest a = LockRequest { lockAffected :: a
}
deriving (Eq, Show, Ord)
instance J.JSON a => J.JSON (LockRequest a) where
showJSON (LockRequest a Nothing) = J.showJSON (a, "release")
showJSON (LockRequest a (Just OwnShared)) = J.showJSON (a, "shared")
showJSON (LockRequest a (Just OwnExclusive)) = J.showJSON (a, "exclusive")
readJSON (J.JSArray [a, J.JSString tp]) =
case J.fromJSString tp of
"release" -> LockRequest <$> J.readJSON a <*> pure Nothing
"shared" -> LockRequest <$> J.readJSON a <*> pure (Just OwnShared)
"exclusive" -> LockRequest <$> J.readJSON a <*> pure (Just OwnExclusive)
_ -> J.Error $ "malformed request type: " ++ J.fromJSString tp
readJSON x = J.Error $ "malformed lock request: " ++ show x
-- | Lock request for an exclusive lock.
requestExclusive :: a -> LockRequest a
requestExclusive lock = LockRequest { lockAffected = lock
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment