Revision 07423850

b/src/Ganeti/Locking/Allocation.hs
44 44
  , opportunisticLockUnion
45 45
  ) where
46 46

  
47
import Control.Applicative (liftA2, (<$>), (<*>))
47
import Control.Applicative (liftA2, (<$>), (<*>), pure)
48 48
import Control.Arrow (second, (***))
49 49
import Control.Monad
50 50
import Data.Foldable (for_, find)
......
156 156
                                 }
157 157
                     deriving (Eq, Show, Ord)
158 158

  
159
instance J.JSON a => J.JSON (LockRequest a) where
160
  showJSON (LockRequest a Nothing) = J.showJSON (a, "release")
161
  showJSON (LockRequest a (Just OwnShared)) = J.showJSON (a, "shared")
162
  showJSON (LockRequest a (Just OwnExclusive)) = J.showJSON (a, "exclusive")
163
  readJSON (J.JSArray [a, J.JSString tp]) =
164
    case J.fromJSString tp of
165
      "release" -> LockRequest <$> J.readJSON a <*> pure Nothing
166
      "shared" -> LockRequest <$> J.readJSON a <*> pure (Just OwnShared)
167
      "exclusive" -> LockRequest <$> J.readJSON a <*> pure (Just OwnExclusive)
168
      _ -> J.Error $ "malformed request type: " ++ J.fromJSString tp
169
  readJSON x = J.Error $ "malformed lock request: " ++ show x
170

  
159 171
-- | Lock request for an exclusive lock.
160 172
requestExclusive :: a -> LockRequest a
161 173
requestExclusive lock = LockRequest { lockAffected = lock

Also available in: Unified diff