Skip to content

Commit 936d6ee

Browse files
committed
review changes
1 parent 6809849 commit 936d6ee

4 files changed

Lines changed: 100 additions & 128 deletions

File tree

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

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@
1616
*/
1717
#pragma once
1818

19-
#include <condition_variable>
2019
#include <memory>
21-
#include <mutex>
2220
#include <string>
2321

2422
#include "ControllerServiceContext.h"
@@ -46,9 +44,9 @@ class ControllerServiceImpl {
4644
MinifiStatus enable(ControllerServiceContext&);
4745
void notifyStop();
4846

49-
std::string getName() const;
50-
minifi::utils::Identifier getUUID() const;
51-
minifi::utils::SmallString<36> getUUIDStr() const;
47+
[[nodiscard]] std::string getName() const;
48+
[[nodiscard]] minifi::utils::Identifier getUUID() const;
49+
[[nodiscard]] minifi::utils::SmallString<36> getUUIDStr() const;
5250

5351
protected:
5452
virtual MinifiStatus enableImpl(api::core::ControllerServiceContext&) = 0;
@@ -57,9 +55,6 @@ class ControllerServiceImpl {
5755
minifi::core::ControllerServiceMetadata metadata_;
5856

5957
std::shared_ptr<minifi::core::logging::Logger> logger_;
60-
61-
private:
62-
mutable std::mutex mutex_;
6358
};
6459

6560
} // namespace core

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@
1717
#pragma once
1818

1919
#include <atomic>
20-
#include <condition_variable>
2120
#include <memory>
22-
#include <mutex>
2321
#include <string>
2422
#include <vector>
2523

@@ -89,9 +87,6 @@ class ProcessorImpl {
8987
std::atomic<bool> trigger_when_empty_;
9088

9189
std::shared_ptr<minifi::core::logging::Logger> logger_;
92-
93-
private:
94-
mutable std::mutex mutex_;
9590
};
9691

9792
} // namespace core

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

Lines changed: 91 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -48,19 +48,14 @@ void useProcessorClassDescription(Fn&& fn) {
4848
std::vector<MinifiPropertyDefinition> class_properties = utils::toProperties(Class::Properties, string_vector_cache);
4949
std::vector<MinifiDynamicPropertyDefinition> dynamic_properties;
5050
for (auto& prop : Class::DynamicProperties) {
51-
dynamic_properties.push_back(MinifiDynamicPropertyDefinition {
52-
.name = utils::toStringView(prop.name),
53-
.value = utils::toStringView(prop.value),
54-
.description = utils::toStringView(prop.description),
55-
.supports_expression_language = prop.supports_expression_language
56-
});
51+
dynamic_properties.push_back(MinifiDynamicPropertyDefinition{.name = utils::toStringView(prop.name),
52+
.value = utils::toStringView(prop.value),
53+
.description = utils::toStringView(prop.description),
54+
.supports_expression_language = prop.supports_expression_language});
5755
}
5856
std::vector<MinifiRelationshipDefinition> relationships;
5957
for (auto& rel : Class::Relationships) {
60-
relationships.push_back(MinifiRelationshipDefinition{
61-
.name = utils::toStringView(rel.name),
62-
.description = utils::toStringView(rel.description)
63-
});
58+
relationships.push_back(MinifiRelationshipDefinition{.name = utils::toStringView(rel.name), .description = utils::toStringView(rel.description)});
6459
}
6560
std::vector<std::vector<MinifiStringView>> attribute_relationships_cache;
6661
std::vector<MinifiOutputAttributeDefinition> output_attributes;
@@ -69,80 +64,68 @@ void useProcessorClassDescription(Fn&& fn) {
6964
for (auto& rel : attr.relationships) {
7065
rel_cache.push_back(utils::toStringView(rel.name));
7166
}
72-
output_attributes.push_back(MinifiOutputAttributeDefinition {
73-
.name = utils::toStringView(attr.name),
74-
.relationships_count = gsl::narrow<uint32_t>(attr.relationships.size()),
75-
.relationships_ptr = rel_cache.data(),
76-
.description = utils::toStringView(attr.description)
77-
});
67+
output_attributes.push_back(MinifiOutputAttributeDefinition{.name = utils::toStringView(attr.name),
68+
.relationships_count = gsl::narrow<uint32_t>(attr.relationships.size()),
69+
.relationships_ptr = rel_cache.data(),
70+
.description = utils::toStringView(attr.description)});
7871
attribute_relationships_cache.push_back(std::move(rel_cache));
7972
}
8073

81-
MinifiProcessorClassDefinition description{
82-
.full_name = utils::toStringView(full_name),
83-
.description = utils::toStringView(Class::Description),
84-
.class_properties_count = gsl::narrow<uint32_t>(class_properties.size()),
85-
.class_properties_ptr = class_properties.data(),
86-
.dynamic_properties_count = gsl::narrow<uint32_t>(dynamic_properties.size()),
87-
.dynamic_properties_ptr = dynamic_properties.data(),
88-
.class_relationships_count = gsl::narrow<uint32_t>(relationships.size()),
89-
.class_relationships_ptr = relationships.data(),
90-
.output_attributes_count = gsl::narrow<uint32_t>(output_attributes.size()),
91-
.output_attributes_ptr = output_attributes.data(),
92-
.supports_dynamic_properties = Class::SupportsDynamicProperties,
93-
.supports_dynamic_relationships = Class::SupportsDynamicRelationships,
94-
.input_requirement = utils::toInputRequirement(Class::InputRequirement),
95-
.is_single_threaded = Class::IsSingleThreaded,
96-
97-
.callbacks = MinifiProcessorCallbacks{
98-
.create = [] (MinifiProcessorMetadata metadata) -> MINIFI_OWNED void* {
99-
return new Class{minifi::core::ProcessorMetadata{
100-
.uuid = minifi::utils::Identifier::parse(std::string{metadata.uuid.data, metadata.uuid.length}).value(),
101-
.name = std::string{metadata.name.data, metadata.name.length},
102-
.logger = std::make_shared<logging::Logger>(metadata.logger)
103-
}};
104-
},
105-
.destroy = [] (MINIFI_OWNED void* self) -> void {
106-
delete static_cast<Class*>(self);
107-
},
108-
.isWorkAvailable = [] (void* self) -> MinifiBool {
109-
return static_cast<Class*>(self)->isWorkAvailable();
110-
},
111-
.getTriggerWhenEmpty = [] (void* self) -> MinifiBool {
112-
return static_cast<Class*>(self)->getTriggerWhenEmpty();
113-
},
114-
.onTrigger = [] (void* self, MinifiProcessContext* context, MinifiProcessSession* session) -> MinifiStatus {
115-
ProcessContext context_wrapper(context);
116-
ProcessSession session_wrapper(session);
117-
try {
118-
return static_cast<Class*>(self)->onTrigger(context_wrapper, session_wrapper);
119-
} catch (...) {
120-
return MINIFI_STATUS_UNKNOWN_ERROR;
121-
}
122-
},
123-
.onSchedule = [] (void* self, MinifiProcessContext* context) -> MinifiStatus {
124-
ProcessContext context_wrapper(context);
125-
try {
126-
return static_cast<Class*>(self)->onSchedule(context_wrapper);
127-
} catch (...) {
128-
return MINIFI_STATUS_UNKNOWN_ERROR;
129-
}
130-
},
131-
.onUnSchedule = [] (void* self) -> void {
132-
static_cast<Class*>(self)->onUnSchedule();
133-
},
134-
.calculateMetrics = [] (void* self) -> MINIFI_OWNED MinifiPublishedMetrics* {
135-
auto metrics = static_cast<Class*>(self)->calculateMetrics();
136-
std::vector<MinifiStringView> names;
137-
std::vector<double> values;
138-
for (auto& [name, val] : metrics) {
139-
names.push_back(utils::toStringView(name));
140-
values.push_back(val);
141-
}
142-
return MinifiPublishedMetricsCreate(gsl::narrow<uint32_t>(metrics.size()), names.data(), values.data());
143-
}
144-
}
145-
};
74+
MinifiProcessorClassDefinition description{.full_name = utils::toStringView(full_name),
75+
.description = utils::toStringView(Class::Description),
76+
.class_properties_count = gsl::narrow<uint32_t>(class_properties.size()),
77+
.class_properties_ptr = class_properties.data(),
78+
.dynamic_properties_count = gsl::narrow<uint32_t>(dynamic_properties.size()),
79+
.dynamic_properties_ptr = dynamic_properties.data(),
80+
.class_relationships_count = gsl::narrow<uint32_t>(relationships.size()),
81+
.class_relationships_ptr = relationships.data(),
82+
.output_attributes_count = gsl::narrow<uint32_t>(output_attributes.size()),
83+
.output_attributes_ptr = output_attributes.data(),
84+
.supports_dynamic_properties = Class::SupportsDynamicProperties,
85+
.supports_dynamic_relationships = Class::SupportsDynamicRelationships,
86+
.input_requirement = utils::toInputRequirement(Class::InputRequirement),
87+
.is_single_threaded = Class::IsSingleThreaded,
88+
89+
.callbacks = MinifiProcessorCallbacks{
90+
.create = [](MinifiProcessorMetadata metadata) -> MINIFI_OWNED void* {
91+
try {
92+
return new Class{minifi::core::ProcessorMetadata{
93+
.uuid = minifi::utils::Identifier::parse(std::string{metadata.uuid.data, metadata.uuid.length}).value(),
94+
.name = std::string{metadata.name.data, metadata.name.length},
95+
.logger = std::make_shared<logging::Logger>(metadata.logger)}};
96+
} catch (...) { return nullptr; }
97+
},
98+
.destroy = [](MINIFI_OWNED void* self) -> void { delete static_cast<Class*>(self); },
99+
.isWorkAvailable = [](void* self) -> MinifiBool { return static_cast<Class*>(self)->isWorkAvailable(); },
100+
.getTriggerWhenEmpty = [](void* self) -> MinifiBool { return static_cast<Class*>(self)->getTriggerWhenEmpty(); },
101+
.onTrigger = [](void* self, MinifiProcessContext* context, MinifiProcessSession* session) -> MinifiStatus {
102+
ProcessContext context_wrapper(context);
103+
ProcessSession session_wrapper(session);
104+
try {
105+
return static_cast<Class*>(self)->onTrigger(context_wrapper, session_wrapper);
106+
} catch (...) { return MINIFI_STATUS_UNKNOWN_ERROR; }
107+
},
108+
.onSchedule = [](void* self, MinifiProcessContext* context) -> MinifiStatus {
109+
ProcessContext context_wrapper(context);
110+
try {
111+
return static_cast<Class*>(self)->onSchedule(context_wrapper);
112+
} catch (...) { return MINIFI_STATUS_UNKNOWN_ERROR; }
113+
},
114+
.onUnSchedule = [](void* self) -> void {
115+
try {
116+
static_cast<Class*>(self)->onUnSchedule();
117+
} catch (...) {}
118+
},
119+
.calculateMetrics = [](void* self) -> MINIFI_OWNED MinifiPublishedMetrics* {
120+
auto metrics = static_cast<Class*>(self)->calculateMetrics();
121+
std::vector<MinifiStringView> names;
122+
std::vector<double> values;
123+
for (auto& [name, val] : metrics) {
124+
names.push_back(utils::toStringView(name));
125+
values.push_back(val);
126+
}
127+
return MinifiPublishedMetricsCreate(gsl::narrow<uint32_t>(metrics.size()), names.data(), values.data());
128+
}}};
146129

147130
fn(description);
148131
}
@@ -155,40 +138,35 @@ void useControllerServiceClassDescription(Fn&& fn) {
155138

156139
std::vector<MinifiPropertyDefinition> class_properties = utils::toProperties(Class::Properties, string_vector_cache);
157140

158-
MinifiControllerServiceClassDefinition description{
159-
.full_name = utils::toStringView(full_name),
160-
.description = utils::toStringView(Class::Description),
161-
.class_properties_count = gsl::narrow<uint32_t>(class_properties.size()),
162-
.class_properties_ptr = class_properties.data(),
163-
164-
.callbacks = MinifiControllerServiceCallbacks{
165-
.create = [] (MinifiControllerServiceMetadata metadata) -> MINIFI_OWNED void* {
166-
return new Class{minifi::core::ControllerServiceMetadata{
167-
.uuid = minifi::utils::Identifier::parse(std::string{metadata.uuid.data, metadata.uuid.length}).value(),
168-
.name = std::string{metadata.name.data, metadata.name.length},
169-
.logger = std::make_shared<logging::Logger>(metadata.logger)
170-
}};
171-
},
172-
.destroy = [] (MINIFI_OWNED void* self) -> void {
173-
delete static_cast<Class*>(self);
174-
},
175-
.enable = [] (void* self, MinifiControllerServiceContext* context) -> MinifiStatus {
176-
ControllerServiceContext context_wrapper(context);
177-
try {
178-
return static_cast<Class*>(self)->enable(context_wrapper);
179-
} catch (...) {
180-
return MINIFI_STATUS_UNKNOWN_ERROR;
181-
}
182-
},
183-
.notifyStop = [] (void* self) -> void {
184-
static_cast<Class*>(self)->notifyStop();
185-
},
186-
}
187-
};
141+
MinifiControllerServiceClassDefinition description{.full_name = utils::toStringView(full_name),
142+
.description = utils::toStringView(Class::Description),
143+
.class_properties_count = gsl::narrow<uint32_t>(class_properties.size()),
144+
.class_properties_ptr = class_properties.data(),
145+
146+
.callbacks = MinifiControllerServiceCallbacks{
147+
.create = [](MinifiControllerServiceMetadata metadata) -> MINIFI_OWNED void* {
148+
try {
149+
return new Class{minifi::core::ControllerServiceMetadata{
150+
.uuid = minifi::utils::Identifier::parse(std::string{metadata.uuid.data, metadata.uuid.length}).value(),
151+
.name = std::string{metadata.name.data, metadata.name.length},
152+
.logger = std::make_shared<logging::Logger>(metadata.logger)}};
153+
} catch (...) { return nullptr; }
154+
},
155+
.destroy = [](MINIFI_OWNED void* self) -> void { delete static_cast<Class*>(self); },
156+
.enable = [](void* self, MinifiControllerServiceContext* context) -> MinifiStatus {
157+
ControllerServiceContext context_wrapper(context);
158+
try {
159+
return static_cast<Class*>(self)->enable(context_wrapper);
160+
} catch (...) { return MINIFI_STATUS_UNKNOWN_ERROR; }
161+
},
162+
.notifyStop = [](void* self) -> void {
163+
try {
164+
static_cast<Class*>(self)->notifyStop();
165+
} catch (...) {}
166+
},
167+
}};
188168

189169
fn(description);
190170
}
191171

192-
193-
194172
} // namespace org::apache::nifi::minifi::api::core

extension-framework/cpp-extension-lib/src/core/ControllerServiceContext.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,19 @@
2121
namespace org::apache::nifi::minifi::api::core {
2222

2323
nonstd::expected<std::string, std::error_code> ControllerServiceContext::getProperty(const std::string_view name) const {
24-
std::optional<std::string> value;
24+
std::optional<std::string> value = std::nullopt;
2525
const MinifiStatus status = MinifiControllerServiceContextGetProperty(impl_, utils::toStringView(name),
2626
[] (void* data, const MinifiStringView result) {
2727
(*static_cast<std::optional<std::string>*>(data)) = std::string(result.data, result.length);
2828
}, &value);
2929

30-
if (!value) {
30+
if (status != MINIFI_STATUS_SUCCESS) {
3131
return nonstd::make_unexpected(utils::make_error_code(status));
3232
}
33+
34+
if (!value) {
35+
return nonstd::make_unexpected(utils::make_error_code(MINIFI_STATUS_UNKNOWN_ERROR));
36+
}
3337
return value.value();
3438
}
3539

0 commit comments

Comments
 (0)