0
votes

I am trying to connect to HBase standalone single cluster installed on my Ubuntu machine from Java Program. I followed the steps given in this blog. https://autofei.wordpress.com/2012/04/02/java-example-code-using-hbase-data-model-operations/

I am able to connect to HBase in EMR cluster when I run this code on AWS EC2 but not able to do it on my local. My hadoop is running and I am able to open hbase shell and scan 'storetable' is showing me some rows without any exception. It seems that the program is going in an infinite loop at line -

table = new HTable(HBaseConfig, "storetable");

because the message "HBase table created..." is never printed. There is no exception caught by the catch block. Please help me out.

I appreciate your help.

Code:

public void connectHBase()
    {
        System.out.println("Trying to establish HBase connection...");
        HBaseConfig = HBaseConfiguration.create();
        HBaseConfig.set("hbase.zookeeper.quorum", "localhost");
        HBaseConfig.set("hbase.zookeeper.property.clientPort", "2181");
        System.out.println("HBase Connection succeded...");
        try 
        {
            System.out.println("Creating HBase table...");
            table = new HTable(HBaseConfig, "storetable");
            System.out.println("HBase table created...");
        } 
        catch(Exception e) 
        {
            System.out.println("Some exception occured...");
            e.printStackTrace();
        }        
    }

Console Output:

Trying to establish HBase connection...
HBase Connection succeded...
Creating HBase table...
15/03/29 16:53:37 INFO zookeeper.ZooKeeper: Client environment:zookeeper.version=3.4.3-1240972, built on 02/06/2012 10:48 GMT
15/03/29 16:53:37 INFO zookeeper.ZooKeeper: Client environment:host.name=localhost
15/03/29 16:53:37 INFO zookeeper.ZooKeeper: Client environment:java.version=1.7.0_76
15/03/29 16:53:37 INFO zookeeper.ZooKeeper: Client environment:java.vendor=Oracle Corporation
15/03/29 16:53:37 INFO zookeeper.ZooKeeper: Client environment:java.home=/usr/lib/jvm/java-7-oracle/jre
15/03/29 16:53:37 INFO zookeeper.ZooKeeper: Client environment:java.class.path=/home/sankalp/workspace/AWSHadoopProject/bin:/home/sankalp/aws-java-sdk/1.9.27/lib/aws-java-sdk-1.9.27.jar:/home/sankalp/aws-java-sdk/1.9.27/third-party/javax-mail-1.4.6/javax.mail-api-1.4.6.jar:/home/sankalp/aws-java-sdk/1.9.27/third-party/joda-time-2.2/joda-time-2.2.jar:/home/sankalp/aws-java-sdk/1.9.27/third-party/jackson-annotations-2.3.0/jackson-annotations-2.3.0.jar:/home/sankalp/aws-java-sdk/1.9.27/third-party/freemarker-2.3.18/freemarker-2.3.18.jar:/home/sankalp/aws-java-sdk/1.9.27/third-party/httpcomponents-client-4.3/httpcore-4.3.jar:/home/sankalp/aws-java-sdk/1.9.27/third-party/httpcomponents-client-4.3/httpclient-4.3.jar:/home/sankalp/aws-java-sdk/1.9.27/third-party/jackson-core-2.3.2/jackson-core-2.3.2.jar:/home/sankalp/aws-java-sdk/1.9.27/third-party/commons-logging-1.1.3/commons-logging-1.1.3.jar:/home/sankalp/aws-java-sdk/1.9.27/third-party/spring-3.0/spring-context-3.0.7.jar:/home/sankalp/aws-java-sdk/1.9.27/third-party/spring-3.0/spring-beans-3.0.7.jar:/home/sankalp/aws-java-sdk/1.9.27/third-party/spring-3.0/spring-core-3.0.7.jar:/home/sankalp/aws-java-sdk/1.9.27/third-party/jackson-databind-2.3.2/jackson-databind-2.3.2.jar:/home/sankalp/aws-java-sdk/1.9.27/third-party/aspectj-1.6/aspectjweaver.jar:/home/sankalp/aws-java-sdk/1.9.27/third-party/aspectj-1.6/aspectjrt.jar:/home/sankalp/aws-java-sdk/1.9.27/third-party/commons-codec-1.6/commons-codec-1.6.jar:/home/sankalp/workspace/AWSHadoopProject/undertow-examples-1.2.0.Beta9.jar:/home/sankalp/workspace/AWSHadoopProject/commons-configuration-1.8.jar:/home/sankalp/workspace/AWSHadoopProject/commons-lang-2.6.jar:/home/sankalp/workspace/AWSHadoopProject/commons-logging-1.1.1.jar:/home/sankalp/workspace/AWSHadoopProject/hadoop-core-1.0.0.jar:/home/sankalp/workspace/AWSHadoopProject/hbase-0.92.1.jar:/home/sankalp/workspace/AWSHadoopProject/log4j-1.2.16.jar:/home/sankalp/workspace/AWSHadoopProject/slf4j-api-1.5.8.jar:/home/sankalp/workspace/AWSHadoopProject/slf4j-log4j12-1.5.8.jar:/home/sankalp/workspace/AWSHadoopProject/zookeeper-3.4.3.jar:/home/sankalp/workspace/AWSHadoopProject/json-simple-1.1.1.jar
15/03/29 16:53:37 INFO zookeeper.ZooKeeper: Client environment:java.library.path=/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib
15/03/29 16:53:37 INFO zookeeper.ZooKeeper: Client environment:java.io.tmpdir=/tmp
15/03/29 16:53:37 INFO zookeeper.ZooKeeper: Client environment:java.compiler=<NA>
15/03/29 16:53:37 INFO zookeeper.ZooKeeper: Client environment:os.name=Linux
15/03/29 16:53:37 INFO zookeeper.ZooKeeper: Client environment:os.arch=amd64
15/03/29 16:53:37 INFO zookeeper.ZooKeeper: Client environment:os.version=3.16.0-33-generic
15/03/29 16:53:37 INFO zookeeper.ZooKeeper: Client environment:user.name=sankalp
15/03/29 16:53:37 INFO zookeeper.ZooKeeper: Client environment:user.home=/home/sankalp
15/03/29 16:53:37 INFO zookeeper.ZooKeeper: Client environment:user.dir=/home/sankalp/workspace/AWSHadoopProject
15/03/29 16:53:37 INFO zookeeper.ZooKeeper: Initiating client connection, connectString=localhost:2181 sessionTimeout=180000 watcher=hconnection
15/03/29 16:53:37 INFO zookeeper.ClientCnxn: Opening socket connection to server /127.0.0.1:2181
15/03/29 16:53:37 INFO client.ZooKeeperSaslClient: Client will not SASL-authenticate because the default JAAS configuration section 'Client' could not be found. If you are not using SASL, you may ignore this. On the other hand, if you expected SASL to work, please fix your JAAS configuration.
15/03/29 16:53:37 INFO zookeeper.RecoverableZooKeeper: The identifier of this process is 9146@skynet
15/03/29 16:53:37 INFO zookeeper.ClientCnxn: Socket connection established to localhost/127.0.0.1:2181, initiating session
15/03/29 16:53:37 INFO zookeeper.ClientCnxn: Session establishment complete on server localhost/127.0.0.1:2181, sessionid = 0x14c6746b9f4000d, negotiated timeout = 40000
2
It says that it is unable to connect. Can you check in hbase shell if you are connected? - proutray
Thanks for your comment. I checked with what you said. I am able to connect to hbase shell and scan table over there. However, I figured out that it is not an exception that I am facing. My program is going in an infinite loop or is caught somewhere at the line when I am creating a table object. I updated the question. - Sankalp

2 Answers

1
votes

check your jar versions, use the same version of jars as in HBase you are trying to connect, also check your hosts file for loopback address.

0
votes

I have faced this issue where create table was not working from java. In my case i haven't included hbasee-site into my class path.

You can refere below link.

Not able to create hbase using java