mirror of
https://github.com/overcuriousity/autopsy-flatpak.git
synced 2025-07-16 09:47:42 +00:00
Added ProcessTerminator to terminate index upgrade
This commit is contained in:
parent
237b2fb8fb
commit
299ecd1a1f
@ -111,10 +111,22 @@ class IndexFinder {
|
|||||||
return bestCandidateIndex;
|
return bestCandidateIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a copy of an existing Solr index as well as a reference copy of Solr config set.
|
||||||
|
*
|
||||||
|
* @param indexToUpgrade Index object to create a copy of
|
||||||
|
* @param context AutopsyService.CaseContext object
|
||||||
|
* @param numCompletedWorkUnits Number of completed progress units so far
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*
|
||||||
|
* @throws
|
||||||
|
* org.sleuthkit.autopsy.framework.AutopsyService.AutopsyServiceException
|
||||||
|
*/
|
||||||
@NbBundle.Messages({
|
@NbBundle.Messages({
|
||||||
"SolrSearch.copyIndex.msg=Copying existing text index",
|
"SolrSearch.copyIndex.msg=Copying existing text index",
|
||||||
"SolrSearch.copyConfigSet.msg=Copying Solr config set",})
|
"SolrSearch.copyConfigSet.msg=Copying Solr config set",})
|
||||||
String copyIndexAndConfigSet(Case theCase, Index indexToUpgrade, AutopsyService.CaseContext context, int numCompletedWorkUnits) throws AutopsyService.AutopsyServiceException {
|
String copyIndexAndConfigSet(Index indexToUpgrade, AutopsyService.CaseContext context, int numCompletedWorkUnits) throws AutopsyService.AutopsyServiceException {
|
||||||
|
|
||||||
ProgressIndicator progress = context.getProgressIndicator();
|
ProgressIndicator progress = context.getProgressIndicator();
|
||||||
|
|
||||||
@ -123,7 +135,7 @@ class IndexFinder {
|
|||||||
|
|
||||||
// Copy the "old" index into ModuleOutput/keywordsearch/data/solrX_schema_Y/index
|
// Copy the "old" index into ModuleOutput/keywordsearch/data/solrX_schema_Y/index
|
||||||
progress.progress(Bundle.SolrSearch_copyIndex_msg(), numCompletedWorkUnits++);
|
progress.progress(Bundle.SolrSearch_copyIndex_msg(), numCompletedWorkUnits++);
|
||||||
String newIndexDir = copyExistingIndex(theCase, indexToUpgrade);
|
String newIndexDir = copyExistingIndex(context.getCase(), indexToUpgrade);
|
||||||
|
|
||||||
// Check for cancellation at whatever points are feasible
|
// Check for cancellation at whatever points are feasible
|
||||||
checkCancellation(context);
|
checkCancellation(context);
|
||||||
@ -180,7 +192,6 @@ class IndexFinder {
|
|||||||
if (!pathToConfigSet.exists() || !pathToConfigSet.isDirectory()) {
|
if (!pathToConfigSet.exists() || !pathToConfigSet.isDirectory()) {
|
||||||
logger.log(Level.WARNING, "Unable to locate KWS config set in order to create a reference copy"); //NON-NLS
|
logger.log(Level.WARNING, "Unable to locate KWS config set in order to create a reference copy"); //NON-NLS
|
||||||
return;
|
return;
|
||||||
// ELTODO This is NTH: throw new AutopsyService.AutopsyServiceException("Unable to locate the config set");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -47,10 +47,23 @@ class IndexUpgrader {
|
|||||||
JAVA_PATH = PlatformUtil.getJavaPath();
|
JAVA_PATH = PlatformUtil.getJavaPath();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Perform Solr text index upgrade to the latest supported version of Solr.
|
||||||
|
*
|
||||||
|
* @param newIndexDir Full path to directory of Solr index to be upgraded
|
||||||
|
* @param indexToUpgrade Index object of the existing Solr index
|
||||||
|
* @param context AutopsyService.CaseContext object
|
||||||
|
* @param numCompletedWorkUnits Number of completed progress units so far
|
||||||
|
*
|
||||||
|
* @return Index object of the upgraded index
|
||||||
|
*
|
||||||
|
* @throws
|
||||||
|
* org.sleuthkit.autopsy.framework.AutopsyService.AutopsyServiceException
|
||||||
|
*/
|
||||||
@NbBundle.Messages({
|
@NbBundle.Messages({
|
||||||
"SolrSearch.upgrade4to5.msg=Upgrading existing text index from Solr 4 to Solr 5",
|
"SolrSearch.upgrade4to5.msg=Upgrading existing text index from Solr 4 to Solr 5",
|
||||||
"SolrSearch.upgrade5to6.msg=Upgrading existing text index from Solr 5 to Solr 6",
|
"SolrSearch.upgrade5to6.msg=Upgrading existing text index from Solr 5 to Solr 6",
|
||||||
"SolrSearch.upgradeFailed.msg=Upgrade of existing Solr text index failed, deleting temporary directories",})
|
"SolrSearch.upgradeFailed.msg=Upgrade of existing Solr text index failed, deleting temporary directories",})
|
||||||
Index performIndexUpgrade(String newIndexDir, Index indexToUpgrade, AutopsyService.CaseContext context, int numCompletedWorkUnits) throws AutopsyService.AutopsyServiceException {
|
Index performIndexUpgrade(String newIndexDir, Index indexToUpgrade, AutopsyService.CaseContext context, int numCompletedWorkUnits) throws AutopsyService.AutopsyServiceException {
|
||||||
|
|
||||||
ProgressIndicator progress = context.getProgressIndicator();
|
ProgressIndicator progress = context.getProgressIndicator();
|
||||||
@ -67,16 +80,19 @@ class IndexUpgrader {
|
|||||||
// Check for cancellation at whatever points are feasible
|
// Check for cancellation at whatever points are feasible
|
||||||
checkCancellation(context);
|
checkCancellation(context);
|
||||||
|
|
||||||
|
// create process terminator that will monitor the cancellation flag
|
||||||
|
UserCancelledProcessTerminator terminatior = new UserCancelledProcessTerminator(context);
|
||||||
|
|
||||||
// upgrade from Solr 4 to 5
|
// upgrade from Solr 4 to 5
|
||||||
progress.progress(Bundle.SolrSearch_upgrade4to5_msg(), numCompletedWorkUnits++);
|
progress.progress(Bundle.SolrSearch_upgrade4to5_msg(), numCompletedWorkUnits++);
|
||||||
currentSolrVersion = upgradeSolrIndexVersion4to5(currentSolrVersion, newIndexDir, tempResultsDir);
|
currentSolrVersion = upgradeSolrIndexVersion4to5(currentSolrVersion, newIndexDir, tempResultsDir, terminatior);
|
||||||
|
|
||||||
// Check for cancellation at whatever points are feasible
|
// Check for cancellation at whatever points are feasible
|
||||||
checkCancellation(context);
|
checkCancellation(context);
|
||||||
|
|
||||||
// upgrade from Solr 5 to 6
|
// upgrade from Solr 5 to 6
|
||||||
progress.progress(Bundle.SolrSearch_upgrade5to6_msg(), numCompletedWorkUnits++);
|
progress.progress(Bundle.SolrSearch_upgrade5to6_msg(), numCompletedWorkUnits++);
|
||||||
currentSolrVersion = upgradeSolrIndexVersion5to6(currentSolrVersion, newIndexDir, tempResultsDir);
|
currentSolrVersion = upgradeSolrIndexVersion5to6(currentSolrVersion, newIndexDir, tempResultsDir, terminatior);
|
||||||
|
|
||||||
// create upgraded index object
|
// create upgraded index object
|
||||||
upgradedIndex = new Index(newIndexDir, Double.toString(currentSolrVersion), indexToUpgrade.getSchemaVersion());
|
upgradedIndex = new Index(newIndexDir, Double.toString(currentSolrVersion), indexToUpgrade.getSchemaVersion());
|
||||||
@ -103,10 +119,11 @@ class IndexUpgrader {
|
|||||||
* @param currentIndexVersion Current Solr index version
|
* @param currentIndexVersion Current Solr index version
|
||||||
* @param solr4IndexPath Full path to Solr v4 index directory
|
* @param solr4IndexPath Full path to Solr v4 index directory
|
||||||
* @param tempResultsDir Path to directory where to store log output
|
* @param tempResultsDir Path to directory where to store log output
|
||||||
|
* @param terminatior Implementation of ExecUtil.ProcessTerminator to terminate upgrade process
|
||||||
*
|
*
|
||||||
* @return The new Solr index version.
|
* @return The new Solr index version.
|
||||||
*/
|
*/
|
||||||
private double upgradeSolrIndexVersion4to5(double currentIndexVersion, String solr4IndexPath, String tempResultsDir) throws AutopsyService.AutopsyServiceException, SecurityException, IOException {
|
private double upgradeSolrIndexVersion4to5(double currentIndexVersion, String solr4IndexPath, String tempResultsDir, UserCancelledProcessTerminator terminatior) throws AutopsyService.AutopsyServiceException, SecurityException, IOException {
|
||||||
|
|
||||||
if (currentIndexVersion != 4.0) {
|
if (currentIndexVersion != 4.0) {
|
||||||
return currentIndexVersion;
|
return currentIndexVersion;
|
||||||
@ -139,7 +156,7 @@ class IndexUpgrader {
|
|||||||
ProcessBuilder processBuilder = new ProcessBuilder(commandLine);
|
ProcessBuilder processBuilder = new ProcessBuilder(commandLine);
|
||||||
processBuilder.redirectOutput(new File(outputFileFullPath));
|
processBuilder.redirectOutput(new File(outputFileFullPath));
|
||||||
processBuilder.redirectError(new File(errFileFullPath));
|
processBuilder.redirectError(new File(errFileFullPath));
|
||||||
ExecUtil.execute(processBuilder);
|
ExecUtil.execute(processBuilder, terminatior);
|
||||||
|
|
||||||
// alternatively can execute lucene upgrade command from the folder where lucene jars are located
|
// alternatively can execute lucene upgrade command from the folder where lucene jars are located
|
||||||
// java -cp ".;lucene-core-5.5.1.jar;lucene-backward-codecs-5.5.1.jar;lucene-codecs-5.5.1.jar;lucene-analyzers-common-5.5.1.jar" org.apache.lucene.index.IndexUpgrader \path\to\index
|
// java -cp ".;lucene-core-5.5.1.jar;lucene-backward-codecs-5.5.1.jar;lucene-codecs-5.5.1.jar;lucene-analyzers-common-5.5.1.jar" org.apache.lucene.index.IndexUpgrader \path\to\index
|
||||||
@ -152,10 +169,11 @@ class IndexUpgrader {
|
|||||||
* @param currentIndexVersion Current Solr index version
|
* @param currentIndexVersion Current Solr index version
|
||||||
* @param solr5IndexPath Full path to Solr v5 index directory
|
* @param solr5IndexPath Full path to Solr v5 index directory
|
||||||
* @param tempResultsDir Path to directory where to store log output
|
* @param tempResultsDir Path to directory where to store log output
|
||||||
|
* @param terminatior Implementation of ExecUtil.ProcessTerminator to terminate upgrade process
|
||||||
*
|
*
|
||||||
* @return The new Solr index version.
|
* @return The new Solr index version.
|
||||||
*/
|
*/
|
||||||
private double upgradeSolrIndexVersion5to6(double currentIndexVersion, String solr5IndexPath, String tempResultsDir) throws AutopsyService.AutopsyServiceException, SecurityException, IOException {
|
private double upgradeSolrIndexVersion5to6(double currentIndexVersion, String solr5IndexPath, String tempResultsDir, UserCancelledProcessTerminator terminatior) throws AutopsyService.AutopsyServiceException, SecurityException, IOException {
|
||||||
if (currentIndexVersion != 5.0) {
|
if (currentIndexVersion != 5.0) {
|
||||||
return currentIndexVersion;
|
return currentIndexVersion;
|
||||||
}
|
}
|
||||||
@ -187,11 +205,30 @@ class IndexUpgrader {
|
|||||||
ProcessBuilder processBuilder = new ProcessBuilder(commandLine);
|
ProcessBuilder processBuilder = new ProcessBuilder(commandLine);
|
||||||
processBuilder.redirectOutput(new File(outputFileFullPath));
|
processBuilder.redirectOutput(new File(outputFileFullPath));
|
||||||
processBuilder.redirectError(new File(errFileFullPath));
|
processBuilder.redirectError(new File(errFileFullPath));
|
||||||
ExecUtil.execute(processBuilder);
|
ExecUtil.execute(processBuilder, terminatior);
|
||||||
|
|
||||||
// alternatively can execute lucene upgrade command from the folder where lucene jars are located
|
// alternatively can execute lucene upgrade command from the folder where lucene jars are located
|
||||||
// java -cp ".;lucene-core-6.2.1.jar;lucene-backward-codecs-6.2.1.jar;lucene-codecs-6.2.1.jar;lucene-analyzers-common-6.2.1.jar" org.apache.lucene.index.IndexUpgrader \path\to\index
|
// java -cp ".;lucene-core-6.2.1.jar;lucene-backward-codecs-6.2.1.jar;lucene-codecs-6.2.1.jar;lucene-analyzers-common-6.2.1.jar" org.apache.lucene.index.IndexUpgrader \path\to\index
|
||||||
return 6.0;
|
return 6.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Process terminator that can be used to kill Solr index upgrade processes
|
||||||
|
* if a user has requested to cancel the upgrade.
|
||||||
|
*/
|
||||||
|
private class UserCancelledProcessTerminator implements ExecUtil.ProcessTerminator {
|
||||||
|
|
||||||
|
AutopsyService.CaseContext context = null;
|
||||||
|
UserCancelledProcessTerminator(AutopsyService.CaseContext context) {
|
||||||
|
this.context = context;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean shouldTerminateProcess() {
|
||||||
|
if (context.cancelRequested()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -185,7 +185,7 @@ public class SolrSearchService implements KeywordSearchService, AutopsyService {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
ProgressIndicator progress = context.getProgressIndicator();
|
ProgressIndicator progress = context.getProgressIndicator();
|
||||||
int totalNumProgressUnits = 7;
|
int totalNumProgressUnits = 8;
|
||||||
int progressUnitsCompleted = 1;
|
int progressUnitsCompleted = 1;
|
||||||
|
|
||||||
// do a case subdirectory search to check for the existence and upgrade status of KWS indexes
|
// do a case subdirectory search to check for the existence and upgrade status of KWS indexes
|
||||||
@ -250,7 +250,7 @@ public class SolrSearchService implements KeywordSearchService, AutopsyService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Copy the existing index and config set into ModuleOutput/keywordsearch/data/solrX_schema_Y/
|
// Copy the existing index and config set into ModuleOutput/keywordsearch/data/solrX_schema_Y/
|
||||||
String newIndexDir = indexFinder.copyIndexAndConfigSet(context.getCase(), indexToUpgrade, context, progressUnitsCompleted);
|
String newIndexDir = indexFinder.copyIndexAndConfigSet(indexToUpgrade, context, progressUnitsCompleted);
|
||||||
progressUnitsCompleted += 2; // add progress increments for copying existing index and config set
|
progressUnitsCompleted += 2; // add progress increments for copying existing index and config set
|
||||||
|
|
||||||
// upgrade the existing index to the latest supported Solr version
|
// upgrade the existing index to the latest supported Solr version
|
||||||
|
Loading…
x
Reference in New Issue
Block a user