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());
}
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;
}
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));
}
}
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);
}
}
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"));
}
Aggregations