一步一行PHP 2016-05-24 15:53 采纳率: 0%
浏览 1469

eclipse开发Hbase的一个小程序,但是出现下面一些问题,请求大神赐教

代码:
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.HColumnDescriptor;
import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.Get;
import org.apache.hadoop.hbase.client.HBaseAdmin;
import org.apache.hadoop.hbase.client.HTable;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.client.ResultScanner;
import org.apache.hadoop.hbase.client.Scan;
import org.apache.hadoop.hbase.util.Bytes;

public class HBaseTestCase {
//锟斤拷锟斤拷锟斤拷态锟斤拷锟斤拷
static Configuration cfg=HBaseConfiguration.create();
static {
cfg.set("hbase.zookeeper.quorum", "192.168.153.128");
//cfg.set("hbase.master", "192.168.153.128");
}

//锟斤拷锟斤拷 一锟脚憋拷 
public static void creat(String tablename,String columnFamily) throws Exception {
    HBaseAdmin admin=new HBaseAdmin(cfg);
    if (admin.tableExists(tablename)) {
        System.out.println("table exists");
        System.exit(0);
    }
    else {
        HTableDescriptor tableDesc=new HTableDescriptor(TableName.valueOf(tablename));
        tableDesc.addFamily(new HColumnDescriptor(columnFamily));
        admin.createTable(tableDesc);
        System.out.println("create table success !");
    }
    admin.close();
}
//锟斤拷锟揭伙拷锟斤拷锟铰�
public static void put(String tablename,String row,String columnFamily,String column,String data) throws Exception{
    HTable table=new HTable(cfg, tablename);
    Put p1=new Put(Bytes.toBytes(row));
    p1.add(Bytes.toBytes(columnFamily), Bytes.toBytes(column), Bytes.toBytes(data));
    table.put(p1);
    System.out.println("put "+row+","+columnFamily+":"+column+","+data);
    table.close();
}

//取一锟斤拷 锟斤拷录锟斤拷锟斤拷锟�rowkey
public static void get(String tablename,String row) throws Exception{
    HTable table=new HTable(cfg, tablename);
    Get get=new Get(Bytes.toBytes(row));
    Result result=table.get(get);
    System.out.println("Get:"+result);
    table.close();
}

//锟斤拷锟斤拷
public static void scan(String tablename) throws Exception{
    HTable table=new HTable(cfg, tablename);
    Scan s=new Scan();
    ResultScanner rs=table.getScanner(s);
    for (Result r:rs){
        System.out.println("Scan:"+r);
    }
    table.close();
}

//删锟斤拷锟铰�
public static boolean delete (String tablename) throws Exception{
    HBaseAdmin admin=new HBaseAdmin(cfg);
    if (admin.tableExists(tablename)) {
        try {
            admin.disableTable(tablename);
            admin.deleteTable(tablename);
        } catch (Exception ex) {
            ex.printStackTrace();
            admin.close();
            return false;
        }
    }
    admin.close();
    return true;        
}

public static void main(String[] args) {

    String tablename="htest524";
    String columnFamily="cf";
    try {
        HBaseTestCase.creat(tablename,columnFamily);
        HBaseTestCase.put(tablename, "row1", columnFamily, "cl1", "0000");
        HBaseTestCase.put(tablename, "row1", columnFamily, "cl1", "0000");
        HBaseTestCase.put(tablename, "row1", columnFamily, "cl1", "1111");
        HBaseTestCase.put(tablename, "row1", columnFamily, "cl1", "2222");
        HBaseTestCase.put(tablename, "row1", columnFamily, "cl2", "aaaa");
        HBaseTestCase.put(tablename, "row1", columnFamily, "cl3", "bbbb");
        HBaseTestCase.put(tablename, "row1", columnFamily, "cl4", "cccc");
        HBaseTestCase.scan(tablename);
        if (true==HBaseTestCase.delete(tablename)){
            System.out.println("Delete table success! ");
        } 
    } catch (Exception e) {
      e.printStackTrace();
    }

}

}

问题:
java.io.IOException: java.lang.reflect.InvocationTargetException
at org.apache.hadoop.hbase.client.HConnectionManager.createConnection(HConnectionManager.java:457)
at org.apache.hadoop.hbase.client.HConnectionManager.createConnection(HConnectionManager.java:434)
at org.apache.hadoop.hbase.client.HConnectionManager.getConnection(HConnectionManager.java:315)
at org.apache.hadoop.hbase.client.HBaseAdmin.(HBaseAdmin.java:194)
at HBaseTestCase.creat(HBaseTestCase.java:25)
at HBaseTestCase.main(HBaseTestCase.java:90)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at org.apache.hadoop.hbase.client.HConnectionManager.createConnection(HConnectionManager.java:455)
... 5 more
Caused by: java.lang.ExceptionInInitializerError
at org.apache.hadoop.hbase.ClusterId.parseFrom(ClusterId.java:64)
at org.apache.hadoop.hbase.zookeeper.ZKClusterId.readClusterIdZNode(ZKClusterId.java:69)
at org.apache.hadoop.hbase.client.ZooKeeperRegistry.getClusterId(ZooKeeperRegistry.java:83)
at org.apache.hadoop.hbase.client.HConnectionManager$HConnectionImplementation.retrieveClusterId(HConnectionManager.java:897)
at org.apache.hadoop.hbase.client.HConnectionManager$HConnectionImplementation.(HConnectionManager.java:694)
... 10 more
Caused by: java.lang.IllegalArgumentException: java.net.UnknownHostException: master
at org.apache.hadoop.security.SecurityUtil.buildTokenService(SecurityUtil.java:418)
at org.apache.hadoop.hdfs.NameNodeProxies.createNonHAProxy(NameNodeProxies.java:231)
at org.apache.hadoop.hdfs.NameNodeProxies.createProxy(NameNodeProxies.java:139)
at org.apache.hadoop.hdfs.DFSClient.(DFSClient.java:510)
at org.apache.hadoop.hdfs.DFSClient.(DFSClient.java:453)
at org.apache.hadoop.hdfs.DistributedFileSystem.initialize(DistributedFileSystem.java:136)
at org.apache.hadoop.fs.FileSystem.createFileSystem(FileSystem.java:2433)
at org.apache.hadoop.fs.FileSystem.access$200(FileSystem.java:88)
at org.apache.hadoop.fs.FileSystem$Cache.getInternal(FileSystem.java:2467)
at org.apache.hadoop.fs.FileSystem$Cache.get(FileSystem.java:2449)
at org.apache.hadoop.fs.FileSystem.get(FileSystem.java:367)
at org.apache.hadoop.fs.Path.getFileSystem(Path.java:287)
at org.apache.hadoop.hbase.util.DynamicClassLoader.(DynamicClassLoader.java:104)
at org.apache.hadoop.hbase.protobuf.ProtobufUtil.(ProtobufUtil.java:201)
... 15 more
Caused by: java.net.UnknownHostException: master
... 29 more

  • 写回答

1条回答 默认 最新

  • threenewbee 2016-05-25 02:28
    关注

    网络不通,检查ip地址、网络连接、dns解析、对方计算机是否防火墙阻止了访问等问题。

    评论

报告相同问题?

悬赏问题

  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥85 maple软件,solve求反函数,出现rootof怎么办?
  • ¥15 求chat4.0解答一道线性规划题,用lingo编程运行,第一问要求写出数学模型和lingo语言编程模型,第二问第三问解答就行,我的ddl要到了谁来求了
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥15 maple软件,用solve求反函数出现rootof,怎么办?
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题
  • ¥20 求一个html代码,有偿
  • ¥100 关于使用MATLAB中copularnd函数的问题