forked from apache/jackrabbit-oak
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
OAK-6224 - Enable dumping index definitions and stats via oak-run
-- Initial setup for index command -- Added dependency on felix inventory api and redirected test output to text file -- Support for dumping stats and index definitions git-svn-id: https://svn.apache.org/repos/asf/jackrabbit/oak/trunk@1795321 13f79535-47bb-0310-9956-ffa450edef68
- Loading branch information
Showing
8 changed files
with
585 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
oak-run/src/main/java/org/apache/jackrabbit/oak/index/IndexCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
/* | ||
* 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.index; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.nio.file.Path; | ||
|
||
import joptsimple.OptionParser; | ||
import joptsimple.OptionSet; | ||
import org.apache.felix.inventory.Format; | ||
import org.apache.jackrabbit.oak.console.NodeStoreFixture; | ||
import org.apache.jackrabbit.oak.run.cli.NodeStoreFixtureProvider; | ||
import org.apache.jackrabbit.oak.run.cli.Options; | ||
import org.apache.jackrabbit.oak.run.commons.Command; | ||
import org.apache.jackrabbit.oak.spi.state.NodeStore; | ||
|
||
public class IndexCommand implements Command { | ||
|
||
public static final String INDEX_DEFINITIONS_JSON = "index-definitions.json"; | ||
public static final String INDEX_INFO_TXT = "index-info.txt"; | ||
private File info; | ||
private File definitions; | ||
|
||
@Override | ||
public void execute(String... args) throws Exception { | ||
OptionParser parser = new OptionParser(); | ||
|
||
Options opts = new Options(); | ||
opts.registerOptionsFactory(IndexOptions.FACTORY); | ||
|
||
opts.parseAndConfigure(parser, args); | ||
|
||
IndexOptions indexOpts = opts.getOptionBean(IndexOptions.class); | ||
|
||
try (NodeStoreFixture fixture = NodeStoreFixtureProvider.create(opts)) { | ||
execute(fixture.getStore(), indexOpts); | ||
tellReportPaths(); | ||
} | ||
} | ||
|
||
private void tellReportPaths() { | ||
if (info != null) { | ||
System.out.printf("Index stats stored at %s%n", getPath(info)); | ||
} | ||
|
||
if (definitions != null) { | ||
System.out.printf("Index definitions stored at %s%n", getPath(definitions)); | ||
} | ||
} | ||
|
||
private void execute(NodeStore store, IndexOptions indexOpts) throws IOException { | ||
IndexHelper indexHelper = new IndexHelper(store, indexOpts.getOutDir(), indexOpts.getWorkDir()); | ||
|
||
dumpIndexStats(indexOpts, indexHelper); | ||
dumpIndexDefinitions(indexOpts, indexHelper); | ||
} | ||
|
||
private void dumpIndexDefinitions(IndexOptions indexOpts, IndexHelper indexHelper) throws IOException { | ||
if (indexOpts.dumpDefinitions()) { | ||
PrinterDumper dumper = new PrinterDumper(indexHelper.getOutputDir(), INDEX_DEFINITIONS_JSON, | ||
false, Format.JSON, indexHelper.getIndexDefnPrinter()); | ||
dumper.dump(); | ||
definitions = dumper.getOutFile(); | ||
} | ||
} | ||
|
||
private void dumpIndexStats(IndexOptions indexOpts, IndexHelper indexHelper) throws IOException { | ||
if (indexOpts.dumpStats()) { | ||
PrinterDumper dumper = new PrinterDumper(indexHelper.getOutputDir(), INDEX_INFO_TXT, | ||
true, Format.TEXT, indexHelper.getIndexPrinter()); | ||
dumper.dump(); | ||
info = dumper.getOutFile(); | ||
} | ||
} | ||
|
||
private static Path getPath(File file) { | ||
return file.toPath().normalize().toAbsolutePath(); | ||
} | ||
} |
88 changes: 88 additions & 0 deletions
88
oak-run/src/main/java/org/apache/jackrabbit/oak/index/IndexHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/* | ||
* 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.index; | ||
|
||
import java.io.File; | ||
|
||
import org.apache.jackrabbit.oak.plugins.index.AsyncIndexInfoService; | ||
import org.apache.jackrabbit.oak.plugins.index.AsyncIndexInfoServiceImpl; | ||
import org.apache.jackrabbit.oak.plugins.index.IndexInfoService; | ||
import org.apache.jackrabbit.oak.plugins.index.IndexInfoServiceImpl; | ||
import org.apache.jackrabbit.oak.plugins.index.IndexPathService; | ||
import org.apache.jackrabbit.oak.plugins.index.IndexPathServiceImpl; | ||
import org.apache.jackrabbit.oak.plugins.index.inventory.IndexDefinitionPrinter; | ||
import org.apache.jackrabbit.oak.plugins.index.inventory.IndexPrinter; | ||
import org.apache.jackrabbit.oak.plugins.index.lucene.LuceneIndexInfoProvider; | ||
import org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexInfoProvider; | ||
import org.apache.jackrabbit.oak.spi.state.NodeStore; | ||
|
||
class IndexHelper { | ||
private final NodeStore store; | ||
private final File outputDir; | ||
private final File workDir; | ||
private IndexInfoServiceImpl indexInfoService; | ||
private IndexPathService indexPathService; | ||
private AsyncIndexInfoService asyncIndexInfoService; | ||
|
||
IndexHelper(NodeStore store, File outputDir, File workDir) { | ||
this.store = store; | ||
this.outputDir = outputDir; | ||
this.workDir = workDir; | ||
} | ||
|
||
public File getOutputDir() { | ||
return outputDir; | ||
} | ||
|
||
public IndexPrinter getIndexPrinter() { | ||
return new IndexPrinter(getIndexInfoService(), getAsyncIndexInfoService()); | ||
} | ||
|
||
public IndexDefinitionPrinter getIndexDefnPrinter() { | ||
return new IndexDefinitionPrinter(store, getIndexPathService()); | ||
} | ||
|
||
private IndexPathService getIndexPathService() { | ||
if (indexPathService == null) { | ||
indexPathService = new IndexPathServiceImpl(store); | ||
} | ||
return indexPathService; | ||
} | ||
|
||
private AsyncIndexInfoService getAsyncIndexInfoService() { | ||
if (asyncIndexInfoService == null) { | ||
asyncIndexInfoService = new AsyncIndexInfoServiceImpl(store); | ||
} | ||
return asyncIndexInfoService; | ||
} | ||
|
||
private IndexInfoService getIndexInfoService() { | ||
if (indexInfoService == null) { | ||
indexInfoService = new IndexInfoServiceImpl(store, getIndexPathService()); | ||
bindIndexInfoProviders(indexInfoService); | ||
} | ||
return indexInfoService; | ||
} | ||
|
||
private void bindIndexInfoProviders(IndexInfoServiceImpl indexInfoService) { | ||
indexInfoService.bindInfoProviders(new LuceneIndexInfoProvider(store, getAsyncIndexInfoService(), workDir)); | ||
indexInfoService.bindInfoProviders(new PropertyIndexInfoProvider(store)); | ||
} | ||
} |
79 changes: 79 additions & 0 deletions
79
oak-run/src/main/java/org/apache/jackrabbit/oak/index/IndexOptions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/* | ||
* 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.index; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
|
||
import joptsimple.OptionParser; | ||
import joptsimple.OptionSet; | ||
import joptsimple.OptionSpec; | ||
import org.apache.commons.io.FileUtils; | ||
import org.apache.jackrabbit.oak.run.cli.OptionsBean; | ||
import org.apache.jackrabbit.oak.run.cli.OptionsBeanFactory; | ||
|
||
public class IndexOptions implements OptionsBean { | ||
|
||
public static final OptionsBeanFactory FACTORY = new OptionsBeanFactory() { | ||
@Override | ||
public OptionsBean newInstance(OptionParser parser) { | ||
return new IndexOptions(parser); | ||
} | ||
}; | ||
|
||
private final OptionSpec<File> workDirOpt; | ||
private final OptionSpec<File> outputDirOpt; | ||
private final OptionSpec<Void> stats; | ||
private final OptionSpec<Void> definitions; | ||
private OptionSet options; | ||
|
||
|
||
public IndexOptions(OptionParser parser){ | ||
workDirOpt = parser.accepts("index-work-dir", "Work directory used for storing temp files") | ||
.withRequiredArg().ofType(File.class).defaultsTo(new File("target")); | ||
outputDirOpt = parser.accepts("index-out-dir", "Directory used for output files") | ||
.withRequiredArg().ofType(File.class).defaultsTo(new File(".")); | ||
stats = parser.accepts("index-info", "Collects and dumps information related to the indexes"); | ||
definitions = parser.accepts("index-definitions", "Collects and dumps index definitions"); | ||
} | ||
|
||
@Override | ||
public void configure(OptionSet options) { | ||
this.options = options; | ||
} | ||
|
||
public File getWorkDir() throws IOException { | ||
File workDir = workDirOpt.value(options); | ||
FileUtils.forceMkdir(workDir); | ||
return workDir; | ||
} | ||
|
||
public File getOutDir() { | ||
return outputDirOpt.value(options); | ||
} | ||
|
||
public boolean dumpStats(){ | ||
return options.has(stats); | ||
} | ||
|
||
public boolean dumpDefinitions(){ | ||
return options.has(definitions); | ||
} | ||
} |
68 changes: 68 additions & 0 deletions
68
oak-run/src/main/java/org/apache/jackrabbit/oak/index/PrinterDumper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
* 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.index; | ||
|
||
import java.io.BufferedOutputStream; | ||
import java.io.File; | ||
import java.io.IOException; | ||
import java.io.OutputStream; | ||
import java.io.PrintWriter; | ||
|
||
import org.apache.commons.io.FileUtils; | ||
import org.apache.commons.io.output.TeeOutputStream; | ||
import org.apache.felix.inventory.Format; | ||
import org.apache.felix.inventory.InventoryPrinter; | ||
|
||
import static com.google.common.base.Preconditions.checkNotNull; | ||
|
||
class PrinterDumper { | ||
private final File outDir; | ||
private final String fileName; | ||
private final boolean dumpToSysOut; | ||
private final Format format; | ||
private final InventoryPrinter printer; | ||
private File outFile; | ||
|
||
public PrinterDumper(File outDir, String fileName, boolean dumpToSysOut, Format format, InventoryPrinter printer) { | ||
this.outDir = outDir; | ||
this.fileName = fileName; | ||
this.dumpToSysOut = dumpToSysOut; | ||
this.format = format; | ||
this.printer = printer; | ||
} | ||
|
||
public void dump() throws IOException { | ||
try (OutputStream os = newOutput()) { | ||
OutputStream writerStream = dumpToSysOut ? new TeeOutputStream(os, System.out) : os; | ||
PrintWriter pw = new PrintWriter(writerStream); | ||
printer.print(pw, format, false); | ||
pw.flush(); | ||
} | ||
} | ||
|
||
public File getOutFile() { | ||
return checkNotNull(outFile); | ||
} | ||
|
||
private OutputStream newOutput() throws IOException { | ||
outFile = new File(outDir, fileName); | ||
return new BufferedOutputStream(FileUtils.openOutputStream(outFile)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.