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

Method loadC2ResponseConfiguration

libminifi/src/c2/C2Client.cpp:162–216  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

160}
161
162void C2Client::loadC2ResponseConfiguration(const std::string &prefix) {
163 std::string class_definitions;
164 if (!configuration_->get(prefix, class_definitions)) {
165 return;
166 }
167
168 std::vector<std::string> classes = utils::StringUtils::split(class_definitions, ",");
169
170 for (const std::string& metricsClass : classes) {
171 try {
172 std::string option = prefix + "." + metricsClass;
173 std::string classOption = option + ".classes";
174 std::string nameOption = option + ".name";
175
176 std::string name;
177 if (!configuration_->get(nameOption, name)) {
178 continue;
179 }
180 std::shared_ptr<state::response::ResponseNode> new_node = std::make_shared<state::response::ObjectNode>(name);
181 if (configuration_->get(classOption, class_definitions)) {
182 std::vector<std::string> classes = utils::StringUtils::split(class_definitions, ",");
183 for (const std::string& clazz : classes) {
184 // instantiate the object
185 auto ptr = core::ClassLoader::getDefaultClassLoader().instantiate(clazz, clazz);
186 if (nullptr == ptr) {
187 const bool found_metric = [&] {
188 std::lock_guard<std::mutex> guard{metrics_mutex_};
189 auto metric = component_metrics_.find(clazz);
190 if (metric != component_metrics_.end()) {
191 ptr = metric->second;
192 return true;
193 }
194 return false;
195 }();
196 if (!found_metric) {
197 logger_->log_error("No metric defined for %s", clazz);
198 continue;
199 }
200 }
201 auto node = std::dynamic_pointer_cast<state::response::ResponseNode>(ptr);
202 std::static_pointer_cast<state::response::ObjectNode>(new_node)->add_node(node);
203 }
204
205 } else {
206 std::string optionName = option + "." + name;
207 auto node = loadC2ResponseConfiguration(optionName, new_node);
208 }
209
210 std::lock_guard<std::mutex> guard{metrics_mutex_};
211 root_response_nodes_[name] = new_node;
212 } catch (...) {
213 logger_->log_error("Could not create metrics class %s", metricsClass);
214 }
215 }
216}
217
218std::shared_ptr<state::response::ResponseNode> C2Client::loadC2ResponseConfiguration(const std::string &prefix, std::shared_ptr<state::response::ResponseNode> prev_node) {
219 std::string class_definitions;

Callers

nothing calls this directly

Calls 7

instantiateMethod · 0.80
log_errorMethod · 0.80
getMethod · 0.45
findMethod · 0.45
endMethod · 0.45
add_nodeMethod · 0.45
isEmptyMethod · 0.45

Tested by

no test coverage detected