<?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 Creating multiple flow files and ExecuteScript error handling in Support Questions</title>
    <link>https://community.cloudera.com/t5/Support-Questions/Creating-multiple-flow-files-and-ExecuteScript-error/m-p/236790#M198603</link>
    <description>&lt;P&gt;If I am in the process of creating multiple flow files during an ExecuteScript processor, and an error occurs before I'm done, I transfer the original flow file to its failure relationship.  My doubt, however, is whether or not I have to do anything with the flow files that I've created thus far.&lt;/P&gt;&lt;P&gt;Consider, for example, the following groovy:&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;def flowFile = session.get()&lt;/P&gt;&lt;P&gt;if (!flowFile) return&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;def filesDir = flowFile.getAttribute('filesDirectory')&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;// See &lt;A href="https://community.hortonworks.com/questions/106878/split-one-nifi-flow-file-into-multiple-flow-file-b.html" target="_blank"&gt;https://community.hortonworks.com/questions/106878/split-one-nifi-flow-file-into-multiple-flow-file-b.html&lt;/A&gt;&lt;/P&gt;&lt;P&gt;def flowFiles = [] as List&amp;lt;FlowFile&amp;gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;try {&lt;!-- --&gt;&lt;/P&gt;&lt;P&gt;    // Get a list of all the trades in the portfolio directory.&lt;/P&gt;&lt;P&gt;    File folder = new File(filesDir);&lt;/P&gt;&lt;P&gt;    File[] listOfFiles = folder.listFiles();&lt;/P&gt;&lt;P&gt;    &lt;/P&gt;&lt;P&gt;    for (File file : listOfFiles) {&lt;!-- --&gt;&lt;/P&gt;&lt;P&gt;        if (file.isFile()) {&lt;!-- --&gt;&lt;/P&gt;&lt;P&gt;            // Create a new flow file with that single trade.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;            def newFlowFile = session.create(flowFile)&lt;/P&gt;&lt;P&gt;            flowFiles &amp;lt;&amp;lt; newFlowFile&lt;/P&gt;&lt;P&gt;            &lt;/P&gt;&lt;P&gt;            // put some attributes here, or do something that might throw an exception&lt;/P&gt;&lt;P&gt;            &lt;/P&gt;&lt;P&gt;        }&lt;/P&gt;&lt;P&gt;    }&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;catch (e) {&lt;!-- --&gt;&lt;/P&gt;&lt;P&gt;    session.transfer(flowFile, REL_FAILURE)&lt;/P&gt;&lt;P&gt;    return&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;session.remove(flowFile)&lt;/P&gt;&lt;P&gt;session.transfer(flowFiles, REL_SUCCESS)&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;My doubt is whether or not I need something like this in the "catch" block:&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;catch (e) {&lt;!-- --&gt;&lt;/P&gt;&lt;P&gt;    // is this necessary?&lt;/P&gt;&lt;P&gt;    for (FlowFile theFlowFile : flowFiles) {&lt;!-- --&gt;&lt;/P&gt;&lt;P&gt;        session.remove(theFlowFile)&lt;/P&gt;&lt;P&gt;    }&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;    session.transfer(flowFile, REL_FAILURE)&lt;/P&gt;&lt;P&gt;    return&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;...or will the session automatically clean them up on the basis that they haven't been directed to any relationship?&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 26 Mar 2019 08:14:12 GMT</pubDate>
    <dc:creator>sean_dockery</dc:creator>
    <dc:date>2019-03-26T08:14:12Z</dc:date>
    <item>
      <title>Creating multiple flow files and ExecuteScript error handling</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Creating-multiple-flow-files-and-ExecuteScript-error/m-p/236790#M198603</link>
      <description>&lt;P&gt;If I am in the process of creating multiple flow files during an ExecuteScript processor, and an error occurs before I'm done, I transfer the original flow file to its failure relationship.  My doubt, however, is whether or not I have to do anything with the flow files that I've created thus far.&lt;/P&gt;&lt;P&gt;Consider, for example, the following groovy:&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;def flowFile = session.get()&lt;/P&gt;&lt;P&gt;if (!flowFile) return&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;def filesDir = flowFile.getAttribute('filesDirectory')&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;// See &lt;A href="https://community.hortonworks.com/questions/106878/split-one-nifi-flow-file-into-multiple-flow-file-b.html" target="_blank"&gt;https://community.hortonworks.com/questions/106878/split-one-nifi-flow-file-into-multiple-flow-file-b.html&lt;/A&gt;&lt;/P&gt;&lt;P&gt;def flowFiles = [] as List&amp;lt;FlowFile&amp;gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;try {&lt;!-- --&gt;&lt;/P&gt;&lt;P&gt;    // Get a list of all the trades in the portfolio directory.&lt;/P&gt;&lt;P&gt;    File folder = new File(filesDir);&lt;/P&gt;&lt;P&gt;    File[] listOfFiles = folder.listFiles();&lt;/P&gt;&lt;P&gt;    &lt;/P&gt;&lt;P&gt;    for (File file : listOfFiles) {&lt;!-- --&gt;&lt;/P&gt;&lt;P&gt;        if (file.isFile()) {&lt;!-- --&gt;&lt;/P&gt;&lt;P&gt;            // Create a new flow file with that single trade.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;            def newFlowFile = session.create(flowFile)&lt;/P&gt;&lt;P&gt;            flowFiles &amp;lt;&amp;lt; newFlowFile&lt;/P&gt;&lt;P&gt;            &lt;/P&gt;&lt;P&gt;            // put some attributes here, or do something that might throw an exception&lt;/P&gt;&lt;P&gt;            &lt;/P&gt;&lt;P&gt;        }&lt;/P&gt;&lt;P&gt;    }&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;catch (e) {&lt;!-- --&gt;&lt;/P&gt;&lt;P&gt;    session.transfer(flowFile, REL_FAILURE)&lt;/P&gt;&lt;P&gt;    return&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;session.remove(flowFile)&lt;/P&gt;&lt;P&gt;session.transfer(flowFiles, REL_SUCCESS)&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;My doubt is whether or not I need something like this in the "catch" block:&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;catch (e) {&lt;!-- --&gt;&lt;/P&gt;&lt;P&gt;    // is this necessary?&lt;/P&gt;&lt;P&gt;    for (FlowFile theFlowFile : flowFiles) {&lt;!-- --&gt;&lt;/P&gt;&lt;P&gt;        session.remove(theFlowFile)&lt;/P&gt;&lt;P&gt;    }&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;    session.transfer(flowFile, REL_FAILURE)&lt;/P&gt;&lt;P&gt;    return&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;...or will the session automatically clean them up on the basis that they haven't been directed to any relationship?&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Mar 2019 08:14:12 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Creating-multiple-flow-files-and-ExecuteScript-error/m-p/236790#M198603</guid>
      <dc:creator>sean_dockery</dc:creator>
      <dc:date>2019-03-26T08:14:12Z</dc:date>
    </item>
    <item>
      <title>Re: Creating multiple flow files and ExecuteScript error handling</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Creating-multiple-flow-files-and-ExecuteScript-error/m-p/236791#M198604</link>
      <description>&lt;P&gt;Once a flow file has been created in a session, it must be removed or transferred before the session is committed (which happens at the end of ExecuteScript). Since your try is outside the loop that creates new flow files, you'll want to remove all the created ones, namely the flowFiles list. You can do that with simply:&lt;/P&gt;&lt;PRE&gt;session.remove(flowFiles)&lt;/PRE&gt;&lt;P&gt;rather than the loop you have in your catch statement.&lt;/P&gt;</description>
      <pubDate>Tue, 26 Mar 2019 20:58:27 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Creating-multiple-flow-files-and-ExecuteScript-error/m-p/236791#M198604</guid>
      <dc:creator>mburgess</dc:creator>
      <dc:date>2019-03-26T20:58:27Z</dc:date>
    </item>
    <item>
      <title>Re: Creating multiple flow files and ExecuteScript error handling</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Creating-multiple-flow-files-and-ExecuteScript-error/m-p/236792#M198605</link>
      <description>&lt;P&gt;Thanks, Matt.&lt;/P&gt;</description>
      <pubDate>Wed, 27 Mar 2019 13:32:46 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Creating-multiple-flow-files-and-ExecuteScript-error/m-p/236792#M198605</guid>
      <dc:creator>sean_dockery</dc:creator>
      <dc:date>2019-03-27T13:32:46Z</dc:date>
    </item>
    <item>
      <title>Re: Creating multiple flow files and ExecuteScript error handling</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Creating-multiple-flow-files-and-ExecuteScript-error/m-p/236793#M198606</link>
      <description>&lt;P&gt;&lt;A rel="user" href="https://community.cloudera.com/users/641/mburgess.html" nodeid="641"&gt;@Matt Burgess&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Maybe there is a spot somewhere this may be mentioned in your &lt;STRONG&gt;&lt;EM&gt;already-excellent&lt;/EM&gt;&lt;/STRONG&gt; ExecuteScript Cookbook articles for the next person?&lt;/P&gt;</description>
      <pubDate>Sat, 30 Mar 2019 02:15:08 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Creating-multiple-flow-files-and-ExecuteScript-error/m-p/236793#M198606</guid>
      <dc:creator>sean_dockery</dc:creator>
      <dc:date>2019-03-30T02:15:08Z</dc:date>
    </item>
    <item>
      <title>Re: Creating multiple flow files and ExecuteScript error handling</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Creating-multiple-flow-files-and-ExecuteScript-error/m-p/236794#M198607</link>
      <description>&lt;P&gt;That's a great idea, thanks! I've been meaning to update it, hopefully sooner than later &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 30 Mar 2019 02:20:09 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Creating-multiple-flow-files-and-ExecuteScript-error/m-p/236794#M198607</guid>
      <dc:creator>mburgess</dc:creator>
      <dc:date>2019-03-30T02:20:09Z</dc:date>
    </item>
  </channel>
</rss>

