You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@nifi.apache.org by 尹文才 <ba...@gmail.com> on 2017/07/12 08:04:23 UTC

Trigger timer-driven processor to run from outside NIFI

Hi guys, is it possible for a Java application outside the NIFI environment
to trigger a timer-driven processor to do its work(I mean its ontrigger
method will be called) when the processor is not yet due to be triggered?
The reason why I'm asking about this is because I have a Java applicatiion
with UI outside NIFI and there're some configuration data that could be
updated into a database, and my processor in NIFI need to get the updated
configuration
data from that database as soon as possible, but my processor is configured
to be timer driven of 5 mins. I hope the processor could be triggered to
run after the configuration is updated by the Java application when it's
not yet reached
the time for it to be triggered. Thanks.

Regards,
Ben

Re: Trigger timer-driven processor to run from outside NIFI

Posted by 尹文才 <ba...@gmail.com>.
Thanks very much Koji for your quick response and your example, I will look
into your example. 😀

Regards,
Ben

2017-07-14 17:27 GMT+08:00 Koji Kawamura <ij...@apache.org>:

> Hi Ben,
>
> If the processor is running, stop will wait for the thread to complete.
> Please see stop() method here.
> https://github.com/apache/nifi/blob/master/nifi-nar-
> bundles/nifi-framework-bundle/nifi-framework/nifi-framework-
> core/src/main/java/org/apache/nifi/controller/StandardProcessorNode.java
>
> To stop or start a processor, you just need to update its state. I have an
> example here. Please refer updateProcessorState function.
> https://github.com/ijokarumawak/nifi-api-client-js/blob/master/nifi-api-
> client.js
>
> Trying to reply from mobile at best effort. Excuse me for typos if any..
>
> Thanks,
> Koji
>
>
> On Jul 14, 2017 5:29 PM, "尹文才" <ba...@gmail.com> wrote:
>
> Hi Koji, I tried to play with the NIFI REST API with chrome postman app,
> when you mentioned about restart the processor via REST API, did you mean
> first sending stop command and then send start command via the API "PUT
> /processors/{id}"? By the way, when I send the stop command to the
> processor, will it finish its work
> and then stop the processor or will it simply kill the task directly?
> Thanks.
>
> Regards,
> Ben
>
> 2017-07-14 15:13 GMT+08:00 尹文才 <ba...@gmail.com>:
>
> > Thanks Koji, I checked the NIFI REST API and it seems that I need to use
> > Groovy to do it(I don't understand Groovy), is there any Java related
> > examples which interact with NIFI via REST API? Thanks.
> >
> > Regards,
> > Ben
> >
> > 2017-07-14 13:49 GMT+08:00 Koji Kawamura <ij...@gmail.com>:
> >
> >> Hi Ben,
> >>
> >> Just an idea, using ListenHTTP or HandleHTTPRequest (or whatever
> >> listener type processor you can use) in front of your processor might
> >> be helpful. You also need to change your processor to support incoming
> >> FlowFile as well if it doesn't currently. This way, the outside
> >> application can send a simple HTTP request to do your processor its
> >> job.
> >>
> >> Another possible way would be using NiFi REST API, stop the processor
> >> and then restart it. When the processor is restarted, its onTrigger
> >> will be called, and it will wait for next time to be scheduled (next
> >> 5min in your case).
> >>
> >> Thanks,
> >> Koji
> >>
> >> On Wed, Jul 12, 2017 at 5:04 PM, 尹文才 <ba...@gmail.com> wrote:
> >> > Hi guys, is it possible for a Java application outside the NIFI
> >> environment
> >> > to trigger a timer-driven processor to do its work(I mean its
> ontrigger
> >> > method will be called) when the processor is not yet due to be
> >> triggered?
> >> > The reason why I'm asking about this is because I have a Java
> >> applicatiion
> >> > with UI outside NIFI and there're some configuration data that could
> be
> >> > updated into a database, and my processor in NIFI need to get the
> >> updated
> >> > configuration
> >> > data from that database as soon as possible, but my processor is
> >> configured
> >> > to be timer driven of 5 mins. I hope the processor could be triggered
> to
> >> > run after the configuration is updated by the Java application when
> it's
> >> > not yet reached
> >> > the time for it to be triggered. Thanks.
> >> >
> >> > Regards,
> >> > Ben
> >>
> >
> >
>

Re: Trigger timer-driven processor to run from outside NIFI

Posted by Koji Kawamura <ij...@apache.org>.
Hi Ben,

If the processor is running, stop will wait for the thread to complete.
Please see stop() method here.
https://github.com/apache/nifi/blob/master/nifi-nar-
bundles/nifi-framework-bundle/nifi-framework/nifi-framework-
core/src/main/java/org/apache/nifi/controller/StandardProcessorNode.java

To stop or start a processor, you just need to update its state. I have an
example here. Please refer updateProcessorState function.
https://github.com/ijokarumawak/nifi-api-client-js/blob/master/nifi-api-client.js

Trying to reply from mobile at best effort. Excuse me for typos if any..

Thanks,
Koji


On Jul 14, 2017 5:29 PM, "尹文才" <ba...@gmail.com> wrote:

Hi Koji, I tried to play with the NIFI REST API with chrome postman app,
when you mentioned about restart the processor via REST API, did you mean
first sending stop command and then send start command via the API "PUT
/processors/{id}"? By the way, when I send the stop command to the
processor, will it finish its work
and then stop the processor or will it simply kill the task directly?
Thanks.

Regards,
Ben

2017-07-14 15:13 GMT+08:00 尹文才 <ba...@gmail.com>:

> Thanks Koji, I checked the NIFI REST API and it seems that I need to use
> Groovy to do it(I don't understand Groovy), is there any Java related
> examples which interact with NIFI via REST API? Thanks.
>
> Regards,
> Ben
>
> 2017-07-14 13:49 GMT+08:00 Koji Kawamura <ij...@gmail.com>:
>
>> Hi Ben,
>>
>> Just an idea, using ListenHTTP or HandleHTTPRequest (or whatever
>> listener type processor you can use) in front of your processor might
>> be helpful. You also need to change your processor to support incoming
>> FlowFile as well if it doesn't currently. This way, the outside
>> application can send a simple HTTP request to do your processor its
>> job.
>>
>> Another possible way would be using NiFi REST API, stop the processor
>> and then restart it. When the processor is restarted, its onTrigger
>> will be called, and it will wait for next time to be scheduled (next
>> 5min in your case).
>>
>> Thanks,
>> Koji
>>
>> On Wed, Jul 12, 2017 at 5:04 PM, 尹文才 <ba...@gmail.com> wrote:
>> > Hi guys, is it possible for a Java application outside the NIFI
>> environment
>> > to trigger a timer-driven processor to do its work(I mean its ontrigger
>> > method will be called) when the processor is not yet due to be
>> triggered?
>> > The reason why I'm asking about this is because I have a Java
>> applicatiion
>> > with UI outside NIFI and there're some configuration data that could be
>> > updated into a database, and my processor in NIFI need to get the
>> updated
>> > configuration
>> > data from that database as soon as possible, but my processor is
>> configured
>> > to be timer driven of 5 mins. I hope the processor could be triggered
to
>> > run after the configuration is updated by the Java application when
it's
>> > not yet reached
>> > the time for it to be triggered. Thanks.
>> >
>> > Regards,
>> > Ben
>>
>
>

Re: Trigger timer-driven processor to run from outside NIFI

Posted by 尹文才 <ba...@gmail.com>.
Hi Koji, I tried to play with the NIFI REST API with chrome postman app,
when you mentioned about restart the processor via REST API, did you mean
first sending stop command and then send start command via the API "PUT
/processors/{id}"? By the way, when I send the stop command to the
processor, will it finish its work
and then stop the processor or will it simply kill the task directly?
Thanks.

Regards,
Ben

2017-07-14 15:13 GMT+08:00 尹文才 <ba...@gmail.com>:

> Thanks Koji, I checked the NIFI REST API and it seems that I need to use
> Groovy to do it(I don't understand Groovy), is there any Java related
> examples which interact with NIFI via REST API? Thanks.
>
> Regards,
> Ben
>
> 2017-07-14 13:49 GMT+08:00 Koji Kawamura <ij...@gmail.com>:
>
>> Hi Ben,
>>
>> Just an idea, using ListenHTTP or HandleHTTPRequest (or whatever
>> listener type processor you can use) in front of your processor might
>> be helpful. You also need to change your processor to support incoming
>> FlowFile as well if it doesn't currently. This way, the outside
>> application can send a simple HTTP request to do your processor its
>> job.
>>
>> Another possible way would be using NiFi REST API, stop the processor
>> and then restart it. When the processor is restarted, its onTrigger
>> will be called, and it will wait for next time to be scheduled (next
>> 5min in your case).
>>
>> Thanks,
>> Koji
>>
>> On Wed, Jul 12, 2017 at 5:04 PM, 尹文才 <ba...@gmail.com> wrote:
>> > Hi guys, is it possible for a Java application outside the NIFI
>> environment
>> > to trigger a timer-driven processor to do its work(I mean its ontrigger
>> > method will be called) when the processor is not yet due to be
>> triggered?
>> > The reason why I'm asking about this is because I have a Java
>> applicatiion
>> > with UI outside NIFI and there're some configuration data that could be
>> > updated into a database, and my processor in NIFI need to get the
>> updated
>> > configuration
>> > data from that database as soon as possible, but my processor is
>> configured
>> > to be timer driven of 5 mins. I hope the processor could be triggered to
>> > run after the configuration is updated by the Java application when it's
>> > not yet reached
>> > the time for it to be triggered. Thanks.
>> >
>> > Regards,
>> > Ben
>>
>
>

Re: Trigger timer-driven processor to run from outside NIFI

Posted by 尹文才 <ba...@gmail.com>.
Thanks Koji, I checked the NIFI REST API and it seems that I need to use
Groovy to do it(I don't understand Groovy), is there any Java related
examples which interact with NIFI via REST API? Thanks.

Regards,
Ben

2017-07-14 13:49 GMT+08:00 Koji Kawamura <ij...@gmail.com>:

> Hi Ben,
>
> Just an idea, using ListenHTTP or HandleHTTPRequest (or whatever
> listener type processor you can use) in front of your processor might
> be helpful. You also need to change your processor to support incoming
> FlowFile as well if it doesn't currently. This way, the outside
> application can send a simple HTTP request to do your processor its
> job.
>
> Another possible way would be using NiFi REST API, stop the processor
> and then restart it. When the processor is restarted, its onTrigger
> will be called, and it will wait for next time to be scheduled (next
> 5min in your case).
>
> Thanks,
> Koji
>
> On Wed, Jul 12, 2017 at 5:04 PM, 尹文才 <ba...@gmail.com> wrote:
> > Hi guys, is it possible for a Java application outside the NIFI
> environment
> > to trigger a timer-driven processor to do its work(I mean its ontrigger
> > method will be called) when the processor is not yet due to be triggered?
> > The reason why I'm asking about this is because I have a Java
> applicatiion
> > with UI outside NIFI and there're some configuration data that could be
> > updated into a database, and my processor in NIFI need to get the updated
> > configuration
> > data from that database as soon as possible, but my processor is
> configured
> > to be timer driven of 5 mins. I hope the processor could be triggered to
> > run after the configuration is updated by the Java application when it's
> > not yet reached
> > the time for it to be triggered. Thanks.
> >
> > Regards,
> > Ben
>

Re: Trigger timer-driven processor to run from outside NIFI

Posted by Koji Kawamura <ij...@gmail.com>.
Hi Ben,

Just an idea, using ListenHTTP or HandleHTTPRequest (or whatever
listener type processor you can use) in front of your processor might
be helpful. You also need to change your processor to support incoming
FlowFile as well if it doesn't currently. This way, the outside
application can send a simple HTTP request to do your processor its
job.

Another possible way would be using NiFi REST API, stop the processor
and then restart it. When the processor is restarted, its onTrigger
will be called, and it will wait for next time to be scheduled (next
5min in your case).

Thanks,
Koji

On Wed, Jul 12, 2017 at 5:04 PM, 尹文才 <ba...@gmail.com> wrote:
> Hi guys, is it possible for a Java application outside the NIFI environment
> to trigger a timer-driven processor to do its work(I mean its ontrigger
> method will be called) when the processor is not yet due to be triggered?
> The reason why I'm asking about this is because I have a Java applicatiion
> with UI outside NIFI and there're some configuration data that could be
> updated into a database, and my processor in NIFI need to get the updated
> configuration
> data from that database as soon as possible, but my processor is configured
> to be timer driven of 5 mins. I hope the processor could be triggered to
> run after the configuration is updated by the Java application when it's
> not yet reached
> the time for it to be triggered. Thanks.
>
> Regards,
> Ben