Java tutorial
/** * Copyright 2012 Hanborq Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.rockstor.compact; import java.io.IOException; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.HBaseConfiguration; import org.apache.hadoop.io.NullWritable; import org.apache.hadoop.mapreduce.Job; import org.apache.hadoop.mapreduce.lib.output.NullOutputFormat; import org.apache.log4j.Logger; import com.rockstor.compact.mapreduce.CompactDataMapper; import com.rockstor.compact.mapreduce.CompactDirInputFormat; import com.rockstor.util.RockConfiguration; public class CompactDataTool { private static Logger LOG = Logger.getLogger(CompactDataTool.class); private String NAME = "Compact_CompactData"; private Job createSubmittableJob(Configuration conf) throws IOException { Job job = new Job(conf, NAME); job.setJarByClass(CompactDataTool.class); job.setInputFormatClass(CompactDirInputFormat.class); job.setMapOutputValueClass(NullWritable.class); job.setMapOutputKeyClass(NullWritable.class); job.setMapperClass(CompactDataMapper.class); job.setNumReduceTasks(0); job.setOutputFormatClass(NullOutputFormat.class); LOG.info("init job " + NAME + " OK"); return job; } private static CompactDataTool instance = null; private CompactDataTool() { } public static CompactDataTool getInstance() { if (instance == null) { instance = new CompactDataTool(); } return instance; } public boolean run() throws IOException, InterruptedException, ClassNotFoundException { Configuration conf = RockConfiguration.getDefault(); Job job = createSubmittableJob(HBaseConfiguration.create(conf)); if (job != null) { return job.waitForCompletion(true); } return false; } }