diff options
author | Masood Malekghassemi <soltanmm@users.noreply.github.com> | 2015-08-25 12:34:52 -0400 |
---|---|---|
committer | Masood Malekghassemi <soltanmm@users.noreply.github.com> | 2015-08-25 12:34:52 -0400 |
commit | 62597fdf961298fe4ca110932e7a62c0729e533d (patch) | |
tree | d3783a92eec62b855e736f455c3dea89cde15a45 /src/python/grpcio | |
parent | d1f08380aaa823bded05f86846dba6040a9e1fe3 (diff) | |
parent | 7b92bae20e19c6e94f9652050c50027a0fb5fe0c (diff) |
Merge pull request #3047 from nathanielmanistaatgoogle/status
Status code conformance in grpc._links
Diffstat (limited to 'src/python/grpcio')
-rw-r--r-- | src/python/grpcio/grpc/_links/invocation.py | 4 | ||||
-rw-r--r-- | src/python/grpcio/grpc/_links/service.py | 41 |
2 files changed, 37 insertions, 8 deletions
diff --git a/src/python/grpcio/grpc/_links/invocation.py b/src/python/grpcio/grpc/_links/invocation.py index a74c77ebcc..ee3d72fdbc 100644 --- a/src/python/grpcio/grpc/_links/invocation.py +++ b/src/python/grpcio/grpc/_links/invocation.py @@ -141,6 +141,8 @@ class _Kernel(object): termination = links.Ticket.Termination.CANCELLATION elif event.status.code is _intermediary_low.Code.DEADLINE_EXCEEDED: termination = links.Ticket.Termination.EXPIRATION + elif event.status.code is _intermediary_low.Code.UNKNOWN: + termination = links.Ticket.Termination.LOCAL_FAILURE else: termination = links.Ticket.Termination.TRANSMISSION_FAILURE ticket = links.Ticket( @@ -349,7 +351,7 @@ def invocation_link(channel, host, request_serializers, response_deserializers): """Creates an InvocationLink. Args: - channel: A channel for use by the link. + channel: An _intermediary_low.Channel for use by the link. host: The host to specify when invoking RPCs. request_serializers: A dict from group-method pair to request object serialization behavior. diff --git a/src/python/grpcio/grpc/_links/service.py b/src/python/grpcio/grpc/_links/service.py index 1436176246..43c4c0e80c 100644 --- a/src/python/grpcio/grpc/_links/service.py +++ b/src/python/grpcio/grpc/_links/service.py @@ -40,6 +40,19 @@ from grpc.framework.foundation import logging_pool from grpc.framework.foundation import relay from grpc.framework.interfaces.links import links +_TERMINATION_KIND_TO_CODE = { + links.Ticket.Termination.COMPLETION: _intermediary_low.Code.OK, + links.Ticket.Termination.CANCELLATION: _intermediary_low.Code.CANCELLED, + links.Ticket.Termination.EXPIRATION: + _intermediary_low.Code.DEADLINE_EXCEEDED, + links.Ticket.Termination.SHUTDOWN: _intermediary_low.Code.UNAVAILABLE, + links.Ticket.Termination.RECEPTION_FAILURE: _intermediary_low.Code.INTERNAL, + links.Ticket.Termination.TRANSMISSION_FAILURE: + _intermediary_low.Code.INTERNAL, + links.Ticket.Termination.LOCAL_FAILURE: _intermediary_low.Code.UNKNOWN, + links.Ticket.Termination.REMOTE_FAILURE: _intermediary_low.Code.UNKNOWN, +} + @enum.unique class _Read(enum.Enum): @@ -93,6 +106,15 @@ def _metadatafy(call, metadata): call.add_metadata(metadata_key, metadata_value) +def _status(termination_kind, code, details): + effective_details = b'' if details is None else details + if code is None: + effective_code = _TERMINATION_KIND_TO_CODE[termination_kind] + else: + effective_code = code + return _intermediary_low.Status(effective_code, effective_details) + + class _Kernel(object): def __init__(self, request_deserializers, response_serializers, ticket_relay): @@ -170,8 +192,10 @@ class _Kernel(object): if rpc_state.high_write is _HighWrite.CLOSED: if rpc_state.terminal_metadata is not None: _metadatafy(call, rpc_state.terminal_metadata) - call.status( - _intermediary_low.Status(rpc_state.code, rpc_state.message), call) + status = _status( + links.Ticket.Termination.COMPLETION, rpc_state.code, + rpc_state.message) + call.status(status, call) rpc_state.low_write = _LowWrite.CLOSED else: ticket = links.Ticket( @@ -279,14 +303,17 @@ class _Kernel(object): if rpc_state.low_write is _LowWrite.OPEN: if rpc_state.terminal_metadata is not None: _metadatafy(call, rpc_state.terminal_metadata) - status = _intermediary_low.Status( - _intermediary_low.Code.OK - if rpc_state.code is None else rpc_state.code, - '' if rpc_state.message is None else rpc_state.message) + status = _status( + links.Ticket.Termination.COMPLETION, rpc_state.code, + rpc_state.message) call.status(status, call) rpc_state.low_write = _LowWrite.CLOSED elif ticket.termination is not None: - call.cancel() + if rpc_state.terminal_metadata is not None: + _metadatafy(call, rpc_state.terminal_metadata) + status = _status( + ticket.termination, rpc_state.code, rpc_state.message) + call.status(status, call) self._rpc_states.pop(call, None) def add_port(self, port, server_credentials): |