lib/service_config/service_config_parser.cc
Go to the documentation of this file.
1 //
2 // Copyright 2015 gRPC authors.
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16 
18 
20 
21 #include <stdlib.h>
22 
23 #include <string>
24 
25 #include "absl/strings/str_cat.h"
26 
27 #include <grpc/support/log.h>
28 
29 namespace grpc_core {
30 
33 }
34 
36  std::unique_ptr<Parser> parser) {
37  for (const auto& registered_parser : registered_parsers_) {
38  if (registered_parser->name() == parser->name()) {
39  gpr_log(GPR_ERROR, "%s",
40  absl::StrCat("Parser with name '", parser->name(),
41  "' already registered")
42  .c_str());
43  // We'll otherwise crash later.
44  abort();
45  }
46  }
47  registered_parsers_.emplace_back(std::move(parser));
48 }
49 
52  const Json& json,
53  grpc_error_handle* error) const {
54  ParsedConfigVector parsed_global_configs;
55  std::vector<grpc_error_handle> error_list;
56  for (size_t i = 0; i < registered_parsers_.size(); i++) {
57  grpc_error_handle parser_error = GRPC_ERROR_NONE;
58  auto parsed_config =
59  registered_parsers_[i]->ParseGlobalParams(args, json, &parser_error);
60  if (!GRPC_ERROR_IS_NONE(parser_error)) {
61  error_list.push_back(parser_error);
62  }
63  parsed_global_configs.push_back(std::move(parsed_config));
64  }
65  if (!error_list.empty()) {
66  *error = GRPC_ERROR_CREATE_FROM_VECTOR("Global Params", &error_list);
67  }
68  return parsed_global_configs;
69 }
70 
73  const Json& json,
74  grpc_error_handle* error) const {
75  ParsedConfigVector parsed_method_configs;
76  std::vector<grpc_error_handle> error_list;
77  for (size_t i = 0; i < registered_parsers_.size(); ++i) {
78  grpc_error_handle parser_error = GRPC_ERROR_NONE;
79  auto parsed_config =
80  registered_parsers_[i]->ParsePerMethodParams(args, json, &parser_error);
81  if (!GRPC_ERROR_IS_NONE(parser_error)) {
82  error_list.push_back(parser_error);
83  }
84  parsed_method_configs.push_back(std::move(parsed_config));
85  }
86  if (!error_list.empty()) {
87  *error = GRPC_ERROR_CREATE_FROM_VECTOR("methodConfig", &error_list);
88  }
89  return parsed_method_configs;
90 }
91 
93  for (size_t i = 0; i < registered_parsers_.size(); ++i) {
94  if (registered_parsers_[i]->name() == name) return i;
95  }
96  return -1;
97 }
98 
99 } // namespace grpc_core
GRPC_ERROR_NONE
#define GRPC_ERROR_NONE
Definition: error.h:234
log.h
absl::StrCat
std::string StrCat(const AlphaNum &a, const AlphaNum &b)
Definition: abseil-cpp/absl/strings/str_cat.cc:98
grpc_core
Definition: call_metric_recorder.h:31
absl::string_view
Definition: abseil-cpp/absl/strings/string_view.h:167
error
grpc_error_handle error
Definition: retry_filter.cc:499
grpc_core::ServiceConfigParser::Builder::Build
ServiceConfigParser Build()
Definition: lib/service_config/service_config_parser.cc:31
grpc_core::ServiceConfigParser::ParsedConfigVector
std::vector< std::unique_ptr< ParsedConfig > > ParsedConfigVector
Definition: lib/service_config/service_config_parser.h:77
setup.name
name
Definition: setup.py:542
grpc_channel_args
Definition: grpc_types.h:132
GRPC_ERROR_CREATE_FROM_VECTOR
#define GRPC_ERROR_CREATE_FROM_VECTOR(desc, error_list)
Definition: error.h:314
asyncio_get_stats.parser
parser
Definition: asyncio_get_stats.py:34
asyncio_get_stats.args
args
Definition: asyncio_get_stats.py:40
absl::move
constexpr absl::remove_reference_t< T > && move(T &&t) noexcept
Definition: abseil-cpp/absl/utility/utility.h:221
grpc_core::ServiceConfigParser
Definition: lib/service_config/service_config_parser.h:41
Json
JSON (JavaScript Object Notation).
Definition: third_party/bloaty/third_party/protobuf/conformance/third_party/jsoncpp/json.h:227
gpr_log
GPRAPI void gpr_log(const char *file, int line, gpr_log_severity severity, const char *format,...) GPR_PRINT_FORMAT_CHECK(4
grpc_core::ServiceConfigParser::GetParserIndex
size_t GetParserIndex(absl::string_view name) const
Definition: lib/service_config/service_config_parser.cc:92
grpc_core::ServiceConfigParser::Builder::RegisterParser
void RegisterParser(std::unique_ptr< Parser > parser)
Definition: lib/service_config/service_config_parser.cc:35
GPR_ERROR
#define GPR_ERROR
Definition: include/grpc/impl/codegen/log.h:57
service_config_parser.h
grpc_core::ServiceConfigParser::Builder::registered_parsers_
ServiceConfigParserList registered_parsers_
Definition: lib/service_config/service_config_parser.h:90
grpc_core::ServiceConfigParser::ParseGlobalParameters
ParsedConfigVector ParseGlobalParameters(const grpc_channel_args *args, const Json &json, grpc_error_handle *error) const
Definition: lib/service_config/service_config_parser.cc:51
grpc_error
Definition: error_internal.h:42
grpc_core::ServiceConfigParser::registered_parsers_
ServiceConfigParserList registered_parsers_
Definition: lib/service_config/service_config_parser.h:108
i
uint64_t i
Definition: abseil-cpp/absl/container/btree_benchmark.cc:230
grpc_core::ServiceConfigParser::ServiceConfigParser
ServiceConfigParser(ServiceConfigParserList registered_parsers)
Definition: lib/service_config/service_config_parser.h:106
grpc_core::ServiceConfigParser::ParsePerMethodParameters
ParsedConfigVector ParsePerMethodParameters(const grpc_channel_args *args, const Json &json, grpc_error_handle *error) const
Definition: lib/service_config/service_config_parser.cc:72
GRPC_ERROR_IS_NONE
#define GRPC_ERROR_IS_NONE(err)
Definition: error.h:241
port_platform.h


grpc
Author(s):
autogenerated on Fri May 16 2025 03:00:12