The error should have been printed as an ERROR just before those
lines. Make sure you followed this guide to get the configurations
right: 
http://hbase.apache.org/apidocs/org/apache/hadoop/hbase/mapreduce/package-summary.html#classpath

J-D

On Sat, Jul 30, 2011 at 12:17 AM, air <[email protected]> wrote:
> ---------- Forwarded message ----------
> From: air <[email protected]>
> Date: 2011/7/30
> Subject: org.apache.hadoop.hbase.ZooKeeperConnectionException: An error is
> preventing HBase from connecting to ZooKeeper
> To: CDH Users <[email protected]>
>
>
>
> when I load data to HBase, the error occurred, I am using the Hadoop new API
> to do the work (when use old api , it works well). is there something wrong
> in my program ?  thank you for your help .
>
> import java.io.IOException;
>
> import org.apache.hadoop.conf.Configuration;
> import org.apache.hadoop.io.LongWritable;
> import org.apache.hadoop.io.NullWritable;
> import org.apache.hadoop.io.Text;
> import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
> import org.apache.hadoop.mapreduce.lib.input.TextInputFormat;
> import org.apache.hadoop.mapreduce.Job;
> import org.apache.hadoop.mapreduce.Mapper;
> import org.apache.hadoop.mapreduce.lib.output.NullOutputFormat;
> import org.apache.hadoop.util.GenericOptionsParser;
>
> import org.apache.hadoop.fs.Path;
> 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.mapreduce.TableMapReduceUtil;
>
>
> public class NewLoadToHBase {
>
>    public static class Map extends Mapper<LongWritable, Text, NullWritable,
> NullWritable>{
>
>        private Configuration conf = null;
>        private HTable table = null;
>
>        @Override
>        protected void setup(Context context)throws IOException,
> InterruptedException{
>            super.setup(context);
>            conf = context.getConfiguration(); // 在map任务执行前将conf设置好
>            try{
>                this.table = new HTable(conf , "observations");
>            }catch(IOException e){
>                throw new RuntimeException("Failed HTable construction", e);
>            }
>        }
>
>        @Override
>        protected void cleanup(Context context) throws IOException,
> InterruptedException{
>            super.cleanup(context);
>            table.close();
>        }
>
>        public void map(LongWritable key, Text value, Context context)
> throws IOException{
>            String[] valuelist = value.toString().split("\t");
>            String uid = valuelist[0];
>            byte[] rowKey = uid.getBytes();
>            Put p = new Put(rowKey);
>            p.add("content".getBytes(), "attr1".getBytes(),
> "testvalue".getBytes());
>            table.put(p);
>        }
>    }
>
>    public static void main(String[] args) throws IOException,
> InterruptedException, ClassNotFoundException {
>        Configuration conf = new Configuration();
>        String[] otherArgs = new GenericOptionsParser(conf,
> args).getRemainingArgs();
>        if(otherArgs.length != 1){
>            System.err.println("Usage: wordcount <in>");
>            System.exit(2);
>        }
>
>        Job job = new Job(conf, "NewLoadToHBase!");
>        TableMapReduceUtil.addDependencyJars(job);
>        job.setJarByClass(NewLoadToHBase.class);
>        job.setMapperClass(Map.class);
>        job.setNumReduceTasks(0);
>        job.setInputFormatClass(TextInputFormat.class);
>        job.setOutputFormatClass(NullOutputFormat.class);
>        FileInputFormat.addInputPath(job, new Path(otherArgs[0]));
>        System.exit(job.waitForCompletion(true) ? 0 : 1);
>    }
>
> }
>
>
> javac NewLoadToHBase.java
> jar cvf newloadtohbase.jar *.class
> hadoop jar newloadtohbase.jar NewLoadToHBase
> /user/hive/warehouse/datamining.db/mid_firsttime/platform=xxx/000000_0
>
> and it reports:
>
> ...
> 11/07/30 15:10:22 INFO mapred.JobClient: Task Id :
> attempt_201107291656_2633_m_000000_1, Status : FAILED
> java.lang.RuntimeException: Failed HTable construction
>        at NewLoadToHBase$Map.setup(NewLoadToHBase.java:37)
>        at org.apache.hadoop.mapreduce.Mapper.run(Mapper.java:142)
>        at org.apache.hadoop.mapred.MapTask.runNewMapper(MapTask.java:647)
>        at org.apache.hadoop.mapred.MapTask.run(MapTask.java:323)
>        at org.apache.hadoop.mapred.Child$4.run(Child.java:270)
>        at java.security.AccessController.doPrivileged(Native Method)
>        at javax.security.auth.Subject.doAs(Subject.java:396)
>        at
> org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1127)
>        at org.apache.hadoop.mapred.Child.main(Child.java:264)
> Caused by: org.apache.hadoop.hbase.ZooKeeperConnectionException: An error is
> preventing HBase from connecting to ZooKeeper
>        at
> org.apache.hadoop.hbase.client.HConnectionManager$HConnectionImplementation.getZooKeeperWatcher(HConnectionManager.java:994)
>        at
> org.apache.hadoop.hbase.client.HConnectionManager$HConnectionImplementation.setupZookeeperTrackers(HConnectionManager.java:303)
>        at
> org.apache.hadoop.hbase.client.HConnectionManager$HConnectionImplementation.<init>(HConnectionManager.java:294)
>        at
> org.apache.hadoop.hbase.client.HConnectionManager.getConnection(HConnectionManager.java:156)
>        at org.apache.hadoop.hbase.client.HTable.<init>(HTable.java:168)
>        at org.apache.hadoop.hbase.client.HTable.<init>(HTable.java:146)
>        at NewLoadToHBase$Map.setup(NewLoadToHBase.java:35)
>        ... 8 more
> Caused by: java.io.IOException: Unable to determine ZooKeeper ensemble
>        at org.apache.hadoop.hbase.zookeeper.ZKUtil.connect(ZKUtil.java:92)
>        at
> org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher.<init>(ZooKeeperWatcher.java:119)
>        at
> org.apache.hadoop.hbase.client.HConnectionManager$HConnectionImplementation.getZooKeeperWatcher(HConnectionManager.java:990)
>        ... 14 more
>
> 11/07/30 15:10:27 INFO mapred.JobClient: Task Id :
> attempt_201107291656_2633_m_000000_2, Status : FAILED
> java.lang.RuntimeException: Failed HTable construction
>        at NewLoadToHBase$Map.setup(NewLoadToHBase.java:37)
>        at org.apache.hadoop.mapreduce.Mapper.run(Mapper.java:142)
>        at org.apache.hadoop.mapred.MapTask.runNewMapper(MapTask.java:647)
>        at org.apache.hadoop.mapred.MapTask.run(MapTask.java:323)
>        at org.apache.hadoop.mapred.Child$4.run(Child.java:270)
>        at java.security.AccessController.doPrivileged(Native Method)
>        at javax.security.auth.Subject.doAs(Subject.java:396)
>        at
> org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1127)
>        at org.apache.hadoop.mapred.Child.main(Child.java:264)
> Caused by: org.apache.hadoop.hbase.ZooKeeperConnectionException: An error is
> preventing HBase from connecting to ZooKeeper
>        at
> org.apache.hadoop.hbase.client.HConnectionManager$HConnectionImplementation.getZooKeeperWatcher(HConnectionManager.java:994)
>        at
> org.apache.hadoop.hbase.client.HConnectionManager$HConnectionImplementation.setupZookeeperTrackers(HConnectionManager.java:303)
>        at
> org.apache.hadoop.hbase.client.HConnectionManager$HConnectionImplementation.<init>(HConnectionManager.java:294)
>        at
> org.apache.hadoop.hbase.client.HConnectionManager.getConnection(HConnectionManager.java:156)
>        at org.apache.hadoop.hbase.client.HTable.<init>(HTable.java:168)
>        at org.apache.hadoop.hbase.client.HTable.<init>(HTable.java:146)
>        at NewLoadToHBase$Map.setup(NewLoadToHBase.java:35)
>        ... 8 more
> Caused by: java.io.IOException: Unable to determine ZooKeeper ensemble
>        at org.apache.hadoop.hbase.zookeeper.ZKUtil.connect(ZKUtil.java:92)
>        at
> org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher.<init>(ZooKeeperWatcher.java:119)
>        at
> org.apache.hadoop.hbase.client.HConnectionManager$HConnectionImplementation.getZooKeeperWatcher(HConnectionManager.java:990)
>        ... 14 more
> ...
>
> can anyone help me ? thank you !
>
> --
> Knowledge Mangement .
>
>
>
>
> --
> Knowledge Mangement .
>

Reply via email to