Skip to content

Instantly share code, notes, and snippets.

@mattyb149
Created November 7, 2017 17:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save mattyb149/fa02e1060b0a6dc9f2a3c119863e862b to your computer and use it in GitHub Desktop.
Save mattyb149/fa02e1060b0a6dc9f2a3c119863e862b to your computer and use it in GitHub Desktop.
An InvokeScriptedProcessor template (in Jython) for running ExecuteScript Jython scripts faster
#////////////////////////////////////////////////////////////
#// imports go here
#////////////////////////////////////////////////////////////
from org.apache.nifi.processor import Processor,Relationship
from java.lang import Throwable
class E():
def __init__(self):
pass
def executeScript(self,session, context, log, REL_SUCCESS, REL_FAILURE):
#////////////////////////////////////////////////////////////
#// Replace 'pass' with your code
#////////////////////////////////////////////////////////////
pass
#end class
class JythonProcessor(Processor):
REL_SUCCESS = Relationship.Builder().name("success").description('FlowFiles that were successfully processed are routed here').build()
REL_FAILURE = Relationship.Builder().name("failure").description('FlowFiles that were not successfully processed are routed here').build()
log = None
e = E()
def initialize(self,context):
self.log = context.logger
def getRelationships(self):
return set([self.REL_SUCCESS, self.REL_FAILURE])
def validate(self,context):
pass
def onPropertyModified(self,descriptor, oldValue, newValue):
pass
def getPropertyDescriptors(self):
return []
def getIdentifier(self):
return None
def onTrigger(self,context, sessionFactory):
session = sessionFactory.createSession()
try:
self.e.executeScript(session, context, self.log, self.REL_SUCCESS, self.REL_FAILURE)
session.commit()
except Throwable, t:
self.log.error('{} failed to process due to {}; rolling back session', [self, t])
session.rollback(true)
raise t
#end class
processor = JythonProcessor()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment