Skip to content

Commit 90872fb

Browse files
committed
1
1 parent 3cdc482 commit 90872fb

10 files changed

Lines changed: 1634 additions & 1120 deletions

File tree

cloud/src/common/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ set(COMMON_FILES
1010
logging.cpp
1111
bvars.cpp
1212
encryption_util.cpp
13+
http_helper.cpp
1314
metric.cpp
1415
kms.cpp
1516
network_util.cpp

cloud/src/common/configbase.cpp

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,4 +462,53 @@ std::pair<bool, std::string> set_config(std::unordered_map<std::string, std::str
462462
std::shared_mutex* get_mutable_string_config_lock() {
463463
return &mutable_string_config_lock;
464464
}
465+
466+
std::string show_config(const std::string& conf_name) {
467+
if (full_conf_map == nullptr) {
468+
return "";
469+
}
470+
471+
std::ostringstream oss;
472+
oss << "[";
473+
bool first = true;
474+
for (auto& [name, field] : *Register::_s_field_map) {
475+
if (!conf_name.empty() && name != conf_name) {
476+
continue;
477+
}
478+
auto it = full_conf_map->find(name);
479+
std::string value = (it != full_conf_map->end()) ? it->second : "";
480+
481+
if (!first) oss << ",";
482+
first = false;
483+
oss << "[\"" << name << "\",\"" << field.type << "\",\"" << value << "\","
484+
<< (field.valmutable ? "true" : "false") << "]";
485+
}
486+
oss << "]";
487+
return oss.str();
488+
}
489+
490+
std::pair<bool, std::string> update_config(const std::string& configs, bool persist,
491+
const std::string& custom_conf_path) {
492+
if (configs.empty()) {
493+
return {false, "query param `configs` should not be empty"};
494+
}
495+
496+
std::unordered_map<std::string, std::string> conf_map;
497+
std::istringstream ss(configs);
498+
std::string conf;
499+
while (std::getline(ss, conf, ',')) {
500+
auto pos = conf.find('=');
501+
if (pos == std::string::npos) {
502+
return {false, fmt::format("config {} is invalid", conf)};
503+
}
504+
std::string key = conf.substr(0, pos);
505+
std::string val = conf.substr(pos + 1);
506+
trim(key);
507+
trim(val);
508+
conf_map.emplace(std::move(key), std::move(val));
509+
}
510+
511+
return set_config(std::move(conf_map), persist, custom_conf_path);
512+
}
513+
465514
} // namespace doris::cloud::config

cloud/src/common/configbase.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,4 +181,9 @@ std::pair<bool, std::string> set_config(std::unordered_map<std::string, std::str
181181

182182
std::shared_mutex* get_mutable_string_config_lock();
183183

184+
std::string show_config(const std::string& conf_name);
185+
186+
std::pair<bool, std::string> update_config(const std::string& configs, bool persist,
187+
const std::string& custom_conf_path);
188+
184189
} // namespace doris::cloud::config

cloud/src/common/http_helper.cpp

Lines changed: 1191 additions & 0 deletions
Large diffs are not rendered by default.

cloud/src/common/http_helper.h

Lines changed: 209 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,209 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
#pragma once
19+
20+
#include <brpc/controller.h>
21+
#include <brpc/http_status_code.h>
22+
#include <brpc/uri.h>
23+
#include <fmt/core.h>
24+
#include <fmt/format.h>
25+
#include <gen_cpp/cloud.pb.h>
26+
#include <glog/logging.h>
27+
#include <google/protobuf/message.h>
28+
#include <google/protobuf/service.h>
29+
#include <google/protobuf/util/json_util.h>
30+
#include <rapidjson/document.h>
31+
#include <rapidjson/error/en.h>
32+
#include <rapidjson/prettywriter.h>
33+
#include <rapidjson/stringbuffer.h>
34+
35+
#include <algorithm>
36+
#include <string_view>
37+
38+
#include "meta-service/meta_service_http.h"
39+
40+
namespace doris::cloud {
41+
42+
inline constexpr std::string_view kDefaultHttpApiVersion = "v1";
43+
44+
struct HttpApiPath {
45+
std::string_view version;
46+
std::string_view route;
47+
};
48+
49+
[[maybe_unused]] static bool is_http_api_version(std::string_view segment) {
50+
if (segment.size() < 2 || segment.front() != 'v') {
51+
return false;
52+
}
53+
return std::ranges::all_of(segment.substr(1), [](char ch) { return ch >= '0' && ch <= '9'; });
54+
}
55+
56+
[[maybe_unused]] static HttpApiPath split_http_api_path(std::string_view path) {
57+
auto separator = path.find('/');
58+
if (separator == std::string_view::npos) {
59+
return {.version = "", .route = path};
60+
}
61+
// This helper only splits the version segment from the route. Whether a version is actually
62+
// supported is determined by exact route registration in get_http_handlers().
63+
auto segment = path.substr(0, separator);
64+
if (!is_http_api_version(segment)) {
65+
return {.version = "", .route = path};
66+
}
67+
return {.version = segment, .route = path.substr(separator + 1)};
68+
}
69+
70+
[[maybe_unused]] static std::string_view http_api_route(std::string_view path) {
71+
return split_http_api_path(path).route;
72+
}
73+
74+
[[maybe_unused]] static const HttpHandler* resolve_http_handler(const HttpHandlerInfo& handler_info,
75+
std::string_view version) {
76+
if (version.empty() || version == kDefaultHttpApiVersion) {
77+
return &handler_info.handler;
78+
}
79+
auto it = handler_info.versioned_handlers.find(version);
80+
return it == handler_info.versioned_handlers.end() ? nullptr : &it->second;
81+
}
82+
83+
const std::unordered_map<std::string_view, HttpHandlerInfo>& get_http_handlers();
84+
85+
// injection_point_http.cpp
86+
[[maybe_unused]] HttpResponse process_injection_point(MetaServiceImpl* service,
87+
brpc::Controller* ctrl);
88+
89+
// MetaService Http handlers
90+
[[maybe_unused]] HttpResponse process_alter_cluster(MetaServiceImpl* service,
91+
brpc::Controller* ctrl);
92+
93+
[[maybe_unused]] HttpResponse process_get_obj_store_info(MetaServiceImpl* service,
94+
brpc::Controller* ctrl);
95+
96+
[[maybe_unused]] HttpResponse process_alter_obj_store_info(MetaServiceImpl* service,
97+
brpc::Controller* ctrl);
98+
99+
[[maybe_unused]] HttpResponse process_alter_storage_vault(MetaServiceImpl* service,
100+
brpc::Controller* ctrl);
101+
102+
[[maybe_unused]] HttpResponse process_update_ak_sk(MetaServiceImpl* service,
103+
brpc::Controller* ctrl);
104+
105+
[[maybe_unused]] HttpResponse process_create_instance(MetaServiceImpl* service,
106+
brpc::Controller* ctrl);
107+
108+
[[maybe_unused]] HttpResponse process_alter_instance(MetaServiceImpl* service,
109+
brpc::Controller* ctrl);
110+
111+
[[maybe_unused]] HttpResponse process_abort_txn(MetaServiceImpl* service, brpc::Controller* ctrl);
112+
113+
[[maybe_unused]] HttpResponse process_abort_tablet_job(MetaServiceImpl* service,
114+
brpc::Controller* ctrl);
115+
116+
[[maybe_unused]] HttpResponse process_alter_ram_user(MetaServiceImpl* service,
117+
brpc::Controller* ctrl);
118+
119+
[[maybe_unused]] HttpResponse process_alter_iam(MetaServiceImpl* service, brpc::Controller* ctrl);
120+
121+
[[maybe_unused]] HttpResponse process_adjust_rate_limit(MetaServiceImpl* service,
122+
brpc::Controller* cntl);
123+
124+
[[maybe_unused]] HttpResponse process_query_rate_limit(MetaServiceImpl* service,
125+
brpc::Controller* cntl);
126+
127+
[[maybe_unused]] HttpResponse process_decode_key(MetaServiceImpl*, brpc::Controller* ctrl);
128+
129+
[[maybe_unused]] HttpResponse process_encode_key(MetaServiceImpl*, brpc::Controller* ctrl);
130+
131+
[[maybe_unused]] HttpResponse process_get_value(MetaServiceImpl* service, brpc::Controller* ctrl);
132+
133+
[[maybe_unused]] HttpResponse process_set_value(MetaServiceImpl* service, brpc::Controller* ctrl);
134+
135+
// show all key ranges and their count.
136+
[[maybe_unused]] HttpResponse process_show_meta_ranges(MetaServiceImpl* service,
137+
brpc::Controller* ctrl);
138+
139+
[[maybe_unused]] HttpResponse process_get_instance_info(MetaServiceImpl* service,
140+
brpc::Controller* ctrl);
141+
142+
[[maybe_unused]] HttpResponse process_get_cluster(MetaServiceImpl* service, brpc::Controller* ctrl);
143+
144+
[[maybe_unused]] HttpResponse process_get_tablet_stats(MetaServiceImpl* service,
145+
brpc::Controller* ctrl);
146+
147+
[[maybe_unused]] HttpResponse process_fix_tablet_stats(MetaServiceImpl* service,
148+
brpc::Controller* ctrl);
149+
150+
[[maybe_unused]] HttpResponse process_fix_tablet_db_id(MetaServiceImpl* service,
151+
brpc::Controller* ctrl);
152+
153+
[[maybe_unused]] HttpResponse process_get_stage(MetaServiceImpl* service, brpc::Controller* ctrl);
154+
155+
[[maybe_unused]] HttpResponse process_get_cluster_status(MetaServiceImpl* service,
156+
brpc::Controller* ctrl);
157+
158+
[[maybe_unused]] HttpResponse process_txn_lazy_commit(MetaServiceImpl* service,
159+
brpc::Controller* ctrl);
160+
161+
[[maybe_unused]] HttpResponse process_list_snapshot(MetaServiceImpl* service,
162+
brpc::Controller* ctrl);
163+
164+
[[maybe_unused]] HttpResponse process_compact_snapshot(MetaServiceImpl* service,
165+
brpc::Controller* ctrl);
166+
167+
[[maybe_unused]] HttpResponse process_decouple_instance(MetaServiceImpl* service,
168+
brpc::Controller* ctrl);
169+
170+
[[maybe_unused]] HttpResponse process_set_snapshot_property(MetaServiceImpl* service,
171+
brpc::Controller* ctrl);
172+
173+
[[maybe_unused]] HttpResponse process_set_multi_version_status(MetaServiceImpl* service,
174+
brpc::Controller* ctrl);
175+
176+
[[maybe_unused]] HttpResponse process_get_snapshot_property(MetaServiceImpl* service,
177+
brpc::Controller* ctrl);
178+
179+
// Recycler HTTP handlers
180+
[[maybe_unused]] HttpResponse process_recycle_instance(RecyclerServiceImpl* service,
181+
brpc::Controller* cntl);
182+
183+
[[maybe_unused]] HttpResponse process_statistics_recycle(RecyclerServiceImpl* service,
184+
brpc::Controller* cntl);
185+
186+
[[maybe_unused]] HttpResponse process_recycle_copy_jobs(RecyclerServiceImpl* service,
187+
brpc::Controller* cntl);
188+
189+
[[maybe_unused]] HttpResponse process_recycle_job_info(RecyclerServiceImpl* service,
190+
brpc::Controller* cntl);
191+
[[maybe_unused]] HttpResponse process_check_instance(RecyclerServiceImpl* service,
192+
brpc::Controller* cntl);
193+
194+
[[maybe_unused]] HttpResponse process_check_job_info(RecyclerServiceImpl* service,
195+
brpc::Controller* cntl);
196+
197+
[[maybe_unused]] HttpResponse process_check_meta(RecyclerServiceImpl* service,
198+
brpc::Controller* cntl);
199+
200+
[[maybe_unused]] HttpResponse process_adjust_rate_limiter(RecyclerServiceImpl*,
201+
brpc::Controller* cntl);
202+
203+
// Both http handlers
204+
[[maybe_unused]] HttpResponse process_show_config(MetaServiceImpl*, brpc::Controller* cntl);
205+
206+
[[maybe_unused]] HttpResponse process_update_config(MetaServiceImpl* service,
207+
brpc::Controller* cntl);
208+
209+
} // namespace doris::cloud

0 commit comments

Comments
 (0)