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); } }
HttpClientUtil.setConfigurer(new KerberosHttpClientConfigurer()); final HttpClient httpClient = HttpClientUtil.createClient(params);
void enableKerberos() { HttpClientUtil.addConfigurer(new Krb5HttpClientConfigurer()); }
/** * 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()); }
/** * Initialize any state for this DB. Called once per DB instance; there is one DB instance per * client thread. */ @Override public void init() throws DBException { Properties props = getProperties(); commitTime = Integer .parseInt(props.getProperty("solr.commit.within.time", DEFAULT_COMMIT_WITHIN_TIME)); batchMode = Boolean.parseBoolean(props.getProperty("solr.batch.mode", DEFAULT_BATCH_MODE)); String jaasConfPath = props.getProperty("solr.jaas.conf.path"); if(jaasConfPath != null) { System.setProperty("java.security.auth.login.config", jaasConfPath); HttpClientUtil.setConfigurer(new Krb5HttpClientConfigurer()); } // Check if Solr cluster is running in SolrCloud or Stand-alone mode Boolean cloudMode = Boolean.parseBoolean(props.getProperty("solr.cloud", DEFAULT_CLOUD_MODE)); System.err.println("Solr Cloud Mode = " + cloudMode); if (cloudMode) { System.err.println("Solr Zookeeper Remote Hosts = " + props.getProperty("solr.zookeeper.hosts", DEFAULT_ZOOKEEPER_HOSTS)); client = new CloudSolrClient( props.getProperty("solr.zookeeper.hosts", DEFAULT_ZOOKEEPER_HOSTS)); } else { client = new HttpSolrClient(props.getProperty("solr.base.url", DEFAULT_SOLR_BASE_URL)); } }
@Override public void close() throws IOException { if (this.clientIsInternal && this.httpClient != null) { HttpClientUtil.close(httpClient); } }
headers.forEach((k, v) -> req.addHeader(k, v)); RequestConfig.Builder requestConfigBuilder = HttpClientUtil.createDefaultRequestConfigBuilder(); if (timeout > 0) { requestConfigBuilder.setSocketTimeout(timeout); HttpClientContext httpClientRequestContext = HttpClientUtil.createNewHttpClientRequestContext(); HttpResponse rsp = client.execute(req, httpClientRequestContext); int statusCode = rsp.getStatusLine().getStatusCode();
private void configureSolrClientsForKerberos() throws PermanentBackendException { String kerberosConfig = System.getProperty("java.security.auth.login.config"); if(kerberosConfig == null) { throw new PermanentBackendException("Unable to configure kerberos for solr client. System property 'java.security.auth.login.config' is not set."); } logger.debug("Using kerberos configuration file located at '{}'.", kerberosConfig); try(Krb5HttpClientBuilder krbBuild = new Krb5HttpClientBuilder()) { SolrHttpClientBuilder kb = krbBuild.getBuilder(); HttpClientUtil.setHttpClientBuilder(kb); HttpRequestInterceptor bufferedEntityInterceptor = new HttpRequestInterceptor() { @Override public void process(HttpRequest request, HttpContext context) throws HttpException, IOException { if(request instanceof HttpEntityEnclosingRequest) { HttpEntityEnclosingRequest enclosingRequest = ((HttpEntityEnclosingRequest) request); HttpEntity requestEntity = enclosingRequest.getEntity(); enclosingRequest.setEntity(new BufferedHttpEntity(requestEntity)); } } }; HttpClientUtil.addRequestInterceptor(bufferedEntityInterceptor); HttpRequestInterceptor preemptiveAuth = new PreemptiveAuth(new KerberosScheme()); HttpClientUtil.addRequestInterceptor(preemptiveAuth); } }
HttpClientUtil.setCookiePolicy(SolrPortAwareCookieSpecFactory.POLICY_NAME); return credentialsProvider; }); HttpClientUtil.addRequestInterceptor(bufferedEntityInterceptor);
/** * Executes the given request and returns the response. */ private String getResponse(HttpUriRequest request) throws IOException { HttpEntity entity = null; try { entity = httpClient.execute(request, HttpClientUtil.createNewHttpClientRequestContext()).getEntity(); return EntityUtils.toString(entity, StandardCharsets.UTF_8); } finally { EntityUtils.consumeQuietly(entity); } }
private SolrHttpClientBuilder initHttpClientBuilder(SolrHttpClientBuilder builder) { final String basicAuthUser = defaultParams.get(HttpClientUtil.PROP_BASIC_AUTH_USER); final String basicAuthPass = defaultParams.get(HttpClientUtil.PROP_BASIC_AUTH_PASS); if(basicAuthUser == null || basicAuthPass == null) { throw new IllegalArgumentException("username & password must be specified with " + getClass().getName()); } builder.setDefaultCredentialsProvider(new CredentialsProviderProvider() { @Override public CredentialsProvider getCredentialsProvider() { CredentialsProvider credsProvider = new BasicCredentialsProvider(); credsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(basicAuthUser, basicAuthPass)); return credsProvider; } }); HttpClientUtil.addRequestInterceptor(requestInterceptor); return builder; } }
/** * Initialize any state for this DB. Called once per DB instance; there is one DB instance per * client thread. */ @Override public void init() throws DBException { Properties props = getProperties(); commitTime = Integer .parseInt(props.getProperty("solr.commit.within.time", DEFAULT_COMMIT_WITHIN_TIME)); batchMode = Boolean.parseBoolean(props.getProperty("solr.batch.mode", DEFAULT_BATCH_MODE)); String jaasConfPath = props.getProperty("solr.jaas.conf.path"); if(jaasConfPath != null) { System.setProperty("java.security.auth.login.config", jaasConfPath); HttpClientUtil.setConfigurer(new Krb5HttpClientConfigurer()); } // Check if Solr cluster is running in SolrCloud or Stand-alone mode Boolean cloudMode = Boolean.parseBoolean(props.getProperty("solr.cloud", DEFAULT_CLOUD_MODE)); System.err.println("Solr Cloud Mode = " + cloudMode); if (cloudMode) { System.err.println("Solr Zookeeper Remote Hosts = " + props.getProperty("solr.zookeeper.hosts", DEFAULT_ZOOKEEPER_HOSTS)); client = new CloudSolrClient.Builder().withZkHost( Arrays.asList(props.getProperty("solr.zookeeper.hosts", DEFAULT_ZOOKEEPER_HOSTS).split(","))).build(); } else { client = new HttpSolrClient.Builder(props.getProperty("solr.base.url", DEFAULT_SOLR_BASE_URL)).build(); } }
/** * Close the {@link HttpClientConnectionManager} from the internal client. */ @Override public void close() throws IOException { if (httpClient != null && internalClient) { HttpClientUtil.close(httpClient); } }
+ requestParams.toQueryString()); org.apache.http.client.config.RequestConfig.Builder requestConfigBuilder = HttpClientUtil.createDefaultRequestConfigBuilder(); if (soTimeout != null) { requestConfigBuilder.setSocketTimeout(soTimeout); .execute(method, HttpClientUtil.createNewHttpClientRequestContext());
public MetronSolrClient(String zkHost, Map<String, Object> solrHttpConfig) { super(zkHost, HttpClientUtil.createClient(toSolrProps(solrHttpConfig))); }
HttpClientUtil.setConfigurer(new Krb5HttpClientConfigurer()); String zookeeperUrl = config.get(Solr5Index.ZOOKEEPER_URL); CloudSolrClient cloudServer = new CloudSolrClient(zookeeperUrl, true); solrClient = cloudServer; } 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());
@Override public void prepare(Map<String, Object> topoConf, TopologyContext context, OutputCollector collector) { this.collector = collector; if (solrConfig.isKerberosEnabled()) { HttpClientUtil.setConfigurer(new Krb5HttpClientConfigurer()); } solrMapper.configure(); this.solrClient = new CloudSolrClient(solrConfig.getZkHostString()); this.toCommitTuples = new ArrayList<>(capacity()); }
/** * Close the {@link ClientConnectionManager} from the internal client. */ @Override public void close() throws IOException { if (httpClient != null && internalClient) { HttpClientUtil.close(httpClient); } }
protected NamedList<Object> executeMethod(HttpRequestBase method, final ResponseParser processor, final boolean isV2Api) throws SolrServerException { method.addHeader("User-Agent", AGENT); org.apache.http.client.config.RequestConfig.Builder requestConfigBuilder = HttpClientUtil.createDefaultRequestConfigBuilder(); if (soTimeout != null) { requestConfigBuilder.setSocketTimeout(soTimeout); try { HttpClientContext httpClientRequestContext = HttpClientUtil.createNewHttpClientRequestContext(); final HttpResponse response = httpClient.execute(method, httpClientRequestContext);
@Override public void init(Map stormConf, TopologyContext topologyContext, WriterConfiguration configurations) throws IOException, SolrServerException { Map<String, Object> globalConfiguration = configurations.getGlobalConfig(); initializeFromGlobalConfig(globalConfiguration); LOG.info("Initializing SOLR writer: {}", zookeeperUrl); LOG.info("Forcing commit per batch: {}", shouldCommit); LOG.info("Soft commit: {}", softCommit); LOG.info("Commit Wait Searcher: {}", waitSearcher); LOG.info("Commit Wait Flush: {}", waitFlush); LOG.info("Default Collection: {}", "" + defaultCollection ); if(solr == null) { if (isKerberosEnabled(stormConf)) { HttpClientUtil.addConfigurer(new Krb5HttpClientConfigurer()); } solr = new MetronSolrClient(zookeeperUrl, solrHttpConfig); } solr.setDefaultCollection(defaultCollection); }