Support Questions
Find answers, ask questions, and share your expertise
Announcements
Alert: Welcome to the Unified Cloudera Community. Former HCC members be sure to read and learn how to activate your account here.

In Apache Nifi Rest API, what is difference between Import and Upload?

Solved Go to solution
Highlighted

In Apache Nifi Rest API, what is difference between Import and Upload?

New Contributor
 
1 ACCEPTED SOLUTION

Accepted Solutions

Re: In Apache Nifi Rest API, what is difference between Import and Upload?

Super Guru
@Tommy Lathrop
Upload means Copying (or) uploading the template .XML file into the instance of NiFi.

Once the template is uploaded then the template is ready to be instantiated to the NiFi Canvas.

Import means Loading the copied (or) uploaded .XML file into NiFi Canvas(into root or process group).

Let's consider

You have created a flow in DEV env and then you need to promote this flow to PROD env,

For this case we are going to create a Template in DEV env first, then download the template into local.

Then you are going to Upload the the template to PROD env first so the template will be available in PROD env now.

To add the uploaded template to the NiFi Canvas then you need to import the template.

5 REPLIES 5

Re: In Apache Nifi Rest API, what is difference between Import and Upload?

Super Guru
@Tommy Lathrop
Upload means Copying (or) uploading the template .XML file into the instance of NiFi.

Once the template is uploaded then the template is ready to be instantiated to the NiFi Canvas.

Import means Loading the copied (or) uploaded .XML file into NiFi Canvas(into root or process group).

Let's consider

You have created a flow in DEV env and then you need to promote this flow to PROD env,

For this case we are going to create a Template in DEV env first, then download the template into local.

Then you are going to Upload the the template to PROD env first so the template will be available in PROD env now.

To add the uploaded template to the NiFi Canvas then you need to import the template.

Re: In Apache Nifi Rest API, what is difference between Import and Upload?

New Contributor

Thank you @Shu

I was able to upload to my NiFi instance using following curl:

curl -XPOST http://<nifihost:nifiport>/nifi-api/process-groups/<id>/templates/upload -k -v -F template=@/path/to/template.xml

I am now tryin to import into NiFi Canvas but am unable to formulate the right command for this. Can you help me with correct curl to import the uploaded template onto the canvas?

Re: In Apache Nifi Rest API, what is difference between Import and Upload?

Super Guru
@Tommy Lathrop

To import the Template into NiFi Canvas we need to use specific syntax of curl command and template-instance

curl -i -X POST -H 'Content-Type:application/json' -d '{"originX": 2.0,"originY": 3.0,"templateId": "<template-id>"}' http://localhost:8080/nifi-api/process-groups/<process-group-id>/template-instance

Here is what i tried

I'm having a template in my Downloads folder

1.To upload a template from Downloads folder to NiFi i used below curl with upload method

curl -X POST http://localhost:8080/nifi-api/process-groups/226b1e5f-0160-1000-deb0-791f1a6f1f00/templates/upload -k -v -F template=@/cygdrive/c/shu/Downloads/Count_Loop.xml

in the above curl i'm using POST and my process group id is 226b1e5f-0160-1000-deb0-791f1a6f1f00

??Why we need to specify process group id while uploading??

Templates are owned by a process group (whether that is the root process group or one nested in the canvas). You can upload templates by making use of the '/process-groups/{id}/templates/upload' to upload a template to a particular process group.

Then i have given the path to the my Count_Loop.xml file and uploaded the template into NiFi Instance.

2.Now we need to import the Uploaded Count_Loop.xml into NiFi canvas

For this case we need to have our Template ID, For this id

Curl http://localhost:8080/nifi-api/flow/templates

Hit the above API and get the Template id for the Uploaded template for my case my template id is 02a4b939-ac14-4fac-9f05-550cc521b317.

Then we need to instantiate the template by using POST method and template-instance

POST
/process-groups/{id}/template-instance

My command is as follows

curl -i -X POST -H 'Content-Type:application/json' -d '{"originX": 2.0,"originY": 3.0,"templateId": "02a4b939-ac14-4fac-9f05-550cc521b317"}' http://localhost:8080/nifi-api/process-groups/226b1e5f-0160-1000-deb0-791f1a6f1f00/template-instance

i'm importing the uploaded Count_Loop.xml into the ProcessGroupID 226b1e5f-0160-1000-deb0-791f1a6f1f00 ,we got template id before so i'm using the TemplateID 02a4b939-ac14-4fac-9f05-550cc521b317 in the above curl method.

This template instance expects origin x, y and template id for sure. If you are missing any of these parameters then it results Bad request error.

If the Answer helped to resolve your issue, Click on Accept button below to accept the answer, That would be great help to Community users to find solution quickly for these kind of errors.

Re: In Apache Nifi Rest API, what is difference between Import and Upload?

New Contributor

Thank you @Shu

Re: In Apache Nifi Rest API, what is difference between Import and Upload?

New Contributor
Is it always two step process for XML import, Can I not directly copy the flow or import to the flow to the canvas ?


I understand in Upload and Import there will be always a template copy created for any flow that has to be imported to the canvas.


Scenario:

I have one flow (xml), I will have to create ten copies/instance of this flow (with different source/target).


I know we can import ten times from one template after uploading (one time) and then update the variables again by Rest API.

But I want to update the parameters/variables in xml file itself and then directly import to canvas for some reasons. Is it possible ?