def wrapper(*args, **kwargs): superclient = _connection_pool.get_client(self.conf) try: attr = getattr(superclient, attr_name) try: # Poke it to see if it's closed on the other end. This can happen if a connection # sits in the connection pool longer than the read timeout of the server. sock = self.conf.transport_mode != 'http' and _grab_transport_from_wrapper( superclient.transport).handle if sock and create_synchronous_io_multiplexer().read( [sock]): # the socket is readable, meaning there is either data from a previous call # (i.e our protocol is out of sync), or the connection was shut down on the # remote side. Either way, we need to reopen the connection. # If the socket was closed remotely, btw, socket.read() will return # an empty string. This is a fairly normal condition, btw, since # there are timeouts on both the server and client sides. superclient.transport.close() superclient.transport.open() superclient.set_timeout(self.conf.timeout_seconds) return attr(*args, **kwargs) except TApplicationException as e: # Unknown thrift exception... typically IO errors logging.info("Thrift saw an application exception: " + str(e), exc_info=False) raise StructuredException('THRIFTAPPLICATION', str(e), data=None, error_code=502) except socket.error as e: logging.info("Thrift saw a socket error: " + str(e), exc_info=False) raise StructuredException('THRIFTSOCKET', str(e), data=None, error_code=502) except TTransportException as e: err_msg = str(e) logging.info("Thrift saw a transport exception: " + err_msg, exc_info=False) if err_msg and 'generic failure: Unable to find a callback: 32775' in err_msg: raise StructuredException( _("Increase the sasl_max_buffer value in hue.ini"), err_msg, data=None, error_code=502) raise StructuredThriftTransportException(e, error_code=502) except Exception as e: # Stack tends to be only noisy here. logging.info("Thrift saw exception: " + str(e), exc_info=False) raise finally: self._return_client(superclient)
def _wrap_callable(self, attr_name): # It's gonna be a thrift call. Add wrapping logic to reopen the transport, # and return the connection to the pool when done. def wrapper(*args, **kwargs): superclient = _connection_pool.get_client(self.conf) try: attr = getattr(superclient, attr_name) try: # Poke it to see if it's closed on the other end. This can happen if a connection # sits in the connection pool longer than the read timeout of the server. sock = self.conf.transport_mode == 'binary' and _grab_transport_from_wrapper( superclient.transport).handle if sock and create_synchronous_io_multiplexer().read( [sock]): # the socket is readable, meaning there is either data from a previous call # (i.e our protocol is out of sync), or the connection was shut down on the # remote side. Either way, we need to reopen the connection. # If the socket was closed remotely, btw, socket.read() will return # an empty string. This is a fairly normal condition, btw, since # there are timeouts on both the server and client sides. superclient.transport.close() superclient.transport.open() superclient.set_timeout(self.conf.timeout_seconds) return attr(*args, **kwargs) except TApplicationException, e: # Unknown thrift exception... typically IO errors logging.info("Thrift saw an application exception: " + str(e), exc_info=False) raise StructuredException('THRIFTAPPLICATION', str(e), data=None, error_code=502) except socket.error, e: logging.info("Thrift saw a socket error: " + str(e), exc_info=False) raise StructuredException('THRIFTSOCKET', str(e), data=None, error_code=502) except TTransportException, e: logging.info("Thrift saw a transport exception: " + str(e), exc_info=False) raise StructuredThriftTransportException(e, error_code=502)
def list_sentry_roles_by_group(self, groupName='*'): if self.host.startswith('bad'): raise StructuredThriftTransportException(ex=None) else: return []
def __getattr__(self, attr): if attr in self.__dict__: return self.__dict__[attr] # Fetch the thrift client from the pool superclient = _connection_pool.get_client(self.conf) res = getattr(superclient, attr) if not callable(res): # It's a simple attribute. We can put the superclient back in the pool. _connection_pool.return_client(self.conf, superclient) return res else: # It's gonna be a thrift call. Add wrapping logic to reopen the transport, # and return the connection to the pool when done. def wrapper(*args, **kwargs): try: try: # Poke it to see if it's closed on the other end. This can happen if a connection # sits in the connection pool longer than the read timeout of the server. sock = _grab_transport_from_wrapper( superclient.transport).handle if sock: rlist, wlist, xlist = select.select([sock], [], [], 0) if rlist: # the socket is readable, meaning there is either data from a previous call # (i.e our protocol is out of sync), or the connection was shut down on the # remote side. Either way, we need to reopen the connection. # If the socket was closed remotely, btw, socket.read() will return # an empty string. This is a fairly normal condition, btw, since # there are timeouts on both the server and client sides. superclient.transport.close() superclient.transport.open() superclient.set_timeout(self.conf.timeout_seconds) return res(*args, **kwargs) except TApplicationException, e: # Unknown thrift exception... typically IO errors logging.info("Thrift saw an application exception: " + str(e), exc_info=False) raise StructuredException('THRIFTAPPLICATION', str(e), data=None, error_code=502) except socket.error, e: logging.info("Thrift saw a socket error: " + str(e), exc_info=False) raise StructuredException('THRIFTSOCKET', str(e), data=None, error_code=502) except TTransportException, e: logging.info("Thrift saw a transport exception: " + str(e), exc_info=False) raise StructuredThriftTransportException( e, error_code=502) except Exception, e: # Stack tends to be only noisy here. logging.info("Thrift saw exception: " + str(e), exc_info=False) raise