| 123 | } |
| 124 | |
| 125 | bool FlowController::applyConfiguration(const std::string &source, const std::string &configurePayload) { |
| 126 | std::unique_ptr<core::ProcessGroup> newRoot; |
| 127 | try { |
| 128 | newRoot = flow_configuration_->updateFromPayload(source, configurePayload); |
| 129 | } catch (...) { |
| 130 | logger_->log_error("Invalid configuration payload"); |
| 131 | return false; |
| 132 | } |
| 133 | |
| 134 | if (newRoot == nullptr) |
| 135 | return false; |
| 136 | |
| 137 | if (!isRunning()) |
| 138 | return false; |
| 139 | |
| 140 | logger_->log_info("Starting to reload Flow Controller with flow control name %s, version %d", newRoot->getName(), newRoot->getVersion()); |
| 141 | |
| 142 | updating_ = true; |
| 143 | |
| 144 | std::lock_guard<std::recursive_mutex> flow_lock(mutex_); |
| 145 | stop(); |
| 146 | unload(); |
| 147 | controller_map_->clear(); |
| 148 | auto prevRoot = std::move(this->root_); |
| 149 | this->root_ = std::move(newRoot); |
| 150 | initialized_ = false; |
| 151 | bool started = false; |
| 152 | try { |
| 153 | load(this->root_, true); |
| 154 | flow_update_ = true; |
| 155 | started = start() == 0; |
| 156 | |
| 157 | updating_ = false; |
| 158 | |
| 159 | if (started) { |
| 160 | auto flowVersion = flow_configuration_->getFlowVersion(); |
| 161 | if (flowVersion) { |
| 162 | logger_->log_debug("Setting flow id to %s", flowVersion->getFlowId()); |
| 163 | configuration_->set(Configure::nifi_c2_flow_id, flowVersion->getFlowId()); |
| 164 | configuration_->set(Configure::nifi_c2_flow_url, flowVersion->getFlowIdentifier()->getRegistryUrl()); |
| 165 | } else { |
| 166 | logger_->log_debug("Invalid flow version, not setting"); |
| 167 | } |
| 168 | } |
| 169 | } catch (...) { |
| 170 | this->root_ = std::move(prevRoot); |
| 171 | load(this->root_, true); |
| 172 | flow_update_ = true; |
| 173 | updating_ = false; |
| 174 | } |
| 175 | |
| 176 | return started; |
| 177 | } |
| 178 | |
| 179 | int16_t FlowController::stop() { |
| 180 | std::lock_guard<std::recursive_mutex> flow_lock(mutex_); |
nothing calls this directly
no test coverage detected