public SolrIndex(final Configuration config) throws BackendException { Preconditions.checkArgument(config!=null); configuration = config; mode = Mode.parse(config.get(SOLR_MODE)); dynFields = config.get(DYNAMIC_FIELDS); keyFieldIds = parseKeyFieldsForCollections(config); maxResults = config.get(INDEX_MAX_RESULT_SET_SIZE); ttlField = config.get(TTL_FIELD); waitSearcher = config.get(WAIT_SEARCHER); if (mode==Mode.CLOUD) { String zookeeperUrl = config.get(SolrIndex.ZOOKEEPER_URL); CloudSolrClient cloudServer = new CloudSolrClient(zookeeperUrl, true); cloudServer.connect(); solrClient = cloudServer; } else if (mode==Mode.HTTP) { HttpClient clientParams = HttpClientUtil.createClient(new ModifiableSolrParams() {{ add(HttpClientUtil.PROP_ALLOW_COMPRESSION, config.get(HTTP_ALLOW_COMPRESSION).toString()); add(HttpClientUtil.PROP_CONNECTION_TIMEOUT, config.get(HTTP_CONNECTION_TIMEOUT).toString()); add(HttpClientUtil.PROP_MAX_CONNECTIONS_PER_HOST, config.get(HTTP_MAX_CONNECTIONS_PER_HOST).toString()); add(HttpClientUtil.PROP_MAX_CONNECTIONS, config.get(HTTP_GLOBAL_MAX_CONNECTIONS).toString()); }}); solrClient = new LBHttpSolrClient(clientParams, config.get(HTTP_URLS)); } else { throw new IllegalArgumentException("Unsupported Solr operation mode: " + mode); } }
final HttpClient httpClient = HttpClientUtil.createClient(params);
public MetronSolrClient(String zkHost, Map<String, Object> solrHttpConfig) { super(zkHost, HttpClientUtil.createClient(toSolrProps(solrHttpConfig))); }
/** * Creates new http client by using the provided configuration. * */ public static CloseableHttpClient createClient(final SolrParams params, PoolingHttpClientConnectionManager cm, boolean sharedConnectionManager) { return createClient(params, cm, sharedConnectionManager, null); }
/** * Factory method that returns a {@link HttpClient} instance used for interfacing with a source Solr service. * One can override this method to return a differently configured {@link HttpClient} instance. * For example configure https and http authentication. * * @return a {@link HttpClient} instance used for interfacing with a source Solr service */ protected HttpClient getHttpClient() { return HttpClientUtil.createClient(null); }
/** * Creates new http client by using the provided configuration. * * @param params * http client configuration, if null a client with default * configuration (no additional configuration) is created. */ public static CloseableHttpClient createClient(SolrParams params) { return createClient(params, createPoolingConnectionManager()); }
public static CloseableHttpClient createClient(SolrParams params, PoolingHttpClientConnectionManager cm) { if (params == null) { params = new ModifiableSolrParams(); } return createClient(params, cm, false); }
protected HttpSolrClient(Builder builder) { this.baseUrl = builder.baseSolrUrl; if (baseUrl.endsWith("/")) { baseUrl = baseUrl.substring(0, baseUrl.length() - 1); } if (baseUrl.indexOf('?') >= 0) { throw new RuntimeException( "Invalid base url for solrj. The base URL must not contain parameters: " + baseUrl); } if (builder.httpClient != null) { this.httpClient = builder.httpClient; this.internalClient = false; } else { this.internalClient = true; ModifiableSolrParams params = new ModifiableSolrParams(); params.set(HttpClientUtil.PROP_FOLLOW_REDIRECTS, followRedirects); params.set(HttpClientUtil.PROP_ALLOW_COMPRESSION, builder.compression); httpClient = HttpClientUtil.createClient(params); } this.parser = builder.responseParser; this.invariantParams = builder.invariantParams; this.connectionTimeout = builder.connectionTimeoutMillis; this.soTimeout = builder.socketTimeoutMillis; }
private HttpClient constructClient(String[] solrServerUrl) { ModifiableSolrParams params = new ModifiableSolrParams(); if (solrServerUrl != null && solrServerUrl.length > 1) { // we prefer retrying another server params.set(HttpClientUtil.PROP_USE_RETRY, false); } else { params.set(HttpClientUtil.PROP_USE_RETRY, true); } return HttpClientUtil.createClient(params); }
public HttpSolrClient(String baseURL, HttpClient client, ResponseParser parser) { this.baseUrl = baseURL; if (baseUrl.endsWith("/")) { baseUrl = baseUrl.substring(0, baseUrl.length() - 1); } if (baseUrl.indexOf('?') >= 0) { throw new RuntimeException( "Invalid base url for solrj. The base URL must not contain parameters: " + baseUrl); } if (client != null) { httpClient = client; internalClient = false; } else { internalClient = true; ModifiableSolrParams params = new ModifiableSolrParams(); params.set(HttpClientUtil.PROP_MAX_CONNECTIONS, 128); params.set(HttpClientUtil.PROP_MAX_CONNECTIONS_PER_HOST, 32); params.set(HttpClientUtil.PROP_FOLLOW_REDIRECTS, followRedirects); httpClient = HttpClientUtil.createClient(params); } this.parser = parser; }
public HttpClusterStateProvider(List<String> solrUrls, HttpClient httpClient) throws Exception { this.httpClient = httpClient == null? HttpClientUtil.createClient(null): httpClient; this.clientIsInternal = httpClient == null; for (String solrUrl: solrUrls) { urlScheme = solrUrl.startsWith("https")? "https": "http"; try (SolrClient initialClient = new HttpSolrClient.Builder().withBaseSolrUrl(solrUrl).withHttpClient(httpClient).build()) { Set<String> liveNodes = fetchLiveNodes(initialClient); // throws exception if unable to fetch this.liveNodes = liveNodes; liveNodesTimestamp = System.nanoTime(); break; } catch (IOException e) { log.warn("Attempt to fetch live_nodes from " + solrUrl + " failed.", e); } } if (this.liveNodes == null || this.liveNodes.isEmpty()) { throw new RuntimeException("Tried fetching live_nodes using Solr URLs provided, i.e. " + solrUrls + ". However, " + "succeeded in obtaining the cluster state from none of them." + "If you think your Solr cluster is up and is accessible," + " you could try re-creating a new CloudSolrClient using working" + " solrUrl(s) or zkHost(s)."); } }
this.myClient = (builder.httpClient == null) ? HttpClientUtil.createClient(null) : builder.httpClient; if (builder.loadBalancedSolrClient == null) builder.loadBalancedSolrClient = createLBHttpSolrClient(builder, myClient); this.lbClient = builder.loadBalancedSolrClient;
private HttpClient createHttpClient() { // This is bug in Solr, if we don't create a customize HttpClient, // UpdateRequest with commit flag will throw an authentication error. ModifiableSolrParams params = new ModifiableSolrParams(); params.set(HttpClientUtil.PROP_BASIC_AUTH_USER, getUsername()); params.set(HttpClientUtil.PROP_BASIC_AUTH_PASS, getPassword()); return HttpClientUtil.createClient(params); }
/** The provided httpClient should use a multi-threaded connection manager */ public LBHttpSolrClient(HttpClient httpClient, ResponseParser parser, String... solrServerUrl) { clientIsInternal = (httpClient == null); this.parser = parser; if (httpClient == null) { ModifiableSolrParams params = new ModifiableSolrParams(); if (solrServerUrl.length > 1) { // we prefer retrying another server params.set(HttpClientUtil.PROP_USE_RETRY, false); } else { params.set(HttpClientUtil.PROP_USE_RETRY, true); } this.httpClient = HttpClientUtil.createClient(params); } else { this.httpClient = httpClient; } for (String s : solrServerUrl) { ServerWrapper wrapper = new ServerWrapper(makeSolrClient(s)); aliveServers.put(wrapper.getKey(), wrapper); } updateAliveList(); }
/** * @param zkHost * A zookeeper client endpoint. * @param updatesToLeaders * If true, sends updates only to shard leaders. * @param httpClient * the {@link HttpClient} instance to be used for all requests. The provided httpClient should use a * multi-threaded connection manager. * @see #CloudSolrClient(String) for full description and details on zkHost */ public CloudSolrClient(String zkHost, boolean updatesToLeaders, HttpClient httpClient) { this.zkHost = zkHost; this.clientIsInternal = httpClient == null; this.myClient = httpClient == null ? HttpClientUtil.createClient(null) : httpClient; this.lbClient = new LBHttpSolrClient(myClient); this.lbClient.setRequestWriter(new BinaryRequestWriter()); this.lbClient.setParser(new BinaryResponseParser()); this.updatesToLeaders = updatesToLeaders; shutdownLBHttpSolrServer = true; lbClient.addQueryParams(STATE_VERSION); }
private void createHttpSolrClient() { HttpSolrClient.Builder builder = new HttpSolrClient.Builder().withBaseSolrUrl(this.url); if (timeout != null) { builder = builder.withConnectionTimeout(timeout); } if (maxConnections != null) { ModifiableSolrParams params = new ModifiableSolrParams(); params.set(HttpClientUtil.PROP_MAX_CONNECTIONS, maxConnections); builder.withHttpClient(HttpClientUtil.createClient(params)); } this.setSolrClient(builder.build()); }
this.zkHost = zkHost; this.clientIsInternal = true; this.myClient = HttpClientUtil.createClient(null); this.lbClient = new LBHttpSolrClient(myClient); this.lbClient.setRequestWriter(new BinaryRequestWriter());
this.zkHost = zkHost; this.clientIsInternal = httpClient == null; this.myClient = httpClient == null ? HttpClientUtil.createClient(null) : httpClient; this.lbClient = new LBHttpSolrClient(myClient); this.lbClient.setRequestWriter(new BinaryRequestWriter());
} else if (mode==Mode.HTTP) { HttpClientUtil.setConfigurer(new Krb5HttpClientConfigurer()); HttpClient clientParams = HttpClientUtil.createClient(new ModifiableSolrParams() {{ add(HttpClientUtil.PROP_ALLOW_COMPRESSION, config.get(HTTP_ALLOW_COMPRESSION).toString()); add(HttpClientUtil.PROP_CONNECTION_TIMEOUT, config.get(HTTP_CONNECTION_TIMEOUT).toString());
} else if (mode==Mode.HTTP) { HttpClientUtil.setConfigurer(new Krb5HttpClientConfigurer()); HttpClient clientParams = HttpClientUtil.createClient(new ModifiableSolrParams() {{ add(HttpClientUtil.PROP_ALLOW_COMPRESSION, config.get(HTTP_ALLOW_COMPRESSION).toString()); add(HttpClientUtil.PROP_CONNECTION_TIMEOUT, config.get(HTTP_CONNECTION_TIMEOUT).toString());