• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright 2018 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 
17 #include "src/core/xds/grpc/xds_cluster.h"
18 
19 #include "absl/strings/str_cat.h"
20 #include "absl/strings/str_join.h"
21 #include "src/core/util/json/json_writer.h"
22 #include "src/core/util/match.h"
23 #include "src/core/util/time.h"
24 #include "src/core/xds/grpc/xds_common_types.h"
25 
26 namespace grpc_core {
27 
ToString() const28 std::string XdsClusterResource::ToString() const {
29   std::vector<std::string> contents;
30   Match(
31       type,
32       [&](const Eds& eds) {
33         contents.push_back("type=EDS");
34         if (!eds.eds_service_name.empty()) {
35           contents.push_back(
36               absl::StrCat("eds_service_name=", eds.eds_service_name));
37         }
38       },
39       [&](const LogicalDns& logical_dns) {
40         contents.push_back("type=LOGICAL_DNS");
41         contents.push_back(absl::StrCat("dns_hostname=", logical_dns.hostname));
42       },
43       [&](const Aggregate& aggregate) {
44         contents.push_back("type=AGGREGATE");
45         contents.push_back(absl::StrCat(
46             "prioritized_cluster_names=[",
47             absl::StrJoin(aggregate.prioritized_cluster_names, ", "), "]"));
48       });
49   contents.push_back(absl::StrCat("lb_policy_config=",
50                                   JsonDump(Json::FromArray(lb_policy_config))));
51   if (lrs_load_reporting_server != nullptr) {
52     contents.push_back(absl::StrCat("lrs_load_reporting_server_name=",
53                                     lrs_load_reporting_server->server_uri()));
54   }
55   if (lrs_backend_metric_propagation != nullptr) {
56     contents.push_back(
57         absl::StrCat("lrs_backend_metric_propagation=",
58                      lrs_backend_metric_propagation->AsString()));
59   }
60   if (use_http_connect) contents.push_back("use_http_connect=true");
61   if (!common_tls_context.Empty()) {
62     contents.push_back(
63         absl::StrCat("common_tls_context=", common_tls_context.ToString()));
64   }
65   if (connection_idle_timeout != Duration::Zero()) {
66     contents.push_back(absl::StrCat("connection_idle_timeout=",
67                                     connection_idle_timeout.ToString()));
68   }
69   contents.push_back(
70       absl::StrCat("max_concurrent_requests=", max_concurrent_requests));
71   contents.push_back(absl::StrCat("override_host_statuses=",
72                                   override_host_statuses.ToString()));
73   if (!metadata.empty()) {
74     contents.push_back(absl::StrCat("metadata={", metadata.ToString(), "}"));
75   }
76   return absl::StrCat("{", absl::StrJoin(contents, ", "), "}");
77 }
78 
79 }  // namespace grpc_core
80