List of usage examples for org.apache.solr.client.solrj.impl HttpSolrClient setRequestWriter
public void setRequestWriter(RequestWriter requestWriter)
From source file:de.qaware.chronix.storage.solr.ChronixSolrCloudStorage.java
License:Apache License
/** * Fetches a stream of time series only from a single node with HttpSolrClient. * * @param shardUrl/*w ww. ja va 2 s.c o m*/ * @param query * @param converter * @return */ private Stream<MetricTimeSeries> streamWithHttpSolrClient(String shardUrl, SolrQuery query, TimeSeriesConverter<MetricTimeSeries> converter) { HttpSolrClient solrClient = getSingleNodeSolrClient(shardUrl); solrClient.setRequestWriter(new BinaryRequestWriter()); query.set("distrib", false); LoggerFactory.getLogger(ChronixSolrCloudStorage.class).debug( "Streaming data from solr using converter {}, Solr Client {}, and Solr Query {}", converter, solrClient, query); SolrStreamingService<MetricTimeSeries> solrStreamingService = new SolrStreamingService<>(converter, query, solrClient, nrOfDocumentPerBatch); return StreamSupport.stream(Spliterators.spliteratorUnknownSize(solrStreamingService, Spliterator.SIZED), false); }
From source file:org.apache.ranger.patch.cliutil.DbToSolrMigrationUtil.java
License:Apache License
private SolrClient createSolrClient() throws Exception { SolrClient solrClient = null;/*www . j a v a 2 s.com*/ registerSolrClientJAAS(); String zkHosts = PropertiesUtil.getProperty(SOLR_ZK_HOSTS); if (zkHosts == null) { zkHosts = PropertiesUtil.getProperty("ranger.audit.solr.zookeeper"); } if (zkHosts == null) { zkHosts = PropertiesUtil.getProperty("ranger.solr.zookeeper"); } String solrURL = PropertiesUtil.getProperty(SOLR_URLS_PROP); if (solrURL == null) { // Try with url solrURL = PropertiesUtil.getProperty("ranger.audit.solr.url"); } if (solrURL == null) { // Let's try older property name solrURL = PropertiesUtil.getProperty("ranger.solr.url"); } if (zkHosts != null && !zkHosts.trim().equals("") && !zkHosts.trim().equalsIgnoreCase("none")) { zkHosts = zkHosts.trim(); String collectionName = PropertiesUtil.getProperty(SOLR_COLLECTION_NAME); if (collectionName == null || collectionName.equalsIgnoreCase("none")) { collectionName = DEFAULT_COLLECTION_NAME; } logger.info("Solr zkHosts=" + zkHosts + ", collectionName=" + collectionName); try { // Instantiate HttpClientUtil.setConfigurer(new Krb5HttpClientConfigurer()); CloudSolrClient solrCloudClient = new CloudSolrClient(zkHosts); solrCloudClient.setDefaultCollection(collectionName); solrClient = solrCloudClient; solrCloudClient.close(); } catch (Exception e) { logger.fatal( "Can't connect to Solr server. ZooKeepers=" + zkHosts + ", collection=" + collectionName, e); throw e; } } else { if (solrURL == null || solrURL.isEmpty() || solrURL.equalsIgnoreCase("none")) { logger.fatal("Solr ZKHosts and URL for Audit are empty. Please set property " + SOLR_ZK_HOSTS + " or " + SOLR_URLS_PROP); } else { try { HttpClientUtil.setConfigurer(new Krb5HttpClientConfigurer()); solrClient = new HttpSolrClient(solrURL); if (solrClient instanceof HttpSolrClient) { HttpSolrClient httpSolrClient = (HttpSolrClient) solrClient; httpSolrClient.setAllowCompression(true); httpSolrClient.setConnectionTimeout(1000); httpSolrClient.setMaxRetries(1); httpSolrClient.setRequestWriter(new BinaryRequestWriter()); } } catch (Exception e) { logger.fatal("Can't connect to Solr server. URL=" + solrURL, e); throw e; } } } return solrClient; }
From source file:org.apache.ranger.solr.SolrMgr.java
License:Apache License
void connect() { if (!initDone) { synchronized (lock) { if (!initDone) { if (rangerBizUtil.getAuditDBType().equalsIgnoreCase("solr")) { String zkHosts = PropertiesUtil.getProperty(SOLR_ZK_HOSTS); if (zkHosts == null) { zkHosts = PropertiesUtil.getProperty("ranger.audit.solr.zookeeper"); }//w ww .j ava 2 s .com if (zkHosts == null) { zkHosts = PropertiesUtil.getProperty("ranger.solr.zookeeper"); } String solrURL = PropertiesUtil.getProperty(SOLR_URLS_PROP); if (solrURL == null) { // Try with url solrURL = PropertiesUtil.getProperty("ranger.audit.solr.url"); } if (solrURL == null) { // Let's try older property name solrURL = PropertiesUtil.getProperty("ranger.solr.url"); } if (zkHosts != null && !zkHosts.trim().equals("") && !zkHosts.trim().equalsIgnoreCase("none")) { zkHosts = zkHosts.trim(); String collectionName = PropertiesUtil.getProperty(SOLR_COLLECTION_NAME); if (collectionName == null || collectionName.equalsIgnoreCase("none")) { collectionName = DEFAULT_COLLECTION_NAME; } logger.info("Solr zkHosts=" + zkHosts + ", collectionName=" + collectionName); try { // Instantiate HttpClientUtil.setConfigurer(new Krb5HttpClientConfigurer()); CloudSolrClient solrCloudClient = new CloudSolrClient(zkHosts); solrCloudClient.setDefaultCollection(collectionName); solrClient = solrCloudClient; } catch (Throwable t) { logger.fatal("Can't connect to Solr server. ZooKeepers=" + zkHosts + ", collection=" + collectionName, t); } } else { if (solrURL == null || solrURL.isEmpty() || solrURL.equalsIgnoreCase("none")) { logger.fatal("Solr ZKHosts and URL for Audit are empty. Please set property " + SOLR_ZK_HOSTS + " or " + SOLR_URLS_PROP); } else { try { HttpClientUtil.setConfigurer(new Krb5HttpClientConfigurer()); solrClient = new HttpSolrClient(solrURL); if (solrClient == null) { logger.fatal("Can't connect to Solr. URL=" + solrURL); } else { if (solrClient instanceof HttpSolrClient) { HttpSolrClient httpSolrClient = (HttpSolrClient) solrClient; httpSolrClient.setAllowCompression(true); httpSolrClient.setConnectionTimeout(1000); // httpSolrClient.setSoTimeout(10000); httpSolrClient.setMaxRetries(1); httpSolrClient.setRequestWriter(new BinaryRequestWriter()); } initDone = true; } } catch (Throwable t) { logger.fatal("Can't connect to Solr server. URL=" + solrURL, t); } } } } } } } }
From source file:org.swissbib.sru.SRUApplication.java
License:Open Source License
private HashMap<String, HttpSolrClient> configureSearchServer(String configurations) { String[] configuration = configurations.split("####"); HashMap<String, HttpSolrClient> configuredSolrServers = new HashMap<String, HttpSolrClient>(); for (String server : configuration) { String[] nameAndURL = server.split("###"); HttpSolrClient searchServer = new HttpSolrClient(nameAndURL[0]); searchServer.setParser(new BinaryResponseParser()); searchServer.setRequestWriter(new BinaryRequestWriter()); configuredSolrServers.put(nameAndURL[1], searchServer); }// ww w . j a v a 2 s . com return configuredSolrServers; }