Hadoop get active namenode

Few hadoop commands to get namenode information

List the namenode hostnames

[email protected][~] hdfs getconf -namenodes
dw-master01.cstest.com dw-master02.cstest.com

Get nameservice name

[email protected][~] hdfs getconf -confKey dfs.nameservices
nameservice1

Get active and standby namenodes

[email protected][~] hdfs getconf -confKey dfs.ha.namenodes.nameservice1
namenode70,namenode95

[email protected][~] hdfs haadmin -getServiceState namenode70
active
[email protected][~] hdfs haadmin -getServiceState namenode95
standby

Read More

Hive connection using java

Here is a sample java code to connect hive database through JDBC.

import java.sql.SQLException;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.sql.DriverManager;

public class HiveJdbcTest{
  private static String driverName = "org.apache.hive.jdbc.HiveDriver";

  public static void main(String[] args) throws SQLException {
    try {
      Class.forName(driverName);
    } catch (ClassNotFoundException e) {
      e.printStackTrace();
      System.exit(1);
    }

    Connection con = DriverManager.getConnection("jdbc:hive2://<hive_server>:10000/<db>", "", "");
    Statement stmt = con.createStatement();
    String sql = "show tables";
    System.out.println("Current query: " + sql);
    ResultSet res = stmt.executeQuery(sql);
    if (res.next()) {
      System.out.println(res.getString(1));
        }

  }
}

If you are facing any trouble compiling or running this program include hive and hadoop libraries to classpath using : Read More