Search in sources :

Example 96 with CmdLineParser

use of org.kohsuke.args4j.CmdLineParser in project opennms by OpenNMS.

the class ResourceCli method parseArguments.

public void parseArguments(final String[] args) {
    // Parse the arguments
    final CmdLineParser cmdLineParser = new CmdLineParser(this);
    try {
        cmdLineParser.parseArgument(args);
    } catch (final CmdLineException e) {
        System.err.println("Error: " + e.getMessage() + "\n");
        displayHelp(cmdLineParser);
        System.exit(-1);
    }
    // Display help message if "--help" was used
    if (help) {
        displayHelp(cmdLineParser);
        System.exit(0);
    }
}
Also used : CmdLineParser(org.kohsuke.args4j.CmdLineParser) CmdLineException(org.kohsuke.args4j.CmdLineException)

Example 97 with CmdLineParser

use of org.kohsuke.args4j.CmdLineParser in project opennms by OpenNMS.

the class Init method execute.

@Override
public void execute() throws Exception {
    if (showHelp) {
        System.out.println("Usage: $OPENNMS_HOME/bin/newts init");
        CmdLineParser parser = new CmdLineParser(new Init());
        parser.printUsage(System.out);
        return;
    }
    String keyspace = System.getProperty("org.opennms.newts.config.keyspace", "newts");
    String hostname = System.getProperty("org.opennms.newts.config.hostname", "localhost");
    int port = Integer.getInteger("org.opennms.newts.config.port", 9042);
    String username = System.getProperty("org.opennms.newts.config.username");
    String password = System.getProperty("org.opennms.newts.config.password");
    boolean ssl = Boolean.getBoolean("org.opennms.newts.config.ssl");
    System.out.println(String.format("Initializing the '%s' keyspaces on %s:%d", keyspace, hostname, port));
    try (SchemaManager m = new SchemaManager(keyspace, hostname, port, username, password, ssl)) {
        m.setReplicationFactor(replicationFactor);
        for (Schema s : s_schemas) {
            m.create(s, true, printOnly);
        }
    }
    if (!printOnly) {
        System.out.println("The keyspace was succesfully created.");
    }
}
Also used : CmdLineParser(org.kohsuke.args4j.CmdLineParser) Schema(org.opennms.newts.cassandra.Schema) SchemaManager(org.opennms.newts.cassandra.SchemaManager)

Example 98 with CmdLineParser

use of org.kohsuke.args4j.CmdLineParser in project gerrit by GerritCodeReview.

the class DocIndexer method invoke.

private void invoke(String... parameters) throws IOException {
    CmdLineParser parser = new CmdLineParser(this);
    try {
        parser.parseArgument(parameters);
        if (inputFiles.isEmpty()) {
            throw new CmdLineException(parser, "FAILED: input file missing");
        }
    } catch (CmdLineException e) {
        System.err.println(e.getMessage());
        parser.printUsage(System.err);
        System.exit(1);
        return;
    }
    try (JarOutputStream jar = new JarOutputStream(Files.newOutputStream(Paths.get(outFile)))) {
        byte[] compressedIndex = zip(index());
        JarEntry entry = new JarEntry(String.format("%s/%s", Constants.PACKAGE, Constants.INDEX_ZIP));
        entry.setSize(compressedIndex.length);
        jar.putNextEntry(entry);
        jar.write(compressedIndex);
        jar.closeEntry();
    }
}
Also used : CmdLineParser(org.kohsuke.args4j.CmdLineParser) JarOutputStream(java.util.jar.JarOutputStream) JarEntry(java.util.jar.JarEntry) CmdLineException(org.kohsuke.args4j.CmdLineException)

Example 99 with CmdLineParser

use of org.kohsuke.args4j.CmdLineParser in project asterixdb by apache.

the class AsterixCLI method main.

public static void main(String[] args) throws Exception {
    Options options = new Options();
    CmdLineParser parser = new CmdLineParser(options);
    parser.parseArgument(args);
    ILangCompilationProvider compilationProvider = new AqlCompilationProvider();
    setUp(options);
    try {
        for (String queryFile : options.args) {
            Reader in = new FileReader(queryFile);
            AsterixJavaClient ajc = new AsterixJavaClient((ICcApplicationContext) integrationUtil.cc.getApplicationContext(), integrationUtil.getHyracksClientConnection(), in, compilationProvider, new DefaultStatementExecutorFactory(), new StorageComponentProvider());
            try {
                ajc.compile(true, false, false, false, false, true, false);
            } finally {
                in.close();
            }
            ajc.execute();
        }
    } finally {
        tearDown();
    }
    System.exit(0);
}
Also used : AqlCompilationProvider(org.apache.asterix.compiler.provider.AqlCompilationProvider) CmdLineParser(org.kohsuke.args4j.CmdLineParser) DefaultStatementExecutorFactory(org.apache.asterix.app.translator.DefaultStatementExecutorFactory) ILangCompilationProvider(org.apache.asterix.compiler.provider.ILangCompilationProvider) Reader(java.io.Reader) FileReader(java.io.FileReader) FileReader(java.io.FileReader) StorageComponentProvider(org.apache.asterix.file.StorageComponentProvider) AsterixJavaClient(org.apache.asterix.api.java.AsterixJavaClient)

Example 100 with CmdLineParser

use of org.kohsuke.args4j.CmdLineParser in project asterixdb by apache.

the class SyntheticDataGeneratorForSpatialIndexEvaluation method main.

public static void main(String[] args) throws Exception {
    SyntheticDataGeneratorConfig config = new SyntheticDataGeneratorConfig();
    CmdLineParser clp = new CmdLineParser(config);
    try {
        clp.parseArgument(args);
    } catch (CmdLineException e) {
        System.err.println(e.getMessage());
        clp.printUsage(System.err);
        System.exit(1);
    }
    //prepare data generator
    GULongIDGenerator uidGenerator = new GULongIDGenerator(config.getPartitionId(), (byte) (0));
    String pointSourceFilePath = config.getPointSourceFile();
    int pointSampleInterval = config.getpointSamplingInterval();
    DataGeneratorForSpatialIndexEvaluation dataGenerator = new DataGeneratorForSpatialIndexEvaluation(new InitializationInfo(), pointSourceFilePath, pointSampleInterval);
    //get record count to be generated
    long maxRecordCount = config.getRecordCount();
    long recordCount = 0;
    //prepare timer
    long startTS = System.currentTimeMillis();
    //prepare tweetIterator which acutally generates tweet 
    TweetMessageIterator tweetIterator = dataGenerator.new TweetMessageIterator(0, uidGenerator);
    FileOutputStream fos = null;
    try {
        //prepare output file
        fos = openOutputFile(config.getOutputFilePath());
        while (recordCount < maxRecordCount) {
            //get a tweet and append newline at the end
            String tweet = tweetIterator.next().toString() + "\n";
            //write to file
            fos.write(tweet.getBytes());
            recordCount++;
            if (recordCount % 1000000 == 0) {
                System.out.println("... generated " + recordCount + " records");
            }
        }
        System.out.println("Done: generated " + recordCount + " records in " + ((System.currentTimeMillis() - startTS) / 1000) + " in seconds!");
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        try {
            closeOutputFile(fos);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
Also used : CmdLineParser(org.kohsuke.args4j.CmdLineParser) TweetMessageIterator(org.apache.asterix.tools.external.data.DataGeneratorForSpatialIndexEvaluation.TweetMessageIterator) GULongIDGenerator(org.apache.asterix.tools.external.data.GULongIDGenerator) IOException(java.io.IOException) CmdLineException(org.kohsuke.args4j.CmdLineException) IOException(java.io.IOException) FileOutputStream(java.io.FileOutputStream) DataGeneratorForSpatialIndexEvaluation(org.apache.asterix.tools.external.data.DataGeneratorForSpatialIndexEvaluation) InitializationInfo(org.apache.asterix.tools.external.data.DataGeneratorForSpatialIndexEvaluation.InitializationInfo) CmdLineException(org.kohsuke.args4j.CmdLineException)

Aggregations

CmdLineParser (org.kohsuke.args4j.CmdLineParser)114 CmdLineException (org.kohsuke.args4j.CmdLineException)75 File (java.io.File)16 Test (org.junit.Test)14 IOException (java.io.IOException)11 HyracksConnection (org.apache.hyracks.api.client.HyracksConnection)10 IHyracksClientConnection (org.apache.hyracks.api.client.IHyracksClientConnection)10 ArrayList (java.util.ArrayList)9 JobId (org.apache.hyracks.api.job.JobId)9 JobSpecification (org.apache.hyracks.api.job.JobSpecification)9 PrintStream (java.io.PrintStream)6 FileOutputStream (java.io.FileOutputStream)4 List (java.util.List)4 FeatureExtractors (io.anserini.ltr.feature.FeatureExtractors)3 Qrels (io.anserini.util.Qrels)3 Directory (org.apache.lucene.store.Directory)3 FSDirectory (org.apache.lucene.store.FSDirectory)3 ConsoleReporter (com.codahale.metrics.ConsoleReporter)2 MetricRegistry (com.codahale.metrics.MetricRegistry)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2