<?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 Re: Creating and transferring new flowFile ends with 'transfer relationship not specified' in Archives of Support Questions (Read Only)</title>
    <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Creating-and-transferring-new-flowFile-ends-with-transfer/m-p/237889#M85263</link>
    <description>&lt;P&gt;I figured there had to be a better way to do that, thanks &lt;A href="https://community.hortonworks.com/users/641/mburgess.html"&gt;@Matt Burgess&lt;/A&gt;!&lt;/P&gt;&lt;P&gt;Is there documentation on the different programming language API's that I'm missing? I've been working off of your excellent ExecuteScript cookbooks posted here, but beyond that I couldn't find in the documentation where I could have looked up something like session.remove().&lt;/P&gt;</description>
    <pubDate>Fri, 30 Nov 2018 02:57:49 GMT</pubDate>
    <dc:creator>ariffle</dc:creator>
    <dc:date>2018-11-30T02:57:49Z</dc:date>
    <item>
      <title>Creating and transferring new flowFile ends with 'transfer relationship not specified'</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Creating-and-transferring-new-flowFile-ends-with-transfer/m-p/237887#M85261</link>
      <description>&lt;P&gt;I'm trying to read a JSON from `flowFile` and add the contents as attribute keys in the empty `updated_flowFile`, but I get `transfer relationship not specified` even though I'm specifying it.&lt;/P&gt;&lt;PRE&gt;from org.apache.commons.io import IOUtils
from java.nio.charset import StandardCharsets
from org.apache.nifi.processor.io import InputStreamCallback
from org.apache.nifi.processor.io import OutputStreamCallback
import json

data = {}

# Read contents of flowFile and write contents to data{}
class PyInputStreamCallback(InputStreamCallback):
    def __init__(self):
        pass
    def process(self, inputStream):
        text = IOUtils.toString(inputStream, StandardCharsets.UTF_8)
        global data
        data = json.loads(text)

# Get incoming flowFile and call PyInputStreamCallback
flowFile = session.get()
if (flowFile != None):
    try:
        session.read(flowFile, PyInputStreamCallback())
        global data
        # Create a blank flowfile, update the attributes with contents of data{} and and write it to session
        updated_flowFile = session.create()
        updated_flowFile = session.putAttribute(updated_flowFile, 'left', data['left'])
        updated_flowFile = session.putAttribute(updated_flowFile, 'top', data['top'])
        session.close(flowFile)
        session.transfer(updated_flowFile, REL_SUCCESS)
    except:
        session.close(updated_flowFile)
        session.transfer(flowFile, REL_FAILURE)
else:
        session.transfer(flowFile, REL_FAILURE)&lt;/PRE&gt;&lt;P&gt;Alternatively, if there's a way to use the same flowFile object and wipe the JSON contents that would work too.  I am doing a mergeContent later in my pipeline so I need the contents to be totally empty except for the attributes I'm adding.&lt;/P&gt;</description>
      <pubDate>Thu, 29 Nov 2018 01:55:13 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Creating-and-transferring-new-flowFile-ends-with-transfer/m-p/237887#M85261</guid>
      <dc:creator>ariffle</dc:creator>
      <dc:date>2018-11-29T01:55:13Z</dc:date>
    </item>
    <item>
      <title>Re: Creating and transferring new flowFile ends with 'transfer relationship not specified'</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Creating-and-transferring-new-flowFile-ends-with-transfer/m-p/237888#M85262</link>
      <description>&lt;P&gt;A couple of notes:&lt;/P&gt;&lt;P&gt;1) There is no close() method on the session, I think you want remove(). &lt;/P&gt;&lt;P&gt;2) In your try block you are creating and transferring updated_flowFile, but you don't transfer or remove flowFile. If you replace close() with remove(), it should fix the "transfer relationship not specified" issue.&lt;/P&gt;&lt;P&gt;3) In your except block, you might need to check for updated_flowFile != None before you remove it. If the exception occurs before the updated_flowFile is created, the remove() might fail.&lt;/P&gt;&lt;P&gt;4) Consider using EvaluateJsonPath to extract the "left" and "top" attributes, then ReplaceText to clear the content. Then your provenance/lineage chain will remain intact. Jython is fairly slow so you may see a performance improvement by using EvaluateJsonPath -&amp;gt; ReplaceText&lt;/P&gt;</description>
      <pubDate>Thu, 29 Nov 2018 02:52:35 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Creating-and-transferring-new-flowFile-ends-with-transfer/m-p/237888#M85262</guid>
      <dc:creator>mburgess</dc:creator>
      <dc:date>2018-11-29T02:52:35Z</dc:date>
    </item>
    <item>
      <title>Re: Creating and transferring new flowFile ends with 'transfer relationship not specified'</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Creating-and-transferring-new-flowFile-ends-with-transfer/m-p/237889#M85263</link>
      <description>&lt;P&gt;I figured there had to be a better way to do that, thanks &lt;A href="https://community.hortonworks.com/users/641/mburgess.html"&gt;@Matt Burgess&lt;/A&gt;!&lt;/P&gt;&lt;P&gt;Is there documentation on the different programming language API's that I'm missing? I've been working off of your excellent ExecuteScript cookbooks posted here, but beyond that I couldn't find in the documentation where I could have looked up something like session.remove().&lt;/P&gt;</description>
      <pubDate>Fri, 30 Nov 2018 02:57:49 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Creating-and-transferring-new-flowFile-ends-with-transfer/m-p/237889#M85263</guid>
      <dc:creator>ariffle</dc:creator>
      <dc:date>2018-11-30T02:57:49Z</dc:date>
    </item>
    <item>
      <title>Re: Creating and transferring new flowFile ends with 'transfer relationship not specified'</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Creating-and-transferring-new-flowFile-ends-with-transfer/m-p/237890#M85264</link>
      <description>&lt;P&gt;We don't publish the javadocs for NiFi (&lt;A href="https://issues.apache.org/jira/browse/NIFI-943" target="_blank"&gt;yet&lt;/A&gt;), but you can get at them via javadoc.io (for example, the 1.8.0 nifi-api Javadocs are &lt;A href="http://javadoc.io/doc/org.apache.nifi/nifi-api/1.8.0" target="_blank"&gt;here&lt;/A&gt;). I've been thinking about adding a Part 4 to my cookbook, collecting examples from HCC articles and mailing list questions, to provide more coverage of the available APIs. Also check &lt;A href="https://funnifi.blogspot.com/" target="_blank"&gt;my blog&lt;/A&gt;, those articles are usually left-of-center usages of the API, perhaps to do things for which it wasn't necessarily intended, or to give external tools to help develop scripts (like my &lt;A href="http://funnifi.blogspot.com/2017/10/release-120-of-nifi-script-tester.html" target="_blank"&gt;script tester&lt;/A&gt;, e.g.)&lt;/P&gt;</description>
      <pubDate>Sat, 01 Dec 2018 02:23:49 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Creating-and-transferring-new-flowFile-ends-with-transfer/m-p/237890#M85264</guid>
      <dc:creator>mburgess</dc:creator>
      <dc:date>2018-12-01T02:23:49Z</dc:date>
    </item>
  </channel>
</rss>

