use of org.apache.solr.client.solrj.embedded.JettySolrRunner in project jackrabbit-oak by apache.
the class EmbeddedSolrServerProvider method createSolrServer.
private SolrServer createSolrServer() throws Exception {
log.info("creating new embedded solr server with config: {}", solrServerConfiguration);
String solrHomePath = solrServerConfiguration.getSolrHomePath();
String coreName = solrServerConfiguration.getCoreName();
EmbeddedSolrServerConfiguration.HttpConfiguration httpConfiguration = solrServerConfiguration.getHttpConfiguration();
if (solrHomePath != null && coreName != null) {
checkSolrConfiguration(solrHomePath, coreName);
if (httpConfiguration != null) {
if (log.isInfoEnabled()) {
log.info("starting embedded Solr server with http bindings");
}
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(JettySolrRunner.class.getClassLoader());
Integer httpPort = httpConfiguration.getHttpPort();
String context = httpConfiguration.getContext();
JettySolrRunner jettySolrRunner = null;
try {
jettySolrRunner = new JettySolrRunner(solrHomePath, context, httpPort, "solrconfig.xml", "schema.xml", true);
if (log.isInfoEnabled()) {
log.info("Jetty runner instantiated");
}
jettySolrRunner.start(true);
if (log.isInfoEnabled()) {
log.info("Jetty runner started");
}
} catch (Exception t) {
if (log.isErrorEnabled()) {
log.error("an error has occurred while starting Solr Jetty", t);
}
} finally {
if (jettySolrRunner != null && !jettySolrRunner.isRunning()) {
try {
jettySolrRunner.stop();
if (log.isInfoEnabled()) {
log.info("Jetty runner stopped");
}
} catch (Exception e) {
if (log.isErrorEnabled()) {
log.error("error while stopping the Jetty runner", e);
}
}
}
Thread.currentThread().setContextClassLoader(classLoader);
}
if (log.isInfoEnabled()) {
log.info("starting HTTP Solr server");
}
return new HttpWithJettySolrServer(SolrServerConfigurationDefaults.LOCAL_BASE_URL + ':' + httpPort + context + '/' + coreName, jettySolrRunner);
} else {
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(CoreContainer.class.getClassLoader());
CoreContainer coreContainer = new CoreContainer(solrHomePath);
try {
if (!coreContainer.isLoaded(coreName)) {
coreContainer.load();
}
} catch (Exception e) {
log.error("cannot load core {}, shutting down embedded Solr..", coreName, e);
try {
coreContainer.shutdown();
} catch (Exception se) {
log.error("could not shutdown embedded Solr", se);
}
return null;
} finally {
Thread.currentThread().setContextClassLoader(classLoader);
}
EmbeddedSolrServer server = new EmbeddedSolrServer(coreContainer, coreName);
if (server.ping().getStatus() == 0) {
return server;
} else {
throw new IOException("the embedded Solr server is not alive");
}
}
} else {
throw new Exception("SolrServer configuration proprties not set");
}
}
use of org.apache.solr.client.solrj.embedded.JettySolrRunner in project camel by apache.
the class JettySolrFactory method createJetty.
private static JettySolrRunner createJetty(String solrHome, String configFile, String schemaFile, String context, boolean stopAtShutdown, SortedMap<ServletHolder, String> extraServlets, boolean ssl) throws Exception {
if (!mockedSslClient) {
installAllTrustingClientSsl();
mockedSslClient = true;
}
// Set appropriate paths for Solr to use.
System.setProperty("solr.solr.home", solrHome);
System.setProperty("jetty.testMode", "true");
System.setProperty("solr.data.dir", "target/test-classes/solr/data" + (dataDirNo++));
// Instruct Solr to keep the index in memory, for faster testing.
System.setProperty("solr.directoryFactory", "solr.RAMDirectoryFactory");
SSLConfig sslConfig = buildSSLConfig(ssl, false);
context = context == null ? "/solr" : context;
JettySolrRunner jetty = new JettySolrRunner(solrHome, context, 0, configFile, schemaFile, stopAtShutdown, extraServlets, sslConfig);
jetty.start();
return jetty;
}
use of org.apache.solr.client.solrj.embedded.JettySolrRunner in project YCSB by brianfrankcooper.
the class SolrClientTest method getDB.
@Override
protected DB getDB(Properties props) {
instance = new SolrClient();
// Use the first Solr server in the cluster.
// Doesn't matter if there are more since requests will be forwarded properly by Solr.
JettySolrRunner jettySolrRunner = miniSolrCloudCluster.getJettySolrRunners().get(0);
String solrBaseUrl = String.format("http://localhost:%s%s", jettySolrRunner.getLocalPort(), jettySolrRunner.getBaseUrl());
props.setProperty("solr.base.url", solrBaseUrl);
instance.setProperties(props);
try {
instance.init();
} catch (Exception error) {
assumeNoException(error);
}
return instance;
}
use of org.apache.solr.client.solrj.embedded.JettySolrRunner in project gora by apache.
the class GoraSolrManagedSchemaTestDriver method setUpClass.
@Override
public void setUpClass() throws Exception {
solr = new JettySolrRunner("src/test/conf/solr-managed-schema", "/solr", 9876);
solr.start();
}
use of org.apache.solr.client.solrj.embedded.JettySolrRunner in project gora by apache.
the class GoraSolrTestDriver method setUpClass.
@Override
public void setUpClass() throws Exception {
solr = new JettySolrRunner("src/test/conf/solr", "/solr", 9876);
solr.start();
}
Aggregations