Search in sources :

Example 26 with OptionSet

use of joptsimple.OptionSet in project jackrabbit-oak by apache.

the class DataStoreCacheUpgradeCommand method execute.

@Override
public void execute(String... args) throws Exception {
    OptionParser parser = new OptionParser();
    try {
        OptionSpec<File> homeDirOption = parser.accepts("homeDir", "Home directory of the datastore where the pending uploads is serialized").withRequiredArg().ofType(File.class).required();
        OptionSpec<File> pathOption = parser.accepts("path", "Parent directory of the datastore").withRequiredArg().ofType(File.class).required();
        OptionSpec<Boolean> moveCacheOption = parser.accepts("moveCache", "Move DataStore download cache").withOptionalArg().ofType(Boolean.class).defaultsTo(true);
        OptionSpec<Boolean> delPendingUploadsMapFileOption = parser.accepts("deleteMapFile", "Delete pending uploads file post upgrade").withOptionalArg().ofType(Boolean.class).defaultsTo(true);
        OptionSpec<?> help = parser.acceptsAll(asList("h", "?", "help"), "show help").forHelp();
        OptionSet options = null;
        try {
            options = parser.parse(args);
        } catch (Exception e) {
            System.err.println(e);
            parser.printHelpOn(System.err);
            return;
        }
        if (options.has(help)) {
            parser.printHelpOn(System.out);
            return;
        }
        File homeDir = options.valueOf(homeDirOption);
        File path = options.valueOf(pathOption);
        boolean moveCache = options.valueOf(moveCacheOption);
        boolean delPendingUploadsMapFile = options.valueOf(delPendingUploadsMapFileOption);
        System.out.println("homeDir " + homeDir);
        System.out.println("path " + path);
        System.out.println("moveCache " + moveCache);
        System.out.println("delPendingUploadsMapFile " + delPendingUploadsMapFile);
        DataStoreCacheUpgradeUtils.upgrade(homeDir, path, moveCache, delPendingUploadsMapFile);
    } catch (Exception e) {
        e.printStackTrace();
        System.err.println("Error upgrading cache");
    }
}
Also used : OptionSet(joptsimple.OptionSet) OptionParser(joptsimple.OptionParser) File(java.io.File)

Example 27 with OptionSet

use of joptsimple.OptionSet in project jackrabbit-oak by apache.

the class DataStoreCheckCommand method execute.

@Override
public void execute(String... args) throws Exception {
    OptionParser parser = new OptionParser();
    parser.allowsUnrecognizedOptions();
    String helpStr = "datastorecheck [--id] [--ref] [--consistency] [--store <path>|<mongo_uri>] " + "[--s3ds <s3ds_config>|--fds <fds_config>|--azureblobds <azureblobds_config>] [--dump <path>]";
    Closer closer = Closer.create();
    try {
        // Options for operations requested
        OptionSpecBuilder idOp = parser.accepts("id", "Get ids");
        OptionSpecBuilder refOp = parser.accepts("ref", "Get references");
        OptionSpecBuilder consistencyOp = parser.accepts("consistency", "Check consistency");
        // Node Store - needed for --ref, --consistency
        ArgumentAcceptingOptionSpec<String> store = parser.accepts("store", "Node Store").requiredIf(refOp, consistencyOp).withRequiredArg().ofType(String.class);
        // Optional argument to specify the dump path
        ArgumentAcceptingOptionSpec<String> dump = parser.accepts("dump", "Dump Path").withRequiredArg().ofType(String.class);
        // Optional argument to specify tracking
        ArgumentAcceptingOptionSpec<String> track = parser.accepts("track", "Local repository home folder").withRequiredArg().ofType(String.class);
        OptionSpec<?> help = parser.acceptsAll(asList("h", "?", "help"), "show help").forHelp();
        // Required rules (any one of --id, --ref, --consistency)
        idOp.requiredUnless(refOp, consistencyOp);
        refOp.requiredUnless(idOp, consistencyOp);
        consistencyOp.requiredUnless(idOp, refOp);
        OptionSet options = null;
        try {
            options = parser.parse(args);
        } catch (Exception e) {
            System.err.println(e);
            parser.printHelpOn(System.err);
            return;
        }
        if (options.has(help)) {
            parser.printHelpOn(System.out);
            return;
        }
        String dumpPath = JAVA_IO_TMPDIR.value();
        if (options.has(dump)) {
            dumpPath = options.valueOf(dump);
        }
        GarbageCollectableBlobStore blobStore = null;
        BlobReferenceRetriever marker = null;
        if (options.has(store)) {
            String source = options.valueOf(store);
            if (source.startsWith(MongoURI.MONGODB_PREFIX)) {
                MongoClientURI uri = new MongoClientURI(source);
                MongoClient client = new MongoClient(uri);
                DocumentNodeStore nodeStore = new DocumentMK.Builder().setMongoDB(client.getDB(uri.getDatabase())).getNodeStore();
                closer.register(Utils.asCloseable(nodeStore));
                blobStore = (GarbageCollectableBlobStore) nodeStore.getBlobStore();
                marker = new DocumentBlobReferenceRetriever(nodeStore);
            } else {
                marker = SegmentTarUtils.newBlobReferenceRetriever(source, closer);
            }
        }
        // Initialize S3/FileDataStore if configured
        GarbageCollectableBlobStore dataStore = Utils.bootstrapDataStore(args, closer);
        if (dataStore != null) {
            blobStore = dataStore;
        }
        // blob store still not initialized means configuration not supported
        if (blobStore == null) {
            System.err.println("Operation not defined for SegmentNodeStore without external datastore");
            parser.printHelpOn(System.err);
            return;
        }
        FileRegister register = new FileRegister(options);
        closer.register(register);
        if (options.has(idOp) || options.has(consistencyOp)) {
            File dumpFile = register.createFile(idOp, dumpPath);
            retrieveBlobIds(blobStore, dumpFile);
            // If track path specified copy the file to the location
            if (options.has(track)) {
                String trackPath = options.valueOf(track);
                File trackingFileParent = new File(FilenameUtils.concat(trackPath, "blobids"));
                File trackingFile = new File(trackingFileParent, "blob-" + String.valueOf(System.currentTimeMillis()) + ".gen");
                FileUtils.copyFile(dumpFile, trackingFile);
            }
        }
        if (options.has(refOp) || options.has(consistencyOp)) {
            retrieveBlobReferences(blobStore, marker, register.createFile(refOp, dumpPath));
        }
        if (options.has(consistencyOp)) {
            checkConsistency(register.get(idOp), register.get(refOp), register.createFile(consistencyOp, dumpPath));
        }
    } catch (Throwable t) {
        t.printStackTrace();
    } finally {
        closer.close();
    }
}
Also used : Closer(com.google.common.io.Closer) MongoClientURI(com.mongodb.MongoClientURI) OptionSpecBuilder(joptsimple.OptionSpecBuilder) DocumentNodeStore(org.apache.jackrabbit.oak.plugins.document.DocumentNodeStore) OptionParser(joptsimple.OptionParser) IOException(java.io.IOException) MongoClient(com.mongodb.MongoClient) OptionSpecBuilder(joptsimple.OptionSpecBuilder) DocumentBlobReferenceRetriever(org.apache.jackrabbit.oak.plugins.document.DocumentBlobReferenceRetriever) BlobReferenceRetriever(org.apache.jackrabbit.oak.plugins.blob.BlobReferenceRetriever) GarbageCollectableBlobStore(org.apache.jackrabbit.oak.spi.blob.GarbageCollectableBlobStore) OptionSet(joptsimple.OptionSet) DocumentBlobReferenceRetriever(org.apache.jackrabbit.oak.plugins.document.DocumentBlobReferenceRetriever) File(java.io.File)

Example 28 with OptionSet

use of joptsimple.OptionSet in project jackrabbit-oak by apache.

the class GraphCommand method execute.

@Override
public void execute(String... args) throws Exception {
    OptionParser parser = new OptionParser();
    OptionSpec<File> directoryArg = parser.nonOptions("Path to segment store (required)").ofType(File.class);
    OptionSpec<File> outFileArg = parser.accepts("output", "Output file").withRequiredArg().ofType(File.class).defaultsTo(new File("segments.gdf"));
    OptionSpec<Long> epochArg = parser.accepts("epoch", "Epoch of the segment time stamps (derived from journal.log if not given)").withRequiredArg().ofType(Long.class);
    OptionSpec<Void> gcGraphArg = parser.accepts("gc", "Write the gc generation graph instead of the full graph");
    OptionSpec<String> regExpArg = parser.accepts("pattern", "Regular exception specifying which nodes to include (optional). " + "Ignore when --gc is specified.").withRequiredArg().ofType(String.class);
    OptionSet options = parser.parse(args);
    File directory = directoryArg.value(options);
    if (directory == null) {
        System.err.println("Dump the segment graph to a file. Usage: graph [File] <options>");
        parser.printHelpOn(System.err);
        System.exit(-1);
    }
    String regExp = regExpArg.value(options);
    File outFile = outFileArg.value(options);
    Date epoch;
    if (options.has(epochArg)) {
        epoch = new Date(epochArg.value(options));
    } else {
        Calendar c = Calendar.getInstance();
        c.setTimeInMillis(new File(directory, "journal.log").lastModified());
        c.set(Calendar.HOUR_OF_DAY, 0);
        c.set(Calendar.MINUTE, 0);
        c.set(Calendar.SECOND, 0);
        c.set(Calendar.MILLISECOND, 0);
        epoch = c.getTime();
    }
    if (outFile.exists()) {
        outFile.delete();
    }
    System.out.println("Setting epoch to " + epoch);
    System.out.println("Writing graph to " + outFile.getAbsolutePath());
    FileOutputStream out = new FileOutputStream(outFile);
    boolean gcGraph = options.has(gcGraphArg);
    SegmentTarUtils.graph(directory, gcGraph, epoch, regExp, out);
}
Also used : Calendar(java.util.Calendar) OptionParser(joptsimple.OptionParser) Date(java.util.Date) FileOutputStream(java.io.FileOutputStream) OptionSet(joptsimple.OptionSet) File(java.io.File)

Example 29 with OptionSet

use of joptsimple.OptionSet in project jackrabbit-oak by apache.

the class PersistentCacheCommand method execute.

@SuppressWarnings("unchecked")
@Override
public void execute(String... args) throws Exception {
    OptionParser parser = new OptionParser();
    OptionSpec<String> pathSpec = parser.accepts("path", "only list entries starting with this path prefix").withOptionalArg().defaultsTo("/");
    OptionSpec<String> revisionSpec = parser.accepts("revision", "only list revisions that start with this prefix").withRequiredArg().defaultsTo("");
    OptionSpec<String> mapSpec = parser.accepts("map", "only print contents of this map").withRequiredArg().defaultsTo("");
    OptionSpec<Void> valuesSpec = parser.accepts("values", "print values, not just keys and value lengths");
    OptionSpec<Void> rawSpec = parser.accepts("raw", "print raw data (tab separated map name, key, length, value)");
    OptionSpec<String> outSpec = parser.accepts("out", "print to this file instead of stdout").withRequiredArg().defaultsTo("");
    OptionSpec<?> helpSpec = parser.acceptsAll(asList("h", "?", "help"), "show help").forHelp();
    OptionSet options = parser.parse(args);
    parser.nonOptions("persistent cache file (required)").ofType(File.class);
    if (options.has(helpSpec) || options.nonOptionArguments().isEmpty()) {
        System.out.println("Mode: " + PERSISTENTCACHE);
        System.out.println("Map names and statistic are listed if just the file name is specified.");
        System.out.println("To list all keys, just specify '/' and the file name.");
        System.out.println("To dump multiples files in one go, add multiple file names.");
        System.out.println("Files are accessed in read-only mode; " + "to analyze a running system you need to copy the cache file first.");
        System.out.println("Output format is CSV (',' replaced with '#')");
        System.out.println("To import in H2, use: " + "create table cache as select * from csvread('cache.csv', null, 'fieldDelimiter=')");
        System.out.println();
        parser.printHelpOn(System.out);
        return;
    }
    String path = pathSpec.value(options);
    String revision = revisionSpec.value(options);
    String map = mapSpec.value(options);
    boolean values = options.has(valuesSpec);
    boolean raw = options.has(rawSpec);
    String out = outSpec.value(options);
    PrintWriter write = new PrintWriter(System.out);
    if (out.length() > 0) {
        write = new PrintWriter(new BufferedWriter(new FileWriter(out)));
    }
    for (String fileName : ((List<String>) options.nonOptionArguments())) {
        dump(write, path, revision, map, fileName, values, raw);
    }
    write.flush();
}
Also used : FileWriter(java.io.FileWriter) OptionSet(joptsimple.OptionSet) OptionParser(joptsimple.OptionParser) PrintWriter(java.io.PrintWriter) BufferedWriter(java.io.BufferedWriter)

Example 30 with OptionSet

use of joptsimple.OptionSet in project jackrabbit-oak by apache.

the class Console method main.

public static void main(String[] args) throws Exception {
    OptionParser parser = new OptionParser();
    OptionSpec quiet = parser.accepts("quiet", "be less chatty");
    OptionSpec shell = parser.accepts("shell", "run the shell after executing files");
    Options opts = new Options();
    OptionSet options = opts.parseAndConfigure(parser, args);
    NodeStoreFixture fixture = NodeStoreFixtureProvider.create(opts);
    List<String> nonOptions = opts.getCommonOpts().getNonOptions();
    List<String> scriptArgs = nonOptions.size() > 1 ? nonOptions.subList(1, nonOptions.size()) : Collections.emptyList();
    IO io = new IO();
    if (options.has(quiet)) {
        io.setVerbosity(IO.Verbosity.QUIET);
    }
    if (!opts.getCommonOpts().isReadWrite()) {
        io.out.println("Repository connected in read-only mode. Use '--read-write' for write operations");
    }
    GroovyConsole console = new GroovyConsole(ConsoleSession.create(fixture.getStore(), fixture.getWhiteboard()), new IO(), fixture);
    int code = 0;
    if (!scriptArgs.isEmpty()) {
        code = console.execute(scriptArgs);
    }
    if (scriptArgs.isEmpty() || options.has(shell)) {
        code = console.run();
    }
    System.exit(code);
}
Also used : OptionSpec(joptsimple.OptionSpec) Options(org.apache.jackrabbit.oak.run.cli.Options) IO(org.codehaus.groovy.tools.shell.IO) NodeStoreFixture(org.apache.jackrabbit.oak.run.cli.NodeStoreFixture) OptionSet(joptsimple.OptionSet) OptionParser(joptsimple.OptionParser)

Aggregations

OptionSet (joptsimple.OptionSet)121 OptionParser (joptsimple.OptionParser)93 File (java.io.File)40 OptionException (joptsimple.OptionException)22 IOException (java.io.IOException)20 List (java.util.List)16 Cluster (voldemort.cluster.Cluster)13 ArrayList (java.util.ArrayList)12 Test (org.junit.Test)12 StoreDefinition (voldemort.store.StoreDefinition)12 ClusterMapper (voldemort.xml.ClusterMapper)10 StoreDefinitionsMapper (voldemort.xml.StoreDefinitionsMapper)9 FileNotFoundException (java.io.FileNotFoundException)6 VoldemortException (voldemort.VoldemortException)6 BufferedReader (java.io.BufferedReader)5 Properties (java.util.Properties)5 OptionSpec (joptsimple.OptionSpec)5 Node (voldemort.cluster.Node)5 ByteArray (voldemort.utils.ByteArray)5 Closer (com.google.common.io.Closer)4