You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nifi.apache.org by sz...@apache.org on 2026/01/29 16:50:44 UTC
(nifi-minifi-cpp) 03/04: MINIFICPP-2700 Terminate if ContentRepository creation failed
This is an automated email from the ASF dual-hosted git repository.
szaszm pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/nifi-minifi-cpp.git
commit 3c83d84ca21df47565a8a61f6af529b161fba3f2
Author: Martin Zink <ma...@apache.org>
AuthorDate: Thu Jan 29 16:17:05 2026 +0100
MINIFICPP-2700 Terminate if ContentRepository creation failed
Closes #2083
Signed-off-by: Marton Szasz <sz...@apache.org>
---
.../tests/PrometheusMetricsPublisherTest.cpp | 2 +-
libminifi/include/core/RepositoryFactory.h | 16 ++-----
libminifi/src/core/RepositoryFactory.cpp | 54 +++++++++++-----------
minifi_main/MiNiFiMain.cpp | 2 +-
4 files changed, 31 insertions(+), 43 deletions(-)
diff --git a/extensions/prometheus/tests/PrometheusMetricsPublisherTest.cpp b/extensions/prometheus/tests/PrometheusMetricsPublisherTest.cpp
index 33c078898..36c88ecce 100644
--- a/extensions/prometheus/tests/PrometheusMetricsPublisherTest.cpp
+++ b/extensions/prometheus/tests/PrometheusMetricsPublisherTest.cpp
@@ -52,7 +52,7 @@ class PrometheusPublisherTestFixture {
: configuration_(std::make_shared<ConfigureImpl>()),
provenance_repo_(core::createRepository("provenancerepository")),
flow_file_repo_(core::createRepository("flowfilerepository")),
- content_repo_(core::createContentRepository("volatilecontentrepository")),
+ content_repo_(core::createContentRepository("volatilecontentrepository", "", *core::logging::LoggerFactory<PrometheusPublisherTestFixture>::getLogger())),
response_node_loader_(std::make_shared<state::response::ResponseNodeLoaderImpl>(configuration_,
std::vector<std::shared_ptr<core::RepositoryMetricsSource>>{provenance_repo_, flow_file_repo_, content_repo_}, nullptr)) {
std::unique_ptr<DummyMetricsExposer> dummy_exposer;
diff --git a/libminifi/include/core/RepositoryFactory.h b/libminifi/include/core/RepositoryFactory.h
index 67c308aef..c3ad9c032 100644
--- a/libminifi/include/core/RepositoryFactory.h
+++ b/libminifi/include/core/RepositoryFactory.h
@@ -27,20 +27,10 @@
namespace org::apache::nifi::minifi::core {
-/**
- * Create a context repository
- * @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
- */
-std::unique_ptr<core::ContentRepository> createContentRepository(const std::string& configuration_class_name, bool fail_safe = false, const std::string& repo_name = "");
+std::unique_ptr<core::ContentRepository> createContentRepository(const std::string& configuration_class_name,
+ const std::string& repo_name,
+ logging::Logger& logger);
-/**
- * Create a repository represented by the configuration class name
- * @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
- */
std::unique_ptr<core::Repository> createRepository(const std::string& configuration_class_name, const std::string& repo_name = "");
} // namespace org::apache::nifi::minifi::core
diff --git a/libminifi/src/core/RepositoryFactory.cpp b/libminifi/src/core/RepositoryFactory.cpp
index 07aa04883..914798186 100644
--- a/libminifi/src/core/RepositoryFactory.cpp
+++ b/libminifi/src/core/RepositoryFactory.cpp
@@ -23,45 +23,42 @@
#include "core/repository/FileSystemRepository.h"
#include "core/repository/VolatileProvenanceRepository.h"
#include "core/repository/NoOpThreadedRepository.h"
+#include "range/v3/algorithm/transform.hpp"
using namespace std::literals::chrono_literals;
namespace org::apache::nifi::minifi::core {
-std::unique_ptr<core::ContentRepository> createContentRepository(const std::string& configuration_class_name, bool fail_safe, const std::string& repo_name) {
+std::unique_ptr<ContentRepository> 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<core::ContentRepository>(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<core::repository::VolatileContentRepository>(repo_name);
- } else if (class_name_lc == "filesystemrepository") {
- return std::make_unique<core::repository::FileSystemRepository>(repo_name);
- }
- if (fail_safe) {
- return std::make_unique<core::repository::VolatileContentRepository>("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<core::repository::VolatileContentRepository>("fail_safe");
- }
+ ranges::transform(class_name_lc, class_name_lc.begin(), ::tolower);
+
+ if (auto return_obj = ClassLoader::getDefaultClassLoader().instantiate<ContentRepository>(class_name_lc, class_name_lc)) {
+ return_obj->setName(repo_name);
+ return return_obj;
+ }
+
+ if (class_name_lc == "volatilecontentrepository") {
+ return std::make_unique<repository::VolatileContentRepository>(repo_name);
+ }
+ if (class_name_lc == "filesystemrepository") {
+ return std::make_unique<repository::FileSystemRepository>(repo_name);
}
- throw std::runtime_error("Support for the provided configuration class could not be found");
+ 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<core::Repository> createRepository(const std::string& configuration_class_name, const std::string& repo_name) {
+std::unique_ptr<Repository> createRepository(const std::string& configuration_class_name, const std::string& repo_name) {
std::string class_name_lc = configuration_class_name;
std::transform(class_name_lc.begin(), class_name_lc.end(), class_name_lc.begin(), ::tolower);
- auto return_obj = core::ClassLoader::getDefaultClassLoader().instantiate<core::ThreadedRepository>(class_name_lc,
- class_name_lc);
+ auto return_obj = ClassLoader::getDefaultClassLoader().instantiate<ThreadedRepository>(class_name_lc, class_name_lc);
if (return_obj) {
return_obj->setName(repo_name);
return return_obj;
@@ -69,7 +66,8 @@ std::unique_ptr<core::Repository> createRepository(const std::string& configurat
// if the desired repos don't exist, we can try doing string matches and rely on volatile repositories
if (class_name_lc == "flowfilerepository" || class_name_lc == "volatileflowfilerepository" || class_name_lc == "nooprepository") {
return std::make_unique<repository::NoOpThreadedRepository>(repo_name);
- } else if (class_name_lc == "provenancerepository" || class_name_lc == "volatileprovenancerepository") {
+ }
+ if (class_name_lc == "provenancerepository" || class_name_lc == "volatileprovenancerepository") {
return instantiate<repository::VolatileProvenanceRepository>(repo_name);
}
return {};
diff --git a/minifi_main/MiNiFiMain.cpp b/minifi_main/MiNiFiMain.cpp
index f5c852cf1..958276a8b 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<core::ContentRepository> content_repo = core::createContentRepository(content_repo_class, true, "content");
+ std::shared_ptr<core::ContentRepository> content_repo = core::createContentRepository(content_repo_class, "content", *logger);
if (!content_repo->initialize(configure)) {
logger->log_error("Content repository failed to initialize, exiting..");