services: move classes with protobuf dependency into io.grpc.protobuf.services (#8056)

To separately manage services/classes with and without protobuf dependency in services package, we are moving classes with protobuf dependency into io.grpc.protobuf.services. This includes healthchecking, reflection, channelz, and binlogging.

Forwarding classes are created to avoid breaking existing users, while they are marked as deprecated to notify users to migrate.
This commit is contained in:
Chengyuan Zhang 2021-04-16 17:27:12 -07:00 committed by GitHub
parent eb6764841b
commit bab1fe38dc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
34 changed files with 488 additions and 209 deletions

View File

@ -30,9 +30,9 @@ import io.grpc.Status;
import io.grpc.StatusRuntimeException;
import io.grpc.health.v1.HealthCheckResponse.ServingStatus;
import io.grpc.netty.NettyServerBuilder;
import io.grpc.protobuf.services.HealthStatusManager;
import io.grpc.protobuf.services.ProtoReflectionService;
import io.grpc.services.AdminInterface;
import io.grpc.services.HealthStatusManager;
import io.grpc.stub.StreamObserver;
import io.grpc.testing.integration.Messages.SimpleRequest;
import io.grpc.testing.integration.Messages.SimpleResponse;

View File

@ -5,12 +5,12 @@ package(default_visibility = ["//visibility:public"])
java_library(
name = "binarylog",
srcs = [
"src/main/java/io/grpc/services/BinaryLogProvider.java",
"src/main/java/io/grpc/services/BinaryLogProviderImpl.java",
"src/main/java/io/grpc/services/BinaryLogSink.java",
"src/main/java/io/grpc/services/BinlogHelper.java",
"src/main/java/io/grpc/services/InetAddressUtil.java",
"src/main/java/io/grpc/services/TempFileSink.java",
"src/main/java/io/grpc/protobuf/services/BinaryLogProvider.java",
"src/main/java/io/grpc/protobuf/services/BinaryLogProviderImpl.java",
"src/main/java/io/grpc/protobuf/services/BinaryLogSink.java",
"src/main/java/io/grpc/protobuf/services/BinlogHelper.java",
"src/main/java/io/grpc/protobuf/services/InetAddressUtil.java",
"src/main/java/io/grpc/protobuf/services/TempFileSink.java",
],
deps = [
"//api",
@ -26,7 +26,8 @@ java_library(
java_library(
name = "channelz",
srcs = [
"src/main/java/io/grpc/services/ChannelzProtoUtil.java",
"src/main/java/io/grpc/protobuf/services/ChannelzProtoUtil.java",
"src/main/java/io/grpc/protobuf/services/ChannelzService.java",
"src/main/java/io/grpc/services/ChannelzService.java",
],
deps = [
@ -66,7 +67,8 @@ java_library(
java_library(
name = "health",
srcs = [
"src/main/java/io/grpc/services/HealthServiceImpl.java",
"src/main/java/io/grpc/protobuf/services/HealthServiceImpl.java",
"src/main/java/io/grpc/protobuf/services/HealthStatusManager.java",
"src/main/java/io/grpc/services/HealthStatusManager.java",
],
deps = [

View File

@ -14,7 +14,7 @@
* limitations under the License.
*/
package io.grpc.services;
package io.grpc.protobuf.services;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Preconditions;

View File

@ -14,7 +14,7 @@
* limitations under the License.
*/
package io.grpc.services;
package io.grpc.protobuf.services;
import com.google.common.base.Preconditions;
import io.grpc.CallOptions;

View File

@ -14,7 +14,7 @@
* limitations under the License.
*/
package io.grpc.services;
package io.grpc.protobuf.services;
import com.google.protobuf.MessageLite;
import io.grpc.ExperimentalApi;

View File

@ -0,0 +1,53 @@
/*
* Copyright 2018, gRPC Authors All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.grpc.protobuf.services;
import io.grpc.BinaryLog;
import io.grpc.ExperimentalApi;
import java.io.IOException;
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/4017")
public final class BinaryLogs {
/**
* Creates a binary log that writes to a temp file. <b>Warning:</b> this implementation is
* not performance optimized, and RPCs will experience back pressure if disk IO does not keep
* up.
*/
public static BinaryLog createBinaryLog() throws IOException {
return new BinaryLogProviderImpl();
}
/**
* Deprecated and will be removed in a future version of gRPC.
*/
@Deprecated
public static BinaryLog createBinaryLog(BinaryLogSink sink) throws IOException {
return new BinaryLogProviderImpl(sink);
}
/**
* Creates a binary log with a custom {@link BinaryLogSink} for receiving the logged data,
* and a config string as defined by
* <a href="https://github.com/grpc/proposal/blob/master/A16-binary-logging.md">
* A16-binary-logging</a>.
*/
public static BinaryLog createBinaryLog(BinaryLogSink sink, String configStr) throws IOException {
return new BinaryLogProviderImpl(sink, configStr);
}
private BinaryLogs() {}
}

View File

@ -14,12 +14,12 @@
* limitations under the License.
*/
package io.grpc.services;
package io.grpc.protobuf.services;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
import static io.grpc.services.BinaryLogProvider.BYTEARRAY_MARSHALLER;
import static io.grpc.protobuf.services.BinaryLogProvider.BYTEARRAY_MARSHALLER;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Charsets;

View File

@ -14,7 +14,7 @@
* limitations under the License.
*/
package io.grpc.services;
package io.grpc.protobuf.services;
import com.google.common.base.Preconditions;
import com.google.common.util.concurrent.ListenableFuture;

View File

@ -0,0 +1,234 @@
/*
* Copyright 2018 The gRPC Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.grpc.protobuf.services;
import com.google.common.annotations.VisibleForTesting;
import io.grpc.ExperimentalApi;
import io.grpc.InternalChannelz;
import io.grpc.InternalChannelz.ChannelStats;
import io.grpc.InternalChannelz.ServerList;
import io.grpc.InternalChannelz.ServerSocketsList;
import io.grpc.InternalChannelz.ServerStats;
import io.grpc.InternalChannelz.SocketStats;
import io.grpc.InternalInstrumented;
import io.grpc.Status;
import io.grpc.StatusRuntimeException;
import io.grpc.channelz.v1.ChannelzGrpc;
import io.grpc.channelz.v1.GetChannelRequest;
import io.grpc.channelz.v1.GetChannelResponse;
import io.grpc.channelz.v1.GetServerRequest;
import io.grpc.channelz.v1.GetServerResponse;
import io.grpc.channelz.v1.GetServerSocketsRequest;
import io.grpc.channelz.v1.GetServerSocketsResponse;
import io.grpc.channelz.v1.GetServersRequest;
import io.grpc.channelz.v1.GetServersResponse;
import io.grpc.channelz.v1.GetSocketRequest;
import io.grpc.channelz.v1.GetSocketResponse;
import io.grpc.channelz.v1.GetSubchannelRequest;
import io.grpc.channelz.v1.GetSubchannelResponse;
import io.grpc.channelz.v1.GetTopChannelsRequest;
import io.grpc.channelz.v1.GetTopChannelsResponse;
import io.grpc.stub.StreamObserver;
/**
* The channelz service provides stats about a running gRPC process.
*/
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/4206")
public final class ChannelzService extends ChannelzGrpc.ChannelzImplBase {
private final InternalChannelz channelz;
private final int maxPageSize;
/**
* Creates an instance.
*/
public static ChannelzService newInstance(int maxPageSize) {
return new ChannelzService(InternalChannelz.instance(), maxPageSize);
}
@VisibleForTesting
ChannelzService(InternalChannelz channelz, int maxPageSize) {
this.channelz = channelz;
this.maxPageSize = maxPageSize;
}
/** Returns top level channel aka {@link io.grpc.ManagedChannel}. */
@Override
public void getTopChannels(
GetTopChannelsRequest request, StreamObserver<GetTopChannelsResponse> responseObserver) {
InternalChannelz.RootChannelList rootChannels
= channelz.getRootChannels(request.getStartChannelId(), maxPageSize);
GetTopChannelsResponse resp;
try {
resp = ChannelzProtoUtil.toGetTopChannelResponse(rootChannels);
} catch (StatusRuntimeException e) {
responseObserver.onError(e);
return;
}
responseObserver.onNext(resp);
responseObserver.onCompleted();
}
/** Returns a top level channel aka {@link io.grpc.ManagedChannel}. */
@Override
public void getChannel(
GetChannelRequest request, StreamObserver<GetChannelResponse> responseObserver) {
InternalInstrumented<ChannelStats> s = channelz.getRootChannel(request.getChannelId());
if (s == null) {
responseObserver.onError(
Status.NOT_FOUND.withDescription("Can't find channel " + request.getChannelId())
.asRuntimeException());
return;
}
GetChannelResponse resp;
try {
resp = GetChannelResponse
.newBuilder()
.setChannel(ChannelzProtoUtil.toChannel(s))
.build();
} catch (StatusRuntimeException e) {
responseObserver.onError(e);
return;
}
responseObserver.onNext(resp);
responseObserver.onCompleted();
}
/** Returns servers. */
@Override
public void getServers(
GetServersRequest request, StreamObserver<GetServersResponse> responseObserver) {
ServerList servers = channelz.getServers(request.getStartServerId(), maxPageSize);
GetServersResponse resp;
try {
resp = ChannelzProtoUtil.toGetServersResponse(servers);
} catch (StatusRuntimeException e) {
responseObserver.onError(e);
return;
}
responseObserver.onNext(resp);
responseObserver.onCompleted();
}
/** Returns a server. */
@Override
public void getServer(
GetServerRequest request, StreamObserver<GetServerResponse> responseObserver) {
InternalInstrumented<ServerStats> s = channelz.getServer(request.getServerId());
if (s == null) {
responseObserver.onError(
Status.NOT_FOUND.withDescription("Can't find server " + request.getServerId())
.asRuntimeException());
return;
}
GetServerResponse resp;
try {
resp = GetServerResponse
.newBuilder()
.setServer(ChannelzProtoUtil.toServer(s))
.build();
} catch (StatusRuntimeException e) {
responseObserver.onError(e);
return;
}
responseObserver.onNext(resp);
responseObserver.onCompleted();
}
/** Returns a subchannel. */
@Override
public void getSubchannel(
GetSubchannelRequest request, StreamObserver<GetSubchannelResponse> responseObserver) {
InternalInstrumented<ChannelStats> s = channelz.getSubchannel(request.getSubchannelId());
if (s == null) {
responseObserver.onError(
Status.NOT_FOUND.withDescription("Can't find subchannel " + request.getSubchannelId())
.asRuntimeException());
return;
}
GetSubchannelResponse resp;
try {
resp = GetSubchannelResponse
.newBuilder()
.setSubchannel(ChannelzProtoUtil.toSubchannel(s))
.build();
} catch (StatusRuntimeException e) {
responseObserver.onError(e);
return;
}
responseObserver.onNext(resp);
responseObserver.onCompleted();
}
/** Returns a socket. */
@Override
public void getSocket(
GetSocketRequest request, StreamObserver<GetSocketResponse> responseObserver) {
InternalInstrumented<SocketStats> s = channelz.getSocket(request.getSocketId());
if (s == null) {
responseObserver.onError(
Status.NOT_FOUND.withDescription("Can't find socket " + request.getSocketId())
.asRuntimeException());
return;
}
GetSocketResponse resp;
try {
resp =
GetSocketResponse.newBuilder().setSocket(ChannelzProtoUtil.toSocket(s)).build();
} catch (StatusRuntimeException e) {
responseObserver.onError(e);
return;
}
responseObserver.onNext(resp);
responseObserver.onCompleted();
}
@Override
public void getServerSockets(
GetServerSocketsRequest request, StreamObserver<GetServerSocketsResponse> responseObserver) {
ServerSocketsList serverSockets
= channelz.getServerSockets(request.getServerId(), request.getStartSocketId(), maxPageSize);
if (serverSockets == null) {
responseObserver.onError(
Status.NOT_FOUND.withDescription("Can't find server " + request.getServerId())
.asRuntimeException());
return;
}
GetServerSocketsResponse resp;
try {
resp = ChannelzProtoUtil.toGetServerSocketsResponse(serverSockets);
} catch (StatusRuntimeException e) {
responseObserver.onError(e);
return;
}
responseObserver.onNext(resp);
responseObserver.onCompleted();
}
}

View File

@ -14,7 +14,7 @@
* limitations under the License.
*/
package io.grpc.services;
package io.grpc.protobuf.services;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;

View File

@ -14,7 +14,7 @@
* limitations under the License.
*/
package io.grpc.services;
package io.grpc.protobuf.services;
import io.grpc.ExperimentalApi;
import io.grpc.LoadBalancer;

View File

@ -14,7 +14,7 @@
* limitations under the License.
*/
package io.grpc.services;
package io.grpc.protobuf.services;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.util.concurrent.MoreExecutors;

View File

@ -0,0 +1,89 @@
/*
* Copyright 2016 The gRPC Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.grpc.protobuf.services;
import static com.google.common.base.Preconditions.checkNotNull;
import io.grpc.BindableService;
import io.grpc.health.v1.HealthCheckResponse.ServingStatus;
/**
* A {@code HealthStatusManager} object manages a health check service. A health check service is
* created in the constructor of {@code HealthStatusManager}, and it can be retrieved by the
* {@link #getHealthService()} method.
* The health status manager can update the health statuses of the server.
*
* <p>The default, empty-string, service name, {@link #SERVICE_NAME_ALL_SERVICES}, is initialized to
* {@link ServingStatus#SERVING}.
*/
@io.grpc.ExperimentalApi("https://github.com/grpc/grpc-java/issues/4696")
public final class HealthStatusManager {
/**
* The special "service name" that represent all services on a GRPC server. It is an empty
* string.
*/
public static final String SERVICE_NAME_ALL_SERVICES = "";
private final HealthServiceImpl healthService;
/**
* Creates a new health service instance.
*/
public HealthStatusManager() {
healthService = new HealthServiceImpl();
}
/**
* Gets the health check service created in the constructor.
*/
public BindableService getHealthService() {
return healthService;
}
/**
* Updates the status of the server.
* @param service the name of some aspect of the server that is associated with a health status.
* This name can have no relation with the gRPC services that the server is running with.
* It can also be an empty String {@code ""} per the gRPC specification.
* @param status is one of the values {@link ServingStatus#SERVING},
* {@link ServingStatus#NOT_SERVING} and {@link ServingStatus#UNKNOWN}.
*/
public void setStatus(String service, ServingStatus status) {
checkNotNull(status, "status");
healthService.setStatus(service, status);
}
/**
* Clears the health status record of a service. The health service will respond with NOT_FOUND
* error on checking the status of a cleared service.
* @param service the name of some aspect of the server that is associated with a health status.
* This name can have no relation with the gRPC services that the server is running with.
* It can also be an empty String {@code ""} per the gRPC specification.
*/
public void clearStatus(String service) {
healthService.clearStatus(service);
}
/**
* enterTerminalState causes the health status manager to mark all services as not serving, and
* prevents future updates to services. This method is meant to be called prior to server
* shutdown as a way to indicate that clients should redirect their traffic elsewhere.
*/
public void enterTerminalState() {
healthService.enterTerminalState();
}
}

View File

@ -14,7 +14,7 @@
* limitations under the License.
*/
package io.grpc.services;
package io.grpc.protobuf.services;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
@ -91,4 +91,4 @@ final class InetAddressUtil {
}
return buf.toString();
}
}
}

View File

@ -14,7 +14,7 @@
* limitations under the License.
*/
package io.grpc.services;
package io.grpc.protobuf.services;
import com.google.protobuf.MessageLite;
import java.io.BufferedOutputStream;

View File

@ -14,7 +14,7 @@
* limitations under the License.
*/
package io.grpc.services.internal;
package io.grpc.protobuf.services.internal;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Throwables;
@ -23,7 +23,7 @@ import io.grpc.LoadBalancer;
import io.grpc.LoadBalancer.Helper;
import io.grpc.LoadBalancerProvider;
import io.grpc.NameResolver.ConfigOrError;
import io.grpc.services.HealthCheckingLoadBalancerUtil;
import io.grpc.protobuf.services.HealthCheckingLoadBalancerUtil;
import java.util.Map;
/**

View File

@ -0,0 +1,20 @@
/*
* Copyright 2020 The gRPC Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Service definitions and utilities with protobuf dependency for the pre-defined gRPC services.
*/
package io.grpc.protobuf.services;

View File

@ -19,6 +19,7 @@ package io.grpc.services;
import io.grpc.BindableService;
import io.grpc.ExperimentalApi;
import io.grpc.ServerServiceDefinition;
import io.grpc.protobuf.services.ChannelzService;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;

View File

@ -18,8 +18,13 @@ package io.grpc.services;
import io.grpc.BinaryLog;
import io.grpc.ExperimentalApi;
import io.grpc.protobuf.services.BinaryLogSink;
import java.io.IOException;
/**
* @deprecated Use {@link io.grpc.protobuf.services.BinaryLogs} instead.
*/
@Deprecated
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/4017")
public final class BinaryLogs {
/**
@ -28,7 +33,7 @@ public final class BinaryLogs {
* up.
*/
public static BinaryLog createBinaryLog() throws IOException {
return new BinaryLogProviderImpl();
return io.grpc.protobuf.services.BinaryLogs.createBinaryLog();
}
/**
@ -36,7 +41,7 @@ public final class BinaryLogs {
*/
@Deprecated
public static BinaryLog createBinaryLog(BinaryLogSink sink) throws IOException {
return new BinaryLogProviderImpl(sink);
return io.grpc.protobuf.services.BinaryLogs.createBinaryLog(sink);
}
/**
@ -46,7 +51,7 @@ public final class BinaryLogs {
* A16-binary-logging</a>.
*/
public static BinaryLog createBinaryLog(BinaryLogSink sink, String configStr) throws IOException {
return new BinaryLogProviderImpl(sink, configStr);
return io.grpc.protobuf.services.BinaryLogs.createBinaryLog(sink, configStr);
}
private BinaryLogs() {}

View File

@ -16,17 +16,7 @@
package io.grpc.services;
import com.google.common.annotations.VisibleForTesting;
import io.grpc.ExperimentalApi;
import io.grpc.InternalChannelz;
import io.grpc.InternalChannelz.ChannelStats;
import io.grpc.InternalChannelz.ServerList;
import io.grpc.InternalChannelz.ServerSocketsList;
import io.grpc.InternalChannelz.ServerStats;
import io.grpc.InternalChannelz.SocketStats;
import io.grpc.InternalInstrumented;
import io.grpc.Status;
import io.grpc.StatusRuntimeException;
import io.grpc.channelz.v1.ChannelzGrpc;
import io.grpc.channelz.v1.GetChannelRequest;
import io.grpc.channelz.v1.GetChannelResponse;
@ -46,189 +36,70 @@ import io.grpc.stub.StreamObserver;
/**
* The channelz service provides stats about a running gRPC process.
*
* @deprecated Use {@link io.grpc.protobuf.services.ChannelzService} instead.
*/
@Deprecated
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/4206")
public final class ChannelzService extends ChannelzGrpc.ChannelzImplBase {
private final InternalChannelz channelz;
private final int maxPageSize;
private final io.grpc.protobuf.services.ChannelzService delegate;
/**
* Creates an instance.
*/
public static ChannelzService newInstance(int maxPageSize) {
return new ChannelzService(InternalChannelz.instance(), maxPageSize);
return new ChannelzService(maxPageSize);
}
@VisibleForTesting
ChannelzService(InternalChannelz channelz, int maxPageSize) {
this.channelz = channelz;
this.maxPageSize = maxPageSize;
private ChannelzService(int maxPageSize) {
delegate = io.grpc.protobuf.services.ChannelzService.newInstance(maxPageSize);
}
/** Returns top level channel aka {@link io.grpc.ManagedChannel}. */
@Override
public void getTopChannels(
GetTopChannelsRequest request, StreamObserver<GetTopChannelsResponse> responseObserver) {
InternalChannelz.RootChannelList rootChannels
= channelz.getRootChannels(request.getStartChannelId(), maxPageSize);
GetTopChannelsResponse resp;
try {
resp = ChannelzProtoUtil.toGetTopChannelResponse(rootChannels);
} catch (StatusRuntimeException e) {
responseObserver.onError(e);
return;
}
responseObserver.onNext(resp);
responseObserver.onCompleted();
delegate.getTopChannels(request, responseObserver);
}
/** Returns a top level channel aka {@link io.grpc.ManagedChannel}. */
@Override
public void getChannel(
GetChannelRequest request, StreamObserver<GetChannelResponse> responseObserver) {
InternalInstrumented<ChannelStats> s = channelz.getRootChannel(request.getChannelId());
if (s == null) {
responseObserver.onError(
Status.NOT_FOUND.withDescription("Can't find channel " + request.getChannelId())
.asRuntimeException());
return;
}
GetChannelResponse resp;
try {
resp = GetChannelResponse
.newBuilder()
.setChannel(ChannelzProtoUtil.toChannel(s))
.build();
} catch (StatusRuntimeException e) {
responseObserver.onError(e);
return;
}
responseObserver.onNext(resp);
responseObserver.onCompleted();
delegate.getChannel(request, responseObserver);
}
/** Returns servers. */
@Override
public void getServers(
GetServersRequest request, StreamObserver<GetServersResponse> responseObserver) {
ServerList servers = channelz.getServers(request.getStartServerId(), maxPageSize);
GetServersResponse resp;
try {
resp = ChannelzProtoUtil.toGetServersResponse(servers);
} catch (StatusRuntimeException e) {
responseObserver.onError(e);
return;
}
responseObserver.onNext(resp);
responseObserver.onCompleted();
delegate.getServers(request, responseObserver);
}
/** Returns a server. */
@Override
public void getServer(
GetServerRequest request, StreamObserver<GetServerResponse> responseObserver) {
InternalInstrumented<ServerStats> s = channelz.getServer(request.getServerId());
if (s == null) {
responseObserver.onError(
Status.NOT_FOUND.withDescription("Can't find server " + request.getServerId())
.asRuntimeException());
return;
}
GetServerResponse resp;
try {
resp = GetServerResponse
.newBuilder()
.setServer(ChannelzProtoUtil.toServer(s))
.build();
} catch (StatusRuntimeException e) {
responseObserver.onError(e);
return;
}
responseObserver.onNext(resp);
responseObserver.onCompleted();
delegate.getServer(request, responseObserver);
}
/** Returns a subchannel. */
@Override
public void getSubchannel(
GetSubchannelRequest request, StreamObserver<GetSubchannelResponse> responseObserver) {
InternalInstrumented<ChannelStats> s = channelz.getSubchannel(request.getSubchannelId());
if (s == null) {
responseObserver.onError(
Status.NOT_FOUND.withDescription("Can't find subchannel " + request.getSubchannelId())
.asRuntimeException());
return;
}
GetSubchannelResponse resp;
try {
resp = GetSubchannelResponse
.newBuilder()
.setSubchannel(ChannelzProtoUtil.toSubchannel(s))
.build();
} catch (StatusRuntimeException e) {
responseObserver.onError(e);
return;
}
responseObserver.onNext(resp);
responseObserver.onCompleted();
delegate.getSubchannel(request, responseObserver);
}
/** Returns a socket. */
@Override
public void getSocket(
GetSocketRequest request, StreamObserver<GetSocketResponse> responseObserver) {
InternalInstrumented<SocketStats> s = channelz.getSocket(request.getSocketId());
if (s == null) {
responseObserver.onError(
Status.NOT_FOUND.withDescription("Can't find socket " + request.getSocketId())
.asRuntimeException());
return;
}
GetSocketResponse resp;
try {
resp =
GetSocketResponse.newBuilder().setSocket(ChannelzProtoUtil.toSocket(s)).build();
} catch (StatusRuntimeException e) {
responseObserver.onError(e);
return;
}
responseObserver.onNext(resp);
responseObserver.onCompleted();
delegate.getSocket(request, responseObserver);
}
@Override
public void getServerSockets(
GetServerSocketsRequest request, StreamObserver<GetServerSocketsResponse> responseObserver) {
ServerSocketsList serverSockets
= channelz.getServerSockets(request.getServerId(), request.getStartSocketId(), maxPageSize);
if (serverSockets == null) {
responseObserver.onError(
Status.NOT_FOUND.withDescription("Can't find server " + request.getServerId())
.asRuntimeException());
return;
}
GetServerSocketsResponse resp;
try {
resp = ChannelzProtoUtil.toGetServerSocketsResponse(serverSockets);
} catch (StatusRuntimeException e) {
responseObserver.onError(e);
return;
}
responseObserver.onNext(resp);
responseObserver.onCompleted();
delegate.getServerSockets(request, responseObserver);
}
}

View File

@ -16,8 +16,6 @@
package io.grpc.services;
import static com.google.common.base.Preconditions.checkNotNull;
import io.grpc.BindableService;
import io.grpc.health.v1.HealthCheckResponse.ServingStatus;
@ -29,29 +27,33 @@ import io.grpc.health.v1.HealthCheckResponse.ServingStatus;
*
* <p>The default, empty-string, service name, {@link #SERVICE_NAME_ALL_SERVICES}, is initialized to
* {@link ServingStatus#SERVING}.
*
* @deprecated Use {@link io.grpc.protobuf.services.HealthStatusManager} instead.
*/
@Deprecated
@io.grpc.ExperimentalApi("https://github.com/grpc/grpc-java/issues/4696")
public final class HealthStatusManager {
/**
* The special "service name" that represent all services on a GRPC server. It is an empty
* string.
*/
public static final String SERVICE_NAME_ALL_SERVICES = "";
public static final String SERVICE_NAME_ALL_SERVICES =
io.grpc.protobuf.services.HealthStatusManager.SERVICE_NAME_ALL_SERVICES;
private final HealthServiceImpl healthService;
private io.grpc.protobuf.services.HealthStatusManager delegate;
/**
* Creates a new health service instance.
*/
public HealthStatusManager() {
healthService = new HealthServiceImpl();
delegate = new io.grpc.protobuf.services.HealthStatusManager();
}
/**
* Gets the health check service created in the constructor.
*/
public BindableService getHealthService() {
return healthService;
return delegate.getHealthService();
}
/**
@ -63,8 +65,7 @@ public final class HealthStatusManager {
* {@link ServingStatus#NOT_SERVING} and {@link ServingStatus#UNKNOWN}.
*/
public void setStatus(String service, ServingStatus status) {
checkNotNull(status, "status");
healthService.setStatus(service, status);
delegate.setStatus(service, status);
}
/**
@ -75,7 +76,7 @@ public final class HealthStatusManager {
* It can also be an empty String {@code ""} per the gRPC specification.
*/
public void clearStatus(String service) {
healthService.clearStatus(service);
delegate.clearStatus(service);
}
/**
@ -84,6 +85,6 @@ public final class HealthStatusManager {
* shutdown as a way to indicate that clients should redirect their traffic elsewhere.
*/
public void enterTerminalState() {
healthService.enterTerminalState();
delegate.enterTerminalState();
}
}

View File

@ -14,6 +14,8 @@
* limitations under the License.
*/
// TODO(chengyuanzhang): update description after deleting classes with protobuf dependency that
// have already been moved.
/**
* Service definitions and utilities for the pre-defined gRPC services.
*/

View File

@ -1 +1 @@
io.grpc.services.internal.HealthCheckingRoundRobinLoadBalancerProvider
io.grpc.protobuf.services.internal.HealthCheckingRoundRobinLoadBalancerProvider

View File

@ -14,7 +14,7 @@
* limitations under the License.
*/
package io.grpc.services;
package io.grpc.protobuf.services;
import static org.junit.Assert.assertNull;
import static org.mockito.Mockito.mock;

View File

@ -14,7 +14,7 @@
* limitations under the License.
*/
package io.grpc.services;
package io.grpc.protobuf.services;
import static com.google.common.base.Charsets.UTF_8;
import static com.google.common.truth.Truth.assertThat;

View File

@ -14,12 +14,12 @@
* limitations under the License.
*/
package io.grpc.services;
package io.grpc.protobuf.services;
import static com.google.common.truth.Truth.assertThat;
import static io.grpc.services.BinaryLogProvider.BYTEARRAY_MARSHALLER;
import static io.grpc.services.BinlogHelper.createMetadataProto;
import static io.grpc.services.BinlogHelper.getPeerSocket;
import static io.grpc.protobuf.services.BinaryLogProvider.BYTEARRAY_MARSHALLER;
import static io.grpc.protobuf.services.BinlogHelper.createMetadataProto;
import static io.grpc.protobuf.services.BinlogHelper.getPeerSocket;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
@ -70,11 +70,11 @@ import io.grpc.binarylog.v1.Trailer;
import io.grpc.internal.NoopClientCall;
import io.grpc.internal.NoopServerCall;
import io.grpc.protobuf.StatusProto;
import io.grpc.services.BinlogHelper.FactoryImpl;
import io.grpc.services.BinlogHelper.MaybeTruncated;
import io.grpc.services.BinlogHelper.SinkWriter;
import io.grpc.services.BinlogHelper.SinkWriterImpl;
import io.grpc.services.BinlogHelper.TimeProvider;
import io.grpc.protobuf.services.BinlogHelper.FactoryImpl;
import io.grpc.protobuf.services.BinlogHelper.MaybeTruncated;
import io.grpc.protobuf.services.BinlogHelper.SinkWriter;
import io.grpc.protobuf.services.BinlogHelper.SinkWriterImpl;
import io.grpc.protobuf.services.BinlogHelper.TimeProvider;
import io.netty.channel.unix.DomainSocketAddress;
import java.net.InetAddress;
import java.net.InetSocketAddress;

View File

@ -14,7 +14,7 @@
* limitations under the License.
*/
package io.grpc.services;
package io.grpc.protobuf.services;
import static com.google.common.truth.Truth.assertThat;
import static io.grpc.InternalChannelz.id;
@ -74,10 +74,10 @@ import io.grpc.channelz.v1.SocketOptionTimeout;
import io.grpc.channelz.v1.SocketRef;
import io.grpc.channelz.v1.Subchannel;
import io.grpc.channelz.v1.SubchannelRef;
import io.grpc.services.ChannelzTestHelper.TestChannel;
import io.grpc.services.ChannelzTestHelper.TestListenSocket;
import io.grpc.services.ChannelzTestHelper.TestServer;
import io.grpc.services.ChannelzTestHelper.TestSocket;
import io.grpc.protobuf.services.ChannelzTestHelper.TestChannel;
import io.grpc.protobuf.services.ChannelzTestHelper.TestListenSocket;
import io.grpc.protobuf.services.ChannelzTestHelper.TestServer;
import io.grpc.protobuf.services.ChannelzTestHelper.TestSocket;
import io.netty.channel.unix.DomainSocketAddress;
import java.net.Inet4Address;
import java.net.InetSocketAddress;

View File

@ -14,7 +14,7 @@
* limitations under the License.
*/
package io.grpc.services;
package io.grpc.protobuf.services;
import static com.google.common.truth.Truth.assertWithMessage;
import static org.junit.Assert.assertEquals;
@ -35,9 +35,9 @@ import io.grpc.channelz.v1.GetSubchannelRequest;
import io.grpc.channelz.v1.GetSubchannelResponse;
import io.grpc.channelz.v1.GetTopChannelsRequest;
import io.grpc.channelz.v1.GetTopChannelsResponse;
import io.grpc.services.ChannelzTestHelper.TestChannel;
import io.grpc.services.ChannelzTestHelper.TestServer;
import io.grpc.services.ChannelzTestHelper.TestSocket;
import io.grpc.protobuf.services.ChannelzTestHelper.TestChannel;
import io.grpc.protobuf.services.ChannelzTestHelper.TestServer;
import io.grpc.protobuf.services.ChannelzTestHelper.TestSocket;
import io.grpc.stub.StreamObserver;
import java.util.concurrent.ExecutionException;
import org.junit.Test;

View File

@ -14,7 +14,7 @@
* limitations under the License.
*/
package io.grpc.services;
package io.grpc.protobuf.services;
import com.google.common.base.MoreObjects;
import com.google.common.util.concurrent.ListenableFuture;

View File

@ -14,7 +14,7 @@
* limitations under the License.
*/
package io.grpc.services;
package io.grpc.protobuf.services;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
@ -68,7 +68,7 @@ import io.grpc.inprocess.InProcessServerBuilder;
import io.grpc.internal.BackoffPolicy;
import io.grpc.internal.FakeClock;
import io.grpc.internal.ServiceConfigUtil;
import io.grpc.services.HealthCheckingLoadBalancerFactory.SubchannelImpl;
import io.grpc.protobuf.services.HealthCheckingLoadBalancerFactory.SubchannelImpl;
import io.grpc.stub.StreamObserver;
import java.net.SocketAddress;
import java.text.MessageFormat;

View File

@ -14,7 +14,7 @@
* limitations under the License.
*/
package io.grpc.services;
package io.grpc.protobuf.services;
import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.fail;

View File

@ -14,11 +14,12 @@
* limitations under the License.
*/
package io.grpc.services;
package io.grpc.protobuf.services;
import static org.junit.Assert.assertEquals;
import io.grpc.binarylog.v1.GrpcLogEntry;
import io.grpc.protobuf.services.TempFileSink;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.IOException;
@ -27,7 +28,7 @@ import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
/**
* Tests for {@link io.grpc.services.TempFileSink}.
* Tests for {@link TempFileSink}.
*/
@RunWith(JUnit4.class)
public class TempFileSinkTest {

View File

@ -14,7 +14,7 @@
* limitations under the License.
*/
package io.grpc.services.internal;
package io.grpc.protobuf.services.internal;
import static com.google.common.truth.Truth.assertThat;
@ -25,7 +25,7 @@ import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
/**
* Tests for {@link InternalHealthCheckingRoundRobinLoadBalancerProvider}.
* Tests for {@link HealthCheckingRoundRobinLoadBalancerProvider}.
*/
@RunWith(JUnit4.class)
public class HealthCheckingRoundRobinLoadBalancerProviderTest {

View File

@ -24,7 +24,7 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
/** Tests for {@link BinlogHelper}. */
/** Tests for {@link CallMetricRecorder}. */
@RunWith(JUnit4.class)
public class CallMetricRecorderTest {