Testing Solr clients

This commit is contained in:
Eugene Livis 2020-07-23 15:46:03 -04:00
parent e2e5cc1efb
commit 54b6733721

View File

@ -57,7 +57,7 @@ import org.apache.solr.client.solrj.response.CollectionAdminResponse;
import org.apache.solr.client.solrj.request.CoreAdminRequest; import org.apache.solr.client.solrj.request.CoreAdminRequest;
import org.apache.solr.client.solrj.response.CoreAdminResponse; import org.apache.solr.client.solrj.response.CoreAdminResponse;
import java.util.concurrent.TimeoutException; import java.util.concurrent.TimeoutException;
import org.apache.solr.client.solrj.SolrClient; import org.apache.solr.client.solrj.impl.HttpSolrClient;
import org.apache.solr.client.solrj.impl.BaseHttpSolrClient.RemoteSolrException; import org.apache.solr.client.solrj.impl.BaseHttpSolrClient.RemoteSolrException;
import org.apache.solr.client.solrj.impl.CloudSolrClient; import org.apache.solr.client.solrj.impl.CloudSolrClient;
import org.apache.solr.client.solrj.response.QueryResponse; import org.apache.solr.client.solrj.response.QueryResponse;
@ -69,7 +69,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;
@ -328,6 +327,15 @@ public class Server {
} }
} }
private HttpSolrClient getSolrClient(String solrUrl) {
HttpSolrClient client = new HttpSolrClient.Builder(solrUrl)
.withConnectionTimeout(10000)
.withResponseParser(new XMLResponseParser())
.build();
return client;
}
private ConcurrentUpdateSolrClient getLocalSolrClient(String solrUrl) { private ConcurrentUpdateSolrClient getLocalSolrClient(String solrUrl) {
int numThreads = org.sleuthkit.autopsy.keywordsearch.UserPreferences.getNumThreads(); int numThreads = org.sleuthkit.autopsy.keywordsearch.UserPreferences.getNumThreads();
int numDocs = org.sleuthkit.autopsy.keywordsearch.UserPreferences.getDocumentsQueueSize(); int numDocs = org.sleuthkit.autopsy.keywordsearch.UserPreferences.getDocumentsQueueSize();
@ -1850,7 +1858,7 @@ public class Server {
// the server to access a collection needs to be built from a URL with the // the server to access a collection needs to be built from a URL with the
// collection in it, and is only good for collection-specific operations // collection in it, and is only good for collection-specific operations
private final SolrClient solrClient; private final HttpSolrClient solrClient;
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;
@ -1860,18 +1868,20 @@ public class Server {
if (caseType == CaseType.SINGLE_USER_CASE) { if (caseType == CaseType.SINGLE_USER_CASE) {
// get SolrJ client // get SolrJ client
solrClient = getLocalSolrClient("http://localhost:" + currentSolrServerPort + "/solr/" + name); // ELTODO solrClient = getLocalSolrClient("http://localhost:" + currentSolrServerPort + "/solr/" + name);
solrClient = getSolrClient("http://localhost:" + currentSolrServerPort + "/solr/" + name);
} else { } else {
// read Solr conenction info from user preferences, unless "solrserver.txt" is present // read Solr conenction info from user preferences, unless "solrserver.txt" is present
IndexingServerProperties properties = getMultiUserServerProperties(theCase.getCaseDirectory()); IndexingServerProperties properties = getMultiUserServerProperties(theCase.getCaseDirectory());
List<String> solrServerList = getSolrServerList(properties.getHost(), properties.getPort()); solrClient = getSolrClient("http://" + properties.host + ":" + properties.port + "/solr/" + name);
/*List<String> solrServerList = getSolrServerList(properties.getHost(), properties.getPort());
List<String> solrUrls = new ArrayList<>(); List<String> solrUrls = new ArrayList<>();
for (String server : solrServerList) { for (String server : solrServerList) {
solrUrls.add("http://" + server + "/solr"); solrUrls.add("http://" + server + "/solr");
logger.log(Level.INFO, "Using Solr server: {0}", server); logger.log(Level.INFO, "Using Solr server: {0}", server);
} }
// get SolrJ client // get SolrJ client
solrClient = getCloudSolrClient(solrUrls, name); solrClient = getCloudSolrClient(solrUrls, name);*/
} }
} }