3 * Copyright 2018 gRPC authors.
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
19 #include <grpc/support/port_platform.h>
21 #include "src/cpp/server/channelz/channelz_service.h"
23 #include <grpc/grpc.h>
24 #include <grpc/support/alloc.h>
28 Status ChannelzService::GetTopChannels(
29 ServerContext* unused, const channelz::v1::GetTopChannelsRequest* request,
30 channelz::v1::GetTopChannelsResponse* response) {
31 char* json_str = grpc_channelz_get_top_channels(request->start_channel_id());
32 if (json_str == nullptr) {
33 return Status(StatusCode::INTERNAL,
34 "grpc_channelz_get_top_channels returned null");
36 grpc::protobuf::util::Status s =
37 grpc::protobuf::json::JsonStringToMessage(json_str, response);
40 return Status(StatusCode::INTERNAL, s.ToString());
45 Status ChannelzService::GetServers(
46 ServerContext* unused, const channelz::v1::GetServersRequest* request,
47 channelz::v1::GetServersResponse* response) {
48 char* json_str = grpc_channelz_get_servers(request->start_server_id());
49 if (json_str == nullptr) {
50 return Status(StatusCode::INTERNAL,
51 "grpc_channelz_get_servers returned null");
53 grpc::protobuf::util::Status s =
54 grpc::protobuf::json::JsonStringToMessage(json_str, response);
57 return Status(StatusCode::INTERNAL, s.ToString());
62 Status ChannelzService::GetServer(ServerContext* unused,
63 const channelz::v1::GetServerRequest* request,
64 channelz::v1::GetServerResponse* response) {
65 char* json_str = grpc_channelz_get_server(request->server_id());
66 if (json_str == nullptr) {
67 return Status(StatusCode::INTERNAL,
68 "grpc_channelz_get_server returned null");
70 grpc::protobuf::util::Status s =
71 grpc::protobuf::json::JsonStringToMessage(json_str, response);
74 return Status(StatusCode::INTERNAL, s.ToString());
79 Status ChannelzService::GetServerSockets(
80 ServerContext* unused, const channelz::v1::GetServerSocketsRequest* request,
81 channelz::v1::GetServerSocketsResponse* response) {
82 char* json_str = grpc_channelz_get_server_sockets(
83 request->server_id(), request->start_socket_id(), request->max_results());
84 if (json_str == nullptr) {
85 return Status(StatusCode::INTERNAL,
86 "grpc_channelz_get_server_sockets returned null");
88 grpc::protobuf::util::Status s =
89 grpc::protobuf::json::JsonStringToMessage(json_str, response);
92 return Status(StatusCode::INTERNAL, s.ToString());
97 Status ChannelzService::GetChannel(
98 ServerContext* unused, const channelz::v1::GetChannelRequest* request,
99 channelz::v1::GetChannelResponse* response) {
100 char* json_str = grpc_channelz_get_channel(request->channel_id());
101 if (json_str == nullptr) {
102 return Status(StatusCode::NOT_FOUND, "No object found for that ChannelId");
104 grpc::protobuf::util::Status s =
105 grpc::protobuf::json::JsonStringToMessage(json_str, response);
108 return Status(StatusCode::INTERNAL, s.ToString());
113 Status ChannelzService::GetSubchannel(
114 ServerContext* unused, const channelz::v1::GetSubchannelRequest* request,
115 channelz::v1::GetSubchannelResponse* response) {
116 char* json_str = grpc_channelz_get_subchannel(request->subchannel_id());
117 if (json_str == nullptr) {
118 return Status(StatusCode::NOT_FOUND,
119 "No object found for that SubchannelId");
121 grpc::protobuf::util::Status s =
122 grpc::protobuf::json::JsonStringToMessage(json_str, response);
125 return Status(StatusCode::INTERNAL, s.ToString());
130 Status ChannelzService::GetSocket(ServerContext* unused,
131 const channelz::v1::GetSocketRequest* request,
132 channelz::v1::GetSocketResponse* response) {
133 char* json_str = grpc_channelz_get_socket(request->socket_id());
134 if (json_str == nullptr) {
135 return Status(StatusCode::NOT_FOUND, "No object found for that SocketId");
137 grpc::protobuf::util::Status s =
138 grpc::protobuf::json::JsonStringToMessage(json_str, response);
141 return Status(StatusCode::INTERNAL, s.ToString());