use of org.apache.hbase.thirdparty.org.apache.commons.cli.CommandLine in project hbase by apache.
the class MajorCompactor method run.
@Override
public int run(String[] args) throws Exception {
Options options = getCommonOptions();
options.addOption(Option.builder("table").required().desc("table name").hasArg().build());
options.addOption(Option.builder("cf").optionalArg(true).desc("column families: comma separated eg: a,b,c").hasArg().build());
final CommandLineParser cmdLineParser = new DefaultParser();
CommandLine commandLine = null;
try {
commandLine = cmdLineParser.parse(options, args);
} catch (ParseException parseException) {
System.out.println("ERROR: Unable to parse command-line arguments " + Arrays.toString(args) + " due to: " + parseException);
printUsage(options);
return -1;
}
if (commandLine == null) {
System.out.println("ERROR: Failed parse, empty commandLine; " + Arrays.toString(args));
printUsage(options);
return -1;
}
String tableName = commandLine.getOptionValue("table");
String cf = commandLine.getOptionValue("cf", null);
Set<String> families = Sets.newHashSet();
if (cf != null) {
Iterables.addAll(families, Splitter.on(",").split(cf));
}
Configuration configuration = getConf();
int concurrency = Integer.parseInt(commandLine.getOptionValue("servers"));
long minModTime = Long.parseLong(commandLine.getOptionValue("minModTime", String.valueOf(EnvironmentEdgeManager.currentTime())));
String quorum = commandLine.getOptionValue("zk", configuration.get(HConstants.ZOOKEEPER_QUORUM));
String rootDir = commandLine.getOptionValue("rootDir", configuration.get(HConstants.HBASE_DIR));
long sleep = Long.parseLong(commandLine.getOptionValue("sleep", Long.toString(30000)));
int numServers = Integer.parseInt(commandLine.getOptionValue("numservers", "-1"));
int numRegions = Integer.parseInt(commandLine.getOptionValue("numregions", "-1"));
configuration.set(HConstants.HBASE_DIR, rootDir);
configuration.set(HConstants.ZOOKEEPER_QUORUM, quorum);
MajorCompactor compactor = new MajorCompactor(configuration, TableName.valueOf(tableName), families, concurrency, minModTime, sleep);
compactor.setNumServers(numServers);
compactor.setNumRegions(numRegions);
compactor.setSkipWait(commandLine.hasOption("skipWait"));
compactor.initializeWorkQueues();
if (!commandLine.hasOption("dryRun")) {
compactor.compactAllRegions();
}
compactor.shutdown();
return ERRORS.size();
}
use of org.apache.hbase.thirdparty.org.apache.commons.cli.CommandLine in project hbase by apache.
the class MajorCompactorTTL method run.
@Override
public int run(String[] args) throws Exception {
Options options = getOptions();
final CommandLineParser cmdLineParser = new DefaultParser();
CommandLine commandLine;
try {
commandLine = cmdLineParser.parse(options, args);
} catch (ParseException parseException) {
System.out.println("ERROR: Unable to parse command-line arguments " + Arrays.toString(args) + " due to: " + parseException);
printUsage(options);
return -1;
}
if (commandLine == null) {
System.out.println("ERROR: Failed parse, empty commandLine; " + Arrays.toString(args));
printUsage(options);
return -1;
}
String table = commandLine.getOptionValue("table");
int numServers = Integer.parseInt(commandLine.getOptionValue("numservers", "-1"));
int numRegions = Integer.parseInt(commandLine.getOptionValue("numregions", "-1"));
int concurrency = Integer.parseInt(commandLine.getOptionValue("servers", "1"));
long sleep = Long.parseLong(commandLine.getOptionValue("sleep", Long.toString(30000)));
boolean dryRun = commandLine.hasOption("dryRun");
boolean skipWait = commandLine.hasOption("skipWait");
return compactRegionsTTLOnTable(HBaseConfiguration.create(), table, concurrency, sleep, numServers, numRegions, dryRun, skipWait);
}
use of org.apache.hbase.thirdparty.org.apache.commons.cli.CommandLine in project hbase by apache.
the class TestJoinedScanners method main.
/**
* Command line interface:
* @param args
* @throws IOException if there is a bug while reading from disk
*/
public static void main(final String[] args) throws Exception {
Option encodingOption = new Option("e", "blockEncoding", true, "Data block encoding; Default: FAST_DIFF");
encodingOption.setRequired(false);
options.addOption(encodingOption);
Option ratioOption = new Option("r", "selectionRatio", true, "Ratio of selected rows using essential column family");
ratioOption.setRequired(false);
options.addOption(ratioOption);
Option widthOption = new Option("w", "valueWidth", true, "Width of value for non-essential column family");
widthOption.setRequired(false);
options.addOption(widthOption);
CommandLineParser parser = new GnuParser();
CommandLine cmd = parser.parse(options, args);
if (args.length < 1) {
HelpFormatter formatter = new HelpFormatter();
formatter.printHelp("TestJoinedScanners", options, true);
}
if (cmd.hasOption("e")) {
blockEncoding = DataBlockEncoding.valueOf(cmd.getOptionValue("e"));
}
if (cmd.hasOption("r")) {
selectionRatio = Integer.parseInt(cmd.getOptionValue("r"));
}
if (cmd.hasOption("w")) {
valueWidth = Integer.parseInt(cmd.getOptionValue("w"));
}
// run the test
TestJoinedScanners test = new TestJoinedScanners();
test.testJoinedScanners();
}
use of org.apache.hbase.thirdparty.org.apache.commons.cli.CommandLine in project hbase by apache.
the class HFilePrettyPrinter method parseOptions.
public boolean parseOptions(String[] args) throws ParseException, IOException {
if (args.length == 0) {
HelpFormatter formatter = new HelpFormatter();
formatter.printHelp("hfile", options, true);
return false;
}
CommandLineParser parser = new PosixParser();
CommandLine cmd = parser.parse(options, args);
verbose = cmd.hasOption("v");
printValue = cmd.hasOption("p");
printKey = cmd.hasOption("e") || printValue;
shouldPrintMeta = cmd.hasOption("m");
printBlockIndex = cmd.hasOption("b");
printBlockHeaders = cmd.hasOption("h");
printStats = cmd.hasOption("s");
checkRow = cmd.hasOption("k");
checkFamily = cmd.hasOption("a");
checkMobIntegrity = cmd.hasOption("i");
if (cmd.hasOption("f")) {
files.add(new Path(cmd.getOptionValue("f")));
}
if (cmd.hasOption("w")) {
String key = cmd.getOptionValue("w");
if (key != null && key.length() != 0) {
row = Bytes.toBytesBinary(key);
isSeekToRow = true;
} else {
err.println("Invalid row is specified.");
System.exit(-1);
}
}
if (cmd.hasOption("r")) {
String regionName = cmd.getOptionValue("r");
byte[] rn = Bytes.toBytes(regionName);
byte[][] hri = RegionInfo.parseRegionName(rn);
Path rootDir = CommonFSUtils.getRootDir(getConf());
Path tableDir = CommonFSUtils.getTableDir(rootDir, TableName.valueOf(hri[0]));
String enc = RegionInfo.encodeRegionName(rn);
Path regionDir = new Path(tableDir, enc);
if (verbose)
out.println("region dir -> " + regionDir);
List<Path> regionFiles = HFile.getStoreFiles(FileSystem.get(getConf()), regionDir);
if (verbose)
out.println("Number of region files found -> " + regionFiles.size());
if (verbose) {
int i = 1;
for (Path p : regionFiles) {
if (verbose)
out.println("Found file[" + i++ + "] -> " + p);
}
}
files.addAll(regionFiles);
}
if (checkMobIntegrity) {
if (verbose) {
System.out.println("checkMobIntegrity is enabled");
}
mobFileLocations = new HashMap<>();
}
cmd.getArgList().forEach((file) -> files.add(new Path(file)));
return true;
}
use of org.apache.hbase.thirdparty.org.apache.commons.cli.CommandLine in project hbase by apache.
the class RSGroupMajorCompactionTTL method run.
@Override
public int run(String[] args) throws Exception {
Options options = getOptions();
final CommandLineParser cmdLineParser = new DefaultParser();
CommandLine commandLine;
try {
commandLine = cmdLineParser.parse(options, args);
} catch (ParseException parseException) {
System.out.println("ERROR: Unable to parse command-line arguments " + Arrays.toString(args) + " due to: " + parseException);
printUsage(options);
return -1;
}
if (commandLine == null) {
System.out.println("ERROR: Failed parse, empty commandLine; " + Arrays.toString(args));
printUsage(options);
return -1;
}
String rsgroup = commandLine.getOptionValue("rsgroup");
int numServers = Integer.parseInt(commandLine.getOptionValue("numservers", "-1"));
int numRegions = Integer.parseInt(commandLine.getOptionValue("numregions", "-1"));
int concurrency = Integer.parseInt(commandLine.getOptionValue("servers", "1"));
long sleep = Long.parseLong(commandLine.getOptionValue("sleep", Long.toString(30000)));
boolean dryRun = commandLine.hasOption("dryRun");
boolean skipWait = commandLine.hasOption("skipWait");
Configuration conf = getConf();
return compactTTLRegionsOnGroup(conf, rsgroup, concurrency, sleep, numServers, numRegions, dryRun, skipWait);
}
Aggregations