Merge pull request #7869 from gdicristofaro/AUT-2481_upgradeSolr4

AUT-2481 upgrade from solr4
This commit is contained in:
Mark McKinnon 2023-11-01 11:27:29 -04:00 committed by GitHub
commit a7cb8f116c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 110 additions and 6 deletions

View File

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

View File

@ -306,6 +306,14 @@ KeywordSearchModuleFactory.getIngestJobSettingsPanel.exception.msg=Expected sett
KeywordSearchModuleFactory.createFileIngestModule.exception.msg=Expected settings argument to be instanceof KeywordSearchJobSettings KeywordSearchModuleFactory.createFileIngestModule.exception.msg=Expected settings argument to be instanceof KeywordSearchJobSettings
SearchRunner.Searcher.done.err.msg=Error performing keyword search 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. 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">This case was made with an older version of Keyword Search that is no longer supported. You can continue without upgrading, but some Keyword Search functionality will not be usable while the case is open, and you will encounter errors. You can also choose to upgrade the Keyword Search 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 features like ad hoc search with images in the case.</p></body></html>
Server_configureSolrConnection_unsupportedSolrDisableOpt=Continue
Server_configureSolrConnection_unsupportedSolrTitle=Unsupported Keyword Search in Case
Server_configureSolrConnection_unsupportedSolrUpgradeOpt=Upgrade Solr Core
SolrConnectionCheck.HostnameOrPort=Invalid hostname and/or port number. SolrConnectionCheck.HostnameOrPort=Invalid hostname and/or port number.
SolrConnectionCheck.Hostname=Invalid hostname. SolrConnectionCheck.Hostname=Invalid hostname.
SolrConnectionCheck.MissingHostname=Missing 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.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import static java.util.stream.Collectors.toList; import static java.util.stream.Collectors.toList;
import javax.swing.JOptionPane;
import org.apache.solr.client.solrj.SolrQuery; import org.apache.solr.client.solrj.SolrQuery;
import org.apache.solr.client.solrj.SolrRequest; import org.apache.solr.client.solrj.SolrRequest;
import org.apache.solr.client.solrj.SolrServerException; 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.InstalledFileLocator;
import org.openide.modules.Places; import org.openide.modules.Places;
import org.openide.util.NbBundle; import org.openide.util.NbBundle;
import org.openide.util.NbBundle.Messages;
import org.openide.windows.WindowManager; import org.openide.windows.WindowManager;
import org.sleuthkit.autopsy.casemodule.Case; import org.sleuthkit.autopsy.casemodule.Case;
import org.sleuthkit.autopsy.casemodule.Case.CaseType; import org.sleuthkit.autopsy.casemodule.Case.CaseType;
@ -611,18 +613,22 @@ public class Server {
startLocalSolr(SOLR_VERSION.SOLR8); 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 { private void configureSolrConnection(Case theCase, Index index) throws KeywordSearchModuleException, SolrServerNoPortException {
try { try {
if (theCase.getCaseType() == CaseType.SINGLE_USER_CASE) { if (theCase.getCaseType() == CaseType.SINGLE_USER_CASE) {
// makes sure the proper local Solr server is running // makes sure the proper local Solr server is running
if (IndexFinder.getCurrentSolrVersion().equals(index.getSolrVersion())) { if (!IndexFinder.getCurrentSolrVersion().equals(index.getSolrVersion())) {
startLocalSolr(SOLR_VERSION.SOLR8); throw new KeywordSearchModuleException(Bundle.Server_configureSolrConnection_illegalSolrVersion(index.getSolrVersion()));
} else {
startLocalSolr(SOLR_VERSION.SOLR4);
} }
startLocalSolr(SOLR_VERSION.SOLR8);
// check if the local Solr server is running // check if the local Solr server is running
if (!this.isLocalSolrRunning()) { if (!this.isLocalSolrRunning()) {
logger.log(Level.SEVERE, "Local Solr server is not running"); //NON-NLS logger.log(Level.SEVERE, "Local Solr server is not running"); //NON-NLS
@ -684,8 +690,7 @@ public class Server {
if (version == SOLR_VERSION.SOLR8) { if (version == SOLR_VERSION.SOLR8) {
localSolrFolder = InstalledFileLocator.getDefault().locate("solr", Server.class.getPackage().getName(), false); //NON-NLS localSolrFolder = InstalledFileLocator.getDefault().locate("solr", Server.class.getPackage().getName(), false); //NON-NLS
} else { } else {
// solr4 throw new KeywordSearchModuleException(Bundle.Server_configureSolrConnection_illegalSolrVersion(version.name()));
localSolrFolder = InstalledFileLocator.getDefault().locate("solr4", Server.class.getPackage().getName(), false); //NON-NLS
} }
if (isLocalSolrRunning()) { if (isLocalSolrRunning()) {

View File

@ -18,6 +18,7 @@
*/ */
package org.sleuthkit.autopsy.keywordsearch; package org.sleuthkit.autopsy.keywordsearch;
import java.awt.Component;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.Reader; import java.io.Reader;
@ -26,18 +27,22 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.MissingResourceException; import java.util.MissingResourceException;
import java.util.logging.Level; import java.util.logging.Level;
import javax.swing.JOptionPane;
import org.apache.solr.client.solrj.SolrServerException; import org.apache.solr.client.solrj.SolrServerException;
import org.openide.util.NbBundle; import org.openide.util.NbBundle;
import org.openide.util.lookup.ServiceProvider; import org.openide.util.lookup.ServiceProvider;
import org.openide.util.lookup.ServiceProviders; import org.openide.util.lookup.ServiceProviders;
import org.openide.windows.WindowManager;
import org.sleuthkit.autopsy.appservices.AutopsyService; import org.sleuthkit.autopsy.appservices.AutopsyService;
import org.sleuthkit.autopsy.casemodule.Case; import org.sleuthkit.autopsy.casemodule.Case;
import org.sleuthkit.autopsy.casemodule.CaseMetadata; import org.sleuthkit.autopsy.casemodule.CaseMetadata;
import org.sleuthkit.autopsy.core.RuntimeProperties;
import org.sleuthkit.autopsy.coreutils.FileUtil; import org.sleuthkit.autopsy.coreutils.FileUtil;
import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.coreutils.Logger;
import org.sleuthkit.autopsy.ingest.IngestManager; import org.sleuthkit.autopsy.ingest.IngestManager;
import org.sleuthkit.autopsy.keywordsearchservice.KeywordSearchService; import org.sleuthkit.autopsy.keywordsearchservice.KeywordSearchService;
import org.sleuthkit.autopsy.keywordsearchservice.KeywordSearchServiceException; import org.sleuthkit.autopsy.keywordsearchservice.KeywordSearchServiceException;
import org.sleuthkit.autopsy.progress.ModalDialogProgressIndicator;
import org.sleuthkit.autopsy.progress.ProgressIndicator; import org.sleuthkit.autopsy.progress.ProgressIndicator;
import org.sleuthkit.autopsy.textextractors.TextExtractor; import org.sleuthkit.autopsy.textextractors.TextExtractor;
import org.sleuthkit.autopsy.textextractors.TextExtractorFactory; import org.sleuthkit.autopsy.textextractors.TextExtractorFactory;
@ -316,6 +321,20 @@ public class SolrSearchService implements KeywordSearchService, AutopsyService {
throw new AutopsyServiceException(Bundle.SolrSearch_unableToFindIndex_msg()); 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()) { if (context.cancelRequested()) {
return; return;
} }
@ -356,6 +375,71 @@ public class SolrSearchService implements KeywordSearchService, AutopsyService {
progress.progress(Bundle.SolrSearch_complete_msg(), totalNumProgressUnits); 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 Keyword Search in Case",
"# {0} - solrVersion",
"# {1} - caseName",
"Server_configureSolrConnection_unsupportedSolrDesc=<html><body><p style=\"width: 400px\">This case was made with an older version of Keyword Search that is no longer supported. You can continue without upgrading, but some Keyword Search functionality will not be usable while the case is open, and you will encounter errors. You can also choose to upgrade the Keyword Search 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 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 Keyword Search (Solr " + index.getSolrVersion() + ")");
}
/** /**
* Closes the open core. * Closes the open core.
* *