22#include "data/BackendInterface.hpp"
23#include "migration/MigratiorStatus.hpp"
24#include "migration/impl/Spec.hpp"
25#include "util/Assert.hpp"
26#include "util/Concepts.hpp"
27#include "util/log/Logger.hpp"
28#include "util/newconfig/ObjectView.hpp"
42namespace migration::impl {
47template <
typename BackendType,
typename MigratorType>
48concept MigrationBackend =
requires {
requires std::same_as<typename MigratorType::Backend, BackendType>; };
50template <
typename Backend,
typename... MigratorType>
55 { t.kCAN_BLOCK_CLIO };
65template <
typename Backend,
typename... MigratorType>
71 std::shared_ptr<Backend> backend_;
73 template <
typename Migrator>
77 if (name == Migrator::kNAME) {
78 LOG(log_.
info()) <<
"Running migration: " << name;
79 Migrator::runMigration(backend_, config);
80 backend_->writeMigratorStatus(name,
MigratorStatus(MigratorStatus::Migrated).toString());
81 LOG(log_.
info()) <<
"Finished migration: " << name;
86 static constexpr std::string_view
87 getDescriptionIfMatch(std::string_view targetName)
89 return (T::kNAME == targetName) ? T::kDESCRIPTION :
"";
92 template <
typename First,
typename... Rest>
94 canBlockClioHelper(std::string_view targetName)
96 if (targetName == First::kNAME) {
98 return First::kCAN_BLOCK_CLIO;
102 if constexpr (
sizeof...(Rest) > 0) {
103 return canBlockClioHelper<Rest...>(targetName);
105 ASSERT(
false,
"The migrator name is not found");
134 (callMigration<MigratorType>(name, config), ...);
143 std::vector<std::tuple<std::string, MigratorStatus>>
148 std::vector<std::tuple<std::string, MigratorStatus>> status;
150 std::ranges::transform(fullList, std::back_inserter(status), [&](
auto const& migratorName) {
151 auto const migratorNameStr = std::string(migratorName);
167 if (std::ranges::find(fullList, name) == fullList.end()) {
168 return MigratorStatus::NotKnown;
170 auto const statusStringOpt =
171 data::synchronous([&](
auto yield) {
return backend_->fetchMigratorStatus(name, yield); });
184 return std::array<std::string_view,
sizeof...(MigratorType)>{MigratorType::kNAME...};
196 if constexpr (
sizeof...(MigratorType) == 0) {
197 return "No Description";
200 std::string
const result = ([](std::string
const& name) {
201 return std::string(getDescriptionIfMatch<MigratorType>(name));
204 return result.empty() ?
"No Description" : result;
218 if constexpr (
sizeof...(MigratorType) == 0) {
222 if (std::ranges::find(migratiors, name) == migratiors.end())
225 return canBlockClioHelper<MigratorType...>(name);
The status of a migrator, it provides the helper functions to convert the status to string and vice v...
Definition MigratiorStatus.hpp:31
static MigratorStatus fromString(std::string const &statusStr)
Convert the string to status.
Definition MigratorStatus.cpp:46
The register of migrators. It will dispatch the migration to the corresponding migrator....
Definition MigratorsRegister.hpp:67
void runMigrator(std::string const &name, util::config::ObjectView const &config)
Run the migration according to the given migrator's name.
Definition MigratorsRegister.hpp:131
std::optional< bool > canMigratorBlockClio(std::string_view name) const
Return if the given migrator can block Clio server.
Definition MigratorsRegister.hpp:216
MigratorStatus getMigratorStatus(std::string const &name) const
Get the status of a migrator by its name.
Definition MigratorsRegister.hpp:164
MigratorsRegister(std::shared_ptr< BackendType > backend)
Construct a new Migrators Register object.
Definition MigratorsRegister.hpp:120
constexpr auto getMigratorNames() const
Get all registered migrators' names.
Definition MigratorsRegister.hpp:182
std::string getMigratorDescription(std::string const &name) const
Get the description of a migrator by its name.
Definition MigratorsRegister.hpp:194
std::vector< std::tuple< std::string, MigratorStatus > > getMigratorsStatus() const
Get the status of all the migrators.
Definition MigratorsRegister.hpp:144
Backend BackendType
The backend type which is used by the migrators.
Definition MigratorsRegister.hpp:113
A simple thread-safe logger for the channel specified in the constructor.
Definition Logger.hpp:111
Pump info(SourceLocationType const &loc=CURRENT_SRC_LOCATION) const
Interface for logging at Severity::NFO severity.
Definition Logger.cpp:219
Provides a view into a subset of configuration data defined by a prefix.
Definition ObjectView.hpp:40
used by variadic template to check all migrators are MigratorSpec
Definition Spec.hpp:54
Definition MigratorsRegister.hpp:51
Definition MigratorsRegister.hpp:54
Definition MigratorsRegister.hpp:48
auto synchronous(FnType &&func)
Synchronously executes the given function object inside a coroutine.
Definition BackendInterface.hpp:104
constexpr bool hasNoDuplicateNames()
Checks that the list of given type contains no duplicates.
Definition Concepts.hpp:59