Skip to content

Instantly share code, notes, and snippets.

@prakshalj0512
Created June 24, 2019 22:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save prakshalj0512/d1031eefb3af7c389ee3fa35352a7d4a to your computer and use it in GitHub Desktop.
Save prakshalj0512/d1031eefb3af7c389ee3fa35352a7d4a to your computer and use it in GitHub Desktop.
Apache Nifi Smoke Test Part II
#!/bin/bash
NIFI_HOST="localhost:8080"
HADOOP_CORE_SITE_PATH="/etc/hadoop/conf/core-site.xml"
HADOOP_HDFS_SITE_PATH="/etc/hadoop/conf/hdfs-site.xml"
TEMP_HDFS_DIRECTORY="/tmp/nifiTest"
# Retrieve Root Process ID
mainProcessID=$(curl -s http://{$NIFI_HOST}/nifi-api/flow/process-groups/root/status?recursive=true |
python -c "import sys, json; print (json.load(sys.stdin)['processGroupStatus']['id'])")
# Retrieve Process ID for newly created Process Group "SmokeTestGroup"
processID=$(python <<EOF
import sys, json, urllib;
obj = json.loads(urllib.urlopen('http://$NIFI_HOST/nifi-api/process-groups/$mainProcessID/process-groups').read().decode("utf-8"))
for x in obj['processGroups']:
if (x['component']['name'] == "SmokeTestGroup"):
print (x['component']['id']);
break;
EOF
)
# Retrieve template ID
templateID=$(
python <<EOF
import sys, json, urllib;
obj = json.loads(urllib.urlopen('http://$NIFI_HOST/nifi-api/flow/templates').read().decode("utf-8"))
for x in obj['templates']:
if (x['template']['name'] == "SmokeTest"):
print (x['template']['id']);
break;
EOF
)
# Clear and drop queue
compID=$(curl -X GET http://{$NIFI_HOST}/nifi-api/process-groups/{$processID}/connections |
python -c "import sys, json; print (json.load(sys.stdin)['connections'][0]['component']['id'])")
compVersion=$(curl -X GET http://{$NIFI_HOST}/nifi-api/process-groups/{$processID}/connections |
python -c "import sys, json; print (json.load(sys.stdin)['connections'][0]['revision']['version'])")
curl -i -X POST http://{$NIFI_HOST}/nifi-api/flowfile-queues/{$compID}/drop-requests
sleep 5s
curl -i -X DELETE http://{$NIFI_HOST}/nifi-api/connections/{$compID}?version={$compVersion}
# Delete template
curl -X DELETE http://{$NIFI_HOST}/nifi-api/templates/{$templateID}
processVersion=$(python <<EOF
import sys, json, urllib;
obj = json.loads(urllib.urlopen('http://$NIFI_HOST/nifi-api/process-groups/$mainProcessID/process-groups').read().decode("utf-8"))
for x in obj['processGroups']:
if (x['component']['name'] == "SmokeTestGroup"):
print (x['revision']['version']);
break;
EOF
)
curl -X DELETE http://{$NIFI_HOST}/nifi-api/process-groups/{$processID}?version={$processVersion}
# Clean Up
rm -f /tmp/SmokeTest.xml
hadoop fs -rm -r -f -skipTrash {$TEMP_HDFS_DIRECTORY}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment