Skip to content

Commit ee49532

Browse files
authored
MINIFICPP-2850 Finalize stable API before 1.0 (#2205)
This commit finalizes the “stable” MiNiFi C/C++ extension API surface in preparation for a 1.0 release by renaming and normalizing exported C symbols/headers, updating the C++ extension framework wrappers, and migrating extensions/tests to the new API (including new metrics reporting and trigger-when-empty control paths). * removed MINIFI_NULL * removed struct typedefs * snake_case type and function names * removed stdbool.h, in C23, bool, true, and false are keywords * PropertyDefinition: type -> allowed_type * getTriggerWhenEmpty member -> setTriggerWhenEmpty free function, to be called from onSchedule * onTrigger -> trigger, onSchedule -> schedule, onUnSchedule -> unschedule * calculate_metrics -> call report_metrics on process_context instead of callback * processor_class_definition: removed class_ prefixes from members * minifi-c.h -> minifi-api.h * removed get/setTriggerWhenEmpty from ProcessorApi * moved MinifiLoggerSetMaxLogSize, MinifiLoggerLevel to AdvancedLogger * moved AdvancedLogger.h to minifi-api/include/minifi-cpp/core/logging/AdvancedLogger.h * minifi_processor_class_definition -> minifi_processor_definition * minifi_controller_service_class_definition -> minifi_controller_service_definition * removed <= c23 workarounds * removed unused macro magic
1 parent 0d27eac commit ee49532

109 files changed

Lines changed: 1197 additions & 1181 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.clang-format

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@ AlignConsecutiveAssignments: None
55
AlignOperands: DontAlign
66
AllowAllParametersOfDeclarationOnNextLine: true
77
AllowAllConstructorInitializersOnNextLine: false
8-
AllowShortBlocksOnASingleLine: Always
9-
AllowShortCaseLabelsOnASingleLine: true
10-
AllowShortFunctionsOnASingleLine: Inline
11-
AllowShortIfStatementsOnASingleLine: Always
8+
AllowShortBlocksOnASingleLine: Empty
9+
AllowShortCaseLabelsOnASingleLine: false
10+
AllowShortEnumsOnASingleLine: false
11+
AllowShortFunctionsOnASingleLine: None
12+
AllowShortIfStatementsOnASingleLine: WithoutElse
1213
AllowShortLambdasOnASingleLine: All
1314
AllowShortLoopsOnASingleLine: false
1415
AlwaysBreakAfterReturnType: None

.github/references/ubuntu_22_04_clang_arm_manifest.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11089,13 +11089,13 @@
1108911089
"type": "org.apache.nifi.minifi.api_testing.DogController",
1109011090
"providedApiImplementations": [
1109111091
{
11092-
"artifact": "minifi-system",
11093-
"group": "org.apache.nifi.minifi",
11092+
"artifact": "minifi-stable-api-testing",
11093+
"group": "org.apache.nifi.minifi.api_testing",
1109411094
"type": "org.apache.nifi.minifi.api_testing.CanFlyControllerApi"
1109511095
},
1109611096
{
11097-
"artifact": "minifi-system",
11098-
"group": "org.apache.nifi.minifi",
11097+
"artifact": "minifi-stable-api-testing",
11098+
"group": "org.apache.nifi.minifi.api_testing",
1109911099
"type": "org.apache.nifi.minifi.api_testing.NumberOfLegsControllerApi"
1110011100
}
1110111101
]
@@ -11107,13 +11107,13 @@
1110711107
"type": "org.apache.nifi.minifi.api_testing.DuckController",
1110811108
"providedApiImplementations": [
1110911109
{
11110-
"artifact": "minifi-system",
11111-
"group": "org.apache.nifi.minifi",
11110+
"artifact": "minifi-stable-api-testing",
11111+
"group": "org.apache.nifi.minifi.api_testing",
1111211112
"type": "org.apache.nifi.minifi.api_testing.CanFlyControllerApi"
1111311113
},
1111411114
{
11115-
"artifact": "minifi-system",
11116-
"group": "org.apache.nifi.minifi",
11115+
"artifact": "minifi-stable-api-testing",
11116+
"group": "org.apache.nifi.minifi.api_testing",
1111711117
"type": "org.apache.nifi.minifi.api_testing.NumberOfLegsControllerApi"
1111811118
}
1111911119
]

.github/workflows/create-release-artifacts.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@ jobs:
9595
mkdir minifi-native-sdk
9696
9797
cp behave_framework/dist/*.whl minifi-native-sdk/
98-
cp minifi-api/minifi-c-api.def minifi-native-sdk/
99-
cp minifi-api/include/minifi-c/minifi-c.h minifi-native-sdk/
98+
cp minifi-api/minifi-api.def minifi-native-sdk/
99+
cp minifi-api/include/minifi-api.h minifi-native-sdk/
100100
101101
zip -r minifi-native-sdk.zip minifi-native-sdk/
102102

Extensions.md

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,36 +20,36 @@ To enable all extensions for your platform, you may use -DENABLE_ALL=TRUE OR sel
2020
Extensions are dynamic libraries loaded at runtime by the agent.
2121

2222
## C extensions
23-
You can build shared libraries using the API defined in `minifi-c.h`
24-
For the shared library to be considered a valid extension, it must export a global symbol with the name `MinifiApiVersion`
25-
with its value equal to the uint32_t constant `MINIFI_API_VERSION` from `minifi-c.h`.
23+
You can build shared libraries using the API defined in `minifi-api.h`
24+
For the shared library to be considered a valid extension, it must export a global symbol with the name `minifi_api_version`
25+
with its value equal to the uint32_t constant `MINIFI_API_VERSION` from `minifi-api.h`.
2626

2727
### Resource Lifetime
2828

29-
Unless otherwise specified, the following lifetime rules apply to all functions called by the agent (e.g., `MinifiInitExtension`, `MinifiProcessorCallbacks::onTrigger`, or other callbacks):
29+
Unless otherwise specified, the following lifetime rules apply to all functions called by the agent (e.g., `minifi_init_extension`, `minifi_processor_callbacks::trigger`, or other callbacks):
3030

3131
* Arguments: The lifetime of any resource provided as a function argument is limited to the duration of that function call.
3232

33-
* Created Resources: The lifetime of resources created within these functions (e.g., a handle returned by `MinifiProcessSessionGet` inside `MinifiProcessorCallbacks::onTrigger`)
33+
* Created Resources: The lifetime of resources created within these functions (e.g., a handle returned by `minifi_process_session_get` inside `minifi_processor_callbacks::trigger`)
3434
is limited to the scope of the innermost callback.
35-
(the return value of `MinifiRegisterExtension` is only valid during the execution of `MinifiInitExtension`).
35+
(the return value of `minifi_register_extension` is only valid during the execution of `minifi_init_extension`).
3636

37-
Because of these scoping rules, all processor and controller service registrations must occur within the `MinifiInitExtension` call.
37+
Because of these scoping rules, all processor and controller service registrations must occur within the `minifi_init_extension` call.
3838
One possible example of this is:
3939

4040
```C++
41-
extern "C" const uint32_t MinifiApiVersion = MINIFI_API_VERSION;
41+
extern "C" const uint32_t minifi_api_version = MINIFI_API_VERSION;
4242

43-
extern "C" void MinifiInitExtension(MinifiExtensionContext* extension_context) {
44-
MinifiExtensionDefinition extension_definition{
43+
extern "C" void minifi_init_extension(minifi_extension_context* extension_context) {
44+
minifi_extension_definition extension_definition{
4545
.name = minifi::api::utils::toStringView(MAKESTRING(EXTENSION_NAME)),
4646
.version = minifi::api::utils::toStringView(MAKESTRING(EXTENSION_VERSION)),
4747
.deinit = nullptr,
4848
.user_data = nullptr
4949
};
50-
auto* extension = MinifiRegisterExtension(extension_context, &extension_definition);
51-
minifi::api::core::useProcessorClassDefinition<minifi::extensions::llamacpp::processors::RunLlamaCppInference>([&] (const MinifiProcessorClassDefinition& definition) {
52-
MinifiRegisterProcessor(extension, &definition);
50+
auto* extension = minifi_register_extension(extension_context, &extension_definition);
51+
minifi::api::core::useProcessorClassDefinition<minifi::extensions::llamacpp::processors::RunLlamaCppInference>([&] (const minifi_processor_definition& definition) {
52+
minifi_register_processor(extension, &definition);
5353
});
5454
}
5555
```
@@ -73,18 +73,18 @@ REGISTER_RESOURCE(RESTSender, DescriptionOnly);
7373
```
7474

7575
Some extensions (e.g. `Python`) require initialization before use.
76-
You need to define an `MinifiInitCppExtension` function of type `MinifiExtension*(MinifiExtensionContext*)` to be called.
76+
You need to define an `minifi_init_cpp_extension` function with signature `void minifi_init_cpp_extension(minifi_extension_context*)` to be called.
7777

7878
```C++
79-
extern "C" void MinifiInitCppExtension(MinifiExtensionContext* extension_context) {
79+
extern "C" void minifi_init_cpp_extension(minifi_extension_context* extension_context) {
8080
static PythonLibLoader python_lib_loader([&] (std::string_view key) -> std::optional<std::string> {
8181
std::optional<std::string> result;
82-
MinifiConfigGet(extension_context, minifi::utils::toStringView(key), [] (void* user_data, MinifiStringView value) {
82+
minifi_config_get(extension_context, minifi::utils::toStringView(key), [] (void* user_data, minifi_string_view value) {
8383
*static_cast<std::optional<std::string>*>(user_data) = std::string{value.data, value.length};
8484
}, &result);
8585
return result;
8686
});
87-
MinifiExtensionDefinition extension_definition{
87+
minifi_extension_definition extension_definition{
8888
.name = minifi::utils::toStringView(MAKESTRING(MODULE_NAME)),
8989
.version = minifi::utils::toStringView(minifi::AgentBuild::VERSION),
9090
.deinit = nullptr,

core-framework/include/core/ProcessorImpl.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,6 @@ class ProcessorImpl : public virtual ProcessorApi {
8787

8888
std::string getProcessorType() const override = 0;
8989

90-
void setTriggerWhenEmpty(bool trigger_when_empty) {
91-
trigger_when_empty_ = trigger_when_empty;
92-
}
93-
94-
bool getTriggerWhenEmpty() const override {
95-
return trigger_when_empty_;
96-
}
97-
9890
void initialize(ProcessorDescriptor& self) final;
9991

10092
void setSupportedRelationships(std::span<const RelationshipDefinition> relationships);
@@ -140,8 +132,6 @@ class ProcessorImpl : public virtual ProcessorApi {
140132

141133
ProcessorMetadata metadata_;
142134

143-
std::atomic<bool> trigger_when_empty_;
144-
145135
std::shared_ptr<ProcessorMetricsExtension> metrics_extension_;
146136

147137
std::shared_ptr<logging::Logger> logger_;

core-framework/src/core/ProcessorImpl.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ namespace org::apache::nifi::minifi::core {
4444

4545
ProcessorImpl::ProcessorImpl(ProcessorMetadata metadata)
4646
: metadata_(std::move(metadata)),
47-
trigger_when_empty_(false),
4847
logger_(metadata_.logger) {
4948
logger_->log_debug("Processor {} created with uuid {}", getName(), getUUIDStr());
5049
}

extension-framework/cpp-extension-lib/include/api/core/ControllerServiceContext.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,25 +17,25 @@
1717

1818
#pragma once
1919

20-
#include <string>
2120
#include <expected>
21+
#include <string>
2222

23-
#include "minifi-c.h"
23+
#include "minifi-api.h"
2424
#include "minifi-cpp/core/PropertyDefinition.h"
2525

2626
namespace org::apache::nifi::minifi::api::core {
2727

2828
class ControllerServiceContext {
2929
public:
30-
explicit ControllerServiceContext(MinifiControllerServiceContext* impl) : impl_(impl) {}
30+
explicit ControllerServiceContext(minifi_controller_service_context* impl) : impl_(impl) {}
3131

3232
[[nodiscard]] std::expected<std::string, std::error_code> getProperty(std::string_view name) const;
3333
[[nodiscard]] std::expected<std::string, std::error_code> getProperty(const minifi::core::PropertyReference& property_reference) const {
3434
return getProperty(property_reference.name);
3535
}
3636

3737
private:
38-
MinifiControllerServiceContext* impl_;
38+
minifi_controller_service_context* impl_;
3939
};
4040

4141
} // namespace org::apache::nifi::minifi::api::core

extension-framework/cpp-extension-lib/include/api/core/ControllerServiceImpl.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,15 @@ class ControllerServiceImpl {
4343

4444
virtual ~ControllerServiceImpl();
4545

46-
MinifiStatus enable(ControllerServiceContext&);
46+
minifi_status enable(ControllerServiceContext&);
4747
void disable();
4848

4949
[[nodiscard]] std::string getName() const;
5050
[[nodiscard]] minifi::utils::Identifier getUUID() const;
5151
[[nodiscard]] minifi::utils::SmallString<36> getUUIDStr() const;
5252

5353
protected:
54-
virtual MinifiStatus enableImpl(api::core::ControllerServiceContext&) = 0;
54+
virtual minifi_status enableImpl(api::core::ControllerServiceContext&) = 0;
5555
virtual void disableImpl() {}
5656

5757
minifi::core::ControllerServiceMetadata metadata_;

extension-framework/cpp-extension-lib/include/api/core/FlowFile.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@
2121
#include <memory>
2222
#include <stdexcept>
2323

24-
#include "minifi-c.h"
24+
#include "minifi-api.h"
2525

2626
namespace org::apache::nifi::minifi::api::core {
2727

2828
struct EnsureMovedFromDeleter {
29-
void operator()(MinifiFlowFile* ff) {
29+
void operator()(minifi_flow_file* ff) {
3030
if (ff) {
3131
if (std::uncaught_exceptions()) {
3232
// there is already an exception in progress, do not terminate the process (although there are scenarios we could throw here)
@@ -37,6 +37,6 @@ struct EnsureMovedFromDeleter {
3737
}
3838
};
3939

40-
using FlowFile = std::unique_ptr<MinifiFlowFile, EnsureMovedFromDeleter>;
40+
using FlowFile = std::unique_ptr<minifi_flow_file, EnsureMovedFromDeleter>;
4141

4242
} // namespace org::apache::nifi::minifi::api::core

extension-framework/cpp-extension-lib/include/api/core/ProcessContext.h

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,11 @@
2020
#include <expected>
2121
#include <string>
2222

23+
#include "PublishedMetrics.h"
2324
#include "api/core/FlowFile.h"
2425
#include "api/utils/Proxy.h"
2526
#include "api/utils/Ssl.h"
26-
#include "minifi-c.h"
27+
#include "minifi-api.h"
2728
#include "minifi-cpp/core/PropertyDefinition.h"
2829

2930
namespace org::apache::nifi::minifi::api::core {
@@ -40,32 +41,36 @@ class ProcessContext {
4041

4142
[[nodiscard]] virtual std::expected<std::string, std::error_code> getProperty(const minifi::core::PropertyReference& prop,
4243
const FlowFile* ff) const = 0;
43-
[[nodiscard]] virtual std::expected<MinifiControllerService*, std::error_code> getControllerService(const minifi::core::PropertyReference& prop) const = 0;
44-
[[nodiscard]] virtual bool hasNonEmptyProperty(std::string_view name) const = 0;
44+
[[nodiscard]] virtual std::expected<minifi_controller_service*, std::error_code> getControllerService(const minifi::core::PropertyReference& prop) const = 0;
4545
[[nodiscard]] virtual std::map<std::string, std::string> getDynamicProperties(const FlowFile* flow_file) const = 0;
4646

4747
[[nodiscard]] virtual std::expected<std::optional<utils::net::SslData>, std::error_code> getSslData(const minifi::core::PropertyReference& prop) const = 0;
4848
[[nodiscard]] virtual std::expected<std::optional<utils::ProxyData>, std::error_code> getProxyData(const minifi::core::PropertyReference& prop) const = 0;
49+
50+
[[nodiscard]] virtual std::expected<void, std::error_code> reportMetrics(const PublishedMetrics& metrics) const = 0;
51+
[[nodiscard]] virtual std::expected<void, std::error_code> setTriggerWhenEmpty(bool) = 0;
4952
};
5053

5154
class CffiProcessContext : public ProcessContext {
5255
public:
53-
explicit CffiProcessContext(MinifiProcessContext* impl) : impl_(impl) {}
56+
explicit CffiProcessContext(minifi_process_context* impl) : impl_(impl) {}
5457

5558
[[nodiscard]] std::expected<std::string, std::error_code> getProperty(const minifi::core::PropertyReference& property_reference,
5659
const FlowFile* flow_file) const override;
57-
[[nodiscard]] std::expected<MinifiControllerService*, std::error_code> getControllerService(const minifi::core::PropertyReference& prop) const override;
60+
[[nodiscard]] std::expected<minifi_controller_service*, std::error_code> getControllerService(const minifi::core::PropertyReference& prop) const override;
5861
[[nodiscard]] std::map<std::string, std::string> getDynamicProperties(const FlowFile* flow_file) const override;
59-
[[nodiscard]] bool hasNonEmptyProperty(std::string_view name) const override;
6062

6163
[[nodiscard]] std::expected<std::optional<utils::net::SslData>, std::error_code> getSslData(const minifi::core::PropertyReference& prop) const override;
6264
[[nodiscard]] std::expected<std::optional<utils::ProxyData>, std::error_code> getProxyData(const minifi::core::PropertyReference& prop) const override;
6365

66+
[[nodiscard]] std::expected<void, std::error_code> reportMetrics(const PublishedMetrics& metrics) const override;
67+
[[nodiscard]] std::expected<void, std::error_code> setTriggerWhenEmpty(bool) override;
68+
6469
private:
6570
[[nodiscard]] std::expected<std::string, std::error_code> getProperty(std::string_view name, const FlowFile* flow_file) const;
6671

6772
private:
68-
MinifiProcessContext* impl_;
73+
minifi_process_context* impl_;
6974
};
7075

7176
} // namespace org::apache::nifi::minifi::api::core

0 commit comments

Comments
 (0)