<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>question InvokeScriptedProcessor in Python in Archives of Support Questions (Read Only)</title>
    <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/InvokeScriptedProcessor-in-Python/m-p/105763#M50481</link>
    <description>&lt;P&gt;I'm trying to port this &lt;A target="_blank" href="http://funnifi.blogspot.co.il/2016/02/invokescriptedprocessor-hello-world.html"&gt;InvokeScriptedProcessor - Hello World!&lt;/A&gt; into Python. The Groovy example uses Generics in some of the methods like&lt;/P&gt;&lt;PRE&gt;Set&amp;lt;Relationship&amp;gt; getRelationships() {
	return [REL_SUCCESS] as Set
}

@Override
Collection&amp;lt;ValidationResult&amp;gt; validate(ValidationContext context) { return null }

List&amp;lt;PropertyDescriptor&amp;gt; getPropertyDescriptors() { return null }
&lt;/PRE&gt;&lt;P&gt;How can I port this to Python?&lt;/P&gt;&lt;P&gt;I tried to return Java's HashSet like&lt;/P&gt;&lt;PRE&gt;def getRelationships(self):
    set = HashSet()
    set.add(self.REL_SUCCESS)
    return set&lt;/PRE&gt;&lt;P&gt;and then I am getting &lt;STRONG&gt;&lt;EM&gt;2016-12-30 12:04:10,829 ERROR [NiFi Web Server-139] o.a.n.p.script.InvokeScriptedProcessor InvokeScriptedProcessor[id=4eb16182-0159-1000-dc3a-531dc23b13e6] Unable to get relationships from scripted Processor: java.lang.reflect.UndeclaredThrowableException&lt;/EM&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;I also tried Python's Set like&lt;/P&gt;&lt;PRE&gt;def getRelationships(self):
    return Set([self.REL_SUCCESS,])&lt;/PRE&gt;&lt;P&gt;In this case I received &lt;EM&gt;&lt;STRONG&gt;2016-12-30 11:04:50,588 ERROR [Timer-Driven Process Thread-8] o.a.n.p.script.InvokeScriptedProcessor InvokeScriptedProcessor[id=4eb16182-0159-1000-dc3a-531dc23b13e6] Unable to get relationships from scripted Processor: java.lang.ClassCastException: org.python.core.PyObjectDerived cannot be cast to java.util.Set&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;Here's a complete code so far:&lt;/P&gt;&lt;PRE&gt;import java.util
from org.apache.nifi.processor import Processor, Relationship
from sets import Set


class PythonProcessor(Processor):
    def __init__(self):
        self.REL_SUCCESS = Relationship.Builder().name("success").description("FlowFiles that were successfully processed").build()
        self.log = None

    def initialize(self, context):
        self.log = context.getLogger()

    def getRelationships(self):
        return Set([self.REL_SUCCESS])

    def validate(self, context):
        return None

    def getPropertyDescriptor(self, name):
        return None

    def getPropertyDescriptors(self):
        return None

    def validate(self, context):
        return None

    def onPropertyModified(self, descriptor, oldValue, newValue):
        pass

    def getIdentifier(self):
        return None

processor = PythonProcessor()&lt;/PRE&gt;&lt;P&gt;I will appreciate any help&lt;/P&gt;</description>
    <pubDate>Fri, 30 Dec 2016 16:31:00 GMT</pubDate>
    <dc:creator>michael_kalika</dc:creator>
    <dc:date>2016-12-30T16:31:00Z</dc:date>
    <item>
      <title>InvokeScriptedProcessor in Python</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/InvokeScriptedProcessor-in-Python/m-p/105763#M50481</link>
      <description>&lt;P&gt;I'm trying to port this &lt;A target="_blank" href="http://funnifi.blogspot.co.il/2016/02/invokescriptedprocessor-hello-world.html"&gt;InvokeScriptedProcessor - Hello World!&lt;/A&gt; into Python. The Groovy example uses Generics in some of the methods like&lt;/P&gt;&lt;PRE&gt;Set&amp;lt;Relationship&amp;gt; getRelationships() {
	return [REL_SUCCESS] as Set
}

@Override
Collection&amp;lt;ValidationResult&amp;gt; validate(ValidationContext context) { return null }

List&amp;lt;PropertyDescriptor&amp;gt; getPropertyDescriptors() { return null }
&lt;/PRE&gt;&lt;P&gt;How can I port this to Python?&lt;/P&gt;&lt;P&gt;I tried to return Java's HashSet like&lt;/P&gt;&lt;PRE&gt;def getRelationships(self):
    set = HashSet()
    set.add(self.REL_SUCCESS)
    return set&lt;/PRE&gt;&lt;P&gt;and then I am getting &lt;STRONG&gt;&lt;EM&gt;2016-12-30 12:04:10,829 ERROR [NiFi Web Server-139] o.a.n.p.script.InvokeScriptedProcessor InvokeScriptedProcessor[id=4eb16182-0159-1000-dc3a-531dc23b13e6] Unable to get relationships from scripted Processor: java.lang.reflect.UndeclaredThrowableException&lt;/EM&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;I also tried Python's Set like&lt;/P&gt;&lt;PRE&gt;def getRelationships(self):
    return Set([self.REL_SUCCESS,])&lt;/PRE&gt;&lt;P&gt;In this case I received &lt;EM&gt;&lt;STRONG&gt;2016-12-30 11:04:50,588 ERROR [Timer-Driven Process Thread-8] o.a.n.p.script.InvokeScriptedProcessor InvokeScriptedProcessor[id=4eb16182-0159-1000-dc3a-531dc23b13e6] Unable to get relationships from scripted Processor: java.lang.ClassCastException: org.python.core.PyObjectDerived cannot be cast to java.util.Set&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;Here's a complete code so far:&lt;/P&gt;&lt;PRE&gt;import java.util
from org.apache.nifi.processor import Processor, Relationship
from sets import Set


class PythonProcessor(Processor):
    def __init__(self):
        self.REL_SUCCESS = Relationship.Builder().name("success").description("FlowFiles that were successfully processed").build()
        self.log = None

    def initialize(self, context):
        self.log = context.getLogger()

    def getRelationships(self):
        return Set([self.REL_SUCCESS])

    def validate(self, context):
        return None

    def getPropertyDescriptor(self, name):
        return None

    def getPropertyDescriptors(self):
        return None

    def validate(self, context):
        return None

    def onPropertyModified(self, descriptor, oldValue, newValue):
        pass

    def getIdentifier(self):
        return None

processor = PythonProcessor()&lt;/PRE&gt;&lt;P&gt;I will appreciate any help&lt;/P&gt;</description>
      <pubDate>Fri, 30 Dec 2016 16:31:00 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/InvokeScriptedProcessor-in-Python/m-p/105763#M50481</guid>
      <dc:creator>michael_kalika</dc:creator>
      <dc:date>2016-12-30T16:31:00Z</dc:date>
    </item>
    <item>
      <title>Re: InvokeScriptedProcessor in Python</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/InvokeScriptedProcessor-in-Python/m-p/105764#M50482</link>
      <description>&lt;P&gt;I found the solution. Looks like Set is not automatically translated to corresponding PySet class in Jython. Here's the solution in case someone else encounters the same:&lt;/P&gt;&lt;PRE&gt;from org.apache.nifi.processor import Processor, Relationship
from org.python.core import PySet


class PythonProcessor(Processor):
    def __init__(self):
        self.REL_SUCCESS = Relationship.Builder().name("success").description("FlowFiles that were successfully processed").build()
        self.REL_FAILURE = Relationship.Builder().name("failure").description("FlowFiles that failed to be processed").build()
        self.REL_UNMATCH = Relationship.Builder().name("unmatch").description("FlowFiles that did not match rules").build()
        self.log = None

    def initialize(self, context):
        self.log = context.getLogger()

    def getRelationships(self):
        return PySet([self.REL_SUCCESS, self.REL_FAILURE, self.REL_UNMATCH])

    def validate(self, context):
        return None

    def getPropertyDescriptor(self, name):
        return None

    def getPropertyDescriptors(self):
        return None

    def validate(self, context):
        return None

    def onPropertyModified(self, descriptor, oldValue, newValue):
        pass

    def getIdentifier(self):
        return None

processor = PythonProcessor()&lt;/PRE&gt;</description>
      <pubDate>Fri, 30 Dec 2016 18:30:57 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/InvokeScriptedProcessor-in-Python/m-p/105764#M50482</guid>
      <dc:creator>michael_kalika</dc:creator>
      <dc:date>2016-12-30T18:30:57Z</dc:date>
    </item>
    <item>
      <title>Re: InvokeScriptedProcessor in Python</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/InvokeScriptedProcessor-in-Python/m-p/105765#M50483</link>
      <description>&lt;P&gt;There are some examples of InvokedScriptedProcessor using Jython in the &lt;A target="_blank" href="https://github.com/apache/nifi/tree/master/nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/test/resources/jython"&gt;unit tests here&lt;/A&gt;. The examples use set() (not Set(), I don't know if there's a difference there between the return types or not)&lt;/P&gt;</description>
      <pubDate>Fri, 30 Dec 2016 21:55:38 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/InvokeScriptedProcessor-in-Python/m-p/105765#M50483</guid>
      <dc:creator>mburgess</dc:creator>
      <dc:date>2016-12-30T21:55:38Z</dc:date>
    </item>
  </channel>
</rss>

