nifi-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andy LoPresto <alopre...@apache.org>
Subject Re: Execute Script - Groovy get attribute
Date Wed, 03 Jun 2020 16:53:52 GMT
It also seems like you would rather set the flowfile batch count as a _property_ on the ExecuteScript
processor and obtain it from the session, rather than check a specific flowfile for an attribute
which may or may not exist. 

Andy LoPresto
alopresto@apache.org
alopresto.apache@gmail.com
He/Him
PGP Fingerprint: 70EC B3E5 98A6 5A3F D3C4  BACE 3C6E F65B 2F7D EF69

> On Jun 3, 2020, at 8:07 AM, Matt Burgess <mattyb149@apache.org> wrote:
> 
> Asmath,
> 
> When you pass an integer argument into session.get(), you get an ArrayList back, not
a single FlowFile. You can just use session.get() to get (up to) 1 FlowFile, or if you call
session.get(1) you can just use the first element (once checking to see if it's null), so
trigger[0].getAttribute('cnt')
> 
> Regards,
> Matt
> 
> 
> On Wed, Jun 3, 2020 at 8:58 AM KhajaAsmath Mohammed <mdkhajaasmath@gmail.com <mailto:mdkhajaasmath@gmail.com>>
wrote:
> Hi,
> 
> I have followed the below link to wait for 100 files and then process the next step.
> 
> https://community.cloudera.com/t5/Support-Questions/NiFi-Count-Fileflows-via-attribute/td-p/178860
<https://community.cloudera.com/t5/Support-Questions/NiFi-Count-Fileflows-via-attribute/td-p/178860>

> 
> This works well but my use case is that count number is dynamic. To test the functionality,
I have passed an attribute count to get the value. Below script is not working. any help?

> 
> import org.apache.commons.io.IOUtils
> import java.nio.charset.StandardCharsets
> def trigger=session.get(1)
> def flowFiles=session.get(99)
> if (!trigger) return
> 
> String attr=trigger.getAttribute("cnt");
> 
> 
> if(!flowFiles || flowFiles.size() < 7)
> {
> session.rollback()
> }
> else
> {
> session.transfer(trigger,REL_SUCCESS)
> session.transfer(flowFiles,REL_FAILURE)
> 
> }
> 
> <image.png>
> 
> Here is the error I got.
> 
> Thanks,
> Asmath 


Mime
View raw message