-
Notifications
You must be signed in to change notification settings - Fork 102
MINIFICPP-2816 Add controller_service::api_implementations to C api #2176
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
martinzink
wants to merge
1
commit into
apache:gcp_to_c_api
Choose a base branch
from
martinzink:c_api_controller_service_traits
base: gcp_to_c_api
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
extensions/stable-api-sandbox/AnimalControllerServiceApis.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| /** | ||
| * 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 <cinttypes> | ||
|
|
||
| namespace org::apache::nifi::minifi::api_sandbox { | ||
| class NumberOfLegsControllerApi { | ||
| public: | ||
| virtual ~NumberOfLegsControllerApi() = default; | ||
| virtual uint8_t numberOfLegs() const = 0; | ||
| }; | ||
|
|
||
| class CanFlyControllerApi { | ||
| public: | ||
| virtual ~CanFlyControllerApi() = default; | ||
| virtual bool canFly() const = 0; | ||
| }; | ||
|
|
||
| } // namespace org::apache::nifi::minifi::api_sandbox | ||
30 changes: 30 additions & 0 deletions
30
extensions/stable-api-sandbox/AnimalControllerServices.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| /** | ||
| * 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 "AnimalControllerServices.h" | ||
|
|
||
| #include "api/utils/ProcessorConfigUtils.h" | ||
| namespace org::apache::nifi::minifi::api_sandbox { | ||
|
|
||
| MinifiStatus DogController::enableImpl(api::core::ControllerServiceContext& ctx) { | ||
| this->has_jetpack_ = ctx.getProperty(HasJetpack) | minifi::utils::andThen(parsing::parseBool) | | ||
| minifi::utils::orThrow(fmt::format("Expected parsable bool from \"{}\"", HasJetpack.name)); | ||
|
|
||
| return MINIFI_STATUS_SUCCESS; | ||
| } | ||
|
|
||
| } // namespace org::apache::nifi::minifi::api_sandbox |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| /** | ||
| * 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 "AnimalControllerServiceApis.h" | ||
| #include "api/core/ControllerServiceImpl.h" | ||
| #include "api/utils/Export.h" | ||
| #include "core/PropertyDefinitionBuilder.h" | ||
| #include "minifi-cpp/core/ProvidedControllerServiceInterface.h" | ||
|
|
||
| namespace org::apache::nifi::minifi::api_sandbox { | ||
| class DogController : public api::core::ControllerServiceImpl, public CanFlyControllerApi, public NumberOfLegsControllerApi { | ||
| public: | ||
| EXTENSIONAPI static constexpr const char* Description = "Test DogController"; | ||
| EXTENSIONAPI static constexpr auto HasJetpack = core::PropertyDefinitionBuilder<>::createProperty("Has Jetpack") | ||
| .withDescription("Whether or not the dog has a jetpack") | ||
| .withDefaultValue("false") | ||
| .withValidator(core::StandardPropertyValidators::BOOLEAN_VALIDATOR) | ||
| .build(); | ||
|
|
||
| EXTENSIONAPI static constexpr auto Properties = std::to_array<core::PropertyReference>({ | ||
| HasJetpack, | ||
| }); | ||
| EXTENSIONAPI static constexpr auto ProvidedInterfaces = | ||
| std::to_array<core::ProvidedInterface>({core::createProvidedInterface<CanFlyControllerApi, DogController>(), | ||
| core::createProvidedInterface<NumberOfLegsControllerApi, DogController>()}); | ||
|
|
||
| using ControllerServiceImpl::ControllerServiceImpl; | ||
| MinifiStatus enableImpl(api::core::ControllerServiceContext& ctx) override; | ||
|
|
||
| uint8_t numberOfLegs() const override { return 4; } | ||
| bool canFly() const override { return has_jetpack_; } | ||
|
|
||
| private: | ||
| bool has_jetpack_ = false; | ||
| }; | ||
|
|
||
| class DuckController : public api::core::ControllerServiceImpl, public CanFlyControllerApi, public NumberOfLegsControllerApi { | ||
| public: | ||
| EXTENSIONAPI static constexpr const char* Description = "Test DuckController"; | ||
|
|
||
| EXTENSIONAPI static constexpr std::array<core::PropertyReference, 0> Properties = {}; | ||
| EXTENSIONAPI static constexpr auto ProvidedInterfaces = | ||
| std::to_array<core::ProvidedInterface>({core::createProvidedInterface<CanFlyControllerApi, DuckController>(), | ||
| core::createProvidedInterface<NumberOfLegsControllerApi, DuckController>()}); | ||
| using ControllerServiceImpl::ControllerServiceImpl; | ||
| MinifiStatus enableImpl(api::core::ControllerServiceContext&) override { return MINIFI_STATUS_SUCCESS; } | ||
|
|
||
| uint8_t numberOfLegs() const override { return 2; } | ||
| bool canFly() const override { return true; } | ||
| }; | ||
| } // namespace org::apache::nifi::minifi::api_sandbox |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| # | ||
| # 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. | ||
| # | ||
|
|
||
| if (NOT ENABLE_TEST_PROCESSORS) | ||
| return() | ||
| endif () | ||
|
|
||
| include(${CMAKE_SOURCE_DIR}/extensions/ExtensionHeader.txt) | ||
| file(GLOB SOURCES "*.cpp") | ||
|
|
||
| add_minifi_library(minifi-stable-api-sandbox SHARED ${SOURCES}) | ||
|
|
||
| target_link_libraries(minifi-stable-api-sandbox minifi-cpp-extension-lib) | ||
|
|
||
| register_c_api_extension(minifi-stable-api-sandbox "Stable API Sandbox" SANDBOX-EXTENSION "Stable API Sandbox" "extensions/stable-api-sandbox/tests") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| /** | ||
| * 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 "AnimalControllerServices.h" | ||
| #include "ZooProcessor.h" | ||
| #include "api/core/Resource.h" | ||
| #include "api/utils/minifi-c-utils.h" | ||
|
|
||
| #define MKSOC(x) #x | ||
| #define MAKESTRING(x) MKSOC(x) // NOLINT(cppcoreguidelines-macro-usage) | ||
|
|
||
| namespace minifi = org::apache::nifi::minifi; | ||
|
|
||
| CEXTENSIONAPI const uint32_t MinifiApiVersion = MINIFI_API_VERSION; | ||
|
|
||
| CEXTENSIONAPI void MinifiInitExtension(MinifiExtensionContext* extension_context) { | ||
| const MinifiExtensionDefinition extension_definition{.name = minifi::api::utils::minifiStringView(MAKESTRING(EXTENSION_NAME)), | ||
| .version = minifi::api::utils::minifiStringView(MAKESTRING(EXTENSION_VERSION)), | ||
| .deinit = nullptr, | ||
| .user_data = nullptr}; | ||
| auto* extension = MinifiRegisterExtension(extension_context, &extension_definition); | ||
| minifi::api::core::registerProcessors<minifi::api_sandbox::ZooProcessor>(extension); | ||
| minifi::api::core::registerControllerServices<minifi::api_sandbox::DogController, minifi::api_sandbox::DuckController>(extension); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| /** | ||
| * 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 "ZooProcessor.h" | ||
|
|
||
| #include "AnimalControllerServices.h" | ||
| #include "api/core/ProcessContext.h" | ||
|
|
||
| namespace org::apache::nifi::minifi::api_sandbox { | ||
|
|
||
| MinifiStatus ZooProcessor::onTriggerImpl(api::core::ProcessContext& process_context, api::core::ProcessSession&) { | ||
| if (const auto can_fly_opaque = process_context.getControllerService(CanFlyService)) { | ||
| if (*can_fly_opaque) { | ||
| const auto can_fly_controller_name = process_context.getProperty(CanFlyService, nullptr) | utils::orThrow("Should be here"); | ||
| const CanFlyControllerApi* can_fly = reinterpret_cast<CanFlyControllerApi*>(*can_fly_opaque); | ||
| logger_->log_critical("Can {} fly? {}", can_fly_controller_name, can_fly->canFly()); | ||
| } | ||
| } | ||
| if (const auto num_of_legs_opaque = process_context.getControllerService(NumberOfLegsService)) { | ||
| if (*num_of_legs_opaque) { | ||
| const auto num_of_legs_name = process_context.getProperty(NumberOfLegsService, nullptr) | utils::orThrow("Should be here"); | ||
| const NumberOfLegsControllerApi* num_legs = reinterpret_cast<NumberOfLegsControllerApi*>(*num_of_legs_opaque); | ||
| logger_->log_critical("{} has {} legs", num_of_legs_name, num_legs->numberOfLegs()); | ||
| } | ||
| } | ||
| return MINIFI_STATUS_SUCCESS; | ||
| } | ||
|
|
||
| MinifiStatus ZooProcessor::onScheduleImpl(api::core::ProcessContext& process_context) { | ||
| return ProcessorImpl::onScheduleImpl(process_context); | ||
| } | ||
| } // namespace org::apache::nifi::minifi::api_sandbox |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| /** | ||
| * 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 "AnimalControllerServiceApis.h" | ||
| #include "api/core/ProcessorImpl.h" | ||
| #include "api/utils/Export.h" | ||
| #include "core/PropertyDefinitionBuilder.h" | ||
| #include "minifi-cpp/core/Annotation.h" | ||
|
|
||
| namespace org::apache::nifi::minifi::api_sandbox { | ||
|
|
||
| class ZooProcessor : public api::core::ProcessorImpl { | ||
| public: | ||
| EXTENSIONAPI static constexpr const char* Description = "Test ZooProcessor"; | ||
|
|
||
| EXTENSIONAPI static constexpr auto CanFlyService = core::PropertyDefinitionBuilder<>::createProperty("Can fly service") | ||
| .withDescription("Test CanFlyService") | ||
| .isRequired(true) | ||
| .withAllowedTypes<CanFlyControllerApi>() | ||
| .build(); | ||
|
|
||
| EXTENSIONAPI static constexpr auto NumberOfLegsService = core::PropertyDefinitionBuilder<>::createProperty("Number of legs service") | ||
| .withDescription("Test NumberOfLegsService") | ||
| .isRequired(true) | ||
| .withAllowedTypes<NumberOfLegsControllerApi>() | ||
| .build(); | ||
|
|
||
| EXTENSIONAPI static constexpr auto Properties = std::to_array<core::PropertyReference>({ | ||
| CanFlyService, | ||
| NumberOfLegsService, | ||
| }); | ||
| EXTENSIONAPI static constexpr auto Success = core::RelationshipDefinition{"success", "success"}; | ||
| EXTENSIONAPI static constexpr auto Failure = core::RelationshipDefinition{"failure", "failure"}; | ||
| EXTENSIONAPI static constexpr auto Relationships = std::array{Success, Failure}; | ||
| EXTENSIONAPI static constexpr bool SupportsDynamicProperties = false; | ||
| EXTENSIONAPI static constexpr bool SupportsDynamicRelationships = false; | ||
| EXTENSIONAPI static constexpr core::annotation::Input InputRequirement = core::annotation::Input::INPUT_FORBIDDEN; | ||
| EXTENSIONAPI static constexpr bool IsSingleThreaded = true; | ||
|
|
||
| using ProcessorImpl::ProcessorImpl; | ||
|
|
||
| protected: | ||
| MinifiStatus onTriggerImpl(api::core::ProcessContext&, api::core::ProcessSession&) override; | ||
| MinifiStatus onScheduleImpl(api::core::ProcessContext&) override; | ||
| }; | ||
|
|
||
| } // namespace org::apache::nifi::minifi::api_sandbox |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| # | ||
| # 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. | ||
| # | ||
|
|
||
| file(GLOB SOURCES "*.cpp") | ||
|
|
||
| SET(EXTENSIONS_TEST_COUNT 0) | ||
| FOREACH (testfile ${SOURCES}) | ||
| get_filename_component(testfilename "${testfile}" NAME_WE) | ||
| add_minifi_executable(${testfilename} "${testfile}") | ||
| target_include_directories(${testfilename} BEFORE PRIVATE "${CMAKE_SOURCE_DIR}/libminifi/include") | ||
| target_include_directories(${testfilename} BEFORE PRIVATE "${CMAKE_SOURCE_DIR}/extensions/stable-api-sandbox") | ||
| createTests(${testfilename}) | ||
| target_link_libraries(${testfilename} Catch2WithMain) | ||
| target_link_libraries(${testfilename} minifi-stable-api-sandbox) | ||
| target_link_libraries(${testfilename} libminifi-c-unittest) | ||
|
|
||
| MATH(EXPR EXTENSIONS_TEST_COUNT "${EXTENSIONS_TEST_COUNT}+1") | ||
| add_test(NAME ${testfilename} COMMAND ${testfilename} WORKING_DIRECTORY ${TEST_DIR}) | ||
| ENDFOREACH () |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.