Alex Raj Kaliamoorthy
Alex Raj Kaliamoorthy

Reputation: 2095

How to check the namenode status?

As a developer how can I check the current state of a given Namenode if it is active or standby? I have tried the getServiceState command but that is only intended for the admins with superuser access. Any command that can be run from the edge node to get the status of a provided namemnode??

Upvotes: 4

Views: 9938

Answers (3)

Stanislav G.
Stanislav G.

Reputation: 21

The simplest way to use:

hdfs haadmin -getAllServiceState 

haadmin work for HA mode.

Output:

hadoop-adh-1:8020                standby
hadoop-adh-2:8020                active

Upvotes: 0

I tried your solution but that didn't work. Here's mine which works perfectly for me ( bash script ).

until curl http://<namenode_ip>:50070/jmx?qry=Hadoop:service=NameNode,name=NameNodeStatus|grep -q 'active'; do
  printf "Waiting for namenode!"
  sleep 5
done


Explanation:
Running this curl request outputs namenode's status as json ( sample below ) which has a State flag indicating its status. So I'm simply checking for 'active' text in curl request output. For any other language, you just have to do a curl request and check its output.

{
  "beans" : [ {
    "name" : "Hadoop:service=NameNode,name=NameNodeStatus",
    "modelerType" : "org.apache.hadoop.hdfs.server.namenode.NameNode",
    "NNRole" : "NameNode",
    "HostAndPort" : "<namenode_ip>:8020",
    "SecurityEnabled" : false,
    "LastHATransitionTime" : 0,
    "State" : "active"
  } ]
}

Upvotes: 1

Alex Raj Kaliamoorthy
Alex Raj Kaliamoorthy

Reputation: 2095

Finally, I got an answer to this.

As a developer, one cannot execute dfsadmin commands due to the restriction. To check the namenode availability I used the below if loop in shellscript which did the trick. It wont tell you exactly the namenode is active but with the loop you can easily execute the desired program accordingly.

if hdfs dfs -test -e hdfs://namenodeip/* ; then
echo exist
else 
echo not exist
fi

Upvotes: 4

Related Questions