Support Questions

Find answers, ask questions, and share your expertise
Announcements
Check out our newest addition to the community, the Cloudera Data Analytics (CDA) group hub.

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

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

Expert Contributor
@Michael Bronson

I guess you would be using curl, so providing the example in curl. This one is for the PUT call.

[root@ctr-e136-1513029738776-28711-01-000002 ~]# curl -XPUT -u admin:admin --header X-Requested-By:ambari http://172.27.67.14:8080/api/v1/clusters/cl1/hosts/ctr-e136-1513029738776-28711-01-000002.hwx.site/h... -d '
{"RequestInfo":{"context":"Stop All Host Components","operation_level":{"level":"HOST","cluster_name":"cl1","host_names":"ctr-e136-1513029738776-28711-01-000002.hwx.site"},"query":"HostRoles/component_name.in(JOURNALNODE,SPARK_JOBHISTORYSERVER)"},"Body":{"HostRoles":{"state":"STARTED"}}}'

"http://<ambari_server_host>:8080/api/v1/clusters/cl1/hosts/<host_name>/host_components" this is a GET call and this doesn't require any request body.

View solution in original post

7 REPLIES 7

Expert Contributor

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

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

Expert Contributor
@Michael Bronson

I guess you would be using curl, so providing the example in curl. This one is for the PUT call.

[root@ctr-e136-1513029738776-28711-01-000002 ~]# curl -XPUT -u admin:admin --header X-Requested-By:ambari http://172.27.67.14:8080/api/v1/clusters/cl1/hosts/ctr-e136-1513029738776-28711-01-000002.hwx.site/h... -d '
{"RequestInfo":{"context":"Stop All Host Components","operation_level":{"level":"HOST","cluster_name":"cl1","host_names":"ctr-e136-1513029738776-28711-01-000002.hwx.site"},"query":"HostRoles/component_name.in(JOURNALNODE,SPARK_JOBHISTORYSERVER)"},"Body":{"HostRoles":{"state":"STARTED"}}}'

"http://<ambari_server_host>:8080/api/v1/clusters/cl1/hosts/<host_name>/host_components" this is a GET call and this doesn't require any request body.

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

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

Michael-Bronson

please exept my answer if it fit for you

Michael-Bronson

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..

Take a Tour of the Community
Don't have an account?
Your experience may be limited. Sign in to explore more.