Created
May 13, 2017 11:41
-
-
Save prb112/7a40e334beb9a0ee1727b4498d6d4bb9 to your computer and use it in GitHub Desktop.
Restart all tasks for a given cluster in Ambari
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#https://cwiki.apache.org/confluence/display/AMBARI/Add+a+host+and+deploy+components+using+APIs | |
CLUSTER=cluster | |
IP=localhost | |
curl -H 'X-Requested-By: ambari' --user admin:admin -i -X GET http://${IP}:8080/api/v1/clusters/${CLUSTER}/hosts -o /tmp/hosts.txt | |
for host in `cat /tmp/hosts.txt | grep -i host_name | awk '{print $NF}' | sed 's|"||g'` | |
do | |
echo $host | |
curl -H 'X-Requested-By: ambari' --user admin:admin -i -X GET http://${IP}:8080/api/v1/clusters/${CLUSTER}/hosts/$host/host_components -o /tmp/host_components.txt | |
for component in `cat /tmp/host_components.txt | grep -i href | grep -i host_components | awk '{print $NF}' | sed 's|[",]||g'` | |
do | |
echo $component | |
curl -H 'X-Requested-By: ambari' --user admin:admin -i -X GET $component -o /tmp/component.txt -v | |
curl -H 'X-Requested-By: ambari' --user admin:admin -i -X PUT -d '{"HostRoles": {"state": "INSTALLED"}}' $component | |
sleep 2s | |
done | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment