Skip to content

Commit

Permalink
MINIFICPP-2434 - Check type of acquired controller service
Browse files Browse the repository at this point in the history
Closes #1848

Signed-off-by: Marton Szasz <[email protected]>
  • Loading branch information
adamdebreceni authored and szaszm committed Aug 13, 2024
1 parent 2d3a41b commit 0d9d126
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
2 changes: 1 addition & 1 deletion libminifi/include/core/json/JsonNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class JsonNode : public flow::Node::NodeImpl {
return std::to_string(node_->GetDouble());
}
if (node_->IsBool()) {
return std::to_string(node_->GetDouble());
return node_->GetBool() ? "true" : "false";
}

return getString();
Expand Down
8 changes: 7 additions & 1 deletion libminifi/src/c2/C2Agent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,13 @@ void C2Agent::initialize(core::controller::ControllerServiceProvider *controller
update_sink_ = update_sink;

if (nullptr != controller_) {
update_service_ = std::static_pointer_cast<controllers::UpdatePolicyControllerService>(controller_->getControllerService(UPDATE_NAME));
if (auto service = controller_->getControllerService(UPDATE_NAME)) {
if (auto update_service = std::dynamic_pointer_cast<controllers::UpdatePolicyControllerService>(service)) {
update_service_ = update_service;
} else {
logger_->log_warn("Found controller service with name '{}', but it is not an UpdatePolicyControllerService", c2::UPDATE_NAME);
}
}
}

if (update_service_ == nullptr) {
Expand Down
16 changes: 14 additions & 2 deletions libminifi/src/core/state/nodes/ResponseNodeLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,13 @@ void ResponseNodeLoader::initializeAgentMonitor(const SharedResponseNode& respon
void ResponseNodeLoader::initializeAgentNode(const SharedResponseNode& response_node) const {
auto agent_node = dynamic_cast<state::response::AgentNode*>(response_node.get());
if (agent_node != nullptr && controller_ != nullptr) {
agent_node->setUpdatePolicyController(std::static_pointer_cast<controllers::UpdatePolicyControllerService>(controller_->getControllerService(c2::UPDATE_NAME)).get());
if (auto service = controller_->getControllerService(c2::UPDATE_NAME)) {
if (auto update_service = std::dynamic_pointer_cast<controllers::UpdatePolicyControllerService>(service)) {
agent_node->setUpdatePolicyController(update_service.get());
} else {
logger_->log_warn("Found controller service with name '{}', but it is not an UpdatePolicyControllerService", c2::UPDATE_NAME);
}
}
}
if (agent_node != nullptr) {
agent_node->setConfigurationReader([this](const std::string& key){
Expand Down Expand Up @@ -285,7 +291,13 @@ void ResponseNodeLoader::setStateMonitor(state::StateMonitor* update_sink) {
state::response::NodeReporter::ReportedNode ResponseNodeLoader::getAgentManifest() const {
state::response::AgentInformation agentInfo("agentInfo");
if (controller_) {
agentInfo.setUpdatePolicyController(std::static_pointer_cast<controllers::UpdatePolicyControllerService>(controller_->getControllerService(c2::UPDATE_NAME)).get());
if (auto service = controller_->getControllerService(c2::UPDATE_NAME)) {
if (auto update_service = std::dynamic_pointer_cast<controllers::UpdatePolicyControllerService>(service)) {
agentInfo.setUpdatePolicyController(update_service.get());
} else {
logger_->log_warn("Found controller service with name '{}', but it is not an UpdatePolicyControllerService", c2::UPDATE_NAME);
}
}
}
agentInfo.setAgentIdentificationProvider(configuration_);
agentInfo.setConfigurationReader([this](const std::string& key){
Expand Down

0 comments on commit 0d9d126

Please sign in to comment.