Skip to content

MINIFICPP-2816 Add controller_service::api_implementations to C api#2176

Open
martinzink wants to merge 7 commits into
apache:gcp_to_c_apifrom
martinzink:c_api_controller_service_traits
Open

MINIFICPP-2816 Add controller_service::api_implementations to C api#2176
martinzink wants to merge 7 commits into
apache:gcp_to_c_apifrom
martinzink:c_api_controller_service_traits

Conversation

@martinzink

Copy link
Copy Markdown
Member

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?
  • 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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR extends the C extension API for MiNiFi C++ to let C-based controller services declare and expose multiple "provided interfaces" (additional C++ APIs they implement). The agent surfaces these as api_implementations in class descriptions, and MinifiProcessContextGetControllerService now uses a new get_interface callback to cast a controller service implementation to a requested API type. A new stable-api-sandbox test extension exercises the feature with Dog/Duck controller services that both implement CanFlyControllerApi and NumberOfLegsControllerApi, consumed by a ZooProcessor.

Changes:

  • Added provided_interfaces_* and a get_interface callback to the C controller-service ABI, plumbed through useControllerServiceClassDefinition and useCControllerServiceClassDescription into ClassDescription::api_implementations.
  • Introduced a C++-side ProvidedInterface / createProvidedInterface helper and a ControllerServiceType::minifiSystemControllerServiceType factory.
  • Added a new stable-api-sandbox extension (controller services, processor, init, tests, CMake) demonstrating and testing the multi-interface controller service flow.

Reviewed changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
minifi-api/include/minifi-c/minifi-c.h Adds provided_interfaces_* fields and get_interface callback to controller-service C ABI structs.
minifi-api/include/minifi-cpp/core/ControllerServiceType.h Adds minifiSystemControllerServiceType factory and tightens reformatting; private ctor for raw fields.
minifi-api/common/include/minifi-cpp/core/ProvidedControllerServiceInterface.h New header defining ProvidedInterface and the createProvidedInterface helper template.
extension-framework/cpp-extension-lib/include/api/core/Resource.h Wires Class::ProvidedInterfaces into the C definition and implements the get_interface lambda.
libminifi/src/minifi-c.cpp Builds api_implementations from C-side interface names; uses get_interface in MinifiProcessContextGetControllerService.
extensions/stable-api-sandbox/AnimalControllerServiceApis.h Defines two abstract controller-service APIs used by the sandbox tests.
extensions/stable-api-sandbox/AnimalControllerServices.{h,cpp} DogController/DuckController implementing both APIs and declaring ProvidedInterfaces.
extensions/stable-api-sandbox/ZooProcessor.{h,cpp} Test processor that fetches both interfaces from configured controller services.
extensions/stable-api-sandbox/ExtensionInitializer.cpp Registers the new processor and controller services as a C extension.
extensions/stable-api-sandbox/CMakeLists.txt New CMake module building the sandbox extension.
extensions/stable-api-sandbox/tests/CMakeLists.txt Builds the sandbox extension's tests.
extensions/stable-api-sandbox/tests/ZooTests.cpp End-to-end test exercising multi-interface lookup via the C API.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread extensions/stable-api-sandbox/ExtensionInitializer.cpp Outdated
Comment thread minifi-api/include/minifi-c/minifi-c.h
Comment thread libminifi/src/minifi-c.cpp Outdated
Comment thread minifi-api/common/include/minifi-cpp/core/ProvidedControllerServiceInterface.h Outdated
Comment thread extensions/stable-api-sandbox/AnimalControllerServiceApis.h
@martinzink martinzink force-pushed the c_api_controller_service_traits branch from 615a1aa to 8a61732 Compare May 15, 2026 12:35
@martinzink martinzink changed the base branch from main to gcp_to_c_api May 15, 2026 12:35
@martinzink martinzink requested a review from Copilot May 15, 2026 12:36

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 14 out of 14 changed files in this pull request and generated 5 comments.

Comment thread minifi-api/include/minifi-c/minifi-c.h Outdated
Comment thread libminifi/src/minifi-c.cpp
Comment thread extensions/stable-api-sandbox/tests/ZooTests.cpp Outdated
Comment thread extensions/stable-api-sandbox/tests/ZooTests.cpp Outdated
@martinzink martinzink force-pushed the c_api_controller_service_traits branch 2 times, most recently from e37d114 to 3f19d56 Compare May 18, 2026 11:40
@martinzink martinzink force-pushed the c_api_controller_service_traits branch from 3f19d56 to 4df654c Compare May 26, 2026 13:23
@martinzink martinzink force-pushed the gcp_to_c_api branch 2 times, most recently from a663671 to b607c29 Compare May 27, 2026 15:14
@martinzink martinzink force-pushed the c_api_controller_service_traits branch 3 times, most recently from 75dec07 to 6fc9e41 Compare May 28, 2026 05:48
@martinzink martinzink force-pushed the gcp_to_c_api branch 2 times, most recently from 2cac27e to 97b90aa Compare May 28, 2026 13:52
@martinzink martinzink force-pushed the c_api_controller_service_traits branch 2 times, most recently from 7d06f20 to e727372 Compare May 28, 2026 14:02
@martinzink martinzink marked this pull request as ready for review May 29, 2026 14:57

explicit ControllerServiceFactoryImpl(std::string group_name)
: group_name_(std::move(group_name)),
explicit ControllerServiceFactoryImpl(std::string module_name)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ive renamed it from group_name to module_name, because this groupname was not the groupname in C2 but rather the artifact name

@adamdebreceni adamdebreceni self-requested a review June 2, 2026 07:10
@martinzink martinzink force-pushed the c_api_controller_service_traits branch 2 times, most recently from 62b57f8 to 1311c86 Compare June 2, 2026 08:27
@martinzink martinzink added dependencies Pull requests that update a dependency file depends-on-another-PR and removed dependencies Pull requests that update a dependency file labels Jun 2, 2026
Comment thread core-framework/include/core/ObjectFactory.h Outdated
Comment thread libminifi/src/minifi-c.cpp Outdated
@martinzink martinzink force-pushed the c_api_controller_service_traits branch from 1311c86 to 9175793 Compare June 4, 2026 10:26
Comment thread libminifi/src/core/state/nodes/AgentInformation.cpp Outdated
@martinzink martinzink force-pushed the c_api_controller_service_traits branch from 9175793 to 5955a53 Compare June 15, 2026 12:25
@martinzink martinzink force-pushed the gcp_to_c_api branch 2 times, most recently from 6321c43 to 4429809 Compare June 15, 2026 16:09
@martinzink martinzink force-pushed the c_api_controller_service_traits branch from 5955a53 to c13b5b4 Compare June 17, 2026 11:05
Comment thread extension-framework/cpp-extension-lib/include/api/core/Resource.h Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm thinking we should call this stable-api-tests or something like that, so even at first glance it's clear that this is a test-only extension.

Comment thread extensions/stable-api-sandbox/ZooProcessor.cpp Outdated
Comment thread extensions/stable-api-sandbox/ZooProcessor.cpp Outdated
Comment on lines +32 to +36
EXTENSIONAPI static constexpr auto CanFlyService = core::PropertyDefinitionBuilder<>::createProperty("Can fly service")
.withDescription("Test CanFlyService")
.isRequired(true)
.withAllowedTypes<CanFlyControllerApi>()
.build();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Continuation indentation should be 4 spaces deeper. I'm against trying to maintain alignments, because we get right-heavy lines like these, plus renames and similar changes break alignment.

{
LogTestController::getInstance().clear();
CHECK(controller.getProcessor()->setProperty(ZooProcessor::CanFlyService.name, "duck"));
CHECK(controller.getProcessor()->setProperty(ZooProcessor::NumberOfLegsService.name, "invalid"));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't this throw an error?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no we dont validate here, thats only done on C2 side, we theoratically could so its might be a good feature

void initialize() override {}
void onEnable() override {}

[[nodiscard]] ControllerServiceHandle* getControllerServiceHandle() override { return this; }

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this should be added to the macro ADD_COMMON_VIRTUAL_FUNCTIONS_FOR_CONTROLLER_SERVICES, tho it doesn't strictly belong in the scope of this change, so you decide

Comment thread minifi-api/common/include/minifi-cpp/core/ProvidedControllerServiceInterface.h Outdated
Comment thread minifi-api/common/include/minifi-cpp/core/ProvidedControllerServiceInterface.h Outdated
Comment on lines +55 to +61
constexpr auto system_allowed_types = std::to_array<std::string_view>({
controllers::SSLContextServiceInterface::ProvidesApi.type,
core::RecordSetWriter::ProvidesApi.type,
core::RecordSetReader::ProvidesApi.type,
controllers::ProxyConfigurationServiceInterface::ProvidesApi.type,
controllers::AttributeProviderService::ProvidesApi.type});
return ranges::contains(system_allowed_types, allowed_type);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the old version with inline comparisons better. No need to introduce an STL container and ranges when it doesn't have a benefit, and line patterns are easily readable, even if they are somewhat repetitive.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just noticed that @lordgamez suggested the change, so CC.

@lordgamez lordgamez Jun 17, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not really what I suggested, but we discussed that the originally suggested improvement should be a separate PR. Until that is implemented the same issue persists that when any new system allowed type is introduced it needs to be manually inserted here which is not trivial to find and easily missed, does not really matter if it's inlined or extracted to a container. My original intent to alternatively extract the constants was to move them to a more accessible and discoverable place when introducing a new option, but there's not really a viable place for it now, so it can be reverted.

@szaszm szaszm Jun 17, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah okay. If it's a temporary solution, I don't insist on changing it, but I would still prefer the simpler version.

Co-authored-by: Márton Szász <szaszm@apache.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants