Example usage for org.apache.solr.client.solrj.impl CloudSolrClient setZkConnectTimeout

List of usage examples for org.apache.solr.client.solrj.impl CloudSolrClient setZkConnectTimeout

Introduction

In this page you can find the example usage for org.apache.solr.client.solrj.impl CloudSolrClient setZkConnectTimeout.

Prototype

public void setZkConnectTimeout(int zkConnectTimeout) 

Source Link

Document

Set the connect timeout to the zookeeper ensemble in ms

Usage

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());
    }/*from   www.  j av a  2s.c  om*/
    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 w ww.  j  av a 2 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 ava 2s. co m*/
}

From source file:com.nridge.ds.solr.SolrDS.java

License:Open Source License

/**
 * Creates a Solr Client instance for use within the SolrJ framework.
 * This is an advanced method that should not be used for standard
 * data source operations.//ww  w. ja  va2 s.c  o m
 *
 * @return Solr client instance.
 *
 * @throws DSException Data source related exception.
 */
public SolrClient createSolrClient() throws DSException {
    String propertyName;
    SolrClient solrClient;
    Logger appLogger = mAppMgr.getLogger(this, "createSolrClient");

    appLogger.trace(mAppMgr.LOGMSG_TRACE_ENTER);

    if (StringUtils.isEmpty(mCollectionName)) {
        propertyName = getCfgPropertyPrefix() + ".collection_name";
        mCollectionName = mAppMgr.getString(propertyName);
    }
    ArrayList<String> zkHostNameList = new ArrayList<>();
    propertyName = getCfgPropertyPrefix() + ".cloud_zk_host_names";
    String zookeeperHosts = mAppMgr.getString(propertyName);
    if (mAppMgr.isPropertyMultiValue(propertyName)) {
        String[] zkHosts = mAppMgr.getStringArray(propertyName);
        for (String zkHost : zkHosts)
            zkHostNameList.add(zkHost);
    } else {
        String zkHost = mAppMgr.getString(propertyName);
        if (StringUtils.isNotEmpty(zkHost))
            zkHostNameList.add(zkHost);
    }

    if (zkHostNameList.size() > 0) {
        Optional<String> zkChRoot;
        propertyName = getCfgPropertyPrefix() + ".cloud_zk_root";
        String zkRoot = mAppMgr.getString(propertyName);
        if (StringUtils.isEmpty(zkRoot))
            zkChRoot = Optional.empty();
        else
            zkChRoot = Optional.of(zkRoot);
        CloudSolrClient cloudSolrClient = new CloudSolrClient.Builder(zkHostNameList, zkChRoot).build();
        if (StringUtils.isNotEmpty(mCollectionName)) {
            mSolrIdentity = String.format("SolrCloud (%s)", mCollectionName);
            cloudSolrClient.setDefaultCollection(mCollectionName);
        }
        propertyName = getCfgPropertyPrefix() + ".cloud_zk_timeout";
        int zookeeperTimeout = mAppMgr.getInt(propertyName, Solr.CONNECTION_TIMEOUT_MINIMUM);
        if (zookeeperTimeout > Solr.CONNECTION_TIMEOUT_MINIMUM)
            cloudSolrClient.setZkConnectTimeout(zookeeperTimeout);
        solrClient = cloudSolrClient;
        mBaseSolrURL = getSolrBaseURL(cloudSolrClient);

        appLogger.debug(String.format("SolrCloud: %s (%s) - %d connection timeout.", zookeeperHosts,
                mCollectionName, zookeeperTimeout));
    } else {
        propertyName = getCfgPropertyPrefix() + ".request_uri";
        String solrBaseURL = mAppMgr.getString(propertyName);
        if (StringUtils.isEmpty(solrBaseURL)) {
            String msgStr = String.format("%s: Property is undefined.", propertyName);
            throw new DSException(msgStr);
        }
        mBaseSolrURL = solrBaseURL;
        HttpSolrClient.Builder httpSolrClientBuilder = new HttpSolrClient.Builder(solrBaseURL);
        solrClient = httpSolrClientBuilder.build();
        mSolrIdentity = String.format("SolrServer (%s)", solrBaseURL);
        appLogger.debug(mSolrIdentity);
    }

    appLogger.trace(mAppMgr.LOGMSG_TRACE_DEPART);

    return solrClient;
}

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. jav  a  2  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.dbflute.solr.bhv.AbstractSolrBehavior.java

License:Apache License

/**
 * Create CloudSolrClient associated with the assigned host.
 * @param host Host (NotNull)/*  w  w  w.j a v a  2 s .c  o m*/
 * @return CloudSolrClient (NotNull)
 */
protected CloudSolrClient createCloudSolrClient(String host) {
    CloudSolrClient client = new CloudSolrClient(host);
    client.setZkConnectTimeout(getConnectionTimeout());
    return client;
}

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 {/*from  w ww.  j  a va  2s.c om*/
        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;
}