Beispiel #1
0
 def startMessageBus(self, server):
     messageBusLog = server.cfg.logDir + '/messagebus.log'
     messageLog = server.cfg.logDir + '/messages/messagebus.log'
     util.mkdirChain(os.path.dirname(messageLog))
     m = messagebus.MessageBus('', server.cfg.messageBusPort, messageBusLog,
                               messageLog)
     port = m.getPort()
     pid = server._fork('Message Bus')
     if pid:
         m._close()
         server._messageBusPid = pid
     else:
         try:
             try:
                 m._installSignalHandlers()
                 server._close()
                 self._runServer(m, m.serve_forever, 'Message Bus')
             except Exception, err:
                 m.error('Startup failed: %s: %s' %
                         (err, traceback.format_exc()))
         finally:
             os._exit(3)
Beispiel #2
0
 def _startMessageBus(self):
     if self.cfg.messageBusHost is not None:
         return
     logPath = self.cfg.getMessageBusLogPath()
     messages = self.cfg.logDir + '/messages/messagebus.log'
     util.mkdirChain(os.path.dirname(messages))
     bus = messagebus.MessageBus('', self.cfg.messageBusPort, logPath,
             messages)
     pid = self._fork('messagebus', close=True, criticalLogPath=logPath)
     if pid:
         bus._close()
         return
     try:
         bus._installSignalHandlers()
         bus.serve_forever()
         os._exit(0)
     except SystemExit as err:
         os._exit(err.args[0])
     except Exception:
         bus.exception("Failed to start messagebus:")
     finally:
         os._exit(70)
Beispiel #3
0
    def testDisconnect(self):
        messageBusLog = self.workDir + '/messagebus.log'
        messageBusMessages = self.workDir + '/messagebus.messages'
        clientLog = self.workDir + '/client-log'
        mgr = messagebus.MessageBus('', 0, logPath=messageBusLog, messagePath=messageBusMessages)
        mgr._logger.disableConsole()
        port = mgr.getPort()
        client = busclient.MessageBusClient('localhost', port, None, logPath=clientLog)
        client.logger.disableConsole()
        client.connect()
        client2 = busclient.MessageBusClient('localhost', port, None, logPath=clientLog)
        client2.logger.disableConsole()
        client2.connect()
        p = Poller(mgr, client, client2)
        while (p.writable() or not client.isRegistered()
               or not client2.isRegistered()):
            p.poll()
        client2.popMessages()

        client2.subscribe('/internal/nodes')
        while p.poll():
            pass
        client.disconnect()
        while not client2.hasMessages():
            p.poll()
        m, = client2.popMessages()
        assert(isinstance(m, messages.NodeStatus))
        assert(m.getStatus() == 'DISCONNECTED')

        client.connect()
        while not client2.hasMessages():
            p.poll()
        m, = client2.popMessages()
        assert(isinstance(m, messages.NodeStatus))
        assert(m.getStatus() == 'RECONNECTED')
        assert(m.getStatusId() == client.getSessionId())
Beispiel #4
0
#
# Copyright (c) SAS Institute Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

import logging
from rmake.multinode.server import messagebus

bus = messagebus.MessageBus('::', 50900, '/tmp/mb.log', '/tmp/mb.messages')
bus._logger.logger.handlers = [logging.StreamHandler()]
bus.serve_forever()
Beispiel #5
0
    def testMessageBus(self):
        class MyMessage(messages.Message):
            messageType = 'MINE'

            def set(self, **params):
                self.updateHeaders(params)
        logPath = self.workDir + '/messagebus.log'
        messagePath = self.workDir + '/messagebus.messages'
        clientLog = self.workDir + '/client-log'
        mgr = messagebus.MessageBus('', 0, logPath, messagePath)
        mgr.getLogger().disableConsole()
        port = mgr.getPort()
        client = busclient.MessageBusClient('localhost', port, None, logPath=clientLog)
        client.logger.disableConsole()
        client.connect()
        client2 = busclient.MessageBusClient('localhost', port, None, logPath=clientLog)
        client2.logger.disableConsole()
        client2.connect()
        client3 = busclient.MessageBusClient('localhost', port, None, logPath=clientLog)
        client3.logger.disableConsole()
        client3.connect()
        p = Poller(mgr, client, client2, client3)
        while (p.writable() or not client.isRegistered() or not
                client2.isRegistered() or not client3.isRegistered()):
            p.poll()
        client.popMessages()
        client2.popMessages()
        client3.popMessages()

        client2.subscribe('/foo')
        client3.subscribe('/foo')
        client.subscribe('/foo?a=b')
        msg = MyMessage()
        msg.set(a='b')
        msg2 = MyMessage()
        msg2.set(c='d')
        msg3 = MyMessage()
        msg3.set(e='f')
        client2.sendMessage('/foo', msg)
        client2.sendMessage('/foo', msg2)
        client.sendMessage('/foo', msg2)
        client.sendMessage('/foo', msg3, client2.getSessionId())

        while p.poll() or not client.hasMessages() or not client2.hasMessages():
            pass
        msg, = client.popMessages()
        assert(msg.headers.a == 'b')
        assert(msg.getSessionId() == client2.getSessionId())
        assert(msg.getMessageId() == '%s:2' % client2.getSessionId())
        assert(msg.getDestination() == '/foo')
        assert(msg.getTimestamp())

        msg, two = client2.popMessages()
        assert(msg.headers.c == 'd')
        assert(msg.getSessionId() == client.getSessionId())
        assert(msg.getMessageId() == '%s:2' % client.getSessionId())
        assert(msg.getDestination() == '/foo')
        assert(msg.getTargetId() is None)
        assert(msg.getTimestamp())
        assert(two.headers.e == 'f')
        assert(two.getSessionId() == client.getSessionId())
        assert(two.getMessageId() == '%s:3' % client.getSessionId())
        assert(two.getDestination() == '/foo')
        assert(two.getTargetId() == client2.getSessionId())
        assert(two.getTimestamp())

        msgs = client3.popMessages()
        assert msg3.getMessageId() not in [x.getMessageId() for x in msgs]