changes based on reviewer comments

addressed comments from reviewer.
This commit is contained in:
Mark McKinnon 2019-10-10 10:03:36 -04:00
parent d128e7a902
commit 86c45f3e49
4 changed files with 73 additions and 66 deletions

View File

@ -47,7 +47,8 @@ public final class DeleteDataSourceAction extends AbstractAction {
public void actionPerformed(ActionEvent event) { public void actionPerformed(ActionEvent event) {
try { try {
Case.getCurrentCaseThrows().getSleuthkitCase().deleteDataSource(dataSourceId); Case.getCurrentCaseThrows().getSleuthkitCase().deleteDataSource(dataSourceId);
} catch (NoCurrentCaseException | TskCoreException e) { deleteDataSource(dataSourceId);
} catch (NoCurrentCaseException | TskCoreException | KeywordSearchServiceException e) {
logger.log(Level.WARNING, "Error Deleting Data source " + dataSourceId, e); logger.log(Level.WARNING, "Error Deleting Data source " + dataSourceId, e);
} }
} }

View File

@ -243,6 +243,7 @@ Server.request.exception.exception.msg=Could not issue Solr request
Server.commit.exception.msg=Could not commit index Server.commit.exception.msg=Could not commit index
Server.addDoc.exception.msg=Could not add document to index via update handler: {0} Server.addDoc.exception.msg=Could not add document to index via update handler: {0}
Server.addDoc.exception.msg2=Could not add document to index via update handler: {0} Server.addDoc.exception.msg2=Could not add document to index via update handler: {0}
Server.delDoc.exception.msg=Error deleting content from Solr. Solr image id : {0}
Server.close.exception.msg=Cannot close Core Server.close.exception.msg=Cannot close Core
Server.close.exception.msg2=Cannot close Core Server.close.exception.msg2=Cannot close Core
Server.solrServerNoPortException.msg=Indexing server could not bind to port {0}, port is not available, consider change the default {1} port. Server.solrServerNoPortException.msg=Indexing server could not bind to port {0}, port is not available, consider change the default {1} port.

View File

@ -190,9 +190,9 @@ public class Server {
} }
}, },
/** /**
* termfreq is a function which returns the number of times the term appears. * termfreq is a function which returns the number of times the term
* This is not an actual field defined in schema.xml, but can be gotten from returned documents * appears. This is not an actual field defined in schema.xml, but can
* in the same way as fields. * be gotten from returned documents in the same way as fields.
*/ */
TERMFREQ { TERMFREQ {
@Override @Override
@ -893,26 +893,28 @@ public class Server {
} }
/** /**
* Get the host and port for a multiuser case. * Get the host and port for a multiuser case. If the file solrserver.txt
* If the file solrserver.txt exists, then use the values from that file. * exists, then use the values from that file. Otherwise use the settings
* Otherwise use the settings from the properties file. * from the properties file.
* *
* @param caseDirectory Current case directory * @param caseDirectory Current case directory
* @return IndexingServerProperties containing the solr host/port for this case *
* @return IndexingServerProperties containing the solr host/port for this
* case
*/ */
public static IndexingServerProperties getMultiUserServerProperties(String caseDirectory) { public static IndexingServerProperties getMultiUserServerProperties(String caseDirectory) {
Path serverFilePath = Paths.get(caseDirectory, "solrserver.txt"); Path serverFilePath = Paths.get(caseDirectory, "solrserver.txt");
if(serverFilePath.toFile().exists()){ if (serverFilePath.toFile().exists()) {
try{ try {
List<String> lines = Files.readAllLines(serverFilePath); List<String> lines = Files.readAllLines(serverFilePath);
if(lines.isEmpty()) { if (lines.isEmpty()) {
logger.log(Level.SEVERE, "solrserver.txt file does not contain any data"); logger.log(Level.SEVERE, "solrserver.txt file does not contain any data");
} else if (! lines.get(0).contains(",")) { } else if (!lines.get(0).contains(",")) {
logger.log(Level.SEVERE, "solrserver.txt file is corrupt - could not read host/port from " + lines.get(0)); logger.log(Level.SEVERE, "solrserver.txt file is corrupt - could not read host/port from " + lines.get(0));
} else { } else {
String[] parts = lines.get(0).split(","); String[] parts = lines.get(0).split(",");
if(parts.length != 2) { if (parts.length != 2) {
logger.log(Level.SEVERE, "solrserver.txt file is corrupt - could not read host/port from " + lines.get(0)); logger.log(Level.SEVERE, "solrserver.txt file is corrupt - could not read host/port from " + lines.get(0));
} else { } else {
return new IndexingServerProperties(parts[0], parts[1]); return new IndexingServerProperties(parts[0], parts[1]);
@ -930,55 +932,54 @@ public class Server {
} }
/** /**
* Pick a solr server to use for this case and record it in the case directory. * Pick a solr server to use for this case and record it in the case
* Looks for a file named "solrServerList.txt" in the root output directory - * directory. Looks for a file named "solrServerList.txt" in the root output
* if this does not exist then no server is recorded. * directory - if this does not exist then no server is recorded.
* *
* Format of solrServerList.txt: * Format of solrServerList.txt: (host),(port) Ex: 10.1.2.34,8983
* (host),(port)
* Ex: 10.1.2.34,8983
* *
* @param rootOutputDirectory * @param rootOutputDirectory
* @param caseDirectoryPath * @param caseDirectoryPath
*
* @throws KeywordSearchModuleException * @throws KeywordSearchModuleException
*/ */
public static void selectSolrServerForCase(Path rootOutputDirectory, Path caseDirectoryPath) throws KeywordSearchModuleException { public static void selectSolrServerForCase(Path rootOutputDirectory, Path caseDirectoryPath) throws KeywordSearchModuleException {
// Look for the solr server list file // Look for the solr server list file
String serverListName = "solrServerList.txt"; String serverListName = "solrServerList.txt";
Path serverListPath = Paths.get(rootOutputDirectory.toString(), serverListName); Path serverListPath = Paths.get(rootOutputDirectory.toString(), serverListName);
if(serverListPath.toFile().exists()){ if (serverListPath.toFile().exists()) {
// Read the list of solr servers // Read the list of solr servers
List<String> lines; List<String> lines;
try{ try {
lines = Files.readAllLines(serverListPath); lines = Files.readAllLines(serverListPath);
} catch (IOException ex){ } catch (IOException ex) {
throw new KeywordSearchModuleException(serverListName + " could not be read", ex); throw new KeywordSearchModuleException(serverListName + " could not be read", ex);
} }
// Remove any lines that don't contain a comma (these are likely just whitespace) // Remove any lines that don't contain a comma (these are likely just whitespace)
for (Iterator<String> iterator = lines.iterator(); iterator.hasNext();) { for (Iterator<String> iterator = lines.iterator(); iterator.hasNext();) {
String line = iterator.next(); String line = iterator.next();
if (! line.contains(",")) { if (!line.contains(",")) {
// Remove the current element from the iterator and the list. // Remove the current element from the iterator and the list.
iterator.remove(); iterator.remove();
} }
} }
if(lines.isEmpty()) { if (lines.isEmpty()) {
throw new KeywordSearchModuleException(serverListName + " had no valid server information"); throw new KeywordSearchModuleException(serverListName + " had no valid server information");
} }
// Choose which server to use // Choose which server to use
int rnd = new Random().nextInt(lines.size()); int rnd = new Random().nextInt(lines.size());
String[] parts = lines.get(rnd).split(","); String[] parts = lines.get(rnd).split(",");
if(parts.length != 2) { if (parts.length != 2) {
throw new KeywordSearchModuleException("Invalid server data: " + lines.get(rnd)); throw new KeywordSearchModuleException("Invalid server data: " + lines.get(rnd));
} }
// Split it up just to do a sanity check on the data // Split it up just to do a sanity check on the data
String host = parts[0]; String host = parts[0];
String port = parts[1]; String port = parts[1];
if(host.isEmpty() || port.isEmpty()) { if (host.isEmpty() || port.isEmpty()) {
throw new KeywordSearchModuleException("Invalid server data: " + lines.get(rnd)); throw new KeywordSearchModuleException("Invalid server data: " + lines.get(rnd));
} }
@ -986,11 +987,11 @@ public class Server {
Path serverFile = Paths.get(caseDirectoryPath.toString(), "solrserver.txt"); Path serverFile = Paths.get(caseDirectoryPath.toString(), "solrserver.txt");
try { try {
caseDirectoryPath.toFile().mkdirs(); caseDirectoryPath.toFile().mkdirs();
if (! caseDirectoryPath.toFile().exists()) { if (!caseDirectoryPath.toFile().exists()) {
throw new KeywordSearchModuleException("Case directory " + caseDirectoryPath.toString() + " does not exist"); throw new KeywordSearchModuleException("Case directory " + caseDirectoryPath.toString() + " does not exist");
} }
Files.write(serverFile, lines.get(rnd).getBytes()); Files.write(serverFile, lines.get(rnd).getBytes());
} catch (IOException ex){ } catch (IOException ex) {
throw new KeywordSearchModuleException(serverFile.toString() + " could not be written", ex); throw new KeywordSearchModuleException(serverFile.toString() + " could not be written", ex);
} }
} }
@ -1000,16 +1001,18 @@ public class Server {
* Helper class to store the current server properties * Helper class to store the current server properties
*/ */
public static class IndexingServerProperties { public static class IndexingServerProperties {
private final String host; private final String host;
private final String port; private final String port;
IndexingServerProperties (String host, String port) { IndexingServerProperties(String host, String port) {
this.host = host; this.host = host;
this.port = port; this.port = port;
} }
/** /**
* Get the host * Get the host
*
* @return host * @return host
*/ */
public String getHost() { public String getHost() {
@ -1018,6 +1021,7 @@ public class Server {
/** /**
* Get the port * Get the port
*
* @return port * @return port
*/ */
public String getPort() { public String getPort() {
@ -1273,7 +1277,7 @@ public class Server {
* *
* @throws NoOpenCoreException * @throws NoOpenCoreException
*/ */
public void deleteDataSource(Long dataSourceId) throws NoOpenCoreException { public void deleteDataSource(Long dataSourceId) throws KeywordSearchModuleException, NoOpenCoreException {
currentCoreLock.writeLock().lock(); currentCoreLock.writeLock().lock();
try { try {
if (null == currentCore) { if (null == currentCore) {
@ -1281,8 +1285,9 @@ public class Server {
} }
currentCore.deleteDataSource(dataSourceId); currentCore.deleteDataSource(dataSourceId);
currentCore.commit(); currentCore.commit();
} catch (SolrServerException ex) { } catch (SolrServerException | KeywordSearchModuleException ex) {
logger.log(Level.SEVERE, "Solr delete data dource failed for data source: " + dataSourceId, ex); //NON-NLS throw new KeywordSearchModuleException(
NbBundle.getMessage(this.getClass(), "Server.delDoc.exception.msg", dataSourceId), ex);
} finally { } finally {
currentCoreLock.writeLock().unlock(); currentCoreLock.writeLock().unlock();
} }
@ -1400,8 +1405,8 @@ public class Server {
void connectToSolrServer(HttpSolrServer solrServer) throws SolrServerException, IOException { void connectToSolrServer(HttpSolrServer solrServer) throws SolrServerException, IOException {
TimingMetric metric = HealthMonitor.getTimingMetric("Solr: Connectivity check"); TimingMetric metric = HealthMonitor.getTimingMetric("Solr: Connectivity check");
CoreAdminRequest statusRequest = new CoreAdminRequest(); CoreAdminRequest statusRequest = new CoreAdminRequest();
statusRequest.setCoreName( null ); statusRequest.setCoreName(null);
statusRequest.setAction( CoreAdminParams.CoreAdminAction.STATUS ); statusRequest.setAction(CoreAdminParams.CoreAdminAction.STATUS);
statusRequest.setIndexInfoNeeded(false); statusRequest.setIndexInfoNeeded(false);
statusRequest.process(solrServer); statusRequest.process(solrServer);
HealthMonitor.submitTimingMetric(metric); HealthMonitor.submitTimingMetric(metric);
@ -1529,14 +1534,15 @@ public class Server {
} }
} }
private void deleteDataSource(Long dsObjId) { private void deleteDataSource(Long dsObjId) throws KeywordSearchModuleException {
String dataSourceId = Long.toString(dsObjId); String dataSourceId = Long.toString(dsObjId);
String deleteQuery = "image_id:" + dataSourceId; String deleteQuery = "image_id:" + dataSourceId;
try { try {
// Get the first result. // Get the first result.
UpdateResponse updateResponse = solrCore.deleteByQuery(deleteQuery); UpdateResponse updateResponse = solrCore.deleteByQuery(deleteQuery);
} catch (SolrServerException | IOException ex) { } catch (SolrServerException | IOException ex) {
logger.log(Level.SEVERE, "Error deleting content from Solr. Solr image id " + dataSourceId, ex); //NON-NLS throw new KeywordSearchModuleException(
NbBundle.getMessage(this.getClass(), "Server.delDoc.exception.msg", dataSourceId), ex); //NON-NLS
} }
} }
@ -1561,7 +1567,8 @@ public class Server {
* @param chunkID Chunk ID of the Solr document * @param chunkID Chunk ID of the Solr document
* *
* @return Text from matching Solr document (as String). Null if no * @return Text from matching Solr document (as String). Null if no
* matching Solr document found or error while getting content from Solr * matching Solr document found or error while getting content
* from Solr
*/ */
private String getSolrContent(long contentID, int chunkID) { private String getSolrContent(long contentID, int chunkID) {
final SolrQuery q = new SolrQuery(); final SolrQuery q = new SolrQuery();

View File

@ -208,9 +208,7 @@ public class SolrSearchService implements KeywordSearchService, AutopsyService {
public void deleteDataSource(Long dataSourceId) throws KeywordSearchServiceException { public void deleteDataSource(Long dataSourceId) throws KeywordSearchServiceException {
try { try {
KeywordSearch.getServer().deleteDataSource(dataSourceId); KeywordSearch.getServer().deleteDataSource(dataSourceId);
} catch (NoOpenCoreException ex) { } catch (NoOpenCoreException | KeywordSearchModuleException ex) {
logger.log(Level.WARNING, NbBundle.getMessage(SolrSearchService.class,
"SolrSearchService.deleteDataSource.exceptionMessage.noCurrentSolrCore"));
throw new KeywordSearchServiceException(NbBundle.getMessage(SolrSearchService.class, throw new KeywordSearchServiceException(NbBundle.getMessage(SolrSearchService.class,
"SolrSearchService.deleteDataSource.exceptionMessage.noCurrentSolrCore")); "SolrSearchService.deleteDataSource.exceptionMessage.noCurrentSolrCore"));
} }