From 08b76aefe17bf166ab900b97b09d188324e92072 Mon Sep 17 00:00:00 2001 From: Eugene Livis Date: Mon, 20 Jul 2020 10:11:34 -0400 Subject: [PATCH] Code cleanup --- .../autopsy/keywordsearch/Server.java | 41 ++++++++----------- 1 file changed, 16 insertions(+), 25 deletions(-) diff --git a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/Server.java b/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/Server.java index 925be227cd..ec7f906e37 100644 --- a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/Server.java +++ b/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/Server.java @@ -69,6 +69,7 @@ import org.apache.solr.common.SolrInputDocument; import org.apache.solr.common.util.NamedList; import org.openide.modules.InstalledFileLocator; import org.openide.modules.Places; +import org.openide.util.Exceptions; import org.openide.util.NbBundle; import org.openide.windows.WindowManager; import org.sleuthkit.autopsy.casemodule.Case; @@ -345,27 +346,11 @@ public class Server { private CloudSolrClient getCloudSolrClient(List solrUrls, String defaultCollectionName) { CloudSolrClient client; - //client = new CloudSolrClient.Builder() - // .withZkHost("127.0.0.1:9983") - // .build(); - - // Using a ZK Host String - //String zkHostString = "zkServerA:2181,zkServerB:2181,zkServerC:2181/solr"; - //SolrClient solr = new CloudSolrClient.Builder().withZkHost(zkHostString).build(); - - /* ELTODO - Builder builder = new CloudSolrClient.Builder(); - builder.withZkHost( - Arrays.asList(new String[] { "192.168.204.181:2181,192.168.204.182:2181,192.168.204.183:2181" })); - CloudSolrClient client = builder.build();*/ - logger.log(Level.INFO, "Creating new CloudSolrClient"); //NON-NLS client = new CloudSolrClient.Builder(solrUrls).build(); if (!defaultCollectionName.isEmpty()) { client.setDefaultCollection(defaultCollectionName); } - // ELTODO client.setZkClientTimeout(60000); - // ELTODO client.setZkConnectTimeout(60000); client.connect(); return client; } @@ -601,7 +586,7 @@ public class Server { IndexingServerProperties properties = getMultiUserServerProperties(theCase.getCaseDirectory()); List solrServerList = getSolrServerList(properties.getHost(), properties.getPort()); for (String server : solrServerList) { - solrUrls.add("http://" + server + "/solr"); // ELTODO optimize this + solrUrls.add("http://" + server + "/solr"); logger.log(Level.INFO, "Using Solr server: {0}", server); } } else { @@ -1882,7 +1867,7 @@ public class Server { List solrServerList = getSolrServerList(properties.getHost(), properties.getPort()); List solrUrls = new ArrayList<>(); for (String server : solrServerList) { - solrUrls.add("http://" + server + "/solr"); // ELTODO optimize this + solrUrls.add("http://" + server + "/solr"); logger.log(Level.INFO, "Using Solr server: {0}", server); } // get SolrJ client @@ -2004,20 +1989,26 @@ public class Server { } synchronized void close() throws KeywordSearchModuleException { - // We only unload cores for "single-user" cases. - if (this.caseType == CaseType.MULTI_USER_CASE) { - // solrClient.close(); // do we need to do this? - return; - } - try { + // We only unload cores for "single-user" cases. + if (this.caseType == CaseType.MULTI_USER_CASE) { + return; + } + CoreAdminRequest.unloadCore(this.name, localSolrServer); - } catch (SolrServerException | RemoteSolrException ex) { + } catch (SolrServerException | RemoteSolrException ex) { throw new KeywordSearchModuleException( NbBundle.getMessage(this.getClass(), "Server.close.exception.msg"), ex); } catch (IOException ex) { throw new KeywordSearchModuleException( NbBundle.getMessage(this.getClass(), "Server.close.exception.msg2"), ex); + } finally { + try { + solrClient.close(); + } catch (IOException ex) { + throw new KeywordSearchModuleException( + NbBundle.getMessage(this.getClass(), "Server.close.exception.msg2"), ex); + } } }