|
| 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