Matt, this eliminated the problem. Thanks again for your help. I didn't
realize returning None from getPropertyDescriptors(self) would throw this
error, but now I know. I added
emptyList=[]
return emptyList
I've been monitoring nifi-app.log with a tail -f.  None of these ERRORs are
posting now. Thank you sir.
Cheers,
Jim

On Mon, Apr 3, 2017 at 5:59 PM, Matt Burgess <[email protected]> wrote:

> Sorry empty List.
>
> Sent from my iPhone
>
> On Apr 3, 2017, at 5:52 PM, Matt Burgess <[email protected]> wrote:
>
> Jim,
>
> I'm not at my keyboard but I'm guessing it is a NullPointerException from
> returning None from getPropertyDescriptors(), try returning an empty PyMap
> instead.
>
> Regards,
> Matt
>
> Sent from my iPhone
>
> On Apr 3, 2017, at 5:35 PM, James McMahon <[email protected]> wrote:
>
> Good evening. I am trying to get this simple update attribute function to
> work in an InvokeScriptedProcessor ....processor. I wish to initialize
> custom logging to a distinct log file specifically associated with this
> processor. While updating an attribute is (should be) a very simple case,
> it seems that making the ISP work with this custom directed logging is not.
>
> I was able to get a simple filename attribute change to work, but a
> particular ERROR gets thrown each and every time the ISP wkaes up and
> checks for flowfiles to process. The error is this:
>
> 2017-04-03 10:59:31,370 ERROR [Timer-Driven Process Thread-4]
> o.a.n.p.script.InvokeScriptedProcessor InvokeScriptedProcessor[id=1f379.....]
> Unable to get property descriptors from Processor: java.lang.reflect.
> UndeclaredThrowableException
>
> I am running NiFi 0.7.1.
>
> Either there is something obvious that I've done wrong in the following
> code or I'm not using ISP properly. I did research this error and found a
> link that appeared to be directly related (at Hortonworks), but
> unfortunately when I incorporated the change to PySet it did not resolve my
> issue. Here is that link in case you are interested:
> https://community.hortonworks.com/questions/75420/
> invokescriptedprocessor-in-python.html
>
> I also want to point out that I found this approach documented here, and
> referenced by Matt. B:
> https://github.com/apache/nifi/blob/master/nifi-nar-
> bundles/nifi-scripting-bundle/nifi-scripting-processors/src/
> test/resources/jython/test_update_attribute.py
>
> Please note that I had to recreate my code here. Typos if found are not in
> the code but are introduced by my mad typing "skills" here.
>
> Anyone encounter and fix such a problem, eliminating this error? Thanks in
> advance for any help. Code shown below. -Jim
>
> # Approach:
> # First, get a simple attribute to update (DONE)
> # Second, add directed logging to a specific file (getting many of the
> ERRORs detailed above)
> # Third, expand on the update attribute concept to select a small subset
> of attributes, form them into a json object, and replace the existing
> flowfile payload with that
>
> import sys
> import traceback
> import logging
> from org.apache.nifi.processor import Processor
> from org.apache.nifi.processor import Relationship
> from org.apache.nifi.components import PropertyDescriptor
> from org.apache.nifi.processor.util import StandardValidators
> from org.python.core import PySet
>
> class UpdateAttributes(Processor) :
>      #__rel_success = Relationship.Builder().description("Success").name("
> success".build()
>      def __init__(self) :
>           self.__rel_success = Relationship.Builder().
> description("Success").name("success".build()
>           self.log = None
>
>      def initialize(self,context) :
>           try :
>                LOG_FILENAME='/home/nifi/latest/logs/TestLog.log'
>                # Still tbd:
>                # FORMAT='%(asctime)-15s %(message)s'
>                # formatter = logging.Formatter('%(asctime)-15s
> %(message)s)'
>                # self.log = context.getLogger()
>                # handler = context.FileHandler(LOG_FILENAME)
>                # handler.setFormatter(formatter)
>                #self.addHandler(handler)
>           except :
>                pass
>
>      def getRelationships(self) :
>           return PySet([self.__rel_success])
>
>      def validate(self,context) :
>           return None
>
>      def getPropertyDescriptor(self) :
>           return None
>           # try :
>           #      descriptor = PropertyDescriptor.Builder().
> name("filename").addValidators(StandardValidators.NON_EMPTY_
> VALIDATOR).build()
>           #      return [descriptor]
>           # except :
>           #      pass
>
>      def getPropertyDescriptors(self) :
>           return None
>
>      def onPropertyModified(self,descriptor,newValue,oldValue) :
>           pass
>
>      def onTrigger(self,context,sessionFactory) :
>           session = sessionFactory.createSession()
>           try :
>                # ensure there is work to do
>                flowfile = session.,get()
>                if flowfile is None :
>                     return
>
>                # extract some attribute value of interest
>                # fromPropertyValue = context.getProperty("for-
> attributes").getValue()
>                fromAttributeValue = flowfile.getAttribute("filename")
>
>                # set our attribute to the desired new value
>                # flowfile = session.putAttribute(flowfile,
> "from-property", fromPropertyValue)
>                flowfile = session.putAttribute(flowfile, "filename",
> "LARRY_CURLEY_MOE")
>
>                # transfer
>                session.transfer(flowfile, self.__rel_success)
>                session.commit()
>           except:
>                session.rollback()
>                raise
>
> processor = UpdateAttributes()
>
>

Reply via email to