szaszm commented on code in PR #2220:
URL: https://github.com/apache/nifi-minifi-cpp/pull/2220#discussion_r3717596196
##########
minifi_rust/extensions/minifi_rs_playground/src/processors/generate_flow_file/properties.rs:
##########
@@ -15,64 +15,34 @@
// specific language governing permissions and limitations
// under the License.
-use minifi_native::{Property, StandardPropertyValidator};
+use super::DataFormat;
+use minifi_native::{DataSize, Property};
-pub(crate) const FILE_SIZE: Property = Property {
- name: "File Size",
- description: "The size of the file that will be used",
- is_required: true,
- is_sensitive: false,
- supports_expr_lang: true,
- default_value: Some("1 kB"),
- validator: StandardPropertyValidator::DataSizeValidator,
- allowed_values: &[],
- allowed_type: None,
-};
+pub(crate) const FILE_SIZE: Property<DataSize> =
+ Property::new("File Size", "The size of the file that will be used")
+ .supports_expression_language()
+ .with_default("1 kB");
-pub(crate) const BATCH_SIZE: Property = Property {
- name: "Batch Size",
- description: "The number of FlowFiles to be transferred in each
invocation",
- is_required: true,
- is_sensitive: false,
- supports_expr_lang: false,
- default_value: Some("1"),
- validator: StandardPropertyValidator::U64Validator,
- allowed_values: &[],
- allowed_type: None,
-};
+pub(crate) const BATCH_SIZE: Property<u64> = Property::new(
+ "Batch Size",
+ "The number of FlowFiles to be transferred in each invocation",
+)
+.with_default("1");
Review Comment:
shouldn't this be indented 2 levels as a continuation?
##########
minifi_rust/minifi_native/src/api/property.rs:
##########
@@ -16,102 +16,291 @@
// under the License.
use crate::StandardPropertyValidator::{
- BoolValidator, DataSizeValidator, TimePeriodValidator, U64Validator,
+ BoolValidator, DataSizeValidator, NonBlankValidator, TimePeriodValidator,
U64Validator,
};
use crate::{
ComponentIdentifier, ControllerServiceDefinition, EnableControllerService,
MinifiError,
};
+use std::marker::PhantomData;
use std::str::FromStr;
use std::time::Duration;
+use minifi_native::StandardPropertyValidator::{F64Validator, I64Validator};
#[derive(Debug, Eq, PartialEq)]
pub enum StandardPropertyValidator {
- AlwaysValidValidator,
NonBlankValidator,
TimePeriodValidator,
BoolValidator,
I64Validator,
U64Validator,
DataSizeValidator,
PortValidator,
+ F64Validator
}
-#[derive(Debug)]
-pub struct Property {
+#[derive(Debug, PartialEq)]
+pub enum PropertyConstraints {
+ Validator(StandardPropertyValidator),
+ AllowedValues(&'static [&'static str]),
+ ControllerService(&'static str),
+}
+
+pub struct PropertyDefinition {
pub name: &'static str,
pub description: &'static str,
pub is_required: bool,
pub is_sensitive: bool,
pub supports_expr_lang: bool,
pub default_value: Option<&'static str>,
- pub validator: StandardPropertyValidator,
- pub allowed_values: &'static [&'static str],
- pub allowed_type: Option<&'static str>,
+ pub constraints: Option<PropertyConstraints>,
}
-pub trait GetProperty {
- fn get_property(&self, property: &Property) -> Result<Option<String>,
MinifiError>;
- fn get_bool_property(&self, property: &Property) -> Result<Option<bool>,
MinifiError> {
- if property.validator != BoolValidator {
- return Err(MinifiError::validation_err(format!(
- "to use get_bool_property {:?} must have BoolValidator",
- property
- )));
- }
+#[macro_export]
+macro_rules! property_definitions {
+ ($($property:expr),* $(,)?) => {
+ &[$($property.definition()),*]
+ };
+}
+
+pub struct Property<K: ?Sized + PropertySchema> {
+ pub(crate) name: &'static str,
+ pub(crate) description: &'static str,
+ pub(crate) is_sensitive: bool,
+ pub(crate) supports_expr_lang: bool,
+ pub(crate) default_value: Option<&'static str>,
+ pub(crate) marker: PhantomData<K>,
+}
- if let Some(property_val) = self.get_property(property)? {
- Ok(Some(bool::from_str(&property_val)?))
- } else {
- Ok(None)
+impl<K: ?Sized + PropertySchema> Property<K> {
+ pub const fn new(name: &'static str, description: &'static str) -> Self {
+ Property {
+ name,
+ description,
+ is_sensitive: false,
+ supports_expr_lang: false,
+ default_value: None,
+ marker: PhantomData,
}
}
- fn get_duration_property(&self, property: &Property) ->
Result<Option<Duration>, MinifiError> {
- if property.validator != TimePeriodValidator {
- return Err(MinifiError::validation_err(format!(
- "to use get_duration_property {:?} must have
TimePeriodValidator",
- property
- )));
+ pub const fn sensitive(mut self) -> Self {
+ self.is_sensitive = true;
+ self
+ }
+
+ pub const fn supports_expression_language(mut self) -> Self {
+ self.supports_expr_lang = true;
+ self
+ }
+
+ pub const fn with_default(mut self, default_value: &'static str) -> Self {
+ self.default_value = Some(default_value);
+ self
+ }
+
+ pub const fn name(&self) -> &'static str {
+ self.name
+ }
+
+ pub const fn definition(&self) -> PropertyDefinition {
+ PropertyDefinition {
+ name: self.name,
+ description: self.description,
+ is_required: K::IS_REQUIRED || self.default_value.is_some(),
Review Comment:
I'd say don't try to be smart here, and wire it through directly. That way
if the C++ implementation changes behavior around edge cases (like #2241), the
Rust implementation will automatically work right too.
##########
minifi_rust/minifi_native/src/c_ffi/c_ffi_process_context.rs:
##########
@@ -65,9 +65,9 @@ unsafe extern "C" fn get_property_callback(
impl<'a> ProcessContext for CffiProcessContext<'a> {
type FlowFile = CffiFlowFile<'a>; // FlowFile shouldn't outlive the
ProcessContext
- fn get_property(
+ fn get_raw_property<K: PropertySchema + ?Sized>(
Review Comment:
What does K stand for? Key for something? Because I think that's supposed to
be the type of the property value, not the property key (name).
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]