Skip to content

Commit becaaa9

Browse files
committed
MINIFICPP-2710 Refactor ControllerServiceNodeMap
Closes #2098 Signed-off-by: Martin Zink <martinzink@apache.org>
1 parent abea7c3 commit becaaa9

16 files changed

+172
-145
lines changed

extensions/azure/tests/ListAzureBlobStorageTests.cpp

Lines changed: 61 additions & 68 deletions
Large diffs are not rendered by default.

extensions/standard-processors/tests/unit/ControllerServiceTests.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,13 @@ TEST_CASE("Test ControllerServicesMap", "[cs1]") {
4141
auto service = std::make_shared<core::controller::ControllerService>("", utils::Identifier{}, std::make_unique<MockControllerService>());
4242
auto testNode = std::make_shared<core::controller::StandardControllerServiceNode>(service, "ID", std::make_shared<minifi::ConfigureImpl>());
4343

44-
map.put("ID", testNode);
44+
map.put("ID", testNode, nullptr);
4545
REQUIRE(1 == map.getAllControllerServices().size());
4646

4747
REQUIRE(nullptr != map.get("ID"));
4848

49-
REQUIRE(false== map.put("", testNode));
50-
REQUIRE(false== map.put("", nullptr));
49+
REQUIRE(false== map.put("", testNode, nullptr));
50+
REQUIRE(false== map.put("", nullptr, nullptr));
5151

5252
// ensure the pointer is the same
5353

libminifi/include/core/FlowConfiguration.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ class FlowConfiguration : public CoreComponentImpl {
9090
static std::unique_ptr<core::ProcessGroup> createSimpleProcessGroup(const std::string &name, const utils::Identifier &uuid, int version);
9191
static std::unique_ptr<core::ProcessGroup> createRemoteProcessGroup(const std::string &name, const utils::Identifier &uuid);
9292

93-
std::shared_ptr<core::controller::ControllerServiceNode> createControllerService(const std::string &class_name, const std::string &name, const utils::Identifier &uuid);
93+
std::shared_ptr<core::controller::ControllerServiceNode> createControllerService(const std::string &class_name, const std::string &name, const utils::Identifier &uuid, ProcessGroup* parent);
9494

9595
// Create Connection
9696
[[nodiscard]] std::unique_ptr<minifi::Connection> createConnection(const std::string &name, const utils::Identifier &uuid) const;

libminifi/include/core/ProcessContextImpl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ class ProcessContextImpl : public core::VariableRegistryImpl, public virtual Pro
134134

135135
/* Function to help creating a state storage */
136136
auto create_provider = [&](const std::string& type, const std::unordered_map<std::string, std::string>& extraProperties) -> std::shared_ptr<core::StateStorage> {
137-
auto new_node = controller_service_provider->createControllerService(type, DefaultStateStorageName);
137+
auto new_node = controller_service_provider->createControllerService(type, DefaultStateStorageName, nullptr, std::nullopt);
138138
if (new_node == nullptr) { return nullptr; }
139139
new_node->initialize();
140140
auto storage = new_node->getControllerServiceImplementation();

libminifi/include/core/controller/ControllerServiceNodeMap.h

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,25 @@ class ControllerServiceNodeMap {
4343
ControllerServiceNode* get(const std::string &id) const;
4444
ControllerServiceNode* get(const std::string &id, const utils::Identifier &processor_or_controller_uuid) const;
4545

46-
bool put(const std::string &id, const std::shared_ptr<ControllerServiceNode> &serviceNode);
47-
bool put(const std::string &id, ProcessGroup* process_group);
46+
bool put(std::string id, std::shared_ptr<ControllerServiceNode> controller_service_node, ProcessGroup* parent_group);
47+
48+
bool registerAlternativeKey(std::string primary_key, std::string alternative_key);
4849

4950
void clear();
5051
std::vector<std::shared_ptr<ControllerServiceNode>> getAllControllerServices() const;
5152

5253
protected:
5354
mutable std::mutex mutex_;
54-
// Map of controller service id to the controller service node
55-
std::map<std::string, std::shared_ptr<ControllerServiceNode>> controller_service_nodes_;
56-
// Map of controller service id to the process group that contains it
57-
std::map<std::string, gsl::not_null<ProcessGroup*>> process_groups_;
55+
56+
struct ServiceEntry {
57+
std::shared_ptr<ControllerServiceNode> controller_service_node;
58+
ProcessGroup* parent_group;
59+
};
60+
61+
const ServiceEntry* getEntry(std::string_view primary_key, const std::scoped_lock<std::mutex>& mutex) const;
62+
63+
std::map<std::string, ServiceEntry, std::less<>> services_;
64+
std::map<std::string, std::string, std::less<>> alternative_keys;
5865
};
5966

6067
} // namespace controller

libminifi/include/core/controller/ControllerServiceProvider.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,10 @@ class ControllerServiceProvider : public CoreComponentImpl, public ConfigurableC
6868
return controller_map_->get(id, processor_or_controller_uuid);
6969
}
7070

71-
virtual std::shared_ptr<ControllerServiceNode> createControllerService(const std::string &type, const std::string &id) = 0;
71+
virtual std::shared_ptr<ControllerServiceNode> createControllerService(const std::string &type,
72+
const std::string &id,
73+
ProcessGroup* parent,
74+
const std::optional<std::string>& alternative_key) = 0;
7275

7376
virtual void clearControllerServices() = 0;
7477

@@ -83,7 +86,10 @@ class ControllerServiceProvider : public CoreComponentImpl, public ConfigurableC
8386
std::shared_ptr<ControllerService> getControllerService(const std::string &identifier) const override;
8487
std::shared_ptr<ControllerService> getControllerService(const std::string &identifier, const utils::Identifier &processor_uuid) const override;
8588

86-
virtual void putControllerServiceNode(const std::string& identifier, const std::shared_ptr<ControllerServiceNode>& controller_service_node, ProcessGroup* process_group);
89+
virtual void putControllerServiceNode(const std::string& primary_key,
90+
const std::shared_ptr<ControllerServiceNode>& controller_service_node,
91+
ProcessGroup* process_group,
92+
const std::optional<std::string>& alternative_key);
8793

8894
bool supportsDynamicProperties() const final {
8995
return false;

libminifi/include/core/controller/ForwardingControllerServiceProvider.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ class ForwardingControllerServiceProvider : public ControllerServiceProvider {
3131
public:
3232
using ControllerServiceProvider::ControllerServiceProvider;
3333

34-
std::shared_ptr<ControllerServiceNode> createControllerService(const std::string &type, const std::string &id) override {
35-
return controller_service_provider_impl_->createControllerService(type, id);
34+
std::shared_ptr<ControllerServiceNode> createControllerService(const std::string &type, const std::string &id, ProcessGroup* parent, const std::optional<std::string>& alternative_key) override {
35+
return controller_service_provider_impl_->createControllerService(type, id, parent, alternative_key);
3636
}
3737

3838
ControllerServiceNode* getControllerServiceNode(const std::string &id) const override {

libminifi/include/core/controller/StandardControllerServiceProvider.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,10 @@ class StandardControllerServiceProvider : public ControllerServiceProvider {
4848
stopEnableRetryThread();
4949
}
5050

51-
std::shared_ptr<ControllerServiceNode> createControllerService(const std::string& type, const std::string& id) override;
51+
std::shared_ptr<ControllerServiceNode> createControllerService(const std::string& type,
52+
const std::string& id,
53+
ProcessGroup* parent_group,
54+
const std::optional<std::string>& alternative_key) override;
5255
void enableAllControllerServices() override;
5356
void disableAllControllerServices() override;
5457
void clearControllerServices() override;

libminifi/src/core/FlowConfiguration.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,8 @@ std::unique_ptr<minifi::Connection> FlowConfiguration::createConnection(const st
195195
}
196196

197197
std::shared_ptr<core::controller::ControllerServiceNode> FlowConfiguration::createControllerService(const std::string &class_name, const std::string &name,
198-
const utils::Identifier& uuid) {
199-
std::shared_ptr<core::controller::ControllerServiceNode> controllerServicesNode = service_provider_->createControllerService(class_name, name);
198+
const utils::Identifier& uuid, ProcessGroup* parent) {
199+
std::shared_ptr<core::controller::ControllerServiceNode> controllerServicesNode = service_provider_->createControllerService(class_name, name, parent, uuid.to_string());
200200
if (nullptr != controllerServicesNode)
201201
controllerServicesNode->setUUID(uuid);
202202
return controllerServicesNode;

libminifi/src/core/ProcessGroup.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ Processor* ProcessGroup::findProcessorByName(const std::string &processorName, T
279279
}
280280

281281
void ProcessGroup::addControllerService(const std::string &nodeId, const std::shared_ptr<core::controller::ControllerServiceNode> &node) {
282-
controller_service_map_.put(nodeId, node);
282+
controller_service_map_.put(nodeId, node, this);
283283
}
284284

285285
core::controller::ControllerServiceNode* ProcessGroup::findControllerService(const std::string &nodeId, Traverse traverse) const {

0 commit comments

Comments
 (0)