Support Questions

Find answers, ask questions, and share your expertise
Announcements
Celebrating as our community reaches 100,000 members! Thank you!

NIFI : Create/Backup Template with NIFI-API

avatar
Rising Star

Hi,

Do you know create and backup the templates. I've checked NIFI-API but it is not clear for me?

It seems to need post an URI snippsets before create an template.

thanks

1 ACCEPTED SOLUTION

avatar
Master Guru
Create a snippet via http post

uri example

https://mynifiinstance.com:9091/nifi-api/snippets

Body which includes my parent process group id and and my process group id

{
	"snippet": {
		"parentGroupId": "69ea5920-0157-1000-0000-0000028e1b90",
		"processors": {},
		"funnels": {},
		"inputPorts": {},
		"outputPorts": {},
		"remoteProcessGroups": {},
		"processGroups": {
			"7ce7597d-0157-1000-ffff-ffffc161e771": {
				"clientId": "50b3ec1a-c123-1e4f-718c-b0323fb1e175",
				"version": 0
			}
		},
		"connections": {},
		"labels": {}
	}
}

This will return a snippet json object

{
	"snippet": {
		"id": "50b3ec79-c123-1e4f-0000-000009e32e47",
		"uri": "https://hdf20-0.field.hortonworks.com:9091/nifi-api/process-groups/69ea5920-0157-1000-0000-0000028e1b90/snippets/50b3ec79-c123-1e4f-0000-000009e32e47",
		"parentGroupId": "69ea5920-0157-1000-0000-0000028e1b90",
		"processGroups": {
			"7ce7597d-0157-1000-ffff-ffffc161e771": {
				"clientId": "50b3ec1a-c123-1e4f-718c-b0323fb1e175",
				"version": 0
			}
		},
		"remoteProcessGroups": {},
		"processors": {},
		"inputPorts": {},
		"outputPorts": {},
		"connections": {},
		"labels": {},
		"funnels": {}
	}
}

Here you grab the snippet Id and do a HTTP post

uri

https://mynifiinstance.com:9091/nifi-api/process-groups/69ea5920-0157-1000-0000-0000028e1b90/templat...

body

{
	"name": "dummy5",
	"description": "",
	"snippetId": "50b3ec79-c123-1e4f-0000-000009e32e47"
}

Now you have a template created with name "dummy5"

The response from this post is the template ID which you can then use nifi rest get api /templates/{id}/download

Here is response with template id

{  
   "template":{  
      "uri":"https://mynifiinstance.com:9091/nifi-api/templates/522819e6-e721-3c6b-95a4-81a0591fc9a3",
      "id":"522819e6-e721-3c6b-95a4-81a0591fc9a3",
      "groupId":"69ea5920-0157-1000-0000-0000028e1b90",
      "name":"dummy5",
      "description":"",
      "timestamp":"02/25/2017 03:36:17 UTC",
      "encoding-version":"1.0"
   }
}

View solution in original post

5 REPLIES 5

avatar
Master Guru
Create a snippet via http post

uri example

https://mynifiinstance.com:9091/nifi-api/snippets

Body which includes my parent process group id and and my process group id

{
	"snippet": {
		"parentGroupId": "69ea5920-0157-1000-0000-0000028e1b90",
		"processors": {},
		"funnels": {},
		"inputPorts": {},
		"outputPorts": {},
		"remoteProcessGroups": {},
		"processGroups": {
			"7ce7597d-0157-1000-ffff-ffffc161e771": {
				"clientId": "50b3ec1a-c123-1e4f-718c-b0323fb1e175",
				"version": 0
			}
		},
		"connections": {},
		"labels": {}
	}
}

This will return a snippet json object

{
	"snippet": {
		"id": "50b3ec79-c123-1e4f-0000-000009e32e47",
		"uri": "https://hdf20-0.field.hortonworks.com:9091/nifi-api/process-groups/69ea5920-0157-1000-0000-0000028e1b90/snippets/50b3ec79-c123-1e4f-0000-000009e32e47",
		"parentGroupId": "69ea5920-0157-1000-0000-0000028e1b90",
		"processGroups": {
			"7ce7597d-0157-1000-ffff-ffffc161e771": {
				"clientId": "50b3ec1a-c123-1e4f-718c-b0323fb1e175",
				"version": 0
			}
		},
		"remoteProcessGroups": {},
		"processors": {},
		"inputPorts": {},
		"outputPorts": {},
		"connections": {},
		"labels": {},
		"funnels": {}
	}
}

Here you grab the snippet Id and do a HTTP post

uri

https://mynifiinstance.com:9091/nifi-api/process-groups/69ea5920-0157-1000-0000-0000028e1b90/templat...

body

{
	"name": "dummy5",
	"description": "",
	"snippetId": "50b3ec79-c123-1e4f-0000-000009e32e47"
}

Now you have a template created with name "dummy5"

The response from this post is the template ID which you can then use nifi rest get api /templates/{id}/download

Here is response with template id

{  
   "template":{  
      "uri":"https://mynifiinstance.com:9091/nifi-api/templates/522819e6-e721-3c6b-95a4-81a0591fc9a3",
      "id":"522819e6-e721-3c6b-95a4-81a0591fc9a3",
      "groupId":"69ea5920-0157-1000-0000-0000028e1b90",
      "name":"dummy5",
      "description":"",
      "timestamp":"02/25/2017 03:36:17 UTC",
      "encoding-version":"1.0"
   }
}

avatar
Rising Star

@Sunile Manjee : thanks !!

avatar
New Contributor

Hey! Can you please explain more how to create an apache NIFI template?! 
Actually I need to know is it possible to generate an Apache NiFi template using JAVA ??

avatar
Rising Star

@Sunile Manjee : the documentation about REST-API NIFI it is not clear !!

Why all parameters are optional in the documentation and so if we post a curl with minimum parameters it will failed.

13081-snippets-optional.jpg

avatar
Rising Star

@Sunile Manjee : Hi thanks,

I'm trying to make a java restAPI client.

If somebody has already trying create a class for snippet and template, it is wondering if he send to me the definition of these classes.

thanks.