Package joptsimple

Examples of joptsimple.OptionSet


              .withRequiredArg()
              .describedAs("zone-id")
              .ofType(Integer.class);
        parser.accepts(HELP);

        OptionSet options = parser.parse(args);

        if(options.has(HELP)) {
            parser.printHelpOn(System.out);
            System.exit(0);
        }

        Props mainProps = null;
        if(options.has(PROP_FILE)) {
            String propFileDestination = (String) options.valueOf(PROP_FILE);
            File propertyFile = new File(propFileDestination);
            if(!propertyFile.exists()) {
                printUsage(parser, "Property file does not exist");
            }

            try {
                mainProps = new Props(propertyFile);
            } catch(Exception e) {
                printUsage(parser, "Unable to parse the property file");
            }
        } else {
            mainProps = new Props();

            if(options.has(REQUEST_FILE)) {
                mainProps.put(REQUEST_FILE, (String) options.valueOf(REQUEST_FILE));
                mainProps.put(RECORD_SELECTION, FILE_RECORD_SELECTION);
            } else {
                mainProps.put(RECORD_SELECTION,
                              CmdUtils.valueOf(options, RECORD_SELECTION, UNIFORM_RECORD_SELECTION));
            }

            if(options.has(RECORD_COUNT)) {
                mainProps.put(RECORD_COUNT, (Integer) options.valueOf(RECORD_COUNT));
            } else {
                mainProps.put(RECORD_COUNT, 0);
            }

            if(!options.has(OPS_COUNT)) {
                printUsage(parser, "Missing " + OPS_COUNT);
            }
            mainProps.put(OPS_COUNT, (Integer) options.valueOf(OPS_COUNT));

            if(options.has(URL)) {
                mainProps.put(URL, (String) options.valueOf(URL));
                if(options.has(STORE_NAME)) {
                    mainProps.put(STORE_NAME, (String) options.valueOf(STORE_NAME));
                } else {
                    printUsage(parser, "Missing store name");
                }
            } else {
                mainProps.put(KEY_TYPE, CmdUtils.valueOf(options, KEY_TYPE, STRING_KEY_TYPE));
                mainProps.put(STORAGE_CONFIGURATION_CLASS,
                              CmdUtils.valueOf(options,
                                               STORAGE_CONFIGURATION_CLASS,
                                               BdbStorageConfiguration.class.getName()));
            }

            mainProps.put(VERBOSE, getCmdBoolean(options, VERBOSE));
            mainProps.put(VERIFY, getCmdBoolean(options, VERIFY));
            mainProps.put(IGNORE_NULLS, getCmdBoolean(options, IGNORE_NULLS));
            mainProps.put(CLIENT_ZONE_ID, CmdUtils.valueOf(options, CLIENT_ZONE_ID, -1));
            mainProps.put(START_KEY_INDEX, CmdUtils.valueOf(options, START_KEY_INDEX, 0));
            mainProps.put(VALUE_SIZE, CmdUtils.valueOf(options, VALUE_SIZE, 1024));
            mainProps.put(ITERATIONS, CmdUtils.valueOf(options, ITERATIONS, 1));
            mainProps.put(THREADS, CmdUtils.valueOf(options, THREADS, MAX_WORKERS));
            mainProps.put(NUM_CONNECTIONS_PER_NODE, CmdUtils.valueOf(options,
                                                                     NUM_CONNECTIONS_PER_NODE,
                                                                     MAX_CONNECTIONS_PER_NODE));
            mainProps.put(PERCENT_CACHED, CmdUtils.valueOf(options, PERCENT_CACHED, 0));
            mainProps.put(INTERVAL, CmdUtils.valueOf(options, INTERVAL, 0));
            mainProps.put(TARGET_THROUGHPUT, CmdUtils.valueOf(options, TARGET_THROUGHPUT, -1));
            mainProps.put(METRIC_TYPE, CmdUtils.valueOf(options, METRIC_TYPE, SUMMARY_METRIC_TYPE));
            mainProps.put(READS, CmdUtils.valueOf(options, READS, 0));
            mainProps.put(WRITES, CmdUtils.valueOf(options, WRITES, 0));
            mainProps.put(DELETES, CmdUtils.valueOf(options, DELETES, 0));
            mainProps.put(MIXED, CmdUtils.valueOf(options, MIXED, 0));
            mainProps.put(PLUGIN_CLASS, CmdUtils.valueOf(options, PLUGIN_CLASS, ""));
            mainProps.put(SAMPLE_SIZE, CmdUtils.valueOf(options, SAMPLE_SIZE, 0));
        }

        // Start the benchmark
        Benchmark benchmark = null;
        try {
            benchmark = new Benchmark();
            benchmark.initialize(mainProps);
            benchmark.warmUpAndRun();
            benchmark.close();
        } catch(Exception e) {
            if(options.has(VERBOSE)) {
                e.printStackTrace();
            }
            parser.printHelpOn(System.err);
            System.exit(-1);
        }
View Full Code Here


            System.exit(exitStatus);
        }
    }
    public static void main(String[] argv) throws Exception {
        OptionParser parser = getParser();
        OptionSet options = parser.parse(argv);
        validateOptions(options);

        // bdb_folder output_folder
        String storeBdbFolderPath = (String) options.valueOf("bdb");
        String outputFolderPath = (String) options.valueOf("output");

        File storeBdbFolder = new File(storeBdbFolderPath);
        File outputFolder = new File(outputFolderPath);
        final String storeName = storeBdbFolder.getName();
View Full Code Here

        printUsage();
        Utils.croak("\n" + errMessage);
    }

    private static OptionSet getValidOptions(String[] args) {
        OptionSet options = null;
        try {
            options = parser.parse(args);
        } catch(OptionException oe) {
            printUsageAndDie("Exception when parsing arguments : " + oe.getMessage());
        }

        if(options.has("help")) {
            printUsage();
            System.exit(0);
        }

        Set<String> missing = CmdUtils.missing(options,
                                               "current-cluster",
                                               "current-stores",
                                               "final-cluster");
        if(missing.size() > 0) {
            printUsageAndDie("Missing required arguments: " + Joiner.on(", ").join(missing));
        }
        if(options.has("final-stores") && !options.has("final-cluster")) {
            printUsageAndDie("final-stores specified, but final-cluster not specified.");
        }

        return options;
    }
View Full Code Here

        return options;
    }

    public static void main(String[] args) throws Exception {
        setupParser();
        OptionSet options = getValidOptions(args);

        // Required args
        String currentClusterXML = (String) options.valueOf("current-cluster");
        String currentStoresXML = (String) options.valueOf("current-stores");
        String finalClusterXML = (String) options.valueOf("final-cluster");

        // Required args for some use cases
        String finalStoresXML = new String(currentStoresXML);
        if(options.has("final-stores")) {
            finalStoresXML = (String) options.valueOf("final-stores");
        }

        Cluster currentCluster = new ClusterMapper().readCluster(new File(currentClusterXML));
        List<StoreDefinition> currentStoreDefs = new StoreDefinitionsMapper().readStoreList(new File(currentStoresXML));
        Cluster finalCluster = new ClusterMapper().readCluster(new File(finalClusterXML));
        List<StoreDefinition> finalStoreDefs = new StoreDefinitionsMapper().readStoreList(new File(finalStoresXML));

        // Optional args
        int batchSize = CmdUtils.valueOf(options, "batch-size", RebalancePlan.BATCH_SIZE);

        String outputDir = null;
        if(options.has("output-dir")) {
            outputDir = (String) options.valueOf("output-dir");
        }

        new RebalancePlan(currentCluster,
                          currentStoreDefs,
                          finalCluster,
View Full Code Here

    // - fetch value in addition to version
    // - choose between printing human readable data (.toString()) or computer
    // readable data (ByteUtils.toHexString(byte[])).
    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.has("help")) {
            parser.printHelpOn(System.out);
            printUsage();
            return;
        }
        if(!options.hasArgument("url") || !options.hasArgument("in-dir")
           || !options.hasArgument("out-dir")) {
            parser.printHelpOn(System.out);
            printUsageAndDie("Missing a required argument.");
            return;
        }

        String url = (String) options.valueOf("url");

        String inDir = (String) options.valueOf("in-dir");
        Utils.mkdirs(new File(inDir));

        String outDir = (String) options.valueOf("out-dir");
        Utils.mkdirs(new File(outDir));

        List<String> storeNames = null;
        if(options.hasArgument("store-names")) {
            @SuppressWarnings("unchecked")
            List<String> list = (List<String>) options.valuesOf("store-names");
            storeNames = list;
        }

        Integer keyParallelism = DEFAULT_KEY_PARALLELISM;
        if(options.hasArgument("parallelism")) {
            keyParallelism = (Integer) options.valueOf("parallelism");
        }

        Integer progressPeriodOps = DEFAULT_PROGRESS_PERIOD_OPS;
        if(options.hasArgument("progress-period-ops")) {
            progressPeriodOps = (Integer) options.valueOf("progress-period-ops");
        }

        Integer outputBatchSize = DEFAULT_OUTPUT_BATCH_SIZE;
        if(options.hasArgument("output-batch-size")) {
            outputBatchSize = (Integer) options.valueOf("output-batch-size");
        }

        boolean details = options.has("details");

        try {
            KeyVersionFetcherCLI sampler = new KeyVersionFetcherCLI(url,
                                                                    inDir,
                                                                    outDir,
View Full Code Here

                       "read-only store format [" + ReadOnlyStorageFormat.READONLY_V0.getCode()
                               + "," + ReadOnlyStorageFormat.READONLY_V1.getCode() + ","
                               + ReadOnlyStorageFormat.READONLY_V2.getCode() + "]")
              .withRequiredArg()
              .ofType(String.class);
        OptionSet options = parser.parse(args);

        if(options.has("help")) {
            parser.printHelpOn(System.out);
            System.exit(0);
        }

        Set<String> missing = CmdUtils.missing(options,
                                               "cluster",
                                               "stores",
                                               "name",
                                               "buffer",
                                               "input",
                                               "output");
        if(missing.size() > 0) {
            System.err.println("Missing required arguments: " + Joiner.on(", ").join(missing));
            parser.printHelpOn(System.err);
            System.exit(1);
        }

        String clusterFile = (String) options.valueOf("cluster");
        String storeDefFile = (String) options.valueOf("stores");
        String storeName = (String) options.valueOf("name");
        int sortBufferSize = (Integer) options.valueOf("buffer");
        String inputFile = (String) options.valueOf("input");
        File outputDir = new File((String) options.valueOf("output"));
        int numThreads = CmdUtils.valueOf(options, "threads", 2);
        int chunks = CmdUtils.valueOf(options, "chunks", 2);
        int ioBufferSize = CmdUtils.valueOf(options, "io-buffer-size", 1000000);
        ReadOnlyStorageFormat storageFormat = ReadOnlyStorageFormat.fromCode(CmdUtils.valueOf(options,
                                                                                              "format",
                                                                                              ReadOnlyStorageFormat.READONLY_V2.getCode()));
        boolean gzipIntermediate = options.has("gzip");
        File tempDir = new File(CmdUtils.valueOf(options,
                                                 "temp-dir",
                                                 System.getProperty("java.io.tmpdir")));

        try {
View Full Code Here

              .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;
    }
View Full Code Here

            List<Integer> nodeIds = null;
            Boolean allNodes = true;
            Boolean confirm = false;

            // parse command-line input
            OptionSet options = parser.parse(args);
            if(options.has(AdminParserUtils.OPT_HELP)) {
                printHelp(System.out);
                return;
            }

            // check required options and/or conflicting options
            AdminParserUtils.checkRequired(options, AdminParserUtils.OPT_STORE);
            AdminParserUtils.checkRequired(options, AdminParserUtils.OPT_URL);
            AdminParserUtils.checkOptional(options,
                                           AdminParserUtils.OPT_NODE,
                                           AdminParserUtils.OPT_ALL_NODES);

            // load parameters
            storeNames = (List<String>) options.valuesOf(AdminParserUtils.OPT_STORE);
            url = (String) options.valueOf(AdminParserUtils.OPT_URL);
            if(options.has(AdminParserUtils.OPT_NODE)) {
                nodeIds = (List<Integer>) options.valuesOf(AdminParserUtils.OPT_NODE);
                allNodes = false;
            }
            if(options.has(AdminParserUtils.OPT_CONFIRM)) {
                confirm = true;
            }

            // print summary
            System.out.println("Delete stores");
View Full Code Here

            List<String> storeNames = null;
            List<String> urls = null;
            Boolean verbose = false;

            // parse command-line input
            OptionSet options = parser.parse(args);
            if(options.has(CoordinatorAdminUtils.OPT_HELP)) {
                printHelp(System.out);
                return;
            }

            // check required options and/or conflicting options
            CoordinatorAdminUtils.checkRequired(options, CoordinatorAdminUtils.OPT_URL);
            CoordinatorAdminUtils.checkRequired(options, CoordinatorAdminUtils.OPT_STORE);

            // load parameters
            urls = (List<String>) options.valuesOf(CoordinatorAdminUtils.OPT_URL);
            storeNames = (List<String>) options.valuesOf(CoordinatorAdminUtils.OPT_STORE);
            if(options.has(OPT_VERBOSE)) {
                verbose = true;
            }

            // execute command
            CoordinatorAdminClient client = new CoordinatorAdminClient();
View Full Code Here

            List<Integer> nodeIds = null;
            Boolean allNodes = true;
            Boolean confirm = false;

            // parse command-line input
            OptionSet options = parser.parse(args);
            if(options.has(AdminParserUtils.OPT_HELP)) {
                printHelp(System.out);
                return;
            }

            // check required options and/or conflicting options
            AdminParserUtils.checkRequired(options, AdminParserUtils.OPT_STORE);
            AdminParserUtils.checkRequired(options, AdminParserUtils.OPT_URL);
            AdminParserUtils.checkRequired(options, OPT_VERSION);
            AdminParserUtils.checkOptional(options,
                                           AdminParserUtils.OPT_NODE,
                                           AdminParserUtils.OPT_ALL_NODES);

            // load parameters
            storeName = (String) options.valueOf(AdminParserUtils.OPT_STORE);
            url = (String) options.valueOf(AdminParserUtils.OPT_URL);
            pushVersion = (Long) options.valueOf(OPT_VERSION);
            if(options.has(AdminParserUtils.OPT_NODE)) {
                nodeIds = (List<Integer>) options.valuesOf(AdminParserUtils.OPT_NODE);
                allNodes = false;
            }
            if(options.has(AdminParserUtils.OPT_CONFIRM)) {
                confirm = true;
            }

            // print summary
            System.out.println("Rollback read-only stores");
View Full Code Here

TOP

Related Classes of joptsimple.OptionSet

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.