- Subscribe to RSS Feed
- Mark Question as New
- Mark Question as Read
- Float this Question for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page
Can i stop InvokeHttp processor by another processor?
- Labels:
-
Apache NiFi
Created ‎08-17-2017 06:58 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have service invokation in invokeHTTP processor and it has relaited response i want to stop invokehttp as soon as response fails is it possible to use another invokehttp processor for rest api to stop previous invokehttp or i will need to generate another flowfile for it?
Created on ‎08-17-2017 08:24 PM - edited ‎08-17-2019 07:32 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I don't have a specific link to a doc, but here is an example of what I did once using the ExecuteStreamCommand processor.
Here is a a snapshot of the configuration of the ExecuteStreamCommand processor. My particular example stops and starts the processor. Also, you can put the script anywhere the NiFi process is able to access and execute it.
Here is the script, this script had to retrieve a token, because my particular instance of NiFi was secured and used LDAP for authentication. If your instance of NiFi isn't secured then you could skip that first step and none of your curl commands will need the -H 'Authorization: Bearer'$token'' parameter. In addition, you'll have to change the processor uuid to match the uuid of the InvokeHttp processor and the URL of the NiFi instance should match yours.
#!/bin/bash # Get access token from LDAP server token=$(curl 'https://nifi-server:9091/nifi-api/access/token' -H 'Content-Type: application/x-www-form-urlencoded; charset=UTF-8' --data 'username=username&password=password' --compressed --insecure --tlsv1.2) #echo token = $token # Get the latest version of the flow version=$(curl 'https://nifi-server:9091/nifi-api/processors/62c34df2-015b-1000-89e3-e2e77533331e' -X GET -H 'Content-Type: application/x-www-form-urlencoded; charset=UTF-8' -H 'Authorization: Bearer '$token'' --compressed --insecure --tlsv1.2 | awk -F'[/:]' '{print $4}' | head -c2) #echo version = $version # This command is stopping the processor curl 'https://nifi-server:9091/nifi-api/processors/62c34df2-015b-1000-89e3-e2e77533331e' -X PUT -H 'Host: nifi-ambari-02:9091' -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:52.0) Gecko/20100101 Firefox/52.0' -H 'Accept: application/json, text/javascript, */*; q=0.01' -H 'Accept-Language: en-US,en;q=0.5' --compressed -H 'Referer: https://nifi-ambari-02:9091/nifi/' -H 'Content-Type: application/json' -H 'Authorization: Bearer '$token'' -H 'X-Requested-With: XMLHttpRequest' -H 'Connection: keep-alive' --data '{"revision":{"clientId":"6386076d-015b-1000-2a22-714f84689191","version":'$version'},"component":{"id":"62c34df2-015b-1000-89e3-e2e77533331e","state":"STOPPED"}}' --insecure --tlsv1.2 echo sleep 15 # This step starts the processor curl 'https://nifi-server:9091/nifi-api/processors/62c34df2-015b-1000-89e3-e2e77533331e' -X PUT -H 'Host: nifi-ambari-02:9091' -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:52.0) Gecko/20100101 Firefox/52.0' -H 'Accept: application/json, text/javascript, */*; q=0.01' -H 'Accept-Language: en-US,en;q=0.5' --compressed -H 'Referer: https://nifi-ambari-02:9091/nifi/' -H 'Content-Type: application/json' -H 'Authorization: Bearer '$token'' -H 'X-Requested-With: XMLHttpRequest' -H 'Connection: keep-alive' --data '{"revision":{"clientId":"6386076d-015b-1000-2a22-714f84689191","version":'$version'},"component":{"id":"62c34df2-015b-1000-89e3-e2e77533331e","state":"RUNNING"}}' --insecure --tlsv1.2 # Echo a blank line echo
Created ‎08-17-2017 11:47 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have tried restapi with put request i used links like this in my another invokehttp processsor http://localhost:8080/nifi-api/processors/ea5db028-015d-1000-5ad5-80fd006dda92 and now i want to know ow can i link json components like this to my put request body?
{ "status": { "runStatus": "STOPPED" }, "component": { "state": "STOPPED", "id": "ea5db028-015d-1000-5ad5-80fd006dda92" }, "id": "ea5db028-015d-1000-5ad5-80fd006dda92", "revision": { "version": 46, "clientId": "ef592126-015d-1000-bf4f-93c7cf7eedc0" } }
Created ‎08-17-2017 12:52 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You can use the response output to trigger another processor, you won't have to generate another flow file. A better processor to use would be the ExecuteScript or ExecuteStreamCommand processor to make the rest api call.
Created ‎08-17-2017 05:52 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Can you give me a link of example how can i do it, I have tried this but it doesn't work for me:
For GenerateFlowFiele i have: [{ "status": { "runStatus": "STOPPED" }, "component": { "state": "STOPPED", "id": "ea5db028-015d-1000-5ad5-80fd006dda92" }, "revision": { "version": 46, "clientId": "ef592126-015d-1000-bf4f-93c7cf7eedc0" } } ] and related groovy code in executeScript processor: import org.apache.commons.io.IOUtils import java.nio.charset.* def flowFile = session.get(); if (flowFile == null) { return; } def slurper = new groovy.json.JsonSlurper() def attrs = [:] as Map<String,String> session.read(flowFile, { inputStream -> def text = IOUtils.toString(inputStream, StandardCharsets.UTF_8) text=flowFile.getAttribute('text') def obj = slurper.parseText(text) obj.each {k,v -> attrs[k] = v.toString() } } as InputStreamCallback) flowFile = session.putAllAttributes(flowFile, attrs) session.transfer(flowFile, REL_SUCCESS)
Created on ‎08-17-2017 08:24 PM - edited ‎08-17-2019 07:32 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I don't have a specific link to a doc, but here is an example of what I did once using the ExecuteStreamCommand processor.
Here is a a snapshot of the configuration of the ExecuteStreamCommand processor. My particular example stops and starts the processor. Also, you can put the script anywhere the NiFi process is able to access and execute it.
Here is the script, this script had to retrieve a token, because my particular instance of NiFi was secured and used LDAP for authentication. If your instance of NiFi isn't secured then you could skip that first step and none of your curl commands will need the -H 'Authorization: Bearer'$token'' parameter. In addition, you'll have to change the processor uuid to match the uuid of the InvokeHttp processor and the URL of the NiFi instance should match yours.
#!/bin/bash # Get access token from LDAP server token=$(curl 'https://nifi-server:9091/nifi-api/access/token' -H 'Content-Type: application/x-www-form-urlencoded; charset=UTF-8' --data 'username=username&password=password' --compressed --insecure --tlsv1.2) #echo token = $token # Get the latest version of the flow version=$(curl 'https://nifi-server:9091/nifi-api/processors/62c34df2-015b-1000-89e3-e2e77533331e' -X GET -H 'Content-Type: application/x-www-form-urlencoded; charset=UTF-8' -H 'Authorization: Bearer '$token'' --compressed --insecure --tlsv1.2 | awk -F'[/:]' '{print $4}' | head -c2) #echo version = $version # This command is stopping the processor curl 'https://nifi-server:9091/nifi-api/processors/62c34df2-015b-1000-89e3-e2e77533331e' -X PUT -H 'Host: nifi-ambari-02:9091' -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:52.0) Gecko/20100101 Firefox/52.0' -H 'Accept: application/json, text/javascript, */*; q=0.01' -H 'Accept-Language: en-US,en;q=0.5' --compressed -H 'Referer: https://nifi-ambari-02:9091/nifi/' -H 'Content-Type: application/json' -H 'Authorization: Bearer '$token'' -H 'X-Requested-With: XMLHttpRequest' -H 'Connection: keep-alive' --data '{"revision":{"clientId":"6386076d-015b-1000-2a22-714f84689191","version":'$version'},"component":{"id":"62c34df2-015b-1000-89e3-e2e77533331e","state":"STOPPED"}}' --insecure --tlsv1.2 echo sleep 15 # This step starts the processor curl 'https://nifi-server:9091/nifi-api/processors/62c34df2-015b-1000-89e3-e2e77533331e' -X PUT -H 'Host: nifi-ambari-02:9091' -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:52.0) Gecko/20100101 Firefox/52.0' -H 'Accept: application/json, text/javascript, */*; q=0.01' -H 'Accept-Language: en-US,en;q=0.5' --compressed -H 'Referer: https://nifi-ambari-02:9091/nifi/' -H 'Content-Type: application/json' -H 'Authorization: Bearer '$token'' -H 'X-Requested-With: XMLHttpRequest' -H 'Connection: keep-alive' --data '{"revision":{"clientId":"6386076d-015b-1000-2a22-714f84689191","version":'$version'},"component":{"id":"62c34df2-015b-1000-89e3-e2e77533331e","state":"RUNNING"}}' --insecure --tlsv1.2 # Echo a blank line echo
Created ‎08-18-2017 05:18 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
thnank you
Created ‎08-18-2017 12:04 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
