def test_api_to_json(): r = Request(serverRole='s2', downstream=Downstream(serviceName='serviceName', serverRole='s3', encoding='json', hostPort='localhost:123', downstream=Downstream( serviceName='serviceName', serverRole='s4', encoding='json', hostPort='localhost:123', downstream=None))) api.namedtuple_to_dict(r)
def test_api_to_json(): r = Request( serverRole="s2", downstream=Downstream( serviceName="serviceName", serverRole="s3", encoding="json", hostPort="localhost:123", downstream=Downstream( serviceName="serviceName", serverRole="s4", encoding="json", hostPort="localhost:123", downstream=None ), ), ) api.namedtuple_to_dict(r)
def call_downstream(tchannel, target): if not target: raise tornado.gen.Return(None) req = api.Request(serverRole=target.serverRole, downstream=target.downstream) req = api.namedtuple_to_dict(req) if target.encoding == 'json': response = yield tchannel.json( service=target.serviceName, endpoint='trace', hostport=target.hostPort, body=req, ) res = api.response_from_dict(response.body) elif target.encoding == 'thrift': thrift_service = get_thrift_service(service_name=target.serviceName) data = thrift_service.Data(b1=False, i3=0, s2=json.dumps(req)) response = tchannel.thrift( thrift_service.SimpleService.Call(data), hostport=target.hostPort, ) response = yield response body = response.body res = api.response_from_dict(json.loads(body.s2)) else: raise ValueError(target.encoding) raise tornado.gen.Return(res)
def _process_request(req_dict): req = api.request_from_dict(req_dict) span = observe_span() downstream = yield call_downstream(tchannel=tchannel, target=req.downstream) res = api.Response(span=span, downstream=downstream) raise tornado.gen.Return(api.namedtuple_to_dict(res))
def _process_request(req_dict): req = api.request_from_dict(req_dict) span = observe_span() downstream = yield call_downstream( tchannel=tchannel, target=req.downstream) res = api.Response(span=span, downstream=downstream) raise tornado.gen.Return(api.namedtuple_to_dict(res))