Support Questions
Find answers, ask questions, and share your expertise
Announcements
Alert: Welcome to the Unified Cloudera Community. Former HCC members be sure to read and learn how to activate your account here.

nifi 1.8.0 executescript jython import error, works with a tester

nifi 1.8.0 executescript jython import error, works with a tester

New Contributor

I'm getting this error when I ran a jython script that includes an import statement. The import is a third party package "petl".

ExecuteScript[id=cea50562-0168-1000-c0d7-23905842e886] Failed to process session due to javax.script.ScriptException: java.lang.NoClassDefFoundError: java.lang.NoClassDefFoundError: Could not initialize class java.util.zip.Adler32 in <script> at line number 6: org.apache.nifi.processor.exception.ProcessException: javax.script.ScriptException: java.lang.NoClassDefFoundError: java.lang.NoClassDefFoundError: Could not initialize class java.util.zip.Adler32 in <script> at line number 6
I ran the same script using this excellent testing jar here and it works fine: https://bintray.com/mattyb149/maven/nifi-script-tester#files/mattyb149%2Fnifi-script-tester%2F1.2.0 I am running both nifi and the nifi-script-tester using the same java version (oracle java 8).
 
java -jar nifi-script-tester-1.2.0-all.jar -all -input=./test -modules=/home/kundeng/Dropbox/Dev/work_nifi_prime/petl-1.2.0 testjython.py
Flow file FlowFile[0,example.csv,24B]
---------------------------------------------------------
FlowFile Attributes
Key: 'entryDate'
        Value: 'Fri Feb 08 16:09:36 EST 2019'
Key: 'lineageStartDate'
        Value: 'Fri Feb 08 16:09:36 EST 2019'
Key: 'fileSize'
        Value: '24'
FlowFile Attribute Map Content
Key: 'path'
        Value: 'target'
Key: 'filename'
        Value: 'example.csv'
Key: 'uuid'
        Value: 'b538e232-cb5b-49c3-b702-047993b4ea39'
---------------------------------------------------------
foo, bar, baz
a,1,3.4
The script is here:
from org.apache.commons.io import IOUtils
from java.nio.charset import StandardCharsets
from org.apache.nifi.processor.io import StreamCallback
# test whether jython module path works
import petl as etl
# Define a subclass of StreamCallback for use in session.write()
class PyStreamCallback(StreamCallback):
  def __init__(self):
        pass
  def process(self, inputStream, outputStream):
    text = IOUtils.toString(inputStream, StandardCharsets.UTF_8)
    tbl = etl.fromcsv(etl.MemorySource(text))
    tbl = tbl.head(1)
    a=etl.MemorySource('')
    tbl.tocsv(a)
    outputStream.write(bytearray(a.getvalue().encode('utf-8')))
# end class
flowFile = session.get()
if(flowFile != None):
    flowFile = session.write(flowFile, PyStreamCallback())
    session.transfer(flowFile,REL_SUCCESS)
    session.commit()
# implicit return at the end
1 REPLY 1

Re: nifi 1.8.0 executescript jython import error, works with a tester

Did you set the Module Directory property to /home/kundeng/Dropbox/Dev/work_nifi_prime/petl-1.2.0 ?