Search in sources :

Example 36 with PosixParser

use of org.apache.commons.cli.PosixParser in project metron by apache.

the class SimpleEnrichmentFlatFileLoader method main.

public static void main(Configuration hadoopConfig, String[] argv) throws Exception {
    CommandLine cli = LoadOptions.parse(new PosixParser(), argv);
    EnumMap<LoadOptions, Optional<Object>> config = LoadOptions.createConfig(cli);
    if (LoadOptions.LOG4J_PROPERTIES.has(cli)) {
        PropertyConfigurator.configure(LoadOptions.LOG4J_PROPERTIES.get(cli));
    }
    ExtractorHandler handler = ExtractorHandler.load(FileUtils.readFileToString(new File(LoadOptions.EXTRACTOR_CONFIG.get(cli).trim())));
    ImportStrategy strategy = (ImportStrategy) config.get(LoadOptions.IMPORT_MODE).get();
    strategy.getImporter().importData(config, handler, hadoopConfig);
    SensorEnrichmentUpdateConfig sensorEnrichmentUpdateConfig = null;
    if (LoadOptions.ENRICHMENT_CONFIG.has(cli)) {
        sensorEnrichmentUpdateConfig = JSONUtils.INSTANCE.load(new File(LoadOptions.ENRICHMENT_CONFIG.get(cli)), SensorEnrichmentUpdateConfig.class);
    }
    if (sensorEnrichmentUpdateConfig != null) {
        sensorEnrichmentUpdateConfig.updateSensorConfigs();
    }
}
Also used : CommandLine(org.apache.commons.cli.CommandLine) ImportStrategy(org.apache.metron.dataloads.nonbulk.flatfile.importer.ImportStrategy) Optional(java.util.Optional) ExtractorHandler(org.apache.metron.dataloads.extractor.ExtractorHandler) PosixParser(org.apache.commons.cli.PosixParser) SensorEnrichmentUpdateConfig(org.apache.metron.common.configuration.enrichment.SensorEnrichmentUpdateConfig) File(java.io.File)

Example 37 with PosixParser

use of org.apache.commons.cli.PosixParser in project metron by apache.

the class SimpleFlatFileSummarizer method main.

public static void main(Configuration hadoopConfig, String[] argv) throws Exception {
    CommandLine cli = SummarizeOptions.parse(new PosixParser(), argv);
    EnumMap<SummarizeOptions, Optional<Object>> config = SummarizeOptions.createConfig(cli);
    if (SummarizeOptions.LOG4J_PROPERTIES.has(cli)) {
        PropertyConfigurator.configure(SummarizeOptions.LOG4J_PROPERTIES.get(cli));
    }
    ExtractorHandler handler = ExtractorHandler.load(FileUtils.readFileToString(new File(SummarizeOptions.EXTRACTOR_CONFIG.get(cli).trim())));
    Summarizers strategy = (Summarizers) config.get(SummarizeOptions.IMPORT_MODE).get();
    strategy.getSummarizer().importData(config, handler, hadoopConfig);
}
Also used : CommandLine(org.apache.commons.cli.CommandLine) Optional(java.util.Optional) ExtractorHandler(org.apache.metron.dataloads.extractor.ExtractorHandler) PosixParser(org.apache.commons.cli.PosixParser) File(java.io.File) Summarizers(org.apache.metron.dataloads.nonbulk.flatfile.importer.Summarizers)

Example 38 with PosixParser

use of org.apache.commons.cli.PosixParser in project metron by apache.

the class LeastRecentlyUsedPrunerIntegrationTest method testCommandLine.

@Test
public void testCommandLine() throws Exception {
    Configuration conf = HBaseConfiguration.create();
    String[] argv = { "-a 04/14/2016 12:00:00", "-f cf", "-t malicious_domains", "-u access_trackers", "-v georgia", "-z cf" };
    String[] otherArgs = new GenericOptionsParser(conf, argv).getRemainingArgs();
    CommandLine cli = LeastRecentlyUsedPruner.BulkLoadOptions.parse(new PosixParser(), otherArgs);
    Assert.assertEquals(cf, LeastRecentlyUsedPruner.BulkLoadOptions.COLUMN_FAMILY.get(cli).trim());
    Assert.assertEquals(tableName, LeastRecentlyUsedPruner.BulkLoadOptions.TABLE.get(cli).trim());
    Assert.assertEquals(atTableName, LeastRecentlyUsedPruner.BulkLoadOptions.ACCESS_TABLE.get(cli).trim());
    Assert.assertEquals(atCF, LeastRecentlyUsedPruner.BulkLoadOptions.ACCESS_COLUMN_FAMILY.get(cli).trim());
    Assert.assertEquals(beginTime, LeastRecentlyUsedPruner.BulkLoadOptions.AS_OF_TIME.get(cli).trim());
    Assert.assertEquals(timeFormat, LeastRecentlyUsedPruner.BulkLoadOptions.AS_OF_TIME_FORMAT.get(cli).trim());
}
Also used : CommandLine(org.apache.commons.cli.CommandLine) Configuration(org.apache.hadoop.conf.Configuration) HBaseConfiguration(org.apache.hadoop.hbase.HBaseConfiguration) PosixParser(org.apache.commons.cli.PosixParser) GenericOptionsParser(org.apache.hadoop.util.GenericOptionsParser)

Example 39 with PosixParser

use of org.apache.commons.cli.PosixParser in project metron by apache.

the class SimpleEnrichmentFlatFileLoaderIntegrationTest method testArgs.

@Test
public void testArgs() throws Exception {
    String[] argv = { "-c cf", "-t enrichment", "-e extractor.json", "-n enrichment_config.json", "-l log4j", "-i input.csv", "-p 2", "-b 128", "-q" };
    String[] otherArgs = new GenericOptionsParser(config, argv).getRemainingArgs();
    CommandLine cli = LoadOptions.parse(new PosixParser(), otherArgs);
    Assert.assertEquals(extractorJson, LoadOptions.EXTRACTOR_CONFIG.get(cli).trim());
    Assert.assertEquals(cf, LoadOptions.HBASE_CF.get(cli).trim());
    Assert.assertEquals(tableName, LoadOptions.HBASE_TABLE.get(cli).trim());
    Assert.assertEquals(enrichmentJson, LoadOptions.ENRICHMENT_CONFIG.get(cli).trim());
    Assert.assertEquals(csvFile, LoadOptions.INPUT.get(cli).trim());
    Assert.assertEquals(log4jProperty, LoadOptions.LOG4J_PROPERTIES.get(cli).trim());
    Assert.assertEquals("2", LoadOptions.NUM_THREADS.get(cli).trim());
    Assert.assertEquals("128", LoadOptions.BATCH_SIZE.get(cli).trim());
}
Also used : CommandLine(org.apache.commons.cli.CommandLine) PosixParser(org.apache.commons.cli.PosixParser) GenericOptionsParser(org.apache.hadoop.util.GenericOptionsParser) Test(org.junit.Test)

Example 40 with PosixParser

use of org.apache.commons.cli.PosixParser in project metron by apache.

the class GeoEnrichmentLoaderTest method testCommandLineShortOpts.

@Test
public void testCommandLineShortOpts() throws Exception {
    String[] argv = { "-g testGeoUrl", "-r /test/remoteDir", "-t /test/tmpDir", "-z test:2181" };
    String[] otherArgs = new GenericOptionsParser(argv).getRemainingArgs();
    CommandLine cli = GeoEnrichmentLoader.GeoEnrichmentOptions.parse(new PosixParser(), otherArgs);
    Assert.assertEquals("testGeoUrl", GeoEnrichmentLoader.GeoEnrichmentOptions.GEO_URL.get(cli).trim());
    Assert.assertEquals("/test/remoteDir", GeoEnrichmentLoader.GeoEnrichmentOptions.REMOTE_DIR.get(cli).trim());
    Assert.assertEquals("/test/tmpDir", GeoEnrichmentLoader.GeoEnrichmentOptions.TMP_DIR.get(cli).trim());
    Assert.assertEquals("test:2181", GeoEnrichmentLoader.GeoEnrichmentOptions.ZK_QUORUM.get(cli).trim());
}
Also used : CommandLine(org.apache.commons.cli.CommandLine) PosixParser(org.apache.commons.cli.PosixParser) GenericOptionsParser(org.apache.hadoop.util.GenericOptionsParser)

Aggregations

PosixParser (org.apache.commons.cli.PosixParser)103 CommandLine (org.apache.commons.cli.CommandLine)97 CommandLineParser (org.apache.commons.cli.CommandLineParser)67 Options (org.apache.commons.cli.Options)56 ParseException (org.apache.commons.cli.ParseException)51 File (java.io.File)24 IOException (java.io.IOException)20 HelpFormatter (org.apache.commons.cli.HelpFormatter)16 Optional (java.util.Optional)10 Test (org.junit.Test)9 List (java.util.List)8 Configuration (org.apache.hadoop.conf.Configuration)8 GenericOptionsParser (org.apache.hadoop.util.GenericOptionsParser)7 SystemExitException (org.apache.openejb.cli.SystemExitException)7 Option (org.apache.commons.cli.Option)6 Parser (org.apache.commons.cli.Parser)6 Properties (java.util.Properties)5 Path (org.apache.hadoop.fs.Path)5 ArrayList (java.util.ArrayList)4 HBaseConfiguration (org.apache.hadoop.hbase.HBaseConfiguration)4