List of usage examples for org.apache.solr.client.solrj.impl CloudSolrClient setZkClientTimeout
public void setZkClientTimeout(int zkClientTimeout)
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 ww w.java 2s. co 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:com.frank.search.solr.server.support.HttpSolrClientFactoryBean.java
License:Apache License
private void createCloudClient() { ModifiableSolrParams params = new ModifiableSolrParams(); params.set(HttpClientUtil.PROP_MAX_CONNECTIONS, maxConnections);// 1000 params.set(HttpClientUtil.PROP_MAX_CONNECTIONS_PER_HOST, maxConnectionsPerHost);// 5000 params.set(HttpClientUtil.PROP_CONNECTION_TIMEOUT, timeout); params.set(HttpClientUtil.PROP_SO_TIMEOUT, timeout); HttpClient client = HttpClientUtil.createClient(params); LBHttpSolrClient lbHttpSolrClient = new LBHttpSolrClient(client); CloudSolrClient cloudSolrClient = new CloudSolrClient(url, lbHttpSolrClient); if (zkClientTimeout != null) { cloudSolrClient.setZkClientTimeout(zkClientTimeout.intValue()); }/* w w w . j av a 2 s . c o m*/ if (zkConnectTimeout != null) { cloudSolrClient.setZkConnectTimeout(zkConnectTimeout.intValue()); } if (StringUtils.isNoneBlank(collection)) { cloudSolrClient.setDefaultCollection(collection); } cloudSolrClient.connect(); this.setSolrClient(cloudSolrClient); }
From source file:com.hurence.logisland.service.solr.Solr_5_5_5_ClientService.java
License:Apache License
protected SolrClient createCloudClient(String connectionString, String collection) { CloudSolrClient cloudSolrClient = new CloudSolrClient(connectionString); cloudSolrClient.setDefaultCollection(collection); cloudSolrClient.setZkClientTimeout(30000); cloudSolrClient.setZkConnectTimeout(30000); return cloudSolrClient; }
From source file:com.hurence.logisland.service.solr.Solr_6_4_2_ChronixClientService.java
License:Apache License
/** * Instantiate Chronix Client. This should be called by subclasses' @OnScheduled method to create a client * if one does not yet exist. If called when scheduled, closeClient() should be called by the subclasses' @OnStopped * method so the client will be destroyed when the processor is stopped. * * @param context The context for this processor * @throws ProcessException if an error occurs while creating an Chronix client *//*from ww w . j a v a2 s . c o m*/ protected void createSolrClient(ControllerServiceInitializationContext context) throws ProcessException { if (solr != null) { return; } // create a solr client final boolean isCloud = context.getPropertyValue(SOLR_CLOUD).asBoolean(); final String connectionString = context.getPropertyValue(SOLR_CONNECTION_STRING).asString(); final String collection = context.getPropertyValue(SOLR_COLLECTION).asString(); if (isCloud) { //logInfo("creating solrCloudClient on $solrUrl for collection $collection"); CloudSolrClient cloudSolrClient = new CloudSolrClient.Builder().withZkHost(connectionString).build(); cloudSolrClient.setDefaultCollection(collection); cloudSolrClient.setZkClientTimeout(30000); cloudSolrClient.setZkConnectTimeout(30000); solr = cloudSolrClient; } else { // logInfo(s"creating HttpSolrClient on $solrUrl for collection $collection") solr = new HttpSolrClient.Builder(connectionString + "/" + collection).build(); } }
From source file:com.hurence.logisland.service.solr.Solr_6_6_2_ClientService.java
License:Apache License
@Override protected SolrClient createCloudClient(String connectionString, String collection) { CloudSolrClient cloudSolrClient = new CloudSolrClient.Builder().withZkHost(connectionString).build(); cloudSolrClient.setDefaultCollection(collection); cloudSolrClient.setZkClientTimeout(30000); cloudSolrClient.setZkConnectTimeout(30000); return cloudSolrClient; }
From source file:com.ngdata.hbaseindexer.indexer.SolrClientFactory.java
License:Apache License
public static SolrClient createCloudSolrClient(Map<String, String> connectionParameters, int zkSessionTimeout) { String solrZk = connectionParameters.get(SolrConnectionParams.ZOOKEEPER); CloudSolrClient solr = new CloudSolrClient.Builder().withZkHost(solrZk).build(); solr.setZkClientTimeout(zkSessionTimeout); solr.setZkConnectTimeout(zkSessionTimeout); String collection = connectionParameters.get(SolrConnectionParams.COLLECTION); solr.setDefaultCollection(collection); return solr;/*from w w w . j av a 2s .c o m*/ }
From source file:org.apache.nifi.processors.solr.SolrUtils.java
License:Apache License
public static SolrClient createSolrClient(final PropertyContext context, final String solrLocation) { final Integer socketTimeout = context.getProperty(SOLR_SOCKET_TIMEOUT).asTimePeriod(TimeUnit.MILLISECONDS) .intValue();/*from ww w. ja v a2 s . c o m*/ final Integer connectionTimeout = context.getProperty(SOLR_CONNECTION_TIMEOUT) .asTimePeriod(TimeUnit.MILLISECONDS).intValue(); final Integer maxConnections = context.getProperty(SOLR_MAX_CONNECTIONS).asInteger(); final Integer maxConnectionsPerHost = context.getProperty(SOLR_MAX_CONNECTIONS_PER_HOST).asInteger(); final SSLContextService sslContextService = context.getProperty(SSL_CONTEXT_SERVICE) .asControllerService(SSLContextService.class); final String jaasClientAppName = context.getProperty(JAAS_CLIENT_APP_NAME).getValue(); final ModifiableSolrParams params = new ModifiableSolrParams(); params.set(HttpClientUtil.PROP_SO_TIMEOUT, socketTimeout); params.set(HttpClientUtil.PROP_CONNECTION_TIMEOUT, connectionTimeout); params.set(HttpClientUtil.PROP_MAX_CONNECTIONS, maxConnections); params.set(HttpClientUtil.PROP_MAX_CONNECTIONS_PER_HOST, maxConnectionsPerHost); // has to happen before the client is created below so that correct configurer would be set if neeeded if (!StringUtils.isEmpty(jaasClientAppName)) { System.setProperty("solr.kerberos.jaas.appname", jaasClientAppName); HttpClientUtil.setConfigurer(new Krb5HttpClientConfigurer()); } final HttpClient httpClient = HttpClientUtil.createClient(params); if (sslContextService != null) { final SSLContext sslContext = sslContextService.createSSLContext(SSLContextService.ClientAuth.REQUIRED); final SSLSocketFactory sslSocketFactory = new SSLSocketFactory(sslContext); final Scheme httpsScheme = new Scheme("https", 443, sslSocketFactory); httpClient.getConnectionManager().getSchemeRegistry().register(httpsScheme); } if (SOLR_TYPE_STANDARD.equals(context.getProperty(SOLR_TYPE).getValue())) { return new HttpSolrClient(solrLocation, httpClient); } else { final String collection = context.getProperty(COLLECTION).evaluateAttributeExpressions().getValue(); final Integer zkClientTimeout = context.getProperty(ZK_CLIENT_TIMEOUT) .asTimePeriod(TimeUnit.MILLISECONDS).intValue(); final Integer zkConnectionTimeout = context.getProperty(ZK_CONNECTION_TIMEOUT) .asTimePeriod(TimeUnit.MILLISECONDS).intValue(); CloudSolrClient cloudSolrClient = new CloudSolrClient(solrLocation, httpClient); cloudSolrClient.setDefaultCollection(collection); cloudSolrClient.setZkClientTimeout(zkClientTimeout); cloudSolrClient.setZkConnectTimeout(zkConnectionTimeout); return cloudSolrClient; } }
From source file:org.seedstack.solr.internal.SolrPlugin.java
License:Mozilla Public License
private CloudSolrClient buildCloudSolrClient(Configuration solrClientConfiguration, String[] zooKeeperUrls) throws MalformedURLException { String[] lbUrls = solrClientConfiguration.getStringArray(SolrConfigurationConstants.LB_URLS); CloudSolrClient cloudSolrClient; if (lbUrls != null && lbUrls.length > 0) { cloudSolrClient = new CloudSolrClient(zooKeeperUrls[0], new LBHttpSolrClient(lbUrls), solrClientConfiguration.getBoolean(SolrConfigurationConstants.UPDATE_TO_LEADERS, true)); } else {//w w w . j a v a 2 s .co m cloudSolrClient = new CloudSolrClient(Lists.newArrayList(zooKeeperUrls), solrClientConfiguration.getString(SolrConfigurationConstants.CHROOT)); } String defaultCollection = solrClientConfiguration.getString(SolrConfigurationConstants.DEFAULT_COLLECTION); if (defaultCollection != null && !defaultCollection.isEmpty()) { cloudSolrClient.setDefaultCollection(defaultCollection); } String idField = solrClientConfiguration.getString(SolrConfigurationConstants.ID_FIELD); if (idField != null && !idField.isEmpty()) { cloudSolrClient.setIdField(idField); } if (solrClientConfiguration.containsKey(SolrConfigurationConstants.COLLECTION_CACHE_TTL)) { cloudSolrClient.setCollectionCacheTTl( solrClientConfiguration.getInt(SolrConfigurationConstants.COLLECTION_CACHE_TTL)); } if (solrClientConfiguration.containsKey(SolrConfigurationConstants.PARALLEL_CACHE_REFRESHES)) { cloudSolrClient.setParallelCacheRefreshes( solrClientConfiguration.getInt(SolrConfigurationConstants.PARALLEL_CACHE_REFRESHES)); } if (solrClientConfiguration.containsKey(SolrConfigurationConstants.PARALLEL_UPDATES)) { cloudSolrClient.setParallelUpdates( solrClientConfiguration.getBoolean(SolrConfigurationConstants.PARALLEL_UPDATES)); } if (solrClientConfiguration.containsKey(SolrConfigurationConstants.ZK_CLIENT_TIMEOUT)) { cloudSolrClient.setZkClientTimeout( solrClientConfiguration.getInt(SolrConfigurationConstants.ZK_CLIENT_TIMEOUT)); } if (solrClientConfiguration.containsKey(SolrConfigurationConstants.ZK_CONNECT_TIMEOUT)) { cloudSolrClient.setZkConnectTimeout( solrClientConfiguration.getInt(SolrConfigurationConstants.ZK_CONNECT_TIMEOUT)); } return cloudSolrClient; }