Java Code Examples for org.apache.hbase.thirdparty.org.apache.commons.cli.CommandLine#hasOption()
The following examples show how to use
org.apache.hbase.thirdparty.org.apache.commons.cli.CommandLine#hasOption() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RegionMover.java From hbase with Apache License 2.0 | 6 votes |
@Override protected void processOptions(CommandLine cmd) { String hostname = cmd.getOptionValue("r"); rmbuilder = new RegionMoverBuilder(hostname); if (cmd.hasOption('m')) { rmbuilder.maxthreads(Integer.parseInt(cmd.getOptionValue('m'))); } if (cmd.hasOption('n')) { rmbuilder.ack(false); } if (cmd.hasOption('f')) { rmbuilder.filename(cmd.getOptionValue('f')); } if (cmd.hasOption('x')) { rmbuilder.excludeFile(cmd.getOptionValue('x')); } if (cmd.hasOption('t')) { rmbuilder.timeout(Integer.parseInt(cmd.getOptionValue('t'))); } this.loadUnload = cmd.getOptionValue("o").toLowerCase(Locale.ROOT); }
Example 2
Source File: IntegrationTestBase.java From hbase with Apache License 2.0 | 6 votes |
/** * This allows tests that subclass children of this base class such as * {@link org.apache.hadoop.hbase.test.IntegrationTestReplication} to * include the base options without having to also include the options from the test. * * @param cmd the command line */ protected void processBaseOptions(CommandLine cmd) { if (cmd.hasOption(MONKEY_LONG_OPT)) { monkeyToUse = cmd.getOptionValue(MONKEY_LONG_OPT); } if (cmd.hasOption(NO_CLUSTER_CLEANUP_LONG_OPT)) { noClusterCleanUp = true; } monkeyProps = new Properties(); // Add entries for the CM from hbase-site.xml as a convenience. // Do this prior to loading from the properties file to make sure those in the properties // file are given precedence to those in hbase-site.xml (backwards compatibility). loadMonkeyProperties(monkeyProps, conf); if (cmd.hasOption(CHAOS_MONKEY_PROPS)) { String chaosMonkeyPropsFile = cmd.getOptionValue(CHAOS_MONKEY_PROPS); if (StringUtils.isNotEmpty(chaosMonkeyPropsFile)) { try { monkeyProps.load(this.getClass().getClassLoader() .getResourceAsStream(chaosMonkeyPropsFile)); } catch (IOException e) { LOG.warn("Failed load of monkey properties {} from CLASSPATH", chaosMonkeyPropsFile, e); System.exit(EXIT_FAILURE); } } } }
Example 3
Source File: IntegrationTestIngestWithMOB.java From hbase with Apache License 2.0 | 6 votes |
@Override protected void processOptions(CommandLine cmd) { super.processOptions(cmd); if (cmd.hasOption(THRESHOLD)) { threshold = Integer.parseInt(cmd.getOptionValue(THRESHOLD)); } if (cmd.hasOption(MIN_MOB_DATA_SIZE)) { minMobDataSize = Integer.parseInt(cmd.getOptionValue(MIN_MOB_DATA_SIZE)); } if (cmd.hasOption(MAX_MOB_DATA_SIZE)) { maxMobDataSize = Integer.parseInt(cmd.getOptionValue(MAX_MOB_DATA_SIZE)); } if (minMobDataSize > maxMobDataSize) { throw new IllegalArgumentException( "The minMobDataSize should not be larger than minMobDataSize"); } }
Example 4
Source File: IntegrationTestIngestWithACL.java From hbase with Apache License 2.0 | 6 votes |
@Override protected void processOptions(CommandLine cmd) { super.processOptions(cmd); if (cmd.hasOption(OPT_SUPERUSER)) { superUser = cmd.getOptionValue(OPT_SUPERUSER); } if (cmd.hasOption(OPT_USERS)) { userNames = cmd.getOptionValue(OPT_USERS); } if (User.isHBaseSecurityEnabled(getConf())) { boolean authFileNotFound = false; if (cmd.hasOption(OPT_AUTHN)) { authnFileName = cmd.getOptionValue(OPT_AUTHN); if (StringUtils.isEmpty(authnFileName)) { authFileNotFound = true; } } else { authFileNotFound = true; } if (authFileNotFound) { super.printUsage(); System.exit(EXIT_FAILURE); } } }
Example 5
Source File: CoprocessorValidator.java From hbase with Apache License 2.0 | 6 votes |
@Override protected void processOptions(CommandLine cmd) { String[] jars = cmd.getOptionValues("jar"); if (jars != null) { Collections.addAll(this.jars, jars); } String[] tables = cmd.getOptionValues("table"); if (tables != null) { Arrays.stream(tables).map(Pattern::compile).forEach(tablePatterns::add); } String[] classes = cmd.getOptionValues("class"); if (classes != null) { Collections.addAll(this.classes, classes); } config = cmd.hasOption("config"); dieOnWarnings = cmd.hasOption("e"); }
Example 6
Source File: HBCK2.java From hbase-operator-tools with Apache License 2.0 | 6 votes |
List<Long> unassigns(Hbck hbck, String [] args) throws IOException { Options options = new Options(); Option override = Option.builder("o").longOpt("override").build(); options.addOption(override); // Parse command-line. CommandLineParser parser = new DefaultParser(); CommandLine commandLine; try { commandLine = parser.parse(options, args, false); } catch (ParseException e) { showErrorMessage(e.getMessage()); return null; } boolean overrideFlag = commandLine.hasOption(override.getOpt()); return hbck.unassigns(commandLine.getArgList(), overrideFlag); }
Example 7
Source File: IntegrationTestReplication.java From hbase with Apache License 2.0 | 5 votes |
@Override protected void processOptions(CommandLine cmd) { processBaseOptions(cmd); sourceClusterIdString = cmd.getOptionValue(SOURCE_CLUSTER_OPT); sinkClusterIdString = cmd.getOptionValue(DEST_CLUSTER_OPT); outputDir = cmd.getOptionValue(OUTPUT_DIR_OPT); /** This uses parseInt from {@link org.apache.hadoop.hbase.util.AbstractHBaseTool} */ numMappers = parseInt(cmd.getOptionValue(NUM_MAPPERS_OPT, Integer.toString(DEFAULT_NUM_MAPPERS)), 1, Integer.MAX_VALUE); numReducers = parseInt(cmd.getOptionValue(NUM_REDUCERS_OPT, Integer.toString(DEFAULT_NUM_REDUCERS)), 1, Integer.MAX_VALUE); numNodes = parseInt(cmd.getOptionValue(NUM_NODES_OPT, Integer.toString(DEFAULT_NUM_NODES)), 1, Integer.MAX_VALUE); generateVerifyGap = parseInt(cmd.getOptionValue(GENERATE_VERIFY_GAP_OPT, Integer.toString(DEFAULT_GENERATE_VERIFY_GAP)), 1, Integer.MAX_VALUE); numIterations = parseInt(cmd.getOptionValue(ITERATIONS_OPT, Integer.toString(DEFAULT_NUM_ITERATIONS)), 1, Integer.MAX_VALUE); width = parseInt(cmd.getOptionValue(WIDTH_OPT, Integer.toString(DEFAULT_WIDTH)), 1, Integer.MAX_VALUE); wrapMultiplier = parseInt(cmd.getOptionValue(WRAP_MULTIPLIER_OPT, Integer.toString(DEFAULT_WRAP_MULTIPLIER)), 1, Integer.MAX_VALUE); if (cmd.hasOption(NO_REPLICATION_SETUP_OPT)) { noReplicationSetup = true; } if (numNodes % (width * wrapMultiplier) != 0) { throw new RuntimeException("numNodes must be a multiple of width and wrap multiplier"); } }
Example 8
Source File: AbstractHBaseTool.java From hbase with Apache License 2.0 | 5 votes |
public int getOptionAsInt(CommandLine cmd, String opt, int defaultValue) { if (cmd.hasOption(opt)) { return Integer.parseInt(cmd.getOptionValue(opt)); } else { return defaultValue; } }
Example 9
Source File: IntegrationTestZKAndFSPermissions.java From hbase with Apache License 2.0 | 5 votes |
@Override protected void processOptions(CommandLine cmd) { isForce = cmd.hasOption(FORCE_CHECK_ARG); masterPrincipal = getShortUserName(conf.get(SecurityConstants.MASTER_KRB_PRINCIPAL)); superUser = cmd.getOptionValue(SUPERUSER_ARG, conf.get("hbase.superuser")); masterPrincipal = cmd.getOptionValue(PRINCIPAL_ARG, masterPrincipal); fsPerms = cmd.getOptionValue(FS_PERMS, "700"); skipFSCheck = cmd.hasOption(SKIP_CHECK_FS); skipZKCheck = cmd.hasOption(SKIP_CHECK_ZK); }
Example 10
Source File: RSGroupMajorCompactionTTL.java From hbase with Apache License 2.0 | 5 votes |
@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); }
Example 11
Source File: SnapshotInfo.java From hbase with Apache License 2.0 | 5 votes |
@Override protected void processOptions(CommandLine cmd) { snapshotName = cmd.getOptionValue(Options.SNAPSHOT.getLongOpt()); showFiles = cmd.hasOption(Options.FILES.getLongOpt()); showStats = cmd.hasOption(Options.FILES.getLongOpt()) || cmd.hasOption(Options.STATS.getLongOpt()); showSchema = cmd.hasOption(Options.SCHEMA.getLongOpt()); listSnapshots = cmd.hasOption(Options.LIST_SNAPSHOTS.getLongOpt()); printSizeInBytes = cmd.hasOption(Options.SIZE_IN_BYTES.getLongOpt()); if (cmd.hasOption(Options.REMOTE_DIR.getLongOpt())) { remoteDir = new Path(cmd.getOptionValue(Options.REMOTE_DIR.getLongOpt())); } }
Example 12
Source File: HBCK2.java From hbase-operator-tools with Apache License 2.0 | 5 votes |
List<Long> assigns(Hbck hbck, String[] args) throws IOException { Options options = new Options(); Option override = Option.builder("o").longOpt("override").build(); Option inputFile = Option.builder("i").longOpt("inputFiles").build(); options.addOption(override); options.addOption(inputFile); // Parse command-line. CommandLineParser parser = new DefaultParser(); CommandLine commandLine; try { commandLine = parser.parse(options, args, false); } catch (ParseException e) { showErrorMessage(e.getMessage()); return null; } boolean overrideFlag = commandLine.hasOption(override.getOpt()); List<String> argList = commandLine.getArgList(); if (!commandLine.hasOption(inputFile.getOpt())) { return hbck.assigns(argList, overrideFlag); } List<String> assignmentList = new ArrayList<>(); for (String filePath : argList) { try (InputStream fileStream = new FileInputStream(filePath)){ LineIterator it = IOUtils.lineIterator(fileStream, "UTF-8"); while (it.hasNext()) { assignmentList.add(it.nextLine().trim()); } } } return hbck.assigns(assignmentList, overrideFlag); }
Example 13
Source File: ThriftServer.java From hbase with Apache License 2.0 | 5 votes |
@Override protected void parseCommandLine(CommandLine cmd, Options options) throws Shell.ExitCodeException { super.parseCommandLine(cmd, options); boolean readOnly = THRIFT_READONLY_ENABLED_DEFAULT; if (cmd.hasOption(READONLY_OPTION)) { readOnly = true; } conf.setBoolean(THRIFT_READONLY_ENABLED, readOnly); }
Example 14
Source File: AcidGuaranteesTestTool.java From hbase with Apache License 2.0 | 5 votes |
@Override protected void processOptions(CommandLine cmd) { millisToRun = getOptionAsLong(cmd, "millis", 5000); numWriters = getOptionAsInt(cmd, "numWriters", 50); numGetters = getOptionAsInt(cmd, "numGetters", 2); numScanners = getOptionAsInt(cmd, "numScanners", 2); numUniqueRows = getOptionAsInt(cmd, "numUniqueRows", 3); crazyFlush = cmd.hasOption("crazyFlush"); useMob = cmd.hasOption("useMob"); }
Example 15
Source File: HBCK2.java From hbase-operator-tools with Apache License 2.0 | 5 votes |
/** * @return List of results OR null if failed to run. */ private List<Boolean> bypass(String[] args) throws IOException { // Bypass has two options.... Options options = new Options(); // See usage for 'help' on these options. Option override = Option.builder("o").longOpt("override").build(); options.addOption(override); Option recursive = Option.builder("r").longOpt("recursive").build(); options.addOption(recursive); Option wait = Option.builder("w").longOpt("lockWait").hasArg().type(Integer.class).build(); options.addOption(wait); // Parse command-line. CommandLineParser parser = new DefaultParser(); CommandLine commandLine; try { commandLine = parser.parse(options, args, false); } catch (ParseException e) { showErrorMessage(e.getMessage()); return null; } long lockWait = DEFAULT_LOCK_WAIT; if (commandLine.hasOption(wait.getOpt())) { lockWait = Integer.parseInt(commandLine.getOptionValue(wait.getOpt())); } String[] pidStrs = commandLine.getArgs(); if (pidStrs == null || pidStrs.length <= 0) { showErrorMessage("No pids supplied."); return null; } boolean overrideFlag = commandLine.hasOption(override.getOpt()); boolean recursiveFlag = commandLine.hasOption(recursive.getOpt()); List<Long> pids = Arrays.stream(pidStrs).map(Long::valueOf).collect(Collectors.toList()); try (ClusterConnection connection = connect(); Hbck hbck = connection.getHbck()) { checkFunctionSupported(connection, BYPASS); return hbck.bypassProcedure(pids, lockWait, overrideFlag, recursiveFlag); } }
Example 16
Source File: IntegrationTestBigLinkedListWithVisibility.java From hbase with Apache License 2.0 | 5 votes |
@Override protected void processOptions(CommandLine cmd) { super.processOptions(cmd); if (cmd.hasOption(USER_OPT)) { userName = cmd.getOptionValue(USER_OPT); } }
Example 17
Source File: LoadTestTool.java From hbase with Apache License 2.0 | 5 votes |
private void parseColumnFamilyOptions(CommandLine cmd) { String dataBlockEncodingStr = cmd.getOptionValue(HFileTestUtil.OPT_DATA_BLOCK_ENCODING); dataBlockEncodingAlgo = dataBlockEncodingStr == null ? null : DataBlockEncoding.valueOf(dataBlockEncodingStr); String compressStr = cmd.getOptionValue(OPT_COMPRESSION); compressAlgo = compressStr == null ? Compression.Algorithm.NONE : Compression.Algorithm.valueOf(compressStr); String bloomStr = cmd.getOptionValue(OPT_BLOOM); bloomType = bloomStr == null ? BloomType.ROW : BloomType.valueOf(bloomStr); if (bloomType == BloomType.ROWPREFIX_FIXED_LENGTH) { if (!cmd.hasOption(OPT_BLOOM_PARAM)) { LOG.error("the parameter of bloom filter {} is not specified", bloomType.name()); } else { conf.set(BloomFilterUtil.PREFIX_LENGTH_KEY, cmd.getOptionValue(OPT_BLOOM_PARAM)); } } inMemoryCF = cmd.hasOption(OPT_INMEMORY); if (cmd.hasOption(OPT_ENCRYPTION)) { cipher = Encryption.getCipher(conf, cmd.getOptionValue(OPT_ENCRYPTION)); } }
Example 18
Source File: IntegrationTestBulkLoad.java From hbase with Apache License 2.0 | 4 votes |
@Override protected void processOptions(CommandLine cmd) { super.processOptions(cmd); check = cmd.hasOption(OPT_CHECK); load = cmd.hasOption(OPT_LOAD); }
Example 19
Source File: MajorCompactor.java From hbase with Apache License 2.0 | 4 votes |
@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(System.currentTimeMillis()))); 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(); }
Example 20
Source File: DataBlockEncodingTool.java From hbase with Apache License 2.0 | 4 votes |
/** * A command line interface to benchmarks. Parses command-line arguments and * runs the appropriate benchmarks. * @param args Should have length at least 1 and holds the file path to HFile. * @throws IOException If you specified the wrong file. */ public static void main(final String[] args) throws IOException { // set up user arguments Options options = new Options(); options.addOption(OPT_HFILE_NAME, true, "HFile to analyse (REQUIRED)"); options.getOption(OPT_HFILE_NAME).setArgName("FILENAME"); options.addOption(OPT_KV_LIMIT, true, "Maximum number of KeyValues to process. A benchmark stops running " + "after iterating over this many KV pairs."); options.getOption(OPT_KV_LIMIT).setArgName("NUMBER"); options.addOption(OPT_MEASURE_THROUGHPUT, false, "Measure read throughput"); options.addOption(OPT_OMIT_CORRECTNESS_TEST, false, "Omit corectness tests."); options.addOption(OPT_COMPRESSION_ALGORITHM, true, "What kind of compression algorithm use for comparison."); options.addOption(OPT_BENCHMARK_N_TIMES, true, "Number of times to run each benchmark. Default value: " + DEFAULT_BENCHMARK_N_TIMES); options.addOption(OPT_BENCHMARK_N_OMIT, true, "Number of first runs of every benchmark to exclude from " + "statistics (" + DEFAULT_BENCHMARK_N_OMIT + " by default, so that " + "only the last " + (DEFAULT_BENCHMARK_N_TIMES - DEFAULT_BENCHMARK_N_OMIT) + " times are included in statistics.)"); // parse arguments CommandLineParser parser = new PosixParser(); CommandLine cmd = null; try { cmd = parser.parse(options, args); } catch (ParseException e) { System.err.println("Could not parse arguments!"); System.exit(-1); return; // avoid warning } int kvLimit = Integer.MAX_VALUE; if (cmd.hasOption(OPT_KV_LIMIT)) { kvLimit = Integer.parseInt(cmd.getOptionValue(OPT_KV_LIMIT)); if (kvLimit <= 0) { LOG.error("KV_LIMIT should not less than 1."); } } // basic argument sanity checks if (!cmd.hasOption(OPT_HFILE_NAME)) { LOG.error("Please specify HFile name using the " + OPT_HFILE_NAME + " option"); printUsage(options); System.exit(-1); } String pathName = cmd.getOptionValue(OPT_HFILE_NAME); String compressionName = DEFAULT_COMPRESSION.getName(); if (cmd.hasOption(OPT_COMPRESSION_ALGORITHM)) { compressionName = cmd.getOptionValue(OPT_COMPRESSION_ALGORITHM).toLowerCase(Locale.ROOT); } boolean doBenchmark = cmd.hasOption(OPT_MEASURE_THROUGHPUT); boolean doVerify = !cmd.hasOption(OPT_OMIT_CORRECTNESS_TEST); if (cmd.hasOption(OPT_BENCHMARK_N_TIMES)) { benchmarkNTimes = Integer.valueOf(cmd.getOptionValue( OPT_BENCHMARK_N_TIMES)); } if (cmd.hasOption(OPT_BENCHMARK_N_OMIT)) { benchmarkNOmit = Integer.valueOf(cmd.getOptionValue(OPT_BENCHMARK_N_OMIT)); } if (benchmarkNTimes < benchmarkNOmit) { LOG.error("The number of times to run each benchmark (" + benchmarkNTimes + ") must be greater than the number of benchmark runs to exclude " + "from statistics (" + benchmarkNOmit + ")"); System.exit(1); } LOG.info("Running benchmark " + benchmarkNTimes + " times. " + "Excluding the first " + benchmarkNOmit + " times from statistics."); final Configuration conf = HBaseConfiguration.create(); testCodecs(conf, kvLimit, pathName, compressionName, doBenchmark, doVerify); }