MCPcopy Create free account
hub / github.com/apache/nifi-minifi-cpp / initialize

Method initialize

libminifi/src/c2/C2Client.cpp:61–127  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

59}
60
61void C2Client::initialize(core::controller::ControllerServiceProvider *controller, const std::shared_ptr<state::StateMonitor> &update_sink) {
62 if (!isC2Enabled()) {
63 return;
64 }
65
66 if (!configuration_->getAgentClass()) {
67 logger_->log_info("Agent class is not predefined");
68 }
69
70 configuration_->setFallbackAgentIdentifier(getControllerUUID().to_string());
71
72 if (initialized_ && !flow_update_) {
73 return;
74 }
75
76 // root_response_nodes_ was not cleared before, it is unclear if that was intentional
77
78 std::map<std::string, std::shared_ptr<Connection>> connections;
79 if (root_ != nullptr) {
80 root_->getConnections(connections);
81 }
82
83 std::string class_csv;
84 if (configuration_->get("nifi.c2.root.classes", class_csv)) {
85 std::vector<std::string> classes = utils::StringUtils::split(class_csv, ",");
86
87 for (const std::string& clazz : classes) {
88 auto processor = std::dynamic_pointer_cast<state::response::ResponseNode>(core::ClassLoader::getDefaultClassLoader().instantiate(clazz, clazz));
89 if (nullptr == processor) {
90 logger_->log_error("No metric defined for %s", clazz);
91 continue;
92 }
93 auto identifier = std::dynamic_pointer_cast<state::response::AgentIdentifier>(processor);
94 if (identifier != nullptr) {
95 identifier->setAgentIdentificationProvider(configuration_);
96 }
97 auto monitor = std::dynamic_pointer_cast<state::response::AgentMonitor>(processor);
98 if (monitor != nullptr) {
99 monitor->addRepository(provenance_repo_);
100 monitor->addRepository(flow_file_repo_);
101 monitor->setStateMonitor(update_sink);
102 }
103 auto flowMonitor = std::dynamic_pointer_cast<state::response::FlowMonitor>(processor);
104 if (flowMonitor != nullptr) {
105 for (auto &con : connections) {
106 flowMonitor->addConnection(con.second);
107 }
108 flowMonitor->setStateMonitor(update_sink);
109 flowMonitor->setFlowVersion(flow_configuration_->getFlowVersion());
110 }
111 std::lock_guard<std::mutex> guard(metrics_mutex_);
112 root_response_nodes_[processor->getName()] = processor;
113 }
114 }
115
116 initializeComponentMetrics();
117
118 loadC2ResponseConfiguration("nifi.c2.root.class.definitions");

Callers 1

configureMethod · 0.45

Calls 15

getAgentClassMethod · 0.80
log_infoMethod · 0.80
getConnectionsMethod · 0.80
instantiateMethod · 0.80
log_errorMethod · 0.80
getFlowVersionMethod · 0.80
to_stringMethod · 0.45
getMethod · 0.45
addRepositoryMethod · 0.45
setStateMonitorMethod · 0.45

Tested by

no test coverage detected