List of usage examples for org.apache.solr.client.solrj.impl CloudSolrClient request
public final NamedList<Object> request(final SolrRequest request) throws SolrServerException, IOException
From source file:com.francelabs.datafari.service.search.SolrServers.java
License:Apache License
public static SolrClient getSolrServer(Core core) throws Exception { // Zookeeper Hosts String solrHosts = ScriptConfiguration.getProperty("SOLRHOSTS"); if (!solrClients.containsKey(core)) { try {//from w w w. j av a2s . c o m // TODO : change for ZK ensemble CloudSolrClient solrClient = new CloudSolrClient(solrHosts); solrClient.setDefaultCollection(core.toString()); solrClient.setZkClientTimeout(60000); SolrPing ping = new SolrPing(); solrClient.request(ping); solrClients.put(core, solrClient); } catch (Exception e) { // test default param try { CloudSolrClient solrClient = new CloudSolrClient(defaultURL); solrClient.setDefaultCollection(core.toString()); SolrPing ping = new SolrPing(); solrClient.request(ping); solrClients.put(core, solrClient); } catch (Exception e2) { LOGGER.error("Cannot instanciate Solr Client for core : " + core.toString(), e); throw new Exception("Cannot instanciate Solr Client for core : " + core.toString()); } } } return solrClients.get(core); }
From source file:org.apache.coheigea.bigdata.solr.ranger.RangerSolrCloudTest.java
License:Apache License
private void performQuery(String user, String group, boolean exceptionExpected) throws Exception { final CloudSolrClient cloudSolrClient = server.getSolrClient(); cloudSolrClient.setDefaultCollection("docs"); ModifiableSolrParams params = new ModifiableSolrParams(); params.set("q", "*"); final QueryRequest queryRequest = new QueryRequest(params); queryRequest.setBasicAuthCredentials(user, "SolrRocks"); try {/*w ww . j a va 2 s .c o m*/ if (group != null) { UserGroupInformation ugi = UserGroupInformation.createUserForTesting(user, new String[] { group }); ugi.doAs(new PrivilegedExceptionAction<Void>() { public Void run() throws Exception { cloudSolrClient.request(queryRequest); return null; } }); } else { cloudSolrClient.request(queryRequest); } } catch (Exception ex) { if (!exceptionExpected) { throw ex; } return; } Assert.assertFalse(exceptionExpected); }