Commit 60c4dbb9 authored by Klaus Aehlig's avatar Klaus Aehlig
Browse files

Add process id to lock-owner description



...so that we can notify owners when their pending request got granted.
Signed-off-by: default avatarKlaus Aehlig <aehlig@google.com>
Reviewed-by: default avatarPetr Pudlak <pudlak@google.com>
parent 2dcbfddb
......@@ -71,10 +71,10 @@ def GetWConfdContext(ec_id, livelock):
"""
if ec_id is None:
return (threading.current_thread().getName(),
livelock.lockfile.name)
livelock.lockfile.name, os.getpid())
else:
return (ec_id,
livelock.lockfile.name)
livelock.lockfile.name, os.getpid())
def GetConfig(ec_id, livelock, **kwargs):
......
......@@ -38,10 +38,11 @@ module Ganeti.Locking.Locks
) where
import Control.Applicative ((<$>), (<*>), pure)
import Control.Monad ((>=>))
import Control.Monad ((>=>), liftM)
import Control.Monad.Base (MonadBase, liftBase)
import Control.Monad.Error (MonadError, catchError)
import Data.List (stripPrefix)
import System.Posix.Types (ProcessID)
import qualified Text.JSON as J
......@@ -202,8 +203,8 @@ instance J.JSON ClientType where
readJSON (J.JSString s) = J.Ok . ClientOther $ J.fromJSString s
readJSON jids = J.readJSON jids >>= \jid -> J.Ok (ClientJob jid)
-- | A client is identified as a job id, thread id and path to its process
-- identifier file.
-- | A client is identified as a job id, thread id, a path to its process
-- identifier file, and its process id.
--
-- The JobId isn't enough to identify a client as the master daemon
-- also handles client calls that aren't jobs, but which use the configuration.
......@@ -211,17 +212,20 @@ instance J.JSON ClientType where
data ClientId = ClientId
{ ciIdentifier :: ClientType
, ciLockFile :: FilePath
, ciPid :: ProcessID
}
deriving (Ord, Eq, Show)
-- | Obtain the ClientID from its JSON representation.
clientIdFromJSON :: J.JSValue -> J.Result ClientId
clientIdFromJSON (J.JSArray [clienttp, J.JSString lf]) =
clientIdFromJSON (J.JSArray [clienttp, J.JSString lf, pid]) =
ClientId <$> J.readJSON clienttp <*> pure (J.fromJSString lf)
<*> liftM fromIntegral (J.readJSON pid :: J.Result Integer)
clientIdFromJSON x = J.Error $ "malformed client id: " ++ show x
instance J.JSON ClientId where
showJSON (ClientId client lf) = J.showJSON (client, lf)
showJSON (ClientId client lf pid)
= J.showJSON (client, lf, fromIntegral pid :: Integer)
readJSON = clientIdFromJSON
-- | The type of lock Allocations in Ganeti. In Ganeti, the owner of
......
......@@ -29,6 +29,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
module Test.Ganeti.Locking.Locks (testLocking_Locks) where
import Control.Applicative ((<$>), (<*>), liftA2)
import Control.Monad (liftM)
import System.Posix.Types (CPid)
import Test.QuickCheck
import Text.JSON
......@@ -100,8 +102,11 @@ prop_ReadShow_ClientType :: Property
prop_ReadShow_ClientType = forAll (arbitrary :: Gen ClientType) $ \a ->
readJSON (showJSON a) ==? Ok a
instance Arbitrary CPid where
arbitrary = liftM fromIntegral (arbitrary :: Gen Integer)
instance Arbitrary ClientId where
arbitrary = ClientId <$> arbitrary <*> arbitrary
arbitrary = ClientId <$> arbitrary <*> arbitrary <*> arbitrary
-- | Verify that readJSON . showJSON = Ok for ClientId
prop_ReadShow_ClientId :: Property
......
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