Python thrift.Thrift.TApplicationException() Examples
The following are 11
code examples of thrift.Thrift.TApplicationException().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
thrift.Thrift
, or try the search function
.
Example #1
Source File: thriftaction.py From forsun with MIT License | 6 votes |
def execute(self, *args, **kwargs): if not self.params: raise ExecuteActionError("is empty") host = self.params.get("host", "127.0.0.1") port = int(self.params.get("port", 5643)) max_connections = int(self.params.get("max_connections", config.get("ACTION_THRIFT_MAX_CONNECTIONS", 64))) try: client = self.get_client(host, port, max_connections) try: yield client.forsun_call(self.plan.key, int(self.ts), self.params) except TApplicationException as e: logging.error("thrift action execute error '%s' %s:%s '%s' %.2fms", self.plan.key, host, port, e, (time.time() - self.start_time) * 1000) else: logging.debug("thrift action execute '%s' %s:%s %.2fms", self.plan.key, host, port, (time.time() - self.start_time) * 1000) except Exception as e: logging.error("thrift action execute error '%s' %s:%s '%s' %.2fms", self.plan.key, host, port, e, (time.time() - self.start_time) * 1000) raise ActionExecuteRetry()
Example #2
Source File: thrift_client_mixin.py From kingpin with Apache License 2.0 | 5 votes |
def default_thrift_client_replace_if(exception): """Default policy on whether to replace the underlying thrift client. The default policy tests whether the given exception is a user defined thrift exception. If the given exception is a user defined thrift exception, it indicates the underlying connection to the thrift server is sound and can continue to be used. Args: exception: Exception thrown from method invocation of the thrift client. Return: True, if the underlying thrift client needs to be replaced; otherwise, False will be returned. """ # NOTE: this is the best I can come up with to exam whether the given # exception is a user defined exception or not. Currently # TApplicationException, TProtocolException, TTransportException, and user # defined thrift exceptions are all subclasses of TException; however, the # other types of exceptions besides user defined ones don't have thrift_spec # attribute if isinstance(exception, TException): if (isinstance(exception, TApplicationException) or hasattr(exception, 'thrift_spec')): return False return True
Example #3
Source File: test_thrift_client_mixin.py From kingpin with Apache License 2.0 | 5 votes |
def method_other_error(self): raise TApplicationException()
Example #4
Source File: test_thrift_client_mixin.py From kingpin with Apache License 2.0 | 5 votes |
def test_other_error(self): client = FakeThriftClientMixin(HostsProvider(HOSTS)) self.assertRaises(TApplicationException, client.method_other_error) # Connection should be established. self.assertEqual('fakehost1', client.host) self.assertEqual(100, client.port) self.assertTrue(client.connected) # requests_served doesn't not increase. self.assertEqual(0, client.requests_served)
Example #5
Source File: test_thrift_client_mixin.py From kingpin with Apache License 2.0 | 5 votes |
def method_other_error(self): raise TApplicationException()
Example #6
Source File: test_thrift_client_mixin.py From kingpin with Apache License 2.0 | 5 votes |
def test_replace_if(self): def replace_if(ex): return isinstance(ex, ThriftConnectionError) client = FakePooledThriftClientMixin(host_provider=HostsProvider(HOSTS), conn_replace_policy=replace_if) self.assertRaises(ThriftConnectionError, client.method_network_error) self.assertEqual(0, client.client_pool.num_connected) self.assertRaises(TApplicationException, client.method_other_error) self.assertEqual(1, client.client_pool.num_connected)
Example #7
Source File: f_LiffService.py From AsyncLine with MIT License | 5 votes |
def _issueLiffView(self, ctx, request): memory_buffer = TMemoryOutputBuffer(self._transport.get_request_size_limit()) oprot = self._protocol_factory.get_protocol(memory_buffer) oprot.write_request_headers(ctx) oprot.writeMessageBegin('issueLiffView', TMessageType.CALL, 0) args = issueLiffView_args() args.request = request args.write(oprot) oprot.writeMessageEnd() response_transport = await self._transport.request(ctx, memory_buffer.getvalue()) iprot = self._protocol_factory.get_protocol(response_transport) iprot.read_response_headers(ctx) _, mtype, _ = iprot.readMessageBegin() if mtype == TMessageType.EXCEPTION: x = TApplicationException() x.read(iprot) iprot.readMessageEnd() if x.type == TApplicationExceptionType.RESPONSE_TOO_LARGE: raise TTransportException(type=TTransportExceptionType.RESPONSE_TOO_LARGE, message=x.message) raise x result = issueLiffView_result() result.read(iprot) iprot.readMessageEnd() if result.e is not None: raise result.e if result.success is not None: return result.success raise TApplicationException(TApplicationExceptionType.MISSING_RESULT, "issueLiffView failed: unknown result")
Example #8
Source File: f_LiffService.py From AsyncLine with MIT License | 5 votes |
def _revokeToken(self, ctx, request): memory_buffer = TMemoryOutputBuffer(self._transport.get_request_size_limit()) oprot = self._protocol_factory.get_protocol(memory_buffer) oprot.write_request_headers(ctx) oprot.writeMessageBegin('revokeToken', TMessageType.CALL, 0) args = revokeToken_args() args.request = request args.write(oprot) oprot.writeMessageEnd() response_transport = await self._transport.request(ctx, memory_buffer.getvalue()) iprot = self._protocol_factory.get_protocol(response_transport) iprot.read_response_headers(ctx) _, mtype, _ = iprot.readMessageBegin() if mtype == TMessageType.EXCEPTION: x = TApplicationException() x.read(iprot) iprot.readMessageEnd() if x.type == TApplicationExceptionType.RESPONSE_TOO_LARGE: raise TTransportException(type=TTransportExceptionType.RESPONSE_TOO_LARGE, message=x.message) raise x result = revokeToken_result() result.read(iprot) iprot.readMessageEnd() if result.e is not None: raise result.e
Example #9
Source File: f_LiffService.py From AsyncLine with MIT License | 5 votes |
def process(self, ctx, iprot, oprot): args = issueLiffView_args() args.read(iprot) iprot.readMessageEnd() result = issueLiffView_result() try: ret = self._handler([ctx, args.request]) if inspect.iscoroutine(ret): ret = await ret result.success = ret except TApplicationException as ex: async with self._lock: _write_application_exception(ctx, oprot, "issueLiffView", exception=ex) return except LiffException as e: result.e = e except Exception as e: async with self._lock: _write_application_exception(ctx, oprot, "issueLiffView", ex_code=TApplicationExceptionType.INTERNAL_ERROR, message=str(e)) raise async with self._lock: try: oprot.write_response_headers(ctx) oprot.writeMessageBegin('issueLiffView', TMessageType.REPLY, 0) result.write(oprot) oprot.writeMessageEnd() oprot.get_transport().flush() except TTransportException as e: # catch a request too large error because the TMemoryOutputBuffer always throws that if too much data is written if e.type == TTransportExceptionType.REQUEST_TOO_LARGE: raise _write_application_exception(ctx, oprot, "issueLiffView", ex_code=TApplicationExceptionType.RESPONSE_TOO_LARGE, message=e.message) else: raise e
Example #10
Source File: f_LiffService.py From AsyncLine with MIT License | 5 votes |
def process(self, ctx, iprot, oprot): args = revokeToken_args() args.read(iprot) iprot.readMessageEnd() result = revokeToken_result() try: ret = self._handler([ctx, args.request]) if inspect.iscoroutine(ret): ret = await ret except TApplicationException as ex: async with self._lock: _write_application_exception(ctx, oprot, "revokeToken", exception=ex) return except LiffException as e: result.e = e except Exception as e: async with self._lock: _write_application_exception(ctx, oprot, "revokeToken", ex_code=TApplicationExceptionType.INTERNAL_ERROR, message=str(e)) raise async with self._lock: try: oprot.write_response_headers(ctx) oprot.writeMessageBegin('revokeToken', TMessageType.REPLY, 0) result.write(oprot) oprot.writeMessageEnd() oprot.get_transport().flush() except TTransportException as e: # catch a request too large error because the TMemoryOutputBuffer always throws that if too much data is written if e.type == TTransportExceptionType.REQUEST_TOO_LARGE: raise _write_application_exception(ctx, oprot, "revokeToken", ex_code=TApplicationExceptionType.RESPONSE_TOO_LARGE, message=e.message) else: raise e
Example #11
Source File: f_LiffService.py From AsyncLine with MIT License | 5 votes |
def _write_application_exception(ctx, oprot, method, ex_code=None, message=None, exception=None): if exception is not None: x = exception else: x = TApplicationException(type=ex_code, message=message) oprot.write_response_headers(ctx) oprot.writeMessageBegin(method, TMessageType.EXCEPTION, 0) x.write(oprot) oprot.writeMessageEnd() oprot.get_transport().flush() return x