Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MINIFICPP-2462 - Divide libminifi #1902

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions controller/MiNiFiController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ std::shared_ptr<minifi::core::controller::ControllerService> 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(
Expand Down Expand Up @@ -78,7 +78,7 @@ std::shared_ptr<minifi::controllers::SSLContextService> 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<minifi::controllers::SSLContextService>("ControllerSocketProtocolSSL", configuration);
secure_context = std::make_shared<minifi::controllers::SSLContextServiceImpl>("ControllerSocketProtocolSSL", configuration);
secure_context->onEnable();
}
} else {
Expand All @@ -96,7 +96,7 @@ int main(int argc, char **argv) {
return -1;
}

const auto configuration = std::make_shared<minifi::Configure>();
const auto configuration = std::make_shared<minifi::ConfigureImpl>();
configuration->setHome(minifi_home);
configuration->loadConfigureFile(DEFAULT_NIFI_PROPERTIES_FILE);

Expand Down
19 changes: 10 additions & 9 deletions controller/tests/ControllerTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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<controllers::SSLContextService> ssl_context_service)
: core::controller::ControllerServiceProvider("TestControllerServiceProvider"),
: core::controller::ControllerServiceProviderImpl("TestControllerServiceProvider"),
ssl_context_service_(std::move(ssl_context_service)) {
}
std::shared_ptr<core::controller::ControllerService> getControllerService(const std::string&) const override {
Expand Down Expand Up @@ -239,7 +240,7 @@ class ControllerTestFixture {
};

ControllerTestFixture()
: configuration_(std::make_shared<minifi::Configure>()),
: configuration_(std::make_shared<minifi::ConfigureImpl>()),
controller_(std::make_shared<TestStateController>()),
update_sink_(std::make_unique<TestUpdateSink>(controller_)) {
configuration_->set(minifi::Configure::controller_socket_host, "localhost");
Expand All @@ -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<controllers::SSLContextService>("SSLContextService", configuration_);
ssl_context_service_ = std::make_shared<controllers::SSLContextServiceImpl>("SSLContextService", configuration_);
ssl_context_service_->onEnable();
controller_service_provider_ = std::make_unique<TestControllerServiceProvider>(ssl_context_service_);
controller_socket_data_.host = "localhost";
Expand Down Expand Up @@ -478,7 +479,7 @@ TEST_CASE_METHOD(ControllerTestFixture, "Test manifest getter", "[controllerTest
}

auto reporter = std::make_shared<minifi::c2::ControllerSocketMetricsPublisher>("ControllerSocketMetricsPublisher");
auto response_node_loader = std::make_shared<minifi::state::response::ResponseNodeLoader>(configuration_, std::vector<std::shared_ptr<core::RepositoryMetricsSource>>{}, nullptr);
auto response_node_loader = std::make_shared<minifi::state::response::ResponseNodeLoaderImpl>(configuration_, std::vector<std::shared_ptr<core::RepositoryMetricsSource>>{}, nullptr);
reporter->initialize(configuration_, response_node_loader);
initalizeControllerSocket(reporter);

Expand All @@ -501,7 +502,7 @@ TEST_CASE_METHOD(ControllerTestFixture, "Test jstack getter", "[controllerTests]
}

auto reporter = std::make_shared<minifi::c2::ControllerSocketMetricsPublisher>("ControllerSocketMetricsPublisher");
auto response_node_loader = std::make_shared<minifi::state::response::ResponseNodeLoader>(configuration_, std::vector<std::shared_ptr<core::RepositoryMetricsSource>>{}, nullptr);
auto response_node_loader = std::make_shared<minifi::state::response::ResponseNodeLoaderImpl>(configuration_, std::vector<std::shared_ptr<core::RepositoryMetricsSource>>{}, nullptr);
reporter->initialize(configuration_, response_node_loader);
initalizeControllerSocket(reporter);

Expand Down Expand Up @@ -529,7 +530,7 @@ TEST_CASE_METHOD(ControllerTestFixture, "Test debug bundle getter", "[controller
}

auto reporter = std::make_shared<minifi::c2::ControllerSocketMetricsPublisher>("ControllerSocketMetricsPublisher");
auto response_node_loader = std::make_shared<minifi::state::response::ResponseNodeLoader>(configuration_, std::vector<std::shared_ptr<core::RepositoryMetricsSource>>{}, nullptr);
auto response_node_loader = std::make_shared<minifi::state::response::ResponseNodeLoaderImpl>(configuration_, std::vector<std::shared_ptr<core::RepositoryMetricsSource>>{}, nullptr);
reporter->initialize(configuration_, response_node_loader);
initalizeControllerSocket(reporter);

Expand All @@ -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<minifi::c2::ControllerSocketMetricsPublisher>("ControllerSocketMetricsPublisher");
auto response_node_loader = std::make_shared<minifi::state::response::ResponseNodeLoader>(configuration_, std::vector<std::shared_ptr<core::RepositoryMetricsSource>>{}, nullptr);
auto response_node_loader = std::make_shared<minifi::state::response::ResponseNodeLoaderImpl>(configuration_, std::vector<std::shared_ptr<core::RepositoryMetricsSource>>{}, nullptr);
reporter->initialize(configuration_, response_node_loader);
initalizeControllerSocket(reporter);

Expand All @@ -557,7 +558,7 @@ TEST_CASE_METHOD(ControllerTestFixture, "Debug bundle retrieval fails if target
setConnectionType(ControllerTestFixture::ConnectionType::UNSECURE);

auto reporter = std::make_shared<minifi::c2::ControllerSocketMetricsPublisher>("ControllerSocketMetricsPublisher");
auto response_node_loader = std::make_shared<minifi::state::response::ResponseNodeLoader>(configuration_, std::vector<std::shared_ptr<core::RepositoryMetricsSource>>{}, nullptr);
auto response_node_loader = std::make_shared<minifi::state::response::ResponseNodeLoaderImpl>(configuration_, std::vector<std::shared_ptr<core::RepositoryMetricsSource>>{}, nullptr);
reporter->initialize(configuration_, response_node_loader);
initalizeControllerSocket(reporter);

Expand Down
2 changes: 1 addition & 1 deletion encrypt-config/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
4 changes: 2 additions & 2 deletions encrypt-config/FlowConfigEncryptor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Configure>();
const auto configure = std::make_shared<ConfigureImpl>();
configure->setHome(minifi_home);
configure->loadConfigureFile(DEFAULT_NIFI_PROPERTIES_FILE);

Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion encrypt-config/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
35 changes: 35 additions & 0 deletions extension-utils/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
21 changes: 21 additions & 0 deletions extension-utils/include/FlowFileRecord.h
Original file line number Diff line number Diff line change
@@ -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"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we replace the #include "FlowFileRecord.h" with #include "minifi-cpp/FlowFileRecord.h" in all files and remove this file?

21 changes: 21 additions & 0 deletions extension-utils/include/ResourceClaim.h
Original file line number Diff line number Diff line change
@@ -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"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we replace the #include "ResourceClaim.h" with #include "minifi-cpp/ResourceClaim.h" where it is used and remove this file?

Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,18 @@
#include <vector>

#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<std::string, std::string>;
virtual std::optional<std::vector<AttributeMap>> getAttributes() = 0;
virtual std::string_view name() const = 0;
};

} // namespace org::apache::nifi::minifi::controllers

30 changes: 30 additions & 0 deletions extension-utils/include/controllers/RecordSetReader.h
Original file line number Diff line number Diff line change
@@ -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
29 changes: 29 additions & 0 deletions extension-utils/include/controllers/RecordSetWriter.h
Original file line number Diff line number Diff line change
@@ -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
19 changes: 19 additions & 0 deletions extension-utils/include/controllers/SSLContextService.h
Original file line number Diff line number Diff line change
@@ -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"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can the #include "controllers/SSLContextService.h" includes be replaced with #include "minifi-cpp/controllers/SSLContextService.h" and this file removed?

Original file line number Diff line number Diff line change
Expand Up @@ -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<KeyValueStateStorage*> storage);

using StateManagerImpl::get;
bool set(const core::StateManager::State& kvs) override;
bool get(core::StateManager::State& kvs) override;
bool clear() override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<core::StateManager> getStateManager(const utils::Identifier& uuid) override;
std::unordered_map<utils::Identifier, core::StateManager::State> getAllStates() override;

Expand Down
Loading
Loading