diff --git a/libminifi/include/core/RepositoryFactory.h b/libminifi/include/core/RepositoryFactory.h index 67c308aefb..4f417f1f3f 100644 --- a/libminifi/include/core/RepositoryFactory.h +++ b/libminifi/include/core/RepositoryFactory.h @@ -32,8 +32,11 @@ namespace org::apache::nifi::minifi::core { * @param configuration_class_name configuration class name * @param fail_safe determines whether or not to make the default class if configuration_class_name is invalid * @param repo_name name of the repository + * @param logger pointer to a logger so it can log out errors */ -std::unique_ptr createContentRepository(const std::string& configuration_class_name, bool fail_safe = false, const std::string& repo_name = ""); +std::unique_ptr createContentRepository(const std::string& configuration_class_name, + const std::string& repo_name = "", + logging::Logger* logger = nullptr); /** * Create a repository represented by the configuration class name diff --git a/libminifi/src/core/RepositoryFactory.cpp b/libminifi/src/core/RepositoryFactory.cpp index 07aa04883b..a36ec544b0 100644 --- a/libminifi/src/core/RepositoryFactory.cpp +++ b/libminifi/src/core/RepositoryFactory.cpp @@ -28,33 +28,31 @@ using namespace std::literals::chrono_literals; namespace org::apache::nifi::minifi::core { -std::unique_ptr createContentRepository(const std::string& configuration_class_name, bool fail_safe, const std::string& repo_name) { +std::unique_ptr createContentRepository(const std::string& configuration_class_name, + const std::string& repo_name, + logging::Logger* logger) { std::string class_name_lc = configuration_class_name; std::transform(class_name_lc.begin(), class_name_lc.end(), class_name_lc.begin(), ::tolower); - try { - auto return_obj = core::ClassLoader::getDefaultClassLoader().instantiate(class_name_lc, - class_name_lc); - if (return_obj) { - return_obj->setName(repo_name); - return return_obj; - } - if (class_name_lc == "volatilecontentrepository") { - return std::make_unique(repo_name); - } else if (class_name_lc == "filesystemrepository") { - return std::make_unique(repo_name); - } - if (fail_safe) { - return std::make_unique("fail_safe"); - } else { - throw std::runtime_error("Support for the provided configuration class could not be found"); - } - } catch (const std::runtime_error&) { - if (fail_safe) { - return std::make_unique("fail_safe"); - } + + auto return_obj = core::ClassLoader::getDefaultClassLoader().instantiate(class_name_lc, + class_name_lc); + if (return_obj) { + return_obj->setName(repo_name); + return return_obj; } - throw std::runtime_error("Support for the provided configuration class could not be found"); + if (class_name_lc == "volatilecontentrepository") { + return std::make_unique(repo_name); + } + if (class_name_lc == "filesystemrepository") { + return std::make_unique(repo_name); + } + + logger->log_critical("Could not create the configured content repository ({})", configuration_class_name); + if (class_name_lc == "databasecontentrepository") { + logger->log_error("To use DatabaseContentRepository MiNiFi needs RocksDB extension, please check the extension path configured in minifi.properties"); + } + throw std::runtime_error("Support for the provided configuration class could not be found, check logs for more details"); } std::unique_ptr createRepository(const std::string& configuration_class_name, const std::string& repo_name) { diff --git a/minifi_main/MiNiFiMain.cpp b/minifi_main/MiNiFiMain.cpp index d6d32a50c8..1476f7709b 100644 --- a/minifi_main/MiNiFiMain.cpp +++ b/minifi_main/MiNiFiMain.cpp @@ -352,7 +352,7 @@ int main(int argc, char **argv) { configure->get(minifi::Configure::nifi_content_repository_class_name, content_repo_class); - std::shared_ptr content_repo = core::createContentRepository(content_repo_class, true, "content"); + std::shared_ptr content_repo = core::createContentRepository(content_repo_class, "content", logger.get()); if (!content_repo->initialize(configure)) { logger->log_error("Content repository failed to initialize, exiting..");