Search in sources :

Example 86 with OptionParser

use of joptsimple.OptionParser in project voldemort by voldemort.

the class ClusterForkLiftTool method getParser.

/**
     * Return args parser
     * 
     * @return program parser
     * */
private static OptionParser getParser() {
    OptionParser parser = new OptionParser();
    parser.accepts("help", "print help information");
    parser.accepts("src-url", "[REQUIRED] bootstrap URL of source cluster").withRequiredArg().describedAs("source-bootstrap-url").ofType(String.class);
    parser.accepts("dst-url", "[REQUIRED] bootstrap URL of destination cluster").withRequiredArg().describedAs("destination-bootstrap-url").ofType(String.class);
    parser.accepts("stores", "Store names to forklift. Comma delimited list or singleton. [Default: ALL SOURCE STORES]").withRequiredArg().describedAs("stores").withValuesSeparatedBy(',').ofType(String.class);
    parser.accepts("partitions", "partitions to forklift. Comma delimited list or singleton. [Default: ALL SOURCE PARTITIONS]").withRequiredArg().describedAs("partitions").withValuesSeparatedBy(',').ofType(Integer.class);
    parser.accepts("max-puts-per-second", "Maximum number of put(...) operations issued against destination cluster per second. [Default: " + DEFAULT_MAX_PUTS_PER_SEC + " ]").withRequiredArg().describedAs("maxPutsPerSecond").ofType(Integer.class);
    parser.accepts("progress-period-ops", "Number of operations between progress info is displayed. [Default: " + DEFAULT_PROGRESS_PERIOD_OPS + " ]").withRequiredArg().describedAs("progressPeriodOps").ofType(Integer.class);
    parser.accepts("parallelism", "Number of partitions to fetch in parallel. [Default: " + DEFAULT_PARTITION_PARALLELISM + " ]").withRequiredArg().describedAs("partitionParallelism").ofType(Integer.class);
    parser.accepts("mode", "Determines if a thorough global resolution needs to be done, by comparing all replicas. [Default: " + ForkLiftTaskMode.primary_resolution.toString() + " Fetch from primary alone ]").withOptionalArg().describedAs("mode").ofType(String.class);
    parser.accepts(OVERWRITE_OPTION, OVERWRITE_WARNING_MESSAGE).withOptionalArg().describedAs("overwriteExistingValue").ofType(Boolean.class).defaultsTo(false);
    parser.accepts(IGNORE_SCHEMA_MISMATCH, IGNORE_SCHEMA_WARNING_MESSAGE).withOptionalArg().describedAs("ignoreSchemaMismatch").ofType(Boolean.class).defaultsTo(false);
    return parser;
}
Also used : OptionParser(joptsimple.OptionParser)

Example 87 with OptionParser

use of joptsimple.OptionParser in project voldemort by voldemort.

the class ConsistencyFixCLI method parseArgs.

/**
     * All the logic for parsing and validating options.
     * 
     * @param args
     * @return A struct containing validated options.
     * @throws IOException
     */
private static ConsistencyFixCLI.Options parseArgs(String[] args) {
    OptionParser parser = new OptionParser();
    parser.accepts("help", "print help information");
    parser.accepts("url", "The bootstrap url.").withRequiredArg().describedAs("bootstrapUrl").ofType(String.class);
    parser.accepts("store", "The store name.").withRequiredArg().describedAs("storeName").ofType(String.class);
    parser.accepts("bad-key-file-in", "Name of bad-key-file-in. " + "Each key must be in hexadecimal format. " + "Each key must be on a separate line in the file. ").withRequiredArg().describedAs("badKeyFileIn").ofType(String.class);
    parser.accepts("orphan-format", "Indicates format of bad-key-file-in is of 'orphan' key-values.");
    parser.accepts("dry-run", "Indicates to go through all of the read actions until the point of issuing repair puts. Then, do a 'no-op'.");
    parser.accepts("parse-only", "Indicates to only parse the input file. Does not perform any key queries or repair puts. " + "Does bootstrap though so bootstrapUrl and storeName must be specified.");
    parser.accepts("bad-key-file-out", "Name of bad-key-file-out. " + "Keys that are not mae consistent are output to this file.").withRequiredArg().describedAs("badKeyFileOut").ofType(String.class);
    parser.accepts("parallelism", "Number of consistency fix messages outstanding in parallel. ").withRequiredArg().describedAs("parallelism [Default value: " + Options.defaultParallelism + "]").ofType(Integer.class);
    parser.accepts("progress-period-ops", "Number of operations between 'info' progress messages. ").withRequiredArg().describedAs("period (in operations) between outputting progress [Default value: " + Options.defaultProgressPeriodOps + "]").ofType(Long.class);
    parser.accepts("per-server-qps-limit", "Number of operations that the consistency fixer will issue to any individual server in one second. ").withRequiredArg().describedAs("perServerQPSLimit [Default value: " + Options.defaultPerServerQPSLimit + "]").ofType(Long.class);
    OptionSet optionSet = parser.parse(args);
    if (optionSet.hasArgument("help")) {
        try {
            parser.printHelpOn(System.out);
        } catch (IOException e) {
            e.printStackTrace();
        }
        printUsage();
        System.exit(0);
    }
    if (!optionSet.hasArgument("url")) {
        printUsage("Missing required 'url' argument.", parser);
    }
    if (!optionSet.hasArgument("store")) {
        printUsage("Missing required 'store' argument.", parser);
    }
    if (!optionSet.has("bad-key-file-in")) {
        printUsage("Missing required 'bad-key-file-in' argument.", parser);
    }
    if (!optionSet.has("bad-key-file-out")) {
        printUsage("Missing required 'bad-key-file-out' argument.", parser);
    }
    Options options = new Options();
    options.url = (String) optionSet.valueOf("url");
    options.storeName = (String) optionSet.valueOf("store");
    options.badKeyFileIn = (String) optionSet.valueOf("bad-key-file-in");
    options.badKeyFileOut = (String) optionSet.valueOf("bad-key-file-out");
    if (optionSet.has("orphan-format")) {
        options.badKeyFileInOrphanFormat = true;
    }
    if (optionSet.has("parallelism")) {
        options.parallelism = (Integer) optionSet.valueOf("parallelism");
    }
    if (optionSet.has("progress-period-ops")) {
        options.progressPeriodOps = (Long) optionSet.valueOf("progress-period-ops");
    }
    if (optionSet.has("per-server-qps-limit")) {
        options.perServerQPSLimit = (Long) optionSet.valueOf("per-server-qps-limit");
    }
    if (optionSet.has("dry-run")) {
        options.dryRun = true;
    }
    if (optionSet.has("parse-only")) {
        options.parseOnly = true;
    }
    return options;
}
Also used : IOException(java.io.IOException) OptionSet(joptsimple.OptionSet) OptionParser(joptsimple.OptionParser)

Example 88 with OptionParser

use of joptsimple.OptionParser in project voldemort by voldemort.

the class RepartitionerCLI method setupParser.

private static void setupParser() {
    parser = new OptionParser();
    parser.accepts("help", "Print usage information");
    parser.accepts("current-cluster", "Path to current cluster xml").withRequiredArg().describedAs("cluster.xml");
    parser.accepts("interim-cluster", "Path to interim cluster xml").withRequiredArg().describedAs("cluster.xml");
    parser.accepts("current-stores", "Path to current store definition xml. Needed for cluster and zone expansion.").withRequiredArg().describedAs("stores.xml");
    parser.accepts("final-stores", "Path to final store definition xml. Needed for zone expansion. Used with interim-cluster.").withRequiredArg().describedAs("stores.xml");
    parser.accepts("attempts", "Number of attempts at repartitioning. [ Default: " + Repartitioner.DEFAULT_REPARTITION_ATTEMPTS + " ]").withRequiredArg().ofType(Integer.class).describedAs("num-attempts");
    parser.accepts("output-dir", "Specify the output directory for the repartitioned cluster.xml and the analysis files.").withRequiredArg().ofType(String.class).describedAs("path");
    parser.accepts("disable-node-balancing", "Make sure that all nodes within every zone have the same (within one) number of primary partitions [default: enabled]");
    parser.accepts("disable-zone-balancing", "Make sure that all zones have the same (within one) number of primary partitions [default: enabled]");
    parser.accepts("enable-random-swaps", "Enable attempts to improve balance by random partition swaps within a zone. [Default: disabled]");
    parser.accepts("random-swap-attempts", "Number of random swaps to attempt. [Default:" + Repartitioner.DEFAULT_RANDOM_SWAP_ATTEMPTS + " ]").withRequiredArg().ofType(Integer.class).describedAs("num-attempts");
    parser.accepts("random-swap-successes", "Number of successful random swaps to permit exit before completing all swap attempts. [Default:" + Repartitioner.DEFAULT_RANDOM_SWAP_SUCCESSES + " ]").withRequiredArg().ofType(Integer.class).describedAs("num-successes");
    parser.accepts("random-swap-zoneids", "Comma separated zone ids that you want to shuffle. [Default:Shuffle all zones.]").withRequiredArg().describedAs("random-zoneids-to-shuffle").withValuesSeparatedBy(',').ofType(Integer.class);
    parser.accepts("enable-greedy-swaps", "Enable attempts to improve balance by greedily swapping (random) partitions within a zone. [Default: disabled]");
    parser.accepts("greedy-swap-attempts", "Number of greedy (random) swaps to attempt. [Default:" + Repartitioner.DEFAULT_GREEDY_SWAP_ATTEMPTS + " ]").withRequiredArg().ofType(Integer.class).describedAs("num-attempts");
    parser.accepts("greedy-max-partitions-per-node", "Max number of partitions per-node to evaluate swapping with other partitions within the zone. [Default:" + Repartitioner.DEFAULT_GREEDY_MAX_PARTITIONS_PER_NODE + " ]").withRequiredArg().ofType(Integer.class).describedAs("max-partitions-per-node");
    parser.accepts("greedy-max-partitions-per-zone", "Max number of (random) partitions per-zone to evaluate swapping with partitions from node being evaluated. [Default:" + Repartitioner.DEFAULT_GREEDY_MAX_PARTITIONS_PER_ZONE + " ]").withRequiredArg().ofType(Integer.class).describedAs("max-partitions-per-zone");
    parser.accepts("greedy-swap-zoneids", "Comma separated zone ids that you want to shuffle. [Default: Shuffle each zone.]").withRequiredArg().describedAs("greedy-zoneids-to-shuffle").withValuesSeparatedBy(',').ofType(Integer.class);
    parser.accepts("max-contiguous-partitions", "Limit the number of contiguous partition IDs allowed within a zone. [Default:" + Repartitioner.DEFAULT_MAX_CONTIGUOUS_PARTITIONS + " (indicating no limit)]").withRequiredArg().ofType(Integer.class).describedAs("num-contiguous");
}
Also used : OptionParser(joptsimple.OptionParser)

Example 89 with OptionParser

use of joptsimple.OptionParser in project voldemort by voldemort.

the class ReplaceNodeCLI method main.

public static void main(String[] args) throws Exception {
    OptionParser parser = null;
    OptionSet options = null;
    try {
        parser = getParser();
        options = parser.parse(args);
    } catch (OptionException oe) {
        parser.printHelpOn(System.out);
        printUsageAndDie("Exception when parsing arguments : " + oe.getMessage());
        return;
    }
    /* validate options */
    if (options.hasArgument("help")) {
        parser.printHelpOn(System.out);
        printUsage();
        return;
    }
    if (!options.hasArgument("url") || !options.hasArgument("node") || !options.hasArgument("newurl")) {
        parser.printHelpOn(System.out);
        printUsageAndDie("Missing a required argument.");
        return;
    }
    String url = (String) options.valueOf("url");
    String newUrl = (String) options.valueOf("newurl");
    int nodeId = ((Integer) options.valueOf("node")).intValue();
    boolean skipRestore = options.has("skip-restore");
    int parallelism = ((Integer) options.valueOf("parallelism")).intValue();
    if (parallelism <= 0) {
        Utils.croak(" parallelism " + parallelism + " should be a positive integer ");
    }
    ReplaceNodeCLI nodeReplacer = new ReplaceNodeCLI(url, nodeId, newUrl, skipRestore, parallelism);
    try {
        nodeReplacer.execute();
    } catch (VoldemortApplicationException e) {
        logger.error("Error during node replace", e);
        Utils.croak(e.getMessage());
    }
}
Also used : VoldemortApplicationException(voldemort.VoldemortApplicationException) OptionException(joptsimple.OptionException) OptionSet(joptsimple.OptionSet) OptionParser(joptsimple.OptionParser)

Example 90 with OptionParser

use of joptsimple.OptionParser in project voldemort by voldemort.

the class GenerateScriptCLI method setupParser.

private static OptionParser setupParser() {
    OptionParser parser = new OptionParser();
    parser.accepts("help", "Print usage information").withOptionalArg();
    parser.acceptsAll(Arrays.asList("s", "script"), "Script").withRequiredArg().describedAs("script").ofType(String.class);
    parser.acceptsAll(Arrays.asList("u", "url"), "bootstrapUrl").withRequiredArg().describedAs("url").ofType(String.class);
    parser.acceptsAll(Arrays.asList("scp", "scpFile"), "file to be scp ed").withRequiredArg().describedAs("scp").ofType(String.class);
    parser.acceptsAll(Arrays.asList("o", "output"), "outputScript").withRequiredArg().describedAs("output").ofType(String.class);
    return parser;
}
Also used : OptionParser(joptsimple.OptionParser)

Aggregations

OptionParser (joptsimple.OptionParser)118 OptionSet (joptsimple.OptionSet)91 File (java.io.File)35 IOException (java.io.IOException)15 OptionException (joptsimple.OptionException)14 List (java.util.List)13 Test (org.junit.Test)13 ArrayList (java.util.ArrayList)11 Cluster (voldemort.cluster.Cluster)8 FileNotFoundException (java.io.FileNotFoundException)6 StoreDefinition (voldemort.store.StoreDefinition)6 Closer (com.google.common.io.Closer)5 BufferedReader (java.io.BufferedReader)5 Properties (java.util.Properties)5 OptionSpec (joptsimple.OptionSpec)5 Node (voldemort.cluster.Node)5 ByteArray (voldemort.utils.ByteArray)5 ClusterMapper (voldemort.xml.ClusterMapper)5 MongoClientURI (com.mongodb.MongoClientURI)4 FileReader (java.io.FileReader)4