Search in sources :

Example 11 with MongoConnection

use of org.apache.jackrabbit.oak.plugins.document.util.MongoConnection in project jackrabbit-oak by apache.

the class NodeStoreFixtureProvider method configureDocumentMk.

private static NodeStore configureDocumentMk(Options options, BlobStore blobStore, StatisticsProvider statisticsProvider, Closer closer, Whiteboard wb, boolean readOnly) throws UnknownHostException {
    DocumentMK.Builder builder = new DocumentMK.Builder();
    if (blobStore != null) {
        builder.setBlobStore(blobStore);
    }
    DocumentNodeStoreOptions docStoreOpts = options.getOptionBean(DocumentNodeStoreOptions.class);
    builder.setClusterId(docStoreOpts.getClusterId());
    builder.setStatisticsProvider(statisticsProvider);
    if (readOnly) {
        builder.setReadOnlyMode();
    }
    int cacheSize = docStoreOpts.getCacheSize();
    if (cacheSize != 0) {
        builder.memoryCacheSize(cacheSize * MB);
    }
    if (docStoreOpts.disableBranchesSpec()) {
        builder.disableBranches();
    }
    CommonOptions commonOpts = options.getOptionBean(CommonOptions.class);
    if (docStoreOpts.isCacheDistributionDefined()) {
        builder.memoryCacheDistribution(docStoreOpts.getNodeCachePercentage(), docStoreOpts.getPrevDocCachePercentage(), docStoreOpts.getChildrenCachePercentage(), docStoreOpts.getDiffCachePercentage());
    }
    if (commonOpts.isMongo()) {
        MongoClientURI uri = new MongoClientURI(commonOpts.getStoreArg());
        if (uri.getDatabase() == null) {
            System.err.println("Database missing in MongoDB URI: " + uri.getURI());
            System.exit(1);
        }
        MongoConnection mongo = new MongoConnection(uri.getURI());
        wb.register(MongoConnection.class, mongo, Collections.emptyMap());
        closer.register(mongo::close);
        builder.setMongoDB(mongo.getDB());
    } else if (commonOpts.isRDB()) {
        RDBStoreOptions rdbOpts = options.getOptionBean(RDBStoreOptions.class);
        DataSource ds = RDBDataSourceFactory.forJdbcUrl(commonOpts.getStoreArg(), rdbOpts.getUser(), rdbOpts.getPassword());
        wb.register(DataSource.class, ds, Collections.emptyMap());
        builder.setRDBConnection(ds);
    }
    return builder.getNodeStore();
}
Also used : FileStoreBuilder.fileStoreBuilder(org.apache.jackrabbit.oak.segment.file.FileStoreBuilder.fileStoreBuilder) FileStoreBuilder(org.apache.jackrabbit.oak.segment.file.FileStoreBuilder) DocumentMK(org.apache.jackrabbit.oak.plugins.document.DocumentMK) MongoClientURI(com.mongodb.MongoClientURI) MongoConnection(org.apache.jackrabbit.oak.plugins.document.util.MongoConnection) DataSource(javax.sql.DataSource)

Example 12 with MongoConnection

use of org.apache.jackrabbit.oak.plugins.document.util.MongoConnection in project jackrabbit-oak by apache.

the class RevisionsCommandTest method reset.

@Test
public void reset() throws Exception {
    ns.getVersionGarbageCollector().gc(1, TimeUnit.HOURS);
    Document doc = ns.getDocumentStore().find(Collection.SETTINGS, "versionGC");
    assertNotNull(doc);
    ns.dispose();
    String output = captureSystemOut(new RevisionsCmd("reset"));
    assertTrue(output.contains("resetting recommendations and statistics"));
    MongoConnection c = connectionFactory.getConnection();
    ns = builderProvider.newBuilder().setMongoDB(c.getDB()).getNodeStore();
    doc = ns.getDocumentStore().find(Collection.SETTINGS, "versionGC");
    assertNull(doc);
}
Also used : CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Document(org.apache.jackrabbit.oak.plugins.document.Document) MongoConnection(org.apache.jackrabbit.oak.plugins.document.util.MongoConnection) Test(org.junit.Test)

Example 13 with MongoConnection

use of org.apache.jackrabbit.oak.plugins.document.util.MongoConnection in project jackrabbit-oak by apache.

the class UnlockUpgradeCommandTest method resetFormatVersion.

private void resetFormatVersion(FormatVersion v) {
    MongoConnection c = connectionFactory.getConnection();
    DocumentStore s = new MongoDocumentStore(c.getDB(), new DocumentMK.Builder());
    s.remove(Collection.SETTINGS, "version");
    assertTrue(v.writeTo(s));
    s.dispose();
}
Also used : DocumentStore(org.apache.jackrabbit.oak.plugins.document.DocumentStore) MongoDocumentStore(org.apache.jackrabbit.oak.plugins.document.mongo.MongoDocumentStore) DocumentMK(org.apache.jackrabbit.oak.plugins.document.DocumentMK) MongoConnection(org.apache.jackrabbit.oak.plugins.document.util.MongoConnection) MongoDocumentStore(org.apache.jackrabbit.oak.plugins.document.mongo.MongoDocumentStore)

Example 14 with MongoConnection

use of org.apache.jackrabbit.oak.plugins.document.util.MongoConnection in project jackrabbit-oak by apache.

the class UnlockUpgradeCommandTest method createDocumentNodeStore.

private DocumentNodeStore createDocumentNodeStore() {
    MongoConnection c = connectionFactory.getConnection();
    MongoUtils.dropCollections(c.getDB().getName());
    return builderProvider.newBuilder().setMongoDB(c.getDB()).getNodeStore();
}
Also used : MongoConnection(org.apache.jackrabbit.oak.plugins.document.util.MongoConnection)

Example 15 with MongoConnection

use of org.apache.jackrabbit.oak.plugins.document.util.MongoConnection in project jackrabbit-oak by apache.

the class DocumentMongoFixture method getDb.

protected DB getDb(String suffix) throws UnknownHostException {
    String dbName = new MongoClientURI(uri).getDatabase();
    MongoConnection connection = new MongoConnection(uri);
    return connection.getDB(dbName + "-" + suffix);
}
Also used : MongoClientURI(com.mongodb.MongoClientURI) MongoConnection(org.apache.jackrabbit.oak.plugins.document.util.MongoConnection)

Aggregations

MongoConnection (org.apache.jackrabbit.oak.plugins.document.util.MongoConnection)23 DocumentMK (org.apache.jackrabbit.oak.plugins.document.DocumentMK)8 Test (org.junit.Test)6 MongoClientURI (com.mongodb.MongoClientURI)5 DB (com.mongodb.DB)3 DBCollection (com.mongodb.DBCollection)3 DataSource (javax.sql.DataSource)3 DocumentStore (org.apache.jackrabbit.oak.plugins.document.DocumentStore)3 DBObject (com.mongodb.DBObject)2 MongoDocumentStore (org.apache.jackrabbit.oak.plugins.document.mongo.MongoDocumentStore)2 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)2 Before (org.junit.Before)2 BasicDBObject (com.mongodb.BasicDBObject)1 MongoClientOptions (com.mongodb.MongoClientOptions)1 Closeable (java.io.Closeable)1 IOException (java.io.IOException)1 CheckForNull (javax.annotation.CheckForNull)1 Repository (javax.jcr.Repository)1 RepositoryException (javax.jcr.RepositoryException)1 Session (javax.jcr.Session)1