Support Questions
Find answers, ask questions, and share your expertise
Announcements
Alert: Welcome to the Unified Cloudera Community. Former HCC members be sure to read and learn how to activate your account here.

how to restart all datanode component by API

Solved Go to solution
Highlighted

how to restart all datanode component by API

we have ambari cluster with 176 datanodes machines ( workers )

each datanode have the following component:

capture.png

DataNode  /  HDFS
Metrics Monitor  /  Ambari Metrics
NodeManager  /  YARN

how to restart all these component on all datanode machines by API

* because it will take time to restart all datanode component manual as ( access each datanode machine from ambari and perform --> host actions --> restart all )

Michael-Bronson
1 ACCEPTED SOLUTION

Accepted Solutions

Re: how to restart all datanode component by API

Super Mentor

@Michael Bronson

Step1). You can get all the Hostnames where the DataNode is present using the following API call:

# curl --user admin:admin -H 'X-Requested-By: ambari' -X GET  "http://newhwx1.example.com:8080/api/v1/clusters/NewCluster/services/HDFS/components/DATANODE?fields=host_components/HostRoles/host_name" | grep host_name |  awk '{print $NF}' | awk -F'"' '{print $2}'

.

Step2). Once you have the list of the hosts where the Datanode is installed (using above API call) then you can use it to make the following API call using some shell script to replace the $HOST with the hostname.

# curl --user admin:admin -H 'X-Requested-By: ambari' -X POST  -d '{"RequestInfo":{"command":"RESTART","context":"Restart all components on $HOST","operation_level":{"level":"HOST","cluster_name":"NewCluster"}},"Requests/resource_filters":[{"service_name":"HDFS","component_name":"DATANODE","hosts":"$HOST"}, {"service_name":"YARN","component_name":"NODEMANAGER","hosts":"$HOST"}, {"service_name":"AMBARI_METRICS","component_name":"METRICS_MONITOR","hosts":"$HOST"} ]}' http://ambariserver.example.com:8080/api/v1/clusters/NewCluster/requests

.

NOTE: In the above call please make sure to replace the $HOST with the hostname one by one (using some shell script Loop iteration) which we retrieved from the previous API call.
Also please replace the "NewCluster" with your own cluster name.

Also please replace "ambariserver.example.com" with your ambari hostname and credentials accordingly.

1 REPLY 1

Re: how to restart all datanode component by API

Super Mentor

@Michael Bronson

Step1). You can get all the Hostnames where the DataNode is present using the following API call:

# curl --user admin:admin -H 'X-Requested-By: ambari' -X GET  "http://newhwx1.example.com:8080/api/v1/clusters/NewCluster/services/HDFS/components/DATANODE?fields=host_components/HostRoles/host_name" | grep host_name |  awk '{print $NF}' | awk -F'"' '{print $2}'

.

Step2). Once you have the list of the hosts where the Datanode is installed (using above API call) then you can use it to make the following API call using some shell script to replace the $HOST with the hostname.

# curl --user admin:admin -H 'X-Requested-By: ambari' -X POST  -d '{"RequestInfo":{"command":"RESTART","context":"Restart all components on $HOST","operation_level":{"level":"HOST","cluster_name":"NewCluster"}},"Requests/resource_filters":[{"service_name":"HDFS","component_name":"DATANODE","hosts":"$HOST"}, {"service_name":"YARN","component_name":"NODEMANAGER","hosts":"$HOST"}, {"service_name":"AMBARI_METRICS","component_name":"METRICS_MONITOR","hosts":"$HOST"} ]}' http://ambariserver.example.com:8080/api/v1/clusters/NewCluster/requests

.

NOTE: In the above call please make sure to replace the $HOST with the hostname one by one (using some shell script Loop iteration) which we retrieved from the previous API call.
Also please replace the "NewCluster" with your own cluster name.

Also please replace "ambariserver.example.com" with your ambari hostname and credentials accordingly.

Don't have an account?
Coming from Hortonworks? Activate your account here