@Tags(value={"script","invoke","groovy","python","jython","jruby","ruby","javascript","js","lua","luaj"}) @CapabilityDescription(value="Experimental - Invokes a script engine for a Processor defined in the given script. The script must define a valid class that implements the Processor interface, and it must set a variable \'processor\' to an instance of the class. Processor methods such as onTrigger() will be delegated to the scripted Processor instance. Also any Relationships or PropertyDescriptors defined by the scripted processor will be added to the configuration dialog. The scripted processor can implement public void setLogger(ComponentLog logger) to get access to the parent logger, as well as public void onScheduled(ProcessContext context) and public void onStopped(ProcessContext context) methods to be invoked when the parent InvokeScriptedProcessor is scheduled or stopped, respectively. Experimental: Impact of sustained usage not yet verified.") @DynamicProperty(name="A script engine property to update", value="The value to set it to", expressionLanguageScope=FLOWFILE_ATTRIBUTES, description="Updates a script engine property specified by the Dynamic Property\'s key with the value specified by the Dynamic Property\'s value") @Stateful(scopes={LOCAL,CLUSTER}, description="Scripts can store and retrieve state using the State Management APIs. Consult the State Manager section of the Developer\'s Guide for more details.") @SeeAlso(value=ExecuteScript.class) @Restricted(restrictions=@Restriction(requiredPermission=EXECUTE_CODE,explanation="Provides operator the ability to execute arbitrary code assuming all permissions that NiFi has.")) public class InvokeScriptedProcessor extends AbstractSessionFactoryProcessor
| Modifier and Type | Field and Description |
|---|---|
private File |
kerberosConfigFile |
private File |
kerberosServiceKeytab |
private String |
kerberosServicePrincipal |
private AtomicReference<Processor> |
processor |
private ScriptEngine |
scriptEngine |
(package private) ScriptingComponentHelper |
scriptingComponentHelper |
private AtomicBoolean |
scriptNeedsReload |
private AtomicReference<Collection<ValidationResult>> |
validationResults |
| Constructor and Description |
|---|
InvokeScriptedProcessor() |
| Modifier and Type | Method and Description |
|---|---|
void |
added() |
protected Collection<ValidationResult> |
customValidate(ValidationContext context)
Invokes the validate() routine provided by the script, allowing for
custom validation code.
|
Set<Relationship> |
getRelationships()
Returns the valid relationships for this processor as supplied by the
script itself.
|
protected PropertyDescriptor |
getSupportedDynamicPropertyDescriptor(String propertyDescriptorName)
Returns a PropertyDescriptor for the given name.
|
protected List<PropertyDescriptor> |
getSupportedPropertyDescriptors()
Returns a list of property descriptors supported by this processor.
|
protected void |
init(ProcessorInitializationContext context) |
private void |
invokeScriptedProcessorMethod(String methodName,
Object... params) |
void |
onPropertyModified(PropertyDescriptor descriptor,
String oldValue,
String newValue)
Handles changes to this processor's properties.
|
void |
onTrigger(ProcessContext context,
ProcessSessionFactory sessionFactory)
Invokes the onTrigger() method of the scripted processor.
|
private boolean |
reloadScript(String scriptBody)
Reloads the script Processor.
|
private boolean |
reloadScriptBody(String scriptBody)
Reloads the script defined by the given string
|
private boolean |
reloadScriptFile(String scriptPath)
Reloads the script located at the given path
|
void |
setup() |
void |
setup(ProcessContext context)
Performs setup operations when the processor is scheduled to run.
|
void |
stop(ProcessContext context) |
getControllerServiceLookup, getIdentifier, getLogger, getNodeTypeProvider, initialize, isConfigurationRestored, isScheduled, toString, updateConfiguredRestoredTrue, updateScheduledFalse, updateScheduledTrueequals, getPropertyDescriptor, getPropertyDescriptors, hashCode, validateclone, finalize, getClass, notify, notifyAll, wait, wait, waitgetPropertyDescriptor, getPropertyDescriptors, validateprivate final AtomicReference<Processor> processor
private final AtomicReference<Collection<ValidationResult>> validationResults
private final AtomicBoolean scriptNeedsReload
private volatile ScriptEngine scriptEngine
private volatile String kerberosServicePrincipal
private volatile File kerberosConfigFile
private volatile File kerberosServiceKeytab
volatile ScriptingComponentHelper scriptingComponentHelper
public Set<Relationship> getRelationships()
getRelationships in interface ProcessorgetRelationships in class AbstractSessionFactoryProcessorprotected void init(ProcessorInitializationContext context)
init in class AbstractSessionFactoryProcessorprotected List<PropertyDescriptor> getSupportedPropertyDescriptors()
getSupportedPropertyDescriptors in class AbstractConfigurableComponentprotected PropertyDescriptor getSupportedDynamicPropertyDescriptor(String propertyDescriptorName)
getSupportedDynamicPropertyDescriptor in class AbstractConfigurableComponentpropertyDescriptorName - used to lookup if any property descriptors
exist for that name@OnScheduled public void setup(ProcessContext context)
context - the context in which to perform the setup operationspublic void setup()
public void onPropertyModified(PropertyDescriptor descriptor, String oldValue, String newValue)
onPropertyModified in interface ConfigurableComponentonPropertyModified in class AbstractConfigurableComponentdescriptor - of the modified propertyoldValue - non-null property value (previous)newValue - the new property value or if null indicates the propertyprivate boolean reloadScriptFile(String scriptPath)
scriptPath - the path to the script file to be loadedprivate boolean reloadScriptBody(String scriptBody)
scriptBody - the contents of the script to be loadedprivate boolean reloadScript(String scriptBody)
scriptBody - An input stream associated with the script contentprotected Collection<ValidationResult> customValidate(ValidationContext context)
customValidate in class AbstractConfigurableComponentcontext - The validation context to be passed into the custom
validate methodpublic void onTrigger(ProcessContext context, ProcessSessionFactory sessionFactory) throws ProcessException
context - provides access to convenience methods for obtaining
property values, delaying the scheduling of the processor, provides
access to Controller Services, etc.sessionFactory - provides access to a ProcessSessionFactory,
which can be used for accessing FlowFiles, etc.ProcessException - if the scripted processor's onTrigger() method
throws an exception@OnAdded public void added()
@OnStopped public void stop(ProcessContext context)
Copyright © 2021 Apache NiFi Project. All rights reserved.