Search in sources :

Example 41 with CommandLineParser

use of org.apache.commons.cli.CommandLineParser in project cassandra by apache.

the class SSTableMetadataViewer method main.

/**
     * @param args a list of sstables whose metadata we're interested in
     */
public static void main(String[] args) throws IOException {
    PrintStream out = System.out;
    Option optGcgs = new Option(null, GCGS_KEY, true, "The " + GCGS_KEY + " to use when calculating droppable tombstones");
    Options options = new Options();
    options.addOption(optGcgs);
    CommandLine cmd = null;
    CommandLineParser parser = new PosixParser();
    try {
        cmd = parser.parse(options, args);
    } catch (ParseException e) {
        printHelp(options, out);
    }
    if (cmd.getArgs().length == 0) {
        printHelp(options, out);
    }
    int gcgs = Integer.parseInt(cmd.getOptionValue(GCGS_KEY, "0"));
    Util.initDatabaseDescriptor();
    for (String fname : cmd.getArgs()) {
        if (new File(fname).exists()) {
            Descriptor descriptor = Descriptor.fromFilename(fname);
            Map<MetadataType, MetadataComponent> metadata = descriptor.getMetadataSerializer().deserialize(descriptor, EnumSet.allOf(MetadataType.class));
            ValidationMetadata validation = (ValidationMetadata) metadata.get(MetadataType.VALIDATION);
            StatsMetadata stats = (StatsMetadata) metadata.get(MetadataType.STATS);
            CompactionMetadata compaction = (CompactionMetadata) metadata.get(MetadataType.COMPACTION);
            CompressionMetadata compression = null;
            File compressionFile = new File(descriptor.filenameFor(Component.COMPRESSION_INFO));
            if (compressionFile.exists())
                compression = CompressionMetadata.create(fname);
            SerializationHeader.Component header = (SerializationHeader.Component) metadata.get(MetadataType.HEADER);
            out.printf("SSTable: %s%n", descriptor);
            if (validation != null) {
                out.printf("Partitioner: %s%n", validation.partitioner);
                out.printf("Bloom Filter FP chance: %f%n", validation.bloomFilterFPChance);
            }
            if (stats != null) {
                out.printf("Minimum timestamp: %s%n", stats.minTimestamp);
                out.printf("Maximum timestamp: %s%n", stats.maxTimestamp);
                out.printf("SSTable min local deletion time: %s%n", stats.minLocalDeletionTime);
                out.printf("SSTable max local deletion time: %s%n", stats.maxLocalDeletionTime);
                out.printf("Compressor: %s%n", compression != null ? compression.compressor().getClass().getName() : "-");
                if (compression != null)
                    out.printf("Compression ratio: %s%n", stats.compressionRatio);
                out.printf("TTL min: %s%n", stats.minTTL);
                out.printf("TTL max: %s%n", stats.maxTTL);
                if (validation != null && header != null)
                    printMinMaxToken(descriptor, FBUtilities.newPartitioner(descriptor), header.getKeyType(), out);
                if (header != null && header.getClusteringTypes().size() == stats.minClusteringValues.size()) {
                    List<AbstractType<?>> clusteringTypes = header.getClusteringTypes();
                    List<ByteBuffer> minClusteringValues = stats.minClusteringValues;
                    List<ByteBuffer> maxClusteringValues = stats.maxClusteringValues;
                    String[] minValues = new String[clusteringTypes.size()];
                    String[] maxValues = new String[clusteringTypes.size()];
                    for (int i = 0; i < clusteringTypes.size(); i++) {
                        minValues[i] = clusteringTypes.get(i).getString(minClusteringValues.get(i));
                        maxValues[i] = clusteringTypes.get(i).getString(maxClusteringValues.get(i));
                    }
                    out.printf("minClustringValues: %s%n", Arrays.toString(minValues));
                    out.printf("maxClustringValues: %s%n", Arrays.toString(maxValues));
                }
                out.printf("Estimated droppable tombstones: %s%n", stats.getEstimatedDroppableTombstoneRatio((int) (System.currentTimeMillis() / 1000) - gcgs));
                out.printf("SSTable Level: %d%n", stats.sstableLevel);
                out.printf("Repaired at: %d%n", stats.repairedAt);
                out.printf("Pending repair: %s%n", stats.pendingRepair);
                out.printf("Replay positions covered: %s%n", stats.commitLogIntervals);
                out.printf("totalColumnsSet: %s%n", stats.totalColumnsSet);
                out.printf("totalRows: %s%n", stats.totalRows);
                out.println("Estimated tombstone drop times:");
                for (Map.Entry<Number, long[]> entry : stats.estimatedTombstoneDropTime.getAsMap().entrySet()) {
                    out.printf("%-10s:%10s%n", entry.getKey().intValue(), entry.getValue()[0]);
                }
                printHistograms(stats, out);
            }
            if (compaction != null) {
                out.printf("Estimated cardinality: %s%n", compaction.cardinalityEstimator.cardinality());
            }
            if (header != null) {
                EncodingStats encodingStats = header.getEncodingStats();
                AbstractType<?> keyType = header.getKeyType();
                List<AbstractType<?>> clusteringTypes = header.getClusteringTypes();
                Map<ByteBuffer, AbstractType<?>> staticColumns = header.getStaticColumns();
                Map<String, String> statics = staticColumns.entrySet().stream().collect(Collectors.toMap(e -> UTF8Type.instance.getString(e.getKey()), e -> e.getValue().toString()));
                Map<ByteBuffer, AbstractType<?>> regularColumns = header.getRegularColumns();
                Map<String, String> regulars = regularColumns.entrySet().stream().collect(Collectors.toMap(e -> UTF8Type.instance.getString(e.getKey()), e -> e.getValue().toString()));
                out.printf("EncodingStats minTTL: %s%n", encodingStats.minTTL);
                out.printf("EncodingStats minLocalDeletionTime: %s%n", encodingStats.minLocalDeletionTime);
                out.printf("EncodingStats minTimestamp: %s%n", encodingStats.minTimestamp);
                out.printf("KeyType: %s%n", keyType.toString());
                out.printf("ClusteringTypes: %s%n", clusteringTypes.toString());
                out.printf("StaticColumns: {%s}%n", FBUtilities.toString(statics));
                out.printf("RegularColumns: {%s}%n", FBUtilities.toString(regulars));
            }
        } else {
            out.println("No such file: " + fname);
        }
    }
}
Also used : Arrays(java.util.Arrays) CompressionMetadata(org.apache.cassandra.io.compress.CompressionMetadata) Options(org.apache.commons.cli.Options) AbstractType(org.apache.cassandra.db.marshal.AbstractType) HelpFormatter(org.apache.commons.cli.HelpFormatter) ByteBuffer(java.nio.ByteBuffer) UTF8Type(org.apache.cassandra.db.marshal.UTF8Type) DecoratedKey(org.apache.cassandra.db.DecoratedKey) Pair(org.apache.cassandra.utils.Pair) org.apache.cassandra.io.sstable.metadata(org.apache.cassandra.io.sstable.metadata) Map(java.util.Map) Component(org.apache.cassandra.io.sstable.Component) Descriptor(org.apache.cassandra.io.sstable.Descriptor) CommandLine(org.apache.commons.cli.CommandLine) PosixParser(org.apache.commons.cli.PosixParser) SerializationHeader(org.apache.cassandra.db.SerializationHeader) EnumSet(java.util.EnumSet) Option(org.apache.commons.cli.Option) FBUtilities(org.apache.cassandra.utils.FBUtilities) CommandLineParser(org.apache.commons.cli.CommandLineParser) Collectors(java.util.stream.Collectors) List(java.util.List) java.io(java.io) IPartitioner(org.apache.cassandra.dht.IPartitioner) ParseException(org.apache.commons.cli.ParseException) EncodingStats(org.apache.cassandra.db.rows.EncodingStats) IndexSummary(org.apache.cassandra.io.sstable.IndexSummary) Options(org.apache.commons.cli.Options) PosixParser(org.apache.commons.cli.PosixParser) EncodingStats(org.apache.cassandra.db.rows.EncodingStats) CommandLineParser(org.apache.commons.cli.CommandLineParser) Component(org.apache.cassandra.io.sstable.Component) CompressionMetadata(org.apache.cassandra.io.compress.CompressionMetadata) ByteBuffer(java.nio.ByteBuffer) CommandLine(org.apache.commons.cli.CommandLine) SerializationHeader(org.apache.cassandra.db.SerializationHeader) AbstractType(org.apache.cassandra.db.marshal.AbstractType) Descriptor(org.apache.cassandra.io.sstable.Descriptor) Option(org.apache.commons.cli.Option) ParseException(org.apache.commons.cli.ParseException) Map(java.util.Map)

Example 42 with CommandLineParser

use of org.apache.commons.cli.CommandLineParser in project databus by linkedin.

the class BootstrapConfigBase method loadConfigProperties.

@SuppressWarnings("static-access")
public static Properties loadConfigProperties(String[] args) throws IOException {
    CommandLineParser cliParser = new GnuParser();
    Option dbOption = OptionBuilder.withLongOpt(BOOTSTRAP_DB_PROPS_OPT_LONG_NAME).withDescription("Bootstrap producer properties to use").hasArg().withArgName("property_file").create(BOOTSTRAP_DB_PROP_OPT_CHAR);
    Options options = new Options();
    options.addOption(dbOption);
    CommandLine cmd = null;
    try {
        cmd = cliParser.parse(options, args);
    } catch (ParseException pe) {
        throw new RuntimeException("BootstrapConfig: failed to parse command-line options.", pe);
    }
    Properties props = null;
    if (cmd.hasOption(BOOTSTRAP_DB_PROP_OPT_CHAR)) {
        String propFile = cmd.getOptionValue(BOOTSTRAP_DB_PROP_OPT_CHAR);
        LOG.info("Loading bootstrap DB config from properties file " + propFile);
        props = new Properties();
        FileInputStream f = new FileInputStream(propFile);
        try {
            props.load(f);
        } finally {
            if (null != f)
                f.close();
        }
    } else {
        LOG.info("Using system properties for bootstrap DB config");
    }
    return props;
}
Also used : Options(org.apache.commons.cli.Options) CommandLine(org.apache.commons.cli.CommandLine) GnuParser(org.apache.commons.cli.GnuParser) Option(org.apache.commons.cli.Option) CommandLineParser(org.apache.commons.cli.CommandLineParser) ParseException(org.apache.commons.cli.ParseException) Properties(java.util.Properties) FileInputStream(java.io.FileInputStream)

Example 43 with CommandLineParser

use of org.apache.commons.cli.CommandLineParser in project databus by linkedin.

the class BootstrapAvroFileSeederMain method parseArgs.

@SuppressWarnings("static-access")
public static void parseArgs(String[] args) throws IOException {
    CommandLineParser cliParser = new GnuParser();
    Option helpOption = OptionBuilder.withLongOpt(HELP_OPT_LONG_NAME).withDescription("Help screen").create(HELP_OPT_CHAR);
    Option sourcesOption = OptionBuilder.withLongOpt(PHYSICAL_CONFIG_OPT_LONG_NAME).withDescription("Bootstrap producer properties to use").hasArg().withArgName("property_file").create(PHYSICAL_CONFIG_OPT_CHAR);
    Option dbOption = OptionBuilder.withLongOpt(BOOTSTRAP_DB_PROPS_OPT_LONG_NAME).withDescription("Bootstrap producer properties to use").hasArg().withArgName("property_file").create(BOOTSTRAP_DB_PROP_OPT_CHAR);
    Option log4jPropsOption = OptionBuilder.withLongOpt(LOG4J_PROPS_OPT_LONG_NAME).withDescription("Log4j properties to use").hasArg().withArgName("property_file").create(LOG4J_PROPS_OPT_CHAR);
    Options options = new Options();
    options.addOption(helpOption);
    options.addOption(sourcesOption);
    options.addOption(dbOption);
    options.addOption(log4jPropsOption);
    CommandLine cmd = null;
    try {
        cmd = cliParser.parse(options, args);
    } catch (ParseException pe) {
        LOG.fatal("Bootstrap Physical Config: failed to parse command-line options.", pe);
        throw new RuntimeException("Bootstrap Physical Config: failed to parse command-line options.", pe);
    }
    if (cmd.hasOption(LOG4J_PROPS_OPT_CHAR)) {
        String log4jPropFile = cmd.getOptionValue(LOG4J_PROPS_OPT_CHAR);
        PropertyConfigurator.configure(log4jPropFile);
        LOG.info("Using custom logging settings from file " + log4jPropFile);
    } else {
        PatternLayout defaultLayout = new PatternLayout("%d{ISO8601} +%r [%t] (%p) {%c} %m%n");
        ConsoleAppender defaultAppender = new ConsoleAppender(defaultLayout);
        Logger.getRootLogger().removeAllAppenders();
        Logger.getRootLogger().addAppender(defaultAppender);
        //using info as the default log level
        Logger.getRootLogger().setLevel(Level.INFO);
        LOG.info("Using default logging settings. Log Level is :" + Logger.getRootLogger().getLevel());
    }
    if (cmd.hasOption(HELP_OPT_CHAR)) {
        printCliHelp(options);
        System.exit(0);
    }
    if (!cmd.hasOption(PHYSICAL_CONFIG_OPT_CHAR))
        throw new RuntimeException("Sources Config is not provided; use --help for usage");
    if (!cmd.hasOption(BOOTSTRAP_DB_PROP_OPT_CHAR))
        throw new RuntimeException("Bootstrap config is not provided; use --help for usage");
    _sSourcesConfigFile = cmd.getOptionValue(PHYSICAL_CONFIG_OPT_CHAR);
    String propFile = cmd.getOptionValue(BOOTSTRAP_DB_PROP_OPT_CHAR);
    LOG.info("Loading bootstrap DB config from properties file " + propFile);
    _sBootstrapConfigProps = new Properties();
    FileInputStream fis = new FileInputStream(propFile);
    try {
        _sBootstrapConfigProps.load(fis);
    } finally {
        fis.close();
    }
}
Also used : ConsoleAppender(org.apache.log4j.ConsoleAppender) Options(org.apache.commons.cli.Options) CommandLine(org.apache.commons.cli.CommandLine) PatternLayout(org.apache.log4j.PatternLayout) GnuParser(org.apache.commons.cli.GnuParser) Option(org.apache.commons.cli.Option) CommandLineParser(org.apache.commons.cli.CommandLineParser) ParseException(org.apache.commons.cli.ParseException) Properties(java.util.Properties) FileInputStream(java.io.FileInputStream)

Example 44 with CommandLineParser

use of org.apache.commons.cli.CommandLineParser in project databus by linkedin.

the class BootstrapAvroRecordDumper method parseArgs.

@SuppressWarnings("static-access")
public static void parseArgs(String[] args) throws IOException {
    CommandLineParser cliParser = new GnuParser();
    Option outputDirOption = OptionBuilder.withLongOpt(OUTPUT_DIR_OPT_LONG_NAME).withDescription("Help screen").create(OUTPUT_DIR_OPT_CHAR);
    Options options = new Options();
    options.addOption(outputDirOption);
    CommandLine cmd = null;
    try {
        cmd = cliParser.parse(options, args);
    } catch (ParseException pe) {
        LOG.fatal("Bootstrap Avro Record Dumper: failed to parse command-line options.", pe);
        throw new RuntimeException("Bootstrap Avro Record Dumper: failed to parse command-line options.", pe);
    }
    if (cmd.hasOption(OUTPUT_DIR_OPT_CHAR)) {
        outputDir = cmd.getOptionValue(OUTPUT_DIR_OPT_CHAR);
    }
}
Also used : Options(org.apache.commons.cli.Options) CommandLine(org.apache.commons.cli.CommandLine) GnuParser(org.apache.commons.cli.GnuParser) Option(org.apache.commons.cli.Option) CommandLineParser(org.apache.commons.cli.CommandLineParser) ParseException(org.apache.commons.cli.ParseException)

Example 45 with CommandLineParser

use of org.apache.commons.cli.CommandLineParser in project databus by linkedin.

the class BootstrapTableReader method parseArgs.

@SuppressWarnings("static-access")
public static void parseArgs(String[] args) throws IOException {
    CommandLineParser cliParser = new GnuParser();
    Option helpOption = OptionBuilder.withLongOpt(HELP_OPT_LONG_NAME).withDescription("Help screen").create(HELP_OPT_CHAR);
    Option sourcesOption = OptionBuilder.withLongOpt(QUERY_CONFIG_OPT_LONG_NAME).withDescription("Query Config").hasArg().withArgName("property_file").create(QUERY_CONFIG_OPT_CHAR);
    Option dbOption = OptionBuilder.withLongOpt(BOOTSTRAP_DB_PROPS_OPT_LONG_NAME).withDescription("Bootstrap DB properties to use").hasArg().withArgName("property_file").create(BOOTSTRAP_DB_PROP_OPT_CHAR);
    Option log4jPropsOption = OptionBuilder.withLongOpt(LOG4J_PROPS_OPT_LONG_NAME).withDescription("Log4j properties to use").hasArg().withArgName("property_file").create(LOG4J_PROPS_OPT_CHAR);
    Options options = new Options();
    options.addOption(helpOption);
    options.addOption(sourcesOption);
    options.addOption(dbOption);
    options.addOption(log4jPropsOption);
    CommandLine cmd = null;
    try {
        cmd = cliParser.parse(options, args);
    } catch (ParseException pe) {
        LOG.fatal("Bootstrap Physical Config: failed to parse command-line options.", pe);
        throw new RuntimeException("Bootstrap Physical Config: failed to parse command-line options.", pe);
    }
    if (cmd.hasOption(LOG4J_PROPS_OPT_CHAR)) {
        String log4jPropFile = cmd.getOptionValue(LOG4J_PROPS_OPT_CHAR);
        PropertyConfigurator.configure(log4jPropFile);
        LOG.info("Using custom logging settings from file " + log4jPropFile);
    } else {
        PatternLayout defaultLayout = new PatternLayout("%d{ISO8601} +%r [%t] (%p) {%c} %m%n");
        ConsoleAppender defaultAppender = new ConsoleAppender(defaultLayout);
        Logger.getRootLogger().removeAllAppenders();
        Logger.getRootLogger().addAppender(defaultAppender);
        LOG.info("Using default logging settings");
    }
    if (cmd.hasOption(HELP_OPT_CHAR)) {
        printCliHelp(options);
        System.exit(0);
    }
    if (!cmd.hasOption(QUERY_CONFIG_OPT_CHAR)) {
        throw new RuntimeException("Query Config is not provided; use --help for usage");
    }
    if (!cmd.hasOption(BOOTSTRAP_DB_PROP_OPT_CHAR)) {
        throw new RuntimeException("Bootstrap config is not provided; use --help for usage");
    }
    String propFile1 = cmd.getOptionValue(QUERY_CONFIG_OPT_CHAR);
    String propFile2 = cmd.getOptionValue(BOOTSTRAP_DB_PROP_OPT_CHAR);
    LOG.info("Loading bootstrap DB config from properties file " + propFile2);
    _sQueryConfigProps = new Properties();
    FileInputStream f1 = new FileInputStream(propFile1);
    try {
        _sQueryConfigProps.load(f1);
    } finally {
        f1.close();
    }
    _sBootstrapConfigProps = new Properties();
    FileInputStream f2 = new FileInputStream(propFile2);
    try {
        _sBootstrapConfigProps.load(f2);
    } finally {
        f2.close();
    }
}
Also used : ConsoleAppender(org.apache.log4j.ConsoleAppender) Options(org.apache.commons.cli.Options) CommandLine(org.apache.commons.cli.CommandLine) PatternLayout(org.apache.log4j.PatternLayout) GnuParser(org.apache.commons.cli.GnuParser) Option(org.apache.commons.cli.Option) CommandLineParser(org.apache.commons.cli.CommandLineParser) ParseException(org.apache.commons.cli.ParseException) Properties(java.util.Properties) FileInputStream(java.io.FileInputStream)

Aggregations

CommandLineParser (org.apache.commons.cli.CommandLineParser)265 CommandLine (org.apache.commons.cli.CommandLine)246 Options (org.apache.commons.cli.Options)206 ParseException (org.apache.commons.cli.ParseException)186 GnuParser (org.apache.commons.cli.GnuParser)158 HelpFormatter (org.apache.commons.cli.HelpFormatter)111 PosixParser (org.apache.commons.cli.PosixParser)61 Option (org.apache.commons.cli.Option)52 IOException (java.io.IOException)48 Path (org.apache.hadoop.fs.Path)42 File (java.io.File)41 DefaultParser (org.apache.commons.cli.DefaultParser)29 Job (org.apache.hadoop.mapreduce.Job)27 Configuration (org.apache.hadoop.conf.Configuration)19 FileInputStream (java.io.FileInputStream)16 Properties (java.util.Properties)15 ArrayList (java.util.ArrayList)14 BasicParser (org.apache.commons.cli.BasicParser)14 FileSystem (org.apache.hadoop.fs.FileSystem)12 URI (java.net.URI)10