[Pkg-ganeti-devel] [ganeti] 76/165: Switch the metadata daemon to use the auto-generated client
Apollon Oikonomopoulos
apoikos at moszumanska.debian.org
Tue Aug 11 13:53:15 UTC 2015
This is an automated email from the git hooks/post-receive script.
apoikos pushed a commit to branch master
in repository ganeti.
commit 5a86cd46733ec790e88730e3b7bedee1cac4e9ca
Author: Petr Pudlak <pudlak at google.com>
Date: Mon Mar 2 19:18:44 2015 +0100
Switch the metadata daemon to use the auto-generated client
This includes both the server part (Haskell) and the client part
(Python).
Signed-off-by: Petr Pudlak <pudlak at google.com>
Reviewed-by: Klaus Aehlig <aehlig at google.com>
---
lib/backend.py | 29 ++++-------------------------
src/Ganeti/Metad/ConfigServer.hs | 40 +++++++++++-----------------------------
src/Ganeti/Metad/Server.hs | 3 ++-
3 files changed, 17 insertions(+), 55 deletions(-)
diff --git a/lib/backend.py b/lib/backend.py
index 98d2631..bc376d5 100644
--- a/lib/backend.py
+++ b/lib/backend.py
@@ -56,12 +56,12 @@ import random
import re
import shutil
import signal
-import socket
import stat
import tempfile
import time
import zlib
import copy
+import contextlib
from ganeti import errors
from ganeti import http
@@ -86,8 +86,7 @@ from ganeti import ht
from ganeti.storage.base import BlockDev
from ganeti.storage.drbd import DRBD8
from ganeti import hooksmaster
-from ganeti.rpc import transport
-from ganeti.rpc.errors import NoMasterError, TimeoutError
+import ganeti.metad as metad
_BOOT_ID_PATH = "/proc/sys/kernel/random/boot_id"
@@ -2933,28 +2932,8 @@ def ModifyInstanceMetadata(metadata):
if result.failed:
raise errors.HypervisorError("Failed to start metadata daemon")
- def _Connect():
- return transport.Transport(pathutils.SOCKET_DIR + "/ganeti-metad")
-
- retries = 5
-
- while True:
- try:
- trans = utils.Retry(_Connect, 1.0, constants.LUXI_DEF_CTMO)
- break
- except utils.RetryTimeout:
- raise TimeoutError("Connection to metadata daemon timed out")
- except (socket.error, NoMasterError), err:
- if retries == 0:
- raise TimeoutError("Failed to connect to metadata daemon: %s" % err)
- else:
- retries -= 1
-
- data = serializer.DumpJson(metadata,
- private_encoder=serializer.EncodeWithPrivateFields)
-
- trans.Send(data)
- trans.Close()
+ with contextlib.closing(metad.Client()) as client:
+ client.UpdateConfig(metadata)
def BlockdevCreate(disk, size, owner, on_primary, info, excl_stor):
diff --git a/src/Ganeti/Metad/ConfigServer.hs b/src/Ganeti/Metad/ConfigServer.hs
index 1f1cbb3..ad8e461 100644
--- a/src/Ganeti/Metad/ConfigServer.hs
+++ b/src/Ganeti/Metad/ConfigServer.hs
@@ -1,4 +1,4 @@
-{-# LANGUAGE TupleSections #-}
+{-# LANGUAGE TupleSections, TemplateHaskell #-}
{-| Configuration server for the metadata daemon.
-}
@@ -34,51 +34,33 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-}
module Ganeti.Metad.ConfigServer where
-import Control.Concurrent (forkIO)
-import Control.Concurrent.MVar (MVar)
import Control.Exception (finally)
-import qualified Text.JSON as J
+import Control.Monad.Reader
-import Ganeti.BasicTypes
import Ganeti.Path as Path
import Ganeti.Daemon (DaemonOptions, cleanupSocket, describeError)
-import qualified Ganeti.JSON as J
-import qualified Ganeti.Logging as Logging
import Ganeti.Runtime (GanetiDaemon(..))
-import Ganeti.UDSServer (Client, ConnectConfig(..), Server, ServerConfig(..))
+import Ganeti.THH.RPC
+import Ganeti.UDSServer (ConnectConfig(..), ServerConfig(..))
import qualified Ganeti.UDSServer as UDSServer
import Ganeti.Metad.ConfigCore
-import Ganeti.Metad.Types (InstanceParams)
--- | Reads messages from clients and update the configuration
--- according to these messages.
-acceptConfig :: MetadHandle -> Client -> IO ()
-acceptConfig config client = do
- result <- runResultT $ do
- msg <- liftIO $ UDSServer.recvMsg client
- Logging.logDebug $ "Received: " ++ msg
- instData <- toErrorStr . J.fromJResultE "Parsing instance data" . J.decode
- $ msg
- runMetadMonad (updateConfig instData) config
- annotateResult "Updating Metad instance configuration" $ withError show result
+-- * The handler that converts RPCs to calls to the above functions
--- | Loop that accepts clients and dispatches them to an isolated
--- thread that will handle the client's requests.
-acceptClients :: MetadHandle -> Server -> IO ()
-acceptClients config server =
- do client <- UDSServer.acceptClient server
- _ <- forkIO $ acceptConfig config client
- acceptClients config server
+handler :: RpcServer MetadMonadInt
+handler = $( mkRpcM exportedFunctions )
-start :: DaemonOptions -> MVar InstanceParams -> IO ()
+-- * The main server code
+
+start :: DaemonOptions -> MetadHandle -> IO ()
start _ config = do
socket_path <- Path.defaultMetadSocket
cleanupSocket socket_path
server <- describeError "binding to the socket" Nothing (Just socket_path)
$ UDSServer.connectServer metadConfig True socket_path
finally
- (acceptClients (MetadHandle config) server)
+ (forever $ runMetadMonadInt (UDSServer.listener handler server) config)
(UDSServer.closeServer server)
where
metadConfig = ServerConfig GanetiMetad $ ConnectConfig 60 60
diff --git a/src/Ganeti/Metad/Server.hs b/src/Ganeti/Metad/Server.hs
index 16d0edc..a333bd8 100644
--- a/src/Ganeti/Metad/Server.hs
+++ b/src/Ganeti/Metad/Server.hs
@@ -37,6 +37,7 @@ import Control.Concurrent
import qualified Data.Map (empty)
import Ganeti.Daemon (DaemonOptions)
+import Ganeti.Metad.ConfigCore (MetadHandle(..))
import qualified Ganeti.Metad.ConfigServer as ConfigServer
import qualified Ganeti.Metad.WebServer as WebServer
@@ -44,4 +45,4 @@ start :: DaemonOptions -> IO ()
start opts =
do config <- newMVar Data.Map.empty
_ <- forkIO $ WebServer.start opts config
- ConfigServer.start opts config
+ ConfigServer.start opts (MetadHandle config)
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-ganeti/ganeti.git
More information about the Pkg-ganeti-devel
mailing list