Support Questions

Find answers, ask questions, and share your expertise
Announcements
Celebrating as our community reaches 100,000 members! Thank you!

REST API for stopping and starting all services on a node in Ambari and checking status

avatar
Explorer

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?

4 REPLIES 4

avatar
Master Mentor

@samarth srivastava

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

.

avatar
Master Mentor

@samarth srivastava

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

.

.

avatar
Contributor

@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!

avatar
Contributor

@JaySenSharma

Thanks! Your answer helped me!!