Dynamic Properties in ExecuteScript
ExecuteScript processors support dynamic properties, which allow users to define custom property names and values. These properties are passed as variables to the script, with each property represented as a PropertyValue object.
Key Considerations:
- Property names must conform to the target language's variable naming rules
- PropertyValue objects provide methods to handle Expression Language and type conversion
Accessing Dynamic Property Values
To retrieve a dynamic property value in your script:
Groovy Example
def configParam = dynamicProperty.value
Python Example
config_param = dynamic_property.getValue()
Module Management
ExecuteScript supports adding external modules to enhance functionality:
Java Libraries (JARs)
// Module Directory property accepts comma-separated JAR paths
// Example for Groovy:
def result = new ExternalLibrary().process(data)
Python Modules
# Python example
import sys
sys.path.append('/path/to/modules')
from custom_module import process_data
State Management
NiFi provides state persistence for processors through StateManager:
Retrieving State
// Groovy example
def currentState = context.stateManager.getState(Scope.LOCAL).toMap()
Updating State
// JavaScript example
var newState = {'timestamp': Date.now()};
stateManager.setState(newState, Scope.CLUSTER);
Clearing State
# Python example
context.stateManager.clear(Scope.LOCAL)
Controller Services Integrtaion
Accessing controller services from scripts:
Distributed Cache Example
// Groovy cache client example
def cacheClient = serviceId.asControllerService(DistributedMapCacheClient)
def value = cacheClient.get('key', stringSerializer, stringDeserializer)
Custom Serializer Implementation
// JavaScript serializer example
var StringSerializer = new Serializer(function(val, output) {
output.write(val.getBytes("UTF-8"));
});