aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/clickhouse/src/Backups/BackupFactory.cpp
blob: 898ac7bc4907fe0b0bfc1184ceb53da281c60e66 (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/BackupFactory.h>


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

BackupFactory & BackupFactory::instance()
{
    static BackupFactory the_instance;
    return the_instance;
}

BackupMutablePtr BackupFactory::createBackup(const CreateParams & params) const
{
    const String & engine_name = params.backup_info.backup_engine_name;
    auto it = creators.find(engine_name);
    if (it == creators.end())
        throw Exception(ErrorCodes::BACKUP_ENGINE_NOT_FOUND, "Not found backup engine '{}'", engine_name);
    return (it->second)(params);
}

void BackupFactory::registerBackupEngine(const String & engine_name, const CreatorFn & creator_fn)
{
    if (creators.contains(engine_name))
        throw Exception(ErrorCodes::LOGICAL_ERROR, "Backup engine '{}' was registered twice", engine_name);
    creators[engine_name] = creator_fn;
}

void registerBackupEnginesFileAndDisk(BackupFactory &);
void registerBackupEngineS3(BackupFactory &);

void registerBackupEngines(BackupFactory & factory)
{
    registerBackupEnginesFileAndDisk(factory);
    registerBackupEngineS3(factory);
}

BackupFactory::BackupFactory()
{
    registerBackupEngines(*this);
}

}