Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions minifi_rust/extensions/minifi_rs_playground/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ hex = "0.4.3"
strum_macros = "0.28.0"
lipsum = "0.9.1"


[dev-dependencies]
tempfile = "3.22.0"
filetime = "0.2.26"
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ Feature: Testing controller service api casting
And the "Extra information" property of the Wolfie the magical controller service is set to "The dog (Canis familiaris or Canis lupus familiaris) is a domesticated descendant of wolves."
When the MiNiFi instance starts up

Then the Minifi logs contain the following message: "[minifi_rs_playground::processors::zoo_processor::ZooProcessorRs] [critical] Can DogControllerRs { has_jetpack: true, extra_info: "The dog (Canis familiaris or Canis lupus familiaris) is a domesticated descendant of wolves." } fly? true" in less than 10 seconds
Then the Minifi logs contain the following message: "[minifi_rs_playground::processors::zoo_processor::ZooProcessorRs] [critical] Can DogControllerRs { has_jetpack: true, extra_info: Some("The dog (Canis familiaris or Canis lupus familiaris) is a domesticated descendant of wolves.") } fly?" in less than 10 seconds
And the Minifi logs do not contain errors
And the Minifi logs do not contain warnings
30 changes: 15 additions & 15 deletions minifi_rust/extensions/minifi_rs_playground/minifi_rs_playground.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,24 +130,24 @@ RUST TEST PROCESSOR: Creates FlowFiles from files in a directory. MiNiFi will ig

In the list below, the names of required properties appear in bold. Any other properties (not in bold) are considered optional. The table also indicates any default values, and whether a property supports the NiFi Expression Language.

| Name | Default Value | Allowable Values | Description |
|-------------------------|---------------|------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------|
| **Batch Size** | 10 | | The maximum number of files to pull in each iteration |
| **Ignore Hidden Files** | true | true<br/>false | Indicates whether or not hidden files should be ignored |
| **Input Directory** | | | The input directory from which to pull files<br/>**Supports Expression Language: true** |
| Keep Source File | false | true<br/>false | If true, the file is not deleted after it has been copied to the Content Repository |
| Maximum File Age | | | The maximum age that a file must be in order to be pulled; any file older than this amount of time (according to last modification date) will be ignored |
| Maximum File Size | | | The maximum size that a file can be in order to be pulled |
| Minimum File Age | | | The minimum age that a file must be in order to be pulled; any file younger than this amount of time (according to last modification date) will be ignored |
| Minimum File Size | | | The minimum size that a file can be in order to be pulled |
| Polling Interval | | | Indicates how long to wait before performing a directory listing |
| Recurse Subdirectories | true | true<br/>false | Indicates whether or not to pull files from subdirectories |
| Name | Default Value | Allowable Values | Description |
|----------------------------|---------------|------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------|
| **Batch Size** | 10 | | The maximum number of files to pull in each iteration |
| **Ignore Hidden Files** | true | true<br/>false | Indicates whether or not hidden files should be ignored |
| **Input Directory** | | | The input directory from which to pull files<br/>**Supports Expression Language: true** |
| **Keep Source File** | false | true<br/>false | If true, the file is not deleted after it has been copied to the Content Repository |
| Maximum File Age | | | The maximum age that a file must be in order to be pulled; any file older than this amount of time (according to last modification date) will be ignored |
| Maximum File Size | | | The maximum size that a file can be in order to be pulled |
| Minimum File Age | | | The minimum age that a file must be in order to be pulled; any file younger than this amount of time (according to last modification date) will be ignored |
| Minimum File Size | | | The minimum size that a file can be in order to be pulled |
| Polling Interval | | | Indicates how long to wait before performing a directory listing |
| **Recurse Subdirectories** | true | true<br/>false | Indicates whether or not to pull files from subdirectories |

### Relationships

| Name | Description |
|---------|----------------------------------------------|
| success | FlowFiles are transferred here after logging |
| Name | Description |
|---------|--------------------------------------------|
| success | The created FlowFiles are transferred here |

### Output Attributes

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,42 +18,26 @@
use crate::controller_services::animal_controller_apis::{
CanFlyControllerApi, NumberOfLegsControllerApi,
};
use minifi_native::ControllerServiceApi;
use minifi_native::macros::ComponentIdentifier;
use minifi_native::{
ControllerServiceDefinition, EnableControllerService, GetProperty, Logger, MinifiError,
Property, ProvidedInterface, StandardPropertyValidator, create_provided_interface,
ControllerServiceApi, ControllerServiceDefinition, EnableControllerService, GetProperty,
Logger, MinifiError, Property, PropertyDefinition, ProvidedInterface,
create_provided_interface, property_definitions,
};

pub(crate) const HAS_JETPACK: Property = Property {
name: "Has Jetpack",
description: "Whether or not the dog has a jetpack",
is_required: true,
is_sensitive: false,
supports_expr_lang: false,
default_value: Some("false"),
validator: StandardPropertyValidator::BoolValidator,
allowed_values: &[],
allowed_type: None,
};
pub(crate) const HAS_JETPACK: Property<bool> =
Property::new("Has Jetpack", "Whether or not the dog has a jetpack").with_default("false");

pub(crate) const EXTRA_INFO: Property = Property {
name: "Extra information",
description: "We need this to verify the casting was done correctly",
is_required: false,
is_sensitive: false,
supports_expr_lang: false,
default_value: None,
validator: StandardPropertyValidator::AlwaysValidValidator,
allowed_values: &[],
allowed_type: None,
};
pub(crate) const EXTRA_INFO: Property<Option<String>> = Property::new(
"Extra information",
"We need this to verify the casting was done correctly",
);

#[allow(dead_code)] // extra_info is only used by {:?}
#[derive(Debug, ComponentIdentifier)]
pub(crate) struct DogControllerRs {
has_jetpack: bool,
extra_info: String,
extra_info: Option<String>,
}

impl NumberOfLegsControllerApi for DogControllerRs {
Expand All @@ -73,11 +57,8 @@ impl EnableControllerService for DogControllerRs {
where
Self: Sized,
{
let has_jetpack = context.get_bool_property(&HAS_JETPACK)?.ok_or(
MinifiError::missing_required_property("Has jetpack is required"),
)?;

let extra_info = context.get_property(&EXTRA_INFO)?.unwrap_or("".into());
let has_jetpack = context.get_property(&HAS_JETPACK)?;
let extra_info = context.get_property(&EXTRA_INFO)?;

Ok(Self {
has_jetpack,
Expand All @@ -88,7 +69,8 @@ impl EnableControllerService for DogControllerRs {

impl ControllerServiceDefinition for DogControllerRs {
const DESCRIPTION: &'static str = "RUST TEST CONTROLLER SERVICE: DogControllerRs";
const PROPERTIES: &'static [Property] = &[HAS_JETPACK, EXTRA_INFO];
const PROPERTIES: &'static [PropertyDefinition] =
property_definitions![HAS_JETPACK, EXTRA_INFO];
const PROVIDED_APIS: &'static [ProvidedInterface<Self>] = &[
create_provided_interface!(dyn CanFlyControllerApi),
create_provided_interface!(dyn NumberOfLegsControllerApi),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use minifi_native::ControllerServiceApi;
use minifi_native::macros::ComponentIdentifier;
use minifi_native::{
ControllerServiceDefinition, EnableControllerService, GetProperty, Logger, MinifiError,
Property, ProvidedInterface, create_provided_interface,
PropertyDefinition, ProvidedInterface, create_provided_interface,
};

#[derive(Debug, ComponentIdentifier)]
Expand Down Expand Up @@ -51,7 +51,7 @@ impl EnableControllerService for DuckControllerRs {

impl ControllerServiceDefinition for DuckControllerRs {
const DESCRIPTION: &'static str = "RUST TEST CONTROLLER SERVICE: DuckControllerRs";
const PROPERTIES: &'static [Property] = &[];
const PROPERTIES: &'static [PropertyDefinition] = &[];
const PROVIDED_APIS: &'static [ProvidedInterface<Self>] = &[
create_provided_interface!(dyn CanFlyControllerApi),
create_provided_interface!(dyn NumberOfLegsControllerApi),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
use minifi_native::macros::ComponentIdentifier;
use minifi_native::{
ControllerServiceDefinition, EnableControllerService, GetProperty, Logger, MinifiError,
Property, ProvidedInterface,
PropertyDefinition, ProvidedInterface,
};

#[derive(Debug, ComponentIdentifier)]
Expand All @@ -35,6 +35,6 @@ impl EnableControllerService for DummyControllerService {

impl ControllerServiceDefinition for DummyControllerService {
const DESCRIPTION: &'static str = "RUST TEST CONTROLLER SERVICE: Dummy Controller Service";
const PROPERTIES: &'static [Property] = &[];
const PROPERTIES: &'static [PropertyDefinition] = &[];
const PROVIDED_APIS: &'static [ProvidedInterface<Self>] = &[];
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,11 @@ use lipsum::lipsum;
use minifi_native::macros::ComponentIdentifier;
use minifi_native::{
ControllerServiceDefinition, EnableControllerService, GetProperty, Logger, MinifiError,
Property, ProvidedInterface, StandardPropertyValidator,
Property, PropertyDefinition, ProvidedInterface, property_definitions,
};

const LENGTH: Property = Property {
name: "Length",
description: "How many words to generate",
is_required: true,
is_sensitive: false,
supports_expr_lang: false,
default_value: Some("25"),
validator: StandardPropertyValidator::U64Validator,
allowed_values: &[],
allowed_type: None,
};
const LENGTH: Property<usize> =
Property::new("Length", "How many words to generate").with_default("25");

#[derive(Debug, ComponentIdentifier)]
pub(crate) struct LoremIpsumControllerService {
Expand All @@ -44,17 +35,13 @@ impl EnableControllerService for LoremIpsumControllerService {
where
Self: Sized,
{
let length = context
.get_u64_property(&LENGTH)?
.ok_or(MinifiError::missing_required_property("Length is required"))?;

let data = lipsum(length as usize);
let data = lipsum(context.get_property(&LENGTH)?);
Ok(Self { data })
}
}

impl ControllerServiceDefinition for LoremIpsumControllerService {
const DESCRIPTION: &'static str = "RUST TEST CONTROLLER SERVICE: Holds generated lorem ipsum";
const PROPERTIES: &'static [Property] = &[LENGTH];
const PROPERTIES: &'static [PropertyDefinition] = property_definitions![LENGTH];
const PROVIDED_APIS: &'static [ProvidedInterface<Self>] = &[];
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@

use crate::processors::asciify_german::AsciifyGerman;
use minifi_native::{
OutputAttribute, ProcessorDefinition, ProcessorInputRequirement, Property, Relationship,
OutputAttribute, ProcessorDefinition, ProcessorInputRequirement, PropertyDefinition,
Relationship,
};

impl ProcessorDefinition for AsciifyGerman {
Expand All @@ -28,5 +29,5 @@ impl ProcessorDefinition for AsciifyGerman {
const OUTPUT_ATTRIBUTES: &'static [OutputAttribute] = &[];
const RELATIONSHIPS: &'static [Relationship] =
&[super::relationships::SUCCESS, super::relationships::FAILURE];
const PROPERTIES: &'static [Property] = &[];
const PROPERTIES: &'static [PropertyDefinition] = &[];
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
use minifi_native::macros::ComponentIdentifier;
use minifi_native::{
GetProperty, Logger, MinifiError, MutTrigger, OnTriggerResult, OutputAttribute, ProcessContext,
ProcessSession, ProcessorDefinition, ProcessorInputRequirement, Property, Relationship,
Schedule, debug, info, trace,
ProcessSession, ProcessorDefinition, ProcessorInputRequirement, PropertyDefinition,
Relationship, Schedule, debug, info, trace,
};

#[derive(Debug, ComponentIdentifier)]
Expand Down Expand Up @@ -72,5 +72,5 @@ impl ProcessorDefinition for CountActualLogging {
const SUPPORTS_DYNAMIC_RELATIONSHIPS: bool = false;
const OUTPUT_ATTRIBUTES: &'static [OutputAttribute] = &[];
const RELATIONSHIPS: &'static [Relationship] = &[];
const PROPERTIES: &'static [Property] = &[];
const PROPERTIES: &'static [PropertyDefinition] = &[];
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use minifi_native::macros::ComponentIdentifier;
use minifi_native::{
GetAttribute, GetControllerService, GetProperty, InputStream, Logger, MinifiError,
MutFlowFileStreamTransform, OutputAttribute, OutputStream, ProcessorDefinition,
ProcessorInputRequirement, Property, Relationship, Schedule, TransformStreamResult,
ProcessorInputRequirement, PropertyDefinition, Relationship, Schedule, TransformStreamResult,
};
use std::collections::HashMap;

Expand Down Expand Up @@ -67,5 +67,5 @@ impl ProcessorDefinition for DuplicateStreamText {
const SUPPORTS_DYNAMIC_RELATIONSHIPS: bool = false;
const OUTPUT_ATTRIBUTES: &'static [OutputAttribute] = &[];
const RELATIONSHIPS: &'static [Relationship] = &[SUCCESS];
const PROPERTIES: &'static [Property] = &[];
const PROPERTIES: &'static [PropertyDefinition] = &[];
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,28 @@

// This is the (not production ready) reimplementation of the already existing standard GenerateFlowFile processor

use minifi_native::macros::ComponentIdentifier;
use minifi_native::macros::{ComponentIdentifier, PropertyType};
use minifi_native::{
GetProperty, Logger, MinifiError, OnTriggerResult, ProcessContext, ProcessSession, Schedule,
Trigger,
};
use rand::RngExt;
use rand::distr::Alphanumeric;
use std::cmp::PartialEq;
use strum_macros::{Display, EnumString, IntoStaticStr, VariantNames};

mod properties;
mod relationships;

#[derive(
Debug, Clone, Copy, PartialEq, Display, EnumString, VariantNames, IntoStaticStr, PropertyType,
)]
#[strum(const_into_str)]
pub(crate) enum DataFormat {
Text,
Binary,
}

#[derive(Debug, PartialEq)]
enum Mode {
UniqueBytes,
Expand All @@ -52,22 +62,12 @@ impl Schedule for GenerateFlowFileRs {
where
Self: Sized,
{
let is_unique = context
.get_bool_property(&properties::UNIQUE_FLOW_FILES)?
.expect("Required property");
let is_text = context
.get_property(&properties::DATA_FORMAT)?
.expect("Required property")
.as_str()
== "Text";
let is_unique = context.get_property(&properties::UNIQUE_FLOW_FILES)?;
let is_text = context.get_property(&properties::DATA_FORMAT)? == DataFormat::Text;
let has_custom_text = context.get_property(&properties::CUSTOM_TEXT)?.is_some();

let file_size = context
.get_size_property(&properties::FILE_SIZE)?
.expect("Required property");
let batch_size = context
.get_u64_property(&properties::BATCH_SIZE)?
.expect("Required property");
let file_size = context.get_property(&properties::FILE_SIZE)?;
let batch_size = context.get_property(&properties::BATCH_SIZE)?;

let mode = Self::get_mode(is_unique, is_text, has_custom_text, file_size);
let data_generated_during_on_schedule =
Expand Down Expand Up @@ -162,7 +162,7 @@ impl Trigger for GenerateFlowFileRs {
// flow files.
custom_text_for_batch = Some(
context
.get_property(&properties::CUSTOM_TEXT, None)?
.get_raw_property(&properties::CUSTOM_TEXT, None)?
.ok_or_else(|| {
MinifiError::trigger_err(
"GenerateFlowFile is in CustomText mode but the \"Custom Text\" \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
use super::properties::*;
use super::{GenerateFlowFileRs, relationships};
use minifi_native::{
OutputAttribute, ProcessorDefinition, ProcessorInputRequirement, Property, Relationship,
OutputAttribute, ProcessorDefinition, ProcessorInputRequirement, PropertyDefinition,
Relationship, property_definitions,
};

impl ProcessorDefinition for GenerateFlowFileRs {
Expand All @@ -28,11 +29,11 @@ impl ProcessorDefinition for GenerateFlowFileRs {
const SUPPORTS_DYNAMIC_RELATIONSHIPS: bool = false;
const OUTPUT_ATTRIBUTES: &'static [OutputAttribute] = &[];
const RELATIONSHIPS: &'static [Relationship] = &[relationships::SUCCESS];
const PROPERTIES: &'static [Property] = &[
const PROPERTIES: &'static [PropertyDefinition] = property_definitions![
FILE_SIZE,
BATCH_SIZE,
DATA_FORMAT,
UNIQUE_FLOW_FILES,
CUSTOM_TEXT,
CUSTOM_TEXT
];
}
Loading
Loading