Esempio n. 1
0
 def closed(self, connection):
     for m in connection.waitForSend(ZooKeeperConnectionStateEvent(ZooKeeperConnectionStateEvent.DOWN,
                                                                   connection,
                                                                   connection.connmark,
                                                                   self)):
         yield m
     for m in Protocol.closed(self, connection):
         yield m
Esempio n. 2
0
 def init(self, connection):
     for m in Protocol.init(self, connection):
         yield m
     rr = self.ResponderRoutine(connection, self.passive)
     connection.responder = rr
     rr.start(False)
     if False:
         yield
Esempio n. 3
0
 def init(self, connection):
     for m in Protocol.init(self, connection):
         yield m
     rr = self.ResponderRoutine(connection, self.passive)
     connection.responder = rr
     rr.start(False)
     if False:
         yield
Esempio n. 4
0
 def error(self, connection):
     for m in Protocol.error(self, connection):
         yield m
     err = connection.socket.getsockopt(SOL_SOCKET, SO_ERROR)
     self._logger.warning('Connection error status: %d(%s)', err, errno.errorcode.get(err, 'Not found'))
     connection.responder.mainroutine.close()
     if False:
         yield
Esempio n. 5
0
 def error(self, connection):
     for m in Protocol.error(self, connection):
         yield m
     err = connection.socket.getsockopt(SOL_SOCKET, SO_ERROR)
     self._logger.warning('Connection error status: %d(%s)', err, errno.errorcode.get(err, 'Not found'))
     connection.responder.mainroutine.close()
     if False:
         yield
Esempio n. 6
0
 def notconnected(self, connection):
     for m in connection.waitForSend(
             ZooKeeperConnectionStateEvent(
                 ZooKeeperConnectionStateEvent.NOTCONNECTED, connection,
                 connection.connmark, self)):
         yield m
     for m in Protocol.notconnected(self, connection):
         yield m
Esempio n. 7
0
 def closed(self, connection):
     for m in connection.waitForSend(
             ZooKeeperConnectionStateEvent(
                 ZooKeeperConnectionStateEvent.DOWN, connection,
                 connection.connmark, self)):
         yield m
     for m in Protocol.closed(self, connection):
         yield m
Esempio n. 8
0
 def notconnected(self, connection):
     for m in connection.waitForSend(ZooKeeperConnectionStateEvent(ZooKeeperConnectionStateEvent.NOTCONNECTED,
                                                                   connection,
                                                                   connection.connmark,
                                                                   self)):
         yield m
     for m in Protocol.notconnected(self, connection):
         yield m
Esempio n. 9
0
 def reconnect_init(self, connection):
     for m in Protocol.reconnect_init(self, connection):
         yield m
     connection.xid = ord(os.urandom(1)) + 1
     connection.zookeeper_requests = {}
     connection.zookeeper_handshake = False
     connection.zookeeper_lastzxid = 0
     for m in connection.waitForSend(ZooKeeperConnectionStateEvent(ZooKeeperConnectionStateEvent.UP,
                                                                   connection,
                                                                   connection.connmark,
                                                                   self)):
         yield m
Esempio n. 10
0
 def reconnect_init(self, connection):
     for m in Protocol.reconnect_init(self, connection):
         yield m
     connection.xid = ord(os.urandom(1)) + 1
     connection.zookeeper_requests = {}
     connection.zookeeper_handshake = False
     connection.zookeeper_lastzxid = 0
     for m in connection.waitForSend(
             ZooKeeperConnectionStateEvent(ZooKeeperConnectionStateEvent.UP,
                                           connection, connection.connmark,
                                           self)):
         yield m
Esempio n. 11
0
 def init(self, connection):
     for m in Protocol.init(self, connection):
         yield m
     connection.createdqueues.append(connection.scheduler.queue.addSubQueue(\
             self.messagepriority, ZooKeeperConnectionStateEvent.createMatcher(connection = connection), ('connstate', connection)))
     connection.createdqueues.append(connection.scheduler.queue.addSubQueue(\
             self.messagepriority + 1, ZooKeeperMessageEvent.createMatcher(connection = connection), ('message', connection), self.messagequeuesize))
     connection.createdqueues.append(connection.scheduler.queue.addSubQueue(\
             self.messagepriority + 2, ZooKeeperResponseEvent.createMatcher(connection = connection, xid = zk.PING_XID)))
     if hasattr(connection, 'queue'):
         connection.queue.addSubQueue(1, ZooKeeperWriteEvent.createMatcher(connection = connection,
                                                                                     priority = ZooKeeperWriteEvent.MIDDLE),
                                      None, self.writequeuesize)
         connection.queue.addSubQueue(2, ZooKeeperWriteEvent.createMatcher(connection = connection,
                                                                                     priority = ZooKeeperWriteEvent.HIGH),
                                      None, self.writequeuesize)
     for m in self.reconnect_init(connection):
         yield m
Esempio n. 12
0
 def init(self, connection):
     for m in Protocol.init(self, connection):
         yield m
     connection.createdqueues.append(connection.scheduler.queue.addSubQueue(\
             self.messagepriority, ZooKeeperConnectionStateEvent.createMatcher(connection = connection), ('connstate', connection)))
     connection.createdqueues.append(connection.scheduler.queue.addSubQueue(\
             self.messagepriority + 1, ZooKeeperMessageEvent.createMatcher(connection = connection), ('message', connection), self.messagequeuesize))
     connection.createdqueues.append(connection.scheduler.queue.addSubQueue(\
             self.messagepriority + 2, ZooKeeperResponseEvent.createMatcher(connection = connection, xid = zk.PING_XID)))
     if hasattr(connection, 'queue'):
         connection.queue.addSubQueue(
             1,
             ZooKeeperWriteEvent.createMatcher(
                 connection=connection,
                 priority=ZooKeeperWriteEvent.MIDDLE), None,
             self.writequeuesize)
         connection.queue.addSubQueue(
             2,
             ZooKeeperWriteEvent.createMatcher(
                 connection=connection, priority=ZooKeeperWriteEvent.HIGH),
             None, self.writequeuesize)
     for m in self.reconnect_init(connection):
         yield m
Esempio n. 13
0
 def accept(self, server, newaddr, newsocket):
     self._logger.debug('Connection accepted from ' + repr(newaddr))
     return Protocol.accept(self, server, newaddr, newsocket)
Esempio n. 14
0
 def closed(self, connection):
     for m in Protocol.closed(self, connection):
         yield m
     connection.responder.mainroutine.close()
     if False:
         yield
Esempio n. 15
0
 def __init__(self):
     Protocol.__init__(self)
Esempio n. 16
0
 def serialize(self, connection, event):
     event._zookeeper_sent = True
     return Protocol.serialize(self, connection, event)
Esempio n. 17
0
 def __init__(self, passive):
     Protocol.__init__(self)
     self.passive = passive
Esempio n. 18
0
 def accept(self, server, newaddr, newsocket):
     self._logger.debug('Connection accepted from ' + repr(newaddr))
     return Protocol.accept(self, server, newaddr, newsocket)
Esempio n. 19
0
 def closed(self, connection):
     for m in Protocol.closed(self, connection):
         yield m
     connection.responder.mainroutine.close()
     if False:
         yield
Esempio n. 20
0
    def _intercept_main(self):
        cr = self.apiroutine.currentroutine
        self.sendEventQueue = Queue()
        _console_connect_event = threading.Event()
        _console_connect_event.clear()
        for m in self.apiroutine.waitForSend(ConsoleEvent('initproxy')):
            yield m
        if not self.startinconsole:
            p = Protocol()
            p.persist = True
            p.createqueue = False

            def init(connection):
                sock = connection.socket
                self.telnet_socket = sock
                self.scheduler.unregisterPolling(connection.socket)
                connection.socket = None
                connection.connected = False
                _console_connect_event.set()
                yield (SocketInjectDone.createMatcher(sock), )

            p.init = init
            p.reconnect_init = init
            Client(self.telnetconsole, p, self.scheduler, self.key,
                   self.certificate, self.ca_certs).start()

        def syscall_threaded_main(scheduler, processor):
            # Detach self
            scheduler.unregisterall(cr)
            self._threaded_main_quit = False

            def threaded_main():
                try:
                    scheduler.main(False, False)
                finally:
                    self._threaded_main_quit = True
                    _console_connect_event.set()

            t = threading.Thread(target=threaded_main)
            t.daemon = True
            t.start()
            try:
                if self.startinconsole:
                    self._interactive()
                else:
                    while not self._threaded_main_quit:
                        try:
                            while not _console_connect_event.is_set():
                                # There is a bug in Python 2.x that wait without timeout cannot be
                                # interrupted by signal
                                _console_connect_event.wait(3600)
                            if self._threaded_main_quit:
                                break
                        except InterruptedBySignalException:
                            # This signal should interrupt the poller, but poller is not in the main thread
                            # Send an event through the proxy will do the trick
                            self.sendEventQueue.put((InterruptPoller(), ))
                            continue
                        pstdin_r, pstdin_w = os.pipe()
                        pstdout_r, pstdout_w = os.pipe()
                        orig_stdin = sys.stdin
                        orig_stdout = sys.stdout
                        orig_stderr = sys.stderr
                        try:
                            pstdin = os.fdopen(pstdin_r, 'rU', 0)
                            pstdout = os.fdopen(pstdout_w, 'w', 0)
                            sys.stdin = pstdin
                            sys.stdout = pstdout
                            sys.stderr = pstdout
                            sock = self.telnet_socket
                            sock.setblocking(True)
                            self.telnet_socket = None
                            _console_connect_event.clear()
                            t = threading.Thread(target=self._telnet_server,
                                                 args=(pstdin_w, pstdout_r,
                                                       sock, orig_stdout))
                            t.daemon = True
                            t.start()
                            try:
                                self._interactive()
                            except SystemExit:
                                pass
                            if not t.is_alive():
                                break
                            self.sendEventQueue.put((SocketInjectDone(sock), ))
                        finally:
                            try:
                                sock.shutdown(socket.SHUT_RDWR)
                            except:
                                pass
                            try:
                                pstdin.close()
                            except:
                                pass
                            try:
                                pstdout.close()
                            except:
                                pass
                            sys.stdin = orig_stdin
                            sys.stdout = orig_stdout
                            sys.stderr = orig_stderr
            except SystemExit:
                pass
            finally:
                self.sendEventQueue.put(None)
                scheduler.quit()
                if self.startinconsole:
                    print('Wait for scheduler end, this may take some time...')
                t.join()

        for m in self.apiroutine.syscall(syscall_threaded_main, True):
            yield m
Esempio n. 21
0
 def serialize(self, connection, event):
     event._zookeeper_sent = True
     return Protocol.serialize(self, connection, event)
Esempio n. 22
0
 def __init__(self, passive):
     Protocol.__init__(self)
     self.passive = passive
Esempio n. 23
0
 def _intercept_main(self):
     cr = self.apiroutine.currentroutine
     self.sendEventQueue = Queue()
     _console_connect_event = threading.Event()
     _console_connect_event.clear()
     for m in self.apiroutine.waitForSend(ConsoleEvent('initproxy')):
         yield m
     if not self.startinconsole:
         p = Protocol()
         p.persist = True
         p.createqueue = False
         def init(connection):
             sock = connection.socket
             self.telnet_socket = sock
             self.scheduler.unregisterPolling(connection.socket)
             connection.socket = None
             connection.connected = False
             _console_connect_event.set()
             yield (SocketInjectDone.createMatcher(sock),)
         p.init = init
         p.reconnect_init = init
         Client(self.telnetconsole, p, self.scheduler, self.key, self.certificate, self.ca_certs).start()
     def syscall_threaded_main(scheduler, processor):
         # Detach self
         scheduler.unregisterall(cr)
         self._threaded_main_quit = False
         def threaded_main():
             try:
                 scheduler.main(False, False)
             finally:
                 self._threaded_main_quit = True
                 _console_connect_event.set()
         t = threading.Thread(target=threaded_main)
         t.daemon = True
         t.start()
         try:
             if self.startinconsole:
                 self._interactive()
             else:
                 while not self._threaded_main_quit:
                     try:
                         while not _console_connect_event.is_set():
                             # There is a bug in Python 2.x that wait without timeout cannot be
                             # interrupted by signal
                             _console_connect_event.wait(3600)
                         if self._threaded_main_quit:
                             break
                     except InterruptedBySignalException:
                         # This signal should interrupt the poller, but poller is not in the main thread
                         # Send an event through the proxy will do the trick
                         self.sendEventQueue.put((InterruptPoller(),))
                         continue
                     pstdin_r, pstdin_w = os.pipe()
                     pstdout_r, pstdout_w = os.pipe()
                     orig_stdin = sys.stdin
                     orig_stdout = sys.stdout
                     orig_stderr = sys.stderr
                     try:
                         pstdin = os.fdopen(pstdin_r, 'rU', 0)
                         pstdout = os.fdopen(pstdout_w, 'w', 0)
                         sys.stdin = pstdin
                         sys.stdout = pstdout
                         sys.stderr = pstdout
                         sock = self.telnet_socket
                         sock.setblocking(True)
                         self.telnet_socket = None
                         _console_connect_event.clear()
                         t = threading.Thread(target=self._telnet_server, args=(pstdin_w, pstdout_r, sock, orig_stdout))
                         t.daemon = True
                         t.start()
                         try:
                             self._interactive()
                         except SystemExit:
                             pass
                         if not t.is_alive():
                             break
                         self.sendEventQueue.put((SocketInjectDone(sock),))
                     finally:
                         try:
                             sock.shutdown(socket.SHUT_RDWR)
                         except:
                             pass
                         try:
                             pstdin.close()
                         except:
                             pass
                         try:
                             pstdout.close()
                         except:
                             pass
                         sys.stdin = orig_stdin
                         sys.stdout = orig_stdout
                         sys.stderr = orig_stderr
         except SystemExit:
             pass
         finally:
             self.sendEventQueue.put(None)
             scheduler.quit()
             if self.startinconsole:
                 print('Wait for scheduler end, this may take some time...')
             t.join()
     for m in self.apiroutine.syscall(syscall_threaded_main, True):
         yield m