Author: chetanm
Date: Thu Aug 10 04:47:58 2017
New Revision: 1804632

URL: http://svn.apache.org/viewvc?rev=1804632&view=rev
Log:
OAK-6534 - Compute indexPaths from index definitions json

Modified:
    
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/index/IndexCommand.java
    
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/index/IndexOptions.java
    
jackrabbit/oak/trunk/oak-run/src/test/java/org/apache/jackrabbit/oak/index/ReindexIT.java

Modified: 
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/index/IndexCommand.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/index/IndexCommand.java?rev=1804632&r1=1804631&r2=1804632&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/index/IndexCommand.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/index/IndexCommand.java
 Thu Aug 10 04:47:58 2017
@@ -22,16 +22,22 @@ package org.apache.jackrabbit.oak.index;
 import java.io.File;
 import java.io.IOException;
 import java.nio.file.Path;
+import java.util.ArrayList;
 import java.util.Calendar;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Set;
 import java.util.concurrent.TimeUnit;
 
 import com.google.common.base.Stopwatch;
 import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Sets;
 import com.google.common.io.Closer;
 import joptsimple.OptionParser;
 import org.apache.commons.io.FileUtils;
 import org.apache.felix.inventory.Format;
 import org.apache.jackrabbit.oak.api.CommitFailedException;
+import org.apache.jackrabbit.oak.plugins.index.importer.IndexDefinitionUpdater;
 import org.apache.jackrabbit.oak.run.cli.CommonOptions;
 import org.apache.jackrabbit.oak.run.cli.NodeStoreFixture;
 import org.apache.jackrabbit.oak.run.cli.NodeStoreFixtureProvider;
@@ -139,7 +145,7 @@ public class IndexCommand implements Com
     private IndexHelper createIndexHelper(NodeStoreFixture fixture,
                                           IndexOptions indexOpts, Closer 
closer) throws IOException {
         IndexHelper indexHelper = new IndexHelper(fixture.getStore(), 
fixture.getBlobStore(), fixture.getWhiteboard(),
-                indexOpts.getOutDir(),  indexOpts.getWorkDir(), 
indexOpts.getIndexPaths());
+                indexOpts.getOutDir(),  indexOpts.getWorkDir(), 
computeIndexPaths(indexOpts));
 
         configurePreExtractionSupport(indexOpts, indexHelper);
 
@@ -147,6 +153,22 @@ public class IndexCommand implements Com
         return indexHelper;
     }
 
+    private List<String> computeIndexPaths(IndexOptions indexOpts) throws 
IOException {
+        //Combine the indexPaths from json and cli args
+        Set<String> indexPaths = new 
LinkedHashSet<>(indexOpts.getIndexPaths());
+        File definitions = indexOpts.getIndexDefinitionsFile();
+        if (definitions != null) {
+            IndexDefinitionUpdater updater = new 
IndexDefinitionUpdater(definitions);
+            Set<String> indexPathsFromJson = updater.getIndexPaths();
+            Set<String> diff = Sets.difference(indexPathsFromJson, indexPaths);
+            if (!diff.isEmpty()){
+                log.info("Augmenting the indexPaths with {} which are present 
in {}", diff, definitions);
+            }
+            indexPaths.addAll(indexPathsFromJson);
+        }
+        return new ArrayList<>(indexPaths);
+    }
+
     private void configurePreExtractionSupport(IndexOptions indexOpts, 
IndexHelper indexHelper) throws IOException {
         File preExtractedTextDir = indexOpts.getPreExtractedTextDir();
         if (preExtractedTextDir != null) {

Modified: 
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/index/IndexOptions.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/index/IndexOptions.java?rev=1804632&r1=1804631&r2=1804632&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/index/IndexOptions.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/index/IndexOptions.java
 Thu Aug 10 04:47:58 2017
@@ -87,7 +87,7 @@ public class IndexOptions implements Opt
                 .withOptionalArg().ofType(Integer.class).defaultsTo(1);
 
         dumpIndex = parser.accepts("index-dump", "Dumps index content");
-        reindex = parser.accepts("reindex", "Reindex the indexes specified by 
--index-paths").availableIf("index-paths");
+        reindex = parser.accepts("reindex", "Reindex the indexes specified by 
--index-paths or --index-definitions-file");
 
         importIndex = parser.accepts("index-import", "Imports index");
 

Modified: 
jackrabbit/oak/trunk/oak-run/src/test/java/org/apache/jackrabbit/oak/index/ReindexIT.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-run/src/test/java/org/apache/jackrabbit/oak/index/ReindexIT.java?rev=1804632&r1=1804631&r2=1804632&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-run/src/test/java/org/apache/jackrabbit/oak/index/ReindexIT.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-run/src/test/java/org/apache/jackrabbit/oak/index/ReindexIT.java
 Thu Aug 10 04:47:58 2017
@@ -287,7 +287,6 @@ public class ReindexIT extends AbstractI
         String[] args = {
                 "--index-temp-dir=" + 
temporaryFolder.newFolder().getAbsolutePath(),
                 "--index-out-dir="  + outDir.getAbsolutePath(),
-                "--index-paths=/oak:index/barIndex",
                 "--index-definitions-file=" + jsonFile.getAbsolutePath(),
                 "--reindex",
                 "--read-write",


Reply via email to