0
votes

we have HDP cluster with version 2.6.5 , with ambari platform

in the cluster we have two namenodes , one is active and the second is standby

we want to capture the active namenode IP or active namenode hostname

we try the following API , but without success ( this API not return output )

 curl -sH "X-Requested-By: ambari" -u admin:admin  -H "X-Requested-By: ambari" -X GET http://master:8080/api/v1/clusters//services/HDFS

note - master machine is the ambari server machine

where I am wrong?

1
I don't think Ambari gives you this information. You can use the NameNode HTTP address directly - OneCricketeer
@cricket_007 , I find the API - curl http://$IP_OF_NAME_NODE:50070/jmx?qry=Hadoop:service=NameNode,name=NameNodeStatus , and its works for me - jessica
Feel free to answer your own questions below - OneCricketeer

1 Answers

0
votes

I bumped into same question today, I believe Ambari will do the trick.

So here's my way with Ambari API only.

CLUSTER_LOGIN="$CLUSTER_USER:$CLUSTER_PASSWD"
CLUSTER_NAME=$(curl -s -u "$CLUSTER_LOGIN" -H "X-Requested-By: ambari" -X GET "${CLUSTER_URL}/api/v1/clusters" | jq -r .items[0].Clusters.cluster_name)

NAME_NODES=$(curl -s -u "$CLUSTER_LOGIN" -H "X-Requested-By: ambari" -X GET "${CLUSTER_URL}/api/v1/clusters/${CLUSTER_NAME}/services/HDFS/components/NAMENODE" | jq -r '.host_components[].href')

for nn in $NAME_NODES
do
   href_hastate=$(curl -s -u "$CLUSTER_LOGIN" -H "X-Requested-By: ambari" -X GET $nn | jq -r '.host.href +" "+ .metrics.dfs.FSNamesystem.HAState')
   host_href=$(echo $href_hastate | tr -s ' ' | cut -f1 -d ' ')
   hastate=$(echo $href_hastate | tr -s ' ' | cut -f2 -d ' ')
   host_ip_name=$(curl -s -u "$CLUSTER_LOGIN" -H "X-Requested-By: ambari" -X GET $host_href | jq -r '.Hosts | .ip + " " +.host_name')
   ip=$(echo $host_ip_name | tr -s ' ' | cut -f1 -d ' ')
   node_name=$(echo $host_ip_name | tr -s ' ' | cut -f2 -d ' ')
   echo $node_name $ip $hastate
done

It give me this result in my cluster

hn0-ha004.o0gzzt3sfaaeri0tmljgqkvvdc.cx.internal.chinacloudapp.cn 10.236.111.17 active
hn1-ha004.o0gzzt3sfaaeri0tmljgqkvvdc.cx.internal.chinacloudapp.cn 10.236.111.18 standby