20,809
社区成员
发帖
与我相关
我的任务
分享
public static void main(String[] args) throws IOException,
InterruptedException, ClassNotFoundException, URISyntaxException {
args = new String[3];
args[0] = "/root/workspace/createIndex/config.properties";
if (args.length == 0 || args.length > 3) {
usage();
}
createHBaseConfiguration(args[0]);
ConfigProperties tutorialProperties = new ConfigProperties(args[0]);
String tbName = tutorialProperties.getHBTbName();
String tbFamily = tutorialProperties.getHBFamily();
Job job = new Job(conf, "SolrHBaseIndexer");
job.setJarByClass(SolrHBaseIndexer.class);
Scan scan = new Scan();
scan.addFamily(Bytes.toBytes(tbFamily));
scan.setCaching(10000); // 设置缓存数据量来提高效率
scan.setCacheBlocks(false);
// 创建Map任务
System.out.println("jianli yige mr chengxu ...........................");
TableMapReduceUtil.initTableMapperJob(tbName, scan,
SolrHBaseIndexerMapper.class, null, null, job);
// 不需要输出
job.setOutputFormatClass(NullOutputFormat.class);
// job.setNumReduceTasks(0);
boolean b = job.waitForCompletion(true);
if (!b) {
throw new IOException("error with job!");
}
System.exit(b ? 0 : 1);
}
private int i = 0;
// MAPPER任务
public void map(ImmutableBytesWritable key, Result hbaseResult,
Context context) throws InterruptedException, IOException {
Configuration conf = context.getConfiguration();
//solr服务连接配置
// HttpSolrServer solrServer = new HttpSolrServer(conf.get("solr.server"));
// solrServer.setDefaultMaxConnectionsPerHost(50);
//solrServer.setMaxTotalConnections(100);
// solrServer.setSoTimeout(200);
// solrServer.setConnectionTimeout(20000);
// SolrInputDocument solrDoc = new SolrInputDocument();
// System.out.println("2222222222222222222222222222222222222222222222----"+hbaseResult.size());
// try {
// solrDoc.addField("ID", new String(hbaseResult.getRow()));
for (KeyValue rowQualifierAndValue : hbaseResult.list()) {
String fieldName = new String(
rowQualifierAndValue.getQualifier());
String fieldValue = new String(rowQualifierAndValue.getValue());
if (
// fieldName.equalsIgnoreCase("DZBM")
// || fieldName.equalsIgnoreCase("GMSFHM")
// || fieldName.equalsIgnoreCase("FJMC")
// || fieldName.equalsIgnoreCase("XM")
fieldName.equalsIgnoreCase("FDDWZGYXM")
|| fieldName.equalsIgnoreCase("DWMC")
|| fieldName.equalsIgnoreCase("SFZHM")
|| fieldName.equalsIgnoreCase("TXSJ")
) {
// solrDoc.addField(fieldName, fieldValue);
}
}
// solrServer.add(solrDoc);
// 提交
// solrServer.commit(true, true, true);
i = i + 1;
System.out.println("已成功-- " + i);
// } catch (SolrServerException e) {
// System.err.println("更新Solr索引异常:" + new String(hbaseResult.getRow()));
// }
}
从以下位置加载配置文件: /root/workspace/createIndex/config.properties
从以下位置加载配置文件: /root/workspace/createIndex/config.properties
2014-08-26 08:42:35,356 WARN [main] util.NativeCodeLoader (NativeCodeLoader.java:<clinit>(62)) - Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
jianli yige mr chengxu ...........................
2014-08-26 08:42:35,802 INFO [main] Configuration.deprecation (Configuration.java:warnOnceIfDeprecated(840)) - mapreduce.map.class is deprecated. Instead, use mapreduce.job.map.class
2014-08-26 08:42:35,802 INFO [main] Configuration.deprecation (Configuration.java:warnOnceIfDeprecated(840)) - mapred.job.name is deprecated. Instead, use mapreduce.job.name
# sql connect
HBASE_ZOOKEEPER_QUORUM=Master.Hadoop,
HBASE_ZOOKEEPER_PROPERTY_CLIENT_PORT=2181
HBASE_MASTER=Master.Hadoop:60000
HBASE_ROOTDIR=hdfs://Master.Hadoop:9000/hbase
DFS_NAME_DIR=/usr/local/hadoop/dfs/name
DFS_DATA_DIR=/usr/local/hadoop/dfs/data
FS_DEFAULT_NAME=hdfs://Master.Hadoop:9000
SOLR_SERVER=http://192.168.32.71:8080/solr/collection2
HBASE_TABLE_NAME=emp_natl_temp
HBASE_TABLE_FAMILY=emp_natl_temp
# sde connect