Debian Codegraph @

src/python/grpcio_channelz/grpc_channelz/v1/_servicer.py

raw
1 # Copyright 2020 The gRPC Authors
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14 """Channelz debug service implementation in gRPC Python."""
15
16 from google.protobuf import json_format
17 import grpc
18 from grpc._cython import cygrpc
19 import grpc_channelz.v1.channelz_pb2 as _channelz_pb2
20 import grpc_channelz.v1.channelz_pb2_grpc as _channelz_pb2_grpc
21
22
23 class ChannelzServicer(_channelz_pb2_grpc.ChannelzServicer):
24 """Servicer handling RPCs for service statuses."""
25
26 @staticmethod
27 def GetTopChannels(request, context):
28 try:
29 return json_format.Parse(
30 cygrpc.channelz_get_top_channels(request.start_channel_id),
31 _channelz_pb2.GetTopChannelsResponse(),
32 )
33 except (ValueError, json_format.ParseError) as e:
34 context.set_code(grpc.StatusCode.INTERNAL)
35 context.set_details(str(e))
36
37 @staticmethod
38 def GetServers(request, context):
39 try:
40 return json_format.Parse(
41 cygrpc.channelz_get_servers(request.start_server_id),
42 _channelz_pb2.GetServersResponse(),
43 )
44 except (ValueError, json_format.ParseError) as e:
45 context.set_code(grpc.StatusCode.INTERNAL)
46 context.set_details(str(e))
47
48 @staticmethod
49 def GetServer(request, context):
50 try:
51 return json_format.Parse(
52 cygrpc.channelz_get_server(request.server_id),
53 _channelz_pb2.GetServerResponse(),
54 )
55 except ValueError as e:
56 context.set_code(grpc.StatusCode.NOT_FOUND)
57 context.set_details(str(e))
58 except json_format.ParseError as e:
59 context.set_code(grpc.StatusCode.INTERNAL)
60 context.set_details(str(e))
61
62 @staticmethod
63 def GetServerSockets(request, context):
64 try:
65 return json_format.Parse(
66 cygrpc.channelz_get_server_sockets(request.server_id,
67 request.start_socket_id,
68 request.max_results),
69 _channelz_pb2.GetServerSocketsResponse(),
70 )
71 except ValueError as e:
72 context.set_code(grpc.StatusCode.NOT_FOUND)
73 context.set_details(str(e))
74 except json_format.ParseError as e:
75 context.set_code(grpc.StatusCode.INTERNAL)
76 context.set_details(str(e))
77
78 @staticmethod
79 def GetChannel(request, context):
80 try:
81 return json_format.Parse(
82 cygrpc.channelz_get_channel(request.channel_id),
83 _channelz_pb2.GetChannelResponse(),
84 )
85 except ValueError as e:
86 context.set_code(grpc.StatusCode.NOT_FOUND)
87 context.set_details(str(e))
88 except json_format.ParseError as e:
89 context.set_code(grpc.StatusCode.INTERNAL)
90 context.set_details(str(e))
91
92 @staticmethod
93 def GetSubchannel(request, context):
94 try:
95 return json_format.Parse(
96 cygrpc.channelz_get_subchannel(request.subchannel_id),
97 _channelz_pb2.GetSubchannelResponse(),
98 )
99 except ValueError as e:
100 context.set_code(grpc.StatusCode.NOT_FOUND)
101 context.set_details(str(e))
102 except json_format.ParseError as e:
103 context.set_code(grpc.StatusCode.INTERNAL)
104 context.set_details(str(e))
105
106 @staticmethod
107 def GetSocket(request, context):
108 try:
109 return json_format.Parse(
110 cygrpc.channelz_get_socket(request.socket_id),
111 _channelz_pb2.GetSocketResponse(),
112 )
113 except ValueError as e:
114 context.set_code(grpc.StatusCode.NOT_FOUND)
115 context.set_details(str(e))
116 except json_format.ParseError as e:
117 context.set_code(grpc.StatusCode.INTERNAL)
118 context.set_details(str(e))