AnsweredAssumed Answered

accessing hbase table from tomcat application

Question asked by nishantxebia on Aug 25, 2016
Latest reply on Nov 4, 2016 by aalvarez

0down votefavorite

 

 

I have written a service which is deployed on Tomcat .the service is to read the hbase the hbase table to get certain value . The hbase configuration code is :

public static Configuration getConf(){
  
System.out.println("Inside configuration");
  
Configuration conf;
  conf
= HBaseConfiguration.create();
  conf
.set("hbase.master", "maprfs:///hbase");
  
return conf;
}

Now method to get the table name is :

public static HTable getTableName(Configuration conf,String tableName) throws IOException{
  
HTable processTable = new HTable(conf,tableName);
  
System.out.println("Table name is 1111"+processTable.getName());
  
return processTable;
  
}

 

Now method to get the values from table is :

public ProcessEntity getExecutionDetail(String executionID,String moduleName) {
  
System.out.println("Im in get method");

  
try{
  
HTable hTable = getTableName(getConf(),"ProcessTable");
  
System.out.println("Table name is "+hTable.getName());
  
String filter=".*"+executionID+moduleName;
  
System.out.println("filter is"+filter);
  
synchronized (this){
  
this.pr= new ProcessEntity();
  
Scan s = new Scan();
  
Filter f= new RowFilter(CompareFilter.CompareOp.EQUAL,new RegexStringComparator(filter));
  s
.setFilter(f);
  
ResultScanner rs = hTable.getScanner(s);
  
for(Result r :rs){
pr
.setScheduledDateTime((Bytes.toString(r.getValue(Bytes.toBytes(("processFamily1")),

}

But the code stucks in line ResultScanner rs = hTable.getScanner(s); for a good amount of time before giving connection reset error. It means it not able to connect to Hbase table.I am using MapR distribution.Any help would be appreciated.

Note: If I run this code as simple java application instead of webservice it is working fine.But when I m deploying this as a service to tomcat it is not able to make a connection to hbase. Please help me if i m missing anything related to hbase configuration.

 

I m using M7 and creating the table the same way as you have created except the fact that i m providing only table name and not the full path.I m able to access the table if i m running the hbase project standalone .But in one of the usecase my webservice is reading this hbase table .My service is deployed on tomcat .So do I need to provide some other configuration detail.

My tomcat is present on a different node on cluster .

 

Your answer would be much appreciated.

Thanks a lot

Outcomes