You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@nifi.apache.org by Kumiko Yada <Ku...@ds-iq.com> on 2016/06/17 19:00:51 UTC

Custom Controller Service

Hello,

I wrote the Custom Controller Service to authenticate the Azure Datalake Store, and I'd like to refresh a token every 24 hours.  What is the best way to authenticate every 24 hours?  Should I loop the authenticate code every 24 hours in OnEnabled?

Thanks
Kumiko

RE: Custom Controller Service

Posted by Kumiko Yada <Ku...@ds-iq.com>.
Thank you, Mark! It worked as great per your suggestion.

Thanks
Kumiko

From: Mark Payne [mailto:markap14@hotmail.com]
Sent: Friday, June 17, 2016 12:26 PM
To: users@nifi.apache.org
Cc: Ki Kang <Ki...@ds-iq.com>; Kevin Verhoeven <Ke...@ds-iq.com>
Subject: Re: Custom Controller Service

Hi Kumiko,

I would recommend that in your OnEnabled method that you just create a ScheduledExecutorService and
schedule the task to occur every 24 hours or however you'd like. Then, in your OnDisabled method call
shutdown on that ScheduledExecutorService.

A word to the wise, though - NiFi tends to have quite a few threads running, so for debugging purposes
it is easier to see what's going on if you provide a ThreadFactory to your executor so that you can name
your threads appropriately. Something like:

Executors.newScheduledThreadPool(3, new ThreadFactory() {
            @Override
            public Thread newThread(Runnable r) {
                final Thread t = Executors.defaultThreadFactory().newThread(r);
                t.setDaemon(true);
                t.setName("Refresh Azure DataLake Token");
                return t;
            }
});

I hope this helps!

Thanks
-Mark


On Jun 17, 2016, at 3:00 PM, Kumiko Yada <Ku...@ds-iq.com>> wrote:

Hello,

I wrote the Custom Controller Service to authenticate the Azure Datalake Store, and I’d like to refresh a token every 24 hours.  What is the best way to authenticate every 24 hours?  Should I loop the authenticate code every 24 hours in OnEnabled?

Thanks
Kumiko


Re: Custom Controller Service

Posted by Mark Payne <ma...@hotmail.com>.
We could potentially use a Reporting Task for this, actually. Not really the intent
of the Reporting Task capability, but it does provide all the necessary lifecycle constructs
and is generally easier to implement than Controller Services.

-Mark

> On Jun 17, 2016, at 3:29 PM, Joe Witt <jo...@gmail.com> wrote:
> 
> ...i wonder if we've done the same ourselves or given similar advice
> to others.  This feels like something the framework should make
> available as an expected lifecycle point.  I could see it making sense
> for such cases that we would allow 'OnScheduled' to be on controller
> services and let the user schedule how often that should get invoked
> and just never let them set it to 0 in the case of a controller
> service.
> 
> On Fri, Jun 17, 2016 at 3:25 PM, Mark Payne <ma...@hotmail.com> wrote:
>> Hi Kumiko,
>> 
>> I would recommend that in your OnEnabled method that you just create a
>> ScheduledExecutorService and
>> schedule the task to occur every 24 hours or however you'd like. Then, in
>> your OnDisabled method call
>> shutdown on that ScheduledExecutorService.
>> 
>> A word to the wise, though - NiFi tends to have quite a few threads running,
>> so for debugging purposes
>> it is easier to see what's going on if you provide a ThreadFactory to your
>> executor so that you can name
>> your threads appropriately. Something like:
>> 
>> Executors.newScheduledThreadPool(3, new ThreadFactory() {
>>            @Override
>>            public Thread newThread(Runnable r) {
>>                final Thread t =
>> Executors.defaultThreadFactory().newThread(r);
>>                t.setDaemon(true);
>>                t.setName("Refresh Azure DataLake Token");
>>                return t;
>>            }
>> });
>> 
>> I hope this helps!
>> 
>> Thanks
>> -Mark
>> 
>> 
>> On Jun 17, 2016, at 3:00 PM, Kumiko Yada <Ku...@ds-iq.com> wrote:
>> 
>> Hello,
>> 
>> I wrote the Custom Controller Service to authenticate the Azure Datalake
>> Store, and I’d like to refresh a token every 24 hours.  What is the best way
>> to authenticate every 24 hours?  Should I loop the authenticate code every
>> 24 hours in OnEnabled?
>> 
>> Thanks
>> Kumiko
>> 
>> 


Re: Custom Controller Service

Posted by Joe Witt <jo...@gmail.com>.
...i wonder if we've done the same ourselves or given similar advice
to others.  This feels like something the framework should make
available as an expected lifecycle point.  I could see it making sense
for such cases that we would allow 'OnScheduled' to be on controller
services and let the user schedule how often that should get invoked
and just never let them set it to 0 in the case of a controller
service.

On Fri, Jun 17, 2016 at 3:25 PM, Mark Payne <ma...@hotmail.com> wrote:
> Hi Kumiko,
>
> I would recommend that in your OnEnabled method that you just create a
> ScheduledExecutorService and
> schedule the task to occur every 24 hours or however you'd like. Then, in
> your OnDisabled method call
> shutdown on that ScheduledExecutorService.
>
> A word to the wise, though - NiFi tends to have quite a few threads running,
> so for debugging purposes
> it is easier to see what's going on if you provide a ThreadFactory to your
> executor so that you can name
> your threads appropriately. Something like:
>
> Executors.newScheduledThreadPool(3, new ThreadFactory() {
>             @Override
>             public Thread newThread(Runnable r) {
>                 final Thread t =
> Executors.defaultThreadFactory().newThread(r);
>                 t.setDaemon(true);
>                 t.setName("Refresh Azure DataLake Token");
>                 return t;
>             }
> });
>
> I hope this helps!
>
> Thanks
> -Mark
>
>
> On Jun 17, 2016, at 3:00 PM, Kumiko Yada <Ku...@ds-iq.com> wrote:
>
> Hello,
>
> I wrote the Custom Controller Service to authenticate the Azure Datalake
> Store, and I’d like to refresh a token every 24 hours.  What is the best way
> to authenticate every 24 hours?  Should I loop the authenticate code every
> 24 hours in OnEnabled?
>
> Thanks
> Kumiko
>
>

Re: Custom Controller Service

Posted by Mark Payne <ma...@hotmail.com>.
Hi Kumiko,

I would recommend that in your OnEnabled method that you just create a ScheduledExecutorService and
schedule the task to occur every 24 hours or however you'd like. Then, in your OnDisabled method call
shutdown on that ScheduledExecutorService.

A word to the wise, though - NiFi tends to have quite a few threads running, so for debugging purposes
it is easier to see what's going on if you provide a ThreadFactory to your executor so that you can name
your threads appropriately. Something like:

Executors.newScheduledThreadPool(3, new ThreadFactory() {
            @Override
            public Thread newThread(Runnable r) {
                final Thread t = Executors.defaultThreadFactory().newThread(r);
                t.setDaemon(true);
                t.setName("Refresh Azure DataLake Token");
                return t;
            }
});

I hope this helps!

Thanks
-Mark


> On Jun 17, 2016, at 3:00 PM, Kumiko Yada <Ku...@ds-iq.com> wrote:
> 
> Hello,
>  
> I wrote the Custom Controller Service to authenticate the Azure Datalake Store, and I’d like to refresh a token every 24 hours.  What is the best way to authenticate every 24 hours?  Should I loop the authenticate code every 24 hours in OnEnabled?
>  
> Thanks
> Kumiko