Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 21 commits into from Apr 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
3375c1d
Move classes having protobuf dependency in io.grpc.services into io.g…
voidzcy Apr 7, 2021
2f5eb30
Migrate xds interop server's usage for HealthStatusManager.
voidzcy Apr 7, 2021
0436117
Creata a forwarding class for HealthCheckingLoadBalancerUtil to allow…
voidzcy Apr 7, 2021
d677c84
Merge branch 'master' of github.com:grpc/grpc-java into impl/clean_up…
voidzcy Apr 13, 2021
d8412ab
Keep channelz and binlog implementations in-place, while mark them as…
voidzcy Apr 13, 2021
c402bf9
Forward ProtoReflectionService.
voidzcy Apr 13, 2021
9989179
Fix bazel build.
voidzcy Apr 13, 2021
15fb5fc
Clean up package-info.java in services/protobuf.services.
voidzcy Apr 13, 2021
851628c
Keep tests for channelz and binlog implementations, as they are kept …
voidzcy Apr 13, 2021
b6a5c18
Restore unnecessary changes.
voidzcy Apr 15, 2021
c505f40
Change to forwarding by inheritance instead of by delegating.
voidzcy Apr 16, 2021
a9ce138
Forward with delegation, delete necessary abstract class forwarding.
voidzcy Apr 16, 2021
b592d20
Clean up bazel.
voidzcy Apr 16, 2021
1951bc2
Fix style.
voidzcy Apr 16, 2021
ba9fb8d
Do not extend public interface that is already accessible.
voidzcy Apr 16, 2021
6477050
Statically import constant.
voidzcy Apr 16, 2021
3f4dd94
Reestore excessive empty line change.
voidzcy Apr 16, 2021
1f5dcba
Fix interface reference.
voidzcy Apr 16, 2021
4dae3bb
Empty line.
voidzcy Apr 16, 2021
de38d17
Delete all unnecessary classes.
voidzcy Apr 16, 2021
0c282c1
Clean up bazel.
voidzcy Apr 16, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -30,9 +30,9 @@
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;
Expand Down
18 changes: 10 additions & 8 deletions services/BUILD.bazel
Expand Up @@ -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",
Expand All @@ -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 = [
Expand Down Expand Up @@ -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 = [
Expand Down
Expand Up @@ -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;
Expand Down
Expand Up @@ -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;
Expand Down
Expand Up @@ -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;
Expand Down
53 changes: 53 additions & 0 deletions services/src/main/java/io/grpc/protobuf/services/BinaryLogs.java
@@ -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() {}
}
Expand Up @@ -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;
Expand Down
Expand Up @@ -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;
Expand Down
234 changes: 234 additions & 0 deletions services/src/main/java/io/grpc/protobuf/services/ChannelzService.java
@@ -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();
}
}
Expand Up @@ -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;
Expand Down