Skip to content

Commit 0aa976c

Browse files
V1reflectionservice (grpc#11237)
V1 version of the proto reflection service, as the v1.alpha service has been deprecated. * Create V1 alpha service wrapping underlying V1 service, by modifying the ServerServiceDefinition. * Create ProtoReflectionService for the v1alpha proto by producing a ServerServiceDefinition constructed from that of the v1 service but with the service and method names and proto descriptors modified. Issue grpc#6724.
1 parent 704123e commit 0aa976c

File tree

8 files changed

+1700
-498
lines changed

8 files changed

+1700
-498
lines changed

interop-testing/src/main/java/io/grpc/testing/integration/XdsTestClient.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import io.grpc.Status;
4545
import io.grpc.gcp.csm.observability.CsmObservability;
4646
import io.grpc.protobuf.services.ProtoReflectionService;
47+
import io.grpc.protobuf.services.ProtoReflectionServiceV1;
4748
import io.grpc.services.AdminInterface;
4849
import io.grpc.stub.StreamObserver;
4950
import io.grpc.testing.integration.Messages.ClientConfigureRequest;
@@ -277,6 +278,7 @@ private void run() {
277278
.addService(new XdsStatsImpl())
278279
.addService(new ConfigureUpdateServiceImpl())
279280
.addService(ProtoReflectionService.newInstance())
281+
.addService(ProtoReflectionServiceV1.newInstance())
280282
.addServices(AdminInterface.getStandardServices())
281283
.build();
282284
try {

interop-testing/src/main/java/io/grpc/testing/integration/XdsTestServer.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import io.grpc.netty.NettyServerBuilder;
3838
import io.grpc.protobuf.services.HealthStatusManager;
3939
import io.grpc.protobuf.services.ProtoReflectionService;
40+
import io.grpc.protobuf.services.ProtoReflectionServiceV1;
4041
import io.grpc.services.AdminInterface;
4142
import io.grpc.stub.StreamObserver;
4243
import io.grpc.testing.integration.Messages.Payload;
@@ -220,6 +221,7 @@ void start() throws Exception {
220221
.addService(new XdsUpdateHealthServiceImpl(health))
221222
.addService(health.getHealthService())
222223
.addService(ProtoReflectionService.newInstance())
224+
.addService(ProtoReflectionServiceV1.newInstance())
223225
.addServices(AdminInterface.getStandardServices())
224226
.build();
225227
maintenanceServer.start();
@@ -268,6 +270,7 @@ void start() throws Exception {
268270
.addService(new XdsUpdateHealthServiceImpl(health))
269271
.addService(health.getHealthService())
270272
.addService(ProtoReflectionService.newInstance())
273+
.addService(ProtoReflectionServiceV1.newInstance())
271274
.addServices(AdminInterface.getStandardServices())
272275
.build();
273276
server.start();

services/BUILD.bazel

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,14 +108,17 @@ java_library(
108108
name = "reflection",
109109
srcs = [
110110
"src/main/java/io/grpc/protobuf/services/ProtoReflectionService.java",
111+
"src/main/java/io/grpc/protobuf/services/ProtoReflectionServiceV1.java",
111112
],
112113
deps = [
113114
":_reflection_java_grpc",
115+
":_reflection_v1_java_grpc",
114116
"//api",
115117
"//protobuf",
116118
"//stub",
117119
"@com_google_protobuf//:protobuf_java",
118120
"@com_google_protobuf//:protobuf_java_util",
121+
"@io_grpc_grpc_proto//:reflection_java_proto",
119122
"@io_grpc_grpc_proto//:reflection_java_proto_deprecated",
120123
artifact("com.google.code.findbugs:jsr305"),
121124
artifact("com.google.guava:guava"),
@@ -171,6 +174,13 @@ java_grpc_library(
171174
deps = ["@io_grpc_grpc_proto//:reflection_java_proto_deprecated"],
172175
)
173176

177+
java_grpc_library(
178+
name = "_reflection_v1_java_grpc",
179+
srcs = ["@io_grpc_grpc_proto//:reflection_proto"],
180+
visibility = ["//visibility:private"],
181+
deps = ["@io_grpc_grpc_proto//:reflection_java_proto"],
182+
)
183+
174184
java_grpc_library(
175185
name = "_channelz_java_grpc",
176186
srcs = ["@io_grpc_grpc_proto//:channelz_proto"],
Lines changed: 285 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,285 @@
1+
package io.grpc.reflection.v1;
2+
3+
import static io.grpc.MethodDescriptor.generateFullMethodName;
4+
5+
/**
6+
*/
7+
@javax.annotation.Generated(
8+
value = "by gRPC proto compiler",
9+
comments = "Source: grpc/reflection/v1/reflection.proto")
10+
@io.grpc.stub.annotations.GrpcGenerated
11+
public final class ServerReflectionGrpc {
12+
13+
private ServerReflectionGrpc() {}
14+
15+
public static final java.lang.String SERVICE_NAME = "grpc.reflection.v1.ServerReflection";
16+
17+
// Static method descriptors that strictly reflect the proto.
18+
private static volatile io.grpc.MethodDescriptor<io.grpc.reflection.v1.ServerReflectionRequest,
19+
io.grpc.reflection.v1.ServerReflectionResponse> getServerReflectionInfoMethod;
20+
21+
@io.grpc.stub.annotations.RpcMethod(
22+
fullMethodName = SERVICE_NAME + '/' + "ServerReflectionInfo",
23+
requestType = io.grpc.reflection.v1.ServerReflectionRequest.class,
24+
responseType = io.grpc.reflection.v1.ServerReflectionResponse.class,
25+
methodType = io.grpc.MethodDescriptor.MethodType.BIDI_STREAMING)
26+
public static io.grpc.MethodDescriptor<io.grpc.reflection.v1.ServerReflectionRequest,
27+
io.grpc.reflection.v1.ServerReflectionResponse> getServerReflectionInfoMethod() {
28+
io.grpc.MethodDescriptor<io.grpc.reflection.v1.ServerReflectionRequest, io.grpc.reflection.v1.ServerReflectionResponse> getServerReflectionInfoMethod;
29+
if ((getServerReflectionInfoMethod = ServerReflectionGrpc.getServerReflectionInfoMethod) == null) {
30+
synchronized (ServerReflectionGrpc.class) {
31+
if ((getServerReflectionInfoMethod = ServerReflectionGrpc.getServerReflectionInfoMethod) == null) {
32+
ServerReflectionGrpc.getServerReflectionInfoMethod = getServerReflectionInfoMethod =
33+
io.grpc.MethodDescriptor.<io.grpc.reflection.v1.ServerReflectionRequest, io.grpc.reflection.v1.ServerReflectionResponse>newBuilder()
34+
.setType(io.grpc.MethodDescriptor.MethodType.BIDI_STREAMING)
35+
.setFullMethodName(generateFullMethodName(SERVICE_NAME, "ServerReflectionInfo"))
36+
.setSampledToLocalTracing(true)
37+
.setRequestMarshaller(io.grpc.protobuf.ProtoUtils.marshaller(
38+
io.grpc.reflection.v1.ServerReflectionRequest.getDefaultInstance()))
39+
.setResponseMarshaller(io.grpc.protobuf.ProtoUtils.marshaller(
40+
io.grpc.reflection.v1.ServerReflectionResponse.getDefaultInstance()))
41+
.setSchemaDescriptor(new ServerReflectionMethodDescriptorSupplier("ServerReflectionInfo"))
42+
.build();
43+
}
44+
}
45+
}
46+
return getServerReflectionInfoMethod;
47+
}
48+
49+
/**
50+
* Creates a new async stub that supports all call types for the service
51+
*/
52+
public static ServerReflectionStub newStub(io.grpc.Channel channel) {
53+
io.grpc.stub.AbstractStub.StubFactory<ServerReflectionStub> factory =
54+
new io.grpc.stub.AbstractStub.StubFactory<ServerReflectionStub>() {
55+
@java.lang.Override
56+
public ServerReflectionStub newStub(io.grpc.Channel channel, io.grpc.CallOptions callOptions) {
57+
return new ServerReflectionStub(channel, callOptions);
58+
}
59+
};
60+
return ServerReflectionStub.newStub(factory, channel);
61+
}
62+
63+
/**
64+
* Creates a new blocking-style stub that supports unary and streaming output calls on the service
65+
*/
66+
public static ServerReflectionBlockingStub newBlockingStub(
67+
io.grpc.Channel channel) {
68+
io.grpc.stub.AbstractStub.StubFactory<ServerReflectionBlockingStub> factory =
69+
new io.grpc.stub.AbstractStub.StubFactory<ServerReflectionBlockingStub>() {
70+
@java.lang.Override
71+
public ServerReflectionBlockingStub newStub(io.grpc.Channel channel, io.grpc.CallOptions callOptions) {
72+
return new ServerReflectionBlockingStub(channel, callOptions);
73+
}
74+
};
75+
return ServerReflectionBlockingStub.newStub(factory, channel);
76+
}
77+
78+
/**
79+
* Creates a new ListenableFuture-style stub that supports unary calls on the service
80+
*/
81+
public static ServerReflectionFutureStub newFutureStub(
82+
io.grpc.Channel channel) {
83+
io.grpc.stub.AbstractStub.StubFactory<ServerReflectionFutureStub> factory =
84+
new io.grpc.stub.AbstractStub.StubFactory<ServerReflectionFutureStub>() {
85+
@java.lang.Override
86+
public ServerReflectionFutureStub newStub(io.grpc.Channel channel, io.grpc.CallOptions callOptions) {
87+
return new ServerReflectionFutureStub(channel, callOptions);
88+
}
89+
};
90+
return ServerReflectionFutureStub.newStub(factory, channel);
91+
}
92+
93+
/**
94+
*/
95+
public interface AsyncService {
96+
97+
/**
98+
* <pre>
99+
* The reflection service is structured as a bidirectional stream, ensuring
100+
* all related requests go to a single server.
101+
* </pre>
102+
*/
103+
default io.grpc.stub.StreamObserver<io.grpc.reflection.v1.ServerReflectionRequest> serverReflectionInfo(
104+
io.grpc.stub.StreamObserver<io.grpc.reflection.v1.ServerReflectionResponse> responseObserver) {
105+
return io.grpc.stub.ServerCalls.asyncUnimplementedStreamingCall(getServerReflectionInfoMethod(), responseObserver);
106+
}
107+
}
108+
109+
/**
110+
* Base class for the server implementation of the service ServerReflection.
111+
*/
112+
public static abstract class ServerReflectionImplBase
113+
implements io.grpc.BindableService, AsyncService {
114+
115+
@java.lang.Override public final io.grpc.ServerServiceDefinition bindService() {
116+
return ServerReflectionGrpc.bindService(this);
117+
}
118+
}
119+
120+
/**
121+
* A stub to allow clients to do asynchronous rpc calls to service ServerReflection.
122+
*/
123+
public static final class ServerReflectionStub
124+
extends io.grpc.stub.AbstractAsyncStub<ServerReflectionStub> {
125+
private ServerReflectionStub(
126+
io.grpc.Channel channel, io.grpc.CallOptions callOptions) {
127+
super(channel, callOptions);
128+
}
129+
130+
@java.lang.Override
131+
protected ServerReflectionStub build(
132+
io.grpc.Channel channel, io.grpc.CallOptions callOptions) {
133+
return new ServerReflectionStub(channel, callOptions);
134+
}
135+
136+
/**
137+
* <pre>
138+
* The reflection service is structured as a bidirectional stream, ensuring
139+
* all related requests go to a single server.
140+
* </pre>
141+
*/
142+
public io.grpc.stub.StreamObserver<io.grpc.reflection.v1.ServerReflectionRequest> serverReflectionInfo(
143+
io.grpc.stub.StreamObserver<io.grpc.reflection.v1.ServerReflectionResponse> responseObserver) {
144+
return io.grpc.stub.ClientCalls.asyncBidiStreamingCall(
145+
getChannel().newCall(getServerReflectionInfoMethod(), getCallOptions()), responseObserver);
146+
}
147+
}
148+
149+
/**
150+
* A stub to allow clients to do synchronous rpc calls to service ServerReflection.
151+
*/
152+
public static final class ServerReflectionBlockingStub
153+
extends io.grpc.stub.AbstractBlockingStub<ServerReflectionBlockingStub> {
154+
private ServerReflectionBlockingStub(
155+
io.grpc.Channel channel, io.grpc.CallOptions callOptions) {
156+
super(channel, callOptions);
157+
}
158+
159+
@java.lang.Override
160+
protected ServerReflectionBlockingStub build(
161+
io.grpc.Channel channel, io.grpc.CallOptions callOptions) {
162+
return new ServerReflectionBlockingStub(channel, callOptions);
163+
}
164+
}
165+
166+
/**
167+
* A stub to allow clients to do ListenableFuture-style rpc calls to service ServerReflection.
168+
*/
169+
public static final class ServerReflectionFutureStub
170+
extends io.grpc.stub.AbstractFutureStub<ServerReflectionFutureStub> {
171+
private ServerReflectionFutureStub(
172+
io.grpc.Channel channel, io.grpc.CallOptions callOptions) {
173+
super(channel, callOptions);
174+
}
175+
176+
@java.lang.Override
177+
protected ServerReflectionFutureStub build(
178+
io.grpc.Channel channel, io.grpc.CallOptions callOptions) {
179+
return new ServerReflectionFutureStub(channel, callOptions);
180+
}
181+
}
182+
183+
private static final int METHODID_SERVER_REFLECTION_INFO = 0;
184+
185+
private static final class MethodHandlers<Req, Resp> implements
186+
io.grpc.stub.ServerCalls.UnaryMethod<Req, Resp>,
187+
io.grpc.stub.ServerCalls.ServerStreamingMethod<Req, Resp>,
188+
io.grpc.stub.ServerCalls.ClientStreamingMethod<Req, Resp>,
189+
io.grpc.stub.ServerCalls.BidiStreamingMethod<Req, Resp> {
190+
private final AsyncService serviceImpl;
191+
private final int methodId;
192+
193+
MethodHandlers(AsyncService serviceImpl, int methodId) {
194+
this.serviceImpl = serviceImpl;
195+
this.methodId = methodId;
196+
}
197+
198+
@java.lang.Override
199+
@java.lang.SuppressWarnings("unchecked")
200+
public void invoke(Req request, io.grpc.stub.StreamObserver<Resp> responseObserver) {
201+
switch (methodId) {
202+
default:
203+
throw new AssertionError();
204+
}
205+
}
206+
207+
@java.lang.Override
208+
@java.lang.SuppressWarnings("unchecked")
209+
public io.grpc.stub.StreamObserver<Req> invoke(
210+
io.grpc.stub.StreamObserver<Resp> responseObserver) {
211+
switch (methodId) {
212+
case METHODID_SERVER_REFLECTION_INFO:
213+
return (io.grpc.stub.StreamObserver<Req>) serviceImpl.serverReflectionInfo(
214+
(io.grpc.stub.StreamObserver<io.grpc.reflection.v1.ServerReflectionResponse>) responseObserver);
215+
default:
216+
throw new AssertionError();
217+
}
218+
}
219+
}
220+
221+
public static final io.grpc.ServerServiceDefinition bindService(AsyncService service) {
222+
return io.grpc.ServerServiceDefinition.builder(getServiceDescriptor())
223+
.addMethod(
224+
getServerReflectionInfoMethod(),
225+
io.grpc.stub.ServerCalls.asyncBidiStreamingCall(
226+
new MethodHandlers<
227+
io.grpc.reflection.v1.ServerReflectionRequest,
228+
io.grpc.reflection.v1.ServerReflectionResponse>(
229+
service, METHODID_SERVER_REFLECTION_INFO)))
230+
.build();
231+
}
232+
233+
private static abstract class ServerReflectionBaseDescriptorSupplier
234+
implements io.grpc.protobuf.ProtoFileDescriptorSupplier, io.grpc.protobuf.ProtoServiceDescriptorSupplier {
235+
ServerReflectionBaseDescriptorSupplier() {}
236+
237+
@java.lang.Override
238+
public com.google.protobuf.Descriptors.FileDescriptor getFileDescriptor() {
239+
return io.grpc.reflection.v1.ServerReflectionProto.getDescriptor();
240+
}
241+
242+
@java.lang.Override
243+
public com.google.protobuf.Descriptors.ServiceDescriptor getServiceDescriptor() {
244+
return getFileDescriptor().findServiceByName("ServerReflection");
245+
}
246+
}
247+
248+
private static final class ServerReflectionFileDescriptorSupplier
249+
extends ServerReflectionBaseDescriptorSupplier {
250+
ServerReflectionFileDescriptorSupplier() {}
251+
}
252+
253+
private static final class ServerReflectionMethodDescriptorSupplier
254+
extends ServerReflectionBaseDescriptorSupplier
255+
implements io.grpc.protobuf.ProtoMethodDescriptorSupplier {
256+
private final java.lang.String methodName;
257+
258+
ServerReflectionMethodDescriptorSupplier(java.lang.String methodName) {
259+
this.methodName = methodName;
260+
}
261+
262+
@java.lang.Override
263+
public com.google.protobuf.Descriptors.MethodDescriptor getMethodDescriptor() {
264+
return getServiceDescriptor().findMethodByName(methodName);
265+
}
266+
}
267+
268+
private static volatile io.grpc.ServiceDescriptor serviceDescriptor;
269+
270+
public static io.grpc.ServiceDescriptor getServiceDescriptor() {
271+
io.grpc.ServiceDescriptor result = serviceDescriptor;
272+
if (result == null) {
273+
synchronized (ServerReflectionGrpc.class) {
274+
result = serviceDescriptor;
275+
if (result == null) {
276+
serviceDescriptor = result = io.grpc.ServiceDescriptor.newBuilder(SERVICE_NAME)
277+
.setSchemaDescriptor(new ServerReflectionFileDescriptorSupplier())
278+
.addMethod(getServerReflectionInfoMethod())
279+
.build();
280+
}
281+
}
282+
}
283+
return result;
284+
}
285+
}

0 commit comments

Comments
 (0)