Support Questions

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

how to stop all components on data-node machine ( worker machine ) by rest API

avatar

we have in the ambari 3 workers machines ( data node machines )

each worker machine has the following components:

DataNode ( HDFS )

Metrics Monitor

NodeManager

how to stop/start all these components only on worker machine!

second

is it possible to stop/start the components only on all workers machines ( instead to stop/start each individual work machine ) ?

47406-capture.png

47405-capture.png

YARN

Michael-Bronson
1 ACCEPTED SOLUTION

avatar
Super Collaborator
hide-solution

This problem has been solved!

Want to get a detailed solution you have to login/registered on the community

Register/Login
7 REPLIES 7

avatar
Super Collaborator

@Michael Bronson

use below api to stop all the components on a host :

PUT : http://<ambari_server_host>:8080/api/v1/clusters/cl1/hosts/<host_name>/host_components

Body :

{"RequestInfo":{"context":"Stop All Host Components","operation_level":{"level":"HOST","cluster_name":"cl1","host_names":"<host_name>"},"query":"HostRoles/component_name.in(DATANODE,HBASE_REGIONSERVER,JOURNALNODE,METRICS_MONITOR,NFS_GATEWAY,SPARK_JOBHISTORYSERVER)"},"Body":{"HostRoles":{"state":"INSTALLED"}}}

use below api to start all the components on a host :

PUT : http://<ambari_server_host>:8080/api/v1/clusters/cl1/hosts/<host_name>/host_components

Body :

{"RequestInfo":{"context":"Start All Host Components","operation_level":{"level":"HOST","cluster_name":"cl1","host_names":"<host_name>"},"query":"HostRoles/component_name.in(DATANODE,HBASE_REGIONSERVER,JOURNALNODE,METRICS_MONITOR,NFS_GATEWAY,SPARK_JOBHISTORYSERVER)"},"Body":{"HostRoles":{"state":"STARTED"}}}

Note : Here "HostRoles/component_name.in" should be replaced with components on a specific host. You can obtain this using the api : http://<ambari_server_host>:8080/api/v1/clusters/cl1/hosts/<host_name>?fields=host_components

If you are planning to write a script to automatically start/stop components on a DATANODE host then you can follow below steps :

1) Use GET http://<ambari_server_host>:8080/api/v1/clusters/cl1/services/HDFS/components/DATANODE/?fields=host_... to find all the hosts which have DATANODE installed.

2) Then use the PUT apis to STOP/START(as mentioned above) in a loop to perform the required operation on all the respective hosts.

Please let me know if you have any questions.

avatar

thank you for the response , about the syntax "http://<ambari_server_host>:8080/api/v1/clusters/cl1/hosts/<host_name>/host_components" , where is the place for body? , can you show me please the full syntax ?

Michael-Bronson

avatar
Super Collaborator
hide-solution

This problem has been solved!

Want to get a detailed solution you have to login/registered on the community

Register/Login

avatar

Is it possible to call a script on the host directly to do this shutdown?
When my server is issue a shutdown command I want to called a script directly to shutdown all ambari components on that host.

Thanks

avatar

if your ambari server is down then you cant call API in order to stop the services / components

Michael-Bronson

avatar

please exept my answer if it fit for you

Michael-Bronson

avatar

Thanks for quick reply.

I meant to call a script to shutdown the ambari components after the server is issued a shutdown command, but before it actually shutdowns!

But I found a solution to the issue anyway - I just needed to add this command "ExecStop=" to the systemd service files and all seems to work fine now.

Thanks again for your quick reply..