You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nifi.apache.org by ma...@apache.org on 2026/02/12 15:42:15 UTC
(nifi-minifi-cpp) branch controller_c_api_requirements created (now 233e9b6ba)
This is an automated email from the ASF dual-hosted git repository.
martinzink pushed a change to branch controller_c_api_requirements
in repository https://gitbox.apache.org/repos/asf/nifi-minifi-cpp.git
at 233e9b6ba MINIFICPP-2715 - Use symbols to check api compatibility
This branch includes the following new commits:
new abea7c3c7 MINIFICPP-2669 - Reduce controller service api
new becaaa9bb MINIFICPP-2710 Refactor ControllerServiceNodeMap
new 233e9b6ba MINIFICPP-2715 - Use symbols to check api compatibility
The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
(nifi-minifi-cpp) 01/03: MINIFICPP-2669 - Reduce controller service api
Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
martinzink pushed a commit to branch controller_c_api_requirements
in repository https://gitbox.apache.org/repos/asf/nifi-minifi-cpp.git
commit abea7c3c7f3373c783a464fbf72ee6c22a20cfd9
Author: Adam Debreceni <ad...@apache.org>
AuthorDate: Thu Feb 12 16:30:41 2026 +0100
MINIFICPP-2669 - Reduce controller service api
Closes #2065
Signed-off-by: Martin Zink <ma...@apache.org>
---
controller/MiNiFiController.cpp | 4 +-
controller/tests/ControllerTests.cpp | 3 +-
core-framework/include/core/Resource.h | 6 +
.../include/core/controller/ControllerService.h | 121 ----------------
.../core/controller/ControllerServiceBase.h | 113 +++++++++++++++
.../core/controller/ControllerServiceFactoryImpl.h | 49 ++++---
core-framework/include/utils/ThreadPool.h | 21 +--
core-framework/src/utils/ThreadPool.cpp | 65 +--------
encrypt-config/FlowConfigEncryptor.cpp | 2 +-
.../include/controllers/AttributeProviderService.h | 10 +-
.../include/controllers/RecordSetReader.h | 8 +-
.../include/controllers/RecordSetWriter.h | 8 +-
.../controllers/keyvalue/KeyValueStateStorage.h | 20 +--
.../include/utils/ProcessorConfigUtils.h | 2 +-
.../controllers/keyvalue/KeyValueStateStorage.cpp | 4 -
.../aws/controllerservices/AWSCredentialsService.h | 26 +---
extensions/aws/tests/AWSCredentialsServiceTest.cpp | 6 +-
.../aws/tests/MultipartUploadStateStorageTest.cpp | 7 +-
.../AzureStorageCredentialsService.h | 28 +---
.../azure/processors/AzureStorageProcessorBase.cpp | 2 +-
extensions/civetweb/tests/ListenHTTPTests.cpp | 3 +-
.../controllerservices/CouchbaseClusterService.h | 27 +---
.../couchbase/tests/GetCouchbaseKeyTests.cpp | 2 +-
.../couchbase/tests/MockCouchbaseClusterService.h | 1 -
.../couchbase/tests/PutCouchbaseKeyTests.cpp | 2 +-
.../ElasticsearchCredentialsControllerService.h | 20 +--
.../GCPCredentialsControllerService.h | 21 +--
.../tests/GCPCredentialsControllerServiceTests.cpp | 4 +-
.../KubernetesControllerService.cpp | 13 +-
.../KubernetesControllerService.h | 5 +-
extensions/rocksdb-repos/FlowFileLoader.h | 2 +-
.../controllers/RocksDbStateStorage.cpp | 6 +-
.../controllers/RocksDbStateStorage.h | 5 +-
extensions/smb/SmbConnectionControllerService.h | 12 +-
extensions/smb/tests/FetchSmbTests.cpp | 2 +-
extensions/smb/tests/ListAndFetchSmbTests.cpp | 2 +-
extensions/smb/tests/ListSmbTests.cpp | 2 +-
extensions/smb/tests/PutSmbTests.cpp | 4 +-
.../tests/SmbConnectionControllerServiceTests.cpp | 2 +-
.../utils/MockSmbConnectionControllerService.h | 1 -
extensions/sql/services/DatabaseService.cpp | 4 +-
extensions/sql/services/DatabaseService.h | 35 +----
extensions/sql/services/ODBCConnector.h | 17 +--
extensions/sql/tests/mocks/MockODBCService.h | 17 +--
.../controllers/JsonRecordSetWriter.h | 6 +-
.../controllers/JsonTreeReader.h | 6 +-
.../controllers/PersistentMapStateStorage.cpp | 11 +-
.../controllers/PersistentMapStateStorage.h | 5 +-
.../controllers/VolatileMapStateStorage.cpp | 11 +-
.../controllers/VolatileMapStateStorage.h | 5 +-
.../standard-processors/controllers/XMLReader.h | 7 +-
.../controllers/XMLRecordSetWriter.h | 7 +-
.../tests/unit/ControllerServiceTests.cpp | 4 +-
.../tests/unit/JsonRecordTests.cpp | 17 +--
.../tests/unit/TailFileTests.cpp | 3 +-
.../tests/unit/XMLReaderTests.cpp | 13 +-
.../tests/unit/XMLRecordSetWriterTests.cpp | 39 ++---
libminifi/include/FlowController.h | 2 +-
libminifi/include/SchedulingAgent.h | 2 +-
libminifi/include/c2/C2Protocol.h | 2 +-
libminifi/include/c2/ControllerSocketProtocol.h | 2 +-
libminifi/include/c2/HeartbeatReporter.h | 2 +-
.../controllers/NetworkPrioritizerService.h | 69 ++++-----
libminifi/include/controllers/SSLContextService.h | 87 +-----------
.../include/controllers/ThreadManagementService.h | 82 -----------
.../controllers/UpdatePolicyControllerService.h | 24 +---
libminifi/include/core/FlowConfiguration.h | 2 +-
libminifi/include/core/ProcessContextImpl.h | 13 +-
libminifi/include/core/ProcessGroup.h | 2 +-
.../include/core/controller/ControllerService.h | 158 +++++++++++++++++++++
.../core/controller/ControllerServiceLookup.h | 22 +--
.../core/controller/ControllerServiceNode.h | 29 ++--
.../core/controller/ControllerServiceNodeMap.h | 2 +-
.../core/controller/ControllerServiceProvider.h | 97 +++----------
.../ForwardingControllerServiceProvider.h | 18 +--
.../controller/StandardControllerServiceNode.h | 9 +-
.../controller/StandardControllerServiceProvider.h | 6 +-
libminifi/include/io/NetworkPrioritizer.h | 29 ----
libminifi/src/FlowController.cpp | 7 +-
libminifi/src/RemoteProcessGroupPort.cpp | 6 +-
libminifi/src/c2/C2Agent.cpp | 6 +-
libminifi/src/c2/ControllerSocketProtocol.cpp | 3 +-
libminifi/src/c2/protocols/RESTSender.cpp | 7 +-
.../src/controllers/NetworkPrioritizerService.cpp | 42 ++----
libminifi/src/controllers/SSLContextService.cpp | 69 ++++++++-
.../controllers/UpdatePolicyControllerService.cpp | 11 --
libminifi/src/core/ClassLoader.cpp | 43 ++++++
.../src/core/controller/ControllerServiceNode.cpp | 8 +-
.../core/controller/ControllerServiceProvider.cpp | 6 +-
libminifi/src/core/logging/LoggerConfiguration.cpp | 3 +-
.../src/core/state/nodes/ResponseNodeLoader.cpp | 8 +-
.../integration/C2ControllerEnableFailureTest.cpp | 21 +--
.../ControllerServiceIntegrationTests.cpp | 2 +-
.../keyvalue-tests/PersistentStateStorageTest.cpp | 3 +-
.../keyvalue-tests/VolatileMapStateStorageTest.cpp | 3 +-
.../test/libtest/integration/HTTPHandlers.cpp | 1 +
libminifi/test/libtest/integration/HTTPHandlers.h | 2 +-
.../test/libtest/unit/ControllerServiceUtils.h | 43 +++---
libminifi/test/libtest/unit/MockClasses.h | 31 ++--
libminifi/test/unit/BackTraceTests.cpp | 2 +-
libminifi/test/unit/ComponentManifestTests.cpp | 14 +-
libminifi/test/unit/JsonFlowSerializerTests.cpp | 4 +-
libminifi/test/unit/NetUtilsTest.cpp | 16 +--
.../test/unit/NetworkPrioritizerServiceTests.cpp | 45 +++---
libminifi/test/unit/ProcessorConfigUtilsTests.cpp | 28 ++--
libminifi/test/unit/UpdatePolicyTests.cpp | 25 ++--
libminifi/test/unit/YamlFlowSerializerTests.cpp | 4 +-
minifi-api/CMakeLists.txt | 1 +
.../controllers/AttributeProviderService.h | 4 +-
.../minifi-cpp/controllers/RecordSetReader.h | 6 +-
.../minifi-cpp/controllers/RecordSetWriter.h | 6 +-
.../controllers/SSLContextServiceInterface.h | 6 +-
.../controllers/ThreadManagementService.h | 75 ----------
minifi-api/include/minifi-cpp/core/ClassLoader.h | 3 +
.../core/ControllerServiceApiDefinition.h | 1 +
.../include/minifi-cpp/core/ProcessContext.h | 4 +-
.../core/controller/ControllerServiceApi.h | 28 ++--
.../core/controller/ControllerServiceContext.h | 26 ++--
.../core/controller/ControllerServiceDescriptor.h | 15 +-
.../core/controller/ControllerServiceFactory.h | 27 ++--
...ollerService.h => ControllerServiceInterface.h} | 16 +--
.../core/controller/ControllerServiceMetadata.h | 23 ++-
.../core/controller/ControllerServiceProvider.h | 54 -------
123 files changed, 879 insertions(+), 1386 deletions(-)
diff --git a/controller/MiNiFiController.cpp b/controller/MiNiFiController.cpp
index 64e94fef2..6a2c91680 100644
--- a/controller/MiNiFiController.cpp
+++ b/controller/MiNiFiController.cpp
@@ -30,7 +30,6 @@
#include "c2/ControllerSocketProtocol.h"
#include "controllers/SSLContextService.h"
#include "core/ConfigurationFactory.h"
-#include "minifi-cpp/core/controller/ControllerService.h"
#include "core/extension/ExtensionManager.h"
#include "properties/Configure.h"
#include "range/v3/algorithm/contains.hpp"
@@ -42,8 +41,7 @@ std::shared_ptr<minifi::controllers::SSLContextServiceInterface> getSSLContextSe
std::shared_ptr<minifi::controllers::SSLContextServiceInterface> secure_context;
std::string secure_str;
if (configuration->get(minifi::Configure::nifi_remote_input_secure, secure_str) && minifi::utils::string::toBool(secure_str).value_or(false)) {
- secure_context = std::make_shared<minifi::controllers::SSLContextService>("ControllerSocketProtocolSSL", configuration);
- secure_context->onEnable();
+ secure_context = minifi::controllers::SSLContextService::createAndEnable("ControllerSocketProtocolSSL", configuration);
}
return secure_context;
diff --git a/controller/tests/ControllerTests.cpp b/controller/tests/ControllerTests.cpp
index bd0149ca0..a2376de68 100644
--- a/controller/tests/ControllerTests.cpp
+++ b/controller/tests/ControllerTests.cpp
@@ -228,8 +228,7 @@ class ControllerTestFixture {
configuration_->set(minifi::Configure::nifi_security_client_private_key, (minifi::utils::file::FileUtils::get_executable_dir() / "resources" / "minifi-cpp-flow.key").string());
configuration_->set(minifi::Configure::nifi_security_client_pass_phrase, "abcdefgh");
configuration_->set(minifi::Configure::nifi_security_client_ca_certificate, (minifi::utils::file::FileUtils::get_executable_dir() / "resources" / "root-ca.pem").string());
- ssl_context_service_ = std::make_shared<controllers::SSLContextService>("SSLContextService", configuration_);
- ssl_context_service_->onEnable();
+ ssl_context_service_ = controllers::SSLContextService::createAndEnable("SSLContextService", configuration_);
controller_socket_data_.host = "localhost";
controller_socket_data_.port = 9997;
}
diff --git a/core-framework/include/core/Resource.h b/core-framework/include/core/Resource.h
index a4dd1be87..daa23bc92 100644
--- a/core-framework/include/core/Resource.h
+++ b/core-framework/include/core/Resource.h
@@ -30,6 +30,7 @@
#include "utils/OptionalUtils.h"
#include "utils/Macro.h"
#include "core/ProcessorFactoryImpl.h"
+#include "core/controller/ControllerServiceFactoryImpl.h"
#include "core/ObjectFactory.h"
#include "minifi-cpp/agent/agent_version.h"
@@ -62,6 +63,11 @@ class StaticClassType {
auto factory = std::unique_ptr<ProcessorFactory>(new ProcessorFactoryImpl<Class>(module_name));
getClassLoader().registerClass(construction_name, std::move(factory));
}
+ } else if constexpr (Type == ResourceType::ControllerService) {
+ for (const auto& construction_name : construction_names_) {
+ auto factory = std::unique_ptr<controller::ControllerServiceFactory>(new controller::ControllerServiceFactoryImpl<Class>(module_name));
+ getClassLoader().registerClass(construction_name, std::move(factory));
+ }
} else {
for (const auto& construction_name : construction_names_) {
auto factory = std::unique_ptr<ObjectFactory>(new DefaultObjectFactory<Class>(module_name));
diff --git a/core-framework/include/core/controller/ControllerService.h b/core-framework/include/core/controller/ControllerService.h
deleted file mode 100644
index bd0432802..000000000
--- a/core-framework/include/core/controller/ControllerService.h
+++ /dev/null
@@ -1,121 +0,0 @@
-/**
- *
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#pragma once
-
-#include <memory>
-#include <string>
-#include <utility>
-#include <vector>
-
-#include "minifi-cpp/properties/Configure.h"
-#include "core/Core.h"
-#include "core/ConfigurableComponentImpl.h"
-#include "core/Connectable.h"
-#include "minifi-cpp/core/controller/ControllerService.h"
-#include "minifi-cpp/core/ControllerServiceApiDefinition.h"
-
-#define ADD_COMMON_VIRTUAL_FUNCTIONS_FOR_CONTROLLER_SERVICES \
- bool supportsDynamicProperties() const override { return SupportsDynamicProperties; }
-
-namespace org::apache::nifi::minifi::core::controller {
-
-/**
- * Controller Service base class that contains some pure virtual methods.
- *
- * Design: OnEnable is executed when the controller service is being enabled.
- * Note that keeping state here must be protected in this function.
- */
-class ControllerServiceImpl : public ConfigurableComponentImpl, public ConnectableImpl, public virtual ControllerService {
- public:
- ControllerServiceImpl()
- : ConnectableImpl(core::className<ControllerService>()),
- configuration_(Configure::create()) {
- current_state_ = DISABLED;
- }
-
- explicit ControllerServiceImpl(std::string_view name, const utils::Identifier &uuid)
- : ConnectableImpl(name, uuid),
- configuration_(Configure::create()) {
- current_state_ = DISABLED;
- }
-
- explicit ControllerServiceImpl(std::string_view name)
- : ConnectableImpl(name),
- configuration_(Configure::create()) {
- current_state_ = DISABLED;
- }
-
- void initialize() override {
- current_state_ = ENABLED;
- }
-
- bool supportsDynamicRelationships() const final {
- return false;
- }
-
- ~ControllerServiceImpl() override {
- notifyStop();
- }
-
- /**
- * Replaces the configuration object within the controller service.
- */
- void setConfiguration(const std::shared_ptr<Configure> &configuration) override {
- configuration_ = configuration;
- }
-
- ControllerServiceState getState() const override {
- return current_state_.load();
- }
-
- /**
- * Function is called when Controller Services are enabled and being run
- */
- void onEnable() override {
- }
-
- /**
- * Function is called when Controller Services are disabled
- */
- void notifyStop() override {
- }
-
- void setState(ControllerServiceState state) override {
- current_state_ = state;
- if (state == DISABLED) {
- notifyStop();
- }
- }
-
- void setLinkedControllerServices(const std::vector<std::shared_ptr<controller::ControllerService>> &services) override {
- linked_services_ = services;
- }
-
-
- static constexpr auto ImplementsApis = std::array<ControllerServiceApiDefinition, 0>{};
-
- protected:
- std::vector<std::shared_ptr<controller::ControllerService> > linked_services_;
- std::shared_ptr<Configure> configuration_;
- mutable std::atomic<ControllerServiceState> current_state_;
- bool canEdit() override {
- return true;
- }
-};
-
-} // namespace org::apache::nifi::minifi::core::controller
diff --git a/core-framework/include/core/controller/ControllerServiceBase.h b/core-framework/include/core/controller/ControllerServiceBase.h
new file mode 100644
index 000000000..2fd22b299
--- /dev/null
+++ b/core-framework/include/core/controller/ControllerServiceBase.h
@@ -0,0 +1,113 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#pragma once
+
+#include <memory>
+#include <string>
+#include <utility>
+#include <vector>
+
+#include "minifi-cpp/properties/Configure.h"
+#include "core/Core.h"
+#include "core/ConfigurableComponentImpl.h"
+#include "core/Connectable.h"
+#include "minifi-cpp/core/controller/ControllerServiceApi.h"
+#include "minifi-cpp/core/controller/ControllerServiceInterface.h"
+#include "minifi-cpp/core/ControllerServiceApiDefinition.h"
+#include "minifi-cpp/core/controller/ControllerServiceMetadata.h"
+
+namespace org::apache::nifi::minifi::core::controller {
+
+// A base class that helps with controller service development, contains common functionalities.
+class ControllerServiceBase : public ControllerServiceApi {
+ public:
+ explicit ControllerServiceBase(ControllerServiceMetadata metadata)
+ : name_(std::move(metadata.name)),
+ uuid_(metadata.uuid),
+ logger_(std::move(metadata.logger)) {}
+
+ virtual void initialize() {}
+
+ void initialize(ControllerServiceDescriptor& descriptor) final {
+ gsl_Expects(!descriptor_);
+ descriptor_ = &descriptor;
+ auto guard = gsl::finally([&] {descriptor_ = nullptr;});
+ initialize();
+ }
+
+ void setSupportedProperties(std::span<const PropertyReference> properties) {
+ gsl_Expects(descriptor_);
+ descriptor_->setSupportedProperties(properties);
+ }
+
+ ~ControllerServiceBase() override {}
+
+ virtual void onEnable() {}
+
+ /**
+ * Function is called when Controller Services are enabled and being run
+ */
+ void onEnable(ControllerServiceContext& context, const std::shared_ptr<Configure>& configuration, const std::vector<std::shared_ptr<ControllerServiceInterface>>& linked_services) final {
+ configuration_ = configuration;
+ linked_services_ = linked_services;
+ gsl_Expects(!context_);
+ context_ = &context;
+ auto guard = gsl::finally([&] {context_ = nullptr;});
+ onEnable();
+ }
+
+ [[nodiscard]] nonstd::expected<std::string, std::error_code> getProperty(std::string_view name) const {
+ gsl_Expects(context_);
+ return context_->getProperty(name);
+ }
+
+ [[nodiscard]] nonstd::expected<std::vector<std::string>, std::error_code> getAllPropertyValues(std::string_view name) const {
+ gsl_Expects(context_);
+ return context_->getAllPropertyValues(name);
+ }
+
+ /**
+ * Function is called when Controller Services are disabled
+ */
+ void notifyStop() override {}
+
+ std::string getName() const {
+ return name_;
+ }
+
+ utils::Identifier getUUID() const {
+ return uuid_;
+ }
+
+
+ static constexpr auto ImplementsApis = std::array<ControllerServiceApiDefinition, 0>{};
+
+ protected:
+ std::string name_;
+ utils::Identifier uuid_;
+ std::vector<std::shared_ptr<controller::ControllerServiceInterface> > linked_services_;
+ std::shared_ptr<Configure> configuration_;
+ // valid during initialize, sink for supported properties
+ ControllerServiceDescriptor* descriptor_{nullptr};
+ // valid during onEnable, provides property access
+ ControllerServiceContext* context_{nullptr};
+
+ std::shared_ptr<core::logging::Logger> logger_;
+};
+
+} // namespace org::apache::nifi::minifi::core::controller
diff --git a/minifi-api/include/minifi-cpp/core/controller/ControllerServiceNode.h b/core-framework/include/core/controller/ControllerServiceFactoryImpl.h
similarity index 55%
rename from minifi-api/include/minifi-cpp/core/controller/ControllerServiceNode.h
rename to core-framework/include/core/controller/ControllerServiceFactoryImpl.h
index 02673531f..4060e9d18 100644
--- a/minifi-api/include/minifi-cpp/core/controller/ControllerServiceNode.h
+++ b/core-framework/include/core/controller/ControllerServiceFactoryImpl.h
@@ -1,5 +1,4 @@
/**
- *
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
@@ -15,32 +14,44 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
#pragma once
-#include <memory>
#include <string>
+#include <memory>
#include <utility>
-#include <vector>
-
-#include "minifi-cpp/core/Core.h"
-#include "minifi-cpp/core/ConfigurableComponent.h"
-#include "minifi-cpp/core/logging/Logger.h"
-#include "minifi-cpp/properties/Configure.h"
-#include "ControllerService.h"
-#include "io/validation.h"
-#include "minifi-cpp/Exception.h"
+#include "core/ClassName.h"
+#include "minifi-cpp/core/controller/ControllerServiceFactory.h"
namespace org::apache::nifi::minifi::core::controller {
-class ControllerServiceNode : public virtual CoreComponent, public virtual ConfigurableComponent {
+template<class T>
+class ControllerServiceFactoryImpl : public ControllerServiceFactory {
public:
- virtual std::shared_ptr<ControllerService> getControllerServiceImplementation() = 0;
- virtual const ControllerService* getControllerServiceImplementation() const = 0;
- virtual const std::vector<ControllerServiceNode*>& getLinkedControllerServices() const = 0;
- virtual bool canEnable() = 0;
- virtual bool enabled() = 0;
- virtual bool enable() = 0;
- virtual bool disable() = 0;
+ ControllerServiceFactoryImpl()
+ : class_name_(core::className<T>()) {
+ }
+
+ explicit ControllerServiceFactoryImpl(std::string group_name)
+ : group_name_(std::move(group_name)),
+ class_name_(core::className<T>()) {
+ }
+
+ std::string getGroupName() const override {
+ return group_name_;
+ }
+
+ std::unique_ptr<ControllerServiceApi> create(ControllerServiceMetadata metadata) override {
+ return std::make_unique<T>(metadata);
+ }
+
+ std::string getClassName() const override {
+ return std::string{class_name_};
+ }
+
+ protected:
+ std::string group_name_;
+ std::string_view class_name_;
};
} // namespace org::apache::nifi::minifi::core::controller
diff --git a/core-framework/include/utils/ThreadPool.h b/core-framework/include/utils/ThreadPool.h
index d65baf07a..f7ecf8cd6 100644
--- a/core-framework/include/utils/ThreadPool.h
+++ b/core-framework/include/utils/ThreadPool.h
@@ -37,8 +37,6 @@
#include "MinifiConcurrentQueue.h"
#include "Monitors.h"
#include "core/expect.h"
-#include "minifi-cpp/controllers/ThreadManagementService.h"
-#include "minifi-cpp/core/controller/ControllerServiceLookup.h"
#include "minifi-cpp/core/logging/Logger.h"
namespace org::apache::nifi::minifi::utils {
@@ -137,8 +135,7 @@ class WorkerThread {
*/
class ThreadPool {
public:
- ThreadPool(int max_worker_threads = 2,
- core::controller::ControllerServiceLookup* controller_service_provider = nullptr, std::string name = "NamelessPool");
+ ThreadPool(int max_worker_threads = 2, std::string name = "NamelessPool");
ThreadPool(const ThreadPool &other) = delete;
ThreadPool& operator=(const ThreadPool &other) = delete;
@@ -231,20 +228,6 @@ class ThreadPool {
start();
}
- void setControllerServiceProvider(core::controller::ControllerServiceLookup* controller_service_provider) {
- std::lock_guard<std::recursive_mutex> lock(manager_mutex_);
- bool was_running = running_;
- if (was_running) {
- shutdown();
- }
- controller_service_provider_ = controller_service_provider;
- if (was_running)
- start();
- }
-
- private:
- std::shared_ptr<controllers::ThreadManagementService> createThreadManager() const;
-
protected:
std::thread createThread(std::function<void()> &&functor) {
return std::thread([ functor ]() mutable {
@@ -272,8 +255,6 @@ class ThreadPool {
std::thread manager_thread_;
std::thread delayed_scheduler_thread_;
std::atomic<bool> running_;
- core::controller::ControllerServiceLookup* controller_service_provider_;
- std::shared_ptr<controllers::ThreadManagementService> thread_manager_;
ConcurrentQueue<std::shared_ptr<WorkerThread>> deceased_thread_queue_;
ConditionConcurrentQueue<Worker> worker_queue_;
std::priority_queue<Worker, std::vector<Worker>, DelayedTaskComparator> delayed_worker_queue_;
diff --git a/core-framework/src/utils/ThreadPool.cpp b/core-framework/src/utils/ThreadPool.cpp
index d46064722..07f23930e 100644
--- a/core-framework/src/utils/ThreadPool.cpp
+++ b/core-framework/src/utils/ThreadPool.cpp
@@ -22,12 +22,11 @@ using namespace std::literals::chrono_literals;
namespace org::apache::nifi::minifi::utils {
-ThreadPool::ThreadPool(int max_worker_threads, core::controller::ControllerServiceLookup* controller_service_provider, std::string name)
+ThreadPool::ThreadPool(int max_worker_threads, std::string name)
: thread_reduction_count_(0),
max_worker_threads_(max_worker_threads),
current_workers_(0),
running_(false),
- controller_service_provider_(controller_service_provider),
name_(std::move(name)),
logger_(core::logging::LoggerFactory<ThreadPool>::getLogger()) {
}
@@ -141,71 +140,15 @@ void ThreadPool::manageWorkers() {
}
}
- if (nullptr != thread_manager_) {
- while (running_) {
- auto wait_period = 500ms;
- {
- std::unique_lock<std::recursive_mutex> manager_lock(manager_mutex_, std::try_to_lock);
- if (!manager_lock.owns_lock()) {
- // Threadpool is being stopped/started or config is being changed, better wait a bit
- std::this_thread::sleep_for(10ms);
- continue;
- }
- if (thread_manager_->isAboveMax(current_workers_)) {
- auto max = thread_manager_->getMaxConcurrentTasks();
- auto differential = current_workers_ - max;
- thread_reduction_count_ += differential;
- } else if (thread_manager_->shouldReduce()) {
- if (current_workers_ > 1)
- thread_reduction_count_++;
- thread_manager_->reduce();
- } else if (thread_manager_->canIncrease() && max_worker_threads_ > current_workers_) { // increase slowly
- std::unique_lock<std::mutex> worker_queue_lock(worker_queue_mutex_);
- auto worker_thread = std::make_shared<WorkerThread>();
- worker_thread->thread_ = createThread([this, worker_thread] { run_tasks(worker_thread); });
- thread_queue_.push_back(worker_thread);
- current_workers_++;
- }
- std::shared_ptr<WorkerThread> thread_ref;
- while (deceased_thread_queue_.tryDequeue(thread_ref)) {
- std::unique_lock<std::mutex> worker_queue_lock(worker_queue_mutex_);
- if (thread_ref->thread_.joinable())
- thread_ref->thread_.join();
- thread_queue_.erase(std::remove(thread_queue_.begin(), thread_queue_.end(), thread_ref), thread_queue_.end());
- }
- }
- std::this_thread::sleep_for(wait_period);
- }
- } else {
- for (auto &thread : thread_queue_) {
- if (thread->thread_.joinable())
- thread->thread_.join();
- }
- }
-}
-
-std::shared_ptr<controllers::ThreadManagementService> ThreadPool::createThreadManager() const {
- if (!controller_service_provider_) {
- return nullptr;
- }
- auto service = controller_service_provider_->getControllerService("ThreadPoolManager");
- if (!service) {
- logger_->log_info("Could not find a ThreadPoolManager service");
- return nullptr;
+ for (auto &thread : thread_queue_) {
+ if (thread->thread_.joinable())
+ thread->thread_.join();
}
- auto thread_manager_service = std::dynamic_pointer_cast<controllers::ThreadManagementService>(service);
- if (!thread_manager_service) {
- logger_->log_error("Found ThreadPoolManager, but it is not a ThreadManagementService");
- return nullptr;
- }
- return thread_manager_service;
}
void ThreadPool::start() {
std::lock_guard<std::recursive_mutex> lock(manager_mutex_);
if (!running_) {
- thread_manager_ = createThreadManager();
-
running_ = true;
worker_queue_.start();
manager_thread_ = std::thread(&ThreadPool::manageWorkers, this);
diff --git a/encrypt-config/FlowConfigEncryptor.cpp b/encrypt-config/FlowConfigEncryptor.cpp
index dec950757..02499a5a8 100644
--- a/encrypt-config/FlowConfigEncryptor.cpp
+++ b/encrypt-config/FlowConfigEncryptor.cpp
@@ -97,7 +97,7 @@ std::vector<SensitiveItem> listSensitiveItems(const minifi::core::ProcessGroup &
std::unordered_set<minifi::utils::Identifier> processed_controller_services;
for (const auto* controller_service_node : process_group.getAllControllerServices()) {
gsl_Expects(controller_service_node);
- const auto* controller_service = controller_service_node->getControllerServiceImplementation();
+ const auto controller_service = controller_service_node->getControllerServiceImplementation();
gsl_Expects(controller_service);
if (processed_controller_services.contains(controller_service->getUUID())) {
continue;
diff --git a/extension-framework/include/controllers/AttributeProviderService.h b/extension-framework/include/controllers/AttributeProviderService.h
index 7e3836f53..f1659321c 100644
--- a/extension-framework/include/controllers/AttributeProviderService.h
+++ b/extension-framework/include/controllers/AttributeProviderService.h
@@ -21,18 +21,16 @@
#include <unordered_map>
#include <vector>
-#include "core/controller/ControllerService.h"
+#include "core/controller/ControllerServiceBase.h"
#include "minifi-cpp/controllers/AttributeProviderService.h"
namespace org::apache::nifi::minifi::controllers {
-class AttributeProviderServiceImpl : public core::controller::ControllerServiceImpl, public virtual AttributeProviderService {
+class AttributeProviderServiceImpl : public core::controller::ControllerServiceBase, public AttributeProviderService {
public:
- using ControllerServiceImpl::ControllerServiceImpl;
+ using ControllerServiceBase::ControllerServiceBase;
- void yield() override {}
- bool isRunning() const override { return getState() == core::controller::ControllerServiceState::ENABLED; }
- bool isWorkAvailable() override { return false; }
+ ControllerServiceInterface* getControllerServiceInterface() override {return this;}
};
} // namespace org::apache::nifi::minifi::controllers
diff --git a/extension-framework/include/controllers/RecordSetReader.h b/extension-framework/include/controllers/RecordSetReader.h
index ead6e019f..1c67cd833 100644
--- a/extension-framework/include/controllers/RecordSetReader.h
+++ b/extension-framework/include/controllers/RecordSetReader.h
@@ -17,14 +17,16 @@
#pragma once
#include "minifi-cpp/controllers/RecordSetReader.h"
-#include "core/controller/ControllerService.h"
+#include "core/controller/ControllerServiceBase.h"
namespace org::apache::nifi::minifi::core {
-class RecordSetReaderImpl : public virtual controller::ControllerServiceImpl, public virtual RecordSetReader {
+class RecordSetReaderImpl : public controller::ControllerServiceBase, public RecordSetReader {
public:
- using ControllerServiceImpl::ControllerServiceImpl;
+ using ControllerServiceBase::ControllerServiceBase;
+
+ ControllerServiceInterface* getControllerServiceInterface() override {return this;}
};
} // namespace org::apache::nifi::minifi::core
diff --git a/extension-framework/include/controllers/RecordSetWriter.h b/extension-framework/include/controllers/RecordSetWriter.h
index 8ba127b3d..ba893cb8b 100644
--- a/extension-framework/include/controllers/RecordSetWriter.h
+++ b/extension-framework/include/controllers/RecordSetWriter.h
@@ -17,13 +17,15 @@
#pragma once
#include "minifi-cpp/controllers/RecordSetWriter.h"
-#include "core/controller/ControllerService.h"
+#include "core/controller/ControllerServiceBase.h"
namespace org::apache::nifi::minifi::core {
-class RecordSetWriterImpl : public virtual controller::ControllerServiceImpl, public virtual RecordSetWriter {
+class RecordSetWriterImpl : public controller::ControllerServiceBase, public RecordSetWriter {
public:
- using ControllerServiceImpl::ControllerServiceImpl;
+ using ControllerServiceBase::ControllerServiceBase;
+
+ ControllerServiceInterface* getControllerServiceInterface() override {return this;}
};
} // namespace org::apache::nifi::minifi::core
diff --git a/extension-framework/include/controllers/keyvalue/KeyValueStateStorage.h b/extension-framework/include/controllers/keyvalue/KeyValueStateStorage.h
index 149c79539..5124cf92f 100644
--- a/extension-framework/include/controllers/keyvalue/KeyValueStateStorage.h
+++ b/extension-framework/include/controllers/keyvalue/KeyValueStateStorage.h
@@ -21,7 +21,7 @@
#include <string>
#include <unordered_map>
-#include "core/controller/ControllerService.h"
+#include "core/controller/ControllerServiceBase.h"
#include "core/Core.h"
#include "core/logging/LoggerFactory.h"
#include "minifi-cpp/core/StateManager.h"
@@ -30,9 +30,9 @@
namespace org::apache::nifi::minifi::controllers {
-class KeyValueStateStorage : public core::StateStorageImpl, public core::controller::ControllerServiceImpl {
+class KeyValueStateStorage : public core::StateStorageImpl, public core::controller::ControllerServiceBase, public core::controller::ControllerServiceInterface {
public:
- explicit KeyValueStateStorage(const std::string& name, const utils::Identifier& uuid = {});
+ using ControllerServiceBase::ControllerServiceBase;
static core::StateManager::State deserialize(const std::string& serialized);
static std::string serialize(const core::StateManager::State& kvs);
@@ -41,17 +41,6 @@ class KeyValueStateStorage : public core::StateStorageImpl, public core::control
std::unique_ptr<core::StateManager> getStateManager(const utils::Identifier& uuid) override;
std::unordered_map<utils::Identifier, core::StateManager::State> getAllStates() override;
- void yield() override {
- }
-
- bool isRunning() const override {
- return getState() == core::controller::ControllerServiceState::ENABLED;
- }
-
- bool isWorkAvailable() override {
- return false;
- }
-
virtual bool set(const std::string& key, const std::string& value) = 0;
virtual bool get(const std::string& key, std::string& value) = 0;
virtual bool get(std::unordered_map<std::string, std::string>& kvs) = 0;
@@ -59,11 +48,10 @@ class KeyValueStateStorage : public core::StateStorageImpl, public core::control
virtual bool clear() = 0;
virtual bool update(const std::string& key, const std::function<bool(bool /*exists*/, std::string& /*value*/)>& update_func) = 0;
virtual bool persist() = 0;
+ ControllerServiceInterface* getControllerServiceInterface() override {return this;}
private:
bool getAll(std::unordered_map<utils::Identifier, std::string>& kvs);
-
- std::shared_ptr<core::logging::Logger> logger_ = core::logging::LoggerFactory<KeyValueStateStorage>::getLogger();
};
} // namespace org::apache::nifi::minifi::controllers
diff --git a/extension-framework/include/utils/ProcessorConfigUtils.h b/extension-framework/include/utils/ProcessorConfigUtils.h
index 148435df8..312d168af 100644
--- a/extension-framework/include/utils/ProcessorConfigUtils.h
+++ b/extension-framework/include/utils/ProcessorConfigUtils.h
@@ -173,7 +173,7 @@ std::shared_ptr<ControllerServiceType> parseOptionalControllerService(const core
return nullptr;
}
- const std::shared_ptr<core::controller::ControllerService> service = context.getControllerService(*controller_service_name, processor_uuid);
+ const std::shared_ptr<core::controller::ControllerServiceInterface> service = context.getControllerService(*controller_service_name, processor_uuid);
if (!service) {
throw Exception(PROCESS_SCHEDULE_EXCEPTION, fmt::format("Controller service '{}' = '{}' not found", prop.name, *controller_service_name));
}
diff --git a/extension-framework/src/controllers/keyvalue/KeyValueStateStorage.cpp b/extension-framework/src/controllers/keyvalue/KeyValueStateStorage.cpp
index 26cccd547..697e8574d 100644
--- a/extension-framework/src/controllers/keyvalue/KeyValueStateStorage.cpp
+++ b/extension-framework/src/controllers/keyvalue/KeyValueStateStorage.cpp
@@ -62,10 +62,6 @@ core::StateManager::State KeyValueStateStorage::deserialize(const std::string& s
return retState;
}
-KeyValueStateStorage::KeyValueStateStorage(const std::string& name, const utils::Identifier& uuid)
- : ControllerServiceImpl(name, uuid) {
-}
-
std::unique_ptr<core::StateManager> KeyValueStateStorage::getStateManager(const utils::Identifier& uuid) {
return std::make_unique<KeyValueStateManager>(uuid, gsl::make_not_null(this));
}
diff --git a/extensions/aws/controllerservices/AWSCredentialsService.h b/extensions/aws/controllerservices/AWSCredentialsService.h
index b70038177..6b785d0ba 100644
--- a/extensions/aws/controllerservices/AWSCredentialsService.h
+++ b/extensions/aws/controllerservices/AWSCredentialsService.h
@@ -26,7 +26,7 @@
#include "aws/core/auth/AWSCredentials.h"
#include "utils/AWSInitializer.h"
-#include "core/controller/ControllerService.h"
+#include "core/controller/ControllerServiceBase.h"
#include "core/logging/LoggerFactory.h"
#include "minifi-cpp/core/PropertyDefinition.h"
#include "core/PropertyDefinitionBuilder.h"
@@ -37,15 +37,9 @@ class AWSCredentialsServiceTestAccessor;
namespace org::apache::nifi::minifi::aws::controllers {
-class AWSCredentialsService : public core::controller::ControllerServiceImpl {
+class AWSCredentialsService : public core::controller::ControllerServiceBase, public core::controller::ControllerServiceInterface {
public:
- explicit AWSCredentialsService(std::string_view name, const minifi::utils::Identifier &uuid = {})
- : ControllerServiceImpl(name, uuid) {
- }
-
- explicit AWSCredentialsService(std::string_view name, const std::shared_ptr<Configure>& /*configuration*/)
- : ControllerServiceImpl(name) {
- }
+ using ControllerServiceBase::ControllerServiceBase;
EXTENSIONAPI static constexpr const char* Description = "Manages the Amazon Web Services (AWS) credentials for an AWS account. This allows for multiple "
"AWS credential services to be defined. This also allows for multiple AWS related processors to reference this single "
@@ -76,23 +70,13 @@ class AWSCredentialsService : public core::controller::ControllerServiceImpl {
EXTENSIONAPI static constexpr bool SupportsDynamicProperties = false;
- ADD_COMMON_VIRTUAL_FUNCTIONS_FOR_CONTROLLER_SERVICES
void initialize() override;
- void yield() override {
- };
-
- bool isWorkAvailable() override {
- return false;
- };
-
- bool isRunning() const override {
- return getState() == core::controller::ControllerServiceState::ENABLED;
- }
-
void onEnable() override;
+ ControllerServiceInterface* getControllerServiceInterface() override {return this;}
+
std::optional<Aws::Auth::AWSCredentials> getAWSCredentials();
private:
diff --git a/extensions/aws/tests/AWSCredentialsServiceTest.cpp b/extensions/aws/tests/AWSCredentialsServiceTest.cpp
index d6377c8d0..c532d6243 100644
--- a/extensions/aws/tests/AWSCredentialsServiceTest.cpp
+++ b/extensions/aws/tests/AWSCredentialsServiceTest.cpp
@@ -23,7 +23,7 @@
#include "unit/Catch.h"
#include "controllerservices/AWSCredentialsService.h"
#include "unit/TestUtils.h"
-#include "minifi-cpp/core/controller/ControllerServiceNode.h"
+#include "core/controller/ControllerServiceNode.h"
class AWSCredentialsServiceTestAccessor {
public:
@@ -64,7 +64,7 @@ TEST_CASE_METHOD(AWSCredentialsServiceTestAccessor, "Test expired credentials ar
plan->setProperty(aws_credentials_service, minifi::aws::controllers::AWSCredentialsService::SecretKey, "secret");
aws_credentials_service->enable();
assert(aws_credentials_service->getControllerServiceImplementation() != nullptr);
- auto aws_credentials_impl = std::dynamic_pointer_cast<minifi::aws::controllers::AWSCredentialsService>(aws_credentials_service->getControllerServiceImplementation());
+ auto aws_credentials_impl = aws_credentials_service->getControllerServiceImplementation<minifi::aws::controllers::AWSCredentialsService>();
// Check intial credentials
REQUIRE(aws_credentials_impl->getAWSCredentials());
@@ -85,7 +85,7 @@ TEST_CASE_METHOD(AWSCredentialsServiceTestAccessor, "Test credentials from defau
plan->setProperty(aws_credentials_service, minifi::aws::controllers::AWSCredentialsService::UseDefaultCredentials, "true");
aws_credentials_service->enable();
assert(aws_credentials_service->getControllerServiceImplementation() != nullptr);
- auto aws_credentials_impl = std::dynamic_pointer_cast<minifi::aws::controllers::AWSCredentialsService>(aws_credentials_service->getControllerServiceImplementation());
+ auto aws_credentials_impl = aws_credentials_service->getControllerServiceImplementation<minifi::aws::controllers::AWSCredentialsService>();
// Check intial credentials
REQUIRE(aws_credentials_impl->getAWSCredentials());
diff --git a/extensions/aws/tests/MultipartUploadStateStorageTest.cpp b/extensions/aws/tests/MultipartUploadStateStorageTest.cpp
index 9e15f63e3..c791e85c9 100644
--- a/extensions/aws/tests/MultipartUploadStateStorageTest.cpp
+++ b/extensions/aws/tests/MultipartUploadStateStorageTest.cpp
@@ -31,7 +31,12 @@ class MultipartUploadStateStorageTestFixture {
public:
MultipartUploadStateStorageTestFixture() {
LogTestController::getInstance().setDebug<minifi::aws::s3::MultipartUploadStateStorage>();
- state_storage_ = std::make_unique<minifi::controllers::VolatileMapStateStorage>("KeyValueStateStorage");
+ const auto storage_uuid = minifi::utils::IdGenerator::getIdGenerator()->generate();
+ state_storage_ = std::make_unique<minifi::controllers::VolatileMapStateStorage>(core::controller::ControllerServiceMetadata{
+ .uuid = storage_uuid,
+ .name = "KeyValueStateStorage",
+ .logger = logging::LoggerFactory<minifi::controllers::VolatileMapStateStorage>::getLogger(storage_uuid)
+ });
state_manager_ = std::make_unique<minifi::controllers::KeyValueStateManager>(minifi::utils::IdGenerator::getIdGenerator()->generate(), gsl::make_not_null(state_storage_.get()));
upload_storage_ = std::make_unique<minifi::aws::s3::MultipartUploadStateStorage>(gsl::make_not_null(state_manager_.get()));
}
diff --git a/extensions/azure/controllerservices/AzureStorageCredentialsService.h b/extensions/azure/controllerservices/AzureStorageCredentialsService.h
index b93d42b22..38d4e7278 100644
--- a/extensions/azure/controllerservices/AzureStorageCredentialsService.h
+++ b/extensions/azure/controllerservices/AzureStorageCredentialsService.h
@@ -22,7 +22,7 @@
#include <memory>
#include <utility>
-#include "core/controller/ControllerService.h"
+#include "core/controller/ControllerServiceBase.h"
#include "core/logging/LoggerFactory.h"
#include "minifi-cpp/core/PropertyDefinition.h"
#include "core/PropertyDefinitionBuilder.h"
@@ -33,7 +33,7 @@
namespace org::apache::nifi::minifi::azure::controllers {
-class AzureStorageCredentialsService : public core::controller::ControllerServiceImpl {
+class AzureStorageCredentialsService : public core::controller::ControllerServiceBase, public core::controller::ControllerServiceInterface {
public:
EXTENSIONAPI static constexpr const char* Description = "Manages the credentials for an Azure Storage account. This allows for multiple Azure Storage related processors to reference this single "
"controller service so that Azure storage credentials can be managed and controlled in a central location.";
@@ -83,40 +83,22 @@ class AzureStorageCredentialsService : public core::controller::ControllerServic
ManagedIdentityClientId
});
+ using ControllerServiceBase::ControllerServiceBase;
EXTENSIONAPI static constexpr bool SupportsDynamicProperties = false;
- ADD_COMMON_VIRTUAL_FUNCTIONS_FOR_CONTROLLER_SERVICES
-
- explicit AzureStorageCredentialsService(std::string_view name, const minifi::utils::Identifier& uuid = {})
- : ControllerServiceImpl(name, uuid) {
- }
-
- explicit AzureStorageCredentialsService(std::string_view name, const std::shared_ptr<Configure>& /*configuration*/)
- : ControllerServiceImpl(name) {
- }
void initialize() override;
- void yield() override {
- }
-
- bool isWorkAvailable() override {
- return false;
- }
-
- bool isRunning() const override {
- return getState() == core::controller::ControllerServiceState::ENABLED;
- }
-
void onEnable() override;
+ ControllerServiceInterface* getControllerServiceInterface() override {return this;}
+
storage::AzureStorageCredentials getCredentials() const {
return credentials_;
}
private:
storage::AzureStorageCredentials credentials_;
- std::shared_ptr<core::logging::Logger> logger_ = core::logging::LoggerFactory<AzureStorageCredentialsService>::getLogger(uuid_);
};
} // namespace org::apache::nifi::minifi::azure::controllers
diff --git a/extensions/azure/processors/AzureStorageProcessorBase.cpp b/extensions/azure/processors/AzureStorageProcessorBase.cpp
index 7795a4786..e1fb93369 100644
--- a/extensions/azure/processors/AzureStorageProcessorBase.cpp
+++ b/extensions/azure/processors/AzureStorageProcessorBase.cpp
@@ -35,7 +35,7 @@ std::tuple<AzureStorageProcessorBase::GetCredentialsFromControllerResult, std::o
return std::make_tuple(GetCredentialsFromControllerResult::CONTROLLER_NAME_EMPTY, std::nullopt);
}
- std::shared_ptr<core::controller::ControllerService> service = context.getControllerService(service_name, getUUID());
+ std::shared_ptr<core::controller::ControllerServiceInterface> service = context.getControllerService(service_name, getUUID());
if (nullptr == service) {
logger_->log_error("Azure Storage credentials service with name: '{}' could not be found", service_name);
return std::make_tuple(GetCredentialsFromControllerResult::CONTROLLER_NAME_INVALID, std::nullopt);
diff --git a/extensions/civetweb/tests/ListenHTTPTests.cpp b/extensions/civetweb/tests/ListenHTTPTests.cpp
index 0f4f80ec8..b4c996468 100644
--- a/extensions/civetweb/tests/ListenHTTPTests.cpp
+++ b/extensions/civetweb/tests/ListenHTTPTests.cpp
@@ -135,8 +135,7 @@ class ListenHTTPTestsFixture {
config->set(minifi::Configure::nifi_security_client_private_key, (executable_dir / "resources" / client_cert).string());
config->set(minifi::Configure::nifi_security_client_pass_phrase, "Password12");
}
- ssl_context_service = std::make_shared<minifi::controllers::SSLContextService>("SSLContextService", config);
- ssl_context_service->onEnable();
+ ssl_context_service = minifi::controllers::SSLContextService::createAndEnable("SSLContextService", config);
}
void run_server() {
diff --git a/extensions/couchbase/controllerservices/CouchbaseClusterService.h b/extensions/couchbase/controllerservices/CouchbaseClusterService.h
index f443b1ee6..7d854d2e1 100644
--- a/extensions/couchbase/controllerservices/CouchbaseClusterService.h
+++ b/extensions/couchbase/controllerservices/CouchbaseClusterService.h
@@ -24,7 +24,7 @@
#include <mutex>
#include <variant>
-#include "core/controller/ControllerService.h"
+#include "core/controller/ControllerServiceBase.h"
#include "minifi-cpp/core/PropertyDefinition.h"
#include "core/PropertyDefinitionBuilder.h"
#include "minifi-cpp/core/PropertyValidator.h"
@@ -101,15 +101,9 @@ class CouchbaseClient {
namespace controllers {
-class CouchbaseClusterService : public core::controller::ControllerServiceImpl {
+class CouchbaseClusterService : public core::controller::ControllerServiceBase, public core::controller::ControllerServiceInterface {
public:
- explicit CouchbaseClusterService(std::string_view name, const minifi::utils::Identifier &uuid = {})
- : ControllerServiceImpl(name, uuid) {
- }
-
- explicit CouchbaseClusterService(std::string_view name, const std::shared_ptr<Configure>& /*configuration*/)
- : ControllerServiceImpl(name) {
- }
+ using ControllerServiceBase::ControllerServiceBase;
EXTENSIONAPI static constexpr const char* Description = "Provides a centralized Couchbase connection and bucket passwords management. Bucket passwords can be specified via dynamic properties.";
@@ -133,21 +127,9 @@ class CouchbaseClusterService : public core::controller::ControllerServiceImpl {
EXTENSIONAPI static constexpr bool SupportsDynamicProperties = false;
- ADD_COMMON_VIRTUAL_FUNCTIONS_FOR_CONTROLLER_SERVICES
void initialize() override;
- void yield() override {
- }
-
- bool isWorkAvailable() override {
- return false;
- }
-
- bool isRunning() const override {
- return getState() == core::controller::ControllerServiceState::ENABLED;
- }
-
void onEnable() override;
void notifyStop() override {
if (client_) {
@@ -155,6 +137,8 @@ class CouchbaseClusterService : public core::controller::ControllerServiceImpl {
}
}
+ ControllerServiceInterface* getControllerServiceInterface() override {return this;}
+
virtual nonstd::expected<CouchbaseUpsertResult, CouchbaseErrorType> upsert(const CouchbaseCollection& collection, CouchbaseValueType document_type,
const std::string& document_id, const std::vector<std::byte>& buffer, const ::couchbase::upsert_options& options) {
gsl_Expects(client_);
@@ -168,7 +152,6 @@ class CouchbaseClusterService : public core::controller::ControllerServiceImpl {
private:
std::unique_ptr<CouchbaseClient> client_;
- std::shared_ptr<core::logging::Logger> logger_ = core::logging::LoggerFactory<CouchbaseClusterService>::getLogger(uuid_);
};
} // namespace controllers
diff --git a/extensions/couchbase/tests/GetCouchbaseKeyTests.cpp b/extensions/couchbase/tests/GetCouchbaseKeyTests.cpp
index aa3e3f442..0839792c4 100644
--- a/extensions/couchbase/tests/GetCouchbaseKeyTests.cpp
+++ b/extensions/couchbase/tests/GetCouchbaseKeyTests.cpp
@@ -47,7 +47,7 @@ class GetCouchbaseKeyTestController : public TestController {
LogTestController::getInstance().setDebug<controllers::CouchbaseClusterService>();
LogTestController::getInstance().setDebug<processors::GetCouchbaseKey>();
auto controller_service_node = controller_.plan->addController("MockCouchbaseClusterService", "MockCouchbaseClusterService");
- mock_couchbase_cluster_service_ = std::dynamic_pointer_cast<MockCouchbaseClusterService>(controller_service_node->getControllerServiceImplementation());
+ mock_couchbase_cluster_service_ = controller_service_node->getControllerServiceImplementation<MockCouchbaseClusterService>();
gsl_Assert(mock_couchbase_cluster_service_);
REQUIRE(proc_->setProperty(processors::GetCouchbaseKey::CouchbaseClusterControllerService.name, "MockCouchbaseClusterService"));
}
diff --git a/extensions/couchbase/tests/MockCouchbaseClusterService.h b/extensions/couchbase/tests/MockCouchbaseClusterService.h
index 6566e85d4..fe14e46fc 100644
--- a/extensions/couchbase/tests/MockCouchbaseClusterService.h
+++ b/extensions/couchbase/tests/MockCouchbaseClusterService.h
@@ -48,7 +48,6 @@ class MockCouchbaseClusterService : public controllers::CouchbaseClusterService
public:
using CouchbaseClusterService::CouchbaseClusterService;
EXTENSIONAPI static constexpr bool SupportsDynamicProperties = false;
- ADD_COMMON_VIRTUAL_FUNCTIONS_FOR_CONTROLLER_SERVICES
void onEnable() override {}
void notifyStop() override {}
diff --git a/extensions/couchbase/tests/PutCouchbaseKeyTests.cpp b/extensions/couchbase/tests/PutCouchbaseKeyTests.cpp
index 51d180053..dff7abdfb 100644
--- a/extensions/couchbase/tests/PutCouchbaseKeyTests.cpp
+++ b/extensions/couchbase/tests/PutCouchbaseKeyTests.cpp
@@ -51,7 +51,7 @@ class PutCouchbaseKeyTestController : public TestController {
LogTestController::getInstance().setDebug<controllers::CouchbaseClusterService>();
LogTestController::getInstance().setDebug<processors::PutCouchbaseKey>();
auto controller_service_node = controller_.plan->addController("MockCouchbaseClusterService", "MockCouchbaseClusterService");
- mock_couchbase_cluster_service_ = std::dynamic_pointer_cast<MockCouchbaseClusterService>(controller_service_node->getControllerServiceImplementation());
+ mock_couchbase_cluster_service_ = controller_service_node->getControllerServiceImplementation<MockCouchbaseClusterService>();
gsl_Assert(mock_couchbase_cluster_service_);
REQUIRE(proc_->setProperty(processors::PutCouchbaseKey::CouchbaseClusterControllerService.name, "MockCouchbaseClusterService"));
}
diff --git a/extensions/elasticsearch/ElasticsearchCredentialsControllerService.h b/extensions/elasticsearch/ElasticsearchCredentialsControllerService.h
index 00c42cce7..8b428c0c2 100644
--- a/extensions/elasticsearch/ElasticsearchCredentialsControllerService.h
+++ b/extensions/elasticsearch/ElasticsearchCredentialsControllerService.h
@@ -23,14 +23,14 @@
#include <memory>
#include "http/HTTPClient.h"
-#include "core/controller/ControllerService.h"
+#include "core/controller/ControllerServiceBase.h"
#include "minifi-cpp/core/PropertyDefinition.h"
#include "core/PropertyDefinitionBuilder.h"
#include "utils/Enum.h"
namespace org::apache::nifi::minifi::extensions::elasticsearch {
-class ElasticsearchCredentialsControllerService : public core::controller::ControllerServiceImpl {
+class ElasticsearchCredentialsControllerService : public core::controller::ControllerServiceBase, public core::controller::ControllerServiceInterface {
public:
EXTENSIONAPI static constexpr const char* Description = "Elasticsearch/Opensearch Credentials Controller Service";
@@ -56,29 +56,19 @@ class ElasticsearchCredentialsControllerService : public core::controller::Contr
EXTENSIONAPI static constexpr bool SupportsDynamicProperties = false;
- ADD_COMMON_VIRTUAL_FUNCTIONS_FOR_CONTROLLER_SERVICES
- using ControllerServiceImpl::ControllerServiceImpl;
+ using ControllerServiceBase::ControllerServiceBase;
void initialize() override;
- void yield() override {}
-
- bool isWorkAvailable() override {
- return false;
- }
-
- bool isRunning() const override {
- return getState() == core::controller::ControllerServiceState::ENABLED;
- }
-
void onEnable() override;
+ ControllerServiceInterface* getControllerServiceInterface() override {return this;}
+
void authenticateClient(http::HTTPClient& client);
private:
std::optional<std::pair<std::string, std::string>> username_password_;
std::optional<std::string> api_key_;
- std::shared_ptr<core::logging::Logger> logger_ = core::logging::LoggerFactory<ElasticsearchCredentialsControllerService>::getLogger(uuid_);
};
} // namespace org::apache::nifi::minifi::extensions::elasticsearch
diff --git a/extensions/gcp/controllerservices/GCPCredentialsControllerService.h b/extensions/gcp/controllerservices/GCPCredentialsControllerService.h
index 20d7c65b2..acc6888e2 100644
--- a/extensions/gcp/controllerservices/GCPCredentialsControllerService.h
+++ b/extensions/gcp/controllerservices/GCPCredentialsControllerService.h
@@ -21,7 +21,7 @@
#include <string>
#include <memory>
-#include "core/controller/ControllerService.h"
+#include "core/controller/ControllerServiceBase.h"
#include "minifi-cpp/core/logging/Logger.h"
#include "core/logging/LoggerFactory.h"
#include "minifi-cpp/core/PropertyDefinition.h"
@@ -63,7 +63,7 @@ constexpr customize_t enum_name<CredentialsLocation>(CredentialsLocation value)
namespace org::apache::nifi::minifi::extensions::gcp {
-class GCPCredentialsControllerService : public core::controller::ControllerServiceImpl {
+class GCPCredentialsControllerService : public core::controller::ControllerServiceBase, public core::controller::ControllerServiceInterface {
public:
EXTENSIONAPI static constexpr const char* Description = "Manages the credentials for Google Cloud Platform. This allows for multiple Google Cloud Platform related processors "
"to reference this single controller service so that Google Cloud Platform credentials can be managed and controlled in a central location.";
@@ -91,25 +91,15 @@ class GCPCredentialsControllerService : public core::controller::ControllerServi
EXTENSIONAPI static constexpr bool SupportsDynamicProperties = false;
- ADD_COMMON_VIRTUAL_FUNCTIONS_FOR_CONTROLLER_SERVICES
- using ControllerServiceImpl::ControllerServiceImpl;
+ using ControllerServiceBase::ControllerServiceBase;
void initialize() override;
- void yield() override {
- }
-
- bool isWorkAvailable() override {
- return false;
- }
-
- bool isRunning() const override {
- return getState() == core::controller::ControllerServiceState::ENABLED;
- }
-
void onEnable() override;
+ ControllerServiceInterface* getControllerServiceInterface() override {return this;}
+
[[nodiscard]] const auto& getCredentials() const { return credentials_; }
protected:
@@ -119,6 +109,5 @@ class GCPCredentialsControllerService : public core::controller::ControllerServi
std::shared_ptr<google::cloud::storage::oauth2::Credentials> credentials_;
- std::shared_ptr<core::logging::Logger> logger_ = core::logging::LoggerFactory<GCPCredentialsControllerService>::getLogger(uuid_);
};
} // namespace org::apache::nifi::minifi::extensions::gcp
diff --git a/extensions/gcp/tests/GCPCredentialsControllerServiceTests.cpp b/extensions/gcp/tests/GCPCredentialsControllerServiceTests.cpp
index 969865a74..a045133d7 100644
--- a/extensions/gcp/tests/GCPCredentialsControllerServiceTests.cpp
+++ b/extensions/gcp/tests/GCPCredentialsControllerServiceTests.cpp
@@ -21,7 +21,7 @@
#include "../controllerservices/GCPCredentialsControllerService.h"
#include "core/Resource.h"
#include "core/Processor.h"
-#include "minifi-cpp/core/controller/ControllerServiceNode.h"
+#include "core/controller/ControllerServiceNode.h"
#include "rapidjson/document.h"
#include "rapidjson/stream.h"
#include "rapidjson/writer.h"
@@ -77,7 +77,7 @@ class GCPCredentialsTests : public ::testing::Test {
TestController test_controller_;
std::shared_ptr<TestPlan> plan_ = test_controller_.createPlan();
std::shared_ptr<minifi::core::controller::ControllerServiceNode> gcp_credentials_node_ = plan_->addController("GCPCredentialsControllerService", "gcp_credentials_controller_service");
- std::shared_ptr<GCPCredentialsControllerService> gcp_credentials_ = std::dynamic_pointer_cast<GCPCredentialsControllerService>(gcp_credentials_node_->getControllerServiceImplementation());
+ std::shared_ptr<GCPCredentialsControllerService> gcp_credentials_ = gcp_credentials_node_->getControllerServiceImplementation<GCPCredentialsControllerService>();
};
TEST_F(GCPCredentialsTests, DefaultGCPCredentialsWithoutEnv) {
diff --git a/extensions/kubernetes/controllerservice/KubernetesControllerService.cpp b/extensions/kubernetes/controllerservice/KubernetesControllerService.cpp
index e1118a17a..580970a06 100644
--- a/extensions/kubernetes/controllerservice/KubernetesControllerService.cpp
+++ b/extensions/kubernetes/controllerservice/KubernetesControllerService.cpp
@@ -31,22 +31,11 @@ extern "C" {
namespace org::apache::nifi::minifi::controllers {
-KubernetesControllerService::KubernetesControllerService(const std::string_view name, const utils::Identifier& uuid)
- : AttributeProviderServiceImpl(name, uuid),
- logger_{core::logging::LoggerFactory<KubernetesControllerService>::getLogger(uuid)} {
-}
-
-KubernetesControllerService::KubernetesControllerService(const std::string_view name, const std::shared_ptr<Configure>& configuration)
- : KubernetesControllerService{name} {
- setConfiguration(configuration);
- initialize();
-}
-
void KubernetesControllerService::initialize() {
std::lock_guard<std::mutex> lock(initialization_mutex_);
if (initialized_) { return; }
- ControllerServiceImpl::initialize();
+ ControllerServiceBase::initialize();
setSupportedProperties(Properties);
initialized_ = true;
}
diff --git a/extensions/kubernetes/controllerservice/KubernetesControllerService.h b/extensions/kubernetes/controllerservice/KubernetesControllerService.h
index c331c6127..245f42fd0 100644
--- a/extensions/kubernetes/controllerservice/KubernetesControllerService.h
+++ b/extensions/kubernetes/controllerservice/KubernetesControllerService.h
@@ -33,8 +33,7 @@ namespace org::apache::nifi::minifi::controllers {
class KubernetesControllerService : public AttributeProviderServiceImpl {
public:
- explicit KubernetesControllerService(const std::string_view name, const utils::Identifier& uuid = {});
- KubernetesControllerService(const std::string_view name, const std::shared_ptr<Configure>& configuration);
+ using AttributeProviderServiceImpl::AttributeProviderServiceImpl;
EXTENSIONAPI static constexpr const char* Description = "Controller service that provides access to the Kubernetes API";
@@ -56,7 +55,6 @@ class KubernetesControllerService : public AttributeProviderServiceImpl {
EXTENSIONAPI static constexpr bool SupportsDynamicProperties = false;
- ADD_COMMON_VIRTUAL_FUNCTIONS_FOR_CONTROLLER_SERVICES
void initialize() final;
void onEnable() override;
@@ -73,7 +71,6 @@ class KubernetesControllerService : public AttributeProviderServiceImpl {
std::optional<utils::Regex> namespace_filter_;
std::optional<utils::Regex> pod_name_filter_;
std::optional<utils::Regex> container_name_filter_;
- std::shared_ptr<core::logging::Logger> logger_;
std::unique_ptr<kubernetes::ApiClient> api_client_;
};
diff --git a/extensions/rocksdb-repos/FlowFileLoader.h b/extensions/rocksdb-repos/FlowFileLoader.h
index 99160ed45..51ca2232c 100644
--- a/extensions/rocksdb-repos/FlowFileLoader.h
+++ b/extensions/rocksdb-repos/FlowFileLoader.h
@@ -51,7 +51,7 @@ class FlowFileLoader {
private:
utils::TaskRescheduleInfo loadImpl(const std::vector<SwappedFlowFile>& flow_files, const std::shared_ptr<std::promise<FlowFilePtrVec>>& output);
- utils::ThreadPool thread_pool_{thread_count_, nullptr, "FlowFileLoaderThreadPool"};
+ utils::ThreadPool thread_pool_{thread_count_, "FlowFileLoaderThreadPool"};
gsl::not_null<minifi::internal::RocksDatabase*> db_;
diff --git a/extensions/rocksdb-repos/controllers/RocksDbStateStorage.cpp b/extensions/rocksdb-repos/controllers/RocksDbStateStorage.cpp
index 26956e480..ec0a50e94 100644
--- a/extensions/rocksdb-repos/controllers/RocksDbStateStorage.cpp
+++ b/extensions/rocksdb-repos/controllers/RocksDbStateStorage.cpp
@@ -28,16 +28,12 @@
namespace org::apache::nifi::minifi::controllers {
-RocksDbStateStorage::RocksDbStateStorage(const std::string& name, const utils::Identifier& uuid /*= utils::Identifier()*/)
- : KeyValueStateStorage(name, uuid) {
-}
-
RocksDbStateStorage::~RocksDbStateStorage() {
auto_persistor_.stop();
}
void RocksDbStateStorage::initialize() {
- ControllerServiceImpl::initialize();
+ ControllerServiceBase::initialize();
setSupportedProperties(Properties);
}
diff --git a/extensions/rocksdb-repos/controllers/RocksDbStateStorage.h b/extensions/rocksdb-repos/controllers/RocksDbStateStorage.h
index da19fc641..313b6098d 100644
--- a/extensions/rocksdb-repos/controllers/RocksDbStateStorage.h
+++ b/extensions/rocksdb-repos/controllers/RocksDbStateStorage.h
@@ -39,7 +39,7 @@ class RocksDbStateStorage : public KeyValueStateStorage {
static constexpr const char* ENCRYPTION_KEY_NAME = "nifi.state.storage.local.encryption.key";
static constexpr const char* ENCRYPTION_KEY_NAME_OLD = "nifi.state.management.provider.local.encryption.key";
- explicit RocksDbStateStorage(const std::string& name, const utils::Identifier& uuid = {});
+ using KeyValueStateStorage::KeyValueStateStorage;
~RocksDbStateStorage() override;
@@ -69,7 +69,6 @@ class RocksDbStateStorage : public KeyValueStateStorage {
EXTENSIONAPI static constexpr bool SupportsDynamicProperties = false;
- ADD_COMMON_VIRTUAL_FUNCTIONS_FOR_CONTROLLER_SERVICES
void initialize() override;
void onEnable() override;
@@ -94,8 +93,6 @@ class RocksDbStateStorage : public KeyValueStateStorage {
rocksdb::WriteOptions default_write_options;
AutoPersistor auto_persistor_;
bool verify_checksums_in_rocksdb_reads_ = false;
-
- std::shared_ptr<core::logging::Logger> logger_ = core::logging::LoggerFactory<RocksDbStateStorage>::getLogger();
};
} // namespace org::apache::nifi::minifi::controllers
diff --git a/extensions/smb/SmbConnectionControllerService.h b/extensions/smb/SmbConnectionControllerService.h
index 22e3e5377..84eb2f38e 100644
--- a/extensions/smb/SmbConnectionControllerService.h
+++ b/extensions/smb/SmbConnectionControllerService.h
@@ -26,7 +26,7 @@
#include "minifi-cpp/core/ProcessContext.h"
#include "minifi-cpp/core/PropertyDefinition.h"
#include "core/PropertyDefinitionBuilder.h"
-#include "core/controller/ControllerService.h"
+#include "core/controller/ControllerServiceBase.h"
#include "minifi-cpp/core/logging/Logger.h"
#include "core/logging/LoggerFactory.h"
#include "utils/Enum.h"
@@ -34,7 +34,7 @@
namespace org::apache::nifi::minifi::extensions::smb {
-class SmbConnectionControllerService : public core::controller::ControllerServiceImpl {
+class SmbConnectionControllerService : public core::controller::ControllerServiceBase, public core::controller::ControllerServiceInterface {
public:
EXTENSIONAPI static constexpr const char* Description = "SMB Connection Controller Service";
@@ -69,18 +69,15 @@ class SmbConnectionControllerService : public core::controller::ControllerServic
});
EXTENSIONAPI static constexpr bool SupportsDynamicProperties = false;
- ADD_COMMON_VIRTUAL_FUNCTIONS_FOR_CONTROLLER_SERVICES
- using ControllerServiceImpl::ControllerServiceImpl;
+ using ControllerServiceBase::ControllerServiceBase;
void initialize() override;
void onEnable() override;
void notifyStop() override;
- void yield() override {}
- bool isRunning() const override { return getState() == core::controller::ControllerServiceState::ENABLED; }
- bool isWorkAvailable() override { return false; }
+ ControllerServiceInterface* getControllerServiceInterface() override {return this;}
virtual std::error_code validateConnection();
virtual std::filesystem::path getPath() const { return server_path_; }
@@ -98,6 +95,5 @@ class SmbConnectionControllerService : public core::controller::ControllerServic
std::optional<Credentials> credentials_;
std::string server_path_;
NETRESOURCEA net_resource_;
- std::shared_ptr<core::logging::Logger> logger_ = core::logging::LoggerFactory<SmbConnectionControllerService>::getLogger(uuid_);
};
} // namespace org::apache::nifi::minifi::extensions::smb
diff --git a/extensions/smb/tests/FetchSmbTests.cpp b/extensions/smb/tests/FetchSmbTests.cpp
index 921b92341..059328153 100644
--- a/extensions/smb/tests/FetchSmbTests.cpp
+++ b/extensions/smb/tests/FetchSmbTests.cpp
@@ -48,7 +48,7 @@ TEST_CASE("FetchSmb tests") {
const auto fetch_smb = controller.getProcessor();
auto smb_connection_node = controller.plan->addController("MockSmbConnectionControllerService", "smb_connection_controller_service");
- auto mock_smb_connection_controller_service = std::dynamic_pointer_cast<MockSmbConnectionControllerService>(smb_connection_node->getControllerServiceImplementation());
+ auto mock_smb_connection_controller_service = smb_connection_node->getControllerServiceImplementation<MockSmbConnectionControllerService>();
REQUIRE(mock_smb_connection_controller_service);
constexpr std::string_view a_content = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus malesuada elit odio, sit amet viverra ante venenatis eget.";
diff --git a/extensions/smb/tests/ListAndFetchSmbTests.cpp b/extensions/smb/tests/ListAndFetchSmbTests.cpp
index e75462ebe..426466240 100644
--- a/extensions/smb/tests/ListAndFetchSmbTests.cpp
+++ b/extensions/smb/tests/ListAndFetchSmbTests.cpp
@@ -44,7 +44,7 @@ TEST_CASE("ListSmb and FetchSmb work together") {
plan->addConnection(fetch_smb, FetchSmb::Failure, read_from_failure_relationship);
auto smb_connection_node = plan->addController("MockSmbConnectionControllerService", "smb_connection_controller_service");
- auto mock_smb_connection_controller_service = std::dynamic_pointer_cast<MockSmbConnectionControllerService>(smb_connection_node->getControllerServiceImplementation());
+ auto mock_smb_connection_controller_service = smb_connection_node->getControllerServiceImplementation<MockSmbConnectionControllerService>();
REQUIRE(mock_smb_connection_controller_service);
plan->setProperty(list_smb, ListSmb::ConnectionControllerService, "smb_connection_controller_service");
diff --git a/extensions/smb/tests/ListSmbTests.cpp b/extensions/smb/tests/ListSmbTests.cpp
index 7269df7e3..9fcd020e6 100644
--- a/extensions/smb/tests/ListSmbTests.cpp
+++ b/extensions/smb/tests/ListSmbTests.cpp
@@ -57,7 +57,7 @@ TEST_CASE("ListSmb tests") {
const auto list_smb = controller.getProcessor();
auto smb_connection_node = controller.plan->addController("MockSmbConnectionControllerService", "smb_connection_controller_service");
- auto mock_smb_connection_controller_service = std::dynamic_pointer_cast<MockSmbConnectionControllerService>(smb_connection_node->getControllerServiceImplementation());
+ auto mock_smb_connection_controller_service = smb_connection_node->getControllerServiceImplementation<MockSmbConnectionControllerService>();
REQUIRE(mock_smb_connection_controller_service);
mock_smb_connection_controller_service->setPath(controller.createTempDirectory());
diff --git a/extensions/smb/tests/PutSmbTests.cpp b/extensions/smb/tests/PutSmbTests.cpp
index 1f86d83e2..4382df01b 100644
--- a/extensions/smb/tests/PutSmbTests.cpp
+++ b/extensions/smb/tests/PutSmbTests.cpp
@@ -54,7 +54,7 @@ TEST_CASE("PutSmb conflict resolution test") {
auto temp_directory = controller.createTempDirectory();
auto smb_connection_node = controller.plan->addController("MockSmbConnectionControllerService", "smb_connection_controller_service");
- auto mock_smb_connection_controller_service = std::dynamic_pointer_cast<MockSmbConnectionControllerService>(smb_connection_node->getControllerServiceImplementation());
+ auto mock_smb_connection_controller_service = smb_connection_node->getControllerServiceImplementation<MockSmbConnectionControllerService>();
REQUIRE(mock_smb_connection_controller_service);
mock_smb_connection_controller_service->setPath(temp_directory);
@@ -139,7 +139,7 @@ TEST_CASE("PutSmb create missing dirs test") {
auto temp_directory = controller.createTempDirectory();
auto smb_connection_node = controller.plan->addController("MockSmbConnectionControllerService", "smb_connection_controller_service");
- auto mock_smb_connection_controller_service = std::dynamic_pointer_cast<MockSmbConnectionControllerService>(smb_connection_node->getControllerServiceImplementation());
+ auto mock_smb_connection_controller_service = smb_connection_node->getControllerServiceImplementation<MockSmbConnectionControllerService>();
REQUIRE(mock_smb_connection_controller_service);
mock_smb_connection_controller_service->setPath(temp_directory);
diff --git a/extensions/smb/tests/SmbConnectionControllerServiceTests.cpp b/extensions/smb/tests/SmbConnectionControllerServiceTests.cpp
index 557810e6c..379698fb3 100644
--- a/extensions/smb/tests/SmbConnectionControllerServiceTests.cpp
+++ b/extensions/smb/tests/SmbConnectionControllerServiceTests.cpp
@@ -29,7 +29,7 @@ struct SmbConnectionControllerServiceFixture {
TestController test_controller_{};
std::shared_ptr<TestPlan> plan_ = test_controller_.createPlan();
std::shared_ptr<minifi::core::controller::ControllerServiceNode> smb_connection_node_ = plan_->addController("SmbConnectionControllerService", "smb_connection_controller_service");
- std::shared_ptr<SmbConnectionControllerService> smb_connection_ = std::dynamic_pointer_cast<SmbConnectionControllerService>(smb_connection_node_->getControllerServiceImplementation());
+ std::shared_ptr<SmbConnectionControllerService> smb_connection_ = smb_connection_node_->getControllerServiceImplementation<SmbConnectionControllerService>();
};
diff --git a/extensions/smb/tests/utils/MockSmbConnectionControllerService.h b/extensions/smb/tests/utils/MockSmbConnectionControllerService.h
index bc158df48..a70836e34 100644
--- a/extensions/smb/tests/utils/MockSmbConnectionControllerService.h
+++ b/extensions/smb/tests/utils/MockSmbConnectionControllerService.h
@@ -56,7 +56,6 @@ class MockSmbConnectionControllerService : public SmbConnectionControllerService
public:
using SmbConnectionControllerService::SmbConnectionControllerService;
EXTENSIONAPI static constexpr bool SupportsDynamicProperties = false;
- ADD_COMMON_VIRTUAL_FUNCTIONS_FOR_CONTROLLER_SERVICES
void onEnable() override {}
void notifyStop() override {}
diff --git a/extensions/sql/services/DatabaseService.cpp b/extensions/sql/services/DatabaseService.cpp
index 1ccae3b63..9dc179a58 100644
--- a/extensions/sql/services/DatabaseService.cpp
+++ b/extensions/sql/services/DatabaseService.cpp
@@ -19,7 +19,7 @@
#include <set>
#include "core/logging/LoggerFactory.h"
-#include "core/controller/ControllerService.h"
+#include "core/controller/ControllerServiceBase.h"
#include "DatabaseService.h"
#include "io/validation.h"
#include "minifi-cpp/properties/Configure.h"
@@ -33,7 +33,7 @@ void DatabaseService::initialize() {
return;
}
- ControllerServiceImpl::initialize();
+ ControllerServiceBase::initialize();
initializeProperties();
diff --git a/extensions/sql/services/DatabaseService.h b/extensions/sql/services/DatabaseService.h
index 03a5df71a..0509f25e4 100644
--- a/extensions/sql/services/DatabaseService.h
+++ b/extensions/sql/services/DatabaseService.h
@@ -22,7 +22,7 @@
#include <utility>
#include "core/logging/LoggerFactory.h"
-#include "core/controller/ControllerService.h"
+#include "core/controller/ControllerServiceBase.h"
#include "minifi-cpp/core/PropertyDefinition.h"
#include "core/PropertyDefinitionBuilder.h"
#include "data/DatabaseConnectors.h"
@@ -34,20 +34,9 @@ namespace org::apache::nifi::minifi::sql::controllers {
* services to internal services. While a controller service is generally configured from the flow,
* we want to follow the open closed principle and provide Database services
*/
-class DatabaseService : public core::controller::ControllerServiceImpl {
+class DatabaseService : public core::controller::ControllerServiceBase, public core::controller::ControllerServiceInterface {
public:
- explicit DatabaseService(const std::string_view name, const utils::Identifier &uuid = {})
- : ControllerServiceImpl(name, uuid),
- initialized_(false) {
- DatabaseService::initialize();
- }
-
- explicit DatabaseService(const std::string_view name, const std::shared_ptr<Configure> &configuration)
- : ControllerServiceImpl(name),
- initialized_(false) {
- ControllerServiceImpl::setConfiguration(configuration);
- DatabaseService::initialize();
- }
+ using ControllerServiceBase::ControllerServiceBase;
/**
* Parameters needed.
@@ -61,19 +50,10 @@ class DatabaseService : public core::controller::ControllerServiceImpl {
void initialize() override;
- void yield() override {
- }
-
- bool isRunning() const override {
- return getState() == core::controller::ControllerServiceState::ENABLED;
- }
-
- bool isWorkAvailable() override {
- return false;
- }
-
void onEnable() override;
+ ControllerServiceInterface* getControllerServiceInterface() override {return this;}
+
virtual std::unique_ptr<sql::Connection> getConnection() const = 0;
protected:
@@ -82,12 +62,9 @@ class DatabaseService : public core::controller::ControllerServiceImpl {
// initialization mutex.
std::recursive_mutex initialization_mutex_;
- bool initialized_;
+ bool initialized_{false};
std::string connection_string_;
-
- private:
- std::shared_ptr<core::logging::Logger> logger_ = core::logging::LoggerFactory<DatabaseService>::getLogger(uuid_);
};
} // namespace org::apache::nifi::minifi::sql::controllers
diff --git a/extensions/sql/services/ODBCConnector.h b/extensions/sql/services/ODBCConnector.h
index 5c3e6d845..303e505d2 100644
--- a/extensions/sql/services/ODBCConnector.h
+++ b/extensions/sql/services/ODBCConnector.h
@@ -22,7 +22,7 @@
#include <utility>
#include "core/logging/LoggerFactory.h"
-#include "core/controller/ControllerService.h"
+#include "core/controller/ControllerServiceBase.h"
#include "DatabaseService.h"
#include "data/SociConnectors.h"
@@ -36,26 +36,13 @@ namespace org::apache::nifi::minifi::sql::controllers {
*/
class ODBCService final : public DatabaseService {
public:
- explicit ODBCService(const std::string_view name, const utils::Identifier &uuid = {})
- : DatabaseService(name, uuid) {
- DatabaseService::initialize();
- }
-
- explicit ODBCService(const std::string_view name, const std::shared_ptr<Configure> &configuration)
- : DatabaseService(name) {
- ControllerServiceImpl::setConfiguration(configuration);
- DatabaseService::initialize();
- }
+ using DatabaseService::DatabaseService;
EXTENSIONAPI static constexpr const char* Description = "Controller service that provides ODBC database connection";
EXTENSIONAPI static constexpr auto Properties = DatabaseService::Properties;
EXTENSIONAPI static constexpr bool SupportsDynamicProperties = false;
- ADD_COMMON_VIRTUAL_FUNCTIONS_FOR_CONTROLLER_SERVICES
std::unique_ptr<sql::Connection> getConnection() const override;
-
- private:
- std::shared_ptr<core::logging::Logger> logger_ = core::logging::LoggerFactory<ODBCService>::getLogger(uuid_);
};
} // namespace org::apache::nifi::minifi::sql::controllers
diff --git a/extensions/sql/tests/mocks/MockODBCService.h b/extensions/sql/tests/mocks/MockODBCService.h
index 4de179125..fcf9a343e 100644
--- a/extensions/sql/tests/mocks/MockODBCService.h
+++ b/extensions/sql/tests/mocks/MockODBCService.h
@@ -30,30 +30,15 @@ namespace org::apache::nifi::minifi::sql::controllers {
class MockODBCService : public DatabaseService {
public:
- explicit MockODBCService(std::string_view name, utils::Identifier uuid = utils::Identifier())
- : DatabaseService(name, uuid),
- logger_(logging::LoggerFactory<MockODBCService>::getLogger(uuid)) {
- initialize();
- }
-
- explicit MockODBCService(std::string_view name, const std::shared_ptr<Configure> &configuration)
- : DatabaseService(name),
- logger_(logging::LoggerFactory<MockODBCService>::getLogger()) {
- setConfiguration(configuration);
- initialize();
- }
+ using DatabaseService::DatabaseService;
static constexpr const char* Description = "Controller service that provides Mock ODBC database connection";
static constexpr auto Properties = DatabaseService::Properties;
static constexpr bool SupportsDynamicProperties = false;
- ADD_COMMON_VIRTUAL_FUNCTIONS_FOR_CONTROLLER_SERVICES
std::unique_ptr<sql::Connection> getConnection() const override {
return std::make_unique<sql::MockODBCConnection>(connection_string_);
}
-
- private:
- std::shared_ptr<logging::Logger> logger_;
};
REGISTER_RESOURCE(MockODBCService, ControllerService);
diff --git a/extensions/standard-processors/controllers/JsonRecordSetWriter.h b/extensions/standard-processors/controllers/JsonRecordSetWriter.h
index dfb126b6d..e8f491b42 100644
--- a/extensions/standard-processors/controllers/JsonRecordSetWriter.h
+++ b/extensions/standard-processors/controllers/JsonRecordSetWriter.h
@@ -49,7 +49,7 @@ namespace org::apache::nifi::minifi::standard {
class JsonRecordSetWriter final : public core::RecordSetWriterImpl {
public:
- explicit JsonRecordSetWriter(const std::string_view name, const utils::Identifier& uuid = {}) : RecordSetWriterImpl(name, uuid) {}
+ using RecordSetWriterImpl::RecordSetWriterImpl;
JsonRecordSetWriter(JsonRecordSetWriter&&) = delete;
JsonRecordSetWriter(const JsonRecordSetWriter&) = delete;
@@ -84,7 +84,6 @@ class JsonRecordSetWriter final : public core::RecordSetWriterImpl {
EXTENSIONAPI static constexpr bool SupportsDynamicProperties = false;
EXTENSIONAPI static constexpr auto ImplementsApis = std::array{ RecordSetWriter::ProvidesApi };
- ADD_COMMON_VIRTUAL_FUNCTIONS_FOR_CONTROLLER_SERVICES
void write(const core::RecordSet& record_set, const std::shared_ptr<core::FlowFile>& flow_file, core::ProcessSession& session) override;
@@ -92,9 +91,6 @@ class JsonRecordSetWriter final : public core::RecordSetWriterImpl {
setSupportedProperties(Properties);
}
void onEnable() override;
- void yield() override {}
- bool isRunning() const override { return getState() == core::controller::ControllerServiceState::ENABLED; }
- bool isWorkAvailable() override { return false; }
private:
void writeAsArray(const core::RecordSet& record_set, const std::shared_ptr<core::FlowFile>& flow_file, core::ProcessSession& session) const;
diff --git a/extensions/standard-processors/controllers/JsonTreeReader.h b/extensions/standard-processors/controllers/JsonTreeReader.h
index dc9e9540a..8855c2ff3 100644
--- a/extensions/standard-processors/controllers/JsonTreeReader.h
+++ b/extensions/standard-processors/controllers/JsonTreeReader.h
@@ -22,7 +22,7 @@ namespace org::apache::nifi::minifi::standard {
class JsonTreeReader final : public core::RecordSetReaderImpl {
public:
- explicit JsonTreeReader(const std::string_view name, const utils::Identifier& uuid = {}) : RecordSetReaderImpl(name, uuid) {}
+ using RecordSetReaderImpl::RecordSetReaderImpl;
JsonTreeReader(JsonTreeReader&&) = delete;
JsonTreeReader(const JsonTreeReader&) = delete;
@@ -42,7 +42,6 @@ class JsonTreeReader final : public core::RecordSetReaderImpl {
EXTENSIONAPI static constexpr bool SupportsDynamicProperties = false;
EXTENSIONAPI static constexpr auto ImplementsApis = std::array{ RecordSetReader::ProvidesApi };
- ADD_COMMON_VIRTUAL_FUNCTIONS_FOR_CONTROLLER_SERVICES
nonstd::expected<core::RecordSet, std::error_code> read(io::InputStream& input_stream) override;
@@ -50,9 +49,6 @@ class JsonTreeReader final : public core::RecordSetReaderImpl {
setSupportedProperties(Properties);
}
void onEnable() override {}
- void yield() override {}
- bool isRunning() const override { return getState() == core::controller::ControllerServiceState::ENABLED; }
- bool isWorkAvailable() override { return false; }
};
} // namespace org::apache::nifi::minifi::standard
diff --git a/extensions/standard-processors/controllers/PersistentMapStateStorage.cpp b/extensions/standard-processors/controllers/PersistentMapStateStorage.cpp
index da7b444c4..1aa1ceb57 100644
--- a/extensions/standard-processors/controllers/PersistentMapStateStorage.cpp
+++ b/extensions/standard-processors/controllers/PersistentMapStateStorage.cpp
@@ -52,15 +52,6 @@ namespace {
namespace org::apache::nifi::minifi::controllers {
-PersistentMapStateStorage::PersistentMapStateStorage(const std::string& name, const utils::Identifier& uuid /*= utils::Identifier()*/)
- : KeyValueStateStorage(name, uuid) {
-}
-
-PersistentMapStateStorage::PersistentMapStateStorage(const std::string& name, const std::shared_ptr<Configure> &configuration)
- : KeyValueStateStorage(name) {
- setConfiguration(configuration);
-}
-
PersistentMapStateStorage::~PersistentMapStateStorage() {
auto_persistor_.stop();
persistNonVirtual();
@@ -123,7 +114,7 @@ bool PersistentMapStateStorage::parseLine(const std::string& line, std::string&
void PersistentMapStateStorage::initialize() {
// VolatileMapStateStorage::initialize() also calls setSupportedProperties, and we don't want that
- ControllerServiceImpl::initialize(); // NOLINT(bugprone-parent-virtual-call)
+ ControllerServiceBase::initialize(); // NOLINT(bugprone-parent-virtual-call)
setSupportedProperties(Properties);
}
diff --git a/extensions/standard-processors/controllers/PersistentMapStateStorage.h b/extensions/standard-processors/controllers/PersistentMapStateStorage.h
index e1a59d13e..cf64b50f1 100644
--- a/extensions/standard-processors/controllers/PersistentMapStateStorage.h
+++ b/extensions/standard-processors/controllers/PersistentMapStateStorage.h
@@ -37,8 +37,7 @@ namespace org::apache::nifi::minifi::controllers {
class PersistentMapStateStorage : public KeyValueStateStorage {
public:
- explicit PersistentMapStateStorage(const std::string& name, const utils::Identifier& uuid = {});
- explicit PersistentMapStateStorage(const std::string& name, const std::shared_ptr<Configure>& configuration);
+ using KeyValueStateStorage::KeyValueStateStorage;
~PersistentMapStateStorage() override;
@@ -68,7 +67,6 @@ class PersistentMapStateStorage : public KeyValueStateStorage {
EXTENSIONAPI static constexpr bool SupportsDynamicProperties = false;
- ADD_COMMON_VIRTUAL_FUNCTIONS_FOR_CONTROLLER_SERVICES
void onEnable() override;
void initialize() override;
@@ -99,7 +97,6 @@ class PersistentMapStateStorage : public KeyValueStateStorage {
std::string file_;
InMemoryKeyValueStorage storage_;
AutoPersistor auto_persistor_;
- std::shared_ptr<core::logging::Logger> logger_ = core::logging::LoggerFactory<PersistentMapStateStorage>::getLogger();
};
} // namespace org::apache::nifi::minifi::controllers
diff --git a/extensions/standard-processors/controllers/VolatileMapStateStorage.cpp b/extensions/standard-processors/controllers/VolatileMapStateStorage.cpp
index 1f7a375ce..67b40fbf1 100644
--- a/extensions/standard-processors/controllers/VolatileMapStateStorage.cpp
+++ b/extensions/standard-processors/controllers/VolatileMapStateStorage.cpp
@@ -20,17 +20,8 @@
namespace org::apache::nifi::minifi::controllers {
-VolatileMapStateStorage::VolatileMapStateStorage(const std::string& name, const utils::Identifier& uuid /*= utils::Identifier()*/)
- : KeyValueStateStorage(name, uuid) {
-}
-
-VolatileMapStateStorage::VolatileMapStateStorage(const std::string& name, const std::shared_ptr<Configure> &configuration)
- : KeyValueStateStorage(name) {
- setConfiguration(configuration);
-}
-
void VolatileMapStateStorage::initialize() {
- ControllerServiceImpl::initialize();
+ ControllerServiceBase::initialize();
setSupportedProperties(Properties);
}
diff --git a/extensions/standard-processors/controllers/VolatileMapStateStorage.h b/extensions/standard-processors/controllers/VolatileMapStateStorage.h
index d3b8c6b4d..129168102 100644
--- a/extensions/standard-processors/controllers/VolatileMapStateStorage.h
+++ b/extensions/standard-processors/controllers/VolatileMapStateStorage.h
@@ -36,8 +36,7 @@ namespace org::apache::nifi::minifi::controllers {
/// Key-value state storage purely in RAM without disk usage
class VolatileMapStateStorage : virtual public KeyValueStateStorage {
public:
- explicit VolatileMapStateStorage(const std::string& name, const utils::Identifier& uuid = {});
- explicit VolatileMapStateStorage(const std::string& name, const std::shared_ptr<Configure>& configuration);
+ using KeyValueStateStorage::KeyValueStateStorage;
EXTENSIONAPI static constexpr const char* Description = "A key-value service implemented by a locked std::unordered_map<std::string, std::string>";
EXTENSIONAPI static constexpr auto LinkedServices = core::PropertyDefinitionBuilder<>::createProperty("Linked Services")
@@ -45,7 +44,6 @@ class VolatileMapStateStorage : virtual public KeyValueStateStorage {
.build();
EXTENSIONAPI static constexpr auto Properties = std::to_array<core::PropertyReference>({LinkedServices});
EXTENSIONAPI static constexpr bool SupportsDynamicProperties = false;
- ADD_COMMON_VIRTUAL_FUNCTIONS_FOR_CONTROLLER_SERVICES
void initialize() override;
@@ -63,7 +61,6 @@ class VolatileMapStateStorage : virtual public KeyValueStateStorage {
private:
std::mutex mutex_;
InMemoryKeyValueStorage storage_;
- std::shared_ptr<core::logging::Logger> logger_ = core::logging::LoggerFactory<VolatileMapStateStorage>::getLogger();
};
} // namespace org::apache::nifi::minifi::controllers
diff --git a/extensions/standard-processors/controllers/XMLReader.h b/extensions/standard-processors/controllers/XMLReader.h
index 383be487d..158bffc34 100644
--- a/extensions/standard-processors/controllers/XMLReader.h
+++ b/extensions/standard-processors/controllers/XMLReader.h
@@ -26,7 +26,7 @@ namespace org::apache::nifi::minifi::standard {
class XMLReader final : public core::RecordSetReaderImpl {
public:
- explicit XMLReader(const std::string_view name, const utils::Identifier& uuid = {}) : RecordSetReaderImpl(name, uuid) {}
+ using RecordSetReaderImpl::RecordSetReaderImpl;
XMLReader(XMLReader&&) = delete;
XMLReader(const XMLReader&) = delete;
@@ -67,7 +67,6 @@ class XMLReader final : public core::RecordSetReaderImpl {
EXTENSIONAPI static constexpr bool SupportsDynamicProperties = false;
EXTENSIONAPI static constexpr auto ImplementsApis = std::array{ RecordSetReader::ProvidesApi };
- ADD_COMMON_VIRTUAL_FUNCTIONS_FOR_CONTROLLER_SERVICES
nonstd::expected<core::RecordSet, std::error_code> read(io::InputStream& input_stream) override;
@@ -75,9 +74,6 @@ class XMLReader final : public core::RecordSetReaderImpl {
setSupportedProperties(Properties);
}
void onEnable() override;
- void yield() override {}
- bool isRunning() const override { return getState() == core::controller::ControllerServiceState::ENABLED; }
- bool isWorkAvailable() override { return false; }
private:
void writeRecordField(core::RecordObject& record_object, const std::string& name, const std::string& value, bool write_pcdata_node = false) const;
@@ -90,7 +86,6 @@ class XMLReader final : public core::RecordSetReaderImpl {
bool parse_xml_attributes_ = false;
std::string attribute_prefix_;
bool expect_records_as_array_ = false;
- std::shared_ptr<core::logging::Logger> logger_ = core::logging::LoggerFactory<XMLReader>::getLogger();
};
} // namespace org::apache::nifi::minifi::standard
diff --git a/extensions/standard-processors/controllers/XMLRecordSetWriter.h b/extensions/standard-processors/controllers/XMLRecordSetWriter.h
index 6b1456113..46fc79c83 100644
--- a/extensions/standard-processors/controllers/XMLRecordSetWriter.h
+++ b/extensions/standard-processors/controllers/XMLRecordSetWriter.h
@@ -51,7 +51,7 @@ namespace org::apache::nifi::minifi::standard {
class XMLRecordSetWriter final : public core::RecordSetWriterImpl {
public:
- explicit XMLRecordSetWriter(const std::string_view name, const utils::Identifier& uuid = {}) : RecordSetWriterImpl(name, uuid) {}
+ using RecordSetWriterImpl::RecordSetWriterImpl;
XMLRecordSetWriter(XMLRecordSetWriter&&) = delete;
XMLRecordSetWriter(const XMLRecordSetWriter&) = delete;
@@ -103,7 +103,6 @@ class XMLRecordSetWriter final : public core::RecordSetWriterImpl {
EXTENSIONAPI static constexpr bool SupportsDynamicProperties = false;
EXTENSIONAPI static constexpr auto ImplementsApis = std::array{ RecordSetWriter::ProvidesApi };
- ADD_COMMON_VIRTUAL_FUNCTIONS_FOR_CONTROLLER_SERVICES
void write(const core::RecordSet& record_set, const std::shared_ptr<core::FlowFile>& flow_file, core::ProcessSession& session) override;
@@ -111,9 +110,6 @@ class XMLRecordSetWriter final : public core::RecordSetWriterImpl {
setSupportedProperties(Properties);
}
void onEnable() override;
- void yield() override {}
- bool isRunning() const override { return getState() == core::controller::ControllerServiceState::ENABLED; }
- bool isWorkAvailable() override { return false; }
private:
std::string formatXmlOutput(pugi::xml_document& xml_doc) const;
@@ -127,7 +123,6 @@ class XMLRecordSetWriter final : public core::RecordSetWriterImpl {
bool pretty_print_xml_ = false;
std::string name_of_record_tag_;
std::string name_of_root_tag_;
- std::shared_ptr<core::logging::Logger> logger_ = core::logging::LoggerFactory<XMLRecordSetWriter>::getLogger();
};
} // namespace org::apache::nifi::minifi::standard
diff --git a/extensions/standard-processors/tests/unit/ControllerServiceTests.cpp b/extensions/standard-processors/tests/unit/ControllerServiceTests.cpp
index 4b08faef5..705d0fd62 100644
--- a/extensions/standard-processors/tests/unit/ControllerServiceTests.cpp
+++ b/extensions/standard-processors/tests/unit/ControllerServiceTests.cpp
@@ -38,7 +38,7 @@ TEST_CASE("Test ControllerServicesMap", "[cs1]") {
core::controller::ControllerServiceNodeMap map;
REQUIRE(map.getAllControllerServices().empty());
- std::shared_ptr<core::controller::ControllerService> service = std::make_shared<MockControllerService>();
+ auto service = std::make_shared<core::controller::ControllerService>("", utils::Identifier{}, std::make_unique<MockControllerService>());
auto testNode = std::make_shared<core::controller::StandardControllerServiceNode>(service, "ID", std::make_shared<minifi::ConfigureImpl>());
map.put("ID", testNode);
@@ -67,7 +67,7 @@ TEST_CASE("Test StandardControllerServiceNode nullPtr", "[cs1]") {
}
std::shared_ptr<core::controller::StandardControllerServiceNode> newCsNode(const std::string& id) {
- std::shared_ptr<core::controller::ControllerService> service = std::make_shared<MockControllerService>();
+ auto service = std::make_shared<core::controller::ControllerService>("", utils::Identifier{}, std::make_unique<MockControllerService>());
auto testNode = std::make_shared<core::controller::StandardControllerServiceNode>(service, id, std::make_shared<minifi::ConfigureImpl>());
return testNode;
diff --git a/extensions/standard-processors/tests/unit/JsonRecordTests.cpp b/extensions/standard-processors/tests/unit/JsonRecordTests.cpp
index f6df18066..03cbd7bad 100644
--- a/extensions/standard-processors/tests/unit/JsonRecordTests.cpp
+++ b/extensions/standard-processors/tests/unit/JsonRecordTests.cpp
@@ -26,6 +26,7 @@
#include "unit/RecordSetTesters.h"
#include "unit/TestBase.h"
#include "unit/TestRecord.h"
+#include "unit/ControllerServiceUtils.h"
namespace org::apache::nifi::minifi::standard::test {
@@ -91,16 +92,16 @@ TEST_CASE("JsonRecordSetWriter tests") {
record_set.push_back(core::test::createSampleRecord());
record_set.push_back(core::test::createSampleRecord2());
- JsonRecordSetWriter json_record_set_writer{"json_record_set_writer"};
+ auto json_record_set_writer = minifi::test::utils::make_controller_service<JsonRecordSetWriter>("json_record_set_writer");
const auto [output_grouping, prety_print, output_str] = GENERATE(
std::make_tuple("One Line Per Object", "false", record_per_line_str),
std::make_tuple("Array", "false", array_compressed_str),
std::make_tuple("Array", "true", array_pretty_str));
- json_record_set_writer.initialize();
- CHECK(json_record_set_writer.setProperty(JsonRecordSetWriter::OutputGrouping.name, output_grouping));
- CHECK(json_record_set_writer.setProperty(JsonRecordSetWriter::PrettyPrint.name, prety_print));
- json_record_set_writer.onEnable();
- CHECK(core::test::testRecordWriter(json_record_set_writer, record_set, [expected = output_str](const auto& serialized_record_set) -> bool {
+ json_record_set_writer->initialize();
+ CHECK(json_record_set_writer->setProperty(JsonRecordSetWriter::OutputGrouping.name, output_grouping));
+ CHECK(json_record_set_writer->setProperty(JsonRecordSetWriter::PrettyPrint.name, prety_print));
+ json_record_set_writer->onEnable();
+ CHECK(core::test::testRecordWriter(*json_record_set_writer->getImplementation<JsonRecordSetWriter>(), record_set, [expected = output_str](const auto& serialized_record_set) -> bool {
return testJsonEquality(expected, serialized_record_set);
}));
}
@@ -110,9 +111,9 @@ TEST_CASE("JsonTreeReader tests") {
expected_record_set.push_back(core::test::createSampleRecord(true));
expected_record_set.push_back(core::test::createSampleRecord2(true));
- JsonTreeReader json_record_set_reader{"json_record_set_reader"};
+ auto json_record_set_reader = minifi::test::utils::make_controller_service<JsonTreeReader>("json_record_set_reader");
const auto input_str = GENERATE(record_per_line_str, array_compressed_str, array_pretty_str);
- CHECK(core::test::testRecordReader(json_record_set_reader, input_str, expected_record_set));
+ CHECK(core::test::testRecordReader(*json_record_set_reader->getImplementation<JsonTreeReader>(), input_str, expected_record_set));
}
} // namespace org::apache::nifi::minifi::standard::test
diff --git a/extensions/standard-processors/tests/unit/TailFileTests.cpp b/extensions/standard-processors/tests/unit/TailFileTests.cpp
index 6f4844575..3d6979a8e 100644
--- a/extensions/standard-processors/tests/unit/TailFileTests.cpp
+++ b/extensions/standard-processors/tests/unit/TailFileTests.cpp
@@ -1716,7 +1716,6 @@ class TestAttributeProviderService final : public minifi::controllers::Attribute
static constexpr const char* Description = "An attribute provider service which provides a constant set of records.";
static constexpr auto Properties = std::array<core::PropertyReference, 0>{};
static constexpr bool SupportsDynamicProperties = false;
- ADD_COMMON_VIRTUAL_FUNCTIONS_FOR_CONTROLLER_SERVICES
void initialize() override {};
void onEnable() override {};
@@ -1724,7 +1723,7 @@ class TestAttributeProviderService final : public minifi::controllers::Attribute
return std::vector<AttributeMap>{AttributeMap{{"color", "red"}, {"fruit", "apple"}, {"uid", "001"}, {"animal", "dog"}},
AttributeMap{{"color", "yellow"}, {"fruit", "banana"}, {"uid", "004"}, {"animal", "dolphin"}}};
}
- std::string_view name() const override { return "test"; }
+ [[nodiscard]] std::string_view name() const override { return "test"; }
};
REGISTER_RESOURCE(TestAttributeProviderService, ControllerService);
diff --git a/extensions/standard-processors/tests/unit/XMLReaderTests.cpp b/extensions/standard-processors/tests/unit/XMLReaderTests.cpp
index a98715127..e7e56ee0a 100644
--- a/extensions/standard-processors/tests/unit/XMLReaderTests.cpp
+++ b/extensions/standard-processors/tests/unit/XMLReaderTests.cpp
@@ -21,32 +21,33 @@
#include "controllers/XMLReader.h"
#include "unit/Catch.h"
#include "unit/TestBase.h"
+#include "unit/ControllerServiceUtils.h"
namespace org::apache::nifi::minifi::standard::test {
class XMLReaderTestFixture {
public:
- XMLReaderTestFixture() : xml_reader_("XMLReader") {
+ XMLReaderTestFixture() : xml_reader_(minifi::test::utils::make_controller_service<XMLReader>("XMLReader")) {
LogTestController::getInstance().clear();
LogTestController::getInstance().setTrace<XMLReader>();
}
auto readRecordsFromXml(const std::string& xml_input, const std::unordered_map<std::string_view, std::string_view>& properties = {}) {
initializeTestObject(xml_input, properties);
- return xml_reader_.read(buffer_stream_);
+ return xml_reader_->getImplementation<XMLReader>()->read(buffer_stream_);
}
private:
void initializeTestObject(const std::string& xml_input, const std::unordered_map<std::string_view, std::string_view>& properties = {}) {
- xml_reader_.initialize();
+ xml_reader_->initialize();
for (const auto& [key, value] : properties) {
- REQUIRE(xml_reader_.setProperty(key, std::string{value}));
+ REQUIRE(xml_reader_->setProperty(key, std::string{value}));
}
- xml_reader_.onEnable();
+ xml_reader_->onEnable();
buffer_stream_.write(reinterpret_cast<const uint8_t*>(xml_input.data()), xml_input.size());
}
- XMLReader xml_reader_;
+ std::unique_ptr<core::controller::ControllerService> xml_reader_;
io::BufferStream buffer_stream_;
};
diff --git a/extensions/standard-processors/tests/unit/XMLRecordSetWriterTests.cpp b/extensions/standard-processors/tests/unit/XMLRecordSetWriterTests.cpp
index dec6f7d5c..b83415717 100644
--- a/extensions/standard-processors/tests/unit/XMLRecordSetWriterTests.cpp
+++ b/extensions/standard-processors/tests/unit/XMLRecordSetWriterTests.cpp
@@ -26,6 +26,7 @@
#include "core/ProcessSession.h"
#include "catch2/generators/catch_generators.hpp"
#include "utils/StringUtils.h"
+#include "unit/ControllerServiceUtils.h"
namespace org::apache::nifi::minifi::test {
@@ -33,7 +34,7 @@ class XMLRecordSetWriterTestFixture {
public:
const core::Relationship Success{"success", "everything is fine"};
- XMLRecordSetWriterTestFixture() : xml_record_set_writer_("XMLRecordSetWriter") {
+ XMLRecordSetWriterTestFixture() : xml_record_set_writer_(minifi::test::utils::make_controller_service<standard::XMLRecordSetWriter>("XMLRecordSetWriter")) {
test_plan_ = test_controller_.createPlan();
dummy_processor_ = test_plan_->addProcessor("DummyProcessor", "dummyProcessor");
context_ = [this] {
@@ -44,14 +45,14 @@ class XMLRecordSetWriterTestFixture {
}
std::string writeRecordsAsXml(const core::RecordSet& record_set, const std::unordered_map<std::string_view, std::string_view>& properties) {
- xml_record_set_writer_.initialize();
+ xml_record_set_writer_->initialize();
for (const auto& [key, value] : properties) {
- REQUIRE(xml_record_set_writer_.setProperty(key, std::string{value}));
+ REQUIRE(xml_record_set_writer_->setProperty(key, std::string{value}));
}
- xml_record_set_writer_.onEnable();
+ xml_record_set_writer_->onEnable();
auto flow_file = process_session_->create();
- xml_record_set_writer_.write(record_set, flow_file, *process_session_);
+ xml_record_set_writer_->getImplementation<standard::XMLRecordSetWriter>()->write(record_set, flow_file, *process_session_);
transferAndCommit(flow_file);
std::string xml_content;
process_session_->read(*flow_file, [&xml_content](const std::shared_ptr<io::InputStream>& input_stream) {
@@ -125,31 +126,31 @@ class XMLRecordSetWriterTestFixture {
core::Processor* dummy_processor_;
std::shared_ptr<core::ProcessContext> context_;
std::unique_ptr<core::ProcessSession> process_session_;
- standard::XMLRecordSetWriter xml_record_set_writer_;
+ std::unique_ptr<core::controller::ControllerService> xml_record_set_writer_;
};
TEST_CASE_METHOD(XMLRecordSetWriterTestFixture, "If wrap elements of arrays is set then Array Tag Name property must be set", "[XMLRecordSetWriter]") {
- standard::XMLRecordSetWriter xml_record_set_writer("XMLRecordSetWriter");
- xml_record_set_writer.initialize();
- REQUIRE(xml_record_set_writer.setProperty(standard::XMLRecordSetWriter::NameOfRecordTag.name, "record"));
- REQUIRE(xml_record_set_writer.setProperty(standard::XMLRecordSetWriter::NameOfRootTag.name, "root"));
+ auto xml_record_set_writer = minifi::test::utils::make_controller_service<standard::XMLRecordSetWriter>("XMLRecordSetWriter");
+ xml_record_set_writer->initialize();
+ REQUIRE(xml_record_set_writer->setProperty(standard::XMLRecordSetWriter::NameOfRecordTag.name, "record"));
+ REQUIRE(xml_record_set_writer->setProperty(standard::XMLRecordSetWriter::NameOfRootTag.name, "root"));
std::string wrap_element_option = GENERATE("Use Property as Wrapper", "Use Property for Elements");
- REQUIRE(xml_record_set_writer.setProperty(standard::XMLRecordSetWriter::WrapElementsOfArrays.name, wrap_element_option));
- REQUIRE_THROWS_WITH(xml_record_set_writer.onEnable(),
+ REQUIRE(xml_record_set_writer->setProperty(standard::XMLRecordSetWriter::WrapElementsOfArrays.name, wrap_element_option));
+ REQUIRE_THROWS_WITH(xml_record_set_writer->onEnable(),
"Process Schedule Operation: Array Tag Name property must be set when Wrap Elements of Arrays is set to Use Property as Wrapper or Use Property for Elements");
}
TEST_CASE_METHOD(XMLRecordSetWriterTestFixture, "Name of Record Tag must be set", "[XMLRecordSetWriter]") {
- standard::XMLRecordSetWriter xml_record_set_writer("XMLRecordSetWriter");
- xml_record_set_writer.initialize();
- REQUIRE_THROWS_WITH(xml_record_set_writer.onEnable(), "Process Schedule Operation: Name of Record Tag property must be set");
+ auto xml_record_set_writer = minifi::test::utils::make_controller_service<standard::XMLRecordSetWriter>("XMLRecordSetWriter");
+ xml_record_set_writer->initialize();
+ REQUIRE_THROWS_WITH(xml_record_set_writer->onEnable(), "Process Schedule Operation: Name of Record Tag property must be set");
}
TEST_CASE_METHOD(XMLRecordSetWriterTestFixture, "Name of Root Tag must be set", "[XMLRecordSetWriter]") {
- standard::XMLRecordSetWriter xml_record_set_writer("XMLRecordSetWriter");
- xml_record_set_writer.initialize();
- REQUIRE(xml_record_set_writer.setProperty(standard::XMLRecordSetWriter::NameOfRecordTag.name, "record"));
- REQUIRE_THROWS_WITH(xml_record_set_writer.onEnable(), "Process Schedule Operation: Name of Root Tag property must be set");
+ auto xml_record_set_writer = minifi::test::utils::make_controller_service<standard::XMLRecordSetWriter>("XMLRecordSetWriter");
+ xml_record_set_writer->initialize();
+ REQUIRE(xml_record_set_writer->setProperty(standard::XMLRecordSetWriter::NameOfRecordTag.name, "record"));
+ REQUIRE_THROWS_WITH(xml_record_set_writer->onEnable(), "Process Schedule Operation: Name of Root Tag property must be set");
}
TEST_CASE_METHOD(XMLRecordSetWriterTestFixture, "Test empty record set", "[XMLRecordSetWriter]") {
diff --git a/libminifi/include/FlowController.h b/libminifi/include/FlowController.h
index 069a80692..ddeafba51 100644
--- a/libminifi/include/FlowController.h
+++ b/libminifi/include/FlowController.h
@@ -32,7 +32,7 @@
#include <utility>
#include <vector>
-#include "minifi-cpp/core/controller/ControllerServiceProvider.h"
+#include "core/controller/ControllerServiceProvider.h"
#include "core/controller/ForwardingControllerServiceProvider.h"
#include "core/FlowConfiguration.h"
#include "minifi-cpp/core/logging/Logger.h"
diff --git a/libminifi/include/SchedulingAgent.h b/libminifi/include/SchedulingAgent.h
index eeea76bcb..f1e3b892b 100644
--- a/libminifi/include/SchedulingAgent.h
+++ b/libminifi/include/SchedulingAgent.h
@@ -41,7 +41,7 @@
#include "minifi-cpp/core/logging/Logger.h"
#include "core/Processor.h"
#include "minifi-cpp/core/ProcessContext.h"
-#include "minifi-cpp/core/controller/ControllerServiceProvider.h"
+#include "core/controller/ControllerServiceProvider.h"
constexpr std::chrono::milliseconds SCHEDULING_WATCHDOG_CHECK_PERIOD = std::chrono::seconds(1);
constexpr std::chrono::milliseconds SCHEDULING_WATCHDOG_DEFAULT_ALERT_PERIOD = std::chrono::seconds(5);
diff --git a/libminifi/include/c2/C2Protocol.h b/libminifi/include/c2/C2Protocol.h
index e5e08fdfe..4223fddeb 100644
--- a/libminifi/include/c2/C2Protocol.h
+++ b/libminifi/include/c2/C2Protocol.h
@@ -23,7 +23,7 @@
#include <vector>
#include "C2Payload.h"
-#include "minifi-cpp/core/controller/ControllerServiceProvider.h"
+#include "core/controller/ControllerServiceProvider.h"
#include "properties/Configure.h"
#include "core/Connectable.h"
namespace org::apache::nifi::minifi::c2 {
diff --git a/libminifi/include/c2/ControllerSocketProtocol.h b/libminifi/include/c2/ControllerSocketProtocol.h
index 1ed31759e..e16e7e65a 100644
--- a/libminifi/include/c2/ControllerSocketProtocol.h
+++ b/libminifi/include/c2/ControllerSocketProtocol.h
@@ -26,7 +26,7 @@
#include "minifi-cpp/io/BaseStream.h"
#include "core/logging/LoggerFactory.h"
#include "core/state/nodes/StateMonitor.h"
-#include "minifi-cpp/core/controller/ControllerServiceProvider.h"
+#include "core/controller/ControllerServiceProvider.h"
#include "ControllerSocketReporter.h"
#include "utils/MinifiConcurrentQueue.h"
#include "asio/ip/tcp.hpp"
diff --git a/libminifi/include/c2/HeartbeatReporter.h b/libminifi/include/c2/HeartbeatReporter.h
index cd866db23..545412e13 100644
--- a/libminifi/include/c2/HeartbeatReporter.h
+++ b/libminifi/include/c2/HeartbeatReporter.h
@@ -23,7 +23,7 @@
#include "C2Protocol.h"
#include "C2Payload.h"
-#include "minifi-cpp/core/controller/ControllerServiceProvider.h"
+#include "core/controller/ControllerServiceProvider.h"
#include "properties/Configure.h"
#include "core/Connectable.h"
diff --git a/libminifi/include/controllers/NetworkPrioritizerService.h b/libminifi/include/controllers/NetworkPrioritizerService.h
index 9253659c8..6e8e8593b 100644
--- a/libminifi/include/controllers/NetworkPrioritizerService.h
+++ b/libminifi/include/controllers/NetworkPrioritizerService.h
@@ -25,7 +25,7 @@
#include "utils/StringUtils.h"
#include "io/validation.h"
-#include "core/controller/ControllerService.h"
+#include "core/controller/ControllerServiceBase.h"
#include "core/logging/LoggerFactory.h"
#include "minifi-cpp/core/PropertyDefinition.h"
#include "core/PropertyDefinitionBuilder.h"
@@ -39,29 +39,24 @@ namespace org::apache::nifi::minifi::controllers {
/**
* Purpose: Network prioritizer for selecting network interfaces through the flow configuration.
*/
-class NetworkPrioritizerService : public core::controller::ControllerServiceImpl, public minifi::io::NetworkPrioritizer, public utils::EnableSharedFromThis {
+class NetworkPrioritizerService : public core::controller::ControllerServiceBase, public core::controller::ControllerServiceInterface {
+ class StandardNetworkPrioritizer : public io::NetworkPrioritizer {
+ public:
+ void reduce_tokens(uint32_t size) override;
+
+ uint32_t tokens_{1000};
+ std::mutex token_mutex_;
+ uint32_t bytes_per_token_{0};
+ };
+
public:
- explicit NetworkPrioritizerService(std::string_view name,
- const utils::Identifier& uuid = {},
- std::shared_ptr<utils::timeutils::Clock> clock = std::make_shared<utils::timeutils::SteadyClock>())
- : ControllerServiceImpl(name, uuid),
- enabled_(false),
- max_throughput_(std::numeric_limits<uint64_t>::max()),
- max_payload_(std::numeric_limits<uint64_t>::max()),
- tokens_per_ms(2),
- tokens_(1000),
- timestamp_(0),
- bytes_per_token_(0),
- verify_interfaces_(true),
+ using ControllerServiceBase::ControllerServiceBase;
+ explicit NetworkPrioritizerService(core::controller::ControllerServiceMetadata metadata,
+ std::shared_ptr<utils::timeutils::Clock> clock)
+ : ControllerServiceBase(std::move(metadata)),
clock_(std::move(clock)) {
}
- explicit NetworkPrioritizerService(std::string_view name, const std::shared_ptr<Configure> &configuration)
- : NetworkPrioritizerService(name) {
- setConfiguration(configuration);
- initialize();
- }
-
MINIFIAPI static constexpr const char* Description = "Enables selection of networking interfaces on defined parameters to include output and payload size";
MINIFIAPI static constexpr auto NetworkControllers = core::PropertyDefinitionBuilder<>::createProperty("Network Controllers")
@@ -102,19 +97,14 @@ class NetworkPrioritizerService : public core::controller::ControllerServiceImpl
MINIFIAPI static constexpr bool SupportsDynamicProperties = false;
- ADD_COMMON_VIRTUAL_FUNCTIONS_FOR_CONTROLLER_SERVICES
void initialize() override;
- void yield() override;
-
- bool isRunning() const override;
-
- bool isWorkAvailable() override;
-
void onEnable() override;
- io::NetworkInterface getInterface(uint32_t size) override;
+ ControllerServiceInterface* getControllerServiceInterface() override {return this;}
+
+ io::NetworkInterface getInterface(uint32_t size);
protected:
std::string get_nearest_interface(const std::vector<std::string> &ifcs);
@@ -125,17 +115,15 @@ class NetworkPrioritizerService : public core::controller::ControllerServiceImpl
bool sufficient_tokens(uint32_t size);
- void reduce_tokens(uint32_t size) override;
-
- bool enabled_;
+ bool enabled_{false};
- uint64_t max_throughput_;
+ uint64_t max_throughput_{std::numeric_limits<uint64_t>::max()};
- uint64_t max_payload_;
+ uint64_t max_payload_{std::numeric_limits<uint64_t>::max()};
std::vector<std::string> network_controllers_;
- int tokens_per_ms;
+ int tokens_per_ms{2};
/**
* Using a variation of the token bucket algorithm.
@@ -146,19 +134,14 @@ class NetworkPrioritizerService : public core::controller::ControllerServiceImpl
* When a request arrives tokens will be decremented. We will compute the amount of data that can be sent per token from the configuration
* of max_throughput_
*/
- uint32_t tokens_;
-
- std::mutex token_mutex_;
-
- uint64_t timestamp_;
- uint32_t bytes_per_token_;
+ uint64_t timestamp_{0};
- bool verify_interfaces_;
+ bool verify_interfaces_{true};
private:
- std::shared_ptr<utils::timeutils::Clock> clock_;
- std::shared_ptr<core::logging::Logger> logger_ = core::logging::LoggerFactory<NetworkPrioritizerService>::getLogger(uuid_);
+ std::shared_ptr<StandardNetworkPrioritizer> prioritizer_{std::make_shared<StandardNetworkPrioritizer>()};
+ std::shared_ptr<utils::timeutils::Clock> clock_{std::make_shared<utils::timeutils::SteadyClock>()};
};
} // namespace org::apache::nifi::minifi::controllers
diff --git a/libminifi/include/controllers/SSLContextService.h b/libminifi/include/controllers/SSLContextService.h
index db5f19b26..c7d661876 100644
--- a/libminifi/include/controllers/SSLContextService.h
+++ b/libminifi/include/controllers/SSLContextService.h
@@ -37,8 +37,7 @@
#include "minifi-cpp/core/PropertyDefinition.h"
#include "core/PropertyDefinitionBuilder.h"
-#include "core/controller/ControllerService.h"
-#include "core/logging/LoggerFactory.h"
+#include "core/controller/ControllerServiceBase.h"
#include "io/validation.h"
#include "minifi-cpp/controllers/SSLContextServiceInterface.h"
#include "minifi-cpp/core/PropertyValidator.h"
@@ -72,76 +71,18 @@ class SSLContext {
* Justification: Abstracts SSL support out of processors into a
* configurable controller service.
*/
-class SSLContextService : public core::controller::ControllerServiceImpl, public SSLContextServiceInterface {
+class SSLContextService : public core::controller::ControllerServiceBase, public SSLContextServiceInterface {
public:
- explicit SSLContextService(std::string_view name, const utils::Identifier &uuid = {})
- : ControllerServiceImpl(name, uuid),
- initialized_(false),
- logger_(core::logging::LoggerFactory<SSLContextService>::getLogger(uuid_)) {
- }
-
- explicit SSLContextService(std::string_view name, const std::shared_ptr<Configure> &configuration)
- : ControllerServiceImpl(name),
- initialized_(false),
- logger_(core::logging::LoggerFactory<SSLContextService>::getLogger(uuid_)) {
- ControllerServiceImpl::setConfiguration(configuration);
- SSLContextService::initialize();
- auto setPropertyAndHandleError = [this](std::string_view property_name, std::string value) {
- auto result = ControllerServiceImpl::setProperty(property_name, std::move(value));
- if (!result) {
- logger_->log_error("Failed to set property {}: {}", property_name, result.error().message());
- }
- };
-
- // set the properties based on the configuration
- std::string value;
- if (configuration_->get(Configure::nifi_security_client_certificate, value)) {
- setPropertyAndHandleError(ClientCertificate.name, std::move(value));
- }
-
- if (configuration_->get(Configure::nifi_security_client_private_key, value)) {
- setPropertyAndHandleError(PrivateKey.name, std::move(value));
- }
-
- if (configuration_->get(Configure::nifi_security_client_pass_phrase, value)) {
- setPropertyAndHandleError(Passphrase.name, std::move(value));
- }
-
- if (configuration_->get(Configure::nifi_security_client_ca_certificate, value)) {
- setPropertyAndHandleError(CACertificate.name, std::move(value));
- }
-
- if (configuration_->get(Configure::nifi_security_use_system_cert_store, value)) {
- setPropertyAndHandleError(UseSystemCertStore.name, std::move(value));
- }
-
-#ifdef WIN32
- if (configuration_->get(Configure::nifi_security_windows_cert_store_location, value)) {
- setPropertyAndHandleError(CertStoreLocation.name, std::move(value));
- }
-
- if (configuration_->get(Configure::nifi_security_windows_server_cert_store, value)) {
- setPropertyAndHandleError(ServerCertStore.name, std::move(value));
- }
-
- if (configuration_->get(Configure::nifi_security_windows_client_cert_store, value)) {
- setPropertyAndHandleError(ClientCertStore.name, std::move(value));
- }
-
- if (configuration_->get(Configure::nifi_security_windows_client_cert_cn, value)) {
- setPropertyAndHandleError(ClientCertCN.name, std::move(value));
- }
+ using ControllerServiceBase::ControllerServiceBase;
- if (configuration_->get(Configure::nifi_security_windows_client_cert_key_usage, value)) {
- setPropertyAndHandleError(ClientCertKeyUsage.name, std::move(value));
- }
-#endif // WIN32
- }
+ static std::shared_ptr<SSLContextService> createAndEnable(std::string_view name, const std::shared_ptr<Configure> &configuration);
static constexpr auto ImplementsApis = std::array{ SSLContextServiceInterface::ProvidesApi };
void initialize() override;
+ ControllerServiceInterface* getControllerServiceInterface() override {return this;}
+
std::unique_ptr<SSLContext> createSSLContext();
const std::filesystem::path& getCertificateFile() const override;
@@ -149,17 +90,6 @@ class SSLContextService : public core::controller::ControllerServiceImpl, public
const std::filesystem::path& getPrivateKeyFile() const override;
const std::filesystem::path& getCACertificate() const override;
- void yield() override {
- }
-
- bool isRunning() const override {
- return getState() == core::controller::ControllerServiceState::ENABLED;
- }
-
- bool isWorkAvailable() override {
- return false;
- }
-
void setMinTlsVersion(long min_version) override { // NOLINT(runtime/int) long due to SSL lib API
minimum_tls_version_ = min_version;
}
@@ -242,13 +172,12 @@ class SSLContextService : public core::controller::ControllerServiceImpl, public
});
MINIFIAPI static constexpr bool SupportsDynamicProperties = false;
- ADD_COMMON_VIRTUAL_FUNCTIONS_FOR_CONTROLLER_SERVICES
protected:
virtual void initializeProperties();
mutable std::mutex initialization_mutex_;
- bool initialized_;
+ bool initialized_{false};
std::filesystem::path certificate_;
std::filesystem::path private_key_;
std::string passphrase_;
@@ -296,8 +225,6 @@ class SSLContextService : public core::controller::ControllerServiceImpl, public
long maximum_tls_version_ = -1; // NOLINT(runtime/int) long due to SSL lib API
void verifyCertificateExpiration();
-
- std::shared_ptr<core::logging::Logger> logger_;
}; // NOLINT the linter gets confused by the '{'s inside #ifdef's
} // namespace org::apache::nifi::minifi::controllers
diff --git a/libminifi/include/controllers/ThreadManagementService.h b/libminifi/include/controllers/ThreadManagementService.h
deleted file mode 100644
index 6dba08434..000000000
--- a/libminifi/include/controllers/ThreadManagementService.h
+++ /dev/null
@@ -1,82 +0,0 @@
-/**
- *
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#pragma once
-
-#include <iostream>
-#include <string>
-#include <memory>
-#include <utility>
-
-#include "utils/StringUtils.h"
-#include "io/validation.h"
-#include "core/controller/ControllerService.h"
-#include "core/logging/LoggerFactory.h"
-#include "minifi-cpp/controllers/ThreadManagementService.h"
-
-namespace org::apache::nifi::minifi::controllers {
-
-/**
- * Purpose: Thread management service provides a contextual awareness across
- * thread pools that enables us to deliver QOS to an agent.
- */
-class ThreadManagementServiceImpl : public core::controller::ControllerServiceImpl, public virtual ThreadManagementService {
- public:
- explicit ThreadManagementServiceImpl(std::string_view name, const utils::Identifier &uuid = {})
- : ControllerServiceImpl(name, uuid),
- logger_(core::logging::LoggerFactory<ThreadManagementService>::getLogger()) {
- }
-
- explicit ThreadManagementServiceImpl(std::string_view name, const std::shared_ptr<Configure>& /*configuration*/)
- : ControllerServiceImpl(name),
- logger_(core::logging::LoggerFactory<ThreadManagementService>::getLogger()) {
- }
-
- /**
- * Registration function to tabulate total threads.
- * @param threads threads from a thread pool.
- */
- void registerThreadCount(const int threads) override {
- thread_count_ += threads;
- }
-
- void initialize() override {
- ControllerServiceImpl::initialize();
- }
-
- void yield() override {
- }
-
- bool isRunning() const override {
- return getState() == core::controller::ControllerServiceState::ENABLED;
- }
-
- bool isWorkAvailable() override {
- return false;
- }
-
- void onEnable() override {
- }
-
- protected:
- std::atomic<int> thread_count_;
-
- private:
- std::shared_ptr<core::logging::Logger> logger_;
-};
-
-} // namespace org::apache::nifi::minifi::controllers
diff --git a/libminifi/include/controllers/UpdatePolicyControllerService.h b/libminifi/include/controllers/UpdatePolicyControllerService.h
index a4e6eebd8..df547ecb7 100644
--- a/libminifi/include/controllers/UpdatePolicyControllerService.h
+++ b/libminifi/include/controllers/UpdatePolicyControllerService.h
@@ -24,7 +24,7 @@
#include "utils/StringUtils.h"
#include "io/validation.h"
-#include "core/controller/ControllerService.h"
+#include "core/controller/ControllerServiceBase.h"
#include "core/logging/LoggerFactory.h"
#include "minifi-cpp/core/PropertyDefinition.h"
#include "core/PropertyDefinitionBuilder.h"
@@ -38,17 +38,9 @@ namespace org::apache::nifi::minifi::controllers {
* Purpose: UpdatePolicyControllerService allows a flow specific policy on allowing or disallowing updates.
* Since the flow dictates the purpose of a device it will also be used to dictate updates to specific components.
*/
-class UpdatePolicyControllerService : public core::controller::ControllerServiceImpl {
+class UpdatePolicyControllerService : public core::controller::ControllerServiceBase, public core::controller::ControllerServiceInterface {
public:
- explicit UpdatePolicyControllerService(std::string_view name, const utils::Identifier &uuid = {})
- : ControllerServiceImpl(name, uuid) {
- }
-
- explicit UpdatePolicyControllerService(std::string_view name, const std::shared_ptr<Configure> &configuration)
- : UpdatePolicyControllerService(name) {
- ControllerServiceImpl::setConfiguration(configuration);
- UpdatePolicyControllerService::initialize();
- }
+ using ControllerServiceBase::ControllerServiceBase;
MINIFIAPI static constexpr const char* Description = "UpdatePolicyControllerService allows a flow specific policy on allowing or disallowing updates. "
"Since the flow dictates the purpose of a device it will also be used to dictate updates to specific components.";
@@ -80,18 +72,13 @@ class UpdatePolicyControllerService : public core::controller::ControllerService
});
MINIFIAPI static constexpr bool SupportsDynamicProperties = false;
- ADD_COMMON_VIRTUAL_FUNCTIONS_FOR_CONTROLLER_SERVICES
void initialize() override;
- void yield() override;
-
- bool isRunning() const override;
-
- bool isWorkAvailable() override;
-
void onEnable() override;
+ ControllerServiceInterface* getControllerServiceInterface() override {return this;}
+
bool canUpdate(const std::string &property) const {
return policy_->canUpdate(property);
}
@@ -103,7 +90,6 @@ class UpdatePolicyControllerService : public core::controller::ControllerService
private:
bool persist_updates_ = false;
std::unique_ptr<state::UpdatePolicy> policy_ = std::make_unique<state::UpdatePolicy>(false);
- std::shared_ptr<core::logging::Logger> logger_ = core::logging::LoggerFactory<UpdatePolicyControllerService>::getLogger();
};
} // namespace org::apache::nifi::minifi::controllers
diff --git a/libminifi/include/core/FlowConfiguration.h b/libminifi/include/core/FlowConfiguration.h
index 2005d90aa..b79c87bfe 100644
--- a/libminifi/include/core/FlowConfiguration.h
+++ b/libminifi/include/core/FlowConfiguration.h
@@ -28,7 +28,7 @@
#include "core/Core.h"
#include "minifi-cpp/Connection.h"
#include "RemoteProcessGroupPort.h"
-#include "minifi-cpp/core/controller/ControllerServiceNode.h"
+#include "core/controller/ControllerServiceNode.h"
#include "core/controller/StandardControllerServiceProvider.h"
#include "core/reporting/SiteToSiteProvenanceReportingTask.h"
diff --git a/libminifi/include/core/ProcessContextImpl.h b/libminifi/include/core/ProcessContextImpl.h
index 9017de724..19d9464fe 100644
--- a/libminifi/include/core/ProcessContextImpl.h
+++ b/libminifi/include/core/ProcessContextImpl.h
@@ -39,8 +39,7 @@
#include "minifi-cpp/core/Property.h"
#include "minifi-cpp/core/Repository.h"
#include "minifi-cpp/core/StateStorage.h"
-#include "minifi-cpp/core/controller/ControllerServiceLookup.h"
-#include "minifi-cpp/core/controller/ControllerServiceProvider.h"
+#include "core/controller/ControllerServiceProvider.h"
#include "minifi-cpp/core/repository/FileSystemRepository.h"
#include "expression-language/Expression.h"
@@ -102,12 +101,12 @@ class ProcessContextImpl : public core::VariableRegistryImpl, public virtual Pro
// controller services
- std::shared_ptr<core::controller::ControllerService> getControllerService(const std::string &identifier, const utils::Identifier &processor_uuid) const override {
+ std::shared_ptr<core::controller::ControllerServiceInterface> getControllerService(const std::string &identifier, const utils::Identifier &processor_uuid) const override {
auto controller_service = controller_service_provider_ == nullptr ? nullptr : controller_service_provider_->getControllerService(identifier, processor_uuid);
if (!controller_service || controller_service->getState() != core::controller::ControllerServiceState::ENABLED) {
return nullptr;
}
- return controller_service;
+ return {controller_service, controller_service->getImplementation()};
}
static constexpr char const* DefaultStateStorageName = "defaultstatestorage";
@@ -123,7 +122,7 @@ class ProcessContextImpl : public core::VariableRegistryImpl, public virtual Pro
/* See if we have already created a default provider */
core::controller::ControllerServiceNode* node = controller_service_provider->getControllerServiceNode(DefaultStateStorageName);
- if (node != nullptr) { return std::dynamic_pointer_cast<core::StateStorage>(node->getControllerServiceImplementation()); }
+ if (node != nullptr) { return node->getControllerServiceImplementation<StateStorage>(); }
/* Try to get configuration options for default provider */
std::string always_persist;
@@ -146,7 +145,7 @@ class ProcessContextImpl : public core::VariableRegistryImpl, public virtual Pro
if (!storage->setProperty(extraProperty.first, extraProperty.second)) { return nullptr; }
}
if (!new_node->enable()) { return nullptr; }
- return std::dynamic_pointer_cast<core::StateStorage>(storage);
+ return {storage, storage->getImplementation<core::StateStorage>()};
};
std::string preferredType;
@@ -184,7 +183,7 @@ class ProcessContextImpl : public core::VariableRegistryImpl, public virtual Pro
logger->log_error("Failed to find the StateStorage {} defined by {}", requestedStateStorageName, minifi::Configure::nifi_state_storage_local);
return nullptr;
}
- return std::dynamic_pointer_cast<core::StateStorage>(node->getControllerServiceImplementation());
+ return node->getControllerServiceImplementation<core::StateStorage>();
} else {
auto state_storage = getOrCreateDefaultStateStorage(controller_service_provider, configuration);
if (state_storage == nullptr) { logger->log_error("Failed to create default StateStorage"); }
diff --git a/libminifi/include/core/ProcessGroup.h b/libminifi/include/core/ProcessGroup.h
index 9e8fba8ce..de813d5f3 100644
--- a/libminifi/include/core/ProcessGroup.h
+++ b/libminifi/include/core/ProcessGroup.h
@@ -36,7 +36,7 @@
#include "CronDrivenSchedulingAgent.h"
#include "Port.h"
#include "minifi-cpp/core/logging/Logger.h"
-#include "minifi-cpp/core/controller/ControllerServiceNode.h"
+#include "core/controller/ControllerServiceNode.h"
#include "controller/ControllerServiceNodeMap.h"
#include "utils/Id.h"
#include "http/BaseHTTPClient.h"
diff --git a/libminifi/include/core/controller/ControllerService.h b/libminifi/include/core/controller/ControllerService.h
new file mode 100644
index 000000000..c80830db7
--- /dev/null
+++ b/libminifi/include/core/controller/ControllerService.h
@@ -0,0 +1,158 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#pragma once
+
+#include <memory>
+#include <string>
+#include <utility>
+#include <vector>
+
+#include "minifi-cpp/properties/Configure.h"
+#include "core/Core.h"
+#include "core/ConfigurableComponentImpl.h"
+#include "core/Connectable.h"
+#include "minifi-cpp/core/controller/ControllerServiceApi.h"
+#include "minifi-cpp/core/ControllerServiceApiDefinition.h"
+
+namespace org::apache::nifi::minifi::core::controller {
+
+enum ControllerServiceState {
+ DISABLED,
+ DISABLING,
+ ENABLING,
+ ENABLED
+};
+
+// Wrapper class to manage common functionalities of controller service implementations (properties, name, id, etc)
+class ControllerService : public ConfigurableComponentImpl, public CoreComponentImpl {
+ class ControllerServiceDescriptorImpl : public ControllerServiceDescriptor {
+ public:
+ explicit ControllerServiceDescriptorImpl(ControllerService& impl): impl_(impl) {}
+ void setSupportedProperties(std::span<const PropertyReference> properties) override;
+
+ private:
+ ControllerService& impl_;
+ };
+
+ class ControllerServiceContextImpl : public ControllerServiceContext {
+ public:
+ explicit ControllerServiceContextImpl(ControllerService& impl): impl_(impl) {}
+ [[nodiscard]] nonstd::expected<std::string, std::error_code> getProperty(std::string_view name) const override;
+ [[nodiscard]] nonstd::expected<std::vector<std::string>, std::error_code> getAllPropertyValues(std::string_view name) const override;
+
+ private:
+ ControllerService& impl_;
+ };
+
+ public:
+ explicit ControllerService(std::string_view name, const utils::Identifier& uuid, std::unique_ptr<ControllerServiceApi> impl)
+ : CoreComponentImpl(name, uuid),
+ impl_(std::move(impl)),
+ configuration_(Configure::create()) {
+ current_state_ = DISABLED;
+ }
+
+ void initialize() final {
+ ControllerServiceDescriptorImpl descriptor{*this};
+ impl_->initialize(descriptor);
+ }
+
+ bool supportsDynamicRelationships() const final {
+ return false;
+ }
+
+ ~ControllerService() override {
+ notifyStop();
+ }
+
+ /**
+ * Replaces the configuration object within the controller service.
+ */
+ void setConfiguration(const std::shared_ptr<Configure> &configuration) {
+ configuration_ = configuration;
+ }
+
+ ControllerServiceState getState() const {
+ return current_state_.load();
+ }
+
+ /**
+ * Function is called when Controller Services are enabled and being run
+ */
+ void onEnable() {
+ ControllerServiceContextImpl context{*this};
+ std::vector<std::shared_ptr<ControllerServiceInterface>> service_interfaces;
+ for (auto& service : linked_services_) {
+ service_interfaces.emplace_back(std::shared_ptr<ControllerServiceInterface>(service, service->impl_->getControllerServiceInterface()));
+ }
+ impl_->onEnable(context, configuration_, service_interfaces);
+ }
+
+ /**
+ * Function is called when Controller Services are disabled
+ */
+ void notifyStop() {
+ impl_->notifyStop();
+ }
+
+ void setState(ControllerServiceState state) {
+ current_state_ = state;
+ if (state == DISABLED) {
+ notifyStop();
+ }
+ }
+
+ void setLinkedControllerServices(const std::vector<std::shared_ptr<controller::ControllerService>> &services) {
+ linked_services_ = services;
+ }
+
+ template<typename T = ControllerServiceInterface>
+ gsl::not_null<T*> getImplementation() {
+ return gsl::make_not_null(dynamic_cast<T*>(impl_->getControllerServiceInterface()));
+ }
+
+ bool supportsDynamicProperties() const final {
+ return false;
+ }
+
+ static constexpr auto ImplementsApis = std::array<ControllerServiceApiDefinition, 0>{};
+
+ protected:
+ std::unique_ptr<ControllerServiceApi> impl_;
+ std::vector<std::shared_ptr<controller::ControllerService> > linked_services_;
+ std::shared_ptr<Configure> configuration_;
+ mutable std::atomic<ControllerServiceState> current_state_;
+ bool canEdit() override {
+ return true;
+ }
+};
+
+inline void ControllerService::ControllerServiceDescriptorImpl::setSupportedProperties(std::span<const PropertyReference> properties) {
+ impl_.setSupportedProperties(properties);
+}
+
+inline nonstd::expected<std::string, std::error_code> ControllerService::ControllerServiceContextImpl::getProperty(std::string_view name) const {
+ return impl_.getProperty(name);
+}
+
+inline nonstd::expected<std::vector<std::string>, std::error_code> ControllerService::ControllerServiceContextImpl::getAllPropertyValues(std::string_view name) const {
+ return impl_.getAllPropertyValues(name);
+}
+
+
+} // namespace org::apache::nifi::minifi::core::controller
diff --git a/minifi-api/include/minifi-cpp/core/controller/ControllerServiceLookup.h b/libminifi/include/core/controller/ControllerServiceLookup.h
similarity index 73%
rename from minifi-api/include/minifi-cpp/core/controller/ControllerServiceLookup.h
rename to libminifi/include/core/controller/ControllerServiceLookup.h
index 89d13baa1..29a219f9d 100644
--- a/minifi-api/include/minifi-cpp/core/controller/ControllerServiceLookup.h
+++ b/libminifi/include/core/controller/ControllerServiceLookup.h
@@ -22,7 +22,7 @@
#include <map>
#include "minifi-cpp/core/Core.h"
#include "minifi-cpp/core/ConfigurableComponent.h"
-#include "ControllerService.h"
+#include "core/controller/ControllerService.h"
namespace org::apache::nifi::minifi::core::controller {
@@ -54,26 +54,6 @@ class ControllerServiceLookup {
* @return controller service reference.
*/
virtual std::shared_ptr<ControllerService> getControllerService(const std::string &identifier, const utils::Identifier &processor_uuid) const = 0;
-
- /**
- * Detects if controller service is enabled.
- * @param identifier reference string for controller service.
- * @return true if controller service is enabled.
- */
- virtual bool isControllerServiceEnabled(const std::string &identifier) = 0;
-
- /**
- * Detects if controller service is being enabled.
- * @param identifier reference string for controller service.
- * @return true if controller service is enabled.
- */
- virtual bool isControllerServiceEnabling(const std::string &identifier) = 0;
-
- /**
- * Gets the controller service name for the provided reference identifier
- * @param identifier reference string for the controller service.
- */
- virtual const std::string getControllerServiceName(const std::string &identifier) const = 0;
};
} // namespace org::apache::nifi::minifi::core::controller
diff --git a/libminifi/include/core/controller/ControllerServiceNode.h b/libminifi/include/core/controller/ControllerServiceNode.h
index 5a188bef0..dc2a25767 100644
--- a/libminifi/include/core/controller/ControllerServiceNode.h
+++ b/libminifi/include/core/controller/ControllerServiceNode.h
@@ -25,19 +25,18 @@
#include "core/Core.h"
#include "core/ConfigurableComponentImpl.h"
#include "minifi-cpp/core/logging/Logger.h"
-#include "minifi-cpp/core/controller/ControllerServiceNode.h"
#include "minifi-cpp/core/PropertyDefinition.h"
#include "core/PropertyDefinitionBuilder.h"
#include "properties/Configure.h"
-#include "minifi-cpp/core/controller/ControllerService.h"
+#include "core/controller/ControllerService.h"
#include "io/validation.h"
#include "minifi-cpp/Exception.h"
namespace org::apache::nifi::minifi::core::controller {
-class ControllerServiceNodeImpl : public CoreComponentImpl, public ConfigurableComponentImpl, public virtual ControllerServiceNode {
+class ControllerServiceNode : public CoreComponentImpl, public ConfigurableComponentImpl {
public:
- explicit ControllerServiceNodeImpl(std::shared_ptr<ControllerService> service, std::string id, std::shared_ptr<Configure> configuration)
+ explicit ControllerServiceNode(std::shared_ptr<ControllerService> service, std::string id, std::shared_ptr<Configure> configuration)
: CoreComponentImpl(std::move(id)),
active(false),
configuration_(std::move(configuration)),
@@ -73,14 +72,24 @@ class ControllerServiceNodeImpl : public CoreComponentImpl, public ConfigurableC
* maintains
* @return the implementation of the Controller Service
*/
- std::shared_ptr<ControllerService> getControllerServiceImplementation() override;
- const ControllerService* getControllerServiceImplementation() const override;
- const std::vector<ControllerServiceNode*>& getLinkedControllerServices() const override;
+ std::shared_ptr<ControllerService> getControllerServiceImplementation() const;
+ template<typename T>
+ std::shared_ptr<T> getControllerServiceImplementation() {
+ if (auto impl = getControllerServiceImplementation()) {
+ return {impl, impl->getImplementation<T>()};
+ }
+ return {};
+ }
+ virtual const std::vector<ControllerServiceNode*>& getLinkedControllerServices() const;
- bool enabled() override {
+ virtual bool enabled() {
return active.load();
}
+ virtual bool canEnable() = 0;
+ virtual bool enable() = 0;
+ virtual bool disable() = 0;
+
bool supportsDynamicProperties() const override {
return false;
}
@@ -89,8 +98,8 @@ class ControllerServiceNodeImpl : public CoreComponentImpl, public ConfigurableC
return false;
}
- ControllerServiceNodeImpl(const ControllerServiceNodeImpl &other) = delete;
- ControllerServiceNodeImpl &operator=(const ControllerServiceNodeImpl &parent) = delete;
+ ControllerServiceNode(const ControllerServiceNode &other) = delete;
+ ControllerServiceNode &operator=(const ControllerServiceNode &parent) = delete;
protected:
bool canEdit() override {
diff --git a/libminifi/include/core/controller/ControllerServiceNodeMap.h b/libminifi/include/core/controller/ControllerServiceNodeMap.h
index 84f954a0a..27a47e104 100644
--- a/libminifi/include/core/controller/ControllerServiceNodeMap.h
+++ b/libminifi/include/core/controller/ControllerServiceNodeMap.h
@@ -22,7 +22,7 @@
#include <vector>
#include <map>
#include <string>
-#include "minifi-cpp/core/controller/ControllerServiceNode.h"
+#include "ControllerServiceNode.h"
#include "io/validation.h"
namespace org::apache::nifi::minifi::core {
diff --git a/libminifi/include/core/controller/ControllerServiceProvider.h b/libminifi/include/core/controller/ControllerServiceProvider.h
index e700b6d81..72b461052 100644
--- a/libminifi/include/core/controller/ControllerServiceProvider.h
+++ b/libminifi/include/core/controller/ControllerServiceProvider.h
@@ -25,87 +25,65 @@
#include <future>
#include <vector>
-#include "minifi-cpp/core/controller/ControllerServiceProvider.h"
#include "core/Core.h"
-#include "minifi-cpp/core/controller/ControllerServiceLookup.h"
+#include "ControllerServiceLookup.h"
#include "core/ConfigurableComponentImpl.h"
-#include "minifi-cpp/core/controller/ControllerServiceNode.h"
+#include "ControllerServiceNode.h"
#include "ControllerServiceNodeMap.h"
#include "core/ClassLoader.h"
#include "utils/Monitors.h"
namespace org::apache::nifi::minifi::core::controller {
-class ControllerServiceProviderImpl : public CoreComponentImpl, public ConfigurableComponentImpl, public virtual ControllerServiceLookup, public virtual ControllerServiceProvider {
+class ControllerServiceProvider : public CoreComponentImpl, public ConfigurableComponentImpl, public virtual ControllerServiceLookup, public utils::EnableSharedFromThis {
public:
- explicit ControllerServiceProviderImpl(std::string_view name)
+ explicit ControllerServiceProvider(std::string_view name)
: CoreComponentImpl(name),
controller_map_{std::make_unique<ControllerServiceNodeMap>()} {
}
- explicit ControllerServiceProviderImpl(std::unique_ptr<ControllerServiceNodeMap> services)
+ explicit ControllerServiceProvider(std::unique_ptr<ControllerServiceNodeMap> services)
: CoreComponentImpl(core::className<ControllerServiceProvider>()),
controller_map_(std::move(services)) {
}
- explicit ControllerServiceProviderImpl(std::string_view name, std::unique_ptr<ControllerServiceNodeMap> services)
+ explicit ControllerServiceProvider(std::string_view name, std::unique_ptr<ControllerServiceNodeMap> services)
: CoreComponentImpl(name),
controller_map_(std::move(services)) {
}
- ControllerServiceProviderImpl(const ControllerServiceProviderImpl &other) = delete;
- ControllerServiceProviderImpl(ControllerServiceProviderImpl &&other) = delete;
+ ControllerServiceProvider(const ControllerServiceProvider &other) = delete;
+ ControllerServiceProvider(ControllerServiceProvider &&other) = delete;
- ControllerServiceProviderImpl& operator=(const ControllerServiceProviderImpl &other) = delete;
- ControllerServiceProviderImpl& operator=(ControllerServiceProviderImpl &&other) = delete;
+ ControllerServiceProvider& operator=(const ControllerServiceProvider &other) = delete;
+ ControllerServiceProvider& operator=(ControllerServiceProvider &&other) = delete;
- ~ControllerServiceProviderImpl() override = default;
+ ~ControllerServiceProvider() override = default;
- ControllerServiceNode* getControllerServiceNode(const std::string &id) const override {
+ virtual ControllerServiceNode* getControllerServiceNode(const std::string &id) const {
return controller_map_->get(id);
}
- ControllerServiceNode* getControllerServiceNode(const std::string &id, const utils::Identifier &processor_or_controller_uuid) const override {
+ virtual ControllerServiceNode* getControllerServiceNode(const std::string &id, const utils::Identifier &processor_or_controller_uuid) const {
return controller_map_->get(id, processor_or_controller_uuid);
}
- void clearControllerServices() override = 0;
+ virtual std::shared_ptr<ControllerServiceNode> createControllerService(const std::string &type, const std::string &id) = 0;
- std::vector<std::shared_ptr<core::controller::ControllerServiceNode>> getAllControllerServices() override {
- return controller_map_->getAllControllerServices();
- }
+ virtual void clearControllerServices() = 0;
- std::shared_ptr<ControllerService> getControllerService(const std::string &identifier) const override;
- std::shared_ptr<ControllerService> getControllerService(const std::string &identifier, const utils::Identifier &processor_uuid) const override;
+ virtual void enableAllControllerServices() = 0;
- void putControllerServiceNode(const std::string& identifier, const std::shared_ptr<ControllerServiceNode>& controller_service_node, ProcessGroup* process_group) override;
+ virtual void disableAllControllerServices() = 0;
- bool isControllerServiceEnabled(const std::string &identifier) override {
- const ControllerServiceNode* const node = getControllerServiceNode(identifier);
- if (nullptr != node) {
- return linkedServicesAre(ENABLED, node);
- } else {
- return false;
- }
+ virtual std::vector<std::shared_ptr<core::controller::ControllerServiceNode>> getAllControllerServices() {
+ return controller_map_->getAllControllerServices();
}
- bool isControllerServiceEnabling(const std::string &identifier) override {
- const ControllerServiceNode* const node = getControllerServiceNode(identifier);
- if (nullptr != node) {
- return linkedServicesAre(ENABLING, node);
- } else {
- return false;
- }
- }
+ std::shared_ptr<ControllerService> getControllerService(const std::string &identifier) const override;
+ std::shared_ptr<ControllerService> getControllerService(const std::string &identifier, const utils::Identifier &processor_uuid) const override;
- const std::string getControllerServiceName(const std::string &identifier) const override {
- std::shared_ptr<ControllerService> node = getControllerService(identifier);
- if (nullptr != node) {
- return node->getName();
- } else {
- return "";
- }
- }
+ virtual void putControllerServiceNode(const std::string& identifier, const std::shared_ptr<ControllerServiceNode>& controller_service_node, ProcessGroup* process_group);
bool supportsDynamicProperties() const final {
return false;
@@ -116,41 +94,10 @@ class ControllerServiceProviderImpl : public CoreComponentImpl, public Configura
}
protected:
- inline bool linkedServicesAre(ControllerServiceState state, const ControllerServiceNode* node) {
- if (node->getControllerServiceImplementation()->getState() == state) {
- for (auto child_service : node->getLinkedControllerServices()) {
- if (child_service->getControllerServiceImplementation()->getState() != state) {
- return false;
- }
- }
- return true;
- } else {
- return false;
- }
- }
-
bool canEdit() override {
return true;
}
- std::vector<core::controller::ControllerServiceNode*> findLinkedComponents(core::controller::ControllerServiceNode* referenceNode) {
- std::vector<core::controller::ControllerServiceNode*> references;
-
- for (auto* linked_node : referenceNode->getLinkedControllerServices()) {
- references.push_back(linked_node);
- std::vector<core::controller::ControllerServiceNode*> linked_references = findLinkedComponents(linked_node);
-
- auto removal_predicate = [&linked_references](core::controller::ControllerServiceNode* key) ->bool {
- return std::find(linked_references.begin(), linked_references.end(), key) != linked_references.end();
- };
-
- references.erase(std::remove_if(references.begin(), references.end(), removal_predicate), references.end());
-
- references.insert(std::end(references), linked_references.begin(), linked_references.end());
- }
- return references;
- }
-
std::unique_ptr<ControllerServiceNodeMap> controller_map_;
};
diff --git a/libminifi/include/core/controller/ForwardingControllerServiceProvider.h b/libminifi/include/core/controller/ForwardingControllerServiceProvider.h
index edf350bbe..45cce2aef 100644
--- a/libminifi/include/core/controller/ForwardingControllerServiceProvider.h
+++ b/libminifi/include/core/controller/ForwardingControllerServiceProvider.h
@@ -23,13 +23,13 @@
#include <string>
#include "ControllerServiceProvider.h"
-#include "minifi-cpp/core/controller/ControllerServiceNode.h"
+#include "ControllerServiceNode.h"
namespace org::apache::nifi::minifi::core::controller {
-class ForwardingControllerServiceProvider : public ControllerServiceProviderImpl {
+class ForwardingControllerServiceProvider : public ControllerServiceProvider {
public:
- using ControllerServiceProviderImpl::ControllerServiceProviderImpl;
+ using ControllerServiceProvider::ControllerServiceProvider;
std::shared_ptr<ControllerServiceNode> createControllerService(const std::string &type, const std::string &id) override {
return controller_service_provider_impl_->createControllerService(type, id);
@@ -59,18 +59,6 @@ class ForwardingControllerServiceProvider : public ControllerServiceProviderImpl
return controller_service_provider_impl_->getAllControllerServices();
}
- bool isControllerServiceEnabled(const std::string &identifier) override {
- return controller_service_provider_impl_->isControllerServiceEnabled(identifier);
- }
-
- bool isControllerServiceEnabling(const std::string &identifier) override {
- return controller_service_provider_impl_->isControllerServiceEnabling(identifier);
- }
-
- const std::string getControllerServiceName(const std::string &identifier) const override {
- return controller_service_provider_impl_->getControllerServiceName(identifier);
- }
-
void enableAllControllerServices() override {
return controller_service_provider_impl_->enableAllControllerServices();
}
diff --git a/libminifi/include/core/controller/StandardControllerServiceNode.h b/libminifi/include/core/controller/StandardControllerServiceNode.h
index fc4dc7bf0..ba394eee1 100644
--- a/libminifi/include/core/controller/StandardControllerServiceNode.h
+++ b/libminifi/include/core/controller/StandardControllerServiceNode.h
@@ -23,22 +23,23 @@
#include "core/Core.h"
#include "ControllerServiceNode.h"
+#include "ControllerServiceProvider.h"
#include "core/logging/LoggerFactory.h"
#include "core/ProcessGroup.h"
namespace org::apache::nifi::minifi::core::controller {
-class StandardControllerServiceNode : public ControllerServiceNodeImpl {
+class StandardControllerServiceNode : public ControllerServiceNode {
public:
explicit StandardControllerServiceNode(std::shared_ptr<ControllerService> service, std::shared_ptr<ControllerServiceProvider> provider, std::string id,
std::shared_ptr<Configure> configuration)
- : ControllerServiceNodeImpl(std::move(service), std::move(id), std::move(configuration)),
+ : ControllerServiceNode(std::move(service), std::move(id), std::move(configuration)),
provider(std::move(provider)),
logger_(logging::LoggerFactory<StandardControllerServiceNode>::getLogger()) {
}
explicit StandardControllerServiceNode(std::shared_ptr<ControllerService> service, std::string id, std::shared_ptr<Configure> configuration)
- : ControllerServiceNodeImpl(std::move(service), std::move(id), std::move(configuration)),
+ : ControllerServiceNode(std::move(service), std::move(id), std::move(configuration)),
provider(nullptr),
logger_(logging::LoggerFactory<StandardControllerServiceNode>::getLogger()) {
}
@@ -47,7 +48,7 @@ class StandardControllerServiceNode : public ControllerServiceNodeImpl {
StandardControllerServiceNode &operator=(const StandardControllerServiceNode &parent) = delete;
void initialize() override {
- ControllerServiceNodeImpl::initialize();
+ ControllerServiceNode::initialize();
active = false;
}
diff --git a/libminifi/include/core/controller/StandardControllerServiceProvider.h b/libminifi/include/core/controller/StandardControllerServiceProvider.h
index 54eae7115..2fe6c95c3 100644
--- a/libminifi/include/core/controller/StandardControllerServiceProvider.h
+++ b/libminifi/include/core/controller/StandardControllerServiceProvider.h
@@ -22,17 +22,17 @@
#include <memory>
#include <unordered_set>
#include <thread>
-#include "core/controller/ControllerService.h"
+#include "core/controller/ControllerServiceBase.h"
#include "ControllerServiceNodeMap.h"
#include "ControllerServiceProvider.h"
#include "core/logging/LoggerFactory.h"
namespace org::apache::nifi::minifi::core::controller {
-class StandardControllerServiceProvider : public ControllerServiceProviderImpl {
+class StandardControllerServiceProvider : public ControllerServiceProvider {
public:
explicit StandardControllerServiceProvider(std::unique_ptr<ControllerServiceNodeMap> services, std::shared_ptr<Configure> configuration, ClassLoader& loader = ClassLoader::getDefaultClassLoader())
- : ControllerServiceProviderImpl(std::move(services)),
+ : ControllerServiceProvider(std::move(services)),
extension_loader_(loader),
configuration_(std::move(configuration)),
admin_yield_duration_(readAdministrativeYieldDuration()),
diff --git a/libminifi/include/io/NetworkPrioritizer.h b/libminifi/include/io/NetworkPrioritizer.h
index 8f755d1fc..22f0566cf 100644
--- a/libminifi/include/io/NetworkPrioritizer.h
+++ b/libminifi/include/io/NetworkPrioritizer.h
@@ -28,7 +28,6 @@ class NetworkInterface;
struct NetworkPrioritizer {
virtual ~NetworkPrioritizer() noexcept = default;
- virtual NetworkInterface getInterface(uint32_t size) = 0;
protected:
friend class NetworkInterface;
@@ -72,32 +71,4 @@ class NetworkInterface {
std::shared_ptr<NetworkPrioritizer> prioritizer_;
};
-class NetworkPrioritizerFactory {
- public:
- NetworkPrioritizerFactory() = default;
-
- static std::shared_ptr<NetworkPrioritizerFactory> getInstance() {
- static std::shared_ptr<NetworkPrioritizerFactory> fa = std::make_shared<NetworkPrioritizerFactory>();
- return fa;
- }
-
- void clearPrioritizer() {
- np_ = nullptr;
- }
-
- int setPrioritizer(const std::shared_ptr<NetworkPrioritizer> &prioritizer) {
- if (np_ != nullptr)
- return -1;
- np_ = prioritizer;
- return 0;
- }
-
- std::shared_ptr<NetworkPrioritizer> getPrioritizer() {
- return np_;
- }
-
- private:
- std::shared_ptr<NetworkPrioritizer> np_;
-};
-
} // namespace org::apache::nifi::minifi::io
diff --git a/libminifi/src/FlowController.cpp b/libminifi/src/FlowController.cpp
index bd7a38bd7..d459c7b54 100644
--- a/libminifi/src/FlowController.cpp
+++ b/libminifi/src/FlowController.cpp
@@ -37,7 +37,6 @@
#include "utils/file/PathUtils.h"
#include "utils/file/FileSystem.h"
#include "http/BaseHTTPClient.h"
-#include "io/NetworkPrioritizer.h"
#include "io/FileStream.h"
#include "core/ClassLoader.h"
#include "minifi-cpp/core/ThreadedRepository.h"
@@ -54,7 +53,7 @@ FlowController::FlowController(std::shared_ptr<core::Repository> provenance_repo
: core::controller::ForwardingControllerServiceProvider(core::className<FlowController>()),
running_(false),
initialized_(false),
- thread_pool_(5, nullptr, "Flowcontroller threadpool"),
+ thread_pool_(5, "Flowcontroller threadpool"),
configuration_(std::move(configure)),
provenance_repo_(std::move(provenance_repo)),
flow_file_repo_(std::move(flow_file_repo)),
@@ -256,9 +255,6 @@ void FlowController::load(bool reload) {
if (running_) {
stop();
}
- if (reload) {
- io::NetworkPrioritizerFactory::getInstance()->clearPrioritizer();
- }
{
std::scoped_lock<UpdateState> update_lock(updating_);
@@ -279,7 +275,6 @@ void FlowController::load(bool reload) {
if (!thread_pool_.isRunning() || reload) {
thread_pool_.shutdown();
thread_pool_.setMaxConcurrentTasks(configuration_->getInt(Configure::nifi_flow_engine_threads, 5));
- thread_pool_.setControllerServiceProvider(this);
thread_pool_.start();
}
diff --git a/libminifi/src/RemoteProcessGroupPort.cpp b/libminifi/src/RemoteProcessGroupPort.cpp
index 25834ca42..4f52d4111 100644
--- a/libminifi/src/RemoteProcessGroupPort.cpp
+++ b/libminifi/src/RemoteProcessGroupPort.cpp
@@ -30,6 +30,7 @@
#include "minifi-cpp/Exception.h"
#include "controllers/SSLContextService.h"
+#include "core/controller/ControllerService.h"
#include "minifi-cpp/core/ProcessContext.h"
#include "core/Processor.h"
#include "minifi-cpp/core/logging/Logger.h"
@@ -136,14 +137,13 @@ void RemoteProcessGroupPort::onSchedule(core::ProcessContext& context, core::Pro
context_name = RPG_SSL_CONTEXT_SERVICE_NAME;
}
- std::shared_ptr<core::controller::ControllerService> service = context.getControllerService(*context_name, getUUID());
+ std::shared_ptr<core::controller::ControllerServiceInterface> service = context.getControllerService(*context_name, getUUID());
if (nullptr != service) {
ssl_service_ = std::dynamic_pointer_cast<minifi::controllers::SSLContextServiceInterface>(service);
} else {
std::string secureStr;
if (configure_->get(Configure::nifi_remote_input_secure, secureStr) && utils::string::toBool(secureStr).value_or(false)) {
- ssl_service_ = std::make_shared<minifi::controllers::SSLContextService>(RPG_SSL_CONTEXT_SERVICE_NAME, configure_);
- ssl_service_->onEnable();
+ ssl_service_ = controllers::SSLContextService::createAndEnable(RPG_SSL_CONTEXT_SERVICE_NAME, configure_);
}
}
diff --git a/libminifi/src/c2/C2Agent.cpp b/libminifi/src/c2/C2Agent.cpp
index 7f5dc679a..f6a171bb5 100644
--- a/libminifi/src/c2/C2Agent.cpp
+++ b/libminifi/src/c2/C2Agent.cpp
@@ -62,7 +62,7 @@ C2Agent::C2Agent(std::shared_ptr<Configure> configuration,
configuration_(std::move(configuration)),
node_reporter_(std::move(node_reporter)),
filesystem_(std::move(filesystem)),
- thread_pool_(2, nullptr, "C2 threadpool"),
+ thread_pool_(2, "C2 threadpool"),
request_restart_(std::move(request_restart)),
last_run_(std::chrono::steady_clock::now()),
asset_manager_(asset_manager) {
@@ -87,8 +87,8 @@ void C2Agent::initialize(core::controller::ControllerServiceProvider *controller
if (nullptr != controller_) {
if (auto service = controller_->getControllerService(UPDATE_NAME)) {
- if (auto update_service = std::dynamic_pointer_cast<controllers::UpdatePolicyControllerService>(service)) {
- update_service_ = update_service;
+ if (auto* update_service = dynamic_cast<controllers::UpdatePolicyControllerService*>(&*service->getImplementation())) {
+ update_service_ = {service, update_service};
} else {
logger_->log_warn("Found controller service with name '{}', but it is not an UpdatePolicyControllerService", c2::UPDATE_NAME);
}
diff --git a/libminifi/src/c2/ControllerSocketProtocol.cpp b/libminifi/src/c2/ControllerSocketProtocol.cpp
index cea10dcc5..2ba378155 100644
--- a/libminifi/src/c2/ControllerSocketProtocol.cpp
+++ b/libminifi/src/c2/ControllerSocketProtocol.cpp
@@ -146,8 +146,7 @@ void ControllerSocketProtocol::initialize() {
std::shared_ptr<minifi::controllers::SSLContextServiceInterface> secure_context;
std::string secure_str;
if (configuration_->get(Configure::nifi_remote_input_secure, secure_str) && org::apache::nifi::minifi::utils::string::toBool(secure_str).value_or(false)) {
- secure_context = std::make_shared<minifi::controllers::SSLContextService>("ControllerSocketProtocolSSL", configuration_);
- secure_context->onEnable();
+ secure_context = controllers::SSLContextService::createAndEnable("ControllerSocketProtocolSSL", configuration_);
}
std::string limit_str;
diff --git a/libminifi/src/c2/protocols/RESTSender.cpp b/libminifi/src/c2/protocols/RESTSender.cpp
index 709f81589..157971abd 100644
--- a/libminifi/src/c2/protocols/RESTSender.cpp
+++ b/libminifi/src/c2/protocols/RESTSender.cpp
@@ -60,8 +60,7 @@ void RESTSender::initialize(core::controller::ControllerServiceProvider* control
}
std::string ssl_context_str;
if (configure->get(Configure::nifi_remote_input_secure, ssl_context_str) && org::apache::nifi::minifi::utils::string::toBool(ssl_context_str).value_or(false)) {
- ssl_context_service_ = std::make_shared<minifi::controllers::SSLContextService>("RESTSenderSSL", configure);
- ssl_context_service_->onEnable();
+ ssl_context_service_ = minifi::controllers::SSLContextService::createAndEnable("RESTSenderSSL", configure);
}
if (auto req_encoding_str = configure->get(Configuration::nifi_c2_rest_request_encoding)) {
if (auto req_encoding = magic_enum::enum_cast<RequestEncoding>(*req_encoding_str, magic_enum::case_insensitive)) {
@@ -103,9 +102,7 @@ void RESTSender::update(const std::shared_ptr<Configure> &) {
void RESTSender::setSecurityContext(http::HTTPClient &client, http::HttpRequestMethod type, const std::string &url) {
// only use the SSL Context if we have a secure URL.
- auto generatedService = std::make_shared<minifi::controllers::SSLContextService>("Service", configuration_);
- generatedService->onEnable();
- client.initialize(type, url, generatedService);
+ client.initialize(type, url, controllers::SSLContextService::createAndEnable("Service", configuration_));
}
C2Payload RESTSender::sendPayload(const std::string& url, const Direction direction, const C2Payload &payload, std::optional<std::string> data,
diff --git a/libminifi/src/controllers/NetworkPrioritizerService.cpp b/libminifi/src/controllers/NetworkPrioritizerService.cpp
index 517c87e6e..3ab9306e4 100644
--- a/libminifi/src/controllers/NetworkPrioritizerService.cpp
+++ b/libminifi/src/controllers/NetworkPrioritizerService.cpp
@@ -45,9 +45,6 @@ void NetworkPrioritizerService::initialize() {
setSupportedProperties(Properties);
}
-void NetworkPrioritizerService::yield() {
-}
-
/**
* If not an intersecting operation we will attempt to locate the highest priority interface available.
*/
@@ -63,8 +60,8 @@ io::NetworkInterface NetworkPrioritizerService::getInterface(uint32_t size = 0)
if (!controllers.empty()) {
ifc = get_nearest_interface(controllers);
if (!ifc.empty()) {
- reduce_tokens(size);
- io::NetworkInterface newifc(ifc, sharedFromThis<NetworkPrioritizerService>());
+ prioritizer_->reduce_tokens(size);
+ io::NetworkInterface newifc(ifc, prioritizer_);
return newifc;
}
}
@@ -74,8 +71,8 @@ io::NetworkInterface NetworkPrioritizerService::getInterface(uint32_t size = 0)
auto ifcs = np->getInterfaces(size);
ifc = get_nearest_interface(ifcs);
if (!ifc.empty()) {
- np->reduce_tokens(size);
- io::NetworkInterface newifc(ifc, np);
+ np->prioritizer_->reduce_tokens(size);
+ io::NetworkInterface newifc(ifc, np->prioritizer_);
return newifc;
}
}
@@ -126,20 +123,20 @@ std::vector<std::string> NetworkPrioritizerService::getInterfaces(uint32_t size
}
bool NetworkPrioritizerService::sufficient_tokens(uint32_t size) {
- std::lock_guard<std::mutex> lock(token_mutex_);
+ std::lock_guard<std::mutex> lock(prioritizer_->token_mutex_);
auto ms = clock_->timeSinceEpoch().count();
auto diff = ms - timestamp_;
timestamp_ = ms;
if (diff > 0) {
- tokens_ += gsl::narrow<uint32_t>(diff * tokens_per_ms);
+ prioritizer_->tokens_ += gsl::narrow<uint32_t>(diff * tokens_per_ms);
}
- if (bytes_per_token_ > 0 && size > 0) {
- return tokens_ * bytes_per_token_ >= size;
+ if (prioritizer_->bytes_per_token_ > 0 && size > 0) {
+ return prioritizer_->tokens_ * prioritizer_->bytes_per_token_ >= size;
}
return true;
}
-void NetworkPrioritizerService::reduce_tokens(uint32_t size) {
+void NetworkPrioritizerService::StandardNetworkPrioritizer::reduce_tokens(uint32_t size) {
std::lock_guard<std::mutex> lock(token_mutex_);
if (bytes_per_token_ > 0 && size > 0) {
uint32_t tokens = size / bytes_per_token_;
@@ -147,14 +144,6 @@ void NetworkPrioritizerService::reduce_tokens(uint32_t size) {
}
}
-bool NetworkPrioritizerService::isRunning() const {
- return getState() == core::controller::ControllerServiceState::ENABLED;
-}
-
-bool NetworkPrioritizerService::isWorkAvailable() {
- return false;
-}
-
void NetworkPrioritizerService::onEnable() {
if (auto controllers = getProperty(NetworkControllers.name); controllers || !linked_services_.empty()) {
// if this controller service is defined, it will be an intersection of this config with linked services.
@@ -162,10 +151,10 @@ void NetworkPrioritizerService::onEnable() {
max_throughput_ = *max_throughput;
logger_->log_trace("Max throughput is {}", max_throughput_);
if (max_throughput_ < 1000) {
- bytes_per_token_ = 1;
- tokens_ = gsl::narrow<uint32_t>(max_throughput_);
+ prioritizer_->bytes_per_token_ = 1;
+ prioritizer_->tokens_ = gsl::narrow<uint32_t>(max_throughput_);
} else {
- bytes_per_token_ = gsl::narrow<uint32_t>(max_throughput_ / 1000);
+ prioritizer_->bytes_per_token_ = gsl::narrow<uint32_t>(max_throughput_ / 1000);
}
}
@@ -177,13 +166,6 @@ void NetworkPrioritizerService::onEnable() {
logger_->log_trace("{} added to list of applied interfaces", ifc);
}
}
- if (const auto is_default = getProperty(DefaultPrioritizer.name) | utils::andThen(parsing::parseBool)) {
- if (*is_default) {
- if (io::NetworkPrioritizerFactory::getInstance()->setPrioritizer(sharedFromThis<NetworkPrioritizerService>()) < 0) {
- throw std::runtime_error("Can only have one prioritizer");
- }
- }
- }
verify_interfaces_ = (getProperty(VerifyInterfaces.name) | utils::andThen(parsing::parseBool)).value_or(true);
timestamp_ = clock_->timeSinceEpoch().count();
diff --git a/libminifi/src/controllers/SSLContextService.cpp b/libminifi/src/controllers/SSLContextService.cpp
index 5d688c64f..584b5109d 100644
--- a/libminifi/src/controllers/SSLContextService.cpp
+++ b/libminifi/src/controllers/SSLContextService.cpp
@@ -40,6 +40,7 @@
#include "utils/tls/DistinguishedName.h"
#include "utils/tls/WindowsCertStoreLocation.h"
#include "utils/TimeUtil.h"
+#include "core/controller/ControllerService.h"
namespace org::apache::nifi::minifi::controllers {
@@ -78,7 +79,7 @@ void SSLContextService::initialize() {
return;
}
- ControllerServiceImpl::initialize();
+ ControllerServiceBase::initialize();
initializeProperties();
@@ -594,6 +595,72 @@ void SSLContextService::verifyCertificateExpiration() {
#endif
}
+std::shared_ptr<SSLContextService> SSLContextService::createAndEnable(std::string_view name, const std::shared_ptr<Configure>& configuration) {
+ auto uuid = utils::IdGenerator::getIdGenerator()->generate();
+ auto logger = core::logging::LoggerFactory<SSLContextService>::getLogger(uuid);
+ auto service = std::make_shared<core::controller::ControllerService>(name, uuid, std::make_unique<SSLContextService>(core::controller::ControllerServiceMetadata{
+ .uuid = uuid,
+ .name = std::string{name},
+ .logger = logger,
+ }));
+ service->initialize();
+ auto setPropertyAndHandleError = [&](std::string_view property_name, std::string value) {
+ auto result = service->setProperty(property_name, std::move(value));
+ if (!result) {
+ logger->log_error("Failed to set property {}: {}", property_name, result.error().message());
+ }
+ };
+
+ // set the properties based on the configuration
+ std::string value;
+ if (configuration->get(Configure::nifi_security_client_certificate, value)) {
+ setPropertyAndHandleError(ClientCertificate.name, std::move(value));
+ }
+
+ if (configuration->get(Configure::nifi_security_client_private_key, value)) {
+ setPropertyAndHandleError(PrivateKey.name, std::move(value));
+ }
+
+ if (configuration->get(Configure::nifi_security_client_pass_phrase, value)) {
+ setPropertyAndHandleError(Passphrase.name, std::move(value));
+ }
+
+ if (configuration->get(Configure::nifi_security_client_ca_certificate, value)) {
+ setPropertyAndHandleError(CACertificate.name, std::move(value));
+ }
+
+ if (configuration->get(Configure::nifi_security_use_system_cert_store, value)) {
+ setPropertyAndHandleError(UseSystemCertStore.name, std::move(value));
+ }
+
+#ifdef WIN32
+ if (configuration->get(Configure::nifi_security_windows_cert_store_location, value)) {
+ setPropertyAndHandleError(CertStoreLocation.name, std::move(value));
+ }
+
+ if (configuration->get(Configure::nifi_security_windows_server_cert_store, value)) {
+ setPropertyAndHandleError(ServerCertStore.name, std::move(value));
+ }
+
+ if (configuration->get(Configure::nifi_security_windows_client_cert_store, value)) {
+ setPropertyAndHandleError(ClientCertStore.name, std::move(value));
+ }
+
+ if (configuration->get(Configure::nifi_security_windows_client_cert_cn, value)) {
+ setPropertyAndHandleError(ClientCertCN.name, std::move(value));
+ }
+
+ if (configuration->get(Configure::nifi_security_windows_client_cert_key_usage, value)) {
+ setPropertyAndHandleError(ClientCertKeyUsage.name, std::move(value));
+ }
+#endif // WIN32
+
+ service->onEnable();
+
+ return {service, service->getImplementation<SSLContextService>()};
+}
+
+
REGISTER_RESOURCE_IMPLEMENTATION(SSLContextService, "SSLContextService", ControllerService);
} // namespace org::apache::nifi::minifi::controllers
diff --git a/libminifi/src/controllers/UpdatePolicyControllerService.cpp b/libminifi/src/controllers/UpdatePolicyControllerService.cpp
index a4edd2668..2394de6fb 100644
--- a/libminifi/src/controllers/UpdatePolicyControllerService.cpp
+++ b/libminifi/src/controllers/UpdatePolicyControllerService.cpp
@@ -39,17 +39,6 @@ void UpdatePolicyControllerService::initialize() {
setSupportedProperties(Properties);
}
-void UpdatePolicyControllerService::yield() {
-}
-
-bool UpdatePolicyControllerService::isRunning() const {
- return getState() == core::controller::ControllerServiceState::ENABLED;
-}
-
-bool UpdatePolicyControllerService::isWorkAvailable() {
- return false;
-}
-
void UpdatePolicyControllerService::onEnable() {
const bool enable_all = (getProperty(AllowAllProperties.name) | utils::andThen(parsing::parseBool)).value_or(false);
persist_updates_ = (getProperty(PersistUpdates.name) | utils::andThen(parsing::parseBool)).value_or(false);
diff --git a/libminifi/src/core/ClassLoader.cpp b/libminifi/src/core/ClassLoader.cpp
index 520f63465..463b2a2e4 100644
--- a/libminifi/src/core/ClassLoader.cpp
+++ b/libminifi/src/core/ClassLoader.cpp
@@ -24,6 +24,7 @@
#include "range/v3/action/sort.hpp"
#include "range/v3/action/unique.hpp"
#include "core/Processor.h"
+#include "core/controller/ControllerService.h"
#include "core/ObjectFactory.h"
namespace org::apache::nifi::minifi::core {
@@ -43,6 +44,8 @@ class ClassLoaderImpl : public ClassLoader {
void registerClass(const std::string &clazz, std::unique_ptr<ProcessorFactory> factory) override;
+ void registerClass(const std::string &clazz, std::unique_ptr<controller::ControllerServiceFactory> factory) override;
+
void unregisterClass(const std::string& clazz) override;
[[nodiscard]] std::optional<std::string> getGroupForClass(const std::string &class_name) const override;
@@ -136,12 +139,52 @@ class ProcessorFactoryWrapper : public ObjectFactoryImpl {
private:
std::unique_ptr<ProcessorFactory> factory_;
};
+
+class ControllerServiceFactoryWrapper : public ObjectFactoryImpl {
+ public:
+ explicit ControllerServiceFactoryWrapper(std::unique_ptr<controller::ControllerServiceFactory> factory)
+ : ObjectFactoryImpl(factory->getGroupName()),
+ factory_(std::move(factory)) {}
+
+ [[nodiscard]] std::unique_ptr<CoreComponent> create(const std::string &name) override {
+ return std::unique_ptr<CoreComponent>{createRaw(name)};
+ }
+
+ [[nodiscard]] std::unique_ptr<CoreComponent> create(const std::string &name, const utils::Identifier &uuid) override {
+ return std::unique_ptr<CoreComponent>{createRaw(name, uuid)};
+ }
+
+ [[nodiscard]] gsl::owner<CoreComponent*> createRaw(const std::string &name) override {
+ return createRaw(name, utils::IdGenerator::getIdGenerator()->generate());
+ }
+
+ [[nodiscard]] gsl::owner<CoreComponent*> createRaw(const std::string &name, const utils::Identifier &uuid) override {
+ auto logger = logging::LoggerFactoryBase::getAliasedLogger(getClassName(), uuid);
+ return new controller::ControllerService(name, uuid, factory_->create({.uuid = uuid, .name = name, .logger = std::move(logger)}));
+ }
+
+ [[nodiscard]] std::string getGroupName() const override {
+ return factory_->getGroupName();
+ }
+
+ [[nodiscard]] std::string getClassName() override {
+ return factory_->getClassName();
+ }
+
+ private:
+ std::unique_ptr<controller::ControllerServiceFactory> factory_;
+};
+
} // namespace
void ClassLoaderImpl::registerClass(const std::string &clazz, std::unique_ptr<ProcessorFactory> factory) {
registerClass(clazz, std::make_unique<ProcessorFactoryWrapper>(std::move(factory)));
}
+void ClassLoaderImpl::registerClass(const std::string &clazz, std::unique_ptr<controller::ControllerServiceFactory> factory) {
+ registerClass(clazz, std::make_unique<ControllerServiceFactoryWrapper>(std::move(factory)));
+}
+
void ClassLoaderImpl::unregisterClass(const std::string& clazz) {
std::lock_guard<std::mutex> lock(internal_mutex_);
if (loaded_factories_.erase(clazz) == 0) {
diff --git a/libminifi/src/core/controller/ControllerServiceNode.cpp b/libminifi/src/core/controller/ControllerServiceNode.cpp
index a41a31f84..05473b54d 100644
--- a/libminifi/src/core/controller/ControllerServiceNode.cpp
+++ b/libminifi/src/core/controller/ControllerServiceNode.cpp
@@ -22,15 +22,11 @@
namespace org::apache::nifi::minifi::core::controller {
-std::shared_ptr<ControllerService> ControllerServiceNodeImpl::getControllerServiceImplementation() {
+std::shared_ptr<ControllerService> ControllerServiceNode::getControllerServiceImplementation() const {
return controller_service_;
}
-const ControllerService* ControllerServiceNodeImpl::getControllerServiceImplementation() const {
- return controller_service_.get();
-}
-
-const std::vector<ControllerServiceNode*>& ControllerServiceNodeImpl::getLinkedControllerServices() const {
+const std::vector<ControllerServiceNode*>& ControllerServiceNode::getLinkedControllerServices() const {
return linked_controller_services_;
}
diff --git a/libminifi/src/core/controller/ControllerServiceProvider.cpp b/libminifi/src/core/controller/ControllerServiceProvider.cpp
index 0abd0a74f..288929ccb 100644
--- a/libminifi/src/core/controller/ControllerServiceProvider.cpp
+++ b/libminifi/src/core/controller/ControllerServiceProvider.cpp
@@ -25,7 +25,7 @@
namespace org::apache::nifi::minifi::core::controller {
-std::shared_ptr<ControllerService> ControllerServiceProviderImpl::getControllerService(const std::string &identifier) const {
+std::shared_ptr<ControllerService> ControllerServiceProvider::getControllerService(const std::string &identifier) const {
auto service = controller_map_->get(identifier);
if (service != nullptr) {
return service->getControllerServiceImplementation();
@@ -34,7 +34,7 @@ std::shared_ptr<ControllerService> ControllerServiceProviderImpl::getControllerS
}
}
-std::shared_ptr<ControllerService> ControllerServiceProviderImpl::getControllerService(const std::string &identifier, const utils::Identifier &processor_uuid) const {
+std::shared_ptr<ControllerService> ControllerServiceProvider::getControllerService(const std::string &identifier, const utils::Identifier &processor_uuid) const {
auto service = controller_map_->get(identifier, processor_uuid);
if (service != nullptr) {
return service->getControllerServiceImplementation();
@@ -43,7 +43,7 @@ std::shared_ptr<ControllerService> ControllerServiceProviderImpl::getControllerS
}
}
-void ControllerServiceProviderImpl::putControllerServiceNode(const std::string& identifier, const std::shared_ptr<ControllerServiceNode>& controller_service_node, ProcessGroup* process_group) {
+void ControllerServiceProvider::putControllerServiceNode(const std::string& identifier, const std::shared_ptr<ControllerServiceNode>& controller_service_node, ProcessGroup* process_group) {
gsl_Expects(controller_map_);
controller_map_->put(identifier, controller_service_node);
controller_map_->put(identifier, process_group);
diff --git a/libminifi/src/core/logging/LoggerConfiguration.cpp b/libminifi/src/core/logging/LoggerConfiguration.cpp
index 16a6b6f16..9daa950c4 100644
--- a/libminifi/src/core/logging/LoggerConfiguration.cpp
+++ b/libminifi/src/core/logging/LoggerConfiguration.cpp
@@ -348,8 +348,7 @@ void LoggerConfiguration::initializeCompression(const std::lock_guard<std::mutex
}
void LoggerConfiguration::initializeAlertSinks(const std::shared_ptr<Configure>& config) {
- auto ssl_service = std::make_shared<controllers::SSLContextService>("AlertSinkSSLContextService", config);
- ssl_service->onEnable();
+ auto ssl_service = controllers::SSLContextService::createAndEnable("AlertSinkSSLContextService", config);
if (ssl_service->getCertificateFile().empty()) {
ssl_service.reset();
}
diff --git a/libminifi/src/core/state/nodes/ResponseNodeLoader.cpp b/libminifi/src/core/state/nodes/ResponseNodeLoader.cpp
index edd24eac4..7a1a43e46 100644
--- a/libminifi/src/core/state/nodes/ResponseNodeLoader.cpp
+++ b/libminifi/src/core/state/nodes/ResponseNodeLoader.cpp
@@ -173,8 +173,8 @@ void ResponseNodeLoaderImpl::initializeAgentNode(const SharedResponseNode& respo
auto agent_node = dynamic_cast<state::response::AgentNode*>(response_node.get());
if (agent_node != nullptr && controller_ != nullptr) {
if (auto service = controller_->getControllerService(c2::UPDATE_NAME)) {
- if (auto update_service = std::dynamic_pointer_cast<controllers::UpdatePolicyControllerService>(service)) {
- agent_node->setUpdatePolicyController(update_service.get());
+ if (auto* update_service = dynamic_cast<controllers::UpdatePolicyControllerService*>(&*service->getImplementation())) {
+ agent_node->setUpdatePolicyController(update_service);
} else {
logger_->log_warn("Found controller service with name '{}', but it is not an UpdatePolicyControllerService", c2::UPDATE_NAME);
}
@@ -312,8 +312,8 @@ state::response::NodeReporter::ReportedNode ResponseNodeLoaderImpl::getAgentMani
state::response::AgentInformation agentInfo("agentInfo");
if (controller_) {
if (auto service = controller_->getControllerService(c2::UPDATE_NAME)) {
- if (auto update_service = std::dynamic_pointer_cast<controllers::UpdatePolicyControllerService>(service)) {
- agentInfo.setUpdatePolicyController(update_service.get());
+ if (auto* update_service = dynamic_cast<controllers::UpdatePolicyControllerService*>(&*service->getImplementation())) {
+ agentInfo.setUpdatePolicyController(update_service);
} else {
logger_->log_warn("Found controller service with name '{}', but it is not an UpdatePolicyControllerService", c2::UPDATE_NAME);
}
diff --git a/libminifi/test/integration/C2ControllerEnableFailureTest.cpp b/libminifi/test/integration/C2ControllerEnableFailureTest.cpp
index 8a041200d..e3dc24e1a 100644
--- a/libminifi/test/integration/C2ControllerEnableFailureTest.cpp
+++ b/libminifi/test/integration/C2ControllerEnableFailureTest.cpp
@@ -23,7 +23,7 @@
#include "integration/HTTPHandlers.h"
#include "unit/Catch.h"
#include "core/Processor.h"
-#include "core/controller/ControllerService.h"
+#include "core/controller/ControllerServiceBase.h"
#include "core/Resource.h"
#include "utils/ProcessorConfigUtils.h"
@@ -31,9 +31,9 @@ using namespace std::literals::chrono_literals;
namespace org::apache::nifi::minifi::test {
-class DummyController : public core::controller::ControllerServiceImpl {
+class DummyController : public core::controller::ControllerServiceBase, public core::controller::ControllerServiceInterface {
public:
- explicit DummyController(std::string_view name, const minifi::utils::Identifier &uuid = {}) : ControllerServiceImpl(name, uuid) {}
+ using ControllerServiceBase::ControllerServiceBase;
static constexpr const char* Description = "Dummy Controller";
@@ -43,22 +43,12 @@ class DummyController : public core::controller::ControllerServiceImpl {
static constexpr auto Properties = std::to_array<core::PropertyReference>({DummyControllerProperty});
static constexpr bool SupportsDynamicProperties = false;
- ADD_COMMON_VIRTUAL_FUNCTIONS_FOR_CONTROLLER_SERVICES
void initialize() override {
setSupportedProperties(Properties);
}
- void yield() override {
- }
-
- bool isWorkAvailable() override {
- return false;
- }
-
- bool isRunning() const override {
- return getState() == core::controller::ControllerServiceState::ENABLED;
- }
+ ControllerServiceInterface* getControllerServiceInterface() override {return this;}
void onEnable() override {
auto dummy_controller_property = getProperty(DummyControllerProperty.name);
@@ -66,9 +56,6 @@ class DummyController : public core::controller::ControllerServiceImpl {
throw minifi::Exception(minifi::ExceptionType::PROCESS_SCHEDULE_EXCEPTION, "Missing dummy property");
}
}
-
- private:
- std::shared_ptr<core::logging::Logger> logger_ = core::logging::LoggerFactory<DummyController>::getLogger(uuid_);
};
REGISTER_RESOURCE(DummyController, ControllerService);
diff --git a/libminifi/test/integration/ControllerServiceIntegrationTests.cpp b/libminifi/test/integration/ControllerServiceIntegrationTests.cpp
index e6aed9cbf..d5586ca73 100644
--- a/libminifi/test/integration/ControllerServiceIntegrationTests.cpp
+++ b/libminifi/test/integration/ControllerServiceIntegrationTests.cpp
@@ -115,7 +115,7 @@ TEST_CASE("ControllerServiceIntegrationTests", "[controller]") {
REQUIRE(ssl_client_node != nullptr);
ssl_client_node->enable();
REQUIRE(ssl_client_node->getControllerServiceImplementation() != nullptr);
- ssl_client = std::dynamic_pointer_cast<minifi::controllers::SSLContextServiceInterface>(ssl_client_node->getControllerServiceImplementation());
+ ssl_client = ssl_client_node->getControllerServiceImplementation<minifi::controllers::SSLContextServiceInterface>();
}
REQUIRE(!ssl_client->getCACertificate().empty());
// now let's disable one of the controller services.
diff --git a/libminifi/test/keyvalue-tests/PersistentStateStorageTest.cpp b/libminifi/test/keyvalue-tests/PersistentStateStorageTest.cpp
index 6c77dfdac..434bce477 100644
--- a/libminifi/test/keyvalue-tests/PersistentStateStorageTest.cpp
+++ b/libminifi/test/keyvalue-tests/PersistentStateStorageTest.cpp
@@ -110,8 +110,7 @@ class PersistentStateStorageTestsFixture {
REQUIRE(persistable_key_value_store_service_node != nullptr);
persistable_key_value_store_service_node->enable();
- controller = std::dynamic_pointer_cast<minifi::controllers::KeyValueStateStorage>(
- persistable_key_value_store_service_node->getControllerServiceImplementation());
+ controller = persistable_key_value_store_service_node->getControllerServiceImplementation<minifi::controllers::KeyValueStateStorage>();
REQUIRE(controller != nullptr);
}
diff --git a/libminifi/test/keyvalue-tests/VolatileMapStateStorageTest.cpp b/libminifi/test/keyvalue-tests/VolatileMapStateStorageTest.cpp
index 48055c98a..fca7f6602 100644
--- a/libminifi/test/keyvalue-tests/VolatileMapStateStorageTest.cpp
+++ b/libminifi/test/keyvalue-tests/VolatileMapStateStorageTest.cpp
@@ -73,8 +73,7 @@ class VolatileMapStateStorageTestFixture {
REQUIRE(key_value_store_service_node != nullptr);
key_value_store_service_node->enable();
- controller = std::dynamic_pointer_cast<minifi::controllers::KeyValueStateStorage>(
- key_value_store_service_node->getControllerServiceImplementation());
+ controller = key_value_store_service_node->getControllerServiceImplementation<minifi::controllers::KeyValueStateStorage>();
REQUIRE(controller != nullptr);
}
diff --git a/libminifi/test/libtest/integration/HTTPHandlers.cpp b/libminifi/test/libtest/integration/HTTPHandlers.cpp
index 5236d96fd..751c5cbd2 100644
--- a/libminifi/test/libtest/integration/HTTPHandlers.cpp
+++ b/libminifi/test/libtest/integration/HTTPHandlers.cpp
@@ -32,6 +32,7 @@
#include "sitetosite/HttpSiteToSiteClient.h"
#include "utils/StringUtils.h"
#include "utils/net/DNS.h"
+#include "io/validation.h"
namespace org::apache::nifi::minifi::test {
diff --git a/libminifi/test/libtest/integration/HTTPHandlers.h b/libminifi/test/libtest/integration/HTTPHandlers.h
index 5d1cf6d11..25a0dba5d 100644
--- a/libminifi/test/libtest/integration/HTTPHandlers.h
+++ b/libminifi/test/libtest/integration/HTTPHandlers.h
@@ -34,7 +34,7 @@
#include "utils/HTTPUtils.h"
#include "ServerAwareHandler.h"
#include "c2/C2Payload.h"
-#include "properties/Configuration.h"
+#include "properties/Configure.h"
#include "unit/Catch.h"
namespace org::apache::nifi::minifi::test {
diff --git a/extensions/sql/services/DatabaseService.cpp b/libminifi/test/libtest/unit/ControllerServiceUtils.h
similarity index 53%
copy from extensions/sql/services/DatabaseService.cpp
copy to libminifi/test/libtest/unit/ControllerServiceUtils.h
index 1ccae3b63..ff19982d3 100644
--- a/extensions/sql/services/DatabaseService.cpp
+++ b/libminifi/test/libtest/unit/ControllerServiceUtils.h
@@ -1,4 +1,5 @@
/**
+*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
@@ -14,38 +15,26 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-#include <string>
+#pragma once
+
#include <memory>
-#include <set>
+#include <string_view>
-#include "core/logging/LoggerFactory.h"
#include "core/controller/ControllerService.h"
-#include "DatabaseService.h"
-#include "io/validation.h"
-#include "minifi-cpp/properties/Configure.h"
-
-namespace org::apache::nifi::minifi::sql::controllers {
-void DatabaseService::initialize() {
- std::lock_guard<std::recursive_mutex> lock(initialization_mutex_);
+namespace org::apache::nifi::minifi::test::utils {
- if (initialized_) {
- return;
+template<typename T>
+std::unique_ptr<core::controller::ControllerService> make_controller_service(std::string_view name, std::optional<minifi::utils::Identifier> uuid = std::nullopt) {
+ if (!uuid) {
+ uuid = minifi::utils::IdGenerator::getIdGenerator()->generate();
}
-
- ControllerServiceImpl::initialize();
-
- initializeProperties();
-
- initialized_ = true;
-}
-
-void DatabaseService::onEnable() {
- connection_string_ = getProperty(ConnectionString.name).value_or("");
-}
-
-void DatabaseService::initializeProperties() {
- setSupportedProperties(Properties);
+ auto processor_impl = std::make_unique<T>(core::controller::ControllerServiceMetadata{
+ .uuid = uuid.value(),
+ .name = std::string{name},
+ .logger = minifi::core::logging::LoggerFactory<T>::getLogger(uuid.value())
+ });
+ return std::make_unique<core::controller::ControllerService>(name, uuid.value(), std::move(processor_impl));
}
-} // namespace org::apache::nifi::minifi::sql::controllers
+} // namespace org::apache::nifi::minifi::test::utils
diff --git a/libminifi/test/libtest/unit/MockClasses.h b/libminifi/test/libtest/unit/MockClasses.h
index b1279c372..92131519f 100644
--- a/libminifi/test/libtest/unit/MockClasses.h
+++ b/libminifi/test/libtest/unit/MockClasses.h
@@ -20,7 +20,7 @@
#include <string>
#include <utility>
-#include "core/controller/ControllerService.h"
+#include "core/controller/ControllerServiceBase.h"
#include "core/ProcessorImpl.h"
#include "minifi-cpp/core/ProcessContext.h"
#include "core/ProcessSession.h"
@@ -35,26 +35,20 @@ std::mutex control_mutex;
std::atomic<bool> subprocess_controller_service_found_correctly{false};
std::atomic<bool> subprocess_controller_service_not_found_correctly{false};
-class MockControllerService : public minifi::core::controller::ControllerServiceImpl {
+class MockControllerService : public minifi::core::controller::ControllerServiceBase, public core::controller::ControllerServiceInterface {
public:
- explicit MockControllerService(std::string_view name, const minifi::utils::Identifier &uuid)
- : ControllerServiceImpl(name, uuid) {
- }
-
- explicit MockControllerService(std::string_view name)
- : ControllerServiceImpl(name) {
- }
- MockControllerService() = default;
+ using ControllerServiceBase::ControllerServiceBase;
+ MockControllerService()
+ : ControllerServiceBase({.uuid = utils::Identifier{}, .name = "MockControllerService", .logger = logging::LoggerFactory<MockControllerService>::getLogger()}) {}
~MockControllerService() override = default;
static constexpr const char* Description = "An example service";
static constexpr auto Properties = std::array<minifi::core::PropertyReference, 0>{};
static constexpr bool SupportsDynamicProperties = false;
- ADD_COMMON_VIRTUAL_FUNCTIONS_FOR_CONTROLLER_SERVICES
void initialize() override {
- minifi::core::controller::ControllerServiceImpl::initialize();
+ minifi::core::controller::ControllerServiceBase::initialize();
enable();
}
@@ -66,16 +60,7 @@ class MockControllerService : public minifi::core::controller::ControllerService
str = "pushitrealgood";
}
- void yield() override {
- }
-
- bool isRunning() const override {
- return true;
- }
-
- bool isWorkAvailable() override {
- return true;
- }
+ ControllerServiceInterface* getControllerServiceInterface() override {return this;}
protected:
std::string str;
@@ -117,7 +102,7 @@ class MockProcessor : public minifi::core::ProcessorImpl {
}
std::string linked_service = context.getProperty("linkedService").value_or("");
if (!IsNullOrEmpty(linked_service)) {
- std::shared_ptr<minifi::core::controller::ControllerService> service = context.getControllerService(linked_service, getUUID());
+ std::shared_ptr<minifi::core::controller::ControllerServiceInterface> service = context.getControllerService(linked_service, getUUID());
std::lock_guard<std::mutex> lock(control_mutex);
REQUIRE(nullptr != service);
REQUIRE("pushitrealgood" == std::dynamic_pointer_cast<MockControllerService>(service)->doSomething());
diff --git a/libminifi/test/unit/BackTraceTests.cpp b/libminifi/test/unit/BackTraceTests.cpp
index 8dc26803a..b73187909 100644
--- a/libminifi/test/unit/BackTraceTests.cpp
+++ b/libminifi/test/unit/BackTraceTests.cpp
@@ -52,7 +52,7 @@ TEST_CASE("BT2", "[TPT2]") {
constexpr std::string_view thread_pool_name = "Winnie the pool";
constexpr size_t number_of_worker_threads = 3;
- utils::ThreadPool pool(number_of_worker_threads, nullptr, std::string{thread_pool_name});
+ utils::ThreadPool pool(number_of_worker_threads, std::string{thread_pool_name});
utils::Worker worker([&]() -> utils::TaskRescheduleInfo {
outer_function(ready_for_checking, done_with_checking);
return utils::TaskRescheduleInfo::Done();
diff --git a/libminifi/test/unit/ComponentManifestTests.cpp b/libminifi/test/unit/ComponentManifestTests.cpp
index a02bc87e6..862933449 100644
--- a/libminifi/test/unit/ComponentManifestTests.cpp
+++ b/libminifi/test/unit/ComponentManifestTests.cpp
@@ -21,7 +21,7 @@
#include "unit/Catch.h"
#include "core/Core.h"
#include "core/ConfigurableComponentImpl.h"
-#include "core/controller/ControllerService.h"
+#include "core/controller/ControllerServiceBase.h"
#include "minifi-cpp/core/PropertyDefinition.h"
#include "core/PropertyDefinitionBuilder.h"
#include "core/Resource.h"
@@ -40,19 +40,15 @@ SerializedResponseNode& get(SerializedResponseNode& node, const std::string& fie
namespace test::apple {
-class ExampleService : public core::controller::ControllerServiceImpl {
+class ExampleService : public core::controller::ControllerServiceBase, public core::controller::ControllerServiceInterface {
public:
- using ControllerServiceImpl::ControllerServiceImpl;
+ using ControllerServiceBase::ControllerServiceBase;
+
+ ControllerServiceInterface* getControllerServiceInterface() override {return this;}
static constexpr const char* Description = "An example service";
static constexpr auto Properties = std::array<core::PropertyReference, 0>{};
static constexpr bool SupportsDynamicProperties = false;
- ADD_COMMON_VIRTUAL_FUNCTIONS_FOR_CONTROLLER_SERVICES
-
- bool canEdit() override { return false; }
- void yield() override {}
- bool isRunning() const override { return false; }
- bool isWorkAvailable() override { return false; }
};
REGISTER_RESOURCE(ExampleService, ControllerService);
diff --git a/libminifi/test/unit/JsonFlowSerializerTests.cpp b/libminifi/test/unit/JsonFlowSerializerTests.cpp
index 729a62a30..62fad1d3d 100644
--- a/libminifi/test/unit/JsonFlowSerializerTests.cpp
+++ b/libminifi/test/unit/JsonFlowSerializerTests.cpp
@@ -712,11 +712,11 @@ TEST_CASE("The encrypted flow configuration can be decrypted with the correct ke
const auto controller_service_id = "b9801278-7b5d-4314-aed6-713fd4b5f933";
const auto* const controller_service_node_before = process_group_before->findControllerService(controller_service_id);
REQUIRE(controller_service_node_before);
- const auto* const controller_service_before = controller_service_node_before->getControllerServiceImplementation();
+ const auto controller_service_before = controller_service_node_before->getControllerServiceImplementation();
REQUIRE(controller_service_node_before);
const auto* const controller_service_node_after = process_group_after->findControllerService(controller_service_id);
REQUIRE(controller_service_node_after);
- const auto* const controller_service_after = controller_service_node_before->getControllerServiceImplementation();
+ const auto controller_service_after = controller_service_node_after->getControllerServiceImplementation();
REQUIRE(controller_service_after);
CHECK(controller_service_before->getProperty("CA Certificate") == controller_service_after->getProperty("CA Certificate"));
CHECK(controller_service_before->getProperty("Passphrase") == controller_service_after->getProperty("Passphrase"));
diff --git a/libminifi/test/unit/NetUtilsTest.cpp b/libminifi/test/unit/NetUtilsTest.cpp
index c01611fac..67f4b5736 100644
--- a/libminifi/test/unit/NetUtilsTest.cpp
+++ b/libminifi/test/unit/NetUtilsTest.cpp
@@ -64,7 +64,7 @@ TEST_CASE("utils::net::getSslContext") {
auto plan = controller.createPlan();
auto ssl_context_node = plan->addController("SSLContextService", "ssl_context_service");
- auto ssl_context_service = std::dynamic_pointer_cast<minifi::controllers::SSLContextServiceInterface>(ssl_context_node->getControllerServiceImplementation());
+ auto ssl_context_service = ssl_context_node->getControllerServiceImplementation();
const std::filesystem::path cert_dir = minifi::utils::file::FileUtils::get_executable_dir() / "resources";
@@ -94,7 +94,7 @@ TEST_CASE("utils::net::getSslContext") {
REQUIRE(ssl_context_service->setProperty(minifi::controllers::SSLContextService::CACertificate.name, (cert_dir / "alice_by_A_with_key.pem").string()));
}
REQUIRE_NOTHROW(plan->finalize());
- auto ssl_context = utils::net::getSslContext(*ssl_context_service);
+ auto ssl_context = utils::net::getSslContext(*ssl_context_service->getImplementation<minifi::controllers::SSLContextServiceInterface>());
asio::error_code verification_error;
CHECK_FALSE(ssl_context.set_verify_mode(asio::ssl::verify_peer, verification_error));
CHECK_FALSE(verification_error);
@@ -105,7 +105,7 @@ TEST_CASE("utils::net::getSslContext passphrase problems") {
auto plan = controller.createPlan();
auto ssl_context_node = plan->addController("SSLContextService", "ssl_context_service");
- auto ssl_context_service = std::dynamic_pointer_cast<minifi::controllers::SSLContextServiceInterface>(ssl_context_node->getControllerServiceImplementation());
+ auto ssl_context_service = ssl_context_node->getControllerServiceImplementation();
const std::filesystem::path cert_dir = minifi::utils::file::FileUtils::get_executable_dir() / "resources";
@@ -117,7 +117,7 @@ TEST_CASE("utils::net::getSslContext passphrase problems") {
SECTION("Missing passphrase") {
REQUIRE_NOTHROW(plan->finalize());
- REQUIRE_THROWS_MATCHES(utils::net::getSslContext(*ssl_context_service),
+ REQUIRE_THROWS_MATCHES(utils::net::getSslContext(*ssl_context_service->getImplementation<minifi::controllers::SSLContextServiceInterface>()),
std::runtime_error,
ExceptionSubStringMatcher<std::runtime_error>({"use_private_key_file: bad decrypt (Provider routines)"}));
}
@@ -125,7 +125,7 @@ TEST_CASE("utils::net::getSslContext passphrase problems") {
SECTION("Invalid passphrase") {
REQUIRE(ssl_context_service->setProperty(minifi::controllers::SSLContextService::Passphrase.name, "not_the_correct_passphrase"));
REQUIRE_NOTHROW(plan->finalize());
- REQUIRE_THROWS_MATCHES(utils::net::getSslContext(*ssl_context_service),
+ REQUIRE_THROWS_MATCHES(utils::net::getSslContext(*ssl_context_service->getImplementation<minifi::controllers::SSLContextServiceInterface>()),
std::runtime_error,
ExceptionSubStringMatcher<std::runtime_error>({"use_private_key_file: bad decrypt (Provider routines)"}));
}
@@ -133,7 +133,7 @@ TEST_CASE("utils::net::getSslContext passphrase problems") {
SECTION("Invalid passphrase file") {
REQUIRE(ssl_context_service->setProperty(minifi::controllers::SSLContextService::Passphrase.name, (cert_dir / "alice_by_B.pem").string()));
REQUIRE_NOTHROW(plan->finalize());
- REQUIRE_THROWS_MATCHES(utils::net::getSslContext(*ssl_context_service),
+ REQUIRE_THROWS_MATCHES(utils::net::getSslContext(*ssl_context_service->getImplementation<minifi::controllers::SSLContextServiceInterface>()),
std::runtime_error,
ExceptionSubStringMatcher<std::runtime_error>({"use_private_key_file: bad decrypt (Provider routines)"}));
}
@@ -144,7 +144,7 @@ TEST_CASE("utils::net::getSslContext missing CA") {
auto plan = controller.createPlan();
auto ssl_context_node = plan->addController("SSLContextService", "ssl_context_service");
- auto ssl_context_service = std::dynamic_pointer_cast<minifi::controllers::SSLContextServiceInterface>(ssl_context_node->getControllerServiceImplementation());
+ auto ssl_context_service = ssl_context_node->getControllerServiceImplementation();
const std::filesystem::path cert_dir = minifi::utils::file::FileUtils::get_executable_dir() / "resources";
@@ -152,7 +152,7 @@ TEST_CASE("utils::net::getSslContext missing CA") {
REQUIRE(ssl_context_service->setProperty(minifi::controllers::SSLContextService::PrivateKey.name, (cert_dir / "alice.key").string()));
REQUIRE_NOTHROW(plan->finalize());
- auto ssl_context = utils::net::getSslContext(*ssl_context_service);
+ auto ssl_context = utils::net::getSslContext(*ssl_context_service->getImplementation<minifi::controllers::SSLContextServiceInterface>());
asio::error_code verification_error;
CHECK_FALSE(ssl_context.set_verify_mode(asio::ssl::verify_peer, verification_error));
CHECK_FALSE(verification_error);
diff --git a/libminifi/test/unit/NetworkPrioritizerServiceTests.cpp b/libminifi/test/unit/NetworkPrioritizerServiceTests.cpp
index 93a77cc0c..a54ba109a 100644
--- a/libminifi/test/unit/NetworkPrioritizerServiceTests.cpp
+++ b/libminifi/test/unit/NetworkPrioritizerServiceTests.cpp
@@ -21,16 +21,21 @@
#include <string>
#include "unit/TestBase.h"
#include "unit/Catch.h"
-#include "minifi-cpp/core/controller/ControllerService.h"
#include "controllers/NetworkPrioritizerService.h"
#include "unit/TestUtils.h"
namespace {
-std::shared_ptr<minifi::controllers::NetworkPrioritizerService> createNetworkPrioritizerService(
+std::shared_ptr<core::controller::ControllerService> createNetworkPrioritizerService(
const std::string& name,
const std::shared_ptr<utils::timeutils::Clock>& clock = std::make_shared<minifi::test::utils::ManualClock>()) {
- return std::make_shared<minifi::controllers::NetworkPrioritizerService>(name, utils::Identifier{}, clock);
+ return std::make_shared<core::controller::ControllerService>(
+ name, utils::Identifier{},
+ std::make_unique<minifi::controllers::NetworkPrioritizerService>(core::controller::ControllerServiceMetadata{
+ .uuid = utils::Identifier{},
+ .name = name,
+ .logger = logging::LoggerFactory<minifi::controllers::NetworkPrioritizerService>::getLogger()
+ }, clock));
}
} // namespace
@@ -43,7 +48,7 @@ TEST_CASE("TestPrioritizerOneInterface", "[test1]") {
REQUIRE(controller->setProperty(minifi::controllers::NetworkPrioritizerService::MaxThroughput.name, "10 B"));
REQUIRE(controller->setProperty(minifi::controllers::NetworkPrioritizerService::MaxPayload.name, "10 B"));
controller->onEnable();
- REQUIRE("eth0" == controller->getInterface(0).getInterface());
+ REQUIRE("eth0" == controller->getImplementation<minifi::controllers::NetworkPrioritizerService>()->getInterface(0).getInterface());
}
TEST_CASE("TestPrioritizerOneInterfaceMaxPayload", "[test2]") {
@@ -55,9 +60,9 @@ TEST_CASE("TestPrioritizerOneInterfaceMaxPayload", "[test2]") {
REQUIRE(controller->setProperty(minifi::controllers::NetworkPrioritizerService::MaxPayload.name, "10 B"));
controller->onEnable();
- REQUIRE("eth0" == controller->getInterface(5).getInterface());
- REQUIRE(controller->getInterface(20).getInterface().empty()); // larger than max payload
- REQUIRE("eth0" == controller->getInterface(5).getInterface());
+ REQUIRE("eth0" == controller->getImplementation<minifi::controllers::NetworkPrioritizerService>()->getInterface(5).getInterface());
+ REQUIRE(controller->getImplementation<minifi::controllers::NetworkPrioritizerService>()->getInterface(20).getInterface().empty()); // larger than max payload
+ REQUIRE("eth0" == controller->getImplementation<minifi::controllers::NetworkPrioritizerService>()->getInterface(5).getInterface());
}
TEST_CASE("TestPrioritizerOneInterfaceMaxThroughput", "[test3]") {
@@ -68,11 +73,11 @@ TEST_CASE("TestPrioritizerOneInterfaceMaxThroughput", "[test3]") {
REQUIRE(controller->setProperty(minifi::controllers::NetworkPrioritizerService::VerifyInterfaces.name, "false"));
REQUIRE(controller->setProperty(minifi::controllers::NetworkPrioritizerService::MaxThroughput.name, "10 B"));
controller->onEnable();
- REQUIRE("eth0" == controller->getInterface(5).getInterface());
- REQUIRE("eth0" == controller->getInterface(5).getInterface());
- REQUIRE(controller->getInterface(5).getInterface().empty()); // max throughput reached
+ REQUIRE("eth0" == controller->getImplementation<minifi::controllers::NetworkPrioritizerService>()->getInterface(5).getInterface());
+ REQUIRE("eth0" == controller->getImplementation<minifi::controllers::NetworkPrioritizerService>()->getInterface(5).getInterface());
+ REQUIRE(controller->getImplementation<minifi::controllers::NetworkPrioritizerService>()->getInterface(5).getInterface().empty()); // max throughput reached
clock->advance(std::chrono::milliseconds{10}); // wait for more tokens to be generated
- REQUIRE("eth0" == controller->getInterface(5).getInterface()); // now we can send again
+ REQUIRE("eth0" == controller->getImplementation<minifi::controllers::NetworkPrioritizerService>()->getInterface(5).getInterface()); // now we can send again
}
TEST_CASE("TestPriorotizerMultipleInterfaces", "[test4]") {
@@ -103,16 +108,16 @@ TEST_CASE("TestPriorotizerMultipleInterfaces", "[test4]") {
parent_controller->onEnable();
SECTION("Switch to second interface when the first is saturated") {
- REQUIRE("eth0" == parent_controller->getInterface(5).getInterface());
- REQUIRE("eth0" == parent_controller->getInterface(5).getInterface());
+ REQUIRE("eth0" == parent_controller->getImplementation<minifi::controllers::NetworkPrioritizerService>()->getInterface(5).getInterface());
+ REQUIRE("eth0" == parent_controller->getImplementation<minifi::controllers::NetworkPrioritizerService>()->getInterface(5).getInterface());
// triggered the max throughput on eth0, switching to eth1
- REQUIRE("eth1" == parent_controller->getInterface(5).getInterface());
- REQUIRE("eth1" == parent_controller->getInterface(5).getInterface());
+ REQUIRE("eth1" == parent_controller->getImplementation<minifi::controllers::NetworkPrioritizerService>()->getInterface(5).getInterface());
+ REQUIRE("eth1" == parent_controller->getImplementation<minifi::controllers::NetworkPrioritizerService>()->getInterface(5).getInterface());
}
SECTION("Can keep sending on eth0 if we wait between packets") {
for (int i = 0; i < 100; i++) {
- REQUIRE("eth0" == parent_controller->getInterface(10).getInterface());
+ REQUIRE("eth0" == parent_controller->getImplementation<minifi::controllers::NetworkPrioritizerService>()->getInterface(10).getInterface());
clock->advance(std::chrono::milliseconds{5});
}
}
@@ -144,8 +149,8 @@ TEST_CASE("TestPriorotizerMultipleInterfacesMaxPayload", "[test5]") {
parent_controller->setLinkedControllerServices(services);
parent_controller->onEnable();
- REQUIRE("eth0" == parent_controller->getInterface(10).getInterface());
- REQUIRE("eth0" == parent_controller->getInterface(10).getInterface());
- REQUIRE("eth1" == parent_controller->getInterface(50).getInterface()); // larger than max payload
- REQUIRE("eth0" == parent_controller->getInterface(10).getInterface());
+ REQUIRE("eth0" == parent_controller->getImplementation<minifi::controllers::NetworkPrioritizerService>()->getInterface(10).getInterface());
+ REQUIRE("eth0" == parent_controller->getImplementation<minifi::controllers::NetworkPrioritizerService>()->getInterface(10).getInterface());
+ REQUIRE("eth1" == parent_controller->getImplementation<minifi::controllers::NetworkPrioritizerService>()->getInterface(50).getInterface()); // larger than max payload
+ REQUIRE("eth0" == parent_controller->getImplementation<minifi::controllers::NetworkPrioritizerService>()->getInterface(10).getInterface());
}
diff --git a/libminifi/test/unit/ProcessorConfigUtilsTests.cpp b/libminifi/test/unit/ProcessorConfigUtilsTests.cpp
index 8070ce7a1..298faa228 100644
--- a/libminifi/test/unit/ProcessorConfigUtilsTests.cpp
+++ b/libminifi/test/unit/ProcessorConfigUtilsTests.cpp
@@ -17,9 +17,9 @@
#include "unit/TestBase.h"
#include "unit/Catch.h"
-#include "core/controller/ControllerService.h"
+#include "core/controller/ControllerServiceBase.h"
#include "core/controller/ControllerServiceProvider.h"
-#include "minifi-cpp/core/controller/ControllerServiceNode.h"
+#include "core/controller/ControllerServiceNode.h"
#include "minifi-cpp/core/PropertyDefinition.h"
#include "core/ProcessorImpl.h"
#include "core/PropertyDefinitionBuilder.h"
@@ -28,6 +28,7 @@
#include "utils/Id.h"
#include "unit/TestUtils.h"
#include "core/ProcessContextImpl.h"
+#include "unit/ControllerServiceUtils.h"
namespace org::apache::nifi::minifi::core {
namespace {
@@ -91,26 +92,25 @@ TEST_CASE("Parse enum property") {
}
namespace {
-class TestControllerService : public controller::ControllerServiceImpl {
+class TestControllerService : public controller::ControllerServiceBase, public core::controller::ControllerServiceInterface {
public:
- using ControllerServiceImpl::ControllerServiceImpl;
- bool supportsDynamicProperties() const override { return false; }
- void yield() override {}
- bool isRunning() const override { return false; }
- bool isWorkAvailable() override { return false; }
+ using ControllerServiceBase::ControllerServiceBase;
+ ControllerServiceInterface* getControllerServiceInterface() override {return this;}
};
-const auto test_controller_service = []() {
- auto service = std::make_shared<TestControllerService>("test-controller-service", utils::IdGenerator::getIdGenerator()->generate());
+const std::shared_ptr test_controller_service = []() {
+ auto service = minifi::test::utils::make_controller_service<TestControllerService>("test-controller-service", utils::IdGenerator::getIdGenerator()->generate());
service->initialize();
+ service->onEnable();
+ service->setState(minifi::core::controller::ControllerServiceState::ENABLED);
return service;
}();
class WrongTestControllerService : public TestControllerService {};
-class TestControllerServiceProvider : public controller::ControllerServiceProviderImpl {
+class TestControllerServiceProvider : public controller::ControllerServiceProvider {
public:
- using ControllerServiceProviderImpl::ControllerServiceProviderImpl;
+ using ControllerServiceProvider::ControllerServiceProvider;
std::shared_ptr<controller::ControllerServiceNode> createControllerService(const std::string&, const std::string&) override { return nullptr; }
void clearControllerServices() override {}
void enableAllControllerServices() override {}
@@ -141,7 +141,7 @@ TEST_CASE("Parse controller service property") {
SECTION("... is valid") {
REQUIRE(processor->setProperty(property.name, "TestControllerService"));
const auto value = utils::parseControllerService<TestControllerService>(context, property, processor->getUUID());
- CHECK(value == test_controller_service);
+ CHECK(value.get() == test_controller_service->getImplementation<TestControllerService>());
}
SECTION("... is missing") {
CHECK_THROWS(utils::parseControllerService<TestControllerService>(context, property, processor->getUUID()));
@@ -164,7 +164,7 @@ TEST_CASE("Parse controller service property") {
SECTION("... is valid") {
REQUIRE(processor->setProperty(property.name, "TestControllerService"));
const auto value = utils::parseOptionalControllerService<TestControllerService>(context, property, processor->getUUID());;
- CHECK(value == test_controller_service);
+ CHECK(value.get() == test_controller_service->getImplementation<TestControllerService>());
}
SECTION("... is missing") {
const auto value = utils::parseOptionalControllerService<TestControllerService>(context, property, processor->getUUID());;
diff --git a/libminifi/test/unit/UpdatePolicyTests.cpp b/libminifi/test/unit/UpdatePolicyTests.cpp
index 62fa9f436..8f1fe3869 100644
--- a/libminifi/test/unit/UpdatePolicyTests.cpp
+++ b/libminifi/test/unit/UpdatePolicyTests.cpp
@@ -25,52 +25,53 @@
#include "../../controller/Controller.h"
#include "c2/ControllerSocketProtocol.h"
#include "controllers/UpdatePolicyControllerService.h"
+#include "unit/ControllerServiceUtils.h"
TEST_CASE("TestEmptyPolicy", "[test1]") {
- auto controller = std::make_shared<minifi::controllers::UpdatePolicyControllerService>("TestService");
+ auto controller = minifi::test::utils::make_controller_service<minifi::controllers::UpdatePolicyControllerService>("TestService");
std::shared_ptr<minifi::Configure> configuration = std::make_shared<minifi::ConfigureImpl>();
controller->initialize();
controller->onEnable();
- REQUIRE(false == controller->canUpdate("anyproperty"));
+ REQUIRE(false == controller->getImplementation<minifi::controllers::UpdatePolicyControllerService>()->canUpdate("anyproperty"));
}
TEST_CASE("TestAllowAll", "[test1]") {
- auto controller = std::make_shared<minifi::controllers::UpdatePolicyControllerService>("TestService");
+ auto controller = minifi::test::utils::make_controller_service<minifi::controllers::UpdatePolicyControllerService>("TestService");
std::shared_ptr<minifi::Configure> configuration = std::make_shared<minifi::ConfigureImpl>();
controller->initialize();
REQUIRE(controller->setProperty(minifi::controllers::UpdatePolicyControllerService::AllowAllProperties.name, "true"));
controller->onEnable();
- REQUIRE(true == controller->canUpdate("anyproperty"));
+ REQUIRE(true == controller->getImplementation<minifi::controllers::UpdatePolicyControllerService>()->canUpdate("anyproperty"));
}
TEST_CASE("TestAllowAllFails", "[test1]") {
- auto controller = std::make_shared<minifi::controllers::UpdatePolicyControllerService>("TestService");
+ auto controller = minifi::test::utils::make_controller_service<minifi::controllers::UpdatePolicyControllerService>("TestService");
std::shared_ptr<minifi::Configure> configuration = std::make_shared<minifi::ConfigureImpl>();
controller->initialize();
REQUIRE(controller->setProperty(minifi::controllers::UpdatePolicyControllerService::AllowAllProperties.name, "false"));
controller->onEnable();
- REQUIRE(false == controller->canUpdate("anyproperty"));
+ REQUIRE(false == controller->getImplementation<minifi::controllers::UpdatePolicyControllerService>()->canUpdate("anyproperty"));
}
TEST_CASE("TestEnableProperty", "[test1]") {
- auto controller = std::make_shared<minifi::controllers::UpdatePolicyControllerService>("TestService");
+ auto controller = minifi::test::utils::make_controller_service<minifi::controllers::UpdatePolicyControllerService>("TestService");
std::shared_ptr<minifi::Configure> configuration = std::make_shared<minifi::ConfigureImpl>();
controller->initialize();
REQUIRE(controller->setProperty(minifi::controllers::UpdatePolicyControllerService::AllowAllProperties.name, "false"));
REQUIRE(controller->setProperty(minifi::controllers::UpdatePolicyControllerService::AllowedProperties.name, "anyproperty"));
controller->onEnable();
- REQUIRE(true == controller->canUpdate("anyproperty"));
+ REQUIRE(true == controller->getImplementation<minifi::controllers::UpdatePolicyControllerService>()->canUpdate("anyproperty"));
}
TEST_CASE("TestDisableProperty", "[test1]") {
- auto controller = std::make_shared<minifi::controllers::UpdatePolicyControllerService>("TestService");
+ auto controller = minifi::test::utils::make_controller_service<minifi::controllers::UpdatePolicyControllerService>("TestService");
std::shared_ptr<minifi::Configure> configuration = std::make_shared<minifi::ConfigureImpl>();
controller->initialize();
REQUIRE(controller->setProperty(minifi::controllers::UpdatePolicyControllerService::AllowAllProperties.name, "true"));
REQUIRE(controller->setProperty(minifi::controllers::UpdatePolicyControllerService::DisallowedProperties.name, "anyproperty"));
REQUIRE(controller->appendProperty(minifi::controllers::UpdatePolicyControllerService::DisallowedProperties.name, "anyproperty2"));
controller->onEnable();
- REQUIRE(false == controller->canUpdate("anyproperty"));
- REQUIRE(false == controller->canUpdate("anyproperty2"));
- REQUIRE(true == controller->canUpdate("anyproperty3"));
+ REQUIRE(false == controller->getImplementation<minifi::controllers::UpdatePolicyControllerService>()->canUpdate("anyproperty"));
+ REQUIRE(false == controller->getImplementation<minifi::controllers::UpdatePolicyControllerService>()->canUpdate("anyproperty2"));
+ REQUIRE(true == controller->getImplementation<minifi::controllers::UpdatePolicyControllerService>()->canUpdate("anyproperty3"));
}
diff --git a/libminifi/test/unit/YamlFlowSerializerTests.cpp b/libminifi/test/unit/YamlFlowSerializerTests.cpp
index 78e07eac1..445a3cef4 100644
--- a/libminifi/test/unit/YamlFlowSerializerTests.cpp
+++ b/libminifi/test/unit/YamlFlowSerializerTests.cpp
@@ -327,11 +327,11 @@ TEST_CASE("The encrypted flow configuration can be decrypted with the correct ke
const auto controller_service_id = "b9801278-7b5d-4314-aed6-713fd4b5f933";
const auto* const controller_service_node_before = process_group_before->findControllerService(controller_service_id);
REQUIRE(controller_service_node_before);
- const auto* const controller_service_before = controller_service_node_before->getControllerServiceImplementation();
+ const auto controller_service_before = controller_service_node_before->getControllerServiceImplementation();
REQUIRE(controller_service_node_before);
const auto* const controller_service_node_after = process_group_after->findControllerService(controller_service_id);
REQUIRE(controller_service_node_after);
- const auto* const controller_service_after = controller_service_node_before->getControllerServiceImplementation();
+ const auto controller_service_after = controller_service_node_after->getControllerServiceImplementation();
REQUIRE(controller_service_after);
CHECK(controller_service_before->getProperty("CA Certificate") == controller_service_after->getProperty("CA Certificate"));
CHECK(controller_service_before->getProperty("Passphrase") == controller_service_after->getProperty("Passphrase"));
diff --git a/minifi-api/CMakeLists.txt b/minifi-api/CMakeLists.txt
index aa684c154..95fbb885c 100644
--- a/minifi-api/CMakeLists.txt
+++ b/minifi-api/CMakeLists.txt
@@ -1,6 +1,7 @@
add_library(minifi-api-common INTERFACE)
target_include_directories(minifi-api-common INTERFACE common/include)
target_link_libraries(minifi-api-common INTERFACE gsl-lite)
+target_compile_definitions(minifi-api-common INTERFACE MINIFI_VERSION_STR="${MINIFI_VERSION_STR}")
add_library(minifi-api INTERFACE)
target_include_directories(minifi-api INTERFACE include)
diff --git a/minifi-api/include/minifi-cpp/controllers/AttributeProviderService.h b/minifi-api/include/minifi-cpp/controllers/AttributeProviderService.h
index b366ddf20..0b54b773c 100644
--- a/minifi-api/include/minifi-cpp/controllers/AttributeProviderService.h
+++ b/minifi-api/include/minifi-cpp/controllers/AttributeProviderService.h
@@ -21,11 +21,11 @@
#include <unordered_map>
#include <vector>
-#include "minifi-cpp/core/controller/ControllerService.h"
+#include "minifi-cpp/core/controller/ControllerServiceInterface.h"
namespace org::apache::nifi::minifi::controllers {
-class AttributeProviderService : public virtual core::controller::ControllerService {
+class AttributeProviderService : public core::controller::ControllerServiceInterface {
public:
using AttributeMap = std::unordered_map<std::string, std::string>;
virtual std::optional<std::vector<AttributeMap>> getAttributes() = 0;
diff --git a/minifi-api/include/minifi-cpp/controllers/RecordSetReader.h b/minifi-api/include/minifi-cpp/controllers/RecordSetReader.h
index dccfbe8cc..f91dee361 100644
--- a/minifi-api/include/minifi-cpp/controllers/RecordSetReader.h
+++ b/minifi-api/include/minifi-cpp/controllers/RecordSetReader.h
@@ -16,21 +16,23 @@
*/
#pragma once
-#include "minifi-cpp/core/controller/ControllerService.h"
+#include "minifi-cpp/core/controller/ControllerServiceInterface.h"
#include "minifi-cpp/core/ControllerServiceApiDefinition.h"
#include "minifi-cpp/core/Record.h"
#include "utils/Enum.h"
#include "utils/ProcessorConfigUtils.h"
#include "minifi-cpp/io/InputStream.h"
+#include "minifi-cpp/agent/agent_version.h"
namespace org::apache::nifi::minifi::core {
-class RecordSetReader : public virtual controller::ControllerService {
+class RecordSetReader : public controller::ControllerServiceInterface {
public:
static constexpr auto ProvidesApi = core::ControllerServiceApiDefinition{
.artifact = "minifi-system",
.group = "org.apache.nifi.minifi",
.type = "org.apache.nifi.minifi.core.RecordSetReader",
+ .version = MINIFI_VERSION_STR
};
virtual nonstd::expected<RecordSet, std::error_code> read(io::InputStream& input_stream) = 0;
diff --git a/minifi-api/include/minifi-cpp/controllers/RecordSetWriter.h b/minifi-api/include/minifi-cpp/controllers/RecordSetWriter.h
index e895f64f3..bbe1ebdde 100644
--- a/minifi-api/include/minifi-cpp/controllers/RecordSetWriter.h
+++ b/minifi-api/include/minifi-cpp/controllers/RecordSetWriter.h
@@ -16,21 +16,23 @@
*/
#pragma once
-#include "minifi-cpp/core/controller/ControllerService.h"
+#include "minifi-cpp/core/controller/ControllerServiceInterface.h"
#include "minifi-cpp/core/ControllerServiceApiDefinition.h"
#include "minifi-cpp/core/FlowFile.h"
#include "minifi-cpp/core/ProcessSession.h"
#include "minifi-cpp/core/Record.h"
+#include "minifi-cpp/agent/agent_version.h"
namespace org::apache::nifi::minifi::core {
-class RecordSetWriter : public virtual controller::ControllerService {
+class RecordSetWriter : public controller::ControllerServiceInterface {
public:
static constexpr auto ProvidesApi = core::ControllerServiceApiDefinition{
.artifact = "minifi-system",
.group = "org.apache.nifi.minifi",
.type = "org.apache.nifi.minifi.core.RecordSetWriter",
+ .version = MINIFI_VERSION_STR
};
virtual void write(const RecordSet& record_set, const std::shared_ptr<FlowFile>& flow_file, ProcessSession& session) = 0;
diff --git a/minifi-api/include/minifi-cpp/controllers/SSLContextServiceInterface.h b/minifi-api/include/minifi-cpp/controllers/SSLContextServiceInterface.h
index 01877c6c4..68d79380b 100644
--- a/minifi-api/include/minifi-cpp/controllers/SSLContextServiceInterface.h
+++ b/minifi-api/include/minifi-cpp/controllers/SSLContextServiceInterface.h
@@ -22,7 +22,8 @@
#include <utility>
#include "minifi-cpp/core/ControllerServiceApiDefinition.h"
-#include "minifi-cpp/core/controller/ControllerService.h"
+#include "minifi-cpp/agent/agent_version.h"
+#include "minifi-cpp/core/controller/ControllerServiceInterface.h"
namespace org::apache::nifi::minifi::controllers {
@@ -34,12 +35,13 @@ namespace org::apache::nifi::minifi::controllers {
* Justification: Abstracts SSL support out of processors into a
* configurable controller service.
*/
-class SSLContextServiceInterface : public virtual core::controller::ControllerService {
+class SSLContextServiceInterface : public core::controller::ControllerServiceInterface {
public:
static constexpr auto ProvidesApi = core::ControllerServiceApiDefinition{
.artifact = "minifi-system",
.group = "org.apache.nifi.minifi",
.type = "org.apache.nifi.minifi.controllers.SSLContextServiceInterface",
+ .version = MINIFI_VERSION_STR
};
virtual const std::filesystem::path& getCertificateFile() const = 0;
diff --git a/minifi-api/include/minifi-cpp/controllers/ThreadManagementService.h b/minifi-api/include/minifi-cpp/controllers/ThreadManagementService.h
deleted file mode 100644
index 139e39c05..000000000
--- a/minifi-api/include/minifi-cpp/controllers/ThreadManagementService.h
+++ /dev/null
@@ -1,75 +0,0 @@
-/**
- *
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#pragma once
-
-#include <iostream>
-#include <string>
-#include <memory>
-#include <utility>
-
-#include "utils/StringUtils.h"
-#include "io/validation.h"
-#include "minifi-cpp/core/controller/ControllerService.h"
-
-namespace org::apache::nifi::minifi::controllers {
-
-/**
- * Purpose: Thread management service provides a contextual awareness across
- * thread pools that enables us to deliver QOS to an agent.
- */
-class ThreadManagementService : public virtual core::controller::ControllerService {
- public:
- /**
- * Helps to determine if the number of tasks will increase the pools above their threshold.
- * @param new_tasks tasks to be added.
- * @return true if above max, false otherwise.
- */
- virtual bool isAboveMax(const int new_tasks) = 0;
-
- /**
- * Returns the max number of threads allowed by all pools
- * @return max threads.
- */
- virtual uint16_t getMaxThreads() = 0;
-
- /**
- * Function based on cooperative multitasking that will tell a caller whether or not the number of threads should be reduced.
- * @return true if threading impacts QOS.
- */
- virtual bool shouldReduce() = 0;
-
- /**
- * Function to indicate to this controller service that we've reduced threads in a threadpool
- */
- virtual void reduce() = 0;
-
- /**
- * Registration function to tabulate total threads.
- * @param threads threads from a thread pool.
- */
- virtual void registerThreadCount(const int threads) = 0;
-
- /**
- * Function to help callers identify if they can increase threads.
- * @return true if QOS won't be breached.
- */
- virtual bool canIncrease() = 0;
-};
-
-} // namespace org::apache::nifi::minifi::controllers
diff --git a/minifi-api/include/minifi-cpp/core/ClassLoader.h b/minifi-api/include/minifi-cpp/core/ClassLoader.h
index 7956083ff..559ef0048 100644
--- a/minifi-api/include/minifi-cpp/core/ClassLoader.h
+++ b/minifi-api/include/minifi-cpp/core/ClassLoader.h
@@ -27,6 +27,7 @@
#include "Core.h"
#include "ObjectFactory.h"
#include "ProcessorFactory.h"
+#include "controller/ControllerServiceFactory.h"
namespace org::apache::nifi::minifi::core {
@@ -67,6 +68,8 @@ class ClassLoader {
virtual void registerClass(const std::string &clazz, std::unique_ptr<ProcessorFactory> factory) = 0;
+ virtual void registerClass(const std::string &clazz, std::unique_ptr<controller::ControllerServiceFactory> factory) = 0;
+
virtual void unregisterClass(const std::string& clazz) = 0;
[[nodiscard]] virtual std::optional<std::string> getGroupForClass(const std::string &class_name) const = 0;
diff --git a/minifi-api/include/minifi-cpp/core/ControllerServiceApiDefinition.h b/minifi-api/include/minifi-cpp/core/ControllerServiceApiDefinition.h
index 172253569..37084baea 100644
--- a/minifi-api/include/minifi-cpp/core/ControllerServiceApiDefinition.h
+++ b/minifi-api/include/minifi-cpp/core/ControllerServiceApiDefinition.h
@@ -24,6 +24,7 @@ struct ControllerServiceApiDefinition {
std::string_view artifact;
std::string_view group;
std::string_view type;
+ std::string_view version;
};
} // namespace org::apache::nifi::minifi::core
diff --git a/minifi-api/include/minifi-cpp/core/ProcessContext.h b/minifi-api/include/minifi-cpp/core/ProcessContext.h
index a81e45e0f..24f64a82c 100644
--- a/minifi-api/include/minifi-cpp/core/ProcessContext.h
+++ b/minifi-api/include/minifi-cpp/core/ProcessContext.h
@@ -23,12 +23,12 @@
#include "minifi-cpp/core/Core.h"
#include "minifi-cpp/core/ContentRepository.h"
-#include "minifi-cpp/core/controller/ControllerServiceLookup.h"
#include "minifi-cpp/core/Property.h"
#include "minifi-cpp/core/Repository.h"
#include "minifi-cpp/core/FlowFile.h"
#include "minifi-cpp/core/StateStorage.h"
#include "minifi-cpp/core/VariableRegistry.h"
+#include "minifi-cpp/core/controller/ControllerServiceInterface.h"
namespace org::apache::nifi::minifi::core {
@@ -88,7 +88,7 @@ class ProcessContext : public virtual core::VariableRegistry, public virtual uti
virtual bool hasNonEmptyProperty(std::string_view name) const = 0;
virtual void yield() = 0;
- virtual std::shared_ptr<core::controller::ControllerService> getControllerService(const std::string &identifier, const utils::Identifier &processor_uuid) const = 0;
+ virtual std::shared_ptr<core::controller::ControllerServiceInterface> getControllerService(const std::string &identifier, const utils::Identifier &processor_uuid) const = 0;
static constexpr char const* DefaultStateStorageName = "defaultstatestorage";
virtual StateManager* getStateManager() = 0;
diff --git a/libminifi/src/core/controller/ControllerServiceNode.cpp b/minifi-api/include/minifi-cpp/core/controller/ControllerServiceApi.h
similarity index 55%
copy from libminifi/src/core/controller/ControllerServiceNode.cpp
copy to minifi-api/include/minifi-cpp/core/controller/ControllerServiceApi.h
index a41a31f84..f751bb7f9 100644
--- a/libminifi/src/core/controller/ControllerServiceNode.cpp
+++ b/minifi-api/include/minifi-cpp/core/controller/ControllerServiceApi.h
@@ -1,6 +1,5 @@
/**
- *
- * Licensed to the Apache Software Foundation (ASF) under one or more
+* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
@@ -15,23 +14,26 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+#pragma once
-#include "core/controller/ControllerServiceNode.h"
#include <memory>
#include <vector>
-namespace org::apache::nifi::minifi::core::controller {
+#include "ControllerServiceInterface.h"
+#include "ControllerServiceContext.h"
+#include "ControllerServiceDescriptor.h"
+#include "minifi-cpp/properties/Configure.h"
-std::shared_ptr<ControllerService> ControllerServiceNodeImpl::getControllerServiceImplementation() {
- return controller_service_;
-}
+namespace org::apache::nifi::minifi::core::controller {
-const ControllerService* ControllerServiceNodeImpl::getControllerServiceImplementation() const {
- return controller_service_.get();
-}
+class ControllerServiceApi {
+ public:
+ virtual ~ControllerServiceApi() = default;
-const std::vector<ControllerServiceNode*>& ControllerServiceNodeImpl::getLinkedControllerServices() const {
- return linked_controller_services_;
-}
+ virtual void initialize(ControllerServiceDescriptor& descriptor) = 0;
+ virtual void onEnable(ControllerServiceContext& context, const std::shared_ptr<Configure>& configuration, const std::vector<std::shared_ptr<ControllerServiceInterface>>& linked_services) = 0;
+ virtual void notifyStop() = 0;
+ virtual ControllerServiceInterface* getControllerServiceInterface() = 0;
+};
} // namespace org::apache::nifi::minifi::core::controller
diff --git a/libminifi/src/core/controller/ControllerServiceNode.cpp b/minifi-api/include/minifi-cpp/core/controller/ControllerServiceContext.h
similarity index 60%
copy from libminifi/src/core/controller/ControllerServiceNode.cpp
copy to minifi-api/include/minifi-cpp/core/controller/ControllerServiceContext.h
index a41a31f84..ee906e856 100644
--- a/libminifi/src/core/controller/ControllerServiceNode.cpp
+++ b/minifi-api/include/minifi-cpp/core/controller/ControllerServiceContext.h
@@ -1,6 +1,5 @@
/**
- *
- * Licensed to the Apache Software Foundation (ASF) under one or more
+* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
@@ -15,23 +14,22 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+#pragma once
-#include "core/controller/ControllerServiceNode.h"
-#include <memory>
+#include <string>
#include <vector>
+#include <system_error>
+#include <string_view>
+#include "utils/expected.h"
namespace org::apache::nifi::minifi::core::controller {
-std::shared_ptr<ControllerService> ControllerServiceNodeImpl::getControllerServiceImplementation() {
- return controller_service_;
-}
-
-const ControllerService* ControllerServiceNodeImpl::getControllerServiceImplementation() const {
- return controller_service_.get();
-}
+class ControllerServiceContext {
+ public:
+ virtual ~ControllerServiceContext() = default;
-const std::vector<ControllerServiceNode*>& ControllerServiceNodeImpl::getLinkedControllerServices() const {
- return linked_controller_services_;
-}
+ [[nodiscard]] virtual nonstd::expected<std::string, std::error_code> getProperty(std::string_view name) const = 0;
+ [[nodiscard]] virtual nonstd::expected<std::vector<std::string>, std::error_code> getAllPropertyValues(std::string_view name) const = 0;
+};
} // namespace org::apache::nifi::minifi::core::controller
diff --git a/extension-framework/include/controllers/RecordSetReader.h b/minifi-api/include/minifi-cpp/core/controller/ControllerServiceDescriptor.h
similarity index 69%
copy from extension-framework/include/controllers/RecordSetReader.h
copy to minifi-api/include/minifi-cpp/core/controller/ControllerServiceDescriptor.h
index ead6e019f..525a6d6ce 100644
--- a/extension-framework/include/controllers/RecordSetReader.h
+++ b/minifi-api/include/minifi-cpp/core/controller/ControllerServiceDescriptor.h
@@ -16,15 +16,16 @@
*/
#pragma once
-#include "minifi-cpp/controllers/RecordSetReader.h"
-#include "core/controller/ControllerService.h"
+#include <span>
+#include "minifi-cpp/core/PropertyDefinition.h"
+namespace org::apache::nifi::minifi::core::controller {
-namespace org::apache::nifi::minifi::core {
-
-class RecordSetReaderImpl : public virtual controller::ControllerServiceImpl, public virtual RecordSetReader {
+class ControllerServiceDescriptor {
public:
- using ControllerServiceImpl::ControllerServiceImpl;
+ virtual ~ControllerServiceDescriptor() = default;
+
+ virtual void setSupportedProperties(std::span<const PropertyReference> properties) = 0;
};
-} // namespace org::apache::nifi::minifi::core
+} // namespace org::apache::nifi::minifi::core::controller
diff --git a/libminifi/src/core/controller/ControllerServiceNode.cpp b/minifi-api/include/minifi-cpp/core/controller/ControllerServiceFactory.h
similarity index 61%
copy from libminifi/src/core/controller/ControllerServiceNode.cpp
copy to minifi-api/include/minifi-cpp/core/controller/ControllerServiceFactory.h
index a41a31f84..725944bfa 100644
--- a/libminifi/src/core/controller/ControllerServiceNode.cpp
+++ b/minifi-api/include/minifi-cpp/core/controller/ControllerServiceFactory.h
@@ -1,6 +1,5 @@
/**
- *
- * Licensed to the Apache Software Foundation (ASF) under one or more
+* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
@@ -16,22 +15,24 @@
* limitations under the License.
*/
-#include "core/controller/ControllerServiceNode.h"
+#pragma once
+
+#include <string>
#include <memory>
-#include <vector>
+#include <utility>
+#include "minifi-cpp/core/controller/ControllerServiceMetadata.h"
namespace org::apache::nifi::minifi::core::controller {
-std::shared_ptr<ControllerService> ControllerServiceNodeImpl::getControllerServiceImplementation() {
- return controller_service_;
-}
+class ControllerServiceApi;
-const ControllerService* ControllerServiceNodeImpl::getControllerServiceImplementation() const {
- return controller_service_.get();
-}
+class ControllerServiceFactory {
+ public:
+ virtual std::unique_ptr<ControllerServiceApi> create(ControllerServiceMetadata metadata) = 0;
+ virtual std::string getGroupName() const = 0;
+ virtual std::string getClassName() const = 0;
-const std::vector<ControllerServiceNode*>& ControllerServiceNodeImpl::getLinkedControllerServices() const {
- return linked_controller_services_;
-}
+ virtual ~ControllerServiceFactory() = default;
+};
} // namespace org::apache::nifi::minifi::core::controller
diff --git a/minifi-api/include/minifi-cpp/core/controller/ControllerService.h b/minifi-api/include/minifi-cpp/core/controller/ControllerServiceInterface.h
similarity index 71%
rename from minifi-api/include/minifi-cpp/core/controller/ControllerService.h
rename to minifi-api/include/minifi-cpp/core/controller/ControllerServiceInterface.h
index 326075716..e1d7da19e 100644
--- a/minifi-api/include/minifi-cpp/core/controller/ControllerService.h
+++ b/minifi-api/include/minifi-cpp/core/controller/ControllerServiceInterface.h
@@ -28,27 +28,15 @@
namespace org::apache::nifi::minifi::core::controller {
-enum ControllerServiceState {
- DISABLED,
- DISABLING,
- ENABLING,
- ENABLED
-};
-
/**
* Controller Service base class that contains some pure virtual methods.
*
* Design: OnEnable is executed when the controller service is being enabled.
* Note that keeping state here must be protected in this function.
*/
-class ControllerService : public virtual ConfigurableComponent, public virtual Connectable {
+class ControllerServiceInterface {
public:
- virtual void setConfiguration(const std::shared_ptr<Configure> &configuration) = 0;
- virtual ControllerServiceState getState() const = 0;
- virtual void onEnable() = 0;
- virtual void notifyStop() = 0;
- virtual void setState(ControllerServiceState state) = 0;
- virtual void setLinkedControllerServices(const std::vector<std::shared_ptr<controller::ControllerService>> &services) = 0;
+ virtual ~ControllerServiceInterface() = default;
};
} // namespace org::apache::nifi::minifi::core::controller
diff --git a/libminifi/src/core/controller/ControllerServiceNode.cpp b/minifi-api/include/minifi-cpp/core/controller/ControllerServiceMetadata.h
similarity index 65%
copy from libminifi/src/core/controller/ControllerServiceNode.cpp
copy to minifi-api/include/minifi-cpp/core/controller/ControllerServiceMetadata.h
index a41a31f84..3c6fb63b7 100644
--- a/libminifi/src/core/controller/ControllerServiceNode.cpp
+++ b/minifi-api/include/minifi-cpp/core/controller/ControllerServiceMetadata.h
@@ -1,5 +1,4 @@
/**
- *
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
@@ -15,23 +14,19 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+#pragma once
-#include "core/controller/ControllerServiceNode.h"
#include <memory>
-#include <vector>
+#include <string>
+#include "minifi-cpp/utils/Id.h"
+#include "minifi-cpp/core/logging/Logger.h"
namespace org::apache::nifi::minifi::core::controller {
-std::shared_ptr<ControllerService> ControllerServiceNodeImpl::getControllerServiceImplementation() {
- return controller_service_;
-}
-
-const ControllerService* ControllerServiceNodeImpl::getControllerServiceImplementation() const {
- return controller_service_.get();
-}
-
-const std::vector<ControllerServiceNode*>& ControllerServiceNodeImpl::getLinkedControllerServices() const {
- return linked_controller_services_;
-}
+struct ControllerServiceMetadata {
+ utils::Identifier uuid;
+ std::string name;
+ std::shared_ptr<logging::Logger> logger;
+};
} // namespace org::apache::nifi::minifi::core::controller
diff --git a/minifi-api/include/minifi-cpp/core/controller/ControllerServiceProvider.h b/minifi-api/include/minifi-cpp/core/controller/ControllerServiceProvider.h
deleted file mode 100644
index c7ae924d9..000000000
--- a/minifi-api/include/minifi-cpp/core/controller/ControllerServiceProvider.h
+++ /dev/null
@@ -1,54 +0,0 @@
-/**
- *
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#pragma once
-
-#include <memory>
-#include <string>
-#include <string_view>
-#include <utility>
-#include <future>
-#include <vector>
-
-#include "minifi-cpp/core/Core.h"
-#include "minifi-cpp/core/controller/ControllerServiceLookup.h"
-#include "minifi-cpp/core/ConfigurableComponent.h"
-#include "ControllerServiceNode.h"
-
-namespace org::apache::nifi::minifi::core {
-class ProcessGroup;
-}
-
-namespace org::apache::nifi::minifi::core::controller {
-
-class ControllerServiceProvider : public virtual CoreComponent, public virtual ConfigurableComponent, public virtual ControllerServiceLookup, public utils::EnableSharedFromThis {
- public:
- ~ControllerServiceProvider() override = default;
-
- virtual std::shared_ptr<ControllerServiceNode> createControllerService(const std::string &type, const std::string &id) = 0;
- virtual ControllerServiceNode* getControllerServiceNode(const std::string &id) const = 0;
- virtual ControllerServiceNode* getControllerServiceNode(const std::string &id, const utils::Identifier &processor_or_controller_uuid) const = 0;
- virtual void putControllerServiceNode(const std::string& identifier, const std::shared_ptr<ControllerServiceNode>& controller_service_node, ProcessGroup* process_group) = 0;
-
- virtual void clearControllerServices() = 0;
- virtual std::vector<std::shared_ptr<core::controller::ControllerServiceNode>> getAllControllerServices() = 0;
- virtual void enableAllControllerServices() = 0;
- virtual void disableAllControllerServices() = 0;
-};
-
-} // namespace org::apache::nifi::minifi::core::controller
(nifi-minifi-cpp) 02/03: MINIFICPP-2710 Refactor ControllerServiceNodeMap
Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
martinzink pushed a commit to branch controller_c_api_requirements
in repository https://gitbox.apache.org/repos/asf/nifi-minifi-cpp.git
commit becaaa9bb58c0121afa5d4593e67b6600db79ed1
Author: Martin Zink <ma...@apache.org>
AuthorDate: Thu Feb 12 16:31:28 2026 +0100
MINIFICPP-2710 Refactor ControllerServiceNodeMap
Closes #2098
Signed-off-by: Martin Zink <ma...@apache.org>
---
.../azure/tests/ListAzureBlobStorageTests.cpp | 129 ++++++++++-----------
.../tests/unit/ControllerServiceTests.cpp | 6 +-
libminifi/include/core/FlowConfiguration.h | 2 +-
libminifi/include/core/ProcessContextImpl.h | 2 +-
.../core/controller/ControllerServiceNodeMap.h | 19 ++-
.../core/controller/ControllerServiceProvider.h | 10 +-
.../ForwardingControllerServiceProvider.h | 4 +-
.../controller/StandardControllerServiceProvider.h | 5 +-
libminifi/src/core/FlowConfiguration.cpp | 4 +-
libminifi/src/core/ProcessGroup.cpp | 2 +-
.../core/controller/ControllerServiceNodeMap.cpp | 100 +++++++++-------
.../core/controller/ControllerServiceProvider.cpp | 11 +-
.../StandardControllerServiceProvider.cpp | 11 +-
.../src/core/flow/StructuredConfiguration.cpp | 5 +-
libminifi/test/libtest/unit/TestBase.cpp | 5 +-
libminifi/test/unit/ProcessorConfigUtilsTests.cpp | 2 +-
16 files changed, 172 insertions(+), 145 deletions(-)
diff --git a/extensions/azure/tests/ListAzureBlobStorageTests.cpp b/extensions/azure/tests/ListAzureBlobStorageTests.cpp
index 31bdad909..8f837e57f 100644
--- a/extensions/azure/tests/ListAzureBlobStorageTests.cpp
+++ b/extensions/azure/tests/ListAzureBlobStorageTests.cpp
@@ -55,14 +55,14 @@ class ListAzureBlobStorageTestsFixture {
plan_->addProcessor(std::move(list_azure_blob_storage_unique_ptr), "ListAzureBlobStorage", { {"success", "d"} });
auto logattribute = plan_->addProcessor("LogAttribute", "LogAttribute", { {"success", "d"} }, true);
- plan_->setProperty(logattribute, minifi::processors::LogAttribute::FlowFilesToLog, "0");
+ CHECK(plan_->setProperty(logattribute, minifi::processors::LogAttribute::FlowFilesToLog, "0"));
azure_storage_cred_service_ = plan_->addController("AzureStorageCredentialsService", "AzureStorageCredentialsService");
}
void setDefaultCredentials() {
- plan_->setProperty(list_azure_blob_storage_, "Storage Account Name", STORAGE_ACCOUNT_NAME);
- plan_->setProperty(list_azure_blob_storage_, "Storage Account Key", STORAGE_ACCOUNT_KEY);
+ CHECK(plan_->setProperty(list_azure_blob_storage_, "Storage Account Name", STORAGE_ACCOUNT_NAME));
+ CHECK(plan_->setProperty(list_azure_blob_storage_, "Storage Account Key", STORAGE_ACCOUNT_KEY));
}
ListAzureBlobStorageTestsFixture(ListAzureBlobStorageTestsFixture&&) = delete;
@@ -87,82 +87,80 @@ namespace {
using namespace std::literals::chrono_literals;
TEST_CASE_METHOD(ListAzureBlobStorageTestsFixture, "Test credentials settings", "[azureStorageCredentials]") {
- plan_->setProperty(list_azure_blob_storage_, "Container Name", CONTAINER_NAME);
+ CHECK(plan_->setProperty(list_azure_blob_storage_, "Container Name", CONTAINER_NAME));
SECTION("No credentials are set") {
REQUIRE_THROWS_AS(test_controller_.runSession(plan_, true), minifi::Exception);
}
SECTION("No account key or SAS is set") {
- plan_->setProperty(list_azure_blob_storage_, "Storage Account Name", STORAGE_ACCOUNT_NAME);
+ CHECK(plan_->setProperty(list_azure_blob_storage_, "Storage Account Name", STORAGE_ACCOUNT_NAME));
REQUIRE_THROWS_AS(test_controller_.runSession(plan_, true), minifi::Exception);
}
SECTION("Credentials set in Azure Storage Credentials Service") {
- auto azure_storage_cred_service = plan_->addController("AzureStorageCredentialsService", "AzureStorageCredentialsService");
- plan_->setProperty(azure_storage_cred_service, "Storage Account Name", STORAGE_ACCOUNT_NAME);
- plan_->setProperty(azure_storage_cred_service, "Storage Account Key", STORAGE_ACCOUNT_KEY);
- plan_->setProperty(list_azure_blob_storage_, "Azure Storage Credentials Service", "AzureStorageCredentialsService");
+ CHECK(plan_->setProperty(azure_storage_cred_service_, "Storage Account Name", STORAGE_ACCOUNT_NAME));
+ CHECK(plan_->setProperty(azure_storage_cred_service_, "Storage Account Key", STORAGE_ACCOUNT_KEY));
+ CHECK(plan_->setProperty(list_azure_blob_storage_, "Azure Storage Credentials Service", "AzureStorageCredentialsService"));
test_controller_.runSession(plan_, true);
auto passed_params = mock_blob_storage_ptr_->getPassedListParams();
REQUIRE(passed_params.credentials.buildConnectionString() == "AccountName=" + STORAGE_ACCOUNT_NAME + ";AccountKey=" + STORAGE_ACCOUNT_KEY);
}
SECTION("Overriding credentials set in Azure Storage Credentials Service with connection string") {
- auto azure_storage_cred_service = plan_->addController("AzureStorageCredentialsService", "AzureStorageCredentialsService");
- plan_->setProperty(azure_storage_cred_service, "Storage Account Name", STORAGE_ACCOUNT_NAME);
- plan_->setProperty(azure_storage_cred_service, "Storage Account Key", STORAGE_ACCOUNT_KEY);
- plan_->setProperty(azure_storage_cred_service, "Connection String", CONNECTION_STRING);
- plan_->setProperty(list_azure_blob_storage_, "Azure Storage Credentials Service", "AzureStorageCredentialsService");
+ CHECK(plan_->setProperty(azure_storage_cred_service_, "Storage Account Name", STORAGE_ACCOUNT_NAME));
+ CHECK(plan_->setProperty(azure_storage_cred_service_, "Storage Account Key", STORAGE_ACCOUNT_KEY));
+ CHECK(plan_->setProperty(azure_storage_cred_service_, "Connection String", CONNECTION_STRING));
+ CHECK(plan_->setProperty(list_azure_blob_storage_, "Azure Storage Credentials Service", "AzureStorageCredentialsService"));
test_controller_.runSession(plan_, true);
auto passed_params = mock_blob_storage_ptr_->getPassedListParams();
REQUIRE(passed_params.credentials.buildConnectionString() == CONNECTION_STRING);
}
SECTION("Account name and key set in properties") {
- plan_->setProperty(list_azure_blob_storage_, "Storage Account Name", STORAGE_ACCOUNT_NAME);
- plan_->setProperty(list_azure_blob_storage_, "Storage Account Key", STORAGE_ACCOUNT_KEY);
+ CHECK(plan_->setProperty(list_azure_blob_storage_, "Storage Account Name", STORAGE_ACCOUNT_NAME));
+ CHECK(plan_->setProperty(list_azure_blob_storage_, "Storage Account Key", STORAGE_ACCOUNT_KEY));
test_controller_.runSession(plan_, true);
auto passed_params = mock_blob_storage_ptr_->getPassedListParams();
REQUIRE(passed_params.credentials.buildConnectionString() == "AccountName=" + STORAGE_ACCOUNT_NAME + ";AccountKey=" + STORAGE_ACCOUNT_KEY);
}
SECTION("Account name and SAS token set in properties") {
- plan_->setProperty(list_azure_blob_storage_, "Storage Account Name", STORAGE_ACCOUNT_NAME);
- plan_->setProperty(list_azure_blob_storage_, "SAS Token", SAS_TOKEN);
+ CHECK(plan_->setProperty(list_azure_blob_storage_, "Storage Account Name", STORAGE_ACCOUNT_NAME));
+ CHECK(plan_->setProperty(list_azure_blob_storage_, "SAS Token", SAS_TOKEN));
test_controller_.runSession(plan_, true);
auto passed_params = mock_blob_storage_ptr_->getPassedListParams();
REQUIRE(passed_params.credentials.buildConnectionString() == "AccountName=" + STORAGE_ACCOUNT_NAME + ";SharedAccessSignature=" + SAS_TOKEN);
}
SECTION("Account name and SAS token with question mark set in properties") {
- plan_->setProperty(list_azure_blob_storage_, "Storage Account Name", STORAGE_ACCOUNT_NAME);
- plan_->setProperty(list_azure_blob_storage_, "SAS Token", "?" + SAS_TOKEN);
+ CHECK(plan_->setProperty(list_azure_blob_storage_, "Storage Account Name", STORAGE_ACCOUNT_NAME));
+ CHECK(plan_->setProperty(list_azure_blob_storage_, "SAS Token", "?" + SAS_TOKEN));
test_controller_.runSession(plan_, true);
auto passed_params = mock_blob_storage_ptr_->getPassedListParams();
REQUIRE(passed_params.credentials.buildConnectionString() == "AccountName=" + STORAGE_ACCOUNT_NAME + ";SharedAccessSignature=" + SAS_TOKEN);
}
SECTION("Endpoint suffix overriden") {
- plan_->setProperty(list_azure_blob_storage_, "Storage Account Name", STORAGE_ACCOUNT_NAME);
- plan_->setProperty(list_azure_blob_storage_, "Storage Account Key", STORAGE_ACCOUNT_KEY);
- plan_->setProperty(list_azure_blob_storage_, "Common Storage Account Endpoint Suffix", ENDPOINT_SUFFIX);
+ CHECK(plan_->setProperty(list_azure_blob_storage_, "Storage Account Name", STORAGE_ACCOUNT_NAME));
+ CHECK(plan_->setProperty(list_azure_blob_storage_, "Storage Account Key", STORAGE_ACCOUNT_KEY));
+ CHECK(plan_->setProperty(list_azure_blob_storage_, "Common Storage Account Endpoint Suffix", ENDPOINT_SUFFIX));
test_controller_.runSession(plan_, true);
auto passed_params = mock_blob_storage_ptr_->getPassedListParams();
REQUIRE(passed_params.credentials.buildConnectionString() == "AccountName=" + STORAGE_ACCOUNT_NAME + ";AccountKey=" + STORAGE_ACCOUNT_KEY + ";EndpointSuffix=" + ENDPOINT_SUFFIX);
}
SECTION("Use connection string") {
- plan_->setProperty(list_azure_blob_storage_, "Connection String", CONNECTION_STRING);
+ CHECK(plan_->setProperty(list_azure_blob_storage_, "Connection String", CONNECTION_STRING));
test_controller_.runSession(plan_, true);
auto passed_params = mock_blob_storage_ptr_->getPassedListParams();
REQUIRE(passed_params.credentials.buildConnectionString() == CONNECTION_STRING);
}
SECTION("Overriding credentials with connection string") {
- plan_->setProperty(list_azure_blob_storage_, "Storage Account Name", STORAGE_ACCOUNT_NAME);
- plan_->setProperty(list_azure_blob_storage_, "Storage Account Key", STORAGE_ACCOUNT_KEY);
- plan_->setProperty(list_azure_blob_storage_, "Connection String", CONNECTION_STRING);
+ CHECK(plan_->setProperty(list_azure_blob_storage_, "Storage Account Name", STORAGE_ACCOUNT_NAME));
+ CHECK(plan_->setProperty(list_azure_blob_storage_, "Storage Account Key", STORAGE_ACCOUNT_KEY));
+ CHECK(plan_->setProperty(list_azure_blob_storage_, "Connection String", CONNECTION_STRING));
test_controller_.runSession(plan_, true);
auto passed_params = mock_blob_storage_ptr_->getPassedListParams();
REQUIRE(passed_params.credentials.buildConnectionString() == CONNECTION_STRING);
@@ -186,9 +184,9 @@ TEST_CASE_METHOD(ListAzureBlobStorageTestsFixture, "Test credentials settings",
credential_configuration_strategy_string = "Workload Identity";
}
- plan_->setProperty(list_azure_blob_storage_, "Storage Account Name", STORAGE_ACCOUNT_NAME);
- plan_->setProperty(list_azure_blob_storage_, "Credential Configuration Strategy", credential_configuration_strategy_string);
- plan_->setProperty(list_azure_blob_storage_, "Managed Identity Client ID", managed_identity_client_id);
+ CHECK(plan_->setProperty(list_azure_blob_storage_, "Storage Account Name", STORAGE_ACCOUNT_NAME));
+ CHECK(plan_->setProperty(list_azure_blob_storage_, "Credential Configuration Strategy", credential_configuration_strategy_string));
+ CHECK(plan_->setProperty(list_azure_blob_storage_, "Managed Identity Client ID", managed_identity_client_id));
test_controller_.runSession(plan_, true);
auto passed_params = mock_blob_storage_ptr_->getPassedListParams();
CHECK(passed_params.credentials.buildConnectionString().empty());
@@ -217,12 +215,11 @@ TEST_CASE_METHOD(ListAzureBlobStorageTestsFixture, "Test credentials settings",
credential_configuration_strategy_string = "Workload Identity";
}
- auto azure_storage_cred_service = plan_->addController("AzureStorageCredentialsService", "AzureStorageCredentialsService");
- plan_->setProperty(azure_storage_cred_service, "Storage Account Name", STORAGE_ACCOUNT_NAME);
- plan_->setProperty(azure_storage_cred_service, "Credential Configuration Strategy", credential_configuration_strategy_string);
- plan_->setProperty(azure_storage_cred_service, "Common Storage Account Endpoint Suffix", "core.chinacloudapi.cn");
- plan_->setProperty(azure_storage_cred_service, "Managed Identity Client ID", managed_identity_client_id);
- plan_->setProperty(list_azure_blob_storage_, "Azure Storage Credentials Service", "AzureStorageCredentialsService");
+ CHECK(plan_->setProperty(azure_storage_cred_service_, "Storage Account Name", STORAGE_ACCOUNT_NAME));
+ CHECK(plan_->setProperty(azure_storage_cred_service_, "Credential Configuration Strategy", credential_configuration_strategy_string));
+ CHECK(plan_->setProperty(azure_storage_cred_service_, "Common Storage Account Endpoint Suffix", "core.chinacloudapi.cn"));
+ CHECK(plan_->setProperty(azure_storage_cred_service_, "Managed Identity Client ID", managed_identity_client_id));
+ CHECK(plan_->setProperty(list_azure_blob_storage_, "Azure Storage Credentials Service", "AzureStorageCredentialsService"));
test_controller_.runSession(plan_, true);
auto passed_params = mock_blob_storage_ptr_->getPassedListParams();
CHECK(passed_params.credentials.buildConnectionString().empty());
@@ -234,59 +231,55 @@ TEST_CASE_METHOD(ListAzureBlobStorageTestsFixture, "Test credentials settings",
}
SECTION("Azure Storage Credentials Service overrides properties") {
- auto azure_storage_cred_service = plan_->addController("AzureStorageCredentialsService", "AzureStorageCredentialsService");
- plan_->setProperty(azure_storage_cred_service, "Storage Account Name", STORAGE_ACCOUNT_NAME);
- plan_->setProperty(azure_storage_cred_service, "Storage Account Key", STORAGE_ACCOUNT_KEY);
- plan_->setProperty(list_azure_blob_storage_, "Azure Storage Credentials Service", "AzureStorageCredentialsService");
- plan_->setProperty(list_azure_blob_storage_, "Storage Account Name", STORAGE_ACCOUNT_NAME);
- plan_->setProperty(list_azure_blob_storage_, "Storage Account Key", STORAGE_ACCOUNT_KEY);
- plan_->setProperty(list_azure_blob_storage_, "Connection String", CONNECTION_STRING);
+ CHECK(plan_->setProperty(azure_storage_cred_service_, "Storage Account Name", STORAGE_ACCOUNT_NAME));
+ CHECK(plan_->setProperty(azure_storage_cred_service_, "Storage Account Key", STORAGE_ACCOUNT_KEY));
+ CHECK(plan_->setProperty(list_azure_blob_storage_, "Azure Storage Credentials Service", "AzureStorageCredentialsService"));
+ CHECK(plan_->setProperty(list_azure_blob_storage_, "Storage Account Name", STORAGE_ACCOUNT_NAME));
+ CHECK(plan_->setProperty(list_azure_blob_storage_, "Storage Account Key", STORAGE_ACCOUNT_KEY));
+ CHECK(plan_->setProperty(list_azure_blob_storage_, "Connection String", CONNECTION_STRING));
test_controller_.runSession(plan_, true);
auto passed_params = mock_blob_storage_ptr_->getPassedListParams();
REQUIRE(passed_params.credentials.buildConnectionString() == "AccountName=" + STORAGE_ACCOUNT_NAME + ";AccountKey=" + STORAGE_ACCOUNT_KEY);
}
SECTION("Azure Storage Credentials Service is set with invalid parameters") {
- auto azure_storage_cred_service = plan_->addController("AzureStorageCredentialsService", "AzureStorageCredentialsService");
- plan_->setProperty(azure_storage_cred_service, "Storage Account Name", STORAGE_ACCOUNT_NAME);
- plan_->setProperty(list_azure_blob_storage_, "Azure Storage Credentials Service", "AzureStorageCredentialsService");
- plan_->setProperty(list_azure_blob_storage_, "Storage Account Name", STORAGE_ACCOUNT_NAME);
- plan_->setProperty(list_azure_blob_storage_, "Storage Account Key", STORAGE_ACCOUNT_KEY);
+ CHECK(plan_->setProperty(azure_storage_cred_service_, "Storage Account Name", STORAGE_ACCOUNT_NAME));
+ CHECK(plan_->setProperty(list_azure_blob_storage_, "Azure Storage Credentials Service", "AzureStorageCredentialsService"));
+ CHECK(plan_->setProperty(list_azure_blob_storage_, "Storage Account Name", STORAGE_ACCOUNT_NAME));
+ CHECK(plan_->setProperty(list_azure_blob_storage_, "Storage Account Key", STORAGE_ACCOUNT_KEY));
REQUIRE_THROWS_AS(test_controller_.runSession(plan_, true), minifi::Exception);
}
SECTION("Azure Storage Credentials Service name is invalid") {
- auto azure_storage_cred_service = plan_->addController("AzureStorageCredentialsService", "AzureStorageCredentialsService");
- plan_->setProperty(azure_storage_cred_service, "Storage Account Name", STORAGE_ACCOUNT_NAME);
- plan_->setProperty(azure_storage_cred_service, "Storage Account Key", STORAGE_ACCOUNT_KEY);
- plan_->setProperty(list_azure_blob_storage_, "Azure Storage Credentials Service", "invalid_name");
- plan_->setProperty(list_azure_blob_storage_, "Storage Account Name", STORAGE_ACCOUNT_NAME);
- plan_->setProperty(list_azure_blob_storage_, "Storage Account Key", STORAGE_ACCOUNT_KEY);
+ CHECK(plan_->setProperty(azure_storage_cred_service_, "Storage Account Name", STORAGE_ACCOUNT_NAME));
+ CHECK(plan_->setProperty(azure_storage_cred_service_, "Storage Account Key", STORAGE_ACCOUNT_KEY));
+ CHECK(plan_->setProperty(list_azure_blob_storage_, "Azure Storage Credentials Service", "invalid_name"));
+ CHECK(plan_->setProperty(list_azure_blob_storage_, "Storage Account Name", STORAGE_ACCOUNT_NAME));
+ CHECK(plan_->setProperty(list_azure_blob_storage_, "Storage Account Key", STORAGE_ACCOUNT_KEY));
REQUIRE_THROWS_AS(test_controller_.runSession(plan_, true), minifi::Exception);
}
SECTION("Both SAS Token and Storage Account Key cannot be set in credentials service") {
- auto azure_storage_cred_service = plan_->addController("AzureStorageCredentialsService", "AzureStorageCredentialsService");
- plan_->setProperty(azure_storage_cred_service, "Storage Account Name", STORAGE_ACCOUNT_NAME);
- plan_->setProperty(azure_storage_cred_service, "Storage Account Key", STORAGE_ACCOUNT_KEY);
- plan_->setProperty(azure_storage_cred_service, "SAS Token", SAS_TOKEN);
- plan_->setProperty(list_azure_blob_storage_, "Azure Storage Credentials Service", "AzureStorageCredentialsService");
+ CHECK(plan_->setProperty(azure_storage_cred_service_, "Storage Account Name", STORAGE_ACCOUNT_NAME));
+ CHECK(plan_->setProperty(azure_storage_cred_service_, "Storage Account Key", STORAGE_ACCOUNT_KEY));
+ CHECK(plan_->setProperty(azure_storage_cred_service_, "SAS Token", SAS_TOKEN));
+ CHECK(plan_->setProperty(list_azure_blob_storage_, "Azure Storage Credentials Service", "AzureStorageCredentialsService"));
REQUIRE_THROWS_AS(test_controller_.runSession(plan_, true), minifi::Exception);
}
SECTION("Both SAS Token and Storage Account Key cannot be set in properties") {
- plan_->setProperty(list_azure_blob_storage_, "Storage Account Name", STORAGE_ACCOUNT_NAME);
- plan_->setProperty(list_azure_blob_storage_, "Storage Account Key", STORAGE_ACCOUNT_KEY);
- plan_->setProperty(list_azure_blob_storage_, "SAS Token", SAS_TOKEN);
+ CHECK(plan_->setProperty(list_azure_blob_storage_, "Storage Account Name", STORAGE_ACCOUNT_NAME));
+ CHECK(plan_->setProperty(list_azure_blob_storage_, "Storage Account Key", STORAGE_ACCOUNT_KEY));
+ CHECK(plan_->setProperty(list_azure_blob_storage_, "SAS Token", SAS_TOKEN));
REQUIRE_THROWS_AS(test_controller_.runSession(plan_, true), minifi::Exception);
}
}
TEST_CASE_METHOD(ListAzureBlobStorageTestsFixture, "List all files every time", "[ListAzureBlobStorage]") {
setDefaultCredentials();
- plan_->setProperty(list_azure_blob_storage_, minifi::azure::processors::ListAzureBlobStorage::ContainerName, CONTAINER_NAME);
- plan_->setProperty(list_azure_blob_storage_, minifi::azure::processors::ListAzureBlobStorage::Prefix, PREFIX);
- plan_->setProperty(list_azure_blob_storage_, minifi::azure::processors::ListAzureBlobStorage::ListingStrategy, magic_enum::enum_name(minifi::azure::EntityTracking::none));
+ CHECK(plan_->setProperty(list_azure_blob_storage_, minifi::azure::processors::ListAzureBlobStorage::ContainerName, CONTAINER_NAME));
+ CHECK(plan_->setProperty(list_azure_blob_storage_, minifi::azure::processors::ListAzureBlobStorage::Prefix, PREFIX));
+ CHECK(plan_->setProperty(list_azure_blob_storage_, minifi::azure::processors::ListAzureBlobStorage::ListingStrategy, magic_enum::enum_name(minifi::azure::EntityTracking::none)));
test_controller_.runSession(plan_, true);
using org::apache::nifi::minifi::test::utils::verifyLogLinePresenceInPollTime;
auto run_assertions = [this]() {
@@ -319,9 +312,9 @@ TEST_CASE_METHOD(ListAzureBlobStorageTestsFixture, "List all files every time",
TEST_CASE_METHOD(ListAzureBlobStorageTestsFixture, "Do not list same files the second time when timestamps are tracked", "[ListAzureBlobStorage]") {
setDefaultCredentials();
- plan_->setProperty(list_azure_blob_storage_, minifi::azure::processors::ListAzureBlobStorage::ContainerName, CONTAINER_NAME);
- plan_->setProperty(list_azure_blob_storage_, minifi::azure::processors::ListAzureBlobStorage::Prefix, PREFIX);
- plan_->setProperty(list_azure_blob_storage_, minifi::azure::processors::ListAzureBlobStorage::ListingStrategy, magic_enum::enum_name(minifi::azure::EntityTracking::timestamps));
+ CHECK(plan_->setProperty(list_azure_blob_storage_, minifi::azure::processors::ListAzureBlobStorage::ContainerName, CONTAINER_NAME));
+ CHECK(plan_->setProperty(list_azure_blob_storage_, minifi::azure::processors::ListAzureBlobStorage::Prefix, PREFIX));
+ CHECK(plan_->setProperty(list_azure_blob_storage_, minifi::azure::processors::ListAzureBlobStorage::ListingStrategy, magic_enum::enum_name(minifi::azure::EntityTracking::timestamps)));
test_controller_.runSession(plan_, true);
using org::apache::nifi::minifi::test::utils::verifyLogLinePresenceInPollTime;
auto passed_params = mock_blob_storage_ptr_->getPassedListParams();
diff --git a/extensions/standard-processors/tests/unit/ControllerServiceTests.cpp b/extensions/standard-processors/tests/unit/ControllerServiceTests.cpp
index 705d0fd62..0f981582c 100644
--- a/extensions/standard-processors/tests/unit/ControllerServiceTests.cpp
+++ b/extensions/standard-processors/tests/unit/ControllerServiceTests.cpp
@@ -41,13 +41,13 @@ TEST_CASE("Test ControllerServicesMap", "[cs1]") {
auto service = std::make_shared<core::controller::ControllerService>("", utils::Identifier{}, std::make_unique<MockControllerService>());
auto testNode = std::make_shared<core::controller::StandardControllerServiceNode>(service, "ID", std::make_shared<minifi::ConfigureImpl>());
- map.put("ID", testNode);
+ map.put("ID", testNode, nullptr);
REQUIRE(1 == map.getAllControllerServices().size());
REQUIRE(nullptr != map.get("ID"));
- REQUIRE(false== map.put("", testNode));
- REQUIRE(false== map.put("", nullptr));
+ REQUIRE(false== map.put("", testNode, nullptr));
+ REQUIRE(false== map.put("", nullptr, nullptr));
// ensure the pointer is the same
diff --git a/libminifi/include/core/FlowConfiguration.h b/libminifi/include/core/FlowConfiguration.h
index b79c87bfe..8ae3e5330 100644
--- a/libminifi/include/core/FlowConfiguration.h
+++ b/libminifi/include/core/FlowConfiguration.h
@@ -90,7 +90,7 @@ class FlowConfiguration : public CoreComponentImpl {
static std::unique_ptr<core::ProcessGroup> createSimpleProcessGroup(const std::string &name, const utils::Identifier &uuid, int version);
static std::unique_ptr<core::ProcessGroup> createRemoteProcessGroup(const std::string &name, const utils::Identifier &uuid);
- std::shared_ptr<core::controller::ControllerServiceNode> createControllerService(const std::string &class_name, const std::string &name, const utils::Identifier &uuid);
+ std::shared_ptr<core::controller::ControllerServiceNode> createControllerService(const std::string &class_name, const std::string &name, const utils::Identifier &uuid, ProcessGroup* parent);
// Create Connection
[[nodiscard]] std::unique_ptr<minifi::Connection> createConnection(const std::string &name, const utils::Identifier &uuid) const;
diff --git a/libminifi/include/core/ProcessContextImpl.h b/libminifi/include/core/ProcessContextImpl.h
index 19d9464fe..06511d237 100644
--- a/libminifi/include/core/ProcessContextImpl.h
+++ b/libminifi/include/core/ProcessContextImpl.h
@@ -134,7 +134,7 @@ class ProcessContextImpl : public core::VariableRegistryImpl, public virtual Pro
/* Function to help creating a state storage */
auto create_provider = [&](const std::string& type, const std::unordered_map<std::string, std::string>& extraProperties) -> std::shared_ptr<core::StateStorage> {
- auto new_node = controller_service_provider->createControllerService(type, DefaultStateStorageName);
+ auto new_node = controller_service_provider->createControllerService(type, DefaultStateStorageName, nullptr, std::nullopt);
if (new_node == nullptr) { return nullptr; }
new_node->initialize();
auto storage = new_node->getControllerServiceImplementation();
diff --git a/libminifi/include/core/controller/ControllerServiceNodeMap.h b/libminifi/include/core/controller/ControllerServiceNodeMap.h
index 27a47e104..1ee21a50f 100644
--- a/libminifi/include/core/controller/ControllerServiceNodeMap.h
+++ b/libminifi/include/core/controller/ControllerServiceNodeMap.h
@@ -43,18 +43,25 @@ class ControllerServiceNodeMap {
ControllerServiceNode* get(const std::string &id) const;
ControllerServiceNode* get(const std::string &id, const utils::Identifier &processor_or_controller_uuid) const;
- bool put(const std::string &id, const std::shared_ptr<ControllerServiceNode> &serviceNode);
- bool put(const std::string &id, ProcessGroup* process_group);
+ bool put(std::string id, std::shared_ptr<ControllerServiceNode> controller_service_node, ProcessGroup* parent_group);
+
+ bool registerAlternativeKey(std::string primary_key, std::string alternative_key);
void clear();
std::vector<std::shared_ptr<ControllerServiceNode>> getAllControllerServices() const;
protected:
mutable std::mutex mutex_;
- // Map of controller service id to the controller service node
- std::map<std::string, std::shared_ptr<ControllerServiceNode>> controller_service_nodes_;
- // Map of controller service id to the process group that contains it
- std::map<std::string, gsl::not_null<ProcessGroup*>> process_groups_;
+
+ struct ServiceEntry {
+ std::shared_ptr<ControllerServiceNode> controller_service_node;
+ ProcessGroup* parent_group;
+ };
+
+ const ServiceEntry* getEntry(std::string_view primary_key, const std::scoped_lock<std::mutex>& mutex) const;
+
+ std::map<std::string, ServiceEntry, std::less<>> services_;
+ std::map<std::string, std::string, std::less<>> alternative_keys;
};
} // namespace controller
diff --git a/libminifi/include/core/controller/ControllerServiceProvider.h b/libminifi/include/core/controller/ControllerServiceProvider.h
index 72b461052..ccc59b77f 100644
--- a/libminifi/include/core/controller/ControllerServiceProvider.h
+++ b/libminifi/include/core/controller/ControllerServiceProvider.h
@@ -68,7 +68,10 @@ class ControllerServiceProvider : public CoreComponentImpl, public ConfigurableC
return controller_map_->get(id, processor_or_controller_uuid);
}
- virtual std::shared_ptr<ControllerServiceNode> createControllerService(const std::string &type, const std::string &id) = 0;
+ virtual std::shared_ptr<ControllerServiceNode> createControllerService(const std::string &type,
+ const std::string &id,
+ ProcessGroup* parent,
+ const std::optional<std::string>& alternative_key) = 0;
virtual void clearControllerServices() = 0;
@@ -83,7 +86,10 @@ class ControllerServiceProvider : public CoreComponentImpl, public ConfigurableC
std::shared_ptr<ControllerService> getControllerService(const std::string &identifier) const override;
std::shared_ptr<ControllerService> getControllerService(const std::string &identifier, const utils::Identifier &processor_uuid) const override;
- virtual void putControllerServiceNode(const std::string& identifier, const std::shared_ptr<ControllerServiceNode>& controller_service_node, ProcessGroup* process_group);
+ virtual void putControllerServiceNode(const std::string& primary_key,
+ const std::shared_ptr<ControllerServiceNode>& controller_service_node,
+ ProcessGroup* process_group,
+ const std::optional<std::string>& alternative_key);
bool supportsDynamicProperties() const final {
return false;
diff --git a/libminifi/include/core/controller/ForwardingControllerServiceProvider.h b/libminifi/include/core/controller/ForwardingControllerServiceProvider.h
index 45cce2aef..e331bd8e3 100644
--- a/libminifi/include/core/controller/ForwardingControllerServiceProvider.h
+++ b/libminifi/include/core/controller/ForwardingControllerServiceProvider.h
@@ -31,8 +31,8 @@ class ForwardingControllerServiceProvider : public ControllerServiceProvider {
public:
using ControllerServiceProvider::ControllerServiceProvider;
- std::shared_ptr<ControllerServiceNode> createControllerService(const std::string &type, const std::string &id) override {
- return controller_service_provider_impl_->createControllerService(type, id);
+ std::shared_ptr<ControllerServiceNode> createControllerService(const std::string &type, const std::string &id, ProcessGroup* parent, const std::optional<std::string>& alternative_key) override {
+ return controller_service_provider_impl_->createControllerService(type, id, parent, alternative_key);
}
ControllerServiceNode* getControllerServiceNode(const std::string &id) const override {
diff --git a/libminifi/include/core/controller/StandardControllerServiceProvider.h b/libminifi/include/core/controller/StandardControllerServiceProvider.h
index 2fe6c95c3..9136522ee 100644
--- a/libminifi/include/core/controller/StandardControllerServiceProvider.h
+++ b/libminifi/include/core/controller/StandardControllerServiceProvider.h
@@ -48,7 +48,10 @@ class StandardControllerServiceProvider : public ControllerServiceProvider {
stopEnableRetryThread();
}
- std::shared_ptr<ControllerServiceNode> createControllerService(const std::string& type, const std::string& id) override;
+ std::shared_ptr<ControllerServiceNode> createControllerService(const std::string& type,
+ const std::string& id,
+ ProcessGroup* parent_group,
+ const std::optional<std::string>& alternative_key) override;
void enableAllControllerServices() override;
void disableAllControllerServices() override;
void clearControllerServices() override;
diff --git a/libminifi/src/core/FlowConfiguration.cpp b/libminifi/src/core/FlowConfiguration.cpp
index 11f58bd10..aae42ca4e 100644
--- a/libminifi/src/core/FlowConfiguration.cpp
+++ b/libminifi/src/core/FlowConfiguration.cpp
@@ -195,8 +195,8 @@ std::unique_ptr<minifi::Connection> FlowConfiguration::createConnection(const st
}
std::shared_ptr<core::controller::ControllerServiceNode> FlowConfiguration::createControllerService(const std::string &class_name, const std::string &name,
- const utils::Identifier& uuid) {
- std::shared_ptr<core::controller::ControllerServiceNode> controllerServicesNode = service_provider_->createControllerService(class_name, name);
+ const utils::Identifier& uuid, ProcessGroup* parent) {
+ std::shared_ptr<core::controller::ControllerServiceNode> controllerServicesNode = service_provider_->createControllerService(class_name, name, parent, uuid.to_string());
if (nullptr != controllerServicesNode)
controllerServicesNode->setUUID(uuid);
return controllerServicesNode;
diff --git a/libminifi/src/core/ProcessGroup.cpp b/libminifi/src/core/ProcessGroup.cpp
index d8e8ea066..c88709e68 100644
--- a/libminifi/src/core/ProcessGroup.cpp
+++ b/libminifi/src/core/ProcessGroup.cpp
@@ -279,7 +279,7 @@ Processor* ProcessGroup::findProcessorByName(const std::string &processorName, T
}
void ProcessGroup::addControllerService(const std::string &nodeId, const std::shared_ptr<core::controller::ControllerServiceNode> &node) {
- controller_service_map_.put(nodeId, node);
+ controller_service_map_.put(nodeId, node, this);
}
core::controller::ControllerServiceNode* ProcessGroup::findControllerService(const std::string &nodeId, Traverse traverse) const {
diff --git a/libminifi/src/core/controller/ControllerServiceNodeMap.cpp b/libminifi/src/core/controller/ControllerServiceNodeMap.cpp
index 4ad00dd4f..f66316e39 100644
--- a/libminifi/src/core/controller/ControllerServiceNodeMap.cpp
+++ b/libminifi/src/core/controller/ControllerServiceNodeMap.cpp
@@ -17,81 +17,93 @@
*/
#include "core/controller/ControllerServiceNodeMap.h"
+
+#include <ranges>
+
#include "core/ProcessGroup.h"
namespace org::apache::nifi::minifi::core::controller {
ControllerServiceNode* ControllerServiceNodeMap::get(const std::string &id) const {
- std::lock_guard<std::mutex> lock(mutex_);
- auto exists = controller_service_nodes_.find(id);
- if (exists != controller_service_nodes_.end())
- return exists->second.get();
- else
- return nullptr;
+ const std::scoped_lock lock(mutex_);
+ if (const auto entry = getEntry(id, lock)) {
+ return entry->controller_service_node.get();
+ }
+ return nullptr;
}
ControllerServiceNode* ControllerServiceNodeMap::get(const std::string &id, const utils::Identifier& processor_or_controller_uuid) const {
- std::lock_guard<std::mutex> lock(mutex_);
- ControllerServiceNode* controller = nullptr;
- auto exists = controller_service_nodes_.find(id);
- if (exists != controller_service_nodes_.end()) {
- controller = exists->second.get();
- } else {
+ const std::scoped_lock lock(mutex_);
+ const auto entry = getEntry(id, lock);
+ if (!entry || !entry->parent_group) {
return nullptr;
}
- auto process_group_of_controller_exists = process_groups_.find(id);
- ProcessGroup* process_group = nullptr;
- if (process_group_of_controller_exists != process_groups_.end()) {
- process_group = process_group_of_controller_exists->second;
- } else {
- return nullptr;
- }
- if (process_group->findProcessorById(processor_or_controller_uuid, ProcessGroup::Traverse::IncludeChildren)) {
- return controller;
+ if (entry->parent_group->findProcessorById(processor_or_controller_uuid, ProcessGroup::Traverse::IncludeChildren)) {
+ return entry->controller_service_node.get();
}
- if (process_group->findControllerService(processor_or_controller_uuid.to_string(), ProcessGroup::Traverse::IncludeChildren)) {
- return controller;
+ if (entry->parent_group->findControllerService(processor_or_controller_uuid.to_string(), ProcessGroup::Traverse::IncludeChildren)) {
+ return entry->controller_service_node.get();
}
return nullptr;
}
-bool ControllerServiceNodeMap::put(const std::string &id, const std::shared_ptr<ControllerServiceNode> &serviceNode) {
- if (id.empty() || serviceNode == nullptr)
+bool ControllerServiceNodeMap::put(std::string id, std::shared_ptr<ControllerServiceNode> controller_service_node,
+ ProcessGroup* parent_group) {
+ std::scoped_lock lock(mutex_);
+ if (id.empty() || controller_service_node == nullptr || alternative_keys.contains(id)) {
return false;
- std::lock_guard<std::mutex> lock(mutex_);
- controller_service_nodes_[id] = serviceNode;
- return true;
+ }
+ auto [_it, success] = services_.emplace(std::move(id), ServiceEntry{.controller_service_node = std::move(controller_service_node), .parent_group = parent_group});
+ return success;
}
-bool ControllerServiceNodeMap::put(const std::string &id, ProcessGroup* process_group) {
- if (id.empty() || process_group == nullptr)
- return false;
- std::lock_guard<std::mutex> lock(mutex_);
- process_groups_.emplace(id, gsl::make_not_null(process_group));
- return true;
-}
void ControllerServiceNodeMap::clear() {
- std::lock_guard<std::mutex> lock(mutex_);
- for (const auto& [id, node] : controller_service_nodes_) {
- node->disable();
+ std::scoped_lock lock(mutex_);
+ for (const auto& node: services_ | std::views::values) {
+ node.controller_service_node->disable();
}
- controller_service_nodes_.clear();
- process_groups_.clear();
+ services_.clear();
+ alternative_keys.clear();
}
std::vector<std::shared_ptr<ControllerServiceNode>> ControllerServiceNodeMap::getAllControllerServices() const {
- std::lock_guard<std::mutex> lock(mutex_);
+ std::scoped_lock lock(mutex_);
std::vector<std::shared_ptr<ControllerServiceNode>> services;
- services.reserve(controller_service_nodes_.size());
- for (const auto& [id, node] : controller_service_nodes_) {
- services.push_back(node);
+ services.reserve(services_.size());
+ for (const auto& [controller_service_node, _parent_group]: services_ | std::views::values) {
+ services.push_back(controller_service_node);
}
return services;
}
+const ControllerServiceNodeMap::ServiceEntry* ControllerServiceNodeMap::getEntry(const std::string_view key, const std::scoped_lock<std::mutex>&) const {
+ const auto it = services_.find(key);
+ if (it != services_.end()) {
+ return &it->second;
+ }
+ const auto primary_key_it = alternative_keys.find(key);
+ if (primary_key_it == alternative_keys.end()) {
+ return nullptr;
+ }
+ const auto it_from_primary = services_.find(primary_key_it->second);
+ gsl_Expects(it_from_primary != services_.end());
+ return &it_from_primary->second;
+}
+
+
+bool ControllerServiceNodeMap::registerAlternativeKey(std::string primary_key, std::string alternative_key) {
+ std::scoped_lock lock(mutex_);
+ if (!services_.contains(primary_key) || services_.contains(alternative_key) || alternative_keys.contains(alternative_key)) {
+ return false;
+ }
+
+ auto [_it, success] = alternative_keys.emplace(std::move(alternative_key), std::move(primary_key));
+ return success;
+}
+
} // namespace org::apache::nifi::minifi::core::controller
diff --git a/libminifi/src/core/controller/ControllerServiceProvider.cpp b/libminifi/src/core/controller/ControllerServiceProvider.cpp
index 288929ccb..28e60c22b 100644
--- a/libminifi/src/core/controller/ControllerServiceProvider.cpp
+++ b/libminifi/src/core/controller/ControllerServiceProvider.cpp
@@ -43,10 +43,15 @@ std::shared_ptr<ControllerService> ControllerServiceProvider::getControllerServi
}
}
-void ControllerServiceProvider::putControllerServiceNode(const std::string& identifier, const std::shared_ptr<ControllerServiceNode>& controller_service_node, ProcessGroup* process_group) {
+void ControllerServiceProvider::putControllerServiceNode(const std::string& primary_key,
+ const std::shared_ptr<ControllerServiceNode>& controller_service_node,
+ ProcessGroup* process_group,
+ const std::optional<std::string>& alternative_key) {
gsl_Expects(controller_map_);
- controller_map_->put(identifier, controller_service_node);
- controller_map_->put(identifier, process_group);
+ controller_map_->put(primary_key, controller_service_node, process_group);
+ if (alternative_key) {
+ controller_map_->registerAlternativeKey(primary_key, *alternative_key);
+ }
}
} // namespace org::apache::nifi::minifi::core::controller
diff --git a/libminifi/src/core/controller/StandardControllerServiceProvider.cpp b/libminifi/src/core/controller/StandardControllerServiceProvider.cpp
index 28cb21cde..d93c4cd6b 100644
--- a/libminifi/src/core/controller/StandardControllerServiceProvider.cpp
+++ b/libminifi/src/core/controller/StandardControllerServiceProvider.cpp
@@ -24,7 +24,10 @@ using namespace std::literals::chrono_literals;
namespace org::apache::nifi::minifi::core::controller {
-std::shared_ptr<ControllerServiceNode> StandardControllerServiceProvider::createControllerService(const std::string& type, const std::string& id) {
+std::shared_ptr<ControllerServiceNode> StandardControllerServiceProvider::createControllerService(const std::string& type,
+ const std::string& id,
+ ProcessGroup* parent_group,
+ const std::optional<std::string>& alternative_key) {
std::shared_ptr<ControllerService> new_controller_service = extension_loader_.instantiate<ControllerService>(type, id);
if (!new_controller_service) {
@@ -35,7 +38,11 @@ std::shared_ptr<ControllerServiceNode> StandardControllerServiceProvider::create
sharedFromThis<ControllerServiceProvider>(), id,
configuration_);
- controller_map_->put(id, new_service_node);
+ controller_map_->put(id, new_service_node, parent_group);
+ if (alternative_key) {
+ controller_map_->registerAlternativeKey(id, *alternative_key);
+ }
+
return new_service_node;
}
diff --git a/libminifi/src/core/flow/StructuredConfiguration.cpp b/libminifi/src/core/flow/StructuredConfiguration.cpp
index db738846a..2a364ce86 100644
--- a/libminifi/src/core/flow/StructuredConfiguration.cpp
+++ b/libminifi/src/core/flow/StructuredConfiguration.cpp
@@ -656,7 +656,7 @@ void StructuredConfiguration::parseControllerServices(const Node& controller_ser
utils::Identifier uuid;
uuid = id;
- std::shared_ptr<core::controller::ControllerServiceNode> controller_service_node = createControllerService(type, name, uuid);
+ std::shared_ptr<core::controller::ControllerServiceNode> controller_service_node = createControllerService(type, name, uuid, parent_group);
if (nullptr != controller_service_node) {
logger_->log_debug("Created Controller Service with UUID {} and name {}", id, name);
controller_service_node->initialize();
@@ -668,9 +668,6 @@ void StructuredConfiguration::parseControllerServices(const Node& controller_ser
}
}
- service_provider_->putControllerServiceNode(id, controller_service_node, parent_group);
- service_provider_->putControllerServiceNode(name, controller_service_node, parent_group);
-
parent_group->addControllerService(controller_service_node->getName(), controller_service_node);
parent_group->addControllerService(controller_service_node->getUUIDStr(), controller_service_node);
} else {
diff --git a/libminifi/test/libtest/unit/TestBase.cpp b/libminifi/test/libtest/unit/TestBase.cpp
index 0cf593b34..e205ba4a6 100644
--- a/libminifi/test/libtest/unit/TestBase.cpp
+++ b/libminifi/test/libtest/unit/TestBase.cpp
@@ -367,7 +367,7 @@ std::shared_ptr<minifi::core::controller::ControllerServiceNode> TestPlan::addCo
minifi::utils::Identifier uuid = minifi::utils::IdGenerator::getIdGenerator()->generate();
std::shared_ptr<minifi::core::controller::ControllerServiceNode> controller_service_node =
- controller_services_provider_->createControllerService(controller_name, name);
+ controller_services_provider_->createControllerService(controller_name, name, root_process_group_.get(), uuid.to_string());
if (controller_service_node == nullptr) {
return nullptr;
}
@@ -378,9 +378,6 @@ std::shared_ptr<minifi::core::controller::ControllerServiceNode> TestPlan::addCo
controller_service_node->setUUID(uuid);
controller_service_node->setName(name);
- controller_services_provider_->putControllerServiceNode(uuid.to_string(), controller_service_node, root_process_group_.get());
- controller_services_provider_->putControllerServiceNode(name, controller_service_node, root_process_group_.get());
-
root_process_group_->addControllerService(uuid.to_string(), controller_service_node);
return controller_service_node;
diff --git a/libminifi/test/unit/ProcessorConfigUtilsTests.cpp b/libminifi/test/unit/ProcessorConfigUtilsTests.cpp
index 298faa228..71004d240 100644
--- a/libminifi/test/unit/ProcessorConfigUtilsTests.cpp
+++ b/libminifi/test/unit/ProcessorConfigUtilsTests.cpp
@@ -111,7 +111,7 @@ class WrongTestControllerService : public TestControllerService {};
class TestControllerServiceProvider : public controller::ControllerServiceProvider {
public:
using ControllerServiceProvider::ControllerServiceProvider;
- std::shared_ptr<controller::ControllerServiceNode> createControllerService(const std::string&, const std::string&) override { return nullptr; }
+ std::shared_ptr<controller::ControllerServiceNode> createControllerService(const std::string&, const std::string&, ProcessGroup*, const std::optional<std::string>&) override { return nullptr; }
void clearControllerServices() override {}
void enableAllControllerServices() override {}
void disableAllControllerServices() override {}
(nifi-minifi-cpp) 03/03: MINIFICPP-2715 - Use symbols to check api compatibility
Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
martinzink pushed a commit to branch controller_c_api_requirements
in repository https://gitbox.apache.org/repos/asf/nifi-minifi-cpp.git
commit 233e9b6baf26a721ddf8cdc9bd8db577f9778f93
Author: Adam Debreceni <ad...@apache.org>
AuthorDate: Thu Feb 12 16:37:05 2026 +0100
MINIFICPP-2715 - Use symbols to check api compatibility
Closes #2105
Signed-off-by: Martin Zink <ma...@apache.org>
---
Extensions.md | 4 +-
cmake/Extensions.cmake | 23 +----
.../SFTPLoader.cpp => ExtensionInitializer.cpp} | 19 +---
.../llamacpp/processors/ExtensionInitializer.cpp | 4 +-
extensions/opencv/CMakeLists.txt | 1 +
extensions/opencv/OpenCVLoader.cpp | 2 +-
extensions/python/CMakeLists.txt | 2 +
.../python/pythonlibloader/PythonLibLoader.cpp | 2 +-
extensions/python/pythonloader/PyProcLoader.cpp | 2 +-
extensions/sftp/CMakeLists.txt | 1 +
extensions/sftp/SFTPLoader.cpp | 2 +-
libminifi/include/core/extension/Utils.h | 26 -----
libminifi/src/core/extension/Extension.cpp | 2 +-
libminifi/src/core/extension/ExtensionManager.cpp | 8 --
libminifi/src/core/extension/Utils.cpp | 65 -------------
libminifi/src/minifi-c.cpp | 55 ++++++-----
libminifi/test/unit/ExtensionVerificationTests.cpp | 107 ---------------------
minifi-api/CMakeLists.txt | 1 +
minifi-api/include/minifi-c/minifi-c.h | 16 ++-
minifi-api/minifi-c-api.def | 4 +-
20 files changed, 69 insertions(+), 277 deletions(-)
diff --git a/Extensions.md b/Extensions.md
index 7d3fd5392..3a82e212f 100644
--- a/Extensions.md
+++ b/Extensions.md
@@ -33,10 +33,10 @@ REGISTER_RESOURCE(RESTSender, DescriptionOnly);
```
Some extensions (e.g. `OpenCVExtension`) require initialization before use.
-You need to define an `InitExtension` function of type `MinifiExtension*(MinifiConfig*)` to be called.
+You need to define an `MinifiInitExtension` function of type `MinifiExtension*(MinifiConfig*)` to be called.
```C++
-extern "C" MinifiExtension* InitExtension(MinifiConfig* /*config*/) {
+extern "C" MinifiExtension* MinifiInitExtension(MinifiConfig* /*config*/) {
const auto success = org::apache::nifi::minifi::utils::Environment::setEnvironmentVariable("OPENCV_FFMPEG_CAPTURE_OPTIONS", "rtsp_transport;udp", false /*overwrite*/);
if (!success) {
return nullptr;
diff --git a/cmake/Extensions.cmake b/cmake/Extensions.cmake
index 5786967a8..6ea93f1cb 100644
--- a/cmake/Extensions.cmake
+++ b/cmake/Extensions.cmake
@@ -22,29 +22,14 @@ define_property(GLOBAL PROPERTY EXTENSION-OPTIONS
set_property(GLOBAL PROPERTY EXTENSION-OPTIONS "")
-set(extension-build-info-file "${CMAKE_CURRENT_BINARY_DIR}/ExtensionBuildInfo.cpp")
-file(GENERATE OUTPUT ${extension-build-info-file}
- CONTENT "\
- #include \"minifi-cpp/utils/Export.h\"\n\
- #ifdef BUILD_ID_VARIABLE_NAME\n\
- EXTENSIONAPI extern const char* const BUILD_ID_VARIABLE_NAME = \"__EXTENSION_BUILD_IDENTIFIER_BEGIN__${BUILD_IDENTIFIER}__EXTENSION_BUILD_IDENTIFIER_END__\";\n\
- #else\n\
- static_assert(false, \"BUILD_ID_VARIABLE_NAME is not defined\");\n\
- #endif\n")
-
-function(get_build_id_variable_name extension-name output)
- string(REPLACE "-" "_" result ${extension-name})
- string(APPEND result "_build_identifier")
- set("${output}" "${result}" PARENT_SCOPE)
-endfunction()
-
macro(register_extension extension-name extension-display-name extension-guard description)
set(${extension-guard} ${extension-name} PARENT_SCOPE)
get_property(extensions GLOBAL PROPERTY EXTENSION-OPTIONS)
set_property(GLOBAL APPEND PROPERTY EXTENSION-OPTIONS ${extension-name})
- get_build_id_variable_name(${extension-name} build-id-variable-name)
- set_source_files_properties(${extension-build-info-file} PROPERTIES GENERATED TRUE)
- target_sources(${extension-name} PRIVATE ${extension-build-info-file})
+ get_target_property(has_custom_initializer ${extension-name} HAS_CUSTOM_INITIALIZER)
+ if (NOT has_custom_initializer)
+ target_sources(${extension-name} PRIVATE ${CMAKE_SOURCE_DIR}/extensions/ExtensionInitializer.cpp)
+ endif()
target_compile_definitions(${extension-name}
PRIVATE "MODULE_NAME=${extension-name}"
PRIVATE "BUILD_ID_VARIABLE_NAME=${build-id-variable-name}")
diff --git a/extensions/sftp/SFTPLoader.cpp b/extensions/ExtensionInitializer.cpp
similarity index 77%
copy from extensions/sftp/SFTPLoader.cpp
copy to extensions/ExtensionInitializer.cpp
index 8a67842de..3caaaeed0 100644
--- a/extensions/sftp/SFTPLoader.cpp
+++ b/extensions/ExtensionInitializer.cpp
@@ -15,31 +15,18 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
-#include "minifi-cpp/agent/agent_version.h"
-#include "minifi-cpp/properties/Configure.h"
-#include "client/SFTPClient.h"
#include "minifi-c/minifi-c.h"
#include "utils/ExtensionInitUtils.h"
+#include "minifi-cpp/agent/agent_version.h"
#include "core/Resource.h"
namespace minifi = org::apache::nifi::minifi;
-extern "C" MinifiExtension* InitExtension(MinifiConfig* /*config*/) {
- if (libssh2_init(0) != 0) {
- return nullptr;
- }
- if (curl_global_init(CURL_GLOBAL_DEFAULT) != CURLE_OK) {
- libssh2_exit();
- return nullptr;
- }
+extern "C" MinifiExtension* MinifiInitExtension(MinifiConfig* /*config*/) {
MinifiExtensionCreateInfo ext_create_info{
.name = minifi::utils::toStringView(MAKESTRING(MODULE_NAME)),
.version = minifi::utils::toStringView(minifi::AgentBuild::VERSION),
- .deinit = [] (void* /*user_data*/) {
- curl_global_cleanup();
- libssh2_exit();
- },
+ .deinit = nullptr,
.user_data = nullptr,
.processors_count = 0,
.processors_ptr = nullptr
diff --git a/extensions/llamacpp/processors/ExtensionInitializer.cpp b/extensions/llamacpp/processors/ExtensionInitializer.cpp
index 40508955c..b90b8b133 100644
--- a/extensions/llamacpp/processors/ExtensionInitializer.cpp
+++ b/extensions/llamacpp/processors/ExtensionInitializer.cpp
@@ -24,7 +24,7 @@
namespace minifi = org::apache::nifi::minifi;
-extern "C" MinifiExtension* InitExtension(MinifiConfig* /*config*/) {
+extern "C" MinifiExtension* MinifiInitExtension(MinifiConfig* /*config*/) {
MinifiExtension* extension = nullptr;
minifi::api::core::useProcessorClassDescription<minifi::extensions::llamacpp::processors::RunLlamaCppInference>([&] (const MinifiProcessorClassDefinition& description) {
MinifiExtensionCreateInfo ext_create_info{
@@ -39,5 +39,3 @@ extern "C" MinifiExtension* InitExtension(MinifiConfig* /*config*/) {
});
return extension;
}
-
-extern const char* const MINIFI_API_VERSION_TAG_var = MINIFI_API_VERSION_TAG;
diff --git a/extensions/opencv/CMakeLists.txt b/extensions/opencv/CMakeLists.txt
index ed812c1a6..3c80e3efd 100644
--- a/extensions/opencv/CMakeLists.txt
+++ b/extensions/opencv/CMakeLists.txt
@@ -29,6 +29,7 @@ include(${CMAKE_SOURCE_DIR}/extensions/ExtensionHeader.txt)
file(GLOB SOURCES "*.cpp")
add_minifi_library(minifi-opencv SHARED ${SOURCES})
+set_target_properties(minifi-opencv PROPERTIES HAS_CUSTOM_INITIALIZER TRUE)
target_link_libraries(minifi-opencv ${LIBMINIFI})
target_link_libraries(minifi-opencv OPENCV::libopencv)
diff --git a/extensions/opencv/OpenCVLoader.cpp b/extensions/opencv/OpenCVLoader.cpp
index 79a437f75..3f91395c4 100644
--- a/extensions/opencv/OpenCVLoader.cpp
+++ b/extensions/opencv/OpenCVLoader.cpp
@@ -24,7 +24,7 @@
namespace minifi = org::apache::nifi::minifi;
-extern "C" MinifiExtension* InitExtension(MinifiConfig* /*config*/) {
+extern "C" MinifiExtension* MinifiInitExtension(MinifiConfig* /*config*/) {
// By default in OpenCV, ffmpeg capture is hardcoded to use TCP and this is a workaround
// also if UDP timeout, ffmpeg will retry with TCP
// Note:
diff --git a/extensions/python/CMakeLists.txt b/extensions/python/CMakeLists.txt
index ac3f5fe57..34b1df673 100644
--- a/extensions/python/CMakeLists.txt
+++ b/extensions/python/CMakeLists.txt
@@ -25,12 +25,14 @@ include(${CMAKE_SOURCE_DIR}/extensions/ExtensionHeader.txt)
if (NOT WIN32)
add_minifi_library(minifi-python-lib-loader-extension SHARED pythonlibloader/PythonLibLoader.cpp)
+ set_target_properties(minifi-python-lib-loader-extension PROPERTIES HAS_CUSTOM_INITIALIZER TRUE)
target_link_libraries(minifi-python-lib-loader-extension PRIVATE ${LIBMINIFI})
endif()
file(GLOB SOURCES "*.cpp" "types/*.cpp" "pythonloader/PyProcLoader.cpp")
add_minifi_library(minifi-python-script-extension SHARED ${SOURCES})
+set_target_properties(minifi-python-script-extension PROPERTIES HAS_CUSTOM_INITIALIZER TRUE)
target_link_libraries(minifi-python-script-extension PRIVATE ${LIBMINIFI} Threads::Threads)
diff --git a/extensions/python/pythonlibloader/PythonLibLoader.cpp b/extensions/python/pythonlibloader/PythonLibLoader.cpp
index 398322f8f..cdf0356b7 100644
--- a/extensions/python/pythonlibloader/PythonLibLoader.cpp
+++ b/extensions/python/pythonlibloader/PythonLibLoader.cpp
@@ -98,7 +98,7 @@ class PythonLibLoader {
std::shared_ptr<minifi::core::logging::Logger> logger_ = minifi::core::logging::LoggerFactory<PythonLibLoader>::getLogger();
};
-extern "C" MinifiExtension* InitExtension(MinifiConfig* config) {
+extern "C" MinifiExtension* MinifiInitExtension(MinifiConfig* config) {
static PythonLibLoader python_lib_loader([&] (std::string_view key) -> std::optional<std::string> {
std::optional<std::string> result;
MinifiConfigGet(config, minifi::utils::toStringView(key), [] (void* user_data, MinifiStringView value) {
diff --git a/extensions/python/pythonloader/PyProcLoader.cpp b/extensions/python/pythonloader/PyProcLoader.cpp
index 3778f15ec..55ad4ebef 100644
--- a/extensions/python/pythonloader/PyProcLoader.cpp
+++ b/extensions/python/pythonloader/PyProcLoader.cpp
@@ -33,7 +33,7 @@ static minifi::extensions::python::PythonCreator& getPythonCreator() {
// the symbols of the python library
extern "C" const int LOAD_MODULE_AS_GLOBAL = 1;
-extern "C" MinifiExtension* InitExtension(MinifiConfig* config) {
+extern "C" MinifiExtension* MinifiInitExtension(MinifiConfig* config) {
getPythonCreator().configure([&] (std::string_view key) -> std::optional<std::string> {
std::optional<std::string> result;
MinifiConfigGet(config, minifi::utils::toStringView(key), [] (void* user_data, MinifiStringView value) {
diff --git a/extensions/sftp/CMakeLists.txt b/extensions/sftp/CMakeLists.txt
index c5c1cb6a7..7200b41ba 100644
--- a/extensions/sftp/CMakeLists.txt
+++ b/extensions/sftp/CMakeLists.txt
@@ -31,6 +31,7 @@ include_directories(client processors)
file(GLOB SOURCES "*.cpp" "client/*.cpp" "processors/*.cpp")
add_minifi_library(minifi-sftp SHARED ${SOURCES})
+set_target_properties(minifi-sftp PROPERTIES HAS_CUSTOM_INITIALIZER TRUE)
target_link_libraries(minifi-sftp ${LIBMINIFI} Threads::Threads)
target_link_libraries(minifi-sftp libssh2 RapidJSON)
diff --git a/extensions/sftp/SFTPLoader.cpp b/extensions/sftp/SFTPLoader.cpp
index 8a67842de..bb23e9998 100644
--- a/extensions/sftp/SFTPLoader.cpp
+++ b/extensions/sftp/SFTPLoader.cpp
@@ -25,7 +25,7 @@
namespace minifi = org::apache::nifi::minifi;
-extern "C" MinifiExtension* InitExtension(MinifiConfig* /*config*/) {
+extern "C" MinifiExtension* MinifiInitExtension(MinifiConfig* /*config*/) {
if (libssh2_init(0) != 0) {
return nullptr;
}
diff --git a/libminifi/include/core/extension/Utils.h b/libminifi/include/core/extension/Utils.h
index 520827193..c983a25f9 100644
--- a/libminifi/include/core/extension/Utils.h
+++ b/libminifi/include/core/extension/Utils.h
@@ -44,37 +44,11 @@ class Timer {
Callback cb_;
};
-enum LibraryType {
- Cpp,
- CApi,
- Invalid
-};
-
struct LibraryDescriptor {
std::string name;
std::filesystem::path dir;
std::string filename;
-
- [[nodiscard]] bool verify_as_cpp_extension() const;
-
- [[nodiscard]] bool verify_as_c_extension(const std::shared_ptr<logging::Logger>& logger) const;
-
- [[nodiscard]]
- LibraryType verify(const std::shared_ptr<logging::Logger>& logger) const {
- const auto path = getFullPath();
- const Timer timer{[&](const std::chrono::milliseconds elapsed) {
- logger->log_debug("Verification for '{}' took {}", path, elapsed);
- }};
- if (verify_as_cpp_extension()) {
- return Cpp;
- }
- if (verify_as_c_extension(logger)) {
- return CApi;
- }
- return Invalid;
- }
-
[[nodiscard]]
std::filesystem::path getFullPath() const {
return dir / filename;
diff --git a/libminifi/src/core/extension/Extension.cpp b/libminifi/src/core/extension/Extension.cpp
index ac3675b57..268cc2ff4 100644
--- a/libminifi/src/core/extension/Extension.cpp
+++ b/libminifi/src/core/extension/Extension.cpp
@@ -94,7 +94,7 @@ Extension::~Extension() {
bool Extension::initialize(const std::shared_ptr<minifi::Configure>& configure) {
logger_->log_trace("Initializing extension '{}'", name_);
- if (void* init_symbol_ptr = findSymbol("InitExtension")) {
+ if (void* init_symbol_ptr = findSymbol("MinifiInitExtension")) {
logger_->log_debug("Found custom initializer for '{}'", name_);
auto init_fn = reinterpret_cast<MinifiExtension*(*)(MinifiConfig*)>(init_symbol_ptr);
auto config_handle = reinterpret_cast<MinifiConfig*>(configure.get());
diff --git a/libminifi/src/core/extension/ExtensionManager.cpp b/libminifi/src/core/extension/ExtensionManager.cpp
index 0d60e7c6b..98736afcc 100644
--- a/libminifi/src/core/extension/ExtensionManager.cpp
+++ b/libminifi/src/core/extension/ExtensionManager.cpp
@@ -57,14 +57,6 @@ ExtensionManager::ExtensionManager(const std::shared_ptr<Configure>& config): lo
if (!library) {
continue;
}
- const auto library_type = library->verify(logger_);
- if (library_type == internal::Invalid) {
- logger_->log_warn("Skipping library '{}' at '{}': failed verification, different build?",
- library->name, library->getFullPath());
- continue;
- }
-
- logger_->log_trace("Verified library {} at {} as {} extension", library->name, library->getFullPath(), magic_enum::enum_name(library_type));
auto extension = std::make_unique<Extension>(library->name, library->getFullPath());
if (!extension->load()) {
// error already logged by method
diff --git a/libminifi/src/core/extension/Utils.cpp b/libminifi/src/core/extension/Utils.cpp
deleted file mode 100644
index 38e90ac15..000000000
--- a/libminifi/src/core/extension/Utils.cpp
+++ /dev/null
@@ -1,65 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "core/extension/Utils.h"
-#include "minifi-c/minifi-c.h"
-#include "minifi-cpp/agent/agent_version.h"
-#include "utils/RegexUtils.h"
-
-namespace org::apache::nifi::minifi::core::extension::internal {
-
-[[nodiscard]] bool LibraryDescriptor::verify_as_cpp_extension() const {
- const auto path = getFullPath();
- if (!std::filesystem::exists(path)) {
- throw std::runtime_error{"File not found: " + path.string()};
- }
- const std::string_view begin_marker = "__EXTENSION_BUILD_IDENTIFIER_BEGIN__";
- const std::string_view end_marker = "__EXTENSION_BUILD_IDENTIFIER_END__";
- const std::string magic_constant = utils::string::join_pack(begin_marker, AgentBuild::BUILD_IDENTIFIER, end_marker);
- return utils::file::contains(path, magic_constant);
-}
-
-[[nodiscard]] bool LibraryDescriptor::verify_as_c_extension(const std::shared_ptr<logging::Logger>& logger) const {
- const auto path = getFullPath();
- if (!std::filesystem::exists(path)) {
- throw std::runtime_error{"File not found: " + path.string()};
- }
- const std::string_view api_tag_prefix = "MINIFI_API_VERSION=[";
- if (auto version = utils::file::findSubstringWithPrefix(path, api_tag_prefix, api_tag_prefix.size() + 20)) {
- utils::SVMatch match;
- if (!utils::regexSearch(version.value(), match, utils::Regex{R"(MINIFI_API_VERSION=\[([0-9]+)\.([0-9]+)\.([0-9]+)\])"})) {
- logger->log_error("Found api version in invalid format: '{}'", version.value());
- return false;
- }
- gsl_Assert(match.size() == 4);
- const int major = std::stoi(match[1]);
- const int minor = std::stoi(match[2]);
- const int patch = std::stoi(match[3]);
- if (major != MINIFI_API_MAJOR_VERSION) {
- logger->log_error("API major version mismatch, application is '{}' while extension is '{}.{}.{}'", MINIFI_API_VERSION, major, minor, patch);
- return false;
- }
- if (minor > MINIFI_API_MINOR_VERSION) {
- logger->log_error("Extension is built for a newer version, application is '{}' while extension is '{}.{}.{}'", MINIFI_API_VERSION, major, minor, patch);
- return false;
- }
- return true;
- }
- return false;
-}
-
-} // namespace org::apache::nifi::minifi::core::extension::internal
diff --git a/libminifi/src/minifi-c.cpp b/libminifi/src/minifi-c.cpp
index f14847363..6a2d947ab 100644
--- a/libminifi/src/minifi-c.cpp
+++ b/libminifi/src/minifi-c.cpp
@@ -146,6 +146,30 @@ class CProcessorFactory : public minifi::core::ProcessorFactory {
minifi::utils::CProcessorClassDescription class_description_;
};
+MinifiExtension* MinifiCreateExtensionImpl(MinifiStringView /*api_version*/, const MinifiExtensionCreateInfo* extension_create_info) {
+ gsl_Assert(extension_create_info);
+ auto extension_name = toString(extension_create_info->name);
+ minifi::BundleIdentifier bundle{
+ .name = extension_name,
+ .version = toString(extension_create_info->version)
+ };
+ auto& bundle_components = minifi::ClassDescriptionRegistry::getMutableClassDescriptions()[bundle];
+ for (size_t proc_idx = 0; proc_idx < extension_create_info->processors_count; ++proc_idx) {
+ minifi::utils::useCProcessorClassDescription(extension_create_info->processors_ptr[proc_idx], [&] (const auto& description, const auto& c_class_description) {
+ minifi::core::ClassLoader::getDefaultClassLoader().getClassLoader(extension_name).registerClass(
+ c_class_description.name,
+ std::make_unique<CProcessorFactory>(extension_name, toString(extension_create_info->processors_ptr[proc_idx].full_name), c_class_description));
+ bundle_components.processors.emplace_back(description);
+ });
+ }
+ return reinterpret_cast<MinifiExtension*>(new org::apache::nifi::minifi::core::extension::Extension::Info{
+ .name = toString(extension_create_info->name),
+ .version = toString(extension_create_info->version),
+ .deinit = extension_create_info->deinit,
+ .user_data = extension_create_info->user_data
+ });
+}
+
} // namespace
namespace org::apache::nifi::minifi::utils {
@@ -225,30 +249,17 @@ void useCProcessorClassDescription(const MinifiProcessorClassDefinition& class_d
extern "C" {
-MinifiExtension* MinifiCreateExtension(MinifiStringView /*api_version*/, const MinifiExtensionCreateInfo* extension_create_info) {
- gsl_Assert(extension_create_info);
- auto extension_name = toString(extension_create_info->name);
- minifi::BundleIdentifier bundle{
- .name = extension_name,
- .version = toString(extension_create_info->version)
- };
- auto& bundle_components = minifi::ClassDescriptionRegistry::getMutableClassDescriptions()[bundle];
- for (size_t proc_idx = 0; proc_idx < extension_create_info->processors_count; ++proc_idx) {
- minifi::utils::useCProcessorClassDescription(extension_create_info->processors_ptr[proc_idx], [&] (const auto& description, const auto& c_class_description) {
- minifi::core::ClassLoader::getDefaultClassLoader().getClassLoader(extension_name).registerClass(
- c_class_description.name,
- std::make_unique<CProcessorFactory>(extension_name, toString(extension_create_info->processors_ptr[proc_idx].full_name), c_class_description));
- bundle_components.processors.emplace_back(description);
- });
- }
- return reinterpret_cast<MinifiExtension*>(new org::apache::nifi::minifi::core::extension::Extension::Info{
- .name = toString(extension_create_info->name),
- .version = toString(extension_create_info->version),
- .deinit = extension_create_info->deinit,
- .user_data = extension_create_info->user_data
- });
+MinifiExtension* MINIFI_CREATE_EXTENSION_FN(MinifiStringView api_version, const MinifiExtensionCreateInfo* extension_create_info) {
+ return MinifiCreateExtensionImpl(api_version, extension_create_info);
}
+#define REGISTER_C_API_VERSION(major, minor) \
+ MinifiExtension* MINIFI_PRIVATE_JOIN(MinifiCreateExtension, MINIFI_PRIVATE_JOIN(major, minor))(MinifiStringView api_version, const MinifiExtensionCreateInfo* extension_create_info) { \
+ return MinifiCreateExtensionImpl(api_version, extension_create_info); \
+ }
+
+REGISTER_C_API_VERSION(0, 1)
+
MinifiStatus MinifiProcessContextGetProperty(MinifiProcessContext* context, MinifiStringView property_name, MinifiFlowFile* flowfile,
void (*result_cb)(void* user_ctx, MinifiStringView result), void* user_ctx) {
gsl_Assert(context != MINIFI_NULL);
diff --git a/libminifi/test/unit/ExtensionVerificationTests.cpp b/libminifi/test/unit/ExtensionVerificationTests.cpp
deleted file mode 100644
index 71a425ada..000000000
--- a/libminifi/test/unit/ExtensionVerificationTests.cpp
+++ /dev/null
@@ -1,107 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#define CUSTOM_EXTENSION_INIT
-
-#include <filesystem>
-#include "unit/TestBase.h"
-#include "unit/Catch.h"
-#include "minifi-cpp/agent/agent_version.h"
-#include "core/extension/Utils.h"
-#include "unit/TestUtils.h"
-#include "minifi-c/minifi-c.h"
-
-using namespace std::literals;
-
-namespace {
-
-#if defined(WIN32)
-const std::string extension_file = "extension.dll";
-#elif defined(__APPLE__)
-const std::string extension_file = "libextension.dylib";
-#else
-const std::string extension_file = "libextension.so";
-#endif
-
-
-struct Fixture : public TestController {
- Fixture() {
- extension_ = createTempDirectory() / extension_file;
- }
- std::filesystem::path extension_;
-};
-
-const std::shared_ptr<logging::Logger> logger{core::logging::LoggerFactory<Fixture>::getLogger()};
-
-} // namespace
-
-TEST_CASE_METHOD(Fixture, "Could load extension with matching build id") {
- std::ofstream{extension_} << "__EXTENSION_BUILD_IDENTIFIER_BEGIN__"
- << minifi::AgentBuild::BUILD_IDENTIFIER << "__EXTENSION_BUILD_IDENTIFIER_END__";
-
- auto lib = minifi::core::extension::internal::asDynamicLibrary(extension_);
- REQUIRE(lib);
- CHECK(lib->verify(logger) == core::extension::internal::Cpp);
-}
-
-TEST_CASE_METHOD(Fixture, "Could load extension with matching C api") {
- std::ofstream{extension_} << MINIFI_API_VERSION_TAG;
-
- auto lib = minifi::core::extension::internal::asDynamicLibrary(extension_);
- REQUIRE(lib);
- CHECK(lib->verify(logger) == core::extension::internal::CApi);
-}
-
-TEST_CASE_METHOD(Fixture, "Can't load extension if the build id begin marker is missing") {
- std::ofstream{extension_} << "__MISSING_BEGIN__"
- << minifi::AgentBuild::BUILD_IDENTIFIER << "__EXTENSION_BUILD_IDENTIFIER_END__";
-
- auto lib = minifi::core::extension::internal::asDynamicLibrary(extension_);
- REQUIRE(lib);
- CHECK(lib->verify(logger) == core::extension::internal::Invalid);
-}
-
-TEST_CASE_METHOD(Fixture, "Can't load extension if the build id end marker is missing") {
- std::ofstream{extension_} << "__EXTENSION_BUILD_IDENTIFIER_BEGIN__"
- << minifi::AgentBuild::BUILD_IDENTIFIER << "__MISSING_END__";
-
- auto lib = minifi::core::extension::internal::asDynamicLibrary(extension_);
- REQUIRE(lib);
- CHECK(lib->verify(logger) == core::extension::internal::Invalid);
-}
-
-TEST_CASE_METHOD(Fixture, "Can't load extension if the build id does not match") {
- std::ofstream{extension_} << "__EXTENSION_BUILD_IDENTIFIER_BEGIN__"
- << "not the build id" << "__EXTENSION_BUILD_IDENTIFIER_END__";
-
- auto lib = minifi::core::extension::internal::asDynamicLibrary(extension_);
- REQUIRE(lib);
- CHECK(lib->verify(logger) == core::extension::internal::Invalid);
-}
-
-TEST_CASE_METHOD(Fixture, "Can't load extension if the file does not exist") {
- auto lib = minifi::core::extension::internal::asDynamicLibrary(extension_);
- REQUIRE(lib);
- REQUIRE_THROWS_AS(lib->verify(logger), std::runtime_error);
-}
-
-TEST_CASE_METHOD(Fixture, "Can't load extension if the file has zero length") {
- std::ofstream{extension_}; // NOLINT(bugprone-unused-raii)
-
- auto lib = minifi::core::extension::internal::asDynamicLibrary(extension_);
- REQUIRE(lib);
- CHECK(lib->verify(logger) == core::extension::internal::Invalid);
-}
diff --git a/minifi-api/CMakeLists.txt b/minifi-api/CMakeLists.txt
index 95fbb885c..05f78fc99 100644
--- a/minifi-api/CMakeLists.txt
+++ b/minifi-api/CMakeLists.txt
@@ -6,6 +6,7 @@ target_compile_definitions(minifi-api-common INTERFACE MINIFI_VERSION_STR="${MIN
add_library(minifi-api INTERFACE)
target_include_directories(minifi-api INTERFACE include)
target_link_libraries(minifi-api INTERFACE minifi-api-common)
+target_compile_definitions(minifi-api INTERFACE MINIFI_CREATE_EXTENSION_FN=MinifiCreateExtension_${BUILD_IDENTIFIER})
add_library(minifi-c-api INTERFACE)
target_include_directories(minifi-c-api INTERFACE include/minifi-c)
diff --git a/minifi-api/include/minifi-c/minifi-c.h b/minifi-api/include/minifi-c/minifi-c.h
index 1f22c908c..97af61f5b 100644
--- a/minifi-api/include/minifi-c/minifi-c.h
+++ b/minifi-api/include/minifi-c/minifi-c.h
@@ -31,11 +31,18 @@ extern "C" {
#define MINIFI_PRIVATE_STRINGIFY_HELPER(X) #X
#define MINIFI_PRIVATE_STRINGIFY(X) MINIFI_PRIVATE_STRINGIFY_HELPER(X)
+#define MINIFI_PRIVATE_JOIN_HELPER(X, Y) X ## _ ## Y
+#define MINIFI_PRIVATE_JOIN(X, Y) MINIFI_PRIVATE_JOIN_HELPER(X, Y)
+
#define MINIFI_API_MAJOR_VERSION 0
#define MINIFI_API_MINOR_VERSION 1
#define MINIFI_API_PATCH_VERSION 0
#define MINIFI_API_VERSION MINIFI_PRIVATE_STRINGIFY(MINIFI_API_MAJOR_VERSION) "." MINIFI_PRIVATE_STRINGIFY(MINIFI_API_MINOR_VERSION) "." MINIFI_PRIVATE_STRINGIFY(MINIFI_API_PATCH_VERSION)
-#define MINIFI_API_VERSION_TAG "MINIFI_API_VERSION=[" MINIFI_API_VERSION "]"
+
+#ifndef MINIFI_CREATE_EXTENSION_FN
+#define MINIFI_CREATE_EXTENSION_FN MINIFI_PRIVATE_JOIN(MinifiCreateExtension, MINIFI_PRIVATE_JOIN(MINIFI_API_MAJOR_VERSION, MINIFI_API_MINOR_VERSION))
+#endif
+
#define MINIFI_NULL nullptr
#define MINIFI_OWNED
@@ -87,6 +94,7 @@ typedef struct MinifiOutputStream MinifiOutputStream;
typedef struct MinifiConfig MinifiConfig;
typedef struct MinifiExtension MinifiExtension;
typedef struct MinifiPublishedMetrics MinifiPublishedMetrics;
+typedef struct MinifiApiVersion MinifiApiVersion;
typedef enum MinifiStatus {
MINIFI_STATUS_SUCCESS = 0,
@@ -184,7 +192,7 @@ typedef struct MinifiExtensionCreateInfo {
// api_version is used to provide backwards compatible changes to the MinifiExtensionCreateInfo structure,
// e.g. if MinifiExtensionCreateInfo gets a new field in version 1.2.0, extensions built with api 1.1.0 do not
// have to be rebuilt
-MinifiExtension* MinifiCreateExtension(MinifiStringView api_version, const MinifiExtensionCreateInfo*);
+MinifiExtension* MINIFI_CREATE_EXTENSION_FN(MinifiStringView api_version, const MinifiExtensionCreateInfo* create_info);
MINIFI_OWNED MinifiPublishedMetrics* MinifiPublishedMetricsCreate(size_t count, const MinifiStringView* metric_names, const double* metric_values);
@@ -225,4 +233,8 @@ void MinifiFlowFileGetAttributes(MinifiProcessSession* session, MinifiFlowFile*
} // extern "C"
#endif // __cplusplus
+static inline MinifiExtension* MinifiCreateExtension(MinifiStringView api_version, const MinifiExtensionCreateInfo* create_info) {
+ return MINIFI_CREATE_EXTENSION_FN(api_version, create_info);
+}
+
#endif // MINIFI_API_INCLUDE_MINIFI_C_MINIFI_C_H_
diff --git a/minifi-api/minifi-c-api.def b/minifi-api/minifi-c-api.def
index 18fad4bff..d7faf9426 100644
--- a/minifi-api/minifi-c-api.def
+++ b/minifi-api/minifi-c-api.def
@@ -1,6 +1,6 @@
LIBRARY core-minifi.dll
EXPORTS
- MinifiCreateExtension
+ MinifiCreateExtension_0_1
MinifiPublishedMetricsCreate
MinifiProcessContextGetProperty
MinifiProcessContextGetProcessorName
@@ -22,4 +22,4 @@ EXPORTS
MinifiStatusToString
MinifiFlowFileSetAttribute
MinifiFlowFileGetAttribute
- MinifiFlowFileGetAttributes
\ No newline at end of file
+ MinifiFlowFileGetAttributes