Search code examples
apache-nifi

Apache Nifi - Make Flow Definitions Portable by using relative paths


I want to make Flow Definitions portable by replacing absolute file paths to relative in below items

  1. Script Path Property of all ExecuteScript Processors
  2. Database Driver Location(s) property of DBCPConnectionPool Controller Services
  3. Keystore Filename & Truststore Filename properties of StandardRestrictedSSLContextService Controller Services

Questions:

  1. Is it possible to use Relative Paths in above items?
  2. Where does the root of relative path point to - nifi installation directory?
  3. What are best practices for managing paths in flow defitions?
  4. Any other best practices for making flow definitions portable

EDIT: We're using parameters in Flow Definitions to make it easier to configure per environment. Currently we have a param to indicate Nifi root path. Te motive behind this question is to check if this param can eliminated entirely by using relative paths.


Solution

  • You can use relative paths if the property supports expression language. In your case script path, database driver locations support; however, keystore and truststore paths do not.

    For example, I am using relative script path for my ExecuteScripts to run them on macos , windows as well as linux with the same path

    Suppose your Nifi root is opt/nifi/nifi-current and you have groovy folder in the root and a FlowHandler.groovyin it. So your script path would be like below

    ${user.dir}${file.separator}groovy${file.separator}FlowHandler.groovy
    

    Apart from that, I strongly recommend that prepare your own docker image (from base Nifi) and put all constant staffs in it to distribute, so that you can keep your file paths mostly stable across all platforms