You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@nifi.apache.org by "martinzink (via GitHub)" <gi...@apache.org> on 2026/04/01 15:00:08 UTC

[PR] MINIFICPP-2764 Controller Service CPP API [nifi-minifi-cpp]

martinzink opened a new pull request, #2152:
URL: https://github.com/apache/nifi-minifi-cpp/pull/2152

   Thank you for submitting a contribution to Apache NiFi - MiNiFi C++.
   
   In order to streamline the review of the contribution we ask you
   to ensure the following steps have been taken:
   
   ### For all changes:
   - [ ] Is there a JIRA ticket associated with this PR? Is it referenced
        in the commit message?
   
   - [ ] Does your PR title start with MINIFICPP-XXXX where XXXX is the JIRA number you are trying to resolve? Pay particular attention to the hyphen "-" character.
   
   - [ ] Has your PR been rebased against the latest commit within the target branch (typically main)?
   
   - [ ] Is your initial contribution a single, squashed commit?
   
   ### For code changes:
   - [ ] If adding new dependencies to the code, are these dependencies licensed in a way that is compatible for inclusion under [ASF 2.0](http://www.apache.org/legal/resolved.html#category-a)?
   - [ ] If applicable, have you updated the LICENSE file?
   - [ ] If applicable, have you updated the NOTICE file?
   
   ### For documentation related changes:
   - [ ] Have you ensured that format looks appropriate for the output in which it is rendered?
   
   ### Note:
   Please ensure that once the PR is submitted, you check GitHub Actions CI results for build issues and submit an update to your PR as soon as possible.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] MINIFICPP-2764 Controller Service CPP API [nifi-minifi-cpp]

Posted by "martinzink (via GitHub)" <gi...@apache.org>.
martinzink commented on code in PR #2152:
URL: https://github.com/apache/nifi-minifi-cpp/pull/2152#discussion_r3159360987


##########
extension-framework/cpp-extension-lib/include/api/utils/ProcessorConfigUtils.h:
##########
@@ -167,4 +167,28 @@ std::optional<T> parseOptionalEnumProperty(const core::ProcessContext& context,
   return result.value();
 }
 
+template<typename ControllerServiceType>
+ControllerServiceType* parseOptionalControllerService(const core::ProcessContext& context, const minifi::core::PropertyReference& prop) {
+  const auto controller_service_name = context.getProperty(prop.name);
+  if (!controller_service_name || controller_service_name->empty()) {
+    return nullptr;
+  }
+
+  nonstd::expected<MinifiControllerService*, std::error_code> service = context.getControllerService(*controller_service_name, minifi::core::className<ControllerServiceType>());

Review Comment:
   👍 [rebase fix](https://github.com/apache/nifi-minifi-cpp/pull/2152/commits/991fa3e0ba38410828ca33d3de6ead23c91e39d4)



##########
extension-framework/cpp-extension-lib/src/core/ProcessContext.cpp:
##########
@@ -38,4 +38,17 @@ bool ProcessContext::hasNonEmptyProperty(std::string_view name) const {
   return MinifiProcessContextHasNonEmptyProperty(impl_, utils::toStringView(name));
 }
 
+nonstd::expected<MinifiControllerService*, std::error_code> ProcessContext::getControllerService(const std::string_view controller_service_name,
+    const std::string_view controller_service_class) const {
+  void* controller_service = nullptr;

Review Comment:
   👍 [rebase fix](https://github.com/apache/nifi-minifi-cpp/pull/2152/commits/991fa3e0ba38410828ca33d3de6ead23c91e39d4)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] MINIFICPP-2764 Controller Service CPP API [nifi-minifi-cpp]

Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #2152:
URL: https://github.com/apache/nifi-minifi-cpp/pull/2152#discussion_r3022747423


##########
extension-framework/cpp-extension-lib/src/core/ControllerServiceImpl.cpp:
##########
@@ -0,0 +1,72 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include "api/core/ControllerServiceImpl.h"
+
+#include <cctype>
+
+#include <memory>
+#include <set>
+#include <string>
+#include <vector>
+
+#include "fmt/format.h"
+
+using namespace std::literals::chrono_literals;
+
+namespace org::apache::nifi::minifi::api::core {
+
+ControllerServiceImpl::ControllerServiceImpl(minifi::core::ControllerServiceMetadata metadata)
+    : metadata_(std::move(metadata)),
+      logger_(metadata_.logger) {
+  logger_->log_debug("Processor {} created with uuid {}", getName(), getUUIDStr());
+}
+
+ControllerServiceImpl::~ControllerServiceImpl() {
+  logger_->log_debug("Destroying processor {} with uuid {}", getName(), getUUIDStr());

Review Comment:
   These log messages refer to a \"Processor\" even though this class is `ControllerServiceImpl`. This is misleading during debugging/ops; please update the messages to reference \"ControllerService\" (or \"controller service\") consistently.
   ```suggestion
     logger_->log_debug("ControllerService {} created with uuid {}", getName(), getUUIDStr());
   }
   
   ControllerServiceImpl::~ControllerServiceImpl() {
     logger_->log_debug("Destroying ControllerService {} with uuid {}", getName(), getUUIDStr());
   ```



##########
extension-framework/cpp-extension-lib/src/core/ControllerServiceImpl.cpp:
##########
@@ -0,0 +1,72 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include "api/core/ControllerServiceImpl.h"
+
+#include <cctype>
+
+#include <memory>
+#include <set>
+#include <string>
+#include <vector>
+
+#include "fmt/format.h"
+
+using namespace std::literals::chrono_literals;
+

Review Comment:
   In this new file, these headers and the chrono literals namespace are unused (the file only uses `memory`, `string`, and logging). Removing unused includes and `using namespace std::literals::chrono_literals;` will reduce compile time and avoid misleading dependencies.
   ```suggestion
   #include <memory>
   #include <string>
   
   #include "fmt/format.h"
   ```



##########
extension-framework/cpp-extension-lib/include/api/core/ControllerServiceImpl.h:
##########
@@ -0,0 +1,66 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#pragma once
+
+#include <condition_variable>
+#include <memory>
+#include <mutex>
+#include <string>
+
+#include "ControllerServiceContext.h"
+#include "minifi-cpp/core/ControllerServiceMetadata.h"
+#include "minifi-cpp/utils/Id.h"
+#include "utils/SmallString.h"
+
+namespace org::apache::nifi::minifi::api {
+
+class Connection;

Review Comment:
   `<condition_variable>`, the `Connection` forward declaration, and the `mutex_` member are unused in the current implementation (and there are no synchronized accesses shown). If thread-safety is not part of this class’ responsibility, remove these to keep the API minimal; otherwise, add the corresponding synchronized logic so the extra members/includes are justified.



##########
libminifi/include/utils/CControllerService.h:
##########
@@ -104,7 +108,6 @@ class CControllerService final : public core::controller::ControllerServiceApi,
 };
 
 void useCControllerServiceClassDescription(const MinifiControllerServiceClassDefinition& class_description,
-    const BundleIdentifier& bundle_id,
     const std::function<void(ClassDescription, CControllerServiceClassDescription)>& fn);

Review Comment:
   The callback takes `ClassDescription` by value while `ClassDescription` is only forward-declared in this header. Passing an incomplete type by value is a brittle API (and forces the full definition to be available at call sites). Prefer taking `const ClassDescription&` (or a pointer) to avoid copies and reduce header coupling.
   ```suggestion
       const std::function<void(const ClassDescription&, CControllerServiceClassDescription)>& fn);
   ```



##########
extension-framework/cpp-extension-lib/include/api/core/ControllerServiceImpl.h:
##########
@@ -0,0 +1,66 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#pragma once
+
+#include <condition_variable>

Review Comment:
   `<condition_variable>`, the `Connection` forward declaration, and the `mutex_` member are unused in the current implementation (and there are no synchronized accesses shown). If thread-safety is not part of this class’ responsibility, remove these to keep the API minimal; otherwise, add the corresponding synchronized logic so the extra members/includes are justified.



##########
extension-framework/cpp-extension-lib/src/core/ControllerServiceImpl.cpp:
##########
@@ -0,0 +1,72 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include "api/core/ControllerServiceImpl.h"
+
+#include <cctype>
+
+#include <memory>
+#include <set>
+#include <string>
+#include <vector>
+
+#include "fmt/format.h"
+
+using namespace std::literals::chrono_literals;
+

Review Comment:
   In this new file, these headers and the chrono literals namespace are unused (the file only uses `memory`, `string`, and logging). Removing unused includes and `using namespace std::literals::chrono_literals;` will reduce compile time and avoid misleading dependencies.
   ```suggestion
   #include <memory>
   #include <string>
   ```



##########
extension-framework/cpp-extension-lib/src/core/ControllerServiceImpl.cpp:
##########
@@ -0,0 +1,72 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include "api/core/ControllerServiceImpl.h"
+
+#include <cctype>
+
+#include <memory>
+#include <set>
+#include <string>
+#include <vector>
+
+#include "fmt/format.h"
+
+using namespace std::literals::chrono_literals;
+
+namespace org::apache::nifi::minifi::api::core {
+
+ControllerServiceImpl::ControllerServiceImpl(minifi::core::ControllerServiceMetadata metadata)
+    : metadata_(std::move(metadata)),
+      logger_(metadata_.logger) {
+  logger_->log_debug("Processor {} created with uuid {}", getName(), getUUIDStr());
+}
+
+ControllerServiceImpl::~ControllerServiceImpl() {
+  logger_->log_debug("Destroying processor {} with uuid {}", getName(), getUUIDStr());

Review Comment:
   These log messages refer to a \"Processor\" even though this class is `ControllerServiceImpl`. This is misleading during debugging/ops; please update the messages to reference \"ControllerService\" (or \"controller service\") consistently.
   ```suggestion
     logger_->log_debug("ControllerService {} created with uuid {}", getName(), getUUIDStr());
   }
   
   ControllerServiceImpl::~ControllerServiceImpl() {
     logger_->log_debug("Destroying controller service {} with uuid {}", getName(), getUUIDStr());
   ```



##########
extension-framework/cpp-extension-lib/include/api/utils/ProcessorConfigUtils.h:
##########
@@ -167,4 +167,28 @@ std::optional<T> parseOptionalEnumProperty(const core::ProcessContext& context,
   return result.value();
 }
 
+template<typename ControllerServiceType>
+ControllerServiceType* parseOptionalControllerService(const core::ProcessContext& context, const minifi::core::PropertyReference& prop) {
+  const auto controller_service_name = context.getProperty(prop.name);
+  if (!controller_service_name || controller_service_name->empty()) {
+    return nullptr;
+  }
+
+  nonstd::expected<MinifiControllerService*, std::error_code> service = context.getControllerService(*controller_service_name, minifi::core::className<ControllerServiceType>());
+  if (!service) {
+    return nullptr;
+  }
+
+  return reinterpret_cast<ControllerServiceType*>(*service);
+}

Review Comment:
   `MinifiControllerService*` is an opaque C handle type. Reinterpreting it as `ControllerServiceType*` is not type-safe and is very likely incorrect at runtime/ABI level (handle vs. implementation object). A safer design is to return the opaque handle (or a small C++ wrapper around it) and expose typed operations through explicit API functions, rather than casting the handle to the implementation type.



##########
extension-framework/cpp-extension-lib/src/core/ControllerServiceContext.cpp:
##########
@@ -0,0 +1,36 @@
+/**
+* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "api/core/ControllerServiceContext.h"
+#include "api/utils/minifi-c-utils.h"
+
+namespace org::apache::nifi::minifi::api::core {
+
+nonstd::expected<std::string, std::error_code> ControllerServiceContext::getProperty(const std::string_view name) const {
+  std::optional<std::string> value;
+  const MinifiStatus status = MinifiControllerServiceContextGetProperty(impl_, utils::toStringView(name),
+    [] (void* data, const MinifiStringView result) {
+      (*static_cast<std::optional<std::string>*>(data)) = std::string(result.data, result.length);
+    }, &value);
+
+  if (!value) {
+    return nonstd::make_unexpected(utils::make_error_code(status));
+  }
+  return value.value();
+}

Review Comment:
   This returns success whenever the callback sets `value`, even if `status` indicates an error. The C API already returns a `MinifiStatus`, so the wrapper should primarily check `status != MINIFI_STATUS_SUCCESS` (and only use `value` as the payload). Otherwise, any implementation that invokes the callback before returning a failure status could be incorrectly reported as success.



##########
extension-framework/cpp-extension-lib/include/api/core/ControllerServiceImpl.h:
##########
@@ -0,0 +1,66 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#pragma once
+
+#include <condition_variable>
+#include <memory>
+#include <mutex>
+#include <string>
+
+#include "ControllerServiceContext.h"
+#include "minifi-cpp/core/ControllerServiceMetadata.h"
+#include "minifi-cpp/utils/Id.h"
+#include "utils/SmallString.h"
+
+namespace org::apache::nifi::minifi::api {
+
+class Connection;
+
+namespace core {
+
+class ControllerServiceImpl {
+ public:
+  explicit ControllerServiceImpl(minifi::core::ControllerServiceMetadata metadata);
+
+  ControllerServiceImpl(const ControllerServiceImpl&) = delete;
+  ControllerServiceImpl(ControllerServiceImpl&&) = delete;
+  ControllerServiceImpl& operator=(const ControllerServiceImpl&) = delete;
+  ControllerServiceImpl& operator=(ControllerServiceImpl&&) = delete;
+
+  virtual ~ControllerServiceImpl();
+
+  MinifiStatus enable(ControllerServiceContext&);
+  void notifyStop();
+
+  std::string getName() const;
+  minifi::utils::Identifier getUUID() const;
+  minifi::utils::SmallString<36> getUUIDStr() const;
+
+ protected:
+  virtual MinifiStatus enableImpl(api::core::ControllerServiceContext&) = 0;
+  virtual void notifyStopImpl() {}
+
+  minifi::core::ControllerServiceMetadata metadata_;
+
+  std::shared_ptr<minifi::core::logging::Logger> logger_;
+
+ private:
+  mutable std::mutex mutex_;

Review Comment:
   `<condition_variable>`, the `Connection` forward declaration, and the `mutex_` member are unused in the current implementation (and there are no synchronized accesses shown). If thread-safety is not part of this class’ responsibility, remove these to keep the API minimal; otherwise, add the corresponding synchronized logic so the extra members/includes are justified.



##########
libminifi/test/libtest/unit/TestBase.cpp:
##########
@@ -115,7 +115,7 @@ bool LogTestController::contains(const std::function<std::string()>& log_string_
   bool timed_out = false;
   do {
     std::string str = log_string_getter();
-    found = (str.find(ending) != std::string::npos);
+    found = (str.contains(ending));

Review Comment:
   `std::string::contains` is a C++23 feature. If this project is built with C++20 (the rest of this hunk uses `std::ranges`, which is C++20), this line will not compile. Consider using `str.find(ending) != std::string::npos` or gating `contains` behind a feature-test / C++ standard check.
   ```suggestion
       found = (str.find(ending) != std::string::npos);
   ```



##########
extension-framework/cpp-extension-lib/src/core/ControllerServiceContext.cpp:
##########
@@ -0,0 +1,36 @@
+/**
+* Licensed to the Apache Software Foundation (ASF) under one or more

Review Comment:
   The license header formatting is inconsistent with other files in this PR: this line is missing the leading space after `*` (compare with other ASF headers). Please align the comment formatting for consistency.
   ```suggestion
    * Licensed to the Apache Software Foundation (ASF) under one or more
   ```



##########
extension-framework/cpp-extension-lib/include/api/core/Resource.h:
##########
@@ -145,4 +147,48 @@ void useProcessorClassDescription(Fn&& fn) {
   fn(description);
 }
 
+template<typename Class, typename Fn>
+void useControllerServiceClassDescription(Fn&& fn) {
+  std::vector<std::vector<MinifiStringView>> string_vector_cache;
+
+  const auto full_name = minifi::core::className<Class>();
+
+  std::vector<MinifiPropertyDefinition> class_properties = utils::toProperties(Class::Properties, string_vector_cache);
+
+  MinifiControllerServiceClassDefinition description{
+    .full_name = utils::toStringView(full_name),
+    .description = utils::toStringView(Class::Description),
+    .class_properties_count = gsl::narrow<uint32_t>(class_properties.size()),
+    .class_properties_ptr = class_properties.data(),
+
+    .callbacks = MinifiControllerServiceCallbacks{
+      .create = [] (MinifiControllerServiceMetadata metadata) -> MINIFI_OWNED void* {
+        return new Class{minifi::core::ControllerServiceMetadata{
+          .uuid = minifi::utils::Identifier::parse(std::string{metadata.uuid.data, metadata.uuid.length}).value(),
+          .name = std::string{metadata.name.data, metadata.name.length},
+          .logger = std::make_shared<logging::Logger>(metadata.logger)
+        }};
+      },
+      .destroy = [] (MINIFI_OWNED void* self) -> void {
+        delete static_cast<Class*>(self);
+      },
+      .enable = [] (void* self, MinifiControllerServiceContext* context) -> MinifiStatus {
+        ControllerServiceContext context_wrapper(context);
+        try {
+          return static_cast<Class*>(self)->enable(context_wrapper);
+        } catch (...) {
+          return MINIFI_STATUS_UNKNOWN_ERROR;
+        }
+      },
+      .notifyStop = [] (void* self) -> void {
+        static_cast<Class*>(self)->notifyStop();
+      },

Review Comment:
   Exceptions must not cross the C callback boundary. Two concrete issues here:\n1) `.create` can throw (e.g., `parse(...).value()` on invalid UUID, `new Class{...}` if the constructor throws), which would unwind through a C ABI callback.\n2) `.notifyStop` lacks a try/catch, so any exception thrown by the extension implementation will unwind through the C ABI.\nWrap both callbacks in `try/catch (...)` and return a safe failure signal (`nullptr` from `.create`; swallow/log in `.notifyStop` or report via an error channel if available). Also avoid `.value()` here; prefer an explicit failure path.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] MINIFICPP-2764 Controller Service CPP API [nifi-minifi-cpp]

Posted by "martinzink (via GitHub)" <gi...@apache.org>.
martinzink commented on code in PR #2152:
URL: https://github.com/apache/nifi-minifi-cpp/pull/2152#discussion_r3159167470


##########
libminifi/test/libtest/unit/TestBase.cpp:
##########
@@ -360,6 +360,27 @@ minifi::Connection* TestPlan::addConnection(minifi::core::Processor* source_proc
   return retVal;
 }
 
+std::shared_ptr<minifi::core::controller::ControllerServiceNode> TestPlan::addController(const std::string& name, const std::shared_ptr<core::controller::ControllerService>& cs) {

Review Comment:
   it will be used in #2153 and later on, we need this because we would like to instantiate them with preexisting (instantiated through the API) controller services
   
   https://github.com/apache/nifi-minifi-cpp/pull/2153/changes#diff-d5f59e4f9d39633968dfdf29d96503d484179de5c8b66f72a0df9340745f3354R56-R62



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] MINIFICPP-2764 Controller Service CPP API [nifi-minifi-cpp]

Posted by "szaszm (via GitHub)" <gi...@apache.org>.
szaszm commented on code in PR #2152:
URL: https://github.com/apache/nifi-minifi-cpp/pull/2152#discussion_r3150005631


##########
extension-framework/cpp-extension-lib/include/api/core/ControllerServiceImpl.h:
##########
@@ -0,0 +1,61 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#pragma once
+
+#include <memory>
+#include <string>
+
+#include "ControllerServiceContext.h"
+#include "minifi-cpp/core/ControllerServiceMetadata.h"
+#include "minifi-cpp/utils/Id.h"
+#include "utils/SmallString.h"
+
+namespace org::apache::nifi::minifi::api {
+
+class Connection;
+
+namespace core {
+
+class ControllerServiceImpl {

Review Comment:
   What is the purpose of this class? a description in a code comment would be helpful IMO



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] MINIFICPP-2764 Controller Service CPP API [nifi-minifi-cpp]

Posted by "fgerlits (via GitHub)" <gi...@apache.org>.
fgerlits commented on code in PR #2152:
URL: https://github.com/apache/nifi-minifi-cpp/pull/2152#discussion_r3155534324


##########
extension-framework/cpp-extension-lib/include/api/utils/ProcessorConfigUtils.h:
##########
@@ -167,4 +167,28 @@ std::optional<T> parseOptionalEnumProperty(const core::ProcessContext& context,
   return result.value();
 }
 
+template<typename ControllerServiceType>
+ControllerServiceType* parseOptionalControllerService(const core::ProcessContext& context, const minifi::core::PropertyReference& prop) {
+  const auto controller_service_name = context.getProperty(prop.name);
+  if (!controller_service_name || controller_service_name->empty()) {
+    return nullptr;
+  }
+
+  nonstd::expected<MinifiControllerService*, std::error_code> service = context.getControllerService(*controller_service_name, minifi::core::className<ControllerServiceType>());

Review Comment:
   this will need to be fixed on rebase: `nonstd` -> `std`



##########
extension-framework/cpp-extension-lib/src/core/ProcessContext.cpp:
##########
@@ -38,4 +38,17 @@ bool ProcessContext::hasNonEmptyProperty(std::string_view name) const {
   return MinifiProcessContextHasNonEmptyProperty(impl_, utils::toStringView(name));
 }
 
+nonstd::expected<MinifiControllerService*, std::error_code> ProcessContext::getControllerService(const std::string_view controller_service_name,
+    const std::string_view controller_service_class) const {
+  void* controller_service = nullptr;

Review Comment:
   I think this is another thing that you'll fix during rebase without me commenting, but this should be `MinifiControllerService*` instead of `void*`.



##########
extension-framework/cpp-extension-lib/include/api/core/Resource.h:
##########
@@ -145,4 +150,43 @@ void useProcessorClassDescription(Fn&& fn) {
   fn(description);
 }
 
+template<typename Class, typename Fn>
+void useControllerServiceClassDescription(Fn&& fn) {
+  std::vector<std::vector<MinifiStringView>> string_vector_cache;
+
+  const auto full_name = minifi::core::className<Class>();
+
+  std::vector<MinifiPropertyDefinition> class_properties = utils::toProperties(Class::Properties, string_vector_cache);
+
+  MinifiControllerServiceClassDefinition description{.full_name = utils::toStringView(full_name),

Review Comment:
   I know it doesn't matter, but it hurts my OCD that this kind of object is called a "description" everywhere, but the name of the class is "...Definition".
   
   If it's not too much work to change it, it would be better if this was a "definition" everywhere or a "description" everywhere, including the class name.



##########
libminifi/test/libtest/unit/TestBase.cpp:
##########
@@ -360,6 +360,27 @@ minifi::Connection* TestPlan::addConnection(minifi::core::Processor* source_proc
   return retVal;
 }
 
+std::shared_ptr<minifi::core::controller::ControllerServiceNode> TestPlan::addController(const std::string& name, const std::shared_ptr<core::controller::ControllerService>& cs) {

Review Comment:
   Why do we need this new version of `addController`? We only seem to be using the old version.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] MINIFICPP-2764 Controller Service CPP API [nifi-minifi-cpp]

Posted by "martinzink (via GitHub)" <gi...@apache.org>.
martinzink commented on code in PR #2152:
URL: https://github.com/apache/nifi-minifi-cpp/pull/2152#discussion_r3159365467


##########
extension-framework/cpp-extension-lib/include/api/core/Resource.h:
##########
@@ -145,4 +150,43 @@ void useProcessorClassDescription(Fn&& fn) {
   fn(description);
 }
 
+template<typename Class, typename Fn>
+void useControllerServiceClassDescription(Fn&& fn) {
+  std::vector<std::vector<MinifiStringView>> string_vector_cache;
+
+  const auto full_name = minifi::core::className<Class>();
+
+  std::vector<MinifiPropertyDefinition> class_properties = utils::toProperties(Class::Properties, string_vector_cache);
+
+  MinifiControllerServiceClassDefinition description{.full_name = utils::toStringView(full_name),

Review Comment:
   agreed, i went with definition everywhere because the class already contains description so it made more sense for me
   
   [useProcessorClassDescription -> useProcessorClassDefinition](https://github.com/apache/nifi-minifi-cpp/pull/2152/commits/97c898aac7001f4abd67a16b35f0f69f181c55be)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] MINIFICPP-2764 Controller Service CPP API [nifi-minifi-cpp]

Posted by "martinzink (via GitHub)" <gi...@apache.org>.
martinzink commented on code in PR #2152:
URL: https://github.com/apache/nifi-minifi-cpp/pull/2152#discussion_r3186712708


##########
extension-framework/cpp-extension-lib/include/api/core/ControllerServiceImpl.h:
##########
@@ -0,0 +1,61 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#pragma once
+
+#include <memory>
+#include <string>
+
+#include "ControllerServiceContext.h"
+#include "minifi-cpp/core/ControllerServiceMetadata.h"
+#include "minifi-cpp/utils/Id.h"
+#include "utils/SmallString.h"
+
+namespace org::apache::nifi::minifi::api {
+
+class Connection;
+
+namespace core {
+
+class ControllerServiceImpl {

Review Comment:
   [add explanatory comments to ControllerServiceImpl.h](https://github.com/apache/nifi-minifi-cpp/pull/2152/commits/a3960293ebcebfa01feb2aff7c2aed8f01349f87)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] MINIFICPP-2764 Controller Service CPP API [nifi-minifi-cpp]

Posted by "martinzink (via GitHub)" <gi...@apache.org>.
martinzink merged PR #2152:
URL: https://github.com/apache/nifi-minifi-cpp/pull/2152


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org