|
23 | 23 | #include "core/repository/FileSystemRepository.h" |
24 | 24 | #include "core/repository/VolatileProvenanceRepository.h" |
25 | 25 | #include "core/repository/NoOpThreadedRepository.h" |
| 26 | +#include "range/v3/algorithm/transform.hpp" |
26 | 27 |
|
27 | 28 | using namespace std::literals::chrono_literals; |
28 | 29 |
|
29 | 30 | namespace org::apache::nifi::minifi::core { |
30 | 31 |
|
31 | | -std::unique_ptr<core::ContentRepository> createContentRepository(const std::string& configuration_class_name, bool fail_safe, const std::string& repo_name) { |
| 32 | +std::unique_ptr<ContentRepository> createContentRepository(const std::string& configuration_class_name, |
| 33 | + const std::string& repo_name, |
| 34 | + logging::Logger& logger) { |
32 | 35 | std::string class_name_lc = configuration_class_name; |
33 | | - std::transform(class_name_lc.begin(), class_name_lc.end(), class_name_lc.begin(), ::tolower); |
34 | | - try { |
35 | | - auto return_obj = core::ClassLoader::getDefaultClassLoader().instantiate<core::ContentRepository>(class_name_lc, |
36 | | - class_name_lc); |
37 | | - if (return_obj) { |
38 | | - return_obj->setName(repo_name); |
39 | | - return return_obj; |
40 | | - } |
41 | | - if (class_name_lc == "volatilecontentrepository") { |
42 | | - return std::make_unique<core::repository::VolatileContentRepository>(repo_name); |
43 | | - } else if (class_name_lc == "filesystemrepository") { |
44 | | - return std::make_unique<core::repository::FileSystemRepository>(repo_name); |
45 | | - } |
46 | | - if (fail_safe) { |
47 | | - return std::make_unique<core::repository::VolatileContentRepository>("fail_safe"); |
48 | | - } else { |
49 | | - throw std::runtime_error("Support for the provided configuration class could not be found"); |
50 | | - } |
51 | | - } catch (const std::runtime_error&) { |
52 | | - if (fail_safe) { |
53 | | - return std::make_unique<core::repository::VolatileContentRepository>("fail_safe"); |
54 | | - } |
| 36 | + ranges::transform(class_name_lc, class_name_lc.begin(), ::tolower); |
| 37 | + |
| 38 | + if (auto return_obj = ClassLoader::getDefaultClassLoader().instantiate<ContentRepository>(class_name_lc, class_name_lc)) { |
| 39 | + return_obj->setName(repo_name); |
| 40 | + return return_obj; |
| 41 | + } |
| 42 | + |
| 43 | + if (class_name_lc == "volatilecontentrepository") { |
| 44 | + return std::make_unique<repository::VolatileContentRepository>(repo_name); |
| 45 | + } |
| 46 | + if (class_name_lc == "filesystemrepository") { |
| 47 | + return std::make_unique<repository::FileSystemRepository>(repo_name); |
55 | 48 | } |
56 | 49 |
|
57 | | - throw std::runtime_error("Support for the provided configuration class could not be found"); |
| 50 | + logger.log_critical("Could not create the configured content repository ({})", configuration_class_name); |
| 51 | + if (class_name_lc == "databasecontentrepository") { |
| 52 | + logger.log_error("To use DatabaseContentRepository MiNiFi needs RocksDB extension, please check the extension path configured in minifi.properties"); |
| 53 | + } |
| 54 | + |
| 55 | + throw std::runtime_error("Support for the provided configuration class could not be found, check logs for more details"); |
58 | 56 | } |
59 | 57 |
|
60 | | -std::unique_ptr<core::Repository> createRepository(const std::string& configuration_class_name, const std::string& repo_name) { |
| 58 | +std::unique_ptr<Repository> createRepository(const std::string& configuration_class_name, const std::string& repo_name) { |
61 | 59 | std::string class_name_lc = configuration_class_name; |
62 | 60 | std::transform(class_name_lc.begin(), class_name_lc.end(), class_name_lc.begin(), ::tolower); |
63 | | - auto return_obj = core::ClassLoader::getDefaultClassLoader().instantiate<core::ThreadedRepository>(class_name_lc, |
64 | | - class_name_lc); |
| 61 | + auto return_obj = ClassLoader::getDefaultClassLoader().instantiate<ThreadedRepository>(class_name_lc, class_name_lc); |
65 | 62 | if (return_obj) { |
66 | 63 | return_obj->setName(repo_name); |
67 | 64 | return return_obj; |
68 | 65 | } |
69 | 66 | // if the desired repos don't exist, we can try doing string matches and rely on volatile repositories |
70 | 67 | if (class_name_lc == "flowfilerepository" || class_name_lc == "volatileflowfilerepository" || class_name_lc == "nooprepository") { |
71 | 68 | return std::make_unique<repository::NoOpThreadedRepository>(repo_name); |
72 | | - } else if (class_name_lc == "provenancerepository" || class_name_lc == "volatileprovenancerepository") { |
| 69 | + } |
| 70 | + if (class_name_lc == "provenancerepository" || class_name_lc == "volatileprovenancerepository") { |
73 | 71 | return instantiate<repository::VolatileProvenanceRepository>(repo_name); |
74 | 72 | } |
75 | 73 | return {}; |
|
0 commit comments