Search in sources :

Example 36 with OptionSet

use of joptsimple.OptionSet in project samza by apache.

the class RocksDbReadingTool method main.

public static void main(String[] args) throws RocksDBException {
    RocksDbReadingTool tool = new RocksDbReadingTool();
    OptionSet options = tool.parser().parse(args);
    MapConfig config = tool.loadConfig(options);
    String path = tool.getDbPath();
    String dbName = tool.getDbName();
    RocksDbKeyValueReader kvReader = new RocksDbKeyValueReader(dbName, path, config);
    for (Object obj : tool.getKeys()) {
        Object result = kvReader.get(obj);
        tool.outputResult(obj, result);
    }
    kvReader.stop();
}
Also used : MapConfig(org.apache.samza.config.MapConfig) OptionSet(joptsimple.OptionSet)

Example 37 with OptionSet

use of joptsimple.OptionSet in project samza by apache.

the class SamzaRestService method parseConfig.

/**
   * Reads a {@link org.apache.samza.config.Config} from command line parameters.
   * @param args  the command line parameters supported by {@link org.apache.samza.util.CommandLine}.
   * @return      the parsed {@link org.apache.samza.config.Config}.
   */
private static SamzaRestConfig parseConfig(String[] args) {
    CommandLine cmd = new CommandLine();
    OptionSet options = cmd.parser().parse(args);
    MapConfig cfg = cmd.loadConfig(options);
    return new SamzaRestConfig(new MapConfig(cfg));
}
Also used : CommandLine(org.apache.samza.util.CommandLine) MapConfig(org.apache.samza.config.MapConfig) OptionSet(joptsimple.OptionSet)

Example 38 with OptionSet

use of joptsimple.OptionSet in project voldemort by voldemort.

the class VoldemortThinClientShell method main.

@SuppressWarnings("unchecked")
public static void main(String[] args) throws Exception {
    OptionParser parser = new OptionParser();
    OptionSet options = parser.parse(args);
    List<String> nonOptions = (List<String>) options.nonOptionArguments();
    if (nonOptions.size() < 2 || nonOptions.size() > 3) {
        System.err.println("Usage: java VoldemortThinClientShell store_name coordinator_url [command_file] [options]");
        parser.printHelpOn(System.err);
        System.exit(-1);
    }
    String storeName = nonOptions.get(0);
    String bootstrapUrl = nonOptions.get(1);
    BufferedReader inputReader = null;
    boolean fileInput = false;
    try {
        if (nonOptions.size() == 3) {
            inputReader = new BufferedReader(new FileReader(nonOptions.get(2)));
            fileInput = true;
        } else {
            inputReader = new BufferedReader(new InputStreamReader(System.in));
        }
    } catch (IOException e) {
        Utils.croak("Failure to open input stream: " + e.getMessage());
    }
    VoldemortThinClientShell shell = new VoldemortThinClientShell(storeName, bootstrapUrl, inputReader, System.out, System.err);
    shell.process(fileInput);
}
Also used : InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) List(java.util.List) FileReader(java.io.FileReader) IOException(java.io.IOException) OptionSet(joptsimple.OptionSet) OptionParser(joptsimple.OptionParser)

Example 39 with OptionSet

use of joptsimple.OptionSet in project voldemort by voldemort.

the class RemoteDataGenerator method main.

@SuppressWarnings("unchecked")
public static void main(String[] args) throws IOException {
    OptionParser parser = new OptionParser();
    parser.accepts("k", "key size").withRequiredArg().ofType(Integer.class);
    parser.accepts("v", "value size").withRequiredArg().ofType(Integer.class);
    parser.accepts("p", "prefix").withRequiredArg();
    OptionSet options = parser.parse(args);
    List<String> nonOptions = (List<String>) options.nonOptionArguments();
    if (nonOptions.size() != 3) {
        printUsage(System.err, parser);
    }
    String url = nonOptions.get(0);
    String storeName = nonOptions.get(1);
    int requests = Integer.parseInt(nonOptions.get(2));
    int keySize = CmdUtils.valueOf(options, "k", 128);
    int valueSize = CmdUtils.valueOf(options, "v", 256);
    int workers = CmdUtils.valueOf(options, "threads", MAX_WORKERS);
    String postfix = (String) (options.has("p") ? options.valueOf("p") : null);
    RemoteDataGenerator rdg = new RemoteDataGenerator(url, storeName, workers);
    rdg.generateData(requests, keySize, valueSize, postfix);
}
Also used : List(java.util.List) OptionSet(joptsimple.OptionSet) OptionParser(joptsimple.OptionParser)

Example 40 with OptionSet

use of joptsimple.OptionSet in project voldemort by voldemort.

the class RequestFileFilter method main.

/**
     * Filter requests specified in a file, generating a new file containing
     * only requests destined for a specific node.
     * 
     * @param args See usage for more information
     * @throws Exception In case of I/O or Voldemort-specific errors
     */
public static void main(String[] args) throws Exception {
    OptionParser parser = new OptionParser();
    parser.accepts("help", "print usage information");
    parser.accepts("node", "[REQUIRED] node id").withRequiredArg().ofType(Integer.class).describedAs("node id");
    parser.accepts("store-name", "[REQUIRED] store name").withRequiredArg().describedAs("store name");
    parser.accepts("url", "[REQUIRED] bootstrap URL").withRequiredArg().describedAs("bootstrap-url");
    parser.accepts("input", "[REQUIRED] input request file").withRequiredArg().describedAs("input-file");
    parser.accepts("output", "[REQUIRED] output file").withRequiredArg().describedAs("output-file");
    parser.accepts("string-keys");
    OptionSet options = parser.parse(args);
    if (options.has("help")) {
        parser.printHelpOn(System.out);
        System.exit(0);
    }
    Set<String> missing = CmdUtils.missing(options, "node", "store-name", "url", "input", "output");
    if (missing.size() > 0) {
        System.err.println("Missing required arguments: " + Joiner.on(", ").join(missing));
        parser.printHelpOn(System.err);
        System.exit(1);
    }
    int nodeId = (Integer) options.valueOf("node");
    String storeName = (String) options.valueOf("store-name");
    String bootstrapURL = (String) options.valueOf("url");
    String inputFile = (String) options.valueOf("input");
    String outputFile = (String) options.valueOf("output");
    boolean stringKeys = options.has("string-keys");
    AdminClient adminClient = new AdminClient(bootstrapURL);
    List<StoreDefinition> storeDefinitionList = adminClient.metadataMgmtOps.getRemoteStoreDefList(nodeId).getValue();
    StoreDefinition storeDefinition = null;
    for (StoreDefinition def : storeDefinitionList) {
        if (storeName.equals(def.getName())) {
            storeDefinition = def;
        }
    }
    if (storeDefinition == null) {
        Utils.croak("No store found with name\"" + storeName + "\"");
    }
    Cluster cluster = adminClient.metadataMgmtOps.getRemoteCluster(nodeId).getValue();
    Node node = null;
    try {
        node = cluster.getNodeById(nodeId);
    } catch (VoldemortException e) {
        Utils.croak("Can't find a node with id " + nodeId);
    }
    RoutingStrategy routingStrategy = new RoutingStrategyFactory().updateRoutingStrategy(storeDefinition, cluster);
    try {
        new RequestFileFilter(storeDefinition, routingStrategy, inputFile, outputFile, node, stringKeys).filter();
    } catch (FileNotFoundException e) {
        Utils.croak(e.getMessage());
    }
}
Also used : RoutingStrategyFactory(voldemort.routing.RoutingStrategyFactory) Node(voldemort.cluster.Node) FileNotFoundException(java.io.FileNotFoundException) Cluster(voldemort.cluster.Cluster) OptionParser(joptsimple.OptionParser) VoldemortException(voldemort.VoldemortException) StoreDefinition(voldemort.store.StoreDefinition) RoutingStrategy(voldemort.routing.RoutingStrategy) OptionSet(joptsimple.OptionSet) AdminClient(voldemort.client.protocol.admin.AdminClient)

Aggregations

OptionSet (joptsimple.OptionSet)121 OptionParser (joptsimple.OptionParser)93 File (java.io.File)40 OptionException (joptsimple.OptionException)22 IOException (java.io.IOException)20 List (java.util.List)16 Cluster (voldemort.cluster.Cluster)13 ArrayList (java.util.ArrayList)12 Test (org.junit.Test)12 StoreDefinition (voldemort.store.StoreDefinition)12 ClusterMapper (voldemort.xml.ClusterMapper)10 StoreDefinitionsMapper (voldemort.xml.StoreDefinitionsMapper)9 FileNotFoundException (java.io.FileNotFoundException)6 VoldemortException (voldemort.VoldemortException)6 BufferedReader (java.io.BufferedReader)5 Properties (java.util.Properties)5 OptionSpec (joptsimple.OptionSpec)5 Node (voldemort.cluster.Node)5 ByteArray (voldemort.utils.ByteArray)5 Closer (com.google.common.io.Closer)4