now that we are allowed to use C++23. we now have the luxury of using `std::ranges::transform`. in this change, we: - replace `boost::transform` with `std::ranges::transform` - update affected code to work with `std::ranges::transform` to reduce the dependency to boost for better maintainability, and leverage standard library features for better long-term support. this change is part of our ongoing effort to modernize our codebase and reduce external dependencies where possible. Signed-off-by: Kefu Chai <kefu.chai@scylladb.com> Closes scylladb/scylladb#21318
70 lines
2.3 KiB
C++
70 lines
2.3 KiB
C++
/*
|
|
* Copyright (C) 2024-present ScyllaDB
|
|
*/
|
|
|
|
/*
|
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
|
*/
|
|
|
|
#ifndef SCYLLA_BUILD_MODE_RELEASE
|
|
|
|
#include <seastar/core/coroutine.hh>
|
|
|
|
#include "api/api-doc/cql_server_test.json.hh"
|
|
#include "cql_server_test.hh"
|
|
#include "transport/controller.hh"
|
|
#include "transport/server.hh"
|
|
#include "service/qos/qos_common.hh"
|
|
|
|
namespace api {
|
|
|
|
namespace cst = httpd::cql_server_test_json;
|
|
using namespace json;
|
|
using namespace seastar::httpd;
|
|
|
|
struct connection_sl_params : public json::json_base {
|
|
json::json_element<sstring> _role_name;
|
|
json::json_element<sstring> _workload_type;
|
|
json::json_element<sstring> _timeout;
|
|
|
|
connection_sl_params(const sstring& role_name, const sstring& workload_type, const sstring& timeout) {
|
|
_role_name = role_name;
|
|
_workload_type = workload_type;
|
|
_timeout = timeout;
|
|
register_params();
|
|
}
|
|
|
|
connection_sl_params(const connection_sl_params& params)
|
|
: connection_sl_params(params._role_name(), params._workload_type(), params._timeout()) {}
|
|
|
|
void register_params() {
|
|
add(&_role_name, "role_name");
|
|
add(&_workload_type, "workload_type");
|
|
add(&_timeout, "timeout");
|
|
}
|
|
};
|
|
|
|
void set_cql_server_test(http_context& ctx, seastar::httpd::routes& r, cql_transport::controller& ctl) {
|
|
cst::connections_params.set(r, [&ctl] (std::unique_ptr<http::request> req) -> future<json::json_return_type> {
|
|
auto sl_params = co_await ctl.get_connections_service_level_params();
|
|
|
|
std::vector<connection_sl_params> result;
|
|
std::ranges::transform(std::move(sl_params), std::back_inserter(result), [] (const cql_transport::connection_service_level_params& params) {
|
|
auto nanos = std::chrono::duration_cast<std::chrono::nanoseconds>(params.timeout_config.read_timeout).count();
|
|
return connection_sl_params(
|
|
std::move(params.role_name),
|
|
sstring(qos::service_level_options::to_string(params.workload_type)),
|
|
to_string(cql_duration(months_counter{0}, days_counter{0}, nanoseconds_counter{nanos})));
|
|
});
|
|
co_return result;
|
|
});
|
|
}
|
|
|
|
void unset_cql_server_test(http_context& ctx, seastar::httpd::routes& r) {
|
|
cst::connections_params.unset(r);
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|