Skip to content

Commit

Permalink
V1reflectionservice (grpc#11237)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
kannanjgithub authored and larry-safran committed Aug 13, 2024
1 parent 9d102e6 commit caa1e8a
Show file tree
Hide file tree
Showing 8 changed files with 1,700 additions and 498 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import io.grpc.Status;
import io.grpc.gcp.csm.observability.CsmObservability;
import io.grpc.protobuf.services.ProtoReflectionService;
import io.grpc.protobuf.services.ProtoReflectionServiceV1;
import io.grpc.services.AdminInterface;
import io.grpc.stub.StreamObserver;
import io.grpc.testing.integration.Messages.ClientConfigureRequest;
Expand Down Expand Up @@ -277,6 +278,7 @@ private void run() {
.addService(new XdsStatsImpl())
.addService(new ConfigureUpdateServiceImpl())
.addService(ProtoReflectionService.newInstance())
.addService(ProtoReflectionServiceV1.newInstance())
.addServices(AdminInterface.getStandardServices())
.build();
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import io.grpc.netty.NettyServerBuilder;
import io.grpc.protobuf.services.HealthStatusManager;
import io.grpc.protobuf.services.ProtoReflectionService;
import io.grpc.protobuf.services.ProtoReflectionServiceV1;
import io.grpc.services.AdminInterface;
import io.grpc.stub.StreamObserver;
import io.grpc.testing.integration.Messages.Payload;
Expand Down Expand Up @@ -220,6 +221,7 @@ void start() throws Exception {
.addService(new XdsUpdateHealthServiceImpl(health))
.addService(health.getHealthService())
.addService(ProtoReflectionService.newInstance())
.addService(ProtoReflectionServiceV1.newInstance())
.addServices(AdminInterface.getStandardServices())
.build();
maintenanceServer.start();
Expand Down Expand Up @@ -268,6 +270,7 @@ void start() throws Exception {
.addService(new XdsUpdateHealthServiceImpl(health))
.addService(health.getHealthService())
.addService(ProtoReflectionService.newInstance())
.addService(ProtoReflectionServiceV1.newInstance())
.addServices(AdminInterface.getStandardServices())
.build();
server.start();
Expand Down
10 changes: 10 additions & 0 deletions services/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,17 @@ java_library(
name = "reflection",
srcs = [
"src/main/java/io/grpc/protobuf/services/ProtoReflectionService.java",
"src/main/java/io/grpc/protobuf/services/ProtoReflectionServiceV1.java",
],
deps = [
":_reflection_java_grpc",
":_reflection_v1_java_grpc",
"//api",
"//protobuf",
"//stub",
"@com_google_protobuf//:protobuf_java",
"@com_google_protobuf//:protobuf_java_util",
"@io_grpc_grpc_proto//:reflection_java_proto",
"@io_grpc_grpc_proto//:reflection_java_proto_deprecated",
artifact("com.google.code.findbugs:jsr305"),
artifact("com.google.guava:guava"),
Expand Down Expand Up @@ -171,6 +174,13 @@ java_grpc_library(
deps = ["@io_grpc_grpc_proto//:reflection_java_proto_deprecated"],
)

java_grpc_library(
name = "_reflection_v1_java_grpc",
srcs = ["@io_grpc_grpc_proto//:reflection_proto"],
visibility = ["//visibility:private"],
deps = ["@io_grpc_grpc_proto//:reflection_java_proto"],
)

java_grpc_library(
name = "_channelz_java_grpc",
srcs = ["@io_grpc_grpc_proto//:channelz_proto"],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,285 @@
package io.grpc.reflection.v1;

import static io.grpc.MethodDescriptor.generateFullMethodName;

/**
*/
@javax.annotation.Generated(
value = "by gRPC proto compiler",
comments = "Source: grpc/reflection/v1/reflection.proto")
@io.grpc.stub.annotations.GrpcGenerated
public final class ServerReflectionGrpc {

private ServerReflectionGrpc() {}

public static final java.lang.String SERVICE_NAME = "grpc.reflection.v1.ServerReflection";

// Static method descriptors that strictly reflect the proto.
private static volatile io.grpc.MethodDescriptor<io.grpc.reflection.v1.ServerReflectionRequest,
io.grpc.reflection.v1.ServerReflectionResponse> getServerReflectionInfoMethod;

@io.grpc.stub.annotations.RpcMethod(
fullMethodName = SERVICE_NAME + '/' + "ServerReflectionInfo",
requestType = io.grpc.reflection.v1.ServerReflectionRequest.class,
responseType = io.grpc.reflection.v1.ServerReflectionResponse.class,
methodType = io.grpc.MethodDescriptor.MethodType.BIDI_STREAMING)
public static io.grpc.MethodDescriptor<io.grpc.reflection.v1.ServerReflectionRequest,
io.grpc.reflection.v1.ServerReflectionResponse> getServerReflectionInfoMethod() {
io.grpc.MethodDescriptor<io.grpc.reflection.v1.ServerReflectionRequest, io.grpc.reflection.v1.ServerReflectionResponse> getServerReflectionInfoMethod;
if ((getServerReflectionInfoMethod = ServerReflectionGrpc.getServerReflectionInfoMethod) == null) {
synchronized (ServerReflectionGrpc.class) {
if ((getServerReflectionInfoMethod = ServerReflectionGrpc.getServerReflectionInfoMethod) == null) {
ServerReflectionGrpc.getServerReflectionInfoMethod = getServerReflectionInfoMethod =
io.grpc.MethodDescriptor.<io.grpc.reflection.v1.ServerReflectionRequest, io.grpc.reflection.v1.ServerReflectionResponse>newBuilder()
.setType(io.grpc.MethodDescriptor.MethodType.BIDI_STREAMING)
.setFullMethodName(generateFullMethodName(SERVICE_NAME, "ServerReflectionInfo"))
.setSampledToLocalTracing(true)
.setRequestMarshaller(io.grpc.protobuf.ProtoUtils.marshaller(
io.grpc.reflection.v1.ServerReflectionRequest.getDefaultInstance()))
.setResponseMarshaller(io.grpc.protobuf.ProtoUtils.marshaller(
io.grpc.reflection.v1.ServerReflectionResponse.getDefaultInstance()))
.setSchemaDescriptor(new ServerReflectionMethodDescriptorSupplier("ServerReflectionInfo"))
.build();
}
}
}
return getServerReflectionInfoMethod;
}

/**
* Creates a new async stub that supports all call types for the service
*/
public static ServerReflectionStub newStub(io.grpc.Channel channel) {
io.grpc.stub.AbstractStub.StubFactory<ServerReflectionStub> factory =
new io.grpc.stub.AbstractStub.StubFactory<ServerReflectionStub>() {
@java.lang.Override
public ServerReflectionStub newStub(io.grpc.Channel channel, io.grpc.CallOptions callOptions) {
return new ServerReflectionStub(channel, callOptions);
}
};
return ServerReflectionStub.newStub(factory, channel);
}

/**
* Creates a new blocking-style stub that supports unary and streaming output calls on the service
*/
public static ServerReflectionBlockingStub newBlockingStub(
io.grpc.Channel channel) {
io.grpc.stub.AbstractStub.StubFactory<ServerReflectionBlockingStub> factory =
new io.grpc.stub.AbstractStub.StubFactory<ServerReflectionBlockingStub>() {
@java.lang.Override
public ServerReflectionBlockingStub newStub(io.grpc.Channel channel, io.grpc.CallOptions callOptions) {
return new ServerReflectionBlockingStub(channel, callOptions);
}
};
return ServerReflectionBlockingStub.newStub(factory, channel);
}

/**
* Creates a new ListenableFuture-style stub that supports unary calls on the service
*/
public static ServerReflectionFutureStub newFutureStub(
io.grpc.Channel channel) {
io.grpc.stub.AbstractStub.StubFactory<ServerReflectionFutureStub> factory =
new io.grpc.stub.AbstractStub.StubFactory<ServerReflectionFutureStub>() {
@java.lang.Override
public ServerReflectionFutureStub newStub(io.grpc.Channel channel, io.grpc.CallOptions callOptions) {
return new ServerReflectionFutureStub(channel, callOptions);
}
};
return ServerReflectionFutureStub.newStub(factory, channel);
}

/**
*/
public interface AsyncService {

/**
* <pre>
* The reflection service is structured as a bidirectional stream, ensuring
* all related requests go to a single server.
* </pre>
*/
default io.grpc.stub.StreamObserver<io.grpc.reflection.v1.ServerReflectionRequest> serverReflectionInfo(
io.grpc.stub.StreamObserver<io.grpc.reflection.v1.ServerReflectionResponse> responseObserver) {
return io.grpc.stub.ServerCalls.asyncUnimplementedStreamingCall(getServerReflectionInfoMethod(), responseObserver);
}
}

/**
* Base class for the server implementation of the service ServerReflection.
*/
public static abstract class ServerReflectionImplBase
implements io.grpc.BindableService, AsyncService {

@java.lang.Override public final io.grpc.ServerServiceDefinition bindService() {
return ServerReflectionGrpc.bindService(this);
}
}

/**
* A stub to allow clients to do asynchronous rpc calls to service ServerReflection.
*/
public static final class ServerReflectionStub
extends io.grpc.stub.AbstractAsyncStub<ServerReflectionStub> {
private ServerReflectionStub(
io.grpc.Channel channel, io.grpc.CallOptions callOptions) {
super(channel, callOptions);
}

@java.lang.Override
protected ServerReflectionStub build(
io.grpc.Channel channel, io.grpc.CallOptions callOptions) {
return new ServerReflectionStub(channel, callOptions);
}

/**
* <pre>
* The reflection service is structured as a bidirectional stream, ensuring
* all related requests go to a single server.
* </pre>
*/
public io.grpc.stub.StreamObserver<io.grpc.reflection.v1.ServerReflectionRequest> serverReflectionInfo(
io.grpc.stub.StreamObserver<io.grpc.reflection.v1.ServerReflectionResponse> responseObserver) {
return io.grpc.stub.ClientCalls.asyncBidiStreamingCall(
getChannel().newCall(getServerReflectionInfoMethod(), getCallOptions()), responseObserver);
}
}

/**
* A stub to allow clients to do synchronous rpc calls to service ServerReflection.
*/
public static final class ServerReflectionBlockingStub
extends io.grpc.stub.AbstractBlockingStub<ServerReflectionBlockingStub> {
private ServerReflectionBlockingStub(
io.grpc.Channel channel, io.grpc.CallOptions callOptions) {
super(channel, callOptions);
}

@java.lang.Override
protected ServerReflectionBlockingStub build(
io.grpc.Channel channel, io.grpc.CallOptions callOptions) {
return new ServerReflectionBlockingStub(channel, callOptions);
}
}

/**
* A stub to allow clients to do ListenableFuture-style rpc calls to service ServerReflection.
*/
public static final class ServerReflectionFutureStub
extends io.grpc.stub.AbstractFutureStub<ServerReflectionFutureStub> {
private ServerReflectionFutureStub(
io.grpc.Channel channel, io.grpc.CallOptions callOptions) {
super(channel, callOptions);
}

@java.lang.Override
protected ServerReflectionFutureStub build(
io.grpc.Channel channel, io.grpc.CallOptions callOptions) {
return new ServerReflectionFutureStub(channel, callOptions);
}
}

private static final int METHODID_SERVER_REFLECTION_INFO = 0;

private static final class MethodHandlers<Req, Resp> implements
io.grpc.stub.ServerCalls.UnaryMethod<Req, Resp>,
io.grpc.stub.ServerCalls.ServerStreamingMethod<Req, Resp>,
io.grpc.stub.ServerCalls.ClientStreamingMethod<Req, Resp>,
io.grpc.stub.ServerCalls.BidiStreamingMethod<Req, Resp> {
private final AsyncService serviceImpl;
private final int methodId;

MethodHandlers(AsyncService serviceImpl, int methodId) {
this.serviceImpl = serviceImpl;
this.methodId = methodId;
}

@java.lang.Override
@java.lang.SuppressWarnings("unchecked")
public void invoke(Req request, io.grpc.stub.StreamObserver<Resp> responseObserver) {
switch (methodId) {
default:
throw new AssertionError();
}
}

@java.lang.Override
@java.lang.SuppressWarnings("unchecked")
public io.grpc.stub.StreamObserver<Req> invoke(
io.grpc.stub.StreamObserver<Resp> responseObserver) {
switch (methodId) {
case METHODID_SERVER_REFLECTION_INFO:
return (io.grpc.stub.StreamObserver<Req>) serviceImpl.serverReflectionInfo(
(io.grpc.stub.StreamObserver<io.grpc.reflection.v1.ServerReflectionResponse>) responseObserver);
default:
throw new AssertionError();
}
}
}

public static final io.grpc.ServerServiceDefinition bindService(AsyncService service) {
return io.grpc.ServerServiceDefinition.builder(getServiceDescriptor())
.addMethod(
getServerReflectionInfoMethod(),
io.grpc.stub.ServerCalls.asyncBidiStreamingCall(
new MethodHandlers<
io.grpc.reflection.v1.ServerReflectionRequest,
io.grpc.reflection.v1.ServerReflectionResponse>(
service, METHODID_SERVER_REFLECTION_INFO)))
.build();
}

private static abstract class ServerReflectionBaseDescriptorSupplier
implements io.grpc.protobuf.ProtoFileDescriptorSupplier, io.grpc.protobuf.ProtoServiceDescriptorSupplier {
ServerReflectionBaseDescriptorSupplier() {}

@java.lang.Override
public com.google.protobuf.Descriptors.FileDescriptor getFileDescriptor() {
return io.grpc.reflection.v1.ServerReflectionProto.getDescriptor();
}

@java.lang.Override
public com.google.protobuf.Descriptors.ServiceDescriptor getServiceDescriptor() {
return getFileDescriptor().findServiceByName("ServerReflection");
}
}

private static final class ServerReflectionFileDescriptorSupplier
extends ServerReflectionBaseDescriptorSupplier {
ServerReflectionFileDescriptorSupplier() {}
}

private static final class ServerReflectionMethodDescriptorSupplier
extends ServerReflectionBaseDescriptorSupplier
implements io.grpc.protobuf.ProtoMethodDescriptorSupplier {
private final java.lang.String methodName;

ServerReflectionMethodDescriptorSupplier(java.lang.String methodName) {
this.methodName = methodName;
}

@java.lang.Override
public com.google.protobuf.Descriptors.MethodDescriptor getMethodDescriptor() {
return getServiceDescriptor().findMethodByName(methodName);
}
}

private static volatile io.grpc.ServiceDescriptor serviceDescriptor;

public static io.grpc.ServiceDescriptor getServiceDescriptor() {
io.grpc.ServiceDescriptor result = serviceDescriptor;
if (result == null) {
synchronized (ServerReflectionGrpc.class) {
result = serviceDescriptor;
if (result == null) {
serviceDescriptor = result = io.grpc.ServiceDescriptor.newBuilder(SERVICE_NAME)
.setSchemaDescriptor(new ServerReflectionFileDescriptorSupplier())
.addMethod(getServerReflectionInfoMethod())
.build();
}
}
}
return result;
}
}
Loading

0 comments on commit caa1e8a

Please sign in to comment.