Skip to content

Commit

Permalink
services: Deprecate V1alpha (#11681)
Browse files Browse the repository at this point in the history
  • Loading branch information
shivaspeaks authored Nov 12, 2024
1 parent 8237ae2 commit 921f88a
Show file tree
Hide file tree
Showing 11 changed files with 27 additions and 19 deletions.
8 changes: 4 additions & 4 deletions documentation/server-reflection-tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ proto-based services.
## Enable Server Reflection

gRPC-Java Server Reflection is implemented by
`io.grpc.protobuf.services.ProtoReflectionService` in the `grpc-services`
`io.grpc.protobuf.services.ProtoReflectionServiceV1` in the `grpc-services`
package. To enable server reflection, you need to add the
`ProtoReflectionService` to your gRPC server.
`ProtoReflectionServiceV1` to your gRPC server.

For example, to enable server reflection in
`examples/src/main/java/io/grpc/examples/helloworld/HelloWorldServer.java`, we
Expand All @@ -35,15 +35,15 @@ need to make the following changes:

import io.grpc.Server;
import io.grpc.ServerBuilder;
+import io.grpc.protobuf.services.ProtoReflectionService;
+import io.grpc.protobuf.services.ProtoReflectionServiceV1;
import io.grpc.stub.StreamObserver;
import java.io.IOException;
import java.util.logging.Logger;
@@ -50,6 +51,7 @@ public class HelloWorldServer {
int port = 50051;
server = ServerBuilder.forPort(port)
.addService(new GreeterImpl())
+ .addService(ProtoReflectionService.newInstance())
+ .addService(ProtoReflectionServiceV1.newInstance())
.build()
.start();
logger.info("Server started, listening on " + port);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import io.grpc.examples.helloworld.GreeterGrpc;
import io.grpc.examples.helloworld.HelloReply;
import io.grpc.examples.helloworld.HelloRequest;
import io.grpc.protobuf.services.ProtoReflectionService;
import io.grpc.protobuf.services.ProtoReflectionServiceV1;
import io.grpc.services.AdminInterface;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import io.grpc.Server;
import io.grpc.ServerBuilder;
import io.grpc.health.v1.HealthCheckResponse.ServingStatus;
import io.grpc.protobuf.services.ProtoReflectionService;
import io.grpc.protobuf.services.ProtoReflectionServiceV1;
import io.grpc.services.AdminInterface;
import io.grpc.services.HealthStatusManager;
import java.io.IOException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import io.grpc.Server;
import io.grpc.ServerBuilder;
import io.grpc.health.v1.HealthCheckResponse.ServingStatus;
import io.grpc.protobuf.services.ProtoReflectionService;
import io.grpc.protobuf.services.ProtoReflectionServiceV1;
import io.grpc.services.HealthStatusManager;
import java.io.IOException;
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -53,7 +53,7 @@ public static void main(String[] args) throws IOException, InterruptedException
HealthStatusManager health = new HealthStatusManager();
final Server server = Grpc.newServerBuilderForPort(port, InsecureServerCredentials.create())
.addService(new HostnameGreeter(hostname))
.addService(ProtoReflectionService.newInstance())
.addService(ProtoReflectionServiceV1.newInstance())
.addService(health.getHealthService())
.build()
.start();
Expand Down
2 changes: 1 addition & 1 deletion examples/example-reflection/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
gRPC Reflection Example
================

The reflection example has a Hello World server with `ProtoReflectionService` registered.
The reflection example has a Hello World server with `ProtoReflectionServiceV1` registered.

### Build the example

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import io.grpc.examples.helloworld.GreeterGrpc;
import io.grpc.examples.helloworld.HelloReply;
import io.grpc.examples.helloworld.HelloRequest;
import io.grpc.protobuf.services.ProtoReflectionService;
import io.grpc.protobuf.services.ProtoReflectionServiceV1;
import io.grpc.stub.StreamObserver;
import java.io.IOException;
import java.util.concurrent.TimeUnit;
Expand All @@ -26,7 +26,7 @@ private void start() throws IOException {
int port = 50051;
server = Grpc.newServerBuilderForPort(port, InsecureServerCredentials.create())
.addService(new GreeterImpl())
.addService(ProtoReflectionService.newInstance()) // add reflection service
.addService(ProtoReflectionServiceV1.newInstance()) // add reflection service
.build()
.start();
logger.info("Server started, listening on " + port);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import io.grpc.Server;
import io.grpc.ServerCredentials;
import io.grpc.health.v1.HealthCheckResponse.ServingStatus;
import io.grpc.protobuf.services.ProtoReflectionService;
import io.grpc.protobuf.services.ProtoReflectionServiceV1;
import io.grpc.services.HealthStatusManager;
import io.grpc.xds.XdsServerBuilder;
import io.grpc.xds.XdsServerCredentials;
Expand Down Expand Up @@ -66,7 +66,7 @@ public static void main(String[] args) throws IOException, InterruptedException
final HealthStatusManager health = new HealthStatusManager();
final Server server = XdsServerBuilder.forPort(port, credentials)
.addService(new HostnameGreeter(hostname))
.addService(ProtoReflectionService.newInstance()) // convenient for command line tools
.addService(ProtoReflectionServiceV1.newInstance()) // convenient for command line tools
.addService(health.getHealthService()) // allow management servers to monitor health
.build()
.start();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import com.google.common.util.concurrent.MoreExecutors;
import com.google.common.util.concurrent.SettableFuture;
import com.google.protobuf.ByteString;
import io.grpc.BindableService;
import io.grpc.CallOptions;
import io.grpc.Channel;
import io.grpc.ClientCall;
Expand Down Expand Up @@ -273,11 +274,13 @@ private void run() {
.build();
csmObservability.registerGlobal();
}
@SuppressWarnings("deprecation")
BindableService oldReflectionService = ProtoReflectionService.newInstance();
statsServer =
Grpc.newServerBuilderForPort(statsPort, InsecureServerCredentials.create())
.addService(new XdsStatsImpl())
.addService(new ConfigureUpdateServiceImpl())
.addService(ProtoReflectionService.newInstance())
.addService(oldReflectionService)
.addService(ProtoReflectionServiceV1.newInstance())
.addServices(AdminInterface.getStandardServices())
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Iterables;
import com.google.protobuf.ByteString;
import io.grpc.BindableService;
import io.grpc.ForwardingServerCall.SimpleForwardingServerCall;
import io.grpc.Grpc;
import io.grpc.InsecureServerCredentials;
Expand Down Expand Up @@ -212,6 +213,8 @@ void start() throws Exception {
throw new RuntimeException(e);
}
health = new HealthStatusManager();
@SuppressWarnings("deprecation")
BindableService oldReflectionService = ProtoReflectionService.newInstance();
if (secureMode) {
if (addressType != Util.AddressType.IPV4_IPV6) {
throw new IllegalArgumentException("Secure mode only supports IPV4_IPV6 address type");
Expand All @@ -220,7 +223,7 @@ void start() throws Exception {
Grpc.newServerBuilderForPort(maintenancePort, InsecureServerCredentials.create())
.addService(new XdsUpdateHealthServiceImpl(health))
.addService(health.getHealthService())
.addService(ProtoReflectionService.newInstance())
.addService(oldReflectionService)
.addService(ProtoReflectionServiceV1.newInstance())
.addServices(AdminInterface.getStandardServices())
.build();
Expand Down Expand Up @@ -272,7 +275,7 @@ void start() throws Exception {
new TestServiceImpl(serverId, host), new TestInfoInterceptor(host)))
.addService(new XdsUpdateHealthServiceImpl(health))
.addService(health.getHealthService())
.addService(ProtoReflectionService.newInstance())
.addService(oldReflectionService)
.addService(ProtoReflectionServiceV1.newInstance())
.addServices(AdminInterface.getStandardServices())
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,25 @@

/**
* Provides a reflection service for Protobuf services (including the reflection service itself).
* Uses the deprecated v1alpha proto. New users should use ProtoReflectionServiceV1 instead.
*
* <p>Separately tracks mutable and immutable services. Throws an exception if either group of
* services contains multiple Protobuf files with declarations of the same service, method, type, or
* extension.
* Uses the deprecated v1alpha proto. New users should use {@link ProtoReflectionServiceV1} instead.
*/
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/2222")
public final class ProtoReflectionService implements BindableService {

private ProtoReflectionService() {
}

@Deprecated
public static BindableService newInstance() {
return new ProtoReflectionService();
}

@Override
@SuppressWarnings("deprecation")
public ServerServiceDefinition bindService() {
ServerServiceDefinition serverServiceDefinitionV1 = ProtoReflectionServiceV1.newInstance()
.bindService();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ public class ProtoReflectionServiceTest {

private static final String TEST_HOST = "localhost";
private MutableHandlerRegistry handlerRegistry = new MutableHandlerRegistry();
private BindableService reflectionService;
@SuppressWarnings("deprecation")
private BindableService reflectionService = ProtoReflectionService.newInstance();
private ServerServiceDefinition dynamicService =
new DynamicServiceGrpc.DynamicServiceImplBase() {}.bindService();
private ServerServiceDefinition anotherDynamicService =
Expand All @@ -80,7 +81,6 @@ public class ProtoReflectionServiceTest {

@Before
public void setUp() throws Exception {
reflectionService = ProtoReflectionService.newInstance();
Server server =
InProcessServerBuilder.forName("proto-reflection-test")
.directExecutor()
Expand Down

0 comments on commit 921f88a

Please sign in to comment.