Search in sources :

Example 66 with JettySolrRunner

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");
    }
}
Also used : EmbeddedSolrServerConfiguration(org.apache.jackrabbit.oak.plugins.index.solr.configuration.EmbeddedSolrServerConfiguration) CoreContainer(org.apache.solr.core.CoreContainer) JettySolrRunner(org.apache.solr.client.solrj.embedded.JettySolrRunner) IOException(java.io.IOException) EmbeddedSolrServer(org.apache.solr.client.solrj.embedded.EmbeddedSolrServer) IOException(java.io.IOException)

Example 67 with JettySolrRunner

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;
}
Also used : SSLConfig(org.apache.solr.client.solrj.embedded.SSLConfig) JettySolrRunner(org.apache.solr.client.solrj.embedded.JettySolrRunner)

Example 68 with JettySolrRunner

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;
}
Also used : JettySolrRunner(org.apache.solr.client.solrj.embedded.JettySolrRunner) Assume.assumeNoException(org.junit.Assume.assumeNoException)

Example 69 with JettySolrRunner

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();
}
Also used : JettySolrRunner(org.apache.solr.client.solrj.embedded.JettySolrRunner)

Example 70 with JettySolrRunner

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();
}
Also used : JettySolrRunner(org.apache.solr.client.solrj.embedded.JettySolrRunner)

Aggregations

JettySolrRunner (org.apache.solr.client.solrj.embedded.JettySolrRunner)137 Test (org.junit.Test)52 HttpSolrClient (org.apache.solr.client.solrj.impl.HttpSolrClient)29 Replica (org.apache.solr.common.cloud.Replica)28 CloudSolrClient (org.apache.solr.client.solrj.impl.CloudSolrClient)25 SolrInputDocument (org.apache.solr.common.SolrInputDocument)20 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)20 File (java.io.File)19 SolrQuery (org.apache.solr.client.solrj.SolrQuery)19 DocCollection (org.apache.solr.common.cloud.DocCollection)18 Slice (org.apache.solr.common.cloud.Slice)18 IOException (java.io.IOException)15 ArrayList (java.util.ArrayList)15 Properties (java.util.Properties)15 SolrClient (org.apache.solr.client.solrj.SolrClient)15 UpdateRequest (org.apache.solr.client.solrj.request.UpdateRequest)15 QueryResponse (org.apache.solr.client.solrj.response.QueryResponse)15 CoreContainer (org.apache.solr.core.CoreContainer)14 BeforeClass (org.junit.BeforeClass)14 ClusterState (org.apache.solr.common.cloud.ClusterState)13