3#include "data/BackendInterface.hpp"
4#include "migration/MigratiorStatus.hpp"
5#include "migration/impl/Spec.hpp"
6#include "util/Assert.hpp"
7#include "util/Concepts.hpp"
8#include "util/config/ObjectView.hpp"
9#include "util/log/Logger.hpp"
23namespace migration::impl {
28template <
typename BackendType,
typename MigratorType>
30 requires {
requires std::same_as<typename MigratorType::Backend, BackendType>; };
32template <
typename Backend,
typename... MigratorType>
37 { t.kCAN_BLOCK_CLIO };
48template <
typename Backend,
typename... MigratorType>
54 std::shared_ptr<Backend> backend_;
56 template <
typename Migrator>
60 if (name == Migrator::kNAME) {
61 LOG(log_.info()) <<
"Running migration: " << name;
62 Migrator::runMigration(backend_, config);
63 backend_->writeMigratorStatus(
66 LOG(log_.info()) <<
"Finished migration: " << name;
71 static constexpr std::string_view
72 getDescriptionIfMatch(std::string_view targetName)
74 return (T::kNAME == targetName) ? T::kDESCRIPTION :
"";
77 template <
typename First,
typename... Rest>
79 canBlockClioHelper(std::string_view targetName)
81 if (targetName == First::kNAME) {
83 return First::kCAN_BLOCK_CLIO;
87 if constexpr (
sizeof...(Rest) > 0) {
88 return canBlockClioHelper<Rest...>(targetName);
90 ASSERT(
false,
"The migrator name is not found");
119 (callMigration<MigratorType>(name, config), ...);
128 std::vector<std::tuple<std::string, MigratorStatus>>
133 std::vector<std::tuple<std::string, MigratorStatus>> status;
135 std::ranges::transform(fullList, std::back_inserter(status), [&](
auto const& migratorName) {
136 auto const migratorNameStr = std::string(migratorName);
152 if (std::ranges::find(fullList, name) == fullList.end()) {
153 return MigratorStatus::NotKnown;
156 return backend_->fetchMigratorStatus(name, yield);
160 : MigratorStatus::NotMigrated;
171 return std::array<std::string_view,
sizeof...(MigratorType)>{MigratorType::kNAME...};
183 if constexpr (
sizeof...(MigratorType) == 0) {
184 return "No Description";
187 std::string
const result = ([](std::string
const& name) {
188 return std::string(getDescriptionIfMatch<MigratorType>(name));
191 return result.empty() ?
"No Description" : result;
205 if constexpr (
sizeof...(MigratorType) == 0) {
209 if (std::ranges::find(migratiors, name) == migratiors.end())
212 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:13
static MigratorStatus fromString(std::string const &statusStr)
Convert the string to status.
Definition MigratorStatus.cpp:27
void runMigrator(std::string const &name, util::config::ObjectView const &config)
Run the migration according to the given migrator's name.
Definition MigratorsRegister.hpp:116
std::optional< bool > canMigratorBlockClio(std::string_view name) const
Return if the given migrator can block Clio server.
Definition MigratorsRegister.hpp:203
MigratorStatus getMigratorStatus(std::string const &name) const
Get the status of a migrator by its name.
Definition MigratorsRegister.hpp:149
MigratorsRegister(std::shared_ptr< BackendType > backend)
Construct a new Migrators Register object.
Definition MigratorsRegister.hpp:105
constexpr auto getMigratorNames() const
Get all registered migrators' names.
Definition MigratorsRegister.hpp:169
std::string getMigratorDescription(std::string const &name) const
Get the description of a migrator by its name.
Definition MigratorsRegister.hpp:181
std::vector< std::tuple< std::string, MigratorStatus > > getMigratorsStatus() const
Get the status of all the migrators.
Definition MigratorsRegister.hpp:129
Backend BackendType
The backend type which is used by the migrators.
Definition MigratorsRegister.hpp:98
A simple thread-safe logger for the channel specified in the constructor.
Definition Logger.hpp:77
Provides a view into a subset of configuration data defined by a prefix.
Definition ObjectView.hpp:21
used by variadic template to check all migrators are MigratorSpec
Definition Spec.hpp:35
Definition MigratorsRegister.hpp:33
Definition MigratorsRegister.hpp:36
Definition MigratorsRegister.hpp:29
auto synchronous(FnType &&func)
Synchronously executes the given function object inside a coroutine.
Definition BackendInterface.hpp:86
constexpr bool hasNoDuplicateNames()
Checks that the list of given type contains no duplicates.
Definition Concepts.hpp:40