Reputation: 12786
Versions:
Hadoop: 2.0.0-cdh4.3.1
HBase: 0.94.6-cdh4.3.1
I am running cloudera quick start vm, Here is my little remote HBase Java client(HbaseClient.java), all it does is:
public static void main(String[] args) throws IOException {
Configuration config = HBaseConfiguration.create();
HTable table = new HTable(config, "s1");
System.out.println(table.getTableName());
}
When I run my java client, I get this error:
log4j:WARN No appenders could be found for logger (org.apache.hadoop.metrics2.lib.MutableMetricsFactory).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
2013-08-25 00:01:56.684 java[39082:1703] Unable to load realm info from SCDynamicStore
Exception in thread "main" org.apache.hadoop.hbase.client.NoServerForRegionException: Unable to find region for s1,,99999999999999 after 10 tries.
at org.apache.hadoop.hbase.client.HConnectionManager$HConnectionImplementation.locateRegionInMeta(HConnectionManager.java:980)
at org.apache.hadoop.hbase.client.HConnectionManager$HConnectionImplementation.locateRegion(HConnectionManager.java:885)
at org.apache.hadoop.hbase.client.HConnectionManager$HConnectionImplementation.locateRegionInMeta(HConnectionManager.java:987)
at org.apache.hadoop.hbase.client.HConnectionManager$HConnectionImplementation.locateRegion(HConnectionManager.java:889)
at org.apache.hadoop.hbase.client.HConnectionManager$HConnectionImplementation.locateRegion(HConnectionManager.java:846)
at org.apache.hadoop.hbase.client.HTable.finishSetup(HTable.java:271)
at org.apache.hadoop.hbase.client.HTable.<init>(HTable.java:211)
at org.apache.hadoop.hbase.client.HTable.<init>(HTable.java:170)
at com.***************.api.HBaseClient.main(HBaseClient.java:24)
I debugged through the code, it's hard to find whether the client is using my hbase-site.xml in resources folder or not. I even put wrong format content in hbase-site.xml, Java client is getting the same error. So I think it's not using it. Isn't resources folder part of the CLASSPATH? Is there any way to check if the hbase-site.xml gets used, if not used, how to get my client to use it.
Upvotes: 3
Views: 8846
Reputation: 4720
All you have to make sure is that the *site.xml files are copied from your hadoop instance and is made available in your eclipse classpath. Just add the folder which contains the xmls as a source folder and that should be enough.
Upvotes: 1
Reputation: 211
First put your configuration files,meaning core-site.xml hbase-site.xml hdfs-site.xml, in src/main/resources et make this a source folder (under eclipse right click on the folder -> Build Path -> Use as source folder) Then try this code
public class HbaseConfig {
private static final Logger LOG = LoggerFactory.getLogger(HbaseConfig.class);
public static org.apache.hadoop.conf.Configuration getHHConfig() {
Configuration conf = HBaseConfiguration.create();
InputStream confResourceAsInputStream = conf.getConfResourceAsInputStream("hbase-site.xml");
int available = 0;
try {
available = confResourceAsInputStream.available();
} catch (Exception e) {
//for debug purpose
LOG.debug("configuration files not found locally");
} finally {
IOUtils.closeQuietly(confResourceAsInputStream);
}
if (available == 0 ) {
conf = new Configuration();
conf.addResource("core-site.xml");
conf.addResource("hbase-site.xml");
conf.addResource("hdfs-site.xml");
}
return conf;
}
}
Finally in your code
public static void main(String[] args) throws IOException {
Configuration config = HbaseConfig.getHHConfig();
HTable table = new HTable(config, "s1");
System.out.println(table.getTableName());
}
Upvotes: 4