Split IndexHandler into multiple classes

This commit is contained in:
Eugene Livis 2017-01-17 12:57:40 -05:00
parent 623758527d
commit 48b58ce9b0
2 changed files with 50 additions and 44 deletions

View File

@ -24,7 +24,10 @@ import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import org.apache.commons.io.FileUtils;
import org.openide.modules.InstalledFileLocator;
import org.openide.util.NbBundle;
import org.sleuthkit.autopsy.casemodule.Case;
import org.sleuthkit.autopsy.corecomponentinterfaces.AutopsyService;
import org.sleuthkit.autopsy.coreutils.ExecUtil;
import org.sleuthkit.autopsy.coreutils.Logger;
@ -38,11 +41,56 @@ public class IndexUpgrader {
private static final Logger logger = Logger.getLogger(IndexFinder.class.getName());
private final String JAVA_PATH;
// If SOLR_HOME environment variable doesn't exist, try these relative paths to find Solr config sets:
private static final String RELATIVE_PATH_TO_CONFIG_SET = "autopsy/solr/solr/configsets/";
private static final String RELATIVE_PATH_TO_CONFIG_SET_2 = "release/solr/solr/configsets/";
IndexUpgrader() {
JAVA_PATH = PlatformUtil.getJavaPath();
}
void performIndexUpgrade(String newIndexDir, String tempResultsDir) throws AutopsyService.AutopsyServiceException {
// ELTODO Check for cancellation at whatever points are feasible
// Run the upgrade tools on the contents (core) in ModuleOutput/keywordsearch/data/solrX_schema_Y/index
File tmpDir = Paths.get(tempResultsDir, "IndexUpgrade").toFile(); //NON-NLS
tmpDir.mkdirs();
boolean success = true;
try {
// upgrade from Solr 4 to 5. If index is newer than Solr 4 then the upgrade script will throw exception right away.
upgradeSolrIndexVersion4to5(newIndexDir, tempResultsDir);
} catch (AutopsyService.AutopsyServiceException | SecurityException | IOException ex) {
// this may not be an error, for example if index is Solr 5 to begin with
logger.log(Level.SEVERE, "Exception while upgrading keyword search index from Sorl 4 to Solr 5 " + newIndexDir, ex); //NON-NLS
success = false;
} catch (Exception ex2) {
// exceptions thrown by the Solr 4 ot 5 upgrade tool itself may not be an error, for example if index is Solr 5 (or later) to begin with
logger.log(Level.WARNING, "Exception while running Sorl 4 to Solr 5 upgrade tool " + newIndexDir, ex2); //NON-NLS
}
if (success) {
try {
// upgrade from Solr 5 to 6. This one must complete successfully in order to produce a valid Solr 6 index.
upgradeSolrIndexVersion5to6(newIndexDir, tempResultsDir);
} catch (AutopsyService.AutopsyServiceException | SecurityException | IOException ex) {
logger.log(Level.SEVERE, "Exception while upgrading keyword search index from Sorl 5 to Solr 6 " + newIndexDir, ex); //NON-NLS
success = false;
} catch (Exception ex2) {
// exceptions thrown by Solr 5 to 6 upgrade tool itself should always be treated as errors
logger.log(Level.SEVERE, "Exception while running Sorl 5 to Solr 6 upgrade tool " + newIndexDir, ex2); //NON-NLS
success = false;
}
}
success = true; // ELTODO remove
if (!success) {
// delete the new directories
new File(newIndexDir).delete();
throw new AutopsyService.AutopsyServiceException("ELTODO");
}
}
/**
* Upgrades Solr index from version 4 to 5.
*

View File

@ -186,51 +186,9 @@ public class SolrSearchService implements KeywordSearchService, AutopsyService
// Make a reference copy of the configset and place it in ModuleOutput/keywordsearch/data/solrX_schema_Y/configset
indexFinder.createReferenceConfigSetCopy(newIndexDir);
// Run the upgrade tools on the contents (core) in ModuleOutput/keywordsearch/data/solrX_schema_Y/index
File tmpDir = Paths.get(context.getCase().getTempDirectory(), "IndexUpgrade").toFile(); //NON-NLS
tmpDir.mkdirs();
boolean success = true;
// upgrade index to the latest supported Solr version
IndexUpgrader indexUpgrader = new IndexUpgrader();
try {
// upgrade from Solr 4 to 5. If index is newer than Solr 4 then the upgrade script will throw exception right away.
indexUpgrader.upgradeSolrIndexVersion4to5(newIndexDir, tmpDir.getAbsolutePath());
} catch (AutopsyServiceException | SecurityException | IOException ex) {
// this may not be an error, for example if index is Solr 5 to begin with
logger.log(Level.SEVERE, "Exception while upgrading keyword search index from Sorl 4 to Solr 5 " + newIndexDir, ex); //NON-NLS
success = false;
} catch (Exception ex2) {
// exceptions thrown by the Solr 4 ot 5 upgrade tool itself may not be an error, for example if index is Solr 5 (or later) to begin with
logger.log(Level.WARNING, "Exception while running Sorl 4 to Solr 5 upgrade tool " + newIndexDir, ex2); //NON-NLS
}
if (success) {
try {
// upgrade from Solr 5 to 6. This one must complete successfully in order to produce a valid Solr 6 index.
indexUpgrader.upgradeSolrIndexVersion5to6(newIndexDir, tmpDir.getAbsolutePath());
} catch (AutopsyServiceException | SecurityException | IOException ex) {
logger.log(Level.SEVERE, "Exception while upgrading keyword search index from Sorl 5 to Solr 6 " + newIndexDir, ex); //NON-NLS
success = false;
} catch (Exception ex2) {
// exceptions thrown by Solr 5 to 6 upgrade tool itself should always be treated as errors
logger.log(Level.SEVERE, "Exception while running Sorl 5 to Solr 6 upgrade tool " + newIndexDir, ex2); //NON-NLS
success = false;
}
}
success = true; // ELTODO remove
if (!success) {
// delete the new directories
new File(newIndexDir).delete();
throw new AutopsyServiceException("ELTODO");
}
success = true; // ELTODO remove
if (!success) {
// delete the new directories
new File(newIndexDir).delete();
throw new AutopsyServiceException("ELTODO");
}
indexUpgrader.performIndexUpgrade(newIndexDir, context.getCase().getTempDirectory());
// set the upgraded reference index as the index to be used for this case
currentVersionIndexDir = newIndexDir;