1
votes

I am trying to use java API to connect it with hbase.

I am running Hortonworks Sandbox(HDP 2.5) locally on 192.168.56.101.

Following is my java code

import java.io.IOException;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.client.HTable;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.util.Bytes;

public class InsertData{

   public static void main(String[] args) throws IOException {

      // Instantiating Configuration class
       System.out.println("Trying to connect...");

       Configuration configuration = HBaseConfiguration.create();
       configuration.set("hbase.zookeeper.property.clientPort", "2181");
       configuration.set("hbase.zookeeper.quorum", "192.168.56.101");
       configuration.set("zookeeper.znode.parent", "/hbase-unsecure");

       System.out.println("HBase is running!");

       // creating a new table
       HTable table = new HTable(configuration, "emp");
       System.out.println("Table obtained ");
   }
} 

The following is the output

Trying to connect...
HBase is running!
2017-03-21 14:32:37.974 java[12263:1255672] Unable to load realm mapping info from SCDynamicStore
17/03/21 14:32:38 INFO zookeeper.ZooKeeper: Client environment:zookeeper.version=3.4.3-1240972, built on 02/06/2012 10:48 GMT
17/03/21 14:32:38 INFO zookeeper.ZooKeeper: Client environment:host.name=lm-bng-00668684.paypalcorp.com
17/03/21 14:32:38 INFO zookeeper.ZooKeeper: Client environment:java.version=1.7.0_45
17/03/21 14:32:38 INFO zookeeper.ZooKeeper: Client environment:java.vendor=Oracle Corporation
17/03/21 14:32:38 INFO zookeeper.ZooKeeper: Client environment:java.home=/Applications/corona-java-1.1.0/jdk-7u45-macosx-x64/Contents/Home/jre
17/03/21 14:32:38 INFO zookeeper.ZooKeeper: Client environment:java.class.path=/Users/aditsharma/Documents/hbase/Trial_Hbase_run/bin:/Users/aditsharma/Downloads/zookeeper-3.4.3.jar:/Users/aditsharma/Downloads/slf4j-log4j12-1.5.8.jar:/Users/aditsharma/Downloads/slf4j-api-1.5.8.jar:/Users/aditsharma/Downloads/log4j-1.2.16.jar:/Users/aditsharma/Downloads/hbase-0.92.1.jar:/Users/aditsharma/Downloads/hadoop-core-1.0.0.jar:/Users/aditsharma/Downloads/commons-logging-1.1.1.jar:/Users/aditsharma/Downloads/commons-lang-2.6.jar:/Users/aditsharma/Downloads/commons-configuration-1.8.jar
17/03/21 14:32:38 INFO zookeeper.ZooKeeper: Client environment:java.library.path=/Users/aditsharma/Library/Java/Extensions:/Library/Java/Extensions:/Network/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java:.
17/03/21 14:32:38 INFO zookeeper.ZooKeeper: Client environment:java.io.tmpdir=/var/folders/_p/73y8zhkj7mvfzxk123s6l3_m3kg68v/T/
17/03/21 14:32:38 INFO zookeeper.ZooKeeper: Client environment:java.compiler=<NA>
17/03/21 14:32:38 INFO zookeeper.ZooKeeper: Client environment:os.name=Mac OS X
17/03/21 14:32:38 INFO zookeeper.ZooKeeper: Client environment:os.arch=x86_64
17/03/21 14:32:38 INFO zookeeper.ZooKeeper: Client environment:os.version=10.11.6
17/03/21 14:32:38 INFO zookeeper.ZooKeeper: Client environment:user.name=aditsharma
17/03/21 14:32:38 INFO zookeeper.ZooKeeper: Client environment:user.home=/Users/aditsharma
17/03/21 14:32:38 INFO zookeeper.ZooKeeper: Client environment:user.dir=/Users/aditsharma/Documents/hbase/Trial_Hbase_run
17/03/21 14:32:38 INFO zookeeper.ZooKeeper: Initiating client connection, connectString=192.168.56.101:2181 sessionTimeout=90000 watcher=hconnection
17/03/21 14:32:38 INFO zookeeper.ClientCnxn: Opening socket connection to server /192.168.56.101:2181
17/03/21 14:32:38 INFO zookeeper.RecoverableZooKeeper: The identifier of this process is 12263@LM-BNG-00668684
17/03/21 14:32:38 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.
17/03/21 14:32:38 INFO zookeeper.ClientCnxn: Socket connection established to 192.168.56.101/192.168.56.101:2181, initiating session
17/03/21 14:32:38 INFO zookeeper.ClientCnxn: Session establishment complete on server 192.168.56.101/192.168.56.101:2181, sessionid = 0x15aeff6fa460020, negotiated timeout = 40000

As you can see it is getting stuck and "Table obtained" is not getting printed. Thus table was not obtained.

I am using the following jars:
1) commons-configuration-1.8.jar
2) commons-lang-2.6.jar
3) commons-logging-1.1.1.jar
4) hadoop-core-1.0.0.jar
5) hbase-0.92.1.jar
6) log4j-1.2.16.jar
7) slf4j-api-1.5.8.jar
8) slf4j-log4j12-1.5.8.jar
9) zookeeper-3.4.3.jar

UPDATE I also create a runnable jar and tried to run it directly on the cluster. Still it is not running.

1
Can you check that your HBase Master and Region Servers are running? And can you provide logs of HBase Master and RS?Alex
Yes I checked they are running.Aditya Sharma
How do I get there logs?Aditya Sharma
Check /var/log/hbase catalogAlex
The logs have an error like this : org.apache.solr.client.solrj.impl.CloudSolrClient$RouteException: No live SolrServers available to handle this request:[172.17.0.2:8886/solr/ranger_audits_shard1_replica1].Aditya Sharma

1 Answers

0
votes

You error is related with the Solr engine which is required for the HBase work in HDP 2.5. Try to start Infra service and Atlas service. Follow this article to do this. After this your HBase operation should work.