<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>NiFi-API Archives - Big Data Processing</title>
	<atom:link href="https://bigdataproc.com/tag/nifi-api/feed/" rel="self" type="application/rss+xml" />
	<link>https://bigdataproc.com/tag/nifi-api/</link>
	<description>Big Data Solution for GCP, AWS, Azure and on-prem</description>
	<lastBuildDate>Wed, 07 Nov 2018 16:05:56 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.3.2</generator>
	<item>
		<title>NiFi API to filter Processor Groups</title>
		<link>https://bigdataproc.com/nifi-api-to-filter-processor-groups/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=nifi-api-to-filter-processor-groups</link>
					<comments>https://bigdataproc.com/nifi-api-to-filter-processor-groups/#respond</comments>
		
		<dc:creator><![CDATA[Gaurang]]></dc:creator>
		<pubDate>Wed, 24 Oct 2018 14:49:02 +0000</pubDate>
				<category><![CDATA[Hadoop]]></category>
		<category><![CDATA[NiFi]]></category>
		<category><![CDATA[NiFi-API]]></category>
		<guid isPermaLink="false">http://allabouthadoop.net/?p=77</guid>

					<description><![CDATA[<p>Recently I was working on NiFi and realize that our Dev Instance is running too slow, reason being Developers forgot to cleanup their work.&#160; And&#8230;</p>
<div class="more-link-wrapper"><a class="more-link" href="https://bigdataproc.com/nifi-api-to-filter-processor-groups/">Continue reading<span class="screen-reader-text">NiFi API to filter Processor Groups</span></a></div>
<p>The post <a rel="nofollow" href="https://bigdataproc.com/nifi-api-to-filter-processor-groups/">NiFi API to filter Processor Groups</a> appeared first on <a rel="nofollow" href="https://bigdataproc.com">Big Data Processing </a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>Recently I was working on NiFi and realize that our Dev Instance is running too slow, reason being Developers forgot to cleanup their work.&nbsp;</p>



<p>And So I used the NiFi API and write the code in python to identify some of the processor groups which we can delete. I will walk through the code here.</p>



<h2 class="wp-block-heading">How to get API token?</h2>



<p>To access NiFi endpoint behind the security you would need API token. And then you need to send this API token in header of all your request.&nbsp;</p>



<p>Following code will take the username and password and based on&nbsp;</p>



<pre class="lang:python theme:twilight" title="NiFi API get API token">def get_token(username, password, host):
    url = "https://%s:8080/nifi-api/access/token" % host
    header = {"Content-Type": "application/x-www-form-urlencoded;charset=UTF-8"}
    data = {"username": username, "password": password}

    resp = requests.post(url, data=data, headers=header, verify=False)

    if resp.status_code not in (200, 201):
        print resp.reason
        print resp.text
        exit(1)
    return resp.text
</pre>



<h2 class="wp-block-heading">How to Find Stopped Processor Group?</h2>



<p>Following code will find all the processor group which doesn&#8217;t have any processor running.</p>



<pre class="lang:python theme:twilight" title="Find Stopped processor Group using NiFi API">
def find_stopped_processor(group_id, host):
    url = "https://%s:8080/nifi-api/process-groups/%s" % (host, group_id)
    header = {"Authorization": "Bearer %s" % utils.ACCESS_TOKEN}
    r = requests.get(url, headers=header, verify=False)
    resp = r.json()
    running_count = resp.get("runningCount")
    if int(running_count) == 0:
        print "%s,%s" % (group_id, resp.get("status").get("name"))


def find_processor_group_stopped_processor(parent_processor, host):
    for processor_group in parent_processor:
        p = processor_group.get("processGroupStatusSnapshot")
        if len(p.get("processGroupStatusSnapshots")) > 0:
            find_processor_group_stopped_processor(p.get("processGroupStatusSnapshots"))
        else:
            find_stopped_processor(p.get("id"), host)
</pre>



<p></p>
<p>The post <a rel="nofollow" href="https://bigdataproc.com/nifi-api-to-filter-processor-groups/">NiFi API to filter Processor Groups</a> appeared first on <a rel="nofollow" href="https://bigdataproc.com">Big Data Processing </a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://bigdataproc.com/nifi-api-to-filter-processor-groups/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
