Search in sources :

Example 46 with OptionParser

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

the class IndexCommand method execute.

@Override
public void execute(String... args) throws Exception {
    OptionParser parser = new OptionParser();
    opts = new Options();
    opts.setCommandName(NAME);
    opts.setSummary(summary);
    opts.setConnectionString(CommonOptions.DEFAULT_CONNECTION_STRING);
    opts.registerOptionsFactory(IndexOptions.FACTORY);
    opts.parseAndConfigure(parser, args);
    IndexOptions indexOpts = opts.getOptionBean(IndexOptions.class);
    //Clean up before setting up NodeStore as the temp
    //directory might be used by NodeStore for cache stuff like persistentCache
    setupDirectories(indexOpts);
    NodeStoreFixture fixture = NodeStoreFixtureProvider.create(opts);
    try (Closer closer = Closer.create()) {
        closer.register(fixture);
        StatisticsProvider statisticsProvider = WhiteboardUtils.getService(fixture.getWhiteboard(), StatisticsProvider.class);
        execute(fixture.getStore(), fixture.getBlobStore(), statisticsProvider, indexOpts, closer);
        tellReportPaths();
    }
}
Also used : Closer(com.google.common.io.Closer) CommonOptions(org.apache.jackrabbit.oak.run.cli.CommonOptions) Options(org.apache.jackrabbit.oak.run.cli.Options) NodeStoreFixture(org.apache.jackrabbit.oak.run.cli.NodeStoreFixture) OptionParser(joptsimple.OptionParser) StatisticsProvider(org.apache.jackrabbit.oak.stats.StatisticsProvider)

Example 47 with OptionParser

use of joptsimple.OptionParser 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)

Example 48 with OptionParser

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

the class Utils method bootstrapDataStore.

@Nullable
public static GarbageCollectableBlobStore bootstrapDataStore(String[] args, Closer closer) throws IOException, RepositoryException {
    OptionParser parser = new OptionParser();
    parser.allowsUnrecognizedOptions();
    ArgumentAcceptingOptionSpec<String> s3dsConfig = parser.accepts("s3ds", "S3DataStore config").withRequiredArg().ofType(String.class);
    ArgumentAcceptingOptionSpec<String> fdsConfig = parser.accepts("fds", "FileDataStore config").withRequiredArg().ofType(String.class);
    ArgumentAcceptingOptionSpec<String> azureBlobDSConfig = parser.accepts("azureblobds", "AzureBlobStorageDataStore config").withRequiredArg().ofType(String.class);
    OptionSet options = parser.parse(args);
    if (!options.has(s3dsConfig) && !options.has(fdsConfig) && !options.has(azureBlobDSConfig)) {
        return null;
    }
    DataStore delegate;
    if (options.has(s3dsConfig)) {
        SharedS3DataStore s3ds = new SharedS3DataStore();
        String cfgPath = s3dsConfig.value(options);
        Properties props = loadAndTransformProps(cfgPath);
        s3ds.setProperties(props);
        File homeDir = Files.createTempDir();
        closer.register(asCloseable(homeDir));
        s3ds.init(homeDir.getAbsolutePath());
        delegate = s3ds;
    } else if (options.has(azureBlobDSConfig)) {
        AzureDataStore azureds = new AzureDataStore();
        String cfgPath = azureBlobDSConfig.value(options);
        Properties props = loadAndTransformProps(cfgPath);
        azureds.setProperties(props);
        File homeDir = Files.createTempDir();
        azureds.init(homeDir.getAbsolutePath());
        closer.register(asCloseable(homeDir));
        delegate = azureds;
    } else {
        delegate = new OakFileDataStore();
        String cfgPath = fdsConfig.value(options);
        Properties props = loadAndTransformProps(cfgPath);
        populate(delegate, asMap(props), true);
        delegate.init(null);
    }
    DataStoreBlobStore blobStore = new DataStoreBlobStore(delegate);
    closer.register(Utils.asCloseable(blobStore));
    return blobStore;
}
Also used : OakFileDataStore(org.apache.jackrabbit.oak.plugins.blob.datastore.OakFileDataStore) DataStore(org.apache.jackrabbit.core.data.DataStore) AzureDataStore(org.apache.jackrabbit.oak.blob.cloud.azure.blobstorage.AzureDataStore) SharedS3DataStore(org.apache.jackrabbit.oak.blob.cloud.aws.s3.SharedS3DataStore) OakFileDataStore(org.apache.jackrabbit.oak.plugins.blob.datastore.OakFileDataStore) SharedS3DataStore(org.apache.jackrabbit.oak.blob.cloud.aws.s3.SharedS3DataStore) AzureDataStore(org.apache.jackrabbit.oak.blob.cloud.azure.blobstorage.AzureDataStore) OptionSet(joptsimple.OptionSet) Properties(java.util.Properties) OptionParser(joptsimple.OptionParser) File(java.io.File) DataStoreBlobStore(org.apache.jackrabbit.oak.plugins.blob.datastore.DataStoreBlobStore) Nullable(javax.annotation.Nullable)

Example 49 with OptionParser

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

the class OptionsTest method noArgs.

@Test
public void noArgs() throws Exception {
    OptionParser parser = new OptionParser();
    Options opts = new Options().withDisableSystemExit();
    opts.parseAndConfigure(parser, new String[] {});
    assertNotNull(opts.getCommonOpts());
}
Also used : OptionParser(joptsimple.OptionParser) Test(org.junit.Test)

Example 50 with OptionParser

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

the class BlobStoreFixtureProviderTest method createFDSOptions.

private Options createFDSOptions(String... args) throws IOException {
    OptionParser parser = new OptionParser();
    Options opts = new Options().withDisableSystemExit();
    opts.parseAndConfigure(parser, args);
    return opts;
}
Also used : OptionParser(joptsimple.OptionParser)

Aggregations

OptionParser (joptsimple.OptionParser)121 OptionSet (joptsimple.OptionSet)94 File (java.io.File)35 OptionException (joptsimple.OptionException)16 IOException (java.io.IOException)15 List (java.util.List)13 Test (org.junit.Test)13 ArrayList (java.util.ArrayList)11 Cluster (voldemort.cluster.Cluster)8 FileNotFoundException (java.io.FileNotFoundException)6 StoreDefinition (voldemort.store.StoreDefinition)6 Closer (com.google.common.io.Closer)5 BufferedReader (java.io.BufferedReader)5 Properties (java.util.Properties)5 OptionSpec (joptsimple.OptionSpec)5 Node (voldemort.cluster.Node)5 ByteArray (voldemort.utils.ByteArray)5 ClusterMapper (voldemort.xml.ClusterMapper)5 MongoClientURI (com.mongodb.MongoClientURI)4 FileReader (java.io.FileReader)4