Support Questions

Find answers, ask questions, and share your expertise

Getting API token once during a NIFI flow

avatar
Explorer

I have a NIFI flow that moves files from one FTP server to another. The flow starts with ListSFTP processor and ends with the PutSFTP processor. The password required to authenticate with the PutSFTP processor is stored inside another application that exposes REST endpoints to get the password. I want to get the password once and use the same to put all fetched files into the destination SFTP server. Please advise where/how i can use the InvokeHTTP processor in this case so that it doesnt get invoked for each flow file (It doesnt make sense to fetch the password on a per flowfile basis). 

1 REPLY 1

avatar
Master Mentor

@AnkushKoul 

 

You may consider having two dataflows here because you would need to store this password somewhere that your putSFTP processor dataflow would need have access to.
One dataflow that acquires the password from the rest endpoint and another that is actually performs your putSFTP.

Flow to get password would consist of a GenerateFlowFile (configure to generate a FlowFIle on each NiFi node using a run schedule to control how often password will be refreshed)--> invoketHTTP --> putDistributedMapCache (Configured to use DistributedMapCacheClient that uses "localhost" as server hostname. Will need to also add a DistributedMapCacheServer Controller service that above client will talk to.  This will make sure each node grabs password and stores it locally on that nodes's DMCServer)

Then in your flow using putSFTP, you would replace the invokeHTTP processor a fetchDistributedMapCache processor just before the putSftp processor (suggest looping failure relationship from putSFTP back to fetchDistributedMapCache processor  just in case password changes or there was no password stored when fetch was attempted first time).

Keep in mind that flows like this are not idea.  The retrieved password that you are placing in to a FlowFile attribute is stored in plaintext.

If you found this solution helpful, please take a moment to login and click accept on this solution.
Good luck,

Matt