From 2bc23f1138546c11750272e530f810ad3aa44dc0 Mon Sep 17 00:00:00 2001 From: Yash Tibrewal Date: Wed, 25 Oct 2023 11:31:07 -0700 Subject: [PATCH] [xds] C++ XdsServerBuilder Remove src/... header dependency from public header (#34790) --- BUILD | 2 ++ CMakeLists.txt | 1 + build_autogenerated.yaml | 1 + gRPC-C++.podspec | 1 + grpc.gyp | 1 + include/grpcpp/xds_server_builder.h | 16 +---------- src/cpp/server/xds_server_builder.cc | 43 ++++++++++++++++++++++++++++ tools/doxygen/Doxyfile.c++.internal | 1 + 8 files changed, 51 insertions(+), 15 deletions(-) create mode 100644 src/cpp/server/xds_server_builder.cc diff --git a/BUILD b/BUILD index cdc1eb8aff8..b93d89d0892 100644 --- a/BUILD +++ b/BUILD @@ -1144,6 +1144,7 @@ grpc_cc_library( grpc_cc_library( name = "grpc++_xds_server", srcs = [ + "src/cpp/server/xds_server_builder.cc", "src/cpp/server/xds_server_credentials.cc", ], hdrs = [ @@ -1155,6 +1156,7 @@ grpc_cc_library( ], visibility = ["@grpc:xds"], deps = [ + "channel_arg_names", "gpr", "grpc", "grpc++_base", diff --git a/CMakeLists.txt b/CMakeLists.txt index c7ca8122e2d..278adc9fb98 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3895,6 +3895,7 @@ add_library(grpc++ src/cpp/server/server_cc.cc src/cpp/server/server_context.cc src/cpp/server/server_posix.cc + src/cpp/server/xds_server_builder.cc src/cpp/server/xds_server_credentials.cc src/cpp/thread_manager/thread_manager.cc src/cpp/util/byte_buffer_cc.cc diff --git a/build_autogenerated.yaml b/build_autogenerated.yaml index 41d37ec8ee3..deba1f3005f 100644 --- a/build_autogenerated.yaml +++ b/build_autogenerated.yaml @@ -3656,6 +3656,7 @@ libs: - src/cpp/server/server_cc.cc - src/cpp/server/server_context.cc - src/cpp/server/server_posix.cc + - src/cpp/server/xds_server_builder.cc - src/cpp/server/xds_server_credentials.cc - src/cpp/thread_manager/thread_manager.cc - src/cpp/util/byte_buffer_cc.cc diff --git a/gRPC-C++.podspec b/gRPC-C++.podspec index cdb45f3ea47..567042b81c4 100644 --- a/gRPC-C++.podspec +++ b/gRPC-C++.podspec @@ -1181,6 +1181,7 @@ Pod::Spec.new do |s| 'src/cpp/server/server_context.cc', 'src/cpp/server/server_posix.cc', 'src/cpp/server/thread_pool_interface.h', + 'src/cpp/server/xds_server_builder.cc', 'src/cpp/server/xds_server_credentials.cc', 'src/cpp/thread_manager/thread_manager.cc', 'src/cpp/thread_manager/thread_manager.h', diff --git a/grpc.gyp b/grpc.gyp index 82e9a2e73cb..1eb5a1f7cca 100644 --- a/grpc.gyp +++ b/grpc.gyp @@ -1820,6 +1820,7 @@ 'src/cpp/server/server_cc.cc', 'src/cpp/server/server_context.cc', 'src/cpp/server/server_posix.cc', + 'src/cpp/server/xds_server_builder.cc', 'src/cpp/server/xds_server_credentials.cc', 'src/cpp/thread_manager/thread_manager.cc', 'src/cpp/util/byte_buffer_cc.cc', diff --git a/include/grpcpp/xds_server_builder.h b/include/grpcpp/xds_server_builder.h index ae560595df6..f51c5260788 100644 --- a/include/grpcpp/xds_server_builder.h +++ b/include/grpcpp/xds_server_builder.h @@ -23,8 +23,6 @@ #include -#include "src/core/ext/xds/xds_enabled_server.h" - namespace grpc { class XdsServerServingStatusNotifierInterface { @@ -81,19 +79,7 @@ class XdsServerBuilder : public grpc::ServerBuilder { private: // Called at the beginning of BuildAndStart(). - ChannelArguments BuildChannelArgs() override { - ChannelArguments args = ServerBuilder::BuildChannelArgs(); - if (drain_grace_time_ms_ >= 0) { - args.SetInt(GRPC_ARG_SERVER_CONFIG_CHANGE_DRAIN_GRACE_TIME_MS, - drain_grace_time_ms_); - } - args.SetInt(GRPC_ARG_XDS_ENABLED_SERVER, 1); - grpc_channel_args c_channel_args = args.c_channel_args(); - grpc_server_config_fetcher* fetcher = grpc_server_config_fetcher_xds_create( - {OnServingStatusUpdate, notifier_}, &c_channel_args); - if (fetcher != nullptr) set_fetcher(fetcher); - return args; - } + ChannelArguments BuildChannelArgs() override; static void OnServingStatusUpdate(void* user_data, const char* uri, grpc_serving_status_update update) { diff --git a/src/cpp/server/xds_server_builder.cc b/src/cpp/server/xds_server_builder.cc new file mode 100644 index 00000000000..37dc6e2259b --- /dev/null +++ b/src/cpp/server/xds_server_builder.cc @@ -0,0 +1,43 @@ +// +// +// Copyright 2023 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. +// +// + +#include +#include +#include +#include +#include + +#include "src/core/ext/xds/xds_enabled_server.h" + +namespace grpc { + +ChannelArguments XdsServerBuilder::BuildChannelArgs() { + ChannelArguments args = ServerBuilder::BuildChannelArgs(); + if (drain_grace_time_ms_ >= 0) { + args.SetInt(GRPC_ARG_SERVER_CONFIG_CHANGE_DRAIN_GRACE_TIME_MS, + drain_grace_time_ms_); + } + args.SetInt(GRPC_ARG_XDS_ENABLED_SERVER, 1); + grpc_channel_args c_channel_args = args.c_channel_args(); + grpc_server_config_fetcher* fetcher = grpc_server_config_fetcher_xds_create( + {OnServingStatusUpdate, notifier_}, &c_channel_args); + if (fetcher != nullptr) set_fetcher(fetcher); + return args; +} + +} // namespace grpc diff --git a/tools/doxygen/Doxyfile.c++.internal b/tools/doxygen/Doxyfile.c++.internal index cfc6a42af83..d8fa3fdab89 100644 --- a/tools/doxygen/Doxyfile.c++.internal +++ b/tools/doxygen/Doxyfile.c++.internal @@ -2841,6 +2841,7 @@ src/cpp/server/server_cc.cc \ src/cpp/server/server_context.cc \ src/cpp/server/server_posix.cc \ src/cpp/server/thread_pool_interface.h \ +src/cpp/server/xds_server_builder.cc \ src/cpp/server/xds_server_credentials.cc \ src/cpp/thread_manager/thread_manager.cc \ src/cpp/thread_manager/thread_manager.h \