【问题标题】:MapReduce job using Hbase table as source and sink within Spring XD batch job在 Spring XD 批处理作业中使用 Hbase 表作为源和接收器的 MapReduce 作业
【发布时间】:2015-04-07 18:59:34
【问题描述】:
我们如何在 Spring 中配置使用 Hbase 表作为源和接收器的 MapReduce 作业,我计划使用使用 mapreduce 作业的 Spring XD 创建批处理作业,但我想使用 Hbase 表作为这个 hadoop 作业的源和接收器。类似 TableMapReduceUtil.initTableMapperJob(), TableMapReduceUtil.initTableReducerJob() 的东西
<hdp:job>命名空间目前不支持提供输入/输出表
【问题讨论】:
标签:
spring
mapreduce
hbase
【解决方案1】:
我能够通过使用另一个 bean 来解决这个问题,该 bean 将 hadoop 作业作为输入并在设置 Scan() 和源和接收 Hbase 表后返回作业。使用 scope="job" on 和 scope="prototype" on 我能够在 spring XD 中多次运行相同的 MR 作业,没有这个你将在第一次成功后得到 Job is in RUNNING state 而不是 DEFINE state issue运行。
public class InitJobTasklet {
private Job job;
public void setJob(Object job){
this.job = (Job)job;
}
public Job getJob() throws IOException {
Scan scan = new Scan();
System.out.println("Initializing the hadoop job with hbase tables and scan object... ");
TableMapReduceUtil.initTableMapperJob("SourceTable",
scan,
Mapper.class,
Text.class, Result.class, job);
TableMapReduceUtil.initTableReducerJob(
"TargetTable", // output table
Reducer.class, // reducer class
job);
job.setNumReduceTasks(1);
return job;
}
}
spring 批处理作业配置文件:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:hdp="http://www.springframework.org/schema/hadoop"
xmlns:batch="http://www.springframework.org/schema/batch"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/hadoop http://www.springframework.org/schema/hadoop/spring-hadoop.xsd
http://www.springframework.org/schema/batch http://www.springframework.org/schema/batch/spring-batch.xsd">
<hdp:job id="mr-hbase-job"
output-path="/output"
mapper="mapperclass" reducer="reduceclass"
map-key="org.apache.hadoop.hbase.io.ImmutableBytesWritable" map-value="org.apache.hadoop.hbase.client.Result" input-format="org.apache.hadoop.hbase.mapreduce.TableInputFormat" output-format="org.apache.hadoop.hbase.mapreduce.TableOutputFormat" jar-by-class="processor class" scope="prototype">
</hdp:job>
<batch:job id="job" >
<batch:step id="step1">
<hdp:job-tasklet id="hadoop-tasklet" job="#{initTask.job}" wait-for-completion="true" scope="job"/>
</batch:step>
</batch:job>
<hdp:configuration id="hadoopConfiguration">
fs.defaultFS=hdfs://localhost:9000
hadoop.tmp.dir=/home/smunigati/hadoop/temp
hbase.zookeeper.quorum=localhost
hbase.zookeeper.property.clientPort=2181
</hdp:configuration>
<hdp:hbase-configuration id="hbaseConfiguration" configuration-ref="hadoopConfiguration">
</hdp:hbase-configuration>
<bean id="initTask" class="com.somthing.InitJobTasklet" scope="prototype" >
<property name="job" ref="mr-hbase-job" />
</bean>