apihadoopambarihdp

how to capture the active namenode IP by rest api ( or ambari rest api )


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?


Solution

  • 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