title: Connect Java to HBase Remotedly
body: <p>I'm trying to connect Java to HBase in remote server.</p>
  
  <p>Here is the case :</p>
  
  <p>The java class is in my local computer (192.168.111.165)</p>
  
  <p>The Hadoop File System and HBase is in another server (192.168.11.7)</p>
  
  <p>Here is my Hadoop's core-site.xml (in 192.168.11.7) :</p>
  
  <pre><code>&lt;configuration&gt;
    &lt;property&gt;
          &lt;name&gt;fs.default.name&lt;/name&gt;
          &lt;value&gt;hdfs://192.168.11.7:9000&lt;/value&gt;
    &lt;/property&gt;
  &lt;/configuration&gt;
  </code></pre>
  
  <p>Here is my Hadoop's hdfs-site.xml (in 192.168.11.7) :</p>
  
  <pre><code>&lt;configuration&gt;
    &lt;property&gt;
          &lt;name&gt;dfs.replication&lt;/name&gt;
          &lt;value&gt;1&lt;/value&gt;
    &lt;/property&gt;
    &lt;property&gt;
      &lt;name&gt;dfs.name.dir&lt;/name&gt;
      &lt;value&gt;file:///home/hadoop/hadoopinfra/hdfs/namenode&lt;/value&gt;
    &lt;/property&gt;
  
    &lt;property&gt;
      &lt;name&gt;dfs.data.dir&lt;/name&gt;
      &lt;value&gt;file:///home/hadoop/hadoopinfra/hdfs/datanode&lt;/value&gt;
    &lt;/property&gt;   
  &lt;/configuration&gt;
  </code></pre>
  
  <p>Here is my HBase's hbase-site.xml (in 192.168.11.7) :</p>
  
  <pre><code>&lt;configuration&gt;
    &lt;property&gt;
      &lt;name&gt;hbase.rootdir&lt;/name&gt;
      &lt;value&gt;hdfs://192.168.11.7:9000/hbase&lt;/value&gt;
    &lt;/property&gt;
  
    &lt;property&gt;
      &lt;name&gt;hbase.zookeeper.property.dataDir&lt;/name&gt;
      &lt;value&gt;/home/hadoop/zookeeper&lt;/value&gt;
    &lt;/property&gt;
  
    &lt;property&gt;
      &lt;name&gt;hbase.cluster.distributed&lt;/name&gt;
      &lt;value&gt;true&lt;/value&gt;
    &lt;/property&gt;
  &lt;/configuration&gt;
  </code></pre>
  
  <p>I have turned on HDFS and HBase successfully (proven with I can run "list" command in HBase shell). Note that I run the "list" command in HBase Shell using ssh to 192.168.11.7 from my local computer.
  From my local computer (192.168.111.165), I can access hadoop file system and hbase using browser (hadoop by hitting URL : <a href="http://192.168.11.7:50070/" rel="nofollow">http://192.168.11.7:50070/</a>, hadoop cluster by hitting URL : <a href="http://192.168.11.7:8088/" rel="nofollow">http://192.168.11.7:8088/</a>, HBase by hitting URL : <a href="http://192.168.11.7:16010/" rel="nofollow">http://192.168.11.7:16010/</a>)</p>
  
  <p>Now, I develop a Java Code in my local computer (192.168.111.165), which has the hbase-site.xml :</p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;?xml-stylesheet type="text/xsl" href="configuration.xsl"?&gt;
    &lt;configuration&gt;
      &lt;property&gt;
        &lt;name&gt;hbase.rootdir&lt;/name&gt;
        &lt;value&gt;hdfs://192.168.11.7:9000/hbase&lt;/value&gt;
      &lt;/property&gt;
  &lt;/configuration&gt;
  </code></pre>
  
  <p>and my Main code as follows :</p>
  
  <pre><code>private static Configuration conf = null;
  
  public static void main(String[] args) throws Exception {
      try {
          conf = HBaseConfiguration.create();
          String tablename = "scores";
          String[] familys = { "grade", "course" };
          creatTable(tablename, familys);
      } catch (Exception e) {
          e.printStackTrace();
  
          throw e;
      }
  }
  
  public void creatTable(String tableName, String[] familys)
          throws Exception {
      HBaseAdmin admin = new HBaseAdmin(conf);
      if (admin.tableExists(tableName)) {
          System.out.println("table already exists!");
      } else {
          HTableDescriptor tableDesc = new HTableDescriptor(tableName);
          for (int i = 0; i &lt; familys.length; i++) {
              tableDesc.addFamily(new HColumnDescriptor(familys[i]));
          }
          admin.createTable(tableDesc);
          System.out.println("create table " + tableName + " ok.");
      }
  }
  </code></pre>
  
  <p>When I run the code, I got Exception, which has the stacktrace :</p>
  
  <pre><code>org.apache.hadoop.hbase.client.RetriesExhaustedException: Can't get the locations
  at org.apache.hadoop.hbase.client.RpcRetryingCallerWithReadReplicas.getRegionLocations(RpcRetryingCallerWithReadReplicas.java:319)
  at org.apache.hadoop.hbase.client.ScannerCallableWithReplicas.call(ScannerCallableWithReplicas.java:156)
  at org.apache.hadoop.hbase.client.ScannerCallableWithReplicas.call(ScannerCallableWithReplicas.java:60)
  at org.apache.hadoop.hbase.client.RpcRetryingCaller.callWithoutRetries(RpcRetryingCaller.java:210)
  at org.apache.hadoop.hbase.client.ClientScanner.call(ClientScanner.java:326)
  at org.apache.hadoop.hbase.client.ClientScanner.nextScanner(ClientScanner.java:301)
  at org.apache.hadoop.hbase.client.ClientScanner.initializeScannerInConstruction(ClientScanner.java:166)
  at org.apache.hadoop.hbase.client.ClientScanner.&lt;init&gt;(ClientScanner.java:161)
  at org.apache.hadoop.hbase.client.HTable.getScanner(HTable.java:797)
  at org.apache.hadoop.hbase.MetaTableAccessor.fullScan(MetaTableAccessor.java:602)
  at org.apache.hadoop.hbase.MetaTableAccessor.tableExists(MetaTableAccessor.java:366)
  at org.apache.hadoop.hbase.client.HBaseAdmin.tableExists(HBaseAdmin.java:406)
  at org.apache.hadoop.hbase.client.HBaseAdmin.tableExists(HBaseAdmin.java:416)
  at com.volt.kismistest.handler.TestHBaseHandler.creatTable(TestHBaseHandler.java:82)
  at com.volt.kismistest.handler.TestHBaseHandler.doAction(TestHBaseHandler.java:47)
  at com.volt.kismistest.handler.TestHBaseHandler.doAction(TestHBaseHandler.java:1)
  </code></pre>
  
  <p>Note in the exception is :</p>
  
  <p>TestHBaseHandler is the name of my java class</p>
  
  <p>TestHBaseHandler.java:82 is : <strong>if (admin.tableExists(tableName)) {</strong> on the creatTable method</p>
  
  <p>TestHBaseHandler.java:47 is : <strong>creatTable(tablename, familys);</strong> on the main method</p>
  
  <p>Can anyone help me fixing this problem?</p>
  
  <p>Thank you very much</p>