Skip to content

Instantly share code, notes, and snippets.

@prb112
Created May 13, 2017 11:41
Show Gist options
  • Save prb112/7a40e334beb9a0ee1727b4498d6d4bb9 to your computer and use it in GitHub Desktop.
Save prb112/7a40e334beb9a0ee1727b4498d6d4bb9 to your computer and use it in GitHub Desktop.
Restart all tasks for a given cluster in Ambari
#!/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