This is an automated email from the ASF dual-hosted git repository.
szaszm pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/nifi-minifi-cpp.git
The following commit(s) were added to refs/heads/main by this push:
new c1c8293 MINIFICPP-1344 - Correct rest endpoint for buckets on
updateFromPayload and simplify its logic
c1c8293 is described below
commit c1c8293cc0e7d11da75cbb12bed19f524f54c0c7
Author: Adam Hunyadi <[email protected]>
AuthorDate: Wed Dec 9 15:29:42 2020 +0100
MINIFICPP-1344 - Correct rest endpoint for buckets on updateFromPayload and
simplify its logic
Signed-off-by: Marton Szasz <[email protected]>
This closes #885
---
libminifi/include/core/FlowConfiguration.h | 2 +-
libminifi/src/core/FlowConfiguration.cpp | 32 ++++++++++--------------------
2 files changed, 12 insertions(+), 22 deletions(-)
diff --git a/libminifi/include/core/FlowConfiguration.h
b/libminifi/include/core/FlowConfiguration.h
index 685cb67..6fff3c5 100644
--- a/libminifi/include/core/FlowConfiguration.h
+++ b/libminifi/include/core/FlowConfiguration.h
@@ -139,7 +139,7 @@ class FlowConfiguration : public CoreComponent {
return nullptr;
}
- std::unique_ptr<core::ProcessGroup> updateFromPayload(const std::string
&source, const std::string &yamlConfigPayload);
+ std::unique_ptr<core::ProcessGroup> updateFromPayload(const std::string&
url, const std::string& yamlConfigPayload);
virtual std::unique_ptr<core::ProcessGroup> getRootFromPayload(const
std::string &yamlConfigPayload) {
return nullptr;
diff --git a/libminifi/src/core/FlowConfiguration.cpp
b/libminifi/src/core/FlowConfiguration.cpp
index 4c92e4c..b007b52 100644
--- a/libminifi/src/core/FlowConfiguration.cpp
+++ b/libminifi/src/core/FlowConfiguration.cpp
@@ -67,33 +67,23 @@ std::shared_ptr<core::Processor>
FlowConfiguration::createProvenanceReportTask()
return processor;
}
-std::unique_ptr<core::ProcessGroup> FlowConfiguration::updateFromPayload(const
std::string &source, const std::string &yamlConfigPayload) {
+std::unique_ptr<core::ProcessGroup> FlowConfiguration::updateFromPayload(const
std::string& url, const std::string& yamlConfigPayload) {
auto old_services = controller_services_;
auto old_provider = service_provider_;
controller_services_ =
std::make_shared<core::controller::ControllerServiceMap>();
service_provider_ =
std::make_shared<core::controller::StandardControllerServiceProvider>(controller_services_,
nullptr, configuration_);
auto payload = getRootFromPayload(yamlConfigPayload);
- if (!source.empty() && payload != nullptr) {
- std::string host, protocol, path, query, url = source;
- int port = -1;
- utils::parse_url(&url, &host, &port, &protocol, &path, &query);
-
+ if (!url.empty() && payload != nullptr) {
std::string flow_id, bucket_id;
- auto path_split = utils::StringUtils::split(path, "/");
- for (size_t i = 0; i < path_split.size(); i++) {
- const std::string &str = path_split.at(i);
- if (str == "flows") {
- if (i + 1 < path_split.size()) {
- flow_id = path_split.at(i + 1);
- i++;
- }
- }
-
- if (str == "bucket") {
- if (i + 1 < path_split.size()) {
- bucket_id = path_split.at(i + 1);
- i++;
- }
+ auto path_split = utils::StringUtils::split(url, "/");
+ // Registry API docs:
nifi.apache.org/docs/nifi-registry-docs/rest-api/index.html
+ // GET /buckets/{bucketId}/flows/{flowId}: Gets a flow
+ const auto bucket_token_found = std::find(path_split.cbegin(),
path_split.cend(), "buckets");
+ if (bucket_token_found != path_split.cend() &&
std::next(bucket_token_found) != path_split.cend()) {
+ bucket_id = *std::next(bucket_token_found);
+ const auto flows_token_found = std::find(std::next(bucket_token_found,
2), path_split.cend(), "flows");
+ if (flows_token_found != path_split.cend() &&
std::next(flows_token_found) != path_split.cend()) {
+ flow_id = *std::next(flows_token_found);
}
}
flow_version_->setFlowVersion(url, bucket_id, flow_id);