upgrade from solr4

This commit is contained in:
Greg DiCristofaro 2023-09-22 10:52:58 -04:00
parent 556c89f076
commit b2f89ddd36
4 changed files with 111 additions and 7 deletions

View File

@ -263,4 +263,11 @@ public final class ModalDialogProgressIndicator implements ProgressIndicator {
dialog.setLocationRelativeTo(parent);
this.dialog.setVisible(true);
}
/**
* @return The GUI dialog presenting the progress. Possibly null.
*/
public Dialog getDialog() {
return this.dialog;
}
}

View File

@ -52,7 +52,7 @@ KeywordSearchResultFactory.createNodeForKey.noResultsFound.text=No results found
KeywordSearchResultFactory.query.exception.msg=Could not perform the query
OpenIDE-Module-Display-Category=Ingest Module
OpenIDE-Module-Long-Description=Keyword Search ingest module.\n\nThe module indexes files found in the disk image at ingest time.\nIt then periodically runs the search on the indexed files using one or more keyword lists (containing pure words and/or regular expressions) and posts results.\n\n\The module also contains additional tools integrated in the main GUI, such as keyword list configuration, keyword search bar in the top-right corner, extracted text viewer and search results viewer showing highlighted keywords found.
OpenIDE-Module-Long-Description=Keyword Search ingest module.\n\nThe module indexes files found in the disk image at ingest time.\nIt then periodically runs the search on the indexed files using one or more keyword lists (containing pure words and/or regular expressions) and posts results.\n\nThe module also contains additional tools integrated in the main GUI, such as keyword list configuration, keyword search bar in the top-right corner, extracted text viewer and search results viewer showing highlighted keywords found.
OpenIDE-Module-Name=KeywordSearch
OptionsCategory_Name_KeywordSearchOptions=Keyword Search
OptionsCategory_Keywords_KeywordSearchOptions=Keyword Search
@ -306,6 +306,14 @@ KeywordSearchModuleFactory.getIngestJobSettingsPanel.exception.msg=Expected sett
KeywordSearchModuleFactory.createFileIngestModule.exception.msg=Expected settings argument to be instanceof KeywordSearchJobSettings
SearchRunner.Searcher.done.err.msg=Error performing keyword search
Server.status.failed.msg=Local Solr server did not respond to status request. This may be because the server failed to start or is taking too long to initialize.
# {0} - indexVersion
Server_configureSolrConnection_illegalSolrVersion=The solr version in the case: {0}, is not supported.
# {0} - solrVersion
# {1} - caseName
Server_configureSolrConnection_unsupportedSolrDesc=<html><body><p style="width: 400px">The current Solr version: {0} in the case: {1} is no longer supported. You can continue without upgrading, but Solr will not be usable while the case is open, and you will encounter errors. You can also choose to upgrade the Solr version for the case. If you choose to do this, you will need to run Keyword Search with Solr indexing selected in order to use Solr features like ad hoc search with images in the case.</p></body></html>
Server_configureSolrConnection_unsupportedSolrDisableOpt=Continue
Server_configureSolrConnection_unsupportedSolrTitle=Unsupported Solr Version
Server_configureSolrConnection_unsupportedSolrUpgradeOpt=Upgrade Solr Core
SolrConnectionCheck.HostnameOrPort=Invalid hostname and/or port number.
SolrConnectionCheck.Hostname=Invalid hostname.
SolrConnectionCheck.MissingHostname=Missing hostname.

View File

@ -57,6 +57,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;
import static java.util.stream.Collectors.toList;
import javax.swing.JOptionPane;
import org.apache.solr.client.solrj.SolrQuery;
import org.apache.solr.client.solrj.SolrRequest;
import org.apache.solr.client.solrj.SolrServerException;
@ -82,6 +83,7 @@ import org.apache.solr.common.util.NamedList;
import org.openide.modules.InstalledFileLocator;
import org.openide.modules.Places;
import org.openide.util.NbBundle;
import org.openide.util.NbBundle.Messages;
import org.openide.windows.WindowManager;
import org.sleuthkit.autopsy.casemodule.Case;
import org.sleuthkit.autopsy.casemodule.Case.CaseType;
@ -611,18 +613,22 @@ public class Server {
startLocalSolr(SOLR_VERSION.SOLR8);
}
@Messages({
"# {0} - indexVersion",
"Server_configureSolrConnection_illegalSolrVersion=The solr version in the case: {0}, is not supported."
})
private void configureSolrConnection(Case theCase, Index index) throws KeywordSearchModuleException, SolrServerNoPortException {
try {
if (theCase.getCaseType() == CaseType.SINGLE_USER_CASE) {
// makes sure the proper local Solr server is running
if (IndexFinder.getCurrentSolrVersion().equals(index.getSolrVersion())) {
startLocalSolr(SOLR_VERSION.SOLR8);
} else {
startLocalSolr(SOLR_VERSION.SOLR4);
if (!IndexFinder.getCurrentSolrVersion().equals(index.getSolrVersion())) {
throw new KeywordSearchModuleException(Bundle.Server_configureSolrConnection_illegalSolrVersion(index.getSolrVersion()));
}
startLocalSolr(SOLR_VERSION.SOLR8);
// check if the local Solr server is running
if (!this.isLocalSolrRunning()) {
logger.log(Level.SEVERE, "Local Solr server is not running"); //NON-NLS
@ -684,8 +690,7 @@ public class Server {
if (version == SOLR_VERSION.SOLR8) {
localSolrFolder = InstalledFileLocator.getDefault().locate("solr", Server.class.getPackage().getName(), false); //NON-NLS
} else {
// solr4
localSolrFolder = InstalledFileLocator.getDefault().locate("solr4", Server.class.getPackage().getName(), false); //NON-NLS
throw new KeywordSearchModuleException(Bundle.Server_configureSolrConnection_illegalSolrVersion(version.name()));
}
if (isLocalSolrRunning()) {

View File

@ -18,6 +18,7 @@
*/
package org.sleuthkit.autopsy.keywordsearch;
import java.awt.Component;
import java.io.File;
import java.io.IOException;
import java.io.Reader;
@ -26,18 +27,22 @@ import java.util.ArrayList;
import java.util.List;
import java.util.MissingResourceException;
import java.util.logging.Level;
import javax.swing.JOptionPane;
import org.apache.solr.client.solrj.SolrServerException;
import org.openide.util.NbBundle;
import org.openide.util.lookup.ServiceProvider;
import org.openide.util.lookup.ServiceProviders;
import org.openide.windows.WindowManager;
import org.sleuthkit.autopsy.appservices.AutopsyService;
import org.sleuthkit.autopsy.casemodule.Case;
import org.sleuthkit.autopsy.casemodule.CaseMetadata;
import org.sleuthkit.autopsy.core.RuntimeProperties;
import org.sleuthkit.autopsy.coreutils.FileUtil;
import org.sleuthkit.autopsy.coreutils.Logger;
import org.sleuthkit.autopsy.ingest.IngestManager;
import org.sleuthkit.autopsy.keywordsearchservice.KeywordSearchService;
import org.sleuthkit.autopsy.keywordsearchservice.KeywordSearchServiceException;
import org.sleuthkit.autopsy.progress.ModalDialogProgressIndicator;
import org.sleuthkit.autopsy.progress.ProgressIndicator;
import org.sleuthkit.autopsy.textextractors.TextExtractor;
import org.sleuthkit.autopsy.textextractors.TextExtractorFactory;
@ -316,6 +321,20 @@ public class SolrSearchService implements KeywordSearchService, AutopsyService {
throw new AutopsyServiceException(Bundle.SolrSearch_unableToFindIndex_msg());
}
if (context.cancelRequested()) {
return;
}
if (!IndexFinder.getCurrentSolrVersion().equals(indexToUse.getSolrVersion())) {
Index prevIndex = indexToUse;
indexToUse = tryUpgradeSolrVersion(context, indexToUse);
if (indexToUse != prevIndex) {
indexes.add(indexToUse);
}
}
if (context.cancelRequested()) {
return;
}
@ -356,6 +375,71 @@ public class SolrSearchService implements KeywordSearchService, AutopsyService {
progress.progress(Bundle.SolrSearch_complete_msg(), totalNumProgressUnits);
}
private static final long WAIT_TIME_MILLIS = 2000;
/**
* Attempts to upgrade the solr version to most recent version first prompting the user.
* @param context The case context.
* @param index The current index.
* @return The new index.
* @throws org.sleuthkit.autopsy.appservices.AutopsyService.AutopsyServiceException
*/
@NbBundle.Messages({
"Server_configureSolrConnection_unsupportedSolrTitle=Unsupported Solr Version",
"# {0} - solrVersion",
"# {1} - caseName",
"Server_configureSolrConnection_unsupportedSolrDesc=<html><body><p style=\"width: 400px\">The current Solr version: {0} in the case: {1} is no longer supported. You can continue without upgrading, but Solr will not be usable while the case is open, and you will encounter errors. You can also choose to upgrade the Solr version for the case. If you choose to do this, you will need to run Keyword Search with Solr indexing selected in order to use Solr features like ad hoc search with images in the case.</p></body></html>",
"Server_configureSolrConnection_unsupportedSolrDisableOpt=Continue",
"Server_configureSolrConnection_unsupportedSolrUpgradeOpt=Upgrade Solr Core"
})
private Index tryUpgradeSolrVersion(CaseContext context, Index index) throws AutopsyServiceException {
// if not, attempt to fix issue
if (RuntimeProperties.runningWithGUI()) {
Component parentComponent = WindowManager.getDefault().getMainWindow();
if (context.getProgressIndicator() instanceof ModalDialogProgressIndicator progInd && progInd.getDialog() != null) {
parentComponent = progInd.getDialog();
}
if (context.cancelRequested()) {
return index;
}
try {
// progress updates occur right before this in the same window, so there is the possibility that
// the progress window will update just after the option pane is shown causing the option pane to
// not be visible or selectable. This sleep is added to give the window enough time to finish
Thread.sleep(WAIT_TIME_MILLIS);
} catch (InterruptedException ex) {
// just proceed if interrupted
}
if (context.cancelRequested()) {
return index;
}
int selection = JOptionPane.showOptionDialog(
parentComponent,
Bundle.Server_configureSolrConnection_unsupportedSolrDesc(index.getSolrVersion(), context.getCase().getDisplayName()),
Bundle.Server_configureSolrConnection_unsupportedSolrTitle(),
JOptionPane.YES_NO_OPTION,
JOptionPane.WARNING_MESSAGE,
null,
new Object[]{
Bundle.Server_configureSolrConnection_unsupportedSolrDisableOpt(),
Bundle.Server_configureSolrConnection_unsupportedSolrUpgradeOpt()
},
Bundle.Server_configureSolrConnection_unsupportedSolrDisableOpt());
if (selection == 1) {
return IndexFinder.createLatestVersionIndex(context.getCase());
}
}
throw new AutopsyServiceException("Unsupported Solr version: " + index.getSolrVersion());
}
/**
* Closes the open core.
*