Clio develop
The XRP Ledger API server.
Loading...
Searching...
No Matches
MigrationInspectorBase.hpp
1//------------------------------------------------------------------------------
2/*
3 This file is part of clio: https://github.com/XRPLF/clio
4 Copyright (c) 2025, the clio developers.
5
6 Permission to use, copy, modify, and distribute this software for any
7 purpose with or without fee is hereby granted, provided that the above
8 copyright notice and this permission notice appear in all copies.
9
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17*/
18//==============================================================================
19
20#pragma once
21
22#include "migration/MigrationInspectorInterface.hpp"
23#include "migration/MigratiorStatus.hpp"
24
25#include <memory>
26#include <ranges>
27#include <string>
28#include <tuple>
29#include <vector>
30
31namespace migration::impl {
32
39template <typename SupportedMigrators>
41protected:
42 SupportedMigrators migrators_;
43
44public:
50 explicit MigrationInspectorBase(std::shared_ptr<typename SupportedMigrators::BackendType> backend)
51 : migrators_{std::move(backend)}
52 {
53 }
54
61 std::vector<std::tuple<std::string, MigratorStatus>>
62 allMigratorsStatusPairs() const override
63 {
64 return migrators_.getMigratorsStatus();
65 }
66
74 getMigratorStatusByName(std::string const& name) const override
75 {
76 return migrators_.getMigratorStatus(name);
77 }
78
84 std::vector<std::string>
85 allMigratorsNames() const override
86 {
87 auto const names = migrators_.getMigratorNames();
88 return std::vector<std::string>{names.begin(), names.end()};
89 }
90
97 std::string
98 getMigratorDescriptionByName(std::string const& name) const override
99 {
100 return migrators_.getMigratorDescription(name);
101 }
102
108 bool
109 isBlockingClio() const override
110 {
111 return std::ranges::any_of(migrators_.getMigratorNames(), [&](auto const& migrator) {
112 if (auto canBlock = migrators_.canMigratorBlockClio(migrator); canBlock.has_value() and *canBlock and
113 migrators_.getMigratorStatus(std::string(migrator)) == MigratorStatus::Status::NotMigrated) {
114 return true;
115 }
116 return false;
117 });
118 }
119};
120
121} // namespace migration::impl
The status of a migrator, it provides the helper functions to convert the status to string and vice v...
Definition MigratiorStatus.hpp:31
The migration inspector implementation for Cassandra. It will report the migration status for Cassand...
Definition MigrationInspectorBase.hpp:40
std::vector< std::tuple< std::string, MigratorStatus > > allMigratorsStatusPairs() const override
Get the status of all the migrators.
Definition MigrationInspectorBase.hpp:62
MigrationInspectorBase(std::shared_ptr< typename SupportedMigrators::BackendType > backend)
Construct a new Cassandra Migration Inspector object.
Definition MigrationInspectorBase.hpp:50
bool isBlockingClio() const override
Return if there is uncomplete migrator blocking the server.
Definition MigrationInspectorBase.hpp:109
std::string getMigratorDescriptionByName(std::string const &name) const override
Get the description of a migrator by its name.
Definition MigrationInspectorBase.hpp:98
MigratorStatus getMigratorStatusByName(std::string const &name) const override
Get the status of a migrator by its name.
Definition MigrationInspectorBase.hpp:74
std::vector< std::string > allMigratorsNames() const override
Get all registered migrators' names.
Definition MigrationInspectorBase.hpp:85
The interface for the migration inspector.The Clio server application will use this interface to insp...
Definition MigrationInspectorInterface.hpp:34