Search in sources :

Example 1 with CloudSolrClient

use of org.apache.solr.client.solrj.impl.CloudSolrClient in project camel by apache.

the class SolrEndpoint method createProducer.

@Override
public Producer createProducer() throws Exception {
    // do we have servers?
    SolrComponent.SolrServerReference ref = getComponent().getSolrServers(this);
    if (ref == null) {
        // no then create new servers
        ref = new SolrComponent.SolrServerReference();
        CloudSolrClient cloudServer = getCloudServer();
        if (cloudServer == null) {
            HttpSolrClient solrServer = new HttpSolrClient(url);
            ConcurrentUpdateSolrClient solrStreamingServer = new ConcurrentUpdateSolrClient(url, streamingQueueSize, streamingThreadCount);
            // set the properties on the solr server
            if (maxRetries != null) {
                solrServer.setMaxRetries(maxRetries);
            }
            if (soTimeout != null) {
                solrServer.setSoTimeout(soTimeout);
            }
            if (connectionTimeout != null) {
                solrServer.setConnectionTimeout(connectionTimeout);
            }
            if (defaultMaxConnectionsPerHost != null) {
                solrServer.setDefaultMaxConnectionsPerHost(defaultMaxConnectionsPerHost);
            }
            if (maxTotalConnections != null) {
                solrServer.setMaxTotalConnections(maxTotalConnections);
            }
            if (followRedirects != null) {
                solrServer.setFollowRedirects(followRedirects);
            }
            if (allowCompression != null) {
                solrServer.setAllowCompression(allowCompression);
            }
            ref.setSolrServer(solrServer);
            ref.setUpdateSolrServer(solrStreamingServer);
        }
        ref.setCloudSolrServer(cloudServer);
        getComponent().addSolrServers(this, ref);
    }
    ref.addReference();
    return new SolrProducer(this, ref.getSolrServer(), ref.getUpdateSolrServer(), ref.getCloudSolrServer());
}
Also used : HttpSolrClient(org.apache.solr.client.solrj.impl.HttpSolrClient) ConcurrentUpdateSolrClient(org.apache.solr.client.solrj.impl.ConcurrentUpdateSolrClient) CloudSolrClient(org.apache.solr.client.solrj.impl.CloudSolrClient)

Example 2 with CloudSolrClient

use of org.apache.solr.client.solrj.impl.CloudSolrClient in project camel by apache.

the class SolrEndpoint method getCloudServer.

private CloudSolrClient getCloudServer() {
    CloudSolrClient rVal = null;
    if (this.getZkHost() != null && this.getCollection() != null) {
        rVal = new CloudSolrClient(zkHost);
        rVal.setDefaultCollection(this.getCollection());
    }
    return rVal;
}
Also used : CloudSolrClient(org.apache.solr.client.solrj.impl.CloudSolrClient)

Example 3 with CloudSolrClient

use of org.apache.solr.client.solrj.impl.CloudSolrClient in project YCSB by brianfrankcooper.

the class SolrClient method init.

/**
   * 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));
    }
}
Also used : Krb5HttpClientConfigurer(org.apache.solr.client.solrj.impl.Krb5HttpClientConfigurer) HttpSolrClient(org.apache.solr.client.solrj.impl.HttpSolrClient) CloudSolrClient(org.apache.solr.client.solrj.impl.CloudSolrClient)

Example 4 with CloudSolrClient

use of org.apache.solr.client.solrj.impl.CloudSolrClient in project incubator-atlas by apache.

the class Solr5Index method clearStorage.

@Override
public void clearStorage() throws BackendException {
    try {
        if (mode != Mode.CLOUD)
            throw new UnsupportedOperationException("Operation only supported for SolrCloud");
        logger.debug("Clearing storage from Solr: {}", solrClient);
        ZkStateReader zkStateReader = ((CloudSolrClient) solrClient).getZkStateReader();
        zkStateReader.updateClusterState();
        ClusterState clusterState = zkStateReader.getClusterState();
        for (String collection : clusterState.getCollections()) {
            logger.debug("Clearing collection [{}] in Solr", collection);
            UpdateRequest deleteAll = newUpdateRequest();
            deleteAll.deleteByQuery("*:*");
            solrClient.request(deleteAll, collection);
        }
    } catch (SolrServerException e) {
        logger.error("Unable to clear storage from index due to server error on Solr.", e);
        throw new PermanentBackendException(e);
    } catch (IOException e) {
        logger.error("Unable to clear storage from index due to low-level I/O error.", e);
        throw new PermanentBackendException(e);
    } catch (Exception e) {
        logger.error("Unable to clear storage from index due to general error.", e);
        throw new PermanentBackendException(e);
    }
}
Also used : ZkStateReader(org.apache.solr.common.cloud.ZkStateReader) ClusterState(org.apache.solr.common.cloud.ClusterState) UpdateRequest(org.apache.solr.client.solrj.request.UpdateRequest) PermanentBackendException(com.thinkaurelius.titan.diskstorage.PermanentBackendException) SolrServerException(org.apache.solr.client.solrj.SolrServerException) IOException(java.io.IOException) TemporaryBackendException(com.thinkaurelius.titan.diskstorage.TemporaryBackendException) SolrServerException(org.apache.solr.client.solrj.SolrServerException) PermanentBackendException(com.thinkaurelius.titan.diskstorage.PermanentBackendException) BackendException(com.thinkaurelius.titan.diskstorage.BackendException) KeeperException(org.apache.zookeeper.KeeperException) IOException(java.io.IOException) CloudSolrClient(org.apache.solr.client.solrj.impl.CloudSolrClient)

Example 5 with CloudSolrClient

use of org.apache.solr.client.solrj.impl.CloudSolrClient in project lucene-solr by apache.

the class CreateCollectionCleanupTest method testCreateCollectionCleanup.

@Test
public void testCreateCollectionCleanup() throws Exception {
    final CloudSolrClient cloudClient = cluster.getSolrClient();
    // Create a collection that would fail
    CollectionAdminRequest.Create create = CollectionAdminRequest.createCollection("foo", "conf1", 1, 1);
    Properties properties = new Properties();
    properties.put(CoreAdminParams.DATA_DIR, "/some_invalid_dir/foo");
    create.setProperties(properties);
    CollectionAdminResponse rsp = create.process(cloudClient);
    assertFalse(rsp.isSuccess());
    // Confirm using LIST that the collection does not exist
    assertFalse(CollectionAdminRequest.listCollections(cloudClient).contains("foo"));
}
Also used : CollectionAdminResponse(org.apache.solr.client.solrj.response.CollectionAdminResponse) CollectionAdminRequest(org.apache.solr.client.solrj.request.CollectionAdminRequest) Properties(java.util.Properties) CloudSolrClient(org.apache.solr.client.solrj.impl.CloudSolrClient) Test(org.junit.Test)

Aggregations

CloudSolrClient (org.apache.solr.client.solrj.impl.CloudSolrClient)134 Test (org.junit.Test)52 ArrayList (java.util.ArrayList)38 SolrQuery (org.apache.solr.client.solrj.SolrQuery)29 HashMap (java.util.HashMap)25 SolrInputDocument (org.apache.solr.common.SolrInputDocument)25 CollectionAdminRequest (org.apache.solr.client.solrj.request.CollectionAdminRequest)24 QueryResponse (org.apache.solr.client.solrj.response.QueryResponse)24 Slice (org.apache.solr.common.cloud.Slice)24 JettySolrRunner (org.apache.solr.client.solrj.embedded.JettySolrRunner)22 List (java.util.List)21 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)20 Map (java.util.Map)19 QueryRequest (org.apache.solr.client.solrj.request.QueryRequest)19 ZkStateReader (org.apache.solr.common.cloud.ZkStateReader)19 NamedList (org.apache.solr.common.util.NamedList)18 Replica (org.apache.solr.common.cloud.Replica)17 UpdateRequest (org.apache.solr.client.solrj.request.UpdateRequest)16 SolrRequest (org.apache.solr.client.solrj.SolrRequest)15 DocCollection (org.apache.solr.common.cloud.DocCollection)14