Author: chetanm
Date: Fri Aug  4 10:49:12 2017
New Revision: 1804092

URL: http://svn.apache.org/viewvc?rev=1804092&view=rev
Log:
OAK-6524 - Provide an extension point to customize the NodeStore builders

Refactor NodeStoreFixtureProvider and move out NodeStore specific logic to
respective fixtures

Added:
    
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/cli/DocumentFixtureProvider.java
   (with props)
    
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/cli/SegmentTarFixtureProvider.java
      - copied, changed from r1804085, 
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/cli/SegmentFixtureProvider.java
Modified:
    
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/cli/NodeStoreFixtureProvider.java
    
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/cli/SegmentFixtureProvider.java

Added: 
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/cli/DocumentFixtureProvider.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/cli/DocumentFixtureProvider.java?rev=1804092&view=auto
==============================================================================
--- 
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/cli/DocumentFixtureProvider.java
 (added)
+++ 
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/cli/DocumentFixtureProvider.java
 Fri Aug  4 10:49:12 2017
@@ -0,0 +1,115 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.jackrabbit.oak.run.cli;
+
+import java.net.UnknownHostException;
+
+import javax.sql.DataSource;
+
+import com.google.common.io.Closer;
+import com.mongodb.MongoClientURI;
+import org.apache.commons.io.FileUtils;
+import org.apache.jackrabbit.oak.plugins.document.DocumentMK;
+import org.apache.jackrabbit.oak.plugins.document.DocumentNodeStore;
+import org.apache.jackrabbit.oak.plugins.document.mongo.MongoDocumentStore;
+import org.apache.jackrabbit.oak.plugins.document.rdb.RDBDataSourceFactory;
+import org.apache.jackrabbit.oak.plugins.document.rdb.RDBDocumentStore;
+import org.apache.jackrabbit.oak.plugins.document.util.MongoConnection;
+import org.apache.jackrabbit.oak.spi.blob.BlobStore;
+import org.apache.jackrabbit.oak.spi.state.NodeStore;
+import org.apache.jackrabbit.oak.spi.whiteboard.Whiteboard;
+import org.apache.jackrabbit.oak.stats.StatisticsProvider;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+import static java.util.Collections.emptyMap;
+import static 
org.apache.jackrabbit.oak.spi.whiteboard.WhiteboardUtils.getService;
+
+class DocumentFixtureProvider {
+    static NodeStore configureDocumentMk(Options options,
+                                         BlobStore blobStore,
+                                         Whiteboard wb,
+                                         Closer closer,
+                                         boolean readOnly) throws 
UnknownHostException {
+        DocumentMK.Builder builder = new DocumentMK.Builder();
+        StatisticsProvider statisticsProvider = checkNotNull(getService(wb, 
StatisticsProvider.class));
+
+        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 * FileUtils.ONE_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()
+            );
+        }
+
+        DocumentNodeStore dns;
+        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, emptyMap());
+            closer.register(mongo::close);
+            builder.setMongoDB(mongo.getDB());
+            dns = builder.getNodeStore();
+            wb.register(MongoDocumentStore.class, (MongoDocumentStore) 
builder.getDocumentStore(), emptyMap());
+        } 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, emptyMap());
+            builder.setRDBConnection(ds);
+            dns = builder.getNodeStore();
+            wb.register(RDBDocumentStore.class, (RDBDocumentStore) 
builder.getDocumentStore(), emptyMap());
+        } else {
+            throw new IllegalStateException("Unknown DocumentStore");
+        }
+
+        closer.register(dns::dispose);
+
+        return dns;
+    }
+}

Propchange: 
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/cli/DocumentFixtureProvider.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: 
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/cli/NodeStoreFixtureProvider.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/cli/NodeStoreFixtureProvider.java?rev=1804092&r1=1804091&r2=1804092&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/cli/NodeStoreFixtureProvider.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/cli/NodeStoreFixtureProvider.java
 Fri Aug  4 10:49:12 2017
@@ -19,33 +19,16 @@
 
 package org.apache.jackrabbit.oak.run.cli;
 
-import java.io.File;
 import java.io.IOException;
-import java.net.UnknownHostException;
-import java.util.Collections;
 import java.util.concurrent.ScheduledExecutorService;
 import java.util.concurrent.ScheduledThreadPoolExecutor;
 
-import javax.sql.DataSource;
-
 import com.codahale.metrics.ConsoleReporter;
 import com.codahale.metrics.Counting;
 import com.codahale.metrics.MetricRegistry;
 import com.google.common.io.Closer;
 import com.google.common.util.concurrent.MoreExecutors;
-import com.mongodb.MongoClientURI;
-import org.apache.jackrabbit.oak.plugins.document.DocumentMK;
-import org.apache.jackrabbit.oak.plugins.document.DocumentNodeStore;
-import org.apache.jackrabbit.oak.plugins.document.mongo.MongoDocumentStore;
-import org.apache.jackrabbit.oak.plugins.document.rdb.RDBDataSourceFactory;
-import org.apache.jackrabbit.oak.plugins.document.rdb.RDBDocumentStore;
-import org.apache.jackrabbit.oak.plugins.document.util.MongoConnection;
 import org.apache.jackrabbit.oak.plugins.metric.MetricStatisticsProvider;
-import org.apache.jackrabbit.oak.segment.SegmentNodeStoreBuilders;
-import org.apache.jackrabbit.oak.segment.file.FileStore;
-import org.apache.jackrabbit.oak.segment.file.FileStoreBuilder;
-import org.apache.jackrabbit.oak.segment.file.InvalidFileStoreVersionException;
-import org.apache.jackrabbit.oak.segment.file.ReadOnlyFileStore;
 import org.apache.jackrabbit.oak.spi.blob.BlobStore;
 import org.apache.jackrabbit.oak.spi.state.NodeStore;
 import org.apache.jackrabbit.oak.spi.whiteboard.Whiteboard;
@@ -53,11 +36,8 @@ import org.apache.jackrabbit.oak.stats.S
 
 import static java.lang.management.ManagementFactory.getPlatformMBeanServer;
 import static java.util.Collections.emptyMap;
-import static 
org.apache.jackrabbit.oak.segment.file.FileStoreBuilder.fileStoreBuilder;
 
 public class NodeStoreFixtureProvider {
-    private static final long MB = 1024 * 1024;
-
     public static NodeStoreFixture create(Options options) throws Exception {
         return create(options, 
!options.getOptionBean(CommonOptions.class).isReadWrite());
     }
@@ -78,114 +58,16 @@ public class NodeStoreFixtureProvider {
 
         NodeStore store;
         if (commonOpts.isMongo() || commonOpts.isRDB()) {
-            store = configureDocumentMk(options, blobStore, 
statisticsProvider, closer, wb, readOnly);
+            store = DocumentFixtureProvider.configureDocumentMk(options, 
blobStore, wb, closer, readOnly);
         } else if (commonOpts.isOldSegment()) {
-            store = SegmentFixtureProvider.create(options, blobStore, 
statisticsProvider, closer, readOnly);
+            store = SegmentFixtureProvider.create(options, blobStore, wb, 
closer, readOnly);
         } else {
-            store = configureSegment(options, blobStore, statisticsProvider, 
closer, readOnly);
+            store = SegmentTarFixtureProvider.configureSegment(options, 
blobStore, wb, closer, readOnly);
         }
 
         return new SimpleNodeStoreFixture(store, blobStore, wb, closer);
     }
 
-    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()
-            );
-        }
-
-        DocumentNodeStore dns;
-        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, emptyMap());
-            closer.register(mongo::close);
-            builder.setMongoDB(mongo.getDB());
-            dns = builder.getNodeStore();
-            wb.register(MongoDocumentStore.class, (MongoDocumentStore) 
builder.getDocumentStore(), emptyMap());
-        } 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, emptyMap());
-            builder.setRDBConnection(ds);
-            dns = builder.getNodeStore();
-            wb.register(RDBDocumentStore.class, (RDBDocumentStore) 
builder.getDocumentStore(), emptyMap());
-        } else {
-            throw new IllegalStateException("Unknown DocumentStore");
-        }
-
-        closer.register(() -> dns.dispose());
-
-        return dns;
-    }
-
-    private static NodeStore configureSegment(Options options, BlobStore 
blobStore, StatisticsProvider statisticsProvider, Closer closer, boolean 
readOnly)
-            throws IOException, InvalidFileStoreVersionException {
-
-        String path = options.getOptionBean(CommonOptions.class).getStoreArg();
-        FileStoreBuilder builder = fileStoreBuilder(new 
File(path)).withMaxFileSize(256);
-
-        if (blobStore != null) {
-            builder.withBlobStore(blobStore);
-        }
-
-        NodeStore nodeStore;
-        if (readOnly) {
-            ReadOnlyFileStore fileStore = builder
-                    .withStatisticsProvider(statisticsProvider)
-                    .buildReadOnly();
-            closer.register(fileStore);
-            nodeStore = SegmentNodeStoreBuilders.builder(fileStore).build();
-        } else {
-            FileStore fileStore = builder
-                    .withStatisticsProvider(statisticsProvider)
-                    .build();
-            closer.register(fileStore);
-            nodeStore = SegmentNodeStoreBuilders.builder(fileStore).build();
-        }
-
-        return nodeStore;
-    }
-
     private static StatisticsProvider createStatsProvider(Options options, 
Whiteboard wb, Closer closer) {
         if (options.getCommonOpts().isMetricsEnabled()) {
             ScheduledExecutorService executorService =

Modified: 
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/cli/SegmentFixtureProvider.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/cli/SegmentFixtureProvider.java?rev=1804092&r1=1804091&r2=1804092&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/cli/SegmentFixtureProvider.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/cli/SegmentFixtureProvider.java
 Fri Aug  4 10:49:12 2017
@@ -28,12 +28,18 @@ import org.apache.jackrabbit.oak.plugins
 import 
org.apache.jackrabbit.oak.plugins.segment.file.InvalidFileStoreVersionException;
 import org.apache.jackrabbit.oak.spi.blob.BlobStore;
 import org.apache.jackrabbit.oak.spi.state.NodeStore;
+import org.apache.jackrabbit.oak.spi.whiteboard.Whiteboard;
 import org.apache.jackrabbit.oak.stats.StatisticsProvider;
 
+import static com.google.common.base.Preconditions.checkNotNull;
+import static 
org.apache.jackrabbit.oak.spi.whiteboard.WhiteboardUtils.getService;
+
+@SuppressWarnings("deprecation")
 class SegmentFixtureProvider {
 
-    static NodeStore create(Options options, BlobStore blobStore, 
StatisticsProvider statisticsProvider, Closer closer, boolean readOnly)
+    static NodeStore create(Options options, BlobStore blobStore, Whiteboard 
wb, Closer closer, boolean readOnly)
             throws IOException, InvalidFileStoreVersionException {
+        StatisticsProvider statisticsProvider = checkNotNull(getService(wb, 
StatisticsProvider.class));
 
         String path = options.getOptionBean(CommonOptions.class).getStoreArg();
         FileStore.Builder builder = FileStore.builder(new File(path))

Copied: 
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/cli/SegmentTarFixtureProvider.java
 (from r1804085, 
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/cli/SegmentFixtureProvider.java)
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/cli/SegmentTarFixtureProvider.java?p2=jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/cli/SegmentTarFixtureProvider.java&p1=jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/cli/SegmentFixtureProvider.java&r1=1804085&r2=1804092&rev=1804092&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/cli/SegmentFixtureProvider.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/cli/SegmentTarFixtureProvider.java
 Fri Aug  4 10:49:12 2017
@@ -23,21 +23,28 @@ import java.io.File;
 import java.io.IOException;
 
 import com.google.common.io.Closer;
-import org.apache.jackrabbit.oak.plugins.segment.SegmentNodeStore;
-import org.apache.jackrabbit.oak.plugins.segment.file.FileStore;
-import 
org.apache.jackrabbit.oak.plugins.segment.file.InvalidFileStoreVersionException;
+import org.apache.jackrabbit.oak.segment.SegmentNodeStoreBuilders;
+import org.apache.jackrabbit.oak.segment.file.FileStore;
+import org.apache.jackrabbit.oak.segment.file.FileStoreBuilder;
+import org.apache.jackrabbit.oak.segment.file.InvalidFileStoreVersionException;
+import org.apache.jackrabbit.oak.segment.file.ReadOnlyFileStore;
 import org.apache.jackrabbit.oak.spi.blob.BlobStore;
 import org.apache.jackrabbit.oak.spi.state.NodeStore;
+import org.apache.jackrabbit.oak.spi.whiteboard.Whiteboard;
 import org.apache.jackrabbit.oak.stats.StatisticsProvider;
 
-class SegmentFixtureProvider {
+import static com.google.common.base.Preconditions.checkNotNull;
+import static 
org.apache.jackrabbit.oak.segment.file.FileStoreBuilder.fileStoreBuilder;
+import static 
org.apache.jackrabbit.oak.spi.whiteboard.WhiteboardUtils.getService;
 
-    static NodeStore create(Options options, BlobStore blobStore, 
StatisticsProvider statisticsProvider, Closer closer, boolean readOnly)
+class SegmentTarFixtureProvider {
+
+    static NodeStore configureSegment(Options options, BlobStore blobStore, 
Whiteboard wb, Closer closer, boolean readOnly)
             throws IOException, InvalidFileStoreVersionException {
+        StatisticsProvider statisticsProvider = checkNotNull(getService(wb, 
StatisticsProvider.class));
 
         String path = options.getOptionBean(CommonOptions.class).getStoreArg();
-        FileStore.Builder builder = FileStore.builder(new File(path))
-                .withMaxFileSize(256).withDefaultMemoryMapping();
+        FileStoreBuilder builder = fileStoreBuilder(new 
File(path)).withMaxFileSize(256);
 
         if (blobStore != null) {
             builder.withBlobStore(blobStore);
@@ -45,17 +52,17 @@ class SegmentFixtureProvider {
 
         NodeStore nodeStore;
         if (readOnly) {
-            FileStore.ReadOnlyStore fileStore = builder
+            ReadOnlyFileStore fileStore = builder
                     .withStatisticsProvider(statisticsProvider)
                     .buildReadOnly();
             closer.register(fileStore);
-            nodeStore = SegmentNodeStore.builder(fileStore).build();
+            nodeStore = SegmentNodeStoreBuilders.builder(fileStore).build();
         } else {
             FileStore fileStore = builder
                     .withStatisticsProvider(statisticsProvider)
                     .build();
             closer.register(fileStore);
-            nodeStore = SegmentNodeStore.builder(fileStore).build();
+            nodeStore = SegmentNodeStoreBuilders.builder(fileStore).build();
         }
 
         return nodeStore;


Reply via email to