Example usage for org.apache.cassandra.utils OutputHandler output

List of usage examples for org.apache.cassandra.utils OutputHandler output

Introduction

In this page you can find the example usage for org.apache.cassandra.utils OutputHandler output.

Prototype

public void output(String msg);

Source Link

Usage

From source file:com.chaordicsystems.sstableconverter.SSTableConverter.java

License:Apache License

public static void main(String[] args) throws Exception {
    LoaderOptions options = LoaderOptions.parseArgs(args);
    OutputHandler handler = new OutputHandler.SystemOutput(options.verbose, options.debug);

    File srcDir = options.sourceDir;
    File dstDir = options.destDir;
    IPartitioner srcPart = options.srcPartitioner;
    IPartitioner dstPart = options.dstPartitioner;
    String keyspace = options.ks;
    String cf = options.cf;//from   w w  w . j av  a2s.co m

    if (keyspace == null) {
        keyspace = srcDir.getParentFile().getName();
    }
    if (cf == null) {
        cf = srcDir.getName();
    }

    CFMetaData metadata = new CFMetaData(keyspace, cf, ColumnFamilyType.Standard, BytesType.instance, null);
    Collection<SSTableReader> originalSstables = readSSTables(srcPart, srcDir, metadata, handler);

    handler.output(
            String.format("Converting sstables of ks[%s], cf[%s], from %s to %s. Src dir: %s. Dest dir: %s.",
                    keyspace, cf, srcPart.getClass().getName(), dstPart.getClass().getName(),
                    srcDir.getAbsolutePath(), dstDir.getAbsolutePath()));

    SSTableSimpleUnsortedWriter destWriter = new SSTableSimpleUnsortedWriter(dstDir, dstPart, keyspace, cf,
            AsciiType.instance, null, 64);

    for (SSTableReader reader : originalSstables) {
        handler.output("Reading: " + reader.getFilename());
        SSTableIdentityIterator row;
        SSTableScanner scanner = reader.getDirectScanner(null);

        // collecting keys to export
        while (scanner.hasNext()) {
            row = (SSTableIdentityIterator) scanner.next();

            destWriter.newRow(row.getKey().key);
            while (row.hasNext()) {
                IColumn col = (IColumn) row.next();
                destWriter.addColumn(col.name(), col.value(), col.timestamp());
            }
        }
        scanner.close();
    }

    // Don't forget to close!
    destWriter.close();

    System.exit(0);
}

From source file:com.chaordicsystems.sstableconverter.SSTableConverter.java

License:Apache License

public static Collection<SSTableReader> readSSTables(final IPartitioner srcPartitioner, File srcDir,
        final CFMetaData metadata, final OutputHandler outputHandler) {
    final List<SSTableReader> sstables = new ArrayList<SSTableReader>();
    srcDir.list(new FilenameFilter() {
        public boolean accept(File dir, String name) {
            if (new File(dir, name).isDirectory())
                return false;
            Pair<Descriptor, Component> p = SSTable.tryComponentFromFilename(dir, name);
            Descriptor desc = p == null ? null : p.left;
            if (p == null || !p.right.equals(Component.DATA) || desc.temporary)
                return false;

            if (!new File(desc.filenameFor(Component.PRIMARY_INDEX)).exists()) {
                outputHandler.output(String.format("Skipping file %s because index is missing", name));
                return false;
            }//from   w w w .  ja v a 2 s . c o  m

            Set<Component> components = new HashSet<Component>();
            components.add(Component.DATA);
            components.add(Component.PRIMARY_INDEX);
            if (new File(desc.filenameFor(Component.COMPRESSION_INFO)).exists())
                components.add(Component.COMPRESSION_INFO);
            if (new File(desc.filenameFor(Component.STATS)).exists())
                components.add(Component.STATS);

            try {
                sstables.add(SSTableReader.openForBatch(desc, components, srcPartitioner, metadata));
            } catch (IOException e) {
                outputHandler
                        .output(String.format("Skipping file %s, error opening it: %s", name, e.getMessage()));
            }
            return false;
        }
    });
    return sstables;
}