diff --git a/CMakeLists.txt b/CMakeLists.txt index 50e31d8718..c1cc6a6019 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -339,6 +339,9 @@ endfunction() SET(TEST_DIR ${CMAKE_SOURCE_DIR}/libminifi/test) include(Extensions) +add_subdirectory(minifi-api) +add_subdirectory(utils) +add_subdirectory(extension-utils) add_subdirectory(libminifi) if (ENABLE_ALL OR ENABLE_AZURE) diff --git a/controller/MiNiFiController.cpp b/controller/MiNiFiController.cpp index 673680b734..33be0ed715 100644 --- a/controller/MiNiFiController.cpp +++ b/controller/MiNiFiController.cpp @@ -39,7 +39,7 @@ std::shared_ptr getControllerServic const std::string &service_name) { std::string nifi_configuration_class_name = "adaptiveconfiguration"; - minifi::core::extension::ExtensionManager::get().initialize(configuration); + minifi::core::extension::ExtensionManagerImpl::get().initialize(configuration); configuration->get(minifi::Configure::nifi_configuration_class_name, nifi_configuration_class_name); auto flow_configuration = minifi::core::createFlowConfiguration( @@ -78,7 +78,7 @@ std::shared_ptr getSSLContextService(con if (nullptr == secure_context) { std::string secureStr; if (configuration->get(minifi::Configure::nifi_remote_input_secure, secureStr) && minifi::utils::string::toBool(secureStr).value_or(false)) { - secure_context = std::make_shared("ControllerSocketProtocolSSL", configuration); + secure_context = std::make_shared("ControllerSocketProtocolSSL", configuration); secure_context->onEnable(); } } else { @@ -96,7 +96,7 @@ int main(int argc, char **argv) { return -1; } - const auto configuration = std::make_shared(); + const auto configuration = std::make_shared(); configuration->setHome(minifi_home); configuration->loadConfigureFile(DEFAULT_NIFI_PROPERTIES_FILE); diff --git a/controller/tests/ControllerTests.cpp b/controller/tests/ControllerTests.cpp index 08ae1a4bfa..adbe80ca69 100644 --- a/controller/tests/ControllerTests.cpp +++ b/controller/tests/ControllerTests.cpp @@ -34,6 +34,7 @@ #include "controllers/SSLContextService.h" #include "utils/StringUtils.h" #include "state/UpdateController.h" +#include "core/state/nodes/ResponseNodeLoader.h" using namespace std::literals::chrono_literals; @@ -201,10 +202,10 @@ class TestControllerSocketReporter : public c2::ControllerSocketReporter { } }; -class TestControllerServiceProvider : public core::controller::ControllerServiceProvider { +class TestControllerServiceProvider : public core::controller::ControllerServiceProviderImpl { public: explicit TestControllerServiceProvider(std::shared_ptr ssl_context_service) - : core::controller::ControllerServiceProvider("TestControllerServiceProvider"), + : core::controller::ControllerServiceProviderImpl("TestControllerServiceProvider"), ssl_context_service_(std::move(ssl_context_service)) { } std::shared_ptr getControllerService(const std::string&) const override { @@ -239,7 +240,7 @@ class ControllerTestFixture { }; ControllerTestFixture() - : configuration_(std::make_shared()), + : configuration_(std::make_shared()), controller_(std::make_shared()), update_sink_(std::make_unique(controller_)) { configuration_->set(minifi::Configure::controller_socket_host, "localhost"); @@ -249,7 +250,7 @@ class ControllerTestFixture { 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()); configuration_->set(minifi::Configure::controller_ssl_context_service, "SSLContextService"); - ssl_context_service_ = std::make_shared("SSLContextService", configuration_); + ssl_context_service_ = std::make_shared("SSLContextService", configuration_); ssl_context_service_->onEnable(); controller_service_provider_ = std::make_unique(ssl_context_service_); controller_socket_data_.host = "localhost"; @@ -478,7 +479,7 @@ TEST_CASE_METHOD(ControllerTestFixture, "Test manifest getter", "[controllerTest } auto reporter = std::make_shared("ControllerSocketMetricsPublisher"); - auto response_node_loader = std::make_shared(configuration_, std::vector>{}, nullptr); + auto response_node_loader = std::make_shared(configuration_, std::vector>{}, nullptr); reporter->initialize(configuration_, response_node_loader); initalizeControllerSocket(reporter); @@ -501,7 +502,7 @@ TEST_CASE_METHOD(ControllerTestFixture, "Test jstack getter", "[controllerTests] } auto reporter = std::make_shared("ControllerSocketMetricsPublisher"); - auto response_node_loader = std::make_shared(configuration_, std::vector>{}, nullptr); + auto response_node_loader = std::make_shared(configuration_, std::vector>{}, nullptr); reporter->initialize(configuration_, response_node_loader); initalizeControllerSocket(reporter); @@ -529,7 +530,7 @@ TEST_CASE_METHOD(ControllerTestFixture, "Test debug bundle getter", "[controller } auto reporter = std::make_shared("ControllerSocketMetricsPublisher"); - auto response_node_loader = std::make_shared(configuration_, std::vector>{}, nullptr); + auto response_node_loader = std::make_shared(configuration_, std::vector>{}, nullptr); reporter->initialize(configuration_, response_node_loader); initalizeControllerSocket(reporter); @@ -543,7 +544,7 @@ TEST_CASE_METHOD(ControllerTestFixture, "Test debug bundle is created to non-exi setConnectionType(ControllerTestFixture::ConnectionType::UNSECURE); auto reporter = std::make_shared("ControllerSocketMetricsPublisher"); - auto response_node_loader = std::make_shared(configuration_, std::vector>{}, nullptr); + auto response_node_loader = std::make_shared(configuration_, std::vector>{}, nullptr); reporter->initialize(configuration_, response_node_loader); initalizeControllerSocket(reporter); @@ -557,7 +558,7 @@ TEST_CASE_METHOD(ControllerTestFixture, "Debug bundle retrieval fails if target setConnectionType(ControllerTestFixture::ConnectionType::UNSECURE); auto reporter = std::make_shared("ControllerSocketMetricsPublisher"); - auto response_node_loader = std::make_shared(configuration_, std::vector>{}, nullptr); + auto response_node_loader = std::make_shared(configuration_, std::vector>{}, nullptr); reporter->initialize(configuration_, response_node_loader); initalizeControllerSocket(reporter); diff --git a/encrypt-config/CMakeLists.txt b/encrypt-config/CMakeLists.txt index cfa4365642..05146bdb74 100644 --- a/encrypt-config/CMakeLists.txt +++ b/encrypt-config/CMakeLists.txt @@ -26,7 +26,7 @@ endif() add_minifi_executable(encrypt-config "${ENCRYPT_CONFIG_FILES}") target_include_directories(encrypt-config PRIVATE ../libminifi/include) include(ArgParse) -target_link_libraries(encrypt-config libsodium argparse ${LIBMINIFI}) +target_link_libraries(encrypt-config libsodium argparse core-minifi) set_target_properties(encrypt-config PROPERTIES OUTPUT_NAME encrypt-config) set_target_properties(encrypt-config PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin") diff --git a/encrypt-config/FlowConfigEncryptor.cpp b/encrypt-config/FlowConfigEncryptor.cpp index 9c28499dd0..e5cb75cc0a 100644 --- a/encrypt-config/FlowConfigEncryptor.cpp +++ b/encrypt-config/FlowConfigEncryptor.cpp @@ -179,7 +179,7 @@ void encryptSensitiveValuesInFlowConfig(const EncryptionKeys& keys, const std::f throw std::runtime_error("Error: cannot re-encrypt without an .old key!"); } - const auto configure = std::make_shared(); + const auto configure = std::make_shared(); configure->setHome(minifi_home); configure->loadConfigureFile(DEFAULT_NIFI_PROPERTIES_FILE); @@ -191,7 +191,7 @@ void encryptSensitiveValuesInFlowConfig(const EncryptionKeys& keys, const std::f utils::crypto::EncryptionProvider{utils::crypto::XSalsa20Cipher{*keys.old_key}} : utils::crypto::EncryptionProvider{utils::crypto::XSalsa20Cipher{keys.encryption_key}}; - core::extension::ExtensionManager::get().initialize(configure); + core::extension::ExtensionManagerImpl::get().initialize(configure); core::flow::AdaptiveConfiguration adaptive_configuration{core::ConfigurationContext{ .flow_file_repo = nullptr, diff --git a/encrypt-config/tests/CMakeLists.txt b/encrypt-config/tests/CMakeLists.txt index 175e70cff2..f45d82ba06 100644 --- a/encrypt-config/tests/CMakeLists.txt +++ b/encrypt-config/tests/CMakeLists.txt @@ -31,7 +31,7 @@ foreach(testfile ${ENCRYPT_CONFIG_TESTS}) createTests(${testfilename}) - target_link_libraries(${testfilename} Catch2WithMain ${LIBMINIFI} libminifi-unittest) + target_link_libraries(${testfilename} Catch2WithMain core-minifi libminifi-unittest) add_test(NAME ${testfilename} COMMAND ${testfilename} WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}") math(EXPR ENCRYPT_CONFIG_TEST_COUNT "${ENCRYPT_CONFIG_TEST_COUNT}+1") diff --git a/extension-utils/CMakeLists.txt b/extension-utils/CMakeLists.txt new file mode 100644 index 0000000000..3ba365b2c2 --- /dev/null +++ b/extension-utils/CMakeLists.txt @@ -0,0 +1,35 @@ +file(GLOB SOURCES + src/*.cpp + src/core/*.cpp + src/controllers/keyvalue/*.cpp + src/controllers/*.cpp + src/io/*.cpp + src/serialization/*.cpp + src/utils/file/*.cpp + src/utils/net/*.cpp + src/utils/tls/*.cpp + src/utils/*.cpp) +add_minifi_library(minifi-extension-utils STATIC ${SOURCES}) +target_include_directories(minifi-extension-utils PUBLIC include) +target_link_libraries(minifi-extension-utils PUBLIC minifi-core) + +include(RangeV3) +include(Asio) +include(MagicEnum) +list(APPEND CORE_LIBRARIES ZLIB::ZLIB concurrentqueue RapidJSON spdlog Threads::Threads gsl-lite range-v3 expected-lite asio magic_enum OpenSSL::Crypto OpenSSL::SSL CURL::libcurl RapidJSON) +if(NOT WIN32) + list(APPEND CORE_LIBRARIES OSSP::libuuid++) +endif() +if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 9) + list(APPEND CORE_LIBRARIES stdc++fs) +endif() +target_link_libraries(minifi-extension-utils PUBLIC ${CMAKE_DL_LIBS} ${CORE_LIBRARIES}) +if (APPLE) + target_link_libraries(minifi-extension-utils PUBLIC "-framework CoreFoundation -framework SystemConfiguration") +endif() +if (UNIX AND (CMAKE_SYSTEM_PROCESSOR MATCHES "armv7")) + target_link_libraries(minifi-extension-utils PUBLIC "-latomic") +endif() + +target_link_libraries(minifi-extension-utils PRIVATE minifi-core) +target_link_libraries(minifi-extension-utils PUBLIC minifi-utils) \ No newline at end of file diff --git a/extension-utils/include/FlowFileRecord.h b/extension-utils/include/FlowFileRecord.h new file mode 100644 index 0000000000..8a1658e333 --- /dev/null +++ b/extension-utils/include/FlowFileRecord.h @@ -0,0 +1,21 @@ +/** + * + * 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 "minifi-cpp/FlowFileRecord.h" diff --git a/extension-utils/include/ResourceClaim.h b/extension-utils/include/ResourceClaim.h new file mode 100644 index 0000000000..ff9ada8cc5 --- /dev/null +++ b/extension-utils/include/ResourceClaim.h @@ -0,0 +1,21 @@ +/** + * + * 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 "minifi-cpp/ResourceClaim.h" \ No newline at end of file diff --git a/libminifi/include/controllers/AttributeProviderService.h b/extension-utils/include/controllers/AttributeProviderService.h similarity index 80% rename from libminifi/include/controllers/AttributeProviderService.h rename to extension-utils/include/controllers/AttributeProviderService.h index b3a59be874..7e3836f531 100644 --- a/libminifi/include/controllers/AttributeProviderService.h +++ b/extension-utils/include/controllers/AttributeProviderService.h @@ -22,20 +22,18 @@ #include #include "core/controller/ControllerService.h" +#include "minifi-cpp/controllers/AttributeProviderService.h" namespace org::apache::nifi::minifi::controllers { -class AttributeProviderService : public core::controller::ControllerService { +class AttributeProviderServiceImpl : public core::controller::ControllerServiceImpl, public virtual AttributeProviderService { public: - using ControllerService::ControllerService; + using ControllerServiceImpl::ControllerServiceImpl; void yield() override {} bool isRunning() const override { return getState() == core::controller::ControllerServiceState::ENABLED; } bool isWorkAvailable() override { return false; } - - using AttributeMap = std::unordered_map; - virtual std::optional> getAttributes() = 0; - virtual std::string_view name() const = 0; }; } // namespace org::apache::nifi::minifi::controllers + diff --git a/extension-utils/include/controllers/RecordSetReader.h b/extension-utils/include/controllers/RecordSetReader.h new file mode 100644 index 0000000000..ead6e019f1 --- /dev/null +++ b/extension-utils/include/controllers/RecordSetReader.h @@ -0,0 +1,30 @@ +/** +* 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 "minifi-cpp/controllers/RecordSetReader.h" +#include "core/controller/ControllerService.h" + + +namespace org::apache::nifi::minifi::core { + +class RecordSetReaderImpl : public virtual controller::ControllerServiceImpl, public virtual RecordSetReader { + public: + using ControllerServiceImpl::ControllerServiceImpl; +}; + +} // namespace org::apache::nifi::minifi::core diff --git a/extension-utils/include/controllers/RecordSetWriter.h b/extension-utils/include/controllers/RecordSetWriter.h new file mode 100644 index 0000000000..8ba127b3d0 --- /dev/null +++ b/extension-utils/include/controllers/RecordSetWriter.h @@ -0,0 +1,29 @@ +/** +* 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 "minifi-cpp/controllers/RecordSetWriter.h" +#include "core/controller/ControllerService.h" + +namespace org::apache::nifi::minifi::core { + +class RecordSetWriterImpl : public virtual controller::ControllerServiceImpl, public virtual RecordSetWriter { + public: + using ControllerServiceImpl::ControllerServiceImpl; +}; + +} // namespace org::apache::nifi::minifi::core diff --git a/extension-utils/include/controllers/SSLContextService.h b/extension-utils/include/controllers/SSLContextService.h new file mode 100644 index 0000000000..e399a734aa --- /dev/null +++ b/extension-utils/include/controllers/SSLContextService.h @@ -0,0 +1,19 @@ +/** + * 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 "minifi-cpp/controllers/SSLContextService.h" \ No newline at end of file diff --git a/libminifi/include/controllers/keyvalue/KeyValueStateManager.h b/extension-utils/include/controllers/keyvalue/KeyValueStateManager.h similarity index 94% rename from libminifi/include/controllers/keyvalue/KeyValueStateManager.h rename to extension-utils/include/controllers/keyvalue/KeyValueStateManager.h index 19df889935..604a113aec 100644 --- a/libminifi/include/controllers/keyvalue/KeyValueStateManager.h +++ b/extension-utils/include/controllers/keyvalue/KeyValueStateManager.h @@ -29,10 +29,11 @@ namespace org::apache::nifi::minifi::controllers { class KeyValueStateStorage; -class KeyValueStateManager final : public core::StateManager { +class KeyValueStateManager final : public core::StateManagerImpl { public: KeyValueStateManager(const utils::Identifier& id, gsl::not_null storage); + using StateManagerImpl::get; bool set(const core::StateManager::State& kvs) override; bool get(core::StateManager::State& kvs) override; bool clear() override; diff --git a/libminifi/include/controllers/keyvalue/KeyValueStateStorage.h b/extension-utils/include/controllers/keyvalue/KeyValueStateStorage.h similarity index 89% rename from libminifi/include/controllers/keyvalue/KeyValueStateStorage.h rename to extension-utils/include/controllers/keyvalue/KeyValueStateStorage.h index 9fa3fca20b..149c795395 100644 --- a/libminifi/include/controllers/keyvalue/KeyValueStateStorage.h +++ b/extension-utils/include/controllers/keyvalue/KeyValueStateStorage.h @@ -24,21 +24,20 @@ #include "core/controller/ControllerService.h" #include "core/Core.h" #include "core/logging/LoggerFactory.h" -#include "core/StateManager.h" +#include "minifi-cpp/core/StateManager.h" #include "core/StateStorage.h" +#include "minifi-cpp/controllers/keyvalue/KeyValueStateStorage.h" namespace org::apache::nifi::minifi::controllers { -constexpr const char* ALWAYS_PERSIST_PROPERTY_NAME = "Always Persist"; -constexpr const char* AUTO_PERSISTENCE_INTERVAL_PROPERTY_NAME = "Auto Persistence Interval"; - -class KeyValueStateStorage : public core::StateStorage, public core::controller::ControllerService { +class KeyValueStateStorage : public core::StateStorageImpl, public core::controller::ControllerServiceImpl { public: explicit KeyValueStateStorage(const std::string& name, const utils::Identifier& uuid = {}); static core::StateManager::State deserialize(const std::string& serialized); static std::string serialize(const core::StateManager::State& kvs); + using core::StateStorageImpl::getStateManager; std::unique_ptr getStateManager(const utils::Identifier& uuid) override; std::unordered_map getAllStates() override; diff --git a/libminifi/include/core/AbstractProcessor.h b/extension-utils/include/core/AbstractProcessor.h similarity index 93% rename from libminifi/include/core/AbstractProcessor.h rename to extension-utils/include/core/AbstractProcessor.h index 2862bbda23..113361f033 100644 --- a/libminifi/include/core/AbstractProcessor.h +++ b/extension-utils/include/core/AbstractProcessor.h @@ -20,17 +20,17 @@ #include #include #include "range/v3/view/transform.hpp" -#include "core/Annotation.h" +#include "minifi-cpp/core/Annotation.h" #include "core/Core.h" #include "core/Processor.h" #include "core/PropertyDefinition.h" -#include "core/RelationshipDefinition.h" +#include "minifi-cpp/core/RelationshipDefinition.h" namespace org::apache::nifi::minifi::core { template -class AbstractProcessor : public Processor { +class AbstractProcessor : public ProcessorImpl { public: - using Processor::Processor; + using ProcessorImpl::ProcessorImpl; void initialize() final { static_assert(std::is_same_v); diff --git a/extension-utils/include/core/FlowFile.h b/extension-utils/include/core/FlowFile.h new file mode 100644 index 0000000000..4a64a2d078 --- /dev/null +++ b/extension-utils/include/core/FlowFile.h @@ -0,0 +1,20 @@ +/** + * 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 "minifi-cpp/core/FlowFile.h" diff --git a/libminifi/include/core/FlowFileStore.h b/extension-utils/include/core/FlowFileStore.h similarity index 100% rename from libminifi/include/core/FlowFileStore.h rename to extension-utils/include/core/FlowFileStore.h diff --git a/extension-utils/include/core/ProcessSession.h b/extension-utils/include/core/ProcessSession.h new file mode 100644 index 0000000000..26678bedb8 --- /dev/null +++ b/extension-utils/include/core/ProcessSession.h @@ -0,0 +1,27 @@ +/** + * 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 "minifi-cpp/core/ProcessSession.h" + +namespace org::apache::nifi::minifi::core::detail { + +std::string to_string(const ReadBufferResult& read_buffer_result); + +} // namespace org::apache::nifi::minifi::core::detail + diff --git a/extension-utils/include/core/StateManager.h b/extension-utils/include/core/StateManager.h new file mode 100644 index 0000000000..bf5a30e665 --- /dev/null +++ b/extension-utils/include/core/StateManager.h @@ -0,0 +1,55 @@ +/** + * 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 "core/Core.h" + +#include +#include +#include +#include +#include "minifi-cpp/core/StateManager.h" + +namespace org::apache::nifi::minifi::core { + +/** + * Stores state for one component. + * Supported operations: get(), set(), clear(), persist(). + * Behavior can be transactional. Use beginTransaction() to enter a transaction and commit() or rollback() to conclude it. + */ +class StateManagerImpl : public virtual StateManager { + public: + explicit StateManagerImpl(const utils::Identifier& id) + : id_(id) { + } + + ~StateManagerImpl() override = default; + + using StateManager::get; + std::optional get() override { + if (State out; get(out)) { + return out; + } + return std::nullopt; + } + + protected: + utils::Identifier id_; +}; + +} // namespace org::apache::nifi::minifi::core diff --git a/extension-utils/include/core/StateStorage.h b/extension-utils/include/core/StateStorage.h new file mode 100644 index 0000000000..89822310fb --- /dev/null +++ b/extension-utils/include/core/StateStorage.h @@ -0,0 +1,43 @@ +/** + * 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 "core/Core.h" +#include "StateManager.h" + +#include +#include +#include +#include "minifi-cpp/core/StateStorage.h" + +namespace org::apache::nifi::minifi::core { + +/** + * Serves as a state storage background for the entire application, all StateManagers are created by it and use it. + */ +class StateStorageImpl : public virtual StateStorage { + public: + ~StateStorageImpl() override = default; + + using StateStorage::getStateManager; + std::unique_ptr getStateManager(const CoreComponent& component) override { + return getStateManager(component.getUUID()); + } +}; + +} // namespace org::apache::nifi::minifi::core diff --git a/extension-utils/include/properties/Configure.h b/extension-utils/include/properties/Configure.h new file mode 100644 index 0000000000..d3d229d21d --- /dev/null +++ b/extension-utils/include/properties/Configure.h @@ -0,0 +1,19 @@ +/** + * 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 "minifi-cpp/properties/Configure.h" diff --git a/extension-utils/include/properties/Properties.h b/extension-utils/include/properties/Properties.h new file mode 100644 index 0000000000..c1e3eca4c9 --- /dev/null +++ b/extension-utils/include/properties/Properties.h @@ -0,0 +1,19 @@ +/** + * 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 "minifi-cpp/properties/Properties.h" diff --git a/libminifi/include/serialization/FlowFileSerializer.h b/extension-utils/include/serialization/FlowFileSerializer.h similarity index 97% rename from libminifi/include/serialization/FlowFileSerializer.h rename to extension-utils/include/serialization/FlowFileSerializer.h index 6948a00424..e8a612799a 100644 --- a/libminifi/include/serialization/FlowFileSerializer.h +++ b/extension-utils/include/serialization/FlowFileSerializer.h @@ -21,7 +21,7 @@ #include #include #include -#include "io/StreamCallback.h" +#include "minifi-cpp/io/StreamCallback.h" namespace org { namespace apache { diff --git a/libminifi/include/serialization/FlowFileV3Serializer.h b/extension-utils/include/serialization/FlowFileV3Serializer.h similarity index 100% rename from libminifi/include/serialization/FlowFileV3Serializer.h rename to extension-utils/include/serialization/FlowFileV3Serializer.h diff --git a/libminifi/include/serialization/PayloadSerializer.h b/extension-utils/include/serialization/PayloadSerializer.h similarity index 100% rename from libminifi/include/serialization/PayloadSerializer.h rename to extension-utils/include/serialization/PayloadSerializer.h diff --git a/libminifi/include/utils/ListingStateManager.h b/extension-utils/include/utils/ListingStateManager.h similarity index 95% rename from libminifi/include/utils/ListingStateManager.h rename to extension-utils/include/utils/ListingStateManager.h index 7fa9501a9f..0b4a0b7ee5 100644 --- a/libminifi/include/utils/ListingStateManager.h +++ b/extension-utils/include/utils/ListingStateManager.h @@ -57,9 +57,6 @@ class ListingStateManager { void storeState(const ListingState &latest_listing_state); private: - static const std::string LATEST_LISTED_OBJECT_PREFIX; - static const std::string LATEST_LISTED_OBJECT_TIMESTAMP; - [[nodiscard]] static uint64_t getLatestListedKeyTimestampInMilliseconds(const std::unordered_map &state); [[nodiscard]] static std::unordered_set getLatestListedKeys(const std::unordered_map &state); diff --git a/libminifi/include/utils/OpenTelemetryLogDataModelUtils.h b/extension-utils/include/utils/OpenTelemetryLogDataModelUtils.h similarity index 98% rename from libminifi/include/utils/OpenTelemetryLogDataModelUtils.h rename to extension-utils/include/utils/OpenTelemetryLogDataModelUtils.h index c9c639116b..d46d5598a5 100644 --- a/libminifi/include/utils/OpenTelemetryLogDataModelUtils.h +++ b/extension-utils/include/utils/OpenTelemetryLogDataModelUtils.h @@ -20,7 +20,7 @@ #include #include "rapidjson/document.h" -#include "NetworkInterfaceInfo.h" +#include "utils/net/NetworkInterfaceInfo.h" #include "utils/net/DNS.h" namespace org::apache::nifi::minifi::utils { diff --git a/libminifi/include/utils/ProcessorConfigUtils.h b/extension-utils/include/utils/ProcessorConfigUtils.h similarity index 100% rename from libminifi/include/utils/ProcessorConfigUtils.h rename to extension-utils/include/utils/ProcessorConfigUtils.h diff --git a/libminifi/include/utils/ResourceQueue.h b/extension-utils/include/utils/ResourceQueue.h similarity index 94% rename from libminifi/include/utils/ResourceQueue.h rename to extension-utils/include/utils/ResourceQueue.h index 5f326a6afb..91219602e4 100644 --- a/libminifi/include/utils/ResourceQueue.h +++ b/extension-utils/include/utils/ResourceQueue.h @@ -29,7 +29,7 @@ #include "core/logging/Logger.h" #include "concurrentqueue.h" -#include "MinifiConcurrentQueue.h" +#include "utils/MinifiConcurrentQueue.h" namespace org::apache::nifi::minifi::utils { @@ -41,7 +41,7 @@ namespace org::apache::nifi::minifi::utils { * */ template -class ResourceQueue : public std::enable_shared_from_this> { +class ResourceQueue : public utils::EnableSharedFromThis { public: class ResourceWrapper { public: @@ -75,7 +75,7 @@ class ResourceQueue : public std::enable_shared_from_this(resource.get())); - return ResourceWrapper(this->weak_from_this(), std::move(resource)); + return ResourceWrapper(sharedFromThis>(), std::move(resource)); } else { const std::lock_guard lock(counter_mutex_); if (!maximum_number_of_creatable_resources_ || resources_created_ < maximum_number_of_creatable_resources_) { @@ -85,14 +85,14 @@ class ResourceQueue : public std::enable_shared_from_this(resource.get()), resources_created_, maximum_number_of_creatable_resources_ ? " / " + std::to_string(*maximum_number_of_creatable_resources_) : ""); - return ResourceWrapper(this->weak_from_this(), std::move(resource)); + return ResourceWrapper(sharedFromThis>(), std::move(resource)); } } logDebug("Waiting for resource"); if (!internal_queue_.dequeueWait(resource)) { throw std::runtime_error("No resource available"); } - return ResourceWrapper(this->weak_from_this(), std::move(resource)); + return ResourceWrapper(sharedFromThis>(), std::move(resource)); } protected: diff --git a/libminifi/include/utils/file/FileManager.h b/extension-utils/include/utils/file/FileManager.h similarity index 100% rename from libminifi/include/utils/file/FileManager.h rename to extension-utils/include/utils/file/FileManager.h diff --git a/libminifi/include/utils/file/FileReaderCallback.h b/extension-utils/include/utils/file/FileReaderCallback.h similarity index 100% rename from libminifi/include/utils/file/FileReaderCallback.h rename to extension-utils/include/utils/file/FileReaderCallback.h diff --git a/libminifi/include/utils/file/FileWriterCallback.h b/extension-utils/include/utils/file/FileWriterCallback.h similarity index 96% rename from libminifi/include/utils/file/FileWriterCallback.h rename to extension-utils/include/utils/file/FileWriterCallback.h index c284d9ab01..2cb8729fa2 100644 --- a/libminifi/include/utils/file/FileWriterCallback.h +++ b/extension-utils/include/utils/file/FileWriterCallback.h @@ -21,7 +21,7 @@ #include #include "io/StreamPipe.h" #include "utils/expected.h" -#include "core/logging/LoggerConfiguration.h" +#include "core/logging/LoggerFactory.h" namespace org::apache::nifi::minifi::utils { diff --git a/libminifi/include/utils/file/ListedFile.h b/extension-utils/include/utils/file/ListedFile.h similarity index 99% rename from libminifi/include/utils/file/ListedFile.h rename to extension-utils/include/utils/file/ListedFile.h index 9961f7e01a..72677e1116 100644 --- a/libminifi/include/utils/file/ListedFile.h +++ b/extension-utils/include/utils/file/ListedFile.h @@ -22,6 +22,7 @@ #include #include "../ListingStateManager.h" +#include "utils/file/FileUtils.h" namespace org::apache::nifi::minifi::utils { diff --git a/libminifi/include/utils/net/ConnectionHandler.h b/extension-utils/include/utils/net/ConnectionHandler.h similarity index 98% rename from libminifi/include/utils/net/ConnectionHandler.h rename to extension-utils/include/utils/net/ConnectionHandler.h index d7e9825606..b3d5075ec2 100644 --- a/libminifi/include/utils/net/ConnectionHandler.h +++ b/extension-utils/include/utils/net/ConnectionHandler.h @@ -19,8 +19,8 @@ #include -#include "AsioCoro.h" -#include "AsioSocketUtils.h" +#include "utils/net/AsioCoro.h" +#include "utils/net/AsioSocketUtils.h" #include "ConnectionHandlerBase.h" namespace org::apache::nifi::minifi::utils::net { diff --git a/libminifi/include/utils/net/ConnectionHandlerBase.h b/extension-utils/include/utils/net/ConnectionHandlerBase.h similarity index 100% rename from libminifi/include/utils/net/ConnectionHandlerBase.h rename to extension-utils/include/utils/net/ConnectionHandlerBase.h diff --git a/libminifi/include/utils/net/IpProtocol.h b/extension-utils/include/utils/net/IpProtocol.h similarity index 100% rename from libminifi/include/utils/net/IpProtocol.h rename to extension-utils/include/utils/net/IpProtocol.h diff --git a/libminifi/include/utils/net/Message.h b/extension-utils/include/utils/net/Message.h similarity index 100% rename from libminifi/include/utils/net/Message.h rename to extension-utils/include/utils/net/Message.h diff --git a/libminifi/include/utils/net/Server.h b/extension-utils/include/utils/net/Server.h similarity index 100% rename from libminifi/include/utils/net/Server.h rename to extension-utils/include/utils/net/Server.h diff --git a/libminifi/include/utils/net/Ssl.h b/extension-utils/include/utils/net/Ssl.h similarity index 100% rename from libminifi/include/utils/net/Ssl.h rename to extension-utils/include/utils/net/Ssl.h diff --git a/libminifi/include/utils/net/TcpServer.h b/extension-utils/include/utils/net/TcpServer.h similarity index 100% rename from libminifi/include/utils/net/TcpServer.h rename to extension-utils/include/utils/net/TcpServer.h diff --git a/libminifi/include/utils/net/UdpServer.h b/extension-utils/include/utils/net/UdpServer.h similarity index 96% rename from libminifi/include/utils/net/UdpServer.h rename to extension-utils/include/utils/net/UdpServer.h index 97cfa5737c..510f2beaa0 100644 --- a/libminifi/include/utils/net/UdpServer.h +++ b/extension-utils/include/utils/net/UdpServer.h @@ -24,7 +24,7 @@ #include "Server.h" #include "utils/MinifiConcurrentQueue.h" #include "core/logging/Logger.h" -#include "core/logging/LoggerConfiguration.h" +#include "core/logging/LoggerFactory.h" namespace org::apache::nifi::minifi::utils::net { diff --git a/libminifi/src/controllers/keyvalue/KeyValueStateManager.cpp b/extension-utils/src/controllers/keyvalue/KeyValueStateManager.cpp similarity index 99% rename from libminifi/src/controllers/keyvalue/KeyValueStateManager.cpp rename to extension-utils/src/controllers/keyvalue/KeyValueStateManager.cpp index a59a421179..583a3f59ec 100644 --- a/libminifi/src/controllers/keyvalue/KeyValueStateManager.cpp +++ b/extension-utils/src/controllers/keyvalue/KeyValueStateManager.cpp @@ -25,7 +25,7 @@ namespace org::apache::nifi::minifi::controllers { KeyValueStateManager::KeyValueStateManager( const utils::Identifier& id, gsl::not_null storage) - : StateManager(id), + : StateManagerImpl(id), storage_(storage), transaction_in_progress_(false), change_type_(ChangeType::NONE) { diff --git a/libminifi/src/controllers/keyvalue/KeyValueStateStorage.cpp b/extension-utils/src/controllers/keyvalue/KeyValueStateStorage.cpp similarity index 98% rename from libminifi/src/controllers/keyvalue/KeyValueStateStorage.cpp rename to extension-utils/src/controllers/keyvalue/KeyValueStateStorage.cpp index 5de969825a..2339b3e330 100644 --- a/libminifi/src/controllers/keyvalue/KeyValueStateStorage.cpp +++ b/extension-utils/src/controllers/keyvalue/KeyValueStateStorage.cpp @@ -63,7 +63,7 @@ core::StateManager::State KeyValueStateStorage::deserialize(const std::string& s } KeyValueStateStorage::KeyValueStateStorage(const std::string& name, const utils::Identifier& uuid) - : ControllerService(name, uuid) { + : ControllerServiceImpl(name, uuid) { } std::unique_ptr KeyValueStateStorage::getStateManager(const utils::Identifier& uuid) { diff --git a/extension-utils/src/core/ProcessContext.cpp b/extension-utils/src/core/ProcessContext.cpp new file mode 100644 index 0000000000..9dc9b02faa --- /dev/null +++ b/extension-utils/src/core/ProcessContext.cpp @@ -0,0 +1,36 @@ +/** + * 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 "minifi-cpp/core/ProcessContext.h" +#include "core/TypedValues.h" + +namespace org::apache::nifi::minifi::core { + +bool ProcessContext::getProperty(std::string_view name, detail::NotAFlowFile auto &value) const { + if constexpr (std::is_base_of_v>) { + std::string prop_str; + if (!getProperty(std::string{name}, prop_str)) { + return false; + } + value = std::decay_t(std::move(prop_str)); + return true; + } else { + return getProperty(name, value); + } +} + +} // namespace org::apache::nifi::minifi::core diff --git a/libminifi/src/serialization/FlowFileV3Serializer.cpp b/extension-utils/src/serialization/FlowFileV3Serializer.cpp similarity index 98% rename from libminifi/src/serialization/FlowFileV3Serializer.cpp rename to extension-utils/src/serialization/FlowFileV3Serializer.cpp index 3ecc4a5c38..77d327c802 100644 --- a/libminifi/src/serialization/FlowFileV3Serializer.cpp +++ b/extension-utils/src/serialization/FlowFileV3Serializer.cpp @@ -17,8 +17,9 @@ */ #include "serialization/FlowFileV3Serializer.h" -#include "core/ProcessSession.h" +#include "io/StreamPipe.h" #include "utils/gsl.h" +#include "core/FlowFile.h" namespace org::apache::nifi::minifi { diff --git a/libminifi/src/serialization/PayloadSerializer.cpp b/extension-utils/src/serialization/PayloadSerializer.cpp similarity index 83% rename from libminifi/src/serialization/PayloadSerializer.cpp rename to extension-utils/src/serialization/PayloadSerializer.cpp index 4da0d0bf3a..7fd22e171d 100644 --- a/libminifi/src/serialization/PayloadSerializer.cpp +++ b/extension-utils/src/serialization/PayloadSerializer.cpp @@ -17,18 +17,12 @@ */ #include "serialization/PayloadSerializer.h" -#include "core/ProcessSession.h" +#include "io/StreamPipe.h" -namespace org { -namespace apache { -namespace nifi { -namespace minifi { +namespace org::apache::nifi::minifi { int64_t PayloadSerializer::serialize(const std::shared_ptr& flowFile, const std::shared_ptr& out) { return reader_(flowFile, InputStreamPipe{*out}); } -} /* namespace minifi */ -} /* namespace nifi */ -} /* namespace apache */ -} /* namespace org */ +} // namespace org::apache::nifi::minifi diff --git a/extension-utils/src/utils/CallBackTimer.cpp b/extension-utils/src/utils/CallBackTimer.cpp new file mode 100644 index 0000000000..70e26dc7a6 --- /dev/null +++ b/extension-utils/src/utils/CallBackTimer.cpp @@ -0,0 +1,84 @@ +/** + * + * 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 "utils/CallBackTimer.h" +#include + +namespace org::apache::nifi::minifi::utils { + +CallBackTimer::CallBackTimer(std::chrono::milliseconds interval, const std::function& func) : execute_(false), func_(func), interval_(interval) { +} + +CallBackTimer::~CallBackTimer() { + stop(); + std::lock_guard guard(mtx_); + if (thd_.joinable()) { + thd_.join(); + } +} + +void CallBackTimer::stop() { + std::lock_guard guard(mtx_); + { + std::lock_guard cv_guard(cv_mtx_); + if (!execute_) { + return; + } + execute_ = false; + cv_.notify_all(); + } +} + +void CallBackTimer::start() { + std::lock_guard guard(mtx_); + { + std::lock_guard cv_guard(cv_mtx_); + + if (execute_) { + return; + } + } + + if (thd_.joinable()) { + thd_.join(); + } + + { + std::lock_guard cv_guard(cv_mtx_); + execute_ = true; + } + + thd_ = std::thread([this]() { + std::unique_lock lk(cv_mtx_); + while (execute_) { + if (cv_.wait_for(lk, interval_, [this]{return !execute_;})) { + break; + } + lk.unlock(); + this->func_(); + lk.lock(); + } + }); +} + +bool CallBackTimer::is_running() const { + std::lock_guard guard(mtx_); + return execute_ && thd_.joinable(); +} + +} // namespace org::apache::nifi::minifi::utils diff --git a/libminifi/src/utils/ListingStateManager.cpp b/extension-utils/src/utils/ListingStateManager.cpp similarity index 95% rename from libminifi/src/utils/ListingStateManager.cpp rename to extension-utils/src/utils/ListingStateManager.cpp index 9df90c3c55..4036016537 100644 --- a/libminifi/src/utils/ListingStateManager.cpp +++ b/extension-utils/src/utils/ListingStateManager.cpp @@ -22,8 +22,8 @@ namespace org::apache::nifi::minifi::utils { -const std::string ListingStateManager::LATEST_LISTED_OBJECT_PREFIX = "listed_key."; -const std::string ListingStateManager::LATEST_LISTED_OBJECT_TIMESTAMP = "listed_timestamp"; +static const std::string LATEST_LISTED_OBJECT_PREFIX = "listed_key."; +static const std::string LATEST_LISTED_OBJECT_TIMESTAMP = "listed_timestamp"; bool ListingState::wasObjectListedAlready(const ListedObject &object) const { return listed_key_timestamp > object.getLastModified() || diff --git a/libminifi/src/utils/ProcessorConfigUtils.cpp b/extension-utils/src/utils/ProcessorConfigUtils.cpp similarity index 100% rename from libminifi/src/utils/ProcessorConfigUtils.cpp rename to extension-utils/src/utils/ProcessorConfigUtils.cpp diff --git a/libminifi/src/utils/file/FileReaderCallback.cpp b/extension-utils/src/utils/file/FileReaderCallback.cpp similarity index 98% rename from libminifi/src/utils/file/FileReaderCallback.cpp rename to extension-utils/src/utils/file/FileReaderCallback.cpp index 8239ca88fb..906f09580b 100644 --- a/libminifi/src/utils/file/FileReaderCallback.cpp +++ b/extension-utils/src/utils/file/FileReaderCallback.cpp @@ -20,7 +20,7 @@ #include #include -#include "core/logging/LoggerConfiguration.h" +#include "core/logging/LoggerFactory.h" #include "utils/StringUtils.h" namespace { diff --git a/libminifi/src/utils/file/FileWriterCallback.cpp b/extension-utils/src/utils/file/FileWriterCallback.cpp similarity index 100% rename from libminifi/src/utils/file/FileWriterCallback.cpp rename to extension-utils/src/utils/file/FileWriterCallback.cpp diff --git a/libminifi/src/utils/net/Ssl.cpp b/extension-utils/src/utils/net/Ssl.cpp similarity index 100% rename from libminifi/src/utils/net/Ssl.cpp rename to extension-utils/src/utils/net/Ssl.cpp diff --git a/libminifi/src/utils/net/TcpServer.cpp b/extension-utils/src/utils/net/TcpServer.cpp similarity index 100% rename from libminifi/src/utils/net/TcpServer.cpp rename to extension-utils/src/utils/net/TcpServer.cpp diff --git a/libminifi/src/utils/net/UdpServer.cpp b/extension-utils/src/utils/net/UdpServer.cpp similarity index 100% rename from libminifi/src/utils/net/UdpServer.cpp rename to extension-utils/src/utils/net/UdpServer.cpp diff --git a/extensions/ExtensionHeader.txt b/extensions/ExtensionHeader.txt index 9a9da14b4b..0708374784 100644 --- a/extensions/ExtensionHeader.txt +++ b/extensions/ExtensionHeader.txt @@ -19,11 +19,3 @@ cmake_minimum_required(VERSION 3.24) - -include_directories(../../libminifi/include ../../libminifi/include/core) - -if(WIN32) - include_directories(../../libminifi/opsys/win) -else() - include_directories(../../libminifi/opsys/posix) -endif() diff --git a/extensions/aws/AWSCredentialsProvider.cpp b/extensions/aws/AWSCredentialsProvider.cpp index d9bc7f7007..a4ed3c42ec 100644 --- a/extensions/aws/AWSCredentialsProvider.cpp +++ b/extensions/aws/AWSCredentialsProvider.cpp @@ -23,21 +23,17 @@ #include "aws/core/auth/AWSCredentialsProviderChain.h" #include "properties/Properties.h" -namespace org { -namespace apache { -namespace nifi { -namespace minifi { -namespace aws { +namespace org::apache::nifi::minifi::aws { AWSCredentialsProvider::AWSCredentialsProvider( bool use_default_credentials, - const std::string &access_key, - const std::string &secret_key, - const std::string &credentials_file) + std::string access_key, + std::string secret_key, + std::string credentials_file) : use_default_credentials_(use_default_credentials) - , access_key_(access_key) - , secret_key_(secret_key) - , credentials_file_(credentials_file) { + , access_key_(std::move(access_key)) + , secret_key_(std::move(secret_key)) + , credentials_file_(std::move(credentials_file)) { } void AWSCredentialsProvider::setUseDefaultCredentials(bool use_default_credentials) { @@ -77,7 +73,7 @@ std::optional AWSCredentialsProvider::getAWSCredentia } if (!credentials_file_.empty()) { - auto properties = std::make_shared(); + auto properties = minifi::Properties::create(); properties->loadConfigureFile(credentials_file_.c_str()); std::string access_key; std::string secret_key; @@ -91,8 +87,4 @@ std::optional AWSCredentialsProvider::getAWSCredentia return std::nullopt; } -} // namespace aws -} // namespace minifi -} // namespace nifi -} // namespace apache -} // namespace org +} // namespace org::apache::nifi::minifi::aws diff --git a/extensions/aws/AWSCredentialsProvider.h b/extensions/aws/AWSCredentialsProvider.h index 0a9a5a0351..664f847094 100644 --- a/extensions/aws/AWSCredentialsProvider.h +++ b/extensions/aws/AWSCredentialsProvider.h @@ -27,7 +27,7 @@ #include "aws/core/auth/AWSCredentials.h" #include "utils/AWSInitializer.h" #include "core/logging/Logger.h" -#include "core/logging/LoggerConfiguration.h" +#include "core/logging/LoggerFactory.h" namespace org { namespace apache { @@ -39,9 +39,9 @@ class AWSCredentialsProvider { public: explicit AWSCredentialsProvider( bool use_default_credentials = false, - const std::string &access_key = "", - const std::string &secret_key = "", - const std::string &credentials_file = ""); + std::string access_key = "", + std::string secret_key = "", + std::string credentials_file = ""); void setUseDefaultCredentials(bool use_default_credentials); void setAccessKey(const std::string &access_key); void setSecretKey(const std::string &secret_key); diff --git a/extensions/aws/controllerservices/AWSCredentialsService.h b/extensions/aws/controllerservices/AWSCredentialsService.h index 42002a9feb..f06bc6da80 100644 --- a/extensions/aws/controllerservices/AWSCredentialsService.h +++ b/extensions/aws/controllerservices/AWSCredentialsService.h @@ -27,7 +27,7 @@ #include "utils/AWSInitializer.h" #include "core/controller/ControllerService.h" -#include "core/logging/LoggerConfiguration.h" +#include "core/logging/LoggerFactory.h" #include "core/PropertyDefinition.h" #include "core/PropertyDefinitionBuilder.h" #include "core/PropertyType.h" @@ -37,14 +37,14 @@ class AWSCredentialsServiceTestAccessor; namespace org::apache::nifi::minifi::aws::controllers { -class AWSCredentialsService : public core::controller::ControllerService { +class AWSCredentialsService : public core::controller::ControllerServiceImpl { public: explicit AWSCredentialsService(std::string_view name, const minifi::utils::Identifier &uuid = {}) - : ControllerService(name, uuid) { + : ControllerServiceImpl(name, uuid) { } explicit AWSCredentialsService(std::string_view name, const std::shared_ptr& /*configuration*/) - : ControllerService(name) { + : ControllerServiceImpl(name) { } EXTENSIONAPI static constexpr const char* Description = "Manages the Amazon Web Services (AWS) credentials for an AWS account. This allows for multiple " diff --git a/extensions/aws/processors/S3Processor.cpp b/extensions/aws/processors/S3Processor.cpp index 9c40a313b6..eb2b2c528c 100644 --- a/extensions/aws/processors/S3Processor.cpp +++ b/extensions/aws/processors/S3Processor.cpp @@ -32,12 +32,12 @@ namespace org::apache::nifi::minifi::aws::processors { S3Processor::S3Processor(std::string_view name, const minifi::utils::Identifier& uuid, std::shared_ptr logger) - : core::Processor(name, uuid), + : core::ProcessorImpl(name, uuid), logger_(std::move(logger)) { } S3Processor::S3Processor(std::string_view name, const minifi::utils::Identifier& uuid, std::shared_ptr logger, std::unique_ptr s3_request_sender) - : core::Processor(name, uuid), + : core::ProcessorImpl(name, uuid), logger_(std::move(logger)), s3_wrapper_(std::move(s3_request_sender)) { } diff --git a/extensions/aws/processors/S3Processor.h b/extensions/aws/processors/S3Processor.h index 3bfb8998e1..df273b3433 100644 --- a/extensions/aws/processors/S3Processor.h +++ b/extensions/aws/processors/S3Processor.h @@ -31,12 +31,13 @@ #include "aws/core/auth/AWSCredentialsProvider.h" #include "S3Wrapper.h" #include "AWSCredentialsProvider.h" +#include "core/Property.h" #include "core/PropertyDefinition.h" #include "core/PropertyDefinitionBuilder.h" #include "core/PropertyType.h" #include "core/Processor.h" #include "core/logging/Logger.h" -#include "core/logging/LoggerConfiguration.h" +#include "core/logging/LoggerFactory.h" #include "utils/OptionalUtils.h" namespace org::apache::nifi::minifi::aws::processors { @@ -94,7 +95,7 @@ struct CommonProperties { std::string endpoint_override_url; }; -class S3Processor : public core::Processor { +class S3Processor : public core::ProcessorImpl { public: EXTENSIONAPI static constexpr auto Bucket = core::PropertyDefinitionBuilder<>::createProperty("Bucket") .withDescription("The S3 bucket") diff --git a/extensions/aws/s3/MultipartUploadStateStorage.cpp b/extensions/aws/s3/MultipartUploadStateStorage.cpp index aa9c49e4ef..2e9a79d5e0 100644 --- a/extensions/aws/s3/MultipartUploadStateStorage.cpp +++ b/extensions/aws/s3/MultipartUploadStateStorage.cpp @@ -17,6 +17,7 @@ #include "MultipartUploadStateStorage.h" #include "utils/StringUtils.h" +#include "core/Property.h" namespace org::apache::nifi::minifi::aws::s3 { diff --git a/extensions/aws/s3/MultipartUploadStateStorage.h b/extensions/aws/s3/MultipartUploadStateStorage.h index 2da6df063f..10360d305d 100644 --- a/extensions/aws/s3/MultipartUploadStateStorage.h +++ b/extensions/aws/s3/MultipartUploadStateStorage.h @@ -28,7 +28,7 @@ #include "core/StateManager.h" #include "core/logging/Logger.h" -#include "core/logging/LoggerConfiguration.h" +#include "core/logging/LoggerFactory.h" #include "aws/core/utils/DateTime.h" #include "utils/file/FileUtils.h" #include "properties/Configure.h" diff --git a/extensions/aws/s3/S3RequestSender.h b/extensions/aws/s3/S3RequestSender.h index 2c5a850bac..a2cd2078c5 100644 --- a/extensions/aws/s3/S3RequestSender.h +++ b/extensions/aws/s3/S3RequestSender.h @@ -50,7 +50,7 @@ #include "aws/s3/model/AbortMultipartUploadRequest.h" #include "aws/s3/model/AbortMultipartUploadResult.h" #include "core/logging/Logger.h" -#include "core/logging/LoggerConfiguration.h" +#include "core/logging/LoggerFactory.h" #include "utils/AWSInitializer.h" namespace org::apache::nifi::minifi::aws::s3 { diff --git a/extensions/aws/s3/S3Wrapper.h b/extensions/aws/s3/S3Wrapper.h index de906654c0..9bd4725a76 100644 --- a/extensions/aws/s3/S3Wrapper.h +++ b/extensions/aws/s3/S3Wrapper.h @@ -34,7 +34,7 @@ #include "aws/s3/model/ObjectCannedACL.h" #include "core/logging/Logger.h" -#include "core/logging/LoggerConfiguration.h" +#include "core/logging/LoggerFactory.h" #include "utils/AWSInitializer.h" #include "utils/OptionalUtils.h" #include "utils/StringUtils.h" @@ -44,6 +44,9 @@ #include "Exception.h" #include "MultipartUploadStateStorage.h" #include "range/v3/algorithm/find.hpp" +#include "utils/Literals.h" +#include "io/InputStream.h" +#include "io/OutputStream.h" namespace org::apache::nifi::minifi::aws::s3 { diff --git a/extensions/aws/tests/AWSCredentialsServiceTest.cpp b/extensions/aws/tests/AWSCredentialsServiceTest.cpp index 4eacaf3cfa..ccaf91aeff 100644 --- a/extensions/aws/tests/AWSCredentialsServiceTest.cpp +++ b/extensions/aws/tests/AWSCredentialsServiceTest.cpp @@ -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::static_pointer_cast(aws_credentials_service->getControllerServiceImplementation()); + auto aws_credentials_impl = std::dynamic_pointer_cast(aws_credentials_service->getControllerServiceImplementation()); // 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::static_pointer_cast(aws_credentials_service->getControllerServiceImplementation()); + auto aws_credentials_impl = std::dynamic_pointer_cast(aws_credentials_service->getControllerServiceImplementation()); // Check intial credentials REQUIRE(aws_credentials_impl->getAWSCredentials()); diff --git a/extensions/aws/utils/AWSSdkLogger.cpp b/extensions/aws/utils/AWSSdkLogger.cpp index 28ad55e934..cb67e45516 100644 --- a/extensions/aws/utils/AWSSdkLogger.cpp +++ b/extensions/aws/utils/AWSSdkLogger.cpp @@ -20,6 +20,7 @@ #include "AWSSdkLogger.h" #include +#include #include "aws/core/utils/logging/LogLevel.h" #include "utils/gsl.h" diff --git a/extensions/aws/utils/AWSSdkLogger.h b/extensions/aws/utils/AWSSdkLogger.h index 04bb77c426..536336eb02 100644 --- a/extensions/aws/utils/AWSSdkLogger.h +++ b/extensions/aws/utils/AWSSdkLogger.h @@ -23,7 +23,7 @@ #include "aws/core/utils/logging/LogSystemInterface.h" #include "core/logging/Logger.h" -#include "core/logging/LoggerConfiguration.h" +#include "core/logging/LoggerFactory.h" namespace org::apache::nifi::minifi::aws::utils { diff --git a/extensions/azure/controllerservices/AzureStorageCredentialsService.h b/extensions/azure/controllerservices/AzureStorageCredentialsService.h index cb0a0b0483..5be6a6f096 100644 --- a/extensions/azure/controllerservices/AzureStorageCredentialsService.h +++ b/extensions/azure/controllerservices/AzureStorageCredentialsService.h @@ -23,7 +23,7 @@ #include #include "core/controller/ControllerService.h" -#include "core/logging/LoggerConfiguration.h" +#include "core/logging/LoggerFactory.h" #include "core/PropertyDefinition.h" #include "core/PropertyDefinitionBuilder.h" #include "core/PropertyType.h" @@ -32,7 +32,7 @@ namespace org::apache::nifi::minifi::azure::controllers { -class AzureStorageCredentialsService : public core::controller::ControllerService { +class AzureStorageCredentialsService : public core::controller::ControllerServiceImpl { 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."; @@ -76,11 +76,11 @@ class AzureStorageCredentialsService : public core::controller::ControllerServic ADD_COMMON_VIRTUAL_FUNCTIONS_FOR_CONTROLLER_SERVICES explicit AzureStorageCredentialsService(std::string_view name, const minifi::utils::Identifier& uuid = {}) - : ControllerService(name, uuid) { + : ControllerServiceImpl(name, uuid) { } explicit AzureStorageCredentialsService(std::string_view name, const std::shared_ptr& /*configuration*/) - : ControllerService(name) { + : ControllerServiceImpl(name) { } void initialize() override; diff --git a/extensions/azure/processors/AzureBlobStorageSingleBlobProcessorBase.h b/extensions/azure/processors/AzureBlobStorageSingleBlobProcessorBase.h index aff7f501d7..d65e16d068 100644 --- a/extensions/azure/processors/AzureBlobStorageSingleBlobProcessorBase.h +++ b/extensions/azure/processors/AzureBlobStorageSingleBlobProcessorBase.h @@ -26,7 +26,7 @@ #include #include "AzureBlobStorageProcessorBase.h" -#include "PropertyDefinition.h" +#include "core/PropertyDefinition.h" #include "utils/ArrayUtils.h" namespace org::apache::nifi::minifi::azure::processors { diff --git a/extensions/azure/processors/AzureDataLakeStorageProcessorBase.h b/extensions/azure/processors/AzureDataLakeStorageProcessorBase.h index a5a5030d75..3eb5aa125b 100644 --- a/extensions/azure/processors/AzureDataLakeStorageProcessorBase.h +++ b/extensions/azure/processors/AzureDataLakeStorageProcessorBase.h @@ -28,7 +28,7 @@ #include "core/Property.h" #include "core/PropertyDefinition.h" #include "core/logging/Logger.h" -#include "core/logging/LoggerConfiguration.h" +#include "core/logging/LoggerFactory.h" #include "storage/AzureDataLakeStorage.h" #include "utils/ArrayUtils.h" #include "AzureStorageProcessorBase.h" diff --git a/extensions/azure/processors/AzureStorageProcessorBase.h b/extensions/azure/processors/AzureStorageProcessorBase.h index 1f2a1ce63f..c014895aab 100644 --- a/extensions/azure/processors/AzureStorageProcessorBase.h +++ b/extensions/azure/processors/AzureStorageProcessorBase.h @@ -26,7 +26,7 @@ #include #include -#include "PropertyDefinition.h" +#include "core/PropertyDefinition.h" #include "core/Property.h" #include "core/PropertyDefinitionBuilder.h" #include "core/Processor.h" @@ -35,7 +35,7 @@ namespace org::apache::nifi::minifi::azure::processors { -class AzureStorageProcessorBase : public core::Processor { +class AzureStorageProcessorBase : public core::ProcessorImpl { public: EXTENSIONAPI static constexpr auto AzureStorageCredentialsService = core::PropertyDefinitionBuilder<>::createProperty("Azure Storage Credentials Service") .withDescription("Name of the Azure Storage Credentials Service used to retrieve the connection string from.") @@ -43,7 +43,7 @@ class AzureStorageProcessorBase : public core::Processor { EXTENSIONAPI static constexpr auto Properties = std::to_array({AzureStorageCredentialsService}); AzureStorageProcessorBase(std::string_view name, const minifi::utils::Identifier& uuid, const std::shared_ptr& logger) - : core::Processor(name, uuid), + : core::ProcessorImpl(name, uuid), logger_(logger) { } diff --git a/extensions/azure/processors/DeleteAzureBlobStorage.h b/extensions/azure/processors/DeleteAzureBlobStorage.h index e08c55b1ab..3bf2f3f816 100644 --- a/extensions/azure/processors/DeleteAzureBlobStorage.h +++ b/extensions/azure/processors/DeleteAzureBlobStorage.h @@ -30,7 +30,7 @@ #include "core/PropertyDefinition.h" #include "core/PropertyDefinitionBuilder.h" #include "AzureBlobStorageSingleBlobProcessorBase.h" -#include "core/logging/LoggerConfiguration.h" +#include "core/logging/LoggerFactory.h" #include "utils/ArrayUtils.h" template diff --git a/extensions/azure/processors/FetchAzureBlobStorage.h b/extensions/azure/processors/FetchAzureBlobStorage.h index 9a0808407e..57111c54bc 100644 --- a/extensions/azure/processors/FetchAzureBlobStorage.h +++ b/extensions/azure/processors/FetchAzureBlobStorage.h @@ -26,10 +26,10 @@ #include #include -#include "PropertyDefinition.h" +#include "core/PropertyDefinition.h" #include "core/Property.h" #include "AzureBlobStorageSingleBlobProcessorBase.h" -#include "core/logging/LoggerConfiguration.h" +#include "core/logging/LoggerFactory.h" #include "utils/ArrayUtils.h" template diff --git a/extensions/azure/processors/ListAzureBlobStorage.h b/extensions/azure/processors/ListAzureBlobStorage.h index dd1a350673..a6ee36b39e 100644 --- a/extensions/azure/processors/ListAzureBlobStorage.h +++ b/extensions/azure/processors/ListAzureBlobStorage.h @@ -29,7 +29,7 @@ #include "core/Property.h" #include "core/PropertyDefinition.h" #include "AzureBlobStorageProcessorBase.h" -#include "core/logging/LoggerConfiguration.h" +#include "core/logging/LoggerFactory.h" #include "utils/AzureEnums.h" namespace org::apache::nifi::minifi::azure::processors { diff --git a/extensions/azure/processors/PutAzureBlobStorage.h b/extensions/azure/processors/PutAzureBlobStorage.h index 60dfd964c0..fb2ad6765d 100644 --- a/extensions/azure/processors/PutAzureBlobStorage.h +++ b/extensions/azure/processors/PutAzureBlobStorage.h @@ -26,11 +26,11 @@ #include #include -#include "ProcessContext.h" -#include "PropertyDefinition.h" -#include "PropertyType.h" +#include "core/ProcessContext.h" +#include "core/PropertyDefinition.h" +#include "core/PropertyType.h" #include "core/Property.h" -#include "core/logging/LoggerConfiguration.h" +#include "core/logging/LoggerFactory.h" #include "AzureBlobStorageSingleBlobProcessorBase.h" #include "io/StreamPipe.h" #include "utils/ArrayUtils.h" diff --git a/extensions/azure/storage/AzureBlobStorage.h b/extensions/azure/storage/AzureBlobStorage.h index 305da54516..51b0d6e1ed 100644 --- a/extensions/azure/storage/AzureBlobStorage.h +++ b/extensions/azure/storage/AzureBlobStorage.h @@ -27,9 +27,10 @@ #include "BlobStorageClient.h" #include "azure/storage/blobs.hpp" #include "core/logging/Logger.h" -#include "core/logging/LoggerConfiguration.h" +#include "core/logging/LoggerFactory.h" #include "utils/gsl.h" #include "utils/ListingStateManager.h" +#include "io/OutputStream.h" namespace org::apache::nifi::minifi::azure::storage { diff --git a/extensions/azure/storage/AzureBlobStorageClient.cpp b/extensions/azure/storage/AzureBlobStorageClient.cpp index b64c1e367b..629313b700 100644 --- a/extensions/azure/storage/AzureBlobStorageClient.cpp +++ b/extensions/azure/storage/AzureBlobStorageClient.cpp @@ -31,7 +31,7 @@ namespace org::apache::nifi::minifi::azure::storage { namespace { -class AzureBlobStorageInputStream : public io::InputStream { +class AzureBlobStorageInputStream : public io::InputStreamImpl { public: explicit AzureBlobStorageInputStream(Azure::Storage::Blobs::Models::DownloadBlobResult&& result) : result_(std::move(result)) { @@ -102,7 +102,7 @@ std::unique_ptr AzureBlobStorageClient::fetchBlob(const FetchAz if (params.range_start || params.range_length) { Azure::Core::Http::HttpRange range; if (params.range_start) { - range.Offset = *params.range_start; + range.Offset = gsl::narrow(*params.range_start); } if (params.range_length) { diff --git a/extensions/azure/storage/AzureBlobStorageClient.h b/extensions/azure/storage/AzureBlobStorageClient.h index 29455e8882..9b782114ae 100644 --- a/extensions/azure/storage/AzureBlobStorageClient.h +++ b/extensions/azure/storage/AzureBlobStorageClient.h @@ -28,7 +28,7 @@ #include "BlobStorageClient.h" #include "azure/storage/blobs.hpp" #include "core/logging/Logger.h" -#include "core/logging/LoggerConfiguration.h" +#include "core/logging/LoggerFactory.h" namespace org::apache::nifi::minifi::azure::storage { diff --git a/extensions/azure/storage/AzureDataLakeStorage.h b/extensions/azure/storage/AzureDataLakeStorage.h index 587ec5f0d4..fcfbe1c5dc 100644 --- a/extensions/azure/storage/AzureDataLakeStorage.h +++ b/extensions/azure/storage/AzureDataLakeStorage.h @@ -26,9 +26,10 @@ #include #include "core/logging/Logger.h" -#include "core/logging/LoggerConfiguration.h" +#include "core/logging/LoggerFactory.h" #include "DataLakeStorageClient.h" #include "utils/ListingStateManager.h" +#include "io/OutputStream.h" namespace org::apache::nifi::minifi::azure::storage { diff --git a/extensions/azure/storage/AzureDataLakeStorageClient.h b/extensions/azure/storage/AzureDataLakeStorageClient.h index c8eecf0a21..db11cbdd4d 100644 --- a/extensions/azure/storage/AzureDataLakeStorageClient.h +++ b/extensions/azure/storage/AzureDataLakeStorageClient.h @@ -28,7 +28,7 @@ #include "DataLakeStorageClient.h" #include "core/logging/Logger.h" -#include "core/logging/LoggerConfiguration.h" +#include "core/logging/LoggerFactory.h" #include "utils/span.h" namespace org::apache::nifi::minifi::azure::storage { @@ -74,7 +74,7 @@ class AzureDataLakeStorageClient : public DataLakeStorageClient { std::vector listDirectory(const ListAzureDataLakeStorageParameters& params) override; private: - class AzureDataLakeStorageInputStream : public io::InputStream { + class AzureDataLakeStorageInputStream : public io::InputStreamImpl { public: explicit AzureDataLakeStorageInputStream(Azure::Storage::Files::DataLake::Models::DownloadFileResult&& result) : result_(std::move(result)) { diff --git a/extensions/azure/utils/AzureSdkLogger.h b/extensions/azure/utils/AzureSdkLogger.h index 45107e736c..ce67b14720 100644 --- a/extensions/azure/utils/AzureSdkLogger.h +++ b/extensions/azure/utils/AzureSdkLogger.h @@ -22,7 +22,7 @@ #include #include "core/logging/Logger.h" -#include "core/logging/LoggerConfiguration.h" +#include "core/logging/LoggerFactory.h" namespace org::apache::nifi::minifi::azure::utils { diff --git a/extensions/bustache/ApplyTemplate.h b/extensions/bustache/ApplyTemplate.h index f2afa71457..e06e0259f4 100644 --- a/extensions/bustache/ApplyTemplate.h +++ b/extensions/bustache/ApplyTemplate.h @@ -23,21 +23,19 @@ #include #include -#include "PropertyDefinition.h" #include "core/Processor.h" #include "core/ProcessSession.h" #include "core/PropertyDefinitionBuilder.h" -#include "core/FlowFile.h" namespace org::apache::nifi::minifi::processors { /** * Applies a mustache template using incoming attributes as template parameters. */ -class ApplyTemplate : public core::Processor { +class ApplyTemplate final : public core::ProcessorImpl { public: - explicit ApplyTemplate(std::string name, const utils::Identifier& uuid = {}) - : Processor(std::move(name), uuid) {} + explicit ApplyTemplate(const std::string_view name, const utils::Identifier& uuid = {}) + : ProcessorImpl(name, uuid) {} EXTENSIONAPI static constexpr const char* Description = "Applies the mustache template specified by the \"Template\" property and writes the output to the flow file content. " "FlowFile attributes are used as template parameters."; diff --git a/extensions/civetweb/processors/ListenHTTP.cpp b/extensions/civetweb/processors/ListenHTTP.cpp index b50e78b571..1e12f72b16 100644 --- a/extensions/civetweb/processors/ListenHTTP.cpp +++ b/extensions/civetweb/processors/ListenHTTP.cpp @@ -254,7 +254,7 @@ bool ListenHTTP::processRequestBuffer(core::ProcessSession& session) { namespace { -class MgConnectionInputStream : public io::InputStream { +class MgConnectionInputStream : public io::InputStreamImpl { public: MgConnectionInputStream(struct mg_connection* conn, std::optional size): conn_(conn), netstream_size_limit_(size) {} @@ -275,7 +275,7 @@ class MgConnectionInputStream : public io::InputStream { std::optional netstream_size_limit_; // how much can we read from conn_ }; -class MgConnectionOutputStream : public io::OutputStream { +class MgConnectionOutputStream : public io::StreamImpl, public virtual io::OutputStreamImpl { public: explicit MgConnectionOutputStream(struct mg_connection* conn): conn_(conn) {} @@ -548,7 +548,7 @@ void ListenHTTP::notifyStop() { } std::set ListenHTTP::getOutGoingConnections(const std::string &relationship) { - auto result = core::Processor::getOutGoingConnections(relationship); + auto result = core::ProcessorImpl::getOutGoingConnections(relationship); if (relationship == Self.name) { result.insert(this); } diff --git a/extensions/civetweb/processors/ListenHTTP.h b/extensions/civetweb/processors/ListenHTTP.h index 1567c387a7..4a0763df7c 100644 --- a/extensions/civetweb/processors/ListenHTTP.h +++ b/extensions/civetweb/processors/ListenHTTP.h @@ -34,7 +34,7 @@ #include "core/PropertyType.h" #include "core/RelationshipDefinition.h" #include "core/Core.h" -#include "core/logging/LoggerConfiguration.h" +#include "core/logging/LoggerFactory.h" #include "utils/MinifiConcurrentQueue.h" #include "utils/gsl.h" #include "utils/Export.h" @@ -47,7 +47,7 @@ struct ListenHTTPTestAccessor; namespace org::apache::nifi::minifi::processors { -class ListenHTTP : public core::Processor { +class ListenHTTP : public core::ProcessorImpl { private: static constexpr std::string_view DEFAULT_BUFFER_SIZE_STR = "5"; static constexpr core::RelationshipDefinition Self{"__self__", "Marks the FlowFile to be owned by this processor"}; @@ -56,7 +56,7 @@ class ListenHTTP : public core::Processor { friend struct ::org::apache::nifi::minifi::test::ListenHTTPTestAccessor; explicit ListenHTTP(std::string_view name, const utils::Identifier& uuid = {}) - : Processor(name, uuid) { + : ProcessorImpl(name, uuid) { callbacks_.log_message = &logMessage; callbacks_.log_access = &logAccess; } diff --git a/extensions/civetweb/tests/ListenHTTPTests.cpp b/extensions/civetweb/tests/ListenHTTPTests.cpp index cc9de6f548..f67a3f89fb 100644 --- a/extensions/civetweb/tests/ListenHTTPTests.cpp +++ b/extensions/civetweb/tests/ListenHTTPTests.cpp @@ -125,7 +125,7 @@ class ListenHTTPTestsFixture { } void create_ssl_context_service(const char* ca, const char* client_cert) { - auto config = std::make_shared(); + auto config = std::make_shared(); auto executable_dir = minifi::utils::file::FileUtils::get_executable_dir(); if (ca != nullptr) { config->set(minifi::Configure::nifi_security_client_ca_certificate, (executable_dir / "resources" / ca).string()); @@ -135,7 +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("SSLContextService", config); + ssl_context_service = std::make_shared("SSLContextService", config); ssl_context_service->onEnable(); } diff --git a/extensions/couchbase/controllerservices/CouchbaseClusterService.h b/extensions/couchbase/controllerservices/CouchbaseClusterService.h index 2174497233..ba20640044 100644 --- a/extensions/couchbase/controllerservices/CouchbaseClusterService.h +++ b/extensions/couchbase/controllerservices/CouchbaseClusterService.h @@ -30,7 +30,7 @@ #include "core/PropertyType.h" #include "couchbase/cluster.hxx" #include "core/ProcessContext.h" -#include "core/logging/LoggerConfiguration.h" +#include "core/logging/LoggerFactory.h" #include "controllers/SSLContextService.h" namespace org::apache::nifi::minifi::couchbase { @@ -101,14 +101,14 @@ class CouchbaseClient { namespace controllers { -class CouchbaseClusterService : public core::controller::ControllerService { +class CouchbaseClusterService : public core::controller::ControllerServiceImpl { public: explicit CouchbaseClusterService(std::string_view name, const minifi::utils::Identifier &uuid = {}) - : ControllerService(name, uuid) { + : ControllerServiceImpl(name, uuid) { } explicit CouchbaseClusterService(std::string_view name, const std::shared_ptr& /*configuration*/) - : ControllerService(name) { + : ControllerServiceImpl(name) { } EXTENSIONAPI static constexpr const char* Description = "Provides a centralized Couchbase connection and bucket passwords management. Bucket passwords can be specified via dynamic properties."; diff --git a/extensions/couchbase/processors/GetCouchbaseKey.h b/extensions/couchbase/processors/GetCouchbaseKey.h index 4951c18eff..bec91841cd 100644 --- a/extensions/couchbase/processors/GetCouchbaseKey.h +++ b/extensions/couchbase/processors/GetCouchbaseKey.h @@ -23,7 +23,7 @@ #include "core/AbstractProcessor.h" #include "core/ProcessSession.h" -#include "core/logging/LoggerConfiguration.h" +#include "core/logging/LoggerFactory.h" #include "CouchbaseClusterService.h" namespace org::apache::nifi::minifi::couchbase::processors { diff --git a/extensions/couchbase/processors/PutCouchbaseKey.h b/extensions/couchbase/processors/PutCouchbaseKey.h index 1991488ed5..a1e3601af3 100644 --- a/extensions/couchbase/processors/PutCouchbaseKey.h +++ b/extensions/couchbase/processors/PutCouchbaseKey.h @@ -24,7 +24,7 @@ #include "core/AbstractProcessor.h" #include "core/ProcessSession.h" #include "utils/Enum.h" -#include "core/logging/LoggerConfiguration.h" +#include "core/logging/LoggerFactory.h" #include "CouchbaseClusterService.h" #include "couchbase/persist_to.hxx" #include "couchbase/replicate_to.hxx" diff --git a/extensions/couchbase/tests/GetCouchbaseKeyTests.cpp b/extensions/couchbase/tests/GetCouchbaseKeyTests.cpp index 0d2e5b9109..185d99ac01 100644 --- a/extensions/couchbase/tests/GetCouchbaseKeyTests.cpp +++ b/extensions/couchbase/tests/GetCouchbaseKeyTests.cpp @@ -46,7 +46,8 @@ class GetCouchbaseKeyTestController : public TestController { LogTestController::getInstance().setDebug(); LogTestController::getInstance().setDebug(); auto controller_service_node = controller_.plan->addController("MockCouchbaseClusterService", "MockCouchbaseClusterService"); - mock_couchbase_cluster_service_ = std::static_pointer_cast(controller_service_node->getControllerServiceImplementation()); + mock_couchbase_cluster_service_ = std::dynamic_pointer_cast(controller_service_node->getControllerServiceImplementation()); + gsl_Assert(mock_couchbase_cluster_service_); proc_->setProperty(processors::GetCouchbaseKey::CouchbaseClusterControllerService, "MockCouchbaseClusterService"); } diff --git a/extensions/couchbase/tests/PutCouchbaseKeyTests.cpp b/extensions/couchbase/tests/PutCouchbaseKeyTests.cpp index 84afe362b1..56970289f8 100644 --- a/extensions/couchbase/tests/PutCouchbaseKeyTests.cpp +++ b/extensions/couchbase/tests/PutCouchbaseKeyTests.cpp @@ -50,7 +50,8 @@ class PutCouchbaseKeyTestController : public TestController { LogTestController::getInstance().setDebug(); LogTestController::getInstance().setDebug(); auto controller_service_node = controller_.plan->addController("MockCouchbaseClusterService", "MockCouchbaseClusterService"); - mock_couchbase_cluster_service_ = std::static_pointer_cast(controller_service_node->getControllerServiceImplementation()); + mock_couchbase_cluster_service_ = std::dynamic_pointer_cast(controller_service_node->getControllerServiceImplementation()); + gsl_Assert(mock_couchbase_cluster_service_); proc_->setProperty(processors::PutCouchbaseKey::CouchbaseClusterControllerService, "MockCouchbaseClusterService"); } diff --git a/extensions/elasticsearch/ElasticsearchCredentialsControllerService.h b/extensions/elasticsearch/ElasticsearchCredentialsControllerService.h index e9a8540112..3089c3f498 100644 --- a/extensions/elasticsearch/ElasticsearchCredentialsControllerService.h +++ b/extensions/elasticsearch/ElasticsearchCredentialsControllerService.h @@ -30,7 +30,7 @@ namespace org::apache::nifi::minifi::extensions::elasticsearch { -class ElasticsearchCredentialsControllerService : public core::controller::ControllerService { +class ElasticsearchCredentialsControllerService : public core::controller::ControllerServiceImpl { public: EXTENSIONAPI static constexpr const char* Description = "Elasticsearch/Opensearch Credentials Controller Service"; @@ -57,7 +57,7 @@ class ElasticsearchCredentialsControllerService : public core::controller::Contr EXTENSIONAPI static constexpr bool SupportsDynamicProperties = false; ADD_COMMON_VIRTUAL_FUNCTIONS_FOR_CONTROLLER_SERVICES - using ControllerService::ControllerService; + using ControllerServiceImpl::ControllerServiceImpl; void initialize() override; diff --git a/extensions/elasticsearch/PostElasticsearch.h b/extensions/elasticsearch/PostElasticsearch.h index b36cc4d825..5274bf25ec 100644 --- a/extensions/elasticsearch/PostElasticsearch.h +++ b/extensions/elasticsearch/PostElasticsearch.h @@ -34,12 +34,12 @@ namespace org::apache::nifi::minifi::extensions::elasticsearch { -class PostElasticsearch : public core::Processor { +class PostElasticsearch : public core::ProcessorImpl { public: EXTENSIONAPI static constexpr const char* Description = "An Elasticsearch/Opensearch post processor that uses the Elasticsearch/Opensearch _bulk REST API."; explicit PostElasticsearch(const std::string& name, const utils::Identifier& uuid = {}) - : Processor(name, uuid) { + : ProcessorImpl(name, uuid) { } ~PostElasticsearch() override = default; diff --git a/extensions/elasticsearch/tests/MockElastic.h b/extensions/elasticsearch/tests/MockElastic.h index 2a1a6d1e5f..71e60dadfd 100644 --- a/extensions/elasticsearch/tests/MockElastic.h +++ b/extensions/elasticsearch/tests/MockElastic.h @@ -24,7 +24,7 @@ #include #include "integration/CivetLibrary.h" #include "core/logging/Logger.h" -#include "core/logging/LoggerConfiguration.h" +#include "core/logging/LoggerFactory.h" #include "rapidjson/document.h" #include "rapidjson/writer.h" #include "rapidjson/stringbuffer.h" diff --git a/extensions/elasticsearch/tests/PostElasticsearchTests.cpp b/extensions/elasticsearch/tests/PostElasticsearchTests.cpp index 8bb45c7b85..6eb68522f3 100644 --- a/extensions/elasticsearch/tests/PostElasticsearchTests.cpp +++ b/extensions/elasticsearch/tests/PostElasticsearchTests.cpp @@ -20,6 +20,7 @@ #include "MockElastic.h" #include "unit/SingleProcessorTestController.h" #include "unit/Catch.h" +#include "core/FlowFile.h" namespace org::apache::nifi::minifi::extensions::elasticsearch::test { diff --git a/extensions/execute-process/ExecuteProcess.cpp b/extensions/execute-process/ExecuteProcess.cpp index 5c93279e6e..21a215a2c4 100644 --- a/extensions/execute-process/ExecuteProcess.cpp +++ b/extensions/execute-process/ExecuteProcess.cpp @@ -19,18 +19,20 @@ */ #include "ExecuteProcess.h" -#include +#include +#include +#include #include #include -#include + #include "core/ProcessContext.h" #include "core/ProcessSession.h" #include "core/Resource.h" -#include "utils/StringUtils.h" #include "core/TypedValues.h" -#include "utils/gsl.h" #include "utils/Environment.h" +#include "utils/StringUtils.h" +#include "utils/gsl.h" using namespace std::literals::chrono_literals; diff --git a/extensions/execute-process/ExecuteProcess.h b/extensions/execute-process/ExecuteProcess.h index 44d2b59abe..1992599691 100644 --- a/extensions/execute-process/ExecuteProcess.h +++ b/extensions/execute-process/ExecuteProcess.h @@ -35,7 +35,7 @@ #include #include "core/Core.h" -#include "core/logging/LoggerConfiguration.h" +#include "core/logging/LoggerFactory.h" #include "core/Processor.h" #include "core/ProcessSession.h" #include "core/PropertyDefinition.h" @@ -46,10 +46,10 @@ namespace org::apache::nifi::minifi::processors { -class ExecuteProcess : public core::Processor { +class ExecuteProcess final : public core::ProcessorImpl { public: explicit ExecuteProcess(const std::string_view name, const utils::Identifier& uuid = {}) - : Processor(name, uuid), + : ProcessorImpl(name, uuid), working_dir_(".") { } ~ExecuteProcess() override { diff --git a/extensions/expression-language/Expression.cpp b/extensions/expression-language/Expression.cpp index 4bf00fa614..3f53915dd5 100644 --- a/extensions/expression-language/Expression.cpp +++ b/extensions/expression-language/Expression.cpp @@ -34,6 +34,7 @@ #include "utils/OsUtils.h" #include "expression/Expression.h" #include "utils/RegexUtils.h" +#include "utils/TimeUtil.h" #ifdef WIN32 #pragma comment(lib, "wldap32.lib" ) @@ -1634,6 +1635,7 @@ Expression Expression::make_aggregate(const std::function{}; EXTENSIONAPI static constexpr bool SupportsDynamicProperties = false; diff --git a/extensions/expression-language/ProcessContextExpr.cpp b/extensions/expression-language/ProcessContextExpr.cpp index 04f5a7444f..922b9f7978 100644 --- a/extensions/expression-language/ProcessContextExpr.cpp +++ b/extensions/expression-language/ProcessContextExpr.cpp @@ -23,12 +23,12 @@ namespace org::apache::nifi::minifi::core { bool ProcessContextExpr::getProperty(bool supports_expression_language, std::string_view property_name, std::string& value, const FlowFile* const flow_file) { if (!supports_expression_language) { - return ProcessContext::getProperty(property_name, value); + return ProcessContextImpl::getProperty(property_name, value); } std::string name{property_name}; if (expressions_.find(name) == expressions_.end()) { std::string expression_str; - if (!ProcessContext::getProperty(name, expression_str)) { + if (!ProcessContextImpl::getProperty(name, expression_str)) { return false; } logger_->log_debug("Compiling expression for {}/{}: {}", getProcessorNode()->getName(), name, expression_str); @@ -36,7 +36,7 @@ bool ProcessContextExpr::getProperty(bool supports_expression_language, std::str expression_strs_.insert_or_assign(name, expression_str); } - minifi::expression::Parameters p(shared_from_this(), flow_file); + minifi::expression::Parameters p(sharedFromThis(), flow_file); value = expressions_[name](p).asString(); logger_->log_debug(R"(expression "{}" of property "{}" evaluated to: {})", expression_strs_[name], name, value); return true; @@ -52,17 +52,17 @@ bool ProcessContextExpr::getProperty(const PropertyReference& property, std::str bool ProcessContextExpr::getDynamicProperty(const Property &property, std::string &value, const FlowFile* const flow_file) { if (!property.supportsExpressionLanguage()) { - return ProcessContext::getDynamicProperty(property.getName(), value); + return ProcessContextImpl::getDynamicProperty(property.getName(), value); } auto name = property.getName(); if (dynamic_property_expressions_.find(name) == dynamic_property_expressions_.end()) { std::string expression_str; - ProcessContext::getDynamicProperty(name, expression_str); + ProcessContextImpl::getDynamicProperty(name, expression_str); logger_->log_debug("Compiling expression for {}/{}: {}", getProcessorNode()->getName(), name, expression_str); dynamic_property_expressions_.emplace(name, expression::compile(expression_str)); expression_strs_.insert_or_assign(name, expression_str); } - minifi::expression::Parameters p(shared_from_this(), flow_file); + minifi::expression::Parameters p(sharedFromThis(), flow_file); value = dynamic_property_expressions_[name](p).asString(); logger_->log_debug(R"(expression "{}" of dynamic property "{}" evaluated to: {})", expression_strs_[name], name, value); return true; @@ -71,12 +71,12 @@ bool ProcessContextExpr::getDynamicProperty(const Property &property, std::strin bool ProcessContextExpr::setProperty(const std::string& property, std::string value) { expressions_.erase(property); - return ProcessContext::setProperty(property, value); + return ProcessContextImpl::setProperty(property, value); } bool ProcessContextExpr::setDynamicProperty(const std::string& property, std::string value) { dynamic_property_expressions_.erase(property); - return ProcessContext::setDynamicProperty(property, value); + return ProcessContextImpl::setDynamicProperty(property, value); } } // namespace org::apache::nifi::minifi::core diff --git a/extensions/expression-language/ProcessContextExpr.h b/extensions/expression-language/ProcessContextExpr.h index b92bdcc6bb..43689892e8 100644 --- a/extensions/expression-language/ProcessContextExpr.h +++ b/extensions/expression-language/ProcessContextExpr.h @@ -21,7 +21,7 @@ #include #include -#include "ProcessContext.h" +#include "core/ProcessContext.h" #include "impl/expression/Expression.h" namespace org::apache::nifi::minifi::core { @@ -32,19 +32,19 @@ namespace org::apache::nifi::minifi::core { * state. With this case, we can rely on instantiation of a builder to create the necessary * ProcessContext. * */ -class ProcessContextExpr final : public core::ProcessContext { +class ProcessContextExpr final : public core::ProcessContextImpl { public: ProcessContextExpr(const std::shared_ptr &processor, controller::ControllerServiceProvider* controller_service_provider, const std::shared_ptr &repo, const std::shared_ptr &flow_repo, - const std::shared_ptr &content_repo = std::make_shared()) - : core::ProcessContext(processor, controller_service_provider, repo, flow_repo, content_repo), + const std::shared_ptr &content_repo = core::repository::createFileSystemRepository()) + : core::ProcessContextImpl(processor, controller_service_provider, repo, flow_repo, content_repo), logger_(logging::LoggerFactory::getLogger()) { } ProcessContextExpr(const std::shared_ptr &processor, controller::ControllerServiceProvider* controller_service_provider, const std::shared_ptr &repo, const std::shared_ptr &flow_repo, const std::shared_ptr &configuration, - const std::shared_ptr &content_repo = std::make_shared()) - : core::ProcessContext(processor, controller_service_provider, repo, flow_repo, configuration, content_repo), + const std::shared_ptr &content_repo = core::repository::createFileSystemRepository()) + : core::ProcessContextImpl(processor, controller_service_provider, repo, flow_repo, configuration, content_repo), logger_(logging::LoggerFactory::getLogger()) { } @@ -60,6 +60,8 @@ class ProcessContextExpr final : public core::ProcessContext { bool setDynamicProperty(const std::string& property, std::string value) override; + using ProcessContextImpl::getProperty; + private: bool getProperty(bool supports_expression_language, std::string_view property_name, std::string& value, const FlowFile* const flow_file); diff --git a/extensions/expression-language/impl/expression/Expression.h b/extensions/expression-language/impl/expression/Expression.h index 70d5149dac..cfe963730c 100644 --- a/extensions/expression-language/impl/expression/Expression.h +++ b/extensions/expression-language/impl/expression/Expression.h @@ -25,7 +25,7 @@ #include "common/Value.h" #include "FlowFile.h" -#include "VariableRegistry.h" +#include "core/VariableRegistry.h" namespace org::apache::nifi::minifi::expression { diff --git a/extensions/expression-language/tests/ExpressionLanguageTests.cpp b/extensions/expression-language/tests/ExpressionLanguageTests.cpp index 319a7ea9de..76a236c16d 100644 --- a/extensions/expression-language/tests/ExpressionLanguageTests.cpp +++ b/extensions/expression-language/tests/ExpressionLanguageTests.cpp @@ -63,7 +63,7 @@ TEST_CASE("Text expression with escaped dollar", "[expressionLanguageTestEscaped } TEST_CASE("Attribute expression", "[expressionLanguageTestAttributeExpression]") { - auto flow_file = std::make_shared(); + auto flow_file = std::make_shared(); flow_file->addAttribute("attr_a", "__attr_value_a__"); auto expr = expression::compile("text_before${attr_a}text_after"); REQUIRE("text_before__attr_value_a__text_after" == expr(expression::Parameters{ flow_file.get() }).asString()); @@ -76,7 +76,7 @@ TEST_CASE("Attribute expression (Null)", "[expressionLanguageTestAttributeExpres } TEST_CASE("Multi-attribute expression", "[expressionLanguageTestMultiAttributeExpression]") { - auto flow_file = std::make_shared(); + auto flow_file = std::make_shared(); flow_file->addAttribute("attr_a", "__attr_value_a__"); flow_file->addAttribute("attr_b", "__attr_value_b__"); auto expr = expression::compile("text_before${attr_a}text_between${attr_b}text_after"); @@ -87,17 +87,17 @@ TEST_CASE("Multi-flowfile attribute expression", "[expressionLanguageTestMultiFlowfileAttributeExpression]") { auto expr = expression::compile("text_before${attr_a}text_after"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("attr_a", "__flow_a_attr_value_a__"); REQUIRE("text_before__flow_a_attr_value_a__text_after" == expr(expression::Parameters{ flow_file_a.get() }).asString()); - auto flow_file_b = std::make_shared(); + auto flow_file_b = std::make_shared(); flow_file_b->addAttribute("attr_a", "__flow_b_attr_value_a__"); REQUIRE("text_before__flow_b_attr_value_a__text_after" == expr(expression::Parameters{ flow_file_b.get() }).asString()); } TEST_CASE("Attribute expression with whitespace", "[expressionLanguageTestAttributeExpressionWhitespace]") { - auto flow_file = std::make_shared(); + auto flow_file = std::make_shared(); flow_file->addAttribute("attr_a", "__attr_value_a__"); auto expr = expression::compile("text_before${\n\tattr_a \r}text_after"); REQUIRE("text_before__attr_value_a__text_after" == expr(expression::Parameters{ flow_file.get() }).asString()); @@ -106,7 +106,7 @@ TEST_CASE("Attribute expression with whitespace", "[expressionLanguageTestAttrib TEST_CASE("Special characters expression", "[expressionLanguageTestSpecialCharactersExpression]") { auto expr = expression::compile("text_before|{}()[],:;\\/*#'\" \t\r\n${attr_a}}()text_after"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("attr_a", "__flow_a_attr_value_a__"); REQUIRE("text_before|{}()[],:;\\/*#'\" \t\r\n__flow_a_attr_value_a__}()text_after" == expr(expression::Parameters{ flow_file_a.get() }).asString()); } @@ -114,7 +114,7 @@ TEST_CASE("Special characters expression", "[expressionLanguageTestSpecialCharac TEST_CASE("UTF-8 characters expression", "[expressionLanguageTestUTF8Expression]") { auto expr = expression::compile("text_before¥£€¢₡₢₣₤₥₦₧₨₩₪₫₭₮₯₹${attr_a}text_after"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("attr_a", "__flow_a_attr_value_a__"); REQUIRE("text_before¥£€¢₡₢₣₤₥₦₧₨₩₪₫₭₮₯₹__flow_a_attr_value_a__text_after" == expr(expression::Parameters{ flow_file_a.get() }).asString()); } @@ -122,7 +122,7 @@ TEST_CASE("UTF-8 characters expression", "[expressionLanguageTestUTF8Expression] TEST_CASE("UTF-8 characters attribute", "[expressionLanguageTestUTF8Attribute]") { auto expr = expression::compile("text_before${attr_a}text_after"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("attr_a", "__¥£€¢₡₢₣₤₥₦₧₨₩₪₫₭₮₯₹__"); REQUIRE("text_before__¥£€¢₡₢₣₤₥₦₧₨₩₪₫₭₮₯₹__text_after" == expr(expression::Parameters{ flow_file_a.get() }).asString()); } @@ -130,7 +130,7 @@ TEST_CASE("UTF-8 characters attribute", "[expressionLanguageTestUTF8Attribute]") TEST_CASE("Single quoted attribute expression", "[expressionLanguageTestSingleQuotedAttributeExpression]") { auto expr = expression::compile("text_before${'|{}()[],:;\\\\/*# \t\r\n$'}text_after"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("|{}()[],:;\\/*# \t\r\n$", "__flow_a_attr_value_a__"); REQUIRE("text_before__flow_a_attr_value_a__text_after" == expr(expression::Parameters{ flow_file_a.get() }).asString()); } @@ -138,7 +138,7 @@ TEST_CASE("Single quoted attribute expression", "[expressionLanguageTestSingleQu TEST_CASE("Double quoted attribute expression", "[expressionLanguageTestDoubleQuotedAttributeExpression]") { auto expr = expression::compile("text_before${\"|{}()[],:;\\\\/*# \t\r\n$\"}text_after"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("|{}()[],:;\\/*# \t\r\n$", "__flow_a_attr_value_a__"); REQUIRE("text_before__flow_a_attr_value_a__text_after" == expr(expression::Parameters{ flow_file_a.get() }).asString()); } @@ -152,7 +152,7 @@ TEST_CASE("Hostname function", "[expressionLanguageTestHostnameFunction]") { expected.append(hostname.data()); expected.append("text_after"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); REQUIRE(expected == expr(expression::Parameters{ flow_file_a.get() }).asString()); } @@ -160,14 +160,14 @@ TEST_CASE("ToUpper function", "[expressionLanguageTestToUpperFunction]") { auto expr = expression::compile(R"(text_before${ attr_a : toUpper() }text_after)"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("attr_a", "__flow_a_attr_value_a__"); REQUIRE("text_before__FLOW_A_ATTR_VALUE_A__text_after" == expr(expression::Parameters{ flow_file_a.get() }).asString()); } TEST_CASE("ToUpper function w/o whitespace", "[expressionLanguageTestToUpperFunctionWithoutWhitespace]") { auto expr = expression::compile(R"(text_before${attr_a:toUpper()}text_after)"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("attr_a", "__flow_a_attr_value_a__"); REQUIRE("text_before__FLOW_A_ATTR_VALUE_A__text_after" == expr(expression::Parameters{ flow_file_a.get() }).asString()); } @@ -176,7 +176,7 @@ TEST_CASE("ToLower function", "[expressionLanguageTestToLowerFunction]") { auto expr = expression::compile(R"(text_before${ attr_a : toLower() }text_after)"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("attr_a", "__FLOW_A_ATTR_VALUE_A__"); REQUIRE("text_before__flow_a_attr_value_a__text_after" == expr(expression::Parameters{ flow_file_a.get() }).asString()); } @@ -192,7 +192,7 @@ TEST_CASE("GetFile PutFile dynamic attribute", "[expressionLanguageTestGetFilePu LogTestController::getInstance().setTrace(); LogTestController::getInstance().setTrace(); - auto conf = std::make_shared(); + auto conf = std::make_shared(); conf->setHome(testController.createTempDirectory()); conf->set("nifi.my.own.property", "custom_value"); @@ -251,7 +251,7 @@ TEST_CASE("GetFile PutFile dynamic attribute", "[expressionLanguageTestGetFilePu TEST_CASE("Substring 2 arg", "[expressionLanguageSubstring2]") { auto expr = expression::compile("text_before${attr:substring(6, 8)}text_after"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("attr", "__flow_a_attr_value_a__"); REQUIRE("text_before_a_attr_text_after" == expr(expression::Parameters{ flow_file_a.get() }).asString()); } @@ -259,7 +259,7 @@ TEST_CASE("Substring 2 arg", "[expressionLanguageSubstring2]") { TEST_CASE("Substring 1 arg", "[expressionLanguageSubstring1]") { auto expr = expression::compile("text_before${attr:substring(6)}text_after"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("attr", "__flow_a_attr_value_a__"); REQUIRE("text_before_a_attr_value_a__text_after" == expr(expression::Parameters{ flow_file_a.get() }).asString()); } @@ -267,7 +267,7 @@ TEST_CASE("Substring 1 arg", "[expressionLanguageSubstring1]") { TEST_CASE("Substring Before", "[expressionLanguageSubstringBefore]") { auto expr = expression::compile("${attr:substringBefore('attr_value_a__')}"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("attr", "__flow_a_attr_value_a__"); REQUIRE("__flow_a_" == expr(expression::Parameters{ flow_file_a.get() }).asString()); } @@ -275,7 +275,7 @@ TEST_CASE("Substring Before", "[expressionLanguageSubstringBefore]") { TEST_CASE("Substring Before Last", "[expressionLanguageSubstringBeforeLast]") { auto expr = expression::compile("${attr:substringBeforeLast('_a')}"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("attr", "__flow_a_attr_value_a__"); REQUIRE("__flow_a_attr_value" == expr(expression::Parameters{ flow_file_a.get() }).asString()); } @@ -283,7 +283,7 @@ TEST_CASE("Substring Before Last", "[expressionLanguageSubstringBeforeLast]") { TEST_CASE("Substring After", "[expressionLanguageSubstringAfter]") { auto expr = expression::compile("${attr:substringAfter('__flow_a')}"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("attr", "__flow_a_attr_value_a__"); REQUIRE("_attr_value_a__" == expr(expression::Parameters{ flow_file_a.get() }).asString()); } @@ -291,7 +291,7 @@ TEST_CASE("Substring After", "[expressionLanguageSubstringAfter]") { TEST_CASE("Substring After Last", "[expressionLanguageSubstringAfterLast]") { auto expr = expression::compile("${attr:substringAfterLast('_a')}"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("attr", "__flow_a_attr_value_a__"); REQUIRE("__" == expr(expression::Parameters{ flow_file_a.get() }).asString()); } @@ -299,7 +299,7 @@ TEST_CASE("Substring After Last", "[expressionLanguageSubstringAfterLast]") { TEST_CASE("Get Delimited", "[expressionLanguageGetDelimited]") { auto expr = expression::compile("${attr:getDelimitedField(2)}"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("attr", "\"Jacobson, John\", 32, Mr."); REQUIRE(" 32" == expr(expression::Parameters{ flow_file_a.get() }).asString()); } @@ -307,7 +307,7 @@ TEST_CASE("Get Delimited", "[expressionLanguageGetDelimited]") { TEST_CASE("Get Delimited 2", "[expressionLanguageGetDelimited2]") { auto expr = expression::compile("${attr:getDelimitedField(1)}"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("attr", "\"Jacobson, John\", 32, Mr."); REQUIRE("\"Jacobson, John\"" == expr(expression::Parameters{ flow_file_a.get() }).asString()); } @@ -315,7 +315,7 @@ TEST_CASE("Get Delimited 2", "[expressionLanguageGetDelimited2]") { TEST_CASE("Get Delimited 3", "[expressionLanguageGetDelimited3]") { auto expr = expression::compile(R"(${attr:getDelimitedField(1, ',', '\"', '\\', 'true')})"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("attr", "\"Jacobson, John\", 32, Mr."); REQUIRE("Jacobson, John" == expr(expression::Parameters{ flow_file_a.get() }).asString()); } @@ -323,7 +323,7 @@ TEST_CASE("Get Delimited 3", "[expressionLanguageGetDelimited3]") { TEST_CASE("Starts With", "[expressionLanguageStartsWith]") { auto expr = expression::compile("${attr:startsWith('a brand')}"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("attr", "A BRAND TEST"); REQUIRE("false" == expr(expression::Parameters{ flow_file_a.get() }).asString()); } @@ -331,7 +331,7 @@ TEST_CASE("Starts With", "[expressionLanguageStartsWith]") { TEST_CASE("Starts With 2", "[expressionLanguageStartsWith2]") { auto expr = expression::compile("${attr:startsWith('a brand')}"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("attr", "a brand TEST"); REQUIRE("true" == expr(expression::Parameters{ flow_file_a.get() }).asString()); } @@ -339,7 +339,7 @@ TEST_CASE("Starts With 2", "[expressionLanguageStartsWith2]") { TEST_CASE("Ends With", "[expressionLanguageEndsWith]") { auto expr = expression::compile("${attr:endsWith('txt')}"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("attr", "a brand new filename.TXT"); REQUIRE("false" == expr(expression::Parameters{ flow_file_a.get() }).asString()); } @@ -347,7 +347,7 @@ TEST_CASE("Ends With", "[expressionLanguageEndsWith]") { TEST_CASE("Ends With 2", "[expressionLanguageEndsWith2]") { auto expr = expression::compile("${attr:endsWith('TXT')}"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("attr", "a brand new filename.TXT"); REQUIRE("true" == expr(expression::Parameters{ flow_file_a.get() }).asString()); } @@ -355,7 +355,7 @@ TEST_CASE("Ends With 2", "[expressionLanguageEndsWith2]") { TEST_CASE("Contains", "[expressionLanguageContains]") { auto expr = expression::compile("${attr:contains('new')}"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("attr", "a brand new filename.txt"); REQUIRE("true" == expr(expression::Parameters{ flow_file_a.get() }).asString()); } @@ -363,7 +363,7 @@ TEST_CASE("Contains", "[expressionLanguageContains]") { TEST_CASE("Contains 2", "[expressionLanguageContains2]") { auto expr = expression::compile("${attr:contains('NEW')}"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("attr", "a brand new filename.txt"); REQUIRE("false" == expr(expression::Parameters{ flow_file_a.get() }).asString()); } @@ -371,7 +371,7 @@ TEST_CASE("Contains 2", "[expressionLanguageContains2]") { TEST_CASE("In", "[expressionLanguageIn]") { auto expr = expression::compile("${attr:in('PAUL', 'JOHN', 'MIKE')}"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("attr", "JOHN"); REQUIRE("true" == expr(expression::Parameters{ flow_file_a.get() }).asString()); } @@ -379,7 +379,7 @@ TEST_CASE("In", "[expressionLanguageIn]") { TEST_CASE("In 2", "[expressionLanguageIn2]") { auto expr = expression::compile("${attr:in('RED', 'GREEN', 'BLUE')}"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("attr", "JOHN"); REQUIRE("false" == expr(expression::Parameters{ flow_file_a.get() }).asString()); } @@ -395,7 +395,7 @@ TEST_CASE("Substring After No Args", "[expressionLanguageSubstringAfterNoArgs]") TEST_CASE("Replace", "[expressionLanguageReplace]") { auto expr = expression::compile("${attr:replace('.', '_')}"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("attr", "a brand new filename.txt"); REQUIRE("a brand new filename_txt" == expr(expression::Parameters{ flow_file_a.get() }).asString()); } @@ -403,7 +403,7 @@ TEST_CASE("Replace", "[expressionLanguageReplace]") { TEST_CASE("Replace 2", "[expressionLanguageReplace2]") { auto expr = expression::compile("${attr:replace(' ', '.')}"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("attr", "a brand new filename.txt"); REQUIRE("a.brand.new.filename.txt" == expr(expression::Parameters{ flow_file_a.get() }).asString()); } @@ -411,7 +411,7 @@ TEST_CASE("Replace 2", "[expressionLanguageReplace2]") { TEST_CASE("Replace First", "[expressionLanguageReplaceFirst]") { auto expr = expression::compile("${attr:replaceFirst('a', 'the')}"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("attr", "a brand new filename.txt"); REQUIRE("the brand new filename.txt" == expr(expression::Parameters{ flow_file_a.get() }).asString()); } @@ -419,7 +419,7 @@ TEST_CASE("Replace First", "[expressionLanguageReplaceFirst]") { TEST_CASE("Replace First Regex", "[expressionLanguageReplaceFirstRegex]") { auto expr = expression::compile("${attr:replaceFirst('[br]', 'g')}"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("attr", "a brand new filename.txt"); REQUIRE("a grand new filename.txt" == expr(expression::Parameters{ flow_file_a.get() }).asString()); } @@ -427,7 +427,7 @@ TEST_CASE("Replace First Regex", "[expressionLanguageReplaceFirstRegex]") { TEST_CASE("Replace All", "[expressionLanguageReplaceAll]") { auto expr = expression::compile("${attr:replaceAll('\\\\..*', '')}"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("attr", "a brand new filename.txt"); REQUIRE("a brand new filename" == expr(expression::Parameters{ flow_file_a.get() }).asString()); } @@ -435,7 +435,7 @@ TEST_CASE("Replace All", "[expressionLanguageReplaceAll]") { TEST_CASE("Replace All 2", "[expressionLanguageReplaceAll2]") { auto expr = expression::compile("${attr:replaceAll('a brand (new)', '$1')}"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("attr", "a brand new filename.txt"); REQUIRE("new filename.txt" == expr(expression::Parameters{ flow_file_a.get() }).asString()); } @@ -443,7 +443,7 @@ TEST_CASE("Replace All 2", "[expressionLanguageReplaceAll2]") { TEST_CASE("Replace All 3", "[expressionLanguageReplaceAll3]") { auto expr = expression::compile("${attr:replaceAll('XYZ', 'ZZZ')}"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("attr", "a brand new filename.txt"); REQUIRE("a brand new filename.txt" == expr(expression::Parameters{ flow_file_a.get() }).asString()); } @@ -451,7 +451,7 @@ TEST_CASE("Replace All 3", "[expressionLanguageReplaceAll3]") { TEST_CASE("Replace Null", "[expressionLanguageReplaceNull]") { auto expr = expression::compile("${attr:replaceNull('abc')}"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("attr", "a brand new filename.txt"); REQUIRE("a brand new filename.txt" == expr(expression::Parameters{ flow_file_a.get() }).asString()); } @@ -459,7 +459,7 @@ TEST_CASE("Replace Null", "[expressionLanguageReplaceNull]") { TEST_CASE("Replace Null 2", "[expressionLanguageReplaceNull2]") { auto expr = expression::compile("${attr:replaceNull('abc')}"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("attr2", "a brand new filename.txt"); REQUIRE("abc" == expr(expression::Parameters{ flow_file_a.get() }).asString()); } @@ -467,7 +467,7 @@ TEST_CASE("Replace Null 2", "[expressionLanguageReplaceNull2]") { TEST_CASE("Replace Empty", "[expressionLanguageReplaceEmpty]") { auto expr = expression::compile("${attr:replaceEmpty('abc')}"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("attr", "a brand new filename.txt"); REQUIRE("a brand new filename.txt" == expr(expression::Parameters{ flow_file_a.get() }).asString()); } @@ -475,7 +475,7 @@ TEST_CASE("Replace Empty", "[expressionLanguageReplaceEmpty]") { TEST_CASE("Replace Empty 2", "[expressionLanguageReplaceEmpty2]") { auto expr = expression::compile("${attr:replaceEmpty('abc')}"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("attr", " \t \r \n "); REQUIRE("abc" == expr(expression::Parameters{ flow_file_a.get() }).asString()); } @@ -483,7 +483,7 @@ TEST_CASE("Replace Empty 2", "[expressionLanguageReplaceEmpty2]") { TEST_CASE("Replace Empty 3", "[expressionLanguageReplaceEmpty2]") { auto expr = expression::compile("${attr:replaceEmpty('abc')}"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("attr2", "test"); REQUIRE("abc" == expr(expression::Parameters{ flow_file_a.get() }).asString()); } @@ -491,7 +491,7 @@ TEST_CASE("Replace Empty 3", "[expressionLanguageReplaceEmpty2]") { TEST_CASE("Matches", "[expressionLanguageMatches]") { auto expr = expression::compile("${attr:matches('^(Ct|Bt|At):.*t$')}"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("attr", "At:est"); REQUIRE("true" == expr(expression::Parameters{ flow_file_a.get() }).asString()); } @@ -499,7 +499,7 @@ TEST_CASE("Matches", "[expressionLanguageMatches]") { TEST_CASE("Matches 2", "[expressionLanguageMatches2]") { auto expr = expression::compile("${attr:matches('^(Ct|Bt|At):.*t$')}"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("attr", "At:something"); REQUIRE("false" == expr(expression::Parameters{ flow_file_a.get() }).asString()); } @@ -507,7 +507,7 @@ TEST_CASE("Matches 2", "[expressionLanguageMatches2]") { TEST_CASE("Matches 3", "[expressionLanguageMatches3]") { auto expr = expression::compile("${attr:matches('(Ct|Bt|At):.*t')}"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("attr", " At:est"); REQUIRE("false" == expr(expression::Parameters{ flow_file_a.get() }).asString()); } @@ -515,7 +515,7 @@ TEST_CASE("Matches 3", "[expressionLanguageMatches3]") { TEST_CASE("Find", "[expressionLanguageFind]") { auto expr = expression::compile("${attr:find('a [Bb]rand [Nn]ew')}"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("attr", "a brand new filename.txt"); REQUIRE("true" == expr(expression::Parameters{ flow_file_a.get() }).asString()); } @@ -523,7 +523,7 @@ TEST_CASE("Find", "[expressionLanguageFind]") { TEST_CASE("Find 2", "[expressionLanguageFind2]") { auto expr = expression::compile("${attr:find('Brand.*')}"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("attr", "a brand new filename.txt"); REQUIRE("false" == expr(expression::Parameters{ flow_file_a.get() }).asString()); } @@ -531,7 +531,7 @@ TEST_CASE("Find 2", "[expressionLanguageFind2]") { TEST_CASE("Find 3", "[expressionLanguageFind3]") { auto expr = expression::compile("${attr:find('brand')}"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("attr", "a brand new filename.txt"); REQUIRE("true" == expr(expression::Parameters{ flow_file_a.get() }).asString()); } @@ -539,7 +539,7 @@ TEST_CASE("Find 3", "[expressionLanguageFind3]") { TEST_CASE("IndexOf", "[expressionLanguageIndexOf]") { auto expr = expression::compile("${attr:indexOf('a.*txt')}"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("attr", "a brand new filename.txt"); REQUIRE("-1" == expr(expression::Parameters{ flow_file_a.get() }).asString()); } @@ -547,7 +547,7 @@ TEST_CASE("IndexOf", "[expressionLanguageIndexOf]") { TEST_CASE("IndexOf2", "[expressionLanguageIndexOf2]") { auto expr = expression::compile("${attr:indexOf('.')}"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("attr", "a brand new filename.txt"); REQUIRE("20" == expr(expression::Parameters{ flow_file_a.get() }).asString()); } @@ -555,7 +555,7 @@ TEST_CASE("IndexOf2", "[expressionLanguageIndexOf2]") { TEST_CASE("IndexOf3", "[expressionLanguageIndexOf3]") { auto expr = expression::compile("${attr:indexOf('a')}"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("attr", "a brand new filename.txt"); REQUIRE("0" == expr(expression::Parameters{ flow_file_a.get() }).asString()); } @@ -563,7 +563,7 @@ TEST_CASE("IndexOf3", "[expressionLanguageIndexOf3]") { TEST_CASE("IndexOf4", "[expressionLanguageIndexOf4]") { auto expr = expression::compile("${attr:indexOf(' ')}"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("attr", "a brand new filename.txt"); REQUIRE("1" == expr(expression::Parameters{ flow_file_a.get() }).asString()); } @@ -571,7 +571,7 @@ TEST_CASE("IndexOf4", "[expressionLanguageIndexOf4]") { TEST_CASE("LastIndexOf", "[expressionLanguageLastIndexOf]") { auto expr = expression::compile("${attr:lastIndexOf('a.*txt')}"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("attr", "a brand new filename.txt"); REQUIRE("-1" == expr(expression::Parameters{ flow_file_a.get() }).asString()); } @@ -579,7 +579,7 @@ TEST_CASE("LastIndexOf", "[expressionLanguageLastIndexOf]") { TEST_CASE("LastIndexOf2", "[expressionLanguageLastIndexOf2]") { auto expr = expression::compile("${attr:lastIndexOf('.')}"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("attr", "a brand new filename.txt"); REQUIRE("20" == expr(expression::Parameters{ flow_file_a.get() }).asString()); } @@ -587,7 +587,7 @@ TEST_CASE("LastIndexOf2", "[expressionLanguageLastIndexOf2]") { TEST_CASE("LastIndexOf3", "[expressionLanguageLastIndexOf3]") { auto expr = expression::compile("${attr:lastIndexOf('a')}"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("attr", "a brand new filename.txt"); REQUIRE("17" == expr(expression::Parameters{ flow_file_a.get() }).asString()); } @@ -595,7 +595,7 @@ TEST_CASE("LastIndexOf3", "[expressionLanguageLastIndexOf3]") { TEST_CASE("LastIndexOf4", "[expressionLanguageLastIndexOf4]") { auto expr = expression::compile("${attr:lastIndexOf(' ')}"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("attr", "a brand new filename.txt"); REQUIRE("11" == expr(expression::Parameters{ flow_file_a.get() }).asString()); } @@ -603,7 +603,7 @@ TEST_CASE("LastIndexOf4", "[expressionLanguageLastIndexOf4]") { TEST_CASE("Plus Integer", "[expressionLanguagePlusInteger]") { auto expr = expression::compile("${attr:plus(13)}"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("attr", "11"); REQUIRE("24" == expr(expression::Parameters{ flow_file_a.get() }).asString()); } @@ -611,7 +611,7 @@ TEST_CASE("Plus Integer", "[expressionLanguagePlusInteger]") { TEST_CASE("Plus Decimal", "[expressionLanguagePlusDecimal]") { auto expr = expression::compile("${attr:plus(-13.34567)}"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("attr", "11.1"); REQUIRE("-2.24567" == expr(expression::Parameters{ flow_file_a.get() }).asString()); } @@ -619,7 +619,7 @@ TEST_CASE("Plus Decimal", "[expressionLanguagePlusDecimal]") { TEST_CASE("Plus Exponent", "[expressionLanguagePlusExponent]") { auto expr = expression::compile("${attr:plus(10e+6)}"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("attr", "11"); REQUIRE("10000011" == expr(expression::Parameters{ flow_file_a.get() }).asString()); } @@ -627,7 +627,7 @@ TEST_CASE("Plus Exponent", "[expressionLanguagePlusExponent]") { TEST_CASE("Plus Exponent 2", "[expressionLanguagePlusExponent2]") { auto expr = expression::compile("${attr:plus(10e+6)}"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("attr", "11.345678901234"); REQUIRE(10000011.345678901234 == Catch::Approx(expr(expression::Parameters{ flow_file_a.get() }).asLongDouble())); } @@ -635,7 +635,7 @@ TEST_CASE("Plus Exponent 2", "[expressionLanguagePlusExponent2]") { TEST_CASE("Minus Integer", "[expressionLanguageMinusInteger]") { auto expr = expression::compile("${attr:minus(13)}"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("attr", "11"); REQUIRE("-2" == expr(expression::Parameters{ flow_file_a.get() }).asString()); } @@ -643,7 +643,7 @@ TEST_CASE("Minus Integer", "[expressionLanguageMinusInteger]") { TEST_CASE("Minus Decimal", "[expressionLanguageMinusDecimal]") { auto expr = expression::compile("${attr:minus(-13.34567)}"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("attr", "11.1"); REQUIRE("24.44567" == expr(expression::Parameters{ flow_file_a.get() }).asString()); } @@ -651,7 +651,7 @@ TEST_CASE("Minus Decimal", "[expressionLanguageMinusDecimal]") { TEST_CASE("Multiply Integer", "[expressionLanguageMultiplyInteger]") { auto expr = expression::compile("${attr:multiply(13)}"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("attr", "11"); REQUIRE("143" == expr(expression::Parameters{ flow_file_a.get() }).asString()); } @@ -659,7 +659,7 @@ TEST_CASE("Multiply Integer", "[expressionLanguageMultiplyInteger]") { TEST_CASE("Multiply Decimal", "[expressionLanguageMultiplyDecimal]") { auto expr = expression::compile("${attr:multiply(-13.34567)}"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("attr", "11.1"); REQUIRE(-148.136937 == Catch::Approx(expr(expression::Parameters{ flow_file_a.get() }).asLongDouble())); } @@ -667,7 +667,7 @@ TEST_CASE("Multiply Decimal", "[expressionLanguageMultiplyDecimal]") { TEST_CASE("Divide Integer", "[expressionLanguageDivideInteger]") { auto expr = expression::compile("${attr:divide(13)}"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("attr", "11"); REQUIRE("0.846153846153846" == expr(expression::Parameters{ flow_file_a.get() }).asString()); } @@ -675,7 +675,7 @@ TEST_CASE("Divide Integer", "[expressionLanguageDivideInteger]") { TEST_CASE("Divide Decimal", "[expressionLanguageDivideDecimal]") { auto expr = expression::compile("${attr:divide(-13.34567)}"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("attr", "11.1"); REQUIRE("-0.831730441409086" == expr(expression::Parameters{ flow_file_a.get() }).asString()); } @@ -683,7 +683,7 @@ TEST_CASE("Divide Decimal", "[expressionLanguageDivideDecimal]") { TEST_CASE("To Radix", "[expressionLanguageToRadix]") { auto expr = expression::compile("${attr:toRadix(2,16)}"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("attr", "10"); REQUIRE("0000000000001010" == expr(expression::Parameters{ flow_file_a.get() }).asString()); } @@ -691,7 +691,7 @@ TEST_CASE("To Radix", "[expressionLanguageToRadix]") { TEST_CASE("To Radix 2", "[expressionLanguageToRadix2]") { auto expr = expression::compile("${attr:toRadix(16)}"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("attr", "13"); REQUIRE("d" == expr(expression::Parameters{ flow_file_a.get() }).asString()); } @@ -699,7 +699,7 @@ TEST_CASE("To Radix 2", "[expressionLanguageToRadix2]") { TEST_CASE("To Radix 3", "[expressionLanguageToRadix3]") { auto expr = expression::compile("${attr:toRadix(23,8)}"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("attr", "-2347"); REQUIRE("-000004a1" == expr(expression::Parameters{ flow_file_a.get() }).asString()); } @@ -707,7 +707,7 @@ TEST_CASE("To Radix 3", "[expressionLanguageToRadix3]") { TEST_CASE("From Radix", "[expressionLanguageFromRadix]") { auto expr = expression::compile("${attr:fromRadix(2)}"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("attr", "0000000000001010"); REQUIRE("10" == expr(expression::Parameters{ flow_file_a.get() }).asString()); } @@ -715,7 +715,7 @@ TEST_CASE("From Radix", "[expressionLanguageFromRadix]") { TEST_CASE("From Radix 2", "[expressionLanguageFromRadix2]") { auto expr = expression::compile("${attr:fromRadix(16)}"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("attr", "d"); REQUIRE("13" == expr(expression::Parameters{ flow_file_a.get() }).asString()); } @@ -723,7 +723,7 @@ TEST_CASE("From Radix 2", "[expressionLanguageFromRadix2]") { TEST_CASE("From Radix 3", "[expressionLanguageFromRadix3]") { auto expr = expression::compile("${attr:fromRadix(23)}"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("attr", "-000004a1"); REQUIRE("-2347" == expr(expression::Parameters{ flow_file_a.get() }).asString()); } @@ -731,7 +731,7 @@ TEST_CASE("From Radix 3", "[expressionLanguageFromRadix3]") { TEST_CASE("Random", "[expressionLanguageRandom]") { auto expr = expression::compile("${random()}"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); auto result = expr(expression::Parameters{ flow_file_a.get() }).asSignedLong(); REQUIRE(result > 0); } @@ -739,7 +739,7 @@ TEST_CASE("Random", "[expressionLanguageRandom]") { TEST_CASE("Chained call", "[expressionChainedCall]") { auto expr = expression::compile("${attr:multiply(3):plus(1)}"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("attr", "7"); REQUIRE("22" == expr(expression::Parameters{ flow_file_a.get() }).asString()); } @@ -747,14 +747,14 @@ TEST_CASE("Chained call", "[expressionChainedCall]") { TEST_CASE("Chained call 2", "[expressionChainedCall2]") { auto expr = expression::compile("${literal(10):multiply(2):plus(1):multiply(2)}"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); REQUIRE(42 == expr(expression::Parameters{ flow_file_a.get() }).asSignedLong()); } TEST_CASE("Chained call 3", "[expressionChainedCall3]") { auto expr = expression::compile("${literal(10):multiply(2):plus(${attr:multiply(2)}):multiply(${attr})}"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("attr", "7"); REQUIRE("238" == expr(expression::Parameters{ flow_file_a.get() }).asString()); } @@ -762,7 +762,7 @@ TEST_CASE("Chained call 3", "[expressionChainedCall3]") { TEST_CASE("LiteralBool", "[expressionLiteralBool]") { auto expr = expression::compile("${literal(true)}"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("attr", "7"); REQUIRE(true == expr(expression::Parameters{ flow_file_a.get() }).asBoolean()); } @@ -770,7 +770,7 @@ TEST_CASE("LiteralBool", "[expressionLiteralBool]") { TEST_CASE("LiteralBool 2", "[expressionLiteralBool2]") { auto expr = expression::compile("${literal(false)}"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("attr", "7"); REQUIRE(false == expr(expression::Parameters{ flow_file_a.get() }).asBoolean()); } @@ -778,7 +778,7 @@ TEST_CASE("LiteralBool 2", "[expressionLiteralBool2]") { TEST_CASE("Is Null", "[expressionIsNull]") { auto expr = expression::compile("${filename:isNull()}"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("attr", "7"); REQUIRE("true" == expr(expression::Parameters{ flow_file_a.get() }).asString()); } @@ -786,7 +786,7 @@ TEST_CASE("Is Null", "[expressionIsNull]") { TEST_CASE("Is Null 2", "[expressionIsNull2]") { auto expr = expression::compile("${filename:isNull()}"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("filename", "7"); REQUIRE("false" == expr(expression::Parameters{ flow_file_a.get() }).asString()); } @@ -794,7 +794,7 @@ TEST_CASE("Is Null 2", "[expressionIsNull2]") { TEST_CASE("Not Null", "[expressionNotNull]") { auto expr = expression::compile("${filename:notNull()}"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("attr", "7"); REQUIRE("false" == expr(expression::Parameters{ flow_file_a.get() }).asString()); } @@ -802,7 +802,7 @@ TEST_CASE("Not Null", "[expressionNotNull]") { TEST_CASE("Not Null 2", "[expressionNotNull2]") { auto expr = expression::compile("${filename:notNull()}"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("filename", "7"); REQUIRE("true" == expr(expression::Parameters{ flow_file_a.get() }).asString()); } @@ -810,7 +810,7 @@ TEST_CASE("Not Null 2", "[expressionNotNull2]") { TEST_CASE("Is Empty", "[expressionIsEmpty]") { auto expr = expression::compile("${filename:isEmpty()}"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("attr", "7"); REQUIRE("true" == expr(expression::Parameters{ flow_file_a.get() }).asString()); } @@ -818,7 +818,7 @@ TEST_CASE("Is Empty", "[expressionIsEmpty]") { TEST_CASE("Is Empty 2", "[expressionIsEmpty2]") { auto expr = expression::compile("${attr:isEmpty()}"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("attr", "7"); REQUIRE("false" == expr(expression::Parameters{ flow_file_a.get() }).asString()); } @@ -826,7 +826,7 @@ TEST_CASE("Is Empty 2", "[expressionIsEmpty2]") { TEST_CASE("Is Empty 3", "[expressionIsEmpty3]") { auto expr = expression::compile("${attr:isEmpty()}"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("attr", " \t\r\n "); REQUIRE("true" == expr(expression::Parameters{ flow_file_a.get() }).asString()); } @@ -834,7 +834,7 @@ TEST_CASE("Is Empty 3", "[expressionIsEmpty3]") { TEST_CASE("Is Empty 4", "[expressionIsEmpty4]") { auto expr = expression::compile("${attr:isEmpty()}"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("attr", ""); REQUIRE("true" == expr(expression::Parameters{ flow_file_a.get() }).asString()); } @@ -842,7 +842,7 @@ TEST_CASE("Is Empty 4", "[expressionIsEmpty4]") { TEST_CASE("Is Empty 5", "[expressionIsEmpty5]") { auto expr = expression::compile("${attr:isEmpty()}"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("attr", " \t\r\n a \t\r\n "); REQUIRE("false" == expr(expression::Parameters{ flow_file_a.get() }).asString()); } @@ -850,7 +850,7 @@ TEST_CASE("Is Empty 5", "[expressionIsEmpty5]") { TEST_CASE("Equals", "[expressionEquals]") { auto expr = expression::compile("${attr:equals('hello.txt')}"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("attr", "hello.txt"); REQUIRE("true" == expr(expression::Parameters{ flow_file_a.get() }).asString()); } @@ -858,7 +858,7 @@ TEST_CASE("Equals", "[expressionEquals]") { TEST_CASE("Equals 2", "[expressionEquals2]") { auto expr = expression::compile("${attr:equals('hello.txt')}"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("attr", "helllo.txt"); REQUIRE("false" == expr(expression::Parameters{ flow_file_a.get() }).asString()); } @@ -866,7 +866,7 @@ TEST_CASE("Equals 2", "[expressionEquals2]") { TEST_CASE("Equals 3", "[expressionEquals3]") { auto expr = expression::compile("${attr:plus(5):equals(6)}"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("attr", "1"); REQUIRE("true" == expr(expression::Parameters{ flow_file_a.get() }).asString()); } @@ -874,7 +874,7 @@ TEST_CASE("Equals 3", "[expressionEquals3]") { TEST_CASE("Equals Ignore Case", "[expressionEqualsIgnoreCase]") { auto expr = expression::compile("${attr:equalsIgnoreCase('hElLo.txt')}"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("attr", "hello.txt"); REQUIRE("true" == expr(expression::Parameters{ flow_file_a.get() }).asString()); } @@ -882,7 +882,7 @@ TEST_CASE("Equals Ignore Case", "[expressionEqualsIgnoreCase]") { TEST_CASE("Equals Ignore Case 2", "[expressionEqualsIgnoreCase2]") { auto expr = expression::compile("${attr:plus(5):equalsIgnoreCase(6)}"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("attr", "1"); REQUIRE("true" == expr(expression::Parameters{ flow_file_a.get() }).asString()); } @@ -890,7 +890,7 @@ TEST_CASE("Equals Ignore Case 2", "[expressionEqualsIgnoreCase2]") { TEST_CASE("GT", "[expressionGT]") { auto expr = expression::compile("${attr:plus(5):gt(5)}"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("attr", "1"); REQUIRE("true" == expr(expression::Parameters{ flow_file_a.get() }).asString()); } @@ -898,7 +898,7 @@ TEST_CASE("GT", "[expressionGT]") { TEST_CASE("GT2", "[expressionGT2]") { auto expr = expression::compile("${attr:plus(5.1):gt(6.05)}"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("attr", "1"); REQUIRE("true" == expr(expression::Parameters{ flow_file_a.get() }).asString()); } @@ -906,7 +906,7 @@ TEST_CASE("GT2", "[expressionGT2]") { TEST_CASE("GT3", "[expressionGT3]") { auto expr = expression::compile("${attr:plus(5.1):gt(6.15)}"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("attr", "1"); REQUIRE("false" == expr(expression::Parameters{ flow_file_a.get() }).asString()); } @@ -936,7 +936,7 @@ TEST_CASE("GT4 Value parsing errors", "[expressionGT4][outofrange]") { REQUIRE(test_str); REQUIRE(expected_substr); const auto expr = expression::compile("${attr1:gt(13.37)}"); - auto flow_file = std::make_shared(); + auto flow_file = std::make_shared(); flow_file->addAttribute("attr1", test_str); try { const auto result = expr(expression::Parameters{flow_file.get()}).asString(); @@ -952,7 +952,7 @@ TEST_CASE("GT4 Value parsing errors", "[expressionGT4][outofrange]") { TEST_CASE("GE", "[expressionGE]") { auto expr = expression::compile("${attr:plus(5):ge(6)}"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("attr", "1"); REQUIRE("true" == expr(expression::Parameters{ flow_file_a.get() }).asString()); } @@ -960,7 +960,7 @@ TEST_CASE("GE", "[expressionGE]") { TEST_CASE("GE2", "[expressionGE2]") { auto expr = expression::compile("${attr:plus(5.1):ge(6.05)}"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("attr", "1"); REQUIRE("true" == expr(expression::Parameters{ flow_file_a.get() }).asString()); } @@ -968,7 +968,7 @@ TEST_CASE("GE2", "[expressionGE2]") { TEST_CASE("GE3", "[expressionGE3]") { auto expr = expression::compile("${attr:plus(5.1):ge(6.15)}"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("attr", "1"); REQUIRE("false" == expr(expression::Parameters{ flow_file_a.get() }).asString()); } @@ -976,7 +976,7 @@ TEST_CASE("GE3", "[expressionGE3]") { TEST_CASE("LT", "[expressionLT]") { auto expr = expression::compile("${attr:plus(5):lt(5)}"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("attr", "1"); REQUIRE("false" == expr(expression::Parameters{ flow_file_a.get() }).asString()); } @@ -984,7 +984,7 @@ TEST_CASE("LT", "[expressionLT]") { TEST_CASE("LT2", "[expressionLT2]") { auto expr = expression::compile("${attr:plus(5.1):lt(6.05)}"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("attr", "1"); REQUIRE("false" == expr(expression::Parameters{ flow_file_a.get() }).asString()); } @@ -992,7 +992,7 @@ TEST_CASE("LT2", "[expressionLT2]") { TEST_CASE("LT3", "[expressionLT3]") { auto expr = expression::compile("${attr:plus(5.1):lt(6.15)}"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("attr", "1"); REQUIRE("true" == expr(expression::Parameters{ flow_file_a.get() }).asString()); } @@ -1000,7 +1000,7 @@ TEST_CASE("LT3", "[expressionLT3]") { TEST_CASE("LE", "[expressionLE]") { auto expr = expression::compile("${attr:plus(5):le(6)}"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("attr", "1"); REQUIRE("true" == expr(expression::Parameters{ flow_file_a.get() }).asString()); } @@ -1008,7 +1008,7 @@ TEST_CASE("LE", "[expressionLE]") { TEST_CASE("LE2", "[expressionLE2]") { auto expr = expression::compile("${attr:plus(5.1):le(6.05)}"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("attr", "1"); REQUIRE("false" == expr(expression::Parameters{ flow_file_a.get() }).asString()); } @@ -1016,7 +1016,7 @@ TEST_CASE("LE2", "[expressionLE2]") { TEST_CASE("LE3", "[expressionLE3]") { auto expr = expression::compile("${attr:plus(5.1):le(6.15)}"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("attr", "1"); REQUIRE("true" == expr(expression::Parameters{ flow_file_a.get() }).asString()); } @@ -1024,7 +1024,7 @@ TEST_CASE("LE3", "[expressionLE3]") { TEST_CASE("And", "[expressionAnd]") { auto expr = expression::compile("${filename:toLower():equals( ${filename} ):and(${filename:substring(0, 2):equals('an')})}"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("filename", "an example file.txt"); REQUIRE("true" == expr(expression::Parameters{ flow_file_a.get() }).asString()); } @@ -1032,7 +1032,7 @@ TEST_CASE("And", "[expressionAnd]") { TEST_CASE("And 2", "[expressionAnd2]") { auto expr = expression::compile("${filename:toLower():equals( ${filename} ):and(${filename:substring(0, 2):equals('ab')})}"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("filename", "an example file.txt"); REQUIRE("false" == expr(expression::Parameters{ flow_file_a.get() }).asString()); } @@ -1040,7 +1040,7 @@ TEST_CASE("And 2", "[expressionAnd2]") { TEST_CASE("Or", "[expressionOr]") { auto expr = expression::compile("${filename:toLower():equals( ${filename} ):or(${filename:substring(0, 2):equals('an')})}"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("filename", "an example file.txt"); REQUIRE("true" == expr(expression::Parameters{ flow_file_a.get() }).asString()); } @@ -1048,7 +1048,7 @@ TEST_CASE("Or", "[expressionOr]") { TEST_CASE("Or 2", "[expressionOr2]") { auto expr = expression::compile("${filename:toLower():equals( ${filename} ):or(${filename:substring(0, 2):equals('ab')})}"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("filename", "an example file.txt"); REQUIRE("true" == expr(expression::Parameters{ flow_file_a.get() }).asString()); } @@ -1056,7 +1056,7 @@ TEST_CASE("Or 2", "[expressionOr2]") { TEST_CASE("Not", "[expressionNot]") { auto expr = expression::compile("${filename:toLower():equals( ${filename} ):and(${filename:substring(0, 2):equals('an')}):not()}"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("filename", "an example file.txt"); REQUIRE("false" == expr(expression::Parameters{ flow_file_a.get() }).asString()); } @@ -1064,7 +1064,7 @@ TEST_CASE("Not", "[expressionNot]") { TEST_CASE("Not 2", "[expressionNot2]") { auto expr = expression::compile("${filename:toLower():equals( ${filename} ):and(${filename:substring(0, 2):equals('ab')}):not()}"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("filename", "an example file.txt"); REQUIRE("true" == expr(expression::Parameters{ flow_file_a.get() }).asString()); } @@ -1072,7 +1072,7 @@ TEST_CASE("Not 2", "[expressionNot2]") { TEST_CASE("If Else", "[expressionIfElse]") { auto expr = expression::compile("${filename:toLower():equals( ${filename}):ifElse('yes', 'no')}"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("filename", "an example file.txt"); REQUIRE("yes" == expr(expression::Parameters{ flow_file_a.get() }).asString()); } @@ -1080,7 +1080,7 @@ TEST_CASE("If Else", "[expressionIfElse]") { TEST_CASE("If Else 2", "[expressionIfElse2]") { auto expr = expression::compile("${filename:toLower():equals( ${filename}):ifElse('yes', 'no')}"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("filename", "An example file.txt"); REQUIRE("no" == expr(expression::Parameters{ flow_file_a.get() }).asString()); } @@ -1088,7 +1088,7 @@ TEST_CASE("If Else 2", "[expressionIfElse2]") { TEST_CASE("Encode JSON", "[expressionEncodeJSON]") { auto expr = expression::compile("${message:escapeJson()}"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("message", "This is a \"test!\""); REQUIRE("This is a \\\"test!\\\"" == expr(expression::Parameters{ flow_file_a.get() }).asString()); } @@ -1096,7 +1096,7 @@ TEST_CASE("Encode JSON", "[expressionEncodeJSON]") { TEST_CASE("Decode JSON", "[expressionDecodeJSON]") { auto expr = expression::compile("${message:unescapeJson()}"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("message", R"(This is a \"test!\")"); REQUIRE("This is a \"test!\"" == expr(expression::Parameters{ flow_file_a.get() }).asString()); } @@ -1104,7 +1104,7 @@ TEST_CASE("Decode JSON", "[expressionDecodeJSON]") { TEST_CASE("Encode Decode JSON", "[expressionEncodeDecodeJSON]") { auto expr = expression::compile("${message:escapeJson():unescapeJson()}"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("message", "This is a \"test!\""); REQUIRE("This is a \"test!\"" == expr(expression::Parameters{ flow_file_a.get() }).asString()); } @@ -1112,7 +1112,7 @@ TEST_CASE("Encode Decode JSON", "[expressionEncodeDecodeJSON]") { TEST_CASE("Encode XML", "[expressionEncodeXML]") { auto expr = expression::compile("${message:escapeXml()}"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("message", "Zero > One < \"two!\" & 'true'"); REQUIRE("Zero > One < "two!" & 'true'" == expr(expression::Parameters{ flow_file_a.get() }).asString()); } @@ -1120,7 +1120,7 @@ TEST_CASE("Encode XML", "[expressionEncodeXML]") { TEST_CASE("Decode XML", "[expressionDecodeXML]") { auto expr = expression::compile("${message:unescapeXml()}"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("message", "Zero > One < "two!" & 'true'"); REQUIRE("Zero > One < \"two!\" & 'true'" == expr(expression::Parameters{ flow_file_a.get() }).asString()); } @@ -1128,7 +1128,7 @@ TEST_CASE("Decode XML", "[expressionDecodeXML]") { TEST_CASE("Encode Decode XML", "[expressionEncodeDecodeXML]") { auto expr = expression::compile("${message:escapeXml():unescapeXml()}"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("message", "Zero > One < \"two!\" & 'true'"); REQUIRE("Zero > One < \"two!\" & 'true'" == expr(expression::Parameters{ flow_file_a.get() }).asString()); } @@ -1136,7 +1136,7 @@ TEST_CASE("Encode Decode XML", "[expressionEncodeDecodeXML]") { TEST_CASE("Encode HTML3", "[expressionEncodeHTML3]") { auto expr = expression::compile("${message:escapeHtml3()}"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("message", "Â¥ & < «"); REQUIRE("¥ & < «" == expr(expression::Parameters{ flow_file_a.get() }).asString()); } @@ -1144,7 +1144,7 @@ TEST_CASE("Encode HTML3", "[expressionEncodeHTML3]") { TEST_CASE("Decode HTML3", "[expressionDecodeHTML3]") { auto expr = expression::compile("${message:unescapeHtml3()}"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("message", "¥ & < «"); REQUIRE("Â¥ & < «" == expr(expression::Parameters{ flow_file_a.get() }).asString()); } @@ -1152,7 +1152,7 @@ TEST_CASE("Decode HTML3", "[expressionDecodeHTML3]") { TEST_CASE("Encode Decode HTML3", "[expressionEncodeDecodeHTML3]") { auto expr = expression::compile("${message:escapeHtml3():unescapeHtml3()}"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("message", "¥ & < «"); REQUIRE("¥ & < «" == expr(expression::Parameters{ flow_file_a.get() }).asString()); } @@ -1160,7 +1160,7 @@ TEST_CASE("Encode Decode HTML3", "[expressionEncodeDecodeHTML3]") { TEST_CASE("Encode HTML4", "[expressionEncodeHTML4]") { auto expr = expression::compile("${message:escapeHtml4()}"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("message", "Â¥ & Φ < «"); REQUIRE("¥ & Φ < «" == expr(expression::Parameters{ flow_file_a.get() }).asString()); } @@ -1168,7 +1168,7 @@ TEST_CASE("Encode HTML4", "[expressionEncodeHTML4]") { TEST_CASE("Decode HTML4", "[expressionDecodeHTML4]") { auto expr = expression::compile("${message:unescapeHtml4()}"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("message", "¥ ι & < «"); REQUIRE("Â¥ ι & < «" == expr(expression::Parameters{ flow_file_a.get() }).asString()); } @@ -1176,7 +1176,7 @@ TEST_CASE("Decode HTML4", "[expressionDecodeHTML4]") { TEST_CASE("Encode Decode HTML4", "[expressionEncodeDecodeHTML4]") { auto expr = expression::compile("${message:escapeHtml4():unescapeHtml4()}"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("message", "¥ & < Π «"); REQUIRE("¥ & < Π «" == expr(expression::Parameters{ flow_file_a.get() }).asString()); } @@ -1184,7 +1184,7 @@ TEST_CASE("Encode Decode HTML4", "[expressionEncodeDecodeHTML4]") { TEST_CASE("Encode CSV", "[expressionEncodeCSV]") { auto expr = expression::compile("${message:escapeCsv()}"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("message", "Zero > One < \"two!\" & 'true'"); REQUIRE("\"Zero > One < \"\"two!\"\" & 'true'\"" == expr(expression::Parameters{ flow_file_a.get() }).asString()); } @@ -1192,7 +1192,7 @@ TEST_CASE("Encode CSV", "[expressionEncodeCSV]") { TEST_CASE("Decode CSV", "[expressionDecodeCSV]") { auto expr = expression::compile("${message:unescapeCsv()}"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("message", R"("Zero > One < ""two!"" & 'true'")"); REQUIRE("Zero > One < \"two!\" & 'true'" == expr(expression::Parameters{ flow_file_a.get() }).asString()); } @@ -1200,7 +1200,7 @@ TEST_CASE("Decode CSV", "[expressionDecodeCSV]") { TEST_CASE("Decode CSV 2", "[expressionDecodeCSV2]") { auto expr = expression::compile("${message:unescapeCsv()}"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("message", R"("quoted")"); REQUIRE("\"quoted\"" == expr(expression::Parameters{ flow_file_a.get() }).asString()); } @@ -1208,7 +1208,7 @@ TEST_CASE("Decode CSV 2", "[expressionDecodeCSV2]") { TEST_CASE("Encode Decode CSV", "[expressionEncodeDecodeCSV]") { auto expr = expression::compile("${message:escapeCsv():unescapeCsv()}"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("message", "Zero > One < \"two!\" & 'true'"); REQUIRE("Zero > One < \"two!\" & 'true'" == expr(expression::Parameters{ flow_file_a.get() }).asString()); } @@ -1216,7 +1216,7 @@ TEST_CASE("Encode Decode CSV", "[expressionEncodeDecodeCSV]") { TEST_CASE("Encode URL", "[expressionEncodeURL]") { auto expr = expression::compile("${message:urlEncode()}"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("message", "some value with spaces"); REQUIRE("some%20value%20with%20spaces" == expr(expression::Parameters{ flow_file_a.get() }).asString()); } @@ -1224,7 +1224,7 @@ TEST_CASE("Encode URL", "[expressionEncodeURL]") { TEST_CASE("Decode URL", "[expressionDecodeURL]") { auto expr = expression::compile("${message:urlDecode()}"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("message", "some%20value%20with%20spaces"); REQUIRE("some value with spaces" == expr(expression::Parameters{ flow_file_a.get() }).asString()); } @@ -1232,7 +1232,7 @@ TEST_CASE("Decode URL", "[expressionDecodeURL]") { TEST_CASE("Encode Decode URL", "[expressionEncodeDecodeURL]") { auto expr = expression::compile("${message:urlEncode():urlDecode()}"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("message", "some value with spaces"); REQUIRE("some value with spaces" == expr(expression::Parameters{ flow_file_a.get() }).asString()); } @@ -1241,7 +1241,7 @@ TEST_CASE("Parse Date", "[expressionParseDate]") { #ifdef WIN32 expression::dateSetInstall(TZ_DATA_DIR); #endif - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("message", "2014/04/30"); CHECK("1398841200000" == expression::compile("${message:toDate('%Y/%m/%d', 'America/Los_Angeles')}")(expression::Parameters{ flow_file_a.get() }).asString()); @@ -1271,7 +1271,7 @@ TEST_CASE("Reformat Date", "[expressionReformatDate]") { #ifdef WIN32 expression::dateSetInstall(TZ_DATA_DIR); #endif - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("message", "2014/03/14"); flow_file_a->addAttribute("blue", "20130917162643"); @@ -1356,7 +1356,7 @@ TEST_CASE("Format Date", "[expressionFormatDate]") { #ifdef WIN32 expression::dateSetInstall(TZ_DATA_DIR); #endif - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("trillion_milliseconds", "1000000000000"); CHECK(expression::compile("${trillion_milliseconds:format('%Y/%m/%d %H:%M:%SZ', 'UTC')}")(expression::Parameters{ flow_file_a.get() }).asString() == "2001/09/09 01:46:40.000Z"); CHECK(expression::compile("${trillion_milliseconds:format('%Y/%m/%d %H:%M:%SZ', 'Europe/Paris')}")(expression::Parameters{ flow_file_a.get() }).asString() == "2001/09/09 03:46:40.000Z"); @@ -1366,21 +1366,21 @@ TEST_CASE("Format Date", "[expressionFormatDate]") { TEST_CASE("IP", "[expressionIP]") { auto expr = expression::compile("${ip()}"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); REQUIRE(!expr(expression::Parameters{ flow_file_a.get() }).asString().empty()); } TEST_CASE("Full Hostname", "[expressionFullHostname]") { auto expr = expression::compile("${hostname('true')}"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); REQUIRE(!expr(expression::Parameters{ flow_file_a.get() }).asString().empty()); } TEST_CASE("Reverse DNS lookup with valid ip", "[ExpressionLanguage][reverseDnsLookup]") { auto expr = expression::compile("${reverseDnsLookup(${ip_addr})}"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); std::string expected_hostname; SECTION("dns.google IPv6") { @@ -1413,7 +1413,7 @@ TEST_CASE("Reverse DNS lookup with valid ip", "[ExpressionLanguage][reverseDnsLo TEST_CASE("Reverse DNS lookup with invalid ip", "[ExpressionLanguage][reverseDnsLookup]") { auto expr = expression::compile("${reverseDnsLookup(${ip_addr})}"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("ip_addr", "banana"); REQUIRE_THROWS_AS(expr(expression::Parameters{flow_file_a.get()}), std::runtime_error); @@ -1422,7 +1422,7 @@ TEST_CASE("Reverse DNS lookup with invalid ip", "[ExpressionLanguage][reverseDns TEST_CASE("Reverse DNS lookup with invalid timeout parameter", "[ExpressionLanguage][reverseDnsLookup]") { auto expr = expression::compile("${reverseDnsLookup(${ip_addr}, ${timeout})}"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("ip_addr", "192.0.2.1"); flow_file_a->addAttribute("timeout", "strawberry"); @@ -1433,7 +1433,7 @@ TEST_CASE("Reverse DNS lookup with valid timeout parameter", "[ExpressionLanguag LogTestController::getInstance().setWarn(); LogTestController::getInstance().clear(); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); std::string expected_hostname; flow_file_a->addAttribute("ip_addr", "8.8.8.8"); @@ -1447,14 +1447,14 @@ TEST_CASE("Reverse DNS lookup with valid timeout parameter", "[ExpressionLanguag TEST_CASE("UUID", "[expressionUuid]") { auto expr = expression::compile("${UUID()}"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); REQUIRE(36 == expr(expression::Parameters{ flow_file_a.get() }).asString().length()); } TEST_CASE("Trim", "[expressionTrim]") { auto expr = expression::compile("${message:trim()}"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("message", " 1 2 3 "); REQUIRE("1 2 3" == expr(expression::Parameters{ flow_file_a.get() }).asString()); } @@ -1462,7 +1462,7 @@ TEST_CASE("Trim", "[expressionTrim]") { TEST_CASE("Append", "[expressionAppend]") { auto expr = expression::compile("${message:append('.gz')}"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("message", "a brand new filename.txt"); REQUIRE("a brand new filename.txt.gz" == expr(expression::Parameters{ flow_file_a.get() }).asString()); } @@ -1470,7 +1470,7 @@ TEST_CASE("Append", "[expressionAppend]") { TEST_CASE("Prepend", "[expressionPrepend]") { auto expr = expression::compile("${message:prepend('a brand new ')}"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("message", "filename.txt"); REQUIRE("a brand new filename.txt" == expr(expression::Parameters{ flow_file_a.get() }).asString()); } @@ -1478,7 +1478,7 @@ TEST_CASE("Prepend", "[expressionPrepend]") { TEST_CASE("Length", "[expressionLength]") { auto expr = expression::compile("${message:length()}"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("message", "a brand new filename.txt"); REQUIRE(24 == expr(expression::Parameters{ flow_file_a.get() }).asUnsignedLong()); } @@ -1486,7 +1486,7 @@ TEST_CASE("Length", "[expressionLength]") { TEST_CASE("Encode B64", "[expressionEncodeB64]") { auto expr = expression::compile("${message:base64Encode()}"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("message", "admin:admin"); REQUIRE("YWRtaW46YWRtaW4=" == expr(expression::Parameters{ flow_file_a.get() }).asString()); } @@ -1494,7 +1494,7 @@ TEST_CASE("Encode B64", "[expressionEncodeB64]") { TEST_CASE("Decode B64", "[expressionDecodeB64]") { auto expr = expression::compile("${message:base64Decode()}"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("message", "YWRtaW46YWRtaW4="); REQUIRE("admin:admin" == expr(expression::Parameters{ flow_file_a.get() }).asString()); } @@ -1502,7 +1502,7 @@ TEST_CASE("Decode B64", "[expressionDecodeB64]") { TEST_CASE("Encode Decode B64", "[expressionEncodeDecodeB64]") { auto expr = expression::compile("${message:base64Encode():base64Decode()}"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("message", "Zero > One < \"two!\" & 'true'"); REQUIRE("Zero > One < \"two!\" & 'true'" == expr(expression::Parameters{ flow_file_a.get() }).asString()); } @@ -1510,7 +1510,7 @@ TEST_CASE("Encode Decode B64", "[expressionEncodeDecodeB64]") { TEST_CASE("All Contains", "[expressionAllContains]") { auto expr = expression::compile("${allAttributes('a', 'b'):contains('hello')}"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("a", "hello 1"); flow_file_a->addAttribute("b", "hello 2"); REQUIRE(expr(expression::Parameters{ flow_file_a.get() }).asBoolean()); @@ -1519,7 +1519,7 @@ TEST_CASE("All Contains", "[expressionAllContains]") { TEST_CASE("All Contains 2", "[expressionAllContains2]") { auto expr = expression::compile("${allAttributes('a', 'b'):contains('hello')}"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("a", "hello 1"); flow_file_a->addAttribute("b", "mello 2"); REQUIRE(!expr(expression::Parameters{ flow_file_a.get() }).asBoolean()); @@ -1528,7 +1528,7 @@ TEST_CASE("All Contains 2", "[expressionAllContains2]") { TEST_CASE("Any Contains", "[expressionAnyContains]") { auto expr = expression::compile("${anyAttribute('a', 'b'):contains('hello')}"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("a", "hello 1"); flow_file_a->addAttribute("b", "mello 2"); REQUIRE(expr(expression::Parameters{ flow_file_a.get() }).asBoolean()); @@ -1537,7 +1537,7 @@ TEST_CASE("Any Contains", "[expressionAnyContains]") { TEST_CASE("Any Contains 2", "[expressionAnyContains2]") { auto expr = expression::compile("${anyAttribute('a', 'b'):contains('hello')}"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("a", "mello 1"); flow_file_a->addAttribute("b", "mello 2"); REQUIRE(!expr(expression::Parameters{ flow_file_a.get() }).asBoolean()); @@ -1546,7 +1546,7 @@ TEST_CASE("Any Contains 2", "[expressionAnyContains2]") { TEST_CASE("All Matching Contains", "[expressionAllMatchingContains]") { auto expr = expression::compile("${allMatchingAttributes('xyz_.*'):contains('hello')}"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("xyz_1", "hello 1"); flow_file_a->addAttribute("xyz_2", "hello 2"); REQUIRE(expr(expression::Parameters{ flow_file_a.get() }).asBoolean()); @@ -1555,7 +1555,7 @@ TEST_CASE("All Matching Contains", "[expressionAllMatchingContains]") { TEST_CASE("All Matching Contains 2", "[expressionAllMatchingContains2]") { auto expr = expression::compile("${allMatchingAttributes('abc_.*'):contains('hello')}"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("xyz_1", "hello 1"); flow_file_a->addAttribute("xyz_2", "hello 2"); REQUIRE(!expr(expression::Parameters{ flow_file_a.get() }).asBoolean()); @@ -1564,7 +1564,7 @@ TEST_CASE("All Matching Contains 2", "[expressionAllMatchingContains2]") { TEST_CASE("All Matching Contains 3", "[expressionAllMatchingContains3]") { auto expr = expression::compile("${allMatchingAttributes('abc_.*'):contains('hello')}"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("xyz_1", "hello 1"); flow_file_a->addAttribute("abc_2", "hello 2"); REQUIRE(expr(expression::Parameters{ flow_file_a.get() }).asBoolean()); @@ -1573,7 +1573,7 @@ TEST_CASE("All Matching Contains 3", "[expressionAllMatchingContains3]") { TEST_CASE("All Matching Contains 4", "[expressionAllMatchingContains4]") { auto expr = expression::compile("${allMatchingAttributes('xyz_.*'):contains('hello')}"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("xyz_1", "hello 1"); flow_file_a->addAttribute("xyz_2", "2"); REQUIRE(!expr(expression::Parameters{ flow_file_a.get() }).asBoolean()); @@ -1582,7 +1582,7 @@ TEST_CASE("All Matching Contains 4", "[expressionAllMatchingContains4]") { TEST_CASE("Any Matching Contains", "[expressionAnyMatchingContains]") { auto expr = expression::compile("${anyMatchingAttribute('xyz_.*'):contains('hello')}"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("xyz_1", "hello 1"); flow_file_a->addAttribute("xyz_2", "mello 2"); REQUIRE(expr(expression::Parameters{ flow_file_a.get() }).asBoolean()); @@ -1591,7 +1591,7 @@ TEST_CASE("Any Matching Contains", "[expressionAnyMatchingContains]") { TEST_CASE("Any Matching Contains 2", "[expressionAnyMatchingContains2]") { auto expr = expression::compile("${anyMatchingAttribute('abc_.*'):contains('hello')}"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("xyz_1", "hello 1"); flow_file_a->addAttribute("xyz_2", "mello 2"); REQUIRE(!expr(expression::Parameters{ flow_file_a.get() }).asBoolean()); @@ -1600,7 +1600,7 @@ TEST_CASE("Any Matching Contains 2", "[expressionAnyMatchingContains2]") { TEST_CASE("Any Matching Contains 3", "[expressionAnyMatchingContains3]") { auto expr = expression::compile("${anyMatchingAttribute('abc_.*'):contains('hello')}"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("abc_1", "hello 1"); flow_file_a->addAttribute("xyz_2", "mello 2"); REQUIRE(expr(expression::Parameters{ flow_file_a.get() }).asBoolean()); @@ -1609,7 +1609,7 @@ TEST_CASE("Any Matching Contains 3", "[expressionAnyMatchingContains3]") { TEST_CASE("Any Matching Contains 4", "[expressionAnyMatchingContains4]") { auto expr = expression::compile("${anyMatchingAttribute('abc_.*'):contains('hello')}"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("xyz_1", "mello 1"); flow_file_a->addAttribute("xyz_2", "mello 2"); REQUIRE(!expr(expression::Parameters{ flow_file_a.get() }).asBoolean()); @@ -1618,7 +1618,7 @@ TEST_CASE("Any Matching Contains 4", "[expressionAnyMatchingContains4]") { TEST_CASE("All Delineated Contains", "[expressionAllDelineatedContains]") { auto expr = expression::compile("${allDelineatedValues(${word_list}, \",\"):contains('hello')}"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("word_list", "hello_1,hello_2"); REQUIRE(expr(expression::Parameters{ flow_file_a.get() }).asBoolean()); } @@ -1626,7 +1626,7 @@ TEST_CASE("All Delineated Contains", "[expressionAllDelineatedContains]") { TEST_CASE("All Delineated Contains 2", "[expressionAllDelineatedContains2]") { auto expr = expression::compile("${allDelineatedValues(${word_list}, \",\"):contains('hello')}"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("word_list", "hello_1,mello_2"); REQUIRE(!expr(expression::Parameters{ flow_file_a.get() }).asBoolean()); } @@ -1634,7 +1634,7 @@ TEST_CASE("All Delineated Contains 2", "[expressionAllDelineatedContains2]") { TEST_CASE("All Delineated Contains 3", "[expressionAllDelineatedContains3]") { auto expr = expression::compile("${allDelineatedValues(${word_list}, \" \"):contains('1,h')}"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("word_list", "hello_1,hello_2"); REQUIRE(expr(expression::Parameters{ flow_file_a.get() }).asBoolean()); } @@ -1642,7 +1642,7 @@ TEST_CASE("All Delineated Contains 3", "[expressionAllDelineatedContains3]") { TEST_CASE("Any Delineated Contains", "[expressionAnyDelineatedContains]") { auto expr = expression::compile("${anyDelineatedValue(${word_list}, \",\"):contains('hello')}"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("word_list", "hello_1,mello_2"); REQUIRE(expr(expression::Parameters{ flow_file_a.get() }).asBoolean()); } @@ -1650,7 +1650,7 @@ TEST_CASE("Any Delineated Contains", "[expressionAnyDelineatedContains]") { TEST_CASE("Any Delineated Contains 2", "[expressionAnyDelineatedContains2]") { auto expr = expression::compile("${anyDelineatedValue(${word_list}, \",\"):contains('hello')}"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("word_list", "mello_1,mello_2"); REQUIRE(!expr(expression::Parameters{ flow_file_a.get() }).asBoolean()); } @@ -1658,7 +1658,7 @@ TEST_CASE("Any Delineated Contains 2", "[expressionAnyDelineatedContains2]") { TEST_CASE("Count", "[expressionCount]") { auto expr = expression::compile("${allAttributes('a', 'b'):contains('hello'):count()}"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("a", "hello 1"); flow_file_a->addAttribute("b", "mello 2"); REQUIRE(1 == expr(expression::Parameters{ flow_file_a.get() }).asUnsignedLong()); @@ -1667,7 +1667,7 @@ TEST_CASE("Count", "[expressionCount]") { TEST_CASE("Count 2", "[expressionCount2]") { auto expr = expression::compile("${allAttributes('a', 'b'):contains('mello'):count()}"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("a", "mello 1"); flow_file_a->addAttribute("b", "mello 2"); flow_file_a->addAttribute("c", "hello 3"); @@ -1677,7 +1677,7 @@ TEST_CASE("Count 2", "[expressionCount2]") { TEST_CASE("Count 3", "[expressionCount3]") { auto expr = expression::compile("abc${allAttributes('a', 'b'):contains('mello'):count()}xyz"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("a", "mello 1"); flow_file_a->addAttribute("b", "mello 2"); flow_file_a->addAttribute("c", "hello 3"); @@ -1687,7 +1687,7 @@ TEST_CASE("Count 3", "[expressionCount3]") { TEST_CASE("Join", "[expressionJoin]") { auto expr = expression::compile("abc_${allAttributes('a', 'b'):prepend('def_'):append('_ghi'):join(\"|\")}_xyz"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("a", "hello"); flow_file_a->addAttribute("b", "mello"); REQUIRE("abc_def_hello_ghi|def_mello_ghi_xyz" == expr(expression::Parameters{ flow_file_a.get() }).asString()); @@ -1696,7 +1696,7 @@ TEST_CASE("Join", "[expressionJoin]") { TEST_CASE("Join 2", "[expressionJoin2]") { auto expr = expression::compile("abc_${allAttributes('a', 'b'):join(\"|\"):prepend('def_'):append('_ghi')}_xyz"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); flow_file_a->addAttribute("a", "hello"); flow_file_a->addAttribute("b", "mello"); REQUIRE("abc_def_hello|mello_ghi_xyz" == expr(expression::Parameters{ flow_file_a.get() }).asString()); @@ -1705,7 +1705,7 @@ TEST_CASE("Join 2", "[expressionJoin2]") { TEST_CASE("resolve_user_id_test", "[resolve_user_id tests]") { auto expr = expression::compile("${attribute_sid:resolve_user_id()}"); - auto flow_file_a = std::make_shared(); + auto flow_file_a = std::make_shared(); SECTION("TEST 0") { flow_file_a->addAttribute("attribute_sid", "0"); diff --git a/extensions/expression-language/tests/ProcessContextExprTests.cpp b/extensions/expression-language/tests/ProcessContextExprTests.cpp index 89da89d83d..563961b1f9 100644 --- a/extensions/expression-language/tests/ProcessContextExprTests.cpp +++ b/extensions/expression-language/tests/ProcessContextExprTests.cpp @@ -21,18 +21,18 @@ #include "core/ProcessContext.h" #include "core/Resource.h" #include "ProcessContextExpr.h" -#include "Processor.h" -#include "PropertyDefinition.h" -#include "PropertyDefinitionBuilder.h" -#include "RelationshipDefinition.h" +#include "core/Processor.h" +#include "core/PropertyDefinition.h" +#include "core/PropertyDefinitionBuilder.h" +#include "core/RelationshipDefinition.h" #include "unit/TestBase.h" #include "unit/Catch.h" namespace org::apache::nifi::minifi { -class DummyProcessor : public core::Processor { +class DummyProcessor : public core::ProcessorImpl { public: - using core::Processor::Processor; + using core::ProcessorImpl::ProcessorImpl; static constexpr const char* Description = "A processor that does nothing."; static constexpr auto SimpleProperty = core::PropertyDefinitionBuilder<>::createProperty("Simple Property") diff --git a/extensions/gcp/controllerservices/GCPCredentialsControllerService.h b/extensions/gcp/controllerservices/GCPCredentialsControllerService.h index ded5f184d6..87c100d27e 100644 --- a/extensions/gcp/controllerservices/GCPCredentialsControllerService.h +++ b/extensions/gcp/controllerservices/GCPCredentialsControllerService.h @@ -23,7 +23,7 @@ #include "core/controller/ControllerService.h" #include "core/logging/Logger.h" -#include "core/logging/LoggerConfiguration.h" +#include "core/logging/LoggerFactory.h" #include "core/PropertyDefinition.h" #include "core/PropertyDefinitionBuilder.h" #include "utils/Enum.h" @@ -63,7 +63,7 @@ constexpr customize_t enum_name(CredentialsLocation value) namespace org::apache::nifi::minifi::extensions::gcp { -class GCPCredentialsControllerService : public core::controller::ControllerService { +class GCPCredentialsControllerService : public core::controller::ControllerServiceImpl { 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."; @@ -93,7 +93,7 @@ class GCPCredentialsControllerService : public core::controller::ControllerServi EXTENSIONAPI static constexpr bool SupportsDynamicProperties = false; ADD_COMMON_VIRTUAL_FUNCTIONS_FOR_CONTROLLER_SERVICES - using ControllerService::ControllerService; + using ControllerServiceImpl::ControllerServiceImpl; void initialize() override; diff --git a/extensions/gcp/processors/DeleteGCSObject.h b/extensions/gcp/processors/DeleteGCSObject.h index 93e56ccb7a..93e71c7668 100644 --- a/extensions/gcp/processors/DeleteGCSObject.h +++ b/extensions/gcp/processors/DeleteGCSObject.h @@ -23,7 +23,7 @@ #include "../GCPAttributes.h" #include "GCSProcessor.h" -#include "core/logging/LoggerConfiguration.h" +#include "core/logging/LoggerFactory.h" #include "core/OutputAttributeDefinition.h" #include "core/PropertyDefinition.h" #include "core/PropertyDefinitionBuilder.h" diff --git a/extensions/gcp/processors/FetchGCSObject.h b/extensions/gcp/processors/FetchGCSObject.h index ab51ae5d2b..cd030b237c 100644 --- a/extensions/gcp/processors/FetchGCSObject.h +++ b/extensions/gcp/processors/FetchGCSObject.h @@ -23,11 +23,10 @@ #include "../GCPAttributes.h" #include "GCSProcessor.h" -#include "PropertyDefinition.h" -#include "RelationshipDefinition.h" +#include "core/PropertyDefinition.h" +#include "core/RelationshipDefinition.h" #include "google/cloud/storage/well_known_headers.h" -#include "RelationshipDefinition.h" -#include "core/logging/LoggerConfiguration.h" +#include "core/logging/LoggerFactory.h" #include "utils/ArrayUtils.h" namespace org::apache::nifi::minifi::extensions::gcp { diff --git a/extensions/gcp/processors/GCSProcessor.h b/extensions/gcp/processors/GCSProcessor.h index d161064ca6..ff91633101 100644 --- a/extensions/gcp/processors/GCSProcessor.h +++ b/extensions/gcp/processors/GCSProcessor.h @@ -32,10 +32,10 @@ #include "google/cloud/storage/retry_policy.h" namespace org::apache::nifi::minifi::extensions::gcp { -class GCSProcessor : public core::Processor { +class GCSProcessor : public core::ProcessorImpl { public: GCSProcessor(std::string_view name, const minifi::utils::Identifier& uuid, std::shared_ptr logger) - : core::Processor(name, uuid), + : core::ProcessorImpl(name, uuid), logger_(std::move(logger)) { } diff --git a/extensions/gcp/processors/ListGCSBucket.h b/extensions/gcp/processors/ListGCSBucket.h index 229385aa61..87dece09b3 100644 --- a/extensions/gcp/processors/ListGCSBucket.h +++ b/extensions/gcp/processors/ListGCSBucket.h @@ -23,7 +23,7 @@ #include "../GCPAttributes.h" #include "GCSProcessor.h" -#include "core/logging/LoggerConfiguration.h" +#include "core/logging/LoggerFactory.h" #include "core/OutputAttributeDefinition.h" #include "core/PropertyDefinition.h" #include "core/PropertyDefinitionBuilder.h" diff --git a/extensions/gcp/processors/PutGCSObject.h b/extensions/gcp/processors/PutGCSObject.h index dae546b942..bdfe30fc19 100644 --- a/extensions/gcp/processors/PutGCSObject.h +++ b/extensions/gcp/processors/PutGCSObject.h @@ -23,11 +23,10 @@ #include "../GCPAttributes.h" #include "GCSProcessor.h" -#include "PropertyDefinition.h" -#include "PropertyType.h" -#include "RelationshipDefinition.h" -#include "core/logging/LoggerConfiguration.h" -#include "RelationshipDefinition.h" +#include "core/PropertyDefinition.h" +#include "core/PropertyType.h" +#include "core/RelationshipDefinition.h" +#include "core/logging/LoggerFactory.h" #include "utils/ArrayUtils.h" #include "utils/Enum.h" #include "google/cloud/storage/well_known_headers.h" diff --git a/extensions/grafana-loki/PushGrafanaLoki.cpp b/extensions/grafana-loki/PushGrafanaLoki.cpp index a3c14b58ce..191aade6ac 100644 --- a/extensions/grafana-loki/PushGrafanaLoki.cpp +++ b/extensions/grafana-loki/PushGrafanaLoki.cpp @@ -233,7 +233,7 @@ void PushGrafanaLoki::restore(const std::shared_ptr& flow_file) } std::set PushGrafanaLoki::getOutGoingConnections(const std::string &relationship) { - auto result = core::Connectable::getOutGoingConnections(relationship); + auto result = core::ConnectableImpl::getOutGoingConnections(relationship); if (relationship == Self.getName()) { result.insert(this); } diff --git a/extensions/grafana-loki/PushGrafanaLoki.h b/extensions/grafana-loki/PushGrafanaLoki.h index 445677d20d..20148d0a25 100644 --- a/extensions/grafana-loki/PushGrafanaLoki.h +++ b/extensions/grafana-loki/PushGrafanaLoki.h @@ -32,10 +32,10 @@ namespace org::apache::nifi::minifi::extensions::grafana::loki { -class PushGrafanaLoki : public core::Processor { +class PushGrafanaLoki : public core::ProcessorImpl { public: - PushGrafanaLoki(const std::string& name, const utils::Identifier& uuid, const std::shared_ptr& logger) - : Processor(name, uuid), + PushGrafanaLoki(const std::string_view name, const utils::Identifier& uuid, const std::shared_ptr& logger) + : ProcessorImpl(name, uuid), logger_(logger), log_batch_(logger_) { } diff --git a/extensions/grafana-loki/PushGrafanaLokiGrpc.h b/extensions/grafana-loki/PushGrafanaLokiGrpc.h index 1817c06149..78bc5f897d 100644 --- a/extensions/grafana-loki/PushGrafanaLokiGrpc.h +++ b/extensions/grafana-loki/PushGrafanaLokiGrpc.h @@ -18,19 +18,20 @@ #include "PushGrafanaLoki.h" +#include "core/logging/LoggerFactory.h" #include "core/StateManager.h" -#include "grafana-loki-push.pb.h" #include "grafana-loki-push.grpc.pb.h" +#include "grafana-loki-push.pb.h" #include "grpc/grpc.h" namespace org::apache::nifi::minifi::extensions::grafana::loki { -class PushGrafanaLokiGrpc : public PushGrafanaLoki { +class PushGrafanaLokiGrpc final : public PushGrafanaLoki { public: EXTENSIONAPI static constexpr const char* Description = "A Grafana Loki push processor that uses the Grafana Loki Grpc port. The processor expects each flow file to contain a single log line to be " "pushed to Grafana Loki, therefore it is usually used together with the TailFile processor."; - explicit PushGrafanaLokiGrpc(const std::string& name, const utils::Identifier& uuid = {}) + explicit PushGrafanaLokiGrpc(const std::string_view name, const utils::Identifier& uuid = {}) : PushGrafanaLoki(name, uuid, core::logging::LoggerFactory::getLogger(uuid)) { } ~PushGrafanaLokiGrpc() override = default; @@ -64,7 +65,7 @@ class PushGrafanaLokiGrpc : public PushGrafanaLoki { void setUpGrpcChannel(const std::string& url, core::ProcessContext& context); std::string stream_labels_; - std::chrono::milliseconds connection_timeout_ms_; + std::chrono::milliseconds connection_timeout_ms_{}; std::optional tenant_id_; std::shared_ptr<::grpc::Channel> push_channel_; std::unique_ptr push_stub_; diff --git a/extensions/grafana-loki/tests/MockGrafanaLokiREST.h b/extensions/grafana-loki/tests/MockGrafanaLokiREST.h index 0a92d3e077..e09ad21c23 100644 --- a/extensions/grafana-loki/tests/MockGrafanaLokiREST.h +++ b/extensions/grafana-loki/tests/MockGrafanaLokiREST.h @@ -24,7 +24,7 @@ #include #include "integration/CivetLibrary.h" #include "core/logging/Logger.h" -#include "core/logging/LoggerConfiguration.h" +#include "core/logging/LoggerFactory.h" #include "rapidjson/document.h" #include "rapidjson/writer.h" #include "rapidjson/stringbuffer.h" diff --git a/extensions/kafka/ConsumeKafka.h b/extensions/kafka/ConsumeKafka.h index 616c4eb95a..79a99e0de0 100644 --- a/extensions/kafka/ConsumeKafka.h +++ b/extensions/kafka/ConsumeKafka.h @@ -29,7 +29,7 @@ #include "core/PropertyDefinitionBuilder.h" #include "core/PropertyType.h" #include "core/RelationshipDefinition.h" -#include "core/logging/LoggerConfiguration.h" +#include "core/logging/LoggerFactory.h" #include "io/StreamPipe.h" #include "rdkafka.h" #include "rdkafka_utils.h" diff --git a/extensions/kafka/KafkaConnection.h b/extensions/kafka/KafkaConnection.h index 186c506476..93f5bc08e4 100644 --- a/extensions/kafka/KafkaConnection.h +++ b/extensions/kafka/KafkaConnection.h @@ -24,7 +24,7 @@ #include #include -#include "core/logging/LoggerConfiguration.h" +#include "core/logging/LoggerFactory.h" #include "core/logging/Logger.h" #include "rdkafka.h" #include "KafkaTopic.h" diff --git a/extensions/kafka/KafkaProcessorBase.h b/extensions/kafka/KafkaProcessorBase.h index 87f0fc78cb..fa0c05a33a 100644 --- a/extensions/kafka/KafkaProcessorBase.h +++ b/extensions/kafka/KafkaProcessorBase.h @@ -35,7 +35,7 @@ enum class SecurityProtocolOption { plaintext, ssl, sasl_plaintext, sasl_ssl }; enum class SASLMechanismOption { GSSAPI, PLAIN }; } // namespace kafka -class KafkaProcessorBase : public core::Processor { +class KafkaProcessorBase : public core::ProcessorImpl { public: EXTENSIONAPI static constexpr auto SSLContextService = core::PropertyDefinitionBuilder<>::createProperty("SSL Context Service") @@ -90,7 +90,7 @@ class KafkaProcessorBase : public core::Processor { KafkaProcessorBase( const std::string_view name, const utils::Identifier& uuid, std::shared_ptr logger) - : core::Processor(name, uuid), + : core::ProcessorImpl(name, uuid), logger_(std::move(logger)) {} KafkaProcessorBase(const KafkaProcessorBase&) = delete; diff --git a/extensions/kafka/PublishKafka.h b/extensions/kafka/PublishKafka.h index 1fd5e34087..5ddf035b26 100644 --- a/extensions/kafka/PublishKafka.h +++ b/extensions/kafka/PublishKafka.h @@ -38,7 +38,7 @@ #include "core/PropertyType.h" #include "core/RelationshipDefinition.h" #include "core/logging/Logger.h" -#include "core/logging/LoggerConfiguration.h" +#include "core/logging/LoggerFactory.h" #include "rdkafka.h" #include "utils/ArrayUtils.h" #include "utils/RegexUtils.h" diff --git a/extensions/kafka/rdkafka_utils.h b/extensions/kafka/rdkafka_utils.h index 36a20d20b1..6d9214825e 100644 --- a/extensions/kafka/rdkafka_utils.h +++ b/extensions/kafka/rdkafka_utils.h @@ -24,7 +24,7 @@ #include #include -#include "core/logging/LoggerConfiguration.h" +#include "core/logging/LoggerFactory.h" #include "rdkafka.h" #include "utils/net/Ssl.h" diff --git a/extensions/kubernetes/controllerservice/KubernetesControllerService.cpp b/extensions/kubernetes/controllerservice/KubernetesControllerService.cpp index ac2ef0f61f..e114457e40 100644 --- a/extensions/kubernetes/controllerservice/KubernetesControllerService.cpp +++ b/extensions/kubernetes/controllerservice/KubernetesControllerService.cpp @@ -24,19 +24,19 @@ extern "C" { } #include "core/Resource.h" -#include "core/logging/LoggerConfiguration.h" +#include "core/logging/LoggerFactory.h" #include "Exception.h" #include "utils/gsl.h" #include "utils/StringUtils.h" namespace org::apache::nifi::minifi::controllers { -KubernetesControllerService::KubernetesControllerService(const std::string& name, const utils::Identifier& uuid) - : AttributeProviderService(name, uuid), +KubernetesControllerService::KubernetesControllerService(const std::string_view name, const utils::Identifier& uuid) + : AttributeProviderServiceImpl(name, uuid), logger_{core::logging::LoggerFactory::getLogger(uuid)} { } -KubernetesControllerService::KubernetesControllerService(const std::string& name, const std::shared_ptr& configuration) +KubernetesControllerService::KubernetesControllerService(const std::string_view name, const std::shared_ptr& configuration) : KubernetesControllerService{name} { setConfiguration(configuration); initialize(); @@ -46,7 +46,7 @@ void KubernetesControllerService::initialize() { std::lock_guard lock(initialization_mutex_); if (initialized_) { return; } - ControllerService::initialize(); + ControllerServiceImpl::initialize(); setSupportedProperties(Properties); initialized_ = true; } diff --git a/extensions/kubernetes/controllerservice/KubernetesControllerService.h b/extensions/kubernetes/controllerservice/KubernetesControllerService.h index ffe1f50463..b75ba9848a 100644 --- a/extensions/kubernetes/controllerservice/KubernetesControllerService.h +++ b/extensions/kubernetes/controllerservice/KubernetesControllerService.h @@ -31,10 +31,10 @@ namespace org::apache::nifi::minifi::controllers { -class KubernetesControllerService : public AttributeProviderService { +class KubernetesControllerService : public AttributeProviderServiceImpl { public: - explicit KubernetesControllerService(const std::string& name, const utils::Identifier& uuid = {}); - KubernetesControllerService(const std::string& name, const std::shared_ptr& configuration); + explicit KubernetesControllerService(const std::string_view name, const utils::Identifier& uuid = {}); + KubernetesControllerService(const std::string_view name, const std::shared_ptr& configuration); EXTENSIONAPI static constexpr const char* Description = "Controller service that provides access to the Kubernetes API"; diff --git a/extensions/kubernetes/processors/CollectKubernetesPodMetrics.h b/extensions/kubernetes/processors/CollectKubernetesPodMetrics.h index 37ebcf41b5..64ea727239 100644 --- a/extensions/kubernetes/processors/CollectKubernetesPodMetrics.h +++ b/extensions/kubernetes/processors/CollectKubernetesPodMetrics.h @@ -20,17 +20,17 @@ #include #include "../controllerservice/KubernetesControllerService.h" -#include "core/logging/LoggerConfiguration.h" +#include "core/logging/LoggerFactory.h" #include "core/Processor.h" #include "core/PropertyDefinition.h" #include "core/PropertyDefinitionBuilder.h" namespace org::apache::nifi::minifi::processors { -class CollectKubernetesPodMetrics : public core::Processor { +class CollectKubernetesPodMetrics : public core::ProcessorImpl { public: - explicit CollectKubernetesPodMetrics(const std::string& name, const utils::Identifier& uuid = {}) - : Processor(name, uuid) { + explicit CollectKubernetesPodMetrics(const std::string_view name, const utils::Identifier& uuid = {}) + : ProcessorImpl(name, uuid) { } EXTENSIONAPI static constexpr const char* Description = "A processor which collects pod metrics when MiNiFi is run inside Kubernetes."; diff --git a/extensions/libarchive/ArchiveStreamProvider.cpp b/extensions/libarchive/ArchiveStreamProvider.cpp index d9ebf3eee0..d7bfae95c9 100644 --- a/extensions/libarchive/ArchiveStreamProvider.cpp +++ b/extensions/libarchive/ArchiveStreamProvider.cpp @@ -23,9 +23,9 @@ namespace org::apache::nifi::minifi::io { -class ArchiveStreamProviderImpl : public ArchiveStreamProvider { +class ArchiveStreamProviderImpl : public core::CoreComponentImpl, public virtual ArchiveStreamProvider { public: - using ArchiveStreamProvider::ArchiveStreamProvider; + using CoreComponentImpl::CoreComponentImpl; EXTENSIONAPI static constexpr auto Properties = std::array{}; EXTENSIONAPI static constexpr bool SupportsDynamicProperties = false; @@ -48,6 +48,6 @@ class ArchiveStreamProviderImpl : public ArchiveStreamProvider { } }; -REGISTER_RESOURCE_AS(ArchiveStreamProviderImpl, InternalResource, ("ArchiveStreamProvider")); +REGISTER_RESOURCE_IMPLEMENTATION(ArchiveStreamProviderImpl, "ArchiveStreamProvider", InternalResource); } // namespace org::apache::nifi::minifi::io diff --git a/extensions/libarchive/BinFiles.cpp b/extensions/libarchive/BinFiles.cpp index b0687d46e8..0d0e109849 100644 --- a/extensions/libarchive/BinFiles.cpp +++ b/extensions/libarchive/BinFiles.cpp @@ -318,7 +318,7 @@ void BinFiles::restore(const std::shared_ptr& flowFile) { } std::set BinFiles::getOutGoingConnections(const std::string &relationship) { - auto result = core::Connectable::getOutGoingConnections(relationship); + auto result = core::ConnectableImpl::getOutGoingConnections(relationship); if (relationship == Self.getName()) { result.insert(this); } diff --git a/extensions/libarchive/BinFiles.h b/extensions/libarchive/BinFiles.h index ad26382549..e90b708c09 100644 --- a/extensions/libarchive/BinFiles.h +++ b/extensions/libarchive/BinFiles.h @@ -32,7 +32,7 @@ #include "core/PropertyDefinitionBuilder.h" #include "core/PropertyType.h" #include "core/RelationshipDefinition.h" -#include "core/logging/LoggerConfiguration.h" +#include "core/logging/LoggerFactory.h" #include "utils/gsl.h" #include "utils/Id.h" #include "utils/Export.h" @@ -177,12 +177,12 @@ class BinManager { std::shared_ptr logger_{core::logging::LoggerFactory::getLogger()}; }; -class BinFiles : public core::Processor { +class BinFiles : public core::ProcessorImpl { protected: static const core::Relationship Self; public: - using core::Processor::Processor; + using core::ProcessorImpl::ProcessorImpl; ~BinFiles() override = default; EXTENSIONAPI static constexpr const char* Description = "Bins flow files into buckets based on the number of entries or size of entries"; diff --git a/extensions/libarchive/CompressContent.h b/extensions/libarchive/CompressContent.h index 99f6d792bf..ec136918c5 100644 --- a/extensions/libarchive/CompressContent.h +++ b/extensions/libarchive/CompressContent.h @@ -26,7 +26,7 @@ #include #include -#include "PropertyType.h" +#include "core/PropertyType.h" #include "archive_entry.h" #include "archive.h" @@ -36,7 +36,7 @@ #include "core/Core.h" #include "core/PropertyDefinition.h" #include "core/PropertyDefinitionBuilder.h" -#include "core/logging/LoggerConfiguration.h" +#include "core/logging/LoggerFactory.h" #include "io/ZlibStream.h" #include "utils/Enum.h" #include "utils/gsl.h" @@ -83,10 +83,10 @@ constexpr customize_t enum_name(ExtendedCompressionFo namespace org::apache::nifi::minifi::processors { -class CompressContent : public core::Processor { +class CompressContent : public core::ProcessorImpl { public: explicit CompressContent(std::string_view name, const utils::Identifier& uuid = {}) - : core::Processor(name, uuid) { + : core::ProcessorImpl(name, uuid) { } ~CompressContent() override = default; diff --git a/extensions/libarchive/FocusArchiveEntry.h b/extensions/libarchive/FocusArchiveEntry.h index 09d54e06f4..551802a320 100644 --- a/extensions/libarchive/FocusArchiveEntry.h +++ b/extensions/libarchive/FocusArchiveEntry.h @@ -30,16 +30,16 @@ #include "core/PropertyDefinitionBuilder.h" #include "core/RelationshipDefinition.h" #include "core/Core.h" -#include "core/logging/LoggerConfiguration.h" +#include "core/logging/LoggerFactory.h" #include "utils/file/FileManager.h" #include "utils/Export.h" namespace org::apache::nifi::minifi::processors { -class FocusArchiveEntry : public core::Processor { +class FocusArchiveEntry : public core::ProcessorImpl { public: explicit FocusArchiveEntry(std::string_view name, const utils::Identifier& uuid = {}) - : core::Processor(name, uuid) { + : core::ProcessorImpl(name, uuid) { } ~FocusArchiveEntry() override = default; diff --git a/extensions/libarchive/ManipulateArchive.h b/extensions/libarchive/ManipulateArchive.h index ce6c0e5c37..712965b3da 100644 --- a/extensions/libarchive/ManipulateArchive.h +++ b/extensions/libarchive/ManipulateArchive.h @@ -36,10 +36,10 @@ namespace org::apache::nifi::minifi::processors { using core::logging::Logger; -class ManipulateArchive : public core::Processor { +class ManipulateArchive : public core::ProcessorImpl { public: explicit ManipulateArchive(std::string_view name, const utils::Identifier& uuid = {}) - : core::Processor(name, uuid) { + : core::ProcessorImpl(name, uuid) { } ~ManipulateArchive() override = default; diff --git a/extensions/libarchive/MergeContent.cpp b/extensions/libarchive/MergeContent.cpp index 45a7c13f9b..591b7b1b19 100644 --- a/extensions/libarchive/MergeContent.cpp +++ b/extensions/libarchive/MergeContent.cpp @@ -213,7 +213,7 @@ bool MergeContent::processBin(core::ProcessSession &session, std::unique_ptr merge_flow = std::static_pointer_cast(session.create()); + std::shared_ptr merge_flow = session.create(); auto removeMergeFlow = gsl::finally([&](){ if (!session.hasBeenTransferred(*merge_flow)) { session.remove(merge_flow); diff --git a/extensions/libarchive/MergeContent.h b/extensions/libarchive/MergeContent.h index 4995732b83..cf88b7e1ae 100644 --- a/extensions/libarchive/MergeContent.h +++ b/extensions/libarchive/MergeContent.h @@ -28,13 +28,14 @@ #include "archive_entry.h" #include "archive.h" #include "SmartArchivePtrs.h" -#include "core/logging/LoggerConfiguration.h" +#include "core/logging/LoggerFactory.h" #include "core/PropertyDefinitionBuilder.h" #include "core/PropertyType.h" #include "serialization/FlowFileSerializer.h" #include "utils/ArrayUtils.h" #include "utils/gsl.h" #include "utils/Export.h" +#include "io/Stream.h" namespace org::apache::nifi::minifi::processors { @@ -122,7 +123,7 @@ class BinaryConcatenationMerge : public MergeBin { class ArchiveMerge { public: - class ArchiveWriter : public io::OutputStream { + class ArchiveWriter : public io::StreamImpl, public io::OutputStream { public: ArchiveWriter(archive& arch, archive_entry& entry) : arch_(arch), entry_(entry) {} size_t write(const uint8_t* data, const size_t size) override { diff --git a/extensions/libarchive/ReadArchiveStream.h b/extensions/libarchive/ReadArchiveStream.h index 0d1b87abdf..910f808e4f 100644 --- a/extensions/libarchive/ReadArchiveStream.h +++ b/extensions/libarchive/ReadArchiveStream.h @@ -23,7 +23,8 @@ #include "io/OutputStream.h" #include "io/ArchiveStream.h" -#include "core/logging/LoggerConfiguration.h" +#include "io/InputStream.h" +#include "core/logging/LoggerFactory.h" #include "archive_entry.h" #include "archive.h" @@ -31,7 +32,7 @@ namespace org::apache::nifi::minifi::io { -class ReadArchiveStreamImpl final : public ReadArchiveStream { +class ReadArchiveStreamImpl final : public InputStreamImpl, public ReadArchiveStream { class BufferedReader { public: explicit BufferedReader(std::shared_ptr input) : input_(std::move(input)) {} diff --git a/extensions/libarchive/UnfocusArchiveEntry.h b/extensions/libarchive/UnfocusArchiveEntry.h index bdaa5ec0cd..db6cd738a6 100644 --- a/extensions/libarchive/UnfocusArchiveEntry.h +++ b/extensions/libarchive/UnfocusArchiveEntry.h @@ -32,16 +32,16 @@ #include "core/ProcessSession.h" #include "core/RelationshipDefinition.h" #include "core/Core.h" -#include "core/logging/LoggerConfiguration.h" +#include "core/logging/LoggerFactory.h" namespace org::apache::nifi::minifi::processors { using core::logging::Logger; -class UnfocusArchiveEntry : public core::Processor { +class UnfocusArchiveEntry : public core::ProcessorImpl { public: explicit UnfocusArchiveEntry(std::string_view name, const utils::Identifier& uuid = {}) - : core::Processor(name, uuid) { + : core::ProcessorImpl(name, uuid) { } ~UnfocusArchiveEntry() override = default; diff --git a/extensions/libarchive/WriteArchiveStream.h b/extensions/libarchive/WriteArchiveStream.h index 7d86c6db5b..4369543ad7 100644 --- a/extensions/libarchive/WriteArchiveStream.h +++ b/extensions/libarchive/WriteArchiveStream.h @@ -27,7 +27,9 @@ #include "archive.h" #include "SmartArchivePtrs.h" #include "utils/Enum.h" -#include "logging/LoggerConfiguration.h" +#include "core/Core.h" +#include "core/logging/LoggerFactory.h" +#include "io/Stream.h" namespace org::apache::nifi::minifi::io { @@ -61,7 +63,7 @@ constexpr customize_t enum_name(CompressionFormat value) noex namespace org::apache::nifi::minifi::io { -class WriteArchiveStreamImpl final: public WriteArchiveStream { +class WriteArchiveStreamImpl final: public StreamImpl, public WriteArchiveStream { [[nodiscard]] processors::archive_write_unique_ptr createWriteArchive() const; public: diff --git a/extensions/libarchive/tests/CompressContentTests.cpp b/extensions/libarchive/tests/CompressContentTests.cpp index 31d266b2bb..aa9459b3d4 100644 --- a/extensions/libarchive/tests/CompressContentTests.cpp +++ b/extensions/libarchive/tests/CompressContentTests.cpp @@ -123,21 +123,21 @@ class CompressDecompressionTestController : public TestController { REQUIRE(processoruuid); std::shared_ptr content_repo = std::make_shared(); - content_repo->initialize(std::make_shared()); + content_repo->initialize(std::make_shared()); // connection from compress processor to success - output = std::make_shared(repo, content_repo, "Output"); + output = std::make_shared(repo, content_repo, "Output"); output->addRelationship(core::Relationship("success", "compress successful output")); output->setSource(processor.get()); output->setSourceUUID(processoruuid); processor->addConnection(output.get()); // connection to compress processor - input = std::make_shared(repo, content_repo, "Input"); + input = std::make_shared(repo, content_repo, "Input"); input->setDestination(processor.get()); input->setDestinationUUID(processoruuid); processor->addConnection(input.get()); // connection from compress processor to failure - failure_output = std::make_shared(repo, content_repo, "FailureOutput"); + failure_output = std::make_shared(repo, content_repo, "FailureOutput"); failure_output->addRelationship(core::Relationship("failure", "compress failure output")); failure_output->setSource(processor.get()); failure_output->setSourceUUID(processoruuid); @@ -146,8 +146,8 @@ class CompressDecompressionTestController : public TestController { processor->incrementActiveTasks(); processor->setScheduledState(core::ScheduledState::RUNNING); - context = std::make_shared(std::make_shared(processor.get()), nullptr, repo, repo, content_repo); - helper_session = std::make_shared(context); + context = std::make_shared(std::make_shared(processor.get()), nullptr, repo, repo, content_repo); + helper_session = std::make_shared(context); } [[nodiscard]] std::shared_ptr importFlowFile(const std::filesystem::path& content_path) const { @@ -168,9 +168,9 @@ class CompressDecompressionTestController : public TestController { } void trigger() const { - auto factory = core::ProcessSessionFactory(context); + auto factory = core::ProcessSessionFactoryImpl(context); processor->onSchedule(*context, factory); - auto session = core::ProcessSession(context); + auto session = core::ProcessSessionImpl(context); processor->onTrigger(*context, session); session.commit(); } @@ -645,12 +645,12 @@ TEST_CASE_METHOD(CompressTestController, "Batch CompressFileGZip", "[compressFil } REQUIRE(processor->getName() == "compresscontent"); - auto factory = std::make_shared(context); + auto factory = std::make_shared(context); processor->onSchedule(*context, *factory); // Trigger once to process batchSize { - auto session = std::make_shared(context); + auto session = std::make_shared(context); processor->onTrigger(*context, *session); session->commit(); } @@ -665,7 +665,7 @@ TEST_CASE_METHOD(CompressTestController, "Batch CompressFileGZip", "[compressFil // Trigger a second time to process the remaining files { - auto session = std::make_unique(context); + auto session = std::make_unique(context); processor->onTrigger(*context, *session); session->commit(); } diff --git a/extensions/libarchive/tests/MergeFileTests.cpp b/extensions/libarchive/tests/MergeFileTests.cpp index d5fd73d7ee..f49139806b 100644 --- a/extensions/libarchive/tests/MergeFileTests.cpp +++ b/extensions/libarchive/tests/MergeFileTests.cpp @@ -25,7 +25,7 @@ #include #include -#include "Relationship.h" +#include "core/Relationship.h" #include "core/Core.h" #include "core/Processor.h" #include "core/ProcessContext.h" @@ -162,7 +162,7 @@ class MergeTestController : public TestController { std::shared_ptr repo = std::make_shared(); auto content_repo = std::make_shared(); - content_repo->initialize(std::make_shared()); + content_repo->initialize(std::make_shared()); merge_content_processor_ = std::make_unique("mergecontent"); merge_content_processor_->initialize(); @@ -173,7 +173,7 @@ class MergeTestController : public TestController { REQUIRE(logAttributeuuid); // output from merge processor to log attribute - output_ = std::make_unique(repo, content_repo, "logattributeconnection"); + output_ = std::make_unique(repo, content_repo, "logattributeconnection"); output_->addRelationship(minifi::processors::MergeContent::Merge); output_->setSource(merge_content_processor_.get()); output_->setDestination(log_attribute_processor_.get()); @@ -181,7 +181,7 @@ class MergeTestController : public TestController { output_->setDestinationUUID(logAttributeuuid); merge_content_processor_->addConnection(output_.get()); // input to merge processor - input_ = std::make_unique(repo, content_repo, "mergeinput"); + input_ = std::make_unique(repo, content_repo, "mergeinput"); input_->setDestination(merge_content_processor_.get()); input_->setDestinationUUID(processoruuid); merge_content_processor_->addConnection(input_.get()); @@ -193,7 +193,7 @@ class MergeTestController : public TestController { log_attribute_processor_->incrementActiveTasks(); log_attribute_processor_->setScheduledState(core::ScheduledState::RUNNING); - context_ = std::make_shared(std::make_shared(merge_content_processor_.get()), nullptr, repo, repo, content_repo); + context_ = std::make_shared(std::make_shared(merge_content_processor_.get()), nullptr, repo, repo, content_repo); for (size_t i = 0; i < 6; ++i) { flowFileContents_[i] = utils::string::repeat(std::to_string(i), 32); @@ -227,7 +227,7 @@ TEST_CASE_METHOD(MergeTestController, "MergeFileDefragment", "[mergefiletest1]") context_->setProperty(minifi::processors::MergeContent::MergeStrategy, minifi::processors::merge_content_options::MERGE_STRATEGY_DEFRAGMENT); context_->setProperty(minifi::processors::MergeContent::DelimiterStrategy, minifi::processors::merge_content_options::DELIMITER_STRATEGY_TEXT); - core::ProcessSession sessionGenFlowFile(context_); + core::ProcessSessionImpl sessionGenFlowFile(context_); // Generate 6 flowfiles, first three merged to one, second three merged to one for (const int i : {0, 2, 5, 4, 1, 3}) { const auto flow = sessionGenFlowFile.create(); @@ -246,10 +246,10 @@ TEST_CASE_METHOD(MergeTestController, "MergeFileDefragment", "[mergefiletest1]") input_->put(flow); } - auto factory = std::make_shared(context_); + auto factory = std::make_shared(context_); merge_content_processor_->onSchedule(*context_, *factory); for (int i = 0; i < 6; i++) { - auto session = std::make_shared(context_); + auto session = std::make_shared(context_); merge_content_processor_->onTrigger(*context_, *session); session->commit(); } @@ -288,7 +288,7 @@ TEST_CASE_METHOD(MergeTestController, "MergeFileDefragmentDelimiter", "[mergefil context_->setProperty(minifi::processors::MergeContent::Footer, FOOTER_FILE); context_->setProperty(minifi::processors::MergeContent::Demarcator, DEMARCATOR_FILE); - core::ProcessSession sessionGenFlowFile(context_); + core::ProcessSessionImpl sessionGenFlowFile(context_); // Generate 6 flowfiles, first three merged to one, second three merged to one for (const int i : {0, 2, 5, 4, 1, 3}) { const auto flow = sessionGenFlowFile.create(); @@ -308,10 +308,10 @@ TEST_CASE_METHOD(MergeTestController, "MergeFileDefragmentDelimiter", "[mergefil } REQUIRE(merge_content_processor_->getName() == "mergecontent"); - auto factory = std::make_shared(context_); + auto factory = std::make_shared(context_); merge_content_processor_->onSchedule(*context_, *factory); for (int i = 0; i < 6; i++) { - auto session = std::make_shared(context_); + auto session = std::make_shared(context_); merge_content_processor_->onTrigger(*context_, *session); session->commit(); } @@ -345,7 +345,7 @@ TEST_CASE_METHOD(MergeTestController, "MergeFileDefragmentDropFlow", "[mergefile context_->setProperty(minifi::processors::MergeContent::DelimiterStrategy, minifi::processors::merge_content_options::DELIMITER_STRATEGY_TEXT); context_->setProperty(minifi::processors::MergeContent::MaxBinAge, "1 sec"); - core::ProcessSession sessionGenFlowFile(context_); + core::ProcessSessionImpl sessionGenFlowFile(context_); // Generate 5 flowfiles, first threes merged to one, the other two merged to one for (const int i : {0, 2, 5, 1, 3}) { const auto flow = sessionGenFlowFile.create(); @@ -365,16 +365,16 @@ TEST_CASE_METHOD(MergeTestController, "MergeFileDefragmentDropFlow", "[mergefile } REQUIRE(merge_content_processor_->getName() == "mergecontent"); - auto factory = std::make_shared(context_); + auto factory = std::make_shared(context_); merge_content_processor_->onSchedule(*context_, *factory); for (int i = 0; i < 5; i++) { - auto session = std::make_shared(context_); + auto session = std::make_shared(context_); merge_content_processor_->onTrigger(*context_, *session); session->commit(); } std::this_thread::sleep_for(std::chrono::milliseconds(2000)); { - auto session = std::make_shared(context_); + auto session = std::make_shared(context_); merge_content_processor_->onTrigger(*context_, *session); session->commit(); } @@ -408,7 +408,7 @@ TEST_CASE_METHOD(MergeTestController, "MergeFileBinPack", "[mergefiletest4]") { context_->setProperty(minifi::processors::MergeContent::MinSize, "96"); context_->setProperty(minifi::processors::MergeContent::CorrelationAttributeName, "tag"); - core::ProcessSession sessionGenFlowFile(context_); + core::ProcessSessionImpl sessionGenFlowFile(context_); // Generate 6 flowfiles, first threes merged to one, second thress merged to one for (const int i : {0, 1, 2, 3, 4, 5}) { const auto flow = sessionGenFlowFile.create(); @@ -419,10 +419,10 @@ TEST_CASE_METHOD(MergeTestController, "MergeFileBinPack", "[mergefiletest4]") { } REQUIRE(merge_content_processor_->getName() == "mergecontent"); - auto factory = std::make_shared(context_); + auto factory = std::make_shared(context_); merge_content_processor_->onSchedule(*context_, *factory); for (int i = 0; i < 6; i++) { - auto session = std::make_shared(context_); + auto session = std::make_shared(context_); merge_content_processor_->onTrigger(*context_, *session); session->commit(); } @@ -452,7 +452,7 @@ TEST_CASE_METHOD(MergeTestController, "MergeFileTar", "[mergefiletest4]") { context_->setProperty(minifi::processors::MergeContent::MinSize, "96"); context_->setProperty(minifi::processors::MergeContent::CorrelationAttributeName, "tag"); - core::ProcessSession sessionGenFlowFile(context_); + core::ProcessSessionImpl sessionGenFlowFile(context_); // Generate 6 flowfiles, first threes merged to one, second thress merged to one for (const int i : {0, 1, 2, 3, 4, 5}) { const auto flow = sessionGenFlowFile.create(); @@ -463,10 +463,10 @@ TEST_CASE_METHOD(MergeTestController, "MergeFileTar", "[mergefiletest4]") { } REQUIRE(merge_content_processor_->getName() == "mergecontent"); - auto factory = std::make_shared(context_); + auto factory = std::make_shared(context_); merge_content_processor_->onSchedule(*context_, *factory); for (int i = 0; i < 6; i++) { - auto session = std::make_shared(context_); + auto session = std::make_shared(context_); merge_content_processor_->onTrigger(*context_, *session); session->commit(); } @@ -503,7 +503,7 @@ TEST_CASE_METHOD(MergeTestController, "MergeFileZip", "[mergefiletest5]") { context_->setProperty(minifi::processors::MergeContent::MinSize, "96"); context_->setProperty(minifi::processors::MergeContent::CorrelationAttributeName, "tag"); - core::ProcessSession sessionGenFlowFile(context_); + core::ProcessSessionImpl sessionGenFlowFile(context_); // Generate 6 flowfiles, first threes merged to one, second thress merged to one for (const int i : {0, 1, 2, 3, 4, 5}) { const auto flow = sessionGenFlowFile.create(); @@ -514,10 +514,10 @@ TEST_CASE_METHOD(MergeTestController, "MergeFileZip", "[mergefiletest5]") { } REQUIRE(merge_content_processor_->getName() == "mergecontent"); - auto factory = std::make_shared(context_); + auto factory = std::make_shared(context_); merge_content_processor_->onSchedule(*context_, *factory); for (int i = 0; i < 6; i++) { - auto session = std::make_shared(context_); + auto session = std::make_shared(context_); merge_content_processor_->onTrigger(*context_, *session); session->commit(); } @@ -559,7 +559,7 @@ TEST_CASE_METHOD(MergeTestController, "MergeFileOnAttribute", "[mergefiletest5]" context_->setProperty(minifi::processors::MergeContent::MinEntries, "3"); context_->setProperty(minifi::processors::MergeContent::CorrelationAttributeName, "tag"); - core::ProcessSession sessionGenFlowFile(context_); + core::ProcessSessionImpl sessionGenFlowFile(context_); // Generate 6 flowfiles, even files are merged to one, odd files are merged to an other for (const int i : {0, 1, 2, 3, 4, 5}) { const auto flow = sessionGenFlowFile.create(); @@ -573,10 +573,10 @@ TEST_CASE_METHOD(MergeTestController, "MergeFileOnAttribute", "[mergefiletest5]" } REQUIRE(merge_content_processor_->getName() == "mergecontent"); - auto factory = std::make_shared(context_); + auto factory = std::make_shared(context_); merge_content_processor_->onSchedule(*context_, *factory); for (int i = 0; i < 6; i++) { - auto session = std::make_shared(context_); + auto session = std::make_shared(context_); merge_content_processor_->onTrigger(*context_, *session); session->commit(); } @@ -601,7 +601,7 @@ TEST_CASE_METHOD(MergeTestController, "Test Merge File Attributes Keeping Only C context_->setProperty(minifi::processors::MergeContent::MergeStrategy, minifi::processors::merge_content_options::MERGE_STRATEGY_DEFRAGMENT); context_->setProperty(minifi::processors::MergeContent::DelimiterStrategy, minifi::processors::merge_content_options::DELIMITER_STRATEGY_TEXT); - core::ProcessSession sessionGenFlowFile(context_); + core::ProcessSessionImpl sessionGenFlowFile(context_); // Generate 3 flowfiles merging all into one for (const int i : {1, 2, 0}) { @@ -626,10 +626,10 @@ TEST_CASE_METHOD(MergeTestController, "Test Merge File Attributes Keeping Only C input_->put(flow); } - auto factory = std::make_shared(context_); + auto factory = std::make_shared(context_); merge_content_processor_->onSchedule(*context_, *factory); for (int i = 0; i < 3; i++) { - auto session = std::make_shared(context_); + auto session = std::make_shared(context_); merge_content_processor_->onTrigger(*context_, *session); session->commit(); } @@ -651,7 +651,7 @@ TEST_CASE_METHOD(MergeTestController, "Test Merge File Attributes Keeping All Un context_->setProperty(minifi::processors::MergeContent::DelimiterStrategy, minifi::processors::merge_content_options::DELIMITER_STRATEGY_TEXT); context_->setProperty(minifi::processors::MergeContent::AttributeStrategy, minifi::processors::merge_content_options::ATTRIBUTE_STRATEGY_KEEP_ALL_UNIQUE); - core::ProcessSession sessionGenFlowFile(context_); + core::ProcessSessionImpl sessionGenFlowFile(context_); // Generate 3 flowfiles merging all into one for (const int i : {1, 2, 0}) { const auto flow = sessionGenFlowFile.create(); @@ -675,10 +675,10 @@ TEST_CASE_METHOD(MergeTestController, "Test Merge File Attributes Keeping All Un input_->put(flow); } - auto factory = std::make_shared(context_); + auto factory = std::make_shared(context_); merge_content_processor_->onSchedule(*context_, *factory); for (int i = 0; i < 3; i++) { - auto session = std::make_shared(context_); + auto session = std::make_shared(context_); merge_content_processor_->onTrigger(*context_, *session); session->commit(); } @@ -709,7 +709,7 @@ TEST_CASE("FlowFile serialization", "[testFlowFileSerialization]") { std::string footer = "}END"; std::string demarcator = "_"; - core::ProcessSession session(context); + core::ProcessSessionImpl session(context); minifi::PayloadSerializer payloadSerializer([&] (const std::shared_ptr& ff, const minifi::io::InputStreamCallback& cb) { return session.read(ff, cb); @@ -768,10 +768,10 @@ TEST_CASE("FlowFile serialization", "[testFlowFileSerialization]") { const auto expected = utils::span_to(utils::as_span(result->getBuffer())); - auto factory = std::make_shared(context); + auto factory = std::make_shared(context); merge_content_processor->onSchedule(*context, *factory); for (int i = 0; i < 3; i++) { - auto mergeSession = std::make_shared(context); + auto mergeSession = std::make_shared(context); merge_content_processor->onTrigger(*context, *mergeSession); mergeSession->commit(); } @@ -800,7 +800,7 @@ TEST_CASE_METHOD(MergeTestController, "Batch Size", "[testMergeFileBatchSize]") context_->setProperty(minifi::processors::MergeContent::DelimiterStrategy, minifi::processors::merge_content_options::DELIMITER_STRATEGY_TEXT); context_->setProperty(minifi::processors::BinFiles::BatchSize, "3"); - core::ProcessSession sessionGenFlowFile(context_); + core::ProcessSessionImpl sessionGenFlowFile(context_); // enqueue 5 (five) flowFiles for (const int i : {0, 1, 2, 3, 4}) { const auto flow = sessionGenFlowFile.create(); @@ -810,11 +810,11 @@ TEST_CASE_METHOD(MergeTestController, "Batch Size", "[testMergeFileBatchSize]") } REQUIRE(merge_content_processor_->getName() == "mergecontent"); - auto factory = std::make_shared(context_); + auto factory = std::make_shared(context_); merge_content_processor_->onSchedule(*context_, *factory); // two trigger is enough to process all five flowFiles for (int i = 0; i < 2; i++) { - auto session = std::make_shared(context_); + auto session = std::make_shared(context_); merge_content_processor_->onTrigger(*context_, *session); session->commit(); } @@ -859,7 +859,7 @@ TEST_CASE_METHOD(MergeTestController, "Maximum Group Size is respected", "[testM context_->setProperty(minifi::processors::BinFiles::MinEntries, "3"); context_->setProperty(minifi::processors::BinFiles::MaxEntries, "3"); - core::ProcessSession sessionGenFlowFile(context_); + core::ProcessSessionImpl sessionGenFlowFile(context_); // enqueue 6 (six) flowFiles for (const int i : {0, 1, 2, 3, 4, 5}) { const auto flow = sessionGenFlowFile.create(); @@ -869,11 +869,11 @@ TEST_CASE_METHOD(MergeTestController, "Maximum Group Size is respected", "[testM } REQUIRE(merge_content_processor_->getName() == "mergecontent"); - auto factory = std::make_shared(context_); + auto factory = std::make_shared(context_); merge_content_processor_->onSchedule(*context_, *factory); // a single trigger is enough to process all five flowFiles { - auto session = std::make_shared(context_); + auto session = std::make_shared(context_); merge_content_processor_->onTrigger(*context_, *session); session->commit(); } diff --git a/extensions/lua/LuaScriptExecutor.cpp b/extensions/lua/LuaScriptExecutor.cpp index 665d98d988..775778d846 100644 --- a/extensions/lua/LuaScriptExecutor.cpp +++ b/extensions/lua/LuaScriptExecutor.cpp @@ -20,7 +20,7 @@ #include "LuaScriptExecutor.h" #include "range/v3/range/conversion.hpp" -#include "Resource.h" +#include "core/Resource.h" namespace org::apache::nifi::minifi::extensions::lua { diff --git a/extensions/lua/LuaScriptProcessContext.h b/extensions/lua/LuaScriptProcessContext.h index 98fa3c9491..49dd867471 100644 --- a/extensions/lua/LuaScriptProcessContext.h +++ b/extensions/lua/LuaScriptProcessContext.h @@ -23,6 +23,7 @@ #include "core/ProcessSession.h" #include "LuaScriptStateManager.h" +#include "minifi-cpp/core/ProcessContext.h" namespace org::apache::nifi::minifi::extensions::lua { diff --git a/extensions/mqtt/processors/AbstractMQTTProcessor.h b/extensions/mqtt/processors/AbstractMQTTProcessor.h index 4b957a23b1..7556826c3c 100644 --- a/extensions/mqtt/processors/AbstractMQTTProcessor.h +++ b/extensions/mqtt/processors/AbstractMQTTProcessor.h @@ -23,12 +23,12 @@ #include #include -#include "PropertyDefinition.h" +#include "core/PropertyDefinition.h" #include "core/Processor.h" #include "core/ProcessSession.h" #include "core/PropertyDefinitionBuilder.h" #include "core/Core.h" -#include "core/logging/LoggerConfiguration.h" +#include "core/logging/LoggerFactory.h" #include "utils/Enum.h" #include "MQTTAsync.h" @@ -84,10 +84,10 @@ namespace org::apache::nifi::minifi::processors { static constexpr const char* const MQTT_SECURITY_PROTOCOL_SSL = "ssl"; -class AbstractMQTTProcessor : public core::Processor { +class AbstractMQTTProcessor : public core::ProcessorImpl { public: explicit AbstractMQTTProcessor(std::string_view name, const utils::Identifier& uuid = {}, std::shared_ptr metrics = {}) - : core::Processor(name, uuid, std::move(metrics)) { + : core::ProcessorImpl(name, uuid, std::move(metrics)) { } ~AbstractMQTTProcessor() override { diff --git a/extensions/mqtt/processors/ConsumeMQTT.h b/extensions/mqtt/processors/ConsumeMQTT.h index 857555726b..e7cb23c5c0 100644 --- a/extensions/mqtt/processors/ConsumeMQTT.h +++ b/extensions/mqtt/processors/ConsumeMQTT.h @@ -29,7 +29,7 @@ #include "core/Processor.h" #include "core/ProcessSession.h" #include "core/PropertyDefinition.h" -#include "core/logging/LoggerConfiguration.h" +#include "core/logging/LoggerFactory.h" #include "concurrentqueue.h" #include "AbstractMQTTProcessor.h" #include "utils/ArrayUtils.h" diff --git a/extensions/mqtt/processors/PublishMQTT.cpp b/extensions/mqtt/processors/PublishMQTT.cpp index 22ce8a8da3..3c800fee98 100644 --- a/extensions/mqtt/processors/PublishMQTT.cpp +++ b/extensions/mqtt/processors/PublishMQTT.cpp @@ -295,12 +295,12 @@ uint16_t PublishMQTT::InFlightMessageCounter::getCounter() const { } PublishMQTT::PublishMQTTMetrics::PublishMQTTMetrics(const core::Processor& source_processor, const InFlightMessageCounter& in_flight_message_counter) - : core::ProcessorMetrics(source_processor), + : core::ProcessorMetricsImpl(source_processor), in_flight_message_counter_(&in_flight_message_counter) { } std::vector PublishMQTT::PublishMQTTMetrics::serialize() { - auto metrics_vector = core::ProcessorMetrics::serialize(); + auto metrics_vector = core::ProcessorMetricsImpl::serialize(); gsl_Expects(!metrics_vector.empty()); auto& metrics = metrics_vector[0]; @@ -311,7 +311,7 @@ std::vector PublishMQTT::PublishMQTTMet } std::vector PublishMQTT::PublishMQTTMetrics::calculateMetrics() { - auto metrics = core::ProcessorMetrics::calculateMetrics(); + auto metrics = core::ProcessorMetricsImpl::calculateMetrics(); metrics.push_back({"in_flight_message_count", static_cast(in_flight_message_counter_->getCounter()), getCommonLabels()}); return metrics; } diff --git a/extensions/mqtt/processors/PublishMQTT.h b/extensions/mqtt/processors/PublishMQTT.h index 8e8d09bc15..2c2dfef114 100644 --- a/extensions/mqtt/processors/PublishMQTT.h +++ b/extensions/mqtt/processors/PublishMQTT.h @@ -23,25 +23,25 @@ #include #include -#include "FlowFileRecord.h" -#include "RelationshipDefinition.h" +#include "core/RelationshipDefinition.h" #include "core/Processor.h" -#include "RelationshipDefinition.h" #include "core/ProcessSession.h" #include "core/PropertyDefinitionBuilder.h" #include "core/Core.h" #include "core/Property.h" -#include "core/logging/LoggerConfiguration.h" +#include "core/logging/LoggerFactory.h" #include "AbstractMQTTProcessor.h" #include "utils/ArrayUtils.h" #include "utils/gsl.h" +#include "core/ProcessorMetrics.h" namespace org::apache::nifi::minifi::processors { class PublishMQTT : public processors::AbstractMQTTProcessor { public: explicit PublishMQTT(std::string_view name, const utils::Identifier& uuid = {}) - : processors::AbstractMQTTProcessor(name, uuid, std::make_shared(*this, in_flight_message_counter_)) { + : processors::AbstractMQTTProcessor(name, uuid) { + metrics_ = gsl::make_not_null(std::make_shared(*this, in_flight_message_counter_)); } EXTENSIONAPI static constexpr const char* Description = "PublishMQTT serializes FlowFile content as an MQTT payload, sending the message to the configured topic and broker."; @@ -108,7 +108,7 @@ class PublishMQTT : public processors::AbstractMQTTProcessor { uint16_t limit_{MQTT_MAX_RECEIVE_MAXIMUM}; }; - class PublishMQTTMetrics : public core::ProcessorMetrics { + class PublishMQTTMetrics : public core::ProcessorMetricsImpl { public: PublishMQTTMetrics(const core::Processor& source_processor, const InFlightMessageCounter& in_flight_message_counter); std::vector serialize() override; diff --git a/extensions/opc/include/fetchopc.h b/extensions/opc/include/fetchopc.h index 0edfcc0d74..92b9032646 100644 --- a/extensions/opc/include/fetchopc.h +++ b/extensions/opc/include/fetchopc.h @@ -32,7 +32,7 @@ #include "core/PropertyType.h" #include "core/RelationshipDefinition.h" #include "controllers/SSLContextService.h" -#include "core/logging/LoggerConfiguration.h" +#include "core/logging/LoggerFactory.h" #include "utils/ArrayUtils.h" #include "utils/Id.h" #include "utils/gsl.h" diff --git a/extensions/opc/include/opc.h b/extensions/opc/include/opc.h index 20c78cbc23..04cda4f85a 100644 --- a/extensions/opc/include/opc.h +++ b/extensions/opc/include/opc.h @@ -28,7 +28,7 @@ #include #include "open62541/client.h" -#include "logging/Logger.h" +#include "core/logging/Logger.h" #include "Exception.h" namespace org::apache::nifi::minifi::opc { diff --git a/extensions/opc/include/opcbase.h b/extensions/opc/include/opcbase.h index 2fc5ff90dc..c60cbd2b8d 100644 --- a/extensions/opc/include/opcbase.h +++ b/extensions/opc/include/opcbase.h @@ -25,14 +25,14 @@ #include "opc.h" #include "core/Processor.h" #include "core/ProcessSession.h" -#include "PropertyDefinition.h" +#include "core/PropertyDefinition.h" #include "core/PropertyDefinitionBuilder.h" #include "core/Core.h" #include "core/Property.h" namespace org::apache::nifi::minifi::processors { -class BaseOPCProcessor : public core::Processor { +class BaseOPCProcessor : public core::ProcessorImpl { public: EXTENSIONAPI static constexpr auto OPCServerEndPoint = core::PropertyDefinitionBuilder<>::createProperty("OPC server endpoint") .withDescription("Specifies the address, port and relative path of an OPC endpoint") @@ -70,7 +70,7 @@ class BaseOPCProcessor : public core::Processor { explicit BaseOPCProcessor(std::string_view name, const utils::Identifier& uuid = {}) - : Processor(name, uuid) { + : ProcessorImpl(name, uuid) { } void onSchedule(core::ProcessContext& context, core::ProcessSessionFactory& factory) override; diff --git a/extensions/opc/include/putopc.h b/extensions/opc/include/putopc.h index 849ad6e75e..7e3088d8e3 100644 --- a/extensions/opc/include/putopc.h +++ b/extensions/opc/include/putopc.h @@ -31,7 +31,7 @@ #include "core/PropertyDefinitionBuilder.h" #include "core/PropertyType.h" #include "controllers/SSLContextService.h" -#include "core/logging/LoggerConfiguration.h" +#include "core/logging/LoggerFactory.h" #include "utils/ArrayUtils.h" #include "utils/Id.h" diff --git a/extensions/opc/src/fetchopc.cpp b/extensions/opc/src/fetchopc.cpp index c6adc7c713..878a909e52 100644 --- a/extensions/opc/src/fetchopc.cpp +++ b/extensions/opc/src/fetchopc.cpp @@ -26,6 +26,7 @@ #include "core/Resource.h" #include "utils/StringUtils.h" #include "utils/Enum.h" +#include "core/ProcessContext.h" namespace org::apache::nifi::minifi::processors { diff --git a/extensions/opc/src/opc.cpp b/extensions/opc/src/opc.cpp index 8d7af7c96f..ffc466e828 100644 --- a/extensions/opc/src/opc.cpp +++ b/extensions/opc/src/opc.cpp @@ -25,7 +25,7 @@ #include #include "utils/StringUtils.h" -#include "logging/Logger.h" +#include "core/logging/Logger.h" #include "Exception.h" #include "utils/gsl.h" @@ -565,7 +565,7 @@ std::string OPCDateTime2String(UA_DateTime raw_date) { void logFunc(void *context, UA_LogLevel level, UA_LogCategory /*category*/, const char *msg, va_list args) { std::array buffer{}; (void)vsnprintf(buffer.data(), buffer.size(), msg, args); - auto loggerPtr = reinterpret_cast(context); + auto loggerPtr = reinterpret_cast(context); loggerPtr->log_string(MapOPCLogLevel(level), buffer.data()); } diff --git a/extensions/opc/src/putopc.cpp b/extensions/opc/src/putopc.cpp index 76d1b3e061..1ca976a047 100644 --- a/extensions/opc/src/putopc.cpp +++ b/extensions/opc/src/putopc.cpp @@ -23,6 +23,7 @@ #include "core/ProcessSession.h" #include "core/Resource.h" #include "utils/StringUtils.h" +#include "core/ProcessContext.h" namespace org::apache::nifi::minifi::processors { diff --git a/extensions/opencv/CaptureRTSPFrame.h b/extensions/opencv/CaptureRTSPFrame.h index 5c8d068d38..2449565237 100644 --- a/extensions/opencv/CaptureRTSPFrame.h +++ b/extensions/opencv/CaptureRTSPFrame.h @@ -20,13 +20,12 @@ #include #include #include -#include #include #include #include #include -#include "core/logging/LoggerConfiguration.h" +#include "core/logging/LoggerFactory.h" #include "core/Processor.h" #include "core/PropertyDefinitionBuilder.h" #include "io/StreamPipe.h" @@ -35,10 +34,10 @@ namespace org::apache::nifi::minifi::processors { -class CaptureRTSPFrame : public core::Processor { +class CaptureRTSPFrame final : public core::ProcessorImpl { public: - explicit CaptureRTSPFrame(std::string name, const utils::Identifier &uuid = {}) - : Processor(std::move(name), uuid) { + explicit CaptureRTSPFrame(const std::string_view name, const utils::Identifier &uuid = {}) + : ProcessorImpl(name, uuid) { } EXTENSIONAPI static constexpr const char* Description = "Captures a frame from the RTSP stream at specified intervals."; diff --git a/extensions/opencv/MotionDetector.h b/extensions/opencv/MotionDetector.h index 55a9c2c30b..e24eec5233 100644 --- a/extensions/opencv/MotionDetector.h +++ b/extensions/opencv/MotionDetector.h @@ -22,7 +22,7 @@ #include #include -#include "core/logging/LoggerConfiguration.h" +#include "core/logging/LoggerFactory.h" #include "core/Processor.h" #include "core/PropertyDefinition.h" #include "core/PropertyDefinitionBuilder.h" @@ -33,10 +33,10 @@ namespace org::apache::nifi::minifi::processors { -class MotionDetector : public core::Processor { +class MotionDetector final : public core::ProcessorImpl { public: - explicit MotionDetector(std::string name, const utils::Identifier &uuid = {}) - : Processor(std::move(name), uuid) { + explicit MotionDetector(const std::string_view name, const utils::Identifier &uuid = {}) + : ProcessorImpl(name, uuid) { } EXTENSIONAPI static constexpr const char* Description = "Detect motion from captured images."; diff --git a/extensions/pdh/PerformanceDataMonitor.h b/extensions/pdh/PerformanceDataMonitor.h index 867643c44f..024d0333a4 100644 --- a/extensions/pdh/PerformanceDataMonitor.h +++ b/extensions/pdh/PerformanceDataMonitor.h @@ -24,7 +24,7 @@ #include #include -#include "core/logging/LoggerConfiguration.h" +#include "core/logging/LoggerFactory.h" #include "core/Processor.h" #include "core/PropertyDefinition.h" #include "core/PropertyDefinitionBuilder.h" @@ -42,15 +42,15 @@ namespace nifi { namespace minifi { namespace processors { -class PerformanceDataMonitor : public core::Processor { +class PerformanceDataMonitor final : public core::ProcessorImpl { public: static constexpr const char* JSON_FORMAT_STR = "JSON"; static constexpr const char* OPEN_TELEMETRY_FORMAT_STR = "OpenTelemetry"; static constexpr const char* PRETTY_FORMAT_STR = "Pretty"; static constexpr const char* COMPACT_FORMAT_STR = "Compact"; - explicit PerformanceDataMonitor(const std::string& name, utils::Identifier uuid = utils::Identifier()) - : Processor(name, uuid), output_format_(OutputFormat::JSON), pretty_output_(false), + explicit PerformanceDataMonitor(const std::string_view name, utils::Identifier uuid = utils::Identifier()) + : ProcessorImpl(name, uuid), output_format_(OutputFormat::JSON), pretty_output_(false), decimal_places_(std::nullopt), logger_(core::logging::LoggerFactory::getLogger()), pdh_query_(nullptr), resource_consumption_counters_() {} diff --git a/extensions/procfs/ProcFs.h b/extensions/procfs/ProcFs.h index 6816f6b1af..c989ad77be 100644 --- a/extensions/procfs/ProcFs.h +++ b/extensions/procfs/ProcFs.h @@ -33,7 +33,7 @@ #include "NetDev.h" #include "DiskStat.h" -#include "core/logging/LoggerConfiguration.h" +#include "core/logging/LoggerFactory.h" #include "core/logging/Logger.h" namespace org::apache::nifi::minifi::extensions::procfs { diff --git a/extensions/procfs/processors/ProcFsMonitor.h b/extensions/procfs/processors/ProcFsMonitor.h index 0f25ea76d7..ae12031df9 100644 --- a/extensions/procfs/processors/ProcFsMonitor.h +++ b/extensions/procfs/processors/ProcFsMonitor.h @@ -29,7 +29,7 @@ #include "core/PropertyDefinition.h" #include "core/PropertyDefinitionBuilder.h" #include "core/RelationshipDefinition.h" -#include "core/logging/LoggerConfiguration.h" +#include "core/logging/LoggerFactory.h" #include "core/logging/Logger.h" #include "utils/Enum.h" @@ -53,10 +53,10 @@ enum class ResultRelativeness { Absolute }; -class ProcFsMonitor : public core::Processor { +class ProcFsMonitor final : public core::ProcessorImpl { public: - explicit ProcFsMonitor(std::string name, utils::Identifier uuid = utils::Identifier()) - : Processor(std::move(name), uuid) { + explicit ProcFsMonitor(const std::string_view name, utils::Identifier uuid = utils::Identifier()) + : ProcessorImpl(name, uuid) { } ~ProcFsMonitor() override = default; diff --git a/extensions/procfs/tests/MemInfoTests.cpp b/extensions/procfs/tests/MemInfoTests.cpp index ca5ee64c3a..9a8c7164b4 100644 --- a/extensions/procfs/tests/MemInfoTests.cpp +++ b/extensions/procfs/tests/MemInfoTests.cpp @@ -17,7 +17,7 @@ #include "unit/Catch.h" #include "ProcFs.h" -#include "Literals.h" +#include "utils/Literals.h" #include "MockProcFs.h" namespace org::apache::nifi::minifi::extensions::procfs::tests { diff --git a/extensions/prometheus/PrometheusExposerWrapper.h b/extensions/prometheus/PrometheusExposerWrapper.h index b77bea3a0d..7d5d157a77 100644 --- a/extensions/prometheus/PrometheusExposerWrapper.h +++ b/extensions/prometheus/PrometheusExposerWrapper.h @@ -23,7 +23,7 @@ #include "MetricsExposer.h" #include "prometheus/exposer.h" #include "core/logging/Logger.h" -#include "core/logging/LoggerConfiguration.h" +#include "core/logging/LoggerFactory.h" #include "controllers/SSLContextService.h" namespace org::apache::nifi::minifi::extensions::prometheus { diff --git a/extensions/prometheus/PrometheusMetricsPublisher.cpp b/extensions/prometheus/PrometheusMetricsPublisher.cpp index 36f2391660..13ee89173e 100644 --- a/extensions/prometheus/PrometheusMetricsPublisher.cpp +++ b/extensions/prometheus/PrometheusMetricsPublisher.cpp @@ -27,11 +27,11 @@ namespace org::apache::nifi::minifi::extensions::prometheus { PrometheusMetricsPublisher::PrometheusMetricsPublisher(const std::string &name, const utils::Identifier &uuid, std::unique_ptr exposer) - : state::MetricsPublisher(name, uuid), + : state::MetricsPublisherImpl(name, uuid), exposer_(std::move(exposer)) {} void PrometheusMetricsPublisher::initialize(const std::shared_ptr& configuration, const std::shared_ptr& response_node_loader) { - state::MetricsPublisher::initialize(configuration, response_node_loader); + state::MetricsPublisherImpl::initialize(configuration, response_node_loader); if (!exposer_) { exposer_ = std::make_unique(readExposerConfig()); } diff --git a/extensions/prometheus/PrometheusMetricsPublisher.h b/extensions/prometheus/PrometheusMetricsPublisher.h index 64a4fb4105..cd1f68443b 100644 --- a/extensions/prometheus/PrometheusMetricsPublisher.h +++ b/extensions/prometheus/PrometheusMetricsPublisher.h @@ -25,13 +25,13 @@ #include "PublishedMetricGaugeCollection.h" #include "core/Core.h" #include "core/logging/Logger.h" -#include "core/logging/LoggerConfiguration.h" +#include "core/logging/LoggerFactory.h" #include "utils/Id.h" #include "PrometheusExposerWrapper.h" namespace org::apache::nifi::minifi::extensions::prometheus { -class PrometheusMetricsPublisher : public state::MetricsPublisher { +class PrometheusMetricsPublisher : public state::MetricsPublisherImpl { public: explicit PrometheusMetricsPublisher(const std::string &name, const utils::Identifier &uuid = {}, std::unique_ptr exposer = nullptr); diff --git a/extensions/prometheus/PublishedMetricGaugeCollection.cpp b/extensions/prometheus/PublishedMetricGaugeCollection.cpp index 0469b6dbd0..c55c5822bb 100644 --- a/extensions/prometheus/PublishedMetricGaugeCollection.cpp +++ b/extensions/prometheus/PublishedMetricGaugeCollection.cpp @@ -20,7 +20,7 @@ #include #include "prometheus/client_metric.h" -#include "state/PublishedMetricProvider.h" +#include "core/state/PublishedMetricProvider.h" #include "range/v3/range/conversion.hpp" #include "range/v3/view/transform.hpp" diff --git a/extensions/prometheus/PublishedMetricGaugeCollection.h b/extensions/prometheus/PublishedMetricGaugeCollection.h index c86f53e571..bafa6acaa9 100644 --- a/extensions/prometheus/PublishedMetricGaugeCollection.h +++ b/extensions/prometheus/PublishedMetricGaugeCollection.h @@ -20,11 +20,10 @@ #include #include -#include "state/PublishedMetricProvider.h" +#include "core/state/PublishedMetricProvider.h" #include "prometheus/collectable.h" #include "prometheus/metric_family.h" #include "utils/gsl.h" -#include "core/logging/LoggerConfiguration.h" namespace org::apache::nifi::minifi::extensions::prometheus { diff --git a/extensions/prometheus/tests/PrometheusMetricsPublisherTest.cpp b/extensions/prometheus/tests/PrometheusMetricsPublisherTest.cpp index 878ef888a0..33c0788988 100644 --- a/extensions/prometheus/tests/PrometheusMetricsPublisherTest.cpp +++ b/extensions/prometheus/tests/PrometheusMetricsPublisherTest.cpp @@ -49,11 +49,11 @@ class DummyMetricsExposer : public MetricsExposer { class PrometheusPublisherTestFixture { public: explicit PrometheusPublisherTestFixture(bool user_dummy_exposer) - : configuration_(std::make_shared()), + : configuration_(std::make_shared()), provenance_repo_(core::createRepository("provenancerepository")), flow_file_repo_(core::createRepository("flowfilerepository")), content_repo_(core::createContentRepository("volatilecontentrepository")), - response_node_loader_(std::make_shared(configuration_, + response_node_loader_(std::make_shared(configuration_, std::vector>{provenance_repo_, flow_file_repo_, content_repo_}, nullptr)) { std::unique_ptr dummy_exposer; if (user_dummy_exposer) { diff --git a/extensions/python/ExecutePythonProcessor.cpp b/extensions/python/ExecutePythonProcessor.cpp index 7beca34d41..c1ef4da2e9 100644 --- a/extensions/python/ExecutePythonProcessor.cpp +++ b/extensions/python/ExecutePythonProcessor.cpp @@ -187,7 +187,7 @@ void ExecutePythonProcessor::addProperty(const std::string &name, const std::str } const core::Property* ExecutePythonProcessor::findProperty(const std::string& name) const { - if (auto prop_ptr = core::ConfigurableComponent::findProperty(name)) { + if (auto prop_ptr = core::ConfigurableComponentImpl::findProperty(name)) { return prop_ptr; } @@ -204,7 +204,7 @@ const core::Property* ExecutePythonProcessor::findProperty(const std::string& na } std::map ExecutePythonProcessor::getProperties() const { - auto result = ConfigurableComponent::getProperties(); + auto result = ConfigurableComponentImpl::getProperties(); std::lock_guard lock(python_properties_mutex_); diff --git a/extensions/python/ExecutePythonProcessor.h b/extensions/python/ExecutePythonProcessor.h index 8eec7011a0..0cbf2416e2 100644 --- a/extensions/python/ExecutePythonProcessor.h +++ b/extensions/python/ExecutePythonProcessor.h @@ -38,10 +38,10 @@ namespace org::apache::nifi::minifi::extensions::python::processors { -class ExecutePythonProcessor : public core::Processor { +class ExecutePythonProcessor : public core::ProcessorImpl { public: explicit ExecutePythonProcessor(std::string_view name, const utils::Identifier &uuid = {}) - : Processor(name, uuid), + : ProcessorImpl(name, uuid), processor_initialized_(false), python_dynamic_(false), reload_on_script_change_(true) { diff --git a/extensions/python/PythonCreator.h b/extensions/python/PythonCreator.h index dce65b3561..84f35a6561 100644 --- a/extensions/python/PythonCreator.h +++ b/extensions/python/PythonCreator.h @@ -19,23 +19,21 @@ #pragma once #include -#include #include #include #include #include #include "core/Core.h" -#include "core/logging/LoggerConfiguration.h" +#include "core/logging/LoggerFactory.h" #include "core/Resource.h" #include "ExecutePythonProcessor.h" #include "PythonConfigState.h" #include "PythonObjectFactory.h" -#include "agent/agent_version.h" -#include "agent/build_description.h" +#include "minifi-cpp/agent/agent_version.h" +#include "minifi-cpp/agent/build_description.h" #include "utils/file/FileUtils.h" #include "utils/StringUtils.h" #include "range/v3/algorithm.hpp" -#include "properties/Configuration.h" #include "utils/file/FilePattern.h" #include "range/v3/view/filter.hpp" #include "PythonDependencyInstaller.h" @@ -46,10 +44,10 @@ namespace org::apache::nifi::minifi::extensions::python { /** * Can be used to load the python processors from NiFi properties. */ -class PythonCreator : public minifi::core::CoreComponent { +class PythonCreator : public minifi::core::CoreComponentImpl { public: - explicit PythonCreator(std::string name, const utils::Identifier &uuid = {}) - : minifi::core::CoreComponent(std::move(name), uuid) { + explicit PythonCreator(const std::string_view name, const utils::Identifier &uuid = {}) + : minifi::core::CoreComponentImpl(name, uuid) { } ~PythonCreator() override { diff --git a/extensions/python/PythonDependencyInstaller.cpp b/extensions/python/PythonDependencyInstaller.cpp index e0a1001985..2f2b8854a1 100644 --- a/extensions/python/PythonDependencyInstaller.cpp +++ b/extensions/python/PythonDependencyInstaller.cpp @@ -21,6 +21,7 @@ #include "PythonInterpreter.h" #include "PyException.h" #include "types/Types.h" +#include "utils/OptionalUtils.h" namespace org::apache::nifi::minifi::extensions::python { diff --git a/extensions/python/PythonDependencyInstaller.h b/extensions/python/PythonDependencyInstaller.h index dd989d661d..87a99b90cd 100644 --- a/extensions/python/PythonDependencyInstaller.h +++ b/extensions/python/PythonDependencyInstaller.h @@ -21,7 +21,7 @@ #include #include "core/logging/Logger.h" -#include "core/logging/LoggerConfiguration.h" +#include "core/logging/LoggerFactory.h" #include "properties/Configure.h" namespace org::apache::nifi::minifi::extensions::python { diff --git a/extensions/python/PythonScriptEngine.h b/extensions/python/PythonScriptEngine.h index 4a266ea572..bd051643ce 100644 --- a/extensions/python/PythonScriptEngine.h +++ b/extensions/python/PythonScriptEngine.h @@ -33,10 +33,9 @@ #include "PythonProcessor.h" #include "types/PyProcessSession.h" #include "PythonScriptException.h" -#include "properties/Configuration.h" #include "PythonInterpreter.h" #include "core/logging/Logger.h" -#include "core/logging/LoggerConfiguration.h" +#include "core/logging/LoggerFactory.h" namespace org::apache::nifi::minifi::extensions::python { diff --git a/extensions/python/PythonScriptExecutor.cpp b/extensions/python/PythonScriptExecutor.cpp index 1dbe57ecb6..96efcc339c 100644 --- a/extensions/python/PythonScriptExecutor.cpp +++ b/extensions/python/PythonScriptExecutor.cpp @@ -23,7 +23,7 @@ #include "PythonScriptEngine.h" #include "range/v3/range/conversion.hpp" -#include "Resource.h" +#include "core/Resource.h" namespace org::apache::nifi::minifi::extensions::python { diff --git a/extensions/python/pythonlibloader/PythonLibLoader.cpp b/extensions/python/pythonlibloader/PythonLibLoader.cpp index 8c2d7ec551..8c5399c873 100644 --- a/extensions/python/pythonlibloader/PythonLibLoader.cpp +++ b/extensions/python/pythonlibloader/PythonLibLoader.cpp @@ -21,7 +21,7 @@ #include #include #include "utils/StringUtils.h" -#include "core/logging/LoggerConfiguration.h" +#include "core/logging/LoggerFactory.h" #include "core/extension/Extension.h" #if defined(WIN32) || defined(__APPLE__) diff --git a/extensions/python/tests/PythonManifestTests.cpp b/extensions/python/tests/PythonManifestTests.cpp index c054d36f51..f921702417 100644 --- a/extensions/python/tests/PythonManifestTests.cpp +++ b/extensions/python/tests/PythonManifestTests.cpp @@ -159,11 +159,11 @@ class MyPyProc5(FlowFileTransform): controller.configuration_->set(minifi::Configuration::nifi_python_processor_dir, python_dir.string()); controller.configuration_->set(minifi::Configuration::nifi_extension_path, "*minifi-python-script*"); - core::extension::ExtensionManager::get().initialize(controller.configuration_); + core::extension::ExtensionManagerImpl::get().initialize(controller.configuration_); controller.setupFlow(); - auto c2_metrics_publisher = std::static_pointer_cast(controller.metrics_publisher_store_->getMetricsPublisher(minifi::c2::C2_METRICS_PUBLISHER).lock()); + auto c2_metrics_publisher = std::dynamic_pointer_cast(controller.metrics_publisher_store_->getMetricsPublisher(minifi::c2::C2_METRICS_PUBLISHER).lock()); auto agent_info = c2_metrics_publisher->getAgentManifest(); diff --git a/extensions/python/types/PyRecordSetWriter.cpp b/extensions/python/types/PyRecordSetWriter.cpp index ffd784e7b6..caca438c2c 100644 --- a/extensions/python/types/PyRecordSetWriter.cpp +++ b/extensions/python/types/PyRecordSetWriter.cpp @@ -19,7 +19,7 @@ a * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #include "PyScriptFlowFile.h" #include "PyProcessSession.h" -#include "core/Record.h" +#include "minifi-cpp/core/Record.h" #include "rapidjson/document.h" extern "C" { diff --git a/extensions/rocksdb-repos/CMakeLists.txt b/extensions/rocksdb-repos/CMakeLists.txt index 2f43753c7e..a31b631277 100644 --- a/extensions/rocksdb-repos/CMakeLists.txt +++ b/extensions/rocksdb-repos/CMakeLists.txt @@ -30,8 +30,9 @@ file(GLOB SOURCES "*.cpp" "controllers/*.cpp" "database/*.cpp" "encryption/*.cp add_minifi_library(minifi-rocksdb-repos SHARED ${SOURCES}) -target_link_libraries(minifi-rocksdb-repos ${LIBMINIFI} Threads::Threads) -target_link_libraries(minifi-rocksdb-repos RocksDB::RocksDB) +target_link_libraries(minifi-rocksdb-repos PUBLIC RocksDB::RocksDB) +target_link_libraries(minifi-rocksdb-repos PUBLIC minifi-core minifi-extension-utils Threads::Threads) +target_link_libraries(minifi-rocksdb-repos PRIVATE $) register_extension(minifi-rocksdb-repos "ROCKSDB REPOS" ROCKSDB-REPOS "This Enables persistent provenance, flowfile, and content repositories using RocksDB" "extensions/rocksdb-repos/tests") register_extension_linter(minifi-rocksdb-repos-linter) diff --git a/extensions/rocksdb-repos/DatabaseContentRepository.cpp b/extensions/rocksdb-repos/DatabaseContentRepository.cpp index 262f3aef55..5c0f826def 100644 --- a/extensions/rocksdb-repos/DatabaseContentRepository.cpp +++ b/extensions/rocksdb-repos/DatabaseContentRepository.cpp @@ -146,11 +146,11 @@ DatabaseContentRepository::Session::Session(std::shared_ptr r use_synchronous_writes_(use_synchronous_writes) {} std::shared_ptr DatabaseContentRepository::createSession() { - return std::make_shared(sharedFromThis(), use_synchronous_writes_); + return std::make_shared(sharedFromThis(), use_synchronous_writes_); } void DatabaseContentRepository::Session::commit() { - auto dbContentRepository = std::static_pointer_cast(repository_); + auto dbContentRepository = std::dynamic_pointer_cast(repository_); auto opendb = dbContentRepository->db_->open(); if (!opendb) { throw Exception(REPOSITORY_EXCEPTION, "Couldn't open rocksdb database to commit content changes"); diff --git a/extensions/rocksdb-repos/DatabaseContentRepository.h b/extensions/rocksdb-repos/DatabaseContentRepository.h index eb78204f5f..8b430dce8a 100644 --- a/extensions/rocksdb-repos/DatabaseContentRepository.h +++ b/extensions/rocksdb-repos/DatabaseContentRepository.h @@ -25,7 +25,7 @@ #include "core/ContentRepository.h" #include "core/BufferedContentSession.h" -#include "core/logging/LoggerConfiguration.h" +#include "core/logging/LoggerFactory.h" #include "core/Property.h" #include "database/RocksDatabase.h" #include "properties/Configure.h" @@ -33,7 +33,7 @@ namespace org::apache::nifi::minifi::core::repository { -class DatabaseContentRepository : public core::ContentRepository { +class DatabaseContentRepository : public core::ContentRepositoryImpl { class Session : public BufferedContentSession { public: explicit Session(std::shared_ptr repository, bool use_synchronous_writes); @@ -49,7 +49,7 @@ class DatabaseContentRepository : public core::ContentRepository { static constexpr const char* ENCRYPTION_KEY_NAME = "nifi.database.content.repository.encryption.key"; explicit DatabaseContentRepository(std::string_view name = className(), const utils::Identifier& uuid = {}) - : core::ContentRepository(name, uuid), + : core::ContentRepositoryImpl(name, uuid), is_valid_(false), db_(nullptr), logger_(logging::LoggerFactory::getLogger()) { diff --git a/extensions/rocksdb-repos/FlowFileLoader.cpp b/extensions/rocksdb-repos/FlowFileLoader.cpp index 1ab12fd49f..8eb2c685db 100644 --- a/extensions/rocksdb-repos/FlowFileLoader.cpp +++ b/extensions/rocksdb-repos/FlowFileLoader.cpp @@ -23,9 +23,9 @@ #include #include -#include "logging/LoggerConfiguration.h" -#include "FlowFileRecord.h" +#include "core/logging/LoggerFactory.h" #include "utils/gsl.h" +#include "FlowFileRecord.h" namespace org::apache::nifi::minifi { diff --git a/extensions/rocksdb-repos/FlowFileLoader.h b/extensions/rocksdb-repos/FlowFileLoader.h index 79277f6573..f18ab53fd8 100644 --- a/extensions/rocksdb-repos/FlowFileLoader.h +++ b/extensions/rocksdb-repos/FlowFileLoader.h @@ -23,10 +23,9 @@ #include #include "database/RocksDatabase.h" -#include "FlowFile.h" #include "utils/gsl.h" #include "core/ContentRepository.h" -#include "SwapManager.h" +#include "minifi-cpp/SwapManager.h" #include "utils/ThreadPool.h" #include "core/logging/Logger.h" diff --git a/extensions/rocksdb-repos/FlowFileRepository.cpp b/extensions/rocksdb-repos/FlowFileRepository.cpp index b53ec26540..82ea380c91 100644 --- a/extensions/rocksdb-repos/FlowFileRepository.cpp +++ b/extensions/rocksdb-repos/FlowFileRepository.cpp @@ -26,10 +26,11 @@ #include "rocksdb/options.h" #include "rocksdb/slice.h" -#include "FlowFileRecord.h" #include "utils/gsl.h" #include "core/Resource.h" #include "utils/OptionalUtils.h" +#include "core/TypedValues.h" +#include "FlowFileRecord.h" using namespace std::literals::chrono_literals; @@ -120,7 +121,7 @@ void FlowFileRepository::run() { flush(); } -bool FlowFileRepository::contentSizeIsAmpleForFlowFile(const FlowFileRecord& flow_file_record, const std::shared_ptr& resource_claim) const { +bool FlowFileRepository::contentSizeIsAmpleForFlowFile(const FlowFile& flow_file_record, const std::shared_ptr& resource_claim) const { const auto stream_size = resource_claim ? content_repo_->size(*resource_claim) : 0; const auto required_size = flow_file_record.getOffset() + flow_file_record.getSize(); return stream_size >= required_size; @@ -283,7 +284,7 @@ void FlowFileRepository::runCompaction() { } bool FlowFileRepository::start() { - const bool ret = ThreadedRepository::start(); + const bool ret = ThreadedRepositoryImpl::start(); if (swap_loader_) { swap_loader_->start(); } @@ -300,7 +301,7 @@ bool FlowFileRepository::stop() { if (swap_loader_) { swap_loader_->stop(); } - return ThreadedRepository::stop(); + return ThreadedRepositoryImpl::stop(); } void FlowFileRepository::store(std::vector> flow_files) { diff --git a/extensions/rocksdb-repos/FlowFileRepository.h b/extensions/rocksdb-repos/FlowFileRepository.h index 7e9b071b11..164ef703d2 100644 --- a/extensions/rocksdb-repos/FlowFileRepository.h +++ b/extensions/rocksdb-repos/FlowFileRepository.h @@ -28,13 +28,13 @@ #include "rocksdb/slice.h" #include "rocksdb/utilities/checkpoint.h" #include "core/Core.h" -#include "core/logging/LoggerConfiguration.h" -#include "Connection.h" +#include "core/logging/LoggerFactory.h" +#include "minifi-cpp/Connection.h" #include "concurrentqueue.h" #include "database/RocksDatabase.h" #include "encryption/RocksDbEncryptionProvider.h" #include "utils/crypto/EncryptionProvider.h" -#include "SwapManager.h" +#include "minifi-cpp/SwapManager.h" #include "FlowFileLoader.h" #include "range/v3/algorithm/all_of.hpp" #include "utils/Literals.h" @@ -117,7 +117,7 @@ class FlowFileRepository : public RocksDbRepository, public SwapManager { void deserializeFlowFilesWithNoContentClaim(minifi::internal::OpenRocksDb& opendb, std::list& flow_files); - bool contentSizeIsAmpleForFlowFile(const FlowFileRecord& flow_file_record, const std::shared_ptr& resource_claim) const; + bool contentSizeIsAmpleForFlowFile(const FlowFile& flow_file_record, const std::shared_ptr& resource_claim) const; Connectable* getContainer(const std::string& container_id); moodycamel::ConcurrentQueue keys_to_delete_; diff --git a/extensions/rocksdb-repos/ProvenanceRepository.cpp b/extensions/rocksdb-repos/ProvenanceRepository.cpp index 5afe75a4b6..a4378e451b 100644 --- a/extensions/rocksdb-repos/ProvenanceRepository.cpp +++ b/extensions/rocksdb-repos/ProvenanceRepository.cpp @@ -86,7 +86,7 @@ bool ProvenanceRepository::getElements(std::vectorSeekToFirst(); it->Valid(); it->Next()) { if (max_size >= requested_batch) break; - auto eventRead = std::make_shared(); + auto eventRead = ProvenanceEventRecord::create(); std::string key = it->key().ToString(); io::BufferStream stream(gsl::make_span(it->value()).as_span()); if (eventRead->deserialize(stream)) { diff --git a/extensions/rocksdb-repos/ProvenanceRepository.h b/extensions/rocksdb-repos/ProvenanceRepository.h index a5febea18b..89b89dbe81 100644 --- a/extensions/rocksdb-repos/ProvenanceRepository.h +++ b/extensions/rocksdb-repos/ProvenanceRepository.h @@ -27,8 +27,8 @@ #include "rocksdb/options.h" #include "rocksdb/slice.h" #include "core/Core.h" -#include "core/logging/LoggerConfiguration.h" -#include "provenance/Provenance.h" +#include "core/logging/LoggerFactory.h" +#include "minifi-cpp/provenance/Provenance.h" #include "utils/Literals.h" #include "RocksDbRepository.h" @@ -76,8 +76,6 @@ class ProvenanceRepository : public core::repository::RocksDbRepository { void destroy(); - // Prevent default copy constructor and assignment operation - // Only support pass by reference or pointer ProvenanceRepository(const ProvenanceRepository &parent) = delete; ProvenanceRepository &operator=(const ProvenanceRepository &parent) = delete; diff --git a/extensions/rocksdb-repos/RocksDbRepository.cpp b/extensions/rocksdb-repos/RocksDbRepository.cpp index f09d0f9360..2d1698f12d 100644 --- a/extensions/rocksdb-repos/RocksDbRepository.cpp +++ b/extensions/rocksdb-repos/RocksDbRepository.cpp @@ -16,6 +16,7 @@ */ #include "RocksDbRepository.h" #include "utils/span.h" +#include "utils/OptionalUtils.h" using namespace std::literals::chrono_literals; diff --git a/extensions/rocksdb-repos/RocksDbRepository.h b/extensions/rocksdb-repos/RocksDbRepository.h index f29ff97585..b3467a7720 100644 --- a/extensions/rocksdb-repos/RocksDbRepository.h +++ b/extensions/rocksdb-repos/RocksDbRepository.h @@ -29,7 +29,7 @@ namespace org::apache::nifi::minifi::core::repository { constexpr auto FLOWFILE_REPOSITORY_RETRY_INTERVAL_INCREMENTS = std::chrono::milliseconds(500); -class RocksDbRepository : public ThreadedRepository { +class RocksDbRepository : public ThreadedRepositoryImpl { public: RocksDbRepository(std::string_view repo_name, std::string directory, @@ -37,7 +37,7 @@ class RocksDbRepository : public ThreadedRepository { int64_t max_partition_bytes, std::chrono::milliseconds purge_period, std::shared_ptr logger) - : ThreadedRepository(repo_name, std::move(directory), max_partition_millis, max_partition_bytes, purge_period), + : ThreadedRepositoryImpl(repo_name, std::move(directory), max_partition_millis, max_partition_bytes, purge_period), logger_(std::move(logger)) { } diff --git a/extensions/rocksdb-repos/RocksDbStream.cpp b/extensions/rocksdb-repos/RocksDbStream.cpp index 7889622b5a..2f1dc2af9a 100644 --- a/extensions/rocksdb-repos/RocksDbStream.cpp +++ b/extensions/rocksdb-repos/RocksDbStream.cpp @@ -30,7 +30,7 @@ namespace org::apache::nifi::minifi::io { RocksDbStream::RocksDbStream(std::string path, gsl::not_null db, bool write_enable, minifi::internal::WriteBatch* batch, bool use_synchronous_writes, bool verify_checksums) - : BaseStream(), + : BaseStreamImpl(), path_(std::move(path)), write_enable_(write_enable), db_(db), diff --git a/extensions/rocksdb-repos/RocksDbStream.h b/extensions/rocksdb-repos/RocksDbStream.h index 8333115157..1076f0b518 100644 --- a/extensions/rocksdb-repos/RocksDbStream.h +++ b/extensions/rocksdb-repos/RocksDbStream.h @@ -23,7 +23,7 @@ #include #include "database/RocksDatabase.h" #include "io/BaseStream.h" -#include "core/logging/LoggerConfiguration.h" +#include "core/logging/LoggerFactory.h" namespace org { namespace apache { @@ -38,7 +38,7 @@ namespace io { * Design: Simply extends BaseStream and overrides readData/writeData to allow a sink to the * fstream object. */ -class RocksDbStream : public io::BaseStream { +class RocksDbStream : public io::BaseStreamImpl { public: /** * File Stream constructor that accepts an fstream shared pointer. diff --git a/extensions/rocksdb-repos/controllers/RocksDbStateStorage.cpp b/extensions/rocksdb-repos/controllers/RocksDbStateStorage.cpp index ceac73e706..f07125f538 100644 --- a/extensions/rocksdb-repos/controllers/RocksDbStateStorage.cpp +++ b/extensions/rocksdb-repos/controllers/RocksDbStateStorage.cpp @@ -35,7 +35,7 @@ RocksDbStateStorage::~RocksDbStateStorage() { } void RocksDbStateStorage::initialize() { - ControllerService::initialize(); + ControllerServiceImpl::initialize(); setSupportedProperties(Properties); } diff --git a/extensions/rocksdb-repos/controllers/RocksDbStateStorage.h b/extensions/rocksdb-repos/controllers/RocksDbStateStorage.h index d4b4a8ad8e..6c9f8a85ac 100644 --- a/extensions/rocksdb-repos/controllers/RocksDbStateStorage.h +++ b/extensions/rocksdb-repos/controllers/RocksDbStateStorage.h @@ -20,11 +20,11 @@ #include #include -#include "controllers/keyvalue/AutoPersistor.h" +#include "utils/AutoPersistor.h" #include "controllers/keyvalue/KeyValueStateStorage.h" #include "core/Core.h" #include "core/logging/Logger.h" -#include "core/logging/LoggerConfiguration.h" +#include "core/logging/LoggerFactory.h" #include "core/PropertyDefinition.h" #include "core/PropertyDefinitionBuilder.h" #include "core/PropertyType.h" diff --git a/extensions/rocksdb-repos/database/ColumnHandle.cpp b/extensions/rocksdb-repos/database/ColumnHandle.cpp index 4bd05b3d24..ff03b07bd8 100644 --- a/extensions/rocksdb-repos/database/ColumnHandle.cpp +++ b/extensions/rocksdb-repos/database/ColumnHandle.cpp @@ -17,7 +17,7 @@ */ #include "ColumnHandle.h" -#include "logging/LoggerConfiguration.h" +#include "core/logging/LoggerFactory.h" namespace org::apache::nifi::minifi::internal { diff --git a/extensions/rocksdb-repos/database/DbHandle.cpp b/extensions/rocksdb-repos/database/DbHandle.cpp index 2c96a043d1..2b395d55fc 100644 --- a/extensions/rocksdb-repos/database/DbHandle.cpp +++ b/extensions/rocksdb-repos/database/DbHandle.cpp @@ -17,7 +17,7 @@ */ #include "DbHandle.h" -#include "logging/LoggerConfiguration.h" +#include "core/logging/LoggerFactory.h" namespace org::apache::nifi::minifi::internal { diff --git a/extensions/rocksdb-repos/database/OpenRocksDb.h b/extensions/rocksdb-repos/database/OpenRocksDb.h index d65aad6895..08527177dd 100644 --- a/extensions/rocksdb-repos/database/OpenRocksDb.h +++ b/extensions/rocksdb-repos/database/OpenRocksDb.h @@ -28,7 +28,7 @@ #include "rocksdb/utilities/checkpoint.h" #include "WriteBatch.h" #include "core/RepositoryMetricsSource.h" -#include "core/logging/LoggerConfiguration.h" +#include "core/logging/LoggerFactory.h" namespace org::apache::nifi::minifi::internal { diff --git a/extensions/rocksdb-repos/database/RocksDatabase.cpp b/extensions/rocksdb-repos/database/RocksDatabase.cpp index c4a166a6bd..df1c597cc4 100644 --- a/extensions/rocksdb-repos/database/RocksDatabase.cpp +++ b/extensions/rocksdb-repos/database/RocksDatabase.cpp @@ -21,7 +21,7 @@ #include #include -#include "core/logging/LoggerConfiguration.h" +#include "core/logging/LoggerFactory.h" #include "utils/StringUtils.h" #include "RocksDbInstance.h" diff --git a/extensions/rocksdb-repos/database/RocksDatabase.h b/extensions/rocksdb-repos/database/RocksDatabase.h index 7bcb229e96..afab4f8443 100644 --- a/extensions/rocksdb-repos/database/RocksDatabase.h +++ b/extensions/rocksdb-repos/database/RocksDatabase.h @@ -24,7 +24,7 @@ #include #include "rocksdb/db.h" -#include "logging/Logger.h" +#include "core/logging/Logger.h" #include "RocksDbUtils.h" #include "OpenRocksDb.h" diff --git a/extensions/rocksdb-repos/database/RocksDbInstance.cpp b/extensions/rocksdb-repos/database/RocksDbInstance.cpp index 4c23e0ec87..a083115730 100644 --- a/extensions/rocksdb-repos/database/RocksDbInstance.cpp +++ b/extensions/rocksdb-repos/database/RocksDbInstance.cpp @@ -19,7 +19,7 @@ #include "RocksDbInstance.h" #include #include -#include "logging/LoggerConfiguration.h" +#include "core/logging/LoggerFactory.h" #include "rocksdb/utilities/options_util.h" #include "OpenRocksDb.h" #include "ColumnHandle.h" diff --git a/extensions/rocksdb-repos/database/RocksDbInstance.h b/extensions/rocksdb-repos/database/RocksDbInstance.h index b4796c4eba..c6bfbe2418 100644 --- a/extensions/rocksdb-repos/database/RocksDbInstance.h +++ b/extensions/rocksdb-repos/database/RocksDbInstance.h @@ -24,7 +24,7 @@ #include #include "RocksDbUtils.h" #include "rocksdb/db.h" -#include "logging/Logger.h" +#include "core/logging/Logger.h" namespace org::apache::nifi::minifi::internal { diff --git a/extensions/rocksdb-repos/encryption/RocksDbEncryptionProvider.cpp b/extensions/rocksdb-repos/encryption/RocksDbEncryptionProvider.cpp index 881eb91d63..fc39bfdde7 100644 --- a/extensions/rocksdb-repos/encryption/RocksDbEncryptionProvider.cpp +++ b/extensions/rocksdb-repos/encryption/RocksDbEncryptionProvider.cpp @@ -22,7 +22,7 @@ #include "RocksDbEncryptionProvider.h" #include "utils/crypto/ciphers/Aes256Ecb.h" -#include "logging/LoggerConfiguration.h" +#include "core/logging/LoggerFactory.h" namespace org::apache::nifi::minifi::core::repository { diff --git a/extensions/rocksdb-repos/encryption/RocksDbEncryptionProvider.h b/extensions/rocksdb-repos/encryption/RocksDbEncryptionProvider.h index 93f5615549..5b8efe562f 100644 --- a/extensions/rocksdb-repos/encryption/RocksDbEncryptionProvider.h +++ b/extensions/rocksdb-repos/encryption/RocksDbEncryptionProvider.h @@ -23,7 +23,7 @@ #include "rocksdb/env_encryption.h" #include "utils/crypto/EncryptionUtils.h" -#include "logging/Logger.h" +#include "core/logging/Logger.h" #include "utils/crypto/EncryptionManager.h" namespace org::apache::nifi::minifi::core::repository { diff --git a/extensions/rocksdb-repos/tests/ContentSessionTests.cpp b/extensions/rocksdb-repos/tests/ContentSessionTests.cpp index 3a612b758c..9890a971d4 100644 --- a/extensions/rocksdb-repos/tests/ContentSessionTests.cpp +++ b/extensions/rocksdb-repos/tests/ContentSessionTests.cpp @@ -24,7 +24,7 @@ #include "FileSystemRepository.h" #include "VolatileContentRepository.h" #include "DatabaseContentRepository.h" -#include "BufferedContentSession.h" +#include "core/BufferedContentSession.h" #include "FlowFileRecord.h" #include "unit/TestBase.h" #include "unit/Catch.h" @@ -36,7 +36,7 @@ class ContentSessionController : public TestController { ContentSessionController() : contentRepository(std::make_shared()) { auto contentRepoPath = createTempDirectory(); - auto config = std::make_shared(); + auto config = std::make_shared(); config->setHome(contentRepoPath); config->set(minifi::Configure::nifi_dbcontent_repository_directory_default, contentRepoPath.string()); contentRepository->initialize(config); diff --git a/extensions/rocksdb-repos/tests/DBContentRepositoryTests.cpp b/extensions/rocksdb-repos/tests/DBContentRepositoryTests.cpp index 2cd1898665..cfc9e46740 100644 --- a/extensions/rocksdb-repos/tests/DBContentRepositoryTests.cpp +++ b/extensions/rocksdb-repos/tests/DBContentRepositoryTests.cpp @@ -43,13 +43,13 @@ TEST_CASE("Write Claim", "[TestDBCR1]") { auto dir = testController.createTempDirectory(); auto content_repo = std::make_shared(); - auto configuration = std::make_shared(); + auto configuration = std::make_shared(); configuration->setHome(dir); configuration->set(minifi::Configure::nifi_dbcontent_repository_directory_default, dir.string()); REQUIRE(content_repo->initialize(configuration)); - auto claim = std::make_shared(content_repo); + auto claim = std::make_shared(content_repo); auto stream = content_repo->write(*claim); const std::string content = "well hello there"; @@ -66,7 +66,7 @@ TEST_CASE("Write Claim", "[TestDBCR1]") { content_repo = std::make_shared(); - configuration = std::make_shared(); + configuration = std::make_shared(); configuration->setHome(dir); configuration->set(minifi::Configure::nifi_dbcontent_repository_directory_default, dir.string()); REQUIRE(content_repo->initialize(configuration)); @@ -91,13 +91,13 @@ TEST_CASE("Delete Claim", "[TestDBCR2]") { auto dir = testController.createTempDirectory(); auto content_repo = std::make_shared(); - auto configuration = std::make_shared(); + auto configuration = std::make_shared(); configuration->setHome(dir); configuration->set(minifi::Configure::nifi_dbcontent_repository_directory_default, dir.string()); REQUIRE(content_repo->initialize(configuration)); - auto claim = std::make_shared(content_repo); + auto claim = std::make_shared(content_repo); auto stream = content_repo->write(*claim); stream->write("well hello there"); @@ -111,7 +111,7 @@ TEST_CASE("Delete Claim", "[TestDBCR2]") { content_repo = std::make_shared(); - configuration = std::make_shared(); + configuration = std::make_shared(); configuration->setHome(dir); configuration->set(minifi::Configure::nifi_dbcontent_repository_directory_default, dir.string()); @@ -150,7 +150,7 @@ TEST_CASE("Append Claim", "[TestDBCR1]") { auto dir = testController.createTempDirectory(); auto content_repo = std::make_shared(); - auto configuration = std::make_shared(); + auto configuration = std::make_shared(); configuration->setHome(dir); configuration->set(minifi::Configure::nifi_dbcontent_repository_directory_default, dir.string()); REQUIRE(content_repo->initialize(configuration)); @@ -158,7 +158,7 @@ TEST_CASE("Append Claim", "[TestDBCR1]") { const std::string content = "well hello there"; - auto claim = std::make_shared(content_repo); + auto claim = std::make_shared(content_repo); content_repo->write(*claim)->write(as_bytes(std::span(content))); // requesting append before content end fails @@ -192,12 +192,12 @@ TEST_CASE("Test Empty Claim", "[TestDBCR3]") { auto dir = testController.createTempDirectory(); auto content_repo = std::make_shared(); - auto configuration = std::make_shared(); + auto configuration = std::make_shared(); configuration->setHome(dir); configuration->set(minifi::Configure::nifi_dbcontent_repository_directory_default, dir.string()); REQUIRE(content_repo->initialize(configuration)); - auto claim = std::make_shared(content_repo); + auto claim = std::make_shared(content_repo); auto stream = content_repo->write(*claim); // we're writing nothing to the stream. @@ -211,7 +211,7 @@ TEST_CASE("Test Empty Claim", "[TestDBCR3]") { content_repo = std::make_shared(); - configuration = std::make_shared(); + configuration = std::make_shared(); configuration->setHome(dir); configuration->set(minifi::Configure::nifi_dbcontent_repository_directory_default, dir.string()); REQUIRE(content_repo->initialize(configuration)); @@ -229,13 +229,13 @@ TEST_CASE("Delete NonExistent Claim", "[TestDBCR4]") { auto dir = testController.createTempDirectory(); auto content_repo = std::make_shared(); - auto configuration = std::make_shared(); + auto configuration = std::make_shared(); configuration->setHome(dir); configuration->set(minifi::Configure::nifi_dbcontent_repository_directory_default, dir.string()); REQUIRE(content_repo->initialize(configuration)); - auto claim = std::make_shared(content_repo); - auto claim2 = std::make_shared(content_repo); + auto claim = std::make_shared(content_repo); + auto claim2 = std::make_shared(content_repo); auto stream = content_repo->write(*claim); stream->write("well hello there"); @@ -249,7 +249,7 @@ TEST_CASE("Delete NonExistent Claim", "[TestDBCR4]") { content_repo = std::make_shared(); - configuration = std::make_shared(); + configuration = std::make_shared(); configuration->setHome(dir); configuration->set(minifi::Configure::nifi_dbcontent_repository_directory_default, dir.string()); REQUIRE(content_repo->initialize(configuration)); @@ -271,13 +271,13 @@ TEST_CASE("Delete Remove Count Claim", "[TestDBCR5]") { auto dir = testController.createTempDirectory(); auto content_repo = std::make_shared(); - auto configuration = std::make_shared(); + auto configuration = std::make_shared(); configuration->setHome(dir); configuration->set(minifi::Configure::nifi_dbcontent_repository_directory_default, dir.string()); REQUIRE(content_repo->initialize(configuration)); - auto claim = std::make_shared(content_repo); - auto claim2 = std::make_shared(content_repo); + auto claim = std::make_shared(content_repo); + auto claim2 = std::make_shared(content_repo); auto stream = content_repo->write(*claim); stream->write("well hello there"); @@ -291,7 +291,7 @@ TEST_CASE("Delete Remove Count Claim", "[TestDBCR5]") { content_repo = std::make_shared(); - configuration = std::make_shared(); + configuration = std::make_shared(); configuration->setHome(dir); configuration->set(minifi::Configure::nifi_dbcontent_repository_directory_default, dir.string()); REQUIRE(content_repo->initialize(configuration)); @@ -344,14 +344,14 @@ size_t getDbSize(const std::filesystem::path& dir) { TEST_CASE("DBContentRepository can clear orphan entries") { TestController testController; auto dir = testController.createTempDirectory(); - auto configuration = std::make_shared(); + auto configuration = std::make_shared(); configuration->setHome(dir); configuration->set(minifi::Configure::nifi_dbcontent_repository_directory_default, dir.string()); { auto content_repo = std::make_shared(); REQUIRE(content_repo->initialize(configuration)); - minifi::ResourceClaim claim(content_repo); + minifi::ResourceClaimImpl claim(content_repo); content_repo->write(claim)->write("hi"); // ensure that the content is not deleted during resource claim destruction content_repo->incrementStreamCount(claim); diff --git a/extensions/rocksdb-repos/tests/DBProvenanceRepositoryTests.cpp b/extensions/rocksdb-repos/tests/DBProvenanceRepositoryTests.cpp index cab212cc3e..8f6677c354 100644 --- a/extensions/rocksdb-repos/tests/DBProvenanceRepositoryTests.cpp +++ b/extensions/rocksdb-repos/tests/DBProvenanceRepositoryTests.cpp @@ -69,7 +69,7 @@ TEST_CASE("Test size limit", "[sizeLimitTest]") { // 60 sec, 100 KB - going to exceed the size limit minifi::provenance::ProvenanceRepository provdb("TestProvRepo", temp_dir.string(), 1min, TEST_PROVENANCE_STORAGE_SIZE, 1s); - auto configuration = std::make_shared(); + auto configuration = std::make_shared(); configuration->set(minifi::Configure::nifi_dbcontent_repository_directory_default, temp_dir.string()); REQUIRE(provdb.initialize(configuration)); @@ -89,7 +89,7 @@ TEST_CASE("Test time limit", "[timeLimitTest]") { // 1 sec, 100 MB - going to exceed TTL minifi::provenance::ProvenanceRepository provdb("TestProvRepo", temp_dir.string(), 1s, TEST_MAX_PROVENANCE_STORAGE_SIZE, 1s); - auto configuration = std::make_shared(); + auto configuration = std::make_shared(); configuration->set(minifi::Configure::nifi_dbcontent_repository_directory_default, temp_dir.string()); REQUIRE(provdb.initialize(configuration)); diff --git a/extensions/rocksdb-repos/tests/EncryptionTests.cpp b/extensions/rocksdb-repos/tests/EncryptionTests.cpp index 41f285d5d4..cf49528e77 100644 --- a/extensions/rocksdb-repos/tests/EncryptionTests.cpp +++ b/extensions/rocksdb-repos/tests/EncryptionTests.cpp @@ -34,9 +34,9 @@ class FFRepoFixture : public TestController { LogTestController::getInstance().setTrace(); home_ = createTempDirectory(); repo_dir_ = home_ / "flowfile_repo"; - config_ = std::make_shared(); + config_ = std::make_shared(); config_->setHome(home_); - container_ = std::make_unique(nullptr, nullptr, "container"); + container_ = std::make_unique(nullptr, nullptr, "container"); content_repo_ = std::make_shared(); content_repo_->initialize(config_); } @@ -83,7 +83,7 @@ TEST_CASE_METHOD(FFRepoFixture, "FlowFileRepository creates checkpoint and loads runWithNewRepository([&] (const std::shared_ptr& repo) { - auto flowfile = std::make_shared(); + auto flowfile = std::make_shared(); flowfile->setAttribute("my little pony", "my horse is amazing"); flowfile->setConnection(container_.get()); putFlowFile(flowfile, repo); diff --git a/extensions/rocksdb-repos/tests/ProvenanceTests.cpp b/extensions/rocksdb-repos/tests/ProvenanceTests.cpp index 402397cb80..21da1df27c 100644 --- a/extensions/rocksdb-repos/tests/ProvenanceTests.cpp +++ b/extensions/rocksdb-repos/tests/ProvenanceTests.cpp @@ -35,13 +35,13 @@ namespace provenance = minifi::provenance; using namespace std::literals::chrono_literals; TEST_CASE("Test Provenance record create", "[Testprovenance::ProvenanceEventRecord]") { - auto record1 = std::make_shared(provenance::ProvenanceEventRecord::ProvenanceEventType::CREATE, "blah", "blahblah"); + auto record1 = std::make_shared(provenance::ProvenanceEventRecord::ProvenanceEventType::CREATE, "blah", "blahblah"); REQUIRE(record1->getAttributes().empty()); REQUIRE(record1->getAlternateIdentifierUri().length() == 0); } TEST_CASE("Test Provenance record serialization", "[Testprovenance::ProvenanceEventRecordSerializeDeser]") { - auto record1 = std::make_shared(provenance::ProvenanceEventRecord::ProvenanceEventType::CREATE, "componentid", "componenttype"); + auto record1 = std::make_shared(provenance::ProvenanceEventRecord::ProvenanceEventType::CREATE, "componentid", "componenttype"); utils::Identifier eventId = record1->getEventId(); @@ -53,7 +53,7 @@ TEST_CASE("Test Provenance record serialization", "[Testprovenance::ProvenanceEv record1->setEventDuration(sample); testRepository->storeElement(record1); - auto record2 = std::make_shared(); + auto record2 = std::make_shared(); record2->setEventId(eventId); REQUIRE(record2->loadFromRepository(testRepository) == true); REQUIRE(record2->getEventId() == record1->getEventId()); @@ -65,9 +65,9 @@ TEST_CASE("Test Provenance record serialization", "[Testprovenance::ProvenanceEv } TEST_CASE("Test Flowfile record added to provenance", "[TestFlowAndProv1]") { - auto record1 = std::make_shared(provenance::ProvenanceEventRecord::ProvenanceEventType::CLONE, "componentid", "componenttype"); + auto record1 = std::make_shared(provenance::ProvenanceEventRecord::ProvenanceEventType::CLONE, "componentid", "componenttype"); utils::Identifier eventId = record1->getEventId(); - std::shared_ptr ffr1 = std::make_shared(); + std::shared_ptr ffr1 = std::make_shared(); ffr1->setAttribute("potato", "potatoe"); ffr1->setAttribute("tomato", "tomatoe"); @@ -78,7 +78,7 @@ TEST_CASE("Test Flowfile record added to provenance", "[TestFlowAndProv1]") { record1->setEventDuration(sample); testRepository->storeElement(record1); - auto record2 = std::make_shared(); + auto record2 = std::make_shared(); record2->setEventId(eventId); REQUIRE(record2->loadFromRepository(testRepository) == true); REQUIRE(record1->getChildrenUuids().size() == 1); @@ -90,7 +90,7 @@ TEST_CASE("Test Flowfile record added to provenance", "[TestFlowAndProv1]") { } TEST_CASE("Test Provenance record serialization Volatile", "[Testprovenance::ProvenanceEventRecordSerializeDeser]") { - auto record1 = std::make_shared(provenance::ProvenanceEventRecord::ProvenanceEventType::CREATE, "componentid", "componenttype"); + auto record1 = std::make_shared(provenance::ProvenanceEventRecord::ProvenanceEventType::CREATE, "componentid", "componenttype"); utils::Identifier eventId = record1->getEventId(); @@ -104,7 +104,7 @@ TEST_CASE("Test Provenance record serialization Volatile", "[Testprovenance::Pro record1->setEventDuration(sample); testRepository->storeElement(record1); - auto record2 = std::make_shared(); + auto record2 = std::make_shared(); record2->setEventId(eventId); REQUIRE(record2->loadFromRepository(testRepository) == true); REQUIRE(record2->getEventId() == record1->getEventId()); @@ -116,9 +116,9 @@ TEST_CASE("Test Provenance record serialization Volatile", "[Testprovenance::Pro } TEST_CASE("Test Flowfile record added to provenance using Volatile Repo", "[TestFlowAndProv1]") { - auto record1 = std::make_shared(provenance::ProvenanceEventRecord::ProvenanceEventType::CLONE, "componentid", "componenttype"); + auto record1 = std::make_shared(provenance::ProvenanceEventRecord::ProvenanceEventType::CLONE, "componentid", "componenttype"); utils::Identifier eventId = record1->getEventId(); - std::shared_ptr ffr1 = std::make_shared(); + std::shared_ptr ffr1 = std::make_shared(); ffr1->setAttribute("potato", "potatoe"); ffr1->setAttribute("tomato", "tomatoe"); @@ -130,7 +130,7 @@ TEST_CASE("Test Flowfile record added to provenance using Volatile Repo", "[Test record1->setEventDuration(sample); testRepository->storeElement(record1); - auto record2 = std::make_shared(); + auto record2 = std::make_shared(); record2->setEventId(eventId); REQUIRE(record2->loadFromRepository(testRepository) == true); REQUIRE(record1->getChildrenUuids().size() == 1); @@ -142,7 +142,7 @@ TEST_CASE("Test Flowfile record added to provenance using Volatile Repo", "[Test } TEST_CASE("Test Provenance record serialization NoOp", "[Testprovenance::ProvenanceEventRecordSerializeDeser]") { - auto record1 = std::make_shared(provenance::ProvenanceEventRecord::ProvenanceEventType::CREATE, "componentid", "componenttype"); + auto record1 = std::make_shared(provenance::ProvenanceEventRecord::ProvenanceEventType::CREATE, "componentid", "componenttype"); utils::Identifier eventId = record1->getEventId(); @@ -156,7 +156,7 @@ TEST_CASE("Test Provenance record serialization NoOp", "[Testprovenance::Provena record1->setEventDuration(sample); REQUIRE(testRepository->storeElement(record1)); - auto record2 = std::make_shared(); + auto record2 = std::make_shared(); record2->setEventId(eventId); REQUIRE(record2->loadFromRepository(testRepository) == false); } diff --git a/extensions/rocksdb-repos/tests/RepoTests.cpp b/extensions/rocksdb-repos/tests/RepoTests.cpp index fbcf32e4ea..dfba8f64d6 100644 --- a/extensions/rocksdb-repos/tests/RepoTests.cpp +++ b/extensions/rocksdb-repos/tests/RepoTests.cpp @@ -39,15 +39,17 @@ #include "core/repository/VolatileProvenanceRepository.h" #include "DatabaseContentRepository.h" #include "catch2/generators/catch_generators.hpp" +#include "core/repository/FileSystemRepository.h" +#include "core/ProcessorNode.h" using namespace std::literals::chrono_literals; namespace { namespace { -class TestProcessor final : public core::Processor { +class TestProcessor final : public core::ProcessorImpl { public: - using Processor::Processor; + using ProcessorImpl::ProcessorImpl; static constexpr bool SupportsDynamicProperties = false; static constexpr bool SupportsDynamicRelationships = false; @@ -73,12 +75,12 @@ TEST_CASE("Test Repo Empty Value Attribute", "[TestFFR1]") { const auto dir = testController.createTempDirectory(); const auto repository = std::make_shared("ff", dir.string(), 0ms, 0, 1ms); - const auto configuration = std::make_shared(); + const auto configuration = std::make_shared(); configuration->setHome(dir); repository->initialize(configuration); std::shared_ptr content_repo = std::make_shared(); - const auto file = std::make_shared(); + const auto file = std::make_shared(); file->addAttribute("keyA", ""); @@ -95,11 +97,11 @@ TEST_CASE("Test Repo Empty Key Attribute ", "[TestFFR2]") { const auto dir = testController.createTempDirectory(); const auto repository = std::make_shared("ff", dir.string(), 0ms, 0, 1ms); - const auto configuration = std::make_shared(); + const auto configuration = std::make_shared(); configuration->setHome(dir); repository->initialize(configuration); std::shared_ptr content_repo = std::make_shared(); - const auto file = std::make_shared(); + const auto file = std::make_shared(); file->addAttribute("keyA", "hasdgasdgjsdgasgdsgsadaskgasd"); @@ -118,12 +120,12 @@ TEST_CASE("Test Repo Key Attribute Verify ", "[TestFFR3]") { auto dir = testController.createTempDirectory(); const auto repository = std::make_shared("ff", dir.string(), 0ms, 0, 1ms); - const auto configuration = std::make_shared(); + const auto configuration = std::make_shared(); configuration->setHome(dir); repository->initialize(configuration); std::shared_ptr content_repo = std::make_shared(); - minifi::FlowFileRecord record; + minifi::FlowFileRecordImpl record; std::string uuid = record.getUUIDStr(); @@ -175,7 +177,7 @@ TEST_CASE("Test Delete Content ", "[TestFFR4]") { std::shared_ptr content_repo = std::make_shared(); - const auto configuration = std::make_shared(); + const auto configuration = std::make_shared(); configuration->setHome(dir); repository->initialize(configuration); @@ -183,8 +185,8 @@ TEST_CASE("Test Delete Content ", "[TestFFR4]") { { - const auto claim = std::make_shared((dir / "tstFile.ext").string(), content_repo); - minifi::FlowFileRecord record; + const auto claim = std::make_shared((dir / "tstFile.ext").string(), content_repo); + minifi::FlowFileRecordImpl record; record.setResourceClaim(claim); record.addAttribute("keyA", "hasdgasdgjsdgasgdsgsadaskgasd"); @@ -226,16 +228,16 @@ TEST_CASE("Test Validate Checkpoint ", "[TestFFR5]") { std::shared_ptr content_repo = std::make_shared(); - const auto configuration = std::make_shared(); + const auto configuration = std::make_shared(); configuration->setHome(dir); repository->initialize(configuration); repository->loadComponent(content_repo); - auto claim = std::make_shared((dir / "tstFile.ext").string(), content_repo); + auto claim = std::make_shared((dir / "tstFile.ext").string(), content_repo); { - minifi::FlowFileRecord record; + minifi::FlowFileRecordImpl record; record.setResourceClaim(claim); record.addAttribute("keyA", "hasdgasdgjsdgasgdsgsadaskgasd"); @@ -278,7 +280,7 @@ TEST_CASE("Test FlowFile Restore", "[TestFFR6]") { auto dir = testController.createTempDirectory(); - auto config = std::make_shared(); + auto config = std::make_shared(); config->setHome(dir); config->set(minifi::Configure::nifi_dbcontent_repository_directory_default, (dir / "content_repository").string()); config->set(minifi::Configure::nifi_flowfile_repository_directory_default, (dir / "flowfile_repository").string()); @@ -290,7 +292,7 @@ TEST_CASE("Test FlowFile Restore", "[TestFFR6]") { content_repo->initialize(config); core::Relationship inputRel{"Input", "dummy"}; - auto input = std::make_unique(ff_repository, content_repo, "Input"); + auto input = std::make_unique(ff_repository, content_repo, "Input"); input->addRelationship(inputRel); auto root = std::make_unique(core::ProcessGroupType::ROOT_PROCESS_GROUP, "root"); @@ -322,9 +324,9 @@ TEST_CASE("Test FlowFile Restore", "[TestFFR6]") { REQUIRE(uuid); inputPtr->setSourceUUID(uuid); processor->addConnection(inputPtr); - auto node = std::make_shared(processor.get()); - auto context = std::make_shared(node, nullptr, prov_repo, ff_repository, content_repo); - core::ProcessSession sessionGenFlowFile(context); + auto node = std::make_shared(processor.get()); + auto context = std::make_shared(node, nullptr, prov_repo, ff_repository, content_repo); + core::ProcessSessionImpl sessionGenFlowFile(context); std::shared_ptr flow = std::static_pointer_cast(sessionGenFlowFile.create()); sessionGenFlowFile.importFrom(content, flow); sessionGenFlowFile.transfer(flow, inputRel); @@ -380,13 +382,13 @@ TEST_CASE("Flush deleted flowfiles before shutdown", "[TestFFR7]") { TestController testController; const auto dir = testController.createTempDirectory(); - const auto config = std::make_shared(); + const auto config = std::make_shared(); config->setHome(dir); config->set(minifi::Configure::nifi_flowfile_repository_directory_default, (dir / "flowfile_repository").string()); const auto content_repo = std::make_shared(); - auto connection = std::make_shared(nullptr, nullptr, "Connection"); + auto connection = std::make_shared(nullptr, nullptr, "Connection"); std::map connectionMap{{connection->getUUIDStr(), connection.get()}}; // initialize repository { @@ -412,7 +414,7 @@ TEST_CASE("Flush deleted flowfiles before shutdown", "[TestFFR7]") { } for (int keyIdx = 0; keyIdx < 100; ++keyIdx) { - auto file = std::make_shared(); + auto file = std::make_shared(); file->setConnection(connection.get()); // Serialize is sync REQUIRE(file->Persist(ff_repository)); @@ -458,7 +460,7 @@ TEST_CASE("FlowFileRepository triggers content repo orphan clear") { auto ff_dir = testController.createTempDirectory(); auto content_dir = testController.createTempDirectory(); - auto config = std::make_shared(); + auto config = std::make_shared(); config->setHome(home_dir); config->set(minifi::Configure::nifi_flowfile_repository_directory_default, ff_dir.string()); config->set(minifi::Configure::nifi_dbcontent_repository_directory_default, content_dir.string()); @@ -466,7 +468,7 @@ TEST_CASE("FlowFileRepository triggers content repo orphan clear") { { auto content_repo = std::make_shared(); REQUIRE(content_repo->initialize(config)); - minifi::ResourceClaim claim(content_repo); + minifi::ResourceClaimImpl claim(content_repo); content_repo->write(claim)->write("hi"); // ensure that the content is not deleted during resource claim destruction content_repo->incrementStreamCount(claim); @@ -493,7 +495,7 @@ TEST_CASE("FlowFileRepository synchronously pushes existing flow files") { const auto ff_dir = testController.createTempDirectory(); const auto content_dir = testController.createTempDirectory(); - const auto config = std::make_shared(); + const auto config = std::make_shared(); config->setHome(home_dir); config->set(minifi::Configure::nifi_flowfile_repository_directory_default, ff_dir.string()); config->set(minifi::Configure::nifi_dbcontent_repository_directory_default, content_dir.string()); @@ -507,12 +509,12 @@ TEST_CASE("FlowFileRepository synchronously pushes existing flow files") { REQUIRE(ff_repo->initialize(config)); auto content_repo = std::make_shared(); REQUIRE(content_repo->initialize(config)); - auto conn = std::make_shared(ff_repo, content_repo, "TestConnection", connection_id); + auto conn = std::make_shared(ff_repo, content_repo, "TestConnection", connection_id); - auto claim = std::make_shared(content_repo); + auto claim = std::make_shared(content_repo); std::vector>> flow_data; - auto ff = std::make_shared(); + auto ff = std::make_shared(); ff_id = ff->getUUID(); ff->setConnection(conn.get()); content_repo->write(*claim)->write("hello"); @@ -529,7 +531,7 @@ TEST_CASE("FlowFileRepository synchronously pushes existing flow files") { REQUIRE(ff_repo->initialize(config)); auto content_repo = std::make_shared(); REQUIRE(content_repo->initialize(config)); - auto conn = std::make_shared(ff_repo, content_repo, "TestConnection", connection_id); + auto conn = std::make_shared(ff_repo, content_repo, "TestConnection", connection_id); ff_repo->setConnectionMap({{connection_id.to_string(), conn.get()}}); ff_repo->loadComponent(content_repo); @@ -575,11 +577,11 @@ TEST_CASE("Test getting flow file repository size properties", "[TestGettingRepo expected_is_full = true; expected_max_repo_size = 7; } - auto configuration = std::make_shared(); + auto configuration = std::make_shared(); configuration->setHome(dir); repository->initialize(configuration); - auto flow_file = std::make_shared(); + auto flow_file = std::make_shared(); for (auto i = 0; i < 100; ++i) { flow_file->addAttribute("key" + std::to_string(i), "testattributevalue" + std::to_string(i)); @@ -594,7 +596,7 @@ TEST_CASE("Test getting flow file repository size properties", "[TestGettingRepo }, std::chrono::milliseconds(50))); REQUIRE(true == flow_file->Persist(repository)); - auto flow_file_2 = std::make_shared(); + auto flow_file_2 = std::make_shared(); REQUIRE(true == flow_file_2->Persist(repository)); repository->flush(); @@ -624,11 +626,11 @@ TEST_CASE("Test getting noop repository size properties", "[TestGettingRepositor const auto repository = minifi::core::createRepository("NoOpRepository", "ff"); - const auto configuration = std::make_shared(); + const auto configuration = std::make_shared(); configuration->setHome(dir); repository->initialize(configuration); - const auto flow_file = std::make_shared(); + const auto flow_file = std::make_shared(); flow_file->addAttribute("key", "testattributevalue"); @@ -652,7 +654,7 @@ TEST_CASE("Test getting content repository size properties", "[TestGettingReposi const auto repository = std::make_shared("ff", dir.string(), 0ms, 0, 1ms); const auto content_repo_dir = testController.createTempDirectory(); - const auto configuration = std::make_shared(); + const auto configuration = std::make_shared(); configuration->setHome(dir); configuration->set(minifi::Configure::nifi_dbcontent_repository_directory_default, content_repo_dir.string()); std::string content = "content"; @@ -683,7 +685,7 @@ TEST_CASE("Test getting content repository size properties", "[TestGettingReposi repository->loadComponent(content_repo); auto original_content_repo_size = content_repo->getRepositorySize(); - auto flow_file = std::make_shared(); + auto flow_file = std::make_shared(); auto content_session = content_repo->createSession(); auto claim = content_session->create(); @@ -745,7 +747,7 @@ TEST_CASE("Flow file repositories can be stopped", "[TestRepoIsRunning]") { repository = core::createRepository("NoOpRepository", "ff"); } - const auto configuration = std::make_shared(); + const auto configuration = std::make_shared(); configuration->setHome(dir); repository->initialize(configuration); @@ -781,7 +783,7 @@ TEST_CASE("Content repositories are always running", "[TestRepoIsRunning]") { } std::shared_ptr createFlowFileWithContent(core::ContentRepository& content_repo, std::string_view content) { - auto flow_file = std::make_shared(); + auto flow_file = std::make_shared(); const auto content_session = content_repo.createSession(); const auto claim = content_session->create(); const auto stream = content_session->write(claim); @@ -808,7 +810,7 @@ TEST_CASE("FlowFileRepository can filter out too small contents") { const auto ff_dir = testController.createTempDirectory(); const auto content_dir = testController.createTempDirectory(); - auto config = std::make_shared(); + auto config = std::make_shared(); config->setHome(minifi_home); config->set(minifi::Configure::nifi_flowfile_repository_directory_default, ff_dir.string()); config->set(minifi::Configure::nifi_dbcontent_repository_directory_default, content_dir.string()); @@ -842,7 +844,7 @@ TEST_CASE("FlowFileRepository can filter out too small contents") { REQUIRE(ff_repo->initialize(config)); REQUIRE(content_repo->initialize(config)); auto connection_id = utils::IdGenerator::getIdGenerator()->generate(); - auto connection = std::make_shared(ff_repo, content_repo, "TestConnection", connection_id); + auto connection = std::make_shared(ff_repo, content_repo, "TestConnection", connection_id); auto first_flow_file = createFlowFileWithContent(*content_repo, "foo"); auto second_flow_file = createFlowFileWithContent(*content_repo, "bar"); diff --git a/extensions/rocksdb-repos/tests/RocksDBUtilsTests.cpp b/extensions/rocksdb-repos/tests/RocksDBUtilsTests.cpp index a13e2493f2..16eca28c23 100644 --- a/extensions/rocksdb-repos/tests/RocksDBUtilsTests.cpp +++ b/extensions/rocksdb-repos/tests/RocksDBUtilsTests.cpp @@ -32,7 +32,7 @@ TEST_CASE("Get global RocksDB options to override", "[rocksdbutils]") { {"create_if_missing", "false"} }; - auto config = std::make_shared(); + auto config = std::make_shared(); config->set("nifi.c2.rest.url", "http://localhost:8080"); config->set("nifi.global.rocksdb.options.table_cache_numshardbits", "456"); config->set("nifi.global.rocksdb.options.keep_log_file_num", "123"); diff --git a/extensions/rocksdb-repos/tests/SwapTests.cpp b/extensions/rocksdb-repos/tests/SwapTests.cpp index 5e04bf5a6d..a3e6cb0c00 100644 --- a/extensions/rocksdb-repos/tests/SwapTests.cpp +++ b/extensions/rocksdb-repos/tests/SwapTests.cpp @@ -20,19 +20,21 @@ #include "core/repository/VolatileContentRepository.h" #include "FlowFileRepository.h" #include "unit/TestBase.h" -#include "StreamPipe.h" +#include "io/StreamPipe.h" #include "unit/TestUtils.h" #include "core/Processor.h" #include "core/ProcessSession.h" #include "core/PropertyDefinition.h" #include "core/RelationshipDefinition.h" #include "unit/ProvenanceTestHelper.h" +#include "core/ProcessorNode.h" +#include "core/repository/FileSystemRepository.h" namespace org::apache::nifi::minifi::test { -class OutputProcessor : public core::Processor { +class OutputProcessor : public core::ProcessorImpl { public: - using core::Processor::Processor; + using core::ProcessorImpl::ProcessorImpl; static constexpr const char* Description = "Processor used for testing cycles"; static constexpr auto Properties = std::array{}; @@ -82,7 +84,7 @@ TEST_CASE("Connection will on-demand swap flow files") { auto dir = testController.createTempDirectory(); - auto config = std::make_shared(); + auto config = std::make_shared(); config->setHome(dir); config->set(minifi::Configure::nifi_dbcontent_repository_directory_default, (dir / "content_repository").string()); config->set(minifi::Configure::nifi_flowfile_repository_directory_default, (dir / "flowfile_repository").string()); @@ -100,15 +102,15 @@ TEST_CASE("Connection will on-demand swap flow files") { auto processor = std::make_shared("proc"); - auto connection = std::make_shared(ff_repo, content_repo, swap_manager, "conn", minifi::utils::IdGenerator::getIdGenerator()->generate()); + auto connection = std::make_shared(ff_repo, content_repo, swap_manager, "conn", minifi::utils::IdGenerator::getIdGenerator()->generate()); connection->setSwapThreshold(50); connection->addRelationship(OutputProcessor::Success); connection->setSourceUUID(processor->getUUID()); processor->addConnection(connection.get()); - auto processor_node = std::make_shared(processor.get()); - auto context = std::make_shared(processor_node, nullptr, prov_repo, ff_repo, content_repo); - auto session_factory = std::make_shared(context); + auto processor_node = std::make_shared(processor.get()); + auto context = std::make_shared(processor_node, nullptr, prov_repo, ff_repo, content_repo); + auto session_factory = std::make_shared(context); for (size_t i = 0; i < 200; ++i) { processor->triggerAndCommit(context, session_factory); diff --git a/extensions/script/ExecuteScript.h b/extensions/script/ExecuteScript.h index 25a843dfb3..d6d241abdc 100644 --- a/extensions/script/ExecuteScript.h +++ b/extensions/script/ExecuteScript.h @@ -33,7 +33,7 @@ #include "ScriptExecutor.h" #include "utils/Enum.h" #include "utils/ResourceQueue.h" -#include "logging/LoggerFactory.h" +#include "core/logging/LoggerFactory.h" namespace org::apache::nifi::minifi::processors { @@ -44,10 +44,10 @@ enum class ScriptEngineOption { }; } // namespace execute_script -class ExecuteScript : public core::Processor { +class ExecuteScript : public core::ProcessorImpl { public: explicit ExecuteScript(std::string_view name, const utils::Identifier &uuid = {}) - : Processor(name, uuid) { + : ProcessorImpl(name, uuid) { } EXTENSIONAPI static constexpr const char* Description = "Executes a script given the flow file and a process session. " diff --git a/extensions/script/ScriptExecutor.h b/extensions/script/ScriptExecutor.h index b685993b70..1baea83f0f 100644 --- a/extensions/script/ScriptExecutor.h +++ b/extensions/script/ScriptExecutor.h @@ -20,15 +20,15 @@ #include #include -#include "Core.h" -#include "ProcessContext.h" -#include "ProcessSession.h" +#include "core/Core.h" +#include "core/ProcessContext.h" +#include "core/ProcessSession.h" namespace org::apache::nifi::minifi::extensions::script { -class ScriptExecutor : public minifi::core::CoreComponent { +class ScriptExecutor : public minifi::core::CoreComponentImpl { public: - ScriptExecutor(const std::string_view name, const utils::Identifier& uuid) : core::CoreComponent(name, uuid) {} + ScriptExecutor(const std::string_view name, const utils::Identifier& uuid) : core::CoreComponentImpl(name, uuid) {} virtual void onTrigger(core::ProcessContext& context, core::ProcessSession& session) = 0; virtual void initialize(std::filesystem::path script_file, diff --git a/extensions/sftp/client/SFTPClient.cpp b/extensions/sftp/client/SFTPClient.cpp index 2e907931ac..8ad8ec0247 100644 --- a/extensions/sftp/client/SFTPClient.cpp +++ b/extensions/sftp/client/SFTPClient.cpp @@ -29,6 +29,8 @@ #include "utils/StringUtils.h" #include "utils/gsl.h" +#include "minifi-cpp/io/OutputStream.h" +#include "minifi-cpp/io/InputStream.h" namespace org::apache::nifi::minifi::utils { diff --git a/extensions/sftp/client/SFTPClient.h b/extensions/sftp/client/SFTPClient.h index 28d9024a89..fc6b66f7a5 100644 --- a/extensions/sftp/client/SFTPClient.h +++ b/extensions/sftp/client/SFTPClient.h @@ -20,18 +20,23 @@ #include #include #include -#include + #include -#include -#include #include #include +#include +#include +#include #include "Exception.h" -#include "utils/Enum.h" -#include "http/BaseHTTPClient.h" #include "core/logging/Logger.h" +#include "http/BaseHTTPClient.h" +#include "utils/Enum.h" +namespace org::apache::nifi::minifi::io { +class OutputStream; +class InputStream; +} namespace org::apache::nifi::minifi::utils { enum class SFTPError { diff --git a/extensions/sftp/processors/FetchSFTP.h b/extensions/sftp/processors/FetchSFTP.h index 021a565449..4bf9cbe705 100644 --- a/extensions/sftp/processors/FetchSFTP.h +++ b/extensions/sftp/processors/FetchSFTP.h @@ -29,7 +29,7 @@ #include "core/Property.h" #include "core/PropertyDefinitionBuilder.h" #include "core/PropertyType.h" -#include "core/logging/LoggerConfiguration.h" +#include "core/logging/LoggerFactory.h" #include "utils/ArrayUtils.h" #include "utils/Id.h" #include "../client/SFTPClient.h" diff --git a/extensions/sftp/processors/PutSFTP.h b/extensions/sftp/processors/PutSFTP.h index 4d5dc2b94a..5cdeefca93 100644 --- a/extensions/sftp/processors/PutSFTP.h +++ b/extensions/sftp/processors/PutSFTP.h @@ -35,7 +35,7 @@ #include "core/PropertyType.h" #include "core/RelationshipDefinition.h" #include "controllers/SSLContextService.h" -#include "core/logging/LoggerConfiguration.h" +#include "core/logging/LoggerFactory.h" #include "utils/ArrayUtils.h" #include "utils/Id.h" #include "../client/SFTPClient.h" diff --git a/extensions/sftp/processors/SFTPProcessorBase.cpp b/extensions/sftp/processors/SFTPProcessorBase.cpp index 574ea06852..f8e78e370e 100644 --- a/extensions/sftp/processors/SFTPProcessorBase.cpp +++ b/extensions/sftp/processors/SFTPProcessorBase.cpp @@ -42,8 +42,8 @@ namespace org::apache::nifi::minifi::processors { -SFTPProcessorBase::SFTPProcessorBase(std::string_view name, const utils::Identifier& uuid) - : Processor(name, uuid), +SFTPProcessorBase::SFTPProcessorBase(const std::string_view name, const utils::Identifier& uuid) + : ProcessorImpl(name, uuid), connection_timeout_(0), data_timeout_(0), strict_host_checking_(false), diff --git a/extensions/sftp/processors/SFTPProcessorBase.h b/extensions/sftp/processors/SFTPProcessorBase.h index f30b0f21ae..9a3bd8846a 100644 --- a/extensions/sftp/processors/SFTPProcessorBase.h +++ b/extensions/sftp/processors/SFTPProcessorBase.h @@ -38,7 +38,7 @@ namespace org::apache::nifi::minifi::processors { -class SFTPProcessorBase : public core::Processor { +class SFTPProcessorBase : public core::ProcessorImpl { public: SFTPProcessorBase(std::string_view name, const utils::Identifier& uuid); ~SFTPProcessorBase() override; diff --git a/extensions/sftp/tests/ListSFTPTests.cpp b/extensions/sftp/tests/ListSFTPTests.cpp index 8d902503da..1d2bd3e9b6 100644 --- a/extensions/sftp/tests/ListSFTPTests.cpp +++ b/extensions/sftp/tests/ListSFTPTests.cpp @@ -167,7 +167,7 @@ class ListSFTPTestsFixture { class PersistentListSFTPTestsFixture : public ListSFTPTestsFixture { public: PersistentListSFTPTestsFixture() : - ListSFTPTestsFixture(std::make_shared()) { + ListSFTPTestsFixture(std::make_shared()) { } }; @@ -555,7 +555,7 @@ TEST_CASE_METHOD(PersistentListSFTPTestsFixture, "ListSFTP Tracking Timestamps r utils::Identifier list_sftp_uuid = list_sftp->getUUID(); REQUIRE(list_sftp_uuid); - createPlan(&list_sftp_uuid, std::make_shared()); + createPlan(&list_sftp_uuid, std::make_shared()); plan->setProperty(list_sftp, "Listing Strategy", "Tracking Timestamps"); LogTestController::getInstance().clear(); @@ -597,7 +597,7 @@ TEST_CASE_METHOD(PersistentListSFTPTestsFixture, "ListSFTP Tracking Timestamps r utils::Identifier list_sftp_uuid = list_sftp->getUUID(); REQUIRE(list_sftp_uuid); - createPlan(&list_sftp_uuid, std::make_shared()); + createPlan(&list_sftp_uuid, std::make_shared()); plan->setProperty(list_sftp, "Listing Strategy", "Tracking Timestamps"); plan->setProperty(list_sftp, "Remote Path", "/nifi_test"); LogTestController::getInstance().clear(); @@ -836,7 +836,7 @@ TEST_CASE_METHOD(PersistentListSFTPTestsFixture, "ListSFTP Tracking Entities res utils::Identifier list_sftp_uuid = list_sftp->getUUID(); REQUIRE(list_sftp_uuid); - createPlan(&list_sftp_uuid, std::make_shared()); + createPlan(&list_sftp_uuid, std::make_shared()); plan->setProperty(list_sftp, "Listing Strategy", "Tracking Entities"); LogTestController::getInstance().clear(); @@ -896,7 +896,7 @@ TEST_CASE_METHOD(PersistentListSFTPTestsFixture, "ListSFTP Tracking Entities res utils::Identifier list_sftp_uuid = list_sftp->getUUID(); REQUIRE(list_sftp_uuid); - createPlan(&list_sftp_uuid, std::make_shared()); + createPlan(&list_sftp_uuid, std::make_shared()); plan->setProperty(list_sftp, "Listing Strategy", "Tracking Entities"); plan->setProperty(list_sftp, "Remote Path", "/nifi_test"); LogTestController::getInstance().clear(); diff --git a/extensions/sftp/tests/tools/SFTPTestServer.h b/extensions/sftp/tests/tools/SFTPTestServer.h index fb540e1bea..421582134d 100644 --- a/extensions/sftp/tests/tools/SFTPTestServer.h +++ b/extensions/sftp/tests/tools/SFTPTestServer.h @@ -27,7 +27,7 @@ #endif #include "core/logging/Logger.h" -#include "core/logging/LoggerConfiguration.h" +#include "core/logging/LoggerFactory.h" std::filesystem::path get_sftp_test_dir(); diff --git a/extensions/smb/FetchSmb.h b/extensions/smb/FetchSmb.h index 7b50c6595c..54c794e8a9 100644 --- a/extensions/smb/FetchSmb.h +++ b/extensions/smb/FetchSmb.h @@ -29,7 +29,7 @@ #include "core/PropertyDefinition.h" #include "core/PropertyDefinitionBuilder.h" #include "core/OutputAttributeDefinition.h" -#include "core/logging/LoggerConfiguration.h" +#include "core/logging/LoggerFactory.h" #include "utils/Enum.h" #include "utils/ListingStateManager.h" #include "utils/file/ListedFile.h" @@ -37,10 +37,10 @@ namespace org::apache::nifi::minifi::extensions::smb { -class FetchSmb : public core::Processor { +class FetchSmb final : public core::ProcessorImpl { public: - explicit FetchSmb(std::string name, const utils::Identifier& uuid = {}) - : core::Processor(std::move(name), uuid) { + explicit FetchSmb(const std::string_view name, const utils::Identifier& uuid = {}) + : core::ProcessorImpl(name, uuid) { } EXTENSIONAPI static constexpr const char* Description = "Fetches files from a SMB Share. Designed to be used in tandem with ListSmb."; diff --git a/extensions/smb/ListSmb.h b/extensions/smb/ListSmb.h index ddb4409fdc..ae2f9def63 100644 --- a/extensions/smb/ListSmb.h +++ b/extensions/smb/ListSmb.h @@ -29,7 +29,7 @@ #include "core/PropertyDefinition.h" #include "core/PropertyDefinitionBuilder.h" #include "core/OutputAttributeDefinition.h" -#include "core/logging/LoggerConfiguration.h" +#include "core/logging/LoggerFactory.h" #include "utils/Enum.h" #include "utils/ListingStateManager.h" #include "utils/file/ListedFile.h" @@ -37,10 +37,10 @@ namespace org::apache::nifi::minifi::extensions::smb { -class ListSmb : public core::Processor { +class ListSmb : public core::ProcessorImpl { public: - explicit ListSmb(std::string name, const utils::Identifier& uuid = {}) - : core::Processor(std::move(name), uuid) { + explicit ListSmb(std::string_view name, const utils::Identifier& uuid = {}) + : core::ProcessorImpl(name, uuid) { } EXTENSIONAPI static constexpr const char* Description = "Retrieves a listing of files from an SMB share. For each file that is listed, " diff --git a/extensions/smb/PutSmb.cpp b/extensions/smb/PutSmb.cpp index 2b20ce0e81..507629e549 100644 --- a/extensions/smb/PutSmb.cpp +++ b/extensions/smb/PutSmb.cpp @@ -22,6 +22,7 @@ #include "utils/OsUtils.h" #include "utils/file/FileWriterCallback.h" #include "core/Resource.h" +#include "utils/file/FileUtils.h" namespace org::apache::nifi::minifi::extensions::smb { diff --git a/extensions/smb/PutSmb.h b/extensions/smb/PutSmb.h index c25e38f337..cb29d5c805 100644 --- a/extensions/smb/PutSmb.h +++ b/extensions/smb/PutSmb.h @@ -25,14 +25,14 @@ #include "core/ProcessSession.h" #include "utils/Enum.h" #include "SmbConnectionControllerService.h" -#include "core/logging/LoggerConfiguration.h" +#include "core/logging/LoggerFactory.h" namespace org::apache::nifi::minifi::extensions::smb { -class PutSmb : public core::Processor { +class PutSmb final : public core::ProcessorImpl { public: - explicit PutSmb(std::string name, const utils::Identifier& uuid = {}) - : core::Processor(std::move(name), uuid) { + explicit PutSmb(const std::string_view name, const utils::Identifier& uuid = {}) + : core::ProcessorImpl(name, uuid) { } enum class FileExistsResolutionStrategy { diff --git a/extensions/smb/SmbConnectionControllerService.h b/extensions/smb/SmbConnectionControllerService.h index ae05c62ba4..8522e027da 100644 --- a/extensions/smb/SmbConnectionControllerService.h +++ b/extensions/smb/SmbConnectionControllerService.h @@ -20,18 +20,21 @@ #include #include -#include "ProcessContext.h" +#include "Windows.h" +#include "winnetwk.h" + +#include "core/ProcessContext.h" #include "core/PropertyDefinition.h" #include "core/PropertyDefinitionBuilder.h" #include "core/controller/ControllerService.h" #include "core/logging/Logger.h" -#include "core/logging/LoggerConfiguration.h" +#include "core/logging/LoggerFactory.h" #include "utils/Enum.h" #include "utils/expected.h" namespace org::apache::nifi::minifi::extensions::smb { -class SmbConnectionControllerService : public core::controller::ControllerService { +class SmbConnectionControllerService : public core::controller::ControllerServiceImpl { public: EXTENSIONAPI static constexpr const char* Description = "SMB Connection Controller Service"; @@ -70,7 +73,7 @@ class SmbConnectionControllerService : public core::controller::ControllerServic EXTENSIONAPI static constexpr bool SupportsDynamicProperties = false; ADD_COMMON_VIRTUAL_FUNCTIONS_FOR_CONTROLLER_SERVICES - using ControllerService::ControllerService; + using ControllerServiceImpl::ControllerServiceImpl; void initialize() override; diff --git a/extensions/smb/tests/FetchSmbTests.cpp b/extensions/smb/tests/FetchSmbTests.cpp index 8fd05c8c4f..0fe7081675 100644 --- a/extensions/smb/tests/FetchSmbTests.cpp +++ b/extensions/smb/tests/FetchSmbTests.cpp @@ -22,7 +22,7 @@ #include "SmbConnectionControllerService.h" #include "utils/MockSmbConnectionControllerService.h" #include "unit/SingleProcessorTestController.h" -#include "OsUtils.h" +#include "utils/OsUtils.h" #include "core/Resource.h" namespace org::apache::nifi::minifi::extensions::smb::test { diff --git a/extensions/splunk/SplunkHECProcessor.h b/extensions/splunk/SplunkHECProcessor.h index 7df54b9aa4..24f3574a7f 100644 --- a/extensions/splunk/SplunkHECProcessor.h +++ b/extensions/splunk/SplunkHECProcessor.h @@ -34,7 +34,7 @@ class HTTPClient; namespace org::apache::nifi::minifi::extensions::splunk { -class SplunkHECProcessor : public core::Processor { +class SplunkHECProcessor : public core::ProcessorImpl { public: EXTENSIONAPI static constexpr auto Hostname = core::PropertyDefinitionBuilder<>::createProperty("Hostname") .withDescription("The ip address or hostname of the Splunk server.") @@ -71,7 +71,7 @@ class SplunkHECProcessor : public core::Processor { explicit SplunkHECProcessor(std::string_view name, const utils::Identifier& uuid = {}) - : Processor(name, uuid) { + : ProcessorImpl(name, uuid) { } ~SplunkHECProcessor() override = default; diff --git a/extensions/splunk/tests/MockSplunkHEC.h b/extensions/splunk/tests/MockSplunkHEC.h index 53b548ba18..13bce3990f 100644 --- a/extensions/splunk/tests/MockSplunkHEC.h +++ b/extensions/splunk/tests/MockSplunkHEC.h @@ -24,7 +24,7 @@ #include #include "integration/CivetLibrary.h" #include "core/logging/Logger.h" -#include "core/logging/LoggerConfiguration.h" +#include "core/logging/LoggerFactory.h" #include "rapidjson/document.h" #include "rapidjson/writer.h" #include "rapidjson/stringbuffer.h" diff --git a/extensions/sql/data/SociConnectors.cpp b/extensions/sql/data/SociConnectors.cpp index 9bdc626e88..4ed36708b5 100644 --- a/extensions/sql/data/SociConnectors.cpp +++ b/extensions/sql/data/SociConnectors.cpp @@ -17,7 +17,7 @@ */ #include "SociConnectors.h" -#include "logging/LoggerFactory.h" +#include "core/logging/LoggerFactory.h" namespace org::apache::nifi::minifi::sql { diff --git a/extensions/sql/data/SociConnectors.h b/extensions/sql/data/SociConnectors.h index f590ccf735..7c43328d60 100644 --- a/extensions/sql/data/SociConnectors.h +++ b/extensions/sql/data/SociConnectors.h @@ -26,7 +26,7 @@ #include "data/DatabaseConnectors.h" #include #include -#include "logging/Logger.h" +#include "core/logging/Logger.h" namespace org::apache::nifi::minifi::sql { diff --git a/extensions/sql/processors/FlowFileSource.h b/extensions/sql/processors/FlowFileSource.h index 19310eba44..4da2d07328 100644 --- a/extensions/sql/processors/FlowFileSource.h +++ b/extensions/sql/processors/FlowFileSource.h @@ -26,7 +26,7 @@ #include "core/PropertyType.h" #include "utils/Enum.h" #include "data/SQLRowsetProcessor.h" -#include "ProcessSession.h" +#include "core/ProcessSession.h" #include "data/JSONSQLWriter.h" namespace org::apache::nifi::minifi::processors::flow_file_source { diff --git a/extensions/sql/processors/SQLProcessor.h b/extensions/sql/processors/SQLProcessor.h index c6ce3b5aa3..ea326a99ae 100644 --- a/extensions/sql/processors/SQLProcessor.h +++ b/extensions/sql/processors/SQLProcessor.h @@ -31,7 +31,7 @@ namespace org::apache::nifi::minifi::processors { -class SQLProcessor: public core::Processor { +class SQLProcessor: public core::ProcessorImpl { public: EXTENSIONAPI static constexpr auto DBControllerService = core::PropertyDefinitionBuilder<>::createProperty("DB Controller Service") .withDescription("Database Controller Service.") @@ -42,7 +42,7 @@ class SQLProcessor: public core::Processor { protected: SQLProcessor(std::string_view name, const utils::Identifier& uuid, std::shared_ptr logger) - : core::Processor(name, uuid), logger_(std::move(logger)) { + : core::ProcessorImpl(name, uuid), logger_(std::move(logger)) { } static std::vector collectArguments(const std::shared_ptr& flow_file); diff --git a/extensions/sql/services/DatabaseService.cpp b/extensions/sql/services/DatabaseService.cpp index ce3c0fb10e..9c95b724f7 100644 --- a/extensions/sql/services/DatabaseService.cpp +++ b/extensions/sql/services/DatabaseService.cpp @@ -15,7 +15,7 @@ * limitations under the License. */ -#include "core/logging/LoggerConfiguration.h" +#include "core/logging/LoggerFactory.h" #include "core/controller/ControllerService.h" #include #include @@ -33,7 +33,7 @@ void DatabaseService::initialize() { return; } - ControllerService::initialize(); + ControllerServiceImpl::initialize(); initializeProperties(); diff --git a/extensions/sql/services/DatabaseService.h b/extensions/sql/services/DatabaseService.h index 043d0418c0..0679d476e7 100644 --- a/extensions/sql/services/DatabaseService.h +++ b/extensions/sql/services/DatabaseService.h @@ -21,7 +21,7 @@ #include #include -#include "core/logging/LoggerConfiguration.h" +#include "core/logging/LoggerFactory.h" #include "core/controller/ControllerService.h" #include "core/PropertyDefinition.h" #include "core/PropertyDefinitionBuilder.h" @@ -34,19 +34,19 @@ 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::ControllerService { +class DatabaseService : public core::controller::ControllerServiceImpl { public: - explicit DatabaseService(std::string_view name, const utils::Identifier &uuid = {}) - : ControllerService(name, uuid), + explicit DatabaseService(const std::string_view name, const utils::Identifier &uuid = {}) + : ControllerServiceImpl(name, uuid), initialized_(false) { - initialize(); + DatabaseService::initialize(); } - explicit DatabaseService(std::string_view name, const std::shared_ptr &configuration) - : ControllerService(name), + explicit DatabaseService(const std::string_view name, const std::shared_ptr &configuration) + : ControllerServiceImpl(name), initialized_(false) { - setConfiguration(configuration); - initialize(); + ControllerServiceImpl::setConfiguration(configuration); + DatabaseService::initialize(); } /** diff --git a/extensions/sql/services/ODBCConnector.h b/extensions/sql/services/ODBCConnector.h index ebc4498863..5c3e6d845e 100644 --- a/extensions/sql/services/ODBCConnector.h +++ b/extensions/sql/services/ODBCConnector.h @@ -21,7 +21,7 @@ #include #include -#include "core/logging/LoggerConfiguration.h" +#include "core/logging/LoggerFactory.h" #include "core/controller/ControllerService.h" #include "DatabaseService.h" @@ -34,17 +34,17 @@ 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 ODBCService : public DatabaseService { +class ODBCService final : public DatabaseService { public: - explicit ODBCService(std::string name, const utils::Identifier &uuid = {}) - : DatabaseService(std::move(name), uuid) { - initialize(); + explicit ODBCService(const std::string_view name, const utils::Identifier &uuid = {}) + : DatabaseService(name, uuid) { + DatabaseService::initialize(); } - explicit ODBCService(std::string_view name, const std::shared_ptr &configuration) + explicit ODBCService(const std::string_view name, const std::shared_ptr &configuration) : DatabaseService(name) { - setConfiguration(configuration); - initialize(); + ControllerServiceImpl::setConfiguration(configuration); + DatabaseService::initialize(); } EXTENSIONAPI static constexpr const char* Description = "Controller service that provides ODBC database connection"; diff --git a/extensions/sql/tests/SQLTestPlan.h b/extensions/sql/tests/SQLTestPlan.h index aebe51b2b7..4af814634d 100644 --- a/extensions/sql/tests/SQLTestPlan.h +++ b/extensions/sql/tests/SQLTestPlan.h @@ -58,12 +58,12 @@ class SQLTestPlan { } std::shared_ptr addInput(std::initializer_list> attributes = {}, const std::optional& content = {}) { - auto flow_file = std::make_shared(); + auto flow_file = std::make_shared(); for (const auto& attr : attributes) { flow_file->setAttribute(attr.first, attr.second); } if (content) { - auto claim = std::make_shared(plan_->getContentRepo()); + auto claim = std::make_shared(plan_->getContentRepo()); auto content_stream = plan_->getContentRepo()->write(*claim); const auto ret = content_stream->write(reinterpret_cast(content->c_str()), content->length()); REQUIRE(ret == content->length()); diff --git a/extensions/standard-processors/controllers/JsonRecordSetReader.h b/extensions/standard-processors/controllers/JsonRecordSetReader.h index 4dae262b81..26ae7a4cec 100644 --- a/extensions/standard-processors/controllers/JsonRecordSetReader.h +++ b/extensions/standard-processors/controllers/JsonRecordSetReader.h @@ -16,16 +16,15 @@ */ #pragma once -#include "Record.h" #include "controllers/RecordSetReader.h" #include "core/FlowFile.h" #include "core/ProcessSession.h" namespace org::apache::nifi::minifi::standard { -class JsonRecordSetReader final : public core::RecordSetReader { +class JsonRecordSetReader final : public core::RecordSetReaderImpl { public: - explicit JsonRecordSetReader(const std::string_view name, const utils::Identifier& uuid = {}) : RecordSetReader(name, uuid) {} + explicit JsonRecordSetReader(const std::string_view name, const utils::Identifier& uuid = {}) : RecordSetReaderImpl(name, uuid) {} JsonRecordSetReader(JsonRecordSetReader&&) = delete; JsonRecordSetReader(const JsonRecordSetReader&) = delete; diff --git a/extensions/standard-processors/controllers/JsonRecordSetWriter.h b/extensions/standard-processors/controllers/JsonRecordSetWriter.h index 8da60ab8d3..23f1a5e91c 100644 --- a/extensions/standard-processors/controllers/JsonRecordSetWriter.h +++ b/extensions/standard-processors/controllers/JsonRecordSetWriter.h @@ -16,8 +16,7 @@ */ #pragma once -#include "PropertyDefinitionBuilder.h" -#include "Record.h" +#include "core/PropertyDefinitionBuilder.h" #include "controllers/RecordSetWriter.h" #include "core/FlowFile.h" #include "core/ProcessSession.h" @@ -47,9 +46,9 @@ constexpr customize_t enum_name(OutputGroupingType value) no namespace org::apache::nifi::minifi::standard { -class JsonRecordSetWriter final : public core::RecordSetWriter { +class JsonRecordSetWriter final : public core::RecordSetWriterImpl { public: - explicit JsonRecordSetWriter(const std::string_view name, const utils::Identifier& uuid = {}) : RecordSetWriter(name, uuid) {} + explicit JsonRecordSetWriter(const std::string_view name, const utils::Identifier& uuid = {}) : RecordSetWriterImpl(name, uuid) {} JsonRecordSetWriter(JsonRecordSetWriter&&) = delete; JsonRecordSetWriter(const JsonRecordSetWriter&) = delete; diff --git a/extensions/standard-processors/controllers/PersistentMapStateStorage.cpp b/extensions/standard-processors/controllers/PersistentMapStateStorage.cpp index 0765fdf780..024f42a9a2 100644 --- a/extensions/standard-processors/controllers/PersistentMapStateStorage.cpp +++ b/extensions/standard-processors/controllers/PersistentMapStateStorage.cpp @@ -121,7 +121,7 @@ bool PersistentMapStateStorage::parseLine(const std::string& line, std::string& void PersistentMapStateStorage::initialize() { // VolatileMapStateStorage::initialize() also calls setSupportedProperties, and we don't want that - ControllerService::initialize(); // NOLINT(bugprone-parent-virtual-call) + ControllerServiceImpl::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 065fcca41f..86096a07b5 100644 --- a/extensions/standard-processors/controllers/PersistentMapStateStorage.h +++ b/extensions/standard-processors/controllers/PersistentMapStateStorage.h @@ -22,13 +22,13 @@ #include #include -#include "controllers/keyvalue/AutoPersistor.h" +#include "utils/AutoPersistor.h" #include "core/Core.h" #include "properties/Configure.h" #include "InMemoryKeyValueStorage.h" #include "controllers/keyvalue/KeyValueStateStorage.h" #include "core/logging/Logger.h" -#include "core/logging/LoggerConfiguration.h" +#include "core/logging/LoggerFactory.h" #include "core/PropertyDefinition.h" #include "core/PropertyDefinitionBuilder.h" #include "core/PropertyType.h" diff --git a/extensions/standard-processors/controllers/VolatileMapStateStorage.cpp b/extensions/standard-processors/controllers/VolatileMapStateStorage.cpp index b8eb9e391d..1f7a375ce4 100644 --- a/extensions/standard-processors/controllers/VolatileMapStateStorage.cpp +++ b/extensions/standard-processors/controllers/VolatileMapStateStorage.cpp @@ -30,7 +30,7 @@ VolatileMapStateStorage::VolatileMapStateStorage(const std::string& name, const } void VolatileMapStateStorage::initialize() { - ControllerService::initialize(); + ControllerServiceImpl::initialize(); setSupportedProperties(Properties); } diff --git a/extensions/standard-processors/controllers/VolatileMapStateStorage.h b/extensions/standard-processors/controllers/VolatileMapStateStorage.h index 2e8c8f0648..e5572cf38a 100644 --- a/extensions/standard-processors/controllers/VolatileMapStateStorage.h +++ b/extensions/standard-processors/controllers/VolatileMapStateStorage.h @@ -25,7 +25,7 @@ #include "core/Core.h" #include "properties/Configure.h" #include "core/logging/Logger.h" -#include "core/logging/LoggerConfiguration.h" +#include "core/logging/LoggerFactory.h" #include "core/PropertyDefinition.h" #include "core/PropertyDefinitionBuilder.h" #include "controllers/keyvalue/KeyValueStateStorage.h" diff --git a/extensions/standard-processors/modbus/FetchModbusTcp.cpp b/extensions/standard-processors/modbus/FetchModbusTcp.cpp index cb2a284941..0d48196d40 100644 --- a/extensions/standard-processors/modbus/FetchModbusTcp.cpp +++ b/extensions/standard-processors/modbus/FetchModbusTcp.cpp @@ -26,6 +26,7 @@ #include "modbus/ReadModbusFunctions.h" #include "utils/net/AsioCoro.h" #include "utils/net/AsioSocketUtils.h" +#include "io/validation.h" using namespace std::literals::chrono_literals; diff --git a/extensions/standard-processors/modbus/FetchModbusTcp.h b/extensions/standard-processors/modbus/FetchModbusTcp.h index 229bac4111..bcac234235 100644 --- a/extensions/standard-processors/modbus/FetchModbusTcp.h +++ b/extensions/standard-processors/modbus/FetchModbusTcp.h @@ -20,7 +20,7 @@ #include "controllers/RecordSetWriter.h" #include "core/Processor.h" #include "core/PropertyDefinitionBuilder.h" -#include "logging/LoggerFactory.h" +#include "core/logging/LoggerFactory.h" #include "utils/net/AsioCoro.h" #include "utils/net/AsioSocketUtils.h" #include "utils/net/ConnectionHandlerBase.h" @@ -29,10 +29,10 @@ namespace org::apache::nifi::minifi::modbus { class ReadModbusFunction; -class FetchModbusTcp final : public core::Processor { +class FetchModbusTcp final : public core::ProcessorImpl { public: explicit FetchModbusTcp(const std::string_view name, const utils::Identifier& uuid = {}) - : Processor(name, uuid) { + : ProcessorImpl(name, uuid) { } EXTENSIONAPI static constexpr auto Description = "Processor able to read data from industrial PLCs using Modbus TCP/IP"; diff --git a/extensions/standard-processors/modbus/ReadModbusFunctions.h b/extensions/standard-processors/modbus/ReadModbusFunctions.h index d96e3d09b8..8433c73520 100644 --- a/extensions/standard-processors/modbus/ReadModbusFunctions.h +++ b/extensions/standard-processors/modbus/ReadModbusFunctions.h @@ -21,7 +21,7 @@ #include #include -#include "core/RecordField.h" +#include "minifi-cpp/core/RecordField.h" #include "fmt/format.h" #include "modbus/ByteConverters.h" #include "modbus/Error.h" diff --git a/extensions/standard-processors/processors/AppendHostInfo.cpp b/extensions/standard-processors/processors/AppendHostInfo.cpp index b2d0b3f291..33d9196865 100644 --- a/extensions/standard-processors/processors/AppendHostInfo.cpp +++ b/extensions/standard-processors/processors/AppendHostInfo.cpp @@ -31,7 +31,7 @@ #include "core/ProcessSession.h" #include "core/FlowFile.h" #include "core/Resource.h" -#include "utils/NetworkInterfaceInfo.h" +#include "utils/net/NetworkInterfaceInfo.h" #include "utils/net/DNS.h" namespace org::apache::nifi::minifi::processors { diff --git a/extensions/standard-processors/processors/AppendHostInfo.h b/extensions/standard-processors/processors/AppendHostInfo.h index f2a91e0c68..008717ace7 100644 --- a/extensions/standard-processors/processors/AppendHostInfo.h +++ b/extensions/standard-processors/processors/AppendHostInfo.h @@ -27,23 +27,22 @@ #include #include "core/Property.h" -#include "FlowFileRecord.h" #include "core/Processor.h" #include "core/ProcessSession.h" #include "core/PropertyDefinitionBuilder.h" #include "core/Core.h" -#include "core/logging/LoggerConfiguration.h" +#include "core/logging/LoggerFactory.h" #include "utils/Export.h" namespace org::apache::nifi::minifi::processors { -class AppendHostInfo : public core::Processor { +class AppendHostInfo : public core::ProcessorImpl { public: static constexpr const char* REFRESH_POLICY_ON_TRIGGER = "On every trigger"; static constexpr const char* REFRESH_POLICY_ON_SCHEDULE = "On schedule"; explicit AppendHostInfo(std::string_view name, const utils::Identifier& uuid = {}) - : core::Processor(name, uuid) { + : core::ProcessorImpl(name, uuid) { } ~AppendHostInfo() override = default; diff --git a/extensions/standard-processors/processors/AttributeRollingWindow.h b/extensions/standard-processors/processors/AttributeRollingWindow.h index a1a74cf264..3a42afb551 100644 --- a/extensions/standard-processors/processors/AttributeRollingWindow.h +++ b/extensions/standard-processors/processors/AttributeRollingWindow.h @@ -30,7 +30,7 @@ #include "core/PropertyType.h" #include "core/RelationshipDefinition.h" #include "RollingWindow.h" -#include "StateManager.h" +#include "core/StateManager.h" namespace org::apache::nifi::minifi::processors { diff --git a/extensions/standard-processors/processors/AttributesToJSON.h b/extensions/standard-processors/processors/AttributesToJSON.h index b7c4568fc0..48cf6d82c4 100644 --- a/extensions/standard-processors/processors/AttributesToJSON.h +++ b/extensions/standard-processors/processors/AttributesToJSON.h @@ -29,7 +29,7 @@ #include "rapidjson/document.h" #include "core/FlowFile.h" -#include "core/logging/LoggerConfiguration.h" +#include "core/logging/LoggerFactory.h" #include "core/Processor.h" #include "core/PropertyDefinition.h" #include "core/PropertyDefinitionBuilder.h" @@ -64,7 +64,7 @@ constexpr customize_t enum_name(WriteDestination value) noexce namespace org::apache::nifi::minifi::processors { -class AttributesToJSON : public core::Processor { +class AttributesToJSON : public core::ProcessorImpl { public: EXTENSIONAPI static constexpr const char* Description = "Generates a JSON representation of the input FlowFile Attributes. " "The resulting JSON can be written to either a new Attribute 'JSONAttributes' or written to the FlowFile as content."; @@ -117,7 +117,7 @@ class AttributesToJSON : public core::Processor { ADD_COMMON_VIRTUAL_FUNCTIONS_FOR_PROCESSORS explicit AttributesToJSON(std::string_view name, const utils::Identifier& uuid = {}) - : core::Processor(name, uuid) { + : core::ProcessorImpl(name, uuid) { } void initialize() override; diff --git a/extensions/standard-processors/processors/DefragmentText.cpp b/extensions/standard-processors/processors/DefragmentText.cpp index 6d262f11c0..a392c79408 100644 --- a/extensions/standard-processors/processors/DefragmentText.cpp +++ b/extensions/standard-processors/processors/DefragmentText.cpp @@ -195,7 +195,7 @@ void DefragmentText::restore(const std::shared_ptr& flowFile) { } std::set DefragmentText::getOutGoingConnections(const std::string &relationship) { - auto result = core::Connectable::getOutGoingConnections(relationship); + auto result = core::ConnectableImpl::getOutGoingConnections(relationship); if (relationship == Self.getName()) { result.insert(this); } diff --git a/extensions/standard-processors/processors/DefragmentText.h b/extensions/standard-processors/processors/DefragmentText.h index 9d75526ed4..5f2da04e0b 100644 --- a/extensions/standard-processors/processors/DefragmentText.h +++ b/extensions/standard-processors/processors/DefragmentText.h @@ -26,7 +26,7 @@ #include "core/Processor.h" #include "core/FlowFileStore.h" #include "core/logging/Logger.h" -#include "core/logging/LoggerConfiguration.h" +#include "core/logging/LoggerFactory.h" #include "core/PropertyDefinition.h" #include "core/PropertyDefinitionBuilder.h" #include "utils/Enum.h" @@ -57,10 +57,10 @@ constexpr customize_t enum_name(PatternLocation value) noexcept namespace org::apache::nifi::minifi::processors { -class DefragmentText : public core::Processor { +class DefragmentText : public core::ProcessorImpl { public: explicit DefragmentText(std::string_view name, const utils::Identifier& uuid = {}) - : Processor(name, uuid) { + : ProcessorImpl(name, uuid) { } EXTENSIONAPI static constexpr const char* Description = "DefragmentText splits and merges incoming flowfiles so cohesive messages are not split between them. " diff --git a/extensions/standard-processors/processors/ExtractText.h b/extensions/standard-processors/processors/ExtractText.h index 8dd5f34e69..574581a3d2 100644 --- a/extensions/standard-processors/processors/ExtractText.h +++ b/extensions/standard-processors/processors/ExtractText.h @@ -31,15 +31,14 @@ #include "core/PropertyDefinition.h" #include "core/PropertyType.h" #include "core/RelationshipDefinition.h" -#include "FlowFileRecord.h" #include "utils/Export.h" namespace org::apache::nifi::minifi::processors { -class ExtractText : public core::Processor { +class ExtractText : public core::ProcessorImpl { public: explicit ExtractText(std::string_view name, const utils::Identifier& uuid = {}) - : Processor(name, uuid) { + : ProcessorImpl(name, uuid) { } // Default maximum bytes to read into an attribute diff --git a/extensions/standard-processors/processors/FetchFile.h b/extensions/standard-processors/processors/FetchFile.h index b6bfbe9c2a..7103a49509 100644 --- a/extensions/standard-processors/processors/FetchFile.h +++ b/extensions/standard-processors/processors/FetchFile.h @@ -26,7 +26,7 @@ #include "core/PropertyDefinitionBuilder.h" #include "core/RelationshipDefinition.h" #include "utils/Enum.h" -#include "core/logging/LoggerConfiguration.h" +#include "core/logging/LoggerFactory.h" #include "utils/LogUtils.h" namespace org::apache::nifi::minifi::processors::fetch_file { @@ -82,10 +82,10 @@ constexpr customize_t enum_name(MoveConflictStrategy namespace org::apache::nifi::minifi::processors { -class FetchFile final : public core::Processor { +class FetchFile final : public core::ProcessorImpl { public: explicit FetchFile(const std::string_view name, const utils::Identifier& uuid = {}) - : core::Processor(name, uuid) { + : core::ProcessorImpl(name, uuid) { } EXTENSIONAPI static constexpr const char* Description = "Reads the contents of a file from disk and streams it into the contents of an incoming FlowFile. " diff --git a/extensions/standard-processors/processors/GenerateFlowFile.h b/extensions/standard-processors/processors/GenerateFlowFile.h index cad866caf6..ef013c8778 100644 --- a/extensions/standard-processors/processors/GenerateFlowFile.h +++ b/extensions/standard-processors/processors/GenerateFlowFile.h @@ -24,7 +24,6 @@ #include #include -#include "FlowFileRecord.h" #include "core/Processor.h" #include "core/ProcessSession.h" #include "core/PropertyDefinition.h" @@ -37,10 +36,10 @@ namespace org::apache::nifi::minifi::processors { -class GenerateFlowFile : public core::Processor { +class GenerateFlowFile : public core::ProcessorImpl { public: explicit GenerateFlowFile(const std::string_view name, const utils::Identifier& uuid = {}) // NOLINT - : Processor(name, uuid) { + : ProcessorImpl(name, uuid) { } ~GenerateFlowFile() override = default; diff --git a/extensions/standard-processors/processors/GetFile.cpp b/extensions/standard-processors/processors/GetFile.cpp index c3f901c35a..cf3a0c9c89 100644 --- a/extensions/standard-processors/processors/GetFile.cpp +++ b/extensions/standard-processors/processors/GetFile.cpp @@ -196,7 +196,8 @@ bool GetFile::fileMatchesRequestCriteria(const std::filesystem::path& full_name, return false; } - auto* const getfile_metrics = static_cast(metrics_.get()); + auto* const getfile_metrics = dynamic_cast(metrics_.get()); + gsl_Assert(getfile_metrics); getfile_metrics->input_bytes += file_size; ++getfile_metrics->accepted_files; return true; diff --git a/extensions/standard-processors/processors/GetFile.h b/extensions/standard-processors/processors/GetFile.h index 6cd55d2f34..306fd514a7 100644 --- a/extensions/standard-processors/processors/GetFile.h +++ b/extensions/standard-processors/processors/GetFile.h @@ -24,8 +24,6 @@ #include #include -#include "core/state/nodes/MetricsBase.h" -#include "FlowFileRecord.h" #include "core/Processor.h" #include "core/ProcessSession.h" #include "core/PropertyDefinition.h" @@ -33,8 +31,9 @@ #include "core/PropertyType.h" #include "core/RelationshipDefinition.h" #include "core/Core.h" -#include "core/logging/LoggerConfiguration.h" +#include "core/logging/LoggerFactory.h" #include "utils/Export.h" +#include "core/ProcessorMetrics.h" namespace org::apache::nifi::minifi::processors { @@ -52,14 +51,14 @@ struct GetFileRequest { std::filesystem::path inputDirectory; }; -class GetFileMetrics : public core::ProcessorMetrics { +class GetFileMetrics : public core::ProcessorMetricsImpl { public: explicit GetFileMetrics(const core::Processor& source_processor) - : core::ProcessorMetrics(source_processor) { + : core::ProcessorMetricsImpl(source_processor) { } std::vector serialize() override { - auto resp = core::ProcessorMetrics::serialize(); + auto resp = core::ProcessorMetricsImpl::serialize(); auto& root_node = resp[0]; state::response::SerializedResponseNode accepted_files_node{"AcceptedFiles", accepted_files.load()}; @@ -72,7 +71,7 @@ class GetFileMetrics : public core::ProcessorMetrics { } std::vector calculateMetrics() override { - auto metrics = core::ProcessorMetrics::calculateMetrics(); + auto metrics = core::ProcessorMetricsImpl::calculateMetrics(); metrics.push_back({"accepted_files", static_cast(accepted_files.load()), getCommonLabels()}); metrics.push_back({"input_bytes", static_cast(input_bytes.load()), getCommonLabels()}); return metrics; @@ -82,10 +81,11 @@ class GetFileMetrics : public core::ProcessorMetrics { std::atomic input_bytes{0}; }; -class GetFile : public core::Processor { +class GetFile : public core::ProcessorImpl { public: explicit GetFile(std::string_view name, const utils::Identifier& uuid = {}) - : Processor(name, uuid, std::make_shared(*this)) { + : ProcessorImpl(name, uuid) { + metrics_ = gsl::make_not_null(std::make_shared(*this)); } ~GetFile() override = default; diff --git a/extensions/standard-processors/processors/GetTCP.cpp b/extensions/standard-processors/processors/GetTCP.cpp index db4e8e175e..19cd60d345 100644 --- a/extensions/standard-processors/processors/GetTCP.cpp +++ b/extensions/standard-processors/processors/GetTCP.cpp @@ -28,7 +28,6 @@ #include "utils/StringUtils.h" #include "core/ProcessContext.h" #include "core/ProcessSession.h" -#include "core/ProcessSessionFactory.h" #include "core/Resource.h" using namespace std::literals::chrono_literals; diff --git a/extensions/standard-processors/processors/GetTCP.h b/extensions/standard-processors/processors/GetTCP.h index d2782a8927..d17a24274a 100644 --- a/extensions/standard-processors/processors/GetTCP.h +++ b/extensions/standard-processors/processors/GetTCP.h @@ -26,9 +26,7 @@ #include #include "utils/Literals.h" -#include "../core/state/nodes/MetricsBase.h" -#include "FlowFileRecord.h" -#include "core/OutputAttributeDefinition.h" +#include "minifi-cpp/core/OutputAttributeDefinition.h" #include "core/Processor.h" #include "core/ProcessSession.h" #include "core/PropertyDefinition.h" @@ -37,7 +35,7 @@ #include "core/Core.h" #include "concurrentqueue.h" #include "utils/ThreadPool.h" -#include "core/logging/LoggerConfiguration.h" +#include "core/logging/LoggerFactory.h" #include "controllers/SSLContextService.h" #include "utils/gsl.h" #include "utils/Export.h" @@ -46,10 +44,10 @@ namespace org::apache::nifi::minifi::processors { -class GetTCP : public core::Processor { +class GetTCP : public core::ProcessorImpl { public: explicit GetTCP(std::string_view name, const utils::Identifier& uuid = {}) - : Processor(name, uuid) { + : ProcessorImpl(name, uuid) { } ~GetTCP() override { diff --git a/extensions/standard-processors/processors/HashContent.h b/extensions/standard-processors/processors/HashContent.h index efc850ee48..865f84e0f3 100644 --- a/extensions/standard-processors/processors/HashContent.h +++ b/extensions/standard-processors/processors/HashContent.h @@ -32,7 +32,6 @@ #include #include -#include "FlowFileRecord.h" #include "core/Processor.h" #include "core/PropertyDefinition.h" #include "core/PropertyDefinitionBuilder.h" @@ -135,10 +134,10 @@ namespace org::apache::nifi::minifi::processors { static const std::map&)>> HashAlgos = { {"MD5", MD5Hash}, {"SHA1", SHA1Hash}, {"SHA256", SHA256Hash} }; -class HashContent : public core::Processor { +class HashContent : public core::ProcessorImpl { public: explicit HashContent(std::string_view name, const utils::Identifier& uuid = {}) - : Processor(name, uuid) { + : ProcessorImpl(name, uuid) { } EXTENSIONAPI static constexpr const char* Description = "HashContent calculates the checksum of the content of the flowfile and adds it as an attribute. " diff --git a/extensions/standard-processors/processors/InvokeHTTP.h b/extensions/standard-processors/processors/InvokeHTTP.h index bb5e9d2837..150ded6d31 100644 --- a/extensions/standard-processors/processors/InvokeHTTP.h +++ b/extensions/standard-processors/processors/InvokeHTTP.h @@ -24,19 +24,18 @@ #include #include -#include "Core.h" -#include "FlowFileRecord.h" +#include "core/Core.h" #include "core/OutputAttributeDefinition.h" #include "core/Processor.h" #include "core/ProcessSession.h" #include "core/PropertyDefinitionBuilder.h" -#include "PropertyType.h" +#include "core/PropertyType.h" #include "core/RelationshipDefinition.h" #include "controllers/SSLContextService.h" -#include "core/logging/LoggerConfiguration.h" +#include "core/logging/LoggerFactory.h" #include "utils/Id.h" #include "utils/ResourceQueue.h" -#include "../http/HTTPClient.h" +#include "http/HTTPClient.h" #include "utils/Export.h" #include "utils/Enum.h" #include "utils/RegexUtils.h" @@ -51,7 +50,7 @@ enum class InvalidHTTPHeaderFieldHandlingOption { }; } // namespace invoke_http -class InvokeHTTP : public core::Processor { +class InvokeHTTP : public core::ProcessorImpl { public: EXTENSIONAPI static constexpr std::string_view STATUS_CODE = "invokehttp.status.code"; EXTENSIONAPI static constexpr std::string_view STATUS_MESSAGE = "invokehttp.status.message"; @@ -59,7 +58,7 @@ class InvokeHTTP : public core::Processor { EXTENSIONAPI static constexpr std::string_view TRANSACTION_ID = "invokehttp.tx.id"; explicit InvokeHTTP(std::string_view name, const utils::Identifier& uuid = {}) - : Processor(name, uuid) { + : ProcessorImpl(name, uuid) { setTriggerWhenEmpty(true); } diff --git a/extensions/standard-processors/processors/JoltTransformJSON.h b/extensions/standard-processors/processors/JoltTransformJSON.h index db0c8f21d8..dc8619da40 100644 --- a/extensions/standard-processors/processors/JoltTransformJSON.h +++ b/extensions/standard-processors/processors/JoltTransformJSON.h @@ -35,10 +35,10 @@ enum class JoltTransform { namespace org::apache::nifi::minifi::processors { -class JoltTransformJSON : public core::Processor { +class JoltTransformJSON : public core::ProcessorImpl { public: explicit JoltTransformJSON(std::string_view name, const utils::Identifier& uuid = {}) - : Processor(name, uuid) {} + : ProcessorImpl(name, uuid) {} EXTENSIONAPI static constexpr const char* Description = "Applies a list of Jolt specifications to the flowfile JSON payload. A new FlowFile is created " diff --git a/extensions/standard-processors/processors/ListFile.h b/extensions/standard-processors/processors/ListFile.h index 3650064190..da8642166b 100644 --- a/extensions/standard-processors/processors/ListFile.h +++ b/extensions/standard-processors/processors/ListFile.h @@ -28,7 +28,7 @@ #include "core/PropertyDefinition.h" #include "core/PropertyDefinitionBuilder.h" #include "core/PropertyType.h" -#include "core/logging/LoggerConfiguration.h" +#include "core/logging/LoggerFactory.h" #include "utils/Enum.h" #include "utils/ListingStateManager.h" #include "utils/file/ListedFile.h" @@ -36,10 +36,10 @@ namespace org::apache::nifi::minifi::processors { -class ListFile : public core::Processor { +class ListFile : public core::ProcessorImpl { public: explicit ListFile(std::string_view name, const utils::Identifier& uuid = {}) - : core::Processor(name, uuid) { + : core::ProcessorImpl(name, uuid) { } EXTENSIONAPI static constexpr const char* Description = "Retrieves a listing of files from the local filesystem. For each file that is listed, " diff --git a/extensions/standard-processors/processors/ListenSyslog.h b/extensions/standard-processors/processors/ListenSyslog.h index 14ee92723f..911911dbe0 100644 --- a/extensions/standard-processors/processors/ListenSyslog.h +++ b/extensions/standard-processors/processors/ListenSyslog.h @@ -23,8 +23,9 @@ #include #include +#include "controllers/SSLContextService.h" #include "NetworkListenerProcessor.h" -#include "core/logging/LoggerConfiguration.h" +#include "core/logging/LoggerFactory.h" #include "core/OutputAttributeDefinition.h" #include "core/PropertyDefinition.h" #include "core/PropertyDefinitionBuilder.h" diff --git a/extensions/standard-processors/processors/ListenTCP.h b/extensions/standard-processors/processors/ListenTCP.h index d8c4b1e5f7..3d3187d1cb 100644 --- a/extensions/standard-processors/processors/ListenTCP.h +++ b/extensions/standard-processors/processors/ListenTCP.h @@ -20,9 +20,10 @@ #include #include +#include "controllers/SSLContextService.h" #include "NetworkListenerProcessor.h" #include "core/Core.h" -#include "core/logging/LoggerConfiguration.h" +#include "core/logging/LoggerFactory.h" #include "core/OutputAttributeDefinition.h" #include "core/PropertyDefinition.h" #include "core/PropertyDefinitionBuilder.h" diff --git a/extensions/standard-processors/processors/ListenUDP.h b/extensions/standard-processors/processors/ListenUDP.h index 804d7a6e98..b78484fbec 100644 --- a/extensions/standard-processors/processors/ListenUDP.h +++ b/extensions/standard-processors/processors/ListenUDP.h @@ -20,8 +20,8 @@ #include #include "NetworkListenerProcessor.h" -#include "OutputAttributeDefinition.h" -#include "core/logging/LoggerConfiguration.h" +#include "core/OutputAttributeDefinition.h" +#include "core/logging/LoggerFactory.h" #include "core/PropertyDefinition.h" #include "core/PropertyDefinitionBuilder.h" #include "core/PropertyType.h" diff --git a/extensions/standard-processors/processors/LogAttribute.h b/extensions/standard-processors/processors/LogAttribute.h index e1a6efe15f..2cb4ba62d6 100644 --- a/extensions/standard-processors/processors/LogAttribute.h +++ b/extensions/standard-processors/processors/LogAttribute.h @@ -24,7 +24,6 @@ #include #include -#include "FlowFileRecord.h" #include "core/Core.h" #include "core/Processor.h" #include "core/ProcessSession.h" @@ -32,15 +31,15 @@ #include "core/PropertyDefinitionBuilder.h" #include "core/PropertyType.h" #include "core/RelationshipDefinition.h" -#include "core/logging/LoggerConfiguration.h" +#include "core/logging/LoggerFactory.h" #include "utils/Export.h" namespace org::apache::nifi::minifi::processors { -class LogAttribute : public core::Processor { +class LogAttribute : public core::ProcessorImpl { public: explicit LogAttribute(const std::string_view name, const utils::Identifier& uuid = {}) - : Processor(name, uuid) { + : ProcessorImpl(name, uuid) { logger_->set_max_log_size(-1); } ~LogAttribute() override = default; diff --git a/extensions/standard-processors/processors/NetworkListenerProcessor.h b/extensions/standard-processors/processors/NetworkListenerProcessor.h index 4f15637faf..7058d1b2d6 100644 --- a/extensions/standard-processors/processors/NetworkListenerProcessor.h +++ b/extensions/standard-processors/processors/NetworkListenerProcessor.h @@ -29,10 +29,10 @@ namespace org::apache::nifi::minifi::processors { -class NetworkListenerProcessor : public core::Processor { +class NetworkListenerProcessor : public core::ProcessorImpl { public: NetworkListenerProcessor(std::string_view name, const utils::Identifier& uuid, std::shared_ptr logger) - : core::Processor(name, uuid), + : core::ProcessorImpl(name, uuid), logger_(std::move(logger)) { } ~NetworkListenerProcessor() override; diff --git a/extensions/standard-processors/processors/PutFile.h b/extensions/standard-processors/processors/PutFile.h index d969d1d478..227ac5582a 100644 --- a/extensions/standard-processors/processors/PutFile.h +++ b/extensions/standard-processors/processors/PutFile.h @@ -20,7 +20,6 @@ #include #include -#include "FlowFileRecord.h" #include "core/Processor.h" #include "core/ProcessSession.h" #include "core/PropertyDefinition.h" @@ -28,17 +27,17 @@ #include "core/PropertyType.h" #include "core/RelationshipDefinition.h" #include "core/Core.h" -#include "core/logging/LoggerConfiguration.h" +#include "core/logging/LoggerFactory.h" #include "utils/Id.h" #include "utils/Export.h" #include "utils/Enum.h" namespace org::apache::nifi::minifi::processors { -class PutFile : public core::Processor { +class PutFile : public core::ProcessorImpl { public: explicit PutFile(std::string_view name, const utils::Identifier& uuid = {}) - : core::Processor(name, uuid) { + : core::ProcessorImpl(name, uuid) { } ~PutFile() override = default; diff --git a/extensions/standard-processors/processors/PutTCP.cpp b/extensions/standard-processors/processors/PutTCP.cpp index 54b3d2550e..d5756bfcc1 100644 --- a/extensions/standard-processors/processors/PutTCP.cpp +++ b/extensions/standard-processors/processors/PutTCP.cpp @@ -38,7 +38,7 @@ namespace org::apache::nifi::minifi::processors { constexpr size_t chunk_size = 1024; PutTCP::PutTCP(const std::string& name, const utils::Identifier& uuid) - : Processor(name, uuid) {} + : ProcessorImpl(name, uuid) {} PutTCP::~PutTCP() = default; diff --git a/extensions/standard-processors/processors/PutTCP.h b/extensions/standard-processors/processors/PutTCP.h index 263653c0e2..6ea2ecfe21 100644 --- a/extensions/standard-processors/processors/PutTCP.h +++ b/extensions/standard-processors/processors/PutTCP.h @@ -25,7 +25,7 @@ #include #include "io/InputStream.h" -#include "Processor.h" +#include "core/Processor.h" #include "utils/Export.h" #include "controllers/SSLContextService.h" #include "core/Core.h" @@ -43,7 +43,7 @@ namespace org::apache::nifi::minifi::processors { -class PutTCP final : public core::Processor { +class PutTCP final : public core::ProcessorImpl { public: EXTENSIONAPI static constexpr const char* Description = "The PutTCP processor receives a FlowFile and transmits the FlowFile content over a TCP connection to the configured TCP server. " diff --git a/extensions/standard-processors/processors/PutUDP.cpp b/extensions/standard-processors/processors/PutUDP.cpp index e3e5f46d29..242e100e94 100644 --- a/extensions/standard-processors/processors/PutUDP.cpp +++ b/extensions/standard-processors/processors/PutUDP.cpp @@ -23,7 +23,7 @@ #include "core/ProcessContext.h" #include "core/ProcessSession.h" #include "core/Resource.h" -#include "core/logging/LoggerConfiguration.h" +#include "core/logging/LoggerFactory.h" #include "asio/ip/udp.hpp" #include "utils/net/AsioSocketUtils.h" @@ -33,7 +33,7 @@ using asio::ip::udp; namespace org::apache::nifi::minifi::processors { PutUDP::PutUDP(std::string_view name, const utils::Identifier& uuid) - : Processor(name, uuid), logger_{core::logging::LoggerFactory::getLogger(uuid)} + : ProcessorImpl(name, uuid), logger_{core::logging::LoggerFactory::getLogger(uuid)} { } PutUDP::~PutUDP() = default; diff --git a/extensions/standard-processors/processors/PutUDP.h b/extensions/standard-processors/processors/PutUDP.h index a2567e3e1b..e4c072f61b 100644 --- a/extensions/standard-processors/processors/PutUDP.h +++ b/extensions/standard-processors/processors/PutUDP.h @@ -21,7 +21,7 @@ #include #include -#include "Processor.h" +#include "core/Processor.h" #include "core/PropertyDefinition.h" #include "core/PropertyDefinitionBuilder.h" #include "core/RelationshipDefinition.h" @@ -30,7 +30,7 @@ namespace org::apache::nifi::minifi::core::logging { class Logger; } namespace org::apache::nifi::minifi::processors { -class PutUDP final : public core::Processor { +class PutUDP final : public core::ProcessorImpl { public: EXTENSIONAPI static constexpr const char* Description = "The PutUDP processor receives a FlowFile and packages the FlowFile content into a single UDP datagram packet " "which is then transmitted to the configured UDP server. " diff --git a/extensions/standard-processors/processors/ReplaceText.cpp b/extensions/standard-processors/processors/ReplaceText.cpp index 3a903879bd..27d751fcc0 100644 --- a/extensions/standard-processors/processors/ReplaceText.cpp +++ b/extensions/standard-processors/processors/ReplaceText.cpp @@ -22,14 +22,14 @@ #include "core/Resource.h" #include "core/TypedValues.h" -#include "core/logging/LoggerConfiguration.h" +#include "core/logging/LoggerFactory.h" #include "utils/LineByLineInputOutputStreamCallback.h" #include "utils/ProcessorConfigUtils.h" namespace org::apache::nifi::minifi::processors { ReplaceText::ReplaceText(std::string_view name, const utils::Identifier& uuid) - : core::Processor(name, uuid), + : core::ProcessorImpl(name, uuid), logger_(core::logging::LoggerFactory::getLogger(uuid)) { } diff --git a/extensions/standard-processors/processors/ReplaceText.h b/extensions/standard-processors/processors/ReplaceText.h index dd34c2a0ca..2e2258c321 100644 --- a/extensions/standard-processors/processors/ReplaceText.h +++ b/extensions/standard-processors/processors/ReplaceText.h @@ -25,7 +25,6 @@ #include "core/Processor.h" #include "core/ProcessContext.h" #include "core/ProcessSession.h" -#include "core/ProcessSessionFactory.h" #include "core/PropertyDefinition.h" #include "core/PropertyDefinitionBuilder.h" #include "core/RelationshipDefinition.h" @@ -114,7 +113,7 @@ constexpr customize_t enum_name(ReplacementStrategyType namespace org::apache::nifi::minifi::processors { -class ReplaceText : public core::Processor { +class ReplaceText : public core::ProcessorImpl { public: EXTENSIONAPI static constexpr const char* Description = "Updates the content of a FlowFile by replacing parts of it using various replacement strategies."; diff --git a/extensions/standard-processors/processors/RetryFlowFile.h b/extensions/standard-processors/processors/RetryFlowFile.h index 36c8fb2f66..58651acd92 100644 --- a/extensions/standard-processors/processors/RetryFlowFile.h +++ b/extensions/standard-processors/processors/RetryFlowFile.h @@ -25,8 +25,6 @@ #include #include -#include "core/state/nodes/MetricsBase.h" -#include "FlowFileRecord.h" #include "core/Core.h" #include "core/OutputAttributeDefinition.h" #include "core/Processor.h" @@ -35,16 +33,16 @@ #include "core/PropertyDefinitionBuilder.h" #include "core/PropertyType.h" #include "core/RelationshipDefinition.h" -#include "core/logging/LoggerConfiguration.h" +#include "core/logging/LoggerFactory.h" #include "utils/OptionalUtils.h" #include "utils/Export.h" namespace org::apache::nifi::minifi::processors { -class RetryFlowFile : public core::Processor { +class RetryFlowFile : public core::ProcessorImpl { public: explicit RetryFlowFile(std::string_view name, const utils::Identifier& uuid = {}) - : Processor(name, uuid) {} + : ProcessorImpl(name, uuid) {} ~RetryFlowFile() override = default; // ReuseMode allowed values diff --git a/extensions/standard-processors/processors/RouteOnAttribute.h b/extensions/standard-processors/processors/RouteOnAttribute.h index 451e55dbd5..4ca46da794 100644 --- a/extensions/standard-processors/processors/RouteOnAttribute.h +++ b/extensions/standard-processors/processors/RouteOnAttribute.h @@ -24,19 +24,18 @@ #include #include -#include "FlowFileRecord.h" #include "core/Processor.h" #include "core/ProcessSession.h" #include "core/RelationshipDefinition.h" #include "core/Core.h" -#include "core/logging/LoggerConfiguration.h" +#include "core/logging/LoggerFactory.h" namespace org::apache::nifi::minifi::processors { -class RouteOnAttribute : public core::Processor { +class RouteOnAttribute : public core::ProcessorImpl { public: explicit RouteOnAttribute(std::string_view name, const utils::Identifier& uuid = {}) - : core::Processor(name, uuid) { + : core::ProcessorImpl(name, uuid) { } EXTENSIONAPI static constexpr const char* Description = "Routes FlowFiles based on their Attributes using the Attribute Expression Language.\n\n" diff --git a/extensions/standard-processors/processors/RouteText.cpp b/extensions/standard-processors/processors/RouteText.cpp index 68cf537090..704b63dd35 100644 --- a/extensions/standard-processors/processors/RouteText.cpp +++ b/extensions/standard-processors/processors/RouteText.cpp @@ -25,7 +25,7 @@ #include "core/ProcessSession.h" #include "core/Resource.h" #include "io/StreamPipe.h" -#include "logging/LoggerConfiguration.h" +#include "core/logging/LoggerFactory.h" #include "range/v3/view/transform.hpp" #include "range/v3/range/conversion.hpp" #include "range/v3/view/tail.hpp" @@ -37,7 +37,7 @@ namespace org::apache::nifi::minifi::processors { RouteText::RouteText(std::string_view name, const utils::Identifier& uuid) - : core::Processor(name, uuid), logger_(core::logging::LoggerFactory::getLogger(uuid)) {} + : core::ProcessorImpl(name, uuid), logger_(core::logging::LoggerFactory::getLogger(uuid)) {} void RouteText::initialize() { setSupportedProperties(Properties); diff --git a/extensions/standard-processors/processors/RouteText.h b/extensions/standard-processors/processors/RouteText.h index 4d195e0225..4c496d76ac 100644 --- a/extensions/standard-processors/processors/RouteText.h +++ b/extensions/standard-processors/processors/RouteText.h @@ -114,7 +114,7 @@ constexpr customize_t enum_name(Segmentation value) noexcept { namespace org::apache::nifi::minifi::processors { -class RouteText : public core::Processor { +class RouteText : public core::ProcessorImpl { public: EXTENSIONAPI static constexpr const char* Description = "Routes textual data based on a set of user-defined rules. Each segment in an incoming FlowFile is " "compared against the values specified by user-defined Properties. The mechanism by which the text is compared " diff --git a/extensions/standard-processors/processors/SegmentContent.h b/extensions/standard-processors/processors/SegmentContent.h index b0a87b037d..321bf29f38 100644 --- a/extensions/standard-processors/processors/SegmentContent.h +++ b/extensions/standard-processors/processors/SegmentContent.h @@ -32,9 +32,9 @@ namespace org::apache::nifi::minifi::processors { -class SegmentContent final : public core::Processor { +class SegmentContent final : public core::ProcessorImpl { public: - explicit SegmentContent(const std::string_view name, const utils::Identifier& uuid = {}) : Processor(name, uuid) {} + explicit SegmentContent(const std::string_view name, const utils::Identifier& uuid = {}) : ProcessorImpl(name, uuid) {} EXTENSIONAPI static constexpr auto Description = "Segments a FlowFile into multiple smaller segments on byte boundaries."; diff --git a/extensions/standard-processors/processors/SplitContent.h b/extensions/standard-processors/processors/SplitContent.h index 9c77fcfae5..70789a24cf 100644 --- a/extensions/standard-processors/processors/SplitContent.h +++ b/extensions/standard-processors/processors/SplitContent.h @@ -32,9 +32,9 @@ namespace org::apache::nifi::minifi::processors { -class SplitContent final : public core::Processor { +class SplitContent final : public core::ProcessorImpl { public: - explicit SplitContent(const std::string_view name, const utils::Identifier& uuid = {}) : Processor(name, uuid) {} + explicit SplitContent(const std::string_view name, const utils::Identifier& uuid = {}) : ProcessorImpl(name, uuid) {} using size_type = std::vector::size_type; enum class ByteSequenceFormat { Hexadecimal, Text }; diff --git a/extensions/standard-processors/processors/SplitRecord.h b/extensions/standard-processors/processors/SplitRecord.h index ab45b999d0..27bdd7c93c 100644 --- a/extensions/standard-processors/processors/SplitRecord.h +++ b/extensions/standard-processors/processors/SplitRecord.h @@ -19,7 +19,7 @@ #include "core/Annotation.h" #include "core/ProcessContext.h" #include "core/ProcessSession.h" -#include "core/ProcessSessionFactory.h" +#include "minifi-cpp/core/ProcessSessionFactory.h" #include "core/PropertyDefinition.h" #include "core/PropertyDefinitionBuilder.h" #include "core/RelationshipDefinition.h" diff --git a/extensions/standard-processors/processors/SplitText.cpp b/extensions/standard-processors/processors/SplitText.cpp index bbdf6e0be1..e72001d80e 100644 --- a/extensions/standard-processors/processors/SplitText.cpp +++ b/extensions/standard-processors/processors/SplitText.cpp @@ -26,6 +26,7 @@ #include "core/FlowFile.h" #include "utils/gsl.h" #include "utils/ProcessorConfigUtils.h" +#include "io/StreamPipe.h" namespace org::apache::nifi::minifi::processors { diff --git a/extensions/standard-processors/processors/SplitText.h b/extensions/standard-processors/processors/SplitText.h index 528c0de523..0d40a6e9c1 100644 --- a/extensions/standard-processors/processors/SplitText.h +++ b/extensions/standard-processors/processors/SplitText.h @@ -30,7 +30,6 @@ #include "core/PropertyDefinition.h" #include "core/PropertyType.h" #include "core/RelationshipDefinition.h" -#include "FlowFileRecord.h" #include "utils/Export.h" #include "utils/expected.h" @@ -87,10 +86,10 @@ class LineReader { } // namespace detail -class SplitText : public core::Processor { +class SplitText : public core::ProcessorImpl { public: explicit SplitText(std::string_view name, const utils::Identifier& uuid = {}) - : Processor(name, uuid) { + : ProcessorImpl(name, uuid) { } EXTENSIONAPI static constexpr const char* Description = "Splits a text file into multiple smaller text files on line boundaries limited by maximum number of lines or total size of fragment. " diff --git a/extensions/standard-processors/processors/TailFile.cpp b/extensions/standard-processors/processors/TailFile.cpp index bd672d9b36..b2e69d5e42 100644 --- a/extensions/standard-processors/processors/TailFile.cpp +++ b/extensions/standard-processors/processors/TailFile.cpp @@ -30,7 +30,6 @@ #include "range/v3/action/sort.hpp" -#include "FlowFileRecord.h" #include "io/CRCStream.h" #include "utils/file/FileUtils.h" #include "utils/file/PathUtils.h" @@ -804,7 +803,7 @@ void TailFile::checkForNewFiles(core::ProcessContext& context) { } std::string TailFile::baseDirectoryFromAttributes(const controllers::AttributeProviderService::AttributeMap& attribute_map, core::ProcessContext& context) { - auto flow_file = std::make_shared(); + auto flow_file = core::FlowFile::create(); for (const auto& [key, value] : attribute_map) { flow_file->setAttribute(key, value); } diff --git a/extensions/standard-processors/processors/TailFile.h b/extensions/standard-processors/processors/TailFile.h index dc1d76d41e..9069c2f13d 100644 --- a/extensions/standard-processors/processors/TailFile.h +++ b/extensions/standard-processors/processors/TailFile.h @@ -28,7 +28,6 @@ #include #include "controllers/AttributeProviderService.h" -#include "FlowFileRecord.h" #include "core/Core.h" #include "core/Processor.h" #include "core/ProcessSession.h" @@ -36,7 +35,7 @@ #include "core/PropertyDefinitionBuilder.h" #include "core/PropertyType.h" #include "core/RelationshipDefinition.h" -#include "core/logging/LoggerConfiguration.h" +#include "core/logging/LoggerFactory.h" #include "utils/Enum.h" #include "utils/Export.h" #include "utils/RegexUtils.h" @@ -103,10 +102,10 @@ enum class Mode { SINGLE, MULTIPLE, UNDEFINED }; -class TailFile : public core::Processor { +class TailFile : public core::ProcessorImpl { public: explicit TailFile(std::string_view name, const utils::Identifier& uuid = {}) - : core::Processor(name, uuid) { + : core::ProcessorImpl(name, uuid) { } ~TailFile() override = default; diff --git a/extensions/standard-processors/processors/UpdateAttribute.h b/extensions/standard-processors/processors/UpdateAttribute.h index ce80b9733d..7f4407ca51 100644 --- a/extensions/standard-processors/processors/UpdateAttribute.h +++ b/extensions/standard-processors/processors/UpdateAttribute.h @@ -24,20 +24,19 @@ #include #include -#include "FlowFileRecord.h" #include "core/Processor.h" #include "core/ProcessSession.h" #include "core/PropertyDefinition.h" #include "core/RelationshipDefinition.h" #include "core/Core.h" -#include "core/logging/LoggerConfiguration.h" +#include "core/logging/LoggerFactory.h" namespace org::apache::nifi::minifi::processors { -class UpdateAttribute : public core::Processor { +class UpdateAttribute : public core::ProcessorImpl { public: UpdateAttribute(std::string_view name, const utils::Identifier& uuid = {}) // NOLINT - : core::Processor(name, uuid) { + : core::ProcessorImpl(name, uuid) { } EXTENSIONAPI static constexpr const char* Description = "This processor updates the attributes of a FlowFile using properties that are added by the user. " diff --git a/extensions/standard-processors/tests/integration/VerifyInvokeHTTP.h b/extensions/standard-processors/tests/integration/VerifyInvokeHTTP.h index 0419c96278..3f624ab12a 100644 --- a/extensions/standard-processors/tests/integration/VerifyInvokeHTTP.h +++ b/extensions/standard-processors/tests/integration/VerifyInvokeHTTP.h @@ -17,7 +17,6 @@ */ #pragma once -#include "PropertyDefinition.h" #include #include @@ -29,6 +28,7 @@ #include "processors/LogAttribute.h" #include "controllers/SSLContextService.h" #include "core/state/ProcessorController.h" +#include "core/PropertyDefinition.h" #include "integration/HTTPIntegrationBase.h" #include "unit/Catch.h" #include "unit/ProvenanceTestHelper.h" @@ -75,7 +75,7 @@ class VerifyInvokeHTTP : public HTTPIntegrationBase { const auto processorController = dynamic_cast(&component); assert(processorController); auto& proc = processorController->getProcessor(); - proc.setProperty(property, value); + proc.setProperty(property, std::string_view{value}); executed = true; }); diff --git a/extensions/standard-processors/tests/unit/ConfigurationTests.cpp b/extensions/standard-processors/tests/unit/ConfigurationTests.cpp index 7b44c048f6..bc4db378a8 100644 --- a/extensions/standard-processors/tests/unit/ConfigurationTests.cpp +++ b/extensions/standard-processors/tests/unit/ConfigurationTests.cpp @@ -19,7 +19,7 @@ #include "unit/Catch.h" #include "properties/Configuration.h" -#include "Environment.h" +#include "utils/Environment.h" namespace org::apache::nifi::minifi::test { @@ -65,7 +65,7 @@ TEST_CASE("Configuration can fix misconfigured timeperiod<->integer validated pr << "nifi.c2.agent.heartbeat.period=1min\n" << "nifi.administrative.yield.duration=30000\n"; auto properties_file_time_after_creation = std::filesystem::last_write_time(properties_path); - const std::shared_ptr configure = std::make_shared(); + const std::shared_ptr configure = std::make_shared(); configure->loadConfigureFile(properties_path); CHECK(configure->get("nifi.c2.agent.heartbeat.period") == "60000"); @@ -109,7 +109,7 @@ TEST_CASE("Configuration can fix misconfigured datasize<->integer validated prop properties_file.close(); } auto properties_file_time_after_creation = std::filesystem::last_write_time(properties_path); - const std::shared_ptr configure = std::make_shared(); + const std::shared_ptr configure = std::make_shared(); configure->loadConfigureFile(properties_path, "nifi.log."); CHECK(configure->get("appender.rolling.max_file_size") == "6000 B"); @@ -146,7 +146,7 @@ TEST_CASE("Configuration can fix misconfigured validated properties within envir << "compression.cached.log.max.size=${SOME_VARIABLE}\n" << "compression.compressed.log.max.size=3000\n"; auto properties_file_time_after_creation = std::filesystem::last_write_time(properties_path); - const std::shared_ptr configure = std::make_shared(); + const std::shared_ptr configure = std::make_shared(); configure->loadConfigureFile(properties_path, "nifi.log."); CHECK(configure->get("compression.cached.log.max.size") == "4000 B"); diff --git a/extensions/standard-processors/tests/unit/ControllerServiceTests.cpp b/extensions/standard-processors/tests/unit/ControllerServiceTests.cpp index bd14bc144e..d1bb4cf7db 100644 --- a/extensions/standard-processors/tests/unit/ControllerServiceTests.cpp +++ b/extensions/standard-processors/tests/unit/ControllerServiceTests.cpp @@ -39,7 +39,7 @@ TEST_CASE("Test ControllerServicesMap", "[cs1]") { REQUIRE(map.getAllControllerServices().empty()); std::shared_ptr service = std::make_shared(); - std::shared_ptr testNode = std::make_shared(service, "ID", std::make_shared()); + auto testNode = std::make_shared(service, "ID", std::make_shared()); map.put("ID", testNode); REQUIRE(1 == map.getAllControllerServices().size()); @@ -58,7 +58,7 @@ TEST_CASE("Test StandardControllerServiceNode nullPtr", "[cs1]") { core::controller::ControllerServiceNodeMap map; try { - std::shared_ptr testNode = std::make_shared(nullptr, "ID", std::make_shared()); + auto testNode = std::make_shared(nullptr, "ID", std::make_shared()); } catch (const minifi::Exception &) { return; } @@ -68,7 +68,7 @@ TEST_CASE("Test StandardControllerServiceNode nullPtr", "[cs1]") { std::shared_ptr newCsNode(const std::string& id) { std::shared_ptr service = std::make_shared(); - std::shared_ptr testNode = std::make_shared(service, id, std::make_shared()); + auto testNode = std::make_shared(service, id, std::make_shared()); return testNode; } diff --git a/extensions/standard-processors/tests/unit/DefragmentTextTests.cpp b/extensions/standard-processors/tests/unit/DefragmentTextTests.cpp index 86164f4831..1eaa4ad307 100644 --- a/extensions/standard-processors/tests/unit/DefragmentTextTests.cpp +++ b/extensions/standard-processors/tests/unit/DefragmentTextTests.cpp @@ -311,7 +311,7 @@ TEST_CASE("DefragmentTextMultipleSources", "[defragmenttextinvalidsources]") { } } -class FragmentGenerator : public core::Processor { +class FragmentGenerator : public core::ProcessorImpl { public: static constexpr const char* Description = "FragmentGenerator (only for testing purposes)"; static constexpr auto Properties = std::array{}; @@ -324,7 +324,7 @@ class FragmentGenerator : public core::Processor { ADD_COMMON_VIRTUAL_FUNCTIONS_FOR_PROCESSORS explicit FragmentGenerator(std::string_view name, const utils::Identifier& uuid = utils::Identifier()) - : Processor(name, uuid) { + : ProcessorImpl(name, uuid) { } void onTrigger(core::ProcessContext&, core::ProcessSession& session) override { diff --git a/extensions/standard-processors/tests/unit/FlowJsonTests.cpp b/extensions/standard-processors/tests/unit/FlowJsonTests.cpp index 4eb54198a5..14084be803 100644 --- a/extensions/standard-processors/tests/unit/FlowJsonTests.cpp +++ b/extensions/standard-processors/tests/unit/FlowJsonTests.cpp @@ -333,9 +333,9 @@ TEST_CASE("Cannot use the same parameter name within a parameter context twice") REQUIRE_THROWS_WITH(config.getRootFromPayload(CONFIG_JSON), "Parameter Operation: Parameter name 'file_size' already exists, parameter names must be unique within a parameter context!"); } -class DummyFlowJsonProcessor : public core::Processor { +class DummyFlowJsonProcessor : public core::ProcessorImpl { public: - using core::Processor::Processor; + using core::ProcessorImpl::ProcessorImpl; static constexpr const char* Description = "A processor that does nothing."; static constexpr auto SimpleProperty = core::PropertyDefinitionBuilder<>::createProperty("Simple Property") diff --git a/extensions/standard-processors/tests/unit/GetTCPTests.cpp b/extensions/standard-processors/tests/unit/GetTCPTests.cpp index 9fb79d70db..65b7f391df 100644 --- a/extensions/standard-processors/tests/unit/GetTCPTests.cpp +++ b/extensions/standard-processors/tests/unit/GetTCPTests.cpp @@ -50,9 +50,9 @@ void addSslContextServiceTo(SingleProcessorTestController& controller) { auto ssl_context_service = controller.plan->addController("SSLContextService", "SSLContextService"); LogTestController::getInstance().setTrace(); const auto executable_dir = minifi::utils::file::FileUtils::get_executable_dir(); - REQUIRE(controller.plan->setProperty(ssl_context_service, controllers::SSLContextService::CACertificate, (executable_dir / "resources" / "ca_A.crt").string())); - REQUIRE(controller.plan->setProperty(ssl_context_service, controllers::SSLContextService::ClientCertificate, (executable_dir / "resources" / "alice_by_A.pem").string())); - REQUIRE(controller.plan->setProperty(ssl_context_service, controllers::SSLContextService::PrivateKey, (executable_dir / "resources" / "alice.key").string())); + REQUIRE(controller.plan->setProperty(ssl_context_service, controllers::SSLContextServiceImpl::CACertificate, (executable_dir / "resources" / "ca_A.crt").string())); + REQUIRE(controller.plan->setProperty(ssl_context_service, controllers::SSLContextServiceImpl::ClientCertificate, (executable_dir / "resources" / "alice_by_A.pem").string())); + REQUIRE(controller.plan->setProperty(ssl_context_service, controllers::SSLContextServiceImpl::PrivateKey, (executable_dir / "resources" / "alice.key").string())); ssl_context_service->enable(); } diff --git a/extensions/standard-processors/tests/unit/JsonRecordTests.cpp b/extensions/standard-processors/tests/unit/JsonRecordTests.cpp index 406ae5b5dc..922745939f 100644 --- a/extensions/standard-processors/tests/unit/JsonRecordTests.cpp +++ b/extensions/standard-processors/tests/unit/JsonRecordTests.cpp @@ -25,7 +25,7 @@ #include "unit/TestRecord.h" #include "controllers/JsonRecordSetReader.h" #include "controllers/JsonRecordSetWriter.h" -#include "core/Record.h" +#include "minifi-cpp/core/Record.h" namespace org::apache::nifi::minifi::standard::test { diff --git a/extensions/standard-processors/tests/unit/ListenSyslogTests.cpp b/extensions/standard-processors/tests/unit/ListenSyslogTests.cpp index 545e22d954..92f8e7cdc4 100644 --- a/extensions/standard-processors/tests/unit/ListenSyslogTests.cpp +++ b/extensions/standard-processors/tests/unit/ListenSyslogTests.cpp @@ -495,9 +495,9 @@ TEST_CASE("Test ListenSyslog via TCP with SSL connection", "[ListenSyslog][Netwo auto ssl_context_service = controller.plan->addController("SSLContextService", "SSLContextService"); const auto executable_dir = minifi::utils::file::FileUtils::get_executable_dir(); - REQUIRE(controller.plan->setProperty(ssl_context_service, controllers::SSLContextService::CACertificate, (executable_dir / "resources" / "ca_A.crt").string())); - REQUIRE(controller.plan->setProperty(ssl_context_service, controllers::SSLContextService::ClientCertificate, (executable_dir / "resources" / "localhost_by_A.pem").string())); - REQUIRE(controller.plan->setProperty(ssl_context_service, controllers::SSLContextService::PrivateKey, (executable_dir / "resources" / "localhost.key").string())); + REQUIRE(controller.plan->setProperty(ssl_context_service, controllers::SSLContextServiceImpl::CACertificate, (executable_dir / "resources" / "ca_A.crt").string())); + REQUIRE(controller.plan->setProperty(ssl_context_service, controllers::SSLContextServiceImpl::ClientCertificate, (executable_dir / "resources" / "localhost_by_A.pem").string())); + REQUIRE(controller.plan->setProperty(ssl_context_service, controllers::SSLContextServiceImpl::PrivateKey, (executable_dir / "resources" / "localhost.key").string())); ssl_context_service->enable(); LogTestController::getInstance().setTrace(); diff --git a/extensions/standard-processors/tests/unit/ListenTcpTests.cpp b/extensions/standard-processors/tests/unit/ListenTcpTests.cpp index c5e647f84a..9f47af960c 100644 --- a/extensions/standard-processors/tests/unit/ListenTcpTests.cpp +++ b/extensions/standard-processors/tests/unit/ListenTcpTests.cpp @@ -117,10 +117,10 @@ TEST_CASE("Test ListenTCP with SSL connection", "[ListenTCP][NetworkListenerProc auto ssl_context_service = controller.plan->addController("SSLContextService", "SSLContextService"); LogTestController::getInstance().setTrace(); const auto executable_dir = minifi::utils::file::FileUtils::get_executable_dir(); - REQUIRE(controller.plan->setProperty(ssl_context_service, controllers::SSLContextService::CACertificate, (executable_dir / "resources" / "ca_A.crt").string())); - REQUIRE(controller.plan->setProperty(ssl_context_service, controllers::SSLContextService::ClientCertificate, (executable_dir / "resources" / "localhost_by_A.pem").string())); - REQUIRE(controller.plan->setProperty(ssl_context_service, controllers::SSLContextService::PrivateKey, (executable_dir / "resources" / "localhost.key").string())); - REQUIRE(controller.plan->setProperty(ssl_context_service, controllers::SSLContextService::Passphrase, "Password12")); + REQUIRE(controller.plan->setProperty(ssl_context_service, controllers::SSLContextServiceImpl::CACertificate, (executable_dir / "resources" / "ca_A.crt").string())); + REQUIRE(controller.plan->setProperty(ssl_context_service, controllers::SSLContextServiceImpl::ClientCertificate, (executable_dir / "resources" / "localhost_by_A.pem").string())); + REQUIRE(controller.plan->setProperty(ssl_context_service, controllers::SSLContextServiceImpl::PrivateKey, (executable_dir / "resources" / "localhost.key").string())); + REQUIRE(controller.plan->setProperty(ssl_context_service, controllers::SSLContextServiceImpl::Passphrase, "Password12")); REQUIRE(controller.plan->setProperty(listen_tcp, ListenTCP::MaxBatchSize, "2")); REQUIRE(controller.plan->setProperty(listen_tcp, ListenTCP::SSLContextService, "SSLContextService")); std::vector expected_successful_messages; @@ -246,10 +246,10 @@ TEST_CASE("Test ListenTCP SSL/TLS compatibility", "[ListenTCP][NetworkListenerPr auto ssl_context_service = controller.plan->addController("SSLContextService", "SSLContextService"); LogTestController::getInstance().setTrace(); const auto executable_dir = minifi::utils::file::FileUtils::get_executable_dir(); - REQUIRE(controller.plan->setProperty(ssl_context_service, controllers::SSLContextService::CACertificate, (executable_dir / "resources" / "ca_A.crt").string())); - REQUIRE(controller.plan->setProperty(ssl_context_service, controllers::SSLContextService::ClientCertificate, (executable_dir / "resources" / "localhost_by_A.pem").string())); - REQUIRE(controller.plan->setProperty(ssl_context_service, controllers::SSLContextService::PrivateKey, (executable_dir / "resources" / "localhost.key").string())); - REQUIRE(controller.plan->setProperty(ssl_context_service, controllers::SSLContextService::Passphrase, "Password12")); + REQUIRE(controller.plan->setProperty(ssl_context_service, controllers::SSLContextServiceImpl::CACertificate, (executable_dir / "resources" / "ca_A.crt").string())); + REQUIRE(controller.plan->setProperty(ssl_context_service, controllers::SSLContextServiceImpl::ClientCertificate, (executable_dir / "resources" / "localhost_by_A.pem").string())); + REQUIRE(controller.plan->setProperty(ssl_context_service, controllers::SSLContextServiceImpl::PrivateKey, (executable_dir / "resources" / "localhost.key").string())); + REQUIRE(controller.plan->setProperty(ssl_context_service, controllers::SSLContextServiceImpl::Passphrase, "Password12")); REQUIRE(controller.plan->setProperty(listen_tcp, ListenTCP::MaxBatchSize, "2")); REQUIRE(controller.plan->setProperty(listen_tcp, ListenTCP::SSLContextService, "SSLContextService")); REQUIRE(controller.plan->setProperty(listen_tcp, ListenTCP::ClientAuth, "REQUIRED")); diff --git a/extensions/standard-processors/tests/unit/ProcessorTests.cpp b/extensions/standard-processors/tests/unit/ProcessorTests.cpp index 9ed277ed17..4f389fd30e 100644 --- a/extensions/standard-processors/tests/unit/ProcessorTests.cpp +++ b/extensions/standard-processors/tests/unit/ProcessorTests.cpp @@ -26,6 +26,7 @@ #include #include #ifdef WIN32 +#include #include #include #endif /* WIN32 */ @@ -63,19 +64,19 @@ TEST_CASE("Test Creation of GetFile", "[getfileCreate]") { TEST_CASE("Test GetFileMultiple", "[getfileCreate3]") { TestController testController; LogTestController::getInstance().setDebug(); - auto config = std::make_shared(); + auto config = std::make_shared(); std::shared_ptr content_repo = std::make_shared(); content_repo->initialize(config); auto processor = std::make_shared("getfileCreate2"); processor->initialize(); std::shared_ptr test_repo = std::make_shared(); - std::shared_ptr repo = std::static_pointer_cast(test_repo); + std::shared_ptr repo = std::dynamic_pointer_cast(test_repo); auto dir = testController.createTempDirectory(); utils::Identifier processoruuid = processor->getUUID(); REQUIRE(processoruuid); - auto connection = std::make_unique(test_repo, content_repo, "getfileCreate2Connection"); + auto connection = std::make_unique(test_repo, content_repo, "getfileCreate2Connection"); connection->addRelationship(core::Relationship("success", "description")); @@ -89,19 +90,19 @@ TEST_CASE("Test GetFileMultiple", "[getfileCreate3]") { processor->addConnection(connection.get()); REQUIRE(!dir.empty()); - auto node = std::make_shared(processor.get()); - auto context = std::make_shared(node, nullptr, repo, repo, content_repo); + auto node = std::make_shared(processor.get()); + auto context = std::make_shared(node, nullptr, repo, repo, content_repo); context->setProperty(minifi::processors::GetFile::Directory, dir.string()); // replicate 10 threads processor->setScheduledState(core::ScheduledState::RUNNING); - auto factory = std::make_shared(context); + auto factory = std::make_shared(context); processor->onSchedule(*context, *factory); for (int i = 1; i < 10; i++) { - auto session = std::make_shared(context); + auto session = std::make_shared(context); REQUIRE(processor->getName() == "getfileCreate2"); std::shared_ptr record; @@ -151,14 +152,14 @@ TEST_CASE("Test GetFile Ignore", "[getfileCreate3]") { processor->initialize(); std::shared_ptr test_repo = std::make_shared(); - std::shared_ptr repo = std::static_pointer_cast(test_repo); + std::shared_ptr repo = std::dynamic_pointer_cast(test_repo); const auto dir = testController.createTempDirectory(); utils::Identifier processoruuid = processor->getUUID(); REQUIRE(processoruuid); - std::shared_ptr connection = std::make_shared(test_repo, content_repo, "getfileCreate2Connection"); + std::shared_ptr connection = std::make_shared(test_repo, content_repo, "getfileCreate2Connection"); connection->addRelationship(core::Relationship("success", "description")); @@ -172,18 +173,18 @@ TEST_CASE("Test GetFile Ignore", "[getfileCreate3]") { processor->addConnection(connection.get()); REQUIRE(!dir.empty()); - auto node = std::make_shared(processor.get()); - auto context = std::make_shared(node, nullptr, repo, repo, content_repo); + auto node = std::make_shared(processor.get()); + auto context = std::make_shared(node, nullptr, repo, repo, content_repo); context->setProperty(minifi::processors::GetFile::Directory, dir.string()); // replicate 10 threads processor->setScheduledState(core::ScheduledState::RUNNING); - auto factory = std::make_shared(context); + auto factory = std::make_shared(context); processor->onSchedule(*context, *factory); - auto session = std::make_shared(context); + auto session = std::make_shared(context); REQUIRE(processor->getName() == "getfileCreate2"); std::shared_ptr record; @@ -233,16 +234,16 @@ TEST_CASE("TestConnectionFull", "[ConnectionFull]") { TestController testController; LogTestController::getInstance().setDebug(); std::shared_ptr content_repo = std::make_shared(); - content_repo->initialize(std::make_shared()); - auto processor = std::make_shared("GFF"); + content_repo->initialize(std::make_shared()); + auto processor = std::make_shared("GFF"); processor->initialize(); processor->setProperty(minifi::processors::GenerateFlowFile::BatchSize, "10"); processor->setProperty(minifi::processors::GenerateFlowFile::FileSize, "0"); std::shared_ptr test_repo = std::make_shared(); - std::shared_ptr repo = std::static_pointer_cast(test_repo); + std::shared_ptr repo = std::dynamic_pointer_cast(test_repo); - std::shared_ptr connection = std::make_shared(test_repo, content_repo, "GFF2Connection"); + std::shared_ptr connection = std::make_shared(test_repo, content_repo, "GFF2Connection"); connection->setBackpressureThresholdCount(5); connection->addRelationship(core::Relationship("success", "description")); @@ -258,14 +259,14 @@ TEST_CASE("TestConnectionFull", "[ConnectionFull]") { processor->addConnection(connection.get()); processor->setScheduledState(core::ScheduledState::RUNNING); - auto node = std::make_shared(processor.get()); - auto context = std::make_shared(node, nullptr, repo, repo, content_repo); + auto node = std::make_shared(processor.get()); + auto context = std::make_shared(node, nullptr, repo, repo, content_repo); - auto factory = std::make_shared(context); + auto factory = std::make_shared(context); processor->onSchedule(*context, *factory); - auto session = std::make_shared(context); + auto session = std::make_shared(context); CHECK_FALSE(session->outgoingConnectionsFull("success")); CHECK_FALSE(connection->backpressureThresholdReached()); @@ -413,7 +414,7 @@ TEST_CASE("Test Find file", "[getfileCreate3]") { std::shared_ptr plan = testController.createPlan(); auto processor = plan->addProcessor("GetFile", "getfileCreate2"); auto processorReport = plan->addProcessor(std::make_unique( - std::make_shared()), "reporter", core::Relationship("success", "description"), false); + std::make_shared()), "reporter", core::Relationship("success", "description"), false); auto dir = testController.createTempDirectory(); plan->setProperty(processor, minifi::processors::GetFile::Directory, dir.string()); @@ -439,11 +440,11 @@ TEST_CASE("Test Find file", "[getfileCreate3]") { std::shared_ptr ffr = plan->getCurrentFlowFile(); REQUIRE(ffr != nullptr); ffr->getResourceClaim()->decreaseFlowFileRecordOwnedCount(); - auto repo = std::static_pointer_cast(plan->getProvenanceRepo()); + auto repo = std::dynamic_pointer_cast(plan->getProvenanceRepo()); REQUIRE(2 == repo->getRepoMap().size()); for (auto entry : repo->getRepoMap()) { - minifi::provenance::ProvenanceEventRecord newRecord; + minifi::provenance::ProvenanceEventRecordImpl newRecord; minifi::io::BufferStream stream(gsl::make_span(entry.second).as_span()); newRecord.deserialize(stream); @@ -463,10 +464,10 @@ TEST_CASE("Test Find file", "[getfileCreate3]") { throw std::runtime_error("Did not find record"); } } - auto taskReport = static_cast(processorReport); + auto taskReport = dynamic_cast(processorReport); taskReport->setBatchSize(1); std::vector> recordsReport; - recordsReport.push_back(std::make_shared()); + recordsReport.push_back(std::make_shared()); processorReport->incrementActiveTasks(); processorReport->setScheduledState(core::ScheduledState::RUNNING); std::string jsonStr; @@ -483,10 +484,10 @@ TEST_CASE("Test Find file", "[getfileCreate3]") { testController.runSession(plan, false, verifyReporter); } -class TestProcessorNoContent : public minifi::core::Processor { +class TestProcessorNoContent : public minifi::core::ProcessorImpl { public: explicit TestProcessorNoContent(std::string_view name, const utils::Identifier& uuid = {}) - : Processor(name, uuid) { + : ProcessorImpl(name, uuid) { } static constexpr const char* Description = "test resource"; @@ -539,20 +540,20 @@ void testRPGBypass(const std::string &host, const std::string &port, bool has_er LogTestController::getInstance().setTrace(); LogTestController::getInstance().setTrace(); - auto configuration = std::make_shared(); + auto configuration = std::make_shared(); std::shared_ptr content_repo = std::make_shared(); std::shared_ptr test_repo = std::make_shared(); - std::shared_ptr repo = std::static_pointer_cast(test_repo); + std::shared_ptr repo = std::dynamic_pointer_cast(test_repo); auto rpg = std::make_shared("rpg", "http://localhost:8989/nifi", configuration); rpg->initialize(); REQUIRE(rpg->setProperty(minifi::RemoteProcessorGroupPort::hostName, host)); rpg->setProperty(minifi::RemoteProcessorGroupPort::port, port); - auto node = std::make_shared(rpg.get()); - auto context = std::make_shared(node, nullptr, repo, repo, content_repo); - auto psf = std::make_shared(context); + auto node = std::make_shared(rpg.get()); + auto context = std::make_shared(node, nullptr, repo, repo, content_repo); + auto psf = std::make_shared(context); if (has_error) { rpg->onSchedule(*context, *psf); auto expected_error = "No peers selected during scheduling"; @@ -607,18 +608,18 @@ ProcessorWithIncomingConnectionTest::ProcessorWithIncomingConnectionTest() { const auto repo = std::make_shared(); const auto content_repo = std::make_shared(); - content_repo->initialize(std::make_shared()); + content_repo->initialize(std::make_shared()); processor_ = std::make_shared("test_processor"); - incoming_connection_ = std::make_shared(repo, content_repo, "incoming_connection"); + incoming_connection_ = std::make_shared(repo, content_repo, "incoming_connection"); incoming_connection_->addRelationship(core::Relationship{"success", ""}); incoming_connection_->setDestinationUUID(processor_->getUUID()); processor_->addConnection(incoming_connection_.get()); processor_->initialize(); - const auto processor_node = std::make_shared(processor_.get()); - const auto context = std::make_shared(processor_node, nullptr, repo, repo, content_repo); - const auto session_factory = std::make_shared(context); + const auto processor_node = std::make_shared(processor_.get()); + const auto context = std::make_shared(processor_node, nullptr, repo, repo, content_repo); + const auto session_factory = std::make_shared(context); session_ = session_factory->createSession(); } diff --git a/extensions/standard-processors/tests/unit/PutTCPTests.cpp b/extensions/standard-processors/tests/unit/PutTCPTests.cpp index c190c3c8ab..2799a239fd 100644 --- a/extensions/standard-processors/tests/unit/PutTCPTests.cpp +++ b/extensions/standard-processors/tests/unit/PutTCPTests.cpp @@ -36,7 +36,7 @@ using org::apache::nifi::minifi::test::utils::verifyEventHappenedInPollTime; namespace org::apache::nifi::minifi::processors { -using controllers::SSLContextService; +using controllers::SSLContextServiceImpl; namespace { @@ -170,12 +170,12 @@ class PutTCPTestFixture { void addSSLContextToPutTCP(const std::filesystem::path& ca_cert, const std::optional& client_cert, const std::optional& client_cert_key) { const std::filesystem::path ca_dir = minifi::utils::file::FileUtils::get_executable_dir() / "resources"; auto ssl_context_service_node = controller_.plan->addController("SSLContextService", "SSLContextService"); - REQUIRE(controller_.plan->setProperty(ssl_context_service_node, SSLContextService::CACertificate, (ca_dir / ca_cert).string())); + REQUIRE(controller_.plan->setProperty(ssl_context_service_node, SSLContextServiceImpl::CACertificate, (ca_dir / ca_cert).string())); if (client_cert) { - REQUIRE(controller_.plan->setProperty(ssl_context_service_node, SSLContextService::ClientCertificate, (ca_dir / *client_cert).string())); + REQUIRE(controller_.plan->setProperty(ssl_context_service_node, SSLContextServiceImpl::ClientCertificate, (ca_dir / *client_cert).string())); } if (client_cert_key) { - REQUIRE(controller_.plan->setProperty(ssl_context_service_node, SSLContextService::PrivateKey, (ca_dir / *client_cert_key).string())); + REQUIRE(controller_.plan->setProperty(ssl_context_service_node, SSLContextServiceImpl::PrivateKey, (ca_dir / *client_cert_key).string())); } ssl_context_service_node->enable(); diff --git a/extensions/standard-processors/tests/unit/ReplaceTextTests.cpp b/extensions/standard-processors/tests/unit/ReplaceTextTests.cpp index 03c37a7476..924b447228 100644 --- a/extensions/standard-processors/tests/unit/ReplaceTextTests.cpp +++ b/extensions/standard-processors/tests/unit/ReplaceTextTests.cpp @@ -165,7 +165,7 @@ TEST_CASE("Substitute Variables works correctly in ReplaceText", "[applyReplacem replace_text.setEvaluationMode(minifi::processors::EvaluationModeType::ENTIRE_TEXT); replace_text.setReplacementStrategy(minifi::processors::ReplacementStrategyType::SUBSTITUTE_VARIABLES); - const auto flow_file = std::make_shared(); + const auto flow_file = std::make_shared(); flow_file->setAttribute("color", "green"); flow_file->setAttribute("food", "eggs and ham"); diff --git a/extensions/standard-processors/tests/unit/RouteTextTests.cpp b/extensions/standard-processors/tests/unit/RouteTextTests.cpp index f5c3b16627..cc72bf1dcf 100644 --- a/extensions/standard-processors/tests/unit/RouteTextTests.cpp +++ b/extensions/standard-processors/tests/unit/RouteTextTests.cpp @@ -106,7 +106,7 @@ struct RouteTextController : public TestController { } void putFlowFile(const std::map& attributes, const std::string& content) const { - auto flow_file = std::make_shared(); + auto flow_file = std::make_shared(); for (const auto& attr : attributes) { flow_file->setAttribute(attr.first, attr.second); } diff --git a/extensions/standard-processors/tests/unit/TailFileTests.cpp b/extensions/standard-processors/tests/unit/TailFileTests.cpp index d02a58b751..ef973613a2 100644 --- a/extensions/standard-processors/tests/unit/TailFileTests.cpp +++ b/extensions/standard-processors/tests/unit/TailFileTests.cpp @@ -1054,7 +1054,7 @@ TEST_CASE("TailFile finds and finishes the renamed file and continues with the n const core::Relationship success_relationship{"success", "everything is fine"}; // use persistent state storage that defaults to rocksDB, not volatile - const auto configuration = std::make_shared(); + const auto configuration = std::make_shared(); configuration->setHome(log_dir); { auto test_plan = testController.createPlan(configuration, state_dir); @@ -1717,9 +1717,9 @@ TEST_CASE("TailFile onSchedule throws if an invalid Attribute Provider Service i namespace { -class TestAttributeProviderService final : public minifi::controllers::AttributeProviderService { +class TestAttributeProviderService final : public minifi::controllers::AttributeProviderServiceImpl { public: - using AttributeProviderService::AttributeProviderService; + using AttributeProviderServiceImpl::AttributeProviderServiceImpl; static constexpr const char* Description = "An attribute provider service which provides a constant set of records."; static constexpr auto Properties = std::array{}; diff --git a/extensions/standard-processors/tests/unit/YamlConfigurationTests.cpp b/extensions/standard-processors/tests/unit/YamlConfigurationTests.cpp index e2538662ba..876167a4db 100644 --- a/extensions/standard-processors/tests/unit/YamlConfigurationTests.cpp +++ b/extensions/standard-processors/tests/unit/YamlConfigurationTests.cpp @@ -566,7 +566,7 @@ Flow Controller: REQUIRE(!rootFlowConfig->findProcessorByName("XYZ")->getUUIDStr().empty()); } -class DummyComponent : public core::ConfigurableComponent { +class DummyComponent : public core::ConfigurableComponentImpl { public: bool supportsDynamicProperties() const override { return false; @@ -1261,9 +1261,9 @@ NiFi Properties Overrides: {} "Parameter Operation: Parameter name 'lookup.frequency' already exists, parameter names must be unique within a parameter context!"); } -class DummyFlowYamlProcessor : public core::Processor { +class DummyFlowYamlProcessor : public core::ProcessorImpl { public: - using core::Processor::Processor; + using core::ProcessorImpl::ProcessorImpl; static constexpr const char* Description = "A processor that does nothing."; static constexpr auto SimpleProperty = core::PropertyDefinitionBuilder<>::createProperty("Simple Property") diff --git a/extensions/standard-processors/tests/unit/YamlConnectionParserTest.cpp b/extensions/standard-processors/tests/unit/YamlConnectionParserTest.cpp index 34fe823259..ac033c22ee 100644 --- a/extensions/standard-processors/tests/unit/YamlConnectionParserTest.cpp +++ b/extensions/standard-processors/tests/unit/YamlConnectionParserTest.cpp @@ -41,7 +41,7 @@ TEST_CASE("Connections components are parsed from yaml", "[YamlConfiguration]") gsl::not_null parent_ptr{ &parent }; SECTION("Source relationships are read") { - const auto connection = std::make_shared(nullptr, nullptr, "name"); + const auto connection = std::make_shared(nullptr, nullptr, "name"); std::string serialized_yaml; std::set expectations; SECTION("Single relationship name") { @@ -130,7 +130,7 @@ TEST_CASE("Connections components are parsed from yaml", "[YamlConfiguration]") } } SECTION("Errors are handled properly when configuration lines are missing") { - const auto connection = std::make_shared(nullptr, nullptr, "name"); + const auto connection = std::make_shared(nullptr, nullptr, "name"); SECTION("With empty configuration") { YAML::Node yaml_node = YAML::Load(std::string("")); flow::Node connection_node{std::make_shared(yaml_node)}; diff --git a/extensions/standard-processors/tests/unit/YamlProcessGroupParserTests.cpp b/extensions/standard-processors/tests/unit/YamlProcessGroupParserTests.cpp index 0147d30f7c..2e1dac807c 100644 --- a/extensions/standard-processors/tests/unit/YamlProcessGroupParserTests.cpp +++ b/extensions/standard-processors/tests/unit/YamlProcessGroupParserTests.cpp @@ -24,7 +24,7 @@ static core::YamlConfiguration config{core::ConfigurationContext{ .flow_file_repo = nullptr, .content_repo = nullptr, - .configuration = std::make_shared(), + .configuration = std::make_shared(), .path = "", .filesystem = std::make_shared(), .sensitive_values_encryptor = utils::crypto::EncryptionProvider{utils::crypto::XSalsa20Cipher{utils::crypto::XSalsa20Cipher::generateKey()}} diff --git a/extensions/standard-processors/utils/JoltUtils.h b/extensions/standard-processors/utils/JoltUtils.h index 4b0f2f946b..12a9c80784 100644 --- a/extensions/standard-processors/utils/JoltUtils.h +++ b/extensions/standard-processors/utils/JoltUtils.h @@ -27,7 +27,7 @@ #include #include -#include "logging/Logger.h" +#include "core/logging/Logger.h" #include "utils/gsl.h" #include "rapidjson/document.h" #include "utils/expected.h" diff --git a/extensions/systemd/CMakeLists.txt b/extensions/systemd/CMakeLists.txt index 3350d47bad..87f49cafbc 100644 --- a/extensions/systemd/CMakeLists.txt +++ b/extensions/systemd/CMakeLists.txt @@ -25,7 +25,7 @@ include(${CMAKE_SOURCE_DIR}/extensions/ExtensionHeader.txt) add_minifi_library(minifi-systemd SHARED "ConsumeJournald.cpp" "libwrapper/LibWrapper.cpp" "libwrapper/DlopenWrapper.cpp") -target_link_libraries(minifi-systemd ${LIBMINIFI} Threads::Threads date::date) +target_link_libraries(minifi-systemd ${LIBMINIFI} Threads::Threads) register_extension(minifi-systemd "SYSTEMD EXTENSIONS" SYSTEMD-EXTENSIONS "Enabled log collection from journald" "extensions/systemd/tests") register_extension_linter(minifi-systemd-extension-linter) diff --git a/extensions/systemd/ConsumeJournald.cpp b/extensions/systemd/ConsumeJournald.cpp index 1e0dc1d40b..073746cdc6 100644 --- a/extensions/systemd/ConsumeJournald.cpp +++ b/extensions/systemd/ConsumeJournald.cpp @@ -32,8 +32,8 @@ namespace org::apache::nifi::minifi::extensions::systemd { namespace chr = std::chrono; -ConsumeJournald::ConsumeJournald(std::string_view name, const utils::Identifier &id, std::unique_ptr&& libwrapper) - :core::Processor{name, id}, libwrapper_{std::move(libwrapper)} +ConsumeJournald::ConsumeJournald(const std::string_view name, const utils::Identifier &id, std::unique_ptr&& libwrapper) + :core::ProcessorImpl{name, id}, libwrapper_{std::move(libwrapper)} {} void ConsumeJournald::initialize() { diff --git a/extensions/systemd/ConsumeJournald.h b/extensions/systemd/ConsumeJournald.h index fddfd36470..a12e6c9114 100644 --- a/extensions/systemd/ConsumeJournald.h +++ b/extensions/systemd/ConsumeJournald.h @@ -35,7 +35,7 @@ #include "core/PropertyDefinitionBuilder.h" #include "core/PropertyType.h" #include "core/RelationshipDefinition.h" -#include "core/logging/LoggerConfiguration.h" +#include "core/logging/LoggerFactory.h" #include "libwrapper/LibWrapper.h" #include "utils/Deleters.h" #include "utils/gsl.h" @@ -45,7 +45,7 @@ namespace org::apache::nifi::minifi::extensions::systemd { enum class PayloadFormat { Raw, Syslog }; -class ConsumeJournald final : public core::Processor { +class ConsumeJournald final : public core::ProcessorImpl { public: static constexpr const char* CURSOR_KEY = "cursor"; static constexpr const char* PAYLOAD_FORMAT_RAW = "Raw"; diff --git a/extensions/test-processors/KamikazeProcessor.h b/extensions/test-processors/KamikazeProcessor.h index 08ecb6a32b..8b90d78781 100644 --- a/extensions/test-processors/KamikazeProcessor.h +++ b/extensions/test-processors/KamikazeProcessor.h @@ -31,7 +31,7 @@ namespace org::apache::nifi::minifi::processors { -class KamikazeProcessor : public core::Processor { +class KamikazeProcessor : public core::ProcessorImpl { public: EXTENSIONAPI static const std::string OnScheduleExceptionStr; EXTENSIONAPI static const std::string OnTriggerExceptionStr; @@ -40,7 +40,7 @@ class KamikazeProcessor : public core::Processor { EXTENSIONAPI static const std::string OnUnScheduleLogStr; explicit KamikazeProcessor(std::string_view name, const utils::Identifier& uuid = utils::Identifier()) - : Processor(name, uuid) { + : ProcessorImpl(name, uuid) { } EXTENSIONAPI static constexpr const char* Description = "This processor can throw exceptions in onTrigger and onSchedule calls based on configuration. Only for testing purposes."; diff --git a/extensions/test-processors/LogOnDestructionProcessor.h b/extensions/test-processors/LogOnDestructionProcessor.h index 7306818bfb..0d03c2c25f 100644 --- a/extensions/test-processors/LogOnDestructionProcessor.h +++ b/extensions/test-processors/LogOnDestructionProcessor.h @@ -22,15 +22,15 @@ #include #include -#include "core/logging/LoggerConfiguration.h" +#include "core/logging/LoggerFactory.h" #include "core/Processor.h" namespace org::apache::nifi::minifi::processors { -class LogOnDestructionProcessor : public core::Processor { +class LogOnDestructionProcessor : public core::ProcessorImpl { public: explicit LogOnDestructionProcessor(std::string_view name, const utils::Identifier& uuid = utils::Identifier()) - : Processor(name, uuid) { + : ProcessorImpl(name, uuid) { } ~LogOnDestructionProcessor() override { diff --git a/extensions/windows-event-log/Bookmark.h b/extensions/windows-event-log/Bookmark.h index 832a33f2e6..0b17a2e82b 100644 --- a/extensions/windows-event-log/Bookmark.h +++ b/extensions/windows-event-log/Bookmark.h @@ -27,7 +27,7 @@ #include "core/ProcessContext.h" #include "core/ProcessSession.h" #include "wel/UniqueEvtHandle.h" -#include "logging/Logger.h" +#include "core/logging/Logger.h" #include "utils/expected.h" #include "wel/EventPath.h" diff --git a/extensions/windows-event-log/ConsumeWindowsEventLog.cpp b/extensions/windows-event-log/ConsumeWindowsEventLog.cpp index 9c23fe65ae..62a7743f40 100644 --- a/extensions/windows-event-log/ConsumeWindowsEventLog.cpp +++ b/extensions/windows-event-log/ConsumeWindowsEventLog.cpp @@ -45,7 +45,7 @@ #include "core/Resource.h" #include "Bookmark.h" #include "utils/Deleters.h" -#include "logging/LoggerConfiguration.h" +#include "core/logging/LoggerFactory.h" #include "utils/gsl.h" #include "utils/OsUtils.h" @@ -62,7 +62,7 @@ namespace org::apache::nifi::minifi::processors { const int EVT_NEXT_TIMEOUT_MS = 500; ConsumeWindowsEventLog::ConsumeWindowsEventLog(const std::string& name, const utils::Identifier& uuid) - : core::Processor(name, uuid), + : core::ProcessorImpl(name, uuid), logger_(core::logging::LoggerFactory::getLogger(uuid_)) { char buff[MAX_COMPUTERNAME_LENGTH + 1]; DWORD size = sizeof(buff); diff --git a/extensions/windows-event-log/ConsumeWindowsEventLog.h b/extensions/windows-event-log/ConsumeWindowsEventLog.h index 3a86fa33e8..e939d627f7 100644 --- a/extensions/windows-event-log/ConsumeWindowsEventLog.h +++ b/extensions/windows-event-log/ConsumeWindowsEventLog.h @@ -77,7 +77,7 @@ enum class JsonFormat { class Bookmark; -class ConsumeWindowsEventLog : public core::Processor { +class ConsumeWindowsEventLog : public core::ProcessorImpl { public: explicit ConsumeWindowsEventLog(const std::string& name, const utils::Identifier& uuid = {}); diff --git a/extensions/windows-event-log/TailEventLog.cpp b/extensions/windows-event-log/TailEventLog.cpp index 827c36a89b..a055ad53e5 100644 --- a/extensions/windows-event-log/TailEventLog.cpp +++ b/extensions/windows-event-log/TailEventLog.cpp @@ -31,6 +31,7 @@ #include "core/Resource.h" #include "utils/OsUtils.h" +#include "core/Property.h" namespace org::apache::nifi::minifi::processors { diff --git a/extensions/windows-event-log/TailEventLog.h b/extensions/windows-event-log/TailEventLog.h index d155e9d8d3..d91ff85bca 100644 --- a/extensions/windows-event-log/TailEventLog.h +++ b/extensions/windows-event-log/TailEventLog.h @@ -22,6 +22,8 @@ #include #include +#include + #include "core/Core.h" #include "FlowFileRecord.h" #include "core/Processor.h" @@ -40,10 +42,10 @@ namespace processors { const LPCWSTR pEventTypeNames[] = { L"Error", L"Warning", L"Informational", L"Audit Success", L"Audit Failure" }; const char log_name[255] = "Application"; -class TailEventLog : public core::Processor { +class TailEventLog : public core::ProcessorImpl { public: explicit TailEventLog(const std::string& name, const utils::Identifier& uuid = {}) - : core::Processor(name, uuid) { + : core::ProcessorImpl(name, uuid) { } virtual ~TailEventLog() = default; diff --git a/libminifi/CMakeLists.txt b/libminifi/CMakeLists.txt index 73a3fc2628..1d06a7363a 100644 --- a/libminifi/CMakeLists.txt +++ b/libminifi/CMakeLists.txt @@ -42,7 +42,14 @@ endif() set(TLS_SOURCES "src/utils/tls/*.cpp" "src/io/tls/*.cpp") -file(GLOB SOURCES "src/agent/*.cpp" "src/properties/*.cpp" "src/utils/file/*.cpp" "src/sitetosite/*.cpp" "src/core/logging/*.cpp" "src/core/logging/internal/*.cpp" "src/core/logging/alert/*.cpp" "src/core/state/*.cpp" "src/core/state/nodes/*.cpp" "src/c2/protocols/*.cpp" "src/c2/triggers/*.cpp" "src/c2/*.cpp" "src/io/*.cpp" ${SOCKET_SOURCES} ${TLS_SOURCES} "src/core/controller/*.cpp" "src/controllers/*.cpp" "src/controllers/keyvalue/*.cpp" "src/core/*.cpp" "src/core/repository/*.cpp" "src/core/flow/*.cpp" "src/core/json/*.cpp" "src/core/yaml/*.cpp" "src/core/reporting/*.cpp" "src/core/extension/*.cpp" "src/serialization/*.cpp" "src/provenance/*.cpp" "src/utils/*.cpp" "src/utils/crypto/*.cpp" "src/utils/crypto/ciphers/*.cpp" "src/utils/crypto/property_encryption/*.cpp" "src/*.cpp" "src/utils/net/*.cpp" "src/http/*.cpp") +file(GLOB SOURCES + "src/agent/*.cpp" "src/properties/*.cpp" "src/utils/file/*.cpp" "src/sitetosite/*.cpp" + "src/core/logging/*.cpp" "src/core/logging/internal/*.cpp" "src/core/logging/alert/*.cpp" + "src/core/state/*.cpp" "src/core/state/nodes/*.cpp" "src/c2/protocols/*.cpp" "src/c2/triggers/*.cpp" + "src/c2/*.cpp" "src/io/*.cpp" ${SOCKET_SOURCES} ${TLS_SOURCES} "src/core/controller/*.cpp" + "src/controllers/*.cpp" "src/core/*.cpp" "src/core/repository/*.cpp" "src/core/flow/*.cpp" + "src/core/json/*.cpp" "src/core/yaml/*.cpp" "src/core/reporting/*.cpp" "src/core/extension/*.cpp" + "src/serialization/*.cpp" "src/provenance/*.cpp" "src/utils/*.cpp" "src/*.cpp" "src/http/*.cpp") # manually add this as it might not yet be present when this executes list(APPEND SOURCES "${CMAKE_CURRENT_BINARY_DIR}/agent_version.cpp") @@ -76,7 +83,7 @@ endif() include(RangeV3) include(Asio) include(MagicEnum) -list(APPEND LIBMINIFI_LIBRARIES yaml-cpp ZLIB::ZLIB concurrentqueue RapidJSON spdlog::spdlog Threads::Threads gsl-lite libsodium range-v3 expected-lite date::date date::tz asio magic_enum OpenSSL::Crypto OpenSSL::SSL CURL::libcurl RapidJSON fmt::fmt) +list(APPEND LIBMINIFI_LIBRARIES minifi-utils yaml-cpp ZLIB::ZLIB concurrentqueue RapidJSON spdlog::spdlog Threads::Threads gsl-lite libsodium range-v3 expected-lite asio magic_enum OpenSSL::Crypto OpenSSL::SSL CURL::libcurl RapidJSON fmt::fmt) if(NOT WIN32) list(APPEND LIBMINIFI_LIBRARIES OSSP::libuuid++) endif() @@ -91,7 +98,7 @@ if (UNIX AND (CMAKE_SYSTEM_PROCESSOR MATCHES "armv7")) target_link_libraries(core-minifi "-latomic") endif() -SET (LIBMINIFI core-minifi PARENT_SCOPE) +SET(LIBMINIFI minifi-core minifi-extension-utils $ PARENT_SCOPE) if (WIN32) install(TARGETS core-minifi ARCHIVE DESTINATION bin COMPONENT bin) diff --git a/libminifi/include/Connection.h b/libminifi/include/Connection.h index 0cabbfdd38..114c33a907 100644 --- a/libminifi/include/Connection.h +++ b/libminifi/include/Connection.h @@ -35,6 +35,7 @@ #include "core/FlowFile.h" #include "core/Repository.h" #include "utils/FlowFileQueue.h" +#include "minifi-cpp/Connection.h" namespace org::apache::nifi::minifi { @@ -42,123 +43,123 @@ namespace test::utils { struct ConnectionTestAccessor; } // namespace test::utils -class Connection : public core::Connectable { +class ConnectionImpl : public core::ConnectableImpl, public virtual Connection { friend struct test::utils::ConnectionTestAccessor; public: - explicit Connection(std::shared_ptr flow_repository, std::shared_ptr content_repo, std::string_view name); - explicit Connection(std::shared_ptr flow_repository, std::shared_ptr content_repo, std::string_view name, const utils::Identifier &uuid); - explicit Connection(std::shared_ptr flow_repository, std::shared_ptr content_repo, std::string_view name, const utils::Identifier &uuid, + explicit ConnectionImpl(std::shared_ptr flow_repository, std::shared_ptr content_repo, std::string_view name); + explicit ConnectionImpl(std::shared_ptr flow_repository, std::shared_ptr content_repo, std::string_view name, const utils::Identifier &uuid); + explicit ConnectionImpl(std::shared_ptr flow_repository, std::shared_ptr content_repo, std::string_view name, const utils::Identifier &uuid, const utils::Identifier &srcUUID); - explicit Connection(std::shared_ptr flow_repository, std::shared_ptr content_repo, std::string_view name, const utils::Identifier &uuid, + explicit ConnectionImpl(std::shared_ptr flow_repository, std::shared_ptr content_repo, std::string_view name, const utils::Identifier &uuid, const utils::Identifier &srcUUID, const utils::Identifier &destUUID); - explicit Connection(std::shared_ptr flow_repository, std::shared_ptr content_repo, std::shared_ptr swap_manager, + explicit ConnectionImpl(std::shared_ptr flow_repository, std::shared_ptr content_repo, std::shared_ptr swap_manager, std::string_view name, const utils::Identifier& uuid); - ~Connection() override = default; + ~ConnectionImpl() override = default; - Connection(const Connection &parent) = delete; - Connection &operator=(const Connection &parent) = delete; + ConnectionImpl(const ConnectionImpl &parent) = delete; + ConnectionImpl &operator=(const ConnectionImpl &parent) = delete; static constexpr uint64_t DEFAULT_BACKPRESSURE_THRESHOLD_COUNT = 2000; static constexpr uint64_t DEFAULT_BACKPRESSURE_THRESHOLD_DATA_SIZE = 100_MB; - void setSourceUUID(const utils::Identifier &uuid) { + void setSourceUUID(const utils::Identifier &uuid) override { src_uuid_ = uuid; } - void setDestinationUUID(const utils::Identifier &uuid) { + void setDestinationUUID(const utils::Identifier &uuid) override { dest_uuid_ = uuid; } - utils::Identifier getSourceUUID() const { + utils::Identifier getSourceUUID() const override { return src_uuid_; } - utils::Identifier getDestinationUUID() const { + utils::Identifier getDestinationUUID() const override { return dest_uuid_; } - void setSource(core::Connectable* source) { + void setSource(core::Connectable* source) override { source_connectable_ = source; } - core::Connectable* getSource() const { + core::Connectable* getSource() const override { return source_connectable_; } - void setDestination(core::Connectable* dest) { + void setDestination(core::Connectable* dest) override { dest_connectable_ = dest; } - core::Connectable* getDestination() const { + core::Connectable* getDestination() const override { return dest_connectable_; } - void addRelationship(core::Relationship relationship) { + void addRelationship(core::Relationship relationship) override { relationships_.insert(std::move(relationship)); } - const std::set &getRelationships() const { + const std::set &getRelationships() const override { return relationships_; } - void setBackpressureThresholdCount(uint64_t size) { + void setBackpressureThresholdCount(uint64_t size) override { backpressure_threshold_count_ = size; } - uint64_t getBackpressureThresholdCount() const { + uint64_t getBackpressureThresholdCount() const override { return backpressure_threshold_count_; } - void setBackpressureThresholdDataSize(uint64_t size) { + void setBackpressureThresholdDataSize(uint64_t size) override { backpressure_threshold_data_size_ = size; } - uint64_t getBackpressureThresholdDataSize() const { + uint64_t getBackpressureThresholdDataSize() const override { return backpressure_threshold_data_size_; } - void setSwapThreshold(uint64_t size) { + void setSwapThreshold(uint64_t size) override { queue_.setTargetSize(size); queue_.setMinSize(size / 2); queue_.setMaxSize(size * 3 / 2); } - void setFlowExpirationDuration(std::chrono::milliseconds duration) { + void setFlowExpirationDuration(std::chrono::milliseconds duration) override { expired_duration_ = duration; } - std::chrono::milliseconds getFlowExpirationDuration() const { + std::chrono::milliseconds getFlowExpirationDuration() const override { return expired_duration_; } - void setDropEmptyFlowFiles(bool drop) { + void setDropEmptyFlowFiles(bool drop) override { drop_empty_ = drop; } - bool getDropEmptyFlowFiles() const { + bool getDropEmptyFlowFiles() const override { return drop_empty_; } - bool isEmpty() const; + bool isEmpty() const override; - bool backpressureThresholdReached() const; + bool backpressureThresholdReached() const override; - uint64_t getQueueSize() const { + uint64_t getQueueSize() const override { std::lock_guard lock(mutex_); return queue_.size(); } - uint64_t getQueueDataSize() { + uint64_t getQueueDataSize() override { return queued_data_size_; } void put(const std::shared_ptr& flow) override; - void multiPut(std::vector>& flows); + void multiPut(std::vector>& flows) override; - std::shared_ptr poll(std::set> &expiredFlowRecords); + std::shared_ptr poll(std::set> &expiredFlowRecords) override; - void drain(bool delete_permanently); + void drain(bool delete_permanently) override; void yield() override {} diff --git a/libminifi/include/FlowFileRecord.h b/libminifi/include/FlowFileRecord.h index 15d72b4643..260453ae37 100644 --- a/libminifi/include/FlowFileRecord.h +++ b/libminifi/include/FlowFileRecord.h @@ -38,6 +38,7 @@ #include "Connection.h" #include "io/OutputStream.h" #include "io/StreamPipe.h" +#include "minifi-cpp/FlowFileRecord.h" namespace org::apache::nifi::minifi { @@ -47,16 +48,20 @@ namespace core { class ProcessSession; } -class FlowFileRecord : public core::FlowFile { +class FlowFileRecordImpl : public core::FlowFileImpl, public virtual FlowFileRecord { friend class core::ProcessSession; public: - FlowFileRecord(); + FlowFileRecordImpl(); - bool Serialize(io::OutputStream &outStream); + void copy(const core::FlowFile& other) override { + *this = *dynamic_cast(&other); + } + + bool Serialize(io::OutputStream &outStream) override; //! Serialize and Persistent to the repository - bool Persist(const std::shared_ptr& flowRepository); + bool Persist(const std::shared_ptr& flowRepository) override; static std::shared_ptr DeSerialize(std::span buffer, const std::shared_ptr &content_repo, utils::Identifier &container) { io::BufferStream inStream{buffer}; @@ -64,9 +69,9 @@ class FlowFileRecord : public core::FlowFile { } static std::shared_ptr DeSerialize(io::InputStream &stream, const std::shared_ptr &content_repo, utils::Identifier &container); static std::shared_ptr DeSerialize(const std::string& key, const std::shared_ptr& flowRepository, - const std::shared_ptr &content_repo, utils::Identifier &container); + const std::shared_ptr &content_repo, utils::Identifier &container); - std::string getContentFullPath() const { + std::string getContentFullPath() const override { return claim_ ? claim_->getContentFullPath() : ""; } diff --git a/libminifi/include/ForwardingNode.h b/libminifi/include/ForwardingNode.h index f8749836b8..d20468b27a 100644 --- a/libminifi/include/ForwardingNode.h +++ b/libminifi/include/ForwardingNode.h @@ -26,12 +26,12 @@ namespace org::apache::nifi::minifi { -class ForwardingNode : public core::Processor { +class ForwardingNode : public core::ProcessorImpl { public: - ForwardingNode(std::string_view name, const utils::Identifier& uuid, std::shared_ptr logger) : Processor(name, uuid), logger_(std::move(logger)) { + ForwardingNode(std::string_view name, const utils::Identifier& uuid, std::shared_ptr logger) : ProcessorImpl(name, uuid), logger_(std::move(logger)) { strategy_ = core::SchedulingStrategy::EVENT_DRIVEN; } - ForwardingNode(std::string_view name, std::shared_ptr logger) : Processor(name), logger_(std::move(logger)) {} + ForwardingNode(std::string_view name, std::shared_ptr logger) : ProcessorImpl(name), logger_(std::move(logger)) {} MINIFIAPI static constexpr auto Properties = std::array{}; MINIFIAPI static constexpr auto Success = core::RelationshipDefinition{"success", "FlowFiles are routed to success relationship"}; diff --git a/libminifi/include/RemoteProcessorGroupPort.h b/libminifi/include/RemoteProcessorGroupPort.h index e795b365f9..e58497f5ce 100644 --- a/libminifi/include/RemoteProcessorGroupPort.h +++ b/libminifi/include/RemoteProcessorGroupPort.h @@ -35,9 +35,10 @@ #include "core/PropertyDefinitionBuilder.h" #include "core/RelationshipDefinition.h" #include "sitetosite/SiteToSiteClient.h" -#include "controllers/SSLContextService.h" +#include "minifi-cpp/controllers/SSLContextService.h" #include "core/logging/LoggerFactory.h" #include "utils/Export.h" +#include "core/ClassLoader.h" namespace org::apache::nifi::minifi { @@ -74,10 +75,10 @@ struct RPG { std::string protocol_; }; -class RemoteProcessorGroupPort : public core::Processor { +class RemoteProcessorGroupPort : public core::ProcessorImpl { public: RemoteProcessorGroupPort(std::string_view name, std::string url, std::shared_ptr configure, const utils::Identifier &uuid = {}) - : core::Processor(name, uuid), + : core::ProcessorImpl(name, uuid), configure_(std::move(configure)), direction_(sitetosite::SEND), transmitting_(false), diff --git a/libminifi/include/ResourceClaim.h b/libminifi/include/ResourceClaim.h index ea0474306a..6db0048113 100644 --- a/libminifi/include/ResourceClaim.h +++ b/libminifi/include/ResourceClaim.h @@ -1,7 +1,4 @@ /** - * @file ResourceClaim.h - * Resource Claim class declaration - * * 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. @@ -17,8 +14,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#ifndef LIBMINIFI_INCLUDE_RESOURCECLAIM_H_ -#define LIBMINIFI_INCLUDE_RESOURCECLAIM_H_ + +#pragma once #include #include @@ -32,10 +29,7 @@ #include "properties/Configure.h" #include "utils/Id.h" -namespace org { -namespace apache { -namespace nifi { -namespace minifi { +namespace org::apache::nifi::minifi { // Default content directory #define DEFAULT_CONTENT_DIRECTORY "./content_repository" @@ -45,54 +39,46 @@ extern std::string default_directory_path; extern void setDefaultDirectory(std::string); // ResourceClaim Class -class ResourceClaim { +class ResourceClaimImpl : public ResourceClaim { public: - // the type which uniquely represents the resource for the owning manager - using Path = std::string; // Constructor /*! * Create a new resource claim */ // explicit ResourceClaim(std::shared_ptr> claim_manager, const std::string contentDirectory); - explicit ResourceClaim(std::shared_ptr> claim_manager); + explicit ResourceClaimImpl(std::shared_ptr> claim_manager); - explicit ResourceClaim(Path path, std::shared_ptr> claim_manager); + explicit ResourceClaimImpl(Path path, std::shared_ptr> claim_manager); // Destructor - ~ResourceClaim(); + ~ResourceClaimImpl() override; // increaseFlowFileRecordOwnedCount - void increaseFlowFileRecordOwnedCount() { + void increaseFlowFileRecordOwnedCount() override { claim_manager_->incrementStreamCount(*this); } // decreaseFlowFileRecordOwenedCount - void decreaseFlowFileRecordOwnedCount() { + void decreaseFlowFileRecordOwnedCount() override { claim_manager_->decrementStreamCount(*this); } // getFlowFileRecordOwenedCount - uint64_t getFlowFileRecordOwnedCount() { + uint64_t getFlowFileRecordOwnedCount() override { return claim_manager_->getStreamCount(*this); } // Get the content full path - Path getContentFullPath() const { + Path getContentFullPath() const override { return _contentFullPath; } - bool exists() { + bool exists() override { if (claim_manager_ == nullptr) { return false; } return claim_manager_->exists(*this); } - friend std::ostream& operator<<(std::ostream& stream, const ResourceClaim& claim) { - stream << claim._contentFullPath; - return stream; - } - - friend std::ostream& operator<<(std::ostream& stream, const std::shared_ptr& claim) { - stream << claim->_contentFullPath; - return stream; + std::ostream& write(std::ostream& stream) const override { + return stream << _contentFullPath; } protected: @@ -104,16 +90,11 @@ class ResourceClaim { private: // Logger std::shared_ptr logger_; - // Prevent default copy constructor and assignment operation - // Only support pass by reference or pointer - ResourceClaim(const ResourceClaim &parent); - ResourceClaim &operator=(const ResourceClaim &parent); + + ResourceClaimImpl(const ResourceClaimImpl &parent); + ResourceClaimImpl &operator=(const ResourceClaimImpl &parent); static utils::NonRepeatingStringGenerator non_repeating_string_generator_; }; -} // namespace minifi -} // namespace nifi -} // namespace apache -} // namespace org -#endif // LIBMINIFI_INCLUDE_RESOURCECLAIM_H_ +} // namespace org::apache::nifi::minifi diff --git a/libminifi/include/agent/build_description.h b/libminifi/include/agent/build_description.h index 8c570eb476..6de800ea58 100644 --- a/libminifi/include/agent/build_description.h +++ b/libminifi/include/agent/build_description.h @@ -22,7 +22,7 @@ #include #include #include -#include "agent_docs.h" +#include "agent/agent_docs.h" #include "core/controller/ControllerService.h" #include "core/ClassLoader.h" #include "core/expect.h" @@ -31,29 +31,10 @@ #include "core/Processor.h" #include "core/Annotation.h" #include "io/validation.h" +#include "minifi-cpp/agent/build_description.h" namespace org::apache::nifi::minifi { -struct BundleDetails { - std::string artifact; - std::string group; - std::string version; -}; - -class ExternalBuildDescription { - private: - static std::vector &getExternal(); - - static std::map &getExternalMappings(); - - public: - static void addExternalComponent(const BundleDetails& details, const ClassDescription& description); - - static Components getClassDescriptions(const std::string &group); - - static std::vector getExternalGroups(); -}; - class BuildDescription { public: Components getClassDescriptions(const std::string& group = "minifi-system") { diff --git a/libminifi/include/c2/C2Agent.h b/libminifi/include/c2/C2Agent.h index 3f0e12a7c1..4818a6b0b1 100644 --- a/libminifi/include/c2/C2Agent.h +++ b/libminifi/include/c2/C2Agent.h @@ -29,8 +29,8 @@ #include #include -#include "../core/state/nodes/MetricsBase.h" -#include "../core/state/Value.h" +#include "core/state/nodes/MetricsBase.h" +#include "core/state/Value.h" #include "core/state/UpdateController.h" #include "controllers/UpdatePolicyControllerService.h" #include "C2Payload.h" diff --git a/libminifi/include/c2/C2MetricsPublisher.h b/libminifi/include/c2/C2MetricsPublisher.h index 1aa6264391..4472a6de46 100644 --- a/libminifi/include/c2/C2MetricsPublisher.h +++ b/libminifi/include/c2/C2MetricsPublisher.h @@ -40,9 +40,9 @@ namespace org::apache::nifi::minifi::c2 { -class C2MetricsPublisher : public state::response::NodeReporter, public state::MetricsPublisher { +class C2MetricsPublisher : public state::response::NodeReporter, public state::MetricsPublisherImpl { public: - using MetricsPublisher::MetricsPublisher; + using MetricsPublisherImpl::MetricsPublisherImpl; MINIFIAPI static constexpr const char* Description = "Class that provides C2 metrics to the C2Agent"; diff --git a/libminifi/include/c2/C2Payload.h b/libminifi/include/c2/C2Payload.h index 09c90540f4..62a0971c5c 100644 --- a/libminifi/include/c2/C2Payload.h +++ b/libminifi/include/c2/C2Payload.h @@ -24,7 +24,7 @@ #include #include -#include "../core/state/Value.h" +#include "core/state/Value.h" #include "core/state/UpdateController.h" #include "utils/Enum.h" #include "utils/gsl.h" diff --git a/libminifi/include/c2/C2Protocol.h b/libminifi/include/c2/C2Protocol.h index d843afa60c..d7b016fb4b 100644 --- a/libminifi/include/c2/C2Protocol.h +++ b/libminifi/include/c2/C2Protocol.h @@ -32,10 +32,10 @@ namespace org::apache::nifi::minifi::c2 { /** * Defines a protocol to perform state management of the minifi agent. */ -class C2Protocol : public core::Connectable { +class C2Protocol : public core::ConnectableImpl { public: C2Protocol(std::string_view name, const utils::Identifier &uuid) - : core::Connectable(name, uuid), + : core::ConnectableImpl(name, uuid), running_(true) { } @@ -84,6 +84,7 @@ class C2Protocol : public core::Connectable { return running_.load(); } + using core::ConnectableImpl::waitForWork; /** * Block until work is available on any input connection, or the given duration elapses * @param timeoutMs timeout in milliseconds diff --git a/libminifi/include/c2/C2Trigger.h b/libminifi/include/c2/C2Trigger.h index 2c2f33209c..eb774a6506 100644 --- a/libminifi/include/c2/C2Trigger.h +++ b/libminifi/include/c2/C2Trigger.h @@ -35,10 +35,10 @@ namespace org::apache::nifi::minifi::c2 { * * The state machine expects triggered (yes ) -> getAction -> reset(optional) */ -class C2Trigger : public core::Connectable { +class C2Trigger : public core::ConnectableImpl { public: C2Trigger(std::string_view name, const utils::Identifier& uuid) - : core::Connectable(name, uuid) { + : core::ConnectableImpl(name, uuid) { } ~C2Trigger() override = default; diff --git a/libminifi/include/c2/ControllerSocketMetricsPublisher.h b/libminifi/include/c2/ControllerSocketMetricsPublisher.h index 1ae7a0cbcd..2b834865c1 100644 --- a/libminifi/include/c2/ControllerSocketMetricsPublisher.h +++ b/libminifi/include/c2/ControllerSocketMetricsPublisher.h @@ -24,14 +24,14 @@ #include "ControllerSocketReporter.h" #include "core/state/MetricsPublisher.h" -#include "core/logging/Logger.h" +#include "core/logging/LoggerFactory.h" #include "c2/HeartbeatJsonSerializer.h" namespace org::apache::nifi::minifi::c2 { -class ControllerSocketMetricsPublisher : public state::MetricsPublisher, public ControllerSocketReporter { +class ControllerSocketMetricsPublisher : public state::MetricsPublisherImpl, public ControllerSocketReporter { public: - using MetricsPublisher::MetricsPublisher; + using MetricsPublisherImpl::MetricsPublisherImpl; MINIFIAPI static constexpr const char* Description = "Provides the response nodes for c2 operations through localized environment through a simple TCP socket."; void clearMetricNodes() override; diff --git a/libminifi/include/c2/ControllerSocketProtocol.h b/libminifi/include/c2/ControllerSocketProtocol.h index 93c279a2ba..9383ec52a6 100644 --- a/libminifi/include/c2/ControllerSocketProtocol.h +++ b/libminifi/include/c2/ControllerSocketProtocol.h @@ -24,7 +24,7 @@ #include #include "io/BaseStream.h" -#include "core/logging/LoggerConfiguration.h" +#include "core/logging/LoggerFactory.h" #include "core/state/nodes/StateMonitor.h" #include "core/controller/ControllerServiceProvider.h" #include "ControllerSocketReporter.h" @@ -32,6 +32,7 @@ #include "asio/ip/tcp.hpp" #include "asio/ssl/context.hpp" #include "utils/net/AsioCoro.h" +#include "controllers/SSLContextService.h" namespace org::apache::nifi::minifi::c2 { diff --git a/libminifi/include/c2/HeartbeatReporter.h b/libminifi/include/c2/HeartbeatReporter.h index 0bcdfb0576..648add6d10 100644 --- a/libminifi/include/c2/HeartbeatReporter.h +++ b/libminifi/include/c2/HeartbeatReporter.h @@ -34,10 +34,10 @@ namespace org::apache::nifi::minifi::c2 { * Defines a heartbeat reporting interface. Note that this differs from * C2Protocol as heartbeats can be any interface which provides only one way communication. */ -class HeartbeatReporter : public core::Connectable { +class HeartbeatReporter : public core::ConnectableImpl { public: HeartbeatReporter(std::string_view name, const utils::Identifier& uuid) - : core::Connectable(name, uuid), + : core::ConnectableImpl(name, uuid), controller_(nullptr), update_sink_(nullptr), configuration_(nullptr) { diff --git a/libminifi/include/c2/PayloadParser.h b/libminifi/include/c2/PayloadParser.h deleted file mode 100644 index 01b70a58ed..0000000000 --- a/libminifi/include/c2/PayloadParser.h +++ /dev/null @@ -1,187 +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. - */ -#ifndef LIBMINIFI_INCLUDE_C2_PAYLOADPARSER_H_ -#define LIBMINIFI_INCLUDE_C2_PAYLOADPARSER_H_ - -#include -#include -#include - -#include "C2Payload.h" -#include "core/state/Value.h" - -namespace org { -namespace apache { -namespace nifi { -namespace minifi { -namespace c2 { - -class PayloadParseException : public std::runtime_error { - public: - PayloadParseException(const std::string &msg) // NOLINT - : std::runtime_error(msg) { - } -}; - -template -class convert_if_base { - protected: - const std::shared_ptr node_; - explicit convert_if_base(const std::shared_ptr &node) - : node_(node) { - } - public: - T operator()() const { - if (auto sub_type = std::dynamic_pointer_cast(node_)) - return sub_type->getValue(); - throw PayloadParseException("No known type"); - } -}; - -template -struct convert_if { - explicit convert_if(const std::shared_ptr& /*node*/) { - } - - - std::string operator()() const { - throw PayloadParseException("No known type"); - } -}; - -template<> -struct convert_if : public convert_if_base { - explicit convert_if(const std::shared_ptr &node) - : convert_if_base(node) { - } - - std::string operator()() const { - return node_->getStringValue(); - } -}; - -template<> -struct convert_if : public convert_if_base { - explicit convert_if(const std::shared_ptr &node) - : convert_if_base(node) { - } -}; - -template<> -struct convert_if : public convert_if_base { - explicit convert_if(const std::shared_ptr &node) - : convert_if_base(node) { - } -}; - -template<> -struct convert_if : public convert_if_base { - explicit convert_if(const std::shared_ptr &node) - : convert_if_base(node) { - } -}; - -template<> -struct convert_if : public convert_if_base { - explicit convert_if(const std::shared_ptr &node) - : convert_if_base(node) { - } -}; - -template<> -struct convert_if : public convert_if_base { - explicit convert_if(const std::shared_ptr &node) - : convert_if_base(node) { - } -}; - -/** - * Defines a fluent parser that uses Exception management for flow control. - * - * Note that this isn't functionally complete. - */ -class PayloadParser { - public: - static PayloadParser getInstance(const C2Payload &payload) { - return PayloadParser(payload); - } - - inline PayloadParser in(const std::string &payload) { - for (const auto &pl : ref_.getNestedPayloads()) { - if (pl.getLabel() == payload || pl.getIdentifier() == payload) { - return PayloadParser(pl); - } - } - throw PayloadParseException("Invalid payload. Could not find " + payload); - } - - template - inline void foreach(Functor f) { - for (const auto &component : ref_.getNestedPayloads()) { - f(component); - } - } - - template - inline T getAs(const std::string &field, const std::optional& fallback = std::nullopt) { - for (const auto &cmd : ref_.getContent()) { - if (auto it = cmd.operation_arguments.find(field); it != cmd.operation_arguments.end()) { - if (auto* val_node = it->second.valueNode()) { - return convert_if(val_node->getValue())(); - } - } - } - if (!fallback) { - std::stringstream ss; - ss << "Invalid Field. Could not find " << field << " in " << ref_.getLabel(); - throw PayloadParseException(ss.str()); - } - return fallback.value(); - } - - size_t getSize() const { - return ref_.getNestedPayloads().size(); - } - - /** - * Make these explicitly public. - */ - - PayloadParser(const PayloadParser &p) = delete; - const PayloadParser &operator=(const PayloadParser &p) = delete; - PayloadParser(PayloadParser &&parser) = default; - - private: - PayloadParser(const C2Payload &payload) // NOLINT - : ref_(payload) { - } - - const C2Payload &ref_; - - std::vector fields_; - - std::string component_to_get_; -}; - -} // namespace c2 -} // namespace minifi -} // namespace nifi -} // namespace apache -} // namespace org - -#endif // LIBMINIFI_INCLUDE_C2_PAYLOADPARSER_H_ diff --git a/libminifi/include/c2/protocols/RESTProtocol.h b/libminifi/include/c2/protocols/RESTProtocol.h index cb04a2de19..069c4966cc 100644 --- a/libminifi/include/c2/protocols/RESTProtocol.h +++ b/libminifi/include/c2/protocols/RESTProtocol.h @@ -25,6 +25,7 @@ #include "c2/C2Payload.h" #include "c2/HeartbeatJsonSerializer.h" #include "utils/gsl.h" +#include "core/logging/LoggerFactory.h" namespace org::apache::nifi::minifi::c2 { diff --git a/libminifi/include/c2/protocols/RESTSender.h b/libminifi/include/c2/protocols/RESTSender.h index 01f0619d27..4daf6e0cf0 100644 --- a/libminifi/include/c2/protocols/RESTSender.h +++ b/libminifi/include/c2/protocols/RESTSender.h @@ -23,7 +23,7 @@ #include "c2/C2Protocol.h" #include "c2/protocols/RESTProtocol.h" -#include "controllers/SSLContextService.h" +#include "minifi-cpp/controllers/SSLContextService.h" #include "http/HTTPClient.h" #include "utils/Enum.h" diff --git a/libminifi/include/c2/triggers/FileUpdateTrigger.h b/libminifi/include/c2/triggers/FileUpdateTrigger.h index 5831eb5fd4..902dfbf49d 100644 --- a/libminifi/include/c2/triggers/FileUpdateTrigger.h +++ b/libminifi/include/c2/triggers/FileUpdateTrigger.h @@ -34,12 +34,12 @@ namespace org::apache::nifi::minifi::c2 { * Design: Extends C2Trigger, and implements a trigger, action, reset state machine. Calling * triggered will check the file. */ -class FileUpdateTrigger : public C2Trigger { +class FileUpdateTrigger final : public C2Trigger { public: MINIFIAPI static constexpr const char* Description = "Defines a file update trigger when the last write time of a file has been changed."; - explicit FileUpdateTrigger(std::string name, const utils::Identifier &uuid = {}) - : C2Trigger(std::move(name), uuid), + explicit FileUpdateTrigger(const std::string_view name, const utils::Identifier &uuid = {}) + : C2Trigger(name, uuid), update_(false) { } diff --git a/libminifi/include/controllers/LinuxPowerManagementService.h b/libminifi/include/controllers/LinuxPowerManagementService.h deleted file mode 100644 index 65ccacf111..0000000000 --- a/libminifi/include/controllers/LinuxPowerManagementService.h +++ /dev/null @@ -1,168 +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 -#include -#include -#include -#include -#include "utils/StringUtils.h" -#include "io/validation.h" -#include "core/controller/ControllerService.h" -#include "core/logging/LoggerFactory.h" -#include "core/PropertyDefinition.h" -#include "core/PropertyDefinitionBuilder.h" -#include "core/PropertyType.h" -#include "ThreadManagementService.h" - -namespace org::apache::nifi::minifi::controllers { - -/** - * Purpose: Linux power management service uses a path for the battery level - * and the status ( charging/discharging ) - */ -class LinuxPowerManagerService : public ThreadManagementService { - public: - explicit LinuxPowerManagerService(std::string_view name, const utils::Identifier &uuid = {}) - : ThreadManagementService(name, uuid), - enabled_(false), - battery_level_(0), - wait_period_(0), - last_time_(0), - trigger_(0), - low_battery_trigger_(0) { - } - - explicit LinuxPowerManagerService(std::string_view name, const std::shared_ptr &configuration) - : LinuxPowerManagerService(name) { - setConfiguration(configuration); - initialize(); - } - - MINIFIAPI static constexpr const char* Description = "Linux power management service that enables control of power usage in the agent through Linux power management information. " - "Use name \"ThreadPoolManager\" to throttle battery consumption"; - - MINIFIAPI static constexpr auto BatteryCapacityPath = core::PropertyDefinitionBuilder<>::createProperty("Battery Capacity Path") - .withDescription("Path to the battery level") - .isRequired(true) - .withDefaultValue("/sys/class/power_supply/BAT0/capacity") - .build(); - MINIFIAPI static constexpr auto BatteryStatusPath = core::PropertyDefinitionBuilder<>::createProperty("Battery Status Path") - .withDescription("Path to the battery status ( Discharging/Battery )") - .isRequired(true) - .withDefaultValue("/sys/class/power_supply/BAT0/status") - .build(); - MINIFIAPI static constexpr auto BatteryStatusDischargeKeyword = core::PropertyDefinitionBuilder<>::createProperty("Battery Status Discharge") - .withDescription("Keyword to identify if battery is discharging") - .isRequired(true) - .withDefaultValue("Discharging") - .build(); - MINIFIAPI static constexpr auto TriggerThreshold = core::PropertyDefinitionBuilder<>::createProperty("Trigger Threshold") - .withDescription("Battery threshold before which we consider a slow reduction. Should be a number from 1-100") - .isRequired(true) - .withPropertyType(core::StandardPropertyTypes::INTEGER_TYPE) - .withDefaultValue("75") - .build(); - MINIFIAPI static constexpr auto LowBatteryThreshold = core::PropertyDefinitionBuilder<>::createProperty("Low Battery Threshold") - .withDescription("Battery threshold before which we will aggressively reduce. Should be a number from 1-100") - .isRequired(true) - .withPropertyType(core::StandardPropertyTypes::INTEGER_TYPE) - .withDefaultValue("50") - .build(); - MINIFIAPI static constexpr auto WaitPeriod = core::PropertyDefinitionBuilder<>::createProperty("Wait Period") - .withDescription("Decay between checking threshold and determining if a reduction is needed") - .isRequired(true) - .withPropertyType(core::StandardPropertyTypes::TIME_PERIOD_TYPE) - .withDefaultValue("100 ms") - .build(); - MINIFIAPI static constexpr auto Properties = std::to_array({ - BatteryCapacityPath, - BatteryStatusPath, - BatteryStatusDischargeKeyword, - TriggerThreshold, - LowBatteryThreshold, - WaitPeriod - }); - - - MINIFIAPI static constexpr bool SupportsDynamicProperties = false; - ADD_COMMON_VIRTUAL_FUNCTIONS_FOR_CONTROLLER_SERVICES - - /** - * 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. - */ - bool isAboveMax(int new_tasks) override; - - /** - * Returns the max number of threads allowed by all pools - * @return max threads. - */ - uint16_t getMaxThreads() override; - - /** - * 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. - */ - bool shouldReduce() override; - - /** - * Function to indicate to this controller service that we've reduced threads in a threadpool - */ - void reduce() override; - - /** - * Function to help callers identify if they can increase threads. - * @return true if QOS won't be breached. - */ - bool canIncrease() override; - - void initialize() override; - - void yield() override; - - bool isRunning() const override; - - bool isWorkAvailable() override; - - void onEnable() override; - - protected: - std::vector> paths_; - - bool enabled_; - - std::atomic battery_level_; - - std::atomic wait_period_; - - std::atomic last_time_; - - int trigger_; - - int low_battery_trigger_; - - std::string status_keyword_; - - private: - std::shared_ptr logger_ = core::logging::LoggerFactory::getLogger(uuid_); -}; - -} // namespace org::apache::nifi::minifi::controllers diff --git a/libminifi/include/controllers/NetworkPrioritizerService.h b/libminifi/include/controllers/NetworkPrioritizerService.h index 9d8f94a29f..c60c29fde6 100644 --- a/libminifi/include/controllers/NetworkPrioritizerService.h +++ b/libminifi/include/controllers/NetworkPrioritizerService.h @@ -40,12 +40,12 @@ namespace org::apache::nifi::minifi::controllers { /** * Purpose: Network prioritizer for selecting network interfaces through the flow configuration. */ -class NetworkPrioritizerService : public core::controller::ControllerService, public minifi::io::NetworkPrioritizer, public std::enable_shared_from_this { +class NetworkPrioritizerService : public core::controller::ControllerServiceImpl, public minifi::io::NetworkPrioritizer, public utils::EnableSharedFromThis { public: explicit NetworkPrioritizerService(std::string_view name, const utils::Identifier& uuid = {}, std::shared_ptr clock = std::make_shared()) - : ControllerService(name, uuid), + : ControllerServiceImpl(name, uuid), enabled_(false), max_throughput_(std::numeric_limits::max()), max_payload_(std::numeric_limits::max()), @@ -94,12 +94,12 @@ class NetworkPrioritizerService : public core::controller::ControllerService, pu .withDefaultValue("false") .build(); MINIFIAPI static constexpr auto Properties = std::to_array({ - NetworkControllers, - MaxThroughput, - MaxPayload, - VerifyInterfaces, - DefaultPrioritizer - }); + NetworkControllers, + MaxThroughput, + MaxPayload, + VerifyInterfaces, + DefaultPrioritizer + }); MINIFIAPI static constexpr bool SupportsDynamicProperties = false; diff --git a/libminifi/include/controllers/SSLContextService.h b/libminifi/include/controllers/SSLContextService.h index 6b62275fdf..1b906760bd 100644 --- a/libminifi/include/controllers/SSLContextService.h +++ b/libminifi/include/controllers/SSLContextService.h @@ -38,13 +38,14 @@ #include "utils/StringUtils.h" #include "utils/tls/ExtendedKeyUsage.h" #include "io/validation.h" -#include "../core/controller/ControllerService.h" +#include "core/controller/ControllerService.h" #include "core/logging/LoggerFactory.h" #include "core/PropertyDefinition.h" #include "core/PropertyDefinitionBuilder.h" #include "core/PropertyType.h" #include "utils/Export.h" #include "utils/tls/CertificateUtils.h" +#include "minifi-cpp/controllers/SSLContextService.h" namespace org::apache::nifi::minifi::controllers { @@ -70,16 +71,16 @@ class SSLContext { * Justification: Abstracts SSL support out of processors into a * configurable controller service. */ -class SSLContextService : public core::controller::ControllerService { +class SSLContextServiceImpl : public core::controller::ControllerServiceImpl, public SSLContextService { public: - explicit SSLContextService(std::string_view name, const utils::Identifier &uuid = {}) - : ControllerService(name, uuid), + explicit SSLContextServiceImpl(std::string_view name, const utils::Identifier &uuid = {}) + : ControllerServiceImpl(name, uuid), initialized_(false), logger_(core::logging::LoggerFactory::getLogger(uuid_)) { } - explicit SSLContextService(std::string_view name, const std::shared_ptr &configuration) - : ControllerService(name), + explicit SSLContextServiceImpl(std::string_view name, const std::shared_ptr &configuration) + : ControllerServiceImpl(name), initialized_(false), logger_(core::logging::LoggerFactory::getLogger(uuid_)) { setConfiguration(configuration); @@ -134,10 +135,10 @@ class SSLContextService : public core::controller::ControllerService { std::unique_ptr createSSLContext(); - const std::filesystem::path& getCertificateFile() const; - const std::string& getPassphrase() const; - const std::filesystem::path& getPrivateKeyFile() const; - const std::filesystem::path& getCACertificate() const; + const std::filesystem::path& getCertificateFile() const override; + const std::string& getPassphrase() const override; + const std::filesystem::path& getPrivateKeyFile() const override; + const std::filesystem::path& getCACertificate() const override; void yield() override { } @@ -150,14 +151,14 @@ class SSLContextService : public core::controller::ControllerService { return false; } - void setMinTlsVersion(long min_version) { // NOLINT(runtime/int) long due to SSL lib API + void setMinTlsVersion(long min_version) override { // NOLINT(runtime/int) long due to SSL lib API minimum_tls_version_ = min_version; } - void setMaxTlsVersion(long max_version) { // NOLINT(runtime/int) long due to SSL lib API + void setMaxTlsVersion(long max_version) override { // NOLINT(runtime/int) long due to SSL lib API maximum_tls_version_ = max_version; } - bool configure_ssl_context(SSL_CTX *ctx); + bool configure_ssl_context(void* ctx) override; void onEnable() override; @@ -224,12 +225,12 @@ class SSLContextService : public core::controller::ControllerService { #else std::to_array({ #endif // WIN32 - ClientCertificate, - PrivateKey, - Passphrase, - CACertificate, - UseSystemCertStore - }); + ClientCertificate, + PrivateKey, + Passphrase, + CACertificate, + UseSystemCertStore + }); MINIFIAPI static constexpr bool SupportsDynamicProperties = false; ADD_COMMON_VIRTUAL_FUNCTIONS_FOR_CONTROLLER_SERVICES diff --git a/libminifi/include/controllers/ThreadManagementService.h b/libminifi/include/controllers/ThreadManagementService.h index 2d3edd7ba6..bd13a99b64 100644 --- a/libminifi/include/controllers/ThreadManagementService.h +++ b/libminifi/include/controllers/ThreadManagementService.h @@ -27,6 +27,7 @@ #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 { @@ -34,58 +35,28 @@ 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 core::controller::ControllerService { +class ThreadManagementServiceImpl : public core::controller::ControllerServiceImpl, public virtual ThreadManagementService { public: - explicit ThreadManagementService(std::string_view name, const utils::Identifier &uuid = {}) - : ControllerService(name, uuid), + explicit ThreadManagementServiceImpl(std::string_view name, const utils::Identifier &uuid = {}) + : ControllerServiceImpl(name, uuid), logger_(core::logging::LoggerFactory::getLogger()) { } - explicit ThreadManagementService(std::string_view name, const std::shared_ptr& /*configuration*/) - : ControllerService(name), + explicit ThreadManagementServiceImpl(std::string_view name, const std::shared_ptr& /*configuration*/) + : ControllerServiceImpl(name), logger_(core::logging::LoggerFactory::getLogger()) { } - /** - * 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) { + void registerThreadCount(const int threads) override { thread_count_ += threads; } - /** - * Function to help callers identify if they can increase threads. - * @return true if QOS won't be breached. - */ - virtual bool canIncrease() = 0; - void initialize() override { - ControllerService::initialize(); + ControllerServiceImpl::initialize(); } void yield() override { diff --git a/libminifi/include/controllers/UpdatePolicyControllerService.h b/libminifi/include/controllers/UpdatePolicyControllerService.h index 1cc59f5193..562d78cca6 100644 --- a/libminifi/include/controllers/UpdatePolicyControllerService.h +++ b/libminifi/include/controllers/UpdatePolicyControllerService.h @@ -38,10 +38,10 @@ 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::ControllerService, public std::enable_shared_from_this { +class UpdatePolicyControllerService : public core::controller::ControllerServiceImpl { public: explicit UpdatePolicyControllerService(std::string_view name, const utils::Identifier &uuid = {}) - : ControllerService(name, uuid) { + : ControllerServiceImpl(name, uuid) { } explicit UpdatePolicyControllerService(std::string_view name, const std::shared_ptr &configuration) @@ -51,7 +51,7 @@ class UpdatePolicyControllerService : public core::controller::ControllerService } 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."; + "Since the flow dictates the purpose of a device it will also be used to dictate updates to specific components."; MINIFIAPI static constexpr auto AllowAllProperties = core::PropertyDefinitionBuilder<>::createProperty("Allow All Properties") .withDescription("Allows all properties, which are also not disallowed, to be updated") @@ -73,11 +73,11 @@ class UpdatePolicyControllerService : public core::controller::ControllerService .isRequired(false) .build(); MINIFIAPI static constexpr auto Properties = std::to_array({ - AllowAllProperties, - PersistUpdates, - AllowedProperties, - DisallowedProperties - }); + AllowAllProperties, + PersistUpdates, + AllowedProperties, + DisallowedProperties + }); MINIFIAPI static constexpr bool SupportsDynamicProperties = false; ADD_COMMON_VIRTUAL_FUNCTIONS_FOR_CONTROLLER_SERVICES diff --git a/libminifi/include/core/ClassLoader.h b/libminifi/include/core/ClassLoader.h deleted file mode 100644 index 96cbd1ba88..0000000000 --- a/libminifi/include/core/ClassLoader.h +++ /dev/null @@ -1,206 +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 -#include -#include -#include -#include -#include - -#include "core/Core.h" -#include "ObjectFactory.h" - -namespace org { -namespace apache { -namespace nifi { -namespace minifi { -namespace core { - -#define RESOURCE_FAILURE -1 - -#define RESOURCE_SUCCESS 1 - -#ifdef WIN32 -#define RTLD_LAZY 0 -#define RTLD_NOW 0 - -#define RTLD_GLOBAL (1 << 1) -#define RTLD_LOCAL (1 << 2) -#endif - -/** - * Processor class loader that accepts - * a variety of mechanisms to load in shared - * objects. - */ -class ClassLoader { - public: - static ClassLoader &getDefaultClassLoader(); - - /** - * Constructor. - */ - explicit ClassLoader(const std::string& name = "/"); - - /** - * Retrieves a class loader - * @param name name of class loader - * @return class loader reference - */ - ClassLoader& getClassLoader(const std::string& child_name); - - /** - * Register a class with the give ProcessorFactory - */ - void registerClass(const std::string &clazz, std::unique_ptr factory) { - std::lock_guard lock(internal_mutex_); - if (loaded_factories_.find(clazz) != loaded_factories_.end()) { - logger_->log_error("Class '{}' is already registered at '{}'", clazz, name_); - return; - } - logger_->log_trace("Registering class '{}' at '{}'", clazz, name_); - loaded_factories_.insert(std::make_pair(clazz, std::move(factory))); - } - - void unregisterClass(const std::string& clazz) { - std::lock_guard lock(internal_mutex_); - if (loaded_factories_.erase(clazz) == 0) { - logger_->log_error("Could not unregister non-registered class '{}' at '{}'", clazz, name_); - return; - } else { - logger_->log_trace("Unregistered class '{}' at '{}'", clazz, name_); - } - } - - std::optional getGroupForClass(const std::string &class_name) const { - std::lock_guard lock(internal_mutex_); - for (const auto& child_loader : class_loaders_) { - std::optional group = child_loader.second.getGroupForClass(class_name); - if (group) { - return group; - } - } - auto factory = loaded_factories_.find(class_name); - if (factory != loaded_factories_.end()) { - return factory->second->getGroupName(); - } - return {}; - } - - /** - * Return the names of all the registered classes in the group. - */ - std::vector getClasses(const std::string& group) const; - - /** - * Instantiate object based on class_name - * @param class_name class to create - * @param uuid uuid of object - * @return nullptr or object created from class_name definition. - */ - template - std::unique_ptr instantiate(const std::string &class_name, const std::string &name); - - /** - * Instantiate object based on class_name - * @param class_name class to create - * @param uuid uuid of object - * @return nullptr or object created from class_name definition. - */ - template - std::unique_ptr instantiate(const std::string &class_name, const utils::Identifier &uuid); - - /** - * Instantiate object based on class_name - * @param class_name class to create - * @param uuid uuid of object - * @return nullptr or object created from class_name definition. - */ - template - T *instantiateRaw(const std::string &class_name, const std::string &name); - - protected: - std::map> loaded_factories_; - - std::map class_loaders_; - - mutable std::mutex internal_mutex_; - - std::shared_ptr logger_; - - std::string name_; -}; - -template -std::unique_ptr ClassLoader::instantiate(const std::string &class_name, const std::string &name) { - std::lock_guard lock(internal_mutex_); - // allow subsequent classes to override functionality (like ProcessContextBuilder) - for (auto& child_loader : class_loaders_) { - if (auto result = child_loader.second.instantiate(class_name, name)) { - return result; - } - } - auto factory_entry = loaded_factories_.find(class_name); - if (factory_entry != loaded_factories_.end()) { - auto obj = factory_entry->second->create(name); - return utils::dynamic_unique_cast(std::move(obj)); - } - return nullptr; -} - -template -std::unique_ptr ClassLoader::instantiate(const std::string &class_name, const utils::Identifier &uuid) { - std::lock_guard lock(internal_mutex_); - // allow subsequent classes to override functionality (like ProcessContextBuilder) - for (auto& child_loader : class_loaders_) { - if (auto result = child_loader.second.instantiate(class_name, uuid)) { - return result; - } - } - auto factory_entry = loaded_factories_.find(class_name); - if (factory_entry != loaded_factories_.end()) { - auto obj = factory_entry->second->create(class_name, uuid); - return utils::dynamic_unique_cast(std::move(obj)); - } - return nullptr; -} - -template -T *ClassLoader::instantiateRaw(const std::string &class_name, const std::string &name) { - std::lock_guard lock(internal_mutex_); - // allow subsequent classes to override functionality (like ProcessContextBuilder) - for (auto& child_loader : class_loaders_) { - if (auto* result = child_loader.second.instantiateRaw(class_name, name)) { - return result; - } - } - auto factory_entry = loaded_factories_.find(class_name); - if (factory_entry != loaded_factories_.end()) { - auto obj = factory_entry->second->createRaw(name); - return dynamic_cast(obj); - } - return nullptr; -} - -} // namespace core -} // namespace minifi -} // namespace nifi -} // namespace apache -} // namespace org diff --git a/libminifi/include/core/FlowConfiguration.h b/libminifi/include/core/FlowConfiguration.h index c73f0d9347..9cbe93e81d 100644 --- a/libminifi/include/core/FlowConfiguration.h +++ b/libminifi/include/core/FlowConfiguration.h @@ -68,7 +68,7 @@ enum class FlowSerializationType { Json, NifiJson, Yaml }; * Purpose: Flow configuration defines the mechanism * by which we will configure our flow controller */ -class FlowConfiguration : public CoreComponent { +class FlowConfiguration : public CoreComponentImpl { public: /** * Constructor that will be used for configuring diff --git a/libminifi/include/core/FlowFile.h b/libminifi/include/core/FlowFile.h index c5ec7b813e..feb89b42e7 100644 --- a/libminifi/include/core/FlowFile.h +++ b/libminifi/include/core/FlowFile.h @@ -28,102 +28,104 @@ #include "utils/TimeUtil.h" #include "ResourceClaim.h" -#include "Connectable.h" +#include "core/Connectable.h" #include "WeakReference.h" -#include "utils/FlatMap.h" #include "utils/Export.h" +#include "minifi-cpp/core/FlowFile.h" namespace org::apache::nifi::minifi::core { class Connectable; -class FlowFile : public CoreComponent, public ReferenceContainer { +class FlowFileImpl : public CoreComponentImpl, public ReferenceContainerImpl, public virtual FlowFile { public: - FlowFile(); - FlowFile& operator=(const FlowFile& other); + FlowFileImpl(); + FlowFileImpl& operator=(const FlowFileImpl& other); - using AttributeMap = utils::FlatMap; + void copy(const FlowFile& other) override { + *this = *dynamic_cast(&other); + } /** * Returns a pointer to this flow file record's * claim */ - [[nodiscard]] std::shared_ptr getResourceClaim() const; + [[nodiscard]] std::shared_ptr getResourceClaim() const override; /** * Sets _claim to the inbound claim argument */ - void setResourceClaim(const std::shared_ptr& claim); + void setResourceClaim(const std::shared_ptr& claim) override; /** * clear the resource claim */ - void clearResourceClaim(); + void clearResourceClaim() override; /** * Returns a pointer to this flow file record's * claim at the given stash key */ - std::shared_ptr getStashClaim(const std::string& key); + std::shared_ptr getStashClaim(const std::string& key) override; /** * Sets the given stash key to the inbound claim argument */ - void setStashClaim(const std::string& key, const std::shared_ptr& claim); + void setStashClaim(const std::string& key, const std::shared_ptr& claim) override; /** * Clear the resource claim at the given stash key */ - void clearStashClaim(const std::string& key); + void clearStashClaim(const std::string& key) override; /** * Return true if the given stash claim exists */ - bool hasStashClaim(const std::string& key); + bool hasStashClaim(const std::string& key) override; /** * Get lineage identifiers */ - const std::vector& getlineageIdentifiers() const; - std::vector& getlineageIdentifiers(); + const std::vector& getlineageIdentifiers() const override; + std::vector& getlineageIdentifiers() override; /** * Returns whether or not this flow file record * is marked as deleted. * @return marked deleted */ - [[nodiscard]] bool isDeleted() const; + [[nodiscard]] bool isDeleted() const override; /** * Sets whether to mark this flow file record * as deleted * @param deleted deleted flag */ - void setDeleted(bool deleted); + void setDeleted(bool deleted) override; /** * Get entry date for this record * @return entry date uint64_t */ - [[nodiscard]] std::chrono::system_clock::time_point getEntryDate() const; + [[nodiscard]] std::chrono::system_clock::time_point getEntryDate() const override; /** * Gets the event time. * @return event time. */ - [[nodiscard]] std::chrono::system_clock::time_point getEventTime() const; + [[nodiscard]] std::chrono::system_clock::time_point getEventTime() const override; /** * Get lineage start date * @return lineage start date uint64_t */ - [[nodiscard]] std::chrono::system_clock::time_point getlineageStartDate() const; + [[nodiscard]] std::chrono::system_clock::time_point getlineageStartDate() const override; /** * Sets the lineage start date * @param date new lineage start date */ - void setLineageStartDate(std::chrono::system_clock::time_point date); + void setLineageStartDate(std::chrono::system_clock::time_point date) override; - void setLineageIdentifiers(const std::vector& lineage_Identifiers) { + void setLineageIdentifiers(const std::vector& lineage_Identifiers) override { lineage_Identifiers_ = lineage_Identifiers; } /** @@ -133,9 +135,9 @@ class FlowFile : public CoreComponent, public ReferenceContainer { * @param value value to set * @return result of finding key */ - bool getAttribute(std::string_view key, std::string& value) const; + bool getAttribute(std::string_view key, std::string& value) const override; - [[nodiscard]] std::optional getAttribute(std::string_view key) const; + [[nodiscard]] std::optional getAttribute(std::string_view key) const override; /** * Updates the value in the attribute map that corresponds @@ -144,19 +146,19 @@ class FlowFile : public CoreComponent, public ReferenceContainer { * @param value value to set to attribute name * @return result of finding key */ - bool updateAttribute(std::string_view key, const std::string& value); + bool updateAttribute(std::string_view key, const std::string& value) override; /** * Removes the attribute * @param key attribute name to remove * @return result of finding key */ - bool removeAttribute(std::string_view key); + bool removeAttribute(std::string_view key) override; /** * setAttribute, if attribute already there, update it, else, add it */ - bool setAttribute(std::string_view key, std::string value) { + bool setAttribute(std::string_view key, std::string value) override { return attributes_.insert_or_assign(std::string{key}, std::move(value)).second; } @@ -164,7 +166,7 @@ class FlowFile : public CoreComponent, public ReferenceContainer { * Returns the map of attributes * @return attributes. */ - [[nodiscard]] std::map getAttributes() const { + [[nodiscard]] std::map getAttributes() const override { return {attributes_.begin(), attributes_.end()}; } @@ -172,7 +174,7 @@ class FlowFile : public CoreComponent, public ReferenceContainer { * Returns the map of attributes * @return attributes. */ - AttributeMap *getAttributesPtr() { + AttributeMap *getAttributesPtr() override { return &attributes_; } @@ -180,26 +182,26 @@ class FlowFile : public CoreComponent, public ReferenceContainer { * adds an attribute if it does not exist * */ - bool addAttribute(std::string_view key, const std::string& value); + bool addAttribute(std::string_view key, const std::string& value) override; /** * Set the size of this record. * @param size size of record to set. */ - void setSize(const uint64_t size) { + void setSize(const uint64_t size) override { size_ = size; } /** * Returns the size of corresponding flow file * @return size as a uint64_t */ - [[nodiscard]] uint64_t getSize() const; + [[nodiscard]] uint64_t getSize() const override; /** * Sets the offset * @param offset offset to apply to this record. */ - void setOffset(const uint64_t offset) { + void setOffset(const uint64_t offset) override { offset_ = offset; } @@ -208,11 +210,11 @@ class FlowFile : public CoreComponent, public ReferenceContainer { to_be_processed_after_ = std::chrono::steady_clock::now() + duration; } - [[nodiscard]] std::chrono::steady_clock::time_point getPenaltyExpiration() const { + [[nodiscard]] std::chrono::steady_clock::time_point getPenaltyExpiration() const override { return to_be_processed_after_; } - void setPenaltyExpiration(std::chrono::time_point to_be_processed_after) { + void setPenaltyExpiration(std::chrono::time_point to_be_processed_after) override { to_be_processed_after_ = to_be_processed_after; } @@ -220,13 +222,13 @@ class FlowFile : public CoreComponent, public ReferenceContainer { * Gets the offset within the flow file * @return size as a uint64_t */ - [[nodiscard]] uint64_t getOffset() const; + [[nodiscard]] uint64_t getOffset() const override; - [[nodiscard]] bool isPenalized() const { + [[nodiscard]] bool isPenalized() const override { return to_be_processed_after_ > std::chrono::steady_clock::now(); } - [[nodiscard]] uint64_t getId() const { + [[nodiscard]] uint64_t getId() const override { return id_; } @@ -234,18 +236,18 @@ class FlowFile : public CoreComponent, public ReferenceContainer { * Sets the original connection with a shared pointer. * @param connection shared connection. */ - void setConnection(core::Connectable* connection); + void setConnection(core::Connectable* connection) override; /** * Returns the original connection referenced by this record. * @return shared original connection pointer. */ - [[nodiscard]] Connectable* getConnection() const; + [[nodiscard]] Connectable* getConnection() const override; - void setStoredToRepository(bool storedInRepository) { + void setStoredToRepository(bool storedInRepository) override { stored = storedInRepository; } - [[nodiscard]] bool isStored() const { + [[nodiscard]] bool isStored() const override { return stored; } @@ -289,32 +291,4 @@ class FlowFile : public CoreComponent, public ReferenceContainer { static std::shared_ptr numeric_id_generator_; }; -// FlowFile Attribute -struct SpecialFlowAttribute { - // The flowfile's path indicates the relative directory to which a FlowFile belongs and does not contain the filename - MINIFIAPI static constexpr std::string_view PATH = "path"; - // The flowfile's absolute path indicates the absolute directory to which a FlowFile belongs and does not contain the filename - MINIFIAPI static constexpr std::string_view ABSOLUTE_PATH = "absolute.path"; - // The filename of the FlowFile. The filename should not contain any directory structure. - MINIFIAPI static constexpr std::string_view FILENAME = "filename"; - // A unique UUID assigned to this FlowFile. - MINIFIAPI static constexpr std::string_view UUID = "uuid"; - // A numeric value indicating the FlowFile priority - MINIFIAPI static constexpr std::string_view priority = "priority"; - // The MIME Type of this FlowFile - MINIFIAPI static constexpr std::string_view MIME_TYPE = "mime.type"; - // Specifies the reason that a FlowFile is being discarded - MINIFIAPI static constexpr std::string_view DISCARD_REASON = "discard.reason"; - // Indicates an identifier other than the FlowFile's UUID that is known to refer to this FlowFile. - MINIFIAPI static constexpr std::string_view ALTERNATE_IDENTIFIER = "alternate.identifier"; - // Flow identifier - MINIFIAPI static constexpr std::string_view FLOW_ID = "flow.id"; - - static constexpr std::array getSpecialFlowAttributes() { - return { - PATH, ABSOLUTE_PATH, FILENAME, UUID, priority, MIME_TYPE, DISCARD_REASON, ALTERNATE_IDENTIFIER, FLOW_ID - }; - } -}; - } // namespace org::apache::nifi::minifi::core diff --git a/libminifi/include/core/ForwardingContentSession.h b/libminifi/include/core/ForwardingContentSession.h index 68459adaa4..b4b3f65ccc 100644 --- a/libminifi/include/core/ForwardingContentSession.h +++ b/libminifi/include/core/ForwardingContentSession.h @@ -22,7 +22,7 @@ #include #include "ResourceClaim.h" #include "io/BaseStream.h" -#include "ContentSession.h" +#include "core/ContentSession.h" namespace org::apache::nifi::minifi::core { @@ -32,7 +32,7 @@ class ContentRepository; * Warning: this implementation simply forwards all calls to the underlying * repository without any atomicity guarantees or possibility of rollback. */ -class ForwardingContentSession : public ContentSession { +class ForwardingContentSession : public ContentSessionImpl { public: explicit ForwardingContentSession(std::shared_ptr repository); diff --git a/libminifi/include/core/ParameterContext.h b/libminifi/include/core/ParameterContext.h index 1b795414cf..825d9ed1db 100644 --- a/libminifi/include/core/ParameterContext.h +++ b/libminifi/include/core/ParameterContext.h @@ -21,7 +21,7 @@ #include #include -#include "Core.h" +#include "core/Core.h" #include "Exception.h" namespace org::apache::nifi::minifi::core { @@ -39,9 +39,9 @@ struct Parameter { std::string value; }; -class ParameterContext : public CoreComponent { +class ParameterContext : public CoreComponentImpl { public: - using CoreComponent::CoreComponent; + using CoreComponentImpl::CoreComponentImpl; void setDescription(const std::string &description) { description_ = description; diff --git a/libminifi/include/core/ProcessGroup.h b/libminifi/include/core/ProcessGroup.h index 8f64ec2784..bb3b018b7e 100644 --- a/libminifi/include/core/ProcessGroup.h +++ b/libminifi/include/core/ProcessGroup.h @@ -29,7 +29,7 @@ #include #include -#include "Processor.h" +#include "minifi-cpp/core/Processor.h" #include "Exception.h" #include "TimerDrivenSchedulingAgent.h" #include "EventDrivenSchedulingAgent.h" @@ -61,7 +61,7 @@ enum ProcessGroupType { REMOTE_PROCESS_GROUP, }; -class ProcessGroup : public CoreComponent { +class ProcessGroup : public CoreComponentImpl { friend struct ::ProcessGroupTestAccessor; public: enum class Traverse { @@ -268,8 +268,7 @@ class ProcessGroup : public CoreComponent { mutable std::recursive_mutex mutex_; // Logger std::shared_ptr logger_; - // Prevent default copy constructor and assignment operation - // Only support pass by reference or pointer + ProcessGroup(const ProcessGroup &parent); ProcessGroup &operator=(const ProcessGroup &parent); static std::shared_ptr id_generator_; diff --git a/libminifi/include/core/ProcessSession.h b/libminifi/include/core/ProcessSession.h index 59130a7ce8..b424acbce4 100644 --- a/libminifi/include/core/ProcessSession.h +++ b/libminifi/include/core/ProcessSession.h @@ -30,135 +30,105 @@ #include #include -#include "ProcessContext.h" +#include "core/ProcessContext.h" #include "FlowFileRecord.h" #include "Exception.h" #include "core/logging/LoggerFactory.h" -#include "core/Deprecated.h" #include "FlowFile.h" #include "WeakReference.h" #include "provenance/Provenance.h" #include "utils/gsl.h" -#include "ProcessorMetrics.h" +#include "minifi-cpp/core/ProcessorMetrics.h" +#include "minifi-cpp/core/ProcessSession.h" -namespace org::apache::nifi::minifi::core { -namespace detail { -struct ReadBufferResult { - int64_t status; - std::vector buffer; -}; +namespace org::apache::nifi::minifi::core::detail { std::string to_string(const ReadBufferResult& read_buffer_result); -} // namespace detail -// ProcessSession Class -class ProcessSession : public ReferenceContainer { +} // namespace org::apache::nifi::minifi::core::detail + +namespace org::apache::nifi::minifi::core { + +class ProcessSessionImpl : public ReferenceContainerImpl, public virtual ProcessSession { public: - // Constructor - /*! - * Create a new process session - */ - explicit ProcessSession(std::shared_ptr processContext); - - // Destructor - virtual ~ProcessSession(); - - // Commit the session - void commit(); - // Roll Back the session - void rollback(); - - nonstd::expected rollbackNoThrow() noexcept; - // Get Provenance Report - std::shared_ptr getProvenanceReporter() { + explicit ProcessSessionImpl(std::shared_ptr processContext); + + ~ProcessSessionImpl() override; + void commit() override; + void rollback() override; + + nonstd::expected rollbackNoThrow() noexcept override; + + std::shared_ptr getProvenanceReporter() override { return provenance_report_; } - // writes the created contents to the underlying repository - void flushContent(); - - virtual std::shared_ptr get(); - - std::shared_ptr create(const core::FlowFile* const parent = nullptr); - virtual void add(const std::shared_ptr &record); - std::shared_ptr clone(const core::FlowFile& parent); - std::shared_ptr clone(const core::FlowFile& parent, int64_t offset, int64_t size); - // Transfer the FlowFile to the relationship - virtual void transfer(const std::shared_ptr& flow, const Relationship& relationship); - void transferToCustomRelationship(const std::shared_ptr& flow, const std::string& relationship_name); - - void putAttribute(core::FlowFile& flow, std::string_view key, const std::string& value); - void removeAttribute(core::FlowFile& flow, std::string_view key); - - void remove(const std::shared_ptr &flow); - // Access the contents of the flow file as an input stream; returns null if the flow file has no content claim - std::shared_ptr getFlowFileContentStream(const core::FlowFile& flow_file); - // Execute the given read callback against the content - int64_t read(const std::shared_ptr& flow_file, const io::InputStreamCallback& callback); - - int64_t read(const core::FlowFile& flow_file, const io::InputStreamCallback& callback); - // Read content into buffer - detail::ReadBufferResult readBuffer(const std::shared_ptr& flow); - // Execute the given write callback against the content - void write(const std::shared_ptr &flow, const io::OutputStreamCallback& callback); - - void write(core::FlowFile& flow, const io::OutputStreamCallback& callback); + + void flushContent() override; + + std::shared_ptr get() override; + + std::shared_ptr create(const core::FlowFile* const parent = nullptr) override; + void add(const std::shared_ptr &record) override; + std::shared_ptr clone(const core::FlowFile& parent) override; + std::shared_ptr clone(const core::FlowFile& parent, int64_t offset, int64_t size) override; + + void transfer(const std::shared_ptr& flow, const Relationship& relationship) override; + void transferToCustomRelationship(const std::shared_ptr& flow, const std::string& relationship_name) override; + + void putAttribute(core::FlowFile& flow, std::string_view key, const std::string& value) override; + void removeAttribute(core::FlowFile& flow, std::string_view key) override; + + void remove(const std::shared_ptr &flow) override; + + std::shared_ptr getFlowFileContentStream(const core::FlowFile& flow_file) override; + + int64_t read(const std::shared_ptr& flow_file, const io::InputStreamCallback& callback) override; + + int64_t read(const core::FlowFile& flow_file, const io::InputStreamCallback& callback) override; + + detail::ReadBufferResult readBuffer(const std::shared_ptr& flow) override; + + void write(const std::shared_ptr &flow, const io::OutputStreamCallback& callback) override; + + void write(core::FlowFile& flow, const io::OutputStreamCallback& callback) override; // Read and write the flow file at the same time (eg. for processing it line by line) - int64_t readWrite(const std::shared_ptr &flow, const io::InputOutputStreamCallback& callback); - // Replace content with buffer - void writeBuffer(const std::shared_ptr& flow_file, std::span buffer); - void writeBuffer(const std::shared_ptr& flow_file, std::span buffer); - // Execute the given write/append callback against the content - void append(const std::shared_ptr &flow, const io::OutputStreamCallback& callback); - // Append buffer to content - void appendBuffer(const std::shared_ptr& flow, std::span buffer); - void appendBuffer(const std::shared_ptr& flow, std::span buffer); - // Penalize the flow - void penalize(const std::shared_ptr &flow); - - bool outgoingConnectionsFull(const std::string& relationship); - - /** - * Imports a file from the data stream - * @param stream incoming data stream that contains the data to store into a file - * @param flow flow file - */ - void importFrom(io::InputStream &stream, const std::shared_ptr &flow); - void importFrom(io::InputStream&& stream, const std::shared_ptr &flow); - - // import from the data source. - void import(const std::string& source, const std::shared_ptr &flow, bool keepSource = true, uint64_t offset = 0); - DEPRECATED(/*deprecated in*/ 0.7.0, /*will remove in */ 2.0) void import(const std::string& source, std::vector> &flows, bool keepSource, uint64_t offset, char inputDelimiter); // NOLINT - DEPRECATED(/*deprecated in*/ 0.8.0, /*will remove in */ 2.0) void import(const std::string& source, std::vector> &flows, uint64_t offset, char inputDelimiter); - - /** - * Exports the data stream to a file - * @param string file to export stream to - * @param flow flow file - * @param bool whether or not to keep the content in the flow file - */ - bool exportContent(const std::string &destination, const std::shared_ptr &flow, - bool keepContent); - - bool exportContent(const std::string &destination, const std::string &tmpFileName, const std::shared_ptr &flow, - bool keepContent); - - // Stash the content to a key - void stash(const std::string &key, const std::shared_ptr &flow); - // Restore content previously stashed to a key - void restore(const std::string &key, const std::shared_ptr &flow); - - bool existsFlowFileInRelationship(const Relationship &relationship); - - void setMetrics(const std::shared_ptr& metrics) { + int64_t readWrite(const std::shared_ptr &flow, const io::InputOutputStreamCallback& callback) override; + + void writeBuffer(const std::shared_ptr& flow_file, std::span buffer) override; + void writeBuffer(const std::shared_ptr& flow_file, std::span buffer) override; + + void append(const std::shared_ptr &flow, const io::OutputStreamCallback& callback) override; + + void appendBuffer(const std::shared_ptr& flow, std::span buffer) override; + void appendBuffer(const std::shared_ptr& flow, std::span buffer) override; + + void penalize(const std::shared_ptr &flow) override; + + bool outgoingConnectionsFull(const std::string& relationship) override; + + void importFrom(io::InputStream &stream, const std::shared_ptr &flow) override; + void importFrom(io::InputStream&& stream, const std::shared_ptr &flow) override; + + void import(const std::string& source, const std::shared_ptr &flow, bool keepSource = true, uint64_t offset = 0) override; + + bool exportContent(const std::string &destination, const std::shared_ptr &flow, bool keepContent) override; + + bool exportContent(const std::string &destination, const std::string &tmpFileName, const std::shared_ptr &flow, bool keepContent) override; + + void stash(const std::string &key, const std::shared_ptr &flow) override; + + void restore(const std::string &key, const std::shared_ptr &flow) override; + + bool existsFlowFileInRelationship(const Relationship &relationship) override; + + void setMetrics(const std::shared_ptr& metrics) override { metrics_ = metrics; } - bool hasBeenTransferred(const core::FlowFile &flow) const; + bool hasBeenTransferred(const core::FlowFile &flow) const override; -// Prevent default copy constructor and assignment operation -// Only support pass by reference or pointer - ProcessSession(const ProcessSession &parent) = delete; - ProcessSession &operator=(const ProcessSession &parent) = delete; + ProcessSessionImpl(const ProcessSessionImpl &parent) = delete; + ProcessSessionImpl &operator=(const ProcessSessionImpl &parent) = delete; protected: struct FlowFileUpdate { @@ -208,17 +178,11 @@ class ProcessSession : public ReferenceContainer { void ensureNonNullResourceClaim( const std::map>>& transactionMap); - // Clone the flow file during transfer to multiple connections for a relationship std::shared_ptr cloneDuringTransfer(const core::FlowFile& parent); - // ProcessContext std::shared_ptr process_context_; - // Logger std::shared_ptr logger_; - // Provenance Report std::shared_ptr provenance_report_; - std::shared_ptr content_session_; - StateManager* stateManager_; static std::shared_ptr id_generator_; diff --git a/libminifi/include/core/ProcessSessionFactory.h b/libminifi/include/core/ProcessSessionFactory.h index 482fe0a7a2..fae0fb1ed8 100644 --- a/libminifi/include/core/ProcessSessionFactory.h +++ b/libminifi/include/core/ProcessSessionFactory.h @@ -17,49 +17,31 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#ifndef LIBMINIFI_INCLUDE_CORE_PROCESSSESSIONFACTORY_H_ -#define LIBMINIFI_INCLUDE_CORE_PROCESSSESSIONFACTORY_H_ +#pragma once #include -#include "ProcessContext.h" +#include "minifi-cpp/core/ProcessContext.h" #include "ProcessSession.h" +#include "minifi-cpp/core/ProcessSessionFactory.h" -namespace org { -namespace apache { -namespace nifi { -namespace minifi { -namespace core { +namespace org::apache::nifi::minifi::core { -// ProcessSessionFactory Class -class ProcessSessionFactory { +class ProcessSessionFactoryImpl : public virtual ProcessSessionFactory { public: - // Constructor - /*! - * Create a new process session factory - */ - explicit ProcessSessionFactory(std::shared_ptr processContext) + explicit ProcessSessionFactoryImpl(std::shared_ptr processContext) : process_context_(processContext) { } - // Create the session - virtual std::shared_ptr createSession(); + std::shared_ptr createSession() override; - // Prevent default copy constructor and assignment operation - // Only support pass by reference or pointer - ProcessSessionFactory(const ProcessSessionFactory &parent) = delete; - ProcessSessionFactory &operator=(const ProcessSessionFactory &parent) = delete; + ProcessSessionFactoryImpl(const ProcessSessionFactoryImpl &parent) = delete; + ProcessSessionFactoryImpl &operator=(const ProcessSessionFactoryImpl &parent) = delete; - virtual ~ProcessSessionFactory() = default; + ~ProcessSessionFactoryImpl() override = default; private: - // ProcessContext std::shared_ptr process_context_; }; -} // namespace core -} // namespace minifi -} // namespace nifi -} // namespace apache -} // namespace org -#endif // LIBMINIFI_INCLUDE_CORE_PROCESSSESSIONFACTORY_H_ +} // namespace org::apache::nifi::minifi::core diff --git a/libminifi/include/core/ProcessorNode.h b/libminifi/include/core/ProcessorNode.h index b39bef83d4..881298fe22 100644 --- a/libminifi/include/core/ProcessorNode.h +++ b/libminifi/include/core/ProcessorNode.h @@ -23,26 +23,27 @@ #include #include -#include "ConfigurableComponent.h" -#include "Connectable.h" -#include "Property.h" +#include "core/ConfigurableComponent.h" +#include "core/Connectable.h" +#include "core/Property.h" +#include "minifi-cpp/core/ProcessorNode.h" namespace org::apache::nifi::minifi::core { /** * Processor node functions as a pass through to the implementing Connectables */ -class ProcessorNode : public ConfigurableComponent, public Connectable { +class ProcessorNodeImpl : public ConfigurableComponentImpl, public ConnectableImpl, public virtual ProcessorNode { public: - explicit ProcessorNode(Connectable* processor); + explicit ProcessorNodeImpl(Connectable* processor); - ProcessorNode(const ProcessorNode &other) = delete; - ProcessorNode(ProcessorNode &&other) = delete; + ProcessorNodeImpl(const ProcessorNodeImpl &other) = delete; + ProcessorNodeImpl(ProcessorNodeImpl &&other) = delete; - ~ProcessorNode() override; + ~ProcessorNodeImpl() override; - ProcessorNode& operator=(const ProcessorNode &other) = delete; - ProcessorNode& operator=(ProcessorNode &&other) = delete; + ProcessorNodeImpl& operator=(const ProcessorNodeImpl &other) = delete; + ProcessorNodeImpl& operator=(ProcessorNodeImpl &&other) = delete; /** * Get property using the provided name. @@ -50,7 +51,7 @@ class ProcessorNode : public ConfigurableComponent, public Connectable { * @param value value passed in by reference * @return result of getting property. */ - Connectable* getProcessor() const { + Connectable* getProcessor() const override { return processor_; } @@ -70,7 +71,7 @@ class ProcessorNode : public ConfigurableComponent, public Connectable { if (nullptr != processor_cast) { return processor_cast->getProperty(name, value); } else { - return ConfigurableComponent::getProperty(name, value); + return ConfigurableComponentImpl::getProperty(name, value); } } /** @@ -79,9 +80,9 @@ class ProcessorNode : public ConfigurableComponent, public Connectable { * @param value property value. * @return result of setting property. */ - bool setProperty(const std::string &name, const std::string& value) { + bool setProperty(const std::string &name, const std::string& value) override { const auto processor_cast = dynamic_cast(processor_); - bool ret = ConfigurableComponent::setProperty(name, value); + bool ret = ConfigurableComponentImpl::setProperty(name, value); if (nullptr != processor_cast) ret = processor_cast->setProperty(name, value); @@ -94,12 +95,12 @@ class ProcessorNode : public ConfigurableComponent, public Connectable { * @param value value passed in by reference * @return result of getting property. */ - bool getDynamicProperty(const std::string name, std::string &value) const { + bool getDynamicProperty(const std::string& name, std::string &value) const override { const auto processor_cast = dynamic_cast(processor_); if (processor_cast) { return processor_cast->getDynamicProperty(name, value); } else { - return ConfigurableComponent::getDynamicProperty(name, value); + return ConfigurableComponentImpl::getDynamicProperty(name, value); } } @@ -121,9 +122,9 @@ class ProcessorNode : public ConfigurableComponent, public Connectable { * @param value property value. * @return result of setting property. */ - bool setDynamicProperty(const std::string& name, const std::string& value) { + bool setDynamicProperty(const std::string& name, const std::string& value) override { const auto processor_cast = dynamic_cast(processor_); - auto ret = ConfigurableComponent::setDynamicProperty(name, value); + auto ret = ConfigurableComponentImpl::setDynamicProperty(name, value); if (processor_cast) { ret = processor_cast->setDynamicProperty(name, value); @@ -138,12 +139,12 @@ class ProcessorNode : public ConfigurableComponent, public Connectable { * @param value value passed in by reference * @return result of getting property. */ - std::vector getDynamicPropertyKeys() const { + std::vector getDynamicPropertyKeys() const override { const auto processor_cast = dynamic_cast(processor_); if (processor_cast) { return processor_cast->getDynamicPropertyKeys(); } else { - return ConfigurableComponent::getDynamicPropertyKeys(); + return ConfigurableComponentImpl::getDynamicPropertyKeys(); } } @@ -153,24 +154,28 @@ class ProcessorNode : public ConfigurableComponent, public Connectable { * @param value property value. * @return whether property was set or not */ - bool setProperty(const Property &prop, const std::string& value) { + bool setProperty(const Property &prop, const std::string& value) override { const auto processor_cast = dynamic_cast(processor_); - bool ret = ConfigurableComponent::setProperty(prop, value); + bool ret = ConfigurableComponentImpl::setProperty(prop, value); if (nullptr != processor_cast) ret = processor_cast->setProperty(prop, value); return ret; } - void setAutoTerminatedRelationships(std::vector relationships) { + void setAutoTerminatedRelationships(std::span relationships) override { processor_->setAutoTerminatedRelationships(relationships); } - bool isAutoTerminated(const Relationship& relationship) { + void setAutoTerminatedRelationships(std::vector relationships) { + setAutoTerminatedRelationships(std::span(relationships)); + } + + bool isAutoTerminated(const Relationship& relationship) override { return processor_->isAutoTerminated(relationship); } - bool isSupportedRelationship(const Relationship& relationship) { + bool isSupportedRelationship(const Relationship& relationship) override { return processor_->isSupportedRelationship(relationship); } @@ -179,7 +184,7 @@ class ProcessorNode : public ConfigurableComponent, public Connectable { * @param name */ void setName(std::string name) override { - Connectable::setName(name); + ConnectableImpl::setName(name); processor_->setName(std::move(name)); } @@ -188,11 +193,11 @@ class ProcessorNode : public ConfigurableComponent, public Connectable { * @param uuid uuid to apply to the internal representation. */ void setUUID(const utils::Identifier& uuid) override { - Connectable::setUUID(uuid); + ConnectableImpl::setUUID(uuid); processor_->setUUID(uuid); } - std::chrono::milliseconds getPenalizationPeriod() { + std::chrono::milliseconds getPenalizationPeriod() const override { return processor_->getPenalizationPeriod(); } @@ -208,7 +213,7 @@ class ProcessorNode : public ConfigurableComponent, public Connectable { * Get next incoming connection * @return next incoming connection */ - Connectable* getNextIncomingConnection() { + Connectable* getNextIncomingConnection() override { return processor_->getNextIncomingConnection(); } @@ -219,7 +224,7 @@ class ProcessorNode : public ConfigurableComponent, public Connectable { /** * @return true if incoming connections > 0 */ - bool hasIncomingConnections() { + bool hasIncomingConnections() const override { return processor_->hasIncomingConnections(); } @@ -228,7 +233,7 @@ class ProcessorNode : public ConfigurableComponent, public Connectable { * @param uuid uuid struct to which we will copy the memory * @return success of request */ - utils::Identifier getUUID() const { + utils::Identifier getUUID() const override { return processor_->getUUID(); } @@ -236,7 +241,7 @@ class ProcessorNode : public ConfigurableComponent, public Connectable { * Return the UUID string * @return the UUID str */ - utils::SmallString<36> getUUIDStr() const { + utils::SmallString<36> getUUIDStr() const override { return processor_->getUUIDStr(); } @@ -245,7 +250,7 @@ class ProcessorNode : public ConfigurableComponent, public Connectable { return processor_->getName(); } - uint8_t getMaxConcurrentTasks() { + uint8_t getMaxConcurrentTasks() const override { return processor_->getMaxConcurrentTasks(); } diff --git a/libminifi/include/core/PropertyValue.h b/libminifi/include/core/PropertyValue.h deleted file mode 100644 index 50edf41ad4..0000000000 --- a/libminifi/include/core/PropertyValue.h +++ /dev/null @@ -1,259 +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 -#include -#include -#include - -#include "CachedValueValidator.h" -#include "ValidationResult.h" -#include "state/Value.h" -#include "TypedValues.h" - -namespace org::apache::nifi::minifi::core { - -class PropertyValidator; - -static inline std::shared_ptr convert(const std::shared_ptr &prior, const std::string &ref) { - if (prior->getTypeIndex() == state::response::Value::UINT64_TYPE) { - // there are specializations, so check them first - if (std::dynamic_pointer_cast(prior)) { - return std::make_shared(ref); - } else if (std::dynamic_pointer_cast(prior)) { - return std::make_shared(ref); - } else if (std::dynamic_pointer_cast(prior)) { - return std::make_shared(ref); - } else { - return std::make_shared(ref); - } - } else if (prior->getTypeIndex() == state::response::Value::INT64_TYPE) { - return std::make_shared(ref); - } else if (prior->getTypeIndex() == state::response::Value::UINT32_TYPE) { - return std::make_shared(ref); - } else if (prior->getTypeIndex() == state::response::Value::INT_TYPE) { - return std::make_shared(ref); - } else if (prior->getTypeIndex() == state::response::Value::BOOL_TYPE) { - return std::make_shared(ref); - } else if (prior->getTypeIndex() == state::response::Value::DOUBLE_TYPE) { - return std::make_shared(ref); - } else { - return std::make_shared(ref); - } -} - -/** - * Purpose and Design: PropertyValue extends ValueNode, bringing with it value_. - * The reason for this is that there are additional features to support validation - * and value translation. - */ -class PropertyValue : public state::response::ValueNode { - using CachedValueValidator = internal::CachedValueValidator; - - public: - PropertyValue() - : type_id(std::type_index(typeid(std::string))) {} - - PropertyValue(const PropertyValue &o) = default; - PropertyValue(PropertyValue &&o) noexcept = default; - - template - static PropertyValue parse(std::string_view input, const PropertyValidator& validator) { - PropertyValue property_value; - property_value.value_ = std::make_shared(std::string{input}); - property_value.type_id = property_value.value_->getTypeIndex(); - property_value.cached_value_validator_ = validator; - return property_value; - } - - void setValidator(const PropertyValidator& validator) { - cached_value_validator_ = validator; - } - - ValidationResult validate(const std::string &subject) const { - return cached_value_validator_.validate(subject, getValue()); - } - - operator uint64_t() const { - return convertImpl("uint64_t"); - } - - operator int64_t() const { - return convertImpl("int64_t"); - } - - operator uint32_t() const { - return convertImpl("uint32_t"); - } - - operator int() const { - return convertImpl("int"); - } - - operator bool() const { - return convertImpl("bool"); - } - - operator double() const { - return convertImpl("double"); - } - - const char* c_str() const { - if (!isValueUsable()) { - throw utils::internal::InvalidValueException("Cannot convert invalid value"); - } - return value_ ? value_->c_str() : ""; - } - - operator std::string() const { - if (!isValueUsable()) { - throw utils::internal::InvalidValueException("Cannot convert invalid value"); - } - return to_string(); - } - - PropertyValue &operator=(PropertyValue &&o) = default; - PropertyValue &operator=(const PropertyValue &o) = default; - - std::type_index getTypeInfo() const { - return type_id; - } - /** - * Define the representations and eventual storage relationships through - * createValue - */ - template - auto operator=(const T ref) -> typename std::enable_if::value, PropertyValue&>::type { - cached_value_validator_.invalidateCachedResult(); - return WithAssignmentGuard(ref, [&] () -> PropertyValue& { - if (value_ == nullptr) { - type_id = std::type_index(typeid(T)); - value_ = minifi::state::response::createValue(ref); - } else { - type_id = std::type_index(typeid(T)); - auto ret = convert(value_, ref); - if (ret != nullptr) { - value_ = ret; - } else { - /** - * This is a protection mechanism that allows us to fail properties that are strictly defined. - * To maintain backwards compatibility we allow strings to be set by way of the internal API - * We then rely on the developer of the processor to perform the conversion. We want to get away from - * this, so this exception will throw an exception, forcefully, when they specify types in properties. - */ - throw utils::internal::ConversionException("Invalid conversion"); - } - } - return *this; - }); - } - - template - auto operator=(const T ref) -> typename std::enable_if::value || - std::is_same::value || - std::is_same::value || - std::is_same::value || - std::is_same::value, PropertyValue&>::type { - cached_value_validator_.invalidateCachedResult(); - if (value_ == nullptr) { - type_id = std::type_index(typeid(T)); - value_ = minifi::state::response::createValue(ref); - } else { - if (std::dynamic_pointer_cast(value_)) { - value_ = std::make_shared(ref); - type_id = DataSizeValue::type_id; - } else if (std::dynamic_pointer_cast(value_)) { - value_ = std::make_shared(ref); - type_id = DataTransferSpeedValue::type_id; - } else if (std::dynamic_pointer_cast(value_)) { - value_ = std::make_shared(ref); - type_id = TimePeriodValue::type_id; - } else if (type_id == std::type_index(typeid(T))) { - value_ = minifi::state::response::createValue(ref); - } else { - // this is not the place to perform translation. There are other places within - // the code where we can do assignments and transformations from "10" to (int)10; - throw utils::internal::ConversionException("Assigning invalid types"); - } - } - return *this; - } - - template - auto operator=(const T ref) -> typename std::enable_if< - std::is_same::value || - std::is_same::value, PropertyValue&>::type { - // translated these into strings - return operator=(std::string(ref)); - } - - template - auto operator=(const std::string &ref) -> typename std::enable_if< - std::is_same::value || - std::is_same::value || - std::is_same::value, PropertyValue&>::type { - cached_value_validator_.invalidateCachedResult(); - return WithAssignmentGuard(ref, [&] () -> PropertyValue& { - value_ = std::make_shared(ref); - type_id = value_->getTypeIndex(); - return *this; - }); - } - - private: - template - T convertImpl(const char* const type_name) const { - if (!isValueUsable()) { - throw utils::internal::InvalidValueException("Cannot convert invalid value"); - } - T res; - if (value_->convertValue(res)) { - return res; - } - throw utils::internal::ConversionException(std::string("Invalid conversion to ") + type_name + " for " + value_->getStringValue()); - } - - bool isValueUsable() const { - if (!value_) return false; - return validate("__unknown__").valid; - } - - template - auto WithAssignmentGuard(const std::string& ref, Fn&& functor) -> decltype(std::forward(functor)()) { - // TODO(adebreceni): as soon as c++17 comes jump to a RAII implementation - // as we will need std::uncaught_exceptions() - try { - return std::forward(functor)(); - } catch(const utils::internal::ValueException&) { - type_id = std::type_index(typeid(std::string)); - value_ = minifi::state::response::createValue(ref); - throw; - } - } - - protected: - std::type_index type_id; - CachedValueValidator cached_value_validator_; -}; - -inline std::string conditional_conversion(const PropertyValue &v) { - return v.getValue()->getStringValue(); -} - -} // namespace org::apache::nifi::minifi::core diff --git a/libminifi/include/core/RepositoryFactory.h b/libminifi/include/core/RepositoryFactory.h index 352dec51f4..3eda7b0ea1 100644 --- a/libminifi/include/core/RepositoryFactory.h +++ b/libminifi/include/core/RepositoryFactory.h @@ -23,7 +23,7 @@ #include "core/ContentRepository.h" #include "core/Repository.h" -#include "Core.h" +#include "core/Core.h" namespace org::apache::nifi::minifi::core { diff --git a/libminifi/include/core/SerializableComponent.h b/libminifi/include/core/SerializableComponent.h index 78676f39a3..e1e9c8a98e 100644 --- a/libminifi/include/core/SerializableComponent.h +++ b/libminifi/include/core/SerializableComponent.h @@ -24,19 +24,15 @@ #include "utils/gsl.h" #include "io/InputStream.h" #include "io/OutputStream.h" +#include "minifi-cpp/core/SerializableComponent.h" namespace org::apache::nifi::minifi::core { -class SerializableComponent : public core::CoreComponent { +class SerializableComponentImpl : public core::CoreComponentImpl, public virtual SerializableComponent { public: - explicit SerializableComponent(std::string_view name) - : core::CoreComponent(name) { + explicit SerializableComponentImpl(std::string_view name) + : core::CoreComponentImpl(name) { } - - ~SerializableComponent() override = default; - - virtual bool serialize(io::OutputStream& output_stream) = 0; - virtual bool deserialize(io::InputStream &input_stream) = 0; }; } // namespace org::apache::nifi::minifi::core diff --git a/libminifi/include/core/WeakReference.h b/libminifi/include/core/WeakReference.h index 115562de30..be7a27bc6b 100644 --- a/libminifi/include/core/WeakReference.h +++ b/libminifi/include/core/WeakReference.h @@ -16,37 +16,16 @@ * limitations under the License. */ -#ifndef LIBMINIFI_INCLUDE_CORE_WEAKREFERENCE_H_ -#define LIBMINIFI_INCLUDE_CORE_WEAKREFERENCE_H_ +#pragma once #include #include #include -namespace org { -namespace apache { -namespace nifi { -namespace minifi { -namespace core { +#include "minifi-cpp/core/WeakReference.h" -/* - * An homage to weak references in java, this acts as a class - * which can be used to remove referenced classes when needed. - */ -class WeakReference { - public: - WeakReference(const WeakReference &other) = delete; - WeakReference(WeakReference &&other) = default; - WeakReference &operator=(const WeakReference &other) = delete; - WeakReference &operator=(WeakReference &&other) = default; - - virtual ~WeakReference() = default; - - virtual void remove() = 0; - protected: - WeakReference() = default; -}; +namespace org::apache::nifi::minifi::core { /** * Reference container is a vector of weak references that enables @@ -56,23 +35,23 @@ class WeakReference { * the WeakReferences to be referenced counts. The "weak" aspect * originates from and is defined by the corresponding object. */ -class ReferenceContainer { +class ReferenceContainerImpl : public virtual ReferenceContainer { public: - ReferenceContainer() = default; + ReferenceContainerImpl() = default; - ~ReferenceContainer() = default; + ~ReferenceContainerImpl() = default; - void addReference(std::shared_ptr ref) { + void addReference(std::shared_ptr ref) override { std::lock_guard lock(mutex); references.emplace_back(ref); } - size_t getReferenceCount() { + size_t getReferenceCount() override { std::lock_guard lock(mutex); return references.size(); } - void removeReferences() { + void removeReferences() override { std::lock_guard lock(mutex); for (auto ref : references) { ref->remove(); @@ -86,10 +65,4 @@ class ReferenceContainer { std::vector > references; }; -} // namespace core -} // namespace minifi -} // namespace nifi -} // namespace apache -} // namespace org - -#endif // LIBMINIFI_INCLUDE_CORE_WEAKREFERENCE_H_ +} // namespace org::apache::nifi::minifi::core diff --git a/libminifi/include/core/controller/ControllerServiceLookup.h b/libminifi/include/core/controller/ControllerServiceLookup.h index ad6cd62cae..2539b90bde 100644 --- a/libminifi/include/core/controller/ControllerServiceLookup.h +++ b/libminifi/include/core/controller/ControllerServiceLookup.h @@ -15,78 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#ifndef LIBMINIFI_INCLUDE_CORE_CONTROLLER_CONTROLLERSERVICELOOKUP_H_ -#define LIBMINIFI_INCLUDE_CORE_CONTROLLER_CONTROLLERSERVICELOOKUP_H_ -#include -#include -#include -#include "core/Core.h" -#include "core/ConfigurableComponent.h" -#include "ControllerService.h" +#pragma once -namespace org { -namespace apache { -namespace nifi { -namespace minifi { -namespace core { -namespace controller { - -/** - * Controller Service Lookup pure virtual class. - * - * Purpose: Provide a mechanism that controllers can lookup information about - * controller services. - * - */ -class ControllerServiceLookup { - public: - ControllerServiceLookup() = default; - - virtual ~ControllerServiceLookup() = default; - - /** - * Gets the controller service via the provided identifier. This overload returns the controller service in a global scope from all - * available controller services in the flow. - * @param identifier reference string for controller service. - * @return controller service reference. - */ - virtual std::shared_ptr getControllerService(const std::string &identifier) const = 0; - - /** - * Gets the controller service in the scope of the processor via the provided identifier. - * @param identifier reference string for controller service. - * @param processor_uuid uuid of the processor - * @return controller service reference. - */ - virtual std::shared_ptr 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 controller -} // namespace core -} // namespace minifi -} // namespace nifi -} // namespace apache -} // namespace org - -#endif // LIBMINIFI_INCLUDE_CORE_CONTROLLER_CONTROLLERSERVICELOOKUP_H_ +#include "minifi-cpp/core/controller/ControllerServiceLookup.h" diff --git a/libminifi/include/core/controller/ControllerServiceNode.h b/libminifi/include/core/controller/ControllerServiceNode.h index d6296f406e..bb09b2644d 100644 --- a/libminifi/include/core/controller/ControllerServiceNode.h +++ b/libminifi/include/core/controller/ControllerServiceNode.h @@ -25,25 +25,20 @@ #include "core/Core.h" #include "core/ConfigurableComponent.h" #include "core/logging/Logger.h" +#include "minifi-cpp/core/controller/ControllerServiceNode.h" #include "core/PropertyDefinition.h" #include "core/PropertyDefinitionBuilder.h" #include "properties/Configure.h" -#include "ControllerService.h" +#include "minifi-cpp/core/controller/ControllerService.h" #include "io/validation.h" #include "Exception.h" namespace org::apache::nifi::minifi::core::controller { -class ControllerServiceNode : public CoreComponent, public ConfigurableComponent { +class ControllerServiceNodeImpl : public CoreComponentImpl, public ConfigurableComponentImpl, public virtual ControllerServiceNode { public: - /** - * Constructor for the controller service node. - * @param service controller service reference - * @param id identifier for this node. - * @param configuration shared pointer configuration. - */ - explicit ControllerServiceNode(std::shared_ptr service, std::string id, std::shared_ptr configuration) - : CoreComponent(std::move(id)), + explicit ControllerServiceNodeImpl(std::shared_ptr service, std::string id, std::shared_ptr configuration) + : CoreComponentImpl(std::move(id)), active(false), configuration_(std::move(configuration)), controller_service_(std::move(service)) { @@ -65,11 +60,11 @@ class ControllerServiceNode : public CoreComponent, public ConfigurableComponent void setName(std::string name) override { controller_service_->setName(name); - CoreComponent::setName(std::move(name)); + CoreComponentImpl::setName(std::move(name)); } void setUUID(const utils::Identifier& uuid) override { - CoreComponent::setUUID(uuid); + CoreComponentImpl::setUUID(uuid); controller_service_->setUUID(uuid); } @@ -78,30 +73,14 @@ class ControllerServiceNode : public CoreComponent, public ConfigurableComponent * maintains * @return the implementation of the Controller Service */ - std::shared_ptr getControllerServiceImplementation(); - const ControllerService* getControllerServiceImplementation() const; - const std::vector& getLinkedControllerServices() const; - - /** - * Returns true if we can be enabled. - * Returns false if this ControllerServiceNode cannot be enabled. - */ - virtual bool canEnable() = 0; + std::shared_ptr getControllerServiceImplementation() override; + const ControllerService* getControllerServiceImplementation() const override; + const std::vector& getLinkedControllerServices() const override; - virtual bool enabled() { + bool enabled() override { return active.load(); } - /** - * Function to enable the controller service node. - */ - virtual bool enable() = 0; - - /** - * Function to disable the controller service node. - */ - virtual bool disable() = 0; - bool supportsDynamicProperties() const override { return false; } @@ -110,8 +89,8 @@ class ControllerServiceNode : public CoreComponent, public ConfigurableComponent return false; } - ControllerServiceNode(const ControllerServiceNode &other) = delete; - ControllerServiceNode &operator=(const ControllerServiceNode &parent) = delete; + ControllerServiceNodeImpl(const ControllerServiceNodeImpl &other) = delete; + ControllerServiceNodeImpl &operator=(const ControllerServiceNodeImpl &parent) = delete; protected: bool canEdit() override { @@ -120,9 +99,7 @@ class ControllerServiceNode : public CoreComponent, public ConfigurableComponent std::atomic active; std::shared_ptr configuration_; - // controller service. std::shared_ptr controller_service_; - // linked controller services. std::vector linked_controller_services_; }; diff --git a/libminifi/include/core/controller/ControllerServiceProvider.h b/libminifi/include/core/controller/ControllerServiceProvider.h index b46c2322e5..64e9ccd519 100644 --- a/libminifi/include/core/controller/ControllerServiceProvider.h +++ b/libminifi/include/core/controller/ControllerServiceProvider.h @@ -25,6 +25,7 @@ #include #include +#include "minifi-cpp/core/controller/ControllerServiceProvider.h" #include "core/Core.h" #include "ControllerServiceLookup.h" #include "core/ConfigurableComponent.h" @@ -35,51 +36,49 @@ namespace org::apache::nifi::minifi::core::controller { -class ControllerServiceProvider : public CoreComponent, public ConfigurableComponent, public ControllerServiceLookup { +class ControllerServiceProviderImpl : public CoreComponentImpl, public ConfigurableComponentImpl, public virtual ControllerServiceLookup, public virtual ControllerServiceProvider { public: - explicit ControllerServiceProvider(std::string_view name) - : CoreComponent(name), + explicit ControllerServiceProviderImpl(std::string_view name) + : CoreComponentImpl(name), controller_map_{std::make_unique()} { } - explicit ControllerServiceProvider(std::unique_ptr services) - : CoreComponent(core::className()), + explicit ControllerServiceProviderImpl(std::unique_ptr services) + : CoreComponentImpl(core::className()), controller_map_(std::move(services)) { } - explicit ControllerServiceProvider(std::string_view name, std::unique_ptr services) - : CoreComponent(name), + explicit ControllerServiceProviderImpl(std::string_view name, std::unique_ptr services) + : CoreComponentImpl(name), controller_map_(std::move(services)) { } - ControllerServiceProvider(const ControllerServiceProvider &other) = delete; - ControllerServiceProvider(ControllerServiceProvider &&other) = delete; + ControllerServiceProviderImpl(const ControllerServiceProviderImpl &other) = delete; + ControllerServiceProviderImpl(ControllerServiceProviderImpl &&other) = delete; - ControllerServiceProvider& operator=(const ControllerServiceProvider &other) = delete; - ControllerServiceProvider& operator=(ControllerServiceProvider &&other) = delete; + ControllerServiceProviderImpl& operator=(const ControllerServiceProviderImpl &other) = delete; + ControllerServiceProviderImpl& operator=(ControllerServiceProviderImpl &&other) = delete; - ~ControllerServiceProvider() override = default; + ~ControllerServiceProviderImpl() override = default; - virtual std::shared_ptr createControllerService(const std::string &type, const std::string &longType, const std::string &id, bool firstTimeAdded) = 0; - - virtual ControllerServiceNode* getControllerServiceNode(const std::string &id) const { + ControllerServiceNode* getControllerServiceNode(const std::string &id) const override { return controller_map_->get(id); } - virtual ControllerServiceNode* getControllerServiceNode(const std::string &id, const utils::Identifier &processor_or_controller_uuid) const { + ControllerServiceNode* getControllerServiceNode(const std::string &id, const utils::Identifier &processor_or_controller_uuid) const override { return controller_map_->get(id, processor_or_controller_uuid); } - virtual void clearControllerServices() = 0; + void clearControllerServices() override = 0; - virtual std::vector> getAllControllerServices() { + std::vector> getAllControllerServices() override { return controller_map_->getAllControllerServices(); } std::shared_ptr getControllerService(const std::string &identifier) const override; std::shared_ptr getControllerService(const std::string &identifier, const utils::Identifier &processor_uuid) const override; - void putControllerServiceNode(const std::string& identifier, const std::shared_ptr& controller_service_node, ProcessGroup* process_group); + void putControllerServiceNode(const std::string& identifier, const std::shared_ptr& controller_service_node, ProcessGroup* process_group) override; bool isControllerServiceEnabled(const std::string &identifier) override { const ControllerServiceNode* const node = getControllerServiceNode(identifier); @@ -108,10 +107,6 @@ class ControllerServiceProvider : public CoreComponent, public ConfigurableCompo } } - virtual void enableAllControllerServices() = 0; - - virtual void disableAllControllerServices() = 0; - bool supportsDynamicProperties() const final { return false; } diff --git a/libminifi/include/core/controller/ForwardingControllerServiceProvider.h b/libminifi/include/core/controller/ForwardingControllerServiceProvider.h index ffa5cb3a14..f31629f1c4 100644 --- a/libminifi/include/core/controller/ForwardingControllerServiceProvider.h +++ b/libminifi/include/core/controller/ForwardingControllerServiceProvider.h @@ -27,9 +27,9 @@ namespace org::apache::nifi::minifi::core::controller { -class ForwardingControllerServiceProvider : public ControllerServiceProvider { +class ForwardingControllerServiceProvider : public ControllerServiceProviderImpl { public: - using ControllerServiceProvider::ControllerServiceProvider; + using ControllerServiceProviderImpl::ControllerServiceProviderImpl; std::shared_ptr createControllerService(const std::string &type, const std::string &longType, const std::string &id, bool firstTimeAdded) override { return controller_service_provider_impl_->createControllerService(type, longType, id, firstTimeAdded); diff --git a/libminifi/include/core/controller/StandardControllerServiceNode.h b/libminifi/include/core/controller/StandardControllerServiceNode.h index 72f7de1bdf..1e9b85d16a 100644 --- a/libminifi/include/core/controller/StandardControllerServiceNode.h +++ b/libminifi/include/core/controller/StandardControllerServiceNode.h @@ -28,17 +28,17 @@ namespace org::apache::nifi::minifi::core::controller { -class StandardControllerServiceNode : public ControllerServiceNode { +class StandardControllerServiceNode : public ControllerServiceNodeImpl { public: explicit StandardControllerServiceNode(std::shared_ptr service, std::shared_ptr provider, std::string id, std::shared_ptr configuration) - : ControllerServiceNode(std::move(service), std::move(id), std::move(configuration)), + : ControllerServiceNodeImpl(std::move(service), std::move(id), std::move(configuration)), provider(std::move(provider)), logger_(logging::LoggerFactory::getLogger()) { } explicit StandardControllerServiceNode(std::shared_ptr service, std::string id, std::shared_ptr configuration) - : ControllerServiceNode(std::move(service), std::move(id), std::move(configuration)), + : ControllerServiceNodeImpl(std::move(service), std::move(id), std::move(configuration)), provider(nullptr), logger_(logging::LoggerFactory::getLogger()) { } @@ -49,12 +49,12 @@ class StandardControllerServiceNode : public ControllerServiceNode { /** * Initializes the controller service node. */ - virtual void initialize() { - ControllerServiceNode::initialize(); + void initialize() override { + ControllerServiceNodeImpl::initialize(); active = false; } - bool canEnable() { + bool canEnable() override { if (!active.load()) { for (auto linked_service : linked_controller_services_) { if (!linked_service->canEnable()) { @@ -67,9 +67,9 @@ class StandardControllerServiceNode : public ControllerServiceNode { } } - bool enable(); + bool enable() override; - bool disable() { + bool disable() override { controller_service_->setState(DISABLED); active = false; return true; diff --git a/libminifi/include/core/controller/StandardControllerServiceProvider.h b/libminifi/include/core/controller/StandardControllerServiceProvider.h index 533a2540c7..9f1dfbe47f 100644 --- a/libminifi/include/core/controller/StandardControllerServiceProvider.h +++ b/libminifi/include/core/controller/StandardControllerServiceProvider.h @@ -24,7 +24,7 @@ #include #include "core/ProcessGroup.h" #include "core/ClassLoader.h" -#include "ControllerService.h" +#include "core/controller/ControllerService.h" #include "ControllerServiceNodeMap.h" #include "ControllerServiceNode.h" #include "StandardControllerServiceNode.h" @@ -33,10 +33,10 @@ namespace org::apache::nifi::minifi::core::controller { -class StandardControllerServiceProvider : public ControllerServiceProvider, public std::enable_shared_from_this { +class StandardControllerServiceProvider : public ControllerServiceProviderImpl { public: explicit StandardControllerServiceProvider(std::unique_ptr services, std::shared_ptr configuration, ClassLoader& loader = ClassLoader::getDefaultClassLoader()) - : ControllerServiceProvider(std::move(services)), + : ControllerServiceProviderImpl(std::move(services)), extension_loader_(loader), configuration_(std::move(configuration)), logger_(logging::LoggerFactory::getLogger()) { @@ -56,7 +56,7 @@ class StandardControllerServiceProvider : public ControllerServiceProvider, publ } std::shared_ptr new_service_node = std::make_shared(new_controller_service, - std::static_pointer_cast(shared_from_this()), id, + sharedFromThis(), id, configuration_); controller_map_->put(id, new_service_node); diff --git a/libminifi/include/core/extension/DynamicLibrary.h b/libminifi/include/core/extension/DynamicLibrary.h index bd63c0f7f9..824db65e6d 100644 --- a/libminifi/include/core/extension/DynamicLibrary.h +++ b/libminifi/include/core/extension/DynamicLibrary.h @@ -27,7 +27,7 @@ namespace org::apache::nifi::minifi::core::extension { class DynamicLibrary : public Module { - friend class ExtensionManager; + friend class ExtensionManagerImpl; public: DynamicLibrary(std::string name, std::filesystem::path library_path); diff --git a/libminifi/include/core/extension/ExtensionManager.h b/libminifi/include/core/extension/ExtensionManager.h index b99f1d6258..25a99e1996 100644 --- a/libminifi/include/core/extension/ExtensionManager.h +++ b/libminifi/include/core/extension/ExtensionManager.h @@ -24,19 +24,21 @@ #include "core/logging/Logger.h" #include "Module.h" #include "properties/Configure.h" +#include "minifi-cpp/core/extension/ExtensionManager.h" namespace org::apache::nifi::minifi::core::extension { -class ExtensionManager { - ExtensionManager(); +class ExtensionManagerImpl : public ExtensionManager { + friend class ExtensionManager; + ExtensionManagerImpl(); public: - static ExtensionManager& get(); + static ExtensionManagerImpl& get(); bool initialize(const std::shared_ptr& config); - void registerExtension(Extension& extension); - void unregisterExtension(Extension& extension); + void registerExtension(Extension& extension) override; + void unregisterExtension(Extension& extension) override; private: std::vector> modules_; diff --git a/libminifi/include/core/extension/Module.h b/libminifi/include/core/extension/Module.h index bfe129d4ac..6b4941b762 100644 --- a/libminifi/include/core/extension/Module.h +++ b/libminifi/include/core/extension/Module.h @@ -24,7 +24,7 @@ #include "core/logging/Logger.h" #include "utils/gsl.h" #include "properties/Configure.h" -#include "Extension.h" +#include "core/extension/Extension.h" namespace org { namespace apache { @@ -37,7 +37,7 @@ namespace extension { * Represents an initializable component of the agent. */ class Module { - friend class ExtensionManager; + friend class ExtensionManagerImpl; protected: explicit Module(std::string name); diff --git a/libminifi/include/core/logging/LoggerBase.h b/libminifi/include/core/logging/LoggerBase.h new file mode 100644 index 0000000000..69142b4738 --- /dev/null +++ b/libminifi/include/core/logging/LoggerBase.h @@ -0,0 +1,114 @@ +/** + * + * 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 +#include +#include +#include +#include +#include +#include +#include +#include + +#include "spdlog/common.h" +#include "spdlog/logger.h" +#include "utils/gsl.h" +#include "utils/Enum.h" +#include "utils/GeneralUtils.h" +#include "fmt/chrono.h" +#include "fmt/std.h" +#include "fmt/ostream.h" +#include "minifi-cpp/core/logging/Logger.h" + +namespace org::apache::nifi::minifi::core::logging { + +inline constexpr size_t LOG_BUFFER_SIZE = 4096; + +class LoggerControl { + public: + LoggerControl(); + + [[nodiscard]] bool is_enabled() const; + + void setEnabled(bool status); + + protected: + std::atomic is_enabled_; +}; + +inline spdlog::level::level_enum mapToSpdLogLevel(LOG_LEVEL level) { + switch (level) { + case trace: return spdlog::level::trace; + case debug: return spdlog::level::debug; + case info: return spdlog::level::info; + case warn: return spdlog::level::warn; + case err: return spdlog::level::err; + case critical: return spdlog::level::critical; + case off: return spdlog::level::off; + } + throw std::invalid_argument(fmt::format("Invalid LOG_LEVEL {}", magic_enum::enum_underlying(level))); +} + +inline LOG_LEVEL mapFromSpdLogLevel(spdlog::level::level_enum level) { + switch (level) { + case spdlog::level::trace: return LOG_LEVEL::trace; + case spdlog::level::debug: return LOG_LEVEL::debug; + case spdlog::level::info: return LOG_LEVEL::info; + case spdlog::level::warn: return LOG_LEVEL::warn; + case spdlog::level::err: return LOG_LEVEL::err; + case spdlog::level::critical: return LOG_LEVEL::critical; + case spdlog::level::off: return LOG_LEVEL::off; + case spdlog::level::n_levels: break; + } + throw std::invalid_argument(fmt::format("Invalid spdlog::level::level_enum {}", magic_enum::enum_underlying(level))); +} + +class LoggerBase : public Logger { + public: + LoggerBase(LoggerBase const&) = delete; + LoggerBase& operator=(LoggerBase const&) = delete; + + void set_max_log_size(int size) override { + max_log_size_ = size; + } + + bool should_log(LOG_LEVEL level) override; + void log_string(LOG_LEVEL level, std::string str) override; + LOG_LEVEL level() const override; + + protected: + LoggerBase(std::shared_ptr delegate, std::shared_ptr controller); + + LoggerBase(std::shared_ptr delegate); // NOLINT + + int getMaxLogSize() override { + return max_log_size_.load(); + } + + std::shared_ptr delegate_; + std::shared_ptr controller_; + + std::mutex mutex_; + + private: + std::atomic max_log_size_{LOG_BUFFER_SIZE}; +}; + +} // namespace org::apache::nifi::minifi::core::logging diff --git a/libminifi/include/core/logging/LoggerConfiguration.h b/libminifi/include/core/logging/LoggerConfiguration.h index 9aed98df9c..284eb4e928 100644 --- a/libminifi/include/core/logging/LoggerConfiguration.h +++ b/libminifi/include/core/logging/LoggerConfiguration.h @@ -36,7 +36,7 @@ #include "spdlog/formatter.h" #include "core/Core.h" -#include "core/logging/Logger.h" +#include "core/logging/LoggerBase.h" #include "LoggerProperties.h" #include "internal/CompressionManager.h" #include "alert/AlertSink.h" @@ -142,10 +142,10 @@ class LoggerConfiguration { static std::shared_ptr getSpdlogLogger(const std::string& name); - class LoggerImpl : public Logger { + class LoggerImpl : public LoggerBase { public: explicit LoggerImpl(std::string name, const std::optional& id, const std::shared_ptr &controller, const std::shared_ptr &delegate) - : Logger(delegate, controller), + : LoggerBase(delegate, controller), name(std::move(name)), id(internal::formatId(id)) { } diff --git a/libminifi/include/core/logging/LoggerFactory.h b/libminifi/include/core/logging/LoggerFactory.h index 69a0127270..c3ea5a8d81 100644 --- a/libminifi/include/core/logging/LoggerFactory.h +++ b/libminifi/include/core/logging/LoggerFactory.h @@ -21,16 +21,12 @@ #include #include +#include "minifi-cpp/core/logging/LoggerFactory.h" #include "core/logging/Logger.h" #include "core/Core.h" namespace org::apache::nifi::minifi::core::logging { -class LoggerFactoryBase { - public: - static std::shared_ptr getAliasedLogger(std::string_view name, const std::optional& id = {}); -}; - template class LoggerFactory : public LoggerFactoryBase { public: diff --git a/libminifi/include/core/logging/LoggerProperties.h b/libminifi/include/core/logging/LoggerProperties.h index d94f186f1d..0ac4835619 100644 --- a/libminifi/include/core/logging/LoggerProperties.h +++ b/libminifi/include/core/logging/LoggerProperties.h @@ -29,10 +29,10 @@ namespace org::apache::nifi::minifi::core::logging { -class LoggerProperties : public Properties { +class LoggerProperties : public PropertiesImpl { public: LoggerProperties() - : Properties("Logger properties") { + : PropertiesImpl("Logger properties") { } /** * Gets all keys that start with the given prefix and do not have a "." after the prefix and "." separator. diff --git a/libminifi/include/core/repository/FileSystemRepository.h b/libminifi/include/core/repository/FileSystemRepository.h index d8c6b50e62..4882125f22 100644 --- a/libminifi/include/core/repository/FileSystemRepository.h +++ b/libminifi/include/core/repository/FileSystemRepository.h @@ -21,17 +21,17 @@ #include #include -#include "../ContentRepository.h" +#include "core/ContentRepository.h" #include "properties/Configure.h" #include "core/logging/LoggerFactory.h" #include "utils/file/FileUtils.h" namespace org::apache::nifi::minifi::core::repository { -class FileSystemRepository : public ContentRepository { +class FileSystemRepository : public ContentRepositoryImpl { public: explicit FileSystemRepository(const std::string_view name = className()) - : ContentRepository(name), + : ContentRepositoryImpl(name), logger_(logging::LoggerFactory::getLogger()) { } @@ -69,4 +69,6 @@ class FileSystemRepository : public ContentRepository { std::shared_ptr logger_; }; +std::shared_ptr createFileSystemRepository(); + } // namespace org::apache::nifi::minifi::core::repository diff --git a/libminifi/include/core/repository/VolatileContentRepository.h b/libminifi/include/core/repository/VolatileContentRepository.h index 04db09c9a7..1cc2f4d9c6 100644 --- a/libminifi/include/core/repository/VolatileContentRepository.h +++ b/libminifi/include/core/repository/VolatileContentRepository.h @@ -24,7 +24,7 @@ #include "AtomicRepoEntries.h" #include "io/AtomicEntryStream.h" -#include "../ContentRepository.h" +#include "core/ContentRepository.h" #include "properties/Configure.h" #include "core/Connectable.h" #include "core/logging/LoggerFactory.h" @@ -37,12 +37,12 @@ namespace org::apache::nifi::minifi::core::repository { * Purpose: Stages content into a volatile area of memory. Note that when the maximum number * of entries is consumed we will rollback a session to wait for others to be freed. */ -class VolatileContentRepository : public core::ContentRepository { +class VolatileContentRepository : public core::ContentRepositoryImpl { public: static const char *minimal_locking; explicit VolatileContentRepository(std::string_view name = className()) - : core::ContentRepository(name), + : core::ContentRepositoryImpl(name), repo_data_(15000, static_cast(10_MiB * 0.75)), minimize_locking_(true), logger_(logging::LoggerFactory::getLogger()) { diff --git a/libminifi/include/core/repository/VolatileRepository.h b/libminifi/include/core/repository/VolatileRepository.h index e742b32333..8be34e133b 100644 --- a/libminifi/include/core/repository/VolatileRepository.h +++ b/libminifi/include/core/repository/VolatileRepository.h @@ -37,14 +37,14 @@ namespace org::apache::nifi::minifi::core::repository { -class VolatileRepository : public core::ThreadedRepository { +class VolatileRepository : public core::ThreadedRepositoryImpl { public: explicit VolatileRepository(std::string_view repo_name = "", std::string /*dir*/ = REPOSITORY_DIRECTORY, std::chrono::milliseconds maxPartitionMillis = MAX_REPOSITORY_ENTRY_LIFE_TIME, int64_t maxPartitionBytes = MAX_REPOSITORY_STORAGE_SIZE, std::chrono::milliseconds purgePeriod = REPOSITORY_PURGE_PERIOD) - : core::ThreadedRepository(repo_name.length() > 0 ? repo_name : core::className(), "", maxPartitionMillis, maxPartitionBytes, purgePeriod), + : core::ThreadedRepositoryImpl(repo_name.length() > 0 ? repo_name : core::className(), "", maxPartitionMillis, maxPartitionBytes, purgePeriod), repo_data_(10000, static_cast(maxPartitionBytes * 0.75)), current_index_(0), logger_(logging::LoggerFactory::getLogger()) { diff --git a/libminifi/include/core/state/FlowIdentifier.h b/libminifi/include/core/state/FlowIdentifier.h index 89ef54dcde..61fe6d79b9 100644 --- a/libminifi/include/core/state/FlowIdentifier.h +++ b/libminifi/include/core/state/FlowIdentifier.h @@ -15,31 +15,24 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#ifndef LIBMINIFI_INCLUDE_CORE_STATE_FLOWIDENTIFIER_H_ -#define LIBMINIFI_INCLUDE_CORE_STATE_FLOWIDENTIFIER_H_ +#pragma once #include +#include "minifi-cpp/core/state/FlowIdentifier.h" -namespace org { -namespace apache { -namespace nifi { -namespace minifi { -namespace state { +namespace org::apache::nifi::minifi::state { /** * Purpose: Represents a flow identifier for a given flow update or instance. * * Design: Immutable collection of strings for the component parts. */ -class FlowIdentifier { +class FlowIdentifierImpl : public virtual FlowIdentifier { public: - FlowIdentifier() = delete; + FlowIdentifierImpl() = delete; - /** - * Constructor accepts the url, bucket id, and flow id. - */ - explicit FlowIdentifier(const std::string &url, const std::string &bucket_id, const std::string &flow_id) { + explicit FlowIdentifierImpl(const std::string &url, const std::string &bucket_id, const std::string &flow_id) { registry_url_ = url; bucket_id_ = bucket_id; flow_id_ = flow_id; @@ -50,21 +43,21 @@ class FlowIdentifier { * we don't want to cause issues if the FlowVersion object is ever used in a way * that breaks the current paradigm. */ - std::string getRegistryUrl() const { + std::string getRegistryUrl() const override { return registry_url_; } - std::string getBucketId() const { + std::string getBucketId() const override { return bucket_id_; } - std::string getFlowId() const { + std::string getFlowId() const override { return flow_id_; } protected: - FlowIdentifier(const FlowIdentifier &other) = default; - FlowIdentifier &operator=(const FlowIdentifier &other) = default; + FlowIdentifierImpl(const FlowIdentifierImpl &other) = default; + FlowIdentifierImpl &operator=(const FlowIdentifierImpl &other) = default; private: std::string registry_url_; @@ -74,10 +67,4 @@ class FlowIdentifier { }; -} // namespace state -} // namespace minifi -} // namespace nifi -} // namespace apache -} // namespace org - -#endif // LIBMINIFI_INCLUDE_CORE_STATE_FLOWIDENTIFIER_H_ +} // namespace org::apache::nifi::minifi::state diff --git a/libminifi/include/core/state/LogMetricsPublisher.h b/libminifi/include/core/state/LogMetricsPublisher.h index 04b28b1723..a3dbe7d646 100644 --- a/libminifi/include/core/state/LogMetricsPublisher.h +++ b/libminifi/include/core/state/LogMetricsPublisher.h @@ -22,17 +22,17 @@ #include #include "core/logging/Logger.h" -#include "core/logging/LoggerConfiguration.h" -#include "MetricsPublisher.h" +#include "core/logging/LoggerFactory.h" +#include "core/state/MetricsPublisher.h" #include "core/state/nodes/MetricsBase.h" #include "utils/LogUtils.h" #include "utils/StoppableThread.h" namespace org::apache::nifi::minifi::state { -class LogMetricsPublisher : public MetricsPublisher { +class LogMetricsPublisher : public MetricsPublisherImpl { public: - using MetricsPublisher::MetricsPublisher; + using MetricsPublisherImpl::MetricsPublisherImpl; MINIFIAPI static constexpr const char* Description = "Serializes all the configured metrics into a json output and writes the json to the MiNiFi logs periodically"; diff --git a/libminifi/include/core/state/MetricsPublisherFactory.h b/libminifi/include/core/state/MetricsPublisherFactory.h index 79313eb0f3..e3683ebe6a 100644 --- a/libminifi/include/core/state/MetricsPublisherFactory.h +++ b/libminifi/include/core/state/MetricsPublisherFactory.h @@ -21,7 +21,7 @@ #include #include -#include "MetricsPublisher.h" +#include "minifi-cpp/core/state/MetricsPublisher.h" #include "utils/gsl.h" namespace org::apache::nifi::minifi::state { diff --git a/libminifi/include/core/state/MetricsPublisherStore.h b/libminifi/include/core/state/MetricsPublisherStore.h index a1deb3cec0..4be8c3504b 100644 --- a/libminifi/include/core/state/MetricsPublisherStore.h +++ b/libminifi/include/core/state/MetricsPublisherStore.h @@ -23,7 +23,7 @@ #include #include -#include "MetricsPublisher.h" +#include "minifi-cpp/core/state/MetricsPublisher.h" #include "core/state/nodes/ResponseNodeLoader.h" #include "utils/gsl.h" #include "core/ProcessGroup.h" diff --git a/libminifi/include/core/state/nodes/AgentInformation.h b/libminifi/include/core/state/nodes/AgentInformation.h index 1d403aff7b..6b6c11949e 100644 --- a/libminifi/include/core/state/nodes/AgentInformation.h +++ b/libminifi/include/core/state/nodes/AgentInformation.h @@ -27,7 +27,7 @@ #include "core/state/nodes/MetricsBase.h" #include "core/state/nodes/StateMonitor.h" #include "utils/ProcessCpuUsageTracker.h" -#include "core/AgentIdentificationProvider.h" +#include "minifi-cpp/core/AgentIdentificationProvider.h" #include "utils/Export.h" #include "core/RepositoryMetricsSource.h" #include "controllers/UpdatePolicyControllerService.h" @@ -48,7 +48,7 @@ class ComponentManifest : public DeviceInformation { } std::string getName() const override { - return CoreComponent::getName(); + return CoreComponentImpl::getName(); } std::vector serialize() override; diff --git a/libminifi/include/core/state/nodes/AssetInformation.h b/libminifi/include/core/state/nodes/AssetInformation.h index feffa38a0b..bc4caaa725 100644 --- a/libminifi/include/core/state/nodes/AssetInformation.h +++ b/libminifi/include/core/state/nodes/AssetInformation.h @@ -22,10 +22,10 @@ namespace org::apache::nifi::minifi::state::response { -class AssetInformation : public ResponseNode { +class AssetInformation : public ResponseNodeImpl { public: AssetInformation(); - explicit AssetInformation(std::string_view name, const utils::Identifier& uuid = {}) : ResponseNode(name, uuid) {} + explicit AssetInformation(std::string_view name, const utils::Identifier& uuid = {}) : ResponseNodeImpl(name, uuid) {} MINIFIAPI static constexpr const char* Description = "Metric node that defines hash for all asset identifiers"; diff --git a/libminifi/include/core/state/nodes/ConfigurationChecksums.h b/libminifi/include/core/state/nodes/ConfigurationChecksums.h index 733c5834d2..028cec3f54 100644 --- a/libminifi/include/core/state/nodes/ConfigurationChecksums.h +++ b/libminifi/include/core/state/nodes/ConfigurationChecksums.h @@ -27,10 +27,10 @@ namespace org::apache::nifi::minifi::state::response { -class ConfigurationChecksums : public ResponseNode { +class ConfigurationChecksums : public ResponseNodeImpl { public: ConfigurationChecksums() = default; - explicit ConfigurationChecksums(std::string name, const utils::Identifier& uuid = {}) : ResponseNode(std::move(name), uuid) {} + explicit ConfigurationChecksums(const std::string_view name, const utils::Identifier& uuid = {}) : ResponseNodeImpl(name, uuid) {} MINIFIAPI static constexpr const char* Description = "Metric node that defines checksums of configuration files in the C2 protocol"; diff --git a/libminifi/include/core/state/nodes/DeviceInformation.h b/libminifi/include/core/state/nodes/DeviceInformation.h index 88480c7b7d..d7ebf47c82 100644 --- a/libminifi/include/core/state/nodes/DeviceInformation.h +++ b/libminifi/include/core/state/nodes/DeviceInformation.h @@ -48,8 +48,6 @@ #include "core/state/nodes/MetricsBase.h" #include "Connection.h" -#include "utils/OsUtils.h" -#include "utils/NetworkInterfaceInfo.h" #include "utils/SystemCpuUsageTracker.h" #include "utils/Export.h" diff --git a/libminifi/include/core/state/nodes/FlowInformation.h b/libminifi/include/core/state/nodes/FlowInformation.h index a605bd8b25..27d6d136aa 100644 --- a/libminifi/include/core/state/nodes/FlowInformation.h +++ b/libminifi/include/core/state/nodes/FlowInformation.h @@ -76,7 +76,7 @@ class FlowVersion : public DeviceInformation { void setFlowVersion(const std::string &url, const std::string &bucket_id, const std::string &flow_id) { std::lock_guard lock(guard); - identifier = std::make_shared(url, bucket_id, flow_id.empty() ? utils::IdGenerator::getIdGenerator()->generate().to_string() : flow_id); + identifier = std::make_shared(url, bucket_id, flow_id.empty() ? utils::IdGenerator::getIdGenerator()->generate().to_string() : flow_id); } std::vector serialize() override; diff --git a/libminifi/include/core/state/nodes/MetricsBase.h b/libminifi/include/core/state/nodes/MetricsBase.h index a6c59a754c..98a1c260c4 100644 --- a/libminifi/include/core/state/nodes/MetricsBase.h +++ b/libminifi/include/core/state/nodes/MetricsBase.h @@ -24,90 +24,30 @@ #include #include -#include "../Value.h" -#include "../PublishedMetricProvider.h" +#include "core/state/Value.h" +#include "core/state/PublishedMetricProvider.h" #include "core/Core.h" #include "core/Connectable.h" +#include "minifi-cpp/core/state/nodes/MetricsBase.h" +#include "core/state/nodes/ResponseNode.h" namespace org::apache::nifi::minifi::state::response { -class ResponseNode; -using SharedResponseNode = gsl::not_null>; - -/** - * Purpose: Defines a metric. Serialization is intended to be thread safe. - */ -class ResponseNode : public core::Connectable, public PublishedMetricProvider { - public: - ResponseNode() - : core::Connectable("metric"), - is_array_(false) { - } - - explicit ResponseNode(std::string_view name) - : core::Connectable(name), - is_array_(false) { - } - - ResponseNode(std::string_view name, const utils::Identifier& uuid) - : core::Connectable(name, uuid), - is_array_(false) { - } - - ~ResponseNode() override = default; - - static std::vector serializeAndMergeResponseNodes(const std::vector& nodes); - - virtual std::vector serialize() = 0; - - void yield() override { - } - - bool isRunning() const override { - return true; - } - - bool isWorkAvailable() override { - return true; - } - - bool isArray() const { - return is_array_; - } - - virtual bool isEmpty() { - return false; - } - - protected: - bool is_array_; - - void setArray(bool array) { - is_array_ = array; - } -}; - -/** - * Purpose: Defines a metric that - */ -class DeviceInformation : public ResponseNode { +class DeviceInformation : public ResponseNodeImpl { public: DeviceInformation(std::string_view name, const utils::Identifier& uuid) - : ResponseNode(name, uuid) { + : ResponseNodeImpl(name, uuid) { } explicit DeviceInformation(std::string_view name) - : ResponseNode(name) { + : ResponseNodeImpl(name) { } }; -/** - * Purpose: Defines a metric that - */ -class ObjectNode : public ResponseNode { +class ObjectNode : public ResponseNodeImpl { public: - explicit ObjectNode(std::string name, const utils::Identifier& uuid = {}) - : ResponseNode(std::move(name), uuid) { + explicit ObjectNode(const std::string_view name, const utils::Identifier& uuid = {}) + : ResponseNodeImpl(name, uuid) { } void add_node(const SharedResponseNode &node) { @@ -115,7 +55,7 @@ class ObjectNode : public ResponseNode { } std::string getName() const override { - return Connectable::getName(); + return ConnectableImpl::getName(); } std::vector serialize() override; @@ -128,74 +68,4 @@ class ObjectNode : public ResponseNode { std::unordered_map> nodes_; }; -/** - * Purpose: Retrieves Metrics from the defined class. The current Metric, which is a consumable for any reader of Metrics must have the ability to set metrics. - * - */ -class ResponseNodeSource { - public: - virtual ~ResponseNodeSource() = default; - virtual SharedResponseNode getResponseNode() = 0; -}; - -class NodeReporter { - public: - struct ReportedNode { - std::string name; - bool is_array; - std::vector serialized_nodes; - }; - - NodeReporter() = default; - - virtual ~NodeReporter() = default; - - /** - * Retrieves metrics node - * @return metrics response node - */ - virtual std::optional getMetricsNode(const std::string& metricsClass) const = 0; - - /** - * Retrieves root nodes configured to be included in heartbeat - * @param includeManifest -- determines if manifest is to be included - * @return a list of response nodes - */ - virtual std::vector getHeartbeatNodes(bool includeManifest) const = 0; - - /** - * Retrieves the agent manifest to be sent as a response to C2 DESCRIBE manifest - * @return the agent manifest response node - */ - virtual ReportedNode getAgentManifest() = 0; -}; - -/** - * Purpose: Sink interface for all metrics. The current Metric, which is a consumable for any reader of Metrics must have the ability to set metrics. - * - */ -class ResponseNodeSink { - public: - virtual ~ResponseNodeSink() = default; - /** - * Setter for nodes in this sink. - * @param metrics metrics to insert into the current sink. - * @return result of the set operation. - * 0 Success - * 1 No error condition, but cannot obtain lock in timely manner. - * -1 failure - */ - virtual int16_t setResponseNodes(const std::shared_ptr &metrics) = 0; - - /** - * Setter for metrics nodes in this sink. - * @param metrics metrics to insert into the current sink. - * @return result of the set operation. - * 0 Success - * 1 No error condition, but cannot obtain lock in timely manner. - * -1 failure - */ - virtual int16_t setMetricsNodes(const std::shared_ptr &metrics) = 0; -}; - } // namespace org::apache::nifi::minifi::state::response diff --git a/libminifi/include/core/state/nodes/QueueMetrics.h b/libminifi/include/core/state/nodes/QueueMetrics.h index 57ac99944b..fe19c45a10 100644 --- a/libminifi/include/core/state/nodes/QueueMetrics.h +++ b/libminifi/include/core/state/nodes/QueueMetrics.h @@ -31,18 +31,18 @@ namespace org::apache::nifi::minifi::state::response { * C2 server. * */ -class QueueMetrics : public ResponseNode { +class QueueMetrics : public ResponseNodeImpl { public: QueueMetrics(const std::string &name, const utils::Identifier &uuid) - : ResponseNode(name, uuid) { + : ResponseNodeImpl(name, uuid) { } QueueMetrics(const std::string &name) // NOLINT - : ResponseNode(name) { + : ResponseNodeImpl(name) { } QueueMetrics() - : ResponseNode("QueueMetrics") { + : ResponseNodeImpl("QueueMetrics") { } MINIFIAPI static constexpr const char* Description = "Metric node that defines queue metric information"; diff --git a/libminifi/include/core/state/nodes/RepositoryMetrics.h b/libminifi/include/core/state/nodes/RepositoryMetrics.h index a7d69ea09d..63b0ab326a 100644 --- a/libminifi/include/core/state/nodes/RepositoryMetrics.h +++ b/libminifi/include/core/state/nodes/RepositoryMetrics.h @@ -33,20 +33,20 @@ namespace org::apache::nifi::minifi::state::response { * C2 server. * */ -class RepositoryMetrics : public ResponseNode { +class RepositoryMetrics : public ResponseNodeImpl { public: RepositoryMetrics(std::string_view name, const utils::Identifier &uuid) - : ResponseNode(name, uuid), + : ResponseNodeImpl(name, uuid), repository_metrics_source_store_(getName()) { } explicit RepositoryMetrics(std::string_view name) - : ResponseNode(name), + : ResponseNodeImpl(name), repository_metrics_source_store_(getName()) { } RepositoryMetrics() - : ResponseNode("RepositoryMetrics"), + : ResponseNodeImpl("RepositoryMetrics"), repository_metrics_source_store_(getName()) { } diff --git a/libminifi/include/core/state/nodes/ResponseNodeLoader.h b/libminifi/include/core/state/nodes/ResponseNodeLoader.h index 9eb55f413e..41e4db7852 100644 --- a/libminifi/include/core/state/nodes/ResponseNodeLoader.h +++ b/libminifi/include/core/state/nodes/ResponseNodeLoader.h @@ -28,27 +28,28 @@ #include "MetricsBase.h" #include "core/ProcessGroup.h" #include "core/logging/Logger.h" -#include "core/logging/LoggerConfiguration.h" +#include "core/logging/LoggerFactory.h" #include "core/FlowConfiguration.h" #include "utils/gsl.h" #include "utils/Id.h" #include "utils/expected.h" #include "core/RepositoryMetricsSource.h" #include "utils/file/AssetManager.h" +#include "minifi-cpp/core/state/nodes/ResponseNodeLoader.h" namespace org::apache::nifi::minifi::state::response { -class ResponseNodeLoader { +class ResponseNodeLoaderImpl : public ResponseNodeLoader { public: - ResponseNodeLoader(std::shared_ptr configuration, std::vector> repository_metric_sources, + ResponseNodeLoaderImpl(std::shared_ptr configuration, std::vector> repository_metric_sources, std::shared_ptr flow_configuration, utils::file::AssetManager* asset_manager = nullptr); - void setNewConfigRoot(core::ProcessGroup* root); - void clearConfigRoot(); - void setControllerServiceProvider(core::controller::ControllerServiceProvider* controller); - void setStateMonitor(state::StateMonitor* update_sink); - std::vector loadResponseNodes(const std::string& clazz); - state::response::NodeReporter::ReportedNode getAgentManifest() const; + void setNewConfigRoot(core::ProcessGroup* root) override; + void clearConfigRoot() override; + void setControllerServiceProvider(core::controller::ControllerServiceProvider* controller) override; + void setStateMonitor(state::StateMonitor* update_sink) override; + std::vector loadResponseNodes(const std::string& clazz) override; + state::response::NodeReporter::ReportedNode getAgentManifest() const override; private: void initializeComponentMetrics(); diff --git a/libminifi/include/io/AtomicEntryStream.h b/libminifi/include/io/AtomicEntryStream.h index ecb5a2b26f..d8f89fc1f4 100644 --- a/libminifi/include/io/AtomicEntryStream.h +++ b/libminifi/include/io/AtomicEntryStream.h @@ -24,7 +24,7 @@ #include #include -#include "BaseStream.h" +#include "io/BaseStream.h" #include "core/repository/AtomicRepoEntries.h" #include "Exception.h" #include "core/logging/LoggerFactory.h" @@ -37,7 +37,7 @@ namespace minifi { namespace io { template -class AtomicEntryStream : public BaseStream { +class AtomicEntryStream : public BaseStreamImpl { public: AtomicEntryStream(const T key, core::repository::AtomicEntry *entry) : length_(0), diff --git a/libminifi/include/properties/Configuration.h b/libminifi/include/properties/Configuration.h index f5b7bc41bc..138b8641fd 100644 --- a/libminifi/include/properties/Configuration.h +++ b/libminifi/include/properties/Configuration.h @@ -22,6 +22,7 @@ #include #include "properties/Properties.h" +#include "minifi-cpp/properties/Configuration.h" #include "utils/OptionalUtils.h" #include "utils/Export.h" @@ -31,182 +32,9 @@ namespace core { class PropertyValidator; } -class Configuration : public Properties { +class ConfigurationImpl : public PropertiesImpl, public virtual Configuration { public: - Configuration() : Properties("MiNiFi configuration") {} - - static constexpr const char *nifi_volatile_repository_options = "nifi.volatile.repository.options."; - static constexpr const char *nifi_global_rocksdb_options = "nifi.global.rocksdb.options."; - static constexpr const char *nifi_flowfile_repository_rocksdb_options = "nifi.flowfile.repository.rocksdb.options."; - static constexpr const char *nifi_content_repository_rocksdb_options = "nifi.content.repository.rocksdb.options."; - static constexpr const char *nifi_provenance_repository_rocksdb_options = "nifi.provenance.repository.rocksdb.options."; - static constexpr const char *nifi_state_storage_rocksdb_options = "nifi.state.storage.rocksdb.options."; - - // nifi.flow.configuration.file - static constexpr const char *nifi_default_directory = "nifi.default.directory"; - static constexpr const char *nifi_flow_configuration_file = "nifi.flow.configuration.file"; - static constexpr const char *nifi_flow_configuration_encrypt = "nifi.flow.configuration.encrypt"; - static constexpr const char *nifi_flow_configuration_file_backup_update = "nifi.flow.configuration.backup.on.update"; - static constexpr const char *nifi_flow_engine_threads = "nifi.flow.engine.threads"; - static constexpr const char *nifi_flow_engine_alert_period = "nifi.flow.engine.alert.period"; - static constexpr const char *nifi_flow_engine_event_driven_time_slice = "nifi.flow.engine.event.driven.time.slice"; - static constexpr const char *nifi_administrative_yield_duration = "nifi.administrative.yield.duration"; - static constexpr const char *nifi_bored_yield_duration = "nifi.bored.yield.duration"; - static constexpr const char *nifi_graceful_shutdown_seconds = "nifi.flowcontroller.graceful.shutdown.period"; - static constexpr const char *nifi_flowcontroller_drain_timeout = "nifi.flowcontroller.drain.timeout"; - static constexpr const char *nifi_configuration_class_name = "nifi.flow.configuration.class.name"; - static constexpr const char *nifi_flow_repository_class_name = "nifi.flowfile.repository.class.name"; - static constexpr const char *nifi_flow_repository_rocksdb_compression = "nifi.flowfile.repository.rocksdb.compression"; - static constexpr const char *nifi_content_repository_class_name = "nifi.content.repository.class.name"; - static constexpr const char *nifi_content_repository_rocksdb_compression = "nifi.content.repository.rocksdb.compression"; - static constexpr const char *nifi_provenance_repository_class_name = "nifi.provenance.repository.class.name"; - static constexpr const char *nifi_volatile_repository_options_flowfile_max_count = "nifi.volatile.repository.options.flowfile.max.count"; - static constexpr const char *nifi_volatile_repository_options_flowfile_max_bytes = "nifi.volatile.repository.options.flowfile.max.bytes"; - static constexpr const char *nifi_volatile_repository_options_provenance_max_count = "nifi.volatile.repository.options.provenance.max.count"; - static constexpr const char *nifi_volatile_repository_options_provenance_max_bytes = "nifi.volatile.repository.options.provenance.max.bytes"; - static constexpr const char *nifi_volatile_repository_options_content_max_count = "nifi.volatile.repository.options.content.max.count"; - static constexpr const char *nifi_volatile_repository_options_content_max_bytes = "nifi.volatile.repository.options.content.max.bytes"; - static constexpr const char *nifi_volatile_repository_options_content_minimal_locking = "nifi.volatile.repository.options.content.minimal.locking"; - static constexpr const char *nifi_provenance_repository_max_storage_size = "nifi.provenance.repository.max.storage.size"; - static constexpr const char *nifi_provenance_repository_max_storage_time = "nifi.provenance.repository.max.storage.time"; - static constexpr const char *nifi_provenance_repository_directory_default = "nifi.provenance.repository.directory.default"; - static constexpr const char *nifi_flowfile_repository_directory_default = "nifi.flowfile.repository.directory.default"; - static constexpr const char *nifi_dbcontent_repository_directory_default = "nifi.database.content.repository.directory.default"; - - // these are internal properties related to the rocksdb backend - static constexpr const char *nifi_flowfile_repository_rocksdb_compaction_period = "nifi.flowfile.repository.rocksdb.compaction.period"; - static constexpr const char *nifi_dbcontent_repository_rocksdb_compaction_period = "nifi.database.content.repository.rocksdb.compaction.period"; - static constexpr const char *nifi_dbcontent_repository_purge_period = "nifi.database.content.repository.purge.period"; - static constexpr const char *nifi_content_repository_rocksdb_use_synchronous_writes = "nifi.content.repository.rocksdb.use.synchronous.writes"; - static constexpr const char *nifi_content_repository_rocksdb_read_verify_checksums = "nifi.content.repository.rocksdb.read.verify.checksums"; - static constexpr const char *nifi_flowfile_repository_rocksdb_read_verify_checksums = "nifi.flowfile.repository.rocksdb.read.verify.checksums"; - static constexpr const char *nifi_provenance_repository_rocksdb_read_verify_checksums = "nifi.provenance.repository.rocksdb.read.verify.checksums"; - static constexpr const char *nifi_rocksdb_state_storage_read_verify_checksums = "nifi.rocksdb.state.storage.read.verify.checksums"; - - static constexpr const char *nifi_remote_input_secure = "nifi.remote.input.secure"; - static constexpr const char *nifi_security_need_ClientAuth = "nifi.security.need.ClientAuth"; - static constexpr const char *nifi_sensitive_props_additional_keys = "nifi.sensitive.props.additional.keys"; - static constexpr const char *nifi_python_processor_dir = "nifi.python.processor.dir"; - static constexpr const char *nifi_extension_path = "nifi.extension.path"; - - // site2site security config - static constexpr const char *nifi_security_client_certificate = "nifi.security.client.certificate"; - static constexpr const char *nifi_security_client_private_key = "nifi.security.client.private.key"; - static constexpr const char *nifi_security_client_pass_phrase = "nifi.security.client.pass.phrase"; - static constexpr const char *nifi_security_client_ca_certificate = "nifi.security.client.ca.certificate"; - static constexpr const char *nifi_security_use_system_cert_store = "nifi.security.use.system.cert.store"; - static constexpr const char *nifi_security_windows_cert_store_location = "nifi.security.windows.cert.store.location"; - static constexpr const char *nifi_security_windows_server_cert_store = "nifi.security.windows.server.cert.store"; - static constexpr const char *nifi_security_windows_client_cert_store = "nifi.security.windows.client.cert.store"; - static constexpr const char *nifi_security_windows_client_cert_cn = "nifi.security.windows.client.cert.cn"; - static constexpr const char *nifi_security_windows_client_cert_key_usage = "nifi.security.windows.client.cert.key.usage"; - - // nifi rest api user name and password - static constexpr const char *nifi_rest_api_user_name = "nifi.rest.api.user.name"; - static constexpr const char *nifi_rest_api_password = "nifi.rest.api.password"; - - // c2 options - static constexpr const char *nifi_c2_enable = "nifi.c2.enable"; - static constexpr const char *nifi_c2_file_watch = "nifi.c2.file.watch"; - static constexpr const char *nifi_c2_flow_id = "nifi.c2.flow.id"; - static constexpr const char *nifi_c2_flow_url = "nifi.c2.flow.url"; - static constexpr const char *nifi_c2_flow_base_url = "nifi.c2.flow.base.url"; - static constexpr const char *nifi_c2_full_heartbeat = "nifi.c2.full.heartbeat"; - static constexpr const char *nifi_c2_agent_heartbeat_period = "nifi.c2.agent.heartbeat.period"; - static constexpr const char *nifi_c2_agent_class = "nifi.c2.agent.class"; - static constexpr const char *nifi_c2_agent_heartbeat_reporter_classes = "nifi.c2.agent.heartbeat.reporter.classes"; - static constexpr const char *nifi_c2_agent_identifier = "nifi.c2.agent.identifier"; - static constexpr const char *nifi_c2_agent_identifier_fallback = "nifi.c2.agent.identifier.fallback"; - static constexpr const char *nifi_c2_agent_trigger_classes = "nifi.c2.agent.trigger.classes"; - static constexpr const char *nifi_c2_root_classes = "nifi.c2.root.classes"; - static constexpr const char *nifi_c2_root_class_definitions = "nifi.c2.root.class.definitions"; - static constexpr const char *nifi_c2_rest_listener_port = "nifi.c2.rest.listener.port"; - static constexpr const char *nifi_c2_rest_listener_cacert = "nifi.c2.rest.listener.cacert"; - static constexpr const char *nifi_c2_rest_path_base = "nifi.c2.rest.path.base"; - static constexpr const char *nifi_c2_rest_url = "nifi.c2.rest.url"; - static constexpr const char *nifi_c2_rest_url_ack = "nifi.c2.rest.url.ack"; - static constexpr const char *nifi_c2_rest_ssl_context_service = "nifi.c2.rest.ssl.context.service"; - static constexpr const char *nifi_c2_rest_heartbeat_minimize_updates = "nifi.c2.rest.heartbeat.minimize.updates"; - static constexpr const char *nifi_c2_rest_request_encoding = "nifi.c2.rest.request.encoding"; - - // state management options - static constexpr const char *nifi_state_storage_local = "nifi.state.storage.local"; - static constexpr const char *nifi_state_storage_local_old = "nifi.state.management.provider.local"; - static constexpr const char *nifi_state_storage_local_class_name = "nifi.state.storage.local.class.name"; - static constexpr const char *nifi_state_storage_local_class_name_old = "nifi.state.management.provider.local.class.name"; - static constexpr const char *nifi_state_storage_local_always_persist = "nifi.state.storage.local.always.persist"; - static constexpr const char *nifi_state_storage_local_always_persist_old = "nifi.state.management.provider.local.always.persist"; - static constexpr const char *nifi_state_storage_local_auto_persistence_interval = "nifi.state.storage.local.auto.persistence.interval"; - static constexpr const char *nifi_state_storage_local_auto_persistence_interval_old = "nifi.state.management.provider.local.auto.persistence.interval"; - static constexpr const char *nifi_state_storage_local_path = "nifi.state.storage.local.path"; - static constexpr const char *nifi_state_storage_local_path_old = "nifi.state.management.provider.local.path"; - - // disk space watchdog options - static constexpr const char *minifi_disk_space_watchdog_enable = "minifi.disk.space.watchdog.enable"; - static constexpr const char *minifi_disk_space_watchdog_interval = "minifi.disk.space.watchdog.interval"; - static constexpr const char *minifi_disk_space_watchdog_stop_threshold = "minifi.disk.space.watchdog.stop.threshold"; - static constexpr const char *minifi_disk_space_watchdog_restart_threshold = "minifi.disk.space.watchdog.restart.threshold"; - - // Log options - static constexpr const char *nifi_log_spdlog_pattern = "nifi.log.spdlog.pattern"; - static constexpr const char *nifi_log_spdlog_shorten_names = "nifi.log.spdlog.shorten_names"; - static constexpr const char *nifi_log_appender_rolling = "nifi.log.appender.rolling"; - static constexpr const char *nifi_log_appender_rolling_directory = "nifi.log.appender.rolling.directory"; - static constexpr const char *nifi_log_appender_rolling_file_name = "nifi.log.appender.rolling.file_name"; - static constexpr const char *nifi_log_appender_rolling_max_files = "nifi.log.appender.rolling.max_files"; - static constexpr const char *nifi_log_appender_rolling_max_file_size = "nifi.log.appender.rolling.max_file_size"; - static constexpr const char *nifi_log_appender_stdout = "nifi.log.appender.stdout"; - static constexpr const char *nifi_log_appender_stderr = "nifi.log.appender.stderr"; - static constexpr const char *nifi_log_appender_null = "nifi.log.appender.null"; - static constexpr const char *nifi_log_appender_syslog = "nifi.log.appender.syslog"; - static constexpr const char *nifi_log_logger_root = "nifi.log.logger.root"; - static constexpr const char *nifi_log_compression_cached_log_max_size = "nifi.log.compression.cached.log.max.size"; - static constexpr const char *nifi_log_compression_compressed_log_max_size = "nifi.log.compression.compressed.log.max.size"; - static constexpr const char *nifi_log_max_log_entry_length = "nifi.log.max.log.entry.length"; - - // alert options - static constexpr const char *nifi_log_alert_url = "nifi.log.alert.url"; - static constexpr const char *nifi_log_alert_ssl_context_service = "nifi.log.alert.ssl.context.service"; - static constexpr const char *nifi_log_alert_batch_size = "nifi.log.alert.batch.size"; - static constexpr const char *nifi_log_alert_flush_period = "nifi.log.alert.flush.period"; - static constexpr const char *nifi_log_alert_filter = "nifi.log.alert.filter"; - static constexpr const char *nifi_log_alert_rate_limit = "nifi.log.alert.rate.limit"; - static constexpr const char *nifi_log_alert_buffer_limit = "nifi.log.alert.buffer.limit"; - static constexpr const char *nifi_log_alert_level = "nifi.log.alert.level"; - - static constexpr const char *nifi_asset_directory = "nifi.asset.directory"; - - // Metrics publisher options - static constexpr const char *nifi_metrics_publisher_agent_identifier = "nifi.metrics.publisher.agent.identifier"; - static constexpr const char *nifi_metrics_publisher_class = "nifi.metrics.publisher.class"; - static constexpr const char *nifi_metrics_publisher_prometheus_metrics_publisher_port = "nifi.metrics.publisher.PrometheusMetricsPublisher.port"; - static constexpr const char *nifi_metrics_publisher_prometheus_metrics_publisher_metrics = "nifi.metrics.publisher.PrometheusMetricsPublisher.metrics"; - static constexpr const char *nifi_metrics_publisher_log_metrics_publisher_metrics = "nifi.metrics.publisher.LogMetricsPublisher.metrics"; - static constexpr const char *nifi_metrics_publisher_log_metrics_logging_interval = "nifi.metrics.publisher.LogMetricsPublisher.logging.interval"; - static constexpr const char *nifi_metrics_publisher_log_metrics_log_level = "nifi.metrics.publisher.LogMetricsPublisher.log.level"; - static constexpr const char *nifi_metrics_publisher_metrics = "nifi.metrics.publisher.metrics"; - static constexpr const char *nifi_metrics_publisher_prometheus_metrics_publisher_certificate = "nifi.metrics.publisher.PrometheusMetricsPublisher.certificate"; - static constexpr const char *nifi_metrics_publisher_prometheus_metrics_publisher_ca_certificate = "nifi.metrics.publisher.PrometheusMetricsPublisher.ca.certificate"; - - // Controller socket options - static constexpr const char *controller_socket_enable = "controller.socket.enable"; - static constexpr const char *controller_socket_local_any_interface = "controller.socket.local.any.interface"; - static constexpr const char *controller_socket_host = "controller.socket.host"; - static constexpr const char *controller_socket_port = "controller.socket.port"; - static constexpr const char *controller_ssl_context_service = "controller.ssl.context.service"; - - static constexpr const char *nifi_flow_file_repository_check_health = "nifi.flowfile.repository.check.health"; - static constexpr const char *nifi_python_virtualenv_directory = "nifi.python.virtualenv.directory"; - static constexpr const char *nifi_python_env_setup_binary = "nifi.python.env.setup.binary"; - static constexpr const char *nifi_python_install_packages_automatically = "nifi.python.install.packages.automatically"; - - MINIFIAPI static const std::unordered_map> CONFIGURATION_PROPERTIES; - MINIFIAPI static const std::array DEFAULT_SENSITIVE_PROPERTIES; - - static std::vector mergeProperties(std::vector properties, - const std::vector& additional_properties); - static std::vector getSensitiveProperties(const std::function(const std::string&)>& reader); - static bool validatePropertyValue(const std::string& property_name, const std::string& property_value); + ConfigurationImpl() : PropertiesImpl("MiNiFi configuration") {} }; } // namespace org::apache::nifi::minifi diff --git a/libminifi/include/properties/Configure.h b/libminifi/include/properties/Configure.h index 46a6eff6b9..d869ad7da1 100644 --- a/libminifi/include/properties/Configure.h +++ b/libminifi/include/properties/Configure.h @@ -23,30 +23,31 @@ #include "properties/Configuration.h" #include "properties/Decryptor.h" -#include "core/AgentIdentificationProvider.h" +#include "minifi-cpp/core/AgentIdentificationProvider.h" #include "core/logging/LoggerProperties.h" +#include "minifi-cpp/properties/Configure.h" struct ConfigTestAccessor; namespace org::apache::nifi::minifi { -class Configure : public Configuration, public core::AgentIdentificationProvider { +class ConfigureImpl : public ConfigurationImpl, public virtual core::AgentIdentificationProvider, public virtual Configure { friend struct ::ConfigTestAccessor; public: - explicit Configure(std::optional decryptor = std::nullopt, std::shared_ptr logger_properties = {}) + explicit ConfigureImpl(std::optional decryptor = std::nullopt, std::shared_ptr logger_properties = {}) : decryptor_(std::move(decryptor)) , logger_properties_(std::move(logger_properties)) { } - bool get(const std::string& key, std::string& value) const; - bool get(const std::string& key, const std::string& alternate_key, std::string& value) const; - std::optional get(const std::string& key) const; - std::optional getWithFallback(const std::string& key, const std::string& alternate_key) const; - std::optional getRawValue(const std::string& key) const; + bool get(const std::string& key, std::string& value) const override; + bool get(const std::string& key, const std::string& alternate_key, std::string& value) const override; + std::optional get(const std::string& key) const override; + std::optional getWithFallback(const std::string& key, const std::string& alternate_key) const override; + std::optional getRawValue(const std::string& key) const override; std::optional getAgentClass() const override; std::string getAgentIdentifier() const override; - void setFallbackAgentIdentifier(const std::string& id); + void setFallbackAgentIdentifier(const std::string& id) override; using Configuration::set; void set(const std::string& key, const std::string& value, PropertyChangeLifetime lifetime) override; diff --git a/libminifi/include/properties/Properties.h b/libminifi/include/properties/Properties.h index 6d427d64f1..2cab983ae5 100644 --- a/libminifi/include/properties/Properties.h +++ b/libminifi/include/properties/Properties.h @@ -29,15 +29,11 @@ #include "core/logging/Logger.h" #include "utils/ChecksumCalculator.h" #include "utils/StringUtils.h" +#include "minifi-cpp/properties/Properties.h" namespace org::apache::nifi::minifi { -enum class PropertyChangeLifetime { - TRANSIENT, // the changed value will not be committed to disk - PERSISTENT // the changed value will be written to the source file -}; - -class Properties { +class PropertiesImpl : public virtual Properties { struct PropertyValue { std::string persisted_value; std::string active_value; @@ -45,24 +41,22 @@ class Properties { }; public: - explicit Properties(std::string name = ""); + explicit PropertiesImpl(std::string name = ""); - virtual ~Properties() = default; + ~PropertiesImpl() override = default; - virtual const std::string& getName() const { + const std::string& getName() const override { return name_; } - // Clear the load config - void clear() { + void clear() override { std::lock_guard lock(mutex_); properties_.clear(); } - void set(const std::string& key, const std::string& value) { + void set(const std::string& key, const std::string& value) override { set(key, value, PropertyChangeLifetime::PERSISTENT); } - // Set the config value - virtual void set(const std::string &key, const std::string &value, PropertyChangeLifetime lifetime) { + void set(const std::string &key, const std::string &value, PropertyChangeLifetime lifetime) override { auto active_value = utils::string::replaceEnvironmentVariables(value); std::lock_guard lock(mutex_); bool should_persist = lifetime == PropertyChangeLifetime::PERSISTENT; @@ -82,8 +76,7 @@ class Properties { dirty_ = true; } } - // Check whether the config value existed - bool has(const std::string& key) const { + bool has(const std::string& key) const override { std::lock_guard lock(mutex_); return properties_.count(key) > 0; } @@ -93,13 +86,13 @@ class Properties { * @param value value in which to place the map's stored property value * @returns true if found, false otherwise. */ - bool getString(const std::string &key, std::string &value) const; + bool getString(const std::string &key, std::string &value) const override; /** * Returns the configuration value or an empty string. * @return value corresponding to key or empty value. */ - int getInt(const std::string &key, int default_value) const; + int getInt(const std::string &key, int default_value) const override; /** * Returns the config value. @@ -107,20 +100,20 @@ class Properties { * @param key key to look up * @returns the value if found, nullopt otherwise. */ - std::optional getString(const std::string& key) const; + std::optional getString(const std::string& key) const override; /** * Load configure file * @param fileName path of the configuration file RELATIVE to MINIFI_HOME set by setHome() */ - void loadConfigureFile(const std::filesystem::path& configuration_file, std::string_view prefix = ""); + void loadConfigureFile(const std::filesystem::path& configuration_file, std::string_view prefix = "") override; // Set the determined MINIFI_HOME - void setHome(std::filesystem::path minifiHome) { + void setHome(std::filesystem::path minifiHome) override { minifi_home_ = std::move(minifiHome); } - std::vector getConfiguredKeys() const { + std::vector getConfiguredKeys() const override { std::vector keys; for (auto &property : properties_) { keys.push_back(property.first); @@ -129,17 +122,17 @@ class Properties { } // Get the determined MINIFI_HOME - std::filesystem::path getHome() const { + std::filesystem::path getHome() const override { return minifi_home_; } - virtual bool commitChanges(); + bool commitChanges() override; - utils::ChecksumCalculator& getChecksumCalculator() { return checksum_calculator_; } + utils::ChecksumCalculator& getChecksumCalculator() override { return checksum_calculator_; } - std::filesystem::path getFilePath() const; + std::filesystem::path getFilePath() const override; - std::map getProperties() const; + std::map getProperties() const override; private: std::map properties_; @@ -152,7 +145,6 @@ class Properties { // Mutex for protection mutable std::mutex mutex_; - // Logger std::shared_ptr logger_; // Home location for this executable std::filesystem::path minifi_home_; diff --git a/libminifi/include/provenance/Provenance.h b/libminifi/include/provenance/Provenance.h index d9fd2b636c..01e3c3fbe2 100644 --- a/libminifi/include/provenance/Provenance.h +++ b/libminifi/include/provenance/Provenance.h @@ -40,284 +40,183 @@ #include "utils/gsl.h" #include "utils/Id.h" #include "utils/TimeUtil.h" +#include "minifi-cpp/provenance/Provenance.h" namespace org::apache::nifi::minifi::provenance { -class ProvenanceEventRecord : public core::SerializableComponent { +class ProvenanceEventRecordImpl : public core::SerializableComponentImpl, public virtual ProvenanceEventRecord { public: - enum ProvenanceEventType { - /** - * A CREATE event is used when a FlowFile is generated from data that was - * not received from a remote system or external process - */ - CREATE, - - /** - * Indicates a provenance event for receiving data from an external process. This Event Type - * is expected to be the first event for a FlowFile. As such, a Processor that receives data - * from an external source and uses that data to replace the content of an existing FlowFile - * should use the {@link #FETCH} event type, rather than the RECEIVE event type. - */ - RECEIVE, - - /** - * Indicates that the contents of a FlowFile were overwritten using the contents of some - * external resource. This is similar to the {@link #RECEIVE} event but varies in that - * RECEIVE events are intended to be used as the event that introduces the FlowFile into - * the system, whereas FETCH is used to indicate that the contents of an existing FlowFile - * were overwritten. - */ - FETCH, - - /** - * Indicates a provenance event for sending data to an external process - */ - SEND, - - /** - * Indicates that the contents of a FlowFile were downloaded by a user or external entity. - */ - DOWNLOAD, - - /** - * Indicates a provenance event for the conclusion of an object's life for - * some reason other than object expiration - */ - DROP, - - /** - * Indicates a provenance event for the conclusion of an object's life due - * to the fact that the object could not be processed in a timely manner - */ - EXPIRE, - - /** - * FORK is used to indicate that one or more FlowFile was derived from a - * parent FlowFile. - */ - FORK, - - /** - * JOIN is used to indicate that a single FlowFile is derived from joining - * together multiple parent FlowFiles. - */ - JOIN, - - /** - * CLONE is used to indicate that a FlowFile is an exact duplicate of its - * parent FlowFile. - */ - CLONE, - - /** - * CONTENT_MODIFIED is used to indicate that a FlowFile's content was - * modified in some way. When using this Event Type, it is advisable to - * provide details about how the content is modified. - */ - CONTENT_MODIFIED, - - /** - * ATTRIBUTES_MODIFIED is used to indicate that a FlowFile's attributes were - * modified in some way. This event is not needed when another event is - * reported at the same time, as the other event will already contain all - * FlowFile attributes. - */ - ATTRIBUTES_MODIFIED, - - /** - * ROUTE is used to show that a FlowFile was routed to a specified - * {@link org.apache.nifi.processor.Relationship Relationship} and should provide - * information about why the FlowFile was routed to this relationship. - */ - ROUTE, - - /** - * Indicates a provenance event for adding additional information such as a - * new linkage to a new URI or UUID - */ - ADDINFO, - - /** - * Indicates a provenance event for replaying a FlowFile. The UUID of the - * event will indicate the UUID of the original FlowFile that is being - * replayed. The event will contain exactly one Parent UUID that is also the - * UUID of the FlowFile that is being replayed and exactly one Child UUID - * that is the UUID of the a newly created FlowFile that will be re-queued - * for processing. - */ - REPLAY - }; static const char *ProvenanceEventTypeStr[REPLAY + 1]; - ProvenanceEventRecord(ProvenanceEventType event, std::string componentId, std::string componentType); + ProvenanceEventRecordImpl(ProvenanceEventType event, std::string componentId, std::string componentType); - ProvenanceEventRecord() - : core::SerializableComponent(core::className()) { + ProvenanceEventRecordImpl() + : core::SerializableComponentImpl(core::className()) { _eventTime = std::chrono::system_clock::now(); } - virtual ~ProvenanceEventRecord() = default; + ~ProvenanceEventRecordImpl() override = default; - utils::Identifier getEventId() const { + utils::Identifier getEventId() const override { return getUUID(); } - void setEventId(const utils::Identifier &id) { + void setEventId(const utils::Identifier &id) override { setUUID(id); } - std::map getAttributes() const { + std::map getAttributes() const override { return _attributes; } - uint64_t getFileSize() const { + uint64_t getFileSize() const override { return _size; } - uint64_t getFileOffset() const { + uint64_t getFileOffset() const override { return _offset; } - std::chrono::system_clock::time_point getFlowFileEntryDate() const { + std::chrono::system_clock::time_point getFlowFileEntryDate() const override { return _entryDate; } - std::chrono::system_clock::time_point getlineageStartDate() const { + std::chrono::system_clock::time_point getlineageStartDate() const override { return _lineageStartDate; } - std::chrono::system_clock::time_point getEventTime() const { + std::chrono::system_clock::time_point getEventTime() const override { return _eventTime; } - std::chrono::milliseconds getEventDuration() const { + std::chrono::milliseconds getEventDuration() const override { return _eventDuration; } - void setEventDuration(std::chrono::milliseconds duration) { + void setEventDuration(std::chrono::milliseconds duration) override { _eventDuration = duration; } - ProvenanceEventType getEventType() const { + ProvenanceEventType getEventType() const override { return _eventType; } - std::string getComponentId() const { + std::string getComponentId() const override { return _componentId; } - std::string getComponentType() const { + std::string getComponentType() const override { return _componentType; } - utils::Identifier getFlowFileUuid() const { + utils::Identifier getFlowFileUuid() const override { return flow_uuid_; } - std::string getContentFullPath() const { + std::string getContentFullPath() const override { return _contentFullPath; } - std::vector getLineageIdentifiers() const { + std::vector getLineageIdentifiers() const override { return _lineageIdentifiers; } - std::string getDetails() const { + std::string getDetails() const override { return _details; } - void setDetails(const std::string& details) { + void setDetails(const std::string& details) override { _details = details; } - std::string getTransitUri() { + std::string getTransitUri() override { return _transitUri; } - void setTransitUri(const std::string& uri) { + void setTransitUri(const std::string& uri) override { _transitUri = uri; } - std::string getSourceSystemFlowFileIdentifier() const { + std::string getSourceSystemFlowFileIdentifier() const override { return _sourceSystemFlowFileIdentifier; } - void setSourceSystemFlowFileIdentifier(const std::string& identifier) { + void setSourceSystemFlowFileIdentifier(const std::string& identifier) override { _sourceSystemFlowFileIdentifier = identifier; } - std::vector getParentUuids() const { + std::vector getParentUuids() const override { return _parentUuids; } - void addParentUuid(const utils::Identifier& uuid) { + void addParentUuid(const utils::Identifier& uuid) override { if (std::find(_parentUuids.begin(), _parentUuids.end(), uuid) != _parentUuids.end()) return; else _parentUuids.push_back(uuid); } - void addParentFlowFile(const core::FlowFile& flow_file) { + void addParentFlowFile(const core::FlowFile& flow_file) override { addParentUuid(flow_file.getUUID()); } - void removeParentUuid(const utils::Identifier& uuid) { + void removeParentUuid(const utils::Identifier& uuid) override { _parentUuids.erase(std::remove(_parentUuids.begin(), _parentUuids.end(), uuid), _parentUuids.end()); } - void removeParentFlowFile(const core::FlowFile& flow_file) { + void removeParentFlowFile(const core::FlowFile& flow_file) override { removeParentUuid(flow_file.getUUID()); } - std::vector getChildrenUuids() const { + std::vector getChildrenUuids() const override { return _childrenUuids; } - void addChildUuid(const utils::Identifier& uuid) { + void addChildUuid(const utils::Identifier& uuid) override { if (std::find(_childrenUuids.begin(), _childrenUuids.end(), uuid) != _childrenUuids.end()) return; else _childrenUuids.push_back(uuid); } - void addChildFlowFile(const core::FlowFile& flow_file) { + void addChildFlowFile(const core::FlowFile& flow_file) override { addChildUuid(flow_file.getUUID()); return; } - void removeChildUuid(const utils::Identifier& uuid) { + void removeChildUuid(const utils::Identifier& uuid) override { _childrenUuids.erase(std::remove(_childrenUuids.begin(), _childrenUuids.end(), uuid), _childrenUuids.end()); } - void removeChildFlowFile(const core::FlowFile& flow_file) { + void removeChildFlowFile(const core::FlowFile& flow_file) override { removeChildUuid(flow_file.getUUID()); } - std::string getAlternateIdentifierUri() const { + std::string getAlternateIdentifierUri() const override { return _alternateIdentifierUri; } - void setAlternateIdentifierUri(const std::string& uri) { + void setAlternateIdentifierUri(const std::string& uri) override { _alternateIdentifierUri = uri; } - std::string getRelationship() const { + std::string getRelationship() const override { return _relationship; } - void setRelationship(const std::string& relation) { + void setRelationship(const std::string& relation) override { _relationship = relation; } - std::string getSourceQueueIdentifier() const { + std::string getSourceQueueIdentifier() const override { return _sourceQueueIdentifier; } - void setSourceQueueIdentifier(const std::string& identifier) { + void setSourceQueueIdentifier(const std::string& identifier) override { _sourceQueueIdentifier = identifier; } - void fromFlowFile(const core::FlowFile& flow_file) { + void fromFlowFile(const core::FlowFile& flow_file) override { _entryDate = flow_file.getEntryDate(); _lineageStartDate = flow_file.getlineageStartDate(); _lineageIdentifiers = flow_file.getlineageIdentifiers(); @@ -334,7 +233,7 @@ class ProvenanceEventRecord : public core::SerializableComponent { bool serialize(io::OutputStream& output_stream) override; bool deserialize(io::InputStream &input_stream) override; - bool loadFromRepository(const std::shared_ptr &repo); + bool loadFromRepository(const std::shared_ptr &repo) override; protected: ProvenanceEventType _eventType; @@ -365,57 +264,55 @@ class ProvenanceEventRecord : public core::SerializableComponent { std::string _alternateIdentifierUri; private: - // Prevent default copy constructor and assignment operation - // Only support pass by reference or pointer - ProvenanceEventRecord(const ProvenanceEventRecord &parent); - ProvenanceEventRecord &operator=(const ProvenanceEventRecord &parent); + ProvenanceEventRecordImpl(const ProvenanceEventRecordImpl &parent); + ProvenanceEventRecordImpl &operator=(const ProvenanceEventRecordImpl &parent); static std::shared_ptr logger_; static std::shared_ptr id_generator_; }; -class ProvenanceReporter { +class ProvenanceReporterImpl : public virtual ProvenanceReporter { public: - ProvenanceReporter(std::shared_ptr repo, std::string componentId, std::string componentType) + ProvenanceReporterImpl(std::shared_ptr repo, std::string componentId, std::string componentType) : logger_(core::logging::LoggerFactory::getLogger()) { _componentId = componentId; _componentType = componentType; repo_ = repo; } - virtual ~ProvenanceReporter() { + ~ProvenanceReporterImpl() override { clear(); } - std::set> getEvents() const { + std::set> getEvents() const override { return _events; } - void add(const std::shared_ptr &event) { + void add(const std::shared_ptr &event) override { _events.insert(event); } - void remove(const std::shared_ptr &event) { + void remove(const std::shared_ptr &event) override { if (_events.find(event) != _events.end()) { _events.erase(event); } } - void clear() { + void clear() override { _events.clear(); } - void commit(); - void create(const core::FlowFile& flow_file, const std::string& detail); - void route(const core::FlowFile& flow_file, const core::Relationship& relation, const std::string& detail, std::chrono::milliseconds processingDuration); - void modifyAttributes(const core::FlowFile& flow_file, const std::string& detail); - void modifyContent(const core::FlowFile& flow_file, const std::string& detail, std::chrono::milliseconds processingDuration); - void clone(const core::FlowFile& parent, const core::FlowFile& child); - void expire(const core::FlowFile& flow_file, const std::string& detail); - void drop(const core::FlowFile& flow_file, const std::string& reason); - void send(const core::FlowFile& flow_file, const std::string& transitUri, const std::string& detail, std::chrono::milliseconds processingDuration, bool force); - void fetch(const core::FlowFile& flow_file, const std::string& transitUri, const std::string& detail, std::chrono::milliseconds processingDuration); + void commit() override; + void create(const core::FlowFile& flow_file, const std::string& detail) override; + void route(const core::FlowFile& flow_file, const core::Relationship& relation, const std::string& detail, std::chrono::milliseconds processingDuration) override; + void modifyAttributes(const core::FlowFile& flow_file, const std::string& detail) override; + void modifyContent(const core::FlowFile& flow_file, const std::string& detail, std::chrono::milliseconds processingDuration) override; + void clone(const core::FlowFile& parent, const core::FlowFile& child) override; + void expire(const core::FlowFile& flow_file, const std::string& detail) override; + void drop(const core::FlowFile& flow_file, const std::string& reason) override; + void send(const core::FlowFile& flow_file, const std::string& transitUri, const std::string& detail, std::chrono::milliseconds processingDuration, bool force) override; + void fetch(const core::FlowFile& flow_file, const std::string& transitUri, const std::string& detail, std::chrono::milliseconds processingDuration) override; void receive(const core::FlowFile& flow_file, const std::string& transitUri, - const std::string& sourceSystemFlowFileIdentifier, const std::string& detail, std::chrono::milliseconds processingDuration); + const std::string& sourceSystemFlowFileIdentifier, const std::string& detail, std::chrono::milliseconds processingDuration) override; protected: std::shared_ptr allocate(ProvenanceEventRecord::ProvenanceEventType eventType, const core::FlowFile& flow_file) { @@ -423,7 +320,7 @@ class ProvenanceReporter { return nullptr; } - auto event = std::make_shared(eventType, _componentId, _componentType); + auto event = std::make_shared(eventType, _componentId, _componentType); if (event) event->fromFlowFile(flow_file); @@ -438,10 +335,8 @@ class ProvenanceReporter { std::set> _events; std::shared_ptr repo_; - // Prevent default copy constructor and assignment operation - // Only support pass by reference or pointer - ProvenanceReporter(const ProvenanceReporter &parent); - ProvenanceReporter &operator=(const ProvenanceReporter &parent); + ProvenanceReporterImpl(const ProvenanceReporterImpl &parent); + ProvenanceReporterImpl &operator=(const ProvenanceReporterImpl &parent); }; } // namespace org::apache::nifi::minifi::provenance diff --git a/libminifi/include/sitetosite/HTTPProtocol.h b/libminifi/include/sitetosite/HTTPProtocol.h index 769275870d..342078d298 100644 --- a/libminifi/include/sitetosite/HTTPProtocol.h +++ b/libminifi/include/sitetosite/HTTPProtocol.h @@ -148,8 +148,7 @@ class HttpSiteToSiteClient : public sitetosite::SiteToSiteClient { private: sitetosite::RespondCode current_code; std::shared_ptr logger_ = core::logging::LoggerFactory::getLogger(); - // Prevent default copy constructor and assignment operation - // Only support pass by reference or pointer + HttpSiteToSiteClient(const HttpSiteToSiteClient &parent); HttpSiteToSiteClient &operator=(const HttpSiteToSiteClient &parent); static std::shared_ptr id_generator_; diff --git a/libminifi/include/sitetosite/Peer.h b/libminifi/include/sitetosite/Peer.h index d1ced0f139..8261d2d2b5 100644 --- a/libminifi/include/sitetosite/Peer.h +++ b/libminifi/include/sitetosite/Peer.h @@ -130,7 +130,7 @@ class PeerStatus { static const char MAGIC_BYTES[] = { 'N', 'i', 'F', 'i' }; // Site2SitePeer Class -class SiteToSitePeer : public org::apache::nifi::minifi::io::BaseStream { +class SiteToSitePeer : public org::apache::nifi::minifi::io::BaseStreamImpl { public: SiteToSitePeer() : stream_(nullptr), diff --git a/libminifi/include/sitetosite/RawSocketProtocol.h b/libminifi/include/sitetosite/RawSocketProtocol.h index 09baec6882..2bee3b3115 100644 --- a/libminifi/include/sitetosite/RawSocketProtocol.h +++ b/libminifi/include/sitetosite/RawSocketProtocol.h @@ -169,8 +169,6 @@ class RawSiteToSiteClient : public sitetosite::SiteToSiteClient { // commsIdentifier utils::Identifier _commsIdentifier; - // Prevent default copy constructor and assignment operation - // Only support pass by reference or pointer RawSiteToSiteClient(const RawSiteToSiteClient &parent); RawSiteToSiteClient &operator=(const RawSiteToSiteClient &parent); static std::shared_ptr id_generator_; diff --git a/libminifi/include/sitetosite/SiteToSite.h b/libminifi/include/sitetosite/SiteToSite.h index 97491a59fd..5270919d11 100644 --- a/libminifi/include/sitetosite/SiteToSite.h +++ b/libminifi/include/sitetosite/SiteToSite.h @@ -21,7 +21,7 @@ #include #include -#include "controllers/SSLContextService.h" +#include "minifi-cpp/controllers/SSLContextService.h" #include "Peer.h" #include "core/Property.h" #include "properties/Configure.h" diff --git a/libminifi/include/sitetosite/SiteToSiteClient.h b/libminifi/include/sitetosite/SiteToSiteClient.h index 53f4b2f295..da4763f9cc 100644 --- a/libminifi/include/sitetosite/SiteToSiteClient.h +++ b/libminifi/include/sitetosite/SiteToSiteClient.h @@ -54,10 +54,10 @@ class DataPacket { std::shared_ptr logger_reference_; }; -class SiteToSiteClient : public core::Connectable { +class SiteToSiteClient : public core::ConnectableImpl { public: SiteToSiteClient() - : core::Connectable("SitetoSiteClient") { + : core::ConnectableImpl("SitetoSiteClient") { } ~SiteToSiteClient() override = default; diff --git a/libminifi/include/sitetosite/SiteToSiteFactory.h b/libminifi/include/sitetosite/SiteToSiteFactory.h index f40d12c9a0..e766c2efe0 100644 --- a/libminifi/include/sitetosite/SiteToSiteFactory.h +++ b/libminifi/include/sitetosite/SiteToSiteFactory.h @@ -70,7 +70,7 @@ static std::unique_ptr createClient(const SiteToSiteClientConf case HTTP: auto http_protocol = core::ClassLoader::getDefaultClassLoader().instantiateRaw("HttpProtocol", "HttpProtocol"); if (nullptr != http_protocol) { - auto ptr = std::unique_ptr(static_cast(http_protocol)); + auto ptr = std::unique_ptr(dynamic_cast(http_protocol)); ptr->setSSLContextService(client_configuration.getSecurityContext()); auto peer = std::unique_ptr(new SiteToSitePeer(client_configuration.getPeer()->getHost(), client_configuration.getPeer()->getPort(), client_configuration.getInterface())); diff --git a/libminifi/include/utils/FlowFileQueue.h b/libminifi/include/utils/FlowFileQueue.h index 584975d7be..b57b2c33af 100644 --- a/libminifi/include/utils/FlowFileQueue.h +++ b/libminifi/include/utils/FlowFileQueue.h @@ -23,8 +23,8 @@ #include "core/FlowFile.h" #include "MinMaxHeap.h" -#include "SwapManager.h" -#include "TimeUtil.h" +#include "minifi-cpp/SwapManager.h" +#include "utils/TimeUtil.h" namespace org::apache::nifi::minifi::test::utils { struct FlowFileQueueTestAccessor; diff --git a/libminifi/include/utils/StagingQueue.h b/libminifi/include/utils/StagingQueue.h index 6751c53010..f0dc3b8b30 100644 --- a/libminifi/include/utils/StagingQueue.h +++ b/libminifi/include/utils/StagingQueue.h @@ -20,7 +20,7 @@ #include #include #include -#include "MinifiConcurrentQueue.h" +#include "utils/MinifiConcurrentQueue.h" namespace org { namespace apache { diff --git a/libminifi/src/Configure.cpp b/libminifi/src/Configure.cpp index 716d0a43e5..56e44f75c4 100644 --- a/libminifi/src/Configure.cpp +++ b/libminifi/src/Configure.cpp @@ -21,12 +21,13 @@ #include "utils/gsl.h" #include "core/logging/LoggerConfiguration.h" +#include "core/logging/LoggerFactory.h" #include "utils/StringUtils.h" #include "properties/Configuration.h" namespace org::apache::nifi::minifi { -bool Configure::get(const std::string& key, std::string& value) const { +bool ConfigureImpl::get(const std::string& key, std::string& value) const { if (auto opt_value = getRawValue(key)) { value = *opt_value; if (decryptor_ && isEncrypted(key)) { @@ -37,7 +38,7 @@ bool Configure::get(const std::string& key, std::string& value) const { return false; } -bool Configure::get(const std::string& key, const std::string& alternate_key, std::string& value) const { +bool ConfigureImpl::get(const std::string& key, const std::string& alternate_key, std::string& value) const { if (get(key, value)) { if (get(alternate_key)) { const auto logger = core::logging::LoggerFactory::getLogger(); @@ -53,7 +54,7 @@ bool Configure::get(const std::string& key, const std::string& alternate_key, st } } -std::optional Configure::get(const std::string& key) const { +std::optional ConfigureImpl::get(const std::string& key) const { std::string value; if (get(key, value)) { return value; @@ -61,7 +62,7 @@ std::optional Configure::get(const std::string& key) const { return std::nullopt; } -std::optional Configure::getWithFallback(const std::string& key, const std::string& alternate_key) const { +std::optional ConfigureImpl::getWithFallback(const std::string& key, const std::string& alternate_key) const { std::string value; if (get(key, alternate_key, value)) { return value; @@ -69,7 +70,7 @@ std::optional Configure::getWithFallback(const std::string& key, co return std::nullopt; } -std::optional Configure::getRawValue(const std::string& key) const { +std::optional ConfigureImpl::getRawValue(const std::string& key) const { static constexpr std::string_view log_prefix = "nifi.log."; if (utils::string::startsWith(key, log_prefix)) { if (logger_properties_) { @@ -81,13 +82,13 @@ std::optional Configure::getRawValue(const std::string& key) const return getString(key); } -bool Configure::isEncrypted(const std::string& key) const { +bool ConfigureImpl::isEncrypted(const std::string& key) const { gsl_Expects(decryptor_); const auto encryption_marker = getString(key + ".protected"); return decryptor_->isValidEncryptionMarker(encryption_marker); } -std::optional Configure::getAgentClass() const { +std::optional ConfigureImpl::getAgentClass() const { std::string agent_class; if (get(Configuration::nifi_c2_agent_class, "c2.agent.class", agent_class) && !agent_class.empty()) { return agent_class; @@ -95,7 +96,7 @@ std::optional Configure::getAgentClass() const { return {}; } -std::string Configure::getAgentIdentifier() const { +std::string ConfigureImpl::getAgentIdentifier() const { std::string agent_id; if (!get(Configuration::nifi_c2_agent_identifier, "c2.agent.identifier", agent_id) || agent_id.empty()) { std::lock_guard guard(fallback_identifier_mutex_); @@ -104,12 +105,12 @@ std::string Configure::getAgentIdentifier() const { return agent_id; } -void Configure::setFallbackAgentIdentifier(const std::string& id) { +void ConfigureImpl::setFallbackAgentIdentifier(const std::string& id) { std::lock_guard guard(fallback_identifier_mutex_); fallback_identifier_ = id; } -void Configure::set(const std::string& key, const std::string& value, PropertyChangeLifetime lifetime) { +void ConfigureImpl::set(const std::string& key, const std::string& value, PropertyChangeLifetime lifetime) { const std::string_view log_prefix = "nifi.log."; if (utils::string::startsWith(key, log_prefix)) { if (logger_properties_) { @@ -117,11 +118,11 @@ void Configure::set(const std::string& key, const std::string& value, PropertyCh logger_properties_->set(key.substr(log_prefix.length()), value, lifetime); } } else { - Configuration::set(key, value, lifetime); + ConfigurationImpl::set(key, value, lifetime); } } -bool Configure::commitChanges() { +bool ConfigureImpl::commitChanges() { bool success = true; if (logger_properties_) { success &= logger_properties_->commitChanges(); @@ -130,8 +131,12 @@ bool Configure::commitChanges() { logger_properties_changed_ = false; } } - success &= Configuration::commitChanges(); + success &= ConfigurationImpl::commitChanges(); return success; } +std::shared_ptr Configure::create() { + return std::make_shared(); +} + } // namespace org::apache::nifi::minifi diff --git a/libminifi/src/Connection.cpp b/libminifi/src/Connection.cpp index 4f52622abf..2d2eec7927 100644 --- a/libminifi/src/Connection.cpp +++ b/libminifi/src/Connection.cpp @@ -32,32 +32,32 @@ using namespace std::literals::chrono_literals; namespace org::apache::nifi::minifi { -Connection::Connection(std::shared_ptr flow_repository, std::shared_ptr content_repo, std::string_view name) - : core::Connectable(name), +ConnectionImpl::ConnectionImpl(std::shared_ptr flow_repository, std::shared_ptr content_repo, std::string_view name) + : core::ConnectableImpl(name), flow_repository_(std::move(flow_repository)), content_repo_(std::move(content_repo)) { logger_->log_debug("Connection {} created", name_); } -Connection::Connection(std::shared_ptr flow_repository, std::shared_ptr content_repo, std::string_view name, const utils::Identifier &uuid) - : core::Connectable(name, uuid), +ConnectionImpl::ConnectionImpl(std::shared_ptr flow_repository, std::shared_ptr content_repo, std::string_view name, const utils::Identifier &uuid) + : core::ConnectableImpl(name, uuid), flow_repository_(std::move(flow_repository)), content_repo_(std::move(content_repo)) { logger_->log_debug("Connection {} created", name_); } -Connection::Connection(std::shared_ptr flow_repository, std::shared_ptr content_repo, std::string_view name, const utils::Identifier &uuid, +ConnectionImpl::ConnectionImpl(std::shared_ptr flow_repository, std::shared_ptr content_repo, std::string_view name, const utils::Identifier &uuid, const utils::Identifier& srcUUID) - : core::Connectable(name, uuid), + : core::ConnectableImpl(name, uuid), src_uuid_(srcUUID), flow_repository_(std::move(flow_repository)), content_repo_(std::move(content_repo)) { logger_->log_debug("Connection {} created", name_); } -Connection::Connection(std::shared_ptr flow_repository, std::shared_ptr content_repo, std::string_view name, const utils::Identifier &uuid, +ConnectionImpl::ConnectionImpl(std::shared_ptr flow_repository, std::shared_ptr content_repo, std::string_view name, const utils::Identifier &uuid, const utils::Identifier& srcUUID, const utils::Identifier& destUUID) - : core::Connectable(name, uuid), + : core::ConnectableImpl(name, uuid), src_uuid_(srcUUID), dest_uuid_(destUUID), flow_repository_(std::move(flow_repository)), @@ -65,22 +65,22 @@ Connection::Connection(std::shared_ptr flow_repository, std::s logger_->log_debug("Connection {} created", name_); } -Connection::Connection(std::shared_ptr flow_repository, std::shared_ptr content_repo, std::shared_ptr swap_manager, +ConnectionImpl::ConnectionImpl(std::shared_ptr flow_repository, std::shared_ptr content_repo, std::shared_ptr swap_manager, std::string_view name, const utils::Identifier& uuid) - : core::Connectable(name, uuid), + : core::ConnectableImpl(name, uuid), flow_repository_(std::move(flow_repository)), content_repo_(std::move(content_repo)), queue_(std::move(swap_manager)) { logger_->log_debug("Connection {} created", name_); } -bool Connection::isEmpty() const { +bool ConnectionImpl::isEmpty() const { std::lock_guard lock(mutex_); return queue_.empty(); } -bool Connection::backpressureThresholdReached() const { +bool ConnectionImpl::backpressureThresholdReached() const { std::lock_guard lock(mutex_); auto backpressure_threshold_count = backpressure_threshold_count_.load(); auto backpressure_threshold_data_size = backpressure_threshold_data_size_.load(); @@ -94,7 +94,7 @@ bool Connection::backpressureThresholdReached() const { return false; } -void Connection::put(const std::shared_ptr& flow) { +void ConnectionImpl::put(const std::shared_ptr& flow) { if (drop_empty_ && flow->getSize() == 0) { logger_->log_info("Dropping empty flow file: {}", flow->getUUIDStr()); return; @@ -116,7 +116,7 @@ void Connection::put(const std::shared_ptr& flow) { } } -void Connection::multiPut(std::vector>& flows) { +void ConnectionImpl::multiPut(std::vector>& flows) { { std::lock_guard lock(mutex_); @@ -139,7 +139,7 @@ void Connection::multiPut(std::vector>& flows) { } } -std::shared_ptr Connection::poll(std::set> &expiredFlowRecords) { +std::shared_ptr ConnectionImpl::poll(std::set> &expiredFlowRecords) { std::lock_guard lock(mutex_); while (queue_.isWorkAvailable()) { @@ -171,7 +171,7 @@ std::shared_ptr Connection::poll(std::set lock(mutex_); if (!delete_permanently) { // simply discard in-memory flow files diff --git a/libminifi/src/FlowFileRecord.cpp b/libminifi/src/FlowFileRecord.cpp index c7ee2c6e0d..b191033479 100644 --- a/libminifi/src/FlowFileRecord.cpp +++ b/libminifi/src/FlowFileRecord.cpp @@ -35,17 +35,17 @@ namespace org::apache::nifi::minifi { -std::shared_ptr FlowFileRecord::logger_ = core::logging::LoggerFactory::getLogger(); -std::atomic FlowFileRecord::local_flow_seq_number_(0); +std::shared_ptr FlowFileRecordImpl::logger_ = core::logging::LoggerFactory::getLogger(); +std::atomic FlowFileRecordImpl::local_flow_seq_number_(0); -FlowFileRecord::FlowFileRecord() { +FlowFileRecordImpl::FlowFileRecordImpl() { // TODO(adebreceni): // we should revisit if we need these in a follow-up ticket id_ = local_flow_seq_number_++; addAttribute(core::SpecialFlowAttribute::FILENAME, std::to_string(utils::timeutils::getTimeNano())); } -std::shared_ptr FlowFileRecord::DeSerialize(const std::string& key, const std::shared_ptr& flowRepository, +std::shared_ptr FlowFileRecordImpl::DeSerialize(const std::string& key, const std::shared_ptr& flowRepository, const std::shared_ptr& content_repo, utils::Identifier& container) { std::string value; @@ -66,7 +66,7 @@ std::shared_ptr FlowFileRecord::DeSerialize(const std::string& k return record; } -bool FlowFileRecord::Serialize(io::OutputStream &outStream) { +bool FlowFileRecordImpl::Serialize(io::OutputStream &outStream) { { uint64_t event_time_ms = std::chrono::duration_cast(event_time_.time_since_epoch()).count(); const auto ret = outStream.write(event_time_ms); @@ -149,7 +149,7 @@ bool FlowFileRecord::Serialize(io::OutputStream &outStream) { return true; } -bool FlowFileRecord::Persist(const std::shared_ptr& flowRepository) { +bool FlowFileRecordImpl::Persist(const std::shared_ptr& flowRepository) { if (flowRepository->isNoop()) { return true; } @@ -173,8 +173,8 @@ bool FlowFileRecord::Persist(const std::shared_ptr& flowReposi return true; } -std::shared_ptr FlowFileRecord::DeSerialize(io::InputStream& inStream, const std::shared_ptr& content_repo, utils::Identifier& container) { - auto file = std::make_shared(); +std::shared_ptr FlowFileRecordImpl::DeSerialize(io::InputStream& inStream, const std::shared_ptr& content_repo, utils::Identifier& container) { + auto file = std::make_shared(); { uint64_t event_time_in_ms; @@ -266,9 +266,26 @@ std::shared_ptr FlowFileRecord::DeSerialize(io::InputStream& inS } } - file->claim_ = std::make_shared(content_full_path, content_repo); + file->claim_ = std::make_shared(content_full_path, content_repo); return file; } +std::shared_ptr core::FlowFile::create() { + return std::make_shared(); +} + +std::shared_ptr FlowFileRecord::DeSerialize(std::span buffer, const std::shared_ptr &content_repo, utils::Identifier &container) { + return FlowFileRecordImpl::DeSerialize(buffer, content_repo, container); +} + +std::shared_ptr FlowFileRecord::DeSerialize(io::InputStream &stream, const std::shared_ptr &content_repo, utils::Identifier &container) { + return FlowFileRecordImpl::DeSerialize(stream, content_repo, container); +} + +std::shared_ptr FlowFileRecord::DeSerialize(const std::string& key, const std::shared_ptr& flowRepository, + const std::shared_ptr &content_repo, utils::Identifier &container) { + return FlowFileRecordImpl::DeSerialize(key, flowRepository, content_repo, container); +} + } // namespace org::apache::nifi::minifi diff --git a/libminifi/src/RemoteProcessorGroupPort.cpp b/libminifi/src/RemoteProcessorGroupPort.cpp index 8b395385a2..e036b09847 100644 --- a/libminifi/src/RemoteProcessorGroupPort.cpp +++ b/libminifi/src/RemoteProcessorGroupPort.cpp @@ -37,6 +37,8 @@ #include "core/ProcessContext.h" #include "core/ProcessorNode.h" #include "http/BaseHTTPClient.h" +#include "controllers/SSLContextService.h" +#include "utils/net/DNS.h" #undef GetObject // windows.h #defines GetObject = GetObjectA or GetObjectW, which conflicts with rapidjson @@ -120,11 +122,11 @@ void RemoteProcessorGroupPort::onSchedule(core::ProcessContext& context, core::P } std::shared_ptr service = context.getControllerService(context_name, getUUID()); if (nullptr != service) { - ssl_service = std::static_pointer_cast(service); + ssl_service = std::dynamic_pointer_cast(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(RPG_SSL_CONTEXT_SERVICE_NAME, configure_); + ssl_service = std::make_shared(RPG_SSL_CONTEXT_SERVICE_NAME, configure_); ssl_service->onEnable(); } } diff --git a/libminifi/src/ResourceClaim.cpp b/libminifi/src/ResourceClaim.cpp index b47b621727..f14662ba7b 100644 --- a/libminifi/src/ResourceClaim.cpp +++ b/libminifi/src/ResourceClaim.cpp @@ -25,11 +25,12 @@ #include #include "core/StreamManager.h" #include "utils/Id.h" -#include "core/logging/LoggerConfiguration.h" +#include "core/logging/LoggerFactory.h" +#include "core/ContentRepository.h" namespace org::apache::nifi::minifi { -utils::NonRepeatingStringGenerator ResourceClaim::non_repeating_string_generator_; +utils::NonRepeatingStringGenerator ResourceClaimImpl::non_repeating_string_generator_; std::string default_directory_path; @@ -37,7 +38,7 @@ void setDefaultDirectory(std::string path) { default_directory_path = std::move(path); } -ResourceClaim::ResourceClaim(std::shared_ptr> claim_manager) +ResourceClaimImpl::ResourceClaimImpl(std::shared_ptr> claim_manager) : _contentFullPath([&] { auto contentDirectory = claim_manager->getStoragePath(); if (contentDirectory.empty()) @@ -52,15 +53,19 @@ ResourceClaim::ResourceClaim(std::shared_ptr> logger_->log_debug("Resource Claim created {}", _contentFullPath); } -ResourceClaim::ResourceClaim(Path path, std::shared_ptr> claim_manager) +ResourceClaimImpl::ResourceClaimImpl(Path path, std::shared_ptr> claim_manager) : _contentFullPath(std::move(path)), claim_manager_(std::move(claim_manager)), logger_(core::logging::LoggerFactory::getLogger()) { if (claim_manager_) increaseFlowFileRecordOwnedCount(); } -ResourceClaim::~ResourceClaim() { +ResourceClaimImpl::~ResourceClaimImpl() { if (claim_manager_) decreaseFlowFileRecordOwnedCount(); } +std::shared_ptr ResourceClaim::create(std::shared_ptr repository) { + return std::make_shared(repository); +} + } // namespace org::apache::nifi::minifi diff --git a/libminifi/src/ThreadedSchedulingAgent.cpp b/libminifi/src/ThreadedSchedulingAgent.cpp index d0f8a9c284..2796ce4187 100644 --- a/libminifi/src/ThreadedSchedulingAgent.cpp +++ b/libminifi/src/ThreadedSchedulingAgent.cpp @@ -75,7 +75,7 @@ void ThreadedSchedulingAgent::schedule(core::Processor* processor) { return; } - std::shared_ptr processor_node = std::make_shared(processor); + std::shared_ptr processor_node = std::make_shared(processor); std::shared_ptr contextBuilder = core::ClassLoader::getDefaultClassLoader().instantiate("ProcessContextBuilder", "ProcessContextBuilder"); @@ -84,7 +84,7 @@ void ThreadedSchedulingAgent::schedule(core::Processor* processor) { auto process_context = contextBuilder->build(processor_node); - auto session_factory = std::make_shared(process_context); + auto session_factory = std::make_shared(process_context); processor->onSchedule(*process_context, *session_factory); diff --git a/libminifi/src/agent/agent_docs.cpp b/libminifi/src/agent/agent_docs.cpp index 0b4091bada..30f1b9a9ba 100644 --- a/libminifi/src/agent/agent_docs.cpp +++ b/libminifi/src/agent/agent_docs.cpp @@ -19,6 +19,17 @@ namespace org::apache::nifi::minifi { -std::map AgentDocs::class_mappings_; +namespace { +std::map AgentDocs_class_mappings; +} // namespace + +const std::map& AgentDocs::getClassDescriptions() { + return AgentDocs_class_mappings; +} + +std::map& AgentDocs::getMutableClassDescriptions() { + return AgentDocs_class_mappings; +} + } // namespace org::apache::nifi::minifi diff --git a/libminifi/src/c2/C2Agent.cpp b/libminifi/src/c2/C2Agent.cpp index 33f9fbd019..c890dd7dc8 100644 --- a/libminifi/src/c2/C2Agent.cpp +++ b/libminifi/src/c2/C2Agent.cpp @@ -30,12 +30,10 @@ #include #include "core/ProcessContext.h" -#include "core/StateManager.h" #include "core/state/UpdateController.h" #include "core/logging/Logger.h" #include "core/logging/LoggerConfiguration.h" #include "utils/file/FileUtils.h" -#include "utils/file/FileManager.h" #include "utils/file/FileSystem.h" #include "http/BaseHTTPClient.h" #include "utils/file/PathUtils.h" @@ -445,7 +443,7 @@ void C2Agent::handle_clear(const C2ContentResponse &resp) { } case ClearOperand::corecomponentstate: { for (const auto& corecomponent : resp.operation_arguments) { - auto state_storage = core::ProcessContext::getStateStorage(logger_, controller_, configuration_); + auto state_storage = core::ProcessContextImpl::getStateStorage(logger_, controller_, configuration_); if (state_storage != nullptr) { update_sink_->executeOnComponent(corecomponent.second.to_string(), [this, &state_storage] (state::StateController& component) { logger_->log_debug("Clearing state for component {}", component.getComponentName()); @@ -557,7 +555,7 @@ void C2Agent::handle_describe(const C2ContentResponse &resp) { response.setLabel("corecomponentstate"); C2Payload states(Operation::acknowledge, resp.ident, true); states.setLabel("corecomponentstate"); - auto state_storage = core::ProcessContext::getStateStorage(logger_, controller_, configuration_); + auto state_storage = core::ProcessContextImpl::getStateStorage(logger_, controller_, configuration_); if (state_storage != nullptr) { auto core_component_states = state_storage->getAllStates(); for (const auto& core_component_state : core_component_states) { diff --git a/libminifi/src/c2/C2MetricsPublisher.cpp b/libminifi/src/c2/C2MetricsPublisher.cpp index a58b72bf40..fbc7addd2f 100644 --- a/libminifi/src/c2/C2MetricsPublisher.cpp +++ b/libminifi/src/c2/C2MetricsPublisher.cpp @@ -48,7 +48,7 @@ void C2MetricsPublisher::loadNodeClasses(const std::string& class_definitions, c continue; } for (const auto& response_node : response_nodes) { - static_cast(new_node.get())->add_node(response_node); + dynamic_cast(new_node.get())->add_node(response_node); } } } @@ -114,18 +114,18 @@ state::response::SharedResponseNode C2MetricsPublisher::loadC2ResponseConfigurat std::vector sub_classes = utils::string::split(name, ","); for (const std::string& subClassStr : classes) { auto node = loadC2ResponseConfiguration(subClassStr, prev_node); - static_cast(prev_node.get())->add_node(node); + dynamic_cast(prev_node.get())->add_node(node); } } else { if (configuration_->get(classOption, class_definitions)) { loadNodeClasses(class_definitions, new_node); if (!new_node->isEmpty()) { - static_cast(prev_node.get())->add_node(new_node); + dynamic_cast(prev_node.get())->add_node(new_node); } } else { std::string optionName = utils::string::join_pack(option, ".", name); auto sub_node = loadC2ResponseConfiguration(optionName, new_node); - static_cast(prev_node.get())->add_node(sub_node); + dynamic_cast(prev_node.get())->add_node(sub_node); } } } catch (const std::exception& ex) { diff --git a/libminifi/src/c2/C2Payload.cpp b/libminifi/src/c2/C2Payload.cpp index f21f60437b..6dfc8ad132 100644 --- a/libminifi/src/c2/C2Payload.cpp +++ b/libminifi/src/c2/C2Payload.cpp @@ -21,6 +21,7 @@ #include #include #include "utils/StringUtils.h" +#include "rapidjson/writer.h" namespace org::apache::nifi::minifi::c2 { diff --git a/libminifi/src/c2/ControllerSocketProtocol.cpp b/libminifi/src/c2/ControllerSocketProtocol.cpp index b483af3596..89c4dc9633 100644 --- a/libminifi/src/c2/ControllerSocketProtocol.cpp +++ b/libminifi/src/c2/ControllerSocketProtocol.cpp @@ -143,13 +143,13 @@ void ControllerSocketProtocol::initialize() { if (configuration_->get(Configure::controller_ssl_context_service, context_name)) { std::shared_ptr service = controller_.getControllerService(context_name); if (nullptr != service) { - secure_context = std::static_pointer_cast(service); + secure_context = std::dynamic_pointer_cast(service); } } if (nullptr == 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("ControllerSocketProtocolSSL", configuration_); + secure_context = std::make_shared("ControllerSocketProtocolSSL", configuration_); secure_context->onEnable(); } } diff --git a/libminifi/src/c2/HeartbeatJsonSerializer.cpp b/libminifi/src/c2/HeartbeatJsonSerializer.cpp index a25b47f772..523f268c11 100644 --- a/libminifi/src/c2/HeartbeatJsonSerializer.cpp +++ b/libminifi/src/c2/HeartbeatJsonSerializer.cpp @@ -77,27 +77,27 @@ static void setJsonStr(const std::string& key, const c2::C2Value& value, rapidjs } else { if (type_index == state::response::Value::BOOL_TYPE) { bool value = false; - base_type->convertValue(value); + base_type->getValue(value); valueVal.SetBool(value); } else if (type_index == state::response::Value::INT_TYPE) { int value = 0; - base_type->convertValue(value); + base_type->getValue(value); valueVal.SetInt(value); } else if (type_index == state::response::Value::UINT32_TYPE) { uint32_t value = 0; - base_type->convertValue(value); + base_type->getValue(value); valueVal.SetUint(value); } else if (type_index == state::response::Value::INT64_TYPE) { int64_t value = 0; - base_type->convertValue(value); + base_type->getValue(value); valueVal.SetInt64(value); } else if (type_index == state::response::Value::UINT64_TYPE) { int64_t value = 0; - base_type->convertValue(value); + base_type->getValue(value); valueVal.SetInt64(value); } else if (type_index == state::response::Value::DOUBLE_TYPE) { double value = 0; - base_type->convertValue(value); + base_type->getValue(value); valueVal.SetDouble(value); } else { valueVal.SetString(base_type->getStringValue().c_str(), alloc); diff --git a/libminifi/src/c2/protocols/RESTSender.cpp b/libminifi/src/c2/protocols/RESTSender.cpp index 659ed51db0..8265d82b69 100644 --- a/libminifi/src/c2/protocols/RESTSender.cpp +++ b/libminifi/src/c2/protocols/RESTSender.cpp @@ -27,6 +27,8 @@ #include "core/Resource.h" #include "properties/Configuration.h" #include "io/ZlibStream.h" +#include "controllers/SSLContextService.h" +#include "io/BufferStream.h" using namespace std::literals::chrono_literals; @@ -60,13 +62,13 @@ void RESTSender::initialize(core::controller::ControllerServiceProvider* control } if (controller && configure->get(Configuration::nifi_c2_rest_ssl_context_service, "c2.rest.ssl.context.service", ssl_context_service_str)) { if (auto service = controller->getControllerService(ssl_context_service_str)) { - ssl_context_service_ = std::static_pointer_cast(service); + ssl_context_service_ = std::dynamic_pointer_cast(service); } } if (nullptr == ssl_context_service_) { 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("RESTSenderSSL", configure); + ssl_context_service_ = std::make_shared("RESTSenderSSL", configure); ssl_context_service_->onEnable(); } } @@ -108,7 +110,7 @@ void RESTSender::update(const std::shared_ptr &) { 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("Service", configuration_); + auto generatedService = std::make_shared("Service", configuration_); generatedService->onEnable(); client.initialize(type, url, generatedService); } diff --git a/libminifi/src/controllers/LinuxPowerManagementService.cpp b/libminifi/src/controllers/LinuxPowerManagementService.cpp deleted file mode 100644 index 95075117cd..0000000000 --- a/libminifi/src/controllers/LinuxPowerManagementService.cpp +++ /dev/null @@ -1,190 +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 "controllers/LinuxPowerManagementService.h" - -#include -#include -#include -#include -#include - -#include "utils/gsl.h" -#include "utils/StringUtils.h" -#include "core/Resource.h" - -namespace org::apache::nifi::minifi::controllers { - -bool LinuxPowerManagerService::isAboveMax(int /*new_tasks*/) { - return false; -} - -uint16_t LinuxPowerManagerService::getMaxThreads() { - return std::numeric_limits::max(); -} - -bool LinuxPowerManagerService::canIncrease() { - for (const auto& path_pair : paths_) { - try { - auto capacity = path_pair.first; - auto status = path_pair.second; - - std::ifstream status_file(status); - std::string status_str; - std::getline(status_file, status_str); - status_file.close(); - - if (!utils::string::equalsIgnoreCase(status_keyword_, status_str)) { - return true; - } - } catch (...) { - logger_->log_error("Could not read file paths. ignoring, temporarily"); - } - } - return false; -} - -void LinuxPowerManagerService::reduce() { - auto curr_time = std::chrono::system_clock::now().time_since_epoch() / std::chrono::milliseconds(1); - last_time_ = curr_time; -} - -/** - * We expect that the wait period has been - */ -bool LinuxPowerManagerService::shouldReduce() { - if (!enabled_) { - logger_->log_trace("LPM not enabled"); - return false; - } - - bool overConsume = false; - - std::vector batteryAlert; - - auto prev_level = battery_level_.load(); - - bool all_discharging = !paths_.empty(); - - int battery_sum = 0; - for (const auto& path_pair : paths_) { - try { - auto capacity = path_pair.first; - auto status = path_pair.second; - - std::ifstream capacity_file(capacity); - std::string capacity_str; - std::getline(capacity_file, capacity_str); - capacity_file.close(); - int battery_level = std::stoi(capacity_str); - battery_sum += battery_level; - - std::ifstream status_file(status); - std::string status_str; - std::getline(status_file, status_str); - status_file.close(); - - if (!utils::string::equalsIgnoreCase(status_keyword_, status_str)) { - all_discharging &= false; - } - } catch (...) { - logger_->log_error("Error caught while pulling paths"); - return false; - } - } - - // average - battery_level_ = battery_sum / gsl::narrow(paths_.size()); - - // only reduce if we're still going down OR we've triggered the low battery threshold - if (battery_level_ < trigger_ && (battery_level_ < prev_level || battery_level_ < low_battery_trigger_)) { - if (all_discharging) { - // return true and wait until - if (last_time_ == 0) { - overConsume = true; - last_time_ = std::chrono::system_clock::now().time_since_epoch() / std::chrono::milliseconds(1); - } else { - auto curr_time = std::chrono::system_clock::now().time_since_epoch() / std::chrono::milliseconds(1); - if (curr_time - last_time_ > wait_period_) { - overConsume = true; - logger_->log_trace("All banks are discharging, suggesting reduction"); - } else { - logger_->log_debug("Discharging but can't reduce due to time {} {} {}", curr_time, last_time_.load(), wait_period_.load()); - } - } - } - - } else { - logger_->log_trace("{} level is not below trigger of {}", battery_level_.load(), trigger_); - } - - return overConsume; -} - -void LinuxPowerManagerService::initialize() { - ThreadManagementService::initialize(); - setSupportedProperties(Properties); -} - -void LinuxPowerManagerService::yield() { -} - -bool LinuxPowerManagerService::isRunning() const { - return getState() == core::controller::ControllerServiceState::ENABLED; -} - -bool LinuxPowerManagerService::isWorkAvailable() { - return false; -} - -void LinuxPowerManagerService::onEnable() { - if (nullptr == configuration_) { - logger_->log_trace("Cannot enable Linux Power Manager"); - return; - } - status_keyword_ = "Discharging"; - core::Property capacityPaths; - core::Property statusPaths; - - uint64_t wait = 0; - if (getProperty(TriggerThreshold, trigger_) && getProperty(WaitPeriod, wait)) { - wait_period_ = wait; - - getProperty(BatteryStatusDischargeKeyword, status_keyword_); - - if (!getProperty(LowBatteryThreshold, low_battery_trigger_)) { - low_battery_trigger_ = 0; - } - getProperty(BatteryCapacityPath, capacityPaths); - getProperty(BatteryStatusPath, statusPaths); - if (capacityPaths.getValues().size() == statusPaths.getValues().size()) { - for (size_t i = 0; i < capacityPaths.getValues().size(); i++) { - paths_.push_back(std::make_pair(capacityPaths.getValues().at(i), statusPaths.getValues().at(i))); - } - } else { - logger_->log_error("BatteryCapacityPath and BatteryStatusPath mis-configuration"); - } - - enabled_ = true; - logger_->log_trace("Enabled enable "); - } else { - logger_->log_trace("Could not enable "); - } -} - -REGISTER_RESOURCE(LinuxPowerManagerService, ControllerService); - -} // namespace org::apache::nifi::minifi::controllers diff --git a/libminifi/src/controllers/NetworkPrioritizerService.cpp b/libminifi/src/controllers/NetworkPrioritizerService.cpp index 2676967749..e4c863fec5 100644 --- a/libminifi/src/controllers/NetworkPrioritizerService.cpp +++ b/libminifi/src/controllers/NetworkPrioritizerService.cpp @@ -65,7 +65,7 @@ io::NetworkInterface NetworkPrioritizerService::getInterface(uint32_t size = 0) ifc = get_nearest_interface(controllers); if (!ifc.empty()) { reduce_tokens(size); - io::NetworkInterface newifc(ifc, shared_from_this()); + io::NetworkInterface newifc(ifc, sharedFromThis()); return newifc; } } @@ -181,7 +181,7 @@ void NetworkPrioritizerService::onEnable() { bool is_default = false; if (getProperty(DefaultPrioritizer, is_default)) { if (is_default) { - if (io::NetworkPrioritizerFactory::getInstance()->setPrioritizer(shared_from_this()) < 0) { + if (io::NetworkPrioritizerFactory::getInstance()->setPrioritizer(sharedFromThis()) < 0) { throw std::runtime_error("Can only have one prioritizer"); } } diff --git a/libminifi/src/controllers/SSLContextService.cpp b/libminifi/src/controllers/SSLContextService.cpp index 820e9401b8..71998a4791 100644 --- a/libminifi/src/controllers/SSLContextService.cpp +++ b/libminifi/src/controllers/SSLContextService.cpp @@ -72,20 +72,21 @@ std::string getCertName(const utils::tls::X509_unique_ptr& cert) { #endif } // namespace -void SSLContextService::initialize() { +void SSLContextServiceImpl::initialize() { std::lock_guard lock(initialization_mutex_); if (initialized_) { return; } - ControllerService::initialize(); + ControllerServiceImpl::initialize(); initializeProperties(); initialized_ = true; } -bool SSLContextService::configure_ssl_context(SSL_CTX *ctx) { +bool SSLContextServiceImpl::configure_ssl_context(void* raw_ctx) { + auto* const ctx = static_cast(raw_ctx); if (!certificate_.empty()) { if (isFileTypeP12(certificate_)) { if (!addP12CertificateToSSLContext(ctx)) { @@ -140,27 +141,27 @@ bool SSLContextService::configure_ssl_context(SSL_CTX *ctx) { return true; } -bool SSLContextService::addP12CertificateToSSLContext(SSL_CTX* ctx) const { +bool SSLContextServiceImpl::addP12CertificateToSSLContext(SSL_CTX* ctx) const { auto error = utils::tls::processP12Certificate(certificate_, passphrase_, { - .cert_cb = [&] (auto cert) -> std::error_code { - if (SSL_CTX_use_certificate(ctx, cert.get()) != 1) { - return utils::tls::get_last_ssl_error_code(); - } - return {}; - }, - .chain_cert_cb = [&] (auto cacert) -> std::error_code { - if (SSL_CTX_add_extra_chain_cert(ctx, cacert.get()) != 1) { - return utils::tls::get_last_ssl_error_code(); - } - static_cast(cacert.release()); // a successful SSL_CTX_add_extra_chain_cert() takes ownership of cacert - return {}; - }, - .priv_key_cb = [&] (auto priv_key) -> std::error_code { - if (SSL_CTX_use_PrivateKey(ctx, priv_key.get()) != 1) { - return utils::tls::get_last_ssl_error_code(); + .cert_cb = [&] (auto cert) -> std::error_code { + if (SSL_CTX_use_certificate(ctx, cert.get()) != 1) { + return utils::tls::get_last_ssl_error_code(); + } + return {}; + }, + .chain_cert_cb = [&] (auto cacert) -> std::error_code { + if (SSL_CTX_add_extra_chain_cert(ctx, cacert.get()) != 1) { + return utils::tls::get_last_ssl_error_code(); + } + static_cast(cacert.release()); // a successful SSL_CTX_add_extra_chain_cert() takes ownership of cacert + return {}; + }, + .priv_key_cb = [&] (auto priv_key) -> std::error_code { + if (SSL_CTX_use_PrivateKey(ctx, priv_key.get()) != 1) { + return utils::tls::get_last_ssl_error_code(); + } + return {}; } - return {}; - } }); if (error) { logger_->log_error("{}", error.message()); @@ -169,7 +170,7 @@ bool SSLContextService::addP12CertificateToSSLContext(SSL_CTX* ctx) const { return true; } -bool SSLContextService::addPemCertificateToSSLContext(SSL_CTX* ctx) const { +bool SSLContextServiceImpl::addPemCertificateToSSLContext(SSL_CTX* ctx) const { if (SSL_CTX_use_certificate_chain_file(ctx, certificate_.string().c_str()) <= 0) { logger_->log_error("Could not load client certificate {}, {}", certificate_.string(), getLatestOpenSSLErrorString()); return false; @@ -193,7 +194,7 @@ bool SSLContextService::addPemCertificateToSSLContext(SSL_CTX* ctx) const { } #ifdef WIN32 -bool SSLContextService::findClientCertificate(ClientCertCallback cb) const { +bool SSLContextServiceImpl::findClientCertificate(ClientCertCallback cb) const { utils::tls::WindowsCertStore cert_store(utils::tls::WindowsCertStoreLocation{cert_store_location_}, client_cert_store_); if (auto error = cert_store.error()) { logger_->log_error("Could not open system certificate store {}/{} (client certificates): {}", cert_store_location_, client_cert_store_, error.message()); @@ -215,7 +216,7 @@ bool SSLContextService::findClientCertificate(ClientCertCallback cb) const { #endif #ifdef WIN32 -bool SSLContextService::addClientCertificateFromSystemStoreToSSLContext(SSL_CTX* ctx) const { +bool SSLContextServiceImpl::addClientCertificateFromSystemStoreToSSLContext(SSL_CTX* ctx) const { return findClientCertificate([&] (auto cert, auto priv_key) -> bool { auto cert_name = getCertName(cert); if (SSL_CTX_use_certificate(ctx, cert.get()) != 1) { @@ -231,14 +232,14 @@ bool SSLContextService::addClientCertificateFromSystemStoreToSSLContext(SSL_CTX* }); } #else -bool SSLContextService::addClientCertificateFromSystemStoreToSSLContext(SSL_CTX* /*ctx*/) const { +bool SSLContextServiceImpl::addClientCertificateFromSystemStoreToSSLContext(SSL_CTX* /*ctx*/) const { logger_->log_error("Getting client certificate from the system store is only supported on Windows"); return false; } #endif // WIN32 #ifdef WIN32 -bool SSLContextService::useClientCertificate(PCCERT_CONTEXT certificate, ClientCertCallback cb) const { +bool SSLContextServiceImpl::useClientCertificate(PCCERT_CONTEXT certificate, ClientCertCallback cb) const { utils::tls::X509_unique_ptr x509_cert = utils::tls::convertWindowsCertificate(certificate); if (!x509_cert) { logger_->log_error("Failed to convert system store client certificate to X.509 format"); @@ -282,7 +283,7 @@ bool SSLContextService::useClientCertificate(PCCERT_CONTEXT certificate, ClientC } #endif // WIN32 -bool SSLContextService::addServerCertificatesFromSystemStoreToSSLContext(SSL_CTX* ctx) const { // NOLINT(readability-convert-member-functions-to-static) +bool SSLContextServiceImpl::addServerCertificatesFromSystemStoreToSSLContext(SSL_CTX* ctx) const { // NOLINT(readability-convert-member-functions-to-static) #ifdef WIN32 X509_STORE* ssl_store = SSL_CTX_get_cert_store(ctx); if (!ssl_store) { @@ -322,7 +323,7 @@ bool SSLContextService::addServerCertificatesFromSystemStoreToSSLContext(SSL_CTX } #ifdef WIN32 -bool SSLContextService::findServerCertificate(ServerCertCallback cb) const { +bool SSLContextServiceImpl::findServerCertificate(ServerCertCallback cb) const { utils::tls::WindowsCertStore cert_store(utils::tls::WindowsCertStoreLocation{cert_store_location_}, server_cert_store_); if (auto error = cert_store.error()) { logger_->log_error("Could not open system certificate store {}/{} (server certificates): {}", cert_store_location_, server_cert_store_, error.message()); @@ -342,7 +343,7 @@ bool SSLContextService::findServerCertificate(ServerCertCallback cb) const { #endif #ifdef WIN32 -bool SSLContextService::useServerCertificate(PCCERT_CONTEXT certificate, ServerCertCallback cb) const { +bool SSLContextServiceImpl::useServerCertificate(PCCERT_CONTEXT certificate, ServerCertCallback cb) const { utils::tls::X509_unique_ptr x509_cert = utils::tls::convertWindowsCertificate(certificate); if (!x509_cert) { logger_->log_error("Failed to convert system store server certificate to X.509 format"); @@ -358,7 +359,7 @@ bool SSLContextService::useServerCertificate(PCCERT_CONTEXT certificate, ServerC * be returned and it will be up to the caller to determine if this failure is * recoverable. */ -std::unique_ptr SSLContextService::createSSLContext() { +std::unique_ptr SSLContextServiceImpl::createSSLContext() { SSL_library_init(); const SSL_METHOD *method = nullptr; @@ -379,27 +380,27 @@ std::unique_ptr SSLContextService::createSSLContext() { return std::make_unique(ctx); } -const std::filesystem::path &SSLContextService::getCertificateFile() const { +const std::filesystem::path &SSLContextServiceImpl::getCertificateFile() const { std::lock_guard lock(initialization_mutex_); return certificate_; } -const std::string &SSLContextService::getPassphrase() const { +const std::string &SSLContextServiceImpl::getPassphrase() const { std::lock_guard lock(initialization_mutex_); return passphrase_; } -const std::filesystem::path &SSLContextService::getPrivateKeyFile() const { +const std::filesystem::path &SSLContextServiceImpl::getPrivateKeyFile() const { std::lock_guard lock(initialization_mutex_); return private_key_; } -const std::filesystem::path &SSLContextService::getCACertificate() const { +const std::filesystem::path &SSLContextServiceImpl::getCACertificate() const { std::lock_guard lock(initialization_mutex_); return ca_certificate_; } -void SSLContextService::onEnable() { +void SSLContextServiceImpl::onEnable() { std::filesystem::path default_dir; if (configuration_) { @@ -504,11 +505,11 @@ void SSLContextService::onEnable() { verifyCertificateExpiration(); } -void SSLContextService::initializeProperties() { +void SSLContextServiceImpl::initializeProperties() { setSupportedProperties(Properties); } -void SSLContextService::verifyCertificateExpiration() { +void SSLContextServiceImpl::verifyCertificateExpiration() { auto verify = [&] (const std::filesystem::path& cert_file, const utils::tls::X509_unique_ptr& cert) { if (auto end_date = utils::tls::getCertificateExpiration(cert)) { std::string end_date_str = utils::timeutils::getTimeStr(*end_date); @@ -593,6 +594,6 @@ void SSLContextService::verifyCertificateExpiration() { #endif } -REGISTER_RESOURCE(SSLContextService, ControllerService); +REGISTER_RESOURCE_IMPLEMENTATION(SSLContextServiceImpl, "SSLContextService", ControllerService); } // namespace org::apache::nifi::minifi::controllers diff --git a/libminifi/src/core/ClassLoader.cpp b/libminifi/src/core/ClassLoader.cpp index e8ae594a16..985d4cb723 100644 --- a/libminifi/src/core/ClassLoader.cpp +++ b/libminifi/src/core/ClassLoader.cpp @@ -20,7 +20,7 @@ #include #include -#include "core/logging/LoggerConfiguration.h" +#include "core/logging/LoggerFactory.h" #include "range/v3/action/sort.hpp" #include "range/v3/action/unique.hpp" @@ -30,16 +30,46 @@ namespace nifi { namespace minifi { namespace core { -ClassLoader::ClassLoader(const std::string& name) +class ClassLoaderImpl : public ClassLoader { + public: + explicit ClassLoaderImpl(const std::string& name = "/"); + + ClassLoader& getClassLoader(const std::string& child_name) override; + + void registerClass(const std::string &clazz, std::unique_ptr factory) override; + + void unregisterClass(const std::string& clazz) override; + + std::optional getGroupForClass(const std::string &class_name) const override; + + std::unique_ptr instantiate(const std::string &class_name, const std::string &name, std::function filter) override; + + std::unique_ptr instantiate(const std::string &class_name, const utils::Identifier &uuid, std::function filter) override; + + CoreComponent* instantiateRaw(const std::string &class_name, const std::string &name, std::function filter) override; + + private: + std::map> loaded_factories_; + + std::map class_loaders_; + + mutable std::mutex internal_mutex_; + + std::shared_ptr logger_; + + std::string name_; +}; + +ClassLoaderImpl::ClassLoaderImpl(const std::string& name) : logger_(logging::LoggerFactory::getLogger()), name_(name) {} ClassLoader &ClassLoader::getDefaultClassLoader() { - static ClassLoader ret; + static ClassLoaderImpl ret; // populate ret return ret; } -ClassLoader& ClassLoader::getClassLoader(const std::string& child_name) { +ClassLoader& ClassLoaderImpl::getClassLoader(const std::string& child_name) { std::lock_guard lock(internal_mutex_); auto it = class_loaders_.find(child_name); if (it != class_loaders_.end()) { @@ -51,25 +81,98 @@ ClassLoader& ClassLoader::getClassLoader(const std::string& child_name) { } return name_ + "/" + child_name; }(); - ClassLoader& child = class_loaders_[child_name]; + ClassLoaderImpl& child = class_loaders_[child_name]; child.name_ = std::move(full_name); return child; } -std::vector ClassLoader::getClasses(const std::string& group) const { +void ClassLoaderImpl::registerClass(const std::string &clazz, std::unique_ptr factory) { + std::lock_guard lock(internal_mutex_); + if (loaded_factories_.find(clazz) != loaded_factories_.end()) { + logger_->log_error("Class '{}' is already registered at '{}'", clazz, name_); + return; + } + logger_->log_trace("Registering class '{}' at '{}'", clazz, name_); + loaded_factories_.insert(std::make_pair(clazz, std::move(factory))); + } + +void ClassLoaderImpl::unregisterClass(const std::string& clazz) { + std::lock_guard lock(internal_mutex_); + if (loaded_factories_.erase(clazz) == 0) { + logger_->log_error("Could not unregister non-registered class '{}' at '{}'", clazz, name_); + return; + } else { + logger_->log_trace("Unregistered class '{}' at '{}'", clazz, name_); + } +} + +std::optional ClassLoaderImpl::getGroupForClass(const std::string &class_name) const { std::lock_guard lock(internal_mutex_); - std::vector class_names; for (const auto& child_loader : class_loaders_) { - for (auto&& clazz : child_loader.second.getClasses(group)) { - class_names.push_back(std::move(clazz)); + std::optional group = child_loader.second.getGroupForClass(class_name); + if (group) { + return group; + } + } + auto factory = loaded_factories_.find(class_name); + if (factory != loaded_factories_.end()) { + return factory->second->getGroupName(); + } + return {}; +} + +std::unique_ptr ClassLoaderImpl::instantiate(const std::string &class_name, const std::string &name, std::function filter) { + std::lock_guard lock(internal_mutex_); + // allow subsequent classes to override functionality (like ProcessContextBuilder) + for (auto& child_loader : class_loaders_) { + if (auto result = child_loader.second.instantiate(class_name, name, filter)) { + return result; + } + } + auto factory_entry = loaded_factories_.find(class_name); + if (factory_entry != loaded_factories_.end()) { + auto obj = factory_entry->second->create(name); + if (filter(obj.get())) { + return obj; + } + } + return nullptr; +} + +std::unique_ptr ClassLoaderImpl::instantiate(const std::string &class_name, const utils::Identifier &uuid, std::function filter) { + std::lock_guard lock(internal_mutex_); + // allow subsequent classes to override functionality (like ProcessContextBuilder) + for (auto& child_loader : class_loaders_) { + if (auto result = child_loader.second.instantiate(class_name, uuid, filter)) { + return result; + } + } + auto factory_entry = loaded_factories_.find(class_name); + if (factory_entry != loaded_factories_.end()) { + auto obj = factory_entry->second->create(class_name, uuid); + if (filter(obj.get())) { + return obj; + } + } + return nullptr; +} + +CoreComponent* ClassLoaderImpl::instantiateRaw(const std::string &class_name, const std::string &name, std::function filter) { + std::lock_guard lock(internal_mutex_); + // allow subsequent classes to override functionality (like ProcessContextBuilder) + for (auto& child_loader : class_loaders_) { + if (auto* result = child_loader.second.instantiateRaw(class_name, name, filter)) { + return result; } } - for (const auto& factory : loaded_factories_) { - if (factory.second->getGroupName() == group) { - class_names.push_back(factory.second->getClassName()); + auto factory_entry = loaded_factories_.find(class_name); + if (factory_entry != loaded_factories_.end()) { + auto obj = factory_entry->second->createRaw(name); + if (filter(obj)) { + return obj; } } - return std::move(class_names) | ranges::actions::sort | ranges::actions::unique; + return nullptr; } } /* namespace core */ diff --git a/libminifi/src/core/FlowConfiguration.cpp b/libminifi/src/core/FlowConfiguration.cpp index 53b1e8def1..ce32dd0517 100644 --- a/libminifi/src/core/FlowConfiguration.cpp +++ b/libminifi/src/core/FlowConfiguration.cpp @@ -25,11 +25,12 @@ #include "core/ClassLoader.h" #include "processors/ProcessorUtils.h" #include "utils/StringUtils.h" +#include "utils/file/FileUtils.h" namespace org::apache::nifi::minifi::core { FlowConfiguration::FlowConfiguration(ConfigurationContext ctx) - : CoreComponent(core::className()), + : CoreComponentImpl(core::className()), flow_file_repo_(std::move(ctx.flow_file_repo)), content_repo_(std::move(ctx.content_repo)), configuration_(std::move(ctx.configuration)), @@ -165,10 +166,10 @@ std::unique_ptr FlowConfiguration::createConnection(const st if (flow_file_repo_) { auto swap_manager = std::dynamic_pointer_cast(flow_file_repo_); if (swap_manager) { - return std::make_unique(flow_file_repo_, content_repo_, std::move(swap_manager), name, uuid); + return std::make_unique(flow_file_repo_, content_repo_, std::move(swap_manager), name, uuid); } } - return std::make_unique(flow_file_repo_, content_repo_, name, uuid); + return std::make_unique(flow_file_repo_, content_repo_, name, uuid); } std::shared_ptr FlowConfiguration::createControllerService(const std::string &class_name, const std::string &full_class_name, const std::string &name, diff --git a/libminifi/src/core/FlowFile.cpp b/libminifi/src/core/FlowFile.cpp index 0940203190..ad96944ee6 100644 --- a/libminifi/src/core/FlowFile.cpp +++ b/libminifi/src/core/FlowFile.cpp @@ -28,12 +28,12 @@ namespace org::apache::nifi::minifi { namespace core { -std::shared_ptr FlowFile::id_generator_ = utils::IdGenerator::getIdGenerator(); -std::shared_ptr FlowFile::numeric_id_generator_ = std::make_shared(); -std::shared_ptr FlowFile::logger_ = logging::LoggerFactory::getLogger(); +std::shared_ptr FlowFileImpl::id_generator_ = utils::IdGenerator::getIdGenerator(); +std::shared_ptr FlowFileImpl::numeric_id_generator_ = std::make_shared(); +std::shared_ptr FlowFileImpl::logger_ = logging::LoggerFactory::getLogger(); -FlowFile::FlowFile() - : CoreComponent("FlowFile"), +FlowFileImpl::FlowFileImpl() + : CoreComponentImpl("FlowFile"), stored(false), marked_delete_(false), entry_date_(std::chrono::system_clock::now()), @@ -46,7 +46,7 @@ FlowFile::FlowFile() to_be_processed_after_(std::chrono::steady_clock::now()) { } -FlowFile& FlowFile::operator=(const FlowFile& other) { +FlowFileImpl& FlowFileImpl::operator=(const FlowFileImpl& other) { if (this == &other) { return *this; } @@ -70,7 +70,7 @@ FlowFile& FlowFile::operator=(const FlowFile& other) { * is marked as deleted. * @return marked deleted */ -bool FlowFile::isDeleted() const { +bool FlowFileImpl::isDeleted() const { return marked_delete_; } @@ -79,29 +79,29 @@ bool FlowFile::isDeleted() const { * as deleted * @param deleted deleted flag */ -void FlowFile::setDeleted(const bool deleted) { +void FlowFileImpl::setDeleted(const bool deleted) { marked_delete_ = deleted; if (marked_delete_) { removeReferences(); } } -std::shared_ptr FlowFile::getResourceClaim() const { +std::shared_ptr FlowFileImpl::getResourceClaim() const { return claim_; } -void FlowFile::clearResourceClaim() { +void FlowFileImpl::clearResourceClaim() { claim_ = nullptr; } -void FlowFile::setResourceClaim(const std::shared_ptr& claim) { +void FlowFileImpl::setResourceClaim(const std::shared_ptr& claim) { claim_ = claim; } -std::shared_ptr FlowFile::getStashClaim(const std::string& key) { +std::shared_ptr FlowFileImpl::getStashClaim(const std::string& key) { return stashedContent_[key]; } -void FlowFile::setStashClaim(const std::string& key, const std::shared_ptr& claim) { +void FlowFileImpl::setStashClaim(const std::string& key, const std::shared_ptr& claim) { if (hasStashClaim(key)) { logger_->log_warn("Stashing content of record {} to existing key {}; " "existing content will be overwritten", @@ -111,7 +111,7 @@ void FlowFile::setStashClaim(const std::string& key, const std::shared_ptrsecond = nullptr; @@ -119,31 +119,31 @@ void FlowFile::clearStashClaim(const std::string& key) { } } -bool FlowFile::hasStashClaim(const std::string& key) { +bool FlowFileImpl::hasStashClaim(const std::string& key) { return stashedContent_.find(key) != stashedContent_.end(); } // ! Get Entry Date -std::chrono::system_clock::time_point FlowFile::getEntryDate() const { +std::chrono::system_clock::time_point FlowFileImpl::getEntryDate() const { return entry_date_; } -std::chrono::system_clock::time_point FlowFile::getEventTime() const { +std::chrono::system_clock::time_point FlowFileImpl::getEventTime() const { return event_time_; } // ! Get Lineage Start Date -std::chrono::system_clock::time_point FlowFile::getlineageStartDate() const { +std::chrono::system_clock::time_point FlowFileImpl::getlineageStartDate() const { return lineage_start_date_; } -const std::vector& FlowFile::getlineageIdentifiers() const { +const std::vector& FlowFileImpl::getlineageIdentifiers() const { return lineage_Identifiers_; } -std::vector& FlowFile::getlineageIdentifiers() { +std::vector& FlowFileImpl::getlineageIdentifiers() { return lineage_Identifiers_; } -bool FlowFile::getAttribute(std::string_view key, std::string& value) const { +bool FlowFileImpl::getAttribute(std::string_view key, std::string& value) const { const auto attribute = getAttribute(key); if (!attribute) { return false; @@ -152,7 +152,7 @@ bool FlowFile::getAttribute(std::string_view key, std::string& value) const { return true; } -std::optional FlowFile::getAttribute(std::string_view key) const { +std::optional FlowFileImpl::getAttribute(std::string_view key) const { auto it = attributes_.find(key); if (it != attributes_.end()) { return it->second; @@ -161,15 +161,15 @@ std::optional FlowFile::getAttribute(std::string_view key) const { } // Get Size -uint64_t FlowFile::getSize() const { +uint64_t FlowFileImpl::getSize() const { return size_; } // ! Get Offset -uint64_t FlowFile::getOffset() const { +uint64_t FlowFileImpl::getOffset() const { return offset_; } -bool FlowFile::removeAttribute(std::string_view key) { +bool FlowFileImpl::removeAttribute(std::string_view key) { auto it = attributes_.find(key); if (it != attributes_.end()) { attributes_.erase(it); @@ -179,7 +179,7 @@ bool FlowFile::removeAttribute(std::string_view key) { } } -bool FlowFile::updateAttribute(std::string_view key, const std::string& value) { +bool FlowFileImpl::updateAttribute(std::string_view key, const std::string& value) { auto it = attributes_.find(key); if (it != attributes_.end()) { it->second = value; @@ -189,7 +189,7 @@ bool FlowFile::updateAttribute(std::string_view key, const std::string& value) { } } -bool FlowFile::addAttribute(std::string_view key, const std::string& value) { +bool FlowFileImpl::addAttribute(std::string_view key, const std::string& value) { auto it = attributes_.find(key); if (it != attributes_.end()) { // attribute already there in the map @@ -200,7 +200,7 @@ bool FlowFile::addAttribute(std::string_view key, const std::string& value) { } } -void FlowFile::setLineageStartDate(const std::chrono::system_clock::time_point date) { +void FlowFileImpl::setLineageStartDate(const std::chrono::system_clock::time_point date) { lineage_start_date_ = date; } @@ -208,7 +208,7 @@ void FlowFile::setLineageStartDate(const std::chrono::system_clock::time_point d * Sets the original connection with a shared pointer. * @param connection shared connection. */ -void FlowFile::setConnection(core::Connectable* connection) { +void FlowFileImpl::setConnection(core::Connectable* connection) { connection_ = connection; } @@ -216,7 +216,7 @@ void FlowFile::setConnection(core::Connectable* connection) { * Returns the original connection referenced by this record. * @return shared original connection pointer. */ -core::Connectable* FlowFile::getConnection() const { +core::Connectable* FlowFileImpl::getConnection() const { return connection_; } diff --git a/libminifi/src/core/ForwardingContentSession.cpp b/libminifi/src/core/ForwardingContentSession.cpp index 2dfd08d7f6..86105bab68 100644 --- a/libminifi/src/core/ForwardingContentSession.cpp +++ b/libminifi/src/core/ForwardingContentSession.cpp @@ -29,10 +29,10 @@ namespace org::apache::nifi::minifi::core { -ForwardingContentSession::ForwardingContentSession(std::shared_ptr repository) : ContentSession(std::move(repository)) {} +ForwardingContentSession::ForwardingContentSession(std::shared_ptr repository) : ContentSessionImpl(std::move(repository)) {} std::shared_ptr ForwardingContentSession::create() { - auto claim = std::make_shared(repository_); + auto claim = ResourceClaim::create(repository_); created_claims_.insert(claim); return claim; } diff --git a/libminifi/src/core/ProcessContextBuilder.cpp b/libminifi/src/core/ProcessContextBuilder.cpp index 6408a8fc9e..9e9d3f8f2b 100644 --- a/libminifi/src/core/ProcessContextBuilder.cpp +++ b/libminifi/src/core/ProcessContextBuilder.cpp @@ -15,54 +15,10 @@ * limitations under the License. */ #include "core/ProcessContextBuilder.h" -#include -#include -#include "core/logging/LoggerConfiguration.h" #include "core/Resource.h" namespace org::apache::nifi::minifi::core { -ProcessContextBuilder::ProcessContextBuilder(std::string_view name, const minifi::utils::Identifier &uuid) - : core::CoreComponent(name, uuid) { - content_repo_ = std::make_shared(); - configuration_ = std::make_shared(); -} - -ProcessContextBuilder::ProcessContextBuilder(std::string_view name) - : core::CoreComponent(name) { - content_repo_ = std::make_shared(); - configuration_ = std::make_shared(); -} - -std::shared_ptr ProcessContextBuilder::withProvider(core::controller::ControllerServiceProvider* controller_service_provider) { - controller_service_provider_ = controller_service_provider; - return this->shared_from_this(); -} - -std::shared_ptr ProcessContextBuilder::withProvenanceRepository(const std::shared_ptr &repo) { - prov_repo_ = repo; - return this->shared_from_this(); -} - -std::shared_ptr ProcessContextBuilder::withFlowFileRepository(const std::shared_ptr &repo) { - flow_repo_ = repo; - return this->shared_from_this(); -} - -std::shared_ptr ProcessContextBuilder::withContentRepository(const std::shared_ptr &repo) { - content_repo_ = repo; - return this->shared_from_this(); -} - -std::shared_ptr ProcessContextBuilder::withConfiguration(const std::shared_ptr &configuration) { - configuration_ = configuration; - return this->shared_from_this(); -} - -std::shared_ptr ProcessContextBuilder::build(const std::shared_ptr &processor) { - return std::make_shared(processor, controller_service_provider_, prov_repo_, flow_repo_, configuration_, content_repo_); -} - -REGISTER_RESOURCE(ProcessContextBuilder, InternalResource); +REGISTER_RESOURCE_IMPLEMENTATION(ProcessContextBuilderImpl, "ProcessContextBuilder", InternalResource); } // namespace org::apache::nifi::minifi::core diff --git a/libminifi/src/core/ProcessGroup.cpp b/libminifi/src/core/ProcessGroup.cpp index 7fdcf175d9..013f408217 100644 --- a/libminifi/src/core/ProcessGroup.cpp +++ b/libminifi/src/core/ProcessGroup.cpp @@ -44,7 +44,7 @@ ProcessGroup::ProcessGroup(ProcessGroupType type, std::string_view name, const u } ProcessGroup::ProcessGroup(ProcessGroupType type, std::string_view name, const utils::Identifier& uuid, int version, ProcessGroup* parent) - : CoreComponent(name, uuid, id_generator_), + : CoreComponentImpl(name, uuid, id_generator_), config_version_(version), type_(type), parent_process_group_(parent), @@ -56,7 +56,7 @@ ProcessGroup::ProcessGroup(ProcessGroupType type, std::string_view name, const u } ProcessGroup::ProcessGroup(ProcessGroupType type, std::string_view name) - : CoreComponent(name, {}, id_generator_), + : CoreComponentImpl(name, {}, id_generator_), config_version_(0), type_(type), parent_process_group_(nullptr), @@ -99,7 +99,7 @@ void ProcessGroup::addPort(std::unique_ptr port) { auto [processor, inserted] = addProcessor(std::move(port)); if (inserted) { std::lock_guard lock(mutex_); - ports_.insert(static_cast(processor)); + ports_.insert(dynamic_cast(processor)); } } @@ -400,13 +400,13 @@ void ProcessGroup::addConnection(std::unique_ptr connection) { // only allow connections between processors of the same process group or in/output ports of child process groups // check input and output ports connection restrictions inside and outside a process group Processor* source = findPortById(insertedConnection->getSourceUUID()); - if (source && static_cast(source)->getPortType() == PortType::OUTPUT) { + if (source && dynamic_cast(source)->getPortType() == PortType::OUTPUT) { logger_->log_error("Output port [id = '{}'] cannot be a source inside the process group in the connection [name = '{}', id = '{}']", insertedConnection->getSourceUUID().to_string(), insertedConnection->getName(), insertedConnection->getUUIDStr()); source = nullptr; } else if (!source) { source = findChildPortById(insertedConnection->getSourceUUID()); - if (source && static_cast(source)->getPortType() == PortType::INPUT) { + if (source && dynamic_cast(source)->getPortType() == PortType::INPUT) { logger_->log_error("Input port [id = '{}'] cannot be a source outside the process group in the connection [name = '{}', id = '{}']", insertedConnection->getSourceUUID().to_string(), insertedConnection->getName(), insertedConnection->getUUIDStr()); source = nullptr; @@ -424,13 +424,13 @@ void ProcessGroup::addConnection(std::unique_ptr connection) { } Processor* destination = findPortById(insertedConnection->getDestinationUUID()); - if (destination && static_cast(destination)->getPortType() == PortType::INPUT) { + if (destination && dynamic_cast(destination)->getPortType() == PortType::INPUT) { logger_->log_error("Input port [id = '{}'] cannot be a destination inside the process group in the connection [name = '{}', id = '{}']", insertedConnection->getDestinationUUID().to_string(), insertedConnection->getName(), insertedConnection->getUUIDStr()); destination = nullptr; } else if (!destination) { destination = findChildPortById(insertedConnection->getDestinationUUID()); - if (destination && static_cast(destination)->getPortType() == PortType::OUTPUT) { + if (destination && dynamic_cast(destination)->getPortType() == PortType::OUTPUT) { logger_->log_error("Output port [id = '{}'] cannot be a destination outside the process group in the connection [name = '{}', id = '{}']", insertedConnection->getDestinationUUID().to_string(), insertedConnection->getName(), insertedConnection->getUUIDStr()); destination = nullptr; diff --git a/libminifi/src/core/ProcessSession.cpp b/libminifi/src/core/ProcessSession.cpp index 79c02ff63e..30068310ef 100644 --- a/libminifi/src/core/ProcessSession.cpp +++ b/libminifi/src/core/ProcessSession.cpp @@ -53,23 +53,21 @@ int getpagesize(void) { // GetSystemInfo(&system_info); // return system_info.dwPageSize; } +#else +#include #endif namespace org::apache::nifi::minifi::core { -std::string detail::to_string(const detail::ReadBufferResult& read_buffer_result) { - return {reinterpret_cast(read_buffer_result.buffer.data()), read_buffer_result.buffer.size()}; -} - -std::shared_ptr ProcessSession::id_generator_ = utils::IdGenerator::getIdGenerator(); +std::shared_ptr ProcessSessionImpl::id_generator_ = utils::IdGenerator::getIdGenerator(); -ProcessSession::ProcessSession(std::shared_ptr processContext) +ProcessSessionImpl::ProcessSessionImpl(std::shared_ptr processContext) : process_context_(std::move(processContext)), logger_(logging::LoggerFactory::getLogger()), stateManager_(process_context_->hasStateManager() ? process_context_->getStateManager() : nullptr) { logger_->log_trace("ProcessSession created for {}", process_context_->getProcessorNode()->getName()); auto repo = process_context_->getProvenanceRepository(); - provenance_report_ = std::make_shared(repo, process_context_->getProcessorNode()->getName(), process_context_->getProcessorNode()->getName()); + provenance_report_ = std::make_shared(repo, process_context_->getProcessorNode()->getName(), process_context_->getProcessorNode()->getName()); content_session_ = process_context_->getContentRepository()->createSession(); if (stateManager_ && !stateManager_->beginTransaction()) { @@ -77,7 +75,7 @@ ProcessSession::ProcessSession(std::shared_ptr processContext) } } -ProcessSession::~ProcessSession() { +ProcessSessionImpl::~ProcessSessionImpl() { if (stateManager_ && stateManager_->isTransactionInProgress()) { logger_->log_critical("Session has ended without decision on state (commit or rollback)."); std::terminate(); @@ -85,7 +83,7 @@ ProcessSession::~ProcessSession() { removeReferences(); } -void ProcessSession::add(const std::shared_ptr &record) { +void ProcessSessionImpl::add(const std::shared_ptr &record) { utils::Identifier uuid = record->getUUID(); if (updated_flowfiles_.find(uuid) != updated_flowfiles_.end()) { throw Exception(ExceptionType::PROCESSOR_EXCEPTION, "Mustn't add file that was provided by this session"); @@ -94,8 +92,8 @@ void ProcessSession::add(const std::shared_ptr &record) { record->setDeleted(false); } -std::shared_ptr ProcessSession::create(const core::FlowFile* const parent) { - auto record = std::make_shared(); +std::shared_ptr ProcessSessionImpl::create(const core::FlowFile* const parent) { + auto record = std::make_shared(); auto flow_version = process_context_->getProcessorNode()->getFlowIdentifier(); if (flow_version != nullptr) { record->setAttribute(SpecialFlowAttribute::FLOW_ID, flow_version->getFlowId()); @@ -124,7 +122,7 @@ std::shared_ptr ProcessSession::create(const core::FlowFile* con return record; } -std::shared_ptr ProcessSession::clone(const core::FlowFile& parent) { +std::shared_ptr ProcessSessionImpl::clone(const core::FlowFile& parent) { std::shared_ptr record = this->create(&parent); if (record) { logger_->log_debug("Cloned parent flow files {} to {}", parent.getUUIDStr(), record->getUUIDStr()); @@ -140,8 +138,8 @@ std::shared_ptr ProcessSession::clone(const core::FlowFile& pare return record; } -std::shared_ptr ProcessSession::cloneDuringTransfer(const core::FlowFile& parent) { - auto record = std::make_shared(); +std::shared_ptr ProcessSessionImpl::cloneDuringTransfer(const core::FlowFile& parent) { + auto record = std::make_shared(); auto flow_version = process_context_->getProcessorNode()->getFlowIdentifier(); if (flow_version != nullptr) { @@ -175,7 +173,7 @@ std::shared_ptr ProcessSession::cloneDuringTransfer(const core:: return record; } -std::shared_ptr ProcessSession::clone(const FlowFile& parent, int64_t offset, int64_t size) { +std::shared_ptr ProcessSessionImpl::clone(const FlowFile& parent, int64_t offset, int64_t size) { if (gsl::narrow(offset + size) > parent.getSize()) { // Set offset and size logger_->log_error("clone offset {} and size {} exceed parent size {}", offset, size, parent.getSize()); @@ -197,7 +195,7 @@ std::shared_ptr ProcessSession::clone(const FlowFile& parent, in return record; } -void ProcessSession::remove(const std::shared_ptr &flow) { +void ProcessSessionImpl::remove(const std::shared_ptr &flow) { logger_->log_debug("Removing flow file with UUID: {}", flow->getUUIDStr()); flow->setDeleted(true); deleted_flowfiles_.push_back(flow); @@ -205,25 +203,25 @@ void ProcessSession::remove(const std::shared_ptr &flow) { provenance_report_->drop(*flow, reason); } -void ProcessSession::putAttribute(core::FlowFile& flow_file, std::string_view key, const std::string& value) { +void ProcessSessionImpl::putAttribute(core::FlowFile& flow_file, std::string_view key, const std::string& value) { flow_file.setAttribute(key, value); std::string details = fmt::format("{} modify flow record {} attribute {}:{}", process_context_->getProcessorNode()->getName(), flow_file.getUUIDStr(), key, value); provenance_report_->modifyAttributes(flow_file, details); } -void ProcessSession::removeAttribute(core::FlowFile& flow_file, std::string_view key) { +void ProcessSessionImpl::removeAttribute(core::FlowFile& flow_file, std::string_view key) { flow_file.removeAttribute(key); std::string details = fmt::format("{} remove flow record {} attribute {}", process_context_->getProcessorNode()->getName(), flow_file.getUUIDStr(), key); provenance_report_->modifyAttributes(flow_file, details); } -void ProcessSession::penalize(const std::shared_ptr &flow) { +void ProcessSessionImpl::penalize(const std::shared_ptr &flow) { const std::chrono::milliseconds penalization_period = process_context_->getProcessorNode()->getPenalizationPeriod(); logger_->log_info("Penalizing {} for {} at {}", flow->getUUIDStr(), penalization_period, process_context_->getProcessorNode()->getName()); - flow->penalize(penalization_period); + std::dynamic_pointer_cast(flow)->penalize(penalization_period); } -void ProcessSession::transfer(const std::shared_ptr& flow, const Relationship& relationship) { +void ProcessSessionImpl::transfer(const std::shared_ptr& flow, const Relationship& relationship) { logger_->log_debug("Transferring {} from {} to relationship {}", flow->getUUIDStr(), process_context_->getProcessorNode()->getName(), relationship.getName()); utils::Identifier uuid = flow->getUUID(); if (auto it = added_flowfiles_.find(uuid); it != added_flowfiles_.end()) { @@ -234,15 +232,15 @@ void ProcessSession::transfer(const std::shared_ptr& flow, const flow->setDeleted(false); } -void ProcessSession::transferToCustomRelationship(const std::shared_ptr& flow, const std::string& relationship_name) { +void ProcessSessionImpl::transferToCustomRelationship(const std::shared_ptr& flow, const std::string& relationship_name) { transfer(flow, Relationship{relationship_name, relationship_name}); } -void ProcessSession::write(const std::shared_ptr &flow, const io::OutputStreamCallback& callback) { +void ProcessSessionImpl::write(const std::shared_ptr &flow, const io::OutputStreamCallback& callback) { return write(*flow, callback); } -void ProcessSession::write(core::FlowFile &flow, const io::OutputStreamCallback& callback) { +void ProcessSessionImpl::write(core::FlowFile &flow, const io::OutputStreamCallback& callback) { gsl_ExpectsAudit(updated_flowfiles_.contains(flow.getUUID()) || added_flowfiles_.contains(flow.getUUID()) || std::any_of(cloned_flowfiles_.begin(), cloned_flowfiles_.end(), [&flow](const auto& flow_file) { return &flow == flow_file.get(); })); @@ -277,17 +275,17 @@ void ProcessSession::write(core::FlowFile &flow, const io::OutputStreamCallback& } } -void ProcessSession::writeBuffer(const std::shared_ptr& flow_file, std::span buffer) { +void ProcessSessionImpl::writeBuffer(const std::shared_ptr& flow_file, std::span buffer) { writeBuffer(flow_file, as_bytes(buffer)); } -void ProcessSession::writeBuffer(const std::shared_ptr& flow_file, std::span buffer) { +void ProcessSessionImpl::writeBuffer(const std::shared_ptr& flow_file, std::span buffer) { write(flow_file, [buffer](const std::shared_ptr& output_stream) { const auto write_status = output_stream->write(buffer); return io::isError(write_status) ? -1 : gsl::narrow(write_status); }); } -void ProcessSession::append(const std::shared_ptr &flow, const io::OutputStreamCallback& callback) { +void ProcessSessionImpl::append(const std::shared_ptr &flow, const io::OutputStreamCallback& callback) { gsl_ExpectsAudit(updated_flowfiles_.contains(flow->getUUID()) || added_flowfiles_.contains(flow->getUUID()) || std::any_of(cloned_flowfiles_.begin(), cloned_flowfiles_.end(), [&flow](const auto& flow_file) { return flow == flow_file; })); @@ -329,10 +327,10 @@ void ProcessSession::append(const std::shared_ptr &flow, const i throw; } } -void ProcessSession::appendBuffer(const std::shared_ptr& flow_file, std::span buffer) { +void ProcessSessionImpl::appendBuffer(const std::shared_ptr& flow_file, std::span buffer) { appendBuffer(flow_file, as_bytes(buffer)); } -void ProcessSession::appendBuffer(const std::shared_ptr& flow_file, std::span buffer) { +void ProcessSessionImpl::appendBuffer(const std::shared_ptr& flow_file, std::span buffer) { if (buffer.empty()) { return; } append(flow_file, [buffer](const std::shared_ptr& output_stream) { const auto write_status = output_stream->write(buffer); @@ -340,7 +338,7 @@ void ProcessSession::appendBuffer(const std::shared_ptr& flow_fi }); } -std::shared_ptr ProcessSession::getFlowFileContentStream(const core::FlowFile& flow_file) { +std::shared_ptr ProcessSessionImpl::getFlowFileContentStream(const core::FlowFile& flow_file) { if (flow_file.getResourceClaim() == nullptr) { logger_->log_debug("For {}, no resource claim but size is {}", flow_file.getUUIDStr(), flow_file.getSize()); if (flow_file.getSize() == 0) { @@ -358,11 +356,11 @@ std::shared_ptr ProcessSession::getFlowFileContentStream(const return std::make_shared(stream, flow_file.getOffset(), flow_file.getSize()); } -int64_t ProcessSession::read(const std::shared_ptr& flow_file, const io::InputStreamCallback& callback) { +int64_t ProcessSessionImpl::read(const std::shared_ptr& flow_file, const io::InputStreamCallback& callback) { return read(*flow_file, callback); } -int64_t ProcessSession::read(const core::FlowFile& flow_file, const io::InputStreamCallback& callback) { +int64_t ProcessSessionImpl::read(const core::FlowFile& flow_file, const io::InputStreamCallback& callback) { try { auto flow_file_stream = getFlowFileContentStream(flow_file); if (!flow_file_stream) { @@ -384,7 +382,7 @@ int64_t ProcessSession::read(const core::FlowFile& flow_file, const io::InputStr } -int64_t ProcessSession::readWrite(const std::shared_ptr &flow, const io::InputOutputStreamCallback& callback) { +int64_t ProcessSessionImpl::readWrite(const std::shared_ptr &flow, const io::InputOutputStreamCallback& callback) { gsl_Expects(callback); try { @@ -431,7 +429,7 @@ int64_t ProcessSession::readWrite(const std::shared_ptr &flow, c } } -detail::ReadBufferResult ProcessSession::readBuffer(const std::shared_ptr& flow) { +detail::ReadBufferResult ProcessSessionImpl::readBuffer(const std::shared_ptr& flow) { detail::ReadBufferResult result; result.status = read(flow, [&result, this](const std::shared_ptr& input_stream) { result.buffer.resize(input_stream->size()); @@ -445,7 +443,7 @@ detail::ReadBufferResult ProcessSession::readBuffer(const std::shared_ptr &flow) { +void ProcessSessionImpl::importFrom(io::InputStream&& stream, const std::shared_ptr &flow) { importFrom(stream, flow); } /** @@ -454,7 +452,7 @@ void ProcessSession::importFrom(io::InputStream&& stream, const std::shared_ptr< * @param flow flow file * */ -void ProcessSession::importFrom(io::InputStream &stream, const std::shared_ptr &flow) { +void ProcessSessionImpl::importFrom(io::InputStream &stream, const std::shared_ptr &flow) { const std::shared_ptr claim = content_session_->create(); const auto max_read = gsl::narrow_cast(getpagesize()); std::vector buffer(max_read); @@ -499,7 +497,7 @@ void ProcessSession::importFrom(io::InputStream &stream, const std::shared_ptr &flow, bool keepSource, uint64_t offset) { +void ProcessSessionImpl::import(const std::string& source, const std::shared_ptr &flow, bool keepSource, uint64_t offset) { std::shared_ptr claim = content_session_->create(); size_t size = getpagesize(); std::vector charBuffer(size); @@ -572,133 +570,7 @@ void ProcessSession::import(const std::string& source, const std::shared_ptr> &flows, uint64_t offset, char inputDelimiter) { - std::shared_ptr claim; - std::shared_ptr stream; - std::shared_ptr flowFile; - - std::vector buffer(getpagesize()); - try { - std::ifstream input{source, std::ios::in | std::ios::binary}; - logger_->log_debug("Opening {}", source); - if (!input.is_open() || !input.good()) { - throw Exception(FILE_OPERATION_EXCEPTION, utils::string::join_pack("File Import Error: failed to open file \'", source, "\'")); - } - if (offset != 0U) { - input.seekg(gsl::narrow(offset), std::ifstream::beg); - if (!input.good()) { - logger_->log_error("Seeking to {} failed for file {} (does file/filesystem support seeking?)", offset, source); - throw Exception(FILE_OPERATION_EXCEPTION, utils::string::join_pack("File Import Error: Couldn't seek to offset ", std::to_string(offset))); - } - } - while (input.good()) { - input.read(reinterpret_cast(buffer.data()), gsl::narrow(buffer.size())); - std::streamsize read = input.gcount(); - if (read < 0) { - throw Exception(FILE_OPERATION_EXCEPTION, "std::ifstream::gcount returned negative value"); - } - if (read == 0) { - logger_->log_trace("Finished reading input {}", source); - break; - } else { - logger_->log_trace("Read input of {}", read); - } - uint8_t* begin = buffer.data(); - uint8_t* end = begin + read; - while (true) { - auto start_time = std::chrono::steady_clock::now(); - uint8_t* delimiterPos = std::find(begin, end, static_cast(inputDelimiter)); - const auto len = gsl::narrow(delimiterPos - begin); - - logger_->log_trace("Read input of {} length is {} is at end? {}", read, len, delimiterPos == end); - /* - * We do not want to process the rest of the buffer after the last delimiter if - * - we have reached EOF in the file (we would discard it anyway) - * - there is nothing to process (the last character in the buffer is a delimiter) - */ - if (delimiterPos == end && (input.eof() || len == 0)) { - break; - } - - /* Create claim and stream if needed and append data */ - if (claim == nullptr) { - start_time = std::chrono::steady_clock::now(); - claim = content_session_->create(); - } - if (stream == nullptr) { - stream = content_session_->write(claim); - } - if (stream == nullptr) { - logger_->log_error("Stream is null"); - throw Exception(FILE_OPERATION_EXCEPTION, "Failed to open flowfile content for import"); - } - if (stream->write(begin, len) != len) { - logger_->log_error("Error while writing"); - stream->close(); - throw Exception(FILE_OPERATION_EXCEPTION, "File Export Error creating Flowfile"); - } - - /* Create a FlowFile if we reached a delimiter */ - if (delimiterPos == end) { - break; - } - flowFile = create(); - flowFile->setSize(stream->size()); - flowFile->setOffset(0); - flowFile->setResourceClaim(claim); - logger_->log_debug("Import offset {} length {} into content {}, FlowFile UUID {}", - flowFile->getOffset(), flowFile->getSize(), flowFile->getResourceClaim()->getContentFullPath(), flowFile->getUUIDStr()); - stream->close(); - std::string details = process_context_->getProcessorNode()->getName() + " modify flow record content " + flowFile->getUUIDStr(); - auto duration = std::chrono::duration_cast(std::chrono::steady_clock::now() - start_time); - provenance_report_->modifyContent(*flowFile, details, duration); - flows.push_back(flowFile); - - /* Reset these to start processing the next FlowFile with a clean slate */ - flowFile.reset(); - stream.reset(); - claim.reset(); - - /* Skip delimiter */ - begin = delimiterPos + 1; - } - } - } catch (const std::exception& exception) { - logger_->log_debug("Caught Exception during ProcessSession::import, type: {}, what: {}", typeid(exception).name(), exception.what()); - throw; - } catch (...) { - logger_->log_debug("Caught Exception during ProcessSession::import, type: {}", getCurrentExceptionTypeName()); - throw; - } -} - -void ProcessSession::import(const std::string& source, std::vector> &flows, bool keepSource, uint64_t offset, char inputDelimiter) { -// this function calls a deprecated function, but it is itself deprecated, so suppress warnings -#if defined(__clang__) -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wdeprecated-declarations" -#elif defined(__GNUC__) -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wdeprecated-declarations" -#elif defined(WIN32) -#pragma warning(push) -#pragma warning(disable: 4996) -#endif - import(source, flows, offset, inputDelimiter); -#if defined(__clang__) -#pragma clang diagnostic pop -#elif defined(__GNUC__) -#pragma GCC diagnostic pop -#elif defined(WIN32) -#pragma warning(pop) -#endif - logger_->log_trace("Closed input {}, keeping source ? {}", source, keepSource); - if (!keepSource) { - (void)std::remove(source.c_str()); - } -} - -bool ProcessSession::exportContent(const std::string &destination, const std::string &tmpFile, const std::shared_ptr &flow, bool /*keepContent*/) { +bool ProcessSessionImpl::exportContent(const std::string &destination, const std::string &tmpFile, const std::shared_ptr &flow, bool /*keepContent*/) { logger_->log_debug("Exporting content of {} to {}", flow->getUUIDStr(), destination); ProcessSessionReadCallback cb(tmpFile, destination, logger_); @@ -715,7 +587,7 @@ bool ProcessSession::exportContent(const std::string &destination, const std::st return commit_ok; } -bool ProcessSession::exportContent(const std::string &destination, const std::shared_ptr &flow, bool keepContent) { +bool ProcessSessionImpl::exportContent(const std::string &destination, const std::shared_ptr &flow, bool keepContent) { utils::Identifier tmpFileUuid = id_generator_->generate(); std::stringstream tmpFileSs; tmpFileSs << destination << "." << tmpFileUuid.to_string(); @@ -724,7 +596,7 @@ bool ProcessSession::exportContent(const std::string &destination, const std::sh return exportContent(destination, tmpFileName, flow, keepContent); } -void ProcessSession::stash(const std::string &key, const std::shared_ptr &flow) { +void ProcessSessionImpl::stash(const std::string &key, const std::shared_ptr &flow) { logger_->log_debug("Stashing content from {} to key {}", flow->getUUIDStr(), key); auto claim = flow->getResourceClaim(); @@ -742,7 +614,7 @@ void ProcessSession::stash(const std::string &key, const std::shared_ptrclearResourceClaim(); } -void ProcessSession::restore(const std::string &key, const std::shared_ptr &flow) { +void ProcessSessionImpl::restore(const std::string &key, const std::shared_ptr &flow) { logger_->log_info("Restoring content to {} from key {}", flow->getUUIDStr(), key); // Restore the claim @@ -764,7 +636,7 @@ void ProcessSession::restore(const std::string &key, const std::shared_ptrclearStashClaim(key); } -ProcessSession::RouteResult ProcessSession::routeFlowFile(const std::shared_ptr &record, const std::function& transfer_callback) { +ProcessSessionImpl::RouteResult ProcessSessionImpl::routeFlowFile(const std::shared_ptr &record, const std::function& transfer_callback) { if (record->isDeleted()) { return RouteResult::Ok_Deleted; } @@ -815,7 +687,7 @@ ProcessSession::RouteResult ProcessSession::routeFlowFile(const std::shared_ptr< return RouteResult::Ok_Routed; } -void ProcessSession::commit() { +void ProcessSessionImpl::commit() { const auto commit_start_time = std::chrono::steady_clock::now(); try { std::unordered_map transfers; @@ -913,8 +785,8 @@ void ProcessSession::commit() { if (metrics_) { for (const auto& [relationship_name, transfer_metrics] : transfers) { - metrics_->transferred_bytes += transfer_metrics.transfer_size; - metrics_->transferred_flow_files += transfer_metrics.transfer_count; + metrics_->transferredBytes() += transfer_metrics.transfer_size; + metrics_->transferredFlowFiles() += transfer_metrics.transfer_count; metrics_->increaseRelationshipTransferCount(relationship_name, transfer_metrics.transfer_count); } } @@ -941,7 +813,7 @@ void ProcessSession::commit() { } } -void ProcessSession::rollback() { +void ProcessSessionImpl::rollback() { // new FlowFiles are only persisted during commit // no need to delete them here std::map>> connectionQueues; @@ -951,7 +823,7 @@ void ProcessSession::rollback() { for (const auto &it : updated_flowfiles_) { auto flowFile = it.second.modified; // restore flowFile to original state - *flowFile = *it.second.snapshot; + flowFile->copy(*it.second.snapshot); penalize(flowFile); logger_->log_debug("ProcessSession rollback for {}, record {}, to connection {}", process_context_->getProcessorNode()->getName(), @@ -997,7 +869,7 @@ void ProcessSession::rollback() { } } -nonstd::expected ProcessSession::rollbackNoThrow() noexcept { +nonstd::expected ProcessSessionImpl::rollbackNoThrow() noexcept { try { rollback(); return {}; @@ -1006,7 +878,7 @@ nonstd::expected ProcessSession::rollbackNoThrow() noe } } -void ProcessSession::persistFlowFilesBeforeTransfer( +void ProcessSessionImpl::persistFlowFilesBeforeTransfer( std::map > >& transactionMap, const std::map& modifiedFlowFiles) { @@ -1043,7 +915,7 @@ void ProcessSession::persistFlowFilesBeforeTransfer( // collect serialized flowfiles forEachFlowFile(Type::Transferred, [&] (auto& ff, auto& /*original*/) { auto stream = std::make_unique(); - std::static_pointer_cast(ff)->Serialize(*stream); + std::dynamic_pointer_cast(ff)->Serialize(*stream); flowData.emplace_back(ff->getUUIDStr(), std::move(stream)); }); @@ -1083,7 +955,7 @@ void ProcessSession::persistFlowFilesBeforeTransfer( }); } -void ProcessSession::ensureNonNullResourceClaim( +void ProcessSessionImpl::ensureNonNullResourceClaim( const std::map>> &transactionMap) { for (auto& transaction : transactionMap) { for (auto& flowFile : transaction.second) { @@ -1099,7 +971,7 @@ void ProcessSession::ensureNonNullResourceClaim( } } -std::shared_ptr ProcessSession::get() { +std::shared_ptr ProcessSessionImpl::get() { const auto first = process_context_->getProcessorNode()->pickIncomingConnection(); if (first == nullptr) { @@ -1132,8 +1004,8 @@ std::shared_ptr ProcessSession::get() { if (ret) { // add the flow record to the current process session update map ret->setDeleted(false); - std::shared_ptr snapshot = std::make_shared(); - *snapshot = *ret; + std::shared_ptr snapshot = std::make_shared(); + snapshot->copy(*ret); logger_->log_debug("Create Snapshot FlowFile with UUID {}", snapshot->getUUIDStr()); utils::Identifier uuid = ret->getUUID(); updated_flowfiles_[uuid] = {ret, snapshot}; @@ -1149,11 +1021,11 @@ std::shared_ptr ProcessSession::get() { return nullptr; } -void ProcessSession::flushContent() { +void ProcessSessionImpl::flushContent() { content_session_->commit(); } -bool ProcessSession::outgoingConnectionsFull(const std::string& relationship) { +bool ProcessSessionImpl::outgoingConnectionsFull(const std::string& relationship) { std::set connections = process_context_->getProcessorNode()->getOutGoingConnections(relationship); Connection * connection = nullptr; for (const auto conn : connections) { @@ -1165,7 +1037,7 @@ bool ProcessSession::outgoingConnectionsFull(const std::string& relationship) { return false; } -bool ProcessSession::existsFlowFileInRelationship(const Relationship &relationship) { +bool ProcessSessionImpl::existsFlowFileInRelationship(const Relationship &relationship) { return std::any_of(updated_relationships_.begin(), updated_relationships_.end(), [&](const auto& key_value_pair) { return key_value_pair.second && relationship == *key_value_pair.second; @@ -1175,7 +1047,7 @@ bool ProcessSession::existsFlowFileInRelationship(const Relationship &relationsh }); } -bool ProcessSession::hasBeenTransferred(const core::FlowFile &flow) const { +bool ProcessSessionImpl::hasBeenTransferred(const core::FlowFile &flow) const { return (updated_relationships_.contains(flow.getUUID()) && updated_relationships_.at(flow.getUUID()) != nullptr) || (added_flowfiles_.contains(flow.getUUID()) && added_flowfiles_.at(flow.getUUID()).rel != nullptr); } diff --git a/libminifi/src/core/ProcessSessionFactory.cpp b/libminifi/src/core/ProcessSessionFactory.cpp index 4a6f21a11b..148a3f4fde 100644 --- a/libminifi/src/core/ProcessSessionFactory.cpp +++ b/libminifi/src/core/ProcessSessionFactory.cpp @@ -27,8 +27,8 @@ namespace nifi { namespace minifi { namespace core { -std::shared_ptr ProcessSessionFactory::createSession() { - return std::make_shared(process_context_); +std::shared_ptr ProcessSessionFactoryImpl::createSession() { + return std::make_shared(process_context_); } } /* namespace core */ diff --git a/libminifi/src/core/ProcessorNode.cpp b/libminifi/src/core/ProcessorNode.cpp index 026ad86cbe..486c41ac0b 100644 --- a/libminifi/src/core/ProcessorNode.cpp +++ b/libminifi/src/core/ProcessorNode.cpp @@ -20,19 +20,19 @@ #include namespace org::apache::nifi::minifi::core { -ProcessorNode::ProcessorNode(Connectable* processor) - : Connectable(processor->getName()), +ProcessorNodeImpl::ProcessorNodeImpl(Connectable* processor) + : ConnectableImpl(processor->getName()), processor_(processor) { setUUID(processor->getUUID()); } -ProcessorNode::~ProcessorNode() = default; +ProcessorNodeImpl::~ProcessorNodeImpl() = default; -bool ProcessorNode::isWorkAvailable() { +bool ProcessorNodeImpl::isWorkAvailable() { return processor_->isWorkAvailable(); } -bool ProcessorNode::isRunning() const { +bool ProcessorNodeImpl::isRunning() const { return processor_->isRunning(); } diff --git a/libminifi/src/core/RecordField.cpp b/libminifi/src/core/RecordField.cpp index 32042618dc..bbc6c2a40d 100644 --- a/libminifi/src/core/RecordField.cpp +++ b/libminifi/src/core/RecordField.cpp @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include "core/RecordField.h" +#include "minifi-cpp/core/RecordField.h" #include "utils/GeneralUtils.h" #include "utils/TimeUtil.h" diff --git a/libminifi/src/core/RepositoryFactory.cpp b/libminifi/src/core/RepositoryFactory.cpp index 77685d37b4..eb1669468a 100644 --- a/libminifi/src/core/RepositoryFactory.cpp +++ b/libminifi/src/core/RepositoryFactory.cpp @@ -59,10 +59,10 @@ std::unique_ptr createContentRepository(const std::stri throw std::runtime_error("Support for the provided configuration class could not be found"); } -class NoOpThreadedRepository : public core::ThreadedRepository { +class NoOpThreadedRepository : public core::ThreadedRepositoryImpl { public: explicit NoOpThreadedRepository(std::string_view repo_name) - : ThreadedRepository(repo_name) { + : ThreadedRepositoryImpl(repo_name) { } NoOpThreadedRepository(NoOpThreadedRepository&&) = delete; diff --git a/libminifi/src/core/controller/ControllerServiceNode.cpp b/libminifi/src/core/controller/ControllerServiceNode.cpp index 183ee80a58..a41a31f84e 100644 --- a/libminifi/src/core/controller/ControllerServiceNode.cpp +++ b/libminifi/src/core/controller/ControllerServiceNode.cpp @@ -22,15 +22,15 @@ namespace org::apache::nifi::minifi::core::controller { -std::shared_ptr ControllerServiceNode::getControllerServiceImplementation() { +std::shared_ptr ControllerServiceNodeImpl::getControllerServiceImplementation() { return controller_service_; } -const ControllerService* ControllerServiceNode::getControllerServiceImplementation() const { +const ControllerService* ControllerServiceNodeImpl::getControllerServiceImplementation() const { return controller_service_.get(); } -const std::vector& ControllerServiceNode::getLinkedControllerServices() const { +const std::vector& ControllerServiceNodeImpl::getLinkedControllerServices() const { return linked_controller_services_; } diff --git a/libminifi/src/core/controller/ControllerServiceProvider.cpp b/libminifi/src/core/controller/ControllerServiceProvider.cpp index ae783a6d0d..44eadc2c65 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 ControllerServiceProvider::getControllerService(const std::string &identifier) const { +std::shared_ptr ControllerServiceProviderImpl::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 ControllerServiceProvider::getControllerServi } } -std::shared_ptr ControllerServiceProvider::getControllerService(const std::string &identifier, const utils::Identifier &processor_uuid) const { +std::shared_ptr ControllerServiceProviderImpl::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 ControllerServiceProvider::getControllerServi } } -void ControllerServiceProvider::putControllerServiceNode(const std::string& identifier, const std::shared_ptr& controller_service_node, ProcessGroup* process_group) { +void ControllerServiceProviderImpl::putControllerServiceNode(const std::string& identifier, const std::shared_ptr& 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/extension/DynamicLibrary.cpp b/libminifi/src/core/extension/DynamicLibrary.cpp index b1e5f47a89..3a6f5d90bb 100644 --- a/libminifi/src/core/extension/DynamicLibrary.cpp +++ b/libminifi/src/core/extension/DynamicLibrary.cpp @@ -36,7 +36,7 @@ #include "core/extension/DynamicLibrary.h" #include "core/extension/Extension.h" #include "utils/GeneralUtils.h" -#include "core/logging/LoggerConfiguration.h" +#include "core/logging/LoggerFactory.h" namespace org::apache::nifi::minifi::core::extension { diff --git a/libminifi/src/core/extension/ExtensionManager.cpp b/libminifi/src/core/extension/ExtensionManager.cpp index 90074e8599..ea22de7816 100644 --- a/libminifi/src/core/extension/ExtensionManager.cpp +++ b/libminifi/src/core/extension/ExtensionManager.cpp @@ -29,9 +29,9 @@ namespace org::apache::nifi::minifi::core::extension { -const std::shared_ptr ExtensionManager::logger_ = logging::LoggerFactory::getLogger(); +const std::shared_ptr ExtensionManagerImpl::logger_ = logging::LoggerFactory::getLogger(); -ExtensionManager::ExtensionManager() +ExtensionManagerImpl::ExtensionManagerImpl() : modules_([] { std::vector> modules; modules.push_back(std::make_unique()); @@ -40,14 +40,18 @@ ExtensionManager::ExtensionManager() active_module_(modules_[0].get()) { } -ExtensionManager& ExtensionManager::get() { - static ExtensionManager instance; +ExtensionManagerImpl& ExtensionManagerImpl::get() { + static ExtensionManagerImpl instance; return instance; } +ExtensionManager& ExtensionManager::get() { + return ExtensionManagerImpl::get(); +} + constexpr const char* DEFAULT_EXTENSION_PATH = "../extensions/*"; -bool ExtensionManager::initialize(const std::shared_ptr& config) { +bool ExtensionManagerImpl::initialize(const std::shared_ptr& config) { static bool initialized = ([&] { logger_->log_trace("Initializing extensions"); // initialize executable @@ -104,11 +108,11 @@ bool ExtensionManager::initialize(const std::shared_ptr& config) { return initialized; } -void ExtensionManager::registerExtension(Extension& extension) { +void ExtensionManagerImpl::registerExtension(Extension& extension) { active_module_->registerExtension(extension); } -void ExtensionManager::unregisterExtension(Extension& extension) { +void ExtensionManagerImpl::unregisterExtension(Extension& extension) { for (const auto& module : modules_) { if (module->unregisterExtension(extension)) { return; diff --git a/libminifi/src/core/extension/Module.cpp b/libminifi/src/core/extension/Module.cpp index cdbde28d55..026dfdd1b8 100644 --- a/libminifi/src/core/extension/Module.cpp +++ b/libminifi/src/core/extension/Module.cpp @@ -19,7 +19,7 @@ #include #include -#include "core/logging/LoggerConfiguration.h" +#include "core/logging/LoggerFactory.h" #include "utils/gsl.h" #include "properties/Configure.h" #include "core/extension/Module.h" diff --git a/libminifi/src/core/logging/Logger.cpp b/libminifi/src/core/logging/LoggerBase.cpp similarity index 78% rename from libminifi/src/core/logging/Logger.cpp rename to libminifi/src/core/logging/LoggerBase.cpp index 7ae7f53f4b..f4415a891c 100644 --- a/libminifi/src/core/logging/Logger.cpp +++ b/libminifi/src/core/logging/LoggerBase.cpp @@ -16,7 +16,7 @@ * limitations under the License. */ -#include "core/logging/Logger.h" +#include "core/logging/LoggerBase.h" #include #include @@ -36,10 +36,8 @@ void LoggerControl::setEnabled(bool status) { is_enabled_ = status; } -BaseLogger::~BaseLogger() = default; - -bool Logger::should_log(LOG_LEVEL level) { +bool LoggerBase::should_log(LOG_LEVEL level) { if (controller_ && !controller_->is_enabled()) return false; @@ -47,19 +45,19 @@ bool Logger::should_log(LOG_LEVEL level) { return delegate_->should_log(mapToSpdLogLevel(level)); } -void Logger::log_string(LOG_LEVEL level, std::string str) { - log(mapToSpdLogLevel(level), "{}", str); +void LoggerBase::log_string(LOG_LEVEL level, std::string str) { + delegate_->log(mapToSpdLogLevel(level), str.c_str()); } -LOG_LEVEL Logger::level() const { +LOG_LEVEL LoggerBase::level() const { return mapFromSpdLogLevel(delegate_->level()); } -Logger::Logger(std::shared_ptr delegate, std::shared_ptr controller) +LoggerBase::LoggerBase(std::shared_ptr delegate, std::shared_ptr controller) : delegate_(std::move(delegate)), controller_(std::move(controller)) { } -Logger::Logger(std::shared_ptr delegate) +LoggerBase::LoggerBase(std::shared_ptr delegate) : delegate_(std::move(delegate)), controller_(nullptr) { } diff --git a/libminifi/src/core/repository/FileSystemRepository.cpp b/libminifi/src/core/repository/FileSystemRepository.cpp index 99c69f7593..dc2d0ae508 100644 --- a/libminifi/src/core/repository/FileSystemRepository.cpp +++ b/libminifi/src/core/repository/FileSystemRepository.cpp @@ -69,7 +69,7 @@ bool FileSystemRepository::removeKey(const std::string& content_path) { } std::shared_ptr FileSystemRepository::createSession() { - return std::make_shared(sharedFromThis()); + return std::make_shared(sharedFromThis()); } void FileSystemRepository::clearOrphans() { @@ -111,4 +111,8 @@ uint64_t FileSystemRepository::getRepositoryEntryCount() const { [](auto& entry) { return entry.is_regular_file(); }); } +std::shared_ptr createFileSystemRepository() { + return std::make_shared(); +} + } // namespace org::apache::nifi::minifi::core::repository diff --git a/libminifi/src/core/repository/VolatileRepository.cpp b/libminifi/src/core/repository/VolatileRepository.cpp index 36465d2df0..be092c03b2 100644 --- a/libminifi/src/core/repository/VolatileRepository.cpp +++ b/libminifi/src/core/repository/VolatileRepository.cpp @@ -26,10 +26,10 @@ namespace org::apache::nifi::minifi::core::repository { bool VolatileRepository::initialize(const std::shared_ptr &configure) { - repo_data_.initialize(configure, core::ThreadedRepository::getName()); + repo_data_.initialize(configure, core::ThreadedRepositoryImpl::getName()); - logger_->log_info("Resizing value_vector for {} count is {}", core::ThreadedRepository::getName(), repo_data_.max_count); - logger_->log_info("Using a maximum size for {} of {}", core::ThreadedRepository::getName(), repo_data_.max_size); + logger_->log_info("Resizing value_vector for {} count is {}", core::ThreadedRepositoryImpl::getName(), repo_data_.max_count); + logger_->log_info("Using a maximum size for {} of {}", core::ThreadedRepositoryImpl::getName(), repo_data_.max_size); return true; } diff --git a/libminifi/src/core/state/LogMetricsPublisher.cpp b/libminifi/src/core/state/LogMetricsPublisher.cpp index e31428a5ab..f057ab85a5 100644 --- a/libminifi/src/core/state/LogMetricsPublisher.cpp +++ b/libminifi/src/core/state/LogMetricsPublisher.cpp @@ -30,7 +30,7 @@ LogMetricsPublisher::~LogMetricsPublisher() { } void LogMetricsPublisher::initialize(const std::shared_ptr& configuration, const std::shared_ptr& response_node_loader) { - state::MetricsPublisher::initialize(configuration, response_node_loader); + state::MetricsPublisherImpl::initialize(configuration, response_node_loader); readLoggingInterval(); readLogLevel(); } diff --git a/libminifi/src/core/state/MetricsPublisherFactory.cpp b/libminifi/src/core/state/MetricsPublisherFactory.cpp index aba0ddf11d..de19b3ddfa 100644 --- a/libminifi/src/core/state/MetricsPublisherFactory.cpp +++ b/libminifi/src/core/state/MetricsPublisherFactory.cpp @@ -18,6 +18,7 @@ #include "core/state/MetricsPublisherFactory.h" #include "utils/StringUtils.h" +#include "core/ClassLoader.h" namespace org::apache::nifi::minifi::state { diff --git a/libminifi/src/core/state/MetricsPublisherStore.cpp b/libminifi/src/core/state/MetricsPublisherStore.cpp index abd1550d88..85fddb39a6 100644 --- a/libminifi/src/core/state/MetricsPublisherStore.cpp +++ b/libminifi/src/core/state/MetricsPublisherStore.cpp @@ -25,7 +25,7 @@ namespace org::apache::nifi::minifi::state { MetricsPublisherStore::MetricsPublisherStore(std::shared_ptr configuration, const std::vector>& repository_metric_sources, std::shared_ptr flow_configuration, utils::file::AssetManager* asset_manager) : configuration_(configuration), - response_node_loader_(std::make_shared(std::move(configuration), repository_metric_sources, std::move(flow_configuration), asset_manager)) { + response_node_loader_(std::make_shared(std::move(configuration), repository_metric_sources, std::move(flow_configuration), asset_manager)) { } void MetricsPublisherStore::initialize(core::controller::ControllerServiceProvider* controller, state::StateMonitor* update_sink) { diff --git a/libminifi/src/core/state/Value.cpp b/libminifi/src/core/state/Value.cpp index 78df36be2e..062601b3d9 100644 --- a/libminifi/src/core/state/Value.cpp +++ b/libminifi/src/core/state/Value.cpp @@ -21,6 +21,9 @@ #include #include #include "rapidjson/prettywriter.h" +#include "utils/gsl.h" +#include "rapidjson/document.h" +#include "utils/StringUtils.h" namespace org::apache::nifi::minifi::state::response { @@ -57,7 +60,7 @@ std::string hashResponseNodes(const std::vector& nodes) return utils::string::to_hex(digest, true /*uppercase*/); } -rapidjson::Value SerializedResponseNode::nodeToJson(const SerializedResponseNode& node, rapidjson::MemoryPoolAllocator& alloc) { +rapidjson::Value nodeToJson(const SerializedResponseNode& node, rapidjson::MemoryPoolAllocator& alloc) { if (node.value.empty()) { if (node.array) { rapidjson::Value result(rapidjson::kArrayType); @@ -77,8 +80,23 @@ rapidjson::Value SerializedResponseNode::nodeToJson(const SerializedResponseNode } } +template +[[nodiscard]] std::string to_string(const SerializedResponseNode& node) { + rapidjson::Document doc; + doc.SetObject(); + doc.AddMember(rapidjson::Value(node.name.c_str(), doc.GetAllocator()), nodeToJson(node, doc.GetAllocator()), doc.GetAllocator()); + rapidjson::StringBuffer buf; + Writer writer{buf}; + doc.Accept(writer); + return buf.GetString(); +} + +std::string SerializedResponseNode::to_string() const { + return response::to_string>(*this); +} + std::string SerializedResponseNode::to_pretty_string() const { - return to_string>(); + return response::to_string>(*this); } } // namespace org::apache::nifi::minifi::state::response diff --git a/libminifi/src/core/state/nodes/DeviceInformation.cpp b/libminifi/src/core/state/nodes/DeviceInformation.cpp index fb81e7634c..92b8465939 100644 --- a/libminifi/src/core/state/nodes/DeviceInformation.cpp +++ b/libminifi/src/core/state/nodes/DeviceInformation.cpp @@ -21,6 +21,8 @@ #include #include "core/Resource.h" +#include "utils/net/NetworkInterfaceInfo.h" +#include "utils/OsUtils.h" namespace org::apache::nifi::minifi::state::response { diff --git a/libminifi/src/core/state/nodes/ResponseNodeLoader.cpp b/libminifi/src/core/state/nodes/ResponseNodeLoader.cpp index 68b74da48d..5442e08908 100644 --- a/libminifi/src/core/state/nodes/ResponseNodeLoader.cpp +++ b/libminifi/src/core/state/nodes/ResponseNodeLoader.cpp @@ -33,7 +33,7 @@ namespace org::apache::nifi::minifi::state::response { -ResponseNodeLoader::ResponseNodeLoader(std::shared_ptr configuration, std::vector> repository_metric_sources, +ResponseNodeLoaderImpl::ResponseNodeLoaderImpl(std::shared_ptr configuration, std::vector> repository_metric_sources, std::shared_ptr flow_configuration, utils::file::AssetManager* asset_manager) : configuration_(std::move(configuration)), repository_metric_sources_(std::move(repository_metric_sources)), @@ -41,7 +41,7 @@ ResponseNodeLoader::ResponseNodeLoader(std::shared_ptr configuration, asset_manager_(asset_manager) { } -void ResponseNodeLoader::clearConfigRoot() { +void ResponseNodeLoaderImpl::clearConfigRoot() { { std::lock_guard guard(system_metrics_mutex_); system_metrics_.clear(); @@ -56,7 +56,7 @@ void ResponseNodeLoader::clearConfigRoot() { } } -void ResponseNodeLoader::setNewConfigRoot(core::ProcessGroup* root) { +void ResponseNodeLoaderImpl::setNewConfigRoot(core::ProcessGroup* root) { { std::lock_guard guard(root_mutex_); root_ = root; @@ -64,7 +64,7 @@ void ResponseNodeLoader::setNewConfigRoot(core::ProcessGroup* root) { initializeComponentMetrics(); } -void ResponseNodeLoader::initializeComponentMetrics() { +void ResponseNodeLoaderImpl::initializeComponentMetrics() { { std::lock_guard guard(component_metrics_mutex_); component_metrics_.clear(); @@ -94,7 +94,7 @@ void ResponseNodeLoader::initializeComponentMetrics() { } } -nonstd::expected ResponseNodeLoader::getSystemMetricsNode(const std::string& clazz) { +nonstd::expected ResponseNodeLoaderImpl::getSystemMetricsNode(const std::string& clazz) { std::lock_guard guard(system_metrics_mutex_); if (system_metrics_.contains(clazz)) { return system_metrics_.at(clazz); @@ -109,7 +109,7 @@ nonstd::expected ResponseNodeLoader::getSystemM return system_metrics_.at(clazz); } -std::vector ResponseNodeLoader::getResponseNodes(const std::string& clazz) { +std::vector ResponseNodeLoaderImpl::getResponseNodes(const std::string& clazz) { auto component_metrics = getComponentMetricsNodes(clazz); if (!component_metrics.empty()) { return component_metrics; @@ -122,7 +122,7 @@ std::vector ResponseNodeLoader::getResponseNodes(const std:: return {*response_node}; } -void ResponseNodeLoader::initializeRepositoryMetrics(const SharedResponseNode& response_node) const { +void ResponseNodeLoaderImpl::initializeRepositoryMetrics(const SharedResponseNode& response_node) const { auto repository_metrics = dynamic_cast(response_node.get()); if (repository_metrics != nullptr) { for (const auto& repo : repository_metric_sources_) { @@ -131,7 +131,7 @@ void ResponseNodeLoader::initializeRepositoryMetrics(const SharedResponseNode& r } } -void ResponseNodeLoader::initializeQueueMetrics(const SharedResponseNode& response_node) const { +void ResponseNodeLoaderImpl::initializeQueueMetrics(const SharedResponseNode& response_node) const { std::lock_guard guard(root_mutex_); if (!root_) { return; @@ -147,14 +147,14 @@ void ResponseNodeLoader::initializeQueueMetrics(const SharedResponseNode& respon } } -void ResponseNodeLoader::initializeAgentIdentifier(const SharedResponseNode& response_node) const { +void ResponseNodeLoaderImpl::initializeAgentIdentifier(const SharedResponseNode& response_node) const { auto identifier = dynamic_cast(response_node.get()); if (identifier != nullptr) { identifier->setAgentIdentificationProvider(configuration_); } } -void ResponseNodeLoader::initializeAgentMonitor(const SharedResponseNode& response_node) const { +void ResponseNodeLoaderImpl::initializeAgentMonitor(const SharedResponseNode& response_node) const { auto monitor = dynamic_cast(response_node.get()); if (monitor != nullptr) { for (const auto& repo : repository_metric_sources_) { @@ -164,7 +164,7 @@ void ResponseNodeLoader::initializeAgentMonitor(const SharedResponseNode& respon } } -void ResponseNodeLoader::initializeAgentNode(const SharedResponseNode& response_node) const { +void ResponseNodeLoaderImpl::initializeAgentNode(const SharedResponseNode& response_node) const { auto agent_node = dynamic_cast(response_node.get()); if (agent_node != nullptr && controller_ != nullptr) { if (auto service = controller_->getControllerService(c2::UPDATE_NAME)) { @@ -182,7 +182,7 @@ void ResponseNodeLoader::initializeAgentNode(const SharedResponseNode& response_ } } -void ResponseNodeLoader::initializeAgentStatus(const SharedResponseNode& response_node) const { +void ResponseNodeLoaderImpl::initializeAgentStatus(const SharedResponseNode& response_node) const { auto agent_status = dynamic_cast(response_node.get()); if (agent_status != nullptr) { for (const auto& repo : repository_metric_sources_) { @@ -192,7 +192,7 @@ void ResponseNodeLoader::initializeAgentStatus(const SharedResponseNode& respons } } -void ResponseNodeLoader::initializeConfigurationChecksums(const SharedResponseNode& response_node) const { +void ResponseNodeLoaderImpl::initializeConfigurationChecksums(const SharedResponseNode& response_node) const { auto configuration_checksums = dynamic_cast(response_node.get()); if (configuration_checksums) { configuration_checksums->addChecksumCalculator(configuration_->getChecksumCalculator()); @@ -202,14 +202,14 @@ void ResponseNodeLoader::initializeConfigurationChecksums(const SharedResponseNo } } -void ResponseNodeLoader::initializeAssetInformation(const SharedResponseNode& response_node) const { +void ResponseNodeLoaderImpl::initializeAssetInformation(const SharedResponseNode& response_node) const { auto asset_info = dynamic_cast(response_node.get()); if (asset_info) { asset_info->setAssetManager(asset_manager_); } } -void ResponseNodeLoader::initializeFlowMonitor(const SharedResponseNode& response_node) const { +void ResponseNodeLoaderImpl::initializeFlowMonitor(const SharedResponseNode& response_node) const { auto flowMonitor = dynamic_cast(response_node.get()); if (flowMonitor == nullptr) { return; @@ -230,7 +230,7 @@ void ResponseNodeLoader::initializeFlowMonitor(const SharedResponseNode& respons } } -std::vector ResponseNodeLoader::loadResponseNodes(const std::string& clazz) { +std::vector ResponseNodeLoaderImpl::loadResponseNodes(const std::string& clazz) { auto response_nodes = getResponseNodes(clazz); if (response_nodes.empty()) { logger_->log_error("No metric defined for {}", clazz); @@ -251,7 +251,7 @@ std::vector ResponseNodeLoader::loadResponseNodes(const std: return response_nodes; } -std::vector ResponseNodeLoader::getMatchingComponentMetricsNodes(const std::string& regex_str) const { +std::vector ResponseNodeLoaderImpl::getMatchingComponentMetricsNodes(const std::string& regex_str) const { std::vector result; for (const auto& [metric_name, metrics] : component_metrics_) { utils::Regex regex(regex_str); @@ -262,7 +262,7 @@ std::vector ResponseNodeLoader::getMatchingComponentMetricsN return result; } -std::vector ResponseNodeLoader::getComponentMetricsNodes(const std::string& metrics_class) const { +std::vector ResponseNodeLoaderImpl::getComponentMetricsNodes(const std::string& metrics_class) const { if (metrics_class.empty()) { return {}; } @@ -280,15 +280,15 @@ std::vector ResponseNodeLoader::getComponentMetricsNodes(con return {}; } -void ResponseNodeLoader::setControllerServiceProvider(core::controller::ControllerServiceProvider* controller) { +void ResponseNodeLoaderImpl::setControllerServiceProvider(core::controller::ControllerServiceProvider* controller) { controller_ = controller; } -void ResponseNodeLoader::setStateMonitor(state::StateMonitor* update_sink) { +void ResponseNodeLoaderImpl::setStateMonitor(state::StateMonitor* update_sink) { update_sink_ = update_sink; } -state::response::NodeReporter::ReportedNode ResponseNodeLoader::getAgentManifest() const { +state::response::NodeReporter::ReportedNode ResponseNodeLoaderImpl::getAgentManifest() const { state::response::AgentInformation agentInfo("agentInfo"); if (controller_) { if (auto service = controller_->getControllerService(c2::UPDATE_NAME)) { diff --git a/libminifi/src/http/HTTPClient.cpp b/libminifi/src/http/HTTPClient.cpp index cb5baa2fea..84f71bdc4d 100644 --- a/libminifi/src/http/HTTPClient.cpp +++ b/libminifi/src/http/HTTPClient.cpp @@ -15,516 +15,10 @@ * limitations under the License. */ #include "http/HTTPClient.h" - -#include -#include -#include -#include -#include - #include "core/Resource.h" -#include "magic_enum.hpp" -#include "range/v3/algorithm/all_of.hpp" -#include "range/v3/action/transform.hpp" -#include "utils/gsl.h" -#include "utils/HTTPUtils.h" -#include "utils/Literals.h" -#include "utils/StringUtils.h" - -using namespace std::literals::chrono_literals; namespace org::apache::nifi::minifi::http { -HTTPClient::HTTPClient(std::string url, std::shared_ptr ssl_context_service) - : core::Connectable("HTTPClient"), - ssl_context_service_(std::move(ssl_context_service)), - url_(std::move(url)) { - http_session_.reset(curl_easy_init()); -} - -HTTPClient::HTTPClient(std::string_view name, const utils::Identifier& uuid) - : core::Connectable(name, uuid) { - http_session_.reset(curl_easy_init()); -} - -HTTPClient::HTTPClient() - : core::Connectable("HTTPClient") { - http_session_.reset(curl_easy_init()); -} - -void HTTPClient::addFormPart(const std::string& content_type, const std::string& name, std::unique_ptr form_callback, const std::optional& filename) { - if (!form_) { - form_.reset(curl_mime_init(http_session_.get())); - } - form_callback_ = std::move(form_callback); - curl_mimepart* part = curl_mime_addpart(form_.get()); - curl_mime_type(part, content_type.c_str()); - if (filename) { - curl_mime_filename(part, filename->c_str()); - } - curl_mime_name(part, name.c_str()); - curl_mime_data_cb(part, gsl::narrow(form_callback_->size()), - &HTTPRequestResponse::send_write, nullptr, nullptr, static_cast(form_callback_.get())); -} - -HTTPClient::~HTTPClient() { - // forceClose ended up not being the issue in MINIFICPP-667, but leaving here - // out of good hygiene. - forceClose(); - content_.close(); - logger_->log_trace("Closing HTTPClient for {}", url_); -} - -void HTTPClient::forceClose() { - if (nullptr != read_callback_) { - read_callback_->stop = true; - } - - if (nullptr != write_callback_) { - write_callback_->requestStop(); - } -} - -int HTTPClient::debug_callback(CURL *handle, curl_infotype type, char *data, size_t size, void *userptr) { - auto* const logger = static_cast*>(userptr); - if (logger == nullptr) { - return 0; - } - if (type == CURLINFO_TEXT) { - (*logger)->log_debug("CURL({}): {:.{}}", handle, data, size); - } - return 0; -} - -void HTTPClient::setVerbose(bool use_stderr) { - curl_easy_setopt(http_session_.get(), CURLOPT_VERBOSE, 1L); - if (!use_stderr) { - curl_easy_setopt(http_session_.get(), CURLOPT_DEBUGDATA, &logger_); - curl_easy_setopt(http_session_.get(), CURLOPT_DEBUGFUNCTION, &debug_callback); - } -} - -namespace { -bool isSecure(const std::string& url) { - return url.starts_with("https"); -} -} // namespace - -void HTTPClient::initialize(http::HttpRequestMethod method, std::string url, std::shared_ptr ssl_context_service) { - set_request_method(method); - if (ssl_context_service) { - ssl_context_service_ = std::move(ssl_context_service); - } - if (!url.empty()) { - url_ = std::move(url); - } - if (isSecure(url_)) - configure_secure_connection(); -} -void HTTPClient::setBasicAuth(const std::string& username, const std::string& password) { - curl_easy_setopt(http_session_.get(), CURLOPT_USERNAME, username.c_str()); - curl_easy_setopt(http_session_.get(), CURLOPT_PASSWORD, password.c_str()); -} - -void HTTPClient::clearBasicAuth() { - curl_easy_setopt(http_session_.get(), CURLOPT_USERNAME, nullptr); - curl_easy_setopt(http_session_.get(), CURLOPT_PASSWORD, nullptr); -} - -bool HTTPClient::setSpecificSSLVersion(SSLVersion specific_version) { - if (ssl_context_service_) { - switch (specific_version) { - case SSLVersion::TLSv1_0: { - ssl_context_service_->setMinTlsVersion(TLS1_VERSION); - ssl_context_service_->setMaxTlsVersion(TLS1_VERSION); - break; - } - case SSLVersion::TLSv1_1: { - ssl_context_service_->setMinTlsVersion(TLS1_1_VERSION); - ssl_context_service_->setMaxTlsVersion(TLS1_1_VERSION); - break; - } - case SSLVersion::TLSv1_2: { - ssl_context_service_->setMinTlsVersion(TLS1_2_VERSION); - ssl_context_service_->setMaxTlsVersion(TLS1_2_VERSION); - break; - } - case SSLVersion::TLSv1_3: { - ssl_context_service_->setMinTlsVersion(TLS1_3_VERSION); - ssl_context_service_->setMaxTlsVersion(TLS1_3_VERSION); - break; - } - default: break; - } - } - - // bitwise or of different enum types is deprecated in C++20, but the curl api explicitly supports ORing one of CURL_SSLVERSION and one of CURL_SSLVERSION_MAX - switch (specific_version) { - case SSLVersion::TLSv1_0: - return CURLE_OK == curl_easy_setopt(http_session_.get(), CURLOPT_SSLVERSION, static_cast(CURL_SSLVERSION_TLSv1_0) | static_cast(CURL_SSLVERSION_MAX_TLSv1_0)); - case SSLVersion::TLSv1_1: - return CURLE_OK == curl_easy_setopt(http_session_.get(), CURLOPT_SSLVERSION, static_cast(CURL_SSLVERSION_TLSv1_1) | static_cast(CURL_SSLVERSION_MAX_TLSv1_1)); - case SSLVersion::TLSv1_2: - return CURLE_OK == curl_easy_setopt(http_session_.get(), CURLOPT_SSLVERSION, static_cast(CURL_SSLVERSION_TLSv1_2) | static_cast(CURL_SSLVERSION_MAX_TLSv1_2)); - case SSLVersion::TLSv1_3: - return CURLE_OK == curl_easy_setopt(http_session_.get(), CURLOPT_SSLVERSION, static_cast(CURL_SSLVERSION_TLSv1_3) | static_cast(CURL_SSLVERSION_MAX_TLSv1_3)); - default: return false; - } -} - -// If not set, the default will be TLS 1.0, see https://curl.haxx.se/libcurl/c/CURLOPT_SSLVERSION.html -bool HTTPClient::setMinimumSSLVersion(SSLVersion minimum_version) { - if (ssl_context_service_) { - switch (minimum_version) { - case SSLVersion::TLSv1_0: { - ssl_context_service_->setMinTlsVersion(TLS1_VERSION); - break; - } - case SSLVersion::TLSv1_1: { - ssl_context_service_->setMinTlsVersion(TLS1_1_VERSION); - break; - } - case SSLVersion::TLSv1_2: { - ssl_context_service_->setMinTlsVersion(TLS1_2_VERSION); - break; - } - case SSLVersion::TLSv1_3: { - ssl_context_service_->setMinTlsVersion(TLS1_3_VERSION); - break; - } - default: break; - } - } - - CURLcode ret = CURLE_UNKNOWN_OPTION; - switch (minimum_version) { - case SSLVersion::TLSv1_0: - ret = curl_easy_setopt(http_session_.get(), CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1_0); - break; - case SSLVersion::TLSv1_1: - ret = curl_easy_setopt(http_session_.get(), CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1_1); - break; - case SSLVersion::TLSv1_2: - ret = curl_easy_setopt(http_session_.get(), CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1_2); - break; - case SSLVersion::TLSv1_3: - ret = curl_easy_setopt(http_session_.get(), CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1_3); - break; - } - - return ret == CURLE_OK; -} - -void HTTPClient::setKeepAliveProbe(std::optional probe_data) { - if (probe_data) { - curl_easy_setopt(http_session_.get(), CURLOPT_TCP_KEEPALIVE, true); - curl_easy_setopt(http_session_.get(), CURLOPT_TCP_KEEPINTVL, probe_data->keep_alive_interval.count()); - curl_easy_setopt(http_session_.get(), CURLOPT_TCP_KEEPIDLE, probe_data->keep_alive_delay.count()); - } else { - curl_easy_setopt(http_session_.get(), CURLOPT_TCP_KEEPALIVE, false); - } -} - -void HTTPClient::setConnectionTimeout(std::chrono::milliseconds timeout) { - if (timeout < 0ms) { - logger_->log_error("Invalid HTTP connection timeout {}", timeout); - return; - } - connect_timeout_ = timeout; -} - -void HTTPClient::setReadTimeout(std::chrono::milliseconds timeout) { - if (timeout < 0ms) { - logger_->log_error("Invalid HTTP read timeout {}", timeout); - return; - } - read_timeout_ = timeout; -} - -void HTTPClient::setReadCallback(std::unique_ptr callback) { - read_callback_ = std::move(callback); - curl_easy_setopt(http_session_.get(), CURLOPT_WRITEFUNCTION, &HTTPRequestResponse::receiveWrite); - curl_easy_setopt(http_session_.get(), CURLOPT_WRITEDATA, static_cast(read_callback_.get())); -} - -void HTTPClient::setUploadCallback(std::unique_ptr callback) { - logger_->log_debug("Setting callback for {}", url_); - write_callback_ = std::move(callback); - if (method_ == http::HttpRequestMethod::PUT) { - curl_easy_setopt(http_session_.get(), CURLOPT_INFILESIZE_LARGE, (curl_off_t) write_callback_->size()); - } - curl_easy_setopt(http_session_.get(), CURLOPT_READFUNCTION, &HTTPRequestResponse::send_write); - curl_easy_setopt(http_session_.get(), CURLOPT_READDATA, static_cast(write_callback_.get())); - curl_easy_setopt(http_session_.get(), CURLOPT_SEEKDATA, static_cast(write_callback_.get())); - curl_easy_setopt(http_session_.get(), CURLOPT_SEEKFUNCTION, &HTTPRequestResponse::seek_callback); -} - -void HTTPClient::setContentType(std::string content_type) { - request_headers_["Content-Type"] = std::move(content_type); -} - -std::string HTTPClient::escape(std::string string_to_escape) { - struct curl_deleter { void operator()(void* p) noexcept { curl_free(p); } }; - std::unique_ptr escaped_chars{curl_easy_escape(http_session_.get(), string_to_escape.c_str(), gsl::narrow(string_to_escape.length()))}; - std::string escaped_string(escaped_chars.get()); - return escaped_string; -} - -void HTTPClient::setPostFields(const std::string& input) { - setPostSize(input.length()); - curl_easy_setopt(http_session_.get(), CURLOPT_COPYPOSTFIELDS, input.c_str()); -} - -void HTTPClient::setPostSize(size_t size) { - if (size > 2_GB) { - curl_easy_setopt(http_session_.get(), CURLOPT_POSTFIELDSIZE_LARGE, size); - } else { - curl_easy_setopt(http_session_.get(), CURLOPT_POSTFIELDSIZE, size); - } -} - -void HTTPClient::setHTTPProxy(const HTTPProxy &proxy) { - if (!proxy.host.empty()) { - curl_easy_setopt(http_session_.get(), CURLOPT_PROXY, proxy.host.c_str()); - curl_easy_setopt(http_session_.get(), CURLOPT_PROXYPORT, proxy.port); - if (!proxy.username.empty()) { - curl_easy_setopt(http_session_.get(), CURLOPT_PROXYAUTH, CURLAUTH_ANY); - std::string value = proxy.username + ":" + proxy.password; - curl_easy_setopt(http_session_.get(), CURLOPT_PROXYUSERPWD, value.c_str()); - } - } -} - -void HTTPClient::setRequestHeader(std::string key, std::optional value) { - if (value) - request_headers_[std::move(key)] = std::move(*value); - else - request_headers_.erase(key); -} - -namespace { -using CurlSlistDeleter = decltype([](struct curl_slist* slist) { curl_slist_free_all(slist); }); - -std::unique_ptr toCurlSlist(const std::unordered_map& request_headers) { - gsl::owner new_list = nullptr; - const auto guard = gsl::finally([&new_list]() { curl_slist_free_all(new_list); }); - for (const auto& [header_key, header_value] : request_headers) - new_list = (utils::optional_from_ptr(curl_slist_append(new_list, utils::string::join_pack(header_key, ": ", header_value).c_str())) // NOLINT(cppcoreguidelines-owning-memory) - | utils::orElse([]() { throw std::runtime_error{"curl_slist_append failed"}; })).value(); - - return {std::exchange(new_list, nullptr), {}}; -} -} // namespace - - -bool HTTPClient::submit() { - if (url_.empty()) { - logger_->log_error("Tried to submit to an empty url"); - return false; - } - if (!method_) { - logger_->log_error("Tried to use HTTPClient without setting an HTTP method"); - return false; - } - - response_data_.clear(); - - curl_easy_setopt(http_session_.get(), CURLOPT_NOSIGNAL, 1); - curl_easy_setopt(http_session_.get(), CURLOPT_CONNECTTIMEOUT_MS, connect_timeout_.count()); - curl_easy_setopt(http_session_.get(), CURLOPT_TIMEOUT_MS, getAbsoluteTimeout().count()); - - if (read_timeout_ > 0ms) { - progress_.reset(); - curl_easy_setopt(http_session_.get(), CURLOPT_NOPROGRESS, 0); - curl_easy_setopt(http_session_.get(), CURLOPT_XFERINFOFUNCTION, onProgress); - curl_easy_setopt(http_session_.get(), CURLOPT_XFERINFODATA, this); - } else { - // the user explicitly set it to 0 - curl_easy_setopt(http_session_.get(), CURLOPT_NOPROGRESS, 1); - } - - const auto headers = toCurlSlist(request_headers_); - if (headers) { - curl_slist_append(headers.get(), "Expect:"); - curl_easy_setopt(http_session_.get(), CURLOPT_HTTPHEADER, headers.get()); - } - - curl_easy_setopt(http_session_.get(), CURLOPT_URL, url_.c_str()); - logger_->log_debug("Submitting to {}", url_); - if (read_callback_ == nullptr) { - curl_easy_setopt(http_session_.get(), CURLOPT_WRITEFUNCTION, &HTTPRequestResponse::receiveWrite); - curl_easy_setopt(http_session_.get(), CURLOPT_WRITEDATA, static_cast(&content_)); - } - - curl_easy_setopt(http_session_.get(), CURLOPT_HEADERFUNCTION, &HTTPHeaderResponse::receive_headers); - curl_easy_setopt(http_session_.get(), CURLOPT_HEADERDATA, static_cast(&response_data_.header_response)); - - if (form_ != nullptr) { - curl_easy_setopt(http_session_.get(), CURLOPT_MIMEPOST, form_.get()); - } - res_ = curl_easy_perform(http_session_.get()); - if (read_callback_ == nullptr) { - content_.close(); - } - long http_code = 0; // NOLINT(runtime/int,google-runtime-int) long due to libcurl API - curl_easy_getinfo(http_session_.get(), CURLINFO_RESPONSE_CODE, &http_code); - response_data_.response_code = http_code; - curl_easy_getinfo(http_session_.get(), CURLINFO_CONTENT_TYPE, &response_data_.response_content_type); - if (res_ == CURLE_OPERATION_TIMEDOUT) { - logger_->log_error("HTTP operation timed out, with absolute timeout {}\n", getAbsoluteTimeout()); - } - if (res_ != CURLE_OK) { - logger_->log_info("{}", request_headers_.size()); - logger_->log_error("curl_easy_perform() failed {} on {}, error code {}\n", curl_easy_strerror(res_), url_, magic_enum::enum_underlying(res_)); - return false; - } - - logger_->log_debug("Finished with {}", url_); - return true; -} - -int64_t HTTPClient::getResponseCode() const { - return response_data_.response_code; -} - -const char *HTTPClient::getContentType() { - return response_data_.response_content_type; -} - -const std::vector &HTTPClient::getResponseBody() { - if (response_data_.response_body.empty()) { - if (read_callback_) { - response_data_.response_body = read_callback_->to_string(); - } else { - response_data_.response_body = content_.to_string(); - } - } - return response_data_.response_body; -} - -void HTTPClient::set_request_method(http::HttpRequestMethod method) { - if (method_ == method) - return; - method_ = method; - switch (*method_) { - case http::HttpRequestMethod::POST: - curl_easy_setopt(http_session_.get(), CURLOPT_POST, 1L); - curl_easy_setopt(http_session_.get(), CURLOPT_CUSTOMREQUEST, nullptr); - break; - case http::HttpRequestMethod::HEAD: - curl_easy_setopt(http_session_.get(), CURLOPT_NOBODY, 1L); - curl_easy_setopt(http_session_.get(), CURLOPT_CUSTOMREQUEST, nullptr); - break; - case http::HttpRequestMethod::GET: - curl_easy_setopt(http_session_.get(), CURLOPT_HTTPGET, 1L); - curl_easy_setopt(http_session_.get(), CURLOPT_CUSTOMREQUEST, nullptr); - break; - case http::HttpRequestMethod::PUT: - curl_easy_setopt(http_session_.get(), CURLOPT_UPLOAD, 1L); - curl_easy_setopt(http_session_.get(), CURLOPT_CUSTOMREQUEST, nullptr); - break; - default: - curl_easy_setopt(http_session_.get(), CURLOPT_POST, 0L); - curl_easy_setopt(http_session_.get(), CURLOPT_NOBODY, 0L); - curl_easy_setopt(http_session_.get(), CURLOPT_HTTPGET, 0L); - curl_easy_setopt(http_session_.get(), CURLOPT_UPLOAD, 0L); - curl_easy_setopt(http_session_.get(), CURLOPT_CUSTOMREQUEST, std::string(magic_enum::enum_name(*method_)).c_str()); - break; - } -} - -int HTTPClient::onProgress(void *clientp, curl_off_t /*dltotal*/, curl_off_t dlnow, curl_off_t /*ultotal*/, curl_off_t ulnow) { - gsl_Expects(clientp); - HTTPClient& client = *static_cast(clientp); - auto now = std::chrono::steady_clock::now(); - auto elapsed = now - client.progress_.last_transferred_; - if (dlnow != client.progress_.downloaded_data_ || ulnow != client.progress_.uploaded_data_) { - // did transfer data - client.progress_.last_transferred_ = now; - client.progress_.downloaded_data_ = dlnow; - client.progress_.uploaded_data_ = ulnow; - return 0; - } - // did not transfer data - if (elapsed > client.read_timeout_) { - // timeout - client.logger_->log_error("HTTP operation has been idle for {}, limit ({}) reached, terminating connection\n", elapsed, client.read_timeout_); - return 1; - } - return 0; -} - -void HTTPClient::configure_secure_connection() { - if (ssl_context_service_) { - curl_easy_setopt(http_session_.get(), CURLOPT_SSL_CTX_FUNCTION, &configure_ssl_context); - curl_easy_setopt(http_session_.get(), CURLOPT_SSL_CTX_DATA, static_cast(ssl_context_service_.get())); - curl_easy_setopt(http_session_.get(), CURLOPT_CAINFO, nullptr); - curl_easy_setopt(http_session_.get(), CURLOPT_CAPATH, nullptr); - } else { - static const auto default_ca_file = utils::getDefaultCAFile(); - - if (default_ca_file) - logger_->log_debug("Using CA certificate file \"{}\"", *default_ca_file); - else - logger_->log_error("Could not find valid CA certificate file"); - - curl_easy_setopt(http_session_.get(), CURLOPT_SSL_CTX_FUNCTION, nullptr); - curl_easy_setopt(http_session_.get(), CURLOPT_SSL_CTX_DATA, nullptr); - if (default_ca_file) - curl_easy_setopt(http_session_.get(), CURLOPT_CAINFO, std::string(*default_ca_file).c_str()); - else - curl_easy_setopt(http_session_.get(), CURLOPT_CAINFO, nullptr); - curl_easy_setopt(http_session_.get(), CURLOPT_CAPATH, nullptr); - } -} - -void HTTPClient::setInterface(const std::string &ifc) { - curl_easy_setopt(http_session_.get(), CURLOPT_INTERFACE, ifc.c_str()); -} - -void HTTPClient::setFollowRedirects(bool follow) { - curl_easy_setopt(http_session_.get(), CURLOPT_FOLLOWLOCATION, follow); -} - -void HTTPClient::setMaximumUploadSpeed(uint64_t max_bytes_per_second) { - curl_easy_setopt(http_session_.get(), CURLOPT_MAX_SEND_SPEED_LARGE, max_bytes_per_second); -} - -void HTTPClient::setMaximumDownloadSpeed(uint64_t max_bytes_per_second) { - curl_easy_setopt(http_session_.get(), CURLOPT_MAX_RECV_SPEED_LARGE, max_bytes_per_second); -} - -bool HTTPClient::isValidHttpHeaderField(std::string_view field_name) { - if (field_name.empty()) { - return false; - } - - // RFC822 3.1.2: The field-name must be composed of printable ASCII characters - // (i.e., characters that have values between 33. and 126., decimal, except colon). - return ranges::all_of(field_name, [](char c) { return c >= 33 && c <= 126 && c != ':'; }); -} - -std::string HTTPClient::replaceInvalidCharactersInHttpHeaderFieldName(std::string field_name) { - if (field_name.empty()) { - return "X-MiNiFi-Empty-Attribute-Name"; - } - - // RFC822 3.1.2: The field-name must be composed of printable ASCII characters - // (i.e., characters that have values between 33. and 126., decimal, except colon). - ranges::actions::transform(field_name, [](char ch) { // NOLINT: false positive: Add #include for transform [build/include_what_you_use] [4] - return (ch >= 33 && ch <= 126 && ch != ':') ? ch : '-'; - }); - return field_name; -} - -void HTTPClient::CurlEasyCleanup::operator()(CURL* curl) const { - curl_easy_cleanup(curl); -} - -void HTTPClient::CurlMimeFree::operator()(curl_mime* curl_mime) const { - curl_mime_free(curl_mime); -} - REGISTER_RESOURCE(HTTPClient, InternalResource); } // namespace org::apache::nifi::minifi::http diff --git a/libminifi/src/properties/Properties.cpp b/libminifi/src/properties/Properties.cpp index 45ebda39ae..61550510b0 100644 --- a/libminifi/src/properties/Properties.cpp +++ b/libminifi/src/properties/Properties.cpp @@ -29,13 +29,13 @@ namespace org::apache::nifi::minifi { -Properties::Properties(std::string name) +PropertiesImpl::PropertiesImpl(std::string name) : logger_(core::logging::LoggerFactory::getLogger()), name_(std::move(name)) { } // Get the config value -bool Properties::getString(const std::string &key, std::string &value) const { +bool PropertiesImpl::getString(const std::string &key, std::string &value) const { std::lock_guard lock(mutex_); auto it = properties_.find(key); @@ -47,14 +47,14 @@ bool Properties::getString(const std::string &key, std::string &value) const { } } -std::optional Properties::getString(const std::string& key) const { +std::optional PropertiesImpl::getString(const std::string& key) const { if (std::string result; getString(key, result)) { return result; } return std::nullopt; } -int Properties::getInt(const std::string &key, int default_value) const { +int PropertiesImpl::getInt(const std::string &key, int default_value) const { std::lock_guard lock(mutex_); auto it = properties_.find(key); @@ -189,7 +189,7 @@ void fixValidatedProperty(const std::string& property_name, // Load Configure File // If the loaded property is time-period or data-size validated and it has no explicit units ms or B will be appended. // If the loaded property is integer validated and it has some explicit unit(time-period or data-size) it will be converted to ms/B and its unit cut off -void Properties::loadConfigureFile(const std::filesystem::path& configuration_file, std::string_view prefix) { +void PropertiesImpl::loadConfigureFile(const std::filesystem::path& configuration_file, std::string_view prefix) { std::lock_guard lock(mutex_); if (configuration_file.empty()) { logger_->log_error("Configuration file path for {} is empty!", getName()); @@ -232,12 +232,12 @@ void Properties::loadConfigureFile(const std::filesystem::path& configuration_fi checksum_calculator_.setFileLocation(properties_file_); } -std::filesystem::path Properties::getFilePath() const { +std::filesystem::path PropertiesImpl::getFilePath() const { std::lock_guard lock(mutex_); return properties_file_; } -bool Properties::commitChanges() { +bool PropertiesImpl::commitChanges() { std::lock_guard lock(mutex_); if (!dirty_) { logger_->log_info("Attempt to persist, but properties are not updated"); @@ -284,7 +284,7 @@ bool Properties::commitChanges() { return false; } -std::map Properties::getProperties() const { +std::map PropertiesImpl::getProperties() const { std::lock_guard lock(mutex_); std::map properties; for (const auto& prop : properties_) { @@ -293,4 +293,8 @@ std::map Properties::getProperties() const { return properties; } +std::shared_ptr Properties::create() { + return std::make_shared(); +} + } // namespace org::apache::nifi::minifi diff --git a/libminifi/src/provenance/Provenance.cpp b/libminifi/src/provenance/Provenance.cpp index d81d91cac7..e3eaf169dd 100644 --- a/libminifi/src/provenance/Provenance.cpp +++ b/libminifi/src/provenance/Provenance.cpp @@ -34,21 +34,21 @@ namespace org::apache::nifi::minifi::provenance { -std::shared_ptr ProvenanceEventRecord::id_generator_ = utils::IdGenerator::getIdGenerator(); -std::shared_ptr ProvenanceEventRecord::logger_ = core::logging::LoggerFactory::getLogger(); +std::shared_ptr ProvenanceEventRecordImpl::id_generator_ = utils::IdGenerator::getIdGenerator(); +std::shared_ptr ProvenanceEventRecordImpl::logger_ = core::logging::LoggerFactory::getLogger(); const char *ProvenanceEventRecord::ProvenanceEventTypeStr[REPLAY + 1] = { "CREATE", "RECEIVE", "FETCH", "SEND", "DOWNLOAD", // NOLINT(cppcoreguidelines-avoid-c-arrays) "DROP", "EXPIRE", "FORK", "JOIN", "CLONE", "CONTENT_MODIFIED", "ATTRIBUTES_MODIFIED", "ROUTE", "ADDINFO", "REPLAY" }; -ProvenanceEventRecord::ProvenanceEventRecord(ProvenanceEventRecord::ProvenanceEventType event, std::string componentId, std::string componentType) - : core::SerializableComponent(core::className()), +ProvenanceEventRecordImpl::ProvenanceEventRecordImpl(ProvenanceEventRecord::ProvenanceEventType event, std::string componentId, std::string componentType) + : core::SerializableComponentImpl(core::className()), _eventType(event), _eventTime(std::chrono::system_clock::now()), _componentId(std::move(componentId)), _componentType(std::move(componentType)) { } -bool ProvenanceEventRecord::loadFromRepository(const std::shared_ptr &repo) { +bool ProvenanceEventRecordImpl::loadFromRepository(const std::shared_ptr &repo) { std::string value; bool ret = false; @@ -78,7 +78,7 @@ bool ProvenanceEventRecord::loadFromRepository(const std::shared_ptruuid_); if (ret == 0 || io::isError(ret)) { @@ -241,7 +241,7 @@ bool ProvenanceEventRecord::serialize(io::OutputStream& output_stream) { return true; } -bool ProvenanceEventRecord::deserialize(io::InputStream &input_stream) { +bool ProvenanceEventRecordImpl::deserialize(io::InputStream &input_stream) { { const auto ret = input_stream.read(uuid_); if (ret == 0 || io::isError(ret)) { @@ -444,7 +444,7 @@ bool ProvenanceEventRecord::deserialize(io::InputStream &input_stream) { return true; } -void ProvenanceReporter::commit() { +void ProvenanceReporterImpl::commit() { if (repo_->isNoop()) { return; } @@ -465,7 +465,7 @@ void ProvenanceReporter::commit() { repo_->MultiPut(flowData); } -void ProvenanceReporter::create(const core::FlowFile& flow_file, const std::string& detail) { +void ProvenanceReporterImpl::create(const core::FlowFile& flow_file, const std::string& detail) { auto event = allocate(ProvenanceEventRecord::CREATE, flow_file); if (event) { @@ -474,7 +474,7 @@ void ProvenanceReporter::create(const core::FlowFile& flow_file, const std::stri } } -void ProvenanceReporter::route(const core::FlowFile& flow_file, const core::Relationship& relation, const std::string& detail, std::chrono::milliseconds processingDuration) { +void ProvenanceReporterImpl::route(const core::FlowFile& flow_file, const core::Relationship& relation, const std::string& detail, std::chrono::milliseconds processingDuration) { auto event = allocate(ProvenanceEventRecord::ROUTE, flow_file); if (event) { @@ -485,7 +485,7 @@ void ProvenanceReporter::route(const core::FlowFile& flow_file, const core::Rela } } -void ProvenanceReporter::modifyAttributes(const core::FlowFile& flow_file, const std::string& detail) { +void ProvenanceReporterImpl::modifyAttributes(const core::FlowFile& flow_file, const std::string& detail) { auto event = allocate(ProvenanceEventRecord::ATTRIBUTES_MODIFIED, flow_file); if (event) { @@ -494,7 +494,7 @@ void ProvenanceReporter::modifyAttributes(const core::FlowFile& flow_file, const } } -void ProvenanceReporter::modifyContent(const core::FlowFile& flow_file, const std::string& detail, std::chrono::milliseconds processingDuration) { +void ProvenanceReporterImpl::modifyContent(const core::FlowFile& flow_file, const std::string& detail, std::chrono::milliseconds processingDuration) { auto event = allocate(ProvenanceEventRecord::CONTENT_MODIFIED, flow_file); if (event) { @@ -504,7 +504,7 @@ void ProvenanceReporter::modifyContent(const core::FlowFile& flow_file, const st } } -void ProvenanceReporter::clone(const core::FlowFile& parent, const core::FlowFile& child) { +void ProvenanceReporterImpl::clone(const core::FlowFile& parent, const core::FlowFile& child) { auto event = allocate(ProvenanceEventRecord::CLONE, parent); if (event) { @@ -514,7 +514,7 @@ void ProvenanceReporter::clone(const core::FlowFile& parent, const core::FlowFil } } -void ProvenanceReporter::expire(const core::FlowFile& flow_file, const std::string& detail) { +void ProvenanceReporterImpl::expire(const core::FlowFile& flow_file, const std::string& detail) { auto event = allocate(ProvenanceEventRecord::EXPIRE, flow_file); if (event) { @@ -523,7 +523,7 @@ void ProvenanceReporter::expire(const core::FlowFile& flow_file, const std::stri } } -void ProvenanceReporter::drop(const core::FlowFile& flow_file, const std::string& reason) { +void ProvenanceReporterImpl::drop(const core::FlowFile& flow_file, const std::string& reason) { auto event = allocate(ProvenanceEventRecord::DROP, flow_file); if (event) { @@ -533,7 +533,7 @@ void ProvenanceReporter::drop(const core::FlowFile& flow_file, const std::string } } -void ProvenanceReporter::send(const core::FlowFile& flow_file, const std::string& transitUri, const std::string& detail, std::chrono::milliseconds processingDuration, bool force) { +void ProvenanceReporterImpl::send(const core::FlowFile& flow_file, const std::string& transitUri, const std::string& detail, std::chrono::milliseconds processingDuration, bool force) { auto event = allocate(ProvenanceEventRecord::SEND, flow_file); if (event) { @@ -549,7 +549,7 @@ void ProvenanceReporter::send(const core::FlowFile& flow_file, const std::string } } -void ProvenanceReporter::receive(const core::FlowFile& flow_file, +void ProvenanceReporterImpl::receive(const core::FlowFile& flow_file, const std::string& transitUri, const std::string& sourceSystemFlowFileIdentifier, const std::string& detail, @@ -565,7 +565,7 @@ void ProvenanceReporter::receive(const core::FlowFile& flow_file, } } -void ProvenanceReporter::fetch(const core::FlowFile& flow_file, const std::string& transitUri, const std::string& detail, std::chrono::milliseconds processingDuration) { +void ProvenanceReporterImpl::fetch(const core::FlowFile& flow_file, const std::string& transitUri, const std::string& detail, std::chrono::milliseconds processingDuration) { auto event = allocate(ProvenanceEventRecord::FETCH, flow_file); if (event) { @@ -576,4 +576,8 @@ void ProvenanceReporter::fetch(const core::FlowFile& flow_file, const std::strin } } +std::shared_ptr ProvenanceEventRecord::create() { + return std::make_shared(); +} + } // namespace org::apache::nifi::minifi::provenance diff --git a/libminifi/src/sitetosite/HTTPProtocol.cpp b/libminifi/src/sitetosite/HTTPProtocol.cpp index 600ff8a825..095d400d86 100644 --- a/libminifi/src/sitetosite/HTTPProtocol.cpp +++ b/libminifi/src/sitetosite/HTTPProtocol.cpp @@ -30,6 +30,8 @@ #include "io/validation.h" #include "core/Resource.h" +#undef DELETE // macro on windows + namespace org::apache::nifi::minifi::sitetosite { std::shared_ptr HttpSiteToSiteClient::id_generator_ = utils::IdGenerator::getIdGenerator(); diff --git a/libminifi/src/utils/FlowFileQueue.cpp b/libminifi/src/utils/FlowFileQueue.cpp index 11c15bd4ec..837108dff1 100644 --- a/libminifi/src/utils/FlowFileQueue.cpp +++ b/libminifi/src/utils/FlowFileQueue.cpp @@ -16,7 +16,7 @@ */ #include "utils/FlowFileQueue.h" -#include "core/logging/LoggerConfiguration.h" +#include "core/logging/LoggerFactory.h" namespace org::apache::nifi::minifi::utils { diff --git a/libminifi/src/utils/TimeUtil.cpp b/libminifi/src/utils/TimeUtil.cpp index b773293d1b..66fd07d8f6 100644 --- a/libminifi/src/utils/TimeUtil.cpp +++ b/libminifi/src/utils/TimeUtil.cpp @@ -17,17 +17,12 @@ #include "utils/TimeUtil.h" -#include "fmt/format.h" -#include "fmt/chrono.h" -#include "range/v3/algorithm/contains.hpp" - #ifdef WIN32 #include "date/tz.h" #endif namespace org::apache::nifi::minifi::utils::timeutils { -using namespace std::literals::chrono_literals; static std::mutex global_clock_mtx; static std::shared_ptr global_clock{std::make_shared()}; @@ -42,98 +37,12 @@ void setClock(std::shared_ptr clock) { global_clock = std::move(clock); } -namespace { -template -std::tuple breakDownDurations(std::chrono::system_clock::duration input_duration) { - std::tuple result; - - ([&](T& duration) { - duration = std::chrono::duration_cast>(input_duration); - input_duration -= duration; - } (std::get(result)), ...); - - return result; -} - -std::string formatAsDaysHoursMinutesSeconds(std::chrono::system_clock::duration input_duration) { - const auto durs = breakDownDurations(input_duration); - const auto& days = std::get(durs); - std::string day_string; - if (days.count() > 0) { - day_string = fmt::format("{} {}", days.count(), days.count() == 1 ? "day, " : "days, "); - } - return fmt::format("{}{:02}:{:02}:{:02}", - day_string, std::get(durs).count(), - std::get(durs).count(), - std::get(durs).count()); -} - -template -std::string formatAsRoundedLargestUnit(std::chrono::system_clock::duration input_duration) { - std::optional rounded_value_str; - using std::chrono::duration_cast; - using std::chrono::duration; - - ((rounded_value_str = input_duration >= Durations(1) - ? std::optional{fmt::format("{:.2}", duration_cast>(input_duration))} - : std::nullopt) || ...); - - - if (!rounded_value_str) { - return fmt::format("{}", input_duration); - } - - return *rounded_value_str; -} - -} // namespace - -std::string humanReadableDuration(std::chrono::system_clock::duration input_duration) { - if (input_duration > 5s) { - return formatAsDaysHoursMinutesSeconds(input_duration); - } - - return formatAsRoundedLargestUnit(input_duration); -} - -std::optional parseRfc3339(const std::string& str) { - std::istringstream stream(str); - date::year_month_day date_part{}; - date::from_stream(stream, "%F", date_part); - - if (stream.fail()) - return std::nullopt; - - constexpr std::string_view accepted_delimiters = "tT_ "; - char delimiter_char = 0; - stream.get(delimiter_char); - - if (stream.fail() || !ranges::contains(accepted_delimiters, delimiter_char)) - return std::nullopt; - - std::chrono::system_clock::duration time_part; - std::chrono::minutes offset = 0min; - if (str.ends_with('Z') || str.ends_with('z')) { - date::from_stream(stream, "%T", time_part); - if (stream.fail()) - return std::nullopt; - stream.get(); - } else { - date::from_stream(stream, "%T%Ez", time_part, {}, &offset); - } - - if (stream.fail() || (stream.peek() && !stream.eof())) - return std::nullopt; - - return date::sys_days(date_part) + time_part - offset; -} - #ifdef WIN32 -// If minifi is not installed through the MSI installer, then TZDATA might be missing -// date::set_install can point to the TZDATA location, but it has to be called from each library/executable that wants to use timezones -void dateSetInstall(const std::string& install) { +void dateSetGlobalInstall(const std::string& install) { date::set_install(install); } #endif + } // namespace org::apache::nifi::minifi::utils::timeutils + diff --git a/libminifi/src/utils/tls/ExtendedKeyUsage.cpp b/libminifi/src/utils/tls/ExtendedKeyUsage.cpp index e33fe5b79e..fe8df093fe 100644 --- a/libminifi/src/utils/tls/ExtendedKeyUsage.cpp +++ b/libminifi/src/utils/tls/ExtendedKeyUsage.cpp @@ -21,7 +21,7 @@ #include #include -#include "core/logging/LoggerConfiguration.h" +#include "core/logging/LoggerFactory.h" #include "utils/StringUtils.h" namespace org::apache::nifi::minifi::utils::tls { diff --git a/libminifi/test/flow-tests/CustomProcessors.h b/libminifi/test/flow-tests/CustomProcessors.h index 7546547e55..0c763db18e 100644 --- a/libminifi/test/flow-tests/CustomProcessors.h +++ b/libminifi/test/flow-tests/CustomProcessors.h @@ -57,10 +57,10 @@ class ProcessorWithStatistics { std::function onTriggerCb_; }; -class TestProcessor : public core::Processor, public ProcessorWithStatistics { +class TestProcessor : public core::ProcessorImpl, public ProcessorWithStatistics { public: - TestProcessor(std::string_view name, const utils::Identifier& uuid) : Processor(name, uuid) {} - explicit TestProcessor(const std::string& name) : Processor(name) {} + TestProcessor(std::string_view name, const utils::Identifier& uuid) : ProcessorImpl(name, uuid) {} + explicit TestProcessor(const std::string& name) : ProcessorImpl(name) {} static constexpr const char* Description = "Processor used for testing cycles"; static constexpr auto Properties = std::to_array({AppleProbability, BananaProbability}); diff --git a/libminifi/test/flow-tests/CycleTest.cpp b/libminifi/test/flow-tests/CycleTest.cpp index c6064ef8e8..c11cd1bada 100644 --- a/libminifi/test/flow-tests/CycleTest.cpp +++ b/libminifi/test/flow-tests/CycleTest.cpp @@ -111,9 +111,9 @@ TEST_CASE("Flow with two long cycle", "[FlowWithCycle]") { auto controller = testController.controller_; auto root = testController.root_; - auto procGenerator = static_cast(root->findProcessorByName("Generator")); - auto procA = static_cast(root->findProcessorByName("A")); - auto procB = static_cast(root->findProcessorByName("B")); + auto procGenerator = dynamic_cast(root->findProcessorByName("Generator")); + auto procA = dynamic_cast(root->findProcessorByName("A")); + auto procB = dynamic_cast(root->findProcessorByName("B")); int tryCount = 0; while (tryCount++ < 10 && (procA->trigger_count.load() < 10 || procB->trigger_count.load() < 10)) { diff --git a/libminifi/test/flow-tests/FlowControllerTests.cpp b/libminifi/test/flow-tests/FlowControllerTests.cpp index 40c917a528..5771e41f70 100644 --- a/libminifi/test/flow-tests/FlowControllerTests.cpp +++ b/libminifi/test/flow-tests/FlowControllerTests.cpp @@ -109,7 +109,8 @@ TEST_CASE("Flow shutdown drains connections", "[TestFlow1]") { testController.configuration_->set(minifi::Configure::nifi_flowcontroller_drain_timeout, "100 ms"); - auto sinkProc = static_cast(root->findProcessorByName("TestProcessor")); + auto sinkProc = dynamic_cast(root->findProcessorByName("TestProcessor")); + gsl_Assert(sinkProc); // prevent execution of the consumer processor sinkProc->yield(10s); @@ -144,8 +145,8 @@ TEST_CASE("Flow shutdown waits for a while", "[TestFlow2]") { testController.configuration_->set(minifi::Configure::nifi_flowcontroller_drain_timeout, "10 s"); - auto sourceProc = static_cast(root->findProcessorByName("Generator")); - auto sinkProc = static_cast(root->findProcessorByName("TestProcessor")); + auto sourceProc = dynamic_cast(root->findProcessorByName("Generator")); + auto sinkProc = dynamic_cast(root->findProcessorByName("TestProcessor")); std::promise execSinkPromise; std::future execSinkFuture = execSinkPromise.get_future(); @@ -175,8 +176,8 @@ TEST_CASE("Flow stopped after grace period", "[TestFlow3]") { testController.configuration_->set(minifi::Configure::nifi_flowcontroller_drain_timeout, "1000 ms"); - auto sourceProc = static_cast(root->findProcessorByName("Generator")); - auto sinkProc = static_cast(root->findProcessorByName("TestProcessor")); + auto sourceProc = dynamic_cast(root->findProcessorByName("Generator")); + auto sinkProc = dynamic_cast(root->findProcessorByName("TestProcessor")); std::promise execSinkPromise; std::future execSinkFuture = execSinkPromise.get_future(); @@ -214,8 +215,8 @@ TEST_CASE("Extend the waiting period during shutdown", "[TestFlow4]") { testController.configuration_->set(minifi::Configure::nifi_flowcontroller_drain_timeout, fmt::format("{}", timeout_ms)); - auto sourceProc = static_cast(root->findProcessorByName("Generator")); - auto sinkProc = static_cast(root->findProcessorByName("TestProcessor")); + auto sourceProc = dynamic_cast(root->findProcessorByName("Generator")); + auto sinkProc = dynamic_cast(root->findProcessorByName("TestProcessor")); std::promise execSinkPromise; std::future execSinkFuture = execSinkPromise.get_future(); diff --git a/libminifi/test/flow-tests/LoopTest.cpp b/libminifi/test/flow-tests/LoopTest.cpp index b2209d2587..e46aaa2f67 100644 --- a/libminifi/test/flow-tests/LoopTest.cpp +++ b/libminifi/test/flow-tests/LoopTest.cpp @@ -89,8 +89,10 @@ TEST_CASE("Flow with a single loop", "[SingleLoopFlow]") { auto controller = testController.controller_; auto root = testController.root_; - auto procGenerator = static_cast(root->findProcessorByName("Generator")); - auto procA = static_cast(root->findProcessorByName("A")); + auto procGenerator = dynamic_cast(root->findProcessorByName("Generator")); + gsl_Assert(procGenerator); + auto procA = dynamic_cast(root->findProcessorByName("A")); + gsl_Assert(procA); int tryCount = 0; // wait for the procA to get triggered 15 times diff --git a/libminifi/test/flow-tests/MultiLoopTest.cpp b/libminifi/test/flow-tests/MultiLoopTest.cpp index 850ece7044..28aed161ea 100644 --- a/libminifi/test/flow-tests/MultiLoopTest.cpp +++ b/libminifi/test/flow-tests/MultiLoopTest.cpp @@ -98,8 +98,10 @@ TEST_CASE("Flow with two loops", "[MultiLoopFlow]") { auto controller = testController.controller_; auto root = testController.root_; - auto procGenerator = static_cast(root->findProcessorByName("Generator")); - auto procA = static_cast(root->findProcessorByName("A")); + auto procGenerator = dynamic_cast(root->findProcessorByName("Generator")); + gsl_Assert(procGenerator); + auto procA = dynamic_cast(root->findProcessorByName("A")); + gsl_Assert(procA); int tryCount = 0; while (tryCount++ < 10 && procA->trigger_count.load() <= 15) { diff --git a/libminifi/test/flow-tests/SessionTests.cpp b/libminifi/test/flow-tests/SessionTests.cpp index c0609db2bd..a38a3f9887 100644 --- a/libminifi/test/flow-tests/SessionTests.cpp +++ b/libminifi/test/flow-tests/SessionTests.cpp @@ -35,9 +35,9 @@ namespace { -class TestProcessor : public minifi::core::Processor { +class TestProcessor : public minifi::core::ProcessorImpl { public: - using Processor::Processor; + using ProcessorImpl::ProcessorImpl; static constexpr bool SupportsDynamicProperties = false; static constexpr bool SupportsDynamicRelationships = false; @@ -58,7 +58,7 @@ TEST_CASE("Import null data") { auto dir = testController.createTempDirectory(); - auto config = std::make_shared(); + auto config = std::make_shared(); config->set(minifi::Configure::nifi_dbcontent_repository_directory_default, (dir / "content_repository").string()); config->set(minifi::Configure::nifi_flowfile_repository_directory_default, (dir / "flowfile_repository").string()); @@ -82,13 +82,13 @@ TEST_CASE("Import null data") { auto processor = std::make_shared("dummy"); utils::Identifier uuid = processor->getUUID(); - auto output = std::make_unique(ff_repository, content_repo, "output"); + auto output = std::make_unique(ff_repository, content_repo, "output"); output->addRelationship({"out", ""}); output->setSourceUUID(uuid); processor->addConnection(output.get()); - auto node = std::make_shared(processor.get()); - auto context = std::make_shared(node, nullptr, prov_repo, ff_repository, content_repo); - core::ProcessSession session(context); + auto node = std::make_shared(processor.get()); + auto context = std::make_shared(node, nullptr, prov_repo, ff_repository, content_repo); + core::ProcessSessionImpl session(context); minifi::io::BufferStream input{}; auto flowFile = session.create(); diff --git a/libminifi/test/integration/C2AssetSyncTest.cpp b/libminifi/test/integration/C2AssetSyncTest.cpp index 5731025eb0..29658d5bdf 100644 --- a/libminifi/test/integration/C2AssetSyncTest.cpp +++ b/libminifi/test/integration/C2AssetSyncTest.cpp @@ -193,7 +193,7 @@ TEST_CASE("C2AssetSync", "[c2test]") { FileProvider file_C_provider{file_C}; std::string file_A_v2 = "hello from file A version 2"; FileProvider file_Av2_provider{file_A_v2}; - C2HeartbeatHandler hb_handler{std::make_shared()}; + C2HeartbeatHandler hb_handler{std::make_shared()}; VerifyC2AssetSync harness; harness.setUrl("http://localhost:0/api/file/A.txt", &file_A_provider); diff --git a/libminifi/test/integration/C2DescribeManifestTest.cpp b/libminifi/test/integration/C2DescribeManifestTest.cpp index 03ad53f288..f14a30fe3e 100644 --- a/libminifi/test/integration/C2DescribeManifestTest.cpp +++ b/libminifi/test/integration/C2DescribeManifestTest.cpp @@ -55,7 +55,7 @@ TEST_CASE("C2DescribeManifestTest", "[c2test]") { minifi::Decryptor decryptor{minifi::utils::crypto::EncryptionProvider{encryption_key}}; std::string encrypted_value = "l3WY1V27knTiPa6jVX0jrq4qjmKsySOu||ErntqZpHP1M+6OkA14p5sdnqJhuNHWHDVUU5EyMloTtSytKk9a5xNKo="; - harness.setConfiguration(std::make_shared(decryptor)); + harness.setConfiguration(std::make_shared(decryptor)); harness.setKeyDir(TEST_RESOURCES); DescribeManifestHandler responder(harness.getConfiguration(), verified); diff --git a/libminifi/test/integration/C2PauseResumeTest.cpp b/libminifi/test/integration/C2PauseResumeTest.cpp index e79c74dcd4..f02ff339ad 100644 --- a/libminifi/test/integration/C2PauseResumeTest.cpp +++ b/libminifi/test/integration/C2PauseResumeTest.cpp @@ -121,7 +121,7 @@ TEST_CASE("C2PauseResumeTest", "[c2test]") { std::shared_ptr test_repo = std::make_shared(); std::shared_ptr test_flow_repo = std::make_shared(); - std::shared_ptr configuration = std::make_shared(); + std::shared_ptr configuration = std::make_shared(); const auto test_file_path = std::filesystem::path(TEST_RESOURCES) / "C2PauseResumeTest.yml"; configuration->set(minifi::Configure::nifi_flow_configuration_file, test_file_path.string()); diff --git a/libminifi/test/integration/C2PropertiesUpdateTests.cpp b/libminifi/test/integration/C2PropertiesUpdateTests.cpp index 7669f250da..6d0b80b310 100644 --- a/libminifi/test/integration/C2PropertiesUpdateTests.cpp +++ b/libminifi/test/integration/C2PropertiesUpdateTests.cpp @@ -26,7 +26,6 @@ #include "spdlog/sinks/stdout_sinks.h" #include "spdlog/sinks/ostream_sink.h" #include "spdlog/sinks/dist_sink.h" -#include "unit/LogUtils.h" #include "properties/PropertiesFile.h" #include "ConfigTestAccessor.h" #include "unit/Catch.h" diff --git a/libminifi/test/integration/C2RequestClassTest.cpp b/libminifi/test/integration/C2RequestClassTest.cpp index ac55d77645..ebdedd10f7 100644 --- a/libminifi/test/integration/C2RequestClassTest.cpp +++ b/libminifi/test/integration/C2RequestClassTest.cpp @@ -23,7 +23,7 @@ #include "integration/HTTPHandlers.h" #include "unit/TestUtils.h" #include "integration/CivetStream.h" -#include "StreamPipe.h" +#include "io/StreamPipe.h" #include "properties/Configuration.h" #include "unit/Catch.h" diff --git a/libminifi/test/integration/C2UpdateAssetTest.cpp b/libminifi/test/integration/C2UpdateAssetTest.cpp index 907b9f9218..7da531de2e 100644 --- a/libminifi/test/integration/C2UpdateAssetTest.cpp +++ b/libminifi/test/integration/C2UpdateAssetTest.cpp @@ -114,7 +114,7 @@ TEST_CASE("Test update asset C2 command", "[c2test]") { FileProvider file_A_provider{file_A}; std::string file_B = "hello from file B"; FileProvider file_B_provider{file_B}; - C2HeartbeatHandler hb_handler{std::make_shared()}; + C2HeartbeatHandler hb_handler{std::make_shared()}; VerifyC2AssetUpdate harness; harness.setUrl("http://localhost:0/api/file/A.txt", &file_A_provider); diff --git a/libminifi/test/integration/ConfigTestAccessor.h b/libminifi/test/integration/ConfigTestAccessor.h index e1dac61a01..a77d6d1d8c 100644 --- a/libminifi/test/integration/ConfigTestAccessor.h +++ b/libminifi/test/integration/ConfigTestAccessor.h @@ -24,6 +24,6 @@ struct ConfigTestAccessor { static void call_setLoggerProperties(const std::shared_ptr& config, std::shared_ptr props) { - config->setLoggerProperties(props); + std::dynamic_pointer_cast(config)->setLoggerProperties(props); } }; diff --git a/libminifi/test/integration/ControllerServiceIntegrationTests.cpp b/libminifi/test/integration/ControllerServiceIntegrationTests.cpp index 91b2bca490..99ef660622 100644 --- a/libminifi/test/integration/ControllerServiceIntegrationTests.cpp +++ b/libminifi/test/integration/ControllerServiceIntegrationTests.cpp @@ -50,7 +50,7 @@ void waitToVerifyProcessor() { TEST_CASE("ControllerServiceIntegrationTests", "[controller]") { using org::apache::nifi::minifi::test::utils::verifyEventHappenedInPollTime; - std::shared_ptr configuration = std::make_shared(); + std::shared_ptr configuration = std::make_shared(); std::shared_ptr test_repo = std::make_shared(); std::shared_ptr test_flow_repo = std::make_shared(); @@ -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::static_pointer_cast(ssl_client_node->getControllerServiceImplementation()); + ssl_client = std::dynamic_pointer_cast(ssl_client_node->getControllerServiceImplementation()); } REQUIRE(!ssl_client->getCACertificate().empty()); // now let's disable one of the controller services. diff --git a/libminifi/test/integration/OnScheduleErrorHandlingTests.cpp b/libminifi/test/integration/OnScheduleErrorHandlingTests.cpp index dc10474c4e..4d80a46526 100644 --- a/libminifi/test/integration/OnScheduleErrorHandlingTests.cpp +++ b/libminifi/test/integration/OnScheduleErrorHandlingTests.cpp @@ -17,7 +17,7 @@ */ #include "integration/IntegrationBase.h" #include "core/logging/Logger.h" -#include "core/Scheduling.h" +#include "minifi-cpp/core/Scheduling.h" #include "core/state/ProcessorController.h" #include "unit/TestBase.h" #include "../../../extensions/test-processors/KamikazeProcessor.h" diff --git a/libminifi/test/keyvalue-tests/CMakeLists.txt b/libminifi/test/keyvalue-tests/CMakeLists.txt index 13396be9a3..824649a0f8 100644 --- a/libminifi/test/keyvalue-tests/CMakeLists.txt +++ b/libminifi/test/keyvalue-tests/CMakeLists.txt @@ -17,26 +17,19 @@ # under the License. # -file(GLOB KEYVALUE_TESTS "*.cpp") +add_minifi_executable(PersistentMapStateStorageTest "PersistentStateStorageTest.cpp") +createTests(PersistentMapStateStorageTest) +add_test(NAME PersistentMapStateStorageTest COMMAND PersistentMapStateStorageTest --config-yaml "${TEST_RESOURCES}/PersistentMapStateStorage.yml") +target_link_libraries(PersistentMapStateStorageTest minifi-standard-processors Catch2) -SET(KEYVALUE_INT_TEST_COUNT 0) - -FOREACH(testfile ${KEYVALUE_TESTS}) - get_filename_component(testfilename "${testfile}" NAME_WE) - add_minifi_executable("${testfilename}" "${testfile}") - createTests("${testfilename}") - target_link_libraries(${testfilename} minifi-standard-processors Catch2) - if (ENABLE_ROCKSDB) - target_link_libraries(${testfilename} minifi-rocksdb-repos) - endif() - - MATH(EXPR KEYVALUE_INT_TEST_COUNT "${KEYVALUE_INT_TEST_COUNT}+1") -ENDFOREACH() - -message("-- Finished building ${KEYVALUE_INT_TEST_COUNT} keyvalue controller test file(s)...") +add_minifi_executable(VolatileMapStateStorageTest "VolatileMapStateStorageTest.cpp") +createTests(VolatileMapStateStorageTest) +add_test(NAME VolatileMapStateStorageTest COMMAND VolatileMapStateStorageTest --config-yaml "${TEST_RESOURCES}/VolatileMapStateStorage.yml") +target_link_libraries(VolatileMapStateStorageTest minifi-standard-processors Catch2) -add_test(NAME PersistentMapStateStorageTest COMMAND PersistentStateStorageTest --config-yaml "${TEST_RESOURCES}/PersistentMapStateStorage.yml") if (ENABLE_ROCKSDB) - add_test(NAME RocksDbStateStorageTest COMMAND PersistentStateStorageTest --config-yaml "${TEST_RESOURCES}/RocksDbStateStorage.yml") + add_minifi_executable(RocksDbStateStorageTest "PersistentStateStorageTest.cpp") + createTests(RocksDbStateStorageTest) + add_test(NAME RocksDbStateStorageTest COMMAND RocksDbStateStorageTest --config-yaml "${TEST_RESOURCES}/RocksDbStateStorage.yml") + target_link_libraries(RocksDbStateStorageTest minifi-rocksdb-repos Catch2) endif() -add_test(NAME VolatileMapStateStorageTest COMMAND VolatileMapStateStorageTest --config-yaml "${TEST_RESOURCES}/VolatileMapStateStorage.yml") diff --git a/libminifi/test/keyvalue-tests/PersistentStateStorageTest.cpp b/libminifi/test/keyvalue-tests/PersistentStateStorageTest.cpp index ddd425eb1c..a77aab2e5f 100644 --- a/libminifi/test/keyvalue-tests/PersistentStateStorageTest.cpp +++ b/libminifi/test/keyvalue-tests/PersistentStateStorageTest.cpp @@ -28,7 +28,7 @@ #include "core/ProcessGroup.h" #include "core/yaml/YamlConfiguration.h" #include "controllers/keyvalue/KeyValueStateStorage.h" -#include "controllers/keyvalue/AutoPersistor.h" +#include "utils/AutoPersistor.h" #include "unit/ProvenanceTestHelper.h" #include "repository/VolatileContentRepository.h" #include "utils/file/FileUtils.h" @@ -89,7 +89,7 @@ class PersistentStateStorageTestsFixture { test_repo.reset(); configuration.reset(); - configuration = std::make_shared(); + configuration = std::make_shared(); test_repo = std::make_shared(); test_flow_repo = std::make_shared(); diff --git a/libminifi/test/keyvalue-tests/VolatileMapStateStorageTest.cpp b/libminifi/test/keyvalue-tests/VolatileMapStateStorageTest.cpp index 43fb814e79..48055c98ae 100644 --- a/libminifi/test/keyvalue-tests/VolatileMapStateStorageTest.cpp +++ b/libminifi/test/keyvalue-tests/VolatileMapStateStorageTest.cpp @@ -22,7 +22,7 @@ #include "unit/TestBase.h" #include "unit/Catch.h" #include "catch2/catch_session.hpp" -#include "controllers/keyvalue/AutoPersistor.h" +#include "utils/AutoPersistor.h" #include "controllers/keyvalue/KeyValueStateStorage.h" #include "core/ProcessGroup.h" #include "core/yaml/YamlConfiguration.h" @@ -89,7 +89,7 @@ class VolatileMapStateStorageTestFixture { } protected: - std::shared_ptr configuration = std::make_shared(); + std::shared_ptr configuration = std::make_shared(); std::shared_ptr test_repo = std::make_shared(); std::shared_ptr test_flow_repo = std::make_shared(); std::shared_ptr content_repo = std::make_shared(); diff --git a/libminifi/test/libtest/integration/CMakeLists.txt b/libminifi/test/libtest/integration/CMakeLists.txt index e184e85cf8..7225eb4b2e 100644 --- a/libminifi/test/libtest/integration/CMakeLists.txt +++ b/libminifi/test/libtest/integration/CMakeLists.txt @@ -19,5 +19,5 @@ file(GLOB SOURCES "*.cpp") add_minifi_library(libminifi-integrationtest STATIC ${SOURCES}) target_link_libraries(libminifi-integrationtest libminifi-unittest minifi-civet-extensions) -target_include_directories(libminifi-integrationtest BEFORE PRIVATE "${CMAKE_SOURCE_DIR}/libminifi/test/libtest/") +target_include_directories(libminifi-integrationtest BEFORE PRIVATE "${CMAKE_SOURCE_DIR}/libminifi/include/" "${CMAKE_SOURCE_DIR}/libminifi/test/libtest/") target_include_directories(libminifi-integrationtest BEFORE PRIVATE "${CMAKE_SOURCE_DIR}/extensions/civetweb/") diff --git a/libminifi/test/libtest/integration/CivetStream.h b/libminifi/test/libtest/integration/CivetStream.h index 0aa764a508..141a9f3618 100644 --- a/libminifi/test/libtest/integration/CivetStream.h +++ b/libminifi/test/libtest/integration/CivetStream.h @@ -24,7 +24,7 @@ namespace org::apache::nifi::minifi::io { -class CivetStream : public io::InputStream { +class CivetStream : public io::InputStreamImpl { public: /** * File Stream constructor that accepts an fstream shared pointer. diff --git a/libminifi/test/libtest/integration/IntegrationBase.cpp b/libminifi/test/libtest/integration/IntegrationBase.cpp index 72ae844fd7..3652e0ccb2 100644 --- a/libminifi/test/libtest/integration/IntegrationBase.cpp +++ b/libminifi/test/libtest/integration/IntegrationBase.cpp @@ -29,7 +29,7 @@ namespace org::apache::nifi::minifi::test { IntegrationBase::IntegrationBase(std::chrono::milliseconds waitTime) - : configuration(std::make_shared()), + : configuration(std::make_shared()), wait_time_(waitTime) { } @@ -107,7 +107,7 @@ void IntegrationBase::run(const std::optional& test_file_ if (!configuration->get(minifi::Configure::nifi_state_storage_local_path)) { configuration->set(minifi::Configure::nifi_state_storage_local_path, state_dir.string()); } - core::ProcessContext::getOrCreateDefaultStateStorage(controller_service_provider.get(), configuration); + core::ProcessContextImpl::getOrCreateDefaultStateStorage(controller_service_provider.get(), configuration); std::shared_ptr pg(flow_config->getRoot()); queryRootProcessGroup(pg); diff --git a/libminifi/test/libtest/integration/IntegrationBase.h b/libminifi/test/libtest/integration/IntegrationBase.h index 86a46e3f85..76c5186063 100644 --- a/libminifi/test/libtest/integration/IntegrationBase.h +++ b/libminifi/test/libtest/integration/IntegrationBase.h @@ -29,6 +29,7 @@ #include "FlowController.h" #include "properties/Configure.h" #include "utils/file/AssetManager.h" +#include "utils/file/FileUtils.h" namespace minifi = org::apache::nifi::minifi; namespace core = minifi::core; diff --git a/libminifi/test/libtest/unit/CMakeLists.txt b/libminifi/test/libtest/unit/CMakeLists.txt index 3b90524e90..1a6220fe89 100644 --- a/libminifi/test/libtest/unit/CMakeLists.txt +++ b/libminifi/test/libtest/unit/CMakeLists.txt @@ -18,7 +18,7 @@ # file(GLOB TEST_BASE_SOURCES "*.cpp") add_minifi_library(libminifi-unittest STATIC ${TEST_BASE_SOURCES}) -target_link_libraries(libminifi-unittest core-minifi Catch2WithMain) +target_link_libraries(libminifi-unittest core-minifi minifi-extension-utils Catch2WithMain) target_include_directories(libminifi-unittest BEFORE PRIVATE "${CMAKE_SOURCE_DIR}/libminifi/include/") if(WIN32) target_include_directories(libminifi-unittest BEFORE PRIVATE "${CMAKE_SOURCE_DIR}/libminifi/opsys/win") diff --git a/libminifi/test/libtest/unit/ConfigurationTestController.h b/libminifi/test/libtest/unit/ConfigurationTestController.h index 67217b2c7b..6110de55e4 100644 --- a/libminifi/test/libtest/unit/ConfigurationTestController.h +++ b/libminifi/test/libtest/unit/ConfigurationTestController.h @@ -30,7 +30,7 @@ class ConfigurationTestController : public TestController { public: ConfigurationTestController() { flow_file_repo_ = core::createRepository("flowfilerepository"); - configuration_ = std::make_shared(); + configuration_ = std::make_shared(); content_repo_ = std::make_shared(); LogTestController::getInstance().setDebug(); diff --git a/libminifi/test/libtest/unit/ContentRepositoryDependentTests.h b/libminifi/test/libtest/unit/ContentRepositoryDependentTests.h index 245d645e48..f7d6bb7102 100644 --- a/libminifi/test/libtest/unit/ContentRepositoryDependentTests.h +++ b/libminifi/test/libtest/unit/ContentRepositoryDependentTests.h @@ -28,7 +28,7 @@ #include "unit/TestBase.h" #include "unit/Catch.h" #include "unit/DummyProcessor.h" -#include "StreamPipe.h" +#include "io/StreamPipe.h" #pragma once @@ -66,7 +66,7 @@ class Fixture { test_plan_->runNextProcessor(); return test_plan_->getCurrentContext(); }(); - process_session_ = std::make_unique(context_); + process_session_ = std::make_unique(context_); } core::ProcessSession &processSession() { return *process_session_; } diff --git a/libminifi/test/libtest/unit/DummyProcessor.h b/libminifi/test/libtest/unit/DummyProcessor.h index b120d0eca0..d2e65c3e9b 100644 --- a/libminifi/test/libtest/unit/DummyProcessor.h +++ b/libminifi/test/libtest/unit/DummyProcessor.h @@ -25,12 +25,12 @@ namespace org::apache::nifi::minifi::test { -class DummyProcessor : public minifi::core::Processor { - using minifi::core::Processor::Processor; +class DummyProcessor : public minifi::core::ProcessorImpl { + using minifi::core::ProcessorImpl::ProcessorImpl; public: - DummyProcessor(std::string_view name, const minifi::utils::Identifier& uuid) : Processor(name, uuid) {} - explicit DummyProcessor(std::string_view name) : Processor(name) {} + DummyProcessor(std::string_view name, const minifi::utils::Identifier& uuid) : ProcessorImpl(name, uuid) {} + explicit DummyProcessor(std::string_view name) : ProcessorImpl(name) {} static constexpr const char* Description = "A processor that does nothing."; static constexpr auto Properties = std::array{}; static constexpr auto Relationships = std::array{}; diff --git a/libminifi/test/libtest/unit/MockClasses.h b/libminifi/test/libtest/unit/MockClasses.h index 846dce5544..21e9ddf16c 100644 --- a/libminifi/test/libtest/unit/MockClasses.h +++ b/libminifi/test/libtest/unit/MockClasses.h @@ -35,14 +35,14 @@ std::mutex control_mutex; std::atomic subprocess_controller_service_found_correctly{false}; std::atomic subprocess_controller_service_not_found_correctly{false}; -class MockControllerService : public minifi::core::controller::ControllerService { +class MockControllerService : public minifi::core::controller::ControllerServiceImpl { public: explicit MockControllerService(std::string_view name, const minifi::utils::Identifier &uuid) - : ControllerService(name, uuid) { + : ControllerServiceImpl(name, uuid) { } explicit MockControllerService(std::string_view name) - : ControllerService(name) { + : ControllerServiceImpl(name) { } MockControllerService() = default; @@ -54,7 +54,7 @@ class MockControllerService : public minifi::core::controller::ControllerService ADD_COMMON_VIRTUAL_FUNCTIONS_FOR_CONTROLLER_SERVICES void initialize() override { - minifi::core::controller::ControllerService::initialize(); + minifi::core::controller::ControllerServiceImpl::initialize(); enable(); } @@ -81,15 +81,15 @@ class MockControllerService : public minifi::core::controller::ControllerService std::string str; }; -class MockProcessor : public minifi::core::Processor { +class MockProcessor : public minifi::core::ProcessorImpl { public: explicit MockProcessor(std::string_view name, const minifi::utils::Identifier &uuid) - : Processor(name, uuid) { + : ProcessorImpl(name, uuid) { setTriggerWhenEmpty(true); } explicit MockProcessor(std::string_view name) - : Processor(name) { + : ProcessorImpl(name) { setTriggerWhenEmpty(true); } @@ -126,7 +126,7 @@ class MockProcessor : public minifi::core::Processor { std::shared_ptr service = context.getControllerService(linked_service, getUUID()); std::lock_guard lock(control_mutex); REQUIRE(nullptr != service); - REQUIRE("pushitrealgood" == std::static_pointer_cast(service)->doSomething()); + REQUIRE("pushitrealgood" == std::dynamic_pointer_cast(service)->doSomething()); // verify we have access to the controller service // and verify that we can execute it. } diff --git a/libminifi/test/libtest/unit/ProvenanceTestHelper.h b/libminifi/test/libtest/unit/ProvenanceTestHelper.h index ffc30bfafa..36704bc715 100644 --- a/libminifi/test/libtest/unit/ProvenanceTestHelper.h +++ b/libminifi/test/libtest/unit/ProvenanceTestHelper.h @@ -114,7 +114,7 @@ class TestRepositoryBase : public T_BaseRepository { std::map repository_results_; }; -class TestRepository : public TestRepositoryBase { +class TestRepository : public TestRepositoryBase { public: bool start() override { return true; @@ -149,7 +149,7 @@ class TestVolatileRepository : public TestRepositoryBase { +class TestThreadedRepository : public TestRepositoryBase { public: ~TestThreadedRepository() override { stop(); @@ -185,10 +185,10 @@ class TestRocksDbRepository : public TestThreadedRepository { } }; -class TestFlowRepository : public org::apache::nifi::minifi::core::ThreadedRepository { +class TestFlowRepository : public org::apache::nifi::minifi::core::ThreadedRepositoryImpl { public: TestFlowRepository() - : org::apache::nifi::minifi::core::ThreadedRepository("ff", "./dir", 1s, TEST_MAX_REPOSITORY_STORAGE_SIZE, 0ms) { + : org::apache::nifi::minifi::core::ThreadedRepositoryImpl("ff", "./dir", 1s, TEST_MAX_REPOSITORY_STORAGE_SIZE, 0ms) { } bool initialize(const std::shared_ptr &) override { @@ -245,7 +245,7 @@ class TestFlowController : public org::apache::nifi::minifi::FlowController { public: TestFlowController(std::shared_ptr repo, std::shared_ptr flow_file_repo, const std::shared_ptr& /*content_repo*/) - :org::apache::nifi::minifi::FlowController(repo, flow_file_repo, std::make_shared(), nullptr, + :org::apache::nifi::minifi::FlowController(repo, flow_file_repo, org::apache::nifi::minifi::Configure::create(), nullptr, std::make_shared()) { } diff --git a/libminifi/test/libtest/unit/ReadFromFlowFileTestProcessor.h b/libminifi/test/libtest/unit/ReadFromFlowFileTestProcessor.h index c1be2ba17d..869c48bb4c 100644 --- a/libminifi/test/libtest/unit/ReadFromFlowFileTestProcessor.h +++ b/libminifi/test/libtest/unit/ReadFromFlowFileTestProcessor.h @@ -34,14 +34,14 @@ namespace org::apache::nifi::minifi::processors { -class ReadFromFlowFileTestProcessor : public core::Processor { +class ReadFromFlowFileTestProcessor : public core::ProcessorImpl { public: static constexpr const char* ON_SCHEDULE_LOG_STR = "ReadFromFlowFileTestProcessor::onSchedule executed"; static constexpr const char* ON_TRIGGER_LOG_STR = "ReadFromFlowFileTestProcessor::onTrigger executed"; static constexpr const char* ON_UNSCHEDULE_LOG_STR = "ReadFromFlowFileTestProcessor::onUnSchedule executed"; explicit ReadFromFlowFileTestProcessor(std::string_view name, const utils::Identifier& uuid = utils::Identifier()) - : Processor(name, uuid) { + : ProcessorImpl(name, uuid) { } static constexpr const char* Description = "ReadFromFlowFileTestProcessor (only for testing purposes)"; diff --git a/libminifi/test/libtest/unit/RecordSetTesters.h b/libminifi/test/libtest/unit/RecordSetTesters.h index 80b933f273..56f64df4bf 100644 --- a/libminifi/test/libtest/unit/RecordSetTesters.h +++ b/libminifi/test/libtest/unit/RecordSetTesters.h @@ -20,8 +20,9 @@ #include "controllers/RecordSetReader.h" #include "controllers/RecordSetWriter.h" -#include "core/Record.h" +#include "minifi-cpp/core/Record.h" #include "TestBase.h" +#include "core/ProcessSession.h" namespace org::apache::nifi::minifi::core::test { @@ -38,7 +39,7 @@ class RecordSetFixture { std::shared_ptr test_plan_ = test_controller_.createPlan(plan_config_); Processor* dummy_processor_ = test_plan_->addProcessor("DummyProcessor", "dummyProcessor"); std::shared_ptr context_ = [this] { test_plan_->runNextProcessor(); return test_plan_->getCurrentContext(); }(); - std::unique_ptr process_session_ = std::make_unique(context_); + std::unique_ptr process_session_ = std::make_unique(context_); const Relationship relationship_{"success", "description"}; }; diff --git a/libminifi/test/libtest/unit/SingleProcessorTestController.cpp b/libminifi/test/libtest/unit/SingleProcessorTestController.cpp index 3df87c269e..78406378dc 100644 --- a/libminifi/test/libtest/unit/SingleProcessorTestController.cpp +++ b/libminifi/test/libtest/unit/SingleProcessorTestController.cpp @@ -84,7 +84,7 @@ core::Relationship SingleProcessorTestController::addDynamicRelationship(std::st } std::shared_ptr SingleProcessorTestController::createFlowFile(const std::string_view content, std::unordered_map attributes) { - const auto flow_file = std::make_shared(); + const auto flow_file = std::make_shared(); for (auto& attr : std::move(attributes)) { flow_file->setAttribute(attr.first, std::move(attr.second)); } diff --git a/libminifi/test/libtest/unit/SingleProcessorTestController.h b/libminifi/test/libtest/unit/SingleProcessorTestController.h index 0245e3314c..065894a7b1 100644 --- a/libminifi/test/libtest/unit/SingleProcessorTestController.h +++ b/libminifi/test/libtest/unit/SingleProcessorTestController.h @@ -62,7 +62,7 @@ class SingleProcessorTestController : public TestController { core::Relationship addDynamicRelationship(std::string name); template - T* getProcessor() const { return static_cast(processor_); } + T* getProcessor() const { return dynamic_cast(processor_); } std::shared_ptr plan = createPlan(); diff --git a/libminifi/test/libtest/unit/SiteToSiteHelper.h b/libminifi/test/libtest/unit/SiteToSiteHelper.h index e22569c5e9..71390bd60d 100644 --- a/libminifi/test/libtest/unit/SiteToSiteHelper.h +++ b/libminifi/test/libtest/unit/SiteToSiteHelper.h @@ -28,7 +28,7 @@ namespace minifi = org::apache::nifi::minifi; /** * Test repository */ -class SiteToSiteResponder : public minifi::io::BaseStream { +class SiteToSiteResponder : public minifi::io::BaseStreamImpl { private: minifi::io::BufferStream server_responses_; std::queue client_responses_; diff --git a/libminifi/test/libtest/unit/StatefulProcessor.h b/libminifi/test/libtest/unit/StatefulProcessor.h index c6f8f8eef3..5659b16921 100644 --- a/libminifi/test/libtest/unit/StatefulProcessor.h +++ b/libminifi/test/libtest/unit/StatefulProcessor.h @@ -25,9 +25,9 @@ namespace org::apache::nifi::minifi::processors { -class StatefulProcessor : public core::Processor { +class StatefulProcessor : public core::ProcessorImpl { public: - using core::Processor::Processor; + using core::ProcessorImpl::ProcessorImpl; static constexpr const char* Description = "A processor with state for test purposes."; static constexpr auto Properties = std::array{}; diff --git a/libminifi/test/libtest/unit/TestBase.cpp b/libminifi/test/libtest/unit/TestBase.cpp index ee337986e1..8b04e88208 100644 --- a/libminifi/test/libtest/unit/TestBase.cpp +++ b/libminifi/test/libtest/unit/TestBase.cpp @@ -25,6 +25,7 @@ #include #include "core/Processor.h" +#include "core/ProcessorNode.h" #include "core/ProcessContextBuilder.h" #include "core/PropertyDefinition.h" #include "core/logging/LoggerConfiguration.h" @@ -225,7 +226,7 @@ TestPlan::TestPlan(std::shared_ptr content_repo if (!configuration_->get(minifi::Configure::nifi_state_storage_local_path)) { configuration_->set(minifi::Configure::nifi_state_storage_local_path, state_dir_->getPath().string()); } - state_storage_ = minifi::core::ProcessContext::getOrCreateDefaultStateStorage(controller_services_provider_.get(), configuration_); + state_storage_ = minifi::core::ProcessContextImpl::getOrCreateDefaultStateStorage(controller_services_provider_.get(), configuration_); } TestPlan::~TestPlan() { @@ -264,7 +265,7 @@ minifi::core::Processor* TestPlan::addProcessor(std::unique_ptrgetUUIDStr() << "-to-" << processor->getUUIDStr(); - auto connection = std::make_unique(flow_repo_, content_repo_, connection_name.str()); + auto connection = std::make_unique(flow_repo_, content_repo_, connection_name.str()); logger_->log_info("Creating {} connection for proc {}", connection_name.str(), processor_queue_.size() + 1); for (const auto& relationship : relationships) { @@ -282,7 +283,7 @@ minifi::core::Processor* TestPlan::addProcessor(std::unique_ptr node = std::make_shared(processor.get()); + std::shared_ptr node = std::make_shared(processor.get()); processor_nodes_.push_back(node); std::shared_ptr contextBuilder = minifi::core::ClassLoader::getDefaultClassLoader().instantiate("ProcessContextBuilder", "ProcessContextBuilder"); @@ -333,7 +334,7 @@ minifi::Connection* TestPlan::addConnection(minifi::core::Processor* source_proc << (source_proc ? source_proc->getUUIDStr().c_str() : "none") << "-to-" << (destination_proc ? destination_proc->getUUIDStr().c_str() : "none"); - auto connection = std::make_unique(flow_repo_, content_repo_, connection_name.str()); + auto connection = std::make_unique(flow_repo_, content_repo_, connection_name.str()); connection->addRelationship(source_relationship); @@ -484,7 +485,7 @@ std::shared_ptr TestPlan::getProcessContextForProc void TestPlan::scheduleProcessor(minifi::core::Processor* processor, const std::shared_ptr& context) { if (std::find(configured_processors_.begin(), configured_processors_.end(), processor) == configured_processors_.end()) { // Ordering on factories and list of configured processors do not matter - const auto factory = std::make_shared(context); + const auto factory = std::make_shared(context); factories_.push_back(factory); processor->onSchedule(*context, *factory); configured_processors_.push_back(processor); @@ -508,14 +509,14 @@ bool TestPlan::runProcessor(minifi::core::Processor* processor, const PreTrigger return runProcessor(processor_location, verify); } -class TestSessionFactory : public minifi::core::ProcessSessionFactory { +class TestSessionFactory : public minifi::core::ProcessSessionFactoryImpl { using SessionCallback = std::function&)>; public: TestSessionFactory(std::shared_ptr context, SessionCallback on_new_session) - : ProcessSessionFactory(std::move(context)), on_new_session_(std::move(on_new_session)) {} + : ProcessSessionFactoryImpl(std::move(context)), on_new_session_(std::move(on_new_session)) {} std::shared_ptr createSession() override { - auto session = ProcessSessionFactory::createSession(); + auto session = ProcessSessionFactoryImpl::createSession(); on_new_session_(session); return session; } @@ -538,7 +539,7 @@ bool TestPlan::runProcessor(size_t target_location, const PreTriggerVerifier& ve processor->setScheduledState(minifi::core::ScheduledState::RUNNING); if (verify) { - auto current_session = std::make_shared(context); + auto current_session = std::make_shared(context); process_sessions_.push_back(current_session); verify(context, current_session); current_session->commit(); @@ -642,7 +643,7 @@ std::unique_ptr TestPlan::buildFinalConnection(minifi::core: gsl_Expects(termination_); std::stringstream connection_name; connection_name << processor->getUUIDStr() << "-to-" << processor->getUUIDStr(); - auto connection = std::make_unique(flow_repo_, content_repo_, connection_name.str()); + auto connection = std::make_unique(flow_repo_, content_repo_, connection_name.str()); connection->addRelationship(termination_.value()); // link the connections so that we can test results at the end for this @@ -704,13 +705,13 @@ TestController::TestController() : log(LogTestController::getInstance()) { minifi::setDefaultDirectory("./"); log.reset(); - minifi::utils::IdGenerator::getIdGenerator()->initialize(std::make_shared()); + minifi::utils::IdGenerator::getIdGenerator()->initialize(minifi::Properties::create()); flow_version_ = std::make_shared("test", "test", "test"); } std::shared_ptr TestController::createPlan(PlanConfig config) { if (!config.configuration) { - config.configuration = std::make_shared(); + config.configuration = minifi::Configure::create(); config.configuration->setHome(createTempDirectory()); config.configuration->set(minifi::Configure::nifi_state_storage_local_class_name, "VolatileMapStateStorage"); config.configuration->set(minifi::Configure::nifi_dbcontent_repository_directory_default, createTempDirectory().string()); diff --git a/libminifi/test/libtest/unit/TestBase.h b/libminifi/test/libtest/unit/TestBase.h index 85d08d7e87..6a8626847e 100644 --- a/libminifi/test/libtest/unit/TestBase.h +++ b/libminifi/test/libtest/unit/TestBase.h @@ -391,13 +391,13 @@ static bool disableAwsMetadata = [] { static bool extensionInitializer = [] { LogTestController::getInstance().setTrace(); LogTestController::getInstance().setTrace(); - auto config = std::make_shared(); + auto config = minifi::Configure::create(); #ifdef EXTENSION_LIST config->set(minifi::Configuration::nifi_extension_path, EXTENSION_LIST); #else config->set(minifi::Configuration::nifi_extension_path, "*minifi-*"); #endif - core::extension::ExtensionManager::get().initialize(config); + core::extension::ExtensionManagerImpl::get().initialize(config); return true; }(); #endif diff --git a/libminifi/test/libtest/unit/TestControllerWithFlow.cpp b/libminifi/test/libtest/unit/TestControllerWithFlow.cpp index d0fa38e30a..e475e08ab1 100644 --- a/libminifi/test/libtest/unit/TestControllerWithFlow.cpp +++ b/libminifi/test/libtest/unit/TestControllerWithFlow.cpp @@ -40,7 +40,7 @@ TestControllerWithFlow::TestControllerWithFlow(const char* yamlConfigContent, bo yaml_path_ = home_ / "config.yml"; std::ofstream{yaml_path_} << yamlConfigContent; - configuration_ = std::make_shared(); + configuration_ = minifi::Configure::create(); configuration_->setHome(home_.string()); configuration_->set(minifi::Configure::nifi_flow_configuration_file, yaml_path_.string()); configuration_->set(minifi::Configure::nifi_c2_enable, "true"); diff --git a/libminifi/test/libtest/unit/TestRecord.h b/libminifi/test/libtest/unit/TestRecord.h index aaf98e6653..9b88f347fd 100644 --- a/libminifi/test/libtest/unit/TestRecord.h +++ b/libminifi/test/libtest/unit/TestRecord.h @@ -19,7 +19,7 @@ #pragma once #include -#include "core/Record.h" +#include "minifi-cpp/core/Record.h" namespace org::apache::nifi::minifi::core::test { diff --git a/libminifi/test/libtest/unit/WriteToFlowFileTestProcessor.h b/libminifi/test/libtest/unit/WriteToFlowFileTestProcessor.h index e8c16381e7..3949be1808 100644 --- a/libminifi/test/libtest/unit/WriteToFlowFileTestProcessor.h +++ b/libminifi/test/libtest/unit/WriteToFlowFileTestProcessor.h @@ -32,14 +32,14 @@ namespace org::apache::nifi::minifi::processors { -class WriteToFlowFileTestProcessor : public core::Processor { +class WriteToFlowFileTestProcessor : public core::ProcessorImpl { public: static constexpr const char* ON_SCHEDULE_LOG_STR = "WriteToFlowFileTestProcessor::onSchedule executed"; static constexpr const char* ON_TRIGGER_LOG_STR = "WriteToFlowFileTestProcessor::onTrigger executed"; static constexpr const char* ON_UNSCHEDULE_LOG_STR = "WriteToFlowFileTestProcessor::onUnSchedule executed"; explicit WriteToFlowFileTestProcessor(std::string_view name, const utils::Identifier& uuid = utils::Identifier()) - : Processor(name, uuid) { + : ProcessorImpl(name, uuid) { } static constexpr const char* Description = "WriteToFlowFileTestProcessor (only for testing purposes)"; diff --git a/libminifi/test/persistence-tests/PersistenceTests.cpp b/libminifi/test/persistence-tests/PersistenceTests.cpp index 7560982ac3..2391ac6a20 100644 --- a/libminifi/test/persistence-tests/PersistenceTests.cpp +++ b/libminifi/test/persistence-tests/PersistenceTests.cpp @@ -35,7 +35,10 @@ #include "core/repository/VolatileFlowFileRepository.h" #include "../../extensions/rocksdb-repos/DatabaseContentRepository.h" #include "unit/TestUtils.h" +#include "core/ProcessorNode.h" +#include "core/repository/FileSystemRepository.h" +using ConnectionImpl = minifi::ConnectionImpl; using Connection = minifi::Connection; using MergeContent = minifi::processors::MergeContent; @@ -43,9 +46,9 @@ using minifi::test::utils::verifyEventHappenedInPollTime; namespace { -class TestProcessor : public minifi::core::Processor { +class TestProcessor : public minifi::core::ProcessorImpl { public: - using Processor::Processor; + using ProcessorImpl::ProcessorImpl; static constexpr bool SupportsDynamicProperties = false; static constexpr bool SupportsDynamicRelationships = false; @@ -62,20 +65,20 @@ struct TestFlow{ auto processor = processorGenerator(mainProcUUID()); { processor_ = processor.get(); - auto node = std::make_shared(processor_); - processorContext = std::make_shared(node, nullptr, prov_repo, ff_repository, content_repo); + auto node = std::make_shared(processor_); + processorContext = std::make_shared(node, nullptr, prov_repo, ff_repository, content_repo); } // setup INPUT processor { inputProcessor = std::make_shared("source", inputProcUUID()); - auto node = std::make_shared(inputProcessor.get()); - inputContext = std::make_shared(node, nullptr, prov_repo, + auto node = std::make_shared(inputProcessor.get()); + inputContext = std::make_shared(node, nullptr, prov_repo, ff_repository, content_repo); } // setup Input Connection - auto input = std::make_unique(ff_repository, content_repo, "Input", inputConnUUID()); + auto input = std::make_unique(ff_repository, content_repo, "Input", inputConnUUID()); { input_ = input.get(); input->addRelationship({"input", "d"}); @@ -85,7 +88,7 @@ struct TestFlow{ } // setup Output Connection - auto output = std::make_unique(ff_repository, content_repo, "Output", outputConnUUID()); + auto output = std::make_unique(ff_repository, content_repo, "Output", outputConnUUID()); { output_ = output.get(); output->addRelationship(relationshipToOutput); @@ -102,12 +105,12 @@ struct TestFlow{ // prepare Merge Processor for execution processor_->setScheduledState(core::ScheduledState::RUNNING); - process_session_factory_ = std::make_unique(processorContext); + process_session_factory_ = std::make_unique(processorContext); processor_->onSchedule(*processorContext, *process_session_factory_); } std::shared_ptr write(const std::string& data) { minifi::io::BufferStream stream(data); - core::ProcessSession sessionGenFlowFile(inputContext); + core::ProcessSessionImpl sessionGenFlowFile(inputContext); std::shared_ptr flow = std::static_pointer_cast(sessionGenFlowFile.create()); sessionGenFlowFile.importFrom(stream, flow); REQUIRE(flow->getResourceClaim()->getFlowFileRecordOwnedCount() == 1); @@ -116,10 +119,10 @@ struct TestFlow{ return flow; } std::string read(const std::shared_ptr& file) { - return to_string(core::ProcessSession{processorContext}.readBuffer(file)); + return to_string(core::ProcessSessionImpl{processorContext}.readBuffer(file)); } void trigger() { - auto session = std::make_shared(processorContext); + auto session = std::make_shared(processorContext); processor_->onTrigger(*processorContext, *session); session->commit(); } @@ -171,7 +174,7 @@ TEST_CASE("Processors Can Store FlowFiles", "[TestP1]") { auto dir = testController.createTempDirectory(); - auto config = std::make_shared(); + auto config = std::make_shared(); config->setHome(dir); config->set(minifi::Configure::nifi_dbcontent_repository_directory_default, (dir / "content_repository").string()); config->set(minifi::Configure::nifi_flowfile_repository_directory_default, (dir / "flowfile_repository").string()); @@ -250,9 +253,9 @@ TEST_CASE("Processors Can Store FlowFiles", "[TestP1]") { } } -class ContentUpdaterProcessor : public core::Processor { +class ContentUpdaterProcessor : public core::ProcessorImpl { public: - ContentUpdaterProcessor(std::string_view name, const utils::Identifier& id) : Processor(name, id) {} + ContentUpdaterProcessor(std::string_view name, const utils::Identifier& id) : ProcessorImpl(name, id) {} static constexpr bool SupportsDynamicProperties = false; static constexpr bool SupportsDynamicRelationships = false; @@ -285,7 +288,7 @@ TEST_CASE("Persisted flowFiles are updated on modification", "[TestP1]") { auto dir = testController.createTempDirectory(); - auto config = std::make_shared(); + auto config = std::make_shared(); config->setHome(dir); config->set(minifi::Configure::nifi_dbcontent_repository_directory_default, (dir / "content_repository").string()); config->set(minifi::Configure::nifi_flowfile_repository_directory_default, (dir / "flowfile_repository").string()); diff --git a/libminifi/test/resources/RocksDbStateStorage.yml b/libminifi/test/resources/RocksDbStateStorage.yml index 6600445d41..22c5c15d87 100644 --- a/libminifi/test/resources/RocksDbStateStorage.yml +++ b/libminifi/test/resources/RocksDbStateStorage.yml @@ -1,36 +1,14 @@ -# -# 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. -# Flow Controller: - name: MiNiFi Flow - + name: MiNiFi Flow Processors: [] - Connections: [] - Controller Services: - - name: testcontroller - id: 2438e3c8-015a-1000-79ca-83af40ec1994 - class: RocksDbStateStorage - Properties: - Auto Persistence Interval: - - value: 0 sec - Directory: - - value: state - + - name: testcontroller + id: 2438e3c8-015a-1000-79ca-83af40ec1994 + class: RocksDbStateStorage + Properties: + Auto Persistence Interval: + - value: 0 sec + Directory: + - value: state Remote Processing Groups: [] diff --git a/libminifi/test/unit/ComponentManifestTests.cpp b/libminifi/test/unit/ComponentManifestTests.cpp index 7eb5519664..f6aa35b0cd 100644 --- a/libminifi/test/unit/ComponentManifestTests.cpp +++ b/libminifi/test/unit/ComponentManifestTests.cpp @@ -39,9 +39,9 @@ SerializedResponseNode& get(SerializedResponseNode& node, const std::string& fie namespace test::apple { -class ExampleService : public core::controller::ControllerService { +class ExampleService : public core::controller::ControllerServiceImpl { public: - using ControllerService::ControllerService; + using ControllerServiceImpl::ControllerServiceImpl; static constexpr const char* Description = "An example service"; static constexpr auto Properties = std::array{}; @@ -56,9 +56,9 @@ class ExampleService : public core::controller::ControllerService { REGISTER_RESOURCE(ExampleService, ControllerService); -class ExampleProcessor : public core::Processor { +class ExampleProcessor : public core::ProcessorImpl { public: - using Processor::Processor; + using ProcessorImpl::ProcessorImpl; static constexpr const char* Description = "An example processor"; static constexpr auto ExampleProperty = core::PropertyDefinitionBuilder<>::createProperty("Example Property") diff --git a/libminifi/test/unit/ConnectionTests.cpp b/libminifi/test/unit/ConnectionTests.cpp index 343a9bd8e2..fb7482651d 100644 --- a/libminifi/test/unit/ConnectionTests.cpp +++ b/libminifi/test/unit/ConnectionTests.cpp @@ -23,14 +23,14 @@ TEST_CASE("Connection::poll() works correctly", "[poll]") { const auto flow_repo = std::make_shared(); const auto content_repo = std::make_shared(); - content_repo->initialize(std::make_shared()); + content_repo->initialize(std::make_shared()); const auto id_generator = utils::IdGenerator::getIdGenerator(); utils::Identifier connection_id = id_generator->generate(); utils::Identifier src_id = id_generator->generate(); utils::Identifier dest_id = id_generator->generate(); - const auto connection = std::make_shared(flow_repo, content_repo, "test_connection", connection_id, src_id, dest_id); + const auto connection = std::make_shared(flow_repo, content_repo, "test_connection", connection_id, src_id, dest_id); std::set> expired_flow_files; SECTION("when called on an empty Connection, poll() returns nullptr") { @@ -44,7 +44,7 @@ TEST_CASE("Connection::poll() works correctly", "[poll]") { SECTION("without expiration duration") {} SECTION("with expiration duration") { connection->setFlowExpirationDuration(1s); } - const auto flow_file = std::make_shared(); + const auto flow_file = std::make_shared(); connection->put(flow_file); REQUIRE(flow_file == connection->poll(expired_flow_files)); REQUIRE(nullptr == connection->poll(expired_flow_files)); @@ -54,14 +54,14 @@ TEST_CASE("Connection::poll() works correctly", "[poll]") { SECTION("without expiration duration") {} SECTION("with expiration duration") { connection->setFlowExpirationDuration(1s); } - const auto flow_file = std::make_shared(); + const auto flow_file = std::make_shared(); flow_file->penalize(std::chrono::seconds{10}); connection->put(flow_file); REQUIRE(nullptr == connection->poll(expired_flow_files)); } SECTION("when called on a connection with a single expired flow file, poll() returns nullptr and returns the expired flow file in the out parameter") { - const auto flow_file = std::make_shared(); + const auto flow_file = std::make_shared(); connection->setFlowExpirationDuration(1ms); connection->put(flow_file); std::this_thread::sleep_for(std::chrono::milliseconds{2}); @@ -73,11 +73,11 @@ TEST_CASE("Connection::poll() works correctly", "[poll]") { SECTION("without expiration duration") {} SECTION("with expiration duration") { connection->setFlowExpirationDuration(1s); } - const auto penalized_flow_file = std::make_shared(); + const auto penalized_flow_file = std::make_shared(); penalized_flow_file->penalize(std::chrono::seconds{10}); connection->put(penalized_flow_file); - const auto flow_file = std::make_shared(); + const auto flow_file = std::make_shared(); connection->put(flow_file); REQUIRE(flow_file == connection->poll(expired_flow_files)); @@ -88,10 +88,10 @@ TEST_CASE("Connection::poll() works correctly", "[poll]") { TEST_CASE("Connection backpressure tests", "[Connection]") { const auto flow_repo = std::make_shared(); const auto content_repo = std::make_shared(); - content_repo->initialize(std::make_shared()); + content_repo->initialize(std::make_shared()); const auto id_generator = utils::IdGenerator::getIdGenerator(); - const auto connection = std::make_shared(flow_repo, content_repo, "test_connection", id_generator->generate(), id_generator->generate(), id_generator->generate()); + const auto connection = std::make_shared(flow_repo, content_repo, "test_connection", id_generator->generate(), id_generator->generate(), id_generator->generate()); CHECK(connection->getBackpressureThresholdDataSize() == minifi::Connection::DEFAULT_BACKPRESSURE_THRESHOLD_DATA_SIZE); CHECK(connection->getBackpressureThresholdCount() == minifi::Connection::DEFAULT_BACKPRESSURE_THRESHOLD_COUNT); @@ -99,9 +99,9 @@ TEST_CASE("Connection backpressure tests", "[Connection]") { SECTION("The number of flowfiles can be limited") { connection->setBackpressureThresholdCount(2); CHECK_FALSE(connection->backpressureThresholdReached()); - connection->put(std::make_shared()); + connection->put(std::make_shared()); CHECK_FALSE(connection->backpressureThresholdReached()); - connection->put(std::make_shared()); + connection->put(std::make_shared()); CHECK(connection->backpressureThresholdReached()); connection->setBackpressureThresholdCount(0); CHECK_FALSE(connection->backpressureThresholdReached()); @@ -110,13 +110,13 @@ TEST_CASE("Connection backpressure tests", "[Connection]") { connection->setBackpressureThresholdDataSize(3_KB); CHECK_FALSE(connection->backpressureThresholdReached()); { - auto flow_file = std::make_shared(); + auto flow_file = std::make_shared(); flow_file->setSize(2_KB); connection->put(flow_file); } CHECK_FALSE(connection->backpressureThresholdReached()); { - auto flow_file = std::make_shared(); + auto flow_file = std::make_shared(); flow_file->setSize(2_KB); connection->put(flow_file); } diff --git a/libminifi/test/unit/ControllerSocketMetricsPublisherTest.cpp b/libminifi/test/unit/ControllerSocketMetricsPublisherTest.cpp index 702583bbc3..d982d4f156 100644 --- a/libminifi/test/unit/ControllerSocketMetricsPublisherTest.cpp +++ b/libminifi/test/unit/ControllerSocketMetricsPublisherTest.cpp @@ -24,7 +24,7 @@ namespace org::apache::nifi::minifi::test { -class TestQueueMetrics : public state::response::ResponseNode { +class TestQueueMetrics : public state::response::ResponseNodeImpl { public: TestQueueMetrics() { metrics_ = { @@ -62,8 +62,8 @@ class TestControllerSocketMetricsPublisher : public c2::ControllerSocketMetricsP class ControllerSocketMetricsPublisherTestFixture { public: ControllerSocketMetricsPublisherTestFixture() - : configuration_(std::make_shared()), - response_node_loader_(std::make_shared(configuration_, std::vector>{}, nullptr)), + : configuration_(std::make_shared()), + response_node_loader_(std::make_shared(configuration_, std::vector>{}, nullptr)), test_response_node_(std::make_shared()), controller_socket_metrics_publisher_("test_publisher") { controller_socket_metrics_publisher_.initialize(configuration_, response_node_loader_); diff --git a/libminifi/test/unit/CronTests.cpp b/libminifi/test/unit/CronTests.cpp index 83ff20d82a..fa70ac206d 100644 --- a/libminifi/test/unit/CronTests.cpp +++ b/libminifi/test/unit/CronTests.cpp @@ -20,10 +20,12 @@ #include "utils/Cron.h" #include "date/date.h" #include "date/tz.h" +#include "utils/TimeUtil.h" using std::chrono::system_clock; using std::chrono::seconds; using org::apache::nifi::minifi::utils::Cron; +namespace timeutils = org::apache::nifi::minifi::utils::timeutils; void checkNext(const std::string& expr, const date::zoned_time& from, const date::zoned_time& next) { @@ -160,7 +162,7 @@ TEST_CASE("Cron::calculateNextTrigger", "[cron]") { using namespace date::literals; // NOLINT(google-build-using-namespace) using namespace std::literals::chrono_literals; #ifdef WIN32 - date::set_install(TZ_DATA_DIR); + timeutils::dateSetInstall(TZ_DATA_DIR); #endif checkNext("0/15 * 1-4 * * ?", @@ -446,7 +448,7 @@ TEST_CASE("Cron::calculateNextTrigger with timezones", "[cron]") { using namespace date::literals; // NOLINT(google-build-using-namespace) using namespace std::literals::chrono_literals; #ifdef WIN32 - date::set_install(TZ_DATA_DIR); + timeutils::dateSetInstall(TZ_DATA_DIR); #endif const std::vector time_zones{ "Europe/Berlin", "Asia/Seoul", "America/Los_Angeles", "Asia/Singapore", "UTC" }; diff --git a/libminifi/test/unit/DecryptorTests.cpp b/libminifi/test/unit/DecryptorTests.cpp index 68c613695c..a026dc8dc5 100644 --- a/libminifi/test/unit/DecryptorTests.cpp +++ b/libminifi/test/unit/DecryptorTests.cpp @@ -18,7 +18,7 @@ #include "properties/Decryptor.h" #include "unit/Catch.h" #include "unit/TestBase.h" -#include "StringUtils.h" +#include "utils/StringUtils.h" #include "properties/Configure.h" namespace minifi = org::apache::nifi::minifi; @@ -88,7 +88,7 @@ TEST_CASE("Decryptor can decrypt a configuration file", "[decryptSensitiveProper utils::crypto::Bytes encryption_key = utils::string::from_hex("5506c28d0fe265299e294a4c766b723a48986764953e93d38b3c627176fd10ed"); minifi::Decryptor decryptor{utils::crypto::EncryptionProvider{encryption_key}}; - minifi::Configure configuration{decryptor}; + minifi::ConfigureImpl configuration{decryptor}; std::filesystem::path resources_dir{TEST_RESOURCES}; configuration.setHome(resources_dir); configuration.loadConfigureFile("encrypted.minifi.properties"); diff --git a/libminifi/test/unit/DiskSpaceWatchdogTests.cpp b/libminifi/test/unit/DiskSpaceWatchdogTests.cpp index 7be7734086..d654fcd2a8 100644 --- a/libminifi/test/unit/DiskSpaceWatchdogTests.cpp +++ b/libminifi/test/unit/DiskSpaceWatchdogTests.cpp @@ -32,14 +32,14 @@ TEST_CASE("disk_space_watchdog::read_config", "[dsg::read_config]") { const auto mebibytes = 1024 * 1024; SECTION("defaults are present") { - const minifi::Configure configure; + const minifi::ConfigureImpl configure; const auto conf = dsg::read_config(configure); REQUIRE(conf.interval >= chr::nanoseconds{0}); REQUIRE(conf.restart_threshold_bytes > conf.stop_threshold_bytes); } SECTION("basic") { - minifi::Configure configure; + minifi::ConfigureImpl configure; configure.set(minifi::Configure::minifi_disk_space_watchdog_stop_threshold, std::to_string(10 * mebibytes)); configure.set(minifi::Configure::minifi_disk_space_watchdog_restart_threshold, std::to_string(25 * mebibytes)); configure.set(minifi::Configure::minifi_disk_space_watchdog_interval, "2000 millis"); @@ -50,7 +50,7 @@ TEST_CASE("disk_space_watchdog::read_config", "[dsg::read_config]") { } SECTION("units") { - minifi::Configure configure; + minifi::ConfigureImpl configure; configure.set(minifi::Configure::minifi_disk_space_watchdog_stop_threshold, "100 MB"); configure.set(minifi::Configure::minifi_disk_space_watchdog_restart_threshold, "250 MB"); configure.set(minifi::Configure::minifi_disk_space_watchdog_interval, "7 sec"); diff --git a/libminifi/test/unit/DynamicPropertyTests.cpp b/libminifi/test/unit/DynamicPropertyTests.cpp index c603f90932..3f92f186ed 100644 --- a/libminifi/test/unit/DynamicPropertyTests.cpp +++ b/libminifi/test/unit/DynamicPropertyTests.cpp @@ -23,7 +23,7 @@ namespace org::apache::nifi::minifi::core { -class TestConfigurableComponentSupportsDynamic : public ConfigurableComponent { +class TestConfigurableComponentSupportsDynamic : public ConfigurableComponentImpl { public: bool supportsDynamicProperties() const override { return true; @@ -38,7 +38,7 @@ class TestConfigurableComponentSupportsDynamic : public ConfigurableComponent { } }; -class TestConfigurableComponentNotSupportsDynamic : public ConfigurableComponent { +class TestConfigurableComponentNotSupportsDynamic : public ConfigurableComponentImpl { public: bool supportsDynamicProperties() const override { return false; diff --git a/libminifi/test/unit/FileSystemRepositoryTests.cpp b/libminifi/test/unit/FileSystemRepositoryTests.cpp index 675c4ccaf5..99b643286d 100644 --- a/libminifi/test/unit/FileSystemRepositoryTests.cpp +++ b/libminifi/test/unit/FileSystemRepositoryTests.cpp @@ -47,7 +47,7 @@ TEST_CASE("Test Physical memory usage", "[testphysicalmemoryusage]") { TestController controller; auto dir = controller.createTempDirectory(); auto fs_repo = std::make_shared(); - auto config = std::make_shared(); + auto config = std::make_shared(); config->set(minifi::Configure::nifi_dbcontent_repository_directory_default, dir.string()); REQUIRE(fs_repo->initialize(config)); const auto start_memory = minifi::utils::OsUtils::getCurrentProcessPhysicalMemoryUsage(); @@ -73,13 +73,13 @@ TEST_CASE("Test Physical memory usage", "[testphysicalmemoryusage]") { TEST_CASE("FileSystemRepository can clear orphan entries") { TestController testController; auto dir = testController.createTempDirectory(); - auto configuration = std::make_shared(); + auto configuration = std::make_shared(); configuration->set(minifi::Configure::nifi_dbcontent_repository_directory_default, dir.string()); { auto content_repo = std::make_shared(); REQUIRE(content_repo->initialize(configuration)); - minifi::ResourceClaim claim(content_repo); + minifi::ResourceClaimImpl claim(content_repo); content_repo->write(claim)->write("hi"); // ensure that the content is not deleted during resource claim destruction content_repo->incrementStreamCount(claim); @@ -99,13 +99,13 @@ TEST_CASE("FileSystemRepository can retry removing entry that previously failed SKIP("Cannot test insufficient permissions with root user"); TestController testController; auto dir = testController.createTempDirectory(); - auto configuration = std::make_shared(); + auto configuration = std::make_shared(); configuration->set(minifi::Configure::nifi_dbcontent_repository_directory_default, dir.string()); auto content_repo = std::make_shared(); REQUIRE(content_repo->initialize(configuration)); { - minifi::ResourceClaim claim(content_repo); + minifi::ResourceClaimImpl claim(content_repo); content_repo->write(claim)->write("hi"); auto files = minifi::utils::file::list_dir_all(dir, testController.getLogger()); REQUIRE(files.size() == 1); @@ -116,7 +116,7 @@ TEST_CASE("FileSystemRepository can retry removing entry that previously failed utils::makeFileOrDirectoryWritable(dir); REQUIRE(minifi::utils::file::list_dir_all(dir, testController.getLogger()).size() == 1); { - minifi::ResourceClaim claim(content_repo); + minifi::ResourceClaimImpl claim(content_repo); content_repo->write(claim)->write("hi"); REQUIRE(minifi::utils::file::list_dir_all(dir, testController.getLogger()).size() == 2); } @@ -130,14 +130,14 @@ TEST_CASE("FileSystemRepository removes non-existing resource file from purge li SKIP("Cannot test insufficient permissions with root user"); TestController testController; auto dir = testController.createTempDirectory(); - auto configuration = std::make_shared(); + auto configuration = std::make_shared(); configuration->set(minifi::Configure::nifi_dbcontent_repository_directory_default, dir.string()); auto content_repo = std::make_shared(); REQUIRE(content_repo->initialize(configuration)); std::string filename; { - minifi::ResourceClaim claim(content_repo); + minifi::ResourceClaimImpl claim(content_repo); content_repo->write(claim)->write("hi"); auto files = minifi::utils::file::list_dir_all(dir, testController.getLogger()); REQUIRE(files.size() == 1); @@ -150,7 +150,7 @@ TEST_CASE("FileSystemRepository removes non-existing resource file from purge li REQUIRE(std::filesystem::remove(filename)); REQUIRE(minifi::utils::file::list_dir_all(dir, testController.getLogger()).empty()); { - minifi::ResourceClaim claim(content_repo); + minifi::ResourceClaimImpl claim(content_repo); content_repo->write(claim)->write("hi"); REQUIRE(minifi::utils::file::list_dir_all(dir, testController.getLogger()).size() == 1); } @@ -164,14 +164,14 @@ TEST_CASE("Append Claim") { auto dir = testController.createTempDirectory(); auto content_repo = std::make_shared(); - auto configuration = std::make_shared(); + auto configuration = std::make_shared(); configuration->set(minifi::Configure::nifi_dbcontent_repository_directory_default, dir.string()); REQUIRE(content_repo->initialize(configuration)); const std::string content = "well hello there"; - auto claim = std::make_shared(content_repo); + auto claim = std::make_shared(content_repo); content_repo->write(*claim)->write(as_bytes(std::span(content))); // requesting append before content end fails diff --git a/libminifi/test/unit/FileTriggerTests.cpp b/libminifi/test/unit/FileTriggerTests.cpp index c2132b42f0..9e996f268a 100644 --- a/libminifi/test/unit/FileTriggerTests.cpp +++ b/libminifi/test/unit/FileTriggerTests.cpp @@ -27,7 +27,7 @@ TEST_CASE("Empty file", "[t1]") { minifi::c2::FileUpdateTrigger trigger("test"); - std::shared_ptr configuration = std::make_shared(); + std::shared_ptr configuration = std::make_shared(); trigger.initialize(configuration); REQUIRE(false == trigger.triggered()); @@ -36,7 +36,7 @@ TEST_CASE("Empty file", "[t1]") { TEST_CASE("invalidfile file", "[t2]") { minifi::c2::FileUpdateTrigger trigger("test"); - std::shared_ptr configuration = std::make_shared(); + std::shared_ptr configuration = std::make_shared(); configuration->set(minifi::Configure::nifi_c2_file_watch, "/tmp/blahblahblhalbha"); trigger.initialize(configuration); @@ -54,7 +54,7 @@ TEST_CASE("test valid file no update", "[t3]") { file.close(); minifi::c2::FileUpdateTrigger trigger("test"); - std::shared_ptr configuration = std::make_shared(); + std::shared_ptr configuration = std::make_shared(); configuration->set(minifi::Configure::nifi_c2_file_watch, path.string()); trigger.initialize(configuration); @@ -72,7 +72,7 @@ TEST_CASE("test valid file update", "[t4]") { file.close(); minifi::c2::FileUpdateTrigger trigger("test"); - std::shared_ptr configuration = std::make_shared(); + std::shared_ptr configuration = std::make_shared(); configuration->set(minifi::Configure::nifi_c2_file_watch, path.string()); trigger.initialize(configuration); diff --git a/libminifi/test/unit/FlatMapTests.cpp b/libminifi/test/unit/FlatMapTests.cpp index 5272c7eff4..a862ffe38d 100644 --- a/libminifi/test/unit/FlatMapTests.cpp +++ b/libminifi/test/unit/FlatMapTests.cpp @@ -17,7 +17,7 @@ #include "unit/TestBase.h" #include "unit/Catch.h" -#include "utils/FlatMap.h" +#include "minifi-cpp/utils/FlatMap.h" TEST_CASE("FlatMap operator[]", "[flatmap::subscript]") { diff --git a/libminifi/test/unit/FlowFileQueueSwapTests.cpp b/libminifi/test/unit/FlowFileQueueSwapTests.cpp index 4b53d661c8..d666a74457 100644 --- a/libminifi/test/unit/FlowFileQueueSwapTests.cpp +++ b/libminifi/test/unit/FlowFileQueueSwapTests.cpp @@ -25,7 +25,7 @@ #include "unit/TestUtils.h" #include "unit/Catch.h" #include "unit/ProvenanceTestHelper.h" -#include "../utils/gsl.h" +#include "utils/gsl.h" namespace org::apache::nifi::minifi::test { @@ -56,7 +56,7 @@ class SwappingFlowFileTestRepo : public TestFlowRepository, public minifi::SwapM for (const auto& ff : flow_files) { ids.push_back(minifi::SwappedFlowFile{ff->getUUID(), ff->getPenaltyExpiration()}); minifi::io::BufferStream output; - std::static_pointer_cast(ff)->Serialize(output); + std::dynamic_pointer_cast(ff)->Serialize(output); Put(ff->getUUIDStr().c_str(), reinterpret_cast(output.getBuffer().data()), output.size()); } swap_events_.push_back({Store, ids}); @@ -209,7 +209,7 @@ class SwapTestController : public TestController { void pushAll(std::initializer_list seconds) { for (auto sec : seconds) { - auto ff = std::static_pointer_cast(std::make_shared()); + auto ff = std::static_pointer_cast(std::make_shared()); ff->setPenaltyExpiration(Timepoint{std::chrono::seconds{sec}}); queue_->push(std::move(ff)); } @@ -236,7 +236,7 @@ TEST_CASE("Setting swap threshold sets underlying queue limits", "[SwapTest1]") const size_t min_size = target_size / 2; const size_t max_size = target_size * 3 / 2; - minifi::Connection conn(nullptr, nullptr, ""); + minifi::ConnectionImpl conn(nullptr, nullptr, ""); conn.setSwapThreshold(target_size); REQUIRE(utils::FlowFileQueueTestAccessor::get_min_size_(utils::ConnectionTestAccessor::get_queue_(conn)) == min_size); REQUIRE(utils::FlowFileQueueTestAccessor::get_target_size_(utils::ConnectionTestAccessor::get_queue_(conn)) == target_size); diff --git a/libminifi/test/unit/FlowFileQueueTests.cpp b/libminifi/test/unit/FlowFileQueueTests.cpp index 589575e76a..21d87701ea 100644 --- a/libminifi/test/unit/FlowFileQueueTests.cpp +++ b/libminifi/test/unit/FlowFileQueueTests.cpp @@ -35,7 +35,7 @@ TEST_CASE("After construction, a FlowFileQueue is empty", "[FlowFileQueue]") { TEST_CASE("If a non-penalized flow file is added to the FlowFileQueue, we can pop it", "[FlowFileQueue][pop]") { utils::FlowFileQueue queue; - const auto flow_file = std::make_shared(); + const auto flow_file = std::make_shared(); queue.push(flow_file); REQUIRE_FALSE(queue.empty()); @@ -47,11 +47,11 @@ TEST_CASE("If a non-penalized flow file is added to the FlowFileQueue, we can po TEST_CASE("A flow file can be moved into the FlowFileQueue", "[FlowFileQueue][pop]") { utils::FlowFileQueue queue; - auto penalized_flow_file = std::make_shared(); + auto penalized_flow_file = std::make_shared(); penalized_flow_file->penalize(std::chrono::milliseconds{100}); queue.push(std::move(penalized_flow_file)); - queue.push(std::make_shared()); + queue.push(std::make_shared()); REQUIRE_FALSE(queue.empty()); REQUIRE(queue.size() == 2); @@ -59,11 +59,11 @@ TEST_CASE("A flow file can be moved into the FlowFileQueue", "[FlowFileQueue][po TEST_CASE("If three flow files are added to the FlowFileQueue, we can pop them in FIFO order", "[FlowFileQueue][pop]") { utils::FlowFileQueue queue; - const auto flow_file_1 = std::make_shared(); + const auto flow_file_1 = std::make_shared(); queue.push(flow_file_1); - const auto flow_file_2 = std::make_shared(); + const auto flow_file_2 = std::make_shared(); queue.push(flow_file_2); - const auto flow_file_3 = std::make_shared(); + const auto flow_file_3 = std::make_shared(); queue.push(flow_file_3); REQUIRE(queue.isWorkAvailable()); @@ -77,9 +77,9 @@ TEST_CASE("If three flow files are added to the FlowFileQueue, we can pop them i TEST_CASE("Cannot add flow files in the past preempting others", "[FlowFileQueue][pop]") { utils::FlowFileQueue queue; - const auto flow_file_1 = std::make_shared(); + const auto flow_file_1 = std::make_shared(); queue.push(flow_file_1); - const auto flow_file_2 = std::make_shared(); + const auto flow_file_2 = std::make_shared(); flow_file_2->penalize(std::chrono::seconds{-10}); queue.push(flow_file_2); @@ -105,16 +105,16 @@ class PenaltyHasExpired { TEST_CASE("Penalized flow files are popped from the FlowFileQueue in the order their penalties expire", "[FlowFileQueue][pop]") { utils::FlowFileQueue queue; - const auto flow_file_1 = std::make_shared(); + const auto flow_file_1 = std::make_shared(); flow_file_1->penalize(std::chrono::milliseconds{70}); queue.push(flow_file_1); - const auto flow_file_2 = std::make_shared(); + const auto flow_file_2 = std::make_shared(); flow_file_2->penalize(std::chrono::milliseconds{50}); queue.push(flow_file_2); - const auto flow_file_3 = std::make_shared(); + const auto flow_file_3 = std::make_shared(); flow_file_3->penalize(std::chrono::milliseconds{80}); queue.push(flow_file_3); - const auto flow_file_4 = std::make_shared(); + const auto flow_file_4 = std::make_shared(); flow_file_4->penalize(std::chrono::milliseconds{60}); queue.push(flow_file_4); @@ -141,10 +141,10 @@ TEST_CASE("Penalized flow files are popped from the FlowFileQueue in the order t TEST_CASE("If a penalized then a non-penalized flow file is added to the FlowFileQueue, pop() returns the correct one", "[FlowFileQueue][pop]") { utils::FlowFileQueue queue; - const auto penalized_flow_file = std::make_shared(); + const auto penalized_flow_file = std::make_shared(); penalized_flow_file->penalize(std::chrono::milliseconds{10}); queue.push(penalized_flow_file); - const auto flow_file = std::make_shared(); + const auto flow_file = std::make_shared(); queue.push(flow_file); SECTION("Try popping right away") { @@ -166,10 +166,10 @@ TEST_CASE("If a penalized then a non-penalized flow file is added to the FlowFil TEST_CASE("Force pop on FlowFileQueue returns the flow files, whether penalized or not", "[FlowFileQueue][forcePop]") { utils::FlowFileQueue queue; - const auto penalized_flow_file = std::make_shared(); + const auto penalized_flow_file = std::make_shared(); penalized_flow_file->penalize(std::chrono::milliseconds{10}); queue.push(penalized_flow_file); - const auto flow_file = std::make_shared(); + const auto flow_file = std::make_shared(); queue.push(flow_file); REQUIRE_FALSE(queue.empty()); diff --git a/libminifi/test/unit/FlowFileSerializationTests.cpp b/libminifi/test/unit/FlowFileSerializationTests.cpp index 45059642b1..6d1aa9e1c6 100644 --- a/libminifi/test/unit/FlowFileSerializationTests.cpp +++ b/libminifi/test/unit/FlowFileSerializationTests.cpp @@ -30,7 +30,7 @@ #include "FlowFileRecord.h" std::shared_ptr createEmptyFlowFile() { - auto flowFile = std::make_shared(); + auto flowFile = std::make_shared(); flowFile->removeAttribute(core::SpecialFlowAttribute::FILENAME); return flowFile; } diff --git a/libminifi/test/unit/IdTests.cpp b/libminifi/test/unit/IdTests.cpp index 4a9d3b7765..fa37115356 100644 --- a/libminifi/test/unit/IdTests.cpp +++ b/libminifi/test/unit/IdTests.cpp @@ -39,7 +39,7 @@ TEST_CASE("Test default is time", "[id]") { LogTestController::getInstance().setDebug(); std::shared_ptr generator = utils::IdGenerator::getIdGenerator(); - generator->initialize(std::make_shared()); + generator->initialize(std::make_shared()); REQUIRE(true == LogTestController::getInstance().contains("Using uuid_generate_time implementation for uids.")); LogTestController::getInstance().reset(); @@ -49,7 +49,7 @@ TEST_CASE("Test time", "[id]") { TestController test_controller; LogTestController::getInstance().setDebug(); - std::shared_ptr id_props = std::make_shared(); + std::shared_ptr id_props = std::make_shared(); id_props->set("uid.implementation", "TiMe"); std::shared_ptr generator = utils::IdGenerator::getIdGenerator(); @@ -69,7 +69,7 @@ TEST_CASE("Test Generate Move", "[id]") { TestController test_controller; LogTestController::getInstance().setDebug(); - std::shared_ptr id_props = std::make_shared(); + std::shared_ptr id_props = std::make_shared(); id_props->set("uid.implementation", "TiMe"); std::shared_ptr generator = utils::IdGenerator::getIdGenerator(); @@ -86,7 +86,7 @@ TEST_CASE("Test random", "[id]") { TestController test_controller; LogTestController::getInstance().setDebug(); - std::shared_ptr id_props = std::make_shared(); + std::shared_ptr id_props = std::make_shared(); id_props->set("uid.implementation", "RaNDoM"); std::shared_ptr generator = utils::IdGenerator::getIdGenerator(); @@ -106,7 +106,7 @@ TEST_CASE("Test uuid_default", "[id]") { TestController test_controller; LogTestController::getInstance().setDebug(); - std::shared_ptr id_props = std::make_shared(); + std::shared_ptr id_props = std::make_shared(); id_props->set("uid.implementation", "UUID_default"); std::shared_ptr generator = utils::IdGenerator::getIdGenerator(); @@ -120,7 +120,7 @@ TEST_CASE("Test invalid", "[id]") { TestController test_controller; LogTestController::getInstance().setDebug(); - std::shared_ptr id_props = std::make_shared(); + std::shared_ptr id_props = std::make_shared(); id_props->set("uid.implementation", "InVaLiD"); std::shared_ptr generator = utils::IdGenerator::getIdGenerator(); @@ -134,7 +134,7 @@ TEST_CASE("Test parse", "[id]") { TestController test_controller; LogTestController::getInstance().setDebug(); - std::shared_ptr id_props = std::make_shared(); + std::shared_ptr id_props = std::make_shared(); id_props->set("uid.implementation", "time"); std::shared_ptr generator = utils::IdGenerator::getIdGenerator(); @@ -160,7 +160,7 @@ TEST_CASE("Test parse invalid", "[id]") { TestController test_controller; LogTestController::getInstance().setDebug(); - std::shared_ptr id_props = std::make_shared(); + std::shared_ptr id_props = std::make_shared(); id_props->set("uid.implementation", "time"); std::shared_ptr generator = utils::IdGenerator::getIdGenerator(); @@ -187,7 +187,7 @@ TEST_CASE("Test to_string", "[id]") { TestController test_controller; LogTestController::getInstance().setDebug(); - std::shared_ptr id_props = std::make_shared(); + std::shared_ptr id_props = std::make_shared(); id_props->set("uid.implementation", "time"); std::shared_ptr generator = utils::IdGenerator::getIdGenerator(); @@ -229,7 +229,7 @@ TEST_CASE("Test Hex Device Segment 16 bits correct digits", "[id]") { TestController test_controller; LogTestController::getInstance().setDebug(); - std::shared_ptr id_props = std::make_shared(); + std::shared_ptr id_props = std::make_shared(); id_props->set("uid.implementation", "minifi_uid"); id_props->set("uid.minifi.device.segment", "09aF"); @@ -255,7 +255,7 @@ TEST_CASE("Test Hex Device Segment 16 bits too many digits", "[id]") { TestController test_controller; LogTestController::getInstance().setDebug(); - std::shared_ptr id_props = std::make_shared(); + std::shared_ptr id_props = std::make_shared(); id_props->set("uid.implementation", "minifi_uid"); id_props->set("uid.minifi.device.segment", "09aFee"); @@ -283,7 +283,7 @@ TEST_CASE("Test Hex Device Segment 18 bits", "[id]") { TestController test_controller; LogTestController::getInstance().setDebug(); - std::shared_ptr id_props = std::make_shared(); + std::shared_ptr id_props = std::make_shared(); id_props->set("uid.implementation", "minifi_uid"); id_props->set("uid.minifi.device.segment.bits", "18"); id_props->set("uid.minifi.device.segment", "09aF8"); @@ -317,7 +317,7 @@ TEST_CASE("Collision", "[collision]") { TestController test_controller; LogTestController::getInstance().setDebug(); - std::shared_ptr id_props = std::make_shared(); + std::shared_ptr id_props = std::make_shared(); SECTION("random") { id_props->set("uid.implementation", "random"); } @@ -356,7 +356,7 @@ TEST_CASE("Speed", "[speed]") { TestController test_controller; LogTestController::getInstance().setDebug(); - std::shared_ptr id_props = std::make_shared(); + std::shared_ptr id_props = std::make_shared(); std::string implementation; SECTION("random") { implementation = "random"; diff --git a/libminifi/test/unit/LineByLineInputOutputStreamCallbackTests.cpp b/libminifi/test/unit/LineByLineInputOutputStreamCallbackTests.cpp index 29e6dfac43..2e3ce3c60b 100644 --- a/libminifi/test/unit/LineByLineInputOutputStreamCallbackTests.cpp +++ b/libminifi/test/unit/LineByLineInputOutputStreamCallbackTests.cpp @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include "LineByLineInputOutputStreamCallback.h" +#include "utils/LineByLineInputOutputStreamCallback.h" #include "unit/TestBase.h" #include "unit/Catch.h" diff --git a/libminifi/test/unit/LogMetricsPublisherTests.cpp b/libminifi/test/unit/LogMetricsPublisherTests.cpp index 511113d378..8b5475ac4f 100644 --- a/libminifi/test/unit/LogMetricsPublisherTests.cpp +++ b/libminifi/test/unit/LogMetricsPublisherTests.cpp @@ -33,10 +33,10 @@ namespace org::apache::nifi::minifi::test { class LogPublisherTestFixture { public: LogPublisherTestFixture() - : configuration_(std::make_shared()), + : configuration_(std::make_shared()), provenance_repo_(core::createRepository("provenancerepository", "provenancerepository")), flow_file_repo_(core::createRepository("flowfilerepository", "flowfilerepository")), - response_node_loader_(std::make_shared(configuration_, + response_node_loader_(std::make_shared(configuration_, std::vector>{provenance_repo_, flow_file_repo_}, nullptr)), publisher_("LogMetricsPublisher") { configuration_->setHome(temp_directory_.getPath()); diff --git a/libminifi/test/unit/LoggerTests.cpp b/libminifi/test/unit/LoggerTests.cpp index fc87ee5002..64071818b2 100644 --- a/libminifi/test/unit/LoggerTests.cpp +++ b/libminifi/test/unit/LoggerTests.cpp @@ -25,7 +25,7 @@ #include "unit/Catch.h" #include "core/logging/LoggerConfiguration.h" #include "io/ZlibStream.h" -#include "StreamPipe.h" +#include "io/StreamPipe.h" #include "unit/TestUtils.h" #include "utils/span.h" #include "utils/net/AsioSocketUtils.h" diff --git a/libminifi/test/unit/MetricsPublisherStoreTests.cpp b/libminifi/test/unit/MetricsPublisherStoreTests.cpp index 38131b0af1..e58a4d75f0 100644 --- a/libminifi/test/unit/MetricsPublisherStoreTests.cpp +++ b/libminifi/test/unit/MetricsPublisherStoreTests.cpp @@ -26,9 +26,9 @@ namespace org::apache::nifi::minifi::test { -class FirstDummyMetricsPublisher : public minifi::state::MetricsPublisher { +class FirstDummyMetricsPublisher : public minifi::state::MetricsPublisherImpl { public: - using MetricsPublisher::MetricsPublisher; + using MetricsPublisherImpl::MetricsPublisherImpl; static constexpr const char* Description = "FirstDummyMetricsPublisher"; @@ -36,9 +36,9 @@ class FirstDummyMetricsPublisher : public minifi::state::MetricsPublisher { void loadMetricNodes() override {} }; -class SecondDummyMetricsPublisher : public minifi::state::MetricsPublisher { +class SecondDummyMetricsPublisher : public minifi::state::MetricsPublisherImpl { public: - using MetricsPublisher::MetricsPublisher; + using MetricsPublisherImpl::MetricsPublisherImpl; static constexpr const char* Description = "SecondDummyMetricsPublisher"; @@ -50,7 +50,7 @@ REGISTER_RESOURCE(FirstDummyMetricsPublisher, DescriptionOnly); REGISTER_RESOURCE(SecondDummyMetricsPublisher, DescriptionOnly); TEST_CASE("Test single metrics publisher store", "[MetricsPublisherStore]") { - auto configuration = std::make_shared(); + auto configuration = std::make_shared(); configuration->set(Configuration::nifi_metrics_publisher_class, "FirstDummyMetricsPublisher"); minifi::state::MetricsPublisherStore metrics_publisher_store(configuration, std::vector>{}, nullptr); metrics_publisher_store.initialize(nullptr, nullptr); @@ -59,7 +59,7 @@ TEST_CASE("Test single metrics publisher store", "[MetricsPublisherStore]") { } TEST_CASE("Test multiple metrics publisher stores", "[MetricsPublisherStore]") { - auto configuration = std::make_shared(); + auto configuration = std::make_shared(); configuration->set(Configuration::nifi_metrics_publisher_class, "FirstDummyMetricsPublisher,SecondDummyMetricsPublisher"); minifi::state::MetricsPublisherStore metrics_publisher_store(configuration, std::vector>{}, nullptr); metrics_publisher_store.initialize(nullptr, nullptr); diff --git a/libminifi/test/unit/MetricsTests.cpp b/libminifi/test/unit/MetricsTests.cpp index 16e732c185..a48af63df8 100644 --- a/libminifi/test/unit/MetricsTests.cpp +++ b/libminifi/test/unit/MetricsTests.cpp @@ -27,6 +27,7 @@ #include "unit/ProvenanceTestHelper.h" #include "unit/DummyProcessor.h" #include "range/v3/algorithm/find_if.hpp" +#include "core/ProcessorMetrics.h" using namespace std::literals::chrono_literals; @@ -50,14 +51,14 @@ TEST_CASE("QueueMetricsTestConnections", "[c2m3]") { REQUIRE("QueueMetrics" == metrics.getName()); - std::shared_ptr configuration = std::make_shared(); + std::shared_ptr configuration = std::make_shared(); std::shared_ptr content_repo = std::make_shared(); content_repo->initialize(configuration); std::shared_ptr repo = std::make_shared(); - auto connection = std::make_unique(repo, content_repo, "testconnection"); + auto connection = std::make_unique(repo, content_repo, "testconnection"); connection->setBackpressureThresholdDataSize(1024); connection->setBackpressureThresholdCount(1024); @@ -209,7 +210,7 @@ TEST_CASE("VolatileRepositorymetricsCanBeFull", "[c2m4]") { TEST_CASE("Test on trigger runtime processor metrics", "[ProcessorMetrics]") { DummyProcessor dummy_processor("dummy"); - minifi::core::ProcessorMetrics metrics(dummy_processor); + minifi::core::ProcessorMetricsImpl metrics(dummy_processor); REQUIRE("DummyProcessorMetrics" == metrics.getName()); @@ -248,7 +249,7 @@ TEST_CASE("Test on trigger runtime processor metrics", "[ProcessorMetrics]") { TEST_CASE("Test commit runtime processor metrics", "[ProcessorMetrics]") { DummyProcessor dummy_processor("dummy"); - minifi::core::ProcessorMetrics metrics(dummy_processor); + minifi::core::ProcessorMetricsImpl metrics(dummy_processor); REQUIRE("DummyProcessorMetrics" == metrics.getName()); diff --git a/libminifi/test/unit/NetUtilsTest.cpp b/libminifi/test/unit/NetUtilsTest.cpp index 341a8670d4..c4815a0c28 100644 --- a/libminifi/test/unit/NetUtilsTest.cpp +++ b/libminifi/test/unit/NetUtilsTest.cpp @@ -68,30 +68,30 @@ TEST_CASE("utils::net::getSslContext") { const std::filesystem::path cert_dir = minifi::utils::file::FileUtils::get_executable_dir() / "resources"; - REQUIRE(ssl_context_service->setProperty(minifi::controllers::SSLContextService::CACertificate, (cert_dir / "ca_A.crt").string())); + REQUIRE(ssl_context_service->setProperty(minifi::controllers::SSLContextServiceImpl::CACertificate, (cert_dir / "ca_A.crt").string())); SECTION("Secure") { - REQUIRE(ssl_context_service->setProperty(minifi::controllers::SSLContextService::ClientCertificate, (cert_dir / "alice_by_A.pem").string())); - REQUIRE(ssl_context_service->setProperty(minifi::controllers::SSLContextService::PrivateKey, (cert_dir / "alice.key").string())); + REQUIRE(ssl_context_service->setProperty(minifi::controllers::SSLContextServiceImpl::ClientCertificate, (cert_dir / "alice_by_A.pem").string())); + REQUIRE(ssl_context_service->setProperty(minifi::controllers::SSLContextServiceImpl::PrivateKey, (cert_dir / "alice.key").string())); } SECTION("Secure empty pass") { - REQUIRE(ssl_context_service->setProperty(minifi::controllers::SSLContextService::ClientCertificate, (cert_dir / "alice_by_A.pem").string())); - REQUIRE(ssl_context_service->setProperty(minifi::controllers::SSLContextService::PrivateKey, (cert_dir / "alice.key").string())); - REQUIRE(ssl_context_service->setProperty(minifi::controllers::SSLContextService::Passphrase, (cert_dir / "empty_pass").string())); + REQUIRE(ssl_context_service->setProperty(minifi::controllers::SSLContextServiceImpl::ClientCertificate, (cert_dir / "alice_by_A.pem").string())); + REQUIRE(ssl_context_service->setProperty(minifi::controllers::SSLContextServiceImpl::PrivateKey, (cert_dir / "alice.key").string())); + REQUIRE(ssl_context_service->setProperty(minifi::controllers::SSLContextServiceImpl::Passphrase, (cert_dir / "empty_pass").string())); } SECTION("Secure with file pass") { - REQUIRE(ssl_context_service->setProperty(minifi::controllers::SSLContextService::ClientCertificate, (cert_dir / "alice_by_A.pem").string())); - REQUIRE(ssl_context_service->setProperty(minifi::controllers::SSLContextService::PrivateKey, (cert_dir / "alice_encrypted.key").string())); - REQUIRE(ssl_context_service->setProperty(minifi::controllers::SSLContextService::Passphrase, (cert_dir / "alice_encryption_pass").string())); + REQUIRE(ssl_context_service->setProperty(minifi::controllers::SSLContextServiceImpl::ClientCertificate, (cert_dir / "alice_by_A.pem").string())); + REQUIRE(ssl_context_service->setProperty(minifi::controllers::SSLContextServiceImpl::PrivateKey, (cert_dir / "alice_encrypted.key").string())); + REQUIRE(ssl_context_service->setProperty(minifi::controllers::SSLContextServiceImpl::Passphrase, (cert_dir / "alice_encryption_pass").string())); } SECTION("Secure with pass") { - REQUIRE(ssl_context_service->setProperty(minifi::controllers::SSLContextService::ClientCertificate, (cert_dir / "alice_by_A.pem").string())); - REQUIRE(ssl_context_service->setProperty(minifi::controllers::SSLContextService::PrivateKey, (cert_dir / "alice_encrypted.key").string())); - REQUIRE(ssl_context_service->setProperty(minifi::controllers::SSLContextService::Passphrase, "VsVTmHBzixyA9UfTCttRYXus1oMpIxO6jmDXrNrOp5w")); + REQUIRE(ssl_context_service->setProperty(minifi::controllers::SSLContextServiceImpl::ClientCertificate, (cert_dir / "alice_by_A.pem").string())); + REQUIRE(ssl_context_service->setProperty(minifi::controllers::SSLContextServiceImpl::PrivateKey, (cert_dir / "alice_encrypted.key").string())); + REQUIRE(ssl_context_service->setProperty(minifi::controllers::SSLContextServiceImpl::Passphrase, "VsVTmHBzixyA9UfTCttRYXus1oMpIxO6jmDXrNrOp5w")); } SECTION("Secure with common cert and key file") { - REQUIRE(ssl_context_service->setProperty(minifi::controllers::SSLContextService::ClientCertificate, (cert_dir / "alice_by_A_with_key.pem").string())); - REQUIRE(ssl_context_service->setProperty(minifi::controllers::SSLContextService::CACertificate, (cert_dir / "alice_by_A_with_key.pem").string())); + REQUIRE(ssl_context_service->setProperty(minifi::controllers::SSLContextServiceImpl::ClientCertificate, (cert_dir / "alice_by_A_with_key.pem").string())); + REQUIRE(ssl_context_service->setProperty(minifi::controllers::SSLContextServiceImpl::CACertificate, (cert_dir / "alice_by_A_with_key.pem").string())); } REQUIRE_NOTHROW(plan->finalize()); auto ssl_context = utils::net::getSslContext(*ssl_context_service); @@ -109,9 +109,9 @@ TEST_CASE("utils::net::getSslContext passphrase problems") { const std::filesystem::path cert_dir = minifi::utils::file::FileUtils::get_executable_dir() / "resources"; - REQUIRE(ssl_context_service->setProperty(minifi::controllers::SSLContextService::CACertificate, (cert_dir / "ca_A.crt").string())); - REQUIRE(ssl_context_service->setProperty(minifi::controllers::SSLContextService::ClientCertificate, (cert_dir / "alice_by_A.pem").string())); - REQUIRE(ssl_context_service->setProperty(minifi::controllers::SSLContextService::PrivateKey, (cert_dir / "alice_encrypted.key").string())); + REQUIRE(ssl_context_service->setProperty(minifi::controllers::SSLContextServiceImpl::CACertificate, (cert_dir / "ca_A.crt").string())); + REQUIRE(ssl_context_service->setProperty(minifi::controllers::SSLContextServiceImpl::ClientCertificate, (cert_dir / "alice_by_A.pem").string())); + REQUIRE(ssl_context_service->setProperty(minifi::controllers::SSLContextServiceImpl::PrivateKey, (cert_dir / "alice_encrypted.key").string())); SECTION("Missing passphrase") { REQUIRE_NOTHROW(plan->finalize()); @@ -119,13 +119,13 @@ TEST_CASE("utils::net::getSslContext passphrase problems") { } SECTION("Invalid passphrase") { - REQUIRE(ssl_context_service->setProperty(minifi::controllers::SSLContextService::Passphrase, "not_the_correct_passphrase")); + REQUIRE(ssl_context_service->setProperty(minifi::controllers::SSLContextServiceImpl::Passphrase, "not_the_correct_passphrase")); REQUIRE_NOTHROW(plan->finalize()); REQUIRE_THROWS_WITH(utils::net::getSslContext(*ssl_context_service), "use_private_key_file: bad decrypt (Provider routines)"); } SECTION("Invalid passphrase file") { - REQUIRE(ssl_context_service->setProperty(minifi::controllers::SSLContextService::Passphrase, (cert_dir / "alice_by_B.pem").string())); + REQUIRE(ssl_context_service->setProperty(minifi::controllers::SSLContextServiceImpl::Passphrase, (cert_dir / "alice_by_B.pem").string())); REQUIRE_NOTHROW(plan->finalize()); REQUIRE_THROWS_WITH(utils::net::getSslContext(*ssl_context_service), "use_private_key_file: bad decrypt (Provider routines)"); } @@ -140,8 +140,8 @@ TEST_CASE("utils::net::getSslContext missing CA") { const std::filesystem::path cert_dir = minifi::utils::file::FileUtils::get_executable_dir() / "resources"; - REQUIRE(ssl_context_service->setProperty(minifi::controllers::SSLContextService::ClientCertificate, (cert_dir / "alice_by_A.pem").string())); - REQUIRE(ssl_context_service->setProperty(minifi::controllers::SSLContextService::PrivateKey, (cert_dir / "alice.key").string())); + REQUIRE(ssl_context_service->setProperty(minifi::controllers::SSLContextServiceImpl::ClientCertificate, (cert_dir / "alice_by_A.pem").string())); + REQUIRE(ssl_context_service->setProperty(minifi::controllers::SSLContextServiceImpl::PrivateKey, (cert_dir / "alice.key").string())); REQUIRE_NOTHROW(plan->finalize()); auto ssl_context = utils::net::getSslContext(*ssl_context_service); diff --git a/libminifi/test/unit/NetworkInterfaceInfoTests.cpp b/libminifi/test/unit/NetworkInterfaceInfoTests.cpp index 6c42a4f33d..bb57e294d0 100644 --- a/libminifi/test/unit/NetworkInterfaceInfoTests.cpp +++ b/libminifi/test/unit/NetworkInterfaceInfoTests.cpp @@ -17,7 +17,7 @@ #include "unit/TestBase.h" #include "unit/Catch.h" -#include "utils/NetworkInterfaceInfo.h" +#include "utils/net/NetworkInterfaceInfo.h" namespace utils = org::apache::nifi::minifi::utils; diff --git a/libminifi/test/unit/NetworkPrioritizerServiceTests.cpp b/libminifi/test/unit/NetworkPrioritizerServiceTests.cpp index 91004eb9e9..bcce3c5a5d 100644 --- a/libminifi/test/unit/NetworkPrioritizerServiceTests.cpp +++ b/libminifi/test/unit/NetworkPrioritizerServiceTests.cpp @@ -78,7 +78,7 @@ TEST_CASE("TestPrioritizerOneInterfaceMaxThroughput", "[test3]") { TEST_CASE("TestPriorotizerMultipleInterfaces", "[test4]") { auto clock = std::make_shared(); auto parent_controller = createNetworkPrioritizerService("TestService", clock); - std::shared_ptr configuration = std::make_shared(); + std::shared_ptr configuration = std::make_shared(); parent_controller->initialize(); parent_controller->setProperty(minifi::controllers::NetworkPrioritizerService::VerifyInterfaces, "false"); diff --git a/libminifi/test/unit/OpenTelemetryLogDataModelTests.cpp b/libminifi/test/unit/OpenTelemetryLogDataModelTests.cpp index 1d5bd9f5b1..65b6b4b611 100644 --- a/libminifi/test/unit/OpenTelemetryLogDataModelTests.cpp +++ b/libminifi/test/unit/OpenTelemetryLogDataModelTests.cpp @@ -21,6 +21,8 @@ namespace utils = org::apache::nifi::minifi::utils; +// TODO(mzink) move to extension-utils-tests + TEST_CASE("OpenTelemetryLogDataModel tests", "[testnetworkadapter]") { rapidjson::Document document(rapidjson::kObjectType); utils::OpenTelemetryLogDataModel::appendEventInformation(document, "testevent"); diff --git a/libminifi/test/unit/PayloadParserTests.cpp b/libminifi/test/unit/PayloadParserTests.cpp deleted file mode 100644 index 0a9702bfaa..0000000000 --- a/libminifi/test/unit/PayloadParserTests.cpp +++ /dev/null @@ -1,116 +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 -#include -#include "c2/C2Payload.h" -#include "c2/PayloadParser.h" -#include "unit/TestBase.h" -#include "unit/Catch.h" - -TEST_CASE("Test Valid Payload", "[tv1]") { - std::string ident = "identifier"; - std::string cheese = "cheese"; - std::string chips = "chips"; - minifi::c2::C2Payload payload(minifi::c2::Operation::acknowledge, ident); - minifi::c2::C2Payload payload2(minifi::c2::Operation::acknowledge, minifi::state::UpdateState::FULLY_APPLIED, cheese); - minifi::c2::C2ContentResponse response(minifi::c2::Operation::acknowledge); - response.operation_arguments["type"] = minifi::c2::C2Value{"munster"}; - payload2.addContent(std::move(response)); - payload.addPayload(std::move(payload2)); - payload.addPayload(minifi::c2::C2Payload(minifi::c2::Operation::acknowledge, chips)); - REQUIRE("munster" == minifi::c2::PayloadParser::getInstance(payload).in("cheese").getAs("type")); -} - -TEST_CASE("Test Invalid not found", "[tv2]") { - std::string ident = "identifier"; - std::string cheese = "cheese"; - std::string chips = "chips"; - minifi::c2::C2Payload payload(minifi::c2::Operation::acknowledge, ident); - minifi::c2::C2Payload payload2(minifi::c2::Operation::acknowledge, cheese); - minifi::c2::C2ContentResponse response(minifi::c2::Operation::acknowledge); - response.operation_arguments["typeS"] = minifi::c2::C2Value{"munster"}; - payload2.addContent(std::move(response)); - payload.addPayload(std::move(payload2)); - payload.addPayload(minifi::c2::C2Payload(minifi::c2::Operation::acknowledge, chips)); - REQUIRE_THROWS_AS(minifi::c2::PayloadParser::getInstance(payload).in("cheese").getAs("type"), minifi::c2::PayloadParseException); -} - - -TEST_CASE("Test Invalid coercion", "[tv3]") { - std::string ident = "identifier"; - std::string cheese = "cheese"; - std::string chips = "chips"; - minifi::c2::C2Payload payload(minifi::c2::Operation::acknowledge, ident); - minifi::c2::C2Payload payload2(minifi::c2::Operation::acknowledge, minifi::state::UpdateState::FULLY_APPLIED, cheese); - minifi::c2::C2ContentResponse response(minifi::c2::Operation::acknowledge); - response.operation_arguments["type"] = minifi::c2::C2Value{"munster"}; - payload2.addContent(std::move(response)); - payload.addPayload(std::move(payload2)); - payload.addPayload(minifi::c2::C2Payload(minifi::c2::Operation::acknowledge, chips)); - REQUIRE_THROWS_AS(minifi::c2::PayloadParser::getInstance(payload).in("cheese").getAs("type"), minifi::c2::PayloadParseException); -} - -TEST_CASE("Test Invalid not there", "[tv4]") { - std::string ident = "identifier"; - std::string cheese = "cheese"; - std::string chips = "chips"; - minifi::c2::C2Payload payload(minifi::c2::Operation::acknowledge, ident); - minifi::c2::C2Payload payload2(minifi::c2::Operation::acknowledge, minifi::state::UpdateState::FULLY_APPLIED, cheese); - minifi::c2::C2ContentResponse response(minifi::c2::Operation::acknowledge); - response.operation_arguments["type"] = minifi::c2::C2Value{"munster"}; - payload2.addContent(std::move(response)); - payload.addPayload(std::move(payload2)); - payload.addPayload(minifi::c2::C2Payload(minifi::c2::Operation::acknowledge, chips)); - REQUIRE_THROWS_AS(minifi::c2::PayloadParser::getInstance(payload).in("cheeses").getAs("type"), minifi::c2::PayloadParseException); -} - -TEST_CASE("Test typed conversions", "[tv5]") { - std::string ident = "identifier"; - std::string cheese = "cheese"; - std::string chips = "chips"; - uint64_t size = 233; - bool isvalid = false; - minifi::c2::C2Payload payload(minifi::c2::Operation::acknowledge, ident); - minifi::c2::C2Payload payload2(minifi::c2::Operation::acknowledge, minifi::state::UpdateState::FULLY_APPLIED, cheese); - minifi::c2::C2ContentResponse response(minifi::c2::Operation::acknowledge); - response.operation_arguments["type"] = minifi::c2::C2Value{"munster"}; - response.operation_arguments["isvalid"] = minifi::c2::C2Value{isvalid}; - response.operation_arguments["size"] = minifi::c2::C2Value{size}; - payload2.addContent(std::move(response)); - payload.addPayload(std::move(payload2)); - payload.addPayload(minifi::c2::C2Payload(minifi::c2::Operation::acknowledge, chips)); - REQUIRE("munster" == minifi::c2::PayloadParser::getInstance(payload).in("cheese").getAs("type")); - REQUIRE(233 == minifi::c2::PayloadParser::getInstance(payload).in("cheese").getAs("size")); - REQUIRE(false == minifi::c2::PayloadParser::getInstance(payload).in("cheese").getAs("isvalid")); -} - - -TEST_CASE("Test Invalid not there deep", "[tv6]") { - std::string ident = "identifier"; - std::string cheese = "cheese"; - std::string chips = "chips"; - minifi::c2::C2Payload payload(minifi::c2::Operation::acknowledge, ident); - minifi::c2::C2Payload payload2(minifi::c2::Operation::acknowledge, minifi::state::UpdateState::FULLY_APPLIED, cheese); - minifi::c2::C2ContentResponse response(minifi::c2::Operation::acknowledge); - response.operation_arguments["type"] = minifi::c2::C2Value{"munster"}; - payload2.addContent(std::move(response)); - payload.addPayload(std::move(payload2)); - payload.addPayload(minifi::c2::C2Payload(minifi::c2::Operation::acknowledge, chips)); - REQUIRE_THROWS_AS(minifi::c2::PayloadParser::getInstance(payload).in("chips").getAs("type"), minifi::c2::PayloadParseException); -} diff --git a/libminifi/test/unit/ProcessContextTest.cpp b/libminifi/test/unit/ProcessContextTest.cpp index 8afce50b6f..4aee6813d0 100644 --- a/libminifi/test/unit/ProcessContextTest.cpp +++ b/libminifi/test/unit/ProcessContextTest.cpp @@ -16,7 +16,7 @@ */ #include #include "unit/Catch.h" -#include "ProcessContext.h" +#include "core/ProcessContext.h" #include "core/FlowFile.h" #include "utils/meta/detected.h" diff --git a/libminifi/test/unit/ProcessSessionTests.cpp b/libminifi/test/unit/ProcessSessionTests.cpp index 1ef505c86c..6761e5c19c 100644 --- a/libminifi/test/unit/ProcessSessionTests.cpp +++ b/libminifi/test/unit/ProcessSessionTests.cpp @@ -24,9 +24,10 @@ #include "unit/TestBase.h" #include "unit/Catch.h" #include "unit/ContentRepositoryDependentTests.h" -#include "Processor.h" +#include "core/Processor.h" #include "core/repository/VolatileFlowFileRepository.h" #include "unit/TestUtils.h" +#include "core/repository/FileSystemRepository.h" namespace { @@ -42,7 +43,7 @@ class Fixture { std::shared_ptr test_plan_ = test_controller_.createPlan(plan_config_); minifi::core::Processor* dummy_processor_ = test_plan_->addProcessor("DummyProcessor", "dummyProcessor"); std::shared_ptr context_ = [this] { test_plan_->runNextProcessor(); return test_plan_->getCurrentContext(); }(); - std::unique_ptr process_session_ = std::make_unique(context_); + std::unique_ptr process_session_ = std::make_unique(context_); }; const minifi::core::Relationship Success{"success", "everything is fine"}; @@ -144,7 +145,7 @@ class TestVolatileFlowFileRepository : public core::repository::VolatileFlowFile TEST_CASE("ProcessSession::commit avoids dangling ResourceClaims when using VolatileFlowFileRepository", "[incrementbefore]") { TempDirectory tmp_dir; - auto configuration = std::make_shared(); + auto configuration = std::make_shared(); configuration->setHome(tmp_dir.getPath()); configuration->set(minifi::Configure::nifi_volatile_repository_options_flowfile_max_count, "2"); auto ff_repo = std::make_shared("flowfile"); diff --git a/libminifi/test/unit/ProcessorConfigUtilsTests.cpp b/libminifi/test/unit/ProcessorConfigUtilsTests.cpp index 677334f75f..23df09cd2d 100644 --- a/libminifi/test/unit/ProcessorConfigUtilsTests.cpp +++ b/libminifi/test/unit/ProcessorConfigUtilsTests.cpp @@ -17,18 +17,19 @@ #include "unit/TestBase.h" #include "unit/Catch.h" -#include "PropertyDefinition.h" +#include "core/PropertyDefinition.h" #include "core/Processor.h" #include "core/PropertyDefinitionBuilder.h" #include "utils/ProcessorConfigUtils.h" #include "utils/Enum.h" +#include "core/ProcessorNode.h" namespace org::apache::nifi::minifi::core { namespace { -class TestProcessor : public Processor { +class TestProcessor : public ProcessorImpl { public: - using Processor::Processor; + using ProcessorImpl::ProcessorImpl; static constexpr bool SupportsDynamicProperties = false; static constexpr bool SupportsDynamicRelationships = false; @@ -48,7 +49,7 @@ TEST_CASE("Parse enum property") { .build(); auto proc = std::make_shared("test-proc"); proc->setSupportedProperties(std::to_array({prop})); - ProcessContext context(std::make_shared(proc.get()), nullptr, nullptr, nullptr, nullptr, nullptr); + ProcessContextImpl context(std::make_shared(proc.get()), nullptr, nullptr, nullptr, nullptr, nullptr); SECTION("Valid") { proc->setProperty(prop, "B"); const auto val = utils::parseEnumProperty(context, prop); diff --git a/libminifi/test/unit/PropertyValidationTests.cpp b/libminifi/test/unit/PropertyValidationTests.cpp index 933d925bfb..f6f4287d41 100644 --- a/libminifi/test/unit/PropertyValidationTests.cpp +++ b/libminifi/test/unit/PropertyValidationTests.cpp @@ -21,6 +21,7 @@ #include "core/PropertyDefinitionBuilder.h" #include "utils/PropertyErrors.h" #include "core/PropertyType.h" +#include "core/PropertyValue.h" namespace org::apache::nifi::minifi::core { @@ -85,7 +86,7 @@ TEST_CASE("Parsing bool has baggage after") { REQUIRE_THROWS_AS(property.setValue("false almost bool"), utils::internal::ParseException); } -class TestConfigurableComponent : public ConfigurableComponent { +class TestConfigurableComponent : public ConfigurableComponentImpl { public: bool supportsDynamicProperties() const override { return true; diff --git a/libminifi/test/unit/ResourceQueueTests.cpp b/libminifi/test/unit/ResourceQueueTests.cpp index fc9906cdfd..1c05fb4a52 100644 --- a/libminifi/test/unit/ResourceQueueTests.cpp +++ b/libminifi/test/unit/ResourceQueueTests.cpp @@ -19,10 +19,10 @@ #include #include -#include "ResourceQueue.h" +#include "utils/ResourceQueue.h" #include "unit/TestBase.h" #include "unit/Catch.h" -#include "logging/LoggerConfiguration.h" +#include "core/logging/LoggerFactory.h" using namespace std::literals::chrono_literals; diff --git a/libminifi/test/unit/ResponseNodeLoaderTests.cpp b/libminifi/test/unit/ResponseNodeLoaderTests.cpp index a1d9703e13..23accca8e1 100644 --- a/libminifi/test/unit/ResponseNodeLoaderTests.cpp +++ b/libminifi/test/unit/ResponseNodeLoaderTests.cpp @@ -32,7 +32,7 @@ class ResponseNodeLoaderTestFixture { public: ResponseNodeLoaderTestFixture() : root_(std::make_unique(minifi::core::ProcessGroupType::ROOT_PROCESS_GROUP, "root")), - configuration_(std::make_shared()), + configuration_(std::make_shared()), prov_repo_(std::make_shared()), ff_repository_(std::make_shared()), content_repo_(std::make_shared()), @@ -57,7 +57,7 @@ class ResponseNodeLoaderTestFixture { } void addConnection(const std::string& connection_name, const std::string& relationship_name, const minifi::utils::Identifier& src_uuid, const minifi::utils::Identifier& dst_uuid) { - auto connection = std::make_unique(ff_repository_, content_repo_, connection_name); + auto connection = std::make_unique(ff_repository_, content_repo_, connection_name); connection->addRelationship({relationship_name, "d"}); connection->setDestinationUUID(src_uuid); connection->setSourceUUID(dst_uuid); @@ -69,7 +69,7 @@ class ResponseNodeLoaderTestFixture { std::shared_ptr prov_repo_; std::shared_ptr ff_repository_; std::shared_ptr content_repo_; - minifi::state::response::ResponseNodeLoader response_node_loader_; + minifi::state::response::ResponseNodeLoaderImpl response_node_loader_; }; TEST_CASE_METHOD(ResponseNodeLoaderTestFixture, "Load non-existent response node", "[responseNodeLoaderTest]") { diff --git a/libminifi/test/unit/ResponseNodeValueTests.cpp b/libminifi/test/unit/ResponseNodeValueTests.cpp index 42818eb0ec..9f169928d9 100644 --- a/libminifi/test/unit/ResponseNodeValueTests.cpp +++ b/libminifi/test/unit/ResponseNodeValueTests.cpp @@ -17,7 +17,7 @@ */ #include -#include "../../include/core/state/Value.h" +#include "core/state/Value.h" #include "unit/TestBase.h" #include "unit/Catch.h" @@ -27,13 +27,13 @@ using Value = org::apache::nifi::minifi::state::response::Value; template bool canConvertToType(ValueNode value_node) { T conversion_target; - return value_node.getValue()->convertValue(conversion_target); + return value_node.getValue()->getValue(conversion_target); } template bool canConvertToType(ValueNode value_node, const T& expected_result) { T conversion_target; - bool canConvert = value_node.getValue()->convertValue(conversion_target); + bool canConvert = value_node.getValue()->getValue(conversion_target); return canConvert && (expected_result == conversion_target); } diff --git a/libminifi/test/unit/SchedulingAgentTests.cpp b/libminifi/test/unit/SchedulingAgentTests.cpp index 300c889af0..57f706015e 100644 --- a/libminifi/test/unit/SchedulingAgentTests.cpp +++ b/libminifi/test/unit/SchedulingAgentTests.cpp @@ -22,6 +22,7 @@ #include "unit/ProvenanceTestHelper.h" #include "unit/TestUtils.h" #include "utils/TimeUtil.h" +#include "core/ProcessorNode.h" using namespace std::literals::chrono_literals; @@ -29,9 +30,9 @@ namespace org::apache::nifi::minifi::testing { using minifi::core::controller::StandardControllerServiceProvider; -class CountOnTriggersProcessor : public minifi::core::Processor { +class CountOnTriggersProcessor : public minifi::core::ProcessorImpl { public: - using minifi::core::Processor::Processor; + using minifi::core::ProcessorImpl::ProcessorImpl; static constexpr bool SupportsDynamicProperties = false; static constexpr bool SupportsDynamicRelationships = false; @@ -57,6 +58,11 @@ class CountOnTriggersProcessor : public minifi::core::Processor { std::atomic number_of_triggers = 0; }; +#ifdef __GNUC__ +// array-bounds warnings in GCC produce a lot of false positives: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56456 +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Warray-bounds" +#endif class SchedulingAgentTestFixture { public: SchedulingAgentTestFixture() { @@ -65,7 +71,6 @@ class SchedulingAgentTestFixture { #ifdef WIN32 minifi::utils::timeutils::dateSetInstall(TZ_DATA_DIR); - date::set_install(TZ_DATA_DIR); #endif } @@ -76,16 +81,19 @@ class SchedulingAgentTestFixture { TestController test_controller_; std::shared_ptr test_plan = test_controller_.createPlan(); - std::shared_ptr configuration_ = std::make_shared(); + std::shared_ptr configuration_ = std::make_shared(); std::shared_ptr controller_services_provider_ = std::make_shared( std::make_unique(), configuration_); utils::ThreadPool thread_pool_; std::shared_ptr count_proc_ = std::make_shared("count_proc"); - std::shared_ptr node_ = std::make_shared(count_proc_.get()); - std::shared_ptr context_ = std::make_shared(node_, nullptr, test_repo_, test_repo_, content_repo_); - std::shared_ptr factory_ = std::make_shared(context_); + std::shared_ptr node_ = std::make_shared(count_proc_.get()); + std::shared_ptr context_ = std::make_shared(node_, nullptr, test_repo_, test_repo_, content_repo_); + std::shared_ptr factory_ = std::make_shared(context_); }; +#ifdef __GNUC__ +#pragma GCC diagnostic pop +#endif TEST_CASE_METHOD(SchedulingAgentTestFixture, "TimerDrivenSchedulingAgent") { diff --git a/libminifi/test/unit/UpdatePolicyTests.cpp b/libminifi/test/unit/UpdatePolicyTests.cpp index 4a45cf2a34..3a097fb80b 100644 --- a/libminifi/test/unit/UpdatePolicyTests.cpp +++ b/libminifi/test/unit/UpdatePolicyTests.cpp @@ -29,7 +29,7 @@ TEST_CASE("TestEmptyPolicy", "[test1]") { auto controller = std::make_shared("TestService"); - std::shared_ptr configuration = std::make_shared(); + std::shared_ptr configuration = std::make_shared(); controller->initialize(); controller->onEnable(); REQUIRE(false == controller->canUpdate("anyproperty")); @@ -37,7 +37,7 @@ TEST_CASE("TestEmptyPolicy", "[test1]") { TEST_CASE("TestAllowAll", "[test1]") { auto controller = std::make_shared("TestService"); - std::shared_ptr configuration = std::make_shared(); + std::shared_ptr configuration = std::make_shared(); controller->initialize(); controller->setProperty(minifi::controllers::UpdatePolicyControllerService::AllowAllProperties, "true"); controller->onEnable(); @@ -46,7 +46,7 @@ TEST_CASE("TestAllowAll", "[test1]") { TEST_CASE("TestAllowAllFails", "[test1]") { auto controller = std::make_shared("TestService"); - std::shared_ptr configuration = std::make_shared(); + std::shared_ptr configuration = std::make_shared(); controller->initialize(); controller->setProperty(minifi::controllers::UpdatePolicyControllerService::AllowAllProperties, "false"); controller->onEnable(); @@ -55,7 +55,7 @@ TEST_CASE("TestAllowAllFails", "[test1]") { TEST_CASE("TestEnableProperty", "[test1]") { auto controller = std::make_shared("TestService"); - std::shared_ptr configuration = std::make_shared(); + std::shared_ptr configuration = std::make_shared(); controller->initialize(); controller->setProperty(minifi::controllers::UpdatePolicyControllerService::AllowAllProperties, "false"); controller->setProperty(minifi::controllers::UpdatePolicyControllerService::AllowedProperties, "anyproperty"); @@ -65,7 +65,7 @@ TEST_CASE("TestEnableProperty", "[test1]") { TEST_CASE("TestDisableProperty", "[test1]") { auto controller = std::make_shared("TestService"); - std::shared_ptr configuration = std::make_shared(); + std::shared_ptr configuration = std::make_shared(); controller->initialize(); controller->setProperty(minifi::controllers::UpdatePolicyControllerService::AllowAllProperties, "true"); controller->setProperty(minifi::controllers::UpdatePolicyControllerService::DisallowedProperties, "anyproperty"); diff --git a/minifi-api/CMakeLists.txt b/minifi-api/CMakeLists.txt new file mode 100644 index 0000000000..6b2554a3d4 --- /dev/null +++ b/minifi-api/CMakeLists.txt @@ -0,0 +1,3 @@ +add_library(minifi-core INTERFACE) +target_include_directories(minifi-core INTERFACE include) +target_link_libraries(minifi-core INTERFACE gsl-lite) diff --git a/minifi-api/include/minifi-cpp/Connection.h b/minifi-api/include/minifi-cpp/Connection.h new file mode 100644 index 0000000000..3c2e2190a6 --- /dev/null +++ b/minifi-api/include/minifi-cpp/Connection.h @@ -0,0 +1,75 @@ +/** + * @file Connection.h + * Connection class declaration + * + * 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 +#include +#include +#include +#include +#include +#include +#include +#include +#include "core/Core.h" +#include "core/Connectable.h" +#include "core/logging/Logger.h" +#include "core/Relationship.h" +#include "core/FlowFile.h" +#include "core/Repository.h" +#include "minifi-cpp/utils/Literals.h" + +namespace org::apache::nifi::minifi { + +class Connection : public virtual core::Connectable { + public: + ~Connection() override = default; + + static constexpr uint64_t DEFAULT_BACKPRESSURE_THRESHOLD_COUNT = 2000; + static constexpr uint64_t DEFAULT_BACKPRESSURE_THRESHOLD_DATA_SIZE = 100_MB; + + virtual void setSourceUUID(const utils::Identifier &uuid) = 0; + virtual void setDestinationUUID(const utils::Identifier &uuid) = 0; + virtual utils::Identifier getSourceUUID() const = 0; + virtual utils::Identifier getDestinationUUID() const = 0; + virtual void setSource(core::Connectable* source) = 0; + virtual core::Connectable* getSource() const = 0; + virtual void setDestination(core::Connectable* dest) = 0; + virtual core::Connectable* getDestination() const = 0; + virtual void addRelationship(core::Relationship relationship) = 0; + virtual const std::set &getRelationships() const = 0; + virtual void setBackpressureThresholdCount(uint64_t size) = 0; + virtual uint64_t getBackpressureThresholdCount() const = 0; + virtual void setBackpressureThresholdDataSize(uint64_t size) = 0; + virtual uint64_t getBackpressureThresholdDataSize() const = 0; + virtual void setSwapThreshold(uint64_t size) = 0; + virtual void setFlowExpirationDuration(std::chrono::milliseconds duration) = 0; + virtual std::chrono::milliseconds getFlowExpirationDuration() const = 0; + virtual void setDropEmptyFlowFiles(bool drop) = 0; + virtual bool getDropEmptyFlowFiles() const = 0; + virtual bool isEmpty() const = 0; + virtual bool backpressureThresholdReached() const = 0; + virtual uint64_t getQueueSize() const = 0; + virtual uint64_t getQueueDataSize() = 0; + virtual void multiPut(std::vector>& flows) = 0; + virtual std::shared_ptr poll(std::set> &expiredFlowRecords) = 0; + virtual void drain(bool delete_permanently) = 0; +}; +} // namespace org::apache::nifi::minifi diff --git a/libminifi/include/Exception.h b/minifi-api/include/minifi-cpp/Exception.h similarity index 100% rename from libminifi/include/Exception.h rename to minifi-api/include/minifi-cpp/Exception.h diff --git a/minifi-api/include/minifi-cpp/FlowFileRecord.h b/minifi-api/include/minifi-cpp/FlowFileRecord.h new file mode 100644 index 0000000000..87cbbbfcfa --- /dev/null +++ b/minifi-api/include/minifi-cpp/FlowFileRecord.h @@ -0,0 +1,55 @@ +/** + * @file FlowFileRecord.h + * Flow file record class declaration + * + * 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 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "minifi-cpp/core/ContentRepository.h" +#include "minifi-cpp/core/FlowFile.h" +#include "minifi-cpp/core/Repository.h" +#include "io/OutputStream.h" + +namespace org::apache::nifi::minifi { + +class FlowFileRecord : public virtual core::FlowFile { + public: + virtual bool Serialize(io::OutputStream &outStream) = 0; + + //! Serialize and Persistent to the repository + virtual bool Persist(const std::shared_ptr& flowRepository) = 0; + + static std::shared_ptr DeSerialize(std::span buffer, const std::shared_ptr &content_repo, utils::Identifier &container); + static std::shared_ptr DeSerialize(io::InputStream &stream, const std::shared_ptr &content_repo, utils::Identifier &container); + static std::shared_ptr DeSerialize(const std::string& key, const std::shared_ptr& flowRepository, + const std::shared_ptr &content_repo, utils::Identifier &container); + + virtual std::string getContentFullPath() const = 0; +}; + +} // namespace org::apache::nifi::minifi diff --git a/minifi-api/include/minifi-cpp/ResourceClaim.h b/minifi-api/include/minifi-cpp/ResourceClaim.h new file mode 100644 index 0000000000..e0b47797e1 --- /dev/null +++ b/minifi-api/include/minifi-cpp/ResourceClaim.h @@ -0,0 +1,61 @@ +/** + * 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 +#include +#include +#include +#include +#include +#include +#include "core/Core.h" +#include "core/StreamManager.h" +#include "properties/Configure.h" +#include "utils/Id.h" + +namespace org::apache::nifi::minifi { + +namespace core { +class ContentRepository; +} // namespace core + +class ResourceClaim { + public: + using Path = std::string; + + virtual ~ResourceClaim() = default; + virtual void increaseFlowFileRecordOwnedCount() = 0; + virtual void decreaseFlowFileRecordOwnedCount() = 0; + virtual uint64_t getFlowFileRecordOwnedCount() = 0; + virtual Path getContentFullPath() const = 0; + virtual bool exists() = 0; + + static std::shared_ptr create(std::shared_ptr repository); + + virtual std::ostream& write(std::ostream& stream) const = 0; + + friend std::ostream& operator<<(std::ostream& stream, const ResourceClaim& claim) { + return claim.write(stream); + } + + friend std::ostream& operator<<(std::ostream& stream, const std::shared_ptr& claim) { + return claim->write(stream); + } +}; + +} // namespace org::apache::nifi::minifi diff --git a/libminifi/include/SwapManager.h b/minifi-api/include/minifi-cpp/SwapManager.h similarity index 97% rename from libminifi/include/SwapManager.h rename to minifi-api/include/minifi-cpp/SwapManager.h index ed3535dbc0..2137d4d53f 100644 --- a/libminifi/include/SwapManager.h +++ b/minifi-api/include/minifi-cpp/SwapManager.h @@ -21,7 +21,7 @@ #include #include -#include "core/FlowFile.h" +#include "minifi-cpp/core/FlowFile.h" #include "utils/Id.h" namespace org::apache::nifi::minifi { diff --git a/minifi-api/include/minifi-cpp/agent/agent_docs.h b/minifi-api/include/minifi-cpp/agent/agent_docs.h new file mode 100644 index 0000000000..3f961d8eca --- /dev/null +++ b/minifi-api/include/minifi-cpp/agent/agent_docs.h @@ -0,0 +1,71 @@ +/** + * 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 +#include +#include +#include + +#include "minifi-cpp/core/Annotation.h" +#include "minifi-cpp/core/DynamicProperty.h" +#include "minifi-cpp/core/OutputAttributeDefinition.h" +#include "minifi-cpp/core/Property.h" +#include "minifi-cpp/core/Relationship.h" +#include "minifi-cpp/core/RelationshipDefinition.h" + +namespace org::apache::nifi::minifi { + +enum class ResourceType { + Processor, ControllerService, InternalResource, DescriptionOnly +}; + +struct ClassDescription { + ResourceType type_ = ResourceType::Processor; + std::string short_name_{}; + std::string full_name_{}; + std::string description_{}; + std::vector class_properties_{}; + std::span dynamic_properties_{}; + std::vector class_relationships_{}; + std::span output_attributes_{}; + bool supports_dynamic_properties_ = false; + bool supports_dynamic_relationships_ = false; + std::string inputRequirement_{}; + bool isSingleThreaded_ = false; +}; + +struct Components { + std::vector processors_; + std::vector controller_services_; + std::vector other_components_; + + [[nodiscard]] bool empty() const noexcept { + return processors_.empty() && controller_services_.empty() && other_components_.empty(); + } +}; + +class AgentDocs { + public: + static const std::map& getClassDescriptions(); + static std::map& getMutableClassDescriptions(); + + template + static void createClassDescription(const std::string& group, const std::string& name); +}; + +} // namespace org::apache::nifi::minifi diff --git a/libminifi/include/agent/agent_version.h b/minifi-api/include/minifi-cpp/agent/agent_version.h similarity index 83% rename from libminifi/include/agent/agent_version.h rename to minifi-api/include/minifi-cpp/agent/agent_version.h index f1aac9f100..0562a5b382 100644 --- a/libminifi/include/agent/agent_version.h +++ b/minifi-api/include/minifi-cpp/agent/agent_version.h @@ -15,8 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#ifndef LIBMINIFI_INCLUDE_AGENT_AGENT_VERSION_H_ -#define LIBMINIFI_INCLUDE_AGENT_AGENT_VERSION_H_ +#pragma once // The Windows version of pyconfig.h (https://github.com/python/cpython/blob/3.10/PC/pyconfig.h, also on main as of 2022-08-18) // rather unhelpfully #define's COMPILER as the detected compiler version. Since we have a COMPILER variable below, we need to #undef it @@ -25,12 +24,9 @@ #include #include -#include "utils/Export.h" +#include "minifi-cpp/utils/Export.h" -namespace org { -namespace apache { -namespace nifi { -namespace minifi { +namespace org::apache::nifi::minifi { class AgentBuild { public: @@ -44,9 +40,4 @@ class AgentBuild { static std::vector getExtensions(); }; -} // namespace minifi -} // namespace nifi -} // namespace apache -} // namespace org - -#endif // LIBMINIFI_INCLUDE_AGENT_AGENT_VERSION_H_ +} // namespace namespace org::apache::nifi::minifi diff --git a/minifi-api/include/minifi-cpp/agent/build_description.h b/minifi-api/include/minifi-cpp/agent/build_description.h new file mode 100644 index 0000000000..e85f895cbd --- /dev/null +++ b/minifi-api/include/minifi-cpp/agent/build_description.h @@ -0,0 +1,49 @@ +/** + * + * 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 +#include +#include +#include +#include +#include "agent_docs.h" + +namespace org::apache::nifi::minifi { + +struct BundleDetails { + std::string artifact; + std::string group; + std::string version; +}; + +class ExternalBuildDescription { + private: + static std::vector &getExternal(); + + static std::map &getExternalMappings(); + + public: + static void addExternalComponent(const BundleDetails& details, const ClassDescription& description); + + static Components getClassDescriptions(const std::string &group); + + static std::vector getExternalGroups(); +}; + +} // namespace org::apache::nifi::minifi diff --git a/minifi-api/include/minifi-cpp/controllers/AttributeProviderService.h b/minifi-api/include/minifi-cpp/controllers/AttributeProviderService.h new file mode 100644 index 0000000000..b366ddf20f --- /dev/null +++ b/minifi-api/include/minifi-cpp/controllers/AttributeProviderService.h @@ -0,0 +1,35 @@ +/** + * 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 +#include +#include +#include + +#include "minifi-cpp/core/controller/ControllerService.h" + +namespace org::apache::nifi::minifi::controllers { + +class AttributeProviderService : public virtual core::controller::ControllerService { + public: + using AttributeMap = std::unordered_map; + virtual std::optional> getAttributes() = 0; + virtual std::string_view name() const = 0; +}; + +} // namespace org::apache::nifi::minifi::controllers diff --git a/libminifi/include/controllers/RecordSetReader.h b/minifi-api/include/minifi-cpp/controllers/RecordSetReader.h similarity index 86% rename from libminifi/include/controllers/RecordSetReader.h rename to minifi-api/include/minifi-cpp/controllers/RecordSetReader.h index 15f76fe6fe..1c28b4f8b9 100644 --- a/libminifi/include/controllers/RecordSetReader.h +++ b/minifi-api/include/minifi-cpp/controllers/RecordSetReader.h @@ -19,19 +19,17 @@ #include "core/controller/ControllerService.h" -#include "core/FlowFile.h" -#include "core/ProcessSession.h" -#include "Record.h" +#include "minifi-cpp/core/FlowFile.h" +#include "minifi-cpp/core/ProcessSession.h" +#include "minifi-cpp/core/Record.h" #include "utils/Enum.h" #include "utils/ProcessorConfigUtils.h" namespace org::apache::nifi::minifi::core { -class RecordSetReader : public controller::ControllerService { +class RecordSetReader : public virtual controller::ControllerService { public: - using ControllerService::ControllerService; - virtual nonstd::expected read(const std::shared_ptr& flow_file, ProcessSession& session) = 0; }; diff --git a/libminifi/include/controllers/RecordSetWriter.h b/minifi-api/include/minifi-cpp/controllers/RecordSetWriter.h similarity index 80% rename from libminifi/include/controllers/RecordSetWriter.h rename to minifi-api/include/minifi-cpp/controllers/RecordSetWriter.h index 34ee5d87f2..65eecb5b53 100644 --- a/libminifi/include/controllers/RecordSetWriter.h +++ b/minifi-api/include/minifi-cpp/controllers/RecordSetWriter.h @@ -16,18 +16,16 @@ */ #pragma once -#include "core/controller/ControllerService.h" +#include "minifi-cpp/core/controller/ControllerService.h" -#include "core/FlowFile.h" -#include "core/ProcessSession.h" -#include "Record.h" +#include "minifi-cpp/core/FlowFile.h" +#include "minifi-cpp/core/ProcessSession.h" +#include "minifi-cpp/core/Record.h" namespace org::apache::nifi::minifi::core { -class RecordSetWriter : public controller::ControllerService { +class RecordSetWriter : public virtual controller::ControllerService { public: - using ControllerService::ControllerService; - virtual void write(const RecordSet& record_set, const std::shared_ptr& flow_file, ProcessSession& session) = 0; }; diff --git a/minifi-api/include/minifi-cpp/controllers/SSLContextService.h b/minifi-api/include/minifi-cpp/controllers/SSLContextService.h new file mode 100644 index 0000000000..f16ef935e1 --- /dev/null +++ b/minifi-api/include/minifi-cpp/controllers/SSLContextService.h @@ -0,0 +1,50 @@ +/** + * 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 +#include +#include +#include + +#include "minifi-cpp/core/controller/ControllerService.h" + +namespace org::apache::nifi::minifi::controllers { + +/** + * SSLContextService provides a configurable controller service from + * which we can provide an SSL Context or component parts that go + * into creating one. + * + * Justification: Abstracts SSL support out of processors into a + * configurable controller service. + */ +class SSLContextService : public virtual core::controller::ControllerService { + public: + virtual const std::filesystem::path& getCertificateFile() const = 0; + virtual const std::string& getPassphrase() const = 0; + virtual const std::filesystem::path& getPrivateKeyFile() const = 0; + virtual const std::filesystem::path& getCACertificate() const = 0; + + + virtual void setMinTlsVersion(long min_version) = 0; // NOLINT(runtime/int) long due to SSL lib API + + virtual void setMaxTlsVersion(long max_version) = 0; // NOLINT(runtime/int) long due to SSL lib API + virtual bool configure_ssl_context(void* ssl_ctx) = 0; +}; + +} // namespace org::apache::nifi::minifi::controllers diff --git a/minifi-api/include/minifi-cpp/controllers/ThreadManagementService.h b/minifi-api/include/minifi-cpp/controllers/ThreadManagementService.h new file mode 100644 index 0000000000..139e39c051 --- /dev/null +++ b/minifi-api/include/minifi-cpp/controllers/ThreadManagementService.h @@ -0,0 +1,75 @@ +/** + * + * 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 +#include +#include +#include + +#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/controllers/keyvalue/KeyValueStateStorage.h b/minifi-api/include/minifi-cpp/controllers/keyvalue/KeyValueStateStorage.h new file mode 100644 index 0000000000..e3da4e928b --- /dev/null +++ b/minifi-api/include/minifi-cpp/controllers/keyvalue/KeyValueStateStorage.h @@ -0,0 +1,25 @@ +/** + * 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 + +namespace org::apache::nifi::minifi::controllers { + +constexpr const char *ALWAYS_PERSIST_PROPERTY_NAME = "Always Persist"; +constexpr const char *AUTO_PERSISTENCE_INTERVAL_PROPERTY_NAME = "Auto Persistence Interval"; + +} // namespace org::apache::nifi::minifi::controllers diff --git a/libminifi/include/core/AgentIdentificationProvider.h b/minifi-api/include/minifi-cpp/core/AgentIdentificationProvider.h similarity index 100% rename from libminifi/include/core/AgentIdentificationProvider.h rename to minifi-api/include/minifi-cpp/core/AgentIdentificationProvider.h diff --git a/libminifi/include/core/Annotation.h b/minifi-api/include/minifi-cpp/core/Annotation.h similarity index 100% rename from libminifi/include/core/Annotation.h rename to minifi-api/include/minifi-cpp/core/Annotation.h diff --git a/libminifi/include/core/CachedValueValidator.h b/minifi-api/include/minifi-cpp/core/CachedValueValidator.h similarity index 93% rename from libminifi/include/core/CachedValueValidator.h rename to minifi-api/include/minifi-cpp/core/CachedValueValidator.h index b6f261fa0a..f0e2fd58e7 100644 --- a/libminifi/include/core/CachedValueValidator.h +++ b/minifi-api/include/minifi-cpp/core/CachedValueValidator.h @@ -23,16 +23,20 @@ #include "state/Value.h" #include "ValidationResult.h" +#include "minifi-cpp/utils/gsl.h" namespace org::apache::nifi::minifi::core { class PropertyValue; class PropertyValidator; +template struct Converter; + namespace internal { class CachedValueValidator { friend class core::PropertyValue; + template friend struct core::Converter; public: enum class Result { diff --git a/minifi-api/include/minifi-cpp/core/ClassLoader.h b/minifi-api/include/minifi-cpp/core/ClassLoader.h new file mode 100644 index 0000000000..d1fcac4a0b --- /dev/null +++ b/minifi-api/include/minifi-cpp/core/ClassLoader.h @@ -0,0 +1,103 @@ +/** + * 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 +#include +#include +#include +#include +#include + +#include "Core.h" +#include "ObjectFactory.h" + +namespace org::apache::nifi::minifi::core { + +#define RESOURCE_FAILURE -1 + +#define RESOURCE_SUCCESS 1 + +#ifdef WIN32 +#define RTLD_LAZY 0 +#define RTLD_NOW 0 + +#define RTLD_GLOBAL (1 << 1) +#define RTLD_LOCAL (1 << 2) +#endif + +/** + * Processor class loader that accepts + * a variety of mechanisms to load in shared + * objects. + */ +class ClassLoader { + public: + static ClassLoader &getDefaultClassLoader(); + + /** + * Retrieves a class loader + * @param name name of class loader + * @return class loader reference + */ + virtual ClassLoader& getClassLoader(const std::string& child_name) = 0; + + /** + * Register a class with the give ProcessorFactory + */ + virtual void registerClass(const std::string &clazz, std::unique_ptr factory) = 0; + + virtual void unregisterClass(const std::string& clazz) = 0; + + virtual std::optional getGroupForClass(const std::string &class_name) const = 0; + + virtual std::unique_ptr instantiate(const std::string &class_name, const std::string &name, std::function filter) = 0; + + virtual std::unique_ptr instantiate(const std::string &class_name, const utils::Identifier &uuid, std::function filter) = 0; + + virtual CoreComponent* instantiateRaw(const std::string &class_name, const std::string &name, std::function filter) = 0; + + /** + * Instantiate object based on class_name + * @param class_name class to create + * @param uuid uuid of object + * @return nullptr or object created from class_name definition. + */ + template + std::unique_ptr instantiate(const std::string &class_name, const std::string &name); + + /** + * Instantiate object based on class_name + * @param class_name class to create + * @param uuid uuid of object + * @return nullptr or object created from class_name definition. + */ + template + std::unique_ptr instantiate(const std::string &class_name, const utils::Identifier &uuid); + + /** + * Instantiate object based on class_name + * @param class_name class to create + * @param uuid uuid of object + * @return nullptr or object created from class_name definition. + */ + template + T *instantiateRaw(const std::string &class_name, const std::string &name); +}; + +} // namespace org::apache::nifi::minifi::core diff --git a/minifi-api/include/minifi-cpp/core/ConfigurableComponent.h b/minifi-api/include/minifi-cpp/core/ConfigurableComponent.h new file mode 100644 index 0000000000..4c38e2296d --- /dev/null +++ b/minifi-api/include/minifi-cpp/core/ConfigurableComponent.h @@ -0,0 +1,89 @@ +/** + * 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 +#include + +#include "Core.h" +#include +#include +#include +#include + +#include "logging/Logger.h" +#include "Property.h" +#include "utils/gsl.h" + +namespace org::apache::nifi::minifi::core { + +/** + * Represents a configurable component + * Purpose: Extracts configuration items for all components and localized them + */ +class ConfigurableComponent { + public: + virtual bool getProperty(const std::string& name, uint64_t& value) const = 0; + virtual bool getProperty(const std::string& name, int64_t& value) const = 0; + virtual bool getProperty(const std::string& name, uint32_t& value) const = 0; + virtual bool getProperty(const std::string& name, int& value) const = 0; + virtual bool getProperty(const std::string& name, bool& value) const = 0; + virtual bool getProperty(const std::string& name, double& value) const = 0; + virtual bool getProperty(const std::string& name, std::string& value) const = 0; + + + virtual bool getProperty(const std::string &name, Property &prop) const = 0; + virtual bool setProperty(const std::string& name, const std::string& value) = 0; + virtual bool updateProperty(const std::string &name, const std::string &value) = 0; + virtual bool updateProperty(const PropertyReference& property, std::string_view value) = 0; + virtual bool setProperty(const Property& prop, const std::string& value) = 0; + virtual bool setProperty(const PropertyReference& property, std::string_view value) = 0; + virtual bool setProperty(const Property& prop, PropertyValue &value) = 0; + virtual bool supportsDynamicProperties() const = 0; + virtual bool supportsDynamicRelationships() const = 0; + virtual bool getDynamicProperty(const std::string& name, std::string &value) const = 0; + virtual bool getDynamicProperty(const std::string& name, core::Property &item) const = 0; + virtual bool setDynamicProperty(const std::string& name, const std::string& value) = 0; + virtual bool updateDynamicProperty(const std::string &name, const std::string &value) = 0; + virtual void onPropertyModified(const Property& /*old_property*/, const Property& /*new_property*/) = 0; + virtual void onDynamicPropertyModified(const Property& /*old_property*/, const Property& /*new_property*/) = 0; + virtual std::vector getDynamicPropertyKeys() const = 0; + virtual std::map getProperties() const = 0; + virtual bool isPropertyExplicitlySet(const Property&) const = 0; + virtual bool isPropertyExplicitlySet(const PropertyReference&) const = 0; + virtual ~ConfigurableComponent() = default; + virtual void initialize() = 0; + virtual bool canEdit() = 0; + + template + bool getProperty(const std::string& name, T& value) const; + + template + bool getProperty(const std::string& name, std::optional& value) const; + + template + bool getProperty(const core::PropertyReference& property, T& value) const; + + template requires(std::is_default_constructible_v) + std::optional getProperty(const std::string& property_name) const; + + template requires(std::is_default_constructible_v) + std::optional getProperty(const core::PropertyReference& property) const; +}; + +} // namespace org::apache::nifi::minifi::core diff --git a/minifi-api/include/minifi-cpp/core/Connectable.h b/minifi-api/include/minifi-cpp/core/Connectable.h new file mode 100644 index 0000000000..fb116532b0 --- /dev/null +++ b/minifi-api/include/minifi-cpp/core/Connectable.h @@ -0,0 +1,71 @@ +/** + * 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 +#include +#include +#include +#include +#include +#include +#include + +#include "Core.h" +#include +#include "Relationship.h" +#include "Scheduling.h" +#include "minifi-cpp/core/state/FlowIdentifier.h" +#include "utils/gsl.h" + +namespace org::apache::nifi::minifi::core { + +class FlowFile; + +/** + * Represents the base connectable component + * Purpose: As in NiFi, this represents a connection point and allows the derived + * object to be connected to other connectables. + */ +class Connectable : public virtual CoreComponent { + public: + virtual bool isSupportedRelationship(const Relationship &relationship) = 0; + virtual std::vector getSupportedRelationships() const = 0; + virtual void addAutoTerminatedRelationship(const core::Relationship& relationship) = 0; + virtual void setAutoTerminatedRelationships(std::span relationships) = 0; + virtual bool isAutoTerminated(const Relationship &relationship) = 0; + virtual std::chrono::milliseconds getPenalizationPeriod() const = 0; + virtual std::set getOutGoingConnections(const std::string &relationship) = 0; + virtual void put(const std::shared_ptr& /*flow*/) = 0; + virtual void restore(const std::shared_ptr& file) = 0; + virtual Connectable* getNextIncomingConnection() = 0; + virtual Connectable* pickIncomingConnection() = 0; + virtual bool hasIncomingConnections() const = 0; + virtual uint8_t getMaxConcurrentTasks() const = 0; + virtual void setMaxConcurrentTasks(uint8_t tasks) = 0; + virtual void yield() = 0; + ~Connectable() override = default; + virtual bool isRunning() const = 0; + virtual void waitForWork(std::chrono::milliseconds timeout) = 0; + virtual void notifyWork() = 0; + virtual bool isWorkAvailable() = 0; + virtual void setFlowIdentifier(const std::shared_ptr &version) = 0; + virtual std::shared_ptr getFlowIdentifier() const = 0; +}; + +} // namespace org::apache::nifi::minifi::core diff --git a/minifi-api/include/minifi-cpp/core/ContentRepository.h b/minifi-api/include/minifi-cpp/core/ContentRepository.h new file mode 100644 index 0000000000..ce8b889549 --- /dev/null +++ b/minifi-api/include/minifi-cpp/core/ContentRepository.h @@ -0,0 +1,54 @@ +/** + * + * 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 +#include +#include +#include +#include +#include +#include + +#include "minifi-cpp/properties/Configure.h" +#include "minifi-cpp/ResourceClaim.h" +#include "StreamManager.h" +#include "ContentSession.h" +#include "minifi-cpp/core/RepositoryMetricsSource.h" +#include "core/Core.h" +#include "utils/GeneralUtils.h" + +namespace org::apache::nifi::minifi::core { + +/** + * Content repository definition that extends StreamManager. + */ +class ContentRepository : public virtual core::CoreComponent, public virtual StreamManager, public virtual utils::EnableSharedFromThis, public virtual core::RepositoryMetricsSource { + public: + ~ContentRepository() override = default; + + virtual bool initialize(const std::shared_ptr &configure) = 0; + virtual std::shared_ptr createSession() = 0; + virtual void reset() = 0; + virtual void clearOrphans() = 0; + + virtual void start() = 0; + virtual void stop() = 0; +}; + +} // namespace org::apache::nifi::minifi::core diff --git a/libminifi/include/core/ContentSession.h b/minifi-api/include/minifi-cpp/core/ContentSession.h similarity index 70% rename from libminifi/include/core/ContentSession.h rename to minifi-api/include/minifi-cpp/core/ContentSession.h index 75bf29faf4..a48fb020ea 100644 --- a/libminifi/include/core/ContentSession.h +++ b/minifi-api/include/minifi-cpp/core/ContentSession.h @@ -21,7 +21,7 @@ #include #include #include -#include "ResourceClaim.h" +#include "minifi-cpp/ResourceClaim.h" #include "io/BaseStream.h" namespace org::apache::nifi::minifi::core { @@ -30,20 +30,12 @@ class StreamAppendLock; class ContentRepository; class ContentSession { - struct AppendState { - std::shared_ptr stream; - size_t base_size; - std::unique_ptr lock; - }; - public: - explicit ContentSession(std::shared_ptr repository): repository_(std::move(repository)) {} - virtual std::shared_ptr create() = 0; virtual std::shared_ptr write(const std::shared_ptr& resource_id) = 0; - virtual std::shared_ptr append(const std::shared_ptr& resource_id, size_t offset, const std::function&)>& on_copy); + virtual std::shared_ptr append(const std::shared_ptr& resource_id, size_t offset, const std::function&)>& on_copy) = 0; virtual std::shared_ptr read(const std::shared_ptr& resource_id) = 0; @@ -52,13 +44,6 @@ class ContentSession { virtual void rollback() = 0; virtual ~ContentSession() = default; - - protected: - virtual std::shared_ptr append(const std::shared_ptr& resource_id) = 0; - - // contains aux data on resources that have been appended to - std::map, AppendState> append_state_; - std::shared_ptr repository_; }; } // namespace org::apache::nifi::minifi::core diff --git a/minifi-api/include/minifi-cpp/core/Core.h b/minifi-api/include/minifi-cpp/core/Core.h new file mode 100644 index 0000000000..75d3175369 --- /dev/null +++ b/minifi-api/include/minifi-cpp/core/Core.h @@ -0,0 +1,56 @@ +/** + * + * 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 + +#ifdef WIN32 +// ignore the warning about inheriting via dominance from CoreComponent +#pragma warning(disable : 4250) +#endif + +#include +#include +#include +#include +#include +#include + +#include "utils/ArrayUtils.h" +#include "minifi-cpp/utils/Id.h" +#include "minifi-cpp/properties/Configure.h" +#include "utils/StringUtils.h" + +namespace org::apache::nifi::minifi::core { + +/** + * Base component within MiNiFi + * Purpose: Many objects store a name and UUID, therefore + * the functionality is localized here to avoid duplication + */ +class CoreComponent { + public: + virtual ~CoreComponent() = default; + + [[nodiscard]] virtual std::string getName() const = 0; + virtual void setName(std::string name) = 0; + virtual void setUUID(const utils::Identifier& uuid) = 0; + [[nodiscard]] virtual utils::Identifier getUUID() const = 0; + [[nodiscard]] virtual utils::SmallString<36> getUUIDStr() const = 0; + virtual void configure(const std::shared_ptr& /*configuration*/) = 0; +}; + +} // namespace org::apache::nifi::minifi::core diff --git a/libminifi/include/core/DynamicProperty.h b/minifi-api/include/minifi-cpp/core/DynamicProperty.h similarity index 100% rename from libminifi/include/core/DynamicProperty.h rename to minifi-api/include/minifi-cpp/core/DynamicProperty.h diff --git a/minifi-api/include/minifi-cpp/core/FlowFile.h b/minifi-api/include/minifi-cpp/core/FlowFile.h new file mode 100644 index 0000000000..2e20ad314d --- /dev/null +++ b/minifi-api/include/minifi-cpp/core/FlowFile.h @@ -0,0 +1,102 @@ +/** + * + * 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 +#include +#include +#include +#include +#include +#include +#include + +#include "minifi-cpp/ResourceClaim.h" +#include "Connectable.h" +#include "WeakReference.h" +#include "minifi-cpp/utils/FlatMap.h" + +namespace org::apache::nifi::minifi::core { + +class Connectable; + +class FlowFile : public virtual CoreComponent, public virtual ReferenceContainer { + public: + using AttributeMap = utils::FlatMap; + + virtual void copy(const FlowFile&) = 0; + + [[nodiscard]] virtual std::shared_ptr getResourceClaim() const = 0; + virtual void setResourceClaim(const std::shared_ptr& claim) = 0; + virtual void clearResourceClaim() = 0; + virtual std::shared_ptr getStashClaim(const std::string& key) = 0; + virtual void setStashClaim(const std::string& key, const std::shared_ptr& claim) = 0; + virtual void clearStashClaim(const std::string& key) = 0; + virtual bool hasStashClaim(const std::string& key) = 0; + virtual const std::vector& getlineageIdentifiers() const = 0; + virtual std::vector& getlineageIdentifiers() = 0; + [[nodiscard]] virtual bool isDeleted() const = 0; + virtual void setDeleted(bool deleted) = 0; + [[nodiscard]] virtual std::chrono::system_clock::time_point getEntryDate() const = 0; + [[nodiscard]] virtual std::chrono::system_clock::time_point getEventTime() const = 0; + [[nodiscard]] virtual std::chrono::system_clock::time_point getlineageStartDate() const = 0; + virtual void setLineageStartDate(std::chrono::system_clock::time_point date) = 0; + virtual void setLineageIdentifiers(const std::vector& lineage_Identifiers) = 0; + virtual bool getAttribute(std::string_view key, std::string& value) const = 0; + [[nodiscard]] virtual std::optional getAttribute(std::string_view key) const = 0; + virtual bool updateAttribute(std::string_view key, const std::string& value) = 0; + virtual bool removeAttribute(std::string_view key) = 0; + virtual bool setAttribute(std::string_view key, std::string value) = 0; + [[nodiscard]] virtual std::map getAttributes() const = 0; + virtual AttributeMap *getAttributesPtr() = 0; + virtual bool addAttribute(std::string_view key, const std::string& value) = 0; + virtual void setSize(const uint64_t size) = 0; + [[nodiscard]] virtual uint64_t getSize() const = 0; + virtual void setOffset(const uint64_t offset) = 0; + [[nodiscard]] virtual std::chrono::steady_clock::time_point getPenaltyExpiration() const = 0; + virtual void setPenaltyExpiration(std::chrono::time_point to_be_processed_after) = 0; + [[nodiscard]] virtual uint64_t getOffset() const = 0; + [[nodiscard]] virtual bool isPenalized() const = 0; + [[nodiscard]] virtual uint64_t getId() const = 0; + virtual void setConnection(core::Connectable* connection) = 0; + [[nodiscard]] virtual Connectable* getConnection() const = 0; + virtual void setStoredToRepository(bool storedInRepository) = 0; + [[nodiscard]] virtual bool isStored() const = 0; + + static std::shared_ptr create(); +}; + +struct SpecialFlowAttribute { + MINIFIAPI static constexpr std::string_view PATH = "path"; + MINIFIAPI static constexpr std::string_view ABSOLUTE_PATH = "absolute.path"; + MINIFIAPI static constexpr std::string_view FILENAME = "filename"; + MINIFIAPI static constexpr std::string_view UUID = "uuid"; + MINIFIAPI static constexpr std::string_view priority = "priority"; + MINIFIAPI static constexpr std::string_view MIME_TYPE = "mime.type"; + MINIFIAPI static constexpr std::string_view DISCARD_REASON = "discard.reason"; + MINIFIAPI static constexpr std::string_view ALTERNATE_IDENTIFIER = "alternate.identifier"; + MINIFIAPI static constexpr std::string_view FLOW_ID = "flow.id"; + + static constexpr std::array getSpecialFlowAttributes() { + return { + PATH, ABSOLUTE_PATH, FILENAME, UUID, priority, MIME_TYPE, DISCARD_REASON, ALTERNATE_IDENTIFIER, FLOW_ID + }; + } +}; + +} // namespace org::apache::nifi::minifi::core diff --git a/minifi-api/include/minifi-cpp/core/ObjectFactory.h b/minifi-api/include/minifi-cpp/core/ObjectFactory.h new file mode 100644 index 0000000000..9f247b2a2a --- /dev/null +++ b/minifi-api/include/minifi-cpp/core/ObjectFactory.h @@ -0,0 +1,39 @@ +/** + * 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 +#include +#include +#include "Core.h" + +namespace org::apache::nifi::minifi::core { + +class ObjectFactory { + public: + virtual std::unique_ptr create(const std::string& /*name*/) = 0; + virtual CoreComponent *createRaw(const std::string& /*name*/) = 0; + virtual std::unique_ptr create(const std::string& /*name*/, const utils::Identifier& /*uuid*/) = 0; + virtual CoreComponent* createRaw(const std::string& /*name*/, const utils::Identifier& /*uuid*/) = 0; + virtual std::string getGroupName() const = 0; + virtual std::string getClassName() = 0; + + virtual ~ObjectFactory() = default; +}; + +} // namespace org::apache::nifi::minifi::core diff --git a/libminifi/include/core/OutputAttributeDefinition.h b/minifi-api/include/minifi-cpp/core/OutputAttributeDefinition.h similarity index 100% rename from libminifi/include/core/OutputAttributeDefinition.h rename to minifi-api/include/minifi-cpp/core/OutputAttributeDefinition.h diff --git a/minifi-api/include/minifi-cpp/core/ParameterContext.h b/minifi-api/include/minifi-cpp/core/ParameterContext.h new file mode 100644 index 0000000000..1b795414cf --- /dev/null +++ b/minifi-api/include/minifi-cpp/core/ParameterContext.h @@ -0,0 +1,66 @@ +/** + * + * 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 +#include +#include + +#include "Core.h" +#include "Exception.h" + +namespace org::apache::nifi::minifi::core { + +class ParameterException : public Exception { + public: + explicit ParameterException(const std::string& message) : Exception(ExceptionType::PARAMETER_EXCEPTION, message) {} + explicit ParameterException(const char* message) : Exception(ExceptionType::PARAMETER_EXCEPTION, message) {} +}; + +struct Parameter { + std::string name; + std::string description; + bool sensitive = false; + std::string value; +}; + +class ParameterContext : public CoreComponent { + public: + using CoreComponent::CoreComponent; + + void setDescription(const std::string &description) { + description_ = description; + } + + std::string getDescription() const { + return description_; + } + + void addParameter(const Parameter ¶meter); + std::optional getParameter(const std::string &name) const; + const std::unordered_map& getParameters() const { + return parameters_; + } + + private: + std::string description_; + std::unordered_map parameters_; +}; + +} // 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 new file mode 100644 index 0000000000..a7c3027880 --- /dev/null +++ b/minifi-api/include/minifi-cpp/core/ProcessContext.h @@ -0,0 +1,84 @@ +/** + * 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 +#include +#include +#include + +#include "minifi-cpp/core/Core.h" +#include "minifi-cpp/core/ContentRepository.h" +#include "minifi-cpp/core/controller/ControllerService.h" +#include "minifi-cpp/core/ProcessorNode.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" + +namespace org::apache::nifi::minifi::core { + +namespace detail { +template +concept NotAFlowFile = !std::convertible_to && !std::convertible_to &>; +} // namespace detail + +class ProcessContext : public virtual core::VariableRegistry, public virtual utils::EnableSharedFromThis { + public: + virtual std::shared_ptr getProcessorNode() const = 0; + virtual std::optional getProperty(const Property&, const FlowFile* const) = 0; + virtual std::optional getProperty(const PropertyReference&, const FlowFile* const) = 0; + virtual bool getProperty(const Property &property, std::string &value, const FlowFile* const) = 0; + virtual bool getProperty(const PropertyReference& property, std::string &value, const FlowFile* const) = 0; + virtual bool getDynamicProperty(const std::string &name, std::string &value) const = 0; + virtual bool getDynamicProperty(const Property &property, std::string &value, const FlowFile* const) = 0; + virtual std::vector getDynamicPropertyKeys() const = 0; + virtual bool setProperty(const std::string &name, std::string value) = 0; + virtual bool setDynamicProperty(const std::string &name, std::string value) = 0; + virtual bool setProperty(const Property& property, std::string value) = 0; + virtual bool setProperty(const PropertyReference& property, std::string_view value) = 0; + virtual bool isAutoTerminated(Relationship relationship) const = 0; + virtual uint8_t getMaxConcurrentTasks() const = 0; + virtual void yield() = 0; + virtual std::shared_ptr getProvenanceRepository() = 0; + virtual std::shared_ptr getContentRepository() const = 0; + virtual std::shared_ptr getFlowFileRepository() const = 0; + virtual void initializeContentRepository(const std::string& home) = 0; + virtual bool isInitialized() const = 0; + + virtual std::shared_ptr getControllerService(const std::string &identifier, const utils::Identifier &processor_uuid) const = 0; + static constexpr char const* DefaultStateStorageName = "defaultstatestorage"; + + virtual StateManager* getStateManager() = 0; + virtual bool hasStateManager() const = 0; + virtual std::shared_ptr getConfiguration() const = 0; + + + + template + std::optional getProperty(const Property& property) const; + + template + std::optional getProperty(const PropertyReference& property) const; + + bool getProperty(std::string_view name, detail::NotAFlowFile auto& value) const; + + bool getProperty(const PropertyReference& property, detail::NotAFlowFile auto& value) const; +}; + +} // namespace org::apache::nifi::minifi::core diff --git a/minifi-api/include/minifi-cpp/core/ProcessContextBuilder.h b/minifi-api/include/minifi-cpp/core/ProcessContextBuilder.h new file mode 100644 index 0000000000..70adfc0c97 --- /dev/null +++ b/minifi-api/include/minifi-cpp/core/ProcessContextBuilder.h @@ -0,0 +1,47 @@ +/** + * 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 +#include "minifi-cpp/core/Core.h" +#include "core/ContentRepository.h" +#include "minifi-cpp/properties/Configure.h" +#include "minifi-cpp/core/controller/ControllerServiceProvider.h" +#include "ProcessContext.h" +#include "ProcessorNode.h" +#include "minifi-cpp/core/Repository.h" + +namespace org::apache::nifi::minifi::core { +/** + * Could use instantiate from core, which uses a simple compile time check to figure out if a destructor is defined + * and thus that will allow us to know if the context instance exists, but I like using the build because it allows us + * to eventually share the builder across different contexts and shares up the construction ever so slightly. + * + * While this incurs a tiny cost to look up, it allows us to have a replaceable builder that erases the type we are + * constructing. + */ +class ProcessContextBuilder : public virtual core::CoreComponent, public virtual utils::EnableSharedFromThis { + public: + virtual std::shared_ptr withProvider(core::controller::ControllerServiceProvider* controller_service_provider) = 0; + virtual std::shared_ptr withProvenanceRepository(const std::shared_ptr &repo) = 0; + virtual std::shared_ptr withFlowFileRepository(const std::shared_ptr &repo) = 0; + virtual std::shared_ptr withContentRepository(const std::shared_ptr &repo) = 0; + virtual std::shared_ptr withConfiguration(const std::shared_ptr &configuration) = 0; + virtual std::shared_ptr build(const std::shared_ptr &processor) = 0; +}; + +} // namespace org::apache::nifi::minifi::core diff --git a/minifi-api/include/minifi-cpp/core/ProcessSession.h b/minifi-api/include/minifi-cpp/core/ProcessSession.h new file mode 100644 index 0000000000..e19af3b188 --- /dev/null +++ b/minifi-api/include/minifi-cpp/core/ProcessSession.h @@ -0,0 +1,123 @@ +/** + * + * 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 +#include +#include + +#include "FlowFile.h" +#include "minifi-cpp/provenance/Provenance.h" +#include "ProcessorMetrics.h" +#include "minifi-cpp/io/StreamCallback.h" + +namespace org::apache::nifi::minifi::core { + +namespace detail { + +struct ReadBufferResult { + int64_t status; + std::vector buffer; +}; + +} // namespace detail + +// ProcessSession Class +class ProcessSession : public virtual ReferenceContainer { + public: + ~ProcessSession() override = default; + + virtual void commit() = 0; + virtual void rollback() = 0; + + virtual nonstd::expected rollbackNoThrow() noexcept = 0; + virtual std::shared_ptr getProvenanceReporter() = 0; + virtual void flushContent() = 0; + virtual std::shared_ptr get() = 0; + virtual std::shared_ptr create(const core::FlowFile* const parent = nullptr) = 0; + virtual void add(const std::shared_ptr &record) = 0; + virtual std::shared_ptr clone(const core::FlowFile& parent) = 0; + virtual std::shared_ptr clone(const core::FlowFile& parent, int64_t offset, int64_t size) = 0; + virtual void transfer(const std::shared_ptr& flow, const Relationship& relationship) = 0; + virtual void transferToCustomRelationship(const std::shared_ptr& flow, const std::string& relationship_name) = 0; + + virtual void putAttribute(core::FlowFile& flow, std::string_view key, const std::string& value) = 0; + virtual void removeAttribute(core::FlowFile& flow, std::string_view key) = 0; + + virtual void remove(const std::shared_ptr &flow) = 0; + // Access the contents of the flow file as an input stream; returns null if the flow file has no content claim + virtual std::shared_ptr getFlowFileContentStream(const core::FlowFile& flow_file) = 0; + // Execute the given read callback against the content + virtual int64_t read(const std::shared_ptr& flow_file, const io::InputStreamCallback& callback) = 0; + + virtual int64_t read(const core::FlowFile& flow_file, const io::InputStreamCallback& callback) = 0; + // Read content into buffer + virtual detail::ReadBufferResult readBuffer(const std::shared_ptr& flow) = 0; + // Execute the given write callback against the content + virtual void write(const std::shared_ptr &flow, const io::OutputStreamCallback& callback) = 0; + + virtual void write(core::FlowFile& flow, const io::OutputStreamCallback& callback) = 0; + // Read and write the flow file at the same time (eg. for processing it line by line) + virtual int64_t readWrite(const std::shared_ptr &flow, const io::InputOutputStreamCallback& callback) = 0; + // Replace content with buffer + virtual void writeBuffer(const std::shared_ptr& flow_file, std::span buffer) = 0; + virtual void writeBuffer(const std::shared_ptr& flow_file, std::span buffer) = 0; + // Execute the given write/append callback against the content + virtual void append(const std::shared_ptr &flow, const io::OutputStreamCallback& callback) = 0; + // Append buffer to content + virtual void appendBuffer(const std::shared_ptr& flow, std::span buffer) = 0; + virtual void appendBuffer(const std::shared_ptr& flow, std::span buffer) = 0; + // Penalize the flow + virtual void penalize(const std::shared_ptr &flow) = 0; + + virtual bool outgoingConnectionsFull(const std::string& relationship) = 0; + + /** + * Imports a file from the data stream + * @param stream incoming data stream that contains the data to store into a file + * @param flow flow file + */ + virtual void importFrom(io::InputStream &stream, const std::shared_ptr &flow) = 0; + virtual void importFrom(io::InputStream&& stream, const std::shared_ptr &flow) = 0; + + // import from the data source. + virtual void import(const std::string& source, const std::shared_ptr &flow, bool keepSource = true, uint64_t offset = 0) = 0; + + /** + * Exports the data stream to a file + * @param string file to export stream to + * @param flow flow file + * @param bool whether or not to keep the content in the flow file + */ + virtual bool exportContent(const std::string &destination, const std::shared_ptr &flow, bool keepContent) = 0; + + virtual bool exportContent(const std::string &destination, const std::string &tmpFileName, const std::shared_ptr &flow, bool keepContent) = 0; + + // Stash the content to a key + virtual void stash(const std::string &key, const std::shared_ptr &flow) = 0; + // Restore content previously stashed to a key + virtual void restore(const std::string &key, const std::shared_ptr &flow) = 0; + + virtual bool existsFlowFileInRelationship(const Relationship &relationship) = 0; + + virtual void setMetrics(const std::shared_ptr& metrics) = 0; + + virtual bool hasBeenTransferred(const core::FlowFile &flow) const = 0; +}; + +} // namespace org::apache::nifi::minifi::core diff --git a/minifi-api/include/minifi-cpp/core/ProcessSessionFactory.h b/minifi-api/include/minifi-cpp/core/ProcessSessionFactory.h new file mode 100644 index 0000000000..f12f547dc5 --- /dev/null +++ b/minifi-api/include/minifi-cpp/core/ProcessSessionFactory.h @@ -0,0 +1,35 @@ +/** + * @file ProcessSessionFactory.h + * ProcessSessionFactory class declaration + * + * 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 + +#include "ProcessSession.h" + +namespace org::apache::nifi::minifi::core { + +class ProcessSessionFactory { + public: + virtual std::shared_ptr createSession() = 0; + virtual ~ProcessSessionFactory() = default; +}; + +} // namespace org::apache::nifi::minifi::core diff --git a/minifi-api/include/minifi-cpp/core/Processor.h b/minifi-api/include/minifi-cpp/core/Processor.h new file mode 100644 index 0000000000..092df14261 --- /dev/null +++ b/minifi-api/include/minifi-cpp/core/Processor.h @@ -0,0 +1,92 @@ +/** + * 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 +#include +#include +#include +#include +#include + +#include "ConfigurableComponent.h" +#include "Connectable.h" +#include "minifi-cpp/core/Annotation.h" +#include "Scheduling.h" +#include "minifi-cpp/core/state/nodes/MetricsBase.h" +#include "ProcessorMetrics.h" +#include "utils/gsl.h" + +namespace org::apache::nifi::minifi { + +class Connection; + +namespace core { + +class ProcessContext; +class ProcessSession; +class ProcessSessionFactory; + +class Processor : public virtual Connectable, public virtual ConfigurableComponent, public virtual state::response::ResponseNodeSource { + public: + ~Processor() override = default; + + virtual void setScheduledState(ScheduledState state) = 0; + virtual ScheduledState getScheduledState() const = 0; + virtual void setSchedulingStrategy(SchedulingStrategy strategy) = 0; + virtual SchedulingStrategy getSchedulingStrategy() const = 0; + virtual void setSchedulingPeriod(std::chrono::steady_clock::duration period) = 0; + virtual std::chrono::steady_clock::duration getSchedulingPeriod() const = 0; + virtual void setCronPeriod(const std::string &period) = 0; + virtual std::string getCronPeriod() const = 0; + virtual void setRunDurationNano(std::chrono::steady_clock::duration period) = 0; + virtual std::chrono::steady_clock::duration getRunDurationNano() const = 0; + virtual void setYieldPeriodMsec(std::chrono::milliseconds period) = 0; + virtual std::chrono::steady_clock::duration getYieldPeriod() const = 0; + virtual void setPenalizationPeriod(std::chrono::milliseconds period) = 0; + virtual bool isSingleThreaded() const = 0; + virtual std::string getProcessorType() const = 0; + virtual void setTriggerWhenEmpty(bool value) = 0; + virtual bool getTriggerWhenEmpty() const = 0; + virtual uint8_t getActiveTasks() const = 0; + virtual void incrementActiveTasks() = 0; + virtual void decrementActiveTask() = 0; + virtual void clearActiveTask() = 0; + using Connectable::yield; + virtual void yield(std::chrono::steady_clock::duration delta_time) = 0; + virtual bool isYield() = 0; + virtual void clearYield() = 0; + virtual std::chrono::steady_clock::time_point getYieldExpirationTime() const = 0; + virtual std::chrono::steady_clock::duration getYieldTime() const = 0; + virtual bool flowFilesOutGoingFull() const = 0; + virtual bool addConnection(Connectable* connection) = 0; + virtual void triggerAndCommit(const std::shared_ptr& context, const std::shared_ptr& session_factory) = 0; + virtual void trigger(const std::shared_ptr& context, const std::shared_ptr& process_session) = 0; + virtual void onTrigger(ProcessContext&, ProcessSession&) = 0; + virtual void onSchedule(ProcessContext&, ProcessSessionFactory&) = 0; + virtual void onUnSchedule() = 0; + virtual bool isThrottledByBackpressure() const = 0; + virtual void validateAnnotations() const = 0; + virtual annotation::Input getInputRequirement() const = 0; + virtual gsl::not_null> getMetrics() const = 0; + + virtual void updateReachability(const std::lock_guard& graph_lock, bool force = false) = 0; + virtual const std::unordered_map>& reachable_processors() const = 0; +}; + +} // namespace core +} // namespace org::apache::nifi::minifi diff --git a/minifi-api/include/minifi-cpp/core/ProcessorConfig.h b/minifi-api/include/minifi-cpp/core/ProcessorConfig.h new file mode 100644 index 0000000000..0a943ed1a1 --- /dev/null +++ b/minifi-api/include/minifi-cpp/core/ProcessorConfig.h @@ -0,0 +1,50 @@ +/** + * 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 +#include +#include + +#include "Property.h" + +namespace org::apache::nifi::minifi::core { + +constexpr const char* DEFAULT_SCHEDULING_STRATEGY{"TIMER_DRIVEN"}; +constexpr const char* DEFAULT_SCHEDULING_PERIOD_STR{"1 sec"}; +constexpr std::chrono::milliseconds DEFAULT_SCHEDULING_PERIOD_MILLIS{1000}; +constexpr std::chrono::nanoseconds DEFAULT_RUN_DURATION{0}; +constexpr int DEFAULT_MAX_CONCURRENT_TASKS{1}; +constexpr std::chrono::seconds DEFAULT_YIELD_PERIOD_SECONDS{1}; +constexpr std::chrono::seconds DEFAULT_PENALIZATION_PERIOD{30}; + +struct ProcessorConfig { + std::string id; + std::string name; + std::string javaClass; + std::string maxConcurrentTasks; + std::string schedulingStrategy; + std::string schedulingPeriod; + std::string penalizationPeriod; + std::string yieldPeriod; + std::string runDurationNanos; + std::vector autoTerminatedRelationships; + std::vector properties; + std::string parameterContextName; +}; + +} // namespace org::apache::nifi::minifi::core diff --git a/minifi-api/include/minifi-cpp/core/ProcessorMetrics.h b/minifi-api/include/minifi-cpp/core/ProcessorMetrics.h new file mode 100644 index 0000000000..b1e1dda43a --- /dev/null +++ b/minifi-api/include/minifi-cpp/core/ProcessorMetrics.h @@ -0,0 +1,47 @@ +/** + * 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 +#include +#include + +#include "minifi-cpp/core/state/nodes/MetricsBase.h" + +namespace org::apache::nifi::minifi::core { + +class ProcessorMetrics : public virtual state::response::ResponseNode { + public: + virtual void increaseRelationshipTransferCount(const std::string& relationship, size_t count = 1) = 0; + virtual std::chrono::milliseconds getAverageOnTriggerRuntime() const = 0; + virtual std::chrono::milliseconds getLastOnTriggerRuntime() const = 0; + virtual void addLastOnTriggerRuntime(std::chrono::milliseconds runtime) = 0; + + virtual std::chrono::milliseconds getAverageSessionCommitRuntime() const = 0; + virtual std::chrono::milliseconds getLastSessionCommitRuntime() const = 0; + virtual void addLastSessionCommitRuntime(std::chrono::milliseconds runtime) = 0; + + virtual std::atomic& iterations() = 0; + virtual std::atomic& transferredFlowFiles() = 0; + virtual std::atomic& transferredBytes() = 0; + + virtual const std::atomic& iterations() const = 0; + virtual const std::atomic& transferredFlowFiles() const = 0; + virtual const std::atomic& transferredBytes() const = 0; +}; + +} // namespace org::apache::nifi::minifi::core diff --git a/minifi-api/include/minifi-cpp/core/ProcessorNode.h b/minifi-api/include/minifi-cpp/core/ProcessorNode.h new file mode 100644 index 0000000000..06d63f1758 --- /dev/null +++ b/minifi-api/include/minifi-cpp/core/ProcessorNode.h @@ -0,0 +1,49 @@ +/** + * 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 +#include +#include +#include +#include + +#include "ConfigurableComponent.h" +#include "Connectable.h" +#include "Property.h" + +namespace org::apache::nifi::minifi::core { + +class ProcessorNode : public virtual ConfigurableComponent, public virtual Connectable { + public: + virtual Connectable* getProcessor() const = 0; + + using ConfigurableComponent::getProperty; + + template + bool getProperty(const std::string &name, T &value) { + const auto processor_cast = dynamic_cast(getProcessor()); + if (nullptr != processor_cast) { + return processor_cast->getProperty(name, value); + } else { + return ConfigurableComponent::getProperty(name, value); + } + } +}; + +} // namespace org::apache::nifi::minifi::core diff --git a/libminifi/include/core/Property.h b/minifi-api/include/minifi-cpp/core/Property.h similarity index 74% rename from libminifi/include/core/Property.h rename to minifi-api/include/minifi-cpp/core/Property.h index ba30016552..8307747a3e 100644 --- a/libminifi/include/core/Property.h +++ b/minifi-api/include/minifi-cpp/core/Property.h @@ -23,8 +23,9 @@ #include #include -#include "core/PropertyDefinition.h" -#include "core/PropertyValue.h" +#include "PropertyDefinition.h" +#include "PropertyValue.h" +#include "PropertyType.h" #include "range/v3/view/transform.hpp" #include "range/v3/range/conversion.hpp" #include "utils/gsl.h" @@ -40,47 +41,19 @@ class Property { * further overwrites to inherit the bool validator. */ Property(std::string name, std::string description, const std::string& value, bool is_required, std::vector dependent_properties, - std::vector> exclusive_of_properties) - : name_(std::move(name)), - description_(std::move(description)), - is_required_(is_required), - dependent_properties_(std::move(dependent_properties)), - exclusive_of_properties_(std::move(exclusive_of_properties)), - is_collection_(false), - supports_el_(false), - is_transient_(false) { - default_value_ = coerceDefaultValue(value); - } - - Property(std::string name, std::string description, const std::string& value) - : name_(std::move(name)), - description_(std::move(description)), - is_required_(false), - is_collection_(false), - supports_el_(false), - is_transient_(false) { - default_value_ = coerceDefaultValue(value); - } + std::vector> exclusive_of_properties); - Property(std::string name, std::string description) - : name_(std::move(name)), - description_(std::move(description)), - is_required_(false), - is_collection_(true), - supports_el_(false), - is_transient_(false) {} + Property(std::string name, std::string description, const std::string& value); - explicit Property(const PropertyReference& compile_time_property); + Property(std::string name, std::string description); Property(Property &&other) = default; Property(const Property &other) = default; - Property() - : is_required_(false), - is_collection_(false), - supports_el_(false), - is_transient_(false) {} + Property(); + + Property(const PropertyReference&); virtual ~Property() = default; @@ -148,11 +121,10 @@ class Property { void setAllowedValues(gsl::span allowed_values, const core::PropertyParser& property_parser); void addValue(const std::string &value); - Property &operator=(const Property &other) = default; Property &operator=(Property &&other) = default; -// Compare - bool operator <(const Property & right) const; + + bool operator<(const Property & right) const; static bool StringToPermissions(const std::string& input, uint32_t& output) { uint32_t temp = 0U; @@ -194,17 +166,13 @@ class Property { return true; } - // Convert String to Integer template - static bool StringToInt(std::string input, T &output) { - return DataSizeValue::StringToInt(input, output); - } + static bool StringToInt(std::string input, T &output); static bool StringToInt(std::string input, int64_t &output) { return StringToInt(input, output); } -// Convert String to Integer static bool StringToInt(std::string input, uint64_t &output) { return StringToInt(input, output); } @@ -213,28 +181,12 @@ class Property { return StringToInt(input, output); } -// Convert String to Integer static bool StringToInt(std::string input, uint32_t &output) { return StringToInt(input, output); } protected: - /** - * Coerce default values at construction. - */ - PropertyValue coerceDefaultValue(const std::string &value) { - PropertyValue ret; - if (value == "false" || value == "true") { - bool val; - std::istringstream(value) >> std::boolalpha >> val; - ret = val; - validator_ = StandardPropertyTypes::getValidator(ret.getValue()); - } else { - ret = value; - validator_ = gsl::make_not_null(&StandardPropertyTypes::VALID_TYPE); - } - return ret; - } + PropertyValue coerceDefaultValue(const std::string &value); std::string name_; std::string description_; @@ -243,7 +195,7 @@ class Property { std::vector dependent_properties_; std::vector> exclusive_of_properties_; bool is_collection_; - gsl::not_null validator_{&StandardPropertyTypes::VALID_TYPE}; + gsl::not_null validator_; PropertyValue default_value_; std::vector values_; std::string display_name_; diff --git a/libminifi/include/core/PropertyDefinition.h b/minifi-api/include/minifi-cpp/core/PropertyDefinition.h similarity index 88% rename from libminifi/include/core/PropertyDefinition.h rename to minifi-api/include/minifi-cpp/core/PropertyDefinition.h index 7d82e5bb11..57aab5aba9 100644 --- a/libminifi/include/core/PropertyDefinition.h +++ b/minifi-api/include/minifi-cpp/core/PropertyDefinition.h @@ -22,8 +22,7 @@ #include #include -#include "core/Core.h" -#include "core/PropertyType.h" +#include "PropertyType.h" #include "utils/gsl.h" namespace org::apache::nifi::minifi::core { @@ -33,17 +32,17 @@ struct PropertyDefinition { std::string_view name; std::string_view display_name; std::string_view description; - bool is_required = false; - bool is_sensitive = false; + bool is_required; + bool is_sensitive; std::array allowed_values; std::span allowed_types; std::array dependent_properties; std::array, NumExclusiveOfProperties> exclusive_of_properties; std::optional default_value; - gsl::not_null type{gsl::make_not_null(&StandardPropertyTypes::VALID_TYPE)}; - bool supports_expression_language = false; + gsl::not_null type; + bool supports_expression_language; - uint8_t version = 1; + uint8_t version; }; struct PropertyReference { @@ -57,11 +56,9 @@ struct PropertyReference { std::span dependent_properties; std::span> exclusive_of_properties; std::optional default_value; - gsl::not_null type{gsl::make_not_null(&StandardPropertyTypes::VALID_TYPE)}; + gsl::not_null type; bool supports_expression_language = false; - constexpr PropertyReference() = default; - template constexpr PropertyReference(const PropertyDefinition& property_definition) // NOLINT: non-explicit on purpose : name{property_definition.name}, diff --git a/minifi-api/include/minifi-cpp/core/PropertyType.h b/minifi-api/include/minifi-cpp/core/PropertyType.h new file mode 100644 index 0000000000..2f963491c5 --- /dev/null +++ b/minifi-api/include/minifi-cpp/core/PropertyType.h @@ -0,0 +1,54 @@ +/** + * 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 +#include +#include +#include + +#include "minifi-cpp/core/Core.h" +#include "PropertyValue.h" +#include "minifi-cpp/core/state/Value.h" +#include "ValidationResult.h" + +namespace org::apache::nifi::minifi::core { + +class PropertyParser { + public: + virtual constexpr ~PropertyParser() {} // NOLINT can't use = default because of gcc bug: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93413 + + [[nodiscard]] virtual PropertyValue parse(std::string_view input) const = 0; +}; + +class PropertyValidator { + public: + virtual constexpr ~PropertyValidator() {} // NOLINT can't use = default because of gcc bug: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93413 + + [[nodiscard]] virtual std::string_view getValidatorName() const = 0; + + [[nodiscard]] virtual ValidationResult validate(const std::string &subject, const std::shared_ptr &input) const = 0; + + [[nodiscard]] virtual ValidationResult validate(const std::string &subject, const std::string &input) const = 0; +}; + +class PropertyType : public PropertyParser, public PropertyValidator { + public: + virtual constexpr ~PropertyType() {} // NOLINT can't use = default because of gcc bug: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93413 +}; + +} // namespace org::apache::nifi::minifi::core diff --git a/minifi-api/include/minifi-cpp/core/PropertyValue.h b/minifi-api/include/minifi-cpp/core/PropertyValue.h new file mode 100644 index 0000000000..f757ed71a4 --- /dev/null +++ b/minifi-api/include/minifi-cpp/core/PropertyValue.h @@ -0,0 +1,139 @@ +/** + * + * 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 +#include +#include +#include + +#include "CachedValueValidator.h" +#include "ValidationResult.h" +#include "state/Value.h" +#include "minifi-cpp/utils/PropertyErrors.h" + +namespace org::apache::nifi::minifi::core { + +class PropertyValidator; + +/** + * Purpose and Design: PropertyValue extends ValueNode, bringing with it value_. + * The reason for this is that there are additional features to support validation + * and value translation. + */ +class PropertyValue : public state::response::ValueNode { + using CachedValueValidator = internal::CachedValueValidator; + template friend struct Converter; + + public: + PropertyValue() + : type_id(std::type_index(typeid(std::string))) {} + + PropertyValue(const PropertyValue &o) = default; + PropertyValue(PropertyValue &&o) noexcept = default; + + template + static PropertyValue parse(std::string_view input, const PropertyValidator& validator) { + PropertyValue property_value; + property_value.value_ = std::make_shared(std::string{input}); + property_value.type_id = property_value.value_->getTypeIndex(); + property_value.cached_value_validator_ = validator; + return property_value; + } + + void setValidator(const PropertyValidator& validator) { + cached_value_validator_ = validator; + } + + ValidationResult validate(const std::string &subject) const { + return cached_value_validator_.validate(subject, getValue()); + } + + operator uint64_t() const { + return convertImpl("uint64_t"); + } + + operator int64_t() const { + return convertImpl("int64_t"); + } + + operator uint32_t() const { + return convertImpl("uint32_t"); + } + + operator int() const { + return convertImpl("int"); + } + + operator bool() const { + return convertImpl("bool"); + } + + operator double() const { + return convertImpl("double"); + } + + const char* c_str() const { + if (!isValueUsable()) { + throw utils::internal::InvalidValueException("Cannot convert invalid value"); + } + return value_ ? value_->c_str() : ""; + } + + operator std::string() const { + if (!isValueUsable()) { + throw utils::internal::InvalidValueException("Cannot convert invalid value"); + } + return to_string(); + } + + PropertyValue &operator=(PropertyValue &&o) = default; + PropertyValue &operator=(const PropertyValue &o) = default; + + std::type_index getTypeInfo() const { + return type_id; + } + /** + * Define the representations and eventual storage relationships through + * createValue + */ + template + auto operator=(const T& ref) -> std::enable_if_t, PropertyValue>, PropertyValue&>; + + private: + template + T convertImpl(const char* const type_name) const; + + bool isValueUsable() const { + if (!value_) return false; + return validate("__unknown__").valid; + } + + template + auto WithAssignmentGuard(const std::string& ref, Fn&& functor) -> decltype(std::forward(functor)()); + + protected: + std::type_index type_id; + CachedValueValidator cached_value_validator_; +}; + +inline std::string conditional_conversion(const PropertyValue &v) { + return v.getValue()->getStringValue(); +} + +} // namespace org::apache::nifi::minifi::core diff --git a/libminifi/include/core/Record.h b/minifi-api/include/minifi-cpp/core/Record.h similarity index 100% rename from libminifi/include/core/Record.h rename to minifi-api/include/minifi-cpp/core/Record.h diff --git a/libminifi/include/core/RecordField.h b/minifi-api/include/minifi-cpp/core/RecordField.h similarity index 100% rename from libminifi/include/core/RecordField.h rename to minifi-api/include/minifi-cpp/core/RecordField.h diff --git a/libminifi/include/core/Relationship.h b/minifi-api/include/minifi-cpp/core/Relationship.h similarity index 88% rename from libminifi/include/core/Relationship.h rename to minifi-api/include/minifi-cpp/core/Relationship.h index b78276d4b0..15880bed47 100644 --- a/libminifi/include/core/Relationship.h +++ b/minifi-api/include/minifi-cpp/core/Relationship.h @@ -21,7 +21,6 @@ #include #include - #include "RelationshipDefinition.h" namespace org::apache::nifi::minifi::core { @@ -64,10 +63,3 @@ class Relationship { std::string description_; }; } // namespace org::apache::nifi::minifi::core - -template<> -struct std::hash { - size_t operator()(const org::apache::nifi::minifi::core::Relationship& relationship) const noexcept { - return std::hash{}(relationship.getName()); - } -}; diff --git a/libminifi/include/core/RelationshipDefinition.h b/minifi-api/include/minifi-cpp/core/RelationshipDefinition.h similarity index 100% rename from libminifi/include/core/RelationshipDefinition.h rename to minifi-api/include/minifi-cpp/core/RelationshipDefinition.h diff --git a/minifi-api/include/minifi-cpp/core/Repository.h b/minifi-api/include/minifi-cpp/core/Repository.h new file mode 100644 index 0000000000..9754d23247 --- /dev/null +++ b/minifi-api/include/minifi-cpp/core/Repository.h @@ -0,0 +1,66 @@ +/** + * @file Repository + * Repository class declaration + * + * 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 +#include +#include +#include +#include + +#include "Connectable.h" +#include "ContentRepository.h" +#include "SerializableComponent.h" +#include "RepositoryMetricsSource.h" +#include "minifi-cpp/properties/Configure.h" +#include "core/Core.h" + +namespace org::apache::nifi::minifi::core { + +class Repository : public virtual core::CoreComponent, public virtual core::RepositoryMetricsSource { + public: + virtual bool initialize(const std::shared_ptr &configure) = 0; + virtual bool start() = 0; + virtual bool stop() = 0; + virtual bool isNoop() const = 0; + virtual void flush() = 0; + + virtual bool Put(const std::string& /*key*/, const uint8_t* /*buf*/, size_t /*bufLen*/) = 0; + virtual bool MultiPut(const std::vector>>& /*data*/) = 0; + virtual bool Delete(const std::string& /*key*/) = 0; + virtual bool Delete(const std::shared_ptr& item) = 0; + virtual bool Delete(std::vector> &storedValues) = 0; + + virtual void setConnectionMap(std::map connectionMap) = 0; + + virtual void setContainers(std::map containers) = 0; + + virtual bool Get(const std::string& /*key*/, std::string& /*value*/) = 0; + + virtual bool getElements(std::vector>& /*store*/, size_t& /*max_size*/) = 0; + + virtual bool storeElement(const std::shared_ptr& element) = 0; + + virtual void loadComponent(const std::shared_ptr& /*content_repo*/) = 0; + + virtual std::string getDirectory() const = 0; +}; + +} // namespace org::apache::nifi::minifi::core diff --git a/libminifi/include/core/RepositoryMetricsSource.h b/minifi-api/include/minifi-cpp/core/RepositoryMetricsSource.h similarity index 82% rename from libminifi/include/core/RepositoryMetricsSource.h rename to minifi-api/include/minifi-cpp/core/RepositoryMetricsSource.h index 6c933b7eb8..ca55e461c6 100644 --- a/libminifi/include/core/RepositoryMetricsSource.h +++ b/minifi-api/include/minifi-cpp/core/RepositoryMetricsSource.h @@ -34,22 +34,10 @@ class RepositoryMetricsSource { virtual uint64_t getRepositorySize() const = 0; virtual uint64_t getRepositoryEntryCount() const = 0; virtual std::string getRepositoryName() const = 0; - - virtual uint64_t getMaxRepositorySize() const { - return 0; - } - - virtual bool isFull() const { - return false; - } - - virtual bool isRunning() const { - return true; - } - - virtual std::optional getRocksDbStats() const { - return std::nullopt; - } + virtual uint64_t getMaxRepositorySize() const = 0; + virtual bool isFull() const = 0; + virtual bool isRunning() const = 0; + virtual std::optional getRocksDbStats() const = 0; }; } // namespace org::apache::nifi::minifi::core diff --git a/libminifi/include/core/Scheduling.h b/minifi-api/include/minifi-cpp/core/Scheduling.h similarity index 78% rename from libminifi/include/core/Scheduling.h rename to minifi-api/include/minifi-cpp/core/Scheduling.h index 9a46b6cb7b..34b68e9b8d 100644 --- a/libminifi/include/core/Scheduling.h +++ b/minifi-api/include/minifi-cpp/core/Scheduling.h @@ -15,14 +15,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#ifndef LIBMINIFI_INCLUDE_CORE_SCHEDULING_H_ -#define LIBMINIFI_INCLUDE_CORE_SCHEDULING_H_ +#pragma once -namespace org { -namespace apache { -namespace nifi { -namespace minifi { -namespace core { +namespace org::apache::nifi::minifi::core { /* * Indicates the valid values for the state of a entity @@ -49,9 +44,4 @@ enum SchedulingStrategy { CRON_DRIVEN }; -} // namespace core -} // namespace minifi -} // namespace nifi -} // namespace apache -} // namespace org -#endif // LIBMINIFI_INCLUDE_CORE_SCHEDULING_H_ +} // namespace org::apache::nifi::minifi::core diff --git a/minifi-api/include/minifi-cpp/core/SerializableComponent.h b/minifi-api/include/minifi-cpp/core/SerializableComponent.h new file mode 100644 index 0000000000..0e2652f50a --- /dev/null +++ b/minifi-api/include/minifi-cpp/core/SerializableComponent.h @@ -0,0 +1,38 @@ +/** + * + * 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 +#include + +#include "core/Core.h" +#include "utils/gsl.h" +#include "io/InputStream.h" +#include "io/OutputStream.h" + +namespace org::apache::nifi::minifi::core { + +class SerializableComponent : public virtual core::CoreComponent { + public: + ~SerializableComponent() override = default; + + virtual bool serialize(io::OutputStream& output_stream) = 0; + virtual bool deserialize(io::InputStream &input_stream) = 0; +}; + +} // namespace org::apache::nifi::minifi::core diff --git a/libminifi/include/core/StateManager.h b/minifi-api/include/minifi-cpp/core/StateManager.h similarity index 87% rename from libminifi/include/core/StateManager.h rename to minifi-api/include/minifi-cpp/core/StateManager.h index 89ef8b2cdd..1c30b5cc46 100644 --- a/libminifi/include/core/StateManager.h +++ b/minifi-api/include/minifi-cpp/core/StateManager.h @@ -35,21 +35,10 @@ class StateManager { public: using State = std::unordered_map; - explicit StateManager(const utils::Identifier& id) - : id_(id) { - } - virtual ~StateManager() = default; - virtual bool set(const State& kvs) = 0; virtual bool get(State& kvs) = 0; - - std::optional get() { - if (State out; get(out)) { - return out; - } - return std::nullopt; - } + virtual std::optional get() = 0; virtual bool clear() = 0; virtual bool persist() = 0; @@ -59,9 +48,6 @@ class StateManager { virtual bool beginTransaction() = 0; virtual bool commit() = 0; virtual bool rollback() = 0; - - protected: - utils::Identifier id_; }; } // namespace org::apache::nifi::minifi::core diff --git a/libminifi/include/core/StateStorage.h b/minifi-api/include/minifi-cpp/core/StateStorage.h similarity index 91% rename from libminifi/include/core/StateStorage.h rename to minifi-api/include/minifi-cpp/core/StateStorage.h index 6870b47b92..2ea2c96932 100644 --- a/libminifi/include/core/StateStorage.h +++ b/minifi-api/include/minifi-cpp/core/StateStorage.h @@ -35,9 +35,7 @@ class StateStorage { virtual std::unique_ptr getStateManager(const utils::Identifier& uuid) = 0; - std::unique_ptr getStateManager(const CoreComponent& component) { - return getStateManager(component.getUUID()); - } + virtual std::unique_ptr getStateManager(const CoreComponent& component) = 0; virtual std::unordered_map getAllStates() = 0; }; diff --git a/libminifi/include/core/StreamManager.h b/minifi-api/include/minifi-cpp/core/StreamManager.h similarity index 93% rename from libminifi/include/core/StreamManager.h rename to minifi-api/include/minifi-cpp/core/StreamManager.h index 52ff59e0bb..bedb96d2b8 100644 --- a/libminifi/include/core/StreamManager.h +++ b/minifi-api/include/minifi-cpp/core/StreamManager.h @@ -20,8 +20,8 @@ #include #include -#include "properties/Configure.h" -#include "ResourceClaim.h" +#include "minifi-cpp/properties/Configure.h" +#include "minifi-cpp/ResourceClaim.h" #include "io/BufferStream.h" #include "io/BaseStream.h" @@ -67,12 +67,7 @@ class StreamManager { */ virtual std::shared_ptr read(const T &streamId) = 0; - virtual size_t size(const T &streamId) { - auto stream = read(streamId); - if (!stream) - return 0; - return stream->size(); - } + virtual size_t size(const T &streamId) = 0; /** * Closes the stream diff --git a/minifi-api/include/minifi-cpp/core/ThreadedRepository.h b/minifi-api/include/minifi-cpp/core/ThreadedRepository.h new file mode 100644 index 0000000000..da47ac732d --- /dev/null +++ b/minifi-api/include/minifi-cpp/core/ThreadedRepository.h @@ -0,0 +1,33 @@ +/** + * + * 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 +#include + +#include "Repository.h" +#include "TraceableResource.h" + +namespace org::apache::nifi::minifi::core { + +class ThreadedRepository : public virtual core::Repository, public virtual core::TraceableResource { + public: +}; + +} // namespace org::apache::nifi::minifi::core diff --git a/libminifi/include/core/TraceableResource.h b/minifi-api/include/minifi-cpp/core/TraceableResource.h similarity index 90% rename from libminifi/include/core/TraceableResource.h rename to minifi-api/include/minifi-cpp/core/TraceableResource.h index c52b209401..805ee51a96 100644 --- a/libminifi/include/core/TraceableResource.h +++ b/minifi-api/include/minifi-cpp/core/TraceableResource.h @@ -15,8 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#ifndef LIBMINIFI_INCLUDE_CORE_TRACEABLERESOURCE_H_ -#define LIBMINIFI_INCLUDE_CORE_TRACEABLERESOURCE_H_ +#pragma once #include "utils/BackTrace.h" @@ -48,5 +47,3 @@ class TraceableResource { } // namespace nifi } // namespace apache } // namespace org - -#endif // LIBMINIFI_INCLUDE_CORE_TRACEABLERESOURCE_H_ diff --git a/libminifi/include/core/ValidationResult.h b/minifi-api/include/minifi-cpp/core/ValidationResult.h similarity index 100% rename from libminifi/include/core/ValidationResult.h rename to minifi-api/include/minifi-cpp/core/ValidationResult.h diff --git a/minifi-api/include/minifi-cpp/core/VariableRegistry.h b/minifi-api/include/minifi-cpp/core/VariableRegistry.h new file mode 100644 index 0000000000..1e05af505b --- /dev/null +++ b/minifi-api/include/minifi-cpp/core/VariableRegistry.h @@ -0,0 +1,37 @@ +/** + * + * 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 +#include +#include +#include "minifi-cpp/properties/Configure.h" +#include "utils/StringUtils.h" + +namespace org::apache::nifi::minifi::core { + +/** + * Defines a base variable registry for minifi agents. + */ +class VariableRegistry { + public: + virtual ~VariableRegistry() = default; + virtual bool getConfigurationProperty(const std::string &property, std::string &value) const = 0; +}; + +} // namespace org::apache::nifi::minifi::core diff --git a/minifi-api/include/minifi-cpp/core/WeakReference.h b/minifi-api/include/minifi-cpp/core/WeakReference.h new file mode 100644 index 0000000000..70cda61a6d --- /dev/null +++ b/minifi-api/include/minifi-cpp/core/WeakReference.h @@ -0,0 +1,52 @@ +/** + * + * 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 +#include + +namespace org::apache::nifi::minifi::core { + +/* + * An homage to weak references in java, this acts as a class + * which can be used to remove referenced classes when needed. + */ +class WeakReference { + public: + virtual ~WeakReference() = default; + virtual void remove() = 0; +}; + +/** + * Reference container is a vector of weak references that enables + * controllers to remove referenced objects as needed. + * + * There is no need to use weak ptrs here, as we do actually want + * the WeakReferences to be referenced counts. The "weak" aspect + * originates from and is defined by the corresponding object. + */ +class ReferenceContainer { + public: + virtual ~ReferenceContainer() = default; + virtual void addReference(std::shared_ptr ref) = 0; + virtual size_t getReferenceCount() = 0; + virtual void removeReferences() = 0; +}; + +} // namespace org::apache::nifi::minifi::core diff --git a/minifi-api/include/minifi-cpp/core/controller/ControllerService.h b/minifi-api/include/minifi-cpp/core/controller/ControllerService.h new file mode 100644 index 0000000000..3260757165 --- /dev/null +++ b/minifi-api/include/minifi-cpp/core/controller/ControllerService.h @@ -0,0 +1,54 @@ +/** + * + * 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 +#include +#include +#include + +#include "minifi-cpp/properties/Configure.h" +#include "minifi-cpp/core/ConfigurableComponent.h" +#include "minifi-cpp/core/Connectable.h" + +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 { + public: + virtual void setConfiguration(const std::shared_ptr &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> &services) = 0; +}; + +} // namespace org::apache::nifi::minifi::core::controller diff --git a/minifi-api/include/minifi-cpp/core/controller/ControllerServiceLookup.h b/minifi-api/include/minifi-cpp/core/controller/ControllerServiceLookup.h new file mode 100644 index 0000000000..89d13baa1f --- /dev/null +++ b/minifi-api/include/minifi-cpp/core/controller/ControllerServiceLookup.h @@ -0,0 +1,79 @@ +/** + * + * 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 +#include +#include +#include "minifi-cpp/core/Core.h" +#include "minifi-cpp/core/ConfigurableComponent.h" +#include "ControllerService.h" + +namespace org::apache::nifi::minifi::core::controller { + +/** + * Controller Service Lookup pure virtual class. + * + * Purpose: Provide a mechanism that controllers can lookup information about + * controller services. + * + */ +class ControllerServiceLookup { + public: + ControllerServiceLookup() = default; + + virtual ~ControllerServiceLookup() = default; + + /** + * Gets the controller service via the provided identifier. This overload returns the controller service in a global scope from all + * available controller services in the flow. + * @param identifier reference string for controller service. + * @return controller service reference. + */ + virtual std::shared_ptr getControllerService(const std::string &identifier) const = 0; + + /** + * Gets the controller service in the scope of the processor via the provided identifier. + * @param identifier reference string for controller service. + * @param processor_uuid uuid of the processor + * @return controller service reference. + */ + virtual std::shared_ptr 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/minifi-api/include/minifi-cpp/core/controller/ControllerServiceNode.h b/minifi-api/include/minifi-cpp/core/controller/ControllerServiceNode.h new file mode 100644 index 0000000000..daabbe38f8 --- /dev/null +++ b/minifi-api/include/minifi-cpp/core/controller/ControllerServiceNode.h @@ -0,0 +1,46 @@ +/** + * + * 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 +#include +#include +#include + +#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 "Exception.h" + +namespace org::apache::nifi::minifi::core::controller { + +class ControllerServiceNode : public virtual CoreComponent, public virtual ConfigurableComponent { + public: + virtual std::shared_ptr getControllerServiceImplementation() = 0; + virtual const ControllerService* getControllerServiceImplementation() const = 0; + virtual const std::vector& getLinkedControllerServices() const = 0; + virtual bool canEnable() = 0; + virtual bool enabled() = 0; + virtual bool enable() = 0; + virtual bool disable() = 0; +}; + +} // 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 new file mode 100644 index 0000000000..4d7a1dd351 --- /dev/null +++ b/minifi-api/include/minifi-cpp/core/controller/ControllerServiceProvider.h @@ -0,0 +1,54 @@ +/** + * + * 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 +#include +#include +#include +#include +#include + +#include "minifi-cpp/core/Core.h" +#include "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 createControllerService(const std::string &type, const std::string &longType, const std::string &id, bool firstTimeAdded) = 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& controller_service_node, ProcessGroup* process_group) = 0; + + virtual void clearControllerServices() = 0; + virtual std::vector> getAllControllerServices() = 0; + virtual void enableAllControllerServices() = 0; + virtual void disableAllControllerServices() = 0; +}; + +} // namespace org::apache::nifi::minifi::core::controller diff --git a/minifi-api/include/minifi-cpp/core/extension/Extension.h b/minifi-api/include/minifi-cpp/core/extension/Extension.h new file mode 100644 index 0000000000..e4ff35f597 --- /dev/null +++ b/minifi-api/include/minifi-cpp/core/extension/Extension.h @@ -0,0 +1,47 @@ +/** + * 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 +#include +#include + +#include "minifi-cpp/properties/Configure.h" + +namespace org::apache::nifi::minifi::core::extension { + +using ExtensionConfig = std::shared_ptr; + +class Extension { + public: + virtual ~Extension() = default; + + /** + * Ensures that the extension is initialized at most once, and schedules + * an automatic deinitialization on extension unloading. This init/deinit + * is backed by a local static object and sequenced relative to other static + * variable init/deinit (specifically the registration of classes into ClassLoader) + * according to the usual rules. + * @param config + * @return True if the initialization succeeded + */ + virtual bool initialize(const ExtensionConfig& config) = 0; + virtual const std::string& getName() const = 0; +}; + +} // namespace org::apache::nifi::minifi::core::extension diff --git a/minifi-api/include/minifi-cpp/core/extension/ExtensionManager.h b/minifi-api/include/minifi-cpp/core/extension/ExtensionManager.h new file mode 100644 index 0000000000..63936f1d7f --- /dev/null +++ b/minifi-api/include/minifi-cpp/core/extension/ExtensionManager.h @@ -0,0 +1,32 @@ +/** + * 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 "Extension.h" + +namespace org::apache::nifi::minifi::core::extension { + +class ExtensionManager { + public: + static ExtensionManager& get(); + + virtual void registerExtension(Extension& extension) = 0; + virtual void unregisterExtension(Extension& extension) = 0; +}; + +} // namespace org::apache::nifi::minifi::core::extension diff --git a/libminifi/include/core/logging/Logger.h b/minifi-api/include/minifi-cpp/core/logging/Logger.h similarity index 51% rename from libminifi/include/core/logging/Logger.h rename to minifi-api/include/minifi-cpp/core/logging/Logger.h index d3ddac807a..f94a467582 100644 --- a/libminifi/include/core/logging/Logger.h +++ b/minifi-api/include/minifi-cpp/core/logging/Logger.h @@ -27,8 +27,6 @@ #include #include -#include "spdlog/common.h" -#include "spdlog/logger.h" #include "utils/gsl.h" #include "utils/Enum.h" #include "utils/GeneralUtils.h" @@ -38,20 +36,6 @@ namespace org::apache::nifi::minifi::core::logging { -inline constexpr size_t LOG_BUFFER_SIZE = 4096; - -class LoggerControl { - public: - LoggerControl(); - - [[nodiscard]] bool is_enabled() const; - - void setEnabled(bool status); - - protected: - std::atomic is_enabled_; -}; - enum LOG_LEVEL { trace = 0, debug = 1, @@ -62,42 +46,6 @@ enum LOG_LEVEL { off = 6 }; -inline spdlog::level::level_enum mapToSpdLogLevel(LOG_LEVEL level) { - switch (level) { - case trace: return spdlog::level::trace; - case debug: return spdlog::level::debug; - case info: return spdlog::level::info; - case warn: return spdlog::level::warn; - case err: return spdlog::level::err; - case critical: return spdlog::level::critical; - case off: return spdlog::level::off; - } - throw std::invalid_argument(fmt::format("Invalid LOG_LEVEL {}", magic_enum::enum_underlying(level))); -} - -inline LOG_LEVEL mapFromSpdLogLevel(spdlog::level::level_enum level) { - switch (level) { - case spdlog::level::trace: return LOG_LEVEL::trace; - case spdlog::level::debug: return LOG_LEVEL::debug; - case spdlog::level::info: return LOG_LEVEL::info; - case spdlog::level::warn: return LOG_LEVEL::warn; - case spdlog::level::err: return LOG_LEVEL::err; - case spdlog::level::critical: return LOG_LEVEL::critical; - case spdlog::level::off: return LOG_LEVEL::off; - case spdlog::level::n_levels: break; - } - throw std::invalid_argument(fmt::format("Invalid spdlog::level::level_enum {}", magic_enum::enum_underlying(level))); -} - -class BaseLogger { - public: - virtual ~BaseLogger(); - - virtual void log_string(LOG_LEVEL level, std::string str) = 0; - virtual bool should_log(LOG_LEVEL level) = 0; - [[nodiscard]] virtual LOG_LEVEL level() const = 0; -}; - inline constexpr auto map_args = utils::overloaded { [](auto&& f) requires(std::is_invocable_v) { return std::invoke(std::forward(f)); }, [](auto&& value) { return std::forward(value); } @@ -106,69 +54,57 @@ inline constexpr auto map_args = utils::overloaded { template using log_format_string = fmt::format_string...>; -class Logger : public BaseLogger { +class Logger { public: - Logger(Logger const&) = delete; - Logger& operator=(Logger const&) = delete; - template void log_with_level(LOG_LEVEL log_level, log_format_string fmt, Args&& ...args) { - return log(mapToSpdLogLevel(log_level), std::move(fmt), std::forward(args)...); + return log(log_level, std::move(fmt), std::forward(args)...); } template void log_critical(log_format_string fmt, Args&& ...args) { - log(spdlog::level::critical, std::move(fmt), std::forward(args)...); + log(LOG_LEVEL::critical, std::move(fmt), std::forward(args)...); } template void log_error(log_format_string fmt, Args&& ...args) { - log(spdlog::level::err, std::move(fmt), std::forward(args)...); + log(LOG_LEVEL::err, std::move(fmt), std::forward(args)...); } template void log_warn(log_format_string fmt, Args&& ...args) { - log(spdlog::level::warn, std::move(fmt), std::forward(args)...); + log(LOG_LEVEL::warn, std::move(fmt), std::forward(args)...); } template void log_info(log_format_string fmt, Args&& ...args) { - log(spdlog::level::info, std::move(fmt), std::forward(args)...); + log(LOG_LEVEL::info, std::move(fmt), std::forward(args)...); } template void log_debug(log_format_string fmt, Args&& ...args) { - log(spdlog::level::debug, std::move(fmt), std::forward(args)...); + log(LOG_LEVEL::debug, std::move(fmt), std::forward(args)...); } template void log_trace(log_format_string fmt, Args&& ...args) { - log(spdlog::level::trace, std::move(fmt), std::forward(args)...); - } - - void set_max_log_size(int size) { - max_log_size_ = size; + log(LOG_LEVEL::trace, std::move(fmt), std::forward(args)...); } - bool should_log(LOG_LEVEL level) override; - void log_string(LOG_LEVEL level, std::string str) override; - LOG_LEVEL level() const override; - + virtual void set_max_log_size(int size) = 0; virtual std::optional get_id() = 0; + virtual void log_string(LOG_LEVEL level, std::string str) = 0; + virtual bool should_log(LOG_LEVEL level) = 0; + [[nodiscard]] virtual LOG_LEVEL level() const = 0; - protected: - Logger(std::shared_ptr delegate, std::shared_ptr controller); - - Logger(std::shared_ptr delegate); // NOLINT - - std::shared_ptr delegate_; - std::shared_ptr controller_; + virtual ~Logger() = default; - std::mutex mutex_; + protected: + virtual int getMaxLogSize() = 0; private: std::string trimToMaxSizeAndAddId(std::string my_string) { - auto max_log_size = max_log_size_.load(); + auto max_log_size = getMaxLogSize(); if (max_log_size >= 0 && my_string.size() > gsl::narrow(max_log_size)) my_string = my_string.substr(0, max_log_size); if (auto id = get_id()) { @@ -184,17 +120,12 @@ class Logger : public BaseLogger { } template - inline void log(spdlog::level::level_enum level, log_format_string fmt, Args&& ...args) { - if (controller_ && !controller_->is_enabled()) - return; - std::lock_guard lock(mutex_); - if (!delegate_->should_log(level)) { + inline void log(LOG_LEVEL level, log_format_string fmt, Args&& ...args) { + if (!should_log(level)) { return; } - delegate_->log(level, stringify(std::move(fmt), map_args(std::forward(args))...)); + log_string(level, stringify(std::move(fmt), map_args(std::forward(args))...)); } - - std::atomic max_log_size_{LOG_BUFFER_SIZE}; }; } // namespace org::apache::nifi::minifi::core::logging diff --git a/minifi-api/include/minifi-cpp/core/logging/LoggerFactory.h b/minifi-api/include/minifi-cpp/core/logging/LoggerFactory.h new file mode 100644 index 0000000000..acab5ce103 --- /dev/null +++ b/minifi-api/include/minifi-cpp/core/logging/LoggerFactory.h @@ -0,0 +1,34 @@ +/** + * + * 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 +#include + +#include "Logger.h" +#include "minifi-cpp/core/Core.h" + +namespace org::apache::nifi::minifi::core::logging { + +class LoggerFactoryBase { + public: + static std::shared_ptr getAliasedLogger(std::string_view name, const std::optional& id = {}); +}; + +} // namespace org::apache::nifi::minifi::core::logging diff --git a/minifi-api/include/minifi-cpp/core/repository/FileSystemRepository.h b/minifi-api/include/minifi-cpp/core/repository/FileSystemRepository.h new file mode 100644 index 0000000000..7be4c9e838 --- /dev/null +++ b/minifi-api/include/minifi-cpp/core/repository/FileSystemRepository.h @@ -0,0 +1,27 @@ +/** + * + * 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 "minifi-cpp/core/ContentRepository.h" + +namespace org::apache::nifi::minifi::core::repository { + +std::shared_ptr createFileSystemRepository(); + +} // namespace org::apache::nifi::minifi::core::repository diff --git a/minifi-api/include/minifi-cpp/core/state/FlowIdentifier.h b/minifi-api/include/minifi-cpp/core/state/FlowIdentifier.h new file mode 100644 index 0000000000..ebb7a9312b --- /dev/null +++ b/minifi-api/include/minifi-cpp/core/state/FlowIdentifier.h @@ -0,0 +1,39 @@ +/** + * + * 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 + +namespace org::apache::nifi::minifi::state { + +/** + * Purpose: Represents a flow identifier for a given flow update or instance. + * + * Design: Immutable collection of strings for the component parts. + */ +class FlowIdentifier { + public: + virtual std::string getRegistryUrl() const = 0 ; + virtual std::string getBucketId() const = 0; + virtual std::string getFlowId() const = 0; + virtual ~FlowIdentifier() = default; +}; + + +} // namespace org::apache::nifi::minifi::state diff --git a/minifi-api/include/minifi-cpp/core/state/MetricsPublisher.h b/minifi-api/include/minifi-cpp/core/state/MetricsPublisher.h new file mode 100644 index 0000000000..6b6cd1ddc1 --- /dev/null +++ b/minifi-api/include/minifi-cpp/core/state/MetricsPublisher.h @@ -0,0 +1,37 @@ +/** + * + * 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 + +#include "minifi-cpp/core/Core.h" +#include "minifi-cpp/core/state/nodes/ResponseNodeLoader.h" +#include "minifi-cpp/properties/Configure.h" + +namespace org::apache::nifi::minifi::state { + +class MetricsPublisher : public virtual core::CoreComponent { + public: + using CoreComponent::CoreComponent; + virtual void initialize(const std::shared_ptr& configuration, const std::shared_ptr& response_node_loader) = 0; + virtual void clearMetricNodes() = 0; + virtual void loadMetricNodes() = 0; + virtual ~MetricsPublisher() = default; +}; + +} // namespace org::apache::nifi::minifi::state diff --git a/libminifi/include/core/state/PublishedMetricProvider.h b/minifi-api/include/minifi-cpp/core/state/PublishedMetricProvider.h similarity index 93% rename from libminifi/include/core/state/PublishedMetricProvider.h rename to minifi-api/include/minifi-cpp/core/state/PublishedMetricProvider.h index c70b2c055f..80369c9b36 100644 --- a/libminifi/include/core/state/PublishedMetricProvider.h +++ b/minifi-api/include/minifi-cpp/core/state/PublishedMetricProvider.h @@ -31,9 +31,7 @@ struct PublishedMetric { class PublishedMetricProvider { public: - virtual std::vector calculateMetrics() { - return {}; - } + virtual std::vector calculateMetrics() = 0; virtual ~PublishedMetricProvider() = default; }; diff --git a/minifi-api/include/minifi-cpp/core/state/Value.h b/minifi-api/include/minifi-cpp/core/state/Value.h new file mode 100644 index 0000000000..ac17811c1d --- /dev/null +++ b/minifi-api/include/minifi-cpp/core/state/Value.h @@ -0,0 +1,136 @@ +/** + * + * 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 +#include +#include +#include +#include +#include +#include +#include +#include +#include "minifi-cpp/utils/Export.h" +#include "utils/meta/type_list.h" + +namespace org::apache::nifi::minifi::state::response { + +/** + * Purpose: Represents an AST value + * Contains an embedded string representation to be used for a toString analog. + * + * Extensions can be more strongly typed and can be used anywhere where an abstract + * representation is needed. + */ +class Value { + public: + virtual ~Value() = default; + + [[nodiscard]] virtual std::string getStringValue() const = 0; + + [[nodiscard]] virtual const char* c_str() const = 0; + + [[nodiscard]] virtual bool empty() const noexcept = 0; + + virtual std::type_index getTypeIndex() = 0; + + virtual bool getValue(uint32_t &ref) = 0; + virtual bool getValue(int &ref) = 0; + virtual bool getValue(int64_t &ref) = 0; + virtual bool getValue(uint64_t &ref) = 0; + virtual bool getValue(bool &ref) = 0; + virtual bool getValue(double &ref) = 0; + + MINIFIAPI static const std::type_index UINT64_TYPE; + MINIFIAPI static const std::type_index INT64_TYPE; + MINIFIAPI static const std::type_index UINT32_TYPE; + MINIFIAPI static const std::type_index INT_TYPE; + MINIFIAPI static const std::type_index BOOL_TYPE; + MINIFIAPI static const std::type_index DOUBLE_TYPE; + MINIFIAPI static const std::type_index STRING_TYPE; +}; + +/** + * Purpose: ValueNode is the AST container for a value + */ +class ValueNode { + using supported_types = utils::meta::type_list; + + public: + ValueNode() = default; + + template + requires (ValueNode::supported_types::contains()) // NOLINT + /* implicit, because it doesn't change the meaning, and it simplifies construction of maps */ + ValueNode(const T value); // NOLINT + + /** + * Define the representations and eventual storage relationships through + * createValue + */ + template + requires (ValueNode::supported_types::contains()) // NOLINT + ValueNode& operator=(const T ref); + + inline bool operator==(const ValueNode &rhs) const { + return to_string() == rhs.to_string(); + } + + inline bool operator==(const char* rhs) const { + return to_string() == rhs; + } + + friend bool operator==(const char* lhs, const ValueNode& rhs) { + return lhs == rhs.to_string(); + } + + [[nodiscard]] std::string to_string() const { + return value_ ? value_->getStringValue() : ""; + } + + [[nodiscard]] std::shared_ptr getValue() const { + return value_; + } + + [[nodiscard]] bool empty() const noexcept { + return value_ == nullptr || value_->empty(); + } + + protected: + std::shared_ptr value_; +}; + +struct SerializedResponseNode { + std::string name; + ValueNode value{}; + bool array = false; + bool collapsible = true; + bool keep_empty = false; + std::vector children{}; + + [[nodiscard]] bool empty() const noexcept { + return value.empty() && children.empty(); + } + + [[nodiscard]] std::string to_string() const; + + [[nodiscard]] std::string to_pretty_string() const; +}; + +} // namespace org::apache::nifi::minifi::state::response diff --git a/minifi-api/include/minifi-cpp/core/state/nodes/MetricsBase.h b/minifi-api/include/minifi-cpp/core/state/nodes/MetricsBase.h new file mode 100644 index 0000000000..08fccb2490 --- /dev/null +++ b/minifi-api/include/minifi-cpp/core/state/nodes/MetricsBase.h @@ -0,0 +1,72 @@ +/** + * + * 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 +#include +#include +#include +#include + +#include "../Value.h" +#include "../PublishedMetricProvider.h" +#include "core/Core.h" +#include "core/Connectable.h" + +namespace org::apache::nifi::minifi::state::response { + +class ResponseNode; +using SharedResponseNode = gsl::not_null>; + +class ResponseNode : public virtual core::Connectable, public virtual PublishedMetricProvider { + public: + ~ResponseNode() override = default; + + static std::vector serializeAndMergeResponseNodes(const std::vector& nodes); + + virtual std::vector serialize() = 0; + virtual bool isArray() const = 0; + virtual bool isEmpty() = 0; +}; + +class ResponseNodeSource { + public: + virtual ~ResponseNodeSource() = default; + virtual SharedResponseNode getResponseNode() = 0; +}; + +class NodeReporter { + public: + struct ReportedNode { + std::string name; + bool is_array; + std::vector serialized_nodes; + }; + + NodeReporter() = default; + + virtual ~NodeReporter() = default; + + virtual std::optional getMetricsNode(const std::string& metricsClass) const = 0; + + virtual std::vector getHeartbeatNodes(bool includeManifest) const = 0; + + virtual ReportedNode getAgentManifest() = 0; +}; + +} // namespace org::apache::nifi::minifi::state::response diff --git a/minifi-api/include/minifi-cpp/core/state/nodes/ResponseNodeLoader.h b/minifi-api/include/minifi-cpp/core/state/nodes/ResponseNodeLoader.h new file mode 100644 index 0000000000..c887cb0183 --- /dev/null +++ b/minifi-api/include/minifi-cpp/core/state/nodes/ResponseNodeLoader.h @@ -0,0 +1,51 @@ +/** + * + * 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 +#include + +#include "MetricsBase.h" + +namespace org::apache::nifi::minifi::state { +class StateMonitor; +} // namespace org::apache::nifi::minifi::state + +namespace org::apache::nifi::minifi::core { +class ProcessGroup; +} // namespace org::apache::nifi::minifi::core + +namespace org::apache::nifi::minifi::core::controller { +class ControllerServiceProvider; +} // namespace org::apache::nifi::minifi::core::controller + +namespace org::apache::nifi::minifi::state::response { + +class ResponseNodeLoader { + public: + virtual void setNewConfigRoot(core::ProcessGroup* root) = 0; + virtual void clearConfigRoot() = 0; + virtual void setControllerServiceProvider(core::controller::ControllerServiceProvider* controller) = 0; + virtual void setStateMonitor(state::StateMonitor* update_sink) = 0; + virtual std::vector loadResponseNodes(const std::string& clazz) = 0; + virtual state::response::NodeReporter::ReportedNode getAgentManifest() const = 0; + + virtual ~ResponseNodeLoader() = default; +}; + +} // namespace org::apache::nifi::minifi::state::response diff --git a/libminifi/include/io/ArchiveStream.h b/minifi-api/include/minifi-cpp/io/ArchiveStream.h similarity index 90% rename from libminifi/include/io/ArchiveStream.h rename to minifi-api/include/minifi-cpp/io/ArchiveStream.h index 2f04f3ea27..df8e6e5445 100644 --- a/libminifi/include/io/ArchiveStream.h +++ b/minifi-api/include/minifi-cpp/io/ArchiveStream.h @@ -33,18 +33,18 @@ struct EntryInfo { size_t size; }; -class WriteArchiveStream : public OutputStream { +class WriteArchiveStream : public virtual OutputStream { public: virtual bool newEntry(const EntryInfo& info) = 0; virtual bool finish() = 0; }; -class ReadArchiveStream : public InputStream { +class ReadArchiveStream : public virtual InputStream { public: virtual std::optional nextEntry() = 0; }; -class ArchiveStreamProvider : public core::CoreComponent { +class ArchiveStreamProvider : public virtual core::CoreComponent { public: using CoreComponent::CoreComponent; virtual std::unique_ptr createWriteStream(int compress_level, const std::string& compress_format, diff --git a/libminifi/include/io/BaseStream.h b/minifi-api/include/minifi-cpp/io/BaseStream.h similarity index 94% rename from libminifi/include/io/BaseStream.h rename to minifi-api/include/minifi-cpp/io/BaseStream.h index 0c7b344a9b..f6a5595c87 100644 --- a/libminifi/include/io/BaseStream.h +++ b/minifi-api/include/minifi-cpp/io/BaseStream.h @@ -36,6 +36,6 @@ namespace org::apache::nifi::minifi::io { * * Extensions may be thread safe and thus shareable, but that is up to the implementation. */ -class BaseStream : public InputStream, public OutputStream {}; +class BaseStream : public virtual InputStream, public virtual OutputStream {}; } // namespace org::apache::nifi::minifi::io diff --git a/libminifi/include/io/InputStream.h b/minifi-api/include/minifi-cpp/io/InputStream.h similarity index 91% rename from libminifi/include/io/InputStream.h rename to minifi-api/include/minifi-cpp/io/InputStream.h index ad24d6908d..4d615c8a51 100644 --- a/libminifi/include/io/InputStream.h +++ b/minifi-api/include/minifi-cpp/io/InputStream.h @@ -24,15 +24,13 @@ #include #include #include "Stream.h" -#include "utils/Id.h" +#include "minifi-cpp/utils/Id.h" namespace org::apache::nifi::minifi::io { class InputStream : public virtual Stream { public: - [[nodiscard]] virtual size_t size() const { - throw std::runtime_error("Querying size is not supported"); - } + [[nodiscard]] virtual size_t size() const = 0; /** * Reads a byte array from the stream. Use isError (Stream.h) to check for errors. * @param out_buffer reference in which will set the result @@ -82,13 +80,7 @@ class InputStream : public virtual Stream { return sizeof(Integral); } - std::optional readByte() { - std::array buf{}; - if (read(buf) != 1) { - return std::nullopt; - } - return buf[0]; - } + std::optional readByte(); }; } // namespace org::apache::nifi::minifi::io diff --git a/libminifi/include/io/OutputStream.h b/minifi-api/include/minifi-cpp/io/OutputStream.h similarity index 100% rename from libminifi/include/io/OutputStream.h rename to minifi-api/include/minifi-cpp/io/OutputStream.h diff --git a/libminifi/include/io/Stream.h b/minifi-api/include/minifi-cpp/io/Stream.h similarity index 80% rename from libminifi/include/io/Stream.h rename to minifi-api/include/minifi-cpp/io/Stream.h index 048a475ca5..e69b646a06 100644 --- a/libminifi/include/io/Stream.h +++ b/minifi-api/include/minifi-cpp/io/Stream.h @@ -18,6 +18,11 @@ #pragma once +#ifdef WIN32 +// ignore the warning about inheriting via dominance from Stream +#pragma warning(disable : 4250) +#endif + #include #include "utils/gsl.h" @@ -35,23 +40,11 @@ inline bool isError(const size_t read_write_return) noexcept { */ class Stream { public: - virtual void close() {} - - virtual void seek(size_t /*offset*/) { - throw std::runtime_error("Seek is not supported"); - } - - [[nodiscard]] virtual size_t tell() const { - throw std::runtime_error("Tell is not supported"); - } - - virtual int initialize() { - return 1; - } - - [[nodiscard]] virtual std::span getBuffer() const { - throw std::runtime_error("Not a buffered stream"); - } + virtual void close() = 0; + virtual void seek(size_t /*offset*/) = 0; + [[nodiscard]] virtual size_t tell() const = 0; + virtual int initialize() = 0; + [[nodiscard]] virtual std::span getBuffer() const = 0; virtual ~Stream() = default; }; diff --git a/libminifi/include/io/StreamCallback.h b/minifi-api/include/minifi-cpp/io/StreamCallback.h similarity index 100% rename from libminifi/include/io/StreamCallback.h rename to minifi-api/include/minifi-cpp/io/StreamCallback.h diff --git a/minifi-api/include/minifi-cpp/properties/Configuration.h b/minifi-api/include/minifi-cpp/properties/Configuration.h new file mode 100644 index 0000000000..280771ca54 --- /dev/null +++ b/minifi-api/include/minifi-cpp/properties/Configuration.h @@ -0,0 +1,212 @@ +/** + * 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 +#include +#include +#include +#include + +#include "Properties.h" +#include "minifi-cpp/utils/Export.h" +#include "minifi-cpp/utils/gsl.h" + +namespace org::apache::nifi::minifi { + +namespace core { +class PropertyValidator; +} + +class Configuration : public virtual Properties { + public: + static constexpr const char *nifi_volatile_repository_options = "nifi.volatile.repository.options."; + static constexpr const char *nifi_global_rocksdb_options = "nifi.global.rocksdb.options."; + static constexpr const char *nifi_flowfile_repository_rocksdb_options = "nifi.flowfile.repository.rocksdb.options."; + static constexpr const char *nifi_content_repository_rocksdb_options = "nifi.content.repository.rocksdb.options."; + static constexpr const char *nifi_provenance_repository_rocksdb_options = "nifi.provenance.repository.rocksdb.options."; + static constexpr const char *nifi_state_storage_rocksdb_options = "nifi.state.storage.rocksdb.options."; + + // nifi.flow.configuration.file + static constexpr const char *nifi_default_directory = "nifi.default.directory"; + static constexpr const char *nifi_flow_configuration_file = "nifi.flow.configuration.file"; + static constexpr const char *nifi_flow_configuration_encrypt = "nifi.flow.configuration.encrypt"; + static constexpr const char *nifi_flow_configuration_file_backup_update = "nifi.flow.configuration.backup.on.update"; + static constexpr const char *nifi_flow_engine_threads = "nifi.flow.engine.threads"; + static constexpr const char *nifi_flow_engine_alert_period = "nifi.flow.engine.alert.period"; + static constexpr const char *nifi_flow_engine_event_driven_time_slice = "nifi.flow.engine.event.driven.time.slice"; + static constexpr const char *nifi_administrative_yield_duration = "nifi.administrative.yield.duration"; + static constexpr const char *nifi_bored_yield_duration = "nifi.bored.yield.duration"; + static constexpr const char *nifi_graceful_shutdown_seconds = "nifi.flowcontroller.graceful.shutdown.period"; + static constexpr const char *nifi_flowcontroller_drain_timeout = "nifi.flowcontroller.drain.timeout"; + static constexpr const char *nifi_configuration_class_name = "nifi.flow.configuration.class.name"; + static constexpr const char *nifi_flow_repository_class_name = "nifi.flowfile.repository.class.name"; + static constexpr const char *nifi_flow_repository_rocksdb_compression = "nifi.flowfile.repository.rocksdb.compression"; + static constexpr const char *nifi_content_repository_class_name = "nifi.content.repository.class.name"; + static constexpr const char *nifi_content_repository_rocksdb_compression = "nifi.content.repository.rocksdb.compression"; + static constexpr const char *nifi_provenance_repository_class_name = "nifi.provenance.repository.class.name"; + static constexpr const char *nifi_volatile_repository_options_flowfile_max_count = "nifi.volatile.repository.options.flowfile.max.count"; + static constexpr const char *nifi_volatile_repository_options_flowfile_max_bytes = "nifi.volatile.repository.options.flowfile.max.bytes"; + static constexpr const char *nifi_volatile_repository_options_provenance_max_count = "nifi.volatile.repository.options.provenance.max.count"; + static constexpr const char *nifi_volatile_repository_options_provenance_max_bytes = "nifi.volatile.repository.options.provenance.max.bytes"; + static constexpr const char *nifi_volatile_repository_options_content_max_count = "nifi.volatile.repository.options.content.max.count"; + static constexpr const char *nifi_volatile_repository_options_content_max_bytes = "nifi.volatile.repository.options.content.max.bytes"; + static constexpr const char *nifi_volatile_repository_options_content_minimal_locking = "nifi.volatile.repository.options.content.minimal.locking"; + static constexpr const char *nifi_provenance_repository_max_storage_size = "nifi.provenance.repository.max.storage.size"; + static constexpr const char *nifi_provenance_repository_max_storage_time = "nifi.provenance.repository.max.storage.time"; + static constexpr const char *nifi_provenance_repository_directory_default = "nifi.provenance.repository.directory.default"; + static constexpr const char *nifi_flowfile_repository_directory_default = "nifi.flowfile.repository.directory.default"; + static constexpr const char *nifi_dbcontent_repository_directory_default = "nifi.database.content.repository.directory.default"; + + // these are internal properties related to the rocksdb backend + static constexpr const char *nifi_flowfile_repository_rocksdb_compaction_period = "nifi.flowfile.repository.rocksdb.compaction.period"; + static constexpr const char *nifi_dbcontent_repository_rocksdb_compaction_period = "nifi.database.content.repository.rocksdb.compaction.period"; + static constexpr const char *nifi_dbcontent_repository_purge_period = "nifi.database.content.repository.purge.period"; + static constexpr const char *nifi_content_repository_rocksdb_use_synchronous_writes = "nifi.content.repository.rocksdb.use.synchronous.writes"; + static constexpr const char *nifi_content_repository_rocksdb_read_verify_checksums = "nifi.content.repository.rocksdb.read.verify.checksums"; + static constexpr const char *nifi_flowfile_repository_rocksdb_read_verify_checksums = "nifi.flowfile.repository.rocksdb.read.verify.checksums"; + static constexpr const char *nifi_provenance_repository_rocksdb_read_verify_checksums = "nifi.provenance.repository.rocksdb.read.verify.checksums"; + static constexpr const char *nifi_rocksdb_state_storage_read_verify_checksums = "nifi.rocksdb.state.storage.read.verify.checksums"; + + static constexpr const char *nifi_remote_input_secure = "nifi.remote.input.secure"; + static constexpr const char *nifi_security_need_ClientAuth = "nifi.security.need.ClientAuth"; + static constexpr const char *nifi_sensitive_props_additional_keys = "nifi.sensitive.props.additional.keys"; + static constexpr const char *nifi_python_processor_dir = "nifi.python.processor.dir"; + static constexpr const char *nifi_extension_path = "nifi.extension.path"; + + // site2site security config + static constexpr const char *nifi_security_client_certificate = "nifi.security.client.certificate"; + static constexpr const char *nifi_security_client_private_key = "nifi.security.client.private.key"; + static constexpr const char *nifi_security_client_pass_phrase = "nifi.security.client.pass.phrase"; + static constexpr const char *nifi_security_client_ca_certificate = "nifi.security.client.ca.certificate"; + static constexpr const char *nifi_security_use_system_cert_store = "nifi.security.use.system.cert.store"; + static constexpr const char *nifi_security_windows_cert_store_location = "nifi.security.windows.cert.store.location"; + static constexpr const char *nifi_security_windows_server_cert_store = "nifi.security.windows.server.cert.store"; + static constexpr const char *nifi_security_windows_client_cert_store = "nifi.security.windows.client.cert.store"; + static constexpr const char *nifi_security_windows_client_cert_cn = "nifi.security.windows.client.cert.cn"; + static constexpr const char *nifi_security_windows_client_cert_key_usage = "nifi.security.windows.client.cert.key.usage"; + + // nifi rest api user name and password + static constexpr const char *nifi_rest_api_user_name = "nifi.rest.api.user.name"; + static constexpr const char *nifi_rest_api_password = "nifi.rest.api.password"; + + // c2 options + static constexpr const char *nifi_c2_enable = "nifi.c2.enable"; + static constexpr const char *nifi_c2_file_watch = "nifi.c2.file.watch"; + static constexpr const char *nifi_c2_flow_id = "nifi.c2.flow.id"; + static constexpr const char *nifi_c2_flow_url = "nifi.c2.flow.url"; + static constexpr const char *nifi_c2_flow_base_url = "nifi.c2.flow.base.url"; + static constexpr const char *nifi_c2_full_heartbeat = "nifi.c2.full.heartbeat"; + static constexpr const char *nifi_c2_agent_heartbeat_period = "nifi.c2.agent.heartbeat.period"; + static constexpr const char *nifi_c2_agent_class = "nifi.c2.agent.class"; + static constexpr const char *nifi_c2_agent_heartbeat_reporter_classes = "nifi.c2.agent.heartbeat.reporter.classes"; + static constexpr const char *nifi_c2_agent_identifier = "nifi.c2.agent.identifier"; + static constexpr const char *nifi_c2_agent_identifier_fallback = "nifi.c2.agent.identifier.fallback"; + static constexpr const char *nifi_c2_agent_trigger_classes = "nifi.c2.agent.trigger.classes"; + static constexpr const char *nifi_c2_root_classes = "nifi.c2.root.classes"; + static constexpr const char *nifi_c2_root_class_definitions = "nifi.c2.root.class.definitions"; + static constexpr const char *nifi_c2_rest_listener_port = "nifi.c2.rest.listener.port"; + static constexpr const char *nifi_c2_rest_listener_cacert = "nifi.c2.rest.listener.cacert"; + static constexpr const char *nifi_c2_rest_path_base = "nifi.c2.rest.path.base"; + static constexpr const char *nifi_c2_rest_url = "nifi.c2.rest.url"; + static constexpr const char *nifi_c2_rest_url_ack = "nifi.c2.rest.url.ack"; + static constexpr const char *nifi_c2_rest_ssl_context_service = "nifi.c2.rest.ssl.context.service"; + static constexpr const char *nifi_c2_rest_heartbeat_minimize_updates = "nifi.c2.rest.heartbeat.minimize.updates"; + static constexpr const char *nifi_c2_rest_request_encoding = "nifi.c2.rest.request.encoding"; + + // state management options + static constexpr const char *nifi_state_storage_local = "nifi.state.storage.local"; + static constexpr const char *nifi_state_storage_local_old = "nifi.state.management.provider.local"; + static constexpr const char *nifi_state_storage_local_class_name = "nifi.state.storage.local.class.name"; + static constexpr const char *nifi_state_storage_local_class_name_old = "nifi.state.management.provider.local.class.name"; + static constexpr const char *nifi_state_storage_local_always_persist = "nifi.state.storage.local.always.persist"; + static constexpr const char *nifi_state_storage_local_always_persist_old = "nifi.state.management.provider.local.always.persist"; + static constexpr const char *nifi_state_storage_local_auto_persistence_interval = "nifi.state.storage.local.auto.persistence.interval"; + static constexpr const char *nifi_state_storage_local_auto_persistence_interval_old = "nifi.state.management.provider.local.auto.persistence.interval"; + static constexpr const char *nifi_state_storage_local_path = "nifi.state.storage.local.path"; + static constexpr const char *nifi_state_storage_local_path_old = "nifi.state.management.provider.local.path"; + + // disk space watchdog options + static constexpr const char *minifi_disk_space_watchdog_enable = "minifi.disk.space.watchdog.enable"; + static constexpr const char *minifi_disk_space_watchdog_interval = "minifi.disk.space.watchdog.interval"; + static constexpr const char *minifi_disk_space_watchdog_stop_threshold = "minifi.disk.space.watchdog.stop.threshold"; + static constexpr const char *minifi_disk_space_watchdog_restart_threshold = "minifi.disk.space.watchdog.restart.threshold"; + + // Log options + static constexpr const char *nifi_log_spdlog_pattern = "nifi.log.spdlog.pattern"; + static constexpr const char *nifi_log_spdlog_shorten_names = "nifi.log.spdlog.shorten_names"; + static constexpr const char *nifi_log_appender_rolling = "nifi.log.appender.rolling"; + static constexpr const char *nifi_log_appender_rolling_directory = "nifi.log.appender.rolling.directory"; + static constexpr const char *nifi_log_appender_rolling_file_name = "nifi.log.appender.rolling.file_name"; + static constexpr const char *nifi_log_appender_rolling_max_files = "nifi.log.appender.rolling.max_files"; + static constexpr const char *nifi_log_appender_rolling_max_file_size = "nifi.log.appender.rolling.max_file_size"; + static constexpr const char *nifi_log_appender_stdout = "nifi.log.appender.stdout"; + static constexpr const char *nifi_log_appender_stderr = "nifi.log.appender.stderr"; + static constexpr const char *nifi_log_appender_null = "nifi.log.appender.null"; + static constexpr const char *nifi_log_appender_syslog = "nifi.log.appender.syslog"; + static constexpr const char *nifi_log_logger_root = "nifi.log.logger.root"; + static constexpr const char *nifi_log_compression_cached_log_max_size = "nifi.log.compression.cached.log.max.size"; + static constexpr const char *nifi_log_compression_compressed_log_max_size = "nifi.log.compression.compressed.log.max.size"; + static constexpr const char *nifi_log_max_log_entry_length = "nifi.log.max.log.entry.length"; + + // alert options + static constexpr const char *nifi_log_alert_url = "nifi.log.alert.url"; + static constexpr const char *nifi_log_alert_ssl_context_service = "nifi.log.alert.ssl.context.service"; + static constexpr const char *nifi_log_alert_batch_size = "nifi.log.alert.batch.size"; + static constexpr const char *nifi_log_alert_flush_period = "nifi.log.alert.flush.period"; + static constexpr const char *nifi_log_alert_filter = "nifi.log.alert.filter"; + static constexpr const char *nifi_log_alert_rate_limit = "nifi.log.alert.rate.limit"; + static constexpr const char *nifi_log_alert_buffer_limit = "nifi.log.alert.buffer.limit"; + static constexpr const char *nifi_log_alert_level = "nifi.log.alert.level"; + + static constexpr const char *nifi_asset_directory = "nifi.asset.directory"; + + // Metrics publisher options + static constexpr const char *nifi_metrics_publisher_agent_identifier = "nifi.metrics.publisher.agent.identifier"; + static constexpr const char *nifi_metrics_publisher_class = "nifi.metrics.publisher.class"; + static constexpr const char *nifi_metrics_publisher_prometheus_metrics_publisher_port = "nifi.metrics.publisher.PrometheusMetricsPublisher.port"; + static constexpr const char *nifi_metrics_publisher_prometheus_metrics_publisher_metrics = "nifi.metrics.publisher.PrometheusMetricsPublisher.metrics"; + static constexpr const char *nifi_metrics_publisher_log_metrics_publisher_metrics = "nifi.metrics.publisher.LogMetricsPublisher.metrics"; + static constexpr const char *nifi_metrics_publisher_log_metrics_logging_interval = "nifi.metrics.publisher.LogMetricsPublisher.logging.interval"; + static constexpr const char *nifi_metrics_publisher_log_metrics_log_level = "nifi.metrics.publisher.LogMetricsPublisher.log.level"; + static constexpr const char *nifi_metrics_publisher_metrics = "nifi.metrics.publisher.metrics"; + static constexpr const char *nifi_metrics_publisher_prometheus_metrics_publisher_certificate = "nifi.metrics.publisher.PrometheusMetricsPublisher.certificate"; + static constexpr const char *nifi_metrics_publisher_prometheus_metrics_publisher_ca_certificate = "nifi.metrics.publisher.PrometheusMetricsPublisher.ca.certificate"; + + // Controller socket options + static constexpr const char *controller_socket_enable = "controller.socket.enable"; + static constexpr const char *controller_socket_local_any_interface = "controller.socket.local.any.interface"; + static constexpr const char *controller_socket_host = "controller.socket.host"; + static constexpr const char *controller_socket_port = "controller.socket.port"; + static constexpr const char *controller_ssl_context_service = "controller.ssl.context.service"; + + static constexpr const char *nifi_flow_file_repository_check_health = "nifi.flowfile.repository.check.health"; + static constexpr const char *nifi_python_virtualenv_directory = "nifi.python.virtualenv.directory"; + static constexpr const char *nifi_python_env_setup_binary = "nifi.python.env.setup.binary"; + static constexpr const char *nifi_python_install_packages_automatically = "nifi.python.install.packages.automatically"; + + MINIFIAPI static const std::unordered_map> CONFIGURATION_PROPERTIES; + MINIFIAPI static const std::array DEFAULT_SENSITIVE_PROPERTIES; + + static std::vector mergeProperties(std::vector properties, + const std::vector& additional_properties); + static std::vector getSensitiveProperties(const std::function(const std::string&)>& reader); + static bool validatePropertyValue(const std::string& property_name, const std::string& property_value); +}; + +} // namespace org::apache::nifi::minifi diff --git a/minifi-api/include/minifi-cpp/properties/Configure.h b/minifi-api/include/minifi-cpp/properties/Configure.h new file mode 100644 index 0000000000..e72dec51b7 --- /dev/null +++ b/minifi-api/include/minifi-cpp/properties/Configure.h @@ -0,0 +1,49 @@ +/** + * 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 +#include +#include +#include + +#include "Configuration.h" +#include "minifi-cpp/core/AgentIdentificationProvider.h" + +struct ConfigTestAccessor; + +namespace org::apache::nifi::minifi { + +class Configure : public virtual Configuration, public virtual core::AgentIdentificationProvider { + friend struct ::ConfigTestAccessor; + public: + virtual bool get(const std::string& key, std::string& value) const = 0; + virtual bool get(const std::string& key, const std::string& alternate_key, std::string& value) const = 0; + virtual std::optional get(const std::string& key) const = 0; + virtual std::optional getWithFallback(const std::string& key, const std::string& alternate_key) const = 0; + virtual std::optional getRawValue(const std::string& key) const = 0; + + virtual void setFallbackAgentIdentifier(const std::string& id) = 0; + + using Configuration::set; + virtual void set(const std::string& key, const std::string& value, PropertyChangeLifetime lifetime) override = 0; + virtual bool commitChanges() override = 0; + + static std::shared_ptr create(); +}; + +} // namespace org::apache::nifi::minifi diff --git a/minifi-api/include/minifi-cpp/properties/Properties.h b/minifi-api/include/minifi-cpp/properties/Properties.h new file mode 100644 index 0000000000..9f684bdcda --- /dev/null +++ b/minifi-api/include/minifi-cpp/properties/Properties.h @@ -0,0 +1,69 @@ +/** + * @file Configure.h + * Configure class declaration + * + * 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 + +#ifdef WIN32 +// ignore the warning about inheriting via dominance from Properties +#pragma warning(disable : 4250) +#endif + +#include +#include +#include +#include +#include +#include +#include + +namespace org::apache::nifi::minifi { + +namespace utils { +class ChecksumCalculator; +} // namespace utils + +enum class PropertyChangeLifetime { + TRANSIENT, // the changed value will not be committed to disk + PERSISTENT // the changed value will be written to the source file +}; + +class Properties { + public: + virtual ~Properties() = default; + virtual const std::string& getName() const = 0; + virtual void clear() = 0; + virtual void set(const std::string& key, const std::string& value) = 0; + virtual void set(const std::string &key, const std::string &value, PropertyChangeLifetime lifetime) = 0; + virtual bool has(const std::string& key) const = 0; + virtual bool getString(const std::string &key, std::string &value) const = 0; + virtual int getInt(const std::string &key, int default_value) const = 0; + virtual std::optional getString(const std::string& key) const = 0; + virtual void loadConfigureFile(const std::filesystem::path& configuration_file, std::string_view prefix = "") = 0; + virtual void setHome(std::filesystem::path minifiHome) = 0; + virtual std::vector getConfiguredKeys() const = 0; + virtual std::filesystem::path getHome() const = 0; + virtual bool commitChanges() = 0; + virtual utils::ChecksumCalculator& getChecksumCalculator() = 0; + virtual std::filesystem::path getFilePath() const = 0; + virtual std::map getProperties() const = 0; + + static std::shared_ptr create(); +}; + +} // namespace org::apache::nifi::minifi diff --git a/minifi-api/include/minifi-cpp/provenance/Provenance.h b/minifi-api/include/minifi-cpp/provenance/Provenance.h new file mode 100644 index 0000000000..6dafba625c --- /dev/null +++ b/minifi-api/include/minifi-cpp/provenance/Provenance.h @@ -0,0 +1,218 @@ +/** + * + * 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 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "minifi-cpp/core/Core.h" +#include "minifi-cpp/core/SerializableComponent.h" +#include "minifi-cpp/core/Repository.h" +#include "minifi-cpp/core/Property.h" +#include "minifi-cpp/properties/Configure.h" +#include "minifi-cpp/Connection.h" +#include "minifi-cpp/ResourceClaim.h" +#include "utils/gsl.h" +#include "utils/Id.h" + +namespace org::apache::nifi::minifi::provenance { + +class ProvenanceEventRecord : public virtual core::SerializableComponent { + public: + enum ProvenanceEventType { + /** + * A CREATE event is used when a FlowFile is generated from data that was + * not received from a remote system or external process + */ + CREATE, + + /** + * Indicates a provenance event for receiving data from an external process. This Event Type + * is expected to be the first event for a FlowFile. As such, a Processor that receives data + * from an external source and uses that data to replace the content of an existing FlowFile + * should use the {@link #FETCH} event type, rather than the RECEIVE event type. + */ + RECEIVE, + + /** + * Indicates that the contents of a FlowFile were overwritten using the contents of some + * external resource. This is similar to the {@link #RECEIVE} event but varies in that + * RECEIVE events are intended to be used as the event that introduces the FlowFile into + * the system, whereas FETCH is used to indicate that the contents of an existing FlowFile + * were overwritten. + */ + FETCH, + + /** + * Indicates a provenance event for sending data to an external process + */ + SEND, + + /** + * Indicates that the contents of a FlowFile were downloaded by a user or external entity. + */ + DOWNLOAD, + + /** + * Indicates a provenance event for the conclusion of an object's life for + * some reason other than object expiration + */ + DROP, + + /** + * Indicates a provenance event for the conclusion of an object's life due + * to the fact that the object could not be processed in a timely manner + */ + EXPIRE, + + /** + * FORK is used to indicate that one or more FlowFile was derived from a + * parent FlowFile. + */ + FORK, + + /** + * JOIN is used to indicate that a single FlowFile is derived from joining + * together multiple parent FlowFiles. + */ + JOIN, + + /** + * CLONE is used to indicate that a FlowFile is an exact duplicate of its + * parent FlowFile. + */ + CLONE, + + /** + * CONTENT_MODIFIED is used to indicate that a FlowFile's content was + * modified in some way. When using this Event Type, it is advisable to + * provide details about how the content is modified. + */ + CONTENT_MODIFIED, + + /** + * ATTRIBUTES_MODIFIED is used to indicate that a FlowFile's attributes were + * modified in some way. This event is not needed when another event is + * reported at the same time, as the other event will already contain all + * FlowFile attributes. + */ + ATTRIBUTES_MODIFIED, + + /** + * ROUTE is used to show that a FlowFile was routed to a specified + * {@link org.apache.nifi.processor.Relationship Relationship} and should provide + * information about why the FlowFile was routed to this relationship. + */ + ROUTE, + + /** + * Indicates a provenance event for adding additional information such as a + * new linkage to a new URI or UUID + */ + ADDINFO, + + /** + * Indicates a provenance event for replaying a FlowFile. The UUID of the + * event will indicate the UUID of the original FlowFile that is being + * replayed. The event will contain exactly one Parent UUID that is also the + * UUID of the FlowFile that is being replayed and exactly one Child UUID + * that is the UUID of the a newly created FlowFile that will be re-queued + * for processing. + */ + REPLAY + }; + static const char *ProvenanceEventTypeStr[REPLAY + 1]; + + ~ProvenanceEventRecord() override = default; + + virtual utils::Identifier getEventId() const = 0; + virtual void setEventId(const utils::Identifier &id) = 0; + virtual std::map getAttributes() const = 0; + virtual uint64_t getFileSize() const = 0; + virtual uint64_t getFileOffset() const = 0; + virtual std::chrono::system_clock::time_point getFlowFileEntryDate() const = 0; + virtual std::chrono::system_clock::time_point getlineageStartDate() const = 0; + virtual std::chrono::system_clock::time_point getEventTime() const = 0; + virtual std::chrono::milliseconds getEventDuration() const = 0; + virtual void setEventDuration(std::chrono::milliseconds duration) = 0; + virtual ProvenanceEventType getEventType() const = 0; + virtual std::string getComponentId() const = 0; + virtual std::string getComponentType() const = 0; + virtual utils::Identifier getFlowFileUuid() const = 0; + virtual std::string getContentFullPath() const = 0; + virtual std::vector getLineageIdentifiers() const = 0; + virtual std::string getDetails() const = 0; + virtual void setDetails(const std::string& details) = 0; + virtual std::string getTransitUri() = 0; + virtual void setTransitUri(const std::string& uri) = 0; + virtual std::string getSourceSystemFlowFileIdentifier() const = 0; + virtual void setSourceSystemFlowFileIdentifier(const std::string& identifier) = 0; + virtual std::vector getParentUuids() const = 0; + virtual void addParentUuid(const utils::Identifier& uuid) = 0; + virtual void addParentFlowFile(const core::FlowFile& flow_file) = 0; + virtual void removeParentUuid(const utils::Identifier& uuid) = 0; + virtual void removeParentFlowFile(const core::FlowFile& flow_file) = 0; + virtual std::vector getChildrenUuids() const = 0; + virtual void addChildUuid(const utils::Identifier& uuid) = 0; + virtual void addChildFlowFile(const core::FlowFile& flow_file) = 0; + virtual void removeChildUuid(const utils::Identifier& uuid) = 0; + virtual void removeChildFlowFile(const core::FlowFile& flow_file) = 0; + virtual std::string getAlternateIdentifierUri() const = 0; + virtual void setAlternateIdentifierUri(const std::string& uri) = 0; + virtual std::string getRelationship() const = 0; + virtual void setRelationship(const std::string& relation) = 0; + virtual std::string getSourceQueueIdentifier() const = 0; + virtual void setSourceQueueIdentifier(const std::string& identifier) = 0; + virtual void fromFlowFile(const core::FlowFile& flow_file) = 0; + virtual bool loadFromRepository(const std::shared_ptr &repo) = 0; + + static std::shared_ptr create(); +}; + +class ProvenanceReporter { + public: + virtual ~ProvenanceReporter() = default; + + virtual std::set> getEvents() const = 0; + virtual void add(const std::shared_ptr &event) = 0 ; + virtual void remove(const std::shared_ptr &event) = 0; + virtual void clear() = 0; + + virtual void commit() = 0; + virtual void create(const core::FlowFile& flow_file, const std::string& detail) = 0; + virtual void route(const core::FlowFile& flow_file, const core::Relationship& relation, const std::string& detail, std::chrono::milliseconds processingDuration) = 0; + virtual void modifyAttributes(const core::FlowFile& flow_file, const std::string& detail) = 0; + virtual void modifyContent(const core::FlowFile& flow_file, const std::string& detail, std::chrono::milliseconds processingDuration) = 0; + virtual void clone(const core::FlowFile& parent, const core::FlowFile& child) = 0; + virtual void expire(const core::FlowFile& flow_file, const std::string& detail) = 0; + virtual void drop(const core::FlowFile& flow_file, const std::string& reason) = 0; + virtual void send(const core::FlowFile& flow_file, const std::string& transitUri, const std::string& detail, std::chrono::milliseconds processingDuration, bool force) = 0; + virtual void fetch(const core::FlowFile& flow_file, const std::string& transitUri, const std::string& detail, std::chrono::milliseconds processingDuration) = 0; + virtual void receive(const core::FlowFile& flow_file, const std::string& transitUri, + const std::string& sourceSystemFlowFileIdentifier, const std::string& detail, std::chrono::milliseconds processingDuration) = 0; +}; + +} // namespace org::apache::nifi::minifi::provenance diff --git a/libminifi/include/utils/Export.h b/minifi-api/include/minifi-cpp/utils/Export.h similarity index 100% rename from libminifi/include/utils/Export.h rename to minifi-api/include/minifi-cpp/utils/Export.h diff --git a/libminifi/include/utils/FlatMap.h b/minifi-api/include/minifi-cpp/utils/FlatMap.h similarity index 100% rename from libminifi/include/utils/FlatMap.h rename to minifi-api/include/minifi-cpp/utils/FlatMap.h diff --git a/minifi-api/include/minifi-cpp/utils/Id.h b/minifi-api/include/minifi-cpp/utils/Id.h new file mode 100644 index 0000000000..5c435dcf92 --- /dev/null +++ b/minifi-api/include/minifi-cpp/utils/Id.h @@ -0,0 +1,75 @@ +/** + * 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 +#include +#include +#include +#include +#include +#include +#include + +#include "SmallString.h" + +namespace org::apache::nifi::minifi::utils { + +class Identifier { + friend struct IdentifierTestAccessor; + static constexpr const char* hex_lut = "0123456789abcdef"; + + public: + using Data = std::array; + + Identifier() = default; + explicit Identifier(const Data& data); + Identifier &operator=(const Data& data); + + Identifier &operator=(const std::string& idStr); + + explicit operator bool() const { + return !isNil(); + } + + bool operator!=(const Identifier& other) const; + bool operator==(const Identifier& other) const; + bool operator<(const Identifier& other) const; + + bool isNil() const; + + // Numerous places query the string representation + // just to then forward the temporary to build logs, + // streams, or others. Dynamically allocating in these + // instances is wasteful as we immediately discard + // the result. The difference on the test machine is 8x, + // building the representation itself takes 10ns, while + // subsequently turning it into a std::string would take + // 70ns more. + SmallString<36> to_string() const; + + static std::optional parse(const std::string& str); + + private: + friend struct ::std::hash; + + static bool parseByte(Data& data, const uint8_t* input, int& charIdx, int& byteIdx); + + Data data_{}; +}; + +} // namespace org::apache::nifi::minifi::utils diff --git a/libminifi/include/utils/Literals.h b/minifi-api/include/minifi-cpp/utils/Literals.h similarity index 100% rename from libminifi/include/utils/Literals.h rename to minifi-api/include/minifi-cpp/utils/Literals.h diff --git a/libminifi/include/utils/PropertyErrors.h b/minifi-api/include/minifi-cpp/utils/PropertyErrors.h similarity index 94% rename from libminifi/include/utils/PropertyErrors.h rename to minifi-api/include/minifi-cpp/utils/PropertyErrors.h index 85474a55dd..4fafed8ae6 100644 --- a/libminifi/include/utils/PropertyErrors.h +++ b/minifi-api/include/minifi-cpp/utils/PropertyErrors.h @@ -16,8 +16,7 @@ * limitations under the License. */ -#ifndef LIBMINIFI_INCLUDE_UTILS_PROPERTYERRORS_H_ -#define LIBMINIFI_INCLUDE_UTILS_PROPERTYERRORS_H_ +#pragma once #include @@ -89,5 +88,3 @@ class RequiredPropertyMissingException : public PropertyException { } /* namespace nifi */ } /* namespace apache */ } /* namespace org */ - -#endif // LIBMINIFI_INCLUDE_UTILS_PROPERTYERRORS_H_ diff --git a/libminifi/include/utils/SmallString.h b/minifi-api/include/minifi-cpp/utils/SmallString.h similarity index 84% rename from libminifi/include/utils/SmallString.h rename to minifi-api/include/minifi-cpp/utils/SmallString.h index edf9466d20..a92d13b5a3 100644 --- a/libminifi/include/utils/SmallString.h +++ b/minifi-api/include/minifi-cpp/utils/SmallString.h @@ -89,18 +89,3 @@ class SmallString : public std::array { }; } // namespace org::apache::nifi::minifi::utils - -template -struct fmt::formatter> { - formatter string_view_formatter; - - template - constexpr auto parse(ParseContext& ctx) { - return string_view_formatter.parse(ctx); - } - - template - auto format(const org::apache::nifi::minifi::utils::SmallString& small_string, FormatContext& ctx) const { - return string_view_formatter.format(small_string.view(), ctx); - } -}; diff --git a/minifi-api/include/minifi-cpp/utils/TimeUtil.h b/minifi-api/include/minifi-cpp/utils/TimeUtil.h new file mode 100644 index 0000000000..6969261e64 --- /dev/null +++ b/minifi-api/include/minifi-cpp/utils/TimeUtil.h @@ -0,0 +1,55 @@ +/** + * 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 +#include + +namespace org::apache::nifi::minifi::utils::timeutils { + +class Clock { + public: + virtual ~Clock() = default; + virtual std::chrono::milliseconds timeSinceEpoch() const = 0; + virtual bool wait_until(std::condition_variable& cv, std::unique_lock& lck, std::chrono::milliseconds time, const std::function& pred) { + return cv.wait_for(lck, time - timeSinceEpoch(), pred); + } +}; + +class SteadyClock : public Clock { + public: + std::chrono::milliseconds timeSinceEpoch() const override { + return std::chrono::duration_cast(std::chrono::steady_clock::now().time_since_epoch()); + } + + virtual std::chrono::time_point now() const { + return std::chrono::steady_clock::now(); + } +}; + +std::shared_ptr getClock(); + +// test-only utility to specify what clock to use +void setClock(std::shared_ptr clock); + +#ifdef WIN32 +void dateSetGlobalInstall(const std::string& install); +#endif + +} // namespace org::apache::nifi::minifi::utils::timeutils + diff --git a/libminifi/include/utils/gsl.h b/minifi-api/include/minifi-cpp/utils/gsl.h similarity index 100% rename from libminifi/include/utils/gsl.h rename to minifi-api/include/minifi-cpp/utils/gsl.h diff --git a/minifi_main/AgentDocs.cpp b/minifi_main/AgentDocs.cpp index 237bb4d98f..97a609dd4a 100644 --- a/minifi_main/AgentDocs.cpp +++ b/minifi_main/AgentDocs.cpp @@ -33,6 +33,7 @@ #include "agent/agent_version.h" #include "core/Core.h" #include "core/PropertyValue.h" +#include "core/PropertyType.h" #include "core/Relationship.h" #include "TableFormatter.h" #include "utils/file/FileUtils.h" diff --git a/minifi_main/CMakeLists.txt b/minifi_main/CMakeLists.txt index 62eb234f6e..47a4ab6699 100644 --- a/minifi_main/CMakeLists.txt +++ b/minifi_main/CMakeLists.txt @@ -65,7 +65,7 @@ endif() get_property(extensions GLOBAL PROPERTY EXTENSION-OPTIONS) include(ArgParse) -target_link_libraries(minifiexe spdlog libsodium gsl-lite argparse ${LIBMINIFI}) +target_link_libraries(minifiexe spdlog libsodium gsl-lite argparse core-minifi) set_target_properties(minifiexe PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin") set_target_properties(minifiexe PROPERTIES OUTPUT_NAME minifi) diff --git a/minifi_main/MiNiFiMain.cpp b/minifi_main/MiNiFiMain.cpp index f2b66df40f..2297048f8f 100644 --- a/minifi_main/MiNiFiMain.cpp +++ b/minifi_main/MiNiFiMain.cpp @@ -313,7 +313,7 @@ int main(int argc, char **argv) { logger_configuration.initialize(log_properties); - std::shared_ptr uid_properties = std::make_shared("UID properties"); + std::shared_ptr uid_properties = std::make_shared("UID properties"); uid_properties->setHome(minifiHome); uid_properties->loadConfigureFile(DEFAULT_UID_PROPERTIES_FILE); utils::IdGenerator::getIdGenerator()->initialize(uid_properties); @@ -328,12 +328,12 @@ int main(int argc, char **argv) { logger->log_info("No encryption key found, will not decrypt sensitive properties in the configuration"); } - const std::shared_ptr configure = std::make_shared(std::move(decryptor), std::move(log_properties)); + const std::shared_ptr configure = std::make_shared(std::move(decryptor), std::move(log_properties)); configure->setHome(minifiHome); configure->loadConfigureFile(DEFAULT_NIFI_PROPERTIES_FILE); overridePropertiesFromCommandLine(argument_parser, configure); - minifi::core::extension::ExtensionManager::get().initialize(configure); + minifi::core::extension::ExtensionManagerImpl::get().initialize(configure); dumpDocsIfRequested(argument_parser, configure); writeSchemaIfRequested(argument_parser, configure); diff --git a/utils/CMakeLists.txt b/utils/CMakeLists.txt new file mode 100644 index 0000000000..6a763a5561 --- /dev/null +++ b/utils/CMakeLists.txt @@ -0,0 +1,22 @@ +file(GLOB SOURCES + src/*.cpp + src/core/*.cpp + src/core/extension/*.cpp + src/io/*.cpp + src/http/*.cpp + src/utils/*.cpp + src/utils/crypto/*.cpp + src/utils/crypto/ciphers/*.cpp + src/utils/crypto/property_encryption/*.cpp + src/utils/net/*.cpp + src/utils/file/*.cpp) + +add_minifi_library(minifi-utils STATIC ${SOURCES}) +target_include_directories(minifi-utils PUBLIC include) +target_link_libraries(minifi-utils PUBLIC minifi-core ZLIB::ZLIB concurrentqueue RapidJSON spdlog Threads::Threads gsl-lite libsodium range-v3 expected-lite date::date date::tz asio magic_enum OpenSSL::Crypto OpenSSL::SSL CURL::libcurl RapidJSON) +if(NOT WIN32) + target_link_libraries(minifi-utils PUBLIC OSSP::libuuid++) +endif() +if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 9) + target_link_libraries(minifi-utils PUBLIC stdc++fs) +endif() \ No newline at end of file diff --git a/utils/include/Exception.h b/utils/include/Exception.h new file mode 100644 index 0000000000..bf45da7243 --- /dev/null +++ b/utils/include/Exception.h @@ -0,0 +1,21 @@ +/** + * + * 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 "minifi-cpp/Exception.h" \ No newline at end of file diff --git a/utils/include/SwapManager.h b/utils/include/SwapManager.h new file mode 100644 index 0000000000..21c4c28639 --- /dev/null +++ b/utils/include/SwapManager.h @@ -0,0 +1,21 @@ +/** + * + * 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 "minifi-cpp/SwapManager.h" diff --git a/libminifi/include/agent/agent_docs.h b/utils/include/agent/agent_docs.h similarity index 56% rename from libminifi/include/agent/agent_docs.h rename to utils/include/agent/agent_docs.h index a234478c35..2073b8e9c3 100644 --- a/libminifi/include/agent/agent_docs.h +++ b/utils/include/agent/agent_docs.h @@ -16,52 +16,18 @@ */ #pragma once +#include "minifi-cpp/agent/agent_docs.h" + #include #include #include #include -#include "core/Annotation.h" -#include "core/DynamicProperty.h" -#include "core/OutputAttributeDefinition.h" -#include "core/Property.h" -#include "core/PropertyDefinition.h" -#include "core/Relationship.h" -#include "core/RelationshipDefinition.h" -#include "utils/Export.h" #include "utils/StringUtils.h" +#include "core/ClassName.h" namespace org::apache::nifi::minifi { -enum class ResourceType { - Processor, ControllerService, InternalResource, DescriptionOnly -}; - -struct ClassDescription { - ResourceType type_ = ResourceType::Processor; - std::string short_name_{}; - std::string full_name_{}; - std::string description_{}; - std::vector class_properties_{}; - std::span dynamic_properties_{}; - std::vector class_relationships_{}; - std::span output_attributes_{}; - bool supports_dynamic_properties_ = false; - bool supports_dynamic_relationships_ = false; - std::string inputRequirement_{}; - bool isSingleThreaded_ = false; -}; - -struct Components { - std::vector processors_; - std::vector controller_services_; - std::vector other_components_; - - [[nodiscard]] bool empty() const noexcept { - return processors_.empty() && controller_services_.empty() && other_components_.empty(); - } -}; - namespace detail { inline auto toVector(std::span properties) { return std::vector(properties.begin(), properties.end()); @@ -78,21 +44,12 @@ std::string classNameWithDots() { } } // namespace detail -class AgentDocs { - private: - MINIFIAPI static std::map class_mappings_; - - public: - static const std::map& getClassDescriptions() { - return class_mappings_; - } +template +void AgentDocs::createClassDescription(const std::string& group, const std::string& name) { + Components& components = getMutableClassDescriptions()[group]; - template - static void createClassDescription(const std::string& group, const std::string& name) { - Components& components = class_mappings_[group]; - - if constexpr (Type == ResourceType::Processor) { - components.processors_.push_back(ClassDescription{ + if constexpr (Type == ResourceType::Processor) { + components.processors_.push_back(ClassDescription{ .type_ = Type, .short_name_ = name, .full_name_ = detail::classNameWithDots(), @@ -105,33 +62,32 @@ class AgentDocs { .supports_dynamic_relationships_ = Class::SupportsDynamicRelationships, .inputRequirement_ = toString(Class::InputRequirement), .isSingleThreaded_ = Class::IsSingleThreaded - }); - } else if constexpr (Type == ResourceType::ControllerService) { - components.controller_services_.push_back(ClassDescription{ + }); + } else if constexpr (Type == ResourceType::ControllerService) { + components.controller_services_.push_back(ClassDescription{ .type_ = Type, .short_name_ = name, .full_name_ = detail::classNameWithDots(), .description_ = Class::Description, .class_properties_ = detail::toVector(Class::Properties), .supports_dynamic_properties_ = Class::SupportsDynamicProperties, - }); - } else if constexpr (Type == ResourceType::InternalResource) { - components.other_components_.push_back(ClassDescription{ + }); + } else if constexpr (Type == ResourceType::InternalResource) { + components.other_components_.push_back(ClassDescription{ .type_ = Type, .short_name_ = name, .full_name_ = detail::classNameWithDots(), .class_properties_ = detail::toVector(Class::Properties), .supports_dynamic_properties_ = Class::SupportsDynamicProperties, - }); - } else if constexpr (Type == ResourceType::DescriptionOnly) { - components.other_components_.push_back(ClassDescription{ + }); + } else if constexpr (Type == ResourceType::DescriptionOnly) { + components.other_components_.push_back(ClassDescription{ .type_ = Type, .short_name_ = name, .full_name_ = detail::classNameWithDots(), .description_ = Class::Description - }); - } + }); } -}; +} } // namespace org::apache::nifi::minifi diff --git a/utils/include/agent/agent_version.h b/utils/include/agent/agent_version.h new file mode 100644 index 0000000000..6f739203bf --- /dev/null +++ b/utils/include/agent/agent_version.h @@ -0,0 +1,19 @@ +/** + * 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 "minifi-cpp/agent/agent_version.h" diff --git a/utils/include/core/Annotation.h b/utils/include/core/Annotation.h new file mode 100644 index 0000000000..9b729f880e --- /dev/null +++ b/utils/include/core/Annotation.h @@ -0,0 +1,20 @@ +/** + * 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 "minifi-cpp/core/Annotation.h" diff --git a/libminifi/include/core/BufferedContentSession.h b/utils/include/core/BufferedContentSession.h similarity index 96% rename from libminifi/include/core/BufferedContentSession.h rename to utils/include/core/BufferedContentSession.h index 510a64c1dd..97ca2f6097 100644 --- a/libminifi/include/core/BufferedContentSession.h +++ b/utils/include/core/BufferedContentSession.h @@ -20,7 +20,6 @@ #include #include -#include "ResourceClaim.h" #include "io/BaseStream.h" #include "ContentSession.h" @@ -33,7 +32,7 @@ class ContentRepository; * Atomicity is NOT guaranteed in this implementation, override commit if needed. * Rollback is possible. */ -class BufferedContentSession : public ContentSession { +class BufferedContentSession : public ContentSessionImpl { public: explicit BufferedContentSession(std::shared_ptr repository); diff --git a/utils/include/core/ClassLoader.h b/utils/include/core/ClassLoader.h new file mode 100644 index 0000000000..fc6cba0431 --- /dev/null +++ b/utils/include/core/ClassLoader.h @@ -0,0 +1,48 @@ +/** + * 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 "minifi-cpp/core/ClassLoader.h" +#include "utils/GeneralUtils.h" +#include "ObjectFactory.h" + +namespace org::apache::nifi::minifi::core { + +template +std::unique_ptr ClassLoader::instantiate(const std::string &class_name, const std::string &name) { + return utils::dynamic_unique_cast(instantiate(class_name, name, [] (CoreComponent* obj) -> bool { + return dynamic_cast(obj) != nullptr; + })); +} + +template +std::unique_ptr ClassLoader::instantiate(const std::string &class_name, const utils::Identifier &uuid) { + return utils::dynamic_unique_cast(instantiate(class_name, uuid, [] (CoreComponent* obj) -> bool { + return dynamic_cast(obj) != nullptr; + })); +} + +template +T *ClassLoader::instantiateRaw(const std::string &class_name, const std::string &name) { + return dynamic_cast(instantiateRaw(class_name, name, [] (CoreComponent* obj) -> bool { + return dynamic_cast(obj) != nullptr; + })); +} + + +} // namespace org::apache::nifi::minifi::core diff --git a/libminifi/include/core/Core.h b/utils/include/core/ClassName.h similarity index 50% rename from libminifi/include/core/Core.h rename to utils/include/core/ClassName.h index 5f48dac1df..efeb9fdd44 100644 --- a/libminifi/include/core/Core.h +++ b/utils/include/core/ClassName.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,61 +14,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#pragma once - -#ifndef WIN32_LEAN_AND_MEAN -#define WIN32_LEAN_AND_MEAN 1 -#endif - -#include -#include -#include -#include -#include -#include - -#ifdef WIN32 -#pragma comment(lib, "shlwapi.lib") -#endif - -#if defined _WIN32 || defined __CYGWIN__ -#ifdef BUILDING_DLL -#ifdef __GNUC__ -#define DLL_PUBLIC __attribute__ ((dllexport)) -#else -#define DLL_PUBLIC __declspec(dllexport) // Note: actually gcc seems to also supports this syntax. -#endif -#else -#ifdef __GNUC__ -#define DLL_PUBLIC __attribute__ ((dllimport)) -#else -#define DLL_PUBLIC __declspec(dllimport) // Note: actually gcc seems to also supports this syntax. -#endif -#endif -#define DLL_LOCAL -#else -#if __GNUC__ >= 4 -#define DLL_PUBLIC __attribute__ ((visibility ("default"))) -#define DLL_LOCAL __attribute__ ((visibility ("hidden"))) -#else -#define DLL_PUBLIC -#define DLL_LOCAL -#endif -#endif -#ifdef _WIN32 -#ifndef WIN32_LEAN_AND_MEAN -#define WIN32_LEAN_AND_MEAN 1 -#endif -// can't include cxxabi -#else -#include -#endif +#pragma once #include "utils/ArrayUtils.h" -#include "utils/Id.h" -#include "properties/Configure.h" -#include "utils/StringUtils.h" #if defined(_MSC_VER) constexpr std::string_view removeStructOrClassPrefix(std::string_view input) { @@ -127,70 +75,4 @@ constexpr std::string_view className() { return utils::array_to_string_view(TypeNameHolder>::value); } -template -std::unique_ptr instantiate(const std::string name = {}) { - if (name.empty()) { - return std::make_unique(); - } else { - return std::make_unique(name); - } -} - -/** - * Base component within MiNiFi - * Purpose: Many objects store a name and UUID, therefore - * the functionality is localized here to avoid duplication - */ -class CoreComponent { - public: - explicit CoreComponent(std::string_view name, const utils::Identifier &uuid = {}, const std::shared_ptr &idGenerator = utils::IdGenerator::getIdGenerator()); - CoreComponent(const CoreComponent &other) = default; - CoreComponent(CoreComponent &&other) = default; - CoreComponent& operator=(const CoreComponent&) = default; - CoreComponent& operator=(CoreComponent&&) = default; - - virtual ~CoreComponent() = default; - - // Get component name - [[nodiscard]] virtual std::string getName() const; - - /** - * Set name. - * @param name - */ - virtual void setName(std::string name); - - /** - * Set UUID in this instance - * @param uuid uuid to apply to the internal representation. - */ - virtual void setUUID(const utils::Identifier& uuid); - - /** - * Returns the UUID. - * @return the uuid of the component - */ - [[nodiscard]] utils::Identifier getUUID() const; - - /** - * Return the UUID string - */ - [[nodiscard]] utils::SmallString<36> getUUIDStr() const { - return uuid_.to_string(); - } - - virtual void configure(const std::shared_ptr& /*configuration*/) { - } - - void loadComponent() { - } - - protected: - // A global unique identifier - utils::Identifier uuid_; - - // CoreComponent's name - std::string name_; -}; - } // namespace org::apache::nifi::minifi::core diff --git a/libminifi/include/core/ConfigurableComponent.h b/utils/include/core/ConfigurableComponent.h similarity index 57% rename from libminifi/include/core/ConfigurableComponent.h rename to utils/include/core/ConfigurableComponent.h index 56e518fcd4..e582f91331 100644 --- a/libminifi/include/core/ConfigurableComponent.h +++ b/utils/include/core/ConfigurableComponent.h @@ -20,16 +20,17 @@ #include #include -#include "Core.h" +#include "core/Core.h" #include #include #include #include -#include "logging/Logger.h" -#include "Property.h" -#include "PropertyDefinition.h" +#include "minifi-cpp/core/logging/Logger.h" +#include "minifi-cpp/core/Property.h" #include "utils/gsl.h" +#include "minifi-cpp/core/ConfigurableComponent.h" +#include "core/TypedValues.h" namespace org::apache::nifi::minifi::core { @@ -37,61 +38,45 @@ namespace org::apache::nifi::minifi::core { * Represents a configurable component * Purpose: Extracts configuration items for all components and localized them */ -class ConfigurableComponent { +class ConfigurableComponentImpl : public virtual ConfigurableComponent { public: - ConfigurableComponent(); + ConfigurableComponentImpl(); - ConfigurableComponent(const ConfigurableComponent &other) = delete; - ConfigurableComponent(ConfigurableComponent &&other) = delete; + ConfigurableComponentImpl(const ConfigurableComponentImpl &other) = delete; + ConfigurableComponentImpl(ConfigurableComponentImpl &&other) = delete; - ConfigurableComponent& operator=(const ConfigurableComponent &other) = delete; - ConfigurableComponent& operator=(ConfigurableComponent &&other) = delete; + ConfigurableComponentImpl& operator=(const ConfigurableComponentImpl &other) = delete; + ConfigurableComponentImpl& operator=(ConfigurableComponentImpl &&other) = delete; - /** - * Get property using the provided name. - * @param name property name. - * @param value value passed in by reference - * @return result of getting property. - */ - template - bool getProperty(const std::string& name, T &value) const; - - template - bool getProperty(const core::PropertyReference& property, T& value) const { return getProperty(std::string{property.name}, value); } - - template requires(std::is_default_constructible_v) - std::optional getProperty(const std::string& property_name) const { - T value; - try { - if (!getProperty(property_name, value)) return std::nullopt; - } catch (const utils::internal::ValueException&) { - return std::nullopt; - } - return value; - } + using ConfigurableComponent::getProperty; - template requires(std::is_default_constructible_v) - std::optional getProperty(const core::PropertyReference& property) const { return getProperty(std::string(property.name)); } + bool getProperty(const std::string& name, uint64_t& value) const override {return getPropertyImpl(name, value);} + bool getProperty(const std::string& name, int64_t& value) const override {return getPropertyImpl(name, value);} + bool getProperty(const std::string& name, uint32_t& value) const override {return getPropertyImpl(name, value);} + bool getProperty(const std::string& name, int& value) const override {return getPropertyImpl(name, value);} + bool getProperty(const std::string& name, bool& value) const override {return getPropertyImpl(name, value);} + bool getProperty(const std::string& name, double& value) const override {return getPropertyImpl(name, value);} + bool getProperty(const std::string& name, std::string& value) const override {return getPropertyImpl(name, value);} /** * Provides a reference for the property. */ - bool getProperty(const std::string &name, Property &prop) const; + bool getProperty(const std::string &name, Property &prop) const override; /** * Sets the property using the provided name * @param property name * @param value property value. * @return result of setting property. */ - bool setProperty(const std::string& name, const std::string& value); + bool setProperty(const std::string& name, const std::string& value) override; /** * Updates the Property from the key (name), adding value * to the collection of values within the Property. */ - bool updateProperty(const std::string &name, const std::string &value); + bool updateProperty(const std::string &name, const std::string &value) override; - bool updateProperty(const PropertyReference& property, std::string_view value); + bool updateProperty(const PropertyReference& property, std::string_view value) override; /** * Sets the property using the provided name @@ -99,9 +84,9 @@ class ConfigurableComponent { * @param value property value. * @return whether property was set or not */ - bool setProperty(const Property& prop, const std::string& value); + bool setProperty(const Property& prop, const std::string& value) override; - bool setProperty(const PropertyReference& property, std::string_view value); + bool setProperty(const PropertyReference& property, std::string_view value) override; /** * Sets the property using the provided name @@ -109,7 +94,7 @@ class ConfigurableComponent { * @param value property value. * @return whether property was set or not */ - bool setProperty(const Property& prop, PropertyValue &value); + bool setProperty(const Property& prop, PropertyValue &value) override; void setSupportedProperties(std::span properties); @@ -118,14 +103,14 @@ class ConfigurableComponent { * * @return true if this component supports dynamic properties (default is false) */ - virtual bool supportsDynamicProperties() const = 0; + bool supportsDynamicProperties() const override = 0; /** * Gets whether or not this processor supports dynamic relationships. * * @return true if this component supports dynamic relationships (default is false) */ - virtual bool supportsDynamicRelationships() const = 0; + bool supportsDynamicRelationships() const override = 0; /** * Gets the value of a dynamic property (if it was set). @@ -134,9 +119,9 @@ class ConfigurableComponent { * @param value * @return */ - bool getDynamicProperty(const std::string& name, std::string &value) const; + bool getDynamicProperty(const std::string& name, std::string &value) const override; - bool getDynamicProperty(const std::string& name, core::Property &item) const; + bool getDynamicProperty(const std::string& name, core::Property &item) const override; /** * Sets the value of a new dynamic property. @@ -145,7 +130,7 @@ class ConfigurableComponent { * @param value * @return */ - bool setDynamicProperty(const std::string& name, const std::string& value); + bool setDynamicProperty(const std::string& name, const std::string& value) override; /** * Updates the value of an existing dynamic property. @@ -154,18 +139,18 @@ class ConfigurableComponent { * @param value * @return */ - bool updateDynamicProperty(const std::string &name, const std::string &value); + bool updateDynamicProperty(const std::string &name, const std::string &value) override; /** * Invoked anytime a static property is modified */ - virtual void onPropertyModified(const Property& /*old_property*/, const Property& /*new_property*/) { + void onPropertyModified(const Property& /*old_property*/, const Property& /*new_property*/) override { } /** * Invoked anytime a dynamic property is modified. */ - virtual void onDynamicPropertyModified(const Property& /*old_property*/, const Property& /*new_property*/) { + void onDynamicPropertyModified(const Property& /*old_property*/, const Property& /*new_property*/) override { } /** @@ -173,24 +158,24 @@ class ConfigurableComponent { * * @return vector of property keys */ - std::vector getDynamicPropertyKeys() const; + std::vector getDynamicPropertyKeys() const override; /** * Returns a vector all properties * * @return map of property keys to Property instances. */ - virtual std::map getProperties() const; + std::map getProperties() const override; /** * @return if property exists and is explicitly set, not just falling back to default value */ - bool isPropertyExplicitlySet(const Property&) const; - bool isPropertyExplicitlySet(const PropertyReference&) const; + bool isPropertyExplicitlySet(const Property&) const override; + bool isPropertyExplicitlySet(const PropertyReference&) const override; - virtual ~ConfigurableComponent(); + ~ConfigurableComponentImpl() override; - virtual void initialize() { + void initialize() override { } protected: @@ -202,7 +187,7 @@ class ConfigurableComponent { * Returns true if the instance can be edited. * @return true/false */ - virtual bool canEdit() = 0; + bool canEdit() override = 0; mutable std::mutex configuration_mutex_; @@ -217,6 +202,9 @@ class ConfigurableComponent { virtual const Property* findProperty(const std::string& name) const; private: + template + bool getPropertyImpl(const std::string& name, T &value) const; + Property* findProperty(const std::string& name); std::shared_ptr logger_; @@ -224,7 +212,7 @@ class ConfigurableComponent { }; template -bool ConfigurableComponent::getProperty(const std::string& name, T &value) const { +bool ConfigurableComponentImpl::getPropertyImpl(const std::string& name, T &value) const { std::lock_guard lock(configuration_mutex_); const auto prop_ptr = findProperty(name); @@ -241,11 +229,7 @@ bool ConfigurableComponent::getProperty(const std::string& name, T &value) const } logger_->log_debug("Component {} property name {} value {}", name, property.getName(), property.getValue().to_string()); - if constexpr (std::is_base_of::value) { - value = T(property.getValue().operator std::string()); - } else { - value = static_cast(property.getValue()); // cast throws if the value is invalid - } + value = static_cast(property.getValue()); // cast throws if the value is invalid return true; } else { logger_->log_warn("Could not find property {}", name); @@ -253,4 +237,49 @@ bool ConfigurableComponent::getProperty(const std::string& name, T &value) const } } +template +bool ConfigurableComponent::getProperty(const std::string& name, T& value) const { + if constexpr (std::is_base_of::value) { + std::string prop_str; + if (!getProperty(name, prop_str)) { + return false; + } + value = T(std::move(prop_str)); + return true; + } else { + return getProperty(name, value); + } +} + +template +bool ConfigurableComponent::getProperty(const std::string& name, std::optional& value) const { + T raw_value; + if (getProperty(name, raw_value)) { + value = raw_value; + return true; + } + return false; +} + +template +bool ConfigurableComponent::getProperty(const core::PropertyReference& property, T& value) const { + return getProperty(std::string{property.name}, value); +} + +template requires(std::is_default_constructible_v) +std::optional ConfigurableComponent::getProperty(const std::string& property_name) const { + T value; + try { + if (!getProperty(property_name, value)) return std::nullopt; + } catch (const utils::internal::ValueException&) { + return std::nullopt; + } + return value; +} + +template requires(std::is_default_constructible_v) +std::optional ConfigurableComponent::getProperty(const core::PropertyReference& property) const { + return getProperty(std::string(property.name)); +} + } // namespace org::apache::nifi::minifi::core diff --git a/libminifi/include/core/Connectable.h b/utils/include/core/Connectable.h similarity index 70% rename from libminifi/include/core/Connectable.h rename to utils/include/core/Connectable.h index 82311720b1..6b402a1843 100644 --- a/libminifi/include/core/Connectable.h +++ b/utils/include/core/Connectable.h @@ -28,12 +28,13 @@ #include "Core.h" #include -#include "core/logging/Logger.h" -#include "Relationship.h" -#include "RelationshipDefinition.h" -#include "Scheduling.h" -#include "core/state/FlowIdentifier.h" +#include "minifi-cpp/core/logging/Logger.h" +#include "minifi-cpp/core/Relationship.h" +#include "minifi-cpp/core/RelationshipDefinition.h" +#include "minifi-cpp/core/Scheduling.h" +#include "minifi-cpp/core/state/FlowIdentifier.h" #include "utils/gsl.h" +#include "minifi-cpp/core/Connectable.h" namespace org::apache::nifi::minifi::core { @@ -44,30 +45,30 @@ class FlowFile; * Purpose: As in NiFi, this represents a connection point and allows the derived * object to be connected to other connectables. */ -class Connectable : public CoreComponent { +class ConnectableImpl : public CoreComponentImpl, public virtual Connectable { public: - explicit Connectable(std::string_view name); + explicit ConnectableImpl(std::string_view name); - explicit Connectable(std::string_view name, const utils::Identifier &uuid); + explicit ConnectableImpl(std::string_view name, const utils::Identifier &uuid); - Connectable(const Connectable &other) = delete; - Connectable(Connectable &&other) = delete; + ConnectableImpl(const ConnectableImpl &other) = delete; + ConnectableImpl(ConnectableImpl &&other) = delete; - Connectable& operator=(const Connectable &other) = delete; - Connectable& operator=(Connectable&& other) = delete; + ConnectableImpl& operator=(const ConnectableImpl &other) = delete; + ConnectableImpl& operator=(ConnectableImpl&& other) = delete; void setSupportedRelationships(std::span relationships); - bool isSupportedRelationship(const Relationship &relationship); + bool isSupportedRelationship(const Relationship &relationship) override; - std::vector getSupportedRelationships() const; + std::vector getSupportedRelationships() const override; - void addAutoTerminatedRelationship(const core::Relationship& relationship); - void setAutoTerminatedRelationships(std::span relationships); + void addAutoTerminatedRelationship(const core::Relationship& relationship) override; + void setAutoTerminatedRelationships(std::span relationships) override; - bool isAutoTerminated(const Relationship &relationship); + bool isAutoTerminated(const Relationship &relationship) override; - std::chrono::milliseconds getPenalizationPeriod() const { + std::chrono::milliseconds getPenalizationPeriod() const override { return penalization_period_; } @@ -75,12 +76,12 @@ class Connectable : public CoreComponent { * Get outgoing connection based on relationship * @return set of outgoing connections. */ - virtual std::set getOutGoingConnections(const std::string &relationship); + std::set getOutGoingConnections(const std::string &relationship) override; - virtual void put(const std::shared_ptr& /*flow*/) { + void put(const std::shared_ptr& /*flow*/) override { } - virtual void restore(const std::shared_ptr& file) { + void restore(const std::shared_ptr& file) override { put(file); } @@ -88,57 +89,57 @@ class Connectable : public CoreComponent { * Gets and sets next incoming connection * @return next incoming connection */ - Connectable* getNextIncomingConnection(); + Connectable* getNextIncomingConnection() override; - virtual Connectable* pickIncomingConnection(); + Connectable* pickIncomingConnection() override; /** * @return true if incoming connections > 0 */ - bool hasIncomingConnections() const { + bool hasIncomingConnections() const override { return !incoming_connections_.empty(); } - uint8_t getMaxConcurrentTasks() const { + uint8_t getMaxConcurrentTasks() const override { return max_concurrent_tasks_; } - virtual void setMaxConcurrentTasks(uint8_t tasks) { + void setMaxConcurrentTasks(uint8_t tasks) override { max_concurrent_tasks_ = tasks; } /** * Yield */ - virtual void yield() = 0; + void yield() override = 0; - ~Connectable() override; + ~ConnectableImpl() override; /** * Determines if we are connected and operating */ - virtual bool isRunning() const = 0; + bool isRunning() const override = 0; /** * Block until work is available on any input connection, or the given duration elapses * @param timeoutMs timeout in milliseconds */ - void waitForWork(std::chrono::milliseconds timeout); + void waitForWork(std::chrono::milliseconds timeout) override; /** * Notify this processor that work may be available */ - void notifyWork(); + void notifyWork() override; /** * Determines if work is available by this connectable * @return boolean if work is available. */ - virtual bool isWorkAvailable() = 0; + bool isWorkAvailable() override = 0; /** * Sets the flow version for this connectable. */ - void setFlowIdentifier(const std::shared_ptr &version) { + void setFlowIdentifier(const std::shared_ptr &version) override { connectable_version_ = version; } @@ -146,7 +147,7 @@ class Connectable : public CoreComponent { * Returns theflow version * @returns flow version. can be null if a flow version is not tracked. */ - virtual std::shared_ptr getFlowIdentifier() const { + std::shared_ptr getFlowIdentifier() const override { return connectable_version_; } diff --git a/libminifi/include/core/ContentRepository.h b/utils/include/core/ContentRepository.h similarity index 70% rename from libminifi/include/core/ContentRepository.h rename to utils/include/core/ContentRepository.h index 15fc615dcc..ab9d975338 100644 --- a/libminifi/include/core/ContentRepository.h +++ b/utils/include/core/ContentRepository.h @@ -25,46 +25,38 @@ #include #include -#include "properties/Configure.h" -#include "ResourceClaim.h" #include "StreamManager.h" #include "ContentSession.h" -#include "core/RepositoryMetricsSource.h" #include "core/Core.h" +#include "minifi-cpp/core/ContentRepository.h" +#include "core/RepositoryMetricsSource.h" namespace org::apache::nifi::minifi::core { -/** - * Content repository definition that extends StreamManager. - */ -class ContentRepository : public core::CoreComponent, public StreamManager, public utils::EnableSharedFromThis, public core::RepositoryMetricsSource { +class ContentRepositoryImpl : public CoreComponentImpl, public StreamManagerImpl, public RepositoryMetricsSourceImpl, public virtual ContentRepository { class ContentStreamAppendLock : public StreamAppendLock { public: - ContentStreamAppendLock(std::shared_ptr repository, const minifi::ResourceClaim& claim): repository_(std::move(repository)), content_path_(claim.getContentFullPath()) {} + ContentStreamAppendLock(std::shared_ptr repository, const minifi::ResourceClaim& claim): repository_(std::move(repository)), content_path_(claim.getContentFullPath()) {} ~ContentStreamAppendLock() override {repository_->unlockAppend(content_path_);} private: - std::shared_ptr repository_; + std::shared_ptr repository_; ResourceClaim::Path content_path_; }; public: - explicit ContentRepository(std::string_view name, const utils::Identifier& uuid = {}) : core::CoreComponent(name, uuid) {} - ~ContentRepository() override = default; - - virtual bool initialize(const std::shared_ptr &configure) = 0; + explicit ContentRepositoryImpl(std::string_view name, const utils::Identifier& uuid = {}) : core::CoreComponentImpl(name, uuid) {} + ~ContentRepositoryImpl() override = default; std::string getStoragePath() const override; - virtual std::shared_ptr createSession(); - void reset(); + std::shared_ptr createSession() override; + void reset() override; uint32_t getStreamCount(const minifi::ResourceClaim &streamId) override; void incrementStreamCount(const minifi::ResourceClaim &streamId) override; StreamState decrementStreamCount(const minifi::ResourceClaim &streamId) override; - virtual void clearOrphans() = 0; - - virtual void start() {} - virtual void stop() {} + void start() override {} + void stop() override {} bool remove(const minifi::ResourceClaim &streamId) final; diff --git a/utils/include/core/ContentSession.h b/utils/include/core/ContentSession.h new file mode 100644 index 0000000000..c07fd3b9d9 --- /dev/null +++ b/utils/include/core/ContentSession.h @@ -0,0 +1,54 @@ +/** + * + * 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 +#include +#include +#include "io/BaseStream.h" +#include "minifi-cpp/core/ContentSession.h" +#include "ContentRepository.h" + +namespace org::apache::nifi::minifi::core { + +class StreamAppendLock; +class ContentRepository; + +class ContentSessionImpl : public virtual ContentSession { + struct AppendState { + std::shared_ptr stream; + size_t base_size; + std::unique_ptr lock; + }; + + public: + explicit ContentSessionImpl(std::shared_ptr repository): repository_(std::move(repository)) {} + + std::shared_ptr append(const std::shared_ptr& resource_id, size_t offset, const std::function&)>& on_copy) override; + + protected: + virtual std::shared_ptr append(const std::shared_ptr& resource_id) = 0; + + // contains aux data on resources that have been appended to + std::map, AppendState> append_state_; + std::shared_ptr repository_; +}; + +} // namespace org::apache::nifi::minifi::core + diff --git a/utils/include/core/Core.h b/utils/include/core/Core.h new file mode 100644 index 0000000000..ddbd58fb38 --- /dev/null +++ b/utils/include/core/Core.h @@ -0,0 +1,123 @@ +/** + * + * 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 + +#ifndef WIN32_LEAN_AND_MEAN +#define WIN32_LEAN_AND_MEAN 1 +#endif + +#include +#include +#include +#include +#include +#include + +#ifdef WIN32 +#pragma comment(lib, "shlwapi.lib") +#endif + +#if defined _WIN32 || defined __CYGWIN__ +#ifdef BUILDING_DLL +#ifdef __GNUC__ +#define DLL_PUBLIC __attribute__ ((dllexport)) +#else +#define DLL_PUBLIC __declspec(dllexport) // Note: actually gcc seems to also supports this syntax. +#endif +#else +#ifdef __GNUC__ +#define DLL_PUBLIC __attribute__ ((dllimport)) +#else +#define DLL_PUBLIC __declspec(dllimport) // Note: actually gcc seems to also supports this syntax. +#endif +#endif +#define DLL_LOCAL +#else +#if __GNUC__ >= 4 +#define DLL_PUBLIC __attribute__ ((visibility ("default"))) +#define DLL_LOCAL __attribute__ ((visibility ("hidden"))) +#else +#define DLL_PUBLIC +#define DLL_LOCAL +#endif +#endif + +#ifdef _WIN32 +#ifndef WIN32_LEAN_AND_MEAN +#define WIN32_LEAN_AND_MEAN 1 +#endif +// can't include cxxabi +#else +#include +#endif + +#include "utils/ArrayUtils.h" +#include "utils/Id.h" +#include "minifi-cpp/properties/Configure.h" +#include "utils/StringUtils.h" +#include "minifi-cpp/core/Core.h" +#include "core/ClassName.h" + +namespace org::apache::nifi::minifi::core { + +template +std::unique_ptr instantiate(const std::string name = {}) { + if (name.empty()) { + return std::make_unique(); + } else { + return std::make_unique(name); + } +} + +/** + * Base component within MiNiFi + * Purpose: Many objects store a name and UUID, therefore + * the functionality is localized here to avoid duplication + */ +class CoreComponentImpl : public virtual CoreComponent { + public: + explicit CoreComponentImpl(std::string_view name, const utils::Identifier &uuid = {}, const std::shared_ptr &idGenerator = utils::IdGenerator::getIdGenerator()); + CoreComponentImpl(const CoreComponentImpl &other) = default; + CoreComponentImpl(CoreComponentImpl &&other) = default; + CoreComponentImpl& operator=(const CoreComponentImpl&) = default; + CoreComponentImpl& operator=(CoreComponentImpl&&) = default; + + ~CoreComponentImpl() override = default; + + [[nodiscard]] std::string getName() const override; + + void setName(std::string name) override; + + void setUUID(const utils::Identifier& uuid) override; + + [[nodiscard]] utils::Identifier getUUID() const override; + + [[nodiscard]] utils::SmallString<36> getUUIDStr() const override { + return uuid_.to_string(); + } + + void configure(const std::shared_ptr& /*configuration*/) override { + } + + protected: + // A global unique identifier + utils::Identifier uuid_; + std::string name_; +}; + +} // namespace org::apache::nifi::minifi::core diff --git a/libminifi/include/core/ObjectFactory.h b/utils/include/core/ObjectFactory.h similarity index 66% rename from libminifi/include/core/ObjectFactory.h rename to utils/include/core/ObjectFactory.h index 82ababb0a7..434caee9e1 100644 --- a/libminifi/include/core/ObjectFactory.h +++ b/utils/include/core/ObjectFactory.h @@ -20,7 +20,8 @@ #include #include #include -#include "Core.h" +#include "ClassName.h" +#include "minifi-cpp/core/ObjectFactory.h" namespace org { namespace apache { @@ -28,73 +29,33 @@ namespace nifi { namespace minifi { namespace core { -/** - * Factory that is used as an interface for - * creating processors from shared objects. - */ -class ObjectFactory { +class ObjectFactoryImpl : public ObjectFactory { public: - explicit ObjectFactory(std::string group) - : group_(std::move(group)) { - } - - ObjectFactory() = default; - - /** - * Virtual destructor. - */ - virtual ~ObjectFactory() = default; + explicit ObjectFactoryImpl(std::string group) : group_(std::move(group)) {} - /** - * Create a unique pointer to a new processor. - */ - virtual std::unique_ptr create(const std::string& /*name*/) { - return nullptr; - } + ObjectFactoryImpl() = default; - /** - * Create a raw pointer to a new processor. - */ - virtual CoreComponent *createRaw(const std::string& /*name*/) { - return nullptr; - } - - /** - * Create a unique pointer to a new processor. - */ - virtual std::unique_ptr create(const std::string& /*name*/, const utils::Identifier& /*uuid*/) { - return nullptr; - } - - /** - * Create a raw pointer to a new processor. - */ - virtual CoreComponent* createRaw(const std::string& /*name*/, const utils::Identifier& /*uuid*/) { - return nullptr; - } - - virtual std::string getGroupName() const { + std::string getGroupName() const override { return group_; } - virtual std::string getClassName() = 0; - - private: + protected: std::string group_; }; + /** * Factory that is used as an interface for * creating processors from shared objects. */ template -class DefaultObjectFactory : public ObjectFactory { +class DefaultObjectFactory : public ObjectFactoryImpl { public: DefaultObjectFactory() : className(core::className()) { } explicit DefaultObjectFactory(std::string group_name) - : ObjectFactory(std::move(group_name)), + : ObjectFactoryImpl(std::move(group_name)), className(core::className()) { } diff --git a/utils/include/core/OutputAttributeDefinition.h b/utils/include/core/OutputAttributeDefinition.h new file mode 100644 index 0000000000..e0b8af5699 --- /dev/null +++ b/utils/include/core/OutputAttributeDefinition.h @@ -0,0 +1,20 @@ +/** + * 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 "minifi-cpp/core/OutputAttributeDefinition.h" diff --git a/libminifi/include/core/ProcessContext.h b/utils/include/core/ProcessContext.h similarity index 70% rename from libminifi/include/core/ProcessContext.h rename to utils/include/core/ProcessContext.h index e1189e5748..5ed76c4327 100644 --- a/libminifi/include/core/ProcessContext.h +++ b/utils/include/core/ProcessContext.h @@ -28,56 +28,43 @@ #include #include -#include "controllers/keyvalue/KeyValueStateStorage.h" +#include "minifi-cpp/core/repository/FileSystemRepository.h" #include "core/Core.h" #include "core/ContentRepository.h" -#include "core/repository/FileSystemRepository.h" -#include "core/controller/ControllerServiceProvider.h" -#include "core/controller/ControllerServiceLookup.h" +#include "minifi-cpp/core/controller/ControllerServiceProvider.h" +#include "minifi-cpp/core/controller/ControllerServiceLookup.h" #include "core/logging/LoggerFactory.h" -#include "core/ProcessorNode.h" -#include "core/Property.h" -#include "core/PropertyDefinition.h" -#include "core/Repository.h" -#include "core/FlowFile.h" -#include "core/StateStorage.h" +#include "minifi-cpp/core/ProcessorNode.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 "core/VariableRegistry.h" -#include "utils/file/FileUtils.h" -#include "utils/PropertyErrors.h" +#include "minifi-cpp/core/ProcessContext.h" +#include "minifi-cpp/controllers/keyvalue/KeyValueStateStorage.h" +#include "core/ConfigurableComponent.h" namespace org::apache::nifi::minifi::core { -namespace detail { -template -concept NotAFlowFile = !std::convertible_to && !std::convertible_to &>; -} // namespace detail - -class ProcessContext : public core::VariableRegistry, public std::enable_shared_from_this { +class ProcessContextImpl : public core::VariableRegistryImpl, public virtual ProcessContext { public: - /*! - * Create a new process context associated with the processor/controller service/state manager - */ - ProcessContext(const std::shared_ptr &processor, controller::ControllerServiceProvider* controller_service_provider, const std::shared_ptr &repo, - const std::shared_ptr &flow_repo, const std::shared_ptr &content_repo = std::make_shared()) - : VariableRegistry(std::make_shared()), + ProcessContextImpl(const std::shared_ptr &processor, controller::ControllerServiceProvider* controller_service_provider, const std::shared_ptr &repo, + const std::shared_ptr &flow_repo, const std::shared_ptr &content_repo = repository::createFileSystemRepository()) + : VariableRegistryImpl(Configure::create()), controller_service_provider_(controller_service_provider), flow_repo_(flow_repo), content_repo_(content_repo), processor_node_(processor), logger_(logging::LoggerFactory::getLogger()), - configure_(std::make_shared()), + configure_(minifi::Configure::create()), initialized_(false) { repo_ = repo; state_storage_ = getStateStorage(logger_, controller_service_provider_, nullptr); } - /*! - * Create a new process context associated with the processor/controller service/state manager - */ - ProcessContext(const std::shared_ptr &processor, controller::ControllerServiceProvider* controller_service_provider, const std::shared_ptr &repo, - const std::shared_ptr &flow_repo, const std::shared_ptr &configuration, const std::shared_ptr &content_repo = - std::make_shared()) - : VariableRegistry(configuration), + ProcessContextImpl(const std::shared_ptr &processor, controller::ControllerServiceProvider* controller_service_provider, const std::shared_ptr &repo, + const std::shared_ptr &flow_repo, const std::shared_ptr &configuration, const std::shared_ptr &content_repo = repository::createFileSystemRepository()) + : VariableRegistryImpl(configuration), controller_service_provider_(controller_service_provider), flow_repo_(flow_repo), content_repo_(content_repo), @@ -88,128 +75,93 @@ class ProcessContext : public core::VariableRegistry, public std::enable_shared_ repo_ = repo; state_storage_ = getStateStorage(logger_, controller_service_provider_, configuration); if (!configure_) { - configure_ = std::make_shared(); + configure_ = minifi::Configure::create(); } } // Get Processor associated with the Process Context - std::shared_ptr getProcessorNode() const { + std::shared_ptr getProcessorNode() const override { return processor_node_; } - template - std::optional getProperty(const Property& property) const { - T value; - if (getProperty(property.getName(), value)) { - return value; - } - return std::nullopt; - } + using ProcessContext::getProperty; - template - std::optional getProperty(const PropertyReference& property) const { - T value; - if (getProperty(property.name, value)) { - return value; - } - return std::nullopt; - } + std::optional getProperty(const Property&, const FlowFile* const) override; - bool getProperty(std::string_view name, detail::NotAFlowFile auto& value) const { - return getPropertyImp(std::string{name}, value); - } + std::optional getProperty(const PropertyReference&, const FlowFile* const) override; - bool getProperty(const PropertyReference& property, detail::NotAFlowFile auto& value) const { - return getPropertyImp(std::string{property.name}, value); - } - - std::optional getProperty(const Property&, const FlowFile* const); - - std::optional getProperty(const PropertyReference&, const FlowFile* const); - - virtual bool getProperty(const Property &property, std::string &value, const FlowFile* const) { + bool getProperty(const Property &property, std::string &value, const FlowFile* const) override { return getProperty(property.getName(), value); } - virtual bool getProperty(const PropertyReference& property, std::string &value, const FlowFile* const) { + bool getProperty(const PropertyReference& property, std::string &value, const FlowFile* const) override { return getProperty(property.name, value); } - bool getDynamicProperty(const std::string &name, std::string &value) const { + bool getDynamicProperty(const std::string &name, std::string &value) const override { return processor_node_->getDynamicProperty(name, value); } - virtual bool getDynamicProperty(const Property &property, std::string &value, const FlowFile* const) { + bool getDynamicProperty(const Property &property, std::string &value, const FlowFile* const) override { return getDynamicProperty(property.getName(), value); } - std::vector getDynamicPropertyKeys() const { + std::vector getDynamicPropertyKeys() const override { return processor_node_->getDynamicPropertyKeys(); } - // Sets the property value using the property's string name - virtual bool setProperty(const std::string &name, std::string value) { + bool setProperty(const std::string &name, std::string value) override { return processor_node_->setProperty(name, value); - } // Sets the dynamic property value using the property's string name - virtual bool setDynamicProperty(const std::string &name, std::string value) { + } + bool setDynamicProperty(const std::string &name, std::string value) override { return processor_node_->setDynamicProperty(name, value); } - // Sets the property value using the Property object - bool setProperty(const Property& property, std::string value) { + bool setProperty(const Property& property, std::string value) override { return setProperty(property.getName(), value); } - bool setProperty(const PropertyReference& property, std::string_view value) { + bool setProperty(const PropertyReference& property, std::string_view value) override { return setProperty(std::string{property.name}, std::string{value}); } - // Check whether the relationship is auto terminated - bool isAutoTerminated(Relationship relationship) const { + bool isAutoTerminated(Relationship relationship) const override { return processor_node_->isAutoTerminated(relationship); } - // Get ProcessContext Maximum Concurrent Tasks - uint8_t getMaxConcurrentTasks() const { + uint8_t getMaxConcurrentTasks() const override { return processor_node_->getMaxConcurrentTasks(); } - // Yield based on the yield period - void yield() { + void yield() override { processor_node_->yield(); } - std::shared_ptr getProvenanceRepository() { + std::shared_ptr getProvenanceRepository() override { return repo_; } - /** - * Returns a reference to the content repository for the running instance. - * @return content repository shared pointer. - */ - std::shared_ptr getContentRepository() const { + std::shared_ptr getContentRepository() const override { return content_repo_; } - std::shared_ptr getFlowFileRepository() const { + std::shared_ptr getFlowFileRepository() const override { return flow_repo_; } - // Prevent default copy constructor and assignment operation - // Only support pass by reference or pointer - ProcessContext(const ProcessContext &parent) = delete; - ProcessContext &operator=(const ProcessContext &parent) = delete; + ProcessContextImpl(const ProcessContextImpl &parent) = delete; + ProcessContextImpl &operator=(const ProcessContextImpl &parent) = delete; - std::shared_ptr getControllerService(const std::string &identifier, const utils::Identifier &processor_uuid) const { + std::shared_ptr getControllerService(const std::string &identifier, const utils::Identifier &processor_uuid) const override { return controller_service_provider_ == nullptr ? nullptr : controller_service_provider_->getControllerService(identifier, processor_uuid); } - void initializeContentRepository(const std::string& home) { + void initializeContentRepository(const std::string& home) override { configure_->setHome(home); content_repo_->initialize(configure_); initialized_ = true; } - bool isInitialized() const { + bool isInitialized() const override { return initialized_; } static constexpr char const* DefaultStateStorageName = "defaultstatestorage"; - StateManager* getStateManager() { + StateManager* getStateManager() override { if (state_storage_ == nullptr) { return nullptr; } @@ -219,7 +171,7 @@ class ProcessContext : public core::VariableRegistry, public std::enable_shared_ return state_manager_.get(); } - bool hasStateManager() const { + bool hasStateManager() const override { return state_manager_ != nullptr; } @@ -335,7 +287,7 @@ class ProcessContext : public core::VariableRegistry, public std::enable_shared_ } } - std::shared_ptr getConfiguration() const { + std::shared_ptr getConfiguration() const override { return configure_; } @@ -357,16 +309,42 @@ class ProcessContext : public core::VariableRegistry, public std::enable_shared_ bool initialized_; }; -inline std::optional ProcessContext::getProperty(const Property& property, const FlowFile* const flow_file) { +inline std::optional ProcessContextImpl::getProperty(const Property& property, const FlowFile* const flow_file) { std::string value; if (!getProperty(property, value, flow_file)) return std::nullopt; return value; } -inline std::optional ProcessContext::getProperty(const PropertyReference& property, const FlowFile* const flow_file) { +inline std::optional ProcessContextImpl::getProperty(const PropertyReference& property, const FlowFile* const flow_file) { std::string value; if (!getProperty(property, value, flow_file)) return std::nullopt; return value; } +template +std::optional ProcessContext::getProperty(const Property& property) const { + T value; + if (getProperty(property.getName(), value)) { + return value; + } + return std::nullopt; +} + +template +std::optional ProcessContext::getProperty(const PropertyReference& property) const { + T value; + if (getProperty(property.name, value)) { + return value; + } + return std::nullopt; +} + +bool ProcessContext::getProperty(std::string_view name, detail::NotAFlowFile auto& value) const { + return getProcessorNode()->getProperty::type>(std::string{name}, value); +} + +bool ProcessContext::getProperty(const PropertyReference& property, detail::NotAFlowFile auto& value) const { + return getProcessorNode()->getProperty::type>(std::string{property.name}, value); +} + } // namespace org::apache::nifi::minifi::core diff --git a/libminifi/include/core/ProcessContextBuilder.h b/utils/include/core/ProcessContextBuilder.h similarity index 72% rename from libminifi/include/core/ProcessContextBuilder.h rename to utils/include/core/ProcessContextBuilder.h index ab5ac063f7..cd1c4c3e9e 100644 --- a/libminifi/include/core/ProcessContextBuilder.h +++ b/utils/include/core/ProcessContextBuilder.h @@ -24,20 +24,16 @@ #include #include #include -#include "Property.h" +#include "minifi-cpp/core/Property.h" #include "core/Core.h" #include "utils/Id.h" #include "core/ContentRepository.h" -#include "properties/Configure.h" -#include "core/repository/FileSystemRepository.h" -#include "core/controller/ControllerServiceProvider.h" -#include "core/controller/ControllerServiceLookup.h" #include "core/logging/LoggerFactory.h" #include "ProcessContext.h" -#include "ProcessorNode.h" -#include "core/Repository.h" -#include "core/FlowFile.h" +#include "minifi-cpp/core/FlowFile.h" #include "VariableRegistry.h" +#include "minifi-cpp/core/ProcessContextBuilder.h" +#include "utils/GeneralUtils.h" namespace org::apache::nifi::minifi::core { /** @@ -48,29 +44,29 @@ namespace org::apache::nifi::minifi::core { * While this incurs a tiny cost to look up, it allows us to have a replaceable builder that erases the type we are * constructing. */ -class ProcessContextBuilder : public core::CoreComponent, public std::enable_shared_from_this { +class ProcessContextBuilderImpl : public core::CoreComponentImpl, public virtual ProcessContextBuilder { public: - ProcessContextBuilder(std::string_view name, const minifi::utils::Identifier &uuid); + ProcessContextBuilderImpl(std::string_view name, const minifi::utils::Identifier &uuid); - explicit ProcessContextBuilder(std::string_view name); + explicit ProcessContextBuilderImpl(std::string_view name); - ~ProcessContextBuilder() override = default; + ~ProcessContextBuilderImpl() override = default; MINIFIAPI static constexpr auto Properties = std::array{}; MINIFIAPI static constexpr bool SupportsDynamicProperties = false; MINIFIAPI static constexpr bool SupportsDynamicRelationships = false; - std::shared_ptr withProvider(core::controller::ControllerServiceProvider* controller_service_provider); + std::shared_ptr withProvider(core::controller::ControllerServiceProvider* controller_service_provider) override; - std::shared_ptr withProvenanceRepository(const std::shared_ptr &repo); + std::shared_ptr withProvenanceRepository(const std::shared_ptr &repo) override; - std::shared_ptr withFlowFileRepository(const std::shared_ptr &repo); + std::shared_ptr withFlowFileRepository(const std::shared_ptr &repo) override; - std::shared_ptr withContentRepository(const std::shared_ptr &repo); + std::shared_ptr withContentRepository(const std::shared_ptr &repo) override; - std::shared_ptr withConfiguration(const std::shared_ptr &configuration); + std::shared_ptr withConfiguration(const std::shared_ptr &configuration) override; - virtual std::shared_ptr build(const std::shared_ptr &processor); + std::shared_ptr build(const std::shared_ptr &processor) override; protected: std::shared_ptr configuration_; diff --git a/libminifi/include/core/Processor.h b/utils/include/core/Processor.h similarity index 62% rename from libminifi/include/core/Processor.h rename to utils/include/core/Processor.h index 6f25c176c3..0e543fd0d8 100644 --- a/libminifi/include/core/Processor.h +++ b/utils/include/core/Processor.h @@ -32,17 +32,20 @@ #include #include -#include "ConfigurableComponent.h" -#include "Connectable.h" -#include "Core.h" -#include "core/Annotation.h" -#include "DynamicProperty.h" -#include "Scheduling.h" +#include "core/ConfigurableComponent.h" +#include "core/Connectable.h" +#include "core/Core.h" +#include "minifi-cpp/core/Annotation.h" +#include "minifi-cpp/core/DynamicProperty.h" +#include "minifi-cpp/core/Scheduling.h" #include "utils/TimeUtil.h" -#include "core/state/nodes/MetricsBase.h" -#include "ProcessorMetrics.h" +#include "minifi-cpp/core/state/nodes/MetricsBase.h" +#include "minifi-cpp/core/ProcessorMetrics.h" #include "utils/gsl.h" -#include "OutputAttributeDefinition.h" +#include "minifi-cpp/core/OutputAttributeDefinition.h" +#include "minifi-cpp/core/Processor.h" +#include "core/Property.h" +#include "core/ProcessContext.h" #define ADD_GET_PROCESSOR_NAME \ std::string getProcessorType() const override { \ @@ -64,7 +67,6 @@ class Connection; namespace core { -class ProcessContext; class ProcessSession; class ProcessSessionFactory; @@ -72,113 +74,113 @@ constexpr std::chrono::microseconds MINIMUM_SCHEDULING_PERIOD{30}; #define BUILDING_DLL 1 -class Processor : public Connectable, public ConfigurableComponent, public state::response::ResponseNodeSource { +class ProcessorImpl : public virtual Processor, public ConnectableImpl, public ConfigurableComponentImpl { public: - Processor(std::string_view name, const utils::Identifier& uuid, std::shared_ptr metrics = nullptr); - explicit Processor(std::string_view name, std::shared_ptr metrics = nullptr); + ProcessorImpl(std::string_view name, const utils::Identifier& uuid, std::shared_ptr metrics = nullptr); + explicit ProcessorImpl(std::string_view name, std::shared_ptr metrics = nullptr); - Processor(const Processor& parent) = delete; - Processor& operator=(const Processor& parent) = delete; + ProcessorImpl(const ProcessorImpl& parent) = delete; + ProcessorImpl& operator=(const ProcessorImpl& parent) = delete; bool isRunning() const override; - ~Processor() override; + ~ProcessorImpl() override; - void setScheduledState(ScheduledState state); + void setScheduledState(ScheduledState state) override; - ScheduledState getScheduledState() const { + ScheduledState getScheduledState() const override { return state_; } - void setSchedulingStrategy(SchedulingStrategy strategy) { + void setSchedulingStrategy(SchedulingStrategy strategy) override { strategy_ = strategy; } - SchedulingStrategy getSchedulingStrategy() const { + SchedulingStrategy getSchedulingStrategy() const override { return strategy_; } - void setSchedulingPeriod(std::chrono::steady_clock::duration period) { + void setSchedulingPeriod(std::chrono::steady_clock::duration period) override { scheduling_period_ = std::max(std::chrono::steady_clock::duration(MINIMUM_SCHEDULING_PERIOD), period); } - std::chrono::steady_clock::duration getSchedulingPeriod() const { + std::chrono::steady_clock::duration getSchedulingPeriod() const override { return scheduling_period_; } - void setCronPeriod(const std::string &period) { + void setCronPeriod(const std::string &period) override { cron_period_ = period; } - std::string getCronPeriod() const { + std::string getCronPeriod() const override { return cron_period_; } - void setRunDurationNano(std::chrono::steady_clock::duration period) { + void setRunDurationNano(std::chrono::steady_clock::duration period) override { run_duration_ = period; } - std::chrono::steady_clock::duration getRunDurationNano() const { + std::chrono::steady_clock::duration getRunDurationNano() const override { return (run_duration_); } - void setYieldPeriodMsec(std::chrono::milliseconds period) { + void setYieldPeriodMsec(std::chrono::milliseconds period) override { yield_period_ = period; } - std::chrono::steady_clock::duration getYieldPeriod() const { + std::chrono::steady_clock::duration getYieldPeriod() const override { return yield_period_; } - void setPenalizationPeriod(std::chrono::milliseconds period) { + void setPenalizationPeriod(std::chrono::milliseconds period) override { penalization_period_ = period; } void setMaxConcurrentTasks(uint8_t tasks) override; - virtual bool isSingleThreaded() const = 0; + bool isSingleThreaded() const override = 0; - virtual std::string getProcessorType() const = 0; + std::string getProcessorType() const override = 0; - void setTriggerWhenEmpty(bool value) { + void setTriggerWhenEmpty(bool value) override { _triggerWhenEmpty = value; } - bool getTriggerWhenEmpty() const { + bool getTriggerWhenEmpty() const override { return (_triggerWhenEmpty); } - uint8_t getActiveTasks() const { + uint8_t getActiveTasks() const override { return (active_tasks_); } - void incrementActiveTasks() { + void incrementActiveTasks() override { ++active_tasks_; } - void decrementActiveTask() { + void decrementActiveTask() override { if (active_tasks_ > 0) --active_tasks_; } - void clearActiveTask() { + void clearActiveTask() override { active_tasks_ = 0; } void yield() override; - void yield(std::chrono::steady_clock::duration delta_time); + void yield(std::chrono::steady_clock::duration delta_time) override; - virtual bool isYield(); + bool isYield() override; - void clearYield(); + void clearYield() override; - std::chrono::steady_clock::time_point getYieldExpirationTime() const { return yield_expiration_; } - std::chrono::steady_clock::duration getYieldTime() const; + std::chrono::steady_clock::time_point getYieldExpirationTime() const override { return yield_expiration_; } + std::chrono::steady_clock::duration getYieldTime() const override; // Whether flow file queue full in any of the outgoing connection - bool flowFilesOutGoingFull() const; + bool flowFilesOutGoingFull() const override; - bool addConnection(Connectable* connection); + bool addConnection(Connectable* connection) override; bool canEdit() override { return !isRunning(); @@ -187,34 +189,34 @@ class Processor : public Connectable, public ConfigurableComponent, public state void initialize() override { } - virtual void triggerAndCommit(const std::shared_ptr& context, const std::shared_ptr& session_factory); - void trigger(const std::shared_ptr& context, const std::shared_ptr& process_session); + void triggerAndCommit(const std::shared_ptr& context, const std::shared_ptr& session_factory) override; + void trigger(const std::shared_ptr& context, const std::shared_ptr& process_session) override; - virtual void onTrigger(ProcessContext&, ProcessSession&) {} + void onTrigger(ProcessContext&, ProcessSession&) override {} - virtual void onSchedule(ProcessContext&, ProcessSessionFactory&) {} + void onSchedule(ProcessContext&, ProcessSessionFactory&) override {} // Hook executed when onSchedule fails (throws). Configuration should be reset in this - virtual void onUnSchedule() { + void onUnSchedule() override { notifyStop(); } // Check all incoming connections for work bool isWorkAvailable() override; - bool isThrottledByBackpressure() const; + bool isThrottledByBackpressure() const override; Connectable* pickIncomingConnection() override; - void validateAnnotations() const; + void validateAnnotations() const override; - virtual annotation::Input getInputRequirement() const = 0; + annotation::Input getInputRequirement() const override = 0; state::response::SharedResponseNode getResponseNode() override { return metrics_; } - auto getMetrics() const { + gsl::not_null> getMetrics() const override { return metrics_; } @@ -250,7 +252,11 @@ class Processor : public Connectable, public ConfigurableComponent, public state } // must hold the graphMutex - void updateReachability(const std::lock_guard& graph_lock, bool force = false); + void updateReachability(const std::lock_guard& graph_lock, bool force = false) override; + + const std::unordered_map>& reachable_processors() const override { + return reachable_processors_; + } static bool partOfCycle(Connection* conn); diff --git a/libminifi/include/core/ProcessorMetrics.h b/utils/include/core/ProcessorMetrics.h similarity index 69% rename from libminifi/include/core/ProcessorMetrics.h rename to utils/include/core/ProcessorMetrics.h index de5c3d157e..9bc3c06120 100644 --- a/libminifi/include/core/ProcessorMetrics.h +++ b/utils/include/core/ProcessorMetrics.h @@ -23,8 +23,8 @@ #include #include -#include "core/state/nodes/MetricsBase.h" -#include "core/state/PublishedMetricProvider.h" +#include "core/state/nodes/ResponseNode.h" +#include "minifi-cpp/core/ProcessorMetrics.h" namespace org::apache::nifi::minifi::core { @@ -36,26 +36,30 @@ concept DividableByInteger = requires(T x, uint32_t divisor) { x / divisor; }; class Processor; -class ProcessorMetrics : public state::response::ResponseNode { +class ProcessorMetricsImpl : public state::response::ResponseNodeImpl, public virtual ProcessorMetrics { public: - explicit ProcessorMetrics(const Processor& source_processor); + explicit ProcessorMetricsImpl(const Processor& source_processor); [[nodiscard]] std::string getName() const override; std::vector serialize() override; std::vector calculateMetrics() override; - void increaseRelationshipTransferCount(const std::string& relationship, size_t count = 1); - std::chrono::milliseconds getAverageOnTriggerRuntime() const; - std::chrono::milliseconds getLastOnTriggerRuntime() const; - void addLastOnTriggerRuntime(std::chrono::milliseconds runtime); + void increaseRelationshipTransferCount(const std::string& relationship, size_t count = 1) override; + std::chrono::milliseconds getAverageOnTriggerRuntime() const override; + std::chrono::milliseconds getLastOnTriggerRuntime() const override; + void addLastOnTriggerRuntime(std::chrono::milliseconds runtime) override; - std::chrono::milliseconds getAverageSessionCommitRuntime() const; - std::chrono::milliseconds getLastSessionCommitRuntime() const; - void addLastSessionCommitRuntime(std::chrono::milliseconds runtime); + std::chrono::milliseconds getAverageSessionCommitRuntime() const override; + std::chrono::milliseconds getLastSessionCommitRuntime() const override; + void addLastSessionCommitRuntime(std::chrono::milliseconds runtime) override; - std::atomic iterations{0}; - std::atomic transferred_flow_files{0}; - std::atomic transferred_bytes{0}; + std::atomic& iterations() override {return iterations_;} + std::atomic& transferredFlowFiles() override {return transferred_flow_files_;} + std::atomic& transferredBytes() override {return transferred_bytes_;} + + const std::atomic& iterations() const override {return iterations_;} + const std::atomic& transferredFlowFiles() const override {return transferred_flow_files_;} + const std::atomic& transferredBytes() const override {return transferred_bytes_;} protected: template @@ -85,6 +89,11 @@ class ProcessorMetrics : public state::response::ResponseNode { const Processor& source_processor_; Averager on_trigger_runtime_averager_; Averager session_commit_runtime_averager_; + + private: + std::atomic iterations_{0}; + std::atomic transferred_flow_files_{0}; + std::atomic transferred_bytes_{0}; }; } // namespace org::apache::nifi::minifi::core diff --git a/utils/include/core/Property.h b/utils/include/core/Property.h new file mode 100644 index 0000000000..4ec86d5396 --- /dev/null +++ b/utils/include/core/Property.h @@ -0,0 +1,30 @@ +/** + * 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 "minifi-cpp/core/Property.h" +#include "TypedValues.h" + +namespace org::apache::nifi::minifi::core { + +template +bool Property::StringToInt(std::string input, T &output) { + return DataSizeValue::StringToInt(input, output); +} + +} // namespace org::apache::nifi::minifi::core diff --git a/utils/include/core/PropertyDefinition.h b/utils/include/core/PropertyDefinition.h new file mode 100644 index 0000000000..56299edf4a --- /dev/null +++ b/utils/include/core/PropertyDefinition.h @@ -0,0 +1,20 @@ +/** + * 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 "minifi-cpp/core/PropertyDefinition.h" diff --git a/libminifi/include/core/PropertyDefinitionBuilder.h b/utils/include/core/PropertyDefinitionBuilder.h similarity index 91% rename from libminifi/include/core/PropertyDefinitionBuilder.h rename to utils/include/core/PropertyDefinitionBuilder.h index 40ebfbc7bc..a6a0137036 100644 --- a/libminifi/include/core/PropertyDefinitionBuilder.h +++ b/utils/include/core/PropertyDefinitionBuilder.h @@ -20,6 +20,7 @@ #include "core/PropertyDefinition.h" #include "core/PropertyType.h" +#include "core/ClassName.h" namespace org::apache::nifi::minifi::core { @@ -101,7 +102,21 @@ struct PropertyDefinitionBuilder { return property; } - PropertyDefinition property{}; + PropertyDefinition property{ + .name = {}, + .display_name = {}, + .description = {}, + .is_required = false, + .is_sensitive = false, + .allowed_values = {}, + .allowed_types = {}, + .dependent_properties = {}, + .exclusive_of_properties = {}, + .default_value = {}, + .type = gsl::make_not_null(&StandardPropertyTypes::VALID_TYPE), + .supports_expression_language = false, + .version = 1 + }; }; } // namespace org::apache::nifi::minifi::core diff --git a/libminifi/include/core/PropertyType.h b/utils/include/core/PropertyType.h similarity index 86% rename from libminifi/include/core/PropertyType.h rename to utils/include/core/PropertyType.h index 64cd1df246..519e551db9 100644 --- a/libminifi/include/core/PropertyType.h +++ b/utils/include/core/PropertyType.h @@ -21,37 +21,17 @@ #include #include -#include "core/Core.h" -#include "core/PropertyValue.h" -#include "core/state/Value.h" +#include "minifi-cpp/core/PropertyType.h" +#include "PropertyValue.h" +#include "minifi-cpp/core/state/Value.h" #include "TypedValues.h" -#include "utils/Export.h" #include "utils/StringUtils.h" -#include "ValidationResult.h" namespace org::apache::nifi::minifi::core { -class PropertyParser { +class PropertyTypeImpl : public PropertyType { public: - virtual constexpr ~PropertyParser() {} // NOLINT can't use = default because of gcc bug: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93413 - - [[nodiscard]] virtual PropertyValue parse(std::string_view input) const = 0; -}; - -class PropertyValidator { - public: - virtual constexpr ~PropertyValidator() {} // NOLINT can't use = default because of gcc bug: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93413 - - [[nodiscard]] virtual std::string_view getValidatorName() const = 0; - - [[nodiscard]] virtual ValidationResult validate(const std::string &subject, const std::shared_ptr &input) const = 0; - - [[nodiscard]] virtual ValidationResult validate(const std::string &subject, const std::string &input) const = 0; -}; - -class PropertyType : public PropertyParser, public PropertyValidator { - public: - virtual constexpr ~PropertyType() {} // NOLINT can't use = default because of gcc bug: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93413 + virtual constexpr ~PropertyTypeImpl() {} // NOLINT can't use = default because of gcc bug: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93413 [[nodiscard]] PropertyValue parse(std::string_view input) const override; @@ -68,7 +48,7 @@ class PropertyType : public PropertyParser, public PropertyValidator { } }; -class ConstantPropertyType : public PropertyType { +class ConstantPropertyType : public PropertyTypeImpl { public: explicit constexpr ConstantPropertyType(bool value) : value_(value) {} @@ -104,7 +84,7 @@ class NeverValidPropertyType : public ConstantPropertyType { [[nodiscard]] std::string_view getValidatorName() const override { return "INVALID"; } }; -class BooleanPropertyType : public PropertyType { +class BooleanPropertyType : public PropertyTypeImpl { public: constexpr ~BooleanPropertyType() override {} // NOLINT see comment at parent @@ -113,7 +93,7 @@ class BooleanPropertyType : public PropertyType { [[nodiscard]] PropertyValue parse(std::string_view input) const override; [[nodiscard]] ValidationResult validate(const std::string &subject, const std::shared_ptr &input) const override { - return PropertyType::_validate_internal(subject, input); + return PropertyTypeImpl::_validate_internal(subject, input); } [[nodiscard]] ValidationResult validate(const std::string &subject, const std::string &input) const override { @@ -124,7 +104,7 @@ class BooleanPropertyType : public PropertyType { } }; -class IntegerPropertyType : public PropertyType { +class IntegerPropertyType : public PropertyTypeImpl { public: constexpr ~IntegerPropertyType() override {} // NOLINT see comment at parent @@ -133,7 +113,7 @@ class IntegerPropertyType : public PropertyType { [[nodiscard]] PropertyValue parse(std::string_view input) const override; [[nodiscard]] ValidationResult validate(const std::string &subject, const std::shared_ptr &input) const override { - return PropertyType::_validate_internal(subject, input); + return PropertyTypeImpl::_validate_internal(subject, input); } [[nodiscard]] ValidationResult validate(const std::string &subject, const std::string &input) const override { @@ -146,7 +126,7 @@ class IntegerPropertyType : public PropertyType { } }; -class UnsignedIntPropertyType : public PropertyType { +class UnsignedIntPropertyType : public PropertyTypeImpl { public: constexpr ~UnsignedIntPropertyType() override {} // NOLINT see comment at parent @@ -155,7 +135,7 @@ class UnsignedIntPropertyType : public PropertyType { [[nodiscard]] PropertyValue parse(std::string_view input) const override; [[nodiscard]] ValidationResult validate(const std::string &subject, const std::shared_ptr &input) const override { - return PropertyType::_validate_internal(subject, input); + return PropertyTypeImpl::_validate_internal(subject, input); } [[nodiscard]] ValidationResult validate(const std::string &subject, const std::string &input) const override { @@ -210,7 +190,7 @@ class LongPropertyType : public PropertyType { int64_t max_; }; -class UnsignedLongPropertyType : public PropertyType { +class UnsignedLongPropertyType : public PropertyTypeImpl { public: explicit constexpr UnsignedLongPropertyType(uint64_t min = std::numeric_limits::min(), uint64_t max = std::numeric_limits::max()) : min_(min), @@ -224,7 +204,7 @@ class UnsignedLongPropertyType : public PropertyType { [[nodiscard]] PropertyValue parse(std::string_view input) const override; [[nodiscard]] ValidationResult validate(const std::string &subject, const std::shared_ptr &input) const override { - return PropertyType::_validate_internal(subject, input); + return PropertyTypeImpl::_validate_internal(subject, input); } [[nodiscard]] ValidationResult validate(const std::string &subject, const std::string &input) const override { @@ -245,7 +225,7 @@ class UnsignedLongPropertyType : public PropertyType { uint64_t max_; }; -class NonBlankPropertyType : public PropertyType { +class NonBlankPropertyType : public PropertyTypeImpl { public: constexpr ~NonBlankPropertyType() override {} // NOLINT see comment at parent @@ -260,7 +240,7 @@ class NonBlankPropertyType : public PropertyType { } }; -class DataSizePropertyType : public PropertyType { +class DataSizePropertyType : public PropertyTypeImpl { public: constexpr ~DataSizePropertyType() override {} // NOLINT see comment at parent @@ -269,7 +249,7 @@ class DataSizePropertyType : public PropertyType { [[nodiscard]] PropertyValue parse(std::string_view input) const override; [[nodiscard]] ValidationResult validate(const std::string &subject, const std::shared_ptr &input) const override { - return PropertyType::_validate_internal(subject, input); + return PropertyTypeImpl::_validate_internal(subject, input); } [[nodiscard]] ValidationResult validate(const std::string &subject, const std::string &input) const override { @@ -301,7 +281,7 @@ class ListenPortValidator : public LongPropertyType { [[nodiscard]] std::string_view getValidatorName() const override { return "PORT_VALIDATOR"; } }; -class TimePeriodPropertyType : public PropertyType { +class TimePeriodPropertyType : public PropertyTypeImpl { public: constexpr ~TimePeriodPropertyType() override {} // NOLINT see comment at parent @@ -310,7 +290,7 @@ class TimePeriodPropertyType : public PropertyType { [[nodiscard]] PropertyValue parse(std::string_view input) const override; [[nodiscard]] ValidationResult validate(const std::string &subject, const std::shared_ptr &input) const override { - return PropertyType::_validate_internal(subject, input); + return PropertyTypeImpl::_validate_internal(subject, input); } [[nodiscard]] ValidationResult validate(const std::string &subject, const std::string &input) const override { @@ -319,7 +299,7 @@ class TimePeriodPropertyType : public PropertyType { } }; -class DataTransferSpeedPropertyType : public PropertyType { +class DataTransferSpeedPropertyType : public PropertyTypeImpl { public: constexpr ~DataTransferSpeedPropertyType() override {} // NOLINT see comment at parent @@ -328,7 +308,7 @@ class DataTransferSpeedPropertyType : public PropertyType { [[nodiscard]] PropertyValue parse(std::string_view input) const override; [[nodiscard]] ValidationResult validate(const std::string &subject, const std::shared_ptr &input) const override { - return PropertyType::_validate_internal(subject, input); + return PropertyTypeImpl::_validate_internal(subject, input); } [[nodiscard]] ValidationResult validate(const std::string &subject, const std::string &input) const override { diff --git a/utils/include/core/PropertyValue.h b/utils/include/core/PropertyValue.h new file mode 100644 index 0000000000..bd534c9145 --- /dev/null +++ b/utils/include/core/PropertyValue.h @@ -0,0 +1,160 @@ +/** + * + * 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 +#include +#include +#include + +#include "minifi-cpp/core/PropertyValue.h" + +#include "state/Value.h" +#include "TypedValues.h" + +namespace org::apache::nifi::minifi::core { + +class PropertyValidator; + +static inline std::shared_ptr convert(const std::shared_ptr &prior, const std::string &ref) { + if (prior->getTypeIndex() == state::response::Value::UINT64_TYPE) { + // there are specializations, so check them first + if (std::dynamic_pointer_cast(prior)) { + return std::make_shared(ref); + } else if (std::dynamic_pointer_cast(prior)) { + return std::make_shared(ref); + } else if (std::dynamic_pointer_cast(prior)) { + return std::make_shared(ref); + } else { + return std::make_shared(ref); + } + } else if (prior->getTypeIndex() == state::response::Value::INT64_TYPE) { + return std::make_shared(ref); + } else if (prior->getTypeIndex() == state::response::Value::UINT32_TYPE) { + return std::make_shared(ref); + } else if (prior->getTypeIndex() == state::response::Value::INT_TYPE) { + return std::make_shared(ref); + } else if (prior->getTypeIndex() == state::response::Value::BOOL_TYPE) { + return std::make_shared(ref); + } else if (prior->getTypeIndex() == state::response::Value::DOUBLE_TYPE) { + return std::make_shared(ref); + } else { + return std::make_shared(ref); + } +} + +template +auto PropertyValue::WithAssignmentGuard( const std::string& ref, Fn&& functor) -> decltype(std::forward(functor)()) { + // TODO(adebreceni): as soon as c++17 comes jump to a RAII implementation + // as we will need std::uncaught_exceptions() + try { + return std::forward(functor)(); + } catch(const utils::internal::ValueException&) { + type_id = std::type_index(typeid(std::string)); + value_ = minifi::state::response::createValue(ref); + throw; + } +} + +template +struct Converter; + +template +struct Converter, void>> { + void operator()(PropertyValue& self, const T& ref) { + self.cached_value_validator_.invalidateCachedResult(); + self.WithAssignmentGuard(ref, [&] () { + if (self.value_ == nullptr) { + self.type_id = std::type_index(typeid(T)); + self.value_ = minifi::state::response::createValue(ref); + } else { + self.type_id = std::type_index(typeid(T)); + auto ret = convert(self.value_, ref); + if (ret != nullptr) { + self.value_ = ret; + } else { + /** + * This is a protection mechanism that allows us to fail properties that are strictly defined. + * To maintain backwards compatibility we allow strings to be set by way of the internal API + * We then rely on the developer of the processor to perform the conversion. We want to get away from + * this, so this exception will throw an exception, forcefully, when they specify types in properties. + */ + throw utils::internal::ConversionException("Invalid conversion"); + } + } + }); + } +}; + +template +struct Converter || std::is_same_v || std::is_same_v || std::is_same_v || std::is_same_v, void>> { + void operator()(PropertyValue& self, const T& ref) { + self.cached_value_validator_.invalidateCachedResult(); + if (self.value_ == nullptr) { + self.type_id = std::type_index(typeid(T)); + self.value_ = minifi::state::response::createValue(ref); + } else { + if (std::dynamic_pointer_cast(self.value_)) { + self.value_ = std::make_shared(ref); + self.type_id = DataSizeValue::type_id; + } else if (std::dynamic_pointer_cast(self.value_)) { + self.value_ = std::make_shared(ref); + self.type_id = DataTransferSpeedValue::type_id; + } else if (std::dynamic_pointer_cast(self.value_)) { + self.value_ = std::make_shared(ref); + self.type_id = TimePeriodValue::type_id; + } else if (self.type_id == std::type_index(typeid(T))) { + self.value_ = minifi::state::response::createValue(ref); + } else { + // this is not the place to perform translation. There are other places within + // the code where we can do assignments and transformations from "10" to (int)10; + throw utils::internal::ConversionException("Assigning invalid types"); + } + } + } +}; + +template +struct Converter || std::is_same_v || (std::is_array_v && std::is_same_v, char>), void>> { + void operator()(PropertyValue& self, const T& ref) { + // translated these into strings + self.operator=(std::string(ref)); + } +}; + +template +auto PropertyValue::operator=(const T& ref) -> std::enable_if_t, PropertyValue>, PropertyValue&> { + Converter{}(*this, ref); + return *this; +} + +template +T PropertyValue::convertImpl(const char* const type_name) const { + if (!isValueUsable()) { + throw utils::internal::InvalidValueException("Cannot convert invalid value"); + } + T res; + if (auto* value_impl = dynamic_cast(value_.get())) { + if (value_impl->getValue(res)) { + return res; + } + } + throw utils::internal::ConversionException(std::string("Invalid conversion to ") + type_name + " for " + value_->getStringValue()); +} + +} // namespace org::apache::nifi::minifi::core diff --git a/utils/include/core/Relationship.h b/utils/include/core/Relationship.h new file mode 100644 index 0000000000..d1bf0904ff --- /dev/null +++ b/utils/include/core/Relationship.h @@ -0,0 +1,26 @@ +/** + * 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 "minifi-cpp/core/Relationship.h" + +template<> +struct std::hash { + size_t operator()(const org::apache::nifi::minifi::core::Relationship& relationship) const noexcept { + return std::hash{}(relationship.getName()); + } +}; diff --git a/utils/include/core/RelationshipDefinition.h b/utils/include/core/RelationshipDefinition.h new file mode 100644 index 0000000000..56b101f7c4 --- /dev/null +++ b/utils/include/core/RelationshipDefinition.h @@ -0,0 +1,20 @@ +/** + * 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 "minifi-cpp/core/RelationshipDefinition.h" diff --git a/libminifi/include/core/Repository.h b/utils/include/core/Repository.h similarity index 67% rename from libminifi/include/core/Repository.h rename to utils/include/core/Repository.h index 72efd1b407..b5f25a0e29 100644 --- a/libminifi/include/core/Repository.h +++ b/utils/include/core/Repository.h @@ -30,20 +30,17 @@ #include #include -#include "ResourceClaim.h" #include "core/Connectable.h" #include "core/ContentRepository.h" #include "core/Property.h" -#include "core/SerializableComponent.h" #include "core/logging/LoggerFactory.h" #include "core/RepositoryMetricsSource.h" -#include "properties/Configure.h" #include "utils/BackTrace.h" -#include "SwapManager.h" #include "utils/Literals.h" #include "utils/StringUtils.h" #include "utils/TimeUtil.h" #include "core/Core.h" +#include "minifi-cpp/core/Repository.h" #ifndef WIN32 #include @@ -56,14 +53,14 @@ constexpr auto MAX_REPOSITORY_STORAGE_SIZE = 10_MiB; constexpr auto MAX_REPOSITORY_ENTRY_LIFE_TIME = std::chrono::minutes(10); constexpr auto REPOSITORY_PURGE_PERIOD = std::chrono::milliseconds(2500); -class Repository : public core::CoreComponent, public core::RepositoryMetricsSource { +class RepositoryImpl : public core::CoreComponentImpl, public core::RepositoryMetricsSourceImpl, public virtual Repository { public: - explicit Repository(std::string_view repo_name = "Repository", + explicit RepositoryImpl(std::string_view repo_name = "Repository", std::string directory = REPOSITORY_DIRECTORY, std::chrono::milliseconds maxPartitionMillis = MAX_REPOSITORY_ENTRY_LIFE_TIME, int64_t maxPartitionBytes = MAX_REPOSITORY_STORAGE_SIZE, std::chrono::milliseconds purgePeriod = REPOSITORY_PURGE_PERIOD) - : core::CoreComponent(repo_name), + : core::CoreComponentImpl(repo_name), max_partition_millis_(maxPartitionMillis), max_partition_bytes_(maxPartitionBytes), purge_period_(purgePeriod), @@ -72,57 +69,53 @@ class Repository : public core::CoreComponent, public core::RepositoryMetricsSou logger_(logging::LoggerFactory::getLogger()) { } - virtual bool initialize(const std::shared_ptr &configure) = 0; - virtual bool start() = 0; - virtual bool stop() = 0; - - virtual bool isNoop() const { + bool isNoop() const override { return true; } - virtual void flush() { + void flush() override { } - virtual bool Put(const std::string& /*key*/, const uint8_t* /*buf*/, size_t /*bufLen*/) { + bool Put(const std::string& /*key*/, const uint8_t* /*buf*/, size_t /*bufLen*/) override { return true; } - virtual bool MultiPut(const std::vector>>& /*data*/) { + bool MultiPut(const std::vector>>& /*data*/) override { return true; } - virtual bool Delete(const std::string& /*key*/) { + bool Delete(const std::string& /*key*/) override { return true; } - virtual bool Delete(const std::shared_ptr& item) { + bool Delete(const std::shared_ptr& item) override { return Delete(item->getUUIDStr()); } - virtual bool Delete(std::vector> &storedValues); + bool Delete(std::vector> &storedValues) override; - void setConnectionMap(std::map connectionMap) { + void setConnectionMap(std::map connectionMap) override { connection_map_ = std::move(connectionMap); } - void setContainers(std::map containers) { + void setContainers(std::map containers) override { containers_ = std::move(containers); } - virtual bool Get(const std::string& /*key*/, std::string& /*value*/) { + bool Get(const std::string& /*key*/, std::string& /*value*/) override { return false; } - virtual bool getElements(std::vector>& /*store*/, size_t& /*max_size*/) { + bool getElements(std::vector>& /*store*/, size_t& /*max_size*/) override { return true; } - virtual bool storeElement(const std::shared_ptr& element); + bool storeElement(const std::shared_ptr& element) override; - virtual void loadComponent(const std::shared_ptr& /*content_repo*/) { + void loadComponent(const std::shared_ptr& /*content_repo*/) override { } - std::string getDirectory() const { + std::string getDirectory() const override { return directory_; } @@ -130,10 +123,8 @@ class Repository : public core::CoreComponent, public core::RepositoryMetricsSou return getName(); } - // Prevent default copy constructor and assignment operation - // Only support pass by reference or pointer - Repository(const Repository &parent) = delete; - Repository &operator=(const Repository &parent) = delete; + RepositoryImpl(const RepositoryImpl &parent) = delete; + RepositoryImpl &operator=(const RepositoryImpl &parent) = delete; protected: std::map containers_; diff --git a/utils/include/core/RepositoryMetricsSource.h b/utils/include/core/RepositoryMetricsSource.h new file mode 100644 index 0000000000..20803345a1 --- /dev/null +++ b/utils/include/core/RepositoryMetricsSource.h @@ -0,0 +1,47 @@ +/** + * + * 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 +#include + +#include "minifi-cpp/core/RepositoryMetricsSource.h" + +namespace org::apache::nifi::minifi::core { + +class RepositoryMetricsSourceImpl : public virtual RepositoryMetricsSource { + public: + uint64_t getMaxRepositorySize() const override { + return 0; + } + + bool isFull() const override { + return false; + } + + bool isRunning() const override { + return true; + } + + std::optional getRocksDbStats() const override { + return std::nullopt; + } +}; + +} // namespace org::apache::nifi::minifi::core diff --git a/libminifi/include/core/Resource.h b/utils/include/core/Resource.h similarity index 94% rename from libminifi/include/core/Resource.h rename to utils/include/core/Resource.h index 68652d116b..ab4527b251 100644 --- a/libminifi/include/core/Resource.h +++ b/utils/include/core/Resource.h @@ -92,4 +92,7 @@ class StaticClassType { #define REGISTER_RESOURCE_AS(CLASSNAME, TYPE, NAMES) \ static const auto& CLASSNAME##_registrar = core::StaticClassType::get(#CLASSNAME, MAKE_INIT_LIST NAMES) +#define REGISTER_RESOURCE_IMPLEMENTATION(CLASS, CLASSNAME, TYPE) \ + static const auto& CLASS##_registrar = core::StaticClassType::get(CLASSNAME, {CLASSNAME}) + } // namespace org::apache::nifi::minifi::core diff --git a/utils/include/core/StreamManager.h b/utils/include/core/StreamManager.h new file mode 100644 index 0000000000..fed007150d --- /dev/null +++ b/utils/include/core/StreamManager.h @@ -0,0 +1,45 @@ +/** + * + * 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 +#include + +#include "minifi-cpp/core/StreamManager.h" +#include "io/BufferStream.h" +#include "io/BaseStream.h" + +namespace org::apache::nifi::minifi::core { + +/** + * Purpose: Provides a base for all stream based managers. The goal here is to provide + * a small set of interfaces that provide a small set of operations to provide state + * management for streams. + */ +template +class StreamManagerImpl : public virtual StreamManager { + public: + size_t size(const T &streamId) override { + auto stream = this->read(streamId); + if (!stream) + return 0; + return stream->size(); + } +}; + +} // namespace org::apache::nifi::minifi::core diff --git a/libminifi/include/core/ThreadedRepository.h b/utils/include/core/ThreadedRepository.h similarity index 90% rename from libminifi/include/core/ThreadedRepository.h rename to utils/include/core/ThreadedRepository.h index 2b5ae27a21..19942d4578 100644 --- a/libminifi/include/core/ThreadedRepository.h +++ b/utils/include/core/ThreadedRepository.h @@ -21,16 +21,17 @@ #include #include -#include "Repository.h" -#include "TraceableResource.h" +#include "core/Repository.h" +#include "minifi-cpp/core/TraceableResource.h" +#include "minifi-cpp/core/ThreadedRepository.h" namespace org::apache::nifi::minifi::core { -class ThreadedRepository : public core::Repository, public core::TraceableResource { +class ThreadedRepositoryImpl : public core::RepositoryImpl, public virtual core::ThreadedRepository { public: - using Repository::Repository; + using RepositoryImpl::RepositoryImpl; - ~ThreadedRepository() override { + ~ThreadedRepositoryImpl() override { if (running_state_.load() != RunningState::Stopped) { logger_->log_error("Thread of {} should have been stopped in subclass before ThreadedRepository's destruction", name_); } @@ -54,7 +55,7 @@ class ThreadedRepository : public core::Repository, public core::TraceableResour // must set Running state before calling run(), as run() might check state running_state_.store(RunningState::Running); - getThread() = std::thread(&ThreadedRepository::run, this); + getThread() = std::thread(&ThreadedRepositoryImpl::run, this); logger_->log_debug("{} ThreadedRepository monitor thread start", name_); return true; diff --git a/libminifi/include/core/TypedValues.h b/utils/include/core/TypedValues.h similarity index 97% rename from libminifi/include/core/TypedValues.h rename to utils/include/core/TypedValues.h index e4c9ef81e4..c28cdcd6e1 100644 --- a/libminifi/include/core/TypedValues.h +++ b/utils/include/core/TypedValues.h @@ -29,7 +29,6 @@ #include "utils/ValueParser.h" #include "utils/PropertyErrors.h" #include "utils/Literals.h" -#include "utils/Export.h" #include "utils/TimeUtil.h" #include "core/logging/Logger.h" @@ -48,7 +47,7 @@ class TransformableValue { */ class TimePeriodValue : public TransformableValue, public state::response::UInt64Value { public: - MINIFIAPI static const std::type_index type_id; + static const std::type_index type_id; explicit TimePeriodValue(const std::string &timeString) : state::response::UInt64Value(0) { @@ -90,7 +89,7 @@ class DataSizeValue : public TransformableValue, public state::response::UInt64V static std::shared_ptr& getLogger(); public: - MINIFIAPI static const std::type_index type_id; + static const std::type_index type_id; explicit DataSizeValue(const std::string &sizeString) : state::response::UInt64Value(0) { @@ -150,7 +149,7 @@ class DataSizeValue : public TransformableValue, public state::response::UInt64V class DataTransferSpeedValue : public TransformableValue, public state::response::UInt64Value { public: - MINIFIAPI static const std::type_index type_id; + static const std::type_index type_id; explicit DataTransferSpeedValue(const std::string &transfer_speed_string) : state::response::UInt64Value(0) { diff --git a/libminifi/include/core/VariableRegistry.h b/utils/include/core/VariableRegistry.h similarity index 82% rename from libminifi/include/core/VariableRegistry.h rename to utils/include/core/VariableRegistry.h index a48a87ca66..f4d15491ac 100644 --- a/libminifi/include/core/VariableRegistry.h +++ b/utils/include/core/VariableRegistry.h @@ -15,35 +15,32 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#ifndef LIBMINIFI_INCLUDE_CORE_VARIABLEREGISTRY_H_ -#define LIBMINIFI_INCLUDE_CORE_VARIABLEREGISTRY_H_ +#pragma once #include #include #include -#include "properties/Configure.h" +#include "minifi-cpp/properties/Configure.h" #include "utils/StringUtils.h" -namespace org { -namespace apache { -namespace nifi { -namespace minifi { -namespace core { +#include "minifi-cpp/core/VariableRegistry.h" + +namespace org::apache::nifi::minifi::core { /** * Defines a base variable registry for minifi agents. */ -class VariableRegistry { +class VariableRegistryImpl : public virtual VariableRegistry { public: - explicit VariableRegistry(const std::shared_ptr &configuration) + explicit VariableRegistryImpl(const std::shared_ptr &configuration) : configuration_(configuration) { if (configuration_ != nullptr) { loadVariableRegistry(); } } - virtual ~VariableRegistry() = default; + ~VariableRegistryImpl() override = default; - bool getConfigurationProperty(const std::string &property, std::string &value) const { + bool getConfigurationProperty(const std::string &property, std::string &value) const override { auto prop = variable_registry_.find(property); if (prop != variable_registry_.end()) { value = prop->second; @@ -92,10 +89,4 @@ class VariableRegistry { std::shared_ptr configuration_; }; -} // namespace core -} // namespace minifi -} // namespace nifi -} // namespace apache -} // namespace org - -#endif // LIBMINIFI_INCLUDE_CORE_VARIABLEREGISTRY_H_ +} // namespace org::apache::nifi::minifi::core diff --git a/libminifi/include/core/controller/ControllerService.h b/utils/include/core/controller/ControllerService.h similarity index 66% rename from libminifi/include/core/controller/ControllerService.h rename to utils/include/core/controller/ControllerService.h index 2564668490..cf31e08041 100644 --- a/libminifi/include/core/controller/ControllerService.h +++ b/utils/include/core/controller/ControllerService.h @@ -15,66 +15,47 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#ifndef LIBMINIFI_INCLUDE_CORE_CONTROLLER_CONTROLLERSERVICE_H_ -#define LIBMINIFI_INCLUDE_CORE_CONTROLLER_CONTROLLERSERVICE_H_ +#pragma once #include #include #include #include -#include "properties/Configure.h" +#include "minifi-cpp/properties/Configure.h" #include "core/Core.h" #include "core/ConfigurableComponent.h" #include "core/Connectable.h" +#include "minifi-cpp/core/controller/ControllerService.h" #define ADD_COMMON_VIRTUAL_FUNCTIONS_FOR_CONTROLLER_SERVICES \ bool supportsDynamicProperties() const override { return SupportsDynamicProperties; } namespace org::apache::nifi::minifi::core::controller { -enum ControllerServiceState { - /** - * Controller Service is disabled and cannot be used. - */ - DISABLED, - /** - * Controller Service is in the process of being disabled. - */ - DISABLING, - /** - * Controller Service is being enabled. - */ - ENABLING, - /** - * Controller Service is enabled. - */ - 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 ConfigurableComponent, public Connectable { +class ControllerServiceImpl : public ConfigurableComponentImpl, public ConnectableImpl, public virtual ControllerService { public: - ControllerService() - : Connectable(core::className()), - configuration_(std::make_shared()) { + ControllerServiceImpl() + : ConnectableImpl(core::className()), + configuration_(Configure::create()) { current_state_ = DISABLED; } - explicit ControllerService(std::string_view name, const utils::Identifier &uuid) - : Connectable(name, uuid), - configuration_(std::make_shared()) { + explicit ControllerServiceImpl(std::string_view name, const utils::Identifier &uuid) + : ConnectableImpl(name, uuid), + configuration_(Configure::create()) { current_state_ = DISABLED; } - explicit ControllerService(std::string_view name) - : Connectable(name), - configuration_(std::make_shared()) { + explicit ControllerServiceImpl(std::string_view name) + : ConnectableImpl(name), + configuration_(Configure::create()) { current_state_ = DISABLED; } @@ -86,41 +67,41 @@ class ControllerService : public ConfigurableComponent, public Connectable { return false; } - ~ControllerService() override { + ~ControllerServiceImpl() override { notifyStop(); } /** * Replaces the configuration object within the controller service. */ - void setConfiguration(const std::shared_ptr &configuration) { + void setConfiguration(const std::shared_ptr &configuration) override { configuration_ = configuration; } - ControllerServiceState getState() const { + ControllerServiceState getState() const override { return current_state_.load(); } /** * Function is called when Controller Services are enabled and being run */ - virtual void onEnable() { + void onEnable() override { } /** * Function is called when Controller Services are disabled */ - virtual void notifyStop() { + void notifyStop() override { } - void setState(ControllerServiceState state) { + void setState(ControllerServiceState state) override { current_state_ = state; if (state == DISABLED) { notifyStop(); } } - void setLinkedControllerServices(const std::vector> &services) { + void setLinkedControllerServices(const std::vector> &services) override { linked_services_ = services; } @@ -134,5 +115,3 @@ class ControllerService : public ConfigurableComponent, public Connectable { }; } // namespace org::apache::nifi::minifi::core::controller - -#endif // LIBMINIFI_INCLUDE_CORE_CONTROLLER_CONTROLLERSERVICE_H_ diff --git a/libminifi/include/core/expect.h b/utils/include/core/expect.h similarity index 100% rename from libminifi/include/core/expect.h rename to utils/include/core/expect.h diff --git a/libminifi/include/core/extension/Extension.h b/utils/include/core/extension/Extension.h similarity index 75% rename from libminifi/include/core/extension/Extension.h rename to utils/include/core/extension/Extension.h index 24bf7921ce..55ee26b3d1 100644 --- a/libminifi/include/core/extension/Extension.h +++ b/utils/include/core/extension/Extension.h @@ -21,7 +21,7 @@ #include #include -#include "properties/Configure.h" +#include "minifi-cpp/core/extension/Extension.h" namespace org { namespace apache { @@ -30,20 +30,20 @@ namespace minifi { namespace core { namespace extension { -class Extension; +class ExtensionImpl; using ExtensionConfig = std::shared_ptr; -using ExtensionInit = bool(*)(Extension&, const ExtensionConfig&); +using ExtensionInit = bool(*)(ExtensionImpl&, const ExtensionConfig&); using ExtensionInitImpl = bool(*)(const ExtensionConfig&); using ExtensionDeinitImpl = void(*)(); class ExtensionInitializer; -class Extension { +class ExtensionImpl : public Extension { friend class ExtensionInitializer; public: - explicit Extension(std::string name, ExtensionInitImpl init_impl, ExtensionDeinitImpl deinit_impl, ExtensionInit init); - virtual ~Extension(); + explicit ExtensionImpl(std::string name, ExtensionInitImpl init_impl, ExtensionDeinitImpl deinit_impl, ExtensionInit init); + ~ExtensionImpl() override; /** * Ensures that the extension is initialized at most once, and schedules @@ -54,11 +54,11 @@ class Extension { * @param config * @return True if the initialization succeeded */ - bool initialize(const ExtensionConfig& config) { + bool initialize(const ExtensionConfig& config) override { return init_(*this, config); } - const std::string& getName() const { + const std::string& getName() const override { return name_; } @@ -78,16 +78,16 @@ class Extension { class ExtensionInitializer { public: - explicit ExtensionInitializer(Extension& extension, const ExtensionConfig& config); + explicit ExtensionInitializer(ExtensionImpl& extension, const ExtensionConfig& config); ~ExtensionInitializer(); private: - Extension& extension_; + ExtensionImpl& extension_; }; #define REGISTER_EXTENSION(name, init, deinit) \ - static org::apache::nifi::minifi::core::extension::Extension extension_registrar(name, init, deinit, \ - [] (org::apache::nifi::minifi::core::extension::Extension& extension, const org::apache::nifi::minifi::core::extension::ExtensionConfig& config) -> bool { \ + static org::apache::nifi::minifi::core::extension::ExtensionImpl extension_registrar(name, init, deinit, \ + [] (org::apache::nifi::minifi::core::extension::ExtensionImpl& extension, const org::apache::nifi::minifi::core::extension::ExtensionConfig& config) -> bool { \ try { \ static org::apache::nifi::minifi::core::extension::ExtensionInitializer initializer(extension, config); \ return true; \ diff --git a/utils/include/core/logging/Logger.h b/utils/include/core/logging/Logger.h new file mode 100644 index 0000000000..1dd27ab6e7 --- /dev/null +++ b/utils/include/core/logging/Logger.h @@ -0,0 +1,20 @@ +/** + * 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 "minifi-cpp/core/logging/Logger.h" \ No newline at end of file diff --git a/utils/include/core/logging/LoggerFactory.h b/utils/include/core/logging/LoggerFactory.h new file mode 100644 index 0000000000..7f96322f1f --- /dev/null +++ b/utils/include/core/logging/LoggerFactory.h @@ -0,0 +1,42 @@ +/** + * + * 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 +#include + +#include "minifi-cpp/core/logging/LoggerFactory.h" +#include "core/ClassName.h" + +namespace org::apache::nifi::minifi::core::logging { + +template +class LoggerFactory : public LoggerFactoryBase { + public: + static std::shared_ptr getLogger() { + static std::shared_ptr logger = getAliasedLogger(core::className()); + return logger; + } + + static std::shared_ptr getLogger(const utils::Identifier& uuid) { + return getAliasedLogger(core::className(), uuid); + } +}; + +} // namespace org::apache::nifi::minifi::core::logging diff --git a/libminifi/include/core/state/MetricsPublisher.h b/utils/include/core/state/MetricsPublisher.h similarity index 75% rename from libminifi/include/core/state/MetricsPublisher.h rename to utils/include/core/state/MetricsPublisher.h index b71301b972..7c3f92e675 100644 --- a/libminifi/include/core/state/MetricsPublisher.h +++ b/utils/include/core/state/MetricsPublisher.h @@ -20,22 +20,19 @@ #include #include "core/Core.h" -#include "nodes/ResponseNodeLoader.h" #include "properties/Configure.h" +#include "minifi-cpp/core/state/MetricsPublisher.h" namespace org::apache::nifi::minifi::state { -class MetricsPublisher : public core::CoreComponent { +class MetricsPublisherImpl : public core::CoreComponentImpl, public virtual MetricsPublisher { public: - using CoreComponent::CoreComponent; - virtual void initialize(const std::shared_ptr& configuration, const std::shared_ptr& response_node_loader) { + using CoreComponentImpl::CoreComponentImpl; + void initialize(const std::shared_ptr& configuration, const std::shared_ptr& response_node_loader) override { gsl_Expects(configuration && response_node_loader); configuration_ = configuration; response_node_loader_ = response_node_loader; } - virtual void clearMetricNodes() = 0; - virtual void loadMetricNodes() = 0; - virtual ~MetricsPublisher() = default; protected: std::shared_ptr configuration_; diff --git a/utils/include/core/state/PublishedMetricProvider.h b/utils/include/core/state/PublishedMetricProvider.h new file mode 100644 index 0000000000..1516ecafb6 --- /dev/null +++ b/utils/include/core/state/PublishedMetricProvider.h @@ -0,0 +1,35 @@ +/** + * + * 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 +#include +#include + +#include "minifi-cpp/core/state/PublishedMetricProvider.h" + +namespace org::apache::nifi::minifi::state { + +class PublishedMetricProviderImpl : public virtual PublishedMetricProvider { + public: + std::vector calculateMetrics() override { + return {}; + } +}; + +} // namespace org::apache::nifi::minifi::state diff --git a/libminifi/include/core/state/Value.h b/utils/include/core/state/Value.h similarity index 70% rename from libminifi/include/core/state/Value.h rename to utils/include/core/state/Value.h index 2cf0903f2a..11aa17b038 100644 --- a/libminifi/include/core/state/Value.h +++ b/utils/include/core/state/Value.h @@ -26,9 +26,9 @@ #include #include #include +#include "minifi-cpp/core/state/Value.h" #include "utils/ValueParser.h" #include "utils/ValueCaster.h" -#include "utils/Export.h" #include "utils/meta/type_list.h" #include "rapidjson/writer.h" #include "rapidjson/document.h" @@ -43,58 +43,40 @@ namespace org::apache::nifi::minifi::state::response { * Extensions can be more strongly typed and can be used anywhere where an abstract * representation is needed. */ -class Value { +class ValueImpl : public Value { using ParseException = utils::internal::ParseException; public: - explicit Value(std::string value) + explicit ValueImpl(std::string value) : string_value(std::move(value)), type_id(std::type_index(typeid(std::string))) { } - virtual ~Value() = default; + ~ValueImpl() override = default; - [[nodiscard]] std::string getStringValue() const { + [[nodiscard]] std::string getStringValue() const override { return string_value; } - [[nodiscard]] const char* c_str() const { + [[nodiscard]] const char* c_str() const override { return string_value.c_str(); } - template - bool convertValue(T &ref) { - return convertValueImpl::type>(ref); - } - - [[nodiscard]] bool empty() const noexcept { + [[nodiscard]] bool empty() const noexcept override { return string_value.empty(); } - std::type_index getTypeIndex() { + std::type_index getTypeIndex() override { return type_id; } - MINIFIAPI static const std::type_index UINT64_TYPE; - MINIFIAPI static const std::type_index INT64_TYPE; - MINIFIAPI static const std::type_index UINT32_TYPE; - MINIFIAPI static const std::type_index INT_TYPE; - MINIFIAPI static const std::type_index BOOL_TYPE; - MINIFIAPI static const std::type_index DOUBLE_TYPE; - MINIFIAPI static const std::type_index STRING_TYPE; - protected: - template - bool convertValueImpl(T &ref) { - return getValue(ref); - } - template void setTypeId() { type_id = std::type_index(typeid(T)); } - virtual bool getValue(uint32_t &ref) { + bool getValue(uint32_t &ref) override { try { uint32_t value; utils::internal::ValueParser(string_value).parse(value).parseEnd(); @@ -105,7 +87,7 @@ class Value { return true; } - virtual bool getValue(int &ref) { + bool getValue(int &ref) override { try { int value; utils::internal::ValueParser(string_value).parse(value).parseEnd(); @@ -116,7 +98,7 @@ class Value { return true; } - virtual bool getValue(int64_t &ref) { + bool getValue(int64_t &ref) override { try { int64_t value; utils::internal::ValueParser(string_value).parse(value).parseEnd(); @@ -127,7 +109,7 @@ class Value { return true; } - virtual bool getValue(uint64_t &ref) { + bool getValue(uint64_t &ref) override { try { uint64_t value; utils::internal::ValueParser(string_value).parse(value).parseEnd(); @@ -138,7 +120,7 @@ class Value { return true; } - virtual bool getValue(bool &ref) { + bool getValue(bool &ref) override { try { bool value; utils::internal::ValueParser(string_value).parse(value).parseEnd(); @@ -149,7 +131,7 @@ class Value { return true; } - virtual bool getValue(double &ref) { + bool getValue(double &ref) override { try { double value; utils::internal::ValueParser(string_value).parse(value).parseEnd(); @@ -164,16 +146,16 @@ class Value { std::type_index type_id; }; -class UInt32Value : public Value { +class UInt32Value : public ValueImpl { public: explicit UInt32Value(uint32_t value) - : Value(std::to_string(value)), + : ValueImpl(std::to_string(value)), value(value) { setTypeId(); } explicit UInt32Value(const std::string &strvalue) - : Value(strvalue) { + : ValueImpl(strvalue) { utils::internal::ValueParser(strvalue).parse(value).parseEnd(); setTypeId(); } @@ -213,16 +195,16 @@ class UInt32Value : public Value { uint32_t value{}; }; -class IntValue : public Value { +class IntValue : public ValueImpl { public: explicit IntValue(int value) - : Value(std::to_string(value)), + : ValueImpl(std::to_string(value)), value(value) { setTypeId(); } explicit IntValue(const std::string &strvalue) - : Value(strvalue) { + : ValueImpl(strvalue) { utils::internal::ValueParser(strvalue).parse(value).parseEnd(); setTypeId(); } @@ -261,16 +243,16 @@ class IntValue : public Value { int value{}; }; -class BoolValue : public Value { +class BoolValue : public ValueImpl { public: explicit BoolValue(bool value) - : Value(value ? "true" : "false"), + : ValueImpl(value ? "true" : "false"), value(value) { setTypeId(); } explicit BoolValue(const std::string &strvalue) - : Value(strvalue) { + : ValueImpl(strvalue) { utils::internal::ValueParser(strvalue).parse(value).parseEnd(); setTypeId(); } @@ -318,16 +300,16 @@ class BoolValue : public Value { } }; -class UInt64Value : public Value { +class UInt64Value : public ValueImpl { public: explicit UInt64Value(uint64_t value) - : Value(std::to_string(value)), + : ValueImpl(std::to_string(value)), value(value) { setTypeId(); } explicit UInt64Value(const std::string &strvalue) - : Value(strvalue) { + : ValueImpl(strvalue) { utils::internal::ValueParser(strvalue).parse(value).parseEnd(); setTypeId(); } @@ -364,15 +346,15 @@ class UInt64Value : public Value { uint64_t value{}; }; -class Int64Value : public Value { +class Int64Value : public ValueImpl { public: explicit Int64Value(int64_t value) - : Value(std::to_string(value)), + : ValueImpl(std::to_string(value)), value(value) { setTypeId(); } explicit Int64Value(const std::string &strvalue) - : Value(strvalue) { + : ValueImpl(strvalue) { utils::internal::ValueParser(strvalue).parse(value).parseEnd(); setTypeId(); } @@ -410,15 +392,15 @@ class Int64Value : public Value { int64_t value{}; }; -class DoubleValue : public Value { +class DoubleValue : public ValueImpl { public: explicit DoubleValue(double value) - : Value(std::to_string(value)), + : ValueImpl(std::to_string(value)), value(value) { setTypeId(); } explicit DoubleValue(const std::string &strvalue) - : Value(strvalue) { + : ValueImpl(strvalue) { utils::internal::ValueParser(strvalue).parse(value).parseEnd(); setTypeId(); } @@ -461,15 +443,15 @@ static inline std::shared_ptr createValue(const bool &object) { } static inline std::shared_ptr createValue(const char *object) { - return std::make_shared(object); + return std::make_shared(object); } static inline std::shared_ptr createValue(char *object) { - return std::make_shared(std::string(object)); + return std::make_shared(std::string(object)); } static inline std::shared_ptr createValue(const std::string &object) { - return std::make_shared(object); + return std::make_shared(object); } static inline std::shared_ptr createValue(const uint32_t &object) { @@ -496,90 +478,23 @@ static inline std::shared_ptr createValue(const double &object) { return std::make_shared(object); } +template +requires (ValueNode::supported_types::contains()) // NOLINT +/* implicit, because it doesn't change the meaning, and it simplifies construction of maps */ +ValueNode::ValueNode(const T value) // NOLINT + :value_{createValue(value)} +{} + /** - * Purpose: ValueNode is the AST container for a value + * Define the representations and eventual storage relationships through + * createValue */ -class ValueNode { - using supported_types = utils::meta::type_list; - - public: - ValueNode() = default; - - template - requires (supported_types::contains()) // NOLINT - /* implicit, because it doesn't change the meaning, and it simplifies construction of maps */ - ValueNode(const T value) // NOLINT - :value_{createValue(value)} - {} - - /** - * Define the representations and eventual storage relationships through - * createValue - */ - template - requires (supported_types::contains()) // NOLINT - ValueNode& operator=(const T ref) { - value_ = createValue(ref); - return *this; - } - - inline bool operator==(const ValueNode &rhs) const { - return to_string() == rhs.to_string(); - } - - inline bool operator==(const char* rhs) const { - return to_string() == rhs; - } - - friend bool operator==(const char* lhs, const ValueNode& rhs) { - return lhs == rhs.to_string(); - } - - [[nodiscard]] std::string to_string() const { - return value_ ? value_->getStringValue() : ""; - } - - [[nodiscard]] std::shared_ptr getValue() const { - return value_; - } - - [[nodiscard]] bool empty() const noexcept { - return value_ == nullptr || value_->empty(); - } - - protected: - std::shared_ptr value_; -}; - -struct SerializedResponseNode { - std::string name; - ValueNode value{}; - bool array = false; - bool collapsible = true; - bool keep_empty = false; - std::vector children{}; - - [[nodiscard]] bool empty() const noexcept { - return value.empty() && children.empty(); - } - - template> - [[nodiscard]] std::string to_string() const { - rapidjson::Document doc; - doc.SetObject(); - doc.AddMember(rapidjson::Value(name.c_str(), doc.GetAllocator()), nodeToJson(*this, doc.GetAllocator()), doc.GetAllocator()); - rapidjson::StringBuffer buf; - Writer writer{buf}; - doc.Accept(writer); - return buf.GetString(); - } - - [[nodiscard]] std::string to_pretty_string() const; - - private: - static rapidjson::Value nodeToJson(const SerializedResponseNode& node, rapidjson::MemoryPoolAllocator& alloc); -}; - +template +requires (ValueNode::supported_types::contains()) // NOLINT +ValueNode& ValueNode::operator=(const T ref) { + value_ = createValue(ref); + return *this; +} inline std::string to_string(const SerializedResponseNode& node) { return node.to_string(); } diff --git a/utils/include/core/state/nodes/ResponseNode.h b/utils/include/core/state/nodes/ResponseNode.h new file mode 100644 index 0000000000..afd2f7087d --- /dev/null +++ b/utils/include/core/state/nodes/ResponseNode.h @@ -0,0 +1,88 @@ +/** + * + * 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 +#include +#include +#include +#include +#include + +#include "core/Core.h" +#include "core/Connectable.h" +#include "minifi-cpp/core/state/nodes/MetricsBase.h" +#include "core/state/PublishedMetricProvider.h" + +namespace org::apache::nifi::minifi::state::response { + +class ResponseNode; +using SharedResponseNode = gsl::not_null>; + +/** + * Purpose: Defines a metric. Serialization is intended to be thread safe. + */ +class ResponseNodeImpl : public core::ConnectableImpl, public PublishedMetricProviderImpl, public virtual ResponseNode { + public: + ResponseNodeImpl() + : core::ConnectableImpl("metric"), + is_array_(false) { + } + + explicit ResponseNodeImpl(const std::string_view name) + : core::ConnectableImpl(name), + is_array_(false) { + } + + ResponseNodeImpl(const std::string_view name, const utils::Identifier& uuid) + : core::ConnectableImpl(name, uuid), + is_array_(false) { + } + + ~ResponseNodeImpl() override = default; + + static std::vector serializeAndMergeResponseNodes(const std::vector& nodes); + + void yield() override { + } + + bool isRunning() const override { + return true; + } + + bool isWorkAvailable() override { + return true; + } + + bool isArray() const override { + return is_array_; + } + + virtual bool isEmpty() override { + return false; + } + + protected: + bool is_array_; + + void setArray(bool array) { + is_array_ = array; + } +}; + +} // namespace org::apache::nifi::minifi::state::response diff --git a/libminifi/include/http/BaseHTTPClient.h b/utils/include/http/BaseHTTPClient.h similarity index 99% rename from libminifi/include/http/BaseHTTPClient.h rename to utils/include/http/BaseHTTPClient.h index 48e01eee6c..016abb12bc 100644 --- a/libminifi/include/http/BaseHTTPClient.h +++ b/utils/include/http/BaseHTTPClient.h @@ -26,8 +26,7 @@ #include #include "utils/ByteArrayCallback.h" -#include "controllers/SSLContextService.h" -#include "core/Deprecated.h" +#include "minifi-cpp/controllers/SSLContextService.h" #include "utils/gsl.h" namespace org::apache::nifi::minifi::http { diff --git a/libminifi/include/http/HTTPCallback.h b/utils/include/http/HTTPCallback.h similarity index 99% rename from libminifi/include/http/HTTPCallback.h rename to utils/include/http/HTTPCallback.h index 3ea6765d02..991085baf7 100644 --- a/libminifi/include/http/HTTPCallback.h +++ b/utils/include/http/HTTPCallback.h @@ -25,7 +25,7 @@ #include #include -#include "core/logging/LoggerConfiguration.h" +#include "core/logging/LoggerFactory.h" #include "utils/ByteArrayCallback.h" #include "http/BaseHTTPClient.h" diff --git a/libminifi/include/http/HTTPClient.h b/utils/include/http/HTTPClient.h similarity index 97% rename from libminifi/include/http/HTTPClient.h rename to utils/include/http/HTTPClient.h index 28ee9f26fd..0cd92dfcbd 100644 --- a/libminifi/include/http/HTTPClient.h +++ b/utils/include/http/HTTPClient.h @@ -41,9 +41,10 @@ #include #include "utils/ByteArrayCallback.h" -#include "controllers/SSLContextService.h" +#include "minifi-cpp/controllers/SSLContextService.h" #include "core/logging/Logger.h" -#include "core/logging/LoggerConfiguration.h" +#include "core/logging/LoggerFactory.h" +#include "core/Connectable.h" namespace org::apache::nifi::minifi::http { @@ -66,7 +67,7 @@ struct HTTPResponseData { } }; -class HTTPClient : public BaseHTTPClient, public core::Connectable { +class HTTPClient : public BaseHTTPClient, public core::ConnectableImpl { public: HTTPClient(); @@ -215,7 +216,7 @@ class HTTPClient : public BaseHTTPClient, public core::Connectable { gsl_Expects(ctx); gsl_Expects(param); auto& ssl_context_service = *static_cast(param); - if (!ssl_context_service.configure_ssl_context(static_cast(ctx))) { + if (!ssl_context_service.configure_ssl_context(ctx)) { return CURLE_FAILED_INIT; } return CURLE_OK; diff --git a/libminifi/include/http/HTTPStream.h b/utils/include/http/HTTPStream.h similarity index 98% rename from libminifi/include/http/HTTPStream.h rename to utils/include/http/HTTPStream.h index 61033f2ef6..8bb4329b04 100644 --- a/libminifi/include/http/HTTPStream.h +++ b/utils/include/http/HTTPStream.h @@ -29,7 +29,7 @@ namespace org::apache::nifi::minifi::http { -class HttpStream : public io::BaseStream { +class HttpStream : public io::BaseStreamImpl { public: /** * File Stream constructor that accepts an fstream shared pointer. diff --git a/utils/include/io/ArchiveStream.h b/utils/include/io/ArchiveStream.h new file mode 100644 index 0000000000..5c49621276 --- /dev/null +++ b/utils/include/io/ArchiveStream.h @@ -0,0 +1,20 @@ +/** + * + * 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 "minifi-cpp/io/ArchiveStream.h" diff --git a/libminifi/include/io/AsioStream.h b/utils/include/io/AsioStream.h similarity index 98% rename from libminifi/include/io/AsioStream.h rename to utils/include/io/AsioStream.h index 55bae80cbd..0254c454cc 100644 --- a/libminifi/include/io/AsioStream.h +++ b/utils/include/io/AsioStream.h @@ -31,7 +31,7 @@ namespace org::apache::nifi::minifi::io { template -class AsioStream : public io::BaseStream { +class AsioStream : public io::BaseStreamImpl { public: explicit AsioStream(AsioSocketStreamType&& stream) : stream_(std::move(stream)) {} diff --git a/utils/include/io/BaseStream.h b/utils/include/io/BaseStream.h new file mode 100644 index 0000000000..99b62d1593 --- /dev/null +++ b/utils/include/io/BaseStream.h @@ -0,0 +1,37 @@ +/** + * + * 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 "InputStream.h" +#include "OutputStream.h" +#include "minifi-cpp/io/BaseStream.h" + +namespace org::apache::nifi::minifi::io { + +/** + * Base Stream is the base of a composable stream architecture. + * Intended to be the base of layered streams ala DatInputStreams in Java. + * + * ** Not intended to be thread safe as it is not intended to be shared** + * + * Extensions may be thread safe and thus shareable, but that is up to the implementation. + */ +class BaseStreamImpl : public virtual InputStreamImpl, public virtual OutputStreamImpl, public virtual BaseStream {}; + +} // namespace org::apache::nifi::minifi::io diff --git a/libminifi/include/io/BufferStream.h b/utils/include/io/BufferStream.h similarity index 98% rename from libminifi/include/io/BufferStream.h rename to utils/include/io/BufferStream.h index eb00c5dc89..cadf54ab41 100644 --- a/libminifi/include/io/BufferStream.h +++ b/utils/include/io/BufferStream.h @@ -31,7 +31,7 @@ namespace nifi { namespace minifi { namespace io { -class BufferStream : public BaseStream { +class BufferStream : public BaseStreamImpl { public: BufferStream() = default; diff --git a/libminifi/include/io/CRCStream.h b/utils/include/io/CRCStream.h similarity index 95% rename from libminifi/include/io/CRCStream.h rename to utils/include/io/CRCStream.h index e22b96b12d..e0fa7b35ac 100644 --- a/libminifi/include/io/CRCStream.h +++ b/utils/include/io/CRCStream.h @@ -27,8 +27,6 @@ #include #ifdef WIN32 -// ignore the warning about inheriting via dominance from CRCStreamBase -#pragma warning(disable : 4250) #include #else @@ -47,7 +45,7 @@ namespace io { namespace internal { template -class CRCStreamBase : public virtual Stream { +class CRCStreamBase : public virtual StreamImpl { public: StreamType *getstream() const { return child_stream_; @@ -79,7 +77,7 @@ class CRCStreamBase : public virtual Stream { }; template -class InputCRCStream : public virtual CRCStreamBase, public InputStream { +class InputCRCStream : public virtual CRCStreamBase, public virtual InputStream { protected: using CRCStreamBase::child_stream_; using CRCStreamBase::crc_; @@ -99,7 +97,7 @@ class InputCRCStream : public virtual CRCStreamBase, public InputStr }; template -class OutputCRCStream : public virtual CRCStreamBase, public OutputStream { +class OutputCRCStream : public virtual CRCStreamBase, public virtual OutputStream { protected: using CRCStreamBase::child_stream_; using CRCStreamBase::crc_; diff --git a/libminifi/include/io/FileStream.h b/utils/include/io/FileStream.h similarity index 98% rename from libminifi/include/io/FileStream.h rename to utils/include/io/FileStream.h index 82bfa0f97d..1032ab4a8e 100644 --- a/libminifi/include/io/FileStream.h +++ b/utils/include/io/FileStream.h @@ -33,7 +33,7 @@ namespace org::apache::nifi::minifi::io { * Design: Simply extends BaseStream and overrides readData/writeData to allow a sink to the * fstream object. */ -class FileStream : public io::BaseStream { +class FileStream : public io::BaseStreamImpl { public: /** * File Stream constructor that accepts an fstream shared pointer. diff --git a/utils/include/io/InputStream.h b/utils/include/io/InputStream.h new file mode 100644 index 0000000000..07e629d5a3 --- /dev/null +++ b/utils/include/io/InputStream.h @@ -0,0 +1,33 @@ +/** + * + * 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 "minifi-cpp/io/InputStream.h" +#include "Stream.h" + +namespace org::apache::nifi::minifi::io { + +class InputStreamImpl : public virtual InputStream, public StreamImpl { + public: + [[nodiscard]] virtual size_t size() const { + throw std::runtime_error("Querying size is not supported"); + } +}; + +} // namespace org::apache::nifi::minifi::io \ No newline at end of file diff --git a/utils/include/io/OutputStream.h b/utils/include/io/OutputStream.h new file mode 100644 index 0000000000..c7fae4f5ea --- /dev/null +++ b/utils/include/io/OutputStream.h @@ -0,0 +1,27 @@ +/** + * + * 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 "minifi-cpp/io/OutputStream.h" + +namespace org::apache::nifi::minifi::io { + +using OutputStreamImpl = OutputStream; + +} // namespace org::apache::nifi::minifi::io diff --git a/utils/include/io/Stream.h b/utils/include/io/Stream.h new file mode 100644 index 0000000000..f03aeda795 --- /dev/null +++ b/utils/include/io/Stream.h @@ -0,0 +1,49 @@ +/** + * + * 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 "minifi-cpp/io/Stream.h" + +namespace org::apache::nifi::minifi::io { + +/** + * All streams serialize/deserialize in big-endian + */ +class StreamImpl : public virtual Stream { + public: + void close() override {} + + void seek(size_t /*offset*/) override { + throw std::runtime_error("Seek is not supported"); + } + + [[nodiscard]] size_t tell() const override { + throw std::runtime_error("Tell is not supported"); + } + + int initialize() override { + return 1; + } + + [[nodiscard]] std::span getBuffer() const override { + throw std::runtime_error("Not a buffered stream"); + } +}; + +} // namespace org::apache::nifi::minifi::io diff --git a/libminifi/include/io/StreamPipe.h b/utils/include/io/StreamPipe.h similarity index 98% rename from libminifi/include/io/StreamPipe.h rename to utils/include/io/StreamPipe.h index c24d04bfa4..877630bcb4 100644 --- a/libminifi/include/io/StreamPipe.h +++ b/utils/include/io/StreamPipe.h @@ -25,7 +25,7 @@ #include #include "InputStream.h" #include "OutputStream.h" -#include "StreamCallback.h" +#include "minifi-cpp/io/StreamCallback.h" namespace org::apache::nifi::minifi { namespace internal { diff --git a/libminifi/include/io/StreamSlice.h b/utils/include/io/StreamSlice.h similarity index 95% rename from libminifi/include/io/StreamSlice.h rename to utils/include/io/StreamSlice.h index dbce76a8f7..f11a2aba4a 100644 --- a/libminifi/include/io/StreamSlice.h +++ b/utils/include/io/StreamSlice.h @@ -20,7 +20,7 @@ #include #include -#include "StreamCallback.h" +#include "minifi-cpp/io/StreamCallback.h" #include "InputStream.h" namespace org::apache::nifi::minifi::io { @@ -29,7 +29,7 @@ namespace org::apache::nifi::minifi::io { * A wrapped Base Stream with configurable offset and size * It hides the original (bigger stream) and acts like the stream starts and ends at the configured offset/size */ -class StreamSlice : public InputStream { +class StreamSlice : public InputStreamImpl { public: StreamSlice(std::shared_ptr stream, size_t offset, size_t size); diff --git a/libminifi/include/io/ZlibStream.h b/utils/include/io/ZlibStream.h similarity index 88% rename from libminifi/include/io/ZlibStream.h rename to utils/include/io/ZlibStream.h index 33097371d4..76a5f18639 100644 --- a/libminifi/include/io/ZlibStream.h +++ b/utils/include/io/ZlibStream.h @@ -16,8 +16,7 @@ * limitations under the License. */ -#ifndef LIBMINIFI_INCLUDE_IO_ZLIBSTREAM_H_ -#define LIBMINIFI_INCLUDE_IO_ZLIBSTREAM_H_ +#pragma once #include @@ -26,14 +25,11 @@ #include #include "OutputStream.h" -#include "core/logging/Logger.h" +#include "Stream.h" +#include "minifi-cpp/core/logging/Logger.h" #include "utils/gsl.h" -namespace org { -namespace apache { -namespace nifi { -namespace minifi { -namespace io { +namespace org::apache::nifi::minifi::io { enum class ZlibCompressionFormat : uint8_t { ZLIB, @@ -47,7 +43,7 @@ enum class ZlibStreamState : uint8_t { FINISHED }; -class ZlibBaseStream : public OutputStream { +class ZlibBaseStream : public StreamImpl, public virtual OutputStreamImpl { public: virtual bool isFinished() const; @@ -108,9 +104,4 @@ class ZlibDecompressStream : public ZlibBaseStream { std::shared_ptr logger_; }; -} // namespace io -} // namespace minifi -} // namespace nifi -} // namespace apache -} // namespace org -#endif // LIBMINIFI_INCLUDE_IO_ZLIBSTREAM_H_ +} // namespace org::apache::nifi::minifi:io diff --git a/libminifi/include/io/validation.h b/utils/include/io/validation.h similarity index 100% rename from libminifi/include/io/validation.h rename to utils/include/io/validation.h diff --git a/libminifi/include/utils/ArrayUtils.h b/utils/include/utils/ArrayUtils.h similarity index 73% rename from libminifi/include/utils/ArrayUtils.h rename to utils/include/utils/ArrayUtils.h index b7c9a5aa2f..bed9822e2a 100644 --- a/libminifi/include/utils/ArrayUtils.h +++ b/utils/include/utils/ArrayUtils.h @@ -27,6 +27,28 @@ namespace org::apache::nifi::minifi::utils { +namespace detail { +template +constexpr auto tuple_to_array_impl(const std::tuple& data, std::index_sequence) { + return std::array{std::get(data)...}; +}; + +template +constexpr auto array_to_tuple_impl(const std::array& data, std::index_sequence) { + return std::make_tuple(data[Idx]...); +}; +} // namespace detail + +template +constexpr auto tuple_to_array(const std::tuple& data) { + return detail::tuple_to_array_impl(data, std::make_index_sequence{}); +}; + +template +constexpr auto array_to_tuple(const std::array& data) { + return detail::array_to_tuple_impl(data, std::make_index_sequence{}); +}; + /** * Concatenates the arrays in the argument list. * Similar to std::tuple_cat, but for arrays instead of tuples. @@ -34,12 +56,7 @@ namespace org::apache::nifi::minifi::utils { */ template constexpr auto array_cat(const std::array&... arrays) { - std::array result; - std::size_t index{}; - - ((std::copy_n(arrays.begin(), sizes, result.begin() + index), index += sizes), ...); - - return result; + return tuple_to_array(std::tuple_cat(array_to_tuple(arrays)...)); } template diff --git a/libminifi/include/controllers/keyvalue/AutoPersistor.h b/utils/include/utils/AutoPersistor.h similarity index 100% rename from libminifi/include/controllers/keyvalue/AutoPersistor.h rename to utils/include/utils/AutoPersistor.h diff --git a/libminifi/include/utils/BackTrace.h b/utils/include/utils/BackTrace.h similarity index 100% rename from libminifi/include/utils/BackTrace.h rename to utils/include/utils/BackTrace.h diff --git a/libminifi/include/utils/ByteArrayCallback.h b/utils/include/utils/ByteArrayCallback.h similarity index 98% rename from libminifi/include/utils/ByteArrayCallback.h rename to utils/include/utils/ByteArrayCallback.h index 12daf15269..2145de7aa7 100644 --- a/libminifi/include/utils/ByteArrayCallback.h +++ b/utils/include/utils/ByteArrayCallback.h @@ -20,11 +20,12 @@ #include #include #include +#include #include "concurrentqueue.h" -#include "FlowFileRecord.h" #include "core/logging/LoggerFactory.h" #include "utils/gsl.h" +#include "io/InputStream.h" namespace org::apache::nifi::minifi::utils { diff --git a/libminifi/include/utils/CallBackTimer.h b/utils/include/utils/CallBackTimer.h similarity index 100% rename from libminifi/include/utils/CallBackTimer.h rename to utils/include/utils/CallBackTimer.h diff --git a/libminifi/include/utils/ClassUtils.h b/utils/include/utils/ClassUtils.h similarity index 100% rename from libminifi/include/utils/ClassUtils.h rename to utils/include/utils/ClassUtils.h diff --git a/libminifi/include/utils/CollectionUtils.h b/utils/include/utils/CollectionUtils.h similarity index 100% rename from libminifi/include/utils/CollectionUtils.h rename to utils/include/utils/CollectionUtils.h diff --git a/libminifi/include/utils/Cron.h b/utils/include/utils/Cron.h similarity index 100% rename from libminifi/include/utils/Cron.h rename to utils/include/utils/Cron.h diff --git a/libminifi/include/utils/Deleters.h b/utils/include/utils/Deleters.h similarity index 98% rename from libminifi/include/utils/Deleters.h rename to utils/include/utils/Deleters.h index 13e75a90c5..f427183397 100644 --- a/libminifi/include/utils/Deleters.h +++ b/utils/include/utils/Deleters.h @@ -25,7 +25,6 @@ #endif /* WIN32 */ #include #include -#include "utils/net/DNS.h" namespace org { namespace apache { diff --git a/libminifi/include/utils/Enum.h b/utils/include/utils/Enum.h similarity index 100% rename from libminifi/include/utils/Enum.h rename to utils/include/utils/Enum.h diff --git a/libminifi/include/utils/Environment.h b/utils/include/utils/Environment.h similarity index 100% rename from libminifi/include/utils/Environment.h rename to utils/include/utils/Environment.h diff --git a/libminifi/include/utils/Error.h b/utils/include/utils/Error.h similarity index 100% rename from libminifi/include/utils/Error.h rename to utils/include/utils/Error.h diff --git a/libminifi/include/core/Deprecated.h b/utils/include/utils/Export.h similarity index 70% rename from libminifi/include/core/Deprecated.h rename to utils/include/utils/Export.h index 4dd7e54a25..175821d93c 100644 --- a/libminifi/include/core/Deprecated.h +++ b/utils/include/utils/Export.h @@ -1,5 +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. @@ -15,15 +15,21 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#ifndef LIBMINIFI_INCLUDE_CORE_DEPRECATED_H_ -#define LIBMINIFI_INCLUDE_CORE_DEPRECATED_H_ -#ifdef _MSC_VER -#define DEPRECATED(v, ev) __declspec(deprecated) -#elif defined(__GNUC__) | defined(__clang__) -#define DEPRECATED(v, ev) __attribute__((__deprecated__)) +#pragma once + +#ifdef WIN32 + #ifdef LIBMINIFI + #define MINIFIAPI __declspec(dllexport) + #else + #define MINIFIAPI __declspec(dllimport) + #endif + #ifdef MODULE_NAME + #define EXTENSIONAPI __declspec(dllexport) + #else + #define EXTENSIONAPI __declspec(dllimport) + #endif #else -#define DEPRECATED(v, ev) + #define MINIFIAPI + #define EXTENSIONAPI #endif - -#endif /* LIBMINIFI_INCLUDE_CORE_DEPRECATED_H_ */ diff --git a/libminifi/include/utils/FailurePolicy.h b/utils/include/utils/FailurePolicy.h similarity index 100% rename from libminifi/include/utils/FailurePolicy.h rename to utils/include/utils/FailurePolicy.h diff --git a/libminifi/include/utils/FifoExecutor.h b/utils/include/utils/FifoExecutor.h similarity index 100% rename from libminifi/include/utils/FifoExecutor.h rename to utils/include/utils/FifoExecutor.h diff --git a/libminifi/include/utils/FileMutex.h b/utils/include/utils/FileMutex.h similarity index 100% rename from libminifi/include/utils/FileMutex.h rename to utils/include/utils/FileMutex.h diff --git a/libminifi/include/utils/GeneralUtils.h b/utils/include/utils/GeneralUtils.h similarity index 89% rename from libminifi/include/utils/GeneralUtils.h rename to utils/include/utils/GeneralUtils.h index 98656afae4..034bf20586 100644 --- a/libminifi/include/utils/GeneralUtils.h +++ b/utils/include/utils/GeneralUtils.h @@ -67,27 +67,17 @@ struct type_identity { using gsl::owner; -namespace internal { - /* * We need this base class to enable safe multiple inheritance * from std::enable_shared_from_this, it also needs to be polymorphic * to allow dynamic_cast to the derived class. */ -struct EnableSharedFromThisBase : std::enable_shared_from_this { - virtual ~EnableSharedFromThisBase() = default; -}; +struct EnableSharedFromThis : virtual std::enable_shared_from_this { + virtual ~EnableSharedFromThis() = default; -} // namespace internal - -/* - * The virtual inheritance ensures that there is only a single - * std::weak_ptr instance in each instance. - */ -template -struct EnableSharedFromThis : virtual internal::EnableSharedFromThisBase { + template std::shared_ptr sharedFromThis() { - return std::dynamic_pointer_cast(internal::EnableSharedFromThisBase::shared_from_this()); + return std::dynamic_pointer_cast(shared_from_this()); } }; diff --git a/libminifi/include/utils/HTTPUtils.h b/utils/include/utils/HTTPUtils.h similarity index 100% rename from libminifi/include/utils/HTTPUtils.h rename to utils/include/utils/HTTPUtils.h diff --git a/libminifi/include/utils/Hash.h b/utils/include/utils/Hash.h similarity index 100% rename from libminifi/include/utils/Hash.h rename to utils/include/utils/Hash.h diff --git a/libminifi/include/utils/Id.h b/utils/include/utils/Id.h similarity index 71% rename from libminifi/include/utils/Id.h rename to utils/include/utils/Id.h index 33c8f722d7..b9f7208d27 100644 --- a/libminifi/include/utils/Id.h +++ b/utils/include/utils/Id.h @@ -29,9 +29,10 @@ class uuid; #endif -#include "core/logging/Logger.h" -#include "properties/Properties.h" -#include "SmallString.h" +#include "minifi-cpp/utils/Id.h" +#include "minifi-cpp/core/logging/Logger.h" +#include "minifi-cpp/properties/Properties.h" +#include "utils/SmallString.h" #include "Hash.h" #define UUID_TIME_IMPL 0 @@ -48,49 +49,6 @@ class uuid; namespace org::apache::nifi::minifi::utils { -class Identifier { - friend struct IdentifierTestAccessor; - static constexpr const char* hex_lut = "0123456789abcdef"; - - public: - using Data = std::array; - - Identifier() = default; - explicit Identifier(const Data& data); - Identifier &operator=(const Data& data); - - Identifier &operator=(const std::string& idStr); - - explicit operator bool() const { - return !isNil(); - } - - bool operator!=(const Identifier& other) const; - bool operator==(const Identifier& other) const; - bool operator<(const Identifier& other) const; - - bool isNil() const; - - // Numerous places query the string representation - // just to then forward the temporary to build logs, - // streams, or others. Dynamically allocating in these - // instances is wasteful as we immediately discard - // the result. The difference on the test machine is 8x, - // building the representation itself takes 10ns, while - // subsequently turning it into a std::string would take - // 70ns more. - SmallString<36> to_string() const; - - static std::optional parse(const std::string& str); - - private: - friend struct ::std::hash; - - static bool parseByte(Data& data, const uint8_t* input, int& charIdx, int& byteIdx); - - Data data_{}; -}; - class IdGenerator { public: Identifier generate(); diff --git a/libminifi/include/utils/IntervalSwitch.h b/utils/include/utils/IntervalSwitch.h similarity index 100% rename from libminifi/include/utils/IntervalSwitch.h rename to utils/include/utils/IntervalSwitch.h diff --git a/libminifi/include/utils/JsonCallback.h b/utils/include/utils/JsonCallback.h similarity index 100% rename from libminifi/include/utils/JsonCallback.h rename to utils/include/utils/JsonCallback.h diff --git a/libminifi/include/utils/LineByLineInputOutputStreamCallback.h b/utils/include/utils/LineByLineInputOutputStreamCallback.h similarity index 100% rename from libminifi/include/utils/LineByLineInputOutputStreamCallback.h rename to utils/include/utils/LineByLineInputOutputStreamCallback.h diff --git a/utils/include/utils/Literals.h b/utils/include/utils/Literals.h new file mode 100644 index 0000000000..741166a1ac --- /dev/null +++ b/utils/include/utils/Literals.h @@ -0,0 +1,19 @@ +/** + * 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 "minifi-cpp/utils/Literals.h" diff --git a/libminifi/include/utils/LogUtils.h b/utils/include/utils/LogUtils.h similarity index 100% rename from libminifi/include/utils/LogUtils.h rename to utils/include/utils/LogUtils.h diff --git a/libminifi/include/utils/Macro.h b/utils/include/utils/Macro.h similarity index 100% rename from libminifi/include/utils/Macro.h rename to utils/include/utils/Macro.h diff --git a/libminifi/include/utils/MapUtils.h b/utils/include/utils/MapUtils.h similarity index 100% rename from libminifi/include/utils/MapUtils.h rename to utils/include/utils/MapUtils.h diff --git a/libminifi/include/utils/MinifiConcurrentQueue.h b/utils/include/utils/MinifiConcurrentQueue.h similarity index 95% rename from libminifi/include/utils/MinifiConcurrentQueue.h rename to utils/include/utils/MinifiConcurrentQueue.h index 34c9bca278..490cc601a3 100644 --- a/libminifi/include/utils/MinifiConcurrentQueue.h +++ b/utils/include/utils/MinifiConcurrentQueue.h @@ -14,9 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#ifndef LIBMINIFI_INCLUDE_UTILS_MINIFICONCURRENTQUEUE_H_ -#define LIBMINIFI_INCLUDE_UTILS_MINIFICONCURRENTQUEUE_H_ - +#pragma once #include #include @@ -29,11 +27,7 @@ #include "utils/TryMoveCall.h" -namespace org { -namespace apache { -namespace nifi { -namespace minifi { -namespace utils { +namespace org::apache::nifi::minifi::utils { // Provides a queue API and guarantees no race conditions in case of multiple producers and consumers. // Guarantees elements to be dequeued in order of insertion @@ -57,8 +51,6 @@ class ConcurrentQueue { return *this; } - virtual ~ConcurrentQueue() = default; - bool tryDequeue(T& out) { std::unique_lock lck(mtx_); return tryDequeueImpl(lck, out); @@ -244,10 +236,4 @@ class ConditionConcurrentQueue : private ConcurrentQueue { std::condition_variable cv_; }; -} // namespace utils -} // namespace minifi -} // namespace nifi -} // namespace apache -} // namespace org - -#endif // LIBMINIFI_INCLUDE_UTILS_MINIFICONCURRENTQUEUE_H_ +} // namespace org::apache::nifi::minifi::utils diff --git a/libminifi/include/utils/Monitors.h b/utils/include/utils/Monitors.h similarity index 100% rename from libminifi/include/utils/Monitors.h rename to utils/include/utils/Monitors.h diff --git a/libminifi/include/utils/OptionalUtils.h b/utils/include/utils/OptionalUtils.h similarity index 100% rename from libminifi/include/utils/OptionalUtils.h rename to utils/include/utils/OptionalUtils.h diff --git a/libminifi/include/utils/OsUtils.h b/utils/include/utils/OsUtils.h similarity index 100% rename from libminifi/include/utils/OsUtils.h rename to utils/include/utils/OsUtils.h diff --git a/libminifi/include/utils/ProcessCpuUsageTracker.h b/utils/include/utils/ProcessCpuUsageTracker.h similarity index 100% rename from libminifi/include/utils/ProcessCpuUsageTracker.h rename to utils/include/utils/ProcessCpuUsageTracker.h diff --git a/utils/include/utils/PropertyErrors.h b/utils/include/utils/PropertyErrors.h new file mode 100644 index 0000000000..e13db4d54f --- /dev/null +++ b/utils/include/utils/PropertyErrors.h @@ -0,0 +1,19 @@ +/** + * 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 "minifi-cpp/utils/PropertyErrors.h" diff --git a/libminifi/include/utils/RegexUtils.h b/utils/include/utils/RegexUtils.h similarity index 100% rename from libminifi/include/utils/RegexUtils.h rename to utils/include/utils/RegexUtils.h diff --git a/libminifi/include/utils/Searcher.h b/utils/include/utils/Searcher.h similarity index 100% rename from libminifi/include/utils/Searcher.h rename to utils/include/utils/Searcher.h diff --git a/utils/include/utils/SmallString.h b/utils/include/utils/SmallString.h new file mode 100644 index 0000000000..6020d9c5c1 --- /dev/null +++ b/utils/include/utils/SmallString.h @@ -0,0 +1,39 @@ +/** + * 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 +#include +#include +#include +#include "fmt/format.h" +#include "minifi-cpp/utils/SmallString.h" + +template +struct fmt::formatter> { + formatter string_view_formatter; + + template + constexpr auto parse(ParseContext& ctx) { + return string_view_formatter.parse(ctx); + } + + template + auto format(const org::apache::nifi::minifi::utils::SmallString& small_string, FormatContext& ctx) const { + return string_view_formatter.format(small_string.view(), ctx); + } +}; diff --git a/libminifi/include/utils/StoppableThread.h b/utils/include/utils/StoppableThread.h similarity index 100% rename from libminifi/include/utils/StoppableThread.h rename to utils/include/utils/StoppableThread.h diff --git a/libminifi/include/utils/StringUtils.h b/utils/include/utils/StringUtils.h similarity index 100% rename from libminifi/include/utils/StringUtils.h rename to utils/include/utils/StringUtils.h diff --git a/libminifi/include/utils/SystemCpuUsageTracker.h b/utils/include/utils/SystemCpuUsageTracker.h similarity index 100% rename from libminifi/include/utils/SystemCpuUsageTracker.h rename to utils/include/utils/SystemCpuUsageTracker.h diff --git a/libminifi/include/utils/ThreadPool.h b/utils/include/utils/ThreadPool.h similarity index 95% rename from libminifi/include/utils/ThreadPool.h rename to utils/include/utils/ThreadPool.h index cafcb2b94e..7e8de1d336 100644 --- a/libminifi/include/utils/ThreadPool.h +++ b/utils/include/utils/ThreadPool.h @@ -37,9 +37,8 @@ #include "MinifiConcurrentQueue.h" #include "Monitors.h" #include "core/expect.h" -#include "controllers/ThreadManagementService.h" -#include "core/controller/ControllerService.h" -#include "core/controller/ControllerServiceProvider.h" +#include "minifi-cpp/controllers/ThreadManagementService.h" +#include "minifi-cpp/core/controller/ControllerServiceLookup.h" namespace org::apache::nifi::minifi::utils { @@ -138,7 +137,7 @@ class WorkerThread { class ThreadPool { public: ThreadPool(int max_worker_threads = 2, - core::controller::ControllerServiceProvider* controller_service_provider = nullptr, std::string name = "NamelessPool"); + core::controller::ControllerServiceLookup* controller_service_provider = nullptr, std::string name = "NamelessPool"); ThreadPool(const ThreadPool &other) = delete; ThreadPool& operator=(const ThreadPool &other) = delete; @@ -231,7 +230,7 @@ class ThreadPool { start(); } - void setControllerServiceProvider(core::controller::ControllerServiceProvider* controller_service_provider) { + void setControllerServiceProvider(core::controller::ControllerServiceLookup* controller_service_provider) { std::lock_guard lock(manager_mutex_); bool was_running = running_; if (was_running) { @@ -273,7 +272,7 @@ class ThreadPool { std::thread delayed_scheduler_thread_; std::atomic adjust_threads_; std::atomic running_; - core::controller::ControllerServiceProvider* controller_service_provider_; + core::controller::ControllerServiceLookup* controller_service_provider_; std::shared_ptr thread_manager_; ConcurrentQueue> deceased_thread_queue_; ConditionConcurrentQueue worker_queue_; diff --git a/libminifi/include/utils/TimeUtil.h b/utils/include/utils/TimeUtil.h similarity index 88% rename from libminifi/include/utils/TimeUtil.h rename to utils/include/utils/TimeUtil.h index f167865e4b..974e7228b8 100644 --- a/libminifi/include/utils/TimeUtil.h +++ b/utils/include/utils/TimeUtil.h @@ -33,6 +33,7 @@ #include #include "StringUtils.h" +#include "minifi-cpp/utils/TimeUtil.h" // libc++ doesn't define operator<=> on durations, and apparently the operator rewrite rules don't automagically make one #if defined(_LIBCPP_VERSION) @@ -76,41 +77,6 @@ inline uint64_t getTimeNano() { return std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch()).count(); } -/** - * Mockable clock classes - */ -class Clock { - public: - virtual ~Clock() = default; - virtual std::chrono::milliseconds timeSinceEpoch() const = 0; - virtual bool wait_until(std::condition_variable& cv, std::unique_lock& lck, std::chrono::milliseconds time, const std::function& pred) { - return cv.wait_for(lck, time - timeSinceEpoch(), pred); - } -}; - -class SystemClock : public Clock { - public: - std::chrono::milliseconds timeSinceEpoch() const override { - return std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch()); - } -}; - -class SteadyClock : public Clock { - public: - std::chrono::milliseconds timeSinceEpoch() const override { - return std::chrono::duration_cast(std::chrono::steady_clock::now().time_since_epoch()); - } - - virtual std::chrono::time_point now() const { - return std::chrono::steady_clock::now(); - } -}; - -std::shared_ptr getClock(); - -// test-only utility to specify what clock to use -void setClock(std::shared_ptr clock); - inline std::string getTimeStr(std::chrono::system_clock::time_point tp) { std::ostringstream stream; date::to_stream(stream, TIME_FORMAT, std::chrono::floor(tp)); diff --git a/libminifi/include/utils/TryMoveCall.h b/utils/include/utils/TryMoveCall.h similarity index 100% rename from libminifi/include/utils/TryMoveCall.h rename to utils/include/utils/TryMoveCall.h diff --git a/libminifi/include/utils/UnicodeConversion.h b/utils/include/utils/UnicodeConversion.h similarity index 100% rename from libminifi/include/utils/UnicodeConversion.h rename to utils/include/utils/UnicodeConversion.h diff --git a/libminifi/include/utils/ValueCaster.h b/utils/include/utils/ValueCaster.h similarity index 100% rename from libminifi/include/utils/ValueCaster.h rename to utils/include/utils/ValueCaster.h diff --git a/libminifi/include/utils/ValueParser.h b/utils/include/utils/ValueParser.h similarity index 100% rename from libminifi/include/utils/ValueParser.h rename to utils/include/utils/ValueParser.h diff --git a/libminifi/include/utils/crypto/EncryptionManager.h b/utils/include/utils/crypto/EncryptionManager.h similarity index 100% rename from libminifi/include/utils/crypto/EncryptionManager.h rename to utils/include/utils/crypto/EncryptionManager.h diff --git a/libminifi/include/utils/crypto/EncryptionProvider.h b/utils/include/utils/crypto/EncryptionProvider.h similarity index 100% rename from libminifi/include/utils/crypto/EncryptionProvider.h rename to utils/include/utils/crypto/EncryptionProvider.h diff --git a/libminifi/include/utils/crypto/EncryptionUtils.h b/utils/include/utils/crypto/EncryptionUtils.h similarity index 100% rename from libminifi/include/utils/crypto/EncryptionUtils.h rename to utils/include/utils/crypto/EncryptionUtils.h diff --git a/libminifi/include/utils/crypto/ciphers/Aes256Ecb.h b/utils/include/utils/crypto/ciphers/Aes256Ecb.h similarity index 100% rename from libminifi/include/utils/crypto/ciphers/Aes256Ecb.h rename to utils/include/utils/crypto/ciphers/Aes256Ecb.h diff --git a/libminifi/include/utils/crypto/ciphers/XSalsa20.h b/utils/include/utils/crypto/ciphers/XSalsa20.h similarity index 100% rename from libminifi/include/utils/crypto/ciphers/XSalsa20.h rename to utils/include/utils/crypto/ciphers/XSalsa20.h diff --git a/libminifi/include/utils/crypto/property_encryption/PropertyEncryptionUtils.h b/utils/include/utils/crypto/property_encryption/PropertyEncryptionUtils.h similarity index 100% rename from libminifi/include/utils/crypto/property_encryption/PropertyEncryptionUtils.h rename to utils/include/utils/crypto/property_encryption/PropertyEncryptionUtils.h diff --git a/libminifi/include/utils/detail/MonadicOperationWrappers.h b/utils/include/utils/detail/MonadicOperationWrappers.h similarity index 100% rename from libminifi/include/utils/detail/MonadicOperationWrappers.h rename to utils/include/utils/detail/MonadicOperationWrappers.h diff --git a/libminifi/include/utils/expected.h b/utils/include/utils/expected.h similarity index 100% rename from libminifi/include/utils/expected.h rename to utils/include/utils/expected.h diff --git a/libminifi/include/utils/file/FilePattern.h b/utils/include/utils/file/FilePattern.h similarity index 100% rename from libminifi/include/utils/file/FilePattern.h rename to utils/include/utils/file/FilePattern.h diff --git a/libminifi/include/utils/file/FileUtils.h b/utils/include/utils/file/FileUtils.h similarity index 99% rename from libminifi/include/utils/file/FileUtils.h rename to utils/include/utils/file/FileUtils.h index b2c75df471..f0968177dc 100644 --- a/libminifi/include/utils/file/FileUtils.h +++ b/utils/include/utils/file/FileUtils.h @@ -58,7 +58,6 @@ #include -#include "properties/Properties.h" #include "utils/Id.h" #include "accctrl.h" diff --git a/libminifi/include/utils/file/PathUtils.h b/utils/include/utils/file/PathUtils.h similarity index 100% rename from libminifi/include/utils/file/PathUtils.h rename to utils/include/utils/file/PathUtils.h diff --git a/utils/include/utils/gsl.h b/utils/include/utils/gsl.h new file mode 100644 index 0000000000..b17acf1713 --- /dev/null +++ b/utils/include/utils/gsl.h @@ -0,0 +1,21 @@ +/** + * + * 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 "minifi-cpp/utils/gsl.h" \ No newline at end of file diff --git a/libminifi/include/utils/meta/detected.h b/utils/include/utils/meta/detected.h similarity index 100% rename from libminifi/include/utils/meta/detected.h rename to utils/include/utils/meta/detected.h diff --git a/libminifi/include/utils/meta/type_list.h b/utils/include/utils/meta/type_list.h similarity index 100% rename from libminifi/include/utils/meta/type_list.h rename to utils/include/utils/meta/type_list.h diff --git a/libminifi/include/utils/net/AsioCoro.h b/utils/include/utils/net/AsioCoro.h similarity index 100% rename from libminifi/include/utils/net/AsioCoro.h rename to utils/include/utils/net/AsioCoro.h diff --git a/libminifi/include/utils/net/AsioSocketUtils.h b/utils/include/utils/net/AsioSocketUtils.h similarity index 97% rename from libminifi/include/utils/net/AsioSocketUtils.h rename to utils/include/utils/net/AsioSocketUtils.h index ceaf9fcb4a..f8df7e9596 100644 --- a/libminifi/include/utils/net/AsioSocketUtils.h +++ b/utils/include/utils/net/AsioSocketUtils.h @@ -32,10 +32,11 @@ #include "AsioCoro.h" #include "utils/Hash.h" #include "utils/StringUtils.h" // for string <=> on libc++ -#include "controllers/SSLContextService.h" +#include "minifi-cpp/controllers/SSLContextService.h" #include "io/BaseStream.h" #include "utils/Deleters.h" #include "utils/net/Socket.h" +#include "core/logging/LoggerFactory.h" namespace org::apache::nifi::minifi::utils::net { @@ -80,7 +81,7 @@ struct SocketData { std::shared_ptr ssl_context_service; }; -class AsioSocketConnection : public io::BaseStream { +class AsioSocketConnection : public io::BaseStreamImpl { public: explicit AsioSocketConnection(SocketData socket_data); int initialize() override; diff --git a/libminifi/include/utils/net/DNS.h b/utils/include/utils/net/DNS.h similarity index 100% rename from libminifi/include/utils/net/DNS.h rename to utils/include/utils/net/DNS.h diff --git a/libminifi/include/utils/NetworkInterfaceInfo.h b/utils/include/utils/net/NetworkInterfaceInfo.h similarity index 100% rename from libminifi/include/utils/NetworkInterfaceInfo.h rename to utils/include/utils/net/NetworkInterfaceInfo.h diff --git a/libminifi/include/utils/net/Socket.h b/utils/include/utils/net/Socket.h similarity index 100% rename from libminifi/include/utils/net/Socket.h rename to utils/include/utils/net/Socket.h diff --git a/libminifi/include/utils/requirements/Container.h b/utils/include/utils/requirements/Container.h similarity index 100% rename from libminifi/include/utils/requirements/Container.h rename to utils/include/utils/requirements/Container.h diff --git a/libminifi/include/utils/requirements/EqualityComparable.h b/utils/include/utils/requirements/EqualityComparable.h similarity index 100% rename from libminifi/include/utils/requirements/EqualityComparable.h rename to utils/include/utils/requirements/EqualityComparable.h diff --git a/libminifi/include/utils/requirements/LegacyForwardIterator.h b/utils/include/utils/requirements/LegacyForwardIterator.h similarity index 100% rename from libminifi/include/utils/requirements/LegacyForwardIterator.h rename to utils/include/utils/requirements/LegacyForwardIterator.h diff --git a/libminifi/include/utils/requirements/LegacyInputIterator.h b/utils/include/utils/requirements/LegacyInputIterator.h similarity index 100% rename from libminifi/include/utils/requirements/LegacyInputIterator.h rename to utils/include/utils/requirements/LegacyInputIterator.h diff --git a/libminifi/include/utils/requirements/LegacyIterator.h b/utils/include/utils/requirements/LegacyIterator.h similarity index 100% rename from libminifi/include/utils/requirements/LegacyIterator.h rename to utils/include/utils/requirements/LegacyIterator.h diff --git a/libminifi/include/utils/requirements/Swappable.h b/utils/include/utils/requirements/Swappable.h similarity index 100% rename from libminifi/include/utils/requirements/Swappable.h rename to utils/include/utils/requirements/Swappable.h diff --git a/libminifi/include/utils/span.h b/utils/include/utils/span.h similarity index 100% rename from libminifi/include/utils/span.h rename to utils/include/utils/span.h diff --git a/libminifi/src/core/BufferedContentSession.cpp b/utils/src/core/BufferedContentSession.cpp similarity index 94% rename from libminifi/src/core/BufferedContentSession.cpp rename to utils/src/core/BufferedContentSession.cpp index 3afad2c8ab..9a9e1f131a 100644 --- a/libminifi/src/core/BufferedContentSession.cpp +++ b/utils/src/core/BufferedContentSession.cpp @@ -19,7 +19,6 @@ #include "core/BufferedContentSession.h" #include #include "core/ContentRepository.h" -#include "ResourceClaim.h" #include "io/BaseStream.h" #include "io/StreamPipe.h" #include "io/StreamSlice.h" @@ -27,10 +26,10 @@ namespace org::apache::nifi::minifi::core { -BufferedContentSession::BufferedContentSession(std::shared_ptr repository) : ContentSession(std::move(repository)) {} +BufferedContentSession::BufferedContentSession(std::shared_ptr repository) : ContentSessionImpl(std::move(repository)) {} std::shared_ptr BufferedContentSession::create() { - std::shared_ptr claim = std::make_shared(repository_); + std::shared_ptr claim = ResourceClaim::create(repository_); managed_resources_[claim] = std::make_shared(); return claim; } @@ -48,7 +47,7 @@ std::shared_ptr BufferedContentSession::append( if (auto it = managed_resources_.find(resource_id); it != managed_resources_.end()) { return it->second; } - return ContentSession::append(resource_id, offset, on_copy); + return ContentSessionImpl::append(resource_id, offset, on_copy); } std::shared_ptr BufferedContentSession::append(const std::shared_ptr& /*resource_id*/) { diff --git a/libminifi/src/core/CachedValueValidator.cpp b/utils/src/core/CachedValueValidator.cpp similarity index 97% rename from libminifi/src/core/CachedValueValidator.cpp rename to utils/src/core/CachedValueValidator.cpp index 718b12dc74..d51bd0b20f 100644 --- a/libminifi/src/core/CachedValueValidator.cpp +++ b/utils/src/core/CachedValueValidator.cpp @@ -15,7 +15,7 @@ * limitations under the License. */ -#include "core/CachedValueValidator.h" +#include "minifi-cpp/core/CachedValueValidator.h" #include "core/PropertyType.h" namespace org::apache::nifi::minifi::core::internal { diff --git a/libminifi/src/core/ConfigurableComponent.cpp b/utils/src/core/ConfigurableComponent.cpp similarity index 84% rename from libminifi/src/core/ConfigurableComponent.cpp rename to utils/src/core/ConfigurableComponent.cpp index 2769472bc4..02657ae170 100644 --- a/libminifi/src/core/ConfigurableComponent.cpp +++ b/utils/src/core/ConfigurableComponent.cpp @@ -21,22 +21,23 @@ #include #include +#include "core/PropertyValue.h" #include "core/ConfigurableComponent.h" -#include "core/logging/LoggerConfiguration.h" +#include "core/logging/LoggerFactory.h" #include "range/v3/range/conversion.hpp" #include "range/v3/view/transform.hpp" #include "utils/gsl.h" namespace org::apache::nifi::minifi::core { -ConfigurableComponent::ConfigurableComponent() +ConfigurableComponentImpl::ConfigurableComponentImpl() : accept_all_properties_(false), logger_(logging::LoggerFactory::getLogger()) { } -ConfigurableComponent::~ConfigurableComponent() = default; +ConfigurableComponentImpl::~ConfigurableComponentImpl() = default; -const Property* ConfigurableComponent::findProperty(const std::string& name) const { +const Property* ConfigurableComponentImpl::findProperty(const std::string& name) const { const auto& it = properties_.find(name); if (it != properties_.end()) { return &it->second; @@ -44,12 +45,12 @@ const Property* ConfigurableComponent::findProperty(const std::string& name) con return nullptr; } -Property* ConfigurableComponent::findProperty(const std::string& name) { +Property* ConfigurableComponentImpl::findProperty(const std::string& name) { const auto& const_self = *this; return const_cast(const_self.findProperty(name)); } -bool ConfigurableComponent::getProperty(const std::string &name, Property &prop) const { +bool ConfigurableComponentImpl::getProperty(const std::string &name, Property &prop) const { std::lock_guard lock(configuration_mutex_); auto prop_ptr = findProperty(name); @@ -69,7 +70,7 @@ bool ConfigurableComponent::getProperty(const std::string &name, Property &prop) * @param value property value. * @return result of setting property. */ -bool ConfigurableComponent::setProperty(const std::string& name, const std::string& value) { +bool ConfigurableComponentImpl::setProperty(const std::string& name, const std::string& value) { std::lock_guard lock(configuration_mutex_); auto prop_ptr = findProperty(name); @@ -103,7 +104,7 @@ bool ConfigurableComponent::setProperty(const std::string& name, const std::stri * @param value property value. * @return result of setting property. */ -bool ConfigurableComponent::updateProperty(const std::string &name, const std::string &value) { +bool ConfigurableComponentImpl::updateProperty(const std::string &name, const std::string &value) { std::lock_guard lock(configuration_mutex_); auto prop_ptr = findProperty(name); @@ -121,7 +122,7 @@ bool ConfigurableComponent::updateProperty(const std::string &name, const std::s } } -bool ConfigurableComponent::updateProperty(const PropertyReference& property, std::string_view value) { +bool ConfigurableComponentImpl::updateProperty(const PropertyReference& property, std::string_view value) { return updateProperty(std::string{property.name}, std::string{value}); } @@ -131,7 +132,7 @@ bool ConfigurableComponent::updateProperty(const PropertyReference& property, st * @param value property value. * @return whether property was set or not */ -bool ConfigurableComponent::setProperty(const Property& prop, const std::string& value) { +bool ConfigurableComponentImpl::setProperty(const Property& prop, const std::string& value) { std::lock_guard lock(configuration_mutex_); auto prop_ptr = findProperty(prop.getName()); @@ -168,11 +169,11 @@ bool ConfigurableComponent::setProperty(const Property& prop, const std::string& } } -bool ConfigurableComponent::setProperty(const PropertyReference& property, std::string_view value) { +bool ConfigurableComponentImpl::setProperty(const PropertyReference& property, std::string_view value) { return setProperty(std::string{property.name}, std::string{value}); } -bool ConfigurableComponent::setProperty(const Property& prop, PropertyValue &value) { +bool ConfigurableComponentImpl::setProperty(const Property& prop, PropertyValue &value) { std::lock_guard lock(configuration_mutex_); auto prop_ptr = findProperty(prop.getName()); @@ -209,7 +210,7 @@ bool ConfigurableComponent::setProperty(const Property& prop, PropertyValue &val } } -void ConfigurableComponent::setSupportedProperties(std::span properties) { +void ConfigurableComponentImpl::setSupportedProperties(std::span properties) { if (!canEdit()) { return; } @@ -222,7 +223,7 @@ void ConfigurableComponent::setSupportedProperties(std::span lock(configuration_mutex_); auto &&it = dynamic_properties_.find(name); @@ -245,7 +246,7 @@ bool ConfigurableComponent::getDynamicProperty(const std::string& name, std::str } } -bool ConfigurableComponent::getDynamicProperty(const std::string& name, core::Property &item) const { +bool ConfigurableComponentImpl::getDynamicProperty(const std::string& name, core::Property &item) const { std::lock_guard lock(configuration_mutex_); auto &&it = dynamic_properties_.find(name); @@ -266,7 +267,7 @@ bool ConfigurableComponent::getDynamicProperty(const std::string& name, core::Pr } } -bool ConfigurableComponent::createDynamicProperty(const std::string &name, const std::string &value) { +bool ConfigurableComponentImpl::createDynamicProperty(const std::string &name, const std::string &value) { if (!supportsDynamicProperties()) { logger_->log_debug("Attempted to create dynamic property {}, but this component does not support creation." "of dynamic properties.", @@ -284,7 +285,7 @@ bool ConfigurableComponent::createDynamicProperty(const std::string &name, const return true; } -bool ConfigurableComponent::setDynamicProperty(const std::string& name, const std::string& value) { +bool ConfigurableComponentImpl::setDynamicProperty(const std::string& name, const std::string& value) { std::lock_guard lock(configuration_mutex_); auto &&it = dynamic_properties_.find(name); @@ -303,7 +304,7 @@ bool ConfigurableComponent::setDynamicProperty(const std::string& name, const st } } -bool ConfigurableComponent::updateDynamicProperty(const std::string &name, const std::string &value) { +bool ConfigurableComponentImpl::updateDynamicProperty(const std::string &name, const std::string &value) { std::lock_guard lock(configuration_mutex_); auto &&it = dynamic_properties_.find(name); @@ -322,7 +323,7 @@ bool ConfigurableComponent::updateDynamicProperty(const std::string &name, const } } -std::vector ConfigurableComponent::getDynamicPropertyKeys() const { +std::vector ConfigurableComponentImpl::getDynamicPropertyKeys() const { std::lock_guard lock(configuration_mutex_); return dynamic_properties_ @@ -330,7 +331,7 @@ std::vector ConfigurableComponent::getDynamicPropertyKeys() const { | ranges::to(); } -std::map ConfigurableComponent::getProperties() const { +std::map ConfigurableComponentImpl::getProperties() const { std::lock_guard lock(configuration_mutex_); std::map result; @@ -346,12 +347,12 @@ std::map ConfigurableComponent::getProperties() const { return result; } -bool ConfigurableComponent::isPropertyExplicitlySet(const Property& searched_prop) const { +bool ConfigurableComponentImpl::isPropertyExplicitlySet(const Property& searched_prop) const { Property prop; return getProperty(searched_prop.getName(), prop) && !prop.getValues().empty(); } -bool ConfigurableComponent::isPropertyExplicitlySet(const PropertyReference& searched_prop) const { +bool ConfigurableComponentImpl::isPropertyExplicitlySet(const PropertyReference& searched_prop) const { Property prop; return getProperty(std::string(searched_prop.name), prop) && !prop.getValues().empty(); } diff --git a/libminifi/src/core/Connectable.cpp b/utils/src/core/Connectable.cpp similarity index 77% rename from libminifi/src/core/Connectable.cpp rename to utils/src/core/Connectable.cpp index 55e0ff27fe..8a77b95476 100644 --- a/libminifi/src/core/Connectable.cpp +++ b/utils/src/core/Connectable.cpp @@ -20,29 +20,27 @@ #include #include #include -#include "core/RelationshipDefinition.h" -#include "core/logging/LoggerConfiguration.h" -#include "core/Relationship.h" +#include "core/logging/LoggerFactory.h" namespace org::apache::nifi::minifi::core { -Connectable::Connectable(std::string_view name, const utils::Identifier &uuid) - : CoreComponent(name, uuid), +ConnectableImpl::ConnectableImpl(const std::string_view name, const utils::Identifier &uuid) + : CoreComponentImpl(name, uuid), max_concurrent_tasks_(1), connectable_version_(nullptr), logger_(logging::LoggerFactory::getLogger(uuid_)) { } -Connectable::Connectable(std::string_view name) - : CoreComponent(name), +ConnectableImpl::ConnectableImpl(const std::string_view name) + : CoreComponentImpl(name), max_concurrent_tasks_(1), connectable_version_(nullptr), logger_(logging::LoggerFactory::getLogger(uuid_)) { } -Connectable::~Connectable() = default; +ConnectableImpl::~ConnectableImpl() = default; -void Connectable::setSupportedRelationships(std::span relationships) { +void ConnectableImpl::setSupportedRelationships(std::span relationships) { if (isRunning()) { logger_->log_warn("Cannot set processor supported relationship while the process {} is running", name_); return; @@ -57,7 +55,7 @@ void Connectable::setSupportedRelationships(std::span Connectable::getSupportedRelationships() const { +std::vector ConnectableImpl::getSupportedRelationships() const { std::vector relationships; relationships.reserve(relationships_.size()); for (auto const &item : relationships_) { @@ -66,7 +64,7 @@ std::vector Connectable::getSupportedRelationships() const { return relationships; } -bool Connectable::isSupportedRelationship(const core::Relationship &relationship) { +bool ConnectableImpl::isSupportedRelationship(const core::Relationship &relationship) { // if we are running we do not need a lock since the function to change relationships_ ( setSupportedRelationships) // cannot be executed while we are running const bool isConnectableRunning = isRunning(); @@ -76,7 +74,7 @@ bool Connectable::isSupportedRelationship(const core::Relationship &relationship return relationships_.contains(relationship.getName()); } -void Connectable::addAutoTerminatedRelationship(const core::Relationship& relationship) { +void ConnectableImpl::addAutoTerminatedRelationship(const core::Relationship& relationship) { if (isRunning()) { logger_->log_warn("Can not add processor auto terminated relationship while the process {} is running", name_); return; @@ -87,7 +85,7 @@ void Connectable::addAutoTerminatedRelationship(const core::Relationship& relati auto_terminated_relationships_[relationship.getName()] = relationship; } -void Connectable::setAutoTerminatedRelationships(std::span relationships) { +void ConnectableImpl::setAutoTerminatedRelationships(std::span relationships) { if (isRunning()) { logger_->log_warn("Can not set processor auto terminated relationship while the process {} is running", name_); return; @@ -102,7 +100,7 @@ void Connectable::setAutoTerminatedRelationships(std::span Connectable::getOutGoingConnections(const std::string &relationship) { +std::set ConnectableImpl::getOutGoingConnections(const std::string &relationship) { const auto it = outgoing_connections_.find(relationship); if (it != outgoing_connections_.end()) { return it->second; @@ -145,12 +143,12 @@ std::set Connectable::getOutGoingConnections(const std::string &re } } -Connectable* Connectable::getNextIncomingConnection() { +Connectable* ConnectableImpl::getNextIncomingConnection() { std::lock_guard lock(relationship_mutex_); return getNextIncomingConnectionImpl(lock); } -Connectable* Connectable::getNextIncomingConnectionImpl(const std::lock_guard& /*relatioship_mutex_lock*/) { +Connectable* ConnectableImpl::getNextIncomingConnectionImpl(const std::lock_guard& /*relatioship_mutex_lock*/) { if (incoming_connections_.empty()) return nullptr; @@ -166,7 +164,7 @@ Connectable* Connectable::getNextIncomingConnectionImpl(const std::lock_guard lock(count_map_mutex_); count_map_.clear(); } -std::shared_ptr ContentRepository::createSession() { - return std::make_shared(sharedFromThis()); +std::shared_ptr ContentRepositoryImpl::createSession() { + return std::make_shared(sharedFromThis()); } -uint32_t ContentRepository::getStreamCount(const minifi::ResourceClaim &streamId) { +uint32_t ContentRepositoryImpl::getStreamCount(const minifi::ResourceClaim &streamId) { std::lock_guard lock(count_map_mutex_); auto cnt = count_map_.find(streamId.getContentFullPath()); if (cnt != count_map_.end()) { @@ -49,7 +49,7 @@ uint32_t ContentRepository::getStreamCount(const minifi::ResourceClaim &streamId } } -void ContentRepository::incrementStreamCount(const minifi::ResourceClaim &streamId) { +void ContentRepositoryImpl::incrementStreamCount(const minifi::ResourceClaim &streamId) { std::lock_guard lock(count_map_mutex_); const std::string str = streamId.getContentFullPath(); auto count = count_map_.find(str); @@ -60,7 +60,7 @@ void ContentRepository::incrementStreamCount(const minifi::ResourceClaim &stream } } -void ContentRepository::removeFromPurgeList() { +void ContentRepositoryImpl::removeFromPurgeList() { std::lock_guard lock(purge_list_mutex_); for (auto it = purge_list_.begin(); it != purge_list_.end();) { if (removeKey(*it)) { @@ -71,7 +71,7 @@ void ContentRepository::removeFromPurgeList() { } } -ContentRepository::StreamState ContentRepository::decrementStreamCount(const minifi::ResourceClaim &streamId) { +ContentRepository::StreamState ContentRepositoryImpl::decrementStreamCount(const minifi::ResourceClaim &streamId) { { std::lock_guard lock(count_map_mutex_); const std::string str = streamId.getContentFullPath(); @@ -88,7 +88,7 @@ ContentRepository::StreamState ContentRepository::decrementStreamCount(const min return StreamState::Deleted; } -bool ContentRepository::remove(const minifi::ResourceClaim &streamId) { +bool ContentRepositoryImpl::remove(const minifi::ResourceClaim &streamId) { removeFromPurgeList(); if (!removeKey(streamId.getContentFullPath())) { std::lock_guard lock(purge_list_mutex_); @@ -98,7 +98,7 @@ bool ContentRepository::remove(const minifi::ResourceClaim &streamId) { return true; } -std::unique_ptr ContentRepository::lockAppend(const org::apache::nifi::minifi::ResourceClaim &claim, size_t offset) { +std::unique_ptr ContentRepositoryImpl::lockAppend(const org::apache::nifi::minifi::ResourceClaim &claim, size_t offset) { std::lock_guard guard(appending_mutex_); if (offset != size(claim)) { // we are trying to append to a resource that has already been appended to @@ -108,10 +108,10 @@ std::unique_ptr ContentRepository::lockAppend(const org::apach // this resource is currently being appended to return {}; } - return std::make_unique(sharedFromThis(), claim); + return std::make_unique(sharedFromThis(), claim); } -void ContentRepository::unlockAppend(const ResourceClaim::Path &path) { +void ContentRepositoryImpl::unlockAppend(const ResourceClaim::Path &path) { std::lock_guard guard(appending_mutex_); size_t removed_count = appending_.erase(path); gsl_Expects(removed_count == 1); diff --git a/libminifi/src/core/ContentSession.cpp b/utils/src/core/ContentSession.cpp similarity index 89% rename from libminifi/src/core/ContentSession.cpp rename to utils/src/core/ContentSession.cpp index aa975a4750..3584f452aa 100644 --- a/libminifi/src/core/ContentSession.cpp +++ b/utils/src/core/ContentSession.cpp @@ -23,7 +23,7 @@ namespace org::apache::nifi::minifi::core { -std::shared_ptr ContentSession::append(const std::shared_ptr& resource_id, size_t offset, const std::function&)>& on_copy) { +std::shared_ptr ContentSessionImpl::append(const std::shared_ptr& resource_id, size_t offset, const std::function&)>& on_copy) { auto it = append_state_.find(resource_id); if (it != append_state_.end() && it->second.base_size + it->second.stream->size() == offset) { return it->second.stream; diff --git a/libminifi/src/core/Core.cpp b/utils/src/core/Core.cpp similarity index 71% rename from libminifi/src/core/Core.cpp rename to utils/src/core/Core.cpp index 26752cc784..66920bba5b 100644 --- a/libminifi/src/core/Core.cpp +++ b/utils/src/core/Core.cpp @@ -22,32 +22,28 @@ namespace org::apache::nifi::minifi::core { -CoreComponent::CoreComponent(std::string_view name, const utils::Identifier& uuid, const std::shared_ptr& idGenerator) +CoreComponentImpl::CoreComponentImpl(std::string_view name, const utils::Identifier& uuid, const std::shared_ptr& idGenerator) : name_(name) { if (uuid.isNil()) { - // Generate the global UUID for the flow record uuid_ = idGenerator->generate(); } else { uuid_ = uuid; } } -// Set UUID -void CoreComponent::setUUID(const utils::Identifier& uuid) { +void CoreComponentImpl::setUUID(const utils::Identifier& uuid) { uuid_ = uuid; } -// Get UUID -utils::Identifier CoreComponent::getUUID() const { +utils::Identifier CoreComponentImpl::getUUID() const { return uuid_; } -// Set Processor Name -void CoreComponent::setName(std::string name) { +void CoreComponentImpl::setName(std::string name) { name_ = std::move(name); } -// Get Process Name -std::string CoreComponent::getName() const { + +std::string CoreComponentImpl::getName() const { return name_; } diff --git a/utils/src/core/ProcessContextBuilder.cpp b/utils/src/core/ProcessContextBuilder.cpp new file mode 100644 index 0000000000..b807bfc24c --- /dev/null +++ b/utils/src/core/ProcessContextBuilder.cpp @@ -0,0 +1,67 @@ +/** + * 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/ProcessContextBuilder.h" +#include +#include +#include "core/logging/LoggerFactory.h" +#include "core/Resource.h" +#include "minifi-cpp/core/repository/FileSystemRepository.h" + +namespace org::apache::nifi::minifi::core { + +ProcessContextBuilderImpl::ProcessContextBuilderImpl(std::string_view name, const minifi::utils::Identifier &uuid) + : core::CoreComponentImpl(name, uuid) { + content_repo_ = repository::createFileSystemRepository(); + configuration_ = minifi::Configure::create(); +} + +ProcessContextBuilderImpl::ProcessContextBuilderImpl(std::string_view name) + : core::CoreComponentImpl(name) { + content_repo_ = repository::createFileSystemRepository(); + configuration_ = minifi::Configure::create(); +} + +std::shared_ptr ProcessContextBuilderImpl::withProvider(core::controller::ControllerServiceProvider* controller_service_provider) { + controller_service_provider_ = controller_service_provider; + return sharedFromThis(); +} + +std::shared_ptr ProcessContextBuilderImpl::withProvenanceRepository(const std::shared_ptr &repo) { + prov_repo_ = repo; + return sharedFromThis(); +} + +std::shared_ptr ProcessContextBuilderImpl::withFlowFileRepository(const std::shared_ptr &repo) { + flow_repo_ = repo; + return sharedFromThis(); +} + +std::shared_ptr ProcessContextBuilderImpl::withContentRepository(const std::shared_ptr &repo) { + content_repo_ = repo; + return sharedFromThis(); +} + +std::shared_ptr ProcessContextBuilderImpl::withConfiguration(const std::shared_ptr &configuration) { + configuration_ = configuration; + return sharedFromThis(); +} + +std::shared_ptr ProcessContextBuilderImpl::build(const std::shared_ptr &processor) { + return std::make_shared(processor, controller_service_provider_, prov_repo_, flow_repo_, configuration_, content_repo_); +} + +} // namespace org::apache::nifi::minifi::core diff --git a/utils/src/core/ProcessSession.cpp b/utils/src/core/ProcessSession.cpp new file mode 100644 index 0000000000..b73bcbe4f7 --- /dev/null +++ b/utils/src/core/ProcessSession.cpp @@ -0,0 +1,26 @@ +/** + * 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 "minifi-cpp/core/ProcessSession.h" + +namespace org::apache::nifi::minifi::core::detail { + +std::string to_string(const ReadBufferResult &read_buffer_result) { + return {reinterpret_cast(read_buffer_result.buffer.data()), read_buffer_result.buffer.size()}; +} + +} // namespace org::apache::nifi::minifi::core::detail diff --git a/libminifi/src/core/Processor.cpp b/utils/src/core/Processor.cpp similarity index 84% rename from libminifi/src/core/Processor.cpp rename to utils/src/core/Processor.cpp index b5cf616e23..350513fe38 100644 --- a/libminifi/src/core/Processor.cpp +++ b/utils/src/core/Processor.cpp @@ -27,29 +27,32 @@ #include #include -#include "Connection.h" +#include "minifi-cpp/Connection.h" #include "core/Connectable.h" -#include "core/logging/LoggerConfiguration.h" -#include "core/ProcessorConfig.h" -#include "core/ProcessContext.h" -#include "core/ProcessSessionFactory.h" +#include "core/logging/LoggerFactory.h" +#include "minifi-cpp/core/ProcessorConfig.h" +#include "minifi-cpp/core/ProcessContext.h" +#include "minifi-cpp/core/ProcessSessionFactory.h" #include "utils/gsl.h" #include "range/v3/algorithm/any_of.hpp" #include "fmt/format.h" +#include "Exception.h" +#include "core/Processor.h" +#include "core/ProcessorMetrics.h" using namespace std::literals::chrono_literals; namespace org::apache::nifi::minifi::core { -Processor::Processor(std::string_view name, std::shared_ptr metrics) - : Connectable(name), +ProcessorImpl::ProcessorImpl(std::string_view name, std::shared_ptr metrics) + : ConnectableImpl(name), state_(DISABLED), scheduling_period_(MINIMUM_SCHEDULING_PERIOD), run_duration_(DEFAULT_RUN_DURATION), yield_period_(DEFAULT_YIELD_PERIOD_SECONDS), active_tasks_(0), _triggerWhenEmpty(false), - metrics_(metrics ? std::move(metrics) : std::make_shared(*this)), + metrics_(metrics ? std::move(metrics) : std::make_shared(*this)), logger_(logging::LoggerFactory::getLogger(uuid_)) { has_work_.store(false); // Setup the default values @@ -60,15 +63,15 @@ Processor::Processor(std::string_view name, std::shared_ptr me logger_->log_debug("Processor {} created UUID {}", name_, getUUIDStr()); } -Processor::Processor(std::string_view name, const utils::Identifier& uuid, std::shared_ptr metrics) - : Connectable(name, uuid), +ProcessorImpl::ProcessorImpl(std::string_view name, const utils::Identifier& uuid, std::shared_ptr metrics) + : ConnectableImpl(name, uuid), state_(DISABLED), scheduling_period_(MINIMUM_SCHEDULING_PERIOD), run_duration_(DEFAULT_RUN_DURATION), yield_period_(DEFAULT_YIELD_PERIOD_SECONDS), active_tasks_(0), _triggerWhenEmpty(false), - metrics_(metrics ? std::move(metrics) : std::make_shared(*this)), + metrics_(metrics ? std::move(metrics) : std::make_shared(*this)), logger_(logging::LoggerFactory::getLogger(uuid_)) { has_work_.store(false); // Setup the default values @@ -79,22 +82,22 @@ Processor::Processor(std::string_view name, const utils::Identifier& uuid, std:: logger_->log_debug("Processor {} created with uuid {}", name_, getUUIDStr()); } -Processor::~Processor() { +ProcessorImpl::~ProcessorImpl() { logger_->log_debug("Destroying processor {} with uuid {}", name_, getUUIDStr()); } -bool Processor::isRunning() const { +bool ProcessorImpl::isRunning() const { return (state_ == RUNNING && active_tasks_ > 0); } -void Processor::setScheduledState(ScheduledState state) { +void ProcessorImpl::setScheduledState(ScheduledState state) { state_ = state; if (state == STOPPED) { notifyStop(); } } -bool Processor::addConnection(Connectable* conn) { +bool ProcessorImpl::addConnection(Connectable* conn) { enum class SetAs{ NONE, OUTPUT, @@ -164,7 +167,7 @@ bool Processor::addConnection(Connectable* conn) { return result != SetAs::NONE; } -bool Processor::flowFilesOutGoingFull() const { +bool ProcessorImpl::flowFilesOutGoingFull() const { std::lock_guard lock(mutex_); for (const auto& [_name, existed_connection] : outgoing_connections_) { @@ -179,7 +182,7 @@ bool Processor::flowFilesOutGoingFull() const { return false; } -void Processor::triggerAndCommit(const std::shared_ptr& context, const std::shared_ptr& session_factory) { +void ProcessorImpl::triggerAndCommit(const std::shared_ptr& context, const std::shared_ptr& session_factory) { const auto process_session = session_factory->createSession(); process_session->setMetrics(metrics_); try { @@ -197,14 +200,14 @@ void Processor::triggerAndCommit(const std::shared_ptr& context, } } -void Processor::trigger(const std::shared_ptr& context, const std::shared_ptr& process_session) { - ++metrics_->iterations; +void ProcessorImpl::trigger(const std::shared_ptr& context, const std::shared_ptr& process_session) { + ++metrics_->iterations(); const auto start = std::chrono::steady_clock::now(); onTrigger(*context, *process_session); metrics_->addLastOnTriggerRuntime(std::chrono::duration_cast(std::chrono::steady_clock::now() - start)); } -bool Processor::isWorkAvailable() { +bool ProcessorImpl::isWorkAvailable() { // We have work if any incoming connection has work std::lock_guard lock(mutex_); bool hasWork = false; @@ -230,7 +233,7 @@ bool Processor::isWorkAvailable() { } // must hold the graphMutex -void Processor::updateReachability(const std::lock_guard& graph_lock, bool force) { +void ProcessorImpl::updateReachability(const std::lock_guard& graph_lock, bool force) { bool didChange = force; for (auto& outIt : outgoing_connections_) { for (auto& outConn : outIt.second) { @@ -245,7 +248,7 @@ void Processor::updateReachability(const std::lock_guard& graph_lock if (reachable_processors_[connection].insert(dest).second) { didChange = true; } - for (auto& reachedIt : dest->reachable_processors_) { + for (auto& reachedIt : dest->reachable_processors()) { for (auto &reached_proc : reachedIt.second) { if (reachable_processors_[connection].insert(reached_proc).second) { didChange = true; @@ -270,19 +273,19 @@ void Processor::updateReachability(const std::lock_guard& graph_lock } } -bool Processor::partOfCycle(Connection* conn) { +bool ProcessorImpl::partOfCycle(Connection* conn) { auto source = dynamic_cast(conn->getSource()); if (!source) { return false; } - auto it = source->reachable_processors_.find(conn); - if (it == source->reachable_processors_.end()) { + auto it = source->reachable_processors().find(conn); + if (it == source->reachable_processors().end()) { return false; } return it->second.contains(source); } -bool Processor::isThrottledByBackpressure() const { +bool ProcessorImpl::isThrottledByBackpressure() const { bool isThrottledByOutgoing = ranges::any_of(outgoing_connections_, [](auto& name_connection_set_pair) { return ranges::any_of(name_connection_set_pair.second, [](auto& connectable) { auto connection = dynamic_cast(connectable); @@ -296,7 +299,7 @@ bool Processor::isThrottledByBackpressure() const { return isThrottledByOutgoing && !isForcedByIncomingCycle; } -Connectable* Processor::pickIncomingConnection() { +Connectable* ProcessorImpl::pickIncomingConnection() { std::lock_guard rel_guard(relationship_mutex_); auto beginIt = incoming_connections_Iter; @@ -316,7 +319,7 @@ Connectable* Processor::pickIncomingConnection() { return getNextIncomingConnectionImpl(rel_guard); } -void Processor::validateAnnotations() const { +void ProcessorImpl::validateAnnotations() const { switch (getInputRequirement()) { case annotation::Input::INPUT_REQUIRED: { if (!hasIncomingConnections()) { @@ -336,7 +339,7 @@ void Processor::validateAnnotations() const { } } -void Processor::setMaxConcurrentTasks(const uint8_t tasks) { +void ProcessorImpl::setMaxConcurrentTasks(const uint8_t tasks) { if (isSingleThreaded() && tasks > 1) { logger_->log_warn("Processor {} can not be run in parallel, its \"max concurrent tasks\" value is too high. " "It was set to 1 from {}.", name_, tasks); @@ -347,23 +350,23 @@ void Processor::setMaxConcurrentTasks(const uint8_t tasks) { max_concurrent_tasks_ = tasks; } -void Processor::yield() { +void ProcessorImpl::yield() { yield_expiration_ = std::chrono::steady_clock::now() + yield_period_.load(); } -void Processor::yield(std::chrono::steady_clock::duration delta_time) { +void ProcessorImpl::yield(std::chrono::steady_clock::duration delta_time) { yield_expiration_ = std::chrono::steady_clock::now() + delta_time; } -bool Processor::isYield() { +bool ProcessorImpl::isYield() { return getYieldTime() > 0ms; } -void Processor::clearYield() { +void ProcessorImpl::clearYield() { yield_expiration_ = std::chrono::steady_clock::time_point(); } -std::chrono::steady_clock::duration Processor::getYieldTime() const { +std::chrono::steady_clock::duration ProcessorImpl::getYieldTime() const { return std::max(yield_expiration_.load()-std::chrono::steady_clock::now(), std::chrono::steady_clock::duration{0}); } diff --git a/libminifi/src/core/ProcessorMetrics.cpp b/utils/src/core/ProcessorMetrics.cpp similarity index 77% rename from libminifi/src/core/ProcessorMetrics.cpp rename to utils/src/core/ProcessorMetrics.cpp index 8cd0548883..d79e2eb7b5 100644 --- a/libminifi/src/core/ProcessorMetrics.cpp +++ b/utils/src/core/ProcessorMetrics.cpp @@ -24,33 +24,33 @@ using namespace std::literals::chrono_literals; namespace org::apache::nifi::minifi::core { -ProcessorMetrics::ProcessorMetrics(const Processor& source_processor) +ProcessorMetricsImpl::ProcessorMetricsImpl(const Processor& source_processor) : source_processor_(source_processor), on_trigger_runtime_averager_(STORED_ON_TRIGGER_RUNTIME_COUNT), session_commit_runtime_averager_(STORED_ON_TRIGGER_RUNTIME_COUNT) { } -std::string ProcessorMetrics::getName() const { +std::string ProcessorMetricsImpl::getName() const { return source_processor_.getProcessorType() + "Metrics"; } -std::unordered_map ProcessorMetrics::getCommonLabels() const { +std::unordered_map ProcessorMetricsImpl::getCommonLabels() const { return {{"metric_class", getName()}, {"processor_name", source_processor_.getName()}, {"processor_uuid", source_processor_.getUUIDStr()}}; } -std::vector ProcessorMetrics::serialize() { +std::vector ProcessorMetricsImpl::serialize() { std::vector resp; state::response::SerializedResponseNode root_node { .name = source_processor_.getUUIDStr(), .children = { - {.name = "OnTriggerInvocations", .value = static_cast(iterations.load())}, + {.name = "OnTriggerInvocations", .value = static_cast(iterations().load())}, {.name = "AverageOnTriggerRunTime", .value = static_cast(getAverageOnTriggerRuntime().count())}, {.name = "LastOnTriggerRunTime", .value = static_cast(getLastOnTriggerRuntime().count())}, {.name = "AverageSessionCommitRunTime", .value = static_cast(getAverageSessionCommitRuntime().count())}, {.name = "LastSessionCommitRunTime", .value = static_cast(getLastSessionCommitRuntime().count())}, - {.name = "TransferredFlowFiles", .value = static_cast(transferred_flow_files.load())}, - {.name = "TransferredBytes", .value = transferred_bytes.load()} + {.name = "TransferredFlowFiles", .value = static_cast(transferredFlowFiles().load())}, + {.name = "TransferredBytes", .value = transferredBytes().load()} } }; @@ -71,15 +71,15 @@ std::vector ProcessorMetrics::serialize return resp; } -std::vector ProcessorMetrics::calculateMetrics() { +std::vector ProcessorMetricsImpl::calculateMetrics() { std::vector metrics = { - {"onTrigger_invocations", static_cast(iterations.load()), getCommonLabels()}, + {"onTrigger_invocations", static_cast(iterations().load()), getCommonLabels()}, {"average_onTrigger_runtime_milliseconds", static_cast(getAverageOnTriggerRuntime().count()), getCommonLabels()}, {"last_onTrigger_runtime_milliseconds", static_cast(getLastOnTriggerRuntime().count()), getCommonLabels()}, {"average_session_commit_runtime_milliseconds", static_cast(getAverageSessionCommitRuntime().count()), getCommonLabels()}, {"last_session_commit_runtime_milliseconds", static_cast(getLastSessionCommitRuntime().count()), getCommonLabels()}, - {"transferred_flow_files", static_cast(transferred_flow_files.load()), getCommonLabels()}, - {"transferred_bytes", static_cast(transferred_bytes.load()), getCommonLabels()} + {"transferred_flow_files", static_cast(transferredFlowFiles().load()), getCommonLabels()}, + {"transferred_bytes", static_cast(transferredBytes().load()), getCommonLabels()} }; { @@ -93,38 +93,38 @@ std::vector ProcessorMetrics::calculateMetrics() { return metrics; } -void ProcessorMetrics::increaseRelationshipTransferCount(const std::string& relationship, size_t count) { +void ProcessorMetricsImpl::increaseRelationshipTransferCount(const std::string& relationship, size_t count) { std::lock_guard lock(transferred_relationships_mutex_); transferred_relationships_[relationship] += count; } -std::chrono::milliseconds ProcessorMetrics::getAverageOnTriggerRuntime() const { +std::chrono::milliseconds ProcessorMetricsImpl::getAverageOnTriggerRuntime() const { return on_trigger_runtime_averager_.getAverage(); } -void ProcessorMetrics::addLastOnTriggerRuntime(std::chrono::milliseconds runtime) { +void ProcessorMetricsImpl::addLastOnTriggerRuntime(std::chrono::milliseconds runtime) { on_trigger_runtime_averager_.addValue(runtime); } -std::chrono::milliseconds ProcessorMetrics::getLastOnTriggerRuntime() const { +std::chrono::milliseconds ProcessorMetricsImpl::getLastOnTriggerRuntime() const { return on_trigger_runtime_averager_.getLastValue(); } -std::chrono::milliseconds ProcessorMetrics::getAverageSessionCommitRuntime() const { +std::chrono::milliseconds ProcessorMetricsImpl::getAverageSessionCommitRuntime() const { return session_commit_runtime_averager_.getAverage(); } -void ProcessorMetrics::addLastSessionCommitRuntime(std::chrono::milliseconds runtime) { +void ProcessorMetricsImpl::addLastSessionCommitRuntime(std::chrono::milliseconds runtime) { session_commit_runtime_averager_.addValue(runtime); } -std::chrono::milliseconds ProcessorMetrics::getLastSessionCommitRuntime() const { +std::chrono::milliseconds ProcessorMetricsImpl::getLastSessionCommitRuntime() const { return session_commit_runtime_averager_.getLastValue(); } template requires Summable && DividableByInteger -ValueType ProcessorMetrics::Averager::getAverage() const { +ValueType ProcessorMetricsImpl::Averager::getAverage() const { std::lock_guard lock(average_value_mutex_); if (values_.empty()) { return {}; @@ -134,7 +134,7 @@ ValueType ProcessorMetrics::Averager::getAverage() const { template requires Summable && DividableByInteger -void ProcessorMetrics::Averager::addValue(ValueType runtime) { +void ProcessorMetricsImpl::Averager::addValue(ValueType runtime) { std::lock_guard lock(average_value_mutex_); if (values_.size() < SAMPLE_SIZE_) { values_.push_back(runtime); @@ -149,7 +149,7 @@ void ProcessorMetrics::Averager::addValue(ValueType runtime) { template requires Summable && DividableByInteger -ValueType ProcessorMetrics::Averager::getLastValue() const { +ValueType ProcessorMetricsImpl::Averager::getLastValue() const { std::lock_guard lock(average_value_mutex_); if (values_.empty()) { return {}; diff --git a/libminifi/src/core/Property.cpp b/utils/src/core/Property.cpp similarity index 66% rename from libminifi/src/core/Property.cpp rename to utils/src/core/Property.cpp index 4b5186a40c..dcb1fc400a 100644 --- a/libminifi/src/core/Property.cpp +++ b/utils/src/core/Property.cpp @@ -23,6 +23,8 @@ #include "core/PropertyType.h" #include "range/v3/range/conversion.hpp" #include "range/v3/view/transform.hpp" +#include "core/PropertyDefinition.h" +#include "core/TypedValues.h" namespace org::apache::nifi::minifi::core { @@ -67,8 +69,8 @@ const PropertyValidator& Property::getValidator() const { std::vector Property::getValues() { return values_ - | ranges::views::transform([](const auto& property_value) { return property_value.to_string(); }) - | ranges::to(); + | ranges::views::transform([](const auto& property_value) { return property_value.to_string(); }) + | ranges::to(); } void Property::setSupportsExpressionLanguage(bool supportEl) { @@ -103,12 +105,12 @@ std::vector createPropertyValues(std::span createStrings(std::span string_views) { return ranges::views::transform(string_views, [](const auto& string_view) { return std::string{string_view}; }) - | ranges::to; + | ranges::to; } inline std::vector> createStrings(std::span> pairs_of_string_views) { return ranges::views::transform(pairs_of_string_views, [](const auto& pair_of_string_views) { return std::pair(pair_of_string_views); }) - | ranges::to; + | ranges::to; } } // namespace @@ -131,6 +133,61 @@ Property::Property(const PropertyReference& compile_time_property) } } +Property::Property(std::string name, std::string description, const std::string& value, bool is_required, std::vector dependent_properties, + std::vector> exclusive_of_properties) + : name_(std::move(name)), + description_(std::move(description)), + is_required_(is_required), + dependent_properties_(std::move(dependent_properties)), + exclusive_of_properties_(std::move(exclusive_of_properties)), + is_collection_(false), + validator_{&StandardPropertyTypes::VALID_TYPE}, + supports_el_(false), + is_transient_(false) { + default_value_ = coerceDefaultValue(value); +} + +Property::Property(std::string name, std::string description, const std::string& value) + : name_(std::move(name)), + description_(std::move(description)), + is_required_(false), + is_collection_(false), + validator_{&StandardPropertyTypes::VALID_TYPE}, + supports_el_(false), + is_transient_(false) { + default_value_ = coerceDefaultValue(value); +} + +Property::Property(std::string name, std::string description) + : name_(std::move(name)), + description_(std::move(description)), + is_required_(false), + is_collection_(true), + validator_{&StandardPropertyTypes::VALID_TYPE}, + supports_el_(false), + is_transient_(false) {} + +Property::Property() + : is_required_(false), + is_collection_(false), + validator_{&StandardPropertyTypes::VALID_TYPE}, + supports_el_(false), + is_transient_(false) {} + +PropertyValue Property::coerceDefaultValue(const std::string &value) { + PropertyValue ret; + if (value == "false" || value == "true") { + bool val; + std::istringstream(value) >> std::boolalpha >> val; + ret = val; + validator_ = StandardPropertyTypes::getValidator(ret.getValue()); + } else { + ret = value; + validator_ = gsl::make_not_null(&StandardPropertyTypes::VALID_TYPE); + } + return ret; +} + void Property::setAllowedValues(gsl::span allowed_values, const core::PropertyParser& property_parser) { allowed_values_ = createPropertyValues(allowed_values, property_parser); } diff --git a/libminifi/src/core/PropertyType.cpp b/utils/src/core/PropertyType.cpp similarity index 95% rename from libminifi/src/core/PropertyType.cpp rename to utils/src/core/PropertyType.cpp index d1e4e2ad57..46b57f7144 100644 --- a/libminifi/src/core/PropertyType.cpp +++ b/utils/src/core/PropertyType.cpp @@ -20,8 +20,8 @@ namespace org::apache::nifi::minifi::core { -PropertyValue PropertyType::parse(std::string_view input) const { - return PropertyValue::parse(input, *this); +PropertyValue PropertyTypeImpl::parse(std::string_view input) const { + return PropertyValue::parse(input, *this); } PropertyValue BooleanPropertyType::parse(std::string_view input) const { diff --git a/libminifi/src/core/Repository.cpp b/utils/src/core/Repository.cpp similarity index 87% rename from libminifi/src/core/Repository.cpp rename to utils/src/core/Repository.cpp index e17ab886f5..722e82e7a6 100644 --- a/libminifi/src/core/Repository.cpp +++ b/utils/src/core/Repository.cpp @@ -19,7 +19,7 @@ namespace org::apache::nifi::minifi::core { -bool Repository::Delete(std::vector> &storedValues) { +bool RepositoryImpl::Delete(std::vector> &storedValues) { bool found = true; for (const auto& storedValue : storedValues) { found &= Delete(storedValue->getName()); @@ -27,7 +27,7 @@ bool Repository::Delete(std::vector return found; } -bool Repository::storeElement(const std::shared_ptr& element) { +bool RepositoryImpl::storeElement(const std::shared_ptr& element) { if (!element) { return false; } diff --git a/libminifi/src/core/TypedValues.cpp b/utils/src/core/TypedValues.cpp similarity index 96% rename from libminifi/src/core/TypedValues.cpp rename to utils/src/core/TypedValues.cpp index d3908a7ecc..7dde6a98a2 100644 --- a/libminifi/src/core/TypedValues.cpp +++ b/utils/src/core/TypedValues.cpp @@ -20,7 +20,7 @@ #include "core/Property.h" #include "core/TypedValues.h" -#include "core/logging/LoggerConfiguration.h" +#include "core/logging/LoggerFactory.h" namespace org::apache::nifi::minifi::core { diff --git a/libminifi/src/core/extension/Extension.cpp b/utils/src/core/extension/Extension.cpp similarity index 80% rename from libminifi/src/core/extension/Extension.cpp rename to utils/src/core/extension/Extension.cpp index 11a22bbff7..17faa186ac 100644 --- a/libminifi/src/core/extension/Extension.cpp +++ b/utils/src/core/extension/Extension.cpp @@ -16,23 +16,23 @@ */ #include "core/extension/Extension.h" -#include "core/extension/ExtensionManager.h" -#include "core/logging/LoggerConfiguration.h" +#include "minifi-cpp/core/extension/ExtensionManager.h" +#include "core/logging/LoggerFactory.h" namespace org::apache::nifi::minifi::core::extension { static std::shared_ptr init_logger = logging::LoggerFactory::getLogger(); -Extension::Extension(std::string name, ExtensionInitImpl init_impl, ExtensionDeinitImpl deinit_impl, ExtensionInit init) +ExtensionImpl::ExtensionImpl(std::string name, ExtensionInitImpl init_impl, ExtensionDeinitImpl deinit_impl, ExtensionInit init) : name_(std::move(name)), init_impl_(init_impl), deinit_impl_(deinit_impl), init_(init) { ExtensionManager::get().registerExtension(*this); } -Extension::~Extension() { +ExtensionImpl::~ExtensionImpl() { ExtensionManager::get().unregisterExtension(*this); } -ExtensionInitializer::ExtensionInitializer(Extension& extension, const ExtensionConfig& config): extension_(extension) { +ExtensionInitializer::ExtensionInitializer(ExtensionImpl& extension, const ExtensionConfig& config): extension_(extension) { init_logger->log_trace("Initializing extension: {}", extension_.getName()); if (!extension_.init_impl_(config)) { throw std::runtime_error("Failed to initialize extension"); diff --git a/libminifi/src/http/BaseHTTPClient.cpp b/utils/src/http/BaseHTTPClient.cpp similarity index 100% rename from libminifi/src/http/BaseHTTPClient.cpp rename to utils/src/http/BaseHTTPClient.cpp diff --git a/utils/src/http/HTTPClient.cpp b/utils/src/http/HTTPClient.cpp new file mode 100644 index 0000000000..035284ca10 --- /dev/null +++ b/utils/src/http/HTTPClient.cpp @@ -0,0 +1,533 @@ +/** + * 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 "http/HTTPClient.h" + +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include "core/Resource.h" +#include "magic_enum.hpp" +#include "range/v3/algorithm/all_of.hpp" +#include "range/v3/action/transform.hpp" +#include "utils/gsl.h" +#include "utils/HTTPUtils.h" +#include "utils/Literals.h" +#include "utils/StringUtils.h" + +using namespace std::literals::chrono_literals; + +namespace org::apache::nifi::minifi::http { + +HTTPClient::HTTPClient(std::string url, std::shared_ptr ssl_context_service) + : core::ConnectableImpl("HTTPClient"), + ssl_context_service_(std::move(ssl_context_service)), + url_(std::move(url)) { + http_session_.reset(curl_easy_init()); +} + +HTTPClient::HTTPClient(std::string_view name, const utils::Identifier& uuid) + : core::ConnectableImpl(name, uuid) { + http_session_.reset(curl_easy_init()); +} + +HTTPClient::HTTPClient() + : core::ConnectableImpl("HTTPClient") { + http_session_.reset(curl_easy_init()); +} + +void HTTPClient::addFormPart(const std::string& content_type, const std::string& name, std::unique_ptr form_callback, const std::optional& filename) { + if (!form_) { + form_.reset(curl_mime_init(http_session_.get())); + } + form_callback_ = std::move(form_callback); + curl_mimepart* part = curl_mime_addpart(form_.get()); + curl_mime_type(part, content_type.c_str()); + if (filename) { + curl_mime_filename(part, filename->c_str()); + } + curl_mime_name(part, name.c_str()); + curl_mime_data_cb(part, gsl::narrow(form_callback_->size()), + &HTTPRequestResponse::send_write, nullptr, nullptr, static_cast(form_callback_.get())); +} + +HTTPClient::~HTTPClient() { + // forceClose ended up not being the issue in MINIFICPP-667, but leaving here + // out of good hygiene. + forceClose(); + content_.close(); + logger_->log_trace("Closing HTTPClient for {}", url_); +} + +void HTTPClient::forceClose() { + if (nullptr != read_callback_) { + read_callback_->stop = true; + } + + if (nullptr != write_callback_) { + write_callback_->requestStop(); + } +} + +int HTTPClient::debug_callback(CURL *handle, curl_infotype type, char *data, size_t size, void *userptr) { + auto* const logger = static_cast*>(userptr); + if (logger == nullptr) { + return 0; + } + if (type == CURLINFO_TEXT) { + (*logger)->log_debug("CURL({}): {:.{}}", handle, data, size); + } + return 0; +} + +void HTTPClient::setVerbose(bool use_stderr) { + curl_easy_setopt(http_session_.get(), CURLOPT_VERBOSE, 1L); + if (!use_stderr) { + curl_easy_setopt(http_session_.get(), CURLOPT_DEBUGDATA, &logger_); + curl_easy_setopt(http_session_.get(), CURLOPT_DEBUGFUNCTION, &debug_callback); + } +} + +namespace { +bool isSecure(const std::string& url) { + return url.starts_with("https"); +} +} // namespace + +void HTTPClient::initialize(http::HttpRequestMethod method, std::string url, std::shared_ptr ssl_context_service) { + set_request_method(method); + if (ssl_context_service) { + ssl_context_service_ = std::move(ssl_context_service); + } + if (!url.empty()) { + url_ = std::move(url); + } + if (isSecure(url_)) + configure_secure_connection(); +} +void HTTPClient::setBasicAuth(const std::string& username, const std::string& password) { + curl_easy_setopt(http_session_.get(), CURLOPT_USERNAME, username.c_str()); + curl_easy_setopt(http_session_.get(), CURLOPT_PASSWORD, password.c_str()); +} + +void HTTPClient::clearBasicAuth() { + curl_easy_setopt(http_session_.get(), CURLOPT_USERNAME, nullptr); + curl_easy_setopt(http_session_.get(), CURLOPT_PASSWORD, nullptr); +} + +bool HTTPClient::setSpecificSSLVersion(SSLVersion specific_version) { + if (ssl_context_service_) { + switch (specific_version) { + case SSLVersion::TLSv1_0: { + ssl_context_service_->setMinTlsVersion(TLS1_VERSION); + ssl_context_service_->setMaxTlsVersion(TLS1_VERSION); + break; + } + case SSLVersion::TLSv1_1: { + ssl_context_service_->setMinTlsVersion(TLS1_1_VERSION); + ssl_context_service_->setMaxTlsVersion(TLS1_1_VERSION); + break; + } + case SSLVersion::TLSv1_2: { + ssl_context_service_->setMinTlsVersion(TLS1_2_VERSION); + ssl_context_service_->setMaxTlsVersion(TLS1_2_VERSION); + break; + } + case SSLVersion::TLSv1_3: { + ssl_context_service_->setMinTlsVersion(TLS1_3_VERSION); + ssl_context_service_->setMaxTlsVersion(TLS1_3_VERSION); + break; + } + default: break; + } + } + + // bitwise or of different enum types is deprecated in C++20, but the curl api explicitly supports ORing one of CURL_SSLVERSION and one of CURL_SSLVERSION_MAX + switch (specific_version) { + case SSLVersion::TLSv1_0: + return CURLE_OK == curl_easy_setopt(http_session_.get(), CURLOPT_SSLVERSION, static_cast(CURL_SSLVERSION_TLSv1_0) | static_cast(CURL_SSLVERSION_MAX_TLSv1_0)); + case SSLVersion::TLSv1_1: + return CURLE_OK == curl_easy_setopt(http_session_.get(), CURLOPT_SSLVERSION, static_cast(CURL_SSLVERSION_TLSv1_1) | static_cast(CURL_SSLVERSION_MAX_TLSv1_1)); + case SSLVersion::TLSv1_2: + return CURLE_OK == curl_easy_setopt(http_session_.get(), CURLOPT_SSLVERSION, static_cast(CURL_SSLVERSION_TLSv1_2) | static_cast(CURL_SSLVERSION_MAX_TLSv1_2)); + case SSLVersion::TLSv1_3: + return CURLE_OK == curl_easy_setopt(http_session_.get(), CURLOPT_SSLVERSION, static_cast(CURL_SSLVERSION_TLSv1_3) | static_cast(CURL_SSLVERSION_MAX_TLSv1_3)); + default: return false; + } +} + +// If not set, the default will be TLS 1.0, see https://curl.haxx.se/libcurl/c/CURLOPT_SSLVERSION.html +bool HTTPClient::setMinimumSSLVersion(SSLVersion minimum_version) { + if (ssl_context_service_) { + switch (minimum_version) { + case SSLVersion::TLSv1_0: { + ssl_context_service_->setMinTlsVersion(TLS1_VERSION); + break; + } + case SSLVersion::TLSv1_1: { + ssl_context_service_->setMinTlsVersion(TLS1_1_VERSION); + break; + } + case SSLVersion::TLSv1_2: { + ssl_context_service_->setMinTlsVersion(TLS1_2_VERSION); + break; + } + case SSLVersion::TLSv1_3: { + ssl_context_service_->setMinTlsVersion(TLS1_3_VERSION); + break; + } + default: break; + } + } + + CURLcode ret = CURLE_UNKNOWN_OPTION; + switch (minimum_version) { + case SSLVersion::TLSv1_0: + ret = curl_easy_setopt(http_session_.get(), CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1_0); + break; + case SSLVersion::TLSv1_1: + ret = curl_easy_setopt(http_session_.get(), CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1_1); + break; + case SSLVersion::TLSv1_2: + ret = curl_easy_setopt(http_session_.get(), CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1_2); + break; + case SSLVersion::TLSv1_3: + ret = curl_easy_setopt(http_session_.get(), CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1_3); + break; + } + + return ret == CURLE_OK; +} + +void HTTPClient::setKeepAliveProbe(std::optional probe_data) { + if (probe_data) { + curl_easy_setopt(http_session_.get(), CURLOPT_TCP_KEEPALIVE, true); + curl_easy_setopt(http_session_.get(), CURLOPT_TCP_KEEPINTVL, probe_data->keep_alive_interval.count()); + curl_easy_setopt(http_session_.get(), CURLOPT_TCP_KEEPIDLE, probe_data->keep_alive_delay.count()); + } else { + curl_easy_setopt(http_session_.get(), CURLOPT_TCP_KEEPALIVE, false); + } +} + +void HTTPClient::setConnectionTimeout(std::chrono::milliseconds timeout) { + if (timeout < 0ms) { + logger_->log_error("Invalid HTTP connection timeout {}", timeout); + return; + } + connect_timeout_ = timeout; +} + +void HTTPClient::setReadTimeout(std::chrono::milliseconds timeout) { + if (timeout < 0ms) { + logger_->log_error("Invalid HTTP read timeout {}", timeout); + return; + } + read_timeout_ = timeout; +} + +void HTTPClient::setReadCallback(std::unique_ptr callback) { + read_callback_ = std::move(callback); + curl_easy_setopt(http_session_.get(), CURLOPT_WRITEFUNCTION, &HTTPRequestResponse::receiveWrite); + curl_easy_setopt(http_session_.get(), CURLOPT_WRITEDATA, static_cast(read_callback_.get())); +} + +void HTTPClient::setUploadCallback(std::unique_ptr callback) { + logger_->log_debug("Setting callback for {}", url_); + write_callback_ = std::move(callback); + if (method_ == http::HttpRequestMethod::PUT) { + curl_easy_setopt(http_session_.get(), CURLOPT_INFILESIZE_LARGE, (curl_off_t) write_callback_->size()); + } + curl_easy_setopt(http_session_.get(), CURLOPT_READFUNCTION, &HTTPRequestResponse::send_write); + curl_easy_setopt(http_session_.get(), CURLOPT_READDATA, static_cast(write_callback_.get())); + curl_easy_setopt(http_session_.get(), CURLOPT_SEEKDATA, static_cast(write_callback_.get())); + curl_easy_setopt(http_session_.get(), CURLOPT_SEEKFUNCTION, &HTTPRequestResponse::seek_callback); +} + +void HTTPClient::setContentType(std::string content_type) { + request_headers_["Content-Type"] = std::move(content_type); +} + +std::string HTTPClient::escape(std::string string_to_escape) { + struct curl_deleter { void operator()(void* p) noexcept { curl_free(p); } }; + std::unique_ptr escaped_chars{curl_easy_escape(http_session_.get(), string_to_escape.c_str(), gsl::narrow(string_to_escape.length()))}; + std::string escaped_string(escaped_chars.get()); + return escaped_string; +} + +void HTTPClient::setPostFields(const std::string& input) { + setPostSize(input.length()); + curl_easy_setopt(http_session_.get(), CURLOPT_COPYPOSTFIELDS, input.c_str()); +} + +void HTTPClient::setPostSize(size_t size) { + if (size > 2_GB) { + curl_easy_setopt(http_session_.get(), CURLOPT_POSTFIELDSIZE_LARGE, size); + } else { + curl_easy_setopt(http_session_.get(), CURLOPT_POSTFIELDSIZE, size); + } +} + +void HTTPClient::setHTTPProxy(const HTTPProxy &proxy) { + if (!proxy.host.empty()) { + curl_easy_setopt(http_session_.get(), CURLOPT_PROXY, proxy.host.c_str()); + curl_easy_setopt(http_session_.get(), CURLOPT_PROXYPORT, proxy.port); + if (!proxy.username.empty()) { + curl_easy_setopt(http_session_.get(), CURLOPT_PROXYAUTH, CURLAUTH_ANY); + std::string value = proxy.username + ":" + proxy.password; + curl_easy_setopt(http_session_.get(), CURLOPT_PROXYUSERPWD, value.c_str()); + } + } +} + +void HTTPClient::setRequestHeader(std::string key, std::optional value) { + if (value) + request_headers_[std::move(key)] = std::move(*value); + else + request_headers_.erase(key); +} + +namespace { +using CurlSlistDeleter = decltype([](struct curl_slist* slist) { curl_slist_free_all(slist); }); + +std::unique_ptr toCurlSlist(const std::unordered_map& request_headers) { + gsl::owner new_list = nullptr; + const auto guard = gsl::finally([&new_list]() { curl_slist_free_all(new_list); }); + for (const auto& [header_key, header_value] : request_headers) + new_list = (utils::optional_from_ptr(curl_slist_append(new_list, utils::string::join_pack(header_key, ": ", header_value).c_str())) // NOLINT(cppcoreguidelines-owning-memory) + | utils::orElse([]() { throw std::runtime_error{"curl_slist_append failed"}; })).value(); + + return {std::exchange(new_list, nullptr), {}}; +} +} // namespace + + +bool HTTPClient::submit() { + if (url_.empty()) { + logger_->log_error("Tried to submit to an empty url"); + return false; + } + if (!method_) { + logger_->log_error("Tried to use HTTPClient without setting an HTTP method"); + return false; + } + + response_data_.clear(); + + curl_easy_setopt(http_session_.get(), CURLOPT_NOSIGNAL, 1); + curl_easy_setopt(http_session_.get(), CURLOPT_CONNECTTIMEOUT_MS, connect_timeout_.count()); + curl_easy_setopt(http_session_.get(), CURLOPT_TIMEOUT_MS, getAbsoluteTimeout().count()); + + if (read_timeout_ > 0ms) { + progress_.reset(); + curl_easy_setopt(http_session_.get(), CURLOPT_NOPROGRESS, 0); + curl_easy_setopt(http_session_.get(), CURLOPT_XFERINFOFUNCTION, onProgress); + curl_easy_setopt(http_session_.get(), CURLOPT_XFERINFODATA, this); + } else { + // the user explicitly set it to 0 + curl_easy_setopt(http_session_.get(), CURLOPT_NOPROGRESS, 1); + } + + const auto headers = toCurlSlist(request_headers_); + if (headers) { + curl_slist_append(headers.get(), "Expect:"); + curl_easy_setopt(http_session_.get(), CURLOPT_HTTPHEADER, headers.get()); + } + + curl_easy_setopt(http_session_.get(), CURLOPT_URL, url_.c_str()); + logger_->log_debug("Submitting to {}", url_); + if (read_callback_ == nullptr) { + curl_easy_setopt(http_session_.get(), CURLOPT_WRITEFUNCTION, &HTTPRequestResponse::receiveWrite); + curl_easy_setopt(http_session_.get(), CURLOPT_WRITEDATA, static_cast(&content_)); + } + + curl_easy_setopt(http_session_.get(), CURLOPT_HEADERFUNCTION, &HTTPHeaderResponse::receive_headers); + curl_easy_setopt(http_session_.get(), CURLOPT_HEADERDATA, static_cast(&response_data_.header_response)); + + if (form_ != nullptr) { + curl_easy_setopt(http_session_.get(), CURLOPT_MIMEPOST, form_.get()); + } + res_ = curl_easy_perform(http_session_.get()); + if (read_callback_ == nullptr) { + content_.close(); + } + long http_code = 0; // NOLINT(runtime/int,google-runtime-int) long due to libcurl API + curl_easy_getinfo(http_session_.get(), CURLINFO_RESPONSE_CODE, &http_code); + response_data_.response_code = http_code; + curl_easy_getinfo(http_session_.get(), CURLINFO_CONTENT_TYPE, &response_data_.response_content_type); + if (res_ == CURLE_OPERATION_TIMEDOUT) { + logger_->log_error("HTTP operation timed out, with absolute timeout {}\n", getAbsoluteTimeout()); + } + if (res_ != CURLE_OK) { + logger_->log_info("{}", request_headers_.size()); + logger_->log_error("curl_easy_perform() failed {} on {}, error code {}\n", curl_easy_strerror(res_), url_, magic_enum::enum_underlying(res_)); + return false; + } + + logger_->log_debug("Finished with {}", url_); + return true; +} + +int64_t HTTPClient::getResponseCode() const { + return response_data_.response_code; +} + +const char *HTTPClient::getContentType() { + return response_data_.response_content_type; +} + +const std::vector &HTTPClient::getResponseBody() { + if (response_data_.response_body.empty()) { + if (read_callback_) { + response_data_.response_body = read_callback_->to_string(); + } else { + response_data_.response_body = content_.to_string(); + } + } + return response_data_.response_body; +} + +void HTTPClient::set_request_method(http::HttpRequestMethod method) { + if (method_ == method) + return; + method_ = method; + switch (*method_) { + case http::HttpRequestMethod::POST: + curl_easy_setopt(http_session_.get(), CURLOPT_POST, 1L); + curl_easy_setopt(http_session_.get(), CURLOPT_CUSTOMREQUEST, nullptr); + break; + case http::HttpRequestMethod::HEAD: + curl_easy_setopt(http_session_.get(), CURLOPT_NOBODY, 1L); + curl_easy_setopt(http_session_.get(), CURLOPT_CUSTOMREQUEST, nullptr); + break; + case http::HttpRequestMethod::GET: + curl_easy_setopt(http_session_.get(), CURLOPT_HTTPGET, 1L); + curl_easy_setopt(http_session_.get(), CURLOPT_CUSTOMREQUEST, nullptr); + break; + case http::HttpRequestMethod::PUT: + curl_easy_setopt(http_session_.get(), CURLOPT_UPLOAD, 1L); + curl_easy_setopt(http_session_.get(), CURLOPT_CUSTOMREQUEST, nullptr); + break; + default: + curl_easy_setopt(http_session_.get(), CURLOPT_POST, 0L); + curl_easy_setopt(http_session_.get(), CURLOPT_NOBODY, 0L); + curl_easy_setopt(http_session_.get(), CURLOPT_HTTPGET, 0L); + curl_easy_setopt(http_session_.get(), CURLOPT_UPLOAD, 0L); + curl_easy_setopt(http_session_.get(), CURLOPT_CUSTOMREQUEST, std::string(magic_enum::enum_name(*method_)).c_str()); + break; + } +} + +int HTTPClient::onProgress(void *clientp, curl_off_t /*dltotal*/, curl_off_t dlnow, curl_off_t /*ultotal*/, curl_off_t ulnow) { + gsl_Expects(clientp); + HTTPClient& client = *static_cast(clientp); + auto now = std::chrono::steady_clock::now(); + auto elapsed = now - client.progress_.last_transferred_; + if (dlnow != client.progress_.downloaded_data_ || ulnow != client.progress_.uploaded_data_) { + // did transfer data + client.progress_.last_transferred_ = now; + client.progress_.downloaded_data_ = dlnow; + client.progress_.uploaded_data_ = ulnow; + return 0; + } + // did not transfer data + if (elapsed > client.read_timeout_) { + // timeout + client.logger_->log_error("HTTP operation has been idle for {}, limit ({}) reached, terminating connection\n", elapsed, client.read_timeout_); + return 1; + } + return 0; +} + +void HTTPClient::configure_secure_connection() { + if (ssl_context_service_) { + curl_easy_setopt(http_session_.get(), CURLOPT_SSL_CTX_FUNCTION, &configure_ssl_context); + curl_easy_setopt(http_session_.get(), CURLOPT_SSL_CTX_DATA, static_cast(ssl_context_service_.get())); + curl_easy_setopt(http_session_.get(), CURLOPT_CAINFO, nullptr); + curl_easy_setopt(http_session_.get(), CURLOPT_CAPATH, nullptr); + } else { + static const auto default_ca_file = utils::getDefaultCAFile(); + + if (default_ca_file) + logger_->log_debug("Using CA certificate file \"{}\"", *default_ca_file); + else + logger_->log_error("Could not find valid CA certificate file"); + + curl_easy_setopt(http_session_.get(), CURLOPT_SSL_CTX_FUNCTION, nullptr); + curl_easy_setopt(http_session_.get(), CURLOPT_SSL_CTX_DATA, nullptr); + if (default_ca_file) + curl_easy_setopt(http_session_.get(), CURLOPT_CAINFO, std::string(*default_ca_file).c_str()); + else + curl_easy_setopt(http_session_.get(), CURLOPT_CAINFO, nullptr); + curl_easy_setopt(http_session_.get(), CURLOPT_CAPATH, nullptr); + } +} + +void HTTPClient::setInterface(const std::string &ifc) { + curl_easy_setopt(http_session_.get(), CURLOPT_INTERFACE, ifc.c_str()); +} + +void HTTPClient::setFollowRedirects(bool follow) { + curl_easy_setopt(http_session_.get(), CURLOPT_FOLLOWLOCATION, follow); +} + +void HTTPClient::setMaximumUploadSpeed(uint64_t max_bytes_per_second) { + curl_easy_setopt(http_session_.get(), CURLOPT_MAX_SEND_SPEED_LARGE, max_bytes_per_second); +} + +void HTTPClient::setMaximumDownloadSpeed(uint64_t max_bytes_per_second) { + curl_easy_setopt(http_session_.get(), CURLOPT_MAX_RECV_SPEED_LARGE, max_bytes_per_second); +} + +bool HTTPClient::isValidHttpHeaderField(std::string_view field_name) { + if (field_name.empty()) { + return false; + } + + // RFC822 3.1.2: The field-name must be composed of printable ASCII characters + // (i.e., characters that have values between 33. and 126., decimal, except colon). + return ranges::all_of(field_name, [](char c) { return c >= 33 && c <= 126 && c != ':'; }); +} + +std::string HTTPClient::replaceInvalidCharactersInHttpHeaderFieldName(std::string field_name) { + if (field_name.empty()) { + return "X-MiNiFi-Empty-Attribute-Name"; + } + + // RFC822 3.1.2: The field-name must be composed of printable ASCII characters + // (i.e., characters that have values between 33. and 126., decimal, except colon). + ranges::actions::transform(field_name, [](char ch) { // NOLINT: false positive: Add #include for transform [build/include_what_you_use] [4] + return (ch >= 33 && ch <= 126 && ch != ':') ? ch : '-'; + }); + return field_name; +} + +void HTTPClient::CurlEasyCleanup::operator()(CURL* curl) const { + curl_easy_cleanup(curl); +} + +void HTTPClient::CurlMimeFree::operator()(curl_mime* curl_mime) const { + curl_mime_free(curl_mime); +} + +} // namespace org::apache::nifi::minifi::http diff --git a/libminifi/src/http/HTTPStream.cpp b/utils/src/http/HTTPStream.cpp similarity index 100% rename from libminifi/src/http/HTTPStream.cpp rename to utils/src/http/HTTPStream.cpp diff --git a/libminifi/src/io/BufferStream.cpp b/utils/src/io/BufferStream.cpp similarity index 100% rename from libminifi/src/io/BufferStream.cpp rename to utils/src/io/BufferStream.cpp diff --git a/utils/src/io/CPPLINT.cfg b/utils/src/io/CPPLINT.cfg new file mode 100644 index 0000000000..7fbc5049d2 --- /dev/null +++ b/utils/src/io/CPPLINT.cfg @@ -0,0 +1,4 @@ +set noparent +filter=-build/c++11,-build/include_subdir +exclude_files=ClientSocket\.cpp + diff --git a/libminifi/src/io/CRCStream.cpp b/utils/src/io/CRCStream.cpp similarity index 100% rename from libminifi/src/io/CRCStream.cpp rename to utils/src/io/CRCStream.cpp diff --git a/libminifi/src/io/FileStream.cpp b/utils/src/io/FileStream.cpp similarity index 99% rename from libminifi/src/io/FileStream.cpp rename to utils/src/io/FileStream.cpp index 1ef4faa9df..3d53b86a08 100644 --- a/libminifi/src/io/FileStream.cpp +++ b/utils/src/io/FileStream.cpp @@ -20,7 +20,7 @@ #include #include #include -#include +#include "Exception.h" #include "io/validation.h" #include "io/FileStream.h" #include "io/InputStream.h" diff --git a/libminifi/src/io/InputStream.cpp b/utils/src/io/InputStream.cpp similarity index 94% rename from libminifi/src/io/InputStream.cpp rename to utils/src/io/InputStream.cpp index accb580095..6765698fb7 100644 --- a/libminifi/src/io/InputStream.cpp +++ b/utils/src/io/InputStream.cpp @@ -87,4 +87,12 @@ size_t InputStream::read(std::string &str, bool widen) { return length_return + string_length; } +std::optional InputStream::readByte() { + std::array buf{}; + if (read(buf) != 1) { + return std::nullopt; + } + return buf[0]; +} + } // namespace org::apache::nifi::minifi::io diff --git a/libminifi/src/io/OutputStream.cpp b/utils/src/io/OutputStream.cpp similarity index 100% rename from libminifi/src/io/OutputStream.cpp rename to utils/src/io/OutputStream.cpp diff --git a/libminifi/src/io/StreamSlice.cpp b/utils/src/io/StreamSlice.cpp similarity index 100% rename from libminifi/src/io/StreamSlice.cpp rename to utils/src/io/StreamSlice.cpp diff --git a/libminifi/src/io/ZlibStream.cpp b/utils/src/io/ZlibStream.cpp similarity index 99% rename from libminifi/src/io/ZlibStream.cpp rename to utils/src/io/ZlibStream.cpp index 9299805cd1..b44eeee95c 100644 --- a/libminifi/src/io/ZlibStream.cpp +++ b/utils/src/io/ZlibStream.cpp @@ -19,7 +19,7 @@ #include "io/ZlibStream.h" #include "Exception.h" #include "utils/gsl.h" -#include "core/logging/LoggerConfiguration.h" +#include "core/logging/LoggerFactory.h" #include "magic_enum.hpp" namespace org::apache::nifi::minifi::io { diff --git a/libminifi/src/controllers/keyvalue/AutoPersistor.cpp b/utils/src/utils/AutoPersistor.cpp similarity index 98% rename from libminifi/src/controllers/keyvalue/AutoPersistor.cpp rename to utils/src/utils/AutoPersistor.cpp index bc52cff277..6684d4b50b 100644 --- a/libminifi/src/controllers/keyvalue/AutoPersistor.cpp +++ b/utils/src/utils/AutoPersistor.cpp @@ -17,7 +17,7 @@ #include -#include "controllers/keyvalue/AutoPersistor.h" +#include "utils/AutoPersistor.h" #include "core/TypedValues.h" using namespace std::literals::chrono_literals; diff --git a/libminifi/src/utils/BackTrace.cpp b/utils/src/utils/BackTrace.cpp similarity index 100% rename from libminifi/src/utils/BackTrace.cpp rename to utils/src/utils/BackTrace.cpp diff --git a/libminifi/src/utils/ByteArrayCallback.cpp b/utils/src/utils/ByteArrayCallback.cpp similarity index 100% rename from libminifi/src/utils/ByteArrayCallback.cpp rename to utils/src/utils/ByteArrayCallback.cpp diff --git a/libminifi/src/utils/ClassUtils.cpp b/utils/src/utils/ClassUtils.cpp similarity index 100% rename from libminifi/src/utils/ClassUtils.cpp rename to utils/src/utils/ClassUtils.cpp diff --git a/libminifi/src/utils/Cron.cpp b/utils/src/utils/Cron.cpp similarity index 100% rename from libminifi/src/utils/Cron.cpp rename to utils/src/utils/Cron.cpp diff --git a/libminifi/src/utils/Environment.cpp b/utils/src/utils/Environment.cpp similarity index 100% rename from libminifi/src/utils/Environment.cpp rename to utils/src/utils/Environment.cpp diff --git a/libminifi/src/utils/Error.cpp b/utils/src/utils/Error.cpp similarity index 100% rename from libminifi/src/utils/Error.cpp rename to utils/src/utils/Error.cpp diff --git a/libminifi/src/utils/FifoExecutor.cpp b/utils/src/utils/FifoExecutor.cpp similarity index 100% rename from libminifi/src/utils/FifoExecutor.cpp rename to utils/src/utils/FifoExecutor.cpp diff --git a/libminifi/src/utils/FileMutex.cpp b/utils/src/utils/FileMutex.cpp similarity index 100% rename from libminifi/src/utils/FileMutex.cpp rename to utils/src/utils/FileMutex.cpp diff --git a/libminifi/src/utils/HTTPUtils.cpp b/utils/src/utils/HTTPUtils.cpp similarity index 100% rename from libminifi/src/utils/HTTPUtils.cpp rename to utils/src/utils/HTTPUtils.cpp diff --git a/libminifi/src/utils/Id.cpp b/utils/src/utils/Id.cpp similarity index 100% rename from libminifi/src/utils/Id.cpp rename to utils/src/utils/Id.cpp diff --git a/libminifi/src/utils/LineByLineInputOutputStreamCallback.cpp b/utils/src/utils/LineByLineInputOutputStreamCallback.cpp similarity index 100% rename from libminifi/src/utils/LineByLineInputOutputStreamCallback.cpp rename to utils/src/utils/LineByLineInputOutputStreamCallback.cpp diff --git a/libminifi/src/utils/OsUtils.cpp b/utils/src/utils/OsUtils.cpp similarity index 100% rename from libminifi/src/utils/OsUtils.cpp rename to utils/src/utils/OsUtils.cpp diff --git a/libminifi/src/utils/ProcessCpuUsageTracker.cpp b/utils/src/utils/ProcessCpuUsageTracker.cpp similarity index 100% rename from libminifi/src/utils/ProcessCpuUsageTracker.cpp rename to utils/src/utils/ProcessCpuUsageTracker.cpp diff --git a/libminifi/src/utils/RegexUtils.cpp b/utils/src/utils/RegexUtils.cpp similarity index 100% rename from libminifi/src/utils/RegexUtils.cpp rename to utils/src/utils/RegexUtils.cpp diff --git a/libminifi/src/utils/StoppableThread.cpp b/utils/src/utils/StoppableThread.cpp similarity index 100% rename from libminifi/src/utils/StoppableThread.cpp rename to utils/src/utils/StoppableThread.cpp diff --git a/libminifi/src/utils/StringUtils.cpp b/utils/src/utils/StringUtils.cpp similarity index 100% rename from libminifi/src/utils/StringUtils.cpp rename to utils/src/utils/StringUtils.cpp diff --git a/libminifi/src/utils/SystemCpuUsageTracker.cpp b/utils/src/utils/SystemCpuUsageTracker.cpp similarity index 100% rename from libminifi/src/utils/SystemCpuUsageTracker.cpp rename to utils/src/utils/SystemCpuUsageTracker.cpp diff --git a/libminifi/src/utils/ThreadPool.cpp b/utils/src/utils/ThreadPool.cpp similarity index 98% rename from libminifi/src/utils/ThreadPool.cpp rename to utils/src/utils/ThreadPool.cpp index e5f88be510..999f3ad5cc 100644 --- a/libminifi/src/utils/ThreadPool.cpp +++ b/utils/src/utils/ThreadPool.cpp @@ -16,12 +16,13 @@ */ #include "utils/ThreadPool.h" +#include "core/logging/LoggerFactory.h" using namespace std::literals::chrono_literals; namespace org::apache::nifi::minifi::utils { -ThreadPool::ThreadPool(int max_worker_threads, core::controller::ControllerServiceProvider* controller_service_provider, std::string name) +ThreadPool::ThreadPool(int max_worker_threads, core::controller::ControllerServiceLookup* controller_service_provider, std::string name) : thread_reduction_count_(0), max_worker_threads_(max_worker_threads), current_workers_(0), diff --git a/utils/src/utils/TimeUtil.cpp b/utils/src/utils/TimeUtil.cpp new file mode 100644 index 0000000000..67b5ecc6e7 --- /dev/null +++ b/utils/src/utils/TimeUtil.cpp @@ -0,0 +1,126 @@ +/** + * 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 "utils/TimeUtil.h" +#include "range/v3/algorithm/contains.hpp" +#include "fmt/format.h" +#include "fmt/chrono.h" + +#ifdef WIN32 +#include "date/tz.h" +#endif + +namespace org::apache::nifi::minifi::utils::timeutils { + +using namespace std::literals::chrono_literals; + +namespace { +template +std::tuple breakDownDurations(std::chrono::system_clock::duration input_duration) { + std::tuple result; + + ([&](T& duration) { + duration = std::chrono::duration_cast>(input_duration); + input_duration -= duration; + } (std::get(result)), ...); + + return result; +} + +std::string formatAsDaysHoursMinutesSeconds(std::chrono::system_clock::duration input_duration) { + const auto durs = breakDownDurations(input_duration); + const auto& days = std::get(durs); + std::string day_string; + if (days.count() > 0) { + day_string = fmt::format("{} {}", days.count(), days.count() == 1 ? "day, " : "days, "); + } + return fmt::format("{}{:02}:{:02}:{:02}", + day_string, std::get(durs).count(), + std::get(durs).count(), + std::get(durs).count()); +} + +template +std::string formatAsRoundedLargestUnit(std::chrono::system_clock::duration input_duration) { + std::optional rounded_value_str; + using std::chrono::duration_cast; + using std::chrono::duration; + + ((rounded_value_str = input_duration >= Durations(1) + ? std::optional{fmt::format("{:.2}", duration_cast>(input_duration))} + : std::nullopt) || ...); + + + if (!rounded_value_str) { + return fmt::format("{}", input_duration); + } + + return *rounded_value_str; +} + +} // namespace + +std::string humanReadableDuration(std::chrono::system_clock::duration input_duration) { + if (input_duration > 5s) { + return formatAsDaysHoursMinutesSeconds(input_duration); + } + + return formatAsRoundedLargestUnit(input_duration); +} + +std::optional parseRfc3339(const std::string& str) { + std::istringstream stream(str); + date::year_month_day date_part{}; + date::from_stream(stream, "%F", date_part); + + if (stream.fail()) + return std::nullopt; + + constexpr std::string_view accepted_delimiters = "tT_ "; + char delimiter_char = 0; + stream.get(delimiter_char); + + if (stream.fail() || !ranges::contains(accepted_delimiters, delimiter_char)) + return std::nullopt; + + std::chrono::system_clock::duration time_part; + std::chrono::minutes offset = 0min; + if (str.ends_with('Z') || str.ends_with('z')) { + date::from_stream(stream, "%T", time_part); + if (stream.fail()) + return std::nullopt; + stream.get(); + } else { + date::from_stream(stream, "%T%Ez", time_part, {}, &offset); + } + + if (stream.fail() || (stream.peek() && !stream.eof())) + return std::nullopt; + + return date::sys_days(date_part) + time_part - offset; +} + +#ifdef WIN32 +// If minifi is not installed through the MSI installer, then TZDATA might be missing +// date::set_install can point to the TZDATA location, but it has to be called from each library/executable that wants to use timezones +void dateSetInstall(const std::string& install) { + date::set_install(install); + dateSetGlobalInstall(install); +} +#endif + +} // namespace org::apache::nifi::minifi::utils::timeutils diff --git a/libminifi/src/utils/crypto/EncryptionManager.cpp b/utils/src/utils/crypto/EncryptionManager.cpp similarity index 72% rename from libminifi/src/utils/crypto/EncryptionManager.cpp rename to utils/src/utils/crypto/EncryptionManager.cpp index dd0e4fe6e8..3cedac44c2 100644 --- a/libminifi/src/utils/crypto/EncryptionManager.cpp +++ b/utils/src/utils/crypto/EncryptionManager.cpp @@ -19,25 +19,25 @@ #include #include "utils/crypto/EncryptionManager.h" -#include "properties/Properties.h" +#include "minifi-cpp/properties/Properties.h" #include "utils/StringUtils.h" namespace org::apache::nifi::minifi::utils::crypto { std::optional EncryptionManager::readKey(const std::string& key_name) const { - minifi::Properties bootstrap_conf; - bootstrap_conf.setHome(key_dir_); - bootstrap_conf.loadConfigureFile(DEFAULT_NIFI_BOOTSTRAP_FILE); - return bootstrap_conf.getString(key_name) + auto bootstrap_conf = minifi::Properties::create(); + bootstrap_conf->setHome(key_dir_); + bootstrap_conf->loadConfigureFile(DEFAULT_NIFI_BOOTSTRAP_FILE); + return bootstrap_conf->getString(key_name) | utils::transform([](const std::string &encryption_key_hex) { return utils::string::from_hex(encryption_key_hex); }); } bool EncryptionManager::writeKey(const std::string &key_name, const Bytes& key) const { - minifi::Properties bootstrap_conf; - bootstrap_conf.setHome(key_dir_); - bootstrap_conf.loadConfigureFile(DEFAULT_NIFI_BOOTSTRAP_FILE); - bootstrap_conf.set(key_name, utils::string::to_hex(key)); - return bootstrap_conf.commitChanges(); + auto bootstrap_conf = minifi::Properties::create(); + bootstrap_conf->setHome(key_dir_); + bootstrap_conf->loadConfigureFile(DEFAULT_NIFI_BOOTSTRAP_FILE); + bootstrap_conf->set(key_name, utils::string::to_hex(key)); + return bootstrap_conf->commitChanges(); } } // namespace org::apache::nifi::minifi::utils::crypto diff --git a/libminifi/src/utils/crypto/EncryptionProvider.cpp b/utils/src/utils/crypto/EncryptionProvider.cpp similarity index 100% rename from libminifi/src/utils/crypto/EncryptionProvider.cpp rename to utils/src/utils/crypto/EncryptionProvider.cpp diff --git a/libminifi/src/utils/crypto/EncryptionUtils.cpp b/utils/src/utils/crypto/EncryptionUtils.cpp similarity index 100% rename from libminifi/src/utils/crypto/EncryptionUtils.cpp rename to utils/src/utils/crypto/EncryptionUtils.cpp diff --git a/libminifi/src/utils/crypto/ciphers/Aes256Ecb.cpp b/utils/src/utils/crypto/ciphers/Aes256Ecb.cpp similarity index 99% rename from libminifi/src/utils/crypto/ciphers/Aes256Ecb.cpp rename to utils/src/utils/crypto/ciphers/Aes256Ecb.cpp index bad7f6397b..d7fc0425e7 100644 --- a/libminifi/src/utils/crypto/ciphers/Aes256Ecb.cpp +++ b/utils/src/utils/crypto/ciphers/Aes256Ecb.cpp @@ -21,7 +21,7 @@ #include "openssl/evp.h" #include "openssl/err.h" #include "openssl/rand.h" -#include "core/logging/LoggerConfiguration.h" +#include "core/logging/LoggerFactory.h" namespace org::apache::nifi::minifi::utils::crypto { diff --git a/libminifi/src/utils/crypto/property_encryption/PropertyEncryptionUtils.cpp b/utils/src/utils/crypto/property_encryption/PropertyEncryptionUtils.cpp similarity index 100% rename from libminifi/src/utils/crypto/property_encryption/PropertyEncryptionUtils.cpp rename to utils/src/utils/crypto/property_encryption/PropertyEncryptionUtils.cpp diff --git a/libminifi/src/utils/file/FilePattern.cpp b/utils/src/utils/file/FilePattern.cpp similarity index 99% rename from libminifi/src/utils/file/FilePattern.cpp rename to utils/src/utils/file/FilePattern.cpp index 75a918df1b..8042c6588e 100644 --- a/libminifi/src/utils/file/FilePattern.cpp +++ b/utils/src/utils/file/FilePattern.cpp @@ -18,7 +18,7 @@ #include "utils/file/FilePattern.h" #include "utils/file/FileUtils.h" #include "utils/StringUtils.h" -#include "core/logging/LoggerConfiguration.h" +#include "core/logging/LoggerFactory.h" namespace org::apache::nifi::minifi::utils::file { diff --git a/libminifi/src/utils/file/FileUtils.cpp b/utils/src/utils/file/FileUtils.cpp similarity index 100% rename from libminifi/src/utils/file/FileUtils.cpp rename to utils/src/utils/file/FileUtils.cpp diff --git a/libminifi/src/utils/file/PathUtils.cpp b/utils/src/utils/file/PathUtils.cpp similarity index 100% rename from libminifi/src/utils/file/PathUtils.cpp rename to utils/src/utils/file/PathUtils.cpp diff --git a/libminifi/src/utils/net/AsioSocketUtils.cpp b/utils/src/utils/net/AsioSocketUtils.cpp similarity index 98% rename from libminifi/src/utils/net/AsioSocketUtils.cpp rename to utils/src/utils/net/AsioSocketUtils.cpp index 054da24763..632b98eed8 100644 --- a/libminifi/src/utils/net/AsioSocketUtils.cpp +++ b/utils/src/utils/net/AsioSocketUtils.cpp @@ -16,7 +16,7 @@ */ #include "utils/net/AsioSocketUtils.h" -#include "controllers/SSLContextService.h" +#include "minifi-cpp/controllers/SSLContextService.h" #include "io/AsioStream.h" #include "asio/connect.hpp" diff --git a/libminifi/src/utils/net/DNS.cpp b/utils/src/utils/net/DNS.cpp similarity index 100% rename from libminifi/src/utils/net/DNS.cpp rename to utils/src/utils/net/DNS.cpp diff --git a/libminifi/src/utils/NetworkInterfaceInfo.cpp b/utils/src/utils/net/NetworkInterfaceInfo.cpp similarity index 98% rename from libminifi/src/utils/NetworkInterfaceInfo.cpp rename to utils/src/utils/net/NetworkInterfaceInfo.cpp index 3361357931..bc1c1d0b1b 100644 --- a/libminifi/src/utils/NetworkInterfaceInfo.cpp +++ b/utils/src/utils/net/NetworkInterfaceInfo.cpp @@ -14,9 +14,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include "utils/NetworkInterfaceInfo.h" +#include "utils/net/NetworkInterfaceInfo.h" #include "utils/net/Socket.h" -#include "core/logging/LoggerConfiguration.h" +#include "core/logging/LoggerFactory.h" #ifdef WIN32 #include #pragma comment(lib, "IPHLPAPI.lib") diff --git a/libminifi/src/utils/net/Socket.cpp b/utils/src/utils/net/Socket.cpp similarity index 100% rename from libminifi/src/utils/net/Socket.cpp rename to utils/src/utils/net/Socket.cpp