Search in sources :

Example 1 with Pageable

use of org.apache.metron.job.Pageable in project metron by apache.

the class PcapCli method run.

public int run(String[] args) {
    if (args.length < 1) {
        printBasicHelp();
        return -1;
    }
    String jobType = args[0];
    String[] commandArgs = Arrays.copyOfRange(args, 1, args.length);
    Configuration hadoopConf = new Configuration();
    String[] otherArgs = null;
    try {
        otherArgs = new GenericOptionsParser(hadoopConf, commandArgs).getRemainingArgs();
    } catch (IOException e) {
        LOGGER.error("Failed to configure hadoop with provided options: {}", e.getMessage(), e);
        return -1;
    }
    PcapConfig commonConfig = null;
    Pageable<Path> results;
    // write to local FS in the executing directory
    String execDir = System.getProperty("user.dir");
    if ("fixed".equals(jobType)) {
        FixedCliParser fixedParser = new FixedCliParser(prefixStrategy);
        FixedPcapConfig config = null;
        try {
            config = fixedParser.parse(otherArgs);
            commonConfig = config;
            PcapOptions.FINAL_OUTPUT_PATH.put(commonConfig, new Path(execDir));
        } catch (ParseException | java.text.ParseException e) {
            System.err.println(e.getMessage());
            System.err.flush();
            fixedParser.printHelp();
            return -1;
        }
        if (config.showHelp()) {
            fixedParser.printHelp();
            return 0;
        }
        PcapOptions.FILTER_IMPL.put(commonConfig, new FixedPcapFilter.Configurator());
        config.getYarnQueue().ifPresent(s -> hadoopConf.set(MRJobConfig.QUEUE_NAME, s));
        PcapOptions.HADOOP_CONF.put(commonConfig, hadoopConf);
        try {
            PcapOptions.FILESYSTEM.put(commonConfig, FileSystem.get(hadoopConf));
            results = jobRunner.submit(PcapFinalizerStrategies.CLI, commonConfig).get();
        } catch (IOException | InterruptedException | JobException e) {
            LOGGER.error("Failed to execute fixed filter job: {}", e.getMessage(), e);
            return -1;
        }
    } else if ("query".equals(jobType)) {
        QueryCliParser queryParser = new QueryCliParser(prefixStrategy);
        QueryPcapConfig config = null;
        try {
            config = queryParser.parse(otherArgs);
            commonConfig = config;
            PcapOptions.FINAL_OUTPUT_PATH.put(commonConfig, new Path(execDir));
        } catch (ParseException | java.text.ParseException e) {
            System.err.println(e.getMessage());
            queryParser.printHelp();
            return -1;
        }
        if (config.showHelp()) {
            queryParser.printHelp();
            return 0;
        }
        PcapOptions.FILTER_IMPL.put(commonConfig, new FixedPcapFilter.Configurator());
        config.getYarnQueue().ifPresent(s -> hadoopConf.set(MRJobConfig.QUEUE_NAME, s));
        PcapOptions.HADOOP_CONF.put(commonConfig, hadoopConf);
        try {
            PcapOptions.FILESYSTEM.put(commonConfig, FileSystem.get(hadoopConf));
            results = jobRunner.submit(PcapFinalizerStrategies.CLI, commonConfig).get();
        } catch (IOException | InterruptedException | JobException e) {
            LOGGER.error("Failed to execute fixed filter job: {}", e.getMessage(), e);
            return -1;
        }
    } else {
        printBasicHelp();
        return -1;
    }
    return 0;
}
Also used : Path(org.apache.hadoop.fs.Path) PcapConfig(org.apache.metron.pcap.config.PcapConfig) Arrays(java.util.Arrays) FixedPcapFilter(org.apache.metron.pcap.filter.fixed.FixedPcapFilter) Logger(org.slf4j.Logger) FileSystem(org.apache.hadoop.fs.FileSystem) Pageable(org.apache.metron.job.Pageable) MethodHandles(java.lang.invoke.MethodHandles) LoggerFactory(org.slf4j.LoggerFactory) IOException(java.io.IOException) UUID(java.util.UUID) GenericOptionsParser(org.apache.hadoop.util.GenericOptionsParser) QueryPcapConfig(org.apache.metron.pcap.config.QueryPcapConfig) TimestampConverters(org.apache.metron.common.utils.timestamp.TimestampConverters) Pair(org.apache.commons.lang3.tuple.Pair) MRJobConfig(org.apache.hadoop.mapreduce.MRJobConfig) PcapOptions(org.apache.metron.pcap.config.PcapOptions) FixedPcapConfig(org.apache.metron.pcap.config.FixedPcapConfig) ParseException(org.apache.commons.cli.ParseException) Configuration(org.apache.hadoop.conf.Configuration) Path(org.apache.hadoop.fs.Path) PcapFinalizerStrategies(org.apache.metron.pcap.finalizer.PcapFinalizerStrategies) JobException(org.apache.metron.job.JobException) PcapJob(org.apache.metron.pcap.mr.PcapJob) Configuration(org.apache.hadoop.conf.Configuration) QueryPcapConfig(org.apache.metron.pcap.config.QueryPcapConfig) IOException(java.io.IOException) FixedPcapConfig(org.apache.metron.pcap.config.FixedPcapConfig) JobException(org.apache.metron.job.JobException) ParseException(org.apache.commons.cli.ParseException) PcapConfig(org.apache.metron.pcap.config.PcapConfig) QueryPcapConfig(org.apache.metron.pcap.config.QueryPcapConfig) FixedPcapConfig(org.apache.metron.pcap.config.FixedPcapConfig) GenericOptionsParser(org.apache.hadoop.util.GenericOptionsParser) FixedPcapFilter(org.apache.metron.pcap.filter.fixed.FixedPcapFilter)

Aggregations

IOException (java.io.IOException)1 MethodHandles (java.lang.invoke.MethodHandles)1 Arrays (java.util.Arrays)1 UUID (java.util.UUID)1 ParseException (org.apache.commons.cli.ParseException)1 Pair (org.apache.commons.lang3.tuple.Pair)1 Configuration (org.apache.hadoop.conf.Configuration)1 FileSystem (org.apache.hadoop.fs.FileSystem)1 Path (org.apache.hadoop.fs.Path)1 MRJobConfig (org.apache.hadoop.mapreduce.MRJobConfig)1 GenericOptionsParser (org.apache.hadoop.util.GenericOptionsParser)1 TimestampConverters (org.apache.metron.common.utils.timestamp.TimestampConverters)1 JobException (org.apache.metron.job.JobException)1 Pageable (org.apache.metron.job.Pageable)1 FixedPcapConfig (org.apache.metron.pcap.config.FixedPcapConfig)1 PcapConfig (org.apache.metron.pcap.config.PcapConfig)1 PcapOptions (org.apache.metron.pcap.config.PcapOptions)1 QueryPcapConfig (org.apache.metron.pcap.config.QueryPcapConfig)1 FixedPcapFilter (org.apache.metron.pcap.filter.fixed.FixedPcapFilter)1 PcapFinalizerStrategies (org.apache.metron.pcap.finalizer.PcapFinalizerStrategies)1