Support Questions
Find answers, ask questions, and share your expertise

Ambari API to restart all the services with stale configurations ?

Super Guru

Is there any single curl command to restart all the services with stale configurations using Ambari API ?

1 ACCEPTED SOLUTION

Accepted Solutions

Expert Contributor

Unfortunately this is not a part of the release branch. The patch is committed to trunk and scheduled for 2.4.0.

https://issues.apache.org/jira/browse/AMBARI-14394

View solution in original post

6 REPLIES 6

Expert Contributor

Unfortunately this is not a part of the release branch. The patch is committed to trunk and scheduled for 2.4.0.

https://issues.apache.org/jira/browse/AMBARI-14394

View solution in original post

Super Guru

Thanks @swagle

Super Guru

Okay till we get single command, I have created below script which can be useful for others who has same question 🙂

[root@sandbox test12334]# cat ambari.props
CLUSTER_NAME=Sandbox
AMBARI_ADMIN_USER=admin
AMBARI_ADMIN_PASSWORD=admin
AMBARI_HOST=sandbox.hortonworks.com
[root@sandbox test12334]# cat restart_services.sh
#!/bin/bash
#Author - Kuldeep Kulkarni (http://crazyadmins.com)
#############
LOC=`pwd`
PROP=ambari.props
source $LOC/$PROP
#############
start_stale_services()
{
echo "curl -u $AMBARI_ADMIN_USER:$AMBARI_ADMIN_PASSWORD http://$AMBARI_HOST:8080/api/v1/clusters/Sandbox/host_components?HostRoles/stale_configs=true&fields=HostRoles/service_name,HostRoles/host_name&minimal_response=false"> /tmp/curl_ambari.sh
sh /tmp/curl_ambari.sh 1 > /tmp/stale_services_json 2>/dev/null
sleep 1
grep host_components /tmp/stale_services_json|grep -v stale|rev|cut -d'"' -f2|rev > /tmp/list_of_components
for URL in `cat /tmp/list_of_components`
do
curl -u $AMBARI_ADMIN_USER:$AMBARI_ADMIN_PASSWORD -i -H 'X-Requested-By: ambari' -X PUT -d '{"HostRoles": {"state": "INSTALLED"}}' "$URL"
sleep 0.5
curl -u $AMBARI_ADMIN_USER:$AMBARI_ADMIN_PASSWORD -i -H 'X-Requested-By: ambari' -X PUT -d '{"HostRoles": {"state": "STARTED"}}' "$URL"
done
}
start_stale_services

Note - to run this script, you should have ambari.props and script at the same location.

I tried below curl call to stop all/start all but it did not clear the stale service restart alerts hence I had to come up with above workaround.

curl -u admin:$PASSWORD -i -H 'X-Requested-By: ambari' -X PUT -d '{"RequestInfo": {"context" :"Stop HDFS via REST"}, "Body": {"ServiceInfo": {"state": "INSTALLED"}}}' http://AMBARI_SERVER_HOST:8080/api/v1/clusters/CLUSTER_NAME/services
curl -u admin:$PASSWORD -i -H 'X-Requested-By: ambari' -X PUT -d '{"RequestInfo": {"context" :"Stop HDFS via REST"}, "Body": {"ServiceInfo": {"state": "STARTED"}}}' http://AMBARI_SERVER_HOST:8080/api/v1/clusters/CLUSTER_NAME/services

Super Guru

@swagle ^^

Expert Contributor

The Start All/Stop All works just the same although there is a slight delay in updating the state which would mean stae alert not cleared immediately. I believe we send config tags from the agent only after a certain number if heartbeats.

However, what you have in the scrip is exactly what the UI does, so that should work just fine. (+1)

Super Guru

@swagle Thank you. I will check with start all/stop all again.