package com.scylladb.tools;

import java.io.File;
import java.io.IOException;

import org.apache.cassandra.config.CFMetaData;
import org.apache.cassandra.config.Config;
import org.apache.cassandra.config.Schema;
import org.apache.cassandra.exceptions.ConfigurationException;
import org.apache.cassandra.io.sstable.Descriptor;
import org.apache.cassandra.tools.Util;

public class SSTableExport extends org.apache.cassandra.tools.SSTableExport {
    private boolean legacy = true;

    @Override
    protected CFMetaData metadataFromSSTable(Descriptor desc) throws IOException {
        if (!legacy && desc.version.storeRows()) {
            return super.metadataFromSSTable(desc);
        }

        Config.setClientMode(false);

        Util.initDatabaseDescriptor();
        // load keyspace descriptions.
        Schema.instance.loadFromDiskForTool();

        CFMetaData metaData = Schema.instance.getCFMetaData(desc);
        if (metaData == null) {
            throw new IllegalArgumentException(String.format(
                    "Could not locate schema info for %s/(%s:%s). "
                            + "Make sure your 'data_file_directories' is pointed correctly.",
                    desc, desc.ksname, desc.cfname));
        }
        return metaData;
    }

    @Override
    protected void checkValidDescriptor(File file) {
        legacy = Descriptor.isLegacyFile(file);
    }

    public static void main(String args[]) throws ConfigurationException {
        new SSTableExport().run(args);
    }
}

@@ -162,16 +162,71 @@
 Config;%0A
+import org.apache.cassandra.config.DatabaseDescriptor;%0A
 import o
@@ -752,28 +752,47 @@
     
-Config.setClientMode
+DatabaseDescriptor.clientInitialization
 (fal
@@ -796,17 +796,16 @@
 false);%0A
-%0A
         

Use non-deprecated client init