Code review

This commit is contained in:
Eugene Livis 2020-08-11 11:14:06 -04:00
parent d1c91b0089
commit 8cb276c9d5
4 changed files with 72 additions and 82 deletions

View File

@ -813,8 +813,8 @@ public final class MultiUserSettingsPanel extends javax.swing.JPanel {
} }
/** /**
* Tests whether or not values have been entered in all of the mandatory Solr settings * Tests whether or not values have been entered in all of the mandatory
* text fields. Test optional settings for completeness. * Solr settings text fields. Test optional settings for completeness.
* *
* @return True or false. * @return True or false.
*/ */
@ -859,8 +859,6 @@ public final class MultiUserSettingsPanel extends javax.swing.JPanel {
return (isUserSet == isPwSet); return (isUserSet == isPwSet);
} }
void store() { void store() {
boolean prevSelected = UserPreferences.getIsMultiUserModeEnabled(); boolean prevSelected = UserPreferences.getIsMultiUserModeEnabled();
CaseDbConnectionInfo prevConn = null; CaseDbConnectionInfo prevConn = null;
@ -941,9 +939,10 @@ public final class MultiUserSettingsPanel extends javax.swing.JPanel {
} }
// trigger changes to whether or not user can use multi user settings for central repository // trigger changes to whether or not user can use multi user settings for central repository
if (prevSelected != multiUserCasesEnabled || !areCaseDbConnectionEqual(prevConn, info)) if (prevSelected != multiUserCasesEnabled || !areCaseDbConnectionEqual(prevConn, info)) {
GlobalSettingsPanel.onMultiUserChange(this, prevSelected, multiUserCasesEnabled); GlobalSettingsPanel.onMultiUserChange(this, prevSelected, multiUserCasesEnabled);
} }
}
private boolean isRestartRequired() { private boolean isRestartRequired() {
// if ZK was previously configured // if ZK was previously configured
@ -960,8 +959,7 @@ public final class MultiUserSettingsPanel extends javax.swing.JPanel {
private static boolean arePropsEqual(Object a, Object b) { private static boolean arePropsEqual(Object a, Object b) {
if (a == null || b == null) { if (a == null || b == null) {
return (a == null && b == null); return (a == null && b == null);
} } else {
else {
return a.equals(b); return a.equals(b);
} }
} }
@ -971,15 +969,13 @@ public final class MultiUserSettingsPanel extends javax.swing.JPanel {
return (a == null && b == null); return (a == null && b == null);
} }
return return arePropsEqual(a.getDbType(), b.getDbType())
arePropsEqual(a.getDbType(), b.getDbType()) && && arePropsEqual(a.getHost(), b.getHost())
arePropsEqual(a.getHost(), b.getHost()) && && arePropsEqual(a.getPassword(), b.getPassword())
arePropsEqual(a.getPassword(), b.getPassword()) && && arePropsEqual(a.getPort(), b.getPort())
arePropsEqual(a.getPort(), b.getPort()) && && arePropsEqual(a.getUserName(), b.getUserName());
arePropsEqual(a.getUserName(), b.getUserName());
} }
/** /**
* Validates that the form is filled out correctly for our usage. * Validates that the form is filled out correctly for our usage.
* *

View File

@ -49,7 +49,7 @@ class Installer extends ModuleInstall {
server.start(); server.start();
} catch (SolrServerNoPortException ex) { } catch (SolrServerNoPortException ex) {
logger.log(Level.SEVERE, "Failed to start Keyword Search server: ", ex); //NON-NLS logger.log(Level.SEVERE, "Failed to start Keyword Search server: ", ex); //NON-NLS
if (ex.getPortNumber() == server.getCurrentSolrServerPort()) { if (ex.getPortNumber() == server.getLocalSolrServerPort()) {
reportPortError(ex.getPortNumber()); reportPortError(ex.getPortNumber());
} else { } else {
reportStopPortError(ex.getPortNumber()); reportStopPortError(ex.getPortNumber());

View File

@ -1,7 +1,7 @@
/* /*
* Autopsy Forensic Browser * Autopsy Forensic Browser
* *
* Copyright 2011-2019 Basis Technology Corp. * Copyright 2011-2020 Basis Technology Corp.
* Contact: carrier <at> sleuthkit <dot> org * Contact: carrier <at> sleuthkit <dot> org
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
@ -73,7 +73,6 @@ import org.apache.solr.common.SolrInputDocument;
import org.apache.solr.common.util.NamedList; 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.Exceptions;
import org.openide.util.NbBundle; import org.openide.util.NbBundle;
import org.openide.windows.WindowManager; import org.openide.windows.WindowManager;
import org.sleuthkit.autopsy.casemodule.Case; import org.sleuthkit.autopsy.casemodule.Case;
@ -84,6 +83,7 @@ import org.sleuthkit.autopsy.coreutils.Logger;
import org.sleuthkit.autopsy.coreutils.MessageNotifyUtil; import org.sleuthkit.autopsy.coreutils.MessageNotifyUtil;
import org.sleuthkit.autopsy.coreutils.ModuleSettings; import org.sleuthkit.autopsy.coreutils.ModuleSettings;
import org.sleuthkit.autopsy.coreutils.PlatformUtil; import org.sleuthkit.autopsy.coreutils.PlatformUtil;
import org.sleuthkit.autopsy.coreutils.ThreadUtils;
import org.sleuthkit.autopsy.healthmonitor.HealthMonitor; import org.sleuthkit.autopsy.healthmonitor.HealthMonitor;
import org.sleuthkit.autopsy.healthmonitor.TimingMetric; import org.sleuthkit.autopsy.healthmonitor.TimingMetric;
import org.sleuthkit.autopsy.keywordsearchservice.KeywordSearchServiceException; import org.sleuthkit.autopsy.keywordsearchservice.KeywordSearchServiceException;
@ -249,8 +249,7 @@ public class Server {
private HttpSolrClient localSolrServer = null; private HttpSolrClient localSolrServer = null;
private SOLR_VERSION localServerVersion = SOLR_VERSION.SOLR8; // start local Solr 8 by default private SOLR_VERSION localServerVersion = SOLR_VERSION.SOLR8; // start local Solr 8 by default
// A reference to the Solr server we are currently connected to for the Case. // A reference to the remote/network running Solr instance.
// This could be a local or remote server.
private HttpSolrClient remoteSolrServer; private HttpSolrClient remoteSolrServer;
private Collection currentCollection; private Collection currentCollection;
@ -385,11 +384,11 @@ public class Server {
serverAction.addPropertyChangeListener(l); serverAction.addPropertyChangeListener(l);
} }
int getCurrentSolrServerPort() { int getLocalSolrServerPort() {
return localSolrServerPort; return localSolrServerPort;
} }
int getCurrentSolrStopPort() { int getLocalSolrStopPort() {
return localSolrStopPort; return localSolrStopPort;
} }
@ -1869,13 +1868,12 @@ public class Server {
private HttpSolrClient queryClient = null; private HttpSolrClient queryClient = null;
private SolrClient indexingClient = null; private SolrClient indexingClient = null;
public final int maxBufferSize; private final int maxBufferSize;
public final List<SolrInputDocument> buffer; private final List<SolrInputDocument> buffer;
private final Object bufferLock; private final Object bufferLock;
private ScheduledThreadPoolExecutor periodicTasksExecutor = null; private ScheduledThreadPoolExecutor periodicTasksExecutor = null;
private static final long PERIODIC_BATCH_SEND_INTERVAL_MINUTES = 10; private static final long PERIODIC_BATCH_SEND_INTERVAL_MINUTES = 10;
private static final long EXECUTOR_TERMINATION_WAIT_SECS = 30;
private Collection(String name, Case theCase, Index index) throws TimeoutException, InterruptedException, SolrServerException, IOException { private Collection(String name, Case theCase, Index index) throws TimeoutException, InterruptedException, SolrServerException, IOException {
this.name = name; this.name = name;
@ -1905,7 +1903,7 @@ public class Server {
logger.log(Level.INFO, "Using Solr document queue size = {0}", maxBufferSize); //NON-NLS logger.log(Level.INFO, "Using Solr document queue size = {0}", maxBufferSize); //NON-NLS
buffer = new ArrayList<>(maxBufferSize); buffer = new ArrayList<>(maxBufferSize);
periodicTasksExecutor = new ScheduledThreadPoolExecutor(1, new ThreadFactoryBuilder().setNameFormat("periodic-batched-document-task-%d").build()); //NON-NLS periodicTasksExecutor = new ScheduledThreadPoolExecutor(1, new ThreadFactoryBuilder().setNameFormat("periodic-batched-document-task-%d").build()); //NON-NLS
periodicTasksExecutor.scheduleWithFixedDelay(new SentBatchedDocumentsTask(), PERIODIC_BATCH_SEND_INTERVAL_MINUTES, PERIODIC_BATCH_SEND_INTERVAL_MINUTES, TimeUnit.MINUTES); periodicTasksExecutor.scheduleWithFixedDelay(new SendBatchedDocumentsTask(), PERIODIC_BATCH_SEND_INTERVAL_MINUTES, PERIODIC_BATCH_SEND_INTERVAL_MINUTES, TimeUnit.MINUTES);
} }
/** /**
@ -1914,7 +1912,7 @@ public class Server {
* if the buffer is not full, we want to periodically send the batched documents * if the buffer is not full, we want to periodically send the batched documents
* so that users are able to see them in their keyword searches. * so that users are able to see them in their keyword searches.
*/ */
private final class SentBatchedDocumentsTask implements Runnable { private final class SendBatchedDocumentsTask implements Runnable {
@Override @Override
public void run() { public void run() {
@ -1933,7 +1931,6 @@ public class Server {
try { try {
// send the cloned list to Solr // send the cloned list to Solr
logger.log(Level.INFO, "Periodic batched document update"); //NON-NLS
sendBufferedDocs(clone); sendBufferedDocs(clone);
} catch (KeywordSearchModuleException ex) { } catch (KeywordSearchModuleException ex) {
logger.log(Level.SEVERE, "Periodic batched document update failed", ex); //NON-NLS logger.log(Level.SEVERE, "Periodic batched document update failed", ex); //NON-NLS
@ -1980,15 +1977,19 @@ public class Server {
private void commit() throws SolrServerException { private void commit() throws SolrServerException {
List<SolrInputDocument> clone;
synchronized (bufferLock) { synchronized (bufferLock) {
// Make a clone and release the lock, so that we don't
// hold other ingest threads
clone = buffer.stream().collect(toList());
buffer.clear();
}
try { try {
// we do a manual commit after ingest is complete, so I sendBufferedDocs(clone);
// think there is no need to clone the buffer
sendBufferedDocs(buffer);
} catch (KeywordSearchModuleException ex) { } catch (KeywordSearchModuleException ex) {
throw new SolrServerException(NbBundle.getMessage(this.getClass(), "Server.commit.exception.msg"), ex); throw new SolrServerException(NbBundle.getMessage(this.getClass(), "Server.commit.exception.msg"), ex);
} }
}
try { try {
//commit and block //commit and block
@ -2107,14 +2108,7 @@ public class Server {
try { try {
// stop the periodic batch update task. If the task is already running, // stop the periodic batch update task. If the task is already running,
// allow it to finish. // allow it to finish.
periodicTasksExecutor.shutdown(); ThreadUtils.shutDownTaskExecutor(periodicTasksExecutor);
try {
while (!periodicTasksExecutor.awaitTermination(EXECUTOR_TERMINATION_WAIT_SECS, TimeUnit.SECONDS)) {
logger.log(Level.WARNING, "Waited at least {0} seconds for periodic KWS task executor to shut down, continuing to wait", EXECUTOR_TERMINATION_WAIT_SECS); //NON-NLS
}
} catch (InterruptedException ex) {
logger.log(Level.SEVERE, "Unexpected interrupt while stopping periodic KWS task executor", ex); //NON-NLS
}
// We only unload cores for "single-user" cases. // We only unload cores for "single-user" cases.
if (this.caseType == CaseType.MULTI_USER_CASE) { if (this.caseType == CaseType.MULTI_USER_CASE) {

View File

@ -150,10 +150,10 @@ public class SolrSearchService implements KeywordSearchService, AutopsyService {
try { try {
KeywordSearch.getServer().connectToSolrServer(host, Integer.toString(port)); KeywordSearch.getServer().connectToSolrServer(host, Integer.toString(port));
} catch (SolrServerException ex) { } catch (SolrServerException ex) {
logger.log(Level.SEVERE, "Uanble to connect to Solr server. Host: " + host + ", port: " + port, ex); logger.log(Level.SEVERE, "Unable to connect to Solr server. Host: " + host + ", port: " + port, ex);
throw new KeywordSearchServiceException(NbBundle.getMessage(SolrSearchService.class, "SolrConnectionCheck.HostnameOrPort")); //NON-NLS*/ throw new KeywordSearchServiceException(NbBundle.getMessage(SolrSearchService.class, "SolrConnectionCheck.HostnameOrPort")); //NON-NLS*/
} catch (IOException ex) { } catch (IOException ex) {
logger.log(Level.SEVERE, "Uanble to connect to Solr server. Host: " + host + ", port: " + port, ex); logger.log(Level.SEVERE, "Unable to connect to Solr server. Host: " + host + ", port: " + port, ex);
String result = NbBundle.getMessage(SolrSearchService.class, "SolrConnectionCheck.HostnameOrPort"); //NON-NLS String result = NbBundle.getMessage(SolrSearchService.class, "SolrConnectionCheck.HostnameOrPort"); //NON-NLS
String message = ex.getCause().getMessage().toLowerCase(); String message = ex.getCause().getMessage().toLowerCase();
if (message.startsWith(SERVER_REFUSED_CONNECTION)) { if (message.startsWith(SERVER_REFUSED_CONNECTION)) {
@ -173,10 +173,10 @@ public class SolrSearchService implements KeywordSearchService, AutopsyService {
} }
throw new KeywordSearchServiceException(result); throw new KeywordSearchServiceException(result);
} catch (NumberFormatException ex) { } catch (NumberFormatException ex) {
logger.log(Level.SEVERE, "Uanble to connect to Solr server. Host: " + host + ", port: " + port, ex); logger.log(Level.SEVERE, "Unable to connect to Solr server. Host: " + host + ", port: " + port, ex);
throw new KeywordSearchServiceException(Bundle.SolrConnectionCheck_Port()); throw new KeywordSearchServiceException(Bundle.SolrConnectionCheck_Port());
} catch (IllegalArgumentException ex) { } catch (IllegalArgumentException ex) {
logger.log(Level.SEVERE, "Uanble to connect to Solr server. Host: " + host + ", port: " + port, ex); logger.log(Level.SEVERE, "Unable to connect to Solr server. Host: " + host + ", port: " + port, ex);
throw new KeywordSearchServiceException(ex.getMessage()); throw new KeywordSearchServiceException(ex.getMessage());
} }
} }