package com.feng.scheduler.log; import java.io.IOException; import java.util.ArrayList; import java.util.List; import org.apache.commons.lang.StringUtils; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.HBaseConfiguration; import org.apache.hadoop.hbase.KeyValue; import org.apache.hadoop.hbase.client.HTableInterface; import org.apache.hadoop.hbase.client.HTablePool; 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.filter.Filter; import org.apache.hadoop.hbase.filter.FilterList; import org.apache.hadoop.hbase.filter.FilterList.Operator; import org.apache.hadoop.hbase.filter.PageFilter; import org.apache.hadoop.hbase.filter.PrefixFilter; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** * @author bjzhongdegen * */ public class HBaseClient { protected static final Logger LOGGER = LoggerFactory.getLogger(HBaseClient.class); private static Configuration HBASE_CONF = null; private static HTablePool TABLE_POOL = null; private static final String CONNECTOR = "#"; private static com.feng.scheduler.common.filemanager.Configuration commonConf = null; /** * 初始化配置 */ static { commonConf = new com.feng.scheduler.common.filemanager.Configuration("common-config.xml"); Configuration conf = new Configuration(); // 与hbase/conf/hbase-site.xml中hbase.zookeeper.quorum配置的值相同 conf.set("hbase.zookeeper.quorum", commonConf.getDefault("hbase.zookeeper.quorum", "127.0.0.1")); // 与hbase/conf/hbase-site.xml中hbase.zookeeper.property.clientPort配置的值相同 conf.set("hbase.zookeeper.property.clientPort", commonConf.getDefault("hbase.zookeeper.property.clientPort", "2181")); HBASE_CONF = HBaseConfiguration.create(conf); TABLE_POOL = new HTablePool(HBASE_CONF, 30); } public static LogRecord scanLog(String tableName, String prifixKey, String startkey, String stopKey) { LOGGER.info("Get prifixKey["+prifixKey+"], startkey="+startkey+", stopKey="+stopKey); LogRecord result = new LogRecord(); StringBuffer sb = new StringBuffer(); HTableInterface table = null; try { table = TABLE_POOL.getTable(tableName); Scan s = new Scan(); s.setCaching(100); List<Filter> list = new ArrayList<Filter>(); Filter prifixFilter =new PrefixFilter(prifixKey.getBytes()); Filter pageFilter = new PageFilter(100); list.add(pageFilter); list.add(prifixFilter); Filter all = new FilterList(Operator.MUST_PASS_ALL, list); s.setFilter(all); s.setStartRow(startkey.getBytes()); if(!StringUtils.isBlank(stopKey)) { s.setStopRow(stopKey.getBytes()); } ResultScanner rs = table.getScanner(s); for (Result r : rs) { //新版本api for(Cell cell:r.rawCells()){ System.out.println("RowName:"+new String(CellUtil.cloneRow(cell))+" "); System.out.println("Timetamp:"+cell.getTimestamp()+" "); System.out.println("column Family:"+new String(CellUtil.cloneFamily(cell))+" "); System.out.println("row Name:"+new String(CellUtil.cloneQualifier(cell))+" "); System.out.println("value:"+new String(CellUtil.cloneValue(cell))+" "); } KeyValue[] kv = r.raw(); for (int i = 0; i < kv.length; i++) { sb.append(new String(kv[i].getValue())).append("\n"); if(i == kv.length - 1) { result.setNextTimestamp(getTimeStamp(new String(kv[i].getRow()))); } } } rs.close(); } catch (IOException e) { LOGGER.error("Get prifixKey["+prifixKey+"], startkey="+startkey+", stopKey="+stopKey, e); } finally { closeHTable(table); } result.setContent(sb.toString()); return result; } /** * @param string * @return */ private static Long getTimeStamp(String stopKey) { return Long.valueOf(stopKey.split(CONNECTOR)[1]); } public static void pushLog(String tableName, String taskInstanceId, String logContent) { pushLog(tableName, taskInstanceId, logContent, "f", "content"); } public static void pushLog(String tableName, String taskInstanceId, String logContent, String family, String qualifier) { LOGGER.info("push " + taskInstanceId + " log to " + tableName); HTableInterface table = null; try { table = TABLE_POOL.getTable(tableName); Put put = new Put((taskInstanceId + CONNECTOR + System.currentTimeMillis()).getBytes()); put.add(family.getBytes(), qualifier.getBytes(), logContent.getBytes()); table.put(put); } catch (IOException ioe) { LOGGER.error("push " + taskInstanceId + " log to " + tableName + " failed.", ioe); } catch (Throwable e) { LOGGER.error("push " + taskInstanceId + " log to " + tableName + " failed.", e); } finally { closeHTable(table); } } private static void closeHTable(HTableInterface table) { if(table == null) return; try { table.close(); } catch (IOException e) { LOGGER.warn("close hbase table FAILED", e); } } /** * @param args */ public static void main(String[] args) { // for(int i=0; i< 100;i ++) { // HBaseClient.pushLog("task_logs", "xxxxxx", "lllllllllllllllllllllllllll"); // } LogRecord result = HBaseClient.scanLog("task_logs", "9#", "9#1", null); System.out.println(result.getContent()); } }
相关推荐
当前状态:完全通过 HBase 0.94 和 0.94.16Java hbase-client支持 HBase 服务器的版本[√] 0.94.x[√] 0.94.0[√] 0.94.160.95.x0.96.x安装$ npm install hbase-client使用 CRUD:通过 zookeeper 创建 HBase ...
HBaseClient HBase客户端数据管理软件 概要说明 类似PL/SQL,是一个HBase数据库的客户端数据管理软件。是免费开源的软件。 基于XJava,使用xml配置文件绘制可视化界面。 可视化界面操作 表 表的定义、编辑、删除; ...
NULL 博文链接:https://hera.iteye.com/blog/757126
解决hbase client在windows环境下报Could not initialize class org.fusesource.jansi.internal.Kernel32的问题,把jar包放入hbase client的lib包下,重新运行hbase.cmd shell即可
HBaseClient-DownloadHBaseClient 编译后的版本库详见
hbase-client-2.1.0-cdh6.3.0.jar
赠送jar包:hbase-client-1.4.3.jar; 赠送原API文档:hbase-client-1.4.3-javadoc.jar; 赠送源代码:hbase-client-1.4.3-sources.jar; 赠送Maven依赖信息文件:hbase-client-1.4.3.pom; 包含翻译后的API文档:...
大多数人不熟悉命令模式。 但是,在Hadoop和HBase的世界中只有命令模式。 基于上述原因,我们专注于开发一套工具“ HBase Client”,该工具可以更轻松地使用并且具有更友好的界面。
赠送jar包:hbase-client-1.1.2.jar; 赠送原API文档:hbase-client-1.1.2-javadoc.jar; 赠送源代码:hbase-client-1.1.2-sources.jar; 赠送Maven依赖信息文件:hbase-client-1.1.2.pom; 包含翻译后的API文档:...
hbase连接工具,方便操作,可视化数据
HBase_Client_Api_Guide
hbase java api,集成spring使用,mapreduce实例,协处理器实例等等
赠送jar包:hbase-client-1.2.12.jar; 赠送原API文档:hbase-client-1.2.12-javadoc.jar; 赠送源代码:hbase-client-1.2.12-sources.jar; 赠送Maven依赖信息文件:hbase-client-1.2.12.pom; 包含翻译后的API文档...
Hbase 可视化客户端工具(非phoenix连接),支持Hbase1.x,配置方便,类似PL/SQL,是一个HBase数据库的客户端数据管理软件。
HBase是一个分布式的、面向列的开源数据库,该技术来源于Chang et al所撰写的Google论文“Bigtable:一个结构化数据的分布式存储系统”。就像Bigtable利用了Google文件系统(File System)所提供的分布式数据存储...
基于spring boot 的spring-boot-starter-hbase自动注解实现,HbaseTemplate的直接使用
赠送jar包:hbase-client-1.1.2.jar; 赠送原API文档:hbase-client-1.1.2-javadoc.jar; 赠送源代码:hbase-client-1.1.2-sources.jar; 包含翻译后的API文档:hbase-client-1.1.2-javadoc-API文档-中文(简体)-...
Fully revised for HBase 1.0, this second edition brings you up to speed on the new HBase client API, as well as security features and new case studies that demonstrate HBase use in the real world....
Flume可以和许多的系统进行整合,包括了Hadoop、Spark、Kafka、Hbase等等;当然,强悍的Flume也是可以和Mysql进行整合,将分析好的日志存储到Mysql(当然,你也可以存放到pg、oracle等等关系型数据库)。
Fully revised for HBase 1.0, this second edition brings you up to speed on the new HBase client API, as well as security features and new case studies that demonstrate HBase use in the real world. ...