aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/clickhouse/src/Backups/BackupStatus.cpp
blob: 53adaa577eaca473b5057fad2e7197cd00013293 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <Backups/BackupStatus.h>
#include <Common/Exception.h>
#include <base/range.h>


namespace DB
{
namespace ErrorCodes
{
    extern const int LOGICAL_ERROR;
}


std::string_view toString(BackupStatus backup_status)
{
    switch (backup_status)
    {
        case BackupStatus::CREATING_BACKUP:
            return "CREATING_BACKUP";
        case BackupStatus::BACKUP_CREATED:
            return "BACKUP_CREATED";
        case BackupStatus::BACKUP_FAILED:
            return "BACKUP_FAILED";
        case BackupStatus::RESTORING:
            return "RESTORING";
        case BackupStatus::RESTORED:
            return "RESTORED";
        case BackupStatus::RESTORE_FAILED:
            return "RESTORE_FAILED";
        default:
            break;
    }
    throw Exception(ErrorCodes::LOGICAL_ERROR, "Unexpected backup status: {}", static_cast<int>(backup_status));
}

const std::vector<std::pair<String, Int8>> & getBackupStatusEnumValues()
{
    static const std::vector<std::pair<String, Int8>> values = []
    {
        std::vector<std::pair<String, Int8>> res;
        for (auto status : collections::range(BackupStatus::MAX))
            res.emplace_back(toString(status), static_cast<Int8>(status));
        return res;
    }();
    return values;
}

}