Created 03-10-2017 02:51 PM
Hi Experts,
I am looking for REST API to start/stop/status check for all services running on a single node in Ambari. Can you please advice?
Created 03-10-2017 03:25 PM
In order to stop all service using ambari API (On the whole cluster) you can do the following:
curl -i -u admin:admin -H "X-Requested-By: ambari" -X PUT -d '{"RequestInfo":{"context":"_PARSE_.STOP.ALL_SERVICES","operation_level":{"level":"CLUSTER","cluster_name":"Sandbox"}},"Body":{"ServiceInfo":{"state":"INSTALLED"}}}' http://localhost:8080/api/v1/clusters/Sandbox/services
. In order to start all services you can do the following:
curl -i -u admin:admin -H "X-Requested-By: ambari" -X PUT -d '{"RequestInfo":{"context":"_PARSE_.STOP.ALL_SERVICES","operation_level":{"level":"CLUSTER","cluster_name":"Sandbox"}},"Body":{"ServiceInfo":{"state":"STARTED"}}}' http://localhost:8080/api/v1/clusters/Sandbox/services
.
Created 03-10-2017 03:28 PM
NOTE the previously shared API will stop all the services in the cluster.
But as you mentioned that you want to achieve it to stop all the components on a particular host so in that case you can try the following:
- Stop All components on host "sandbox.hortonworks.com"
curl -i -u admin:admin -H "X-Requested-By: ambari" -X PUT -d '{"RequestInfo":{"context":"Stop All Host Components","operation_level":{"level":"HOST","cluster_name":"Sandbox","host_names":"sandbox.hortonworks.com"},"query":"HostRoles/component_name.in(APP_TIMELINE_SERVER,DATANODE,HISTORYSERVER,METRICS_COLLECTOR,METRICS_GRAFANA,METRICS_MONITOR,NAMENODE,NFS_GATEWAY,NODEMANAGER,RANGER_ADMIN,RANGER_TAGSYNC,RANGER_USERSYNC,RESOURCEMANAGER,SECONDARY_NAMENODE,ZOOKEEPER_SERVER)"},"Body":{"HostRoles":{"state":"INSTALLED"}}}' http://localhost:8080/api/v1/clusters/Sandbox/hosts/sandbox.hortonworks.com/host_components
.
- Start All components on host "sandbox.hortonworks.com"
curl -i -u admin:admin -H "X-Requested-By: ambari" -X PUT -d '{"RequestInfo":{"context":"Stop All Host Components","operation_level":{"level":"HOST","cluster_name":"Sandbox","host_names":"sandbox.hortonworks.com"},"query":"HostRoles/component_name.in(APP_TIMELINE_SERVER,DATANODE,HISTORYSERVER,METRICS_COLLECTOR,METRICS_GRAFANA,METRICS_MONITOR,NAMENODE,NFS_GATEWAY,NODEMANAGER,RANGER_ADMIN,RANGER_TAGSYNC,RANGER_USERSYNC,RESOURCEMANAGER,SECONDARY_NAMENODE,ZOOKEEPER_SERVER)"},"Body":{"HostRoles":{"state":"STARTED"}}}' http://localhost:8080/api/v1/clusters/Sandbox/hosts/sandbox.hortonworks.com/host_components
You can get the list of components installed on host "sandbox.hortonworks.com" using the following API.
curl -i -u admin:admin -H "X-Requested-By: ambari" -X GET http://localhost:8080/api/v1/clusters/Sandbox/hosts/sandbox.hortonworks.com/host_components
Once you get the list of components installed on the host you can stop then using the command mentioned.
.
Running All Service Checks using Ambari API: https://gist.github.com/mr-jstraub/0b55de318eeae6695c3f#payload-to-run-all-service-checks
.
.
Created 03-10-2017 10:55 PM
@samarth srivastava Adding one more point. If you want to check the status of each component on the host, you can use this API call
curl -i -u admin:admin -H "X-Requested-By: ambari" -X GET http://<AMBARI_HOST>/api/v1/clusters/<CLUSTER_NAME>/hosts/<HOST_NAME>/host_components?fields=HostRol...
Hope it helps!
Created 08-17-2017 10:30 PM
@JaySenSharma
Thanks! Your answer helped me!!