001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018package org.apache.hadoop.hbase.mob; 019 020import java.io.IOException; 021import org.apache.hadoop.conf.Configuration; 022import org.apache.hadoop.hbase.HBaseConfiguration; 023import org.apache.hadoop.hbase.util.AbstractHBaseTool; 024import org.apache.hadoop.util.ToolRunner; 025import org.apache.yetus.audience.InterfaceAudience; 026import org.apache.yetus.audience.InterfaceStability; 027import org.slf4j.Logger; 028import org.slf4j.LoggerFactory; 029 030import org.apache.hbase.thirdparty.org.apache.commons.cli.CommandLine; 031 032@InterfaceAudience.Private 033@InterfaceStability.Evolving 034public class MobStressTool extends AbstractHBaseTool { 035 private static final Logger LOG = LoggerFactory.getLogger(MobStressTool.class); 036 private CommandLine cmd; 037 038 public MobStressTool() throws IOException { 039 init(); 040 } 041 042 protected void init() throws IOException { 043 // define supported options 044 addOptWithArg("n", "Number of MOB key-values to insert, default - 10000000"); 045 } 046 047 @Override 048 protected void addOptions() { 049 } 050 051 @Override 052 protected void processOptions(CommandLine cmd) { 053 this.cmd = cmd; 054 } 055 056 @Override 057 protected int doWork() throws Exception { 058 long numRowsToInsert = 10000000; 059 if (cmd.hasOption("n")) { 060 numRowsToInsert = Long.parseLong(cmd.getOptionValue("n")); 061 if (numRowsToInsert < 0) { 062 LOG.warn("Ignore wrong option '-n'"); 063 numRowsToInsert = 10000000; 064 } 065 } 066 067 MobStressToolRunner runner = new MobStressToolRunner(); 068 runner.init(getConf(), numRowsToInsert); 069 runner.runStressTest(); 070 return 0; 071 } 072 073 public static void main(String[] args) throws Exception { 074 Configuration conf = HBaseConfiguration.create(); 075 int ret = ToolRunner.run(conf, new MobStressTool(), args); 076 System.exit(ret); 077 } 078 079}