You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@nifi.apache.org by "ara m." <ar...@gmail.com> on 2019/04/03 20:16:00 UTC

Re: set penalty duration on a flowfile

I'm also trying to do this. Ive tried both in NiFi 171 and 191.
ExecuteScript doesnt seem to be able to load StandardFlowFileRecord, which
is strange since its part of nifi-framework-nar-*.nar which is in lib/. 
I read a post saying somebody was using ExecuteGroovyScript which had
different imports, but that if you were using ExecuteScript you should have
nifi classes loaded. 

Ideas why this is failing? 

I've tried even using import and adding lib/ to the modules directory of my
ExecuteScript, ScriptEngine: Groovy. 

this is the body. 
import org.apache.commons.io.IOUtils
import java.nio.charset.StandardCharsets
import org.apache.nifi.controller.repository.*

flowFile = session.get()
if(!flowFile) return

expirationEpochMillis = System.currentTimeMillis() +
(flowFile.getAttribute('waitOnPriorsMinutes').toInteger() * 60 * 1000)

newFlowFile = new
StandardFlowFileRecord.Builder().fromFlowFile(flowFile).penaltyExpirationTime(expirationEpochMillis).build()

session.penalize(newFlowFile)
session.transfer(newFlowFile, REL_SUCCESS)


I get the following error. 

Script879.groovy: 22: unable to resolve class StandardFlowFileRecord.Builder
 @ line 22, column 15.
   newFlowFile = new
StandardFlowFileRecord.Builder().fromFlowFile(flowFile).penaltyExpirationTime(expirationEpochMillis).build()





--
Sent from: http://apache-nifi-users-list.2361937.n4.nabble.com/

Re: set penalty duration on a flowfile

Posted by Bryan Bende <bb...@gmail.com>.
Hello,

Even if there is a way to make this work, I would not recommend doing this.

Processors should not have access to internals of NiFI's framework
(i.e. nifi-framework-nar), they should only have access to what is
provided through the nifi-api which is the session and context.

If you start using stuff outside nifi-api, then your processors are
likely to break on upgrades because the developers are free to change
anything they want inside nifi-framework, the api is what is
guaranteed to be consistent.

-Bryan

On Wed, Apr 3, 2019 at 4:16 PM ara m. <ar...@gmail.com> wrote:
>
> I'm also trying to do this. Ive tried both in NiFi 171 and 191.
> ExecuteScript doesnt seem to be able to load StandardFlowFileRecord, which
> is strange since its part of nifi-framework-nar-*.nar which is in lib/.
> I read a post saying somebody was using ExecuteGroovyScript which had
> different imports, but that if you were using ExecuteScript you should have
> nifi classes loaded.
>
> Ideas why this is failing?
>
> I've tried even using import and adding lib/ to the modules directory of my
> ExecuteScript, ScriptEngine: Groovy.
>
> this is the body.
> import org.apache.commons.io.IOUtils
> import java.nio.charset.StandardCharsets
> import org.apache.nifi.controller.repository.*
>
> flowFile = session.get()
> if(!flowFile) return
>
> expirationEpochMillis = System.currentTimeMillis() +
> (flowFile.getAttribute('waitOnPriorsMinutes').toInteger() * 60 * 1000)
>
> newFlowFile = new
> StandardFlowFileRecord.Builder().fromFlowFile(flowFile).penaltyExpirationTime(expirationEpochMillis).build()
>
> session.penalize(newFlowFile)
> session.transfer(newFlowFile, REL_SUCCESS)
>
>
> I get the following error.
>
> Script879.groovy: 22: unable to resolve class StandardFlowFileRecord.Builder
>  @ line 22, column 15.
>    newFlowFile = new
> StandardFlowFileRecord.Builder().fromFlowFile(flowFile).penaltyExpirationTime(expirationEpochMillis).build()
>
>
>
>
>
> --
> Sent from: http://apache-nifi-users-list.2361937.n4.nabble.com/